[Question]
  [
Mr. Binary Counterman, son of Mr. Boolean Masker & Mrs. Even Oddify, follows in his parents’ footsteps and has a peculiar way of keeping track of the digits.
When given a list of booleans, he counts the 1s and 0s separately, numbering the 1s with the odds & the 0s with the evens.
For example, when he looks at `1 1 0 0 1 0` he counts: `1st odd, 2nd odd, 1st even, 2nd even, 3rd odd, 3rd even` and copies it down as `1 3 2 4 5 6`
Mr. Binary Counterman thinks it looks prettier to start counting odds at 1 and evens at 2. However the pattern is more symmetric if you start counting evens at 0. You may do either. So either `1 3 2 4 5 6` or
`1 3 0 2 5 4` are good given the list above.
As input you may take any representation of a boolean list or binary number, the output should be the list of resulting numbers with any delimiter. (But the list elements should be separate & identifiable.)
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so least bytes wins.
## Test Cases
```
1 0 1 0 1 0
1 2 3 4 5 6
1 1 1 1
1 3 5 7
0 0 0 0
2 4 6 8
0 1 1 0 0
2 1 3 4 6
0 1 1 0 0 1 0 1 1
2 1 3 4 6 5 8 7 9
0 0 1 0 0 1 1 1
2 4 1 6 8 3 5 7
0
2
1
1
1 1 1 0 0 0
1 3 5 2 4 6
```
  
[Answer]
# JavaScript (ES6), 29 bytes
```
a=>a.map(v=>b[v]+=2,b=[0,-1])
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i5RLzexQKPM1i4puixW29ZIJ8k22kBH1zBW839yfl5xfk6qXk5@ukaaRrShjoEOFMdqanJhyIIhFhkDHTDEKmMINhGvHNROXCbD1OBQgc2lOF0Pc@d/AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 12 bytes
```
+2*/:<.&/:\:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/tY209K1s9NT0rWKs/mtypSZn5ANlDRWMFYwUTBR0rRTSwFxDIGmALmuqYKZgrmCJpgpMAtkw1SCVZjA1BghzQMpA5pjC7DGE6zX4DwA "J – Try It Online")
Explanation: Self plus twice the minimum of ascending and descending ranks.
Given a boolean array `1 1 0 0 1 1 1`, ascending rank `/:@/:` and descending rank `/:@\:` are computed as follows:
```
array:       1 1 0 0 1 1 1
asc. rank:   2 3 0 1 4 5 6
desc. rank:  0 1 5 6 2 3 4
minimum:     0 1 0 1 2 3 4
```
# [APL(Dyalog Unicode)](https://dyalog.com), 9 bytes [SBCS](https://github.com/abrudz/SBCS)
```
⊢+2×⍋⌊⍥⍋⍒
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=e9Q31dP/UdsEAwA&c=e9S1SNvo8PRHvd2Peroe9S4FMXonAQA&f=S1MwUDAEQgMFA640BBtMAtlgMQOorCFc3AAA&i=AwA&r=tryAPL&l=apl-dyalog&m=train&n=f)
[Answer]
# [Risky](https://github.com/Radvylf/risky), 44 bytes
```
__0+0+_0+0+__0+0+_0+0+__0+0+_0+0+__0+0+_0+?1__0+0+_0+0+__0+0+_0!-_0!_{1+_0+0_[2_{0+__{1
```
[Try it online!](https://radvylf.github.io/risky?p=WyJfXzArMCtfMCswICsgX18wKzArXzArMCArIF9fMCswK18wKzAgKyBfXzArMCtfMCs_XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDFcbl9fMCswK18wKzAgKyBfXzArMCtfMCEtIF8gMCFfezErXzArMCBfIFsyX3swK19fezEiLCJbWzEsIDAsIDEsIDEsIDBdXSIsMF0)
**How it works:**
This is a really low level explanation:
```
... + __0+0+_0+?                                                  ;  the input array
                 1                                                ;  map with the following pairs:
                   ... + __0+0+_0!-                               ;  [0, -1]
                                    _                             ;  map to
                                      0!_{1+_0+0                  ;  range with same length
                                                 _                ;  map to
                                                   [              ;  absolute value
                                                          +       ;    of the sum of
                                                     2_{0         ;      twice the index in the range and
                                                            __{1  ;      the offset (0 or -1)
```
That's useless, though. Here's a better description of how this works:
Risky has an operator called "map pairs" which takes an array, and maps the items according to a set of rules. The rules are arrays, starting with the item to be replaced, and with (typically) one item to map to. However, if multiple are specified, they'll be used in order.
This answer generates those mappings, which look like `[[0, 2, 4, 6, ...], [1, 1, 3, 5, 7, ...]]`. It does this by mapping `[0, -1]` to `[2_{0+__{1` over a range `[0, x)`, which is essentially `(x, n) => abs(2 * x + n)`, where `x` is the number in the range and `n` is either `0` or `-1`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
,CÄḤ×ƊS_
```
[Try it online!](https://tio.run/##y0rNyan8/1/H@XDLwx1LDk8/1hUc//9w@9FJD3fO0Iz8/z/aUEfBQEcBQcbqKIDEoAjEMwDLGUCZhjDFmAJIxiBpRJaEy4BtQbEKZgsA "Jelly – Try It Online")
-2 bytes thanks to [Bubbler](https://codegolf.stackexchange.com/users/78410/bubbler)
## How it works
```
,CÄḤ×ƊS_ - Main link. Takes a binary list B on the left
 C       - Complement. Flip the bits of B
,        - Pair with B: [B, B']
     Ɗ   - Last 3 links as a monad f([B, B']):
  Ä      -   Cumulative sum of each
   Ḥ     -   Unhalve
    ×    -   Multiply modified B by B and modified B' by B'
      S  - Columnwise sum
       _ - Subtract B, elementwise
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-m`](https://codegolf.meta.stackexchange.com/a/14339/), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
?J±2:T±2
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LW0&code=P0qxMjpUsTI&input=WzEgMSAwIDAgMSAwXQ)
* `J` is initially `-1`,
* `T` is initially `0`, and,
* `±` is the shortcut for `+=`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
,CỤ€⁺«/Ḥ_
```
[Try it online!](https://tio.run/##y0rNyan8/1/H@eHuJY@a1jxq3HVotf7DHUvi/x9uPzrp4c4ZmpH//0cb6igY6CggyFgdBZAYFIF4BmA5AyjTEKYYUwDJGCSNyJJwGbAtKFYh2WKIRRMA "Jelly – Try It Online")
My convoluted port of my own APL/J answer.
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
CỤỤ«ỤỤ$Ḥ_
```
[Try it online!](https://tio.run/##y0rNyan8/9/54e4lQHRoNYRWebhjSfz/w@1HJz3cOUMz8v//aEMdBQMdBQQZq6MAEoMiEM8ALGcAZRrCFGMKIBmDpBFZEi4DtgXFKiRbDLFoAgA "Jelly – Try It Online")
Small modification of caird's 10-byter port.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 6 bytes
```
η^_O·α
```
[Try it online!](https://tio.run/##yy9OTMpM/V9TVmmrpGunoGR/eF@wi8v/c9vj4v0PbT@38b@OkpLOf0MFMOQyUABDIA3io7DAJEwNTATM5zLkMoSrMgAA "05AB1E – Try It Online")
```
η       # prefixes of the input
 ^      # XOR the first value of the input with the first prefix, second value of input with second prefix, ...
  _     # boolean negate
   O    # sum each modified prefix
    ·   # double all integers
     α  # absolute difference to the input
```
`η^_` can be replaced with `δQÅl` (equality table; lower-triangular matrix), which is a byte longer but might be shorter in some other language.
```
δQÅlO·α
```
[Try it online!](https://tio.run/##yy9OTMpM/V9TVmmrpGunoGR/eF@wi8v/c1sCD7fm@B/afm7jfx0lJZ3/hgpgyGWgAIZAGsRHYYFJmBqYCJjPZchlCFdlAAA "05AB1E – Try It Online")
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), 28 bytes
```
$b=0,-1;$args|%{($b[$_]+=2)}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNydFNzi9K/a@SZlv9XyXJ1kBH19BaJbEovbhGtVpDJSlaJT5W29ZIs/Z/LRcQqKmkKRgoGAKhAZgGs/8DAA "PowerShell Core – Try It Online")
Port of [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s [solution](https://codegolf.stackexchange.com/a/229685/97729), thanks !
### Initial implementation, 35 bytes
```
switch($args){0{++$e*2}1{$o++*2+1}}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNydFNzi9K/a@SZlv9v7g8syQ5Q0MlsSi9WLPaoFpbWyVVy6jWsFolX1tby0jbsLb2fy0XEKippCkYKBgCoQGYBrP/AwA "PowerShell Core – Try It Online")  
[Or starting with 0 (35 bytes)](https://tio.run/##K8gvTy0qzkjNydFNzi9K/a@SZlv9v7g8syQ5Q0MlsSi9WLPaoFolVVtby6jWsFolH8TQNqyt/V/LBQRqKmkKBgqGQGgApsHs/wA "PowerShell Core – Try It Online")
Takes the input as a list of `0/1`'s  
Returns a list of integers
## Explanation
```
switch($args){ # For each argument passed as an integer
0{++$e*2}      # if it is 0, output an even number, starting from 2
1{$o++*2+1}}   # if it is 1, output an odd number, starting from 1
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~7~~ 6 bytes
```
ċṪ$ƤḤ+
```
[Try it online!](https://tio.run/##y0rNyan8//9I98Odq1SOLXm4Y4n2////ow10DIHQQMcATALZsQA "Jelly – Try It Online")
Basically a translation of an old version of ovs' [05AB1E answer](https://codegolf.stackexchange.com/a/229702/98955).
## Explanation
```
ċṪ$ƤḤ+ Main monadic link
   Ƥ   Map over prefixes
  $    (
ċ        Count the occurences of
 Ṫ         the last item after removing it
  $    )
    Ḥ  Unhalve
     + Add the original list
```
[Answer]
# 8086 machine code, ~~21~~ 18 bytes
```
00000000: b0 01 b2 02 d1 eb 72 01 92 aa 40 40 72 01 92 e2  ......r...@@r...
00000010: f3 c3                                            ..
```
Function.
```
        [bits 16]
        [cpu 8086]
        section .text
        ; nasm syntax
        ; INPUT:
        ;    DI: destination byte array
        ;    BX: bit pattern (little endian)
        ;    CX: count of bits
        ; OUTPUT:
        ;    stored to DI
        global  mrbitctr
mrbitctr:
        ; Count odd bits in AL
        mov     al, 1
        ; Count evens in DL
        mov     dl, 2
.loop:
        ; Shift right BX one bit. This will put
        ; the lowest bit in CF.
        shr     bx, 1
        ; Was the bit set? If so, jump.
        jc      .no_swap
        ; Even: swap
.swap:
        ; Pull the old switcheroo to select evens
        xchg    ax, dx
        ; Odd: don't swap
.no_swap:
        ; Store to DI and increment
        stosb
        ; Add 2 to AL by incrementing AX twice
        ; Note: INC does not affect the carry flag
        inc     ax
        inc     ax
        ; swap back if even
        jc      .no_swap_back
.swap_back:
        xchg    ax, dx
.no_swap_back:
        ; Loop CX times.
        loop    .loop
.end:
        ret
```
* 3 bytes: swap twice
[Answer]
# [Dyalog APL](https://www.dyalog.com/), ~~24~~ 23 bytes
```
(⍵×¯1+2×+\⍵)+N×2×+\N←~⍵
```
  
The list of evens and the list of odds are generated separately and added elementwise with the `+` in the middle. Here's what it looks like with the problem's example input:
```
Evens:
    ⍵            The input                      → 1 1 0 0 1 0
    ~            Negate it                      → 0 0 1 1 0 1
    N←           Let N be the negated list      → 0 0 1 1 0 1
    +\           Take the running sum           → 0 0 1 2 2 3
    2×           Multiply by two                → 0 0 2 4 4 6
    N×           Multiply by the negated list   → 0 0 2 4 0 6
Odds:
    ⍵            The input                      → 1 1 0 0 1 0
    +\           Take the running sum           → 1 2 2 2 3 3
    2×           Multiply by two                → 2 4 4 4 6 6
    ¯1+          Subtract 1                     → 1 3 3 3 5 5
    ⍵×           Multiply by the list           → 1 3 0 0 5 0
Together:
  (~⍵)×2×+\~⍵    Evens                          → 0 0 2 4 0 6
  (⍵×¯1+2×+\⍵)   Odds                           → 1 3 0 0 5 0
  +              Add elementwise                → 1 3 2 4 5 6
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v//Ud/UR20TqjUe9W49PP3QekNto8PTtWOAPE1tjToQdXg6WATErlUwBEIDIASS//8DAA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 27 26 25 bytes
```
<@({.-~2*#\)/.~@/:~/:&;/:
```
[Try it online!](https://tio.run/##ZY29CgIxEIR7n2JQ8DwxPxtNTleFA8HK6mo78RAbH0DIq8clMY0yTLPfzOwzTXUz4shosIIFi5XGabic06FfvLWKbjm7tkbH3nA0PN8bTu3kfnu8AILDGht4BCjGKAdbXSIk3KOrNKsQJ72AbSG2qBLKq6Eyypt/1Eu7w@4n9f1P6QM "J – Try It Online")
* `/.~@/:~` Sort and group by value
* `({.-~2*#\)` Create `2 4 6 ...` to the length of each group, and subtract the first element of each group from that (vectorized), so that the the 1 group becomes `1 3 5 ...`
* The grouping screws up the order though, so we have to...
* `/:&;/:` Resort it according to the grade up of the original input, which makes it correct again.
## [J](http://jsoftware.com/), bonus: translation of [AviFS's APL answer](https://codegolf.stackexchange.com/a/229684/15469) into J (28 bytes)
```
([:+/**-&1 0)@,:&(2*]*+/\)-.
```
[Try it online!](https://tio.run/##bY0xC8IwEIV3f8XDoW3SJk1ik@qBIAhOTq7WSSzFxf8/xSMxi8rx4LjvvXfPuNb1jD2hRgcDYimN4@V8is2V2l5KVVkYceioapy8ybafhNJRrB735YUZDIvyiTeHDQZ4BCj6Z7HMPcZC02TiOBewzcTkKcSm1lCYTZ0/1HN6xO7L9flv4xs "J – Try It Online")
Just because I liked it and wanted to see how they'd compare.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), ~~15~~ 9 bytes
```
₌⇧⇩⇧$⇧∵d+
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%E2%82%8C%E2%87%A7%E2%87%A9%E2%87%A7%24%E2%87%A7%E2%88%B5d%2B&inputs=%5B0%2C1%2C1%2C0%2C0%2C1%2C0%2C1%2C1%5D&header=&footer=)
Me when APL port
## Explained
```
₌⇧⇩⇧$⇧∵d+
₌⇧⇩       # grade up input, grade down input
   ⇧$⇧    # grade each of those up
      ∵d  # 2 * the minimum of those two lists
        + # added to the input   
```
[Answer]
# [Python 2](https://docs.python.org/2/), 43 bytes
```
b=[2,1]
for e in input():print b[e];b[e]+=2
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P8k22kjHMJYrLb9IIVUhMw@ICkpLNDStCooy80oUkqJTY61BhLYtUHG0oY6BDhTHAgA "Python 2 – Try It Online")
-5 bytes and fix thanks to @xnor
The program is now reusable
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-p`, 29 bytes
Takes input as space separated digits (or any other non-digit separator).
```
gsub(/\d/){($`*2+?1).count$&}
```
[Try it online!](https://tio.run/##KypNqvz/P724NElDPyZFX7NaQyVBy0jb3lBTLzm/NK9ERa32/39DBQMFKOYyVABDLgMFMOQyAPNRWFC1EDUwETCfyxCqH6z3X35BSWZ@XvF/3QIA "Ruby – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 38 bytes
```
f(h:t)=h:f[x+mod(x-h-1)2*2|x<-t]
f e=e
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00jw6pE0zbDKi26Qjs3P0WjQjdD11DTSMuopsJGtySWK00h1Tb1f25iZp6CrUJBUWZeiYKKQppCtKGOoY4BEALJWK7/AA "Haskell – Try It Online")
The recursion happens on “the `t`ail of the list, but with all elements `x` that have the same parity as the `h`ead incremented by 2.” Like so:
```
  f [1,1,0,0,1,0]
= 1 : f [3,0,0,3,0]
= 1 : 3 : f [0,0,5,0]
= 1 : 3 : 0 : f [2,5,2]
= 1 : 3 : 0 : 2 : f [5,4]
= 1 : 3 : 0 : 2 : 5 : f [4]
= 1 : 3 : 0 : 2 : 5 : 4 : f []
= [1,3,0,2,5,4]
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
ṢŒg2ḷ$\€ÄFị@ỤỤ$
```
[Try it online!](https://tio.run/##y0rNyan8///hzkVHJ6UbPdyxXSXmUdOawy1uD3d3OzzcvQSIVP7//2@gYwiEBjoGYBLIBgA "Jelly – Try It Online")
```
ṢŒg2ḷ$\€ÄFị@ỤỤ$  Main Link; take a list of 0s and 1s
Ṣ                Sort the list
 Œg              Group runs of equal elements
       €         For each group
     $\          Cumulatively reduce by
   2ḷ            x => 2 (that is, all but the first element become 2)
        Ä        Cumulative sum, vectorizing to depth 1
         F       Flatten
          ị@     Index into (reverse order)
            ỤỤ$  The input graded up twice
```
Grading up twice returns the permutation to index into another list to get the same ordering or something like that. I think that's how it works.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 15 bytes
```
{x+2*(<<x)&<>x}
```
[Try it online!](https://ngn.bitbucket.io/k#eJxVjl0KhDAMhN97inkSqz4kVi0uZY/jGQrLenbTNP4RCp1vkky2zy/3Y9emlH2TvvnvHIMQMGLGhB0birYnXhAejWs5kt4JizKq5Up3UF4p64Ynn2UiYn37llN3sm69806fLLcdyKtRPqL4VOztTrou4CuBDttBLIk=)
A K port of [@Bubbler's J and APL solutions](https://codegolf.stackexchange.com/a/229690/75681) - don't forget to upvote it!
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~9~~ 8 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
╜♪N·{☼►◄
```
[Run and debug it](https://staxlang.xyz/#p=bd0d4efa7b0f1011&i=%5B0,+1,+0,+1,+0,+1%5D%0A%5B0,+0,+0,+0%5D%0A%5B1,+1,+1,+1%5D%0A%5B1,+0,+0,+1,+1%5D%0A%5B1,+0,+0,+1,+1,+0,+1,+0,+0%5D%0A%5B1,+1,+0,+1,+1,+0,+0,+0%5D%0A%5B1%5D%0A%5B0%5D%0A%5B0,+0,+0,+1,+1,+1%5D%0A&m=2)
Inspired by Arnauld's idea.
0-indexed, takes the bits flipped.
## Explanation
```
AEsF{Q2+}&
AEs        swap the input with  [1,0]
   F       foreach i:
    {   }&  modify the element at i in 2,1
     Q      print without popping
      2+    add 2
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 29 bytes
```
(a=0@-1;a[[#~Mod~2]]+=2&/@#)&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7XyPR1sBB19A6MTpauc43P6XOKDZW29ZITd9BWVPtf0BRZl5JtLKuXZqDcqxaXXByYl5dNVe1oY6BDhTX6oC4YAhiGuiAIYRpCFaEyoHqgyuGCcKEwOYhDIWYxlX7HwA "Wolfram Language (Mathematica) – Try It Online")
Boring answer. Mathematica's `+=` etc. operators have different precedence than assignment `=` etc. operators. This gives them higher precedence than `&`, so unlike `=` expressions they don't need to be parenthesized on the left side of `&`. (`//=`, introduced in 12.2, is slightly different from both aforementioned groups).
[Answer]
# [C (clang)](http://clang.llvm.org/), 52 bytes
-1 thanks to [@AZTECCO](https://codegolf.stackexchange.com/users/84844/aztecco), by using clang instead of gcc.
```
f(a,l)int*a;{for(int b[]={0,-1};l--;)*a++=b[*a]+=2;}
```
[Try it online!](https://tio.run/##jZNdb4MgFIbv/RXGZIkfmBRU1DB@SdcL2tnFpHONsGRb4293B7Trob2Z5iTwwPtyDh@H/HBSw9s8H2NFTkk/mFSJy/FjjKEZ7rc7edmQnE7ilOciSVWWyf02VbtMMjHNdo7ptLGT01CNo/omoWt3X@fuYLpX1w11/9MlwSUI4bP9XrgmrLlI3PjK7NJyI/pnC0WfZUl4HkF0jKOn1zAiyzLbfrcKzp9Gx1H0b/k1s3uHl8F6TEFgE3xX/RDjjA21W0HJhqwxib@xcR1jpCAlqQhHY5pKfusZtsx0P3ZYeQHqGquZLJG6WI7D/VjtOIO1OWmwuvDU5aKmrgJPXy566vL3si9lhRwqz2HdCa@OynOCahpSkxY7VrJFjvxa0dXxzo9fK6O2tsf94bJBbrVzw3pHGFbUkiJF4/YdKx6IbjxFezvBh3Nob6fI7neytffAdd2DMZTAvYGbT9dLuFAGFEIzjxZAIXTh0RIohC49WgGF0JVHOVAIzT1aA4XQtUcboBC68WgLFEK39pHMvw "C (clang) – Try It Online")
---
# [C (gcc)](https://gcc.gnu.org/), 53 bytes
```
f(a,l)int*a;{for(int b[]={0,-1};l--;a++)*a=b[*a]+=2;}
```
[Try it online!](https://tio.run/##jZPfboMgFMbvfQpjssRaTAoqahhP0vWCWtuYdF0jLNnW@OzugLoe2ptpTgI/@L7D4U@TnppmHI@xIudVdzGJErfjRx9DM9xvd/K2ISkdxDlNhVqvV4mS@22idmvJxDDaSabVxs5OQtX36puErt1@XdvGtAfXDXX3066CWxDCZ/udcE1IOknc@MxsbrkR3auFooOc4bUH0TGOXg5hRKY02243C66fRsdR9G/5srJHh7eL9RiCwC7wXXWXGK/YULsXlGzIHIP4G@vnMUYykpOCcDSmqeT3nmHTTPdjh5lnoC6xmskcqbPpPNyP1Y4zyM1JhdWZp84nNXUVePp80lO3fm/1uSyQQ@E5zDvh1VF4TlBNRUpSY8dC1siRLxUtjg9@fKmM2tqe94fLCrmVzg3rHWFYUUqKFJXbd6x4IrryFPX9BJ/Oob6fInvcydreA9d1D8ZQAvcGbj6dL@FEGVAIzTyaAYXQmUdzoBA692gBFEIXHuVAITT3aAkUQpcerYBC6MqjNVAIXdtHMv4C "C (gcc) – Try It Online")
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 21 bytes
```
*>>.&{(%.{$_}+=2)-$_}
```
[Try it online!](https://tio.run/##TU7LDoJADLz3K@aAPFQIuyDgAX7FYISEiGBAYwjh27Hs4iOT3abT6XTuRVdH822AWSKdt1nmmaO98UbjNO1S6bhc57LtYNdVU/QO3AxG1exhtM8H/@c6b66pZWGkPh9Q2jz0Xm13YWmaKRVNs4CP9ZGARIAQB0TEjQLXgImYyIcCSVZESBZCqNWFEmox@iNXV/Ebsk2CGEdt9RFpSciVTb@3SHICxhpDX9ZR1P03 "Perl 6 – Try It Online")
Maps each element to the index into an anonymous hash, incrementing that value by two (initially zero), and finally subtracting the element itself to distinguish between odd and even.This could also be extended to values beyond 0 and 1 simply by changing the `2` to another number.
[Answer]
# [Julia](http://julialang.org/), ~~33~~ 30 bytes
```
f(x,y=[0,-1])=x.|>i->y[i+1]+=2
```
[Try it online!](https://tio.run/##VU7RCsMgDHzPV@RRqR1m7/ZHxIfBKjiKG20GFvrvrnV1wxyBu@Ny5PGewo1Szl4ktRqrVU9OmnTZhtAPqw0duc5cM48LL2hQgCXUeK5Thyw4qMaCL6USasV59wtXs1ql719a2ySAf87IGCKWRwD3ec0h8hQFy0b63WgdCWO85w8 "Julia 1.0 – Try It Online")
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 42 bytes
```
d[1]=1{for(;a++<NF;d[b]+=2)$a=+d[b=$a%2]}1
```
[Try it online!](https://tio.run/##SyzP/v8/Jdow1tawOi2/SMM6UVvbxs/NOiU6KVbb1khTJdFWG8i2VUlUNYqtNfz/30DBEAgNFAzAJJANAA "AWK – Try It Online")
So this one is one test with a codeblock, and a naked `1` to print all the commandline arguments. It replaces each commandline argument with the appropriate even/odd counter in the codeblock.
The "test" for the codeblock is always truthy and it just used to initialize the "odd" counter to `1`.
```
d[1]=1{                                  }
```
The code block runs through each commandline argument,
```
       for(;a++<NF;       )
```
Then sets that argument to the current value of the even/odd counter with:
```
                           $a=+d[b=$a%2]
```
And at the end of the loop, increments the current counter by 2 in preparation for the next match.
```
                   d[b]+=2
```
Once that's done, it just need to print out all the arguments.
```
                                         1
```
[Answer]
# [Zsh](http://www.zsh.org), 23 bytes
```
for x
echo $[x+a$x++*2]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwdbi1BIFAwVDIDQA02D20tKSNF2L7Wn5RQoVXKnJGfkKKtEV2okqFdraWkaxENkFUApKAwA)
Starts even numbers at 0.
Explanation:
* `for x`: for each `$x` in the input,
* `$[]`: arithmetic expansion
* `++`: increment and return original value
* `a$x`: the variable named `a0` or `a1` (which correspond to the number of 0s and 1s seen so far)
* `x+*2`: double and add `x` to get the correct value
* `echo` : print (can't use `<<<` because the mutation wouldn't work in the subshell it creates)
[Answer]
# [Desmos](https://desmos.com/calculator), 64 bytes
```
a(l)=\sum_{n=1}^{[1...length(l)]}l[n]
b=1-l
f(l)=2ba(b)+2la(l)-l
```
Just implements the strategy shown in [AviFS's Dyalog APL answer](https://codegolf.stackexchange.com/a/229684/96039).
[Try It On Desmos!](https://www.desmos.com/calculator/zfuptadr5z)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/4ekzmudvzs)
## Explanation:
`a(l)=\sum_{n=1}^{[1...length(l)]}l[n]`: Function that takes in a list \$l\$ and returns the running total of \$l\$.
`b=1-l`: Variable that stores the inputted list, but with each bit flipped.
`f(l)=2ba(b)+2la(l)-l`: Function that takes in a list of bits \$l\$ and outputs the correct answer, based on the strategy mentioned above.
[Answer]
# [R](https://www.r-project.org/), 42 bytes
```
function(x,y=seq(x)*2){x[x]=y-1;x[!x]=y;x}
```
[Try it online!](https://tio.run/##jZFhC4IwEIa/@yuu9WULA6emhuyXSB9CDASbpRMm0W@30wxiGY6DcQye9@69txnyupOqaK5nKYZLJ3NV1pJqtxdtcaea7Xz20Jk@iX7PU51txi7Vzy@MtqpRdUmLauzaW1UqSjhw8LDwJS4BwhgTgjNnFZuQH2zLwYcAQjhA5DgWs7FMgQDheBX2prWN6T5OjiCxgGffJs6n5SN7gfkK/I8QWkkghqOVnY/gglyIn2jM9jYGvp6EkYFldAsJvOObchhe "R – Try It Online")
*-8 bytes thanks to [@Dominic](https://codegolf.stackexchange.com/users/95126/dominic-van-essen)*
Takes input as booleans: `TRUE`(`1`) and `FALSE`(`0`).
Straightforward approach, but takes advantage of truncating the replacement to the length of items being replaced.
---
Different approach:
### [R](https://www.r-project.org/), 47 bytes
```
function(x,n=0:-1)for(i in x)show(n[i]<-n[i]+2)
```
[Try it online!](https://tio.run/##lZFNCoMwEIX3nmLIKkEFk/rXUk/SdiGiNNAmJUbq7W1MFQoqjQwMQ8J8zHtPDZXshK7VsxTF0HSi0lwK3AeiiE4hJY1UmAMX0JP2Lt9YXPjtHI7dZ@RnF7daaclx/Rin9vXgGiMKFCJTpqMAASKE@JR4VWn/DsAghgTSq0DE8/6yLGeDxQxtD8vW6k0JZE6MyCpb3jJqSiF3ZEwOrVCoVZTu40wO0W2e0ZdDBkdnjTN3nRqbd6N2j29Liltmy7R2ZL2e1TdvNvs8fAA "R – Try It Online")
Takes input incremented by 1: `2` (for `1`) and `1` (for `0`).
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 43 bytes
```
(.)(?<=((\1)|.)*(1)?)
$#3$*2$4¶
2
11
1+
$.&
```
[Try it online!](https://tio.run/##K0otycxL/P9fQ09Tw97GVkMjxlCzRk9TS8NQ016TS0XZWEXLSMXk0DYuIy5DQy5DbS4VPbX//w0NQBAoAhQzAAIuA0NDGAmUAQmCWCAGlyFIGVANAA "Retina 0.8.2 – Try It Online") Link includes test cases. Takes input as a string of bits. 1-indexed. Explanation:
```
(.)(?<=((\1)|.)*(1)?)
```
For each bit, count the number of preceding identical bits. If the current bit is `1` then count it separately otherwise include the current bit in the count.
```
$#3$*2$4¶
```
Record a `2` for each duplicate plus one extra for a `1` bit.
```
2
11
```
Convert to unary.
```
1+
$.&
```
Convert the sum back to decimal.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
ＩＥθ⁺Ｉι⊗№…θκι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzexQKNQRyEgp7QYIpCpqaPgkl@alJOaouGcXwpSV5mck@qckQ9WmA2UztQEA@v//w0NDAwNDYDkf92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Takes input as a string of bits. 0-indexed. Explanation:
```
  θ             Input string
 Ｅ              Map over characters
     ι          Current character
    Ｉ           Cast to integer
   ⁺            Plus
      ⊗         Doubled
       №        Count of
           ι    Current character in
         θ      Input string
        …       Truncated to length
          κ     Current index
Ｉ               Cast to string
                Implicitly print on separate lines
```
[Answer]
# [Perl 5](https://www.perl.org/) (`-ap`), 27 bytes
```
$_+=$x[$_]++*2for@F;$_="@F"
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXttWpSJaJT5WW1vLKC2/yMHNWiXeVsnBTen/fwMFAwVDBTD5L7@gJDM/r/i/bmIBAA "Perl 5 – Try It Online")
]