[Question]
  [
Here the first 100 numbers of an easy sequence:
```
0,1,0,2,1,4,3,7,6,11,10,16,15,22,21,29,28,37,36,46,45,56,55,67,66,79,78,92,91,106,105,121,120,137,136,154,153,172,171,191,190,211,210,232,231,254,253,277,276,301,300,326,325,352,351,379,378,407,406,436,435,466,465,497,496,529,528,562,561,596,595,631,630,667,666,704,703,742,741,781,780,821,820,862,861,904,903,947,946,991,990,1036,1035,1082,1081,1129,1128,1177,1176,1226
```
**How does this sequence work?**
```
n: 0 1     2           3     4     5     6     7     8      9       10      11      12
   0,      1-1=0,      2-1=1,      4-1=3,      7-1=6,       11-1=10,        16-1=15,      
     0+1=1,      0+2=2,      1+3=4,      3+4=7,      6+5=11,        10+6=16,        15+7=22
```
* `a(0) = 0`
* For every odd `n` (0-indexed), it's `a(n-1) + X` (where `X=1` and increases by 1 every time it's accessed)
* For every even `n` (0-indexed), it's `a(n-1) - 1`
## Challenge:
One of:
* Given an input integer `n`, output the `n`'th number in the sequence.
* Given an input integer `n`, output the first `n` numbers of the sequence.
* Output the sequence indefinitely without taking an input ([or taking an empty unused input](https://codegolf.meta.stackexchange.com/questions/12681/are-we-allowed-to-use-empty-input-we-wont-use-when-no-input-is-asked-regarding)).
## Challenge rules:
* Input `n` can be both 0- or 1-indexed.
* If you output (part of) the sequence, you can use a list/array, print to STDOUT with any delimiter (space, comma, newline, etc.). Your call.
* Please state which of the three options you've used in your answer.
* You'll have to support at least the first 10,000 numbers (10,000th number is `12,497,501`).
## General rules:
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.  
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* [Standard rules apply](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code.
* Also, please add an explanation if possible.
## Test cases:
[Pastebin with the first 10,001 numbers in the sequence.](https://pastebin.com/JX6g4Nky) Feel free to pick any you'd like.
Some higher numbers:
```
n (0-indexed)    Output:
68,690           589,772,340
100,000          1,249,975,000
162,207          3,288,888,857
453,271          25,681,824,931
888,888          98,765,012,346
1,000,000        124,999,750,000
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~32~~ ~~28~~ 25 bytes
```
lambda n:(~-n|1)**2/8+n%2
```
[Try it online!](https://tio.run/##Xc5BCsIwEIXhvacIiNBUxJlJk5kI3sRNRYqCxiLdCOLVY2wxDb5VCF/C3z@H8z1Q7PaHeG1vx1Orwq56b8ILdV3TVtZhRbF/XMKgusqAXvzOTpwHvVTzrHhmMg1kg/BdiZAa79mm2xk5IuASGZJxljNqrCHGEpF1gpK@M5jV9KxUXthZwFTl/qrKrLFqyoL4AQ "Python 2 – Try It Online")
Returns the `n`-th number (`0`-indexed)
[Answer]
# Excel, 31 bytes
Answer is `0` indexed. Outputs the `n`the number.
```
=(A1^2+IF(ISODD(A1),7,-2*A1))/8
```
The sequence described is ultimately just two sequences interlaced:
```
ODD:   (x^2+x+2)/2
EVEN:  (x^2-x)/2
```
Interlacing these into one `0` indexed sequence gives:
```
a = (x^2 - 2x)/8 if even
a = (x^2 + 7 )/8 if odd
```
Which gives:
```
=IF(ISODD(A1),(A1^2+7)/8,(A1^2-2*A1)/8)
```
which we golf down to the `31` bytes.
---
Using the same approach, `1` indexed gives `37` bytes:
```
=(A1^2-IF(ISODD(A1),4*A1-3,2*A1-8))/8
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
Rj-ḣ⁸S
```
[Try it online!](https://tio.run/##y0rNyan8/z8oS/fhjsWPGncE////39AADAA "Jelly – Try It Online")
0-indexed. Returns `n`th number.
Explanation:
```
Rj-ḣ⁸S Arguments: z
R      [1..x]: z (implicit)
 j-    Join x with y: ^, -1
   ḣ⁸  Take first y of x: ^, z
     S Sum: ^
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 23 bytes
```
x=>(7+(x-2|1)**2)/8-x%2
```
1-indexed. [Try it online!](https://tio.run/##bcxBDoIwEEDRvafoxqTFVGamQFsT3HkQUorREEqEmC68e43sALc/L//ZvJvJvR7jLIfQ@tTVKdZXrk88SvqgyDISuZHxSMmFYQq9P/fhzjuuUIjDOllNJARjLM/ZLY7ezb69MESDRAo3GAEAf3qNqbC6BNjgylR2j0tjtSZVwJ/18t6tlzekLw "JavaScript (Node.js) – Try It Online")
```
f(x) = f(x+1) + 1 if x is even
     = SUM{1..(x-3)/2} if x is odd
SUM{1..(x-3)/2}
= (1+(x-3)/2)*((x-3)/2)/2
= (x-1)*(x-3)/8
= ((x-2)^2-1)/8
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~40 38~~ 37 bytes
```
scanl(flip($))0$[1..]>>=(:[pred]).(+)
```
Returns an infinite list, [try it online!](https://tio.run/##DcpBCoAgEADAr3josBJJXYP6QS8wicW0pE0W7f1tzXlOrFcgElSTWqV6zASREkOjdd/YwRg3zxOMlkvYnTbQarkx5b/fyMumuKT8KJTXR8KjSueZPw "Haskell – Try It Online")
### Explanation
`scanl` takes three arguments `f`, `init` and `xs` (**[** *x0*, *x1* ... **]**) and builds a new list:
**[** *a0 = init*, *a1 = f(a0,x0)*, *a2 = f(a1, x1)* ... **]**
We set `init = 0` and use the flipped `($)` application operator (thus it applies *ai* to the function *xi*), now we only need a list of functions - the list `[1..]>>=(:[pred]).(+)` is an infinite list with the right functions:
```
[(+1),(-1),(+2),(-1),(+3),(-1),(+4),...
```
### Interesting alternative, 37 bytes
`flip` having the type `(a -> b -> c) -> b -> a -> c` we could also use `id :: d -> d` instead of `($)` because of Haskell's type inference the type `d` would be unified with `a -> b`, giving us the same.
[Try it online!](https://tio.run/##y0gszk7NyfmfqGCrEPO/ODkxL0cjLSezQCEzRdNAJdpQTy/Wzs5Wwyq6oCg1JVZTT0Nb839uYmYeUHluYoFvvEJBUWZeiULi/3/JaTmJ6cX/dZMLCgA "Haskell – Try It Online")
**Edit**
-2 bytes by using `(>>=)` instead of `do`-notation.
-1 byte by using `scanl` instead of `zipWith`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
HḶS‘_Ḃ
```
A monadic link accepting (1-indexed) `n` which returns `a(n)`.
**[Try it online!](https://tio.run/##y0rNyan8/9/j4Y5twY8aZsQ/3NH0//9/QyMA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8/9/j4Y5twY8aZsQ/3NH0/@iew@2Pmta4//8fbWZhZmmoY2gABEDKzMjIwELHxNTYyNxIxwIELCFyBoax2jmZxSUaRYl56akaIB2GmpoA "Jelly – Try It Online")
### How?
```
HḶS‘_Ḃ - link: n
H      - halve         -> n/2.0
 Ḷ     - lowered range -> [0,1,2,...,floor(n/2.0)-1]
  S    - sum           -> TriangleNumber(floor(n/2.0)-1)
   ‘   - increment     -> TriangleNumber(floor(n/2.0)-1)+1
     Ḃ - bit = 1 if n is odd, 0 if it's even
    _  - subtract      -> TriangleNumber(floor(n/2.0)-1)+isEven(n)
```
[Answer]
# [Haskell](https://www.haskell.org/), 25 bytes
```
scanl(+)0$(:[-1])=<<[1..]
```
[Try it online!](https://tio.run/##y0gszk7NyfmfYxvzvzg5MS9HQ1vTQEXDKlrXMFbT1sYm2lBPL/Z/bmJmnoKtQkFRZl6JQs7/f8lpOYnpxf91kwsKAA "Haskell – Try It Online")
Constructs an infinite list.
---
**[Haskell](https://www.haskell.org/), 27 bytes**
```
0:0%1
a%d=a+1:a:(a+d)%(d+1)
```
[Try it online!](https://tio.run/##y0gszk7NyfmfYxvz38DKQNWQK1E1xTZR29Aq0UojUTtFU1UjRdtQ839uYmaegq1CQVFmXolCzv9/yWk5ienF/3WTCwoA "Haskell – Try It Online")
**[Haskell](https://www.haskell.org/), 30 bytes**
```
0:do a<-scanl(+)0[1..];[a+1,a]
```
[Try it online!](https://tio.run/##y0gszk7NyfmfYxvz38AqJV8h0Ua3ODkxL0dDW9Mg2lBPL9Y6OlHbUCcx9n9uYmaegq1CQVFmXolCzv9/yWk5ienF/3WTCwoA "Haskell – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
ÎF<NÈi¼¾>+
```
[Try it online!](https://tio.run/##MzBNTDJM/f//cJ@bjd/hjsxDew7ts9P@/9/MwszSAAA "05AB1E – Try It Online")
**Explanation**
```
Î             # initialize stack with: 0, input
 F            # for N in [0 ... input-1] do:
  <           # decrement the current number
   NÈi        # if N is even
      ¼       # increment a counter
       ¾>     # push counter+1
         +    # add to current number
```
Another 10-byter: `ÎFNÈN;Ì*<O`
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 32 bytes
```
@(x)fix((x-~(m=mod(x,2)))^2/8)+m
```
[Try it online!](https://tio.run/##Zc1LCsIwFIXheVeRiZCLWnNv2zyEghO3IZS2kYIxIkUycusxbXFgPeOf7/h2bF59tHWe5/HEA9ghcB72b@5q5zsedgQAFzpo2Lpo/dM1I7v5@zWzXGppBLBpG3YOj74d@@7IKm2UoqIUKTGKaCl@EkSNRAWmAkXaP4JUGlWJydDzYF0YrWQlMB3JL7NAa2Z2RBY/ "Octave – Try It Online")
Outputs the n-th number, 0-indexed. Uses the same formula as several other answers.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~16~~ 12 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function. 0-indexed.
```
+/⊢↑∘∊¯1,¨⍨⍳
```
[Try it online!](https://tio.run/##Vc6xasMwEAbgvU/hvReqO1nSac6STAlxXsBQ3MXQrp0LIRhskiGQJUumbBn8Bn6UexH3FEipf05a9In7y6969v5d1p8fo3Sn9Vp2Bwzj65s0V9kdZX@WfTPcEYabtDr9WKmQtlO8XEnzM9xtct2p2Mz13i6WxVgl3CO9VJlnH032jLSXLHMcIQQCmxsFaFImAIHyCDE40JdEPJEJE2KBmIHTcUFJ7iwFnBBy4BmBKYdoUQ0/MjGRIXhdg6mN/2tj/hlM/6M2dibV@QU "APL (Dyalog Unicode) – Try It Online")
`+/` the sum of
`⊢↑` the first `n` elements
`∘∊` of the **ϵ**nlisted (flattened)
`¯1,¨⍨` negative-one-appended-to-each
`⍳` first `n` **ɩ**ndices (0 through `n`–1
[Answer]
# [PHP](http://php.net/), ~~73~~ ~~64~~ ~~55~~ ~~51~~ 47 bytes
# First method
First code golf answer!  
I'm sure there's PHP tricks to make it shorter and the maths can probably be improved.
Takes n as the first argument and outputs the nth number in the sequence.
```
$y=$argv[1]/2;for(;$i<$y+1;)$x+=$i++;echo$x-($y|0);
```
Minus 9 bytes by removing "$x=0;" and "$i=0".
Minus 9 bytes thanks to @Kevin Cruijssen improving the for loop and loss of the end tag.
Minus 1 byte using bitwise or "|" rather than "(int)"
Minus 3 bytes thanks to @Dennis as you can remove the tags by running it from the command line with "php -r 'code here'"
[Try it online!](https://tio.run/##DcRJCoAwDADAz@SgFHG5SSw@wQeIiLi1lybUIi34dqNzGDYsXc//kDQs/rzHeiobPMhnCLaDpGrMISoNVincV0MQiwzSU@UoIu3vJQ6W3CXFdhnyYSbe3RyWUw/uAw "PHP – Try It Online")
# Second method
Matched my previous answer with a whole new method!
```
for(;$i<$argv[1];$i++)$x+=($y^=1)?$i/2+1:-1;echo$x;
```
Using XOR and the tenary operator to switch between sums in the loop.
Edit: This doesn't work for n=0 and I have no idea why. $i isn't assigned so therefore it should be 0, therefore the loop `($i<$argv[1])` should fail as `(0<0==false)`, therefore a non assigned $x should output as 0 and not 1.
[Try it online!](https://tio.run/##DcZBCoAgEEDRy8zCkAjblUlH6ABREWXpxhlMoi7f5F88PjnirqfsgVFo8B2s8bxHNeWXsoBHGgHvbFTRg69qqdpSabs5hEczc5P7kJLHcHG5Xw5jWpBsWNJ6miH8 "PHP – Try It Online")
# Third method
Converting the excel formula @Wernisch created to PHP gives a 47 byte solution
```
$z=$argv[1];echo(pow($z,2)+(($z&1)?7:-2*$z))/8;
```
[Try it online!](https://tio.run/##K8go@G9jXwAkVapsVRKL0suiDWOtU5Mz8jUK8ss1VKp0jDS1NYC0mqGmvbmVrpGWSpWmpr6F9f///y2B4F9@QUlmfl7xf92U4oz8opL4/ILUvPiSxHRb/zwA "PHP – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 35 bytes
```
diffinv(rbind(n<-1:scan(),-1)[n-1])
```
[Try it online!](https://tio.run/##K/r/PyUzLS0zr0yjKCkzL0Ujz0bX0Ko4OTFPQ1NH11AzOk/XMFbzv6HBfwA "R – Try It Online")
I thought this was an interesting alternative to [@JayCe's answer](https://codegolf.stackexchange.com/a/165853/67312) since it doesn't port very well to languages without built-in support for matrices, and happens to be just as golfy.
1-indexed, returns the first `n` elements of the sequence.
### How it works:
`rbind(n<-1:scan(),-1)` constructs the following matrix:
```
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]   -1   -1   -1   -1
```
Because R holds matrices in column-major order, if we were to convert this to a `vector`, we would obtain a vector
```
1 -1 2 -1 3 -1 4 -1
```
which if we take a cumulative sum of, we would get
```
1 0 2 1 4 3 7 6
```
which is the sequence, just without the leading `0`. `diffinv` fortunately adds the leading zero, so we take the first `n-1` values from the matrix and `diffinv` them, obtaining the first `n` values of the sequence.
[Answer]
# [R](https://www.r-project.org/), ~~35~~ 34 bytes
```
(u=(n=scan())-n%%2-1)-n+(15+u^2)/8
```
[Try it online!](https://tio.run/##K/r/X6PUViPPtjg5MU9DU1M3T1XVSNcQSGtrGJpql8YZaepb/Dc0@Q8A "R – Try It Online")
First output option.Same formula as many other answers (I'd like to point to the first answer providing the formula, I can't figure which it is).
Second and third output options below:
### [R](https://www.r-project.org/), 43 bytes
```
function(m,n=1:m,u=n%%2+1)((n-u)^2-1)/8+2-u
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jVyfP1tAqV6fUNk9V1UjbUFNDI0@3VDPOSNdQU99C20i39H@ahpGh5n8A "R – Try It Online")
### [R](https://www.r-project.org/), 51 bytes
```
while(T){cat(((T-(u=T%%2+1))^2-1)/8+2-u," ");T=T+1}
```
[Try it online!](https://tio.run/##K/r/vzwjMydVI0SzOjmxRENDI0RXo9Q2RFXVSNtQUzPOSNdQU99C20i3VEdJQUnTOsQ2RNuw9r@R4X8A "R – Try It Online")
[Answer]
# Matlab/Octave, ~~31~~ 26 bytes
5 bytes saved thx to Luis Mendo!
```
@(n)sum(1:n/2+.5)-fix(n/2)
```
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 20 bytes
```
x->x%2+(x=~-x|1)*x/8
```
[Try it online!](https://tio.run/##ZY29jsIwEIT7PMU2JzlEMT/VSSFIlBSIAlGdKPYCQRsc27I3yBEHrx4cTlddsfq0M6OZBm@YN6frQK01jqGJv@yYlJwUyT@t7nTFZPRoVgq9hy2ShnsCYLtvRRV4Ro64GTpBGz2xZ0f68nUEdBefvqMAG80Hja7f2bNDNg7qcgj5KnwsMhHKZx5@5ukkTD@H4h2vjROkGQhKmBURS1iMzLK/QoB97/ncStOxtHGRlRa1RGtVv/ZxTlCa/pY9kvEewws "Java (JDK 10) – Try It Online")
Port of [TFeld's Python 2 anwser](https://codegolf.stackexchange.com/a/165792/16236), so go give them an upvote! ;)
[Answer]
# [Dodos](https://github.com/DennisMitchell/dodos), 69 bytes
```
	. w
w
	. h
	+ r . ' dab h '
h
	h ' '
	. dab
r
	
	r dip
.
	dot
'
	dip
```
[Try it online!](https://tio.run/##NY69DsIwDITn@CluKAoI9YeO0Ik3aeNUyRKXNKhC4t2LpYrFd/5Osm8a17AvOaYywz4/xTt5p3KHJTcWDAOsl9nii@BHRu3qm/riPZywV7s5hbtpsNFGKoHMFRkNLHicEPSQIhU1GiujTIZMBseFGjIshTTSbddPRLNkRMSE6rz6Fzr03eUBFgL@NU89QxuiigpbWUrLwrIe8yimEUvy@w8 "Dodos (with Bash wrapper) – Try It Online")
---
Somehow this is the longest answer.
Explanation.
```
┌────┬─────────────────────────────────────────────────┐
│Name│Function                                         │
├────┼─────────────────────────────────────────────────┤
│.   │Alias for "dot", computes the sum.               │
├────┼─────────────────────────────────────────────────┤
│'   │Alias for "dip".                                 │
├────┼─────────────────────────────────────────────────┤
│r   │Range from 0 to n, reversed.                     │
├────┼─────────────────────────────────────────────────┤
│h   │Halve - return (n mod 2) followed by (n/2) zeros.│
└────┴─────────────────────────────────────────────────┘
```
[Answer]
# [QBasic 1.1](http://www.qbasic.net/), 49 bytes
```
INPUT N
R=1
FOR I=1TO N\2-1
R=R+I
NEXT
?R-N MOD 2
```
1-indexed.
[Answer]
# [QBasic 1.1](http://www.qbasic.net/), 30 bytes
```
INPUT N
?(N-1OR 1)^2\8+N MOD 2
```
Uses TFeld's algorithm. 0-indexed.
[Answer]
# QBasic, 31 bytes
The just-implement-the-spec solution comes in slightly longer than [Erik's solution](https://codegolf.stackexchange.com/a/166168/16766).
```
DO
?n
i=i+1
n=n+i
?n
n=n-1
LOOP
```
This outputs indefinitely. For purposes of running it, I recommend changing the last line to something like `LOOP WHILE INPUT$(1) <> "q"`, which will wait for a keypress after every second sequence entry and exit if the key pressed is `q`.
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 56 bytes
```
n=>{int a=0,i=0;for(;++i<n;)a+=i%2<1?-1:i/2+1;return a;}
```
*-2 bytes thanks to Kevin Crujssen*
[Try it online!](https://tio.run/##bVNNa9tAED1bv2IwLUhonO6uviMrpRRySqG0hx5CDoq8ThaUVZDkNkXot7tvbceEUPDsx@zMvPc042ZYNV2v901bDwN977uHvn6iyRvGejQN/fw7jPrp4npnm7WxI8OuaEsV7W11NeFGdSXYVKLcdr1fhqFZ2zKow8p8VGv5eSUvzScVyrLX4663VJfzvvS85919i@InjN@d2dC32lg/mLwFat7eETj1uhl/6GHXjgPwrP5DhydvMQmWLFhhjTnijFOWkiW8OCSsFCvJqmCVc5RxlHKMX8JJyknCKcJTzgrOci4UFy4RaSJhiSypUAVJMnKlYljEMgNShjcXWwAXYApoKgJQhDPiFOJUlsFSjoSECY4UzirhKFEw@AAaATUWGQyUHLMoATvHEHsBfwGSoJ6Ae5IqmOTE@QowB1YaCdB3EqBBxDDojxVMQpAzwTl05NCRIz9HfoG4AnFFnMFSLqCjgA4pnEgBBlLkyi3QJwGOJccCOVgQotRhSWZ0buHa7Npu0BNRYlu/69XFjbYP4yOewjDAIC0WX4ZB96NvQsnvYm/NXVB6i9mb/zsTr4mAs@y6T/rlGdl6A/CVDDw3Llvyz941iQDzAcw3gQIIbqroBRfpLtBAZxHyKMIeCePVpR/KYoSpQv5RxZuaq1MdEHfudtBufxcUVvQShuew2ck8TDfVzbirW0BvfRu4b3rfdS31h08C7@tzdVbrYk5/xK@dHbpWX/zqzahvjNX@h@U15Bj7vBtpsvMlTa9pM9V2Q9Ox3kxLCsk/oXym5VM9No9LuqTlpiPbjXR0BGCEfuwfddt2/wA "C# (.NET Core) – Try It Online")
1 indexed. Returns `a(n)`
Ungolf'd:
```
int f(int n)
{
    // a needs to be outside the for loop's scope,
    // and it's golfier to also define i here
    int a = 0, i = 1;
    // basic for loop, no initializer because we already defined i
    for (; ++i < n;)
    {
        if (i%2 < 1) {
            // if i is even, subtract 1
            a -= 1;
        }
        else
        {
            // if i is odd, add (i / 2) + 1
            // this lets us handle X without defining another int
            a += i / 2 + 1;
        }
    }
    // a is the number at index n
    return a;
}
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~11~~ ~~9~~ 8 bytes
```
ΘṁṠe→Θ∫N
```
Saved a byte thanks to H.PWiz.  
Outputs as an infinite list.  
[Try it online!](https://tio.run/##ARoA5f9odXNr///OmOG5geG5oGXihpLOmOKIq07//w "Husk – Try It Online")
### Explanation
```
ΘṁṠe→Θ∫N
      ∫N   Cumulative sum of natural numbers (triangular numbers).
     Θ     Prepend 0.
 ṁṠe→      Concatenate [n + 1, n] for each.
Θ          Prepend 0.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
Return the first `n` numbers.
```
Rj-ÄŻḣ
```
[Try it online!](https://tio.run/##y0rNyan8/z8oS/dwy9HdD3cs/v//v6EBAA "Jelly – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 15 bytes
```
Ｉ∨ΣＥＮ⎇﹪ι²±¹⊕⊘ι⁰
```
[Try it online!](https://tio.run/##DYhBCgIxDEWv0mUGKqg7cenGWcwo6AViJ2ihTYeYDnj6mLf47/PSByU1LGZ3yaxwwa/CTeDRK0y4wshr17nXFwkMMTxJGOUHU1t6aZBjOHqd6Y1KcPA7chKqxEoLXLFsrjw4Mex9z2Ynx3Zb@QM "Charcoal – Try It Online") 0-indexed. Link is to verbose version of code. The formula would probably be shorter, but what's the fun in that? Explanation:
```
    Ｎ           Input as a number
   Ｅ            Map over implicit range
     ⎇          Ternary
      ﹪ι²       Current value modulo 2
         ±¹     If true (odd) then -1
           ⊕⊘ι  Otherwise calculate X as i/2+1
  Σ             Take the sum
 ∨            ⁰ If the sum is empty then use zero
Ｉ               Cast to string and implicitly print
```
[Answer]
# JavaScript, ~~49~~ ~~48~~ 45 bytes
```
x=>eval('for(i=0,r=1;++i<x+2;)r+=i%2?-1:i/2')
```
[Try it online!](https://tio.run/##dcxLDsIgFEDRufswhWAtPJXWVnQtpIJ5iqUB09TV42dmiHd4BveqJx37gOOjjCOeTbj74Waeyao0q6OZtCOF9YGg4qugRMcYHmYGHQ1M4RJOpWixgoKm3g/RO7N2/kIskY3cc0oXvyr4p5wlAK8z3u42UIuMm29/3u95egE)
Not as pretty as @tsh answer, but mine works for bigger numbers.
And now thanks @tsh, for the `eval` solution !
[Answer]
# Befunge 93, 26 bytes
```
<v0p030
 >:.130g+:30p+:.1-
```
Runs indefinitely  
[Try it online](https://tio.run/##S0pNK81LT/3/36bMoMDA2IBLwc5Kz9DYIF3bytigQBvI1v3/HwA "Befunge-93 – Try It Online"), though output gets a little wonky and goes back down after x=256, presumably TIO can't handle characters above U+256. Works fine at <https://www.bedroomlan.org/tools/befunge-playground> (Chrome only, unfortunately. With Firefox, endlines get removed at runtime, for some reason...)
[Answer]
# [J](http://jsoftware.com/), 17 bytes
```
1#.[{._1,@,.~1+i.
```
A port of Adám's APL solution.
[Try it online!](https://tio.run/##Vc9NCgIxDAXg/Zwi6GIQQ2jSv3RAEA/gBVy4EAd142KWolevrTJiH3SVj@bllsdpQ2BgAJN5SYcHHRm3SC9eXymvugVBP26oB4TnAOPUdefT5Q4jBA3JQMl@R/CN14QxClpnZsWmplGM4hKm6LFMfi6ImNg4i6KKWp@Ps3PeSuTGicegjCoOk@UZ6icNTIoxlK1cG4a2ofmDXH9K5RRvasX8Bg "J – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 8 bytes
```
s<s,R_1S
```
Returns `n`th number in the sequence, 0-indexed. [Try it online](https://pyth.herokuapp.com/?code=s%3Cs%2CR_1S&test_suite=1&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A9999&debug=0)
Explanation, with example for `n=5`:
```
s<s,R_1SQQ   Final 2 Q's are implicit, Q=eval(input())
       SQ    1-indexed range        [1,2,3,4,5]
   ,R_1      Map each to [n,-1]     [[1,-1],[2,-1],[3,-1],[4,-1],[5,-1]]
  s          Sum (Flatten)          [1,-1,2,-1,3,-1,4,-1,5,-1]
 <       Q   Take 1st Q             [1,-1,2,-1,3]
s            Sum, implicit output   4
```
[Answer]
# [Perl 6](https://perl6.org), ~~38~~ 26 bytes
```
{(0,{$_+(($+^=1)??++$ !!-1)}...*)[$_]}
```
[Try it](https://tio.run/##VZBBT9wwEIXv@RUPEYjDBitZIKRabemhlXriygFBZJIBTB072E7parW/fbEDqsTBmif7m@c3M5JV9X5yhL8171ZJMmxw3JmesN5vWVls03bBWLq4X1f51dVikeLg4LTKd5zzk/w2be92eyc2iB2s5Lwqy5y/GKlZVmR5sBsnz2J10wOE2@jutJduVKGFpW2ObQIcQnp0QsOLPwQBZfQTvBwI3uCJNFnhg34mOHqdSHc0NzmDN4KddPDFIPQm1tE4Jx8UQWqMwgqlSCUBHyf3DOej0Y/RmkE6ckW8sB4xP38cPMuOmj7LC2RYf0dWgM@L@Hyqzvt5oPj1EIO6yX6kCn4dOYfekNOZB/0L80zaSxWfQ6zAhSCBk9pTHxx@Xf@EeBMB@x9mleyShB9/XdGjsWCBB@qmrb@VRdRhxW1Zfup62S7Ly1mfX5y1y8tq1k3TtOEEXUX2g89X@9@klMGNsap/Bw "Perl 6 – Try It Online")
```
{(+^-$_+|1)**2 div 8+$_%2}
```
Based on reverse engineering TFeld's [Python answer](https://codegolf.stackexchange.com/questions/165791/x-steps-forward-1-step-back/165792#165792).  
[Try it](https://tio.run/##NY5BbsIwEEX3PsVfBGyT1LJdMK4QXfcG3dUCHCQqB0cJQUKUs6d2ShejedL8/zRt3QUzDn2NqxGHDSHNDfND9DW2452VXy@FK38UXyw0/OkKWxZuph9jv7uBSSGUlFw0u5ZNHS6@4@nMaEV5MrXDheXdD/vU7duQO4XjuBMgC8SxuTA6s57yChTbd9AKYjI9T2rps@pBiJj/K46xA0sGwFhn3mSVOf3hpHyy0U7L9cTL1avTazWxtdalSaxy9i/PN@NHHULEZ@yC/wU "Perl 6 – Try It Online")
## Expanded
### 38 byte (sequence generator):
```
{  # bare block lambda with implicit parameter $_
  (
    # generate a new sequence everytime this function is called
    0,    # seed the sequence
    {     # bare block that is used to generate the rest of the values
      $_  # parameter to this inner block (previous value)
      +
      (
          # a statement that switches between (0,1) each time it is run
          ( $ +^= 1 )
        ??     # when it is 1 (truish)
          # a statement that increments each time it is run
          ++$ # &prefix:« ++ »( state $foo )
        !!     # or else subtract 1
          -1
      )
    }
    ...  # keep generating until:
    *    # never stop
  )[ $_ ] # index into the sequence
}
```
Note that this has the benefit that you can pass in `*` to get the entire sequence, or pass in a Range to more efficiently generate multiple values.
### 26 byte (direct calculation):
```
{  # bare block lambda with implicit parameter $_
  (
    +^     # numeric binary negate
      -$_  # negative of the input
      +|   # numeric binary or
      1
  ) ** 2   # to the power of 2
  div 8     # integer divide it by 8
  + $_ % 2  # add one if it is odd
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
;L¨O>¹É-
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f2ufQCn@7QzsPd@r@/29oAAKGAA "05AB1E – Try It Online")
Based on Jonathan Allan's Jelly approach (which was probably based on OP editing the question with another definition of the sequence), so 1-indexed.
[Answer]
# [Convex](https://github.com/GamrCorps/Convex), ~~10~~ 9 bytes
```
_½,ª)\2%-
```
[Try it online!](https://tio.run/##S87PK0ut@P8//tBenUOrNGOMVHX///9vaAAChgA "Convex – Try It Online")
Based on Jonathan Allan's Jelly approach (which was probably based on OP editing the question with another definition of the sequence). 1-indexed.
Explanation:
```
_½,ª)\2%- Stack: [A]
_         Duplicate. Stack: [A A]
 ½        Halve. Stack: [A [A]½]
  ,       Range, [0..⌊N⌋). Stack: [A [[A]½],]
   ª      Sum. Stack: [A [[A]½],]ª]
    )     Increment. Stack: [A [[[A]½],]ª])]
     \    Swap. Stack: [[[[A]½],]ª]) A]
      2   2. Stack: [[[[A]½],]ª]) A 2]
       %  Modulo. Stack: [[[[A]½],]ª]) [A 2]%]
        - Minus. Stack: [[[[[A]½],]ª]) [A 2]%]-]
```
]