[Question]
  [
Write a program or function that given *n ≥ 1* returns the number of solutions to ±1 ± 2 ± 3 ± ... ± n = 0.
For n = 6 there are no solutions, so the answer is 0. For n = 4 there are two solutions, so the answer is 2 (the two solutions are 1 - 2 - 3 + 4 = -1 + 2 + 3 - 4 = 0).
This is OEIS sequence [A063865](http://oeis.org/A063865). Some example input/outpus are:
```
n       a(n)
1       0
2       0
3       2
4       2
5       0
6       0
7       8
8       14
9       0
10      0
11      70
12      124
13      0
14      0
15      722
16      1314
```
---
Shortest code in bytes wins.
  
[Answer]
# JavaScript (ES6), 35 bytes
*Saved 1 byte thanks to @tsh*
```
f=(n,s)=>n--?f(n,n-~s)+f(n,n+~s):!s
```
[Try it online!](https://tio.run/##HcsxDkBAEEDR3ilGt5O1Eo0Cy1kEK0RmxIhGuPqaqP5r/tpfvQzHsp@OeJxiDN5QJuhbcq4LanKvoP1lVVUqMfBhCDwUNRA02lJhLcKdAAxMwtuUbzzrAzoiJk/8AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes
```
Count[{1,-1}~Tuples~#.Range@#,0]&
```
Counts the `n`-tuples of 1 and -1 whose dot product with `Range[n]` is 0.
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfOb80ryS62lBH17C2LqS0ICe1uE5ZLygxLz3VQVnHIFbtv0t@dEBRJlBRno6CkoKunYKSjkJadF5srI5CNVDI0Kw29j8A "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 42 bytes
```
f n=sum[1|0<-sum<$>mapM(\x->[x,-x])[1..n]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7a4NDfasMbARhfIsFGxy00s8NWIqdC1i67Q0a2I1Yw21NPLi439n5uYmWcLkczTtSsoLQkuKfLJ0yjOyC9XyNPWVlLQtVNQ0tYG8TWAxmpqgnUamsX@BwA "Haskell – Try It Online")
This is ~~2~~ 1 byte shorter than any recursive function that I could write.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
X®‚sã€ƶO_O
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/4tC6Rw2zig8vftS05tg2/3j///8tAA "05AB1E – Try It Online")
**Explanation**
```
X®‚          # push [1,-1]
   sã        # cartesian product with input
     €ƶ      # multiply each element in each list with its 1-based index
       O     # sum each list
        _    # logical negation of each sum
         O   # sum
```
[Answer]
# C (gcc), ~~45~~ ~~62~~ ~~52~~ 50 bytes
```
f(n,r){n=n?f(n-1,r+n)+f(n-1,r-n):!r;}F(n){f(n,0);}
```
Port of Kevin Cruijssen's Java 8 [answer](https://codegolf.stackexchange.com/a/161131/79343).
Try it online [here](https://tio.run/##LYqxCgIxEAXr5CvWA2GXJHBnaTzs7itsJBJJ4VOW60K@PUawmoGZFJ4p9Z4ZXqVixXVoWLw6iPtrgJwPGtvGkPo7Z4mtv@4FLFStyW/lgp0KrbTEgQud5kHnxBrz0dEyT8fHDZOnjYtItK1/AQ).
Note that due to the improvements suggested in the comments, the code produces undefined behaviour to the point of not working when compiled with clang.
Thanks to [etene](https://codegolf.stackexchange.com/users/79471/etene) for golfing 3 bytes.
Thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen) for golfing 10 more bytes.
Thanks to [Christoph](https://codegolf.stackexchange.com/users/29637/christoph) for golfing another 2 bytes.
Ungolfed version:
```
f(n, r) { // recursive function - return type and parameter type are omitted, they default to int
    n = // instead of returning, we set n - dirty trick
        n ? // if n is not 0, recurse
        f(n-1,r+n) // +n
       +f(n-1,r-n) // -n
        !r; // else if r != 0 return 0 else return 1
}
F(n) { // function to start the recursion; again implicitly int(int)
    n = f(n, 0); // call the recursive function; this time we simply don't return
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~9~~ 8 bytes
Thanks to **Emigna** for saving a byte!
### Code:
```
LæO·sLO¢
```
Uses the **05AB1E** encoding. [Try it online!](https://tio.run/##MzBNTDJM/f/f5/Ay/0Pbi338Dy36/98CAA "05AB1E – Try It Online")
### Explanation
```
L           # Create the list [1, 2, .., input]
 æ          # Compute the powerset of this list
  O         # Sum each list
   ·        # Double each element
    sLO     # Compute the sum of [1, 2, .., input]
       ¢    # Count the number of occurrences
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~14~~ 13 bytes
```
[la]Z^G:!Y*~s
```
*Thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe) for saving 1 byte!*
[Try it online!](https://tio.run/##y00syfn/PzonMTYqzt1KMVKrrvj/f0MzAA) Or [verify all test cases](https://tio.run/##y00syfmv5PA/OicxNirOwUoxUquu@P9/QytDMwA).
### Explanation
Consider `n = 3` as an example. Stack is shown upside down, that is, newest appears below.
```
[la]   % Push array [1 -1]
       % STACK: [1 -1]
Z^     % Cartesian power with inplicit input n
       % STACK: [ 1  1  1
                  1  1 -1
                  1 -1  1
                  1 -1 -1
                 -1  1  1
                 -1  1 -1
                 -1 -1  1
                 -1 -1 -1]
G:     % Push n, range: gives [1 2 ... n]
       % STACK: [ 1  1  1
                  1  1 -1
                  1 -1  1
                  1 -1 -1
                 -1  1  1
                 -1  1 -1
                 -1 -1  1
                 -1 -1 -1],
                 [1  2  3]
!      % Transpose
       % STACK: [ 1  1  1
                  1  1 -1
                  1 -1  1
                  1 -1 -1
                 -1  1  1
                 -1  1 -1
                 -1 -1  1
                 -1 -1 -1],
                 [1
                  2
                  3]
Y*     % Matrix multiplication
       % STACK: [6
                 0
                 2
                -4
                 4
                -2
                 0
                -6]
~      % Logical negation
       % STACK: [0
                 1
                 0
                 0
                 0
                 0
                 1
                 0]
s      % Sum of vector. Implicit display
       % STACK: 2
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
ŒPS€ċÆṁ$
```
[Try it online!](https://tio.run/##y0rNyan8///opIDgR01rjnQfbnu4s1Hlf9DRPYfbgQLu//8bmgEA "Jelly – Try It Online")
### How it works
```
ŒPS€ċÆṁ$  Main link. Argument: n
ŒP        Take the powerset of [1, ..., n].
  S€      Take the sum of each subset.
       $  Combine the two links to the left into a monadic chain.
     Æṁ       Compute the median of the sums, i.e, (1 + ... + n)/2.
    ċ         Count the occurrences of the median.
```
[Answer]
# Python 2, 74 bytes
```
def f(n):l=k=1;exec"l+=l<<n*k;k+=1;"*n;return(l>>n*n*-~n/4)%2**n*(~-n%4>1)
```
More of a fun submission, direct generating function computation.
[Answer]
# [Octave](https://www.gnu.org/software/octave/) (with Communications Package), 39 bytes
```
@(n)sum((2*de2bi(0:2^n-1)-1)*(1:n)'==0)
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999BI0@zuDRXQ8NIKyXVKClTw8DKKC5P11ATiLQ0DK3yNNVtbQ00/ycWFSVWppXmaaTpGFpZav4HAA "Octave – Try It Online")
### Explanation:
Take a range **0 ... n^2-1** and convert it to binary. This gives a matrix with all combinations of **0** and **1**. Multiply by **2** and subtract **1** to get a matrix with all combinations of **-1** and **+1**.
Take the dot-product with a range **1 ... n** to get all combinations of **±1 ± 2 ... ±n**. Count how many are zero.
Basically the same thing, same byte count:
```
@(n)nnz(~((2*de2bi(0:2^n-1)-1)*(1:n)'))
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~31~~ 22 bytes
*9 bytes saved thanks to @H.PWiz*
```
1⊥0=⊂∘⍳+.×¨∘,3-2×∘⍳⍴∘2
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R2wTDR11LDWwfdTU96pjxqHeztt7h6YdWANk6xrpGh6dDBB/1bgEyjIAaFIByvZsNDQA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# Python 2 and 3, 50 bytes
Recursive approach like most of the answers:
```
f=lambda n,r=0:f(n-1,r+n)+f(n-1,r-n)if n else r==0
```
[Try it online](https://tio.run/##LcZBCsIwEAXQq3y6ytApNLgQCrmJm4gZHai/ZczG08eNb/XOb38dvIxhZa/v@6OCGmXdLHHJGjNl/nehuIFo@6chSlmHHQGHE1H5bCkr8lU2nOHsyXW69UlhyUXGDw "Python 3 – Try It Online")
The double recursive call takes too much bytes... There's probably a way to simplify it.
[Answer]
# Java 8, ~~72~~ ~~71~~ 70 bytes
```
n->f(0,n)int f(int r,int n){return n>0?f(r+n,--n)+f(r+~n,n):r==0?1:0;}
```
Port of [*@Arnauld*'s JavaScript (ES6) answer](https://codegolf.stackexchange.com/a/161125/52210).  
-2 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##LU9Nb4MwDL3vVzz1lCiA4LIDLO0vWC89djtkNExpwVQhdKoq9teZk07yt5/t57O5mfx8uqxtb6YJ78bR4wVwFKzvTGuxj2kqoBXRkmy4srCy7EHQWCnfdqLMuBURXcL57Il@eBtmT6BtueuEV5TlOUkVw1/ikdprXe6qumyWFbjOX71rMQUT2N1Gd8LAnMQheEffx08jn3wiUQx8m@xPSkSiBXSjT@edrhq4N129slNKpiZwuE/BDsU4h@LKG0NPwqlN/RE2aiio4Bfl/3/L@gc)
**Explanation:**
```
n->                 // Method with integer parameter and integer return-type
  f(0,n)            //  Call the recursive method with 0 and this parameter
int f(int r,int n){ // Recursive method with integer as both two parameters and return-type
  return n>0?       //  If `n` is not 0 yet:
    f(r+n,--n)      //   Recursive call with `r+n` (and `n` lowered by 1 first with `--n`)
    +f(r+~n,n)      //   + Recursive call with `r-n` (and `n` also lowered by 1)
   :r==0?           //  Else-if `r` is 0
     1              //   Return 1
    :               //  Else:
     0;}            //   Return 0
```
[Answer]
# [Haskell](https://www.haskell.org/), 55 bytes
A straightforward approach of computing all those sums and checking how many are zero.
```
f 0=[0]
f n=[(n+),(n-)]>>=(<$>f(n-1))
g x=sum[1|0<-f x]
```
[Try it online!](https://tio.run/##Dco7DoAgDADQ3VN0cICopDhbLkIYHCwaoTF@Egbvjo4veet87UtKtTIgeQwNg5BX0uleyaCDc6Sm1vEPq3UTodD1ZG9fnAaGEmqeNwGC49zkhhbin701ZsRQPw "Haskell – Try It Online")
EDIT: @H.PWiz has a shorter and way more elegant solution using [`mapM`](https://codegolf.stackexchange.com/a/161132/24877)!
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + GNU utilities, 63 bytes
Bash can probably do better than this with recursive functions, but I can't resist this sort of `eval`/escape/expansion monstrosity:
```
p=eval\ printf\ %s
$p\\\\n \$[$($p \\\{+,-}{1..$1})]|grep -c ^0
```
[Try it online!](https://tio.run/##S0oszvifll@kUJJaXJKcWJyqkJmnUG2op2doVmutkJLPVZxaoqCrq6ACk/9fYJtalpgTo1BQlJlXkhajoFrMpVIQAwR5CjEq0SoaKgUKQE61to5uLcgcFcNazdia9KLUAgXdZIU4g/8p@Xmp/wE "Bash – Try It Online")
---
Update: I don't think bash can do better with recursive functions. [This is the best I could do for a score of 90](https://tio.run/##NYwxCsMwDAB3vUIFESTchCpDl5J@pGRIE5t0saD2luTtbl3odHAH95zSWoK9MfuU5yl5fEXctOv0etxwMUg@Y9si/TtwiQMpBJYNmEnvUaRpmJMbTtSfVWTf69DqyWELi2FAepA6HSt7MtLxq6OHAwIqXsDPqyGlIj9dPg). `eval` hell it is then.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 12 bytes
```
⟦₁{{ṅ|}ᵐ+0}ᶜ
```
[Try it online!](https://tio.run/##ASgA1/9icmFjaHlsb2cy///in6bigoF7e@G5hXx94bWQKzB94bac//8xNv9a "Brachylog – Try It Online")
### Explanation
```
⟦₁               The range [1, …, Input]
  {       }ᶜ     Count the number of times the following predicate succeeds on that range:
   {  }ᵐ           Map for each element of the range:
    ṅ                Negate
     |               Or do nothing
        +0         The sum of the elements after the map is 0
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 42 bytes
```
@(n)sum((dec2bin(0:2^n-1)*2-97)*(1:n)'==0)
```
[Try it online!](https://tio.run/##FchBCoAgEADAe6/w1q4UqIciQ@gfUWBl4KEtUoNebzTHOddoH5fzAIQhHQCbW9XiCYRWM9USuaq7FjlITVgaIzBHFyIzTGrZ9MXmwwXjXz2z923fPRFYChX7D6cS8wc "Octave – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 32 bytes
```
1#.0=1#.1+i.*"1[:<:@+:@#:[:i.2^]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DZX1DGyBhKF2pp6WkmG0lY2Vg7aVg7JVtFWmnlFc7H9NLq7U5Ix8hTQFQxjDCMYwhjFMYAxTGMMMxjCHMSxgDEu4gQZwFtxsQ7jhhnCzDOGGGRlw/QcA "J – Try It Online")
There is certainly much room for golfing. Exlpanation will follow.
[Answer]
# [Haskell](https://www.haskell.org/), 41 bytes
```
(%0)
n%k|n<1=0^k^2|m<-n-1=m%(k+n)+m%(k-n)
```
[Try it online!](https://tio.run/##FcVLCoAgFADAfadwoaCEkUE77SJ9QCRL1Idky87ei2Yzp61xTwm9WZCzXjTA4gNamX6L2/BkLUEqkxmPLYj2X4LAbAMQQ8oV4CaUeE2nWXWdGld8nU/2qChdKR8 "Haskell – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
RżN$ŒpS€ċ0
```
[Try it online!](https://tio.run/##y0rNyan8/z/o6B4/laOTCoIfNa050m3w/1Hj1sPtQPZ/AA "Jelly – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), `-p` 35 bytes
```
#!/usr/bin/perl -p
$_=grep!eval,glob join"{+,-}",0..$_
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3ja9KLVAMbUsMUcnPSc/SSErPzNPqVpbR7dWScdAT08l/v9/i3/5BSWZ@XnF/3UL/uv6muoZGugZAgA "Perl 5 – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 30 bytes
```
n->Pol(prod(i=1,n,x^i+x^-i))%x
```
[Try it online!](https://tio.run/##DcgxCoAwDADArwRBSDAZuri1b/AFBUEqAUlDcejvo8sN5@dQuT0a5DApR3/QR79Qc2LjWXWbVZRondH6QIMMiSHtDD7U3j8WkPLT0IgoPg "Pari/GP – Try It Online")
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 99 bytes
```
p(0,0,1).
p(0,_,0).
p(X,Y,Z):-A is X-1,B is Y+X,p(A,B,C),D is Y-X,p(A,D,E),Z is C+E.
X*Y:-p(X,0,Y).
```
[Try it online!](https://tio.run/##Jcw7DoAgEEXRnlVQOviGgKUdfvYw2FgaExOJFC4fA3Y3p7jpua/74PyepaTOwcGTVbV2uFaCiI1GDvrMWthjqhF7QeoCJsyEpQn/smAlbFXmfrVKTBy5Xhwi2VL8YMR@ "Prolog (SWI) – Try It Online")
[Answer]
# Pyth, ~~14~~ 13 bytes
```
lf!s.nT*F_BRS
```
[Try it here](http://pyth.herokuapp.com/?code=lf%21s.nT%2aF_BRS&input=12&debug=0)
### Explanation
```
lf!s.nT*F_BRS
            SQ  Take the list [1, ..., <implicit input>].
         _BR    Get the pairs [[1, -1], [2, -2], ...].
       *F       Take the Cartesian product.
 f!s.nT         Find the ones where the flattened sum is 0.
l               Take the length.
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 25 bytes
```
ri,:)_Wf*:a.+:m*:e_1fb0e=
```
[Try it online!](https://tio.run/##S85KzP3/vyhTx0ozPjxNyypRT9sqV8sqNd4wLckg1fb/f0NTAA "CJam – Try It Online")
This is a fairly direct translation of @emigna's 05AB1E solution. It's certainly golfable.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 9 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
è%é┐╬@₧╠¬
```
[Run and debug it](https://staxlang.xyz/#p=8a2582bfce409eccaa&i=1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16&a=1&m=2)
 ~~One of the shortest answers so far~~  defeated by Jelly.
I feel that checking explicitly which signs sum to zero is not very golfy, so instead I take the powerset and check how many sets in the powerset have the sum of half the nth triangular number. This method is, not surprisingly, of the same time complexity as checking which signs sum to zero.
ASCII equivalent:
```
RS{|+Hmx|+#
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
/mysdySQsS
```
[Try it online.](http://pyth.herokuapp.com/?code=%2FmysdySQsS&input=8&debug=0) Alternatively, [verify all test cases at once](http://pyth.herokuapp.com/?code=Q%0A%2FmysdySQsS&input=8&test_suite=1&test_suite_input=1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16&debug=0).
Explaination:
```
/mysdySQsS    Implicit: Q=input()
      SQ      Generate range [1...Q]
     y        Generate powerset of above
 m            Map d in the above over...
  ysd         ... double the sum of d
        sS    Sum of range [1...Q] (final Q is implicit)
/             Count the matches (implicit output)
```
[Answer]
# [J](http://jsoftware.com/), 28 bytes
```
(*>:){1j3#1+//.@(*/)/@,.=@i.
```
Uses the other definition from OEIS where `a(n) = coefficient of x^(n(n+1)/4) in Product_{k=1..n} (1+x^k) if n = 0 or 3 mod 4 else a(n) = 0`.
[Try it online!](https://tio.run/##FcqxCoAgFAXQ3a@41KDP5KkEDYLiv0SSLg2O0bdbDWc7bZSOGODwGUqnQLdv6@wXazkrbclmwzFXHiQmhiz/ljB4AkoX4tjPC8pwmRwhBVSG38YL "J – Try It Online")
## Explanation
```
(*>:){1j3#1+//.@(*/)/@,.=@i.  Input: n
                          i.  Range [0, n)
                        =     Self-Classify. Forms an identity matrix of order n
          1           ,.      Stitch. Prepend 1 to each row
                    /         Reduce using
                                Convolution
                 */               Product table
           +//.                   Sum along anti-diagonals
      1j3#                    Copy each once, padding with 3 zeroes after
     {                        Index at n*(n+1)
  >:                            Increment n
 *                              Times n
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
#½Σḣ¹mΣṖḣ
```
[Try it online!](https://tio.run/##yygtzv7/X/nQ3nOLH@5YfGhnLpDeOQ3I/P//v6EZAA "Husk – Try It Online")
### Explanation
```
#½Σḣ¹mΣṖḣ  Implicit input
        ḣ  [1..input]
       Ṗ   Powerset
     mΣ    Sum each list
#          Count occurrence of
   ḣ¹        [1..input]
 ½Σ          Half of sum
```
[Answer]
# [Gol><>](https://github.com/Sp3000/Golfish), 26 bytes
```
:IFPlMF2K+}:@-}||0lMF$z+|h
```
[Try it online!](https://tio.run/##S8/PScsszvj/38rTLSDH183IW7vWykG3tqbGAMhTqdKuAcoZmgIA "Gol><> – Try It Online") or [Run test cases from 1 to 16!](https://tio.run/##S8/PScsszvhv6BipEIkGrLmsPN0CcnzdjLy1a60cdGtragyAPJUq7Ro/p/845TL@/zfkMuIy5jLhMuUy4zLnsuCy5DI04DI05DI04jI05jI04TI05TI0AwA "Gol><> – Try It Online")
### How it works
```
:IFPlMF2K+}:@-}||0lMF$z+|h
Main outer loop
:IFPlMF ...... ||
:        Duplicate top; effectively generate two explicit zeroes
         Top is the loop counter `i`;
         the rest is the generated 2**i sums
 I       Take input as number
  F ........... |  Pop n and loop n times
   P     i++
    lM   Push stack length - 1, which is 2**(i-1)
      F ...... |   Loop 2**(i-1) times
Main inner loop: generate +i and -i from 2**(i-1) previous sums
2K+}:@-}
          Stack: [... x i]
2K        [... x i x i]    Copy top two
  +}      [x+i ... x i]    Add top two and move to the bottom
    :@    [x+i ... i i x]  Duplicate top and rotate top 3
      -}  [i-x x+i ... i]  Subtract and move to the bottom
Counting zeroes
0lMF$z+|h
0lM        Push zero (zero count) and 2**n (loop count)
   F...|   Loop 2**n times
    $z+    Swap top two; Take logical not; add to the count
        h  Print top as number and halt
```
]