[Question]
  [
This is a challenge in which two people, 1 and 2, are running for office. People deterministically vote in certain ways in the world of 1 and 2, which can allow for the candidates to figure out the results before the election.
NOTE: this is not meant to refer to any outside elections or other political events.
Two people are running for office. We'll call these people 1 and 2. Because they both want to know if they will win the election, they decide to use their knowledge of people and some code to figure out what the result will be. Due to the want to minimize government spending, the code needs to be a short as possible.
**Your task:** Given a string of people based on how they are voting, output who wins the election.
There are five kinds of people in the fun and exciting world of 1 and 2:
* `A`: people who will definitely vote for 1.
* `B`: people who will definitely vote for 2.
* `X`: people who will vote for whoever the person to their left will vote for. If there is no person to their left, then they vote for whoever the person at their right will vote for. If it is not clear who the person to their right is voting for, then they do not vote.
* `Y`: people will vote the opposite of the person to their left. If there is no person to their left, then they vote opposite of whoever is at their right. If it is not clear who the person to their right is voting for, then they do not vote.
* `N`: people who do not vote.
This is evaluated from left to right.
**Example:**
Whoever is being "evaluated" is in lowercase, for clarity.
```
Input: `XXAYAN`
        xX      Votes for whoever their friend is voting for. Their friend has not decided yet, so it is unclear, so they do not vote.
        Xx      Person to left is voting "none" so votes "none."
          a     Votes for 1
          Ay    Since person on left is voting for 1, votes for 2.
            a   Votes for 1
             n  Does not vote
```
Final poll:
* 2 people voted for 1
* 1 people voted for 2
* 3 people did not vote
1 has the most votes, so 1 wins!
**Test cases:**
You may use other characters or values as input and output, as long as they are distinct. (For example: numbers instead of letters, different letters, lowercase letters, truthy/falsy or positive/negative (for output), etc.)
```
Input -> Output
"AAAA" -> 1
"BBBB" -> 2
"BBAXY" -> 2
"BAXYBNXBAYXBN" -> 2
"XXAYAN" -> 1
"AAAABXXXX" -> 2
"AXNXXXXAYB" -> 1
"NANNY" -> 1
"XA" -> 1
"YAB" -> 2
"XY" -> anything (do not need to handle test cases with no victor)
"AB" -> anything (do not need to handle test cases with no victor)
```
  
[Answer]
# Java 8, ~~153~~ ~~141~~ ~~135~~ ~~131~~ 129 bytes
```
a->{int l=a.length,t,r=0,i=-1;for(;++i<l;r+=(t=a[i]=a[i]>4?t<3?t^3:3:a[i]>3?t:a[i])>2?0:3-t*2)t=a[i>0?i-1:i<l-1?i+1:i];return r;}
```
Uses an integer array as input with `A=1, B=2, N=3, X=4, Y=5` and outputs a positive integer (`>= 1`) if A wins, a negative integer (`<= -1`) if B wins, or `0` if it's a draw.
-18 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##nVbLbptAFN37K668wjF@AEatTLA1s@ui00rZgNJUmhiSTErAgiFWFHnbD@gn9kfcy/CInRiTdEaCGbDP4Z5z79Xc80c@ug9@7VYRzzL4ykX83AMQsQzTG74KgRVb9QBWGl4vr4APHHy27eElk1yKFTCIwYUdHy2eix9GLh9HYXwr73Spp@5UF@7IcG6SVHOGQ3EeOenQ1aTLL8WVuixmS3luLeVPa27N1QPcqMVgYS6nc2skz8yB@sNiuhQjY44gI2Mphri6ctJQ5mkMqbPdOb3JWe9LvM7lHIhr6EBdUwfmWjp47kwH37V733JZvZdpHhY/ueFRFvbOJhjQOr@OMKAqrsdEBPCAmmgXMhXxrQq@FOTiKZPhwzjJ5XiNr2QUa/3vafIogjAAGWYoF8/CbN5XYoF6pMXhBpSGz4au5nbgwJExmUCf4OjDaFGvNIIBUBQTsgQIbEScDY4hm7qaJ5ApjhK5XCHyFJFnCpmeRjb0mW4fxS6RiefX0ISU2CZiW93YChkZLLwXO1vdLcWlsBGaMo8S36Os4kAKypAJw2CKy0Kuz11cM0Qu8I0K/W0cnkd8UpEwRihhTSRGl/6Vs/jts3IecNTOUg/Hi720caLw2O6KoNDKqvFVLPt@Kw6PFQzEpzUJKwapWAqdzK5IrEIhnO1@M0St/C6WpUrG0Sw9Vi8/4ovkIQQeBEKKJObRuwrHVIliKAGKna3uL4mC2qJ5HqG@V3tIimxURpLKyk9NUpJTiWLr7cmiEsU/TJWPJoutjKzTXa1eGel7rEh5vDQcVGU9aVi6C7elGewVblVQTTMw3mCeMPA6ifNszzvY3InVHYRxAPkavwE4BCnftFla9ZWTHYt4L22lCbzM4BK8zcAToZcG1rI2oU@7UA3d7EAlddXRpiKMLlSrVYGm2ryPf6vVqQD7PwX0sjhs1SEOda6L0PMZq/VVFUhZ3SOspvxOsrT3uIrlVZM76HHvyhCrszTq2m5VZ/8gpA4MiqI@KrWeFu7x5DXOpYjGJE35UzaWSXnI0Phg2Ie/v/9AfxiPV7itzlvb3T8)
**Explanation:**
```
a->{                      // Method with int-array parameter and boolean return-type
  int l=a.length,         //  Length of the input-array
      t,                  //  Temp integer, uninitialized
      r=0,                //  Result-integer, starting at 0
  i=-1;for(;++i<l         //  Loop `i` in the range [0, l):
           ;              //    After every iteration:
            r+=           //     Increase the result by:
             (t=a[i]=     //       Change `i`'th item in the array to:
                 a[i]>4?  //        If the `i`'th item is a 5:
                  t<3?    //         If `t` is 1 or 2:
                   t^3    //          Use `t` Bitwise-XOR 3 to invert it
                          //          (1 becomes 2; 2 becomes 1)
                  :       //         Else (`t` is 3, 4, or 5 instead):
                   3      //          Set it to 3
                 :a[i]>3? //        Else-if the `i`'th item is a 4:
                  t       //         Set it to `t`
                 :        //        Else (the `i`'th item is a 1, 2 or 3):
                  a[i])   //         Leave it unchanged
             )>2?         //      And if this new `i`'th value is 3, 4, or 5:
              0           //       Leave the result the same by increasing it with 0
             :            //      Else (it's 1 or 2 instead):
              3-t*2;      //       Increase it by 3 minus two times the `i`'th value
                          //       (which is 1 for 1; and -1 for 2)
         t=               //   Set `t` to:
           a[i>0?         //    If `i` is not the first item:
              i-1         //     Set `t` to the previous (`i-1`'th) value
             :i<l-1?      //    Else-if `i` is not the last item:
              i+1         //     Set `t` to the next (`i+1`'th) value
             :            //    Else (`i` is the first or last item):
              i];         //     Set `t` to the current item itself
  return r;}              //  Return the result
                          //  (positive if A wins; negative if B wins; 0 if it's draw)
```
[Answer]
## Haskell, ~~60~~ ~~50~~ ~~48~~ 59 bytes
```
l#(v:o)|v<2=v+v#o|n<-(3-v)*l=n+n#o
_#_=0
f x=rem(x!!1)2#x>0
```
Uses `1` for `A`, `-1` for `B`, `0` for `N`, `2` for `X` and `4` for `Y`. Returns `True` if `A` wins, else `False`.
[Try it online!](https://tio.run/##TY5BDoMgEEX3nmIaNlqhAeqqkd6gJzDGkKqpKaJRQ1x4d6ujts1n8d9n@MNL9@/CmHk2xHe3JphcLJULHWkmGzP/ylxwNsqGljReRjLFvRJG1RW1P55OIpBkvPO51pUFBbVuHxn4bVfZAS5QBpB4kAiKSunimaDH@WNBJY0ORlhTvhjkaDMcJ@QCa3Tw3r4OyE17LLFgk8BGvODry0W4jzHQeV4NVWO1gaHoB3jqvuhxz/eT0c@KNJ0/ "Haskell – Try It Online")
On the recursive way down the input list we add `1` for every vote for `A`, `-1` for every vote for `B` and `0` for "no vote". `l` is the last vote, `v` the next. If `v=1`, `-1` or `0` (or `v<2`) we just add it to the sum. If `v` is "vote same" (`X` in the challenge, `2` for my solution) we keep and add `l` (`(3-2)*l` = `l`). If `v` is "vote opposite" (`Y` in the challenge, `4` for my solution) we first negate `l` (`(3-4)*l` = `-l`) and then add it. Base case is the empty list which starts the sum with `0`. Recursion is started with `l` set to `rem s 2` where `s` is the second element of the input list (`x!!1`). `rem s 2` maps `1` and `-1` to itself, all other values to `0`. Fix votes ignore `l` anyway [\*] and `X` or `Y` get the right neighbor if it's a fix vote. If the overall sum is positive, `A` wins.
[\*] this makes singleton lists with fix votes like `[1]` work, because due to Haskell's laziness access to the second element is never evaluated. Inputs like `[2]` fail with error, but don't have to be considered. 
[Answer]
# Perl 5, ~~56~~ ~~80~~ ~~72~~ ~~65~~ 53 bytes
+26 bytes to handle the case X or Y in first position and A or B in second. output is `1` if 1 wins empty (false value in perl) otherwise.
```
s/^X(.)/$1$1/,s/A\KX|B\KY|^Y(?=B)/A/|s/B\KX|A\KY|^Y(?=A)/B/&&redo;$_=y/A//>y/B//
```
[TIO](https://tio.run/##PYsxC4NADIX3/A4RD9oGh07FlmQVMicgdqlDQXriuQj@9l5zSz/IC3y8t0zrfM054ajNJWDVVi2eEtLQ68FDb8dozaPjgIRHQi6a/poCMtb1Or3irXp2u5fwvrvDnMkBdjxIDUqwKJMpC6iSkUApsTpAKuWTMQiJGPiEGMzPN9@4bO/4Sfm8zD8)
using `P` and `S` instead of `X` and `Y` allowing to use xor operation on characters, would save some more bytes
```
s/(?|^(P|S)(?=(A|B))|(A|B)\K(P|S))/P^$1^$2/e&&redo;$_=y/A//>y/B//
```
uses a branch reset group `(?|`..`|`..`)`, so that `$1` `$2` refering to corresponding group in branch.
Using `\0` and `\3` instead of `X` and `Y`
```
$_=s/^\W(?=(\w))|(\w)\K\W/$1.$2^$&/e?redo:y/A//>y/B//
```
[72 bytes](https://tio.run/##NYvBCsJADETv@YqCS6mgBgueSoXkKiwLvSQg9eIehGJL66XQb3dNCz6YCWRmhjh2l7TLpA6Z1g3MKIqhwSpN2BZhafYFLbzH0Lpz68qTKzEeJtye99tW@GcY83yMz75yj3pGQrzOyIgpkQFsmJEorMZemFTYgwgpeVhLLAaQ@PWSMnjyXsEmxKAm23z74fPq31M6Dt0P)
[65 bytes](https://tio.run/##HYuxCoNAEET7/QohIndFWBJIJRfZbQPHgc0uBNPEIiAqmka4b8/l9MHMwDAz98twS6dCXCjUtbChKIYW67SiaWJnQmytaZyhyNbGI56Po7UYuvLSlVfsq2rp31NdvtyGhHjfkBFTogxwJhuJwm7shUmFPYiQkod9xJIBEr8nKYMn7xXyhRg0K39@0/z9TOOazvPwBw)
[53 bytes](https://tio.run/##FYtBC4JAEIXv8zuW0IONFl4Kk5lrNFdnYLFLHgJJ0SCEfnvb7gfve5f35mEZ67ChGvrSH/Ec3L1Zsfdd1jaZ/@T5N9lffYeu2rtD73Y4tMvwmE4bEuJlQ0YMgSLAkShSgyQWZTJlAVUyEkgj1giQSmoyBiERg3ghBk1hAottTL9pfj@n1xqKeQzFrd6X1R8)
[Answer]
# JavaScript (ES6), ~~78 75~~ 73 bytes
Takes input as an array of integers with: \$0\$ = N, \$1\$ = A, \$2\$ = B, \$4\$ = Y, \$8\$ = X.
Returns \$false\$ if the first candidate wins or \$true\$ if the 2nd candidate wins.
```
a=>a.reduce((v,x,i)=>v+~~[,1,-1][p=x?x&3||~-x%7^(p&3||a[i+1]&3):0],p=0)<0
```
[Try it online!](https://tio.run/##dY7RSsMwGIXv9xQh4EhYmjXuQhBTSR4g3iaUWkKaSmW2ZamlF6OvXhtRLzb3Xf3wcc5/3u1ogzs1/ZC0XeWXmi@WZ5aefPXpPEIjmUiDeTbu5jknjCSsyHs@PU/bw/k8J9Pdwyvq423zZseK7QE/pgXpeYqf0mXwYQAcBMAz4Lo2dEdPj90bqlFOKQ0F/bA9ctFCJWRpyrLUkDZt5aeXGjm8stnEEgTFCgS/YLDfgyQD7MfKlWt7/2eFNvCmXaVUWgqjpYKXVmthhII3/sZVUq/A/5qFVtEJ873tMquEUter2PIF "JavaScript (Node.js) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~34~~ ~~33~~ ~~32~~ 30 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
gFÐNè©[[email protected]](/cdn-cgi/l/email-protection)èDÄ2‹*D(‚®èNǝ]O
```
Uses an integer-array as input with `A=-1, B=1, N=0, X=2, Y=3` and outputs a negative integer (`<= -1`) if A wins, a positive integer (`>= 1`) if B wins, or `0` if it's a draw.
[Try it online](https://tio.run/##yy9OTMpM/a/kmVdQWqJQlphTmlqsUFqcmmLFpeBoq2vIpeBkCyT8bA24FCJsjbgUIm2Nubj8S0uAyoFK/FLTE0syy1IVbBUcFcoz84q5FALyizOhQk5QIQMgO6UosVwp5n@62@EJfodXHFpp5JDpV2GoF6x7eIXL4RajRw07tVw0HjXMOrTu8Aq/43Nj/f//jzbSMdYxAkJdQyADSBjEAgA) or [verify all test cases](https://tio.run/##bU@/S8NAFN7vr3hkaStJSe6cxFATgqBDKri0xA6RhnIgrZim1SGQoThXR7GDW0tBcBInITf4f@QfiZe7i1SUdz@@99177/tuEoeXNCq1k/F1MoVZeJVEMSRxNDxA4NiGhcC1@eHbJoKejRH0bYJQN5nycl7iR6NwSmcR2ODAnI5jBGeTmCrKVZTJ8fAmnGsXCM3u2NLr7LPVoeb4bq@vFdnLqQZN9tmC4v4RtE45OmZLn63zDT6i/q3VPjfY2mMLXGQfe16zyJ7yV7b2v1Zp2i29jtfO3zzacNmWLWjDYdtGvmGLNC2y52pq/s4eWhzrZRAYll6vgQ6BpYuoIeexTmQmMSdNfouUCGBWz5hDwRiK2JmrV40i1AMWI2SIJqFnil4eRJVJPUMKipxIoBSJ/keViNk/5iQU9nd/pNqlaO1WecC/xKttCv3a1L/OB4Nv).
**Explanation:**
```
g             # Take the length of the (implicit) input-list
              #  i.e. [3,1,3,3,2,0,1] → 7
 F            # Loop `N` in the range [0, length):
  Ð           #  Triplicate the list at the top of the stack
              #  (which is the implicit input-list in the first iteration)
   Nè         #  Get the `N`'th item of the list
              #   i.e. [3,1,3,3,2,0,1] and `N`=0 → 3
              #   i.e. [-1,1,-1,3,2,0,1] and `N`=3 → 3
     ©        #  Store it in the register (without popping)
   2@i        #  If it's larger than or equal to 2 (so either 2 or 3):
      Nx      #   Push `N` and `N` doubled both to the stack
              #    i.e. `N`=0 → 0 and 0
              #    i.e. `N`=3 → 3 and 6
        1.S   #   Compare the double integer with 1 (-1 if N*2<1; 0 if N*2==1; 1 if N*2>1)
              #   (So this will be -1 in the first iteration, otherwise it will be 1)
              #    i.e. 0 → -1
              #    i.e. 6 → 1
           -è #   Subtract that from the index, and index it into the list
              #    i.e. `N`=0 and -1 → 1 (first item, so get the next index)
              #     → [3,1,3,3,2,0,1] and 1 → 1
              #    i.e. `N`=3 and 1 → 2 (fourth item, so get the previous index)
              #     → [-1,1,-1,3,2,0,1] and 2 → -1
      D       #   Duplicate that value
       Ä2‹    #   Check if that value is -1, 0, or 1 (abs(i) < 2) (truthy=1; falsey=0)
          *   #   And multiply that with the value
              #   (remains the same if truthy; or becomes 0 if falsey)
      D(‚     #   Pair it with its negative (-1 becomes [-1,1]; 1 becomes [1,-1])
         ®è   #   And index the `N`'th value (from the register) into it (with wraparound)
              #   (if it was a 2, it uses the unchanged (first) value of the pair;
              #    if it was a 3, it uses the negative (second) value of the pair)
              #     i.e. [1,-1] and 3 → -1
              #     i.e. [-1,1] and 3 → 1
      Nǝ      #   And replace the `N`'th value with this
              #    i.e. [3,1,3,3,2,0,1], `N`=0 and -1 → [-1,1,3,3,2,0,1]
              #    i.e. [-1,1,-1,3,2,0,1], `N`=3 and 1 → [-1,1,-1,1,2,0,1]
 ]            # Close both the if-statement and loop
  O           # Sum the modified list (which now only contains -1, 0, or 1)
              #  i.e. [-1,1,-1,1,1,0,1] → 2
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 42 bytes
```
s=>s.map(c=>x+=l=c%2|l*c/2,l=s[x=1]%2)|x>1
```
[Try it online!](https://tio.run/##dc/RasMgGAXg@zyFCAWzGTO9FH5BH8BrJeQiuHRsuKbUUALrnj013drBmp7bD89//OiOXQqH9/1Y7YbXft7CnEAl9tntSQA1PUOEsBGn@BRqQSOkZgLebkR5mhSfxz6NCFBCoFAYdmmIPYvDG9mShjGW2p@aRcmXlhWnRnJq5Qt1UlAvK/HdhLbMKYqlimCdg9E1JaprVCnEf9Xk3Ku4qXYeP9SMxjqjvTMW/1fntNcWP7i7rDIuB681a2cX0/6y7e7t3@C1H62qKOYz "JavaScript (Node.js) – Try It Online")
Save 1 bytes, thanks to Shaggy.
---
* Input as integer array where N = 0, A = -1, B = 1, X = 2, Y = -2;
* Output 1 = Falsy, 2 = Truthy
[Answer]
# [Python 2](https://docs.python.org/2/), ~~95~~ 73 bytes
```
lambda(v):sum([l for l in[2*int(v[1]/2)]for i in v for l in[i*l**(i%2)]])
```
[Try it online!](https://tio.run/##VVBNi8MgEL37K4bAEk2TLsmx0AU99OjZkM0h21h2IJqgtrS/PqvpfrAPZsSZN@85Lo/wOdtmPcER3tdpMB/jQG/s4K@GdhNcZgcToO2aAm2gt67uXxvWpzLGMtz@GFhMRUHxJbZ7to76AucG6XkeNTsQiAjahwl9iE5dzvMyb2PIGCqGyPuNlOSW2WPA2ZaAQZtko@3VaDcETX9EvjUT8PLkHY@Q3P4aCU6Hq7O/klBBs/X1HQNlhKBZZhfAPzzZNkGrk2G8730Y0e6dHsZU9fRpucxLWmDbjT3fe04TiRNHHC6UwbbL4tKX/WvsMqjeINtlddVkXb0zw50atPREoywra1ZWNesZWXkEERExcdWSlIRUgrdKSKIUb7kkiSRUBOFKppO3gkguZUsUJy0XJE5y8QU "Python 2 – Try It Online")
---
* Input as integer array where N = 0, A = -2, B = 2, X = 1, Y = -1;
* Output negative = A, 0 = draw, positive = B
* If first input is X or Y, then 2\*int(v[1]/2) maps second to itself or 0
Bug fix was required that added extra bytes, but converting to lambda thanks to @Stephen reduced it back to 95
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 70 bytes
```
AY
AB
BY
BA
}`(A|B)X
$1$1
^X(A|B)|^Y[AB]
$1$1
+`N|X|Y|AB|BA
.+|(?<=B)
```
[Try it online!](https://tio.run/##JY6xCgJBDET7@Y4T9jgQrldkprFLnSAea2FhYyGW8dvXXX1FwgyPkNf9/Xje2q6Uc20MUFBAxKcWpmbHtE4rNv@l3OJCXf/dUi09I6nsPvZLltPhqLk1dqBOH/RxzkPmYrgM7gwahiTvgG5jMwSjWcDHH18 "Retina 0.8.2 – Try It Online") Link includes test cases. Outputs `0` for a tie. Explanation:
```
AY
AB
BY
BA
```
Handle `Y` voters to the right of people with decided votes.
```
}`(A|B)X
$1$1
```
Handle `X` voters to the right of people with decided votes, and then loop back until all possible `Y` and `X` votes can be decided.
```
^X(A|B)|^Y[AB]
$1$1
```
Handle an initial `X` voter next to a decided vote, and also an initial `Y` voter next to a decided vote. As this voter will vote opposite to the decided vote, we can just delete both votes in this case.
```
+`N|X|Y|AB|BA
```
Delete any remaining no vote or undecided votes, and cancel out all pairs of opposing decided votes. Repeat until all possible votes are cancelled. In the case of a tie, nothing will be left, otherwise the remaining votes will all be of the same type.
```
.+|(?<=B)
```
Output `1` if there are any votes, but `2` if they are `B` votes.
[Answer]
# [Python](https://www.python.org) 3.8+, 55 bytes
```
lambda v:[l:=v[1]&~1]and sum((l:=i*l**(i%2))for i in v)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TVDLasMwEKRXfcUSaC2ldsC-tARcKh1yKj7LpD64sUwXbNnYckgI6Y_0EijtP7VfU8lOHwO7Qrszs1q9frR789zo09sqfnwfTBncft5Uef1U5LBdrqtlvF2H2dVLmOW6gH6oKbU1nFfzOcXLiLGy6QABNWzZJP-6uC9UCZsI6aYpFFsSsDCqNxX2BmJYe9zzvdRGYkPaEF42kpxX2_RosNE-oFG1M1Z6qFWXG0V_TM6eDlhOvDgGN-2v4dApM3T61xICiMa-2qGhjBCs26Yz0O974kZXqJUbaO-L3hSoF53KC1ft6Xlk27Rug3E5Nr534xSOYyUdtpTBtEvboTa09A7_e0cI7uAwC4Notg6v63xHa9R0Ra0t80PmByHLjt75I0-fD9yCCAubuEyJSyKRgqdSJERKnvKEOJKQFoTLxJ08FSThSZISyUnKBbFKLibTbw)
Port of [ABridgeTooFar's Python 2 solution](https://codegolf.stackexchange.com/a/179704/85334), since we took the time [in TNB](https://chat.stackexchange.com/transcript/message/60745317#60745317) to figure out why and how that list comprehension does anything at all.
[Answer]
## Python ~~3~~ 2, ~~125~~ ~~121~~ 117 bytes
(Thanks to Jonathan Frech)
```
def f(x):
    for i,v in enumerate(x):n=x[i-(i>0)];x[i]=(v>3)*n+abs(n-1)*(v<0)+x[i]*(0<v<4)
    print x.count(1)>x.count(0)
```
Using tab indentation
Input: list of `int`s where 'A'=1, 'B'=0, 'X'=4, 'N'=3, 'Y'=-1, so "AAAA" is `[1, 1, 1, 1]` and "XXAYAN" is `[4, 4, 1, -1, 1, 3]`.
`[{'A': 1, 'B': 0, 'X': 4, 'N': 3, 'Y': -1}[c] for c in s]` will convert the strings to the needed input format.
You can [Try it online!](https://tio.run/##XY5Na4NAEEDP@iuGXNw1pmi0HxgV1oPHPfWwIh6sUSoka/ALS@lvtyNpTOxc3sLbYd7lq/us5X6ajkUJJRmpqypl3UBlDFBJKGR/LpqsK65Gkf6YVDtSBSZND/hMfTIENtXllsi6A0l1Mngm3c5KJ6Y3eA5VlUtTyQ7Gp7zuZUcsGtyeJp0i8OGUnT@OGbQuFiTfGtNcsAzQQqSJFEgHyZE2MkburJ8kT2FOzefQNqXq9Qxuvjd9YRwgIhuGs7mZvQFRdmr/VIizKPufYiJenLN2qEIuQhaLkC9/nh@PCsFidncvq/25KBQ4i39dBQs@Sxbf294ePWecY9r0Cw "Python 2 – Try It Online") (Thanks to Jonathan Frech for the suggestion)
[Answer]
# Python 3, ~~187~~ 156 bytes
Really not that competitive with the other python answers on this, but I had some good ideas for using dicts to make an answer that actually takes string inputs, and it didn't turn out horribly long.
```
def E(s):
 r,g,*v=range(len(s)),lambda**d:d.get(s[i],0),*s
 for i in r:v[i]=g(A=1,B=-1)
 for i in r:v[i]=g(X=1,Y=-1)*v[(i-1,i+1)[i<1]]or v[i]
 return sum(v)
```
[Try it online!](https://tio.run/##bY4xa8MwEIV3/wqRSVLlEtGlmHo4QVbNJ4wHFyuOIJGN7Bjy651zhoJC3/h9d7w3PZbLGL@@p7RtvT@zE59FVbCkBiXXOnVx8PzqI1Ghrt3tt@@k7Kv@c/ALn5vQqqNQci7YeUwssBBZqlbC9cCh1srUpRb/SSTpdinXhodSq/ChRRN@dNvS7X5EG/xyT5HN9xtfxTalEBd@4gegHIQo/oChvAFAlxMCxqIBh8ZmBhEc5GgvMEjJKdqdgcu7LFibd2G@zkH@8LbsZbcn)
Edit -21 bytes: Some beautifully horrific abuse of python by @Unrelated String
Loops through the input twice to fill out an output list containing the vote of each person (`1` for `A`, `-1` for `B`, `0` for no vote), and filling out the `X`s and `Y`s on the second loop. I thought I could do it with one loop, but irritatingly that fails on an `X` or `Y` at the beginning of the string, as it hasn't processed the following vote yet. The return value is positive if candidate 1 wins, and negative if candidate 2 wins. (The absolute value of it also happens to be the margin of victory)
[Answer]
# Perl 5, 54 bytes
```
s/^\W(?=(\w))|(\w)\K\W/$1^$2^$&/e&&redo;$_=y/A//>y/B//
```
[Try it online!](https://tio.run/##FYs9C8MwDER3/Q4TkqGoH3QKaZHWgtZIYNKlGQqhNkmhGPrb69oP7t1yF@d1OeeEauj3/oR93nDyY3sdWv/pum@1v/kR3WFyx8k1ODfNOj9C7@5DQkK8JGTEnKkAXCgiNahiUSZTFlAlI4E6Yi0AqdQmYxASMSgXYtAaJrDSxvQL8f0Mry3v4vIH "Perl 5 – Try It Online")
Uses `A` for `A`, `B` for `B`, `N` for `N`, `\0` for `X` and `\3` for Y (the last two being literal control chars). The trick is that `A` bitwise-xor `\3` equals `B`, and vice-versa.
[Answer]
# Javascript (ES6) - 133 bytes
```
a=>(i=($=_=>'AB'.search(_)+1)(a[1],o=0),[...a].map(v=>(r=['NAB','NBA']['XY'.search(x)],p=r?r[i]:v,i=$(p),o+='NA'.search(p))),o>0?1:2)
```
Takes in a string with the format given in the OP and returns *1* if candidate 1 won and *2* otherwise (I'll admit it, I'm even-biased).
]