[Question]
  [
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
## Examples
`[]` → `[]`/`[]`
`[42]` → `[0]`/`[1]`
`[7,7,7]` → `[0,1,2]`/`[1,2,3]`
`[10,20,30]` → `[0,0,0]`/`[1,1,1]`
`[5,12,10,12,12,10]` → `[0,0,0,1,2,1]`/`[1,1,1,2,3,2]`
`[2,7,1,8,2,8,1,8,2,8]` → `[0,0,0,0,1,1,1,2,2,3]`/`[1,1,1,1,2,2,2,3,3,4]`
`[3,1,4,1,5,9,2,6,5,3,5,9]` → `[0,0,0,1,0,0,0,0,1,1,2,1]`/`[1,1,1,2,1,1,1,1,2,2,3,2]`
  
[Answer]
# JavaScript (ES6), 26 bytes
1-indexed.
```
a=>a.map(o=x=>o[x]=-~o[x])
```
[Try it online!](https://tio.run/##dc7NDoIwDADgu0/BEZIC@wHFw3gRwmFBMBpkRIzh5KvPFoMSB2u2Llm/dlf91EN1v/SPsDOn2jbKapXr6KZ736hR5aYYSxW@KAW2Mt1g2jpqzdlv/KIMAm9jxbFXlLu/@kRsCqrnDjgAxrqZAAiQDuIMBAPJVtwHYTgoBS4AJZ10WeAvomkgHCrwkxwyfM3mPOsfJSymBhISp4XE9wR3Ckes2WOWdKc2y@nLVvQT@wY "JavaScript (Node.js) – Try It Online")
### Commented
```
a =>                // a[] = input array
  a.map(o =         // assign the callback function of map() to the variable o, so that
                    // we have an object that can be used to store the counters
    x =>            // for each value x in a[]:
      o[x] = -~o[x] //   increment o[x] and yield the result
                    //   the '-~' syntax allows to go from undefined to 1
  )                 // end of map()
```
[Answer]
# [R](https://www.r-project.org/), 27 bytes
```
function(x)ave(x,x,FUN=seq)
```
[Try it online!](https://tio.run/##NYvNCgIxDITvPoXHBEZo011/QK8evfkAUlrYgxV3Xenb1xQiYTJfJsnc8va8a3kt8TO9ClV@fBNVVFzvt8uS3twylfWZ5imSY95kijSIwQFaxt5BHML/ZoQXaNZ7B4tFPzyOEJW5bYLOg2rESdO9eujM3H4 "R – Try It Online")
**Explanation :**
`ave(x,x,FUN=seq)` splits vector `x` into sub-vectors using values of `x` as grouping keys.
Then `seq` function is called for each group and each result is re-arranged back in the original group position.
Better see an example :
```
x <- c(5,7,5,5,7,6)
ave(x, x, FUN=seq) # returns 1,1,2,3,2
 ┌───┬───┬───┬───┬───┐
 │ 5 │ 7 │ 5 │ 5 │ 7 │
 └───┴───┴───┴───┴───┘            
   |   |   |    |  |     
   ▼   |   ▼    ▼  |
 GROUP A : seq(c(5,5,5)) = c(1,2,3)
   |   |   |    |  |     
   ▼   |   ▼    ▼  |
 ┌───┐ | ┌───┬───┐ |
 │ 1 │ | │ 2 │ 3 │ |
 └───┘ | └───┴───┘ |
       ▼           ▼
 GROUP B : seq(c(7,7)) = c(1,2)
       |           |
       ▼           ▼
     ┌───┐       ┌───┐
     │ 1 │       │ 2 │
     └───┘       └───┘ 
   |   |   |   |   |
   ▼   ▼   ▼   ▼   ▼ 
 ┌───┬───┬───┬───┬───┐
 │ 1 │ 1 │ 2 │ 3 │ 2 │
 └───┴───┴───┴───┴───┘  
```
Note : 
`seq(y)` function returns a sequence `1:length(y)` in case `y` has `length(y) > 1`, but returns a sequence from `1:y[1]` if `y` contains only one element.  
This is fortunately not a problem because in that case R *- complaining with a lot of warnings -* selects only the first value which is incidentally what we want :)
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 4 bytes
```
&=Rs
```
This solution is 1-based
Try it out at [MATL Online](https://matl.io/?code=%26%3DRs&inputs=%5B5%2C12%2C10%2C12%2C12%2C10%5D&version=20.10.0)!
**Explanation**
Uses `[1,2,3,2]` as an example
```
    # Implicitly grab the input array of length N
    #
    #   [1,2,3,2]
    #
&=  # Create an N x N boolean matrix by performing an element-wise comparison
    # between the original array and its transpose:
    #
    #     1 2 3 2
    #     -------
    # 1 | 1 0 0 0
    # 2 | 0 1 0 1
    # 3 | 0 0 1 0
    # 2 | 0 1 0 1
    #
R   # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
    #
    #   [1 0 0 0
    #    0 1 0 1
    #    0 0 1 0
    #    0 0 0 1]
    #
s   # Compute the sum down the columns
    #
    #   [1,1,1,2]
    #
    # Implicitly display the result
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 7 bytes
Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.
```
+/¨⊢=,\
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X1v/0IpHXYtsdWL@pz1qm/Cob6pXsL/fo44ZGo96@4A8T/9HXc2H1hs/apsI5AUHOQPJEA/PYE2gEqji/2kK6tGx6lwgysQIyjDXAUIo29BAx8hAx9gAyjXVMTTSAYqBSBADKmwE1GGoY6FjBMRQGipjDOSbALGpjiVQ1AxIG4PYseoA "APL (Dyalog Unicode) – Try It Online")
**Explanation**
The 10-byte non-tacit version will be easier to explain first
```
{+/¨⍵=,\⍵}
{         } A user-defined function, a dfn
      ,\⍵  The list of prefixes of our input list ⍵
           (⍵ more generally means the right argument of a dfn)
           \ is 'scan' which both gives us our prefixes 
           and applies ,/ over each prefix, which keeps each prefix as-is
    ⍵=     Checks each element of ⍵ against its corresponding prefix
           This checks each prefix for occurrences of the last element of that prefix
           This gives us several lists of 0s and 1s
 +/¨       This sums over each list of 0s and 1s to give us the enumeration we are looking for
```
The tacit version does three things
* First, it removes the instance of `⍵` used in `,\⍵` as `,\` on the right by itself can implicitly figure out that it's supposed to operate on the right argument.
* Second, for `⍵=`, we replace the `⍵` with `⊢`, which stands for right argument
* Third, now that we have no explicit arguments (in this case, `⍵`), we can remove the braces `{}` as tacit functions do not use them
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 14
* 1 byte saved thanks to @NahuelFouilleul
```
{print++a[$1]}
```
[Try it online!](https://tio.run/##SyzP/v@/uqAoM69EWzsxWsUwtvb/f2MuQy4TIDblsuQy4jID0sYgNgA)
The above does one-based indexing. If you prefer zero-based indexing, its an extra byte:
```
{print a[$1]++}
```
[Try it online!](https://tio.run/##SyzP/v@/uqAoM69EITFaxTBWW7v2/39jLkMuEyA25bLkMuIyA9LGIDYA "AWK – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 7 bytes
```
1#.]=]\
```
[Try it online!](https://tio.run/##PYu7CoAwDEX3fsVFBRGkpK1v6J/oJBZxcXD222syREp6T06SK6cnWhAWUHal3eK25sYUFnWKtkaLd0F6jDn280YCVaTYeaVRnjaO4AnhX@vhvEj5BdR7PnKYOCdNHQUWHVePmfXAGYTzBw "J – Try It Online")
1-indexed.
## Explanation:
```
]\ all the prefixes (filled with zeros, but there won't be any 0s in the input):
   ]\ 5 12 10 12 12 10
5  0  0  0  0  0
5 12  0  0  0  0
5 12 10  0  0  0
5 12 10 12  0  0
5 12 10 12 12  0
5 12 10 12 12 10
]= is each number from the input equal to the prefix:
   (]=]\) 5 12 10 12 12 10
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 1 0 1 1 0
0 0 1 0 0 1
1#. sum each row:
   (1#.]=]\) 5 12 10 12 12 10
1 1 1 2 3 2
```
# [K (oK)](https://github.com/JohnEarnest/ok), ~~11~~ 10 bytes
-1 byte thanks to ngn!
```
{+/'x=,\x}
```
[Try it online!](https://tio.run/##y9bNz/7/P82qWltfvcJWJ6ai9n@agpGCuYKhggWQtoDR/wE "K (oK) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 48 bytes
```
lambda a:[a[:i].count(v)for i,v in enumerate(a)]
```
[Try it online!](https://tio.run/##VU7bDoIwDH33K5b4Akmju4AiiV8y9zAVIokMQoDEr8dWwJQ0W7uey0776V9N0FN5vU1vX9@fXvjceptX7vBohtBHY1w2nahgFFUQRRjqovN9EfnYTW1XhV6UkXWx2Avrjtbtdv9loue1xL3iwBmwFgwUaMJBg@EcJUFLMHKlYf1oWJyWgtKAXLppYHRyRvIiIn/8iUk1plCQIZCtnaslrDpKtrrMb/IykHA3g1CCJ4ULwifshuZtHu68zcbdKef0BQ "Python 2 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
ηε¤¢
```
[Try it online!](https://tio.run/##yy9OTMpM/f//3PZzWw8tObTo//9oYx1DHRMgNtWx1DHSMQPSxiB2LAA "05AB1E – Try It Online")
or as a [Test Suite](https://tio.run/##yy9OTMpM/W/u9v/c9nNbDy05tOh/rc7/6FiuaBMjIGGuA4RA2tBAx8hAx9gAyDTVMTTSAfJBJIgBFDICqjLUsdAxAmIoDRQ1BrJNgNhUxxIoYgakjUHsWAA)
**Explanation**
```
ηε     # apply to each prefix of the input list
  ¤¢   # count occurrences of the last element
```
[Answer]
# BQN, 1 byte
```
⊒
```
[Try it here!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oqSCgpGIDPigL8x4oC/NOKAvzHigL814oC/OeKAvzLigL824oC/NeKAvzPigL814oC/OQ==), [All tests](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oqSCgooRiDigKJKcynCqOKfqAoKCiJbXSIKCiJbNDJdIgoKIls3LDcsN10iCgoiWzEwLDIwLDMwXSIKCiJbNSwxMiwxMCwxMiwxMiwxMF0iCgoiWzIsNywxLDgsMiw4LDEsOCwyLDhdIgoKIlszLDEsNCwxLDUsOSwyLDYsNSwzLDUsOV0iCuKfqQ==)
I don't know much about BQN, but I learned from [this answer](https://codegolf.stackexchange.com/a/240424/3852) that this is a built-in.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 44 bytes
```
x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))
```
[Try it online!](https://tio.run/##Sy7WTS7O/O9Wmpds4@maV5qbWpSYlJNqk5lXYqeDLmCnkKZg@7/C1q5CLzg1JzW5REOjUidTE8QPScxO1cjU1HPOL80r0aiytauyta3U1PxvzRVQBNSqkaaRl1oeHVttrgOEtZqa6OKmOoZGOoYGYBLEACn5DwA "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# Ruby, 35 bytes
```
->a{f=Hash.new 0;a.map{|v|f[v]+=1}}
```
It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.
Some other, fun options that unfortunately weren't quite short enough:
```
->a{a.dup.map{a.count a.pop}.reverse}   # 37
->a{i=-1;a.map{|v|a[0..i+=1].count v}}  # 38
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~47~~ 43 bytes
```
f=lambda a:a and f(a[:-1])+[a.count(a[-1])]
```
[Try it online!](https://tio.run/##VU5dC8IwDHz3VxR8cRi1H5vOgb@k9KE6hoJ2Q@aDv75e3KYdIU1yuVyve/fXNugYm9PdP861F75Chlo0K2@rjXLZ2vrtpX2FHgDPLnbPW@hBsC4TS2HdzrrFD8v1gErAKsEPhBhXpEjzmjSZhKIkaUlGTizEl4VIWAUpTaDyy03CZl1wxxtWxz//Sw0Likrg5VTTY0nTGduaRIaZpQzliZjBJkcWdMR2j2q4n7tJhefOUnF2GT8 "Python 2 – Try It Online")
A recursive 'one-based' solution.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
ċṪ$Ƥ
```
[Try it online!](https://tio.run/##y0rNyan8//9I98Odq1SOLfn//3@0qY6hkY6hAZgEMWIB "Jelly – Try It Online")
For each prefix of the input list, it counts the number of occurrences of its last element in itself.
[Answer]
# [R](https://www.r-project.org/), 41 bytes
```
function(x)diag(diffinv(outer(x,x,"==")))
```
[Try it online!](https://tio.run/##NY7dCsMwCIXv9xSjVwoOEtPuB9qHGWkduVgKoRl5@8xAiuj5PCqYqlznW5Uc/RH2CAXX8P7AGkRC/MGejy1BoULDsgyIWAVi/m4peDCIFwEPI3d4kEZna4gNuXNnIsukXqsNus16YelJrNm1T5z2o@ZEL3Xvqq6xPvAH "R – Try It Online")
Oddly, returning a zero-based index is shorter in R.
[Answer]
# [R](https://www.r-project.org/), ~~62~~ 43 bytes
```
x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
```
-19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation
**Original**
```
x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z
```
I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.
`r<-table(x)` counts the number of times each number appears and stores it in r, for future reference
`names()` gets the values of each unique entry in the table, and we iterate over these names with a for loop. 
The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration) 
[Try it online!](https://tio.run/##K/r/v8K2yrY4OTFPQ9M6Lb9II1MhM08hLzE3tVijyEa3JDEpJ1WjQlNTsyq6PCMzOUOjwtY2UzPW1tCqKDoz1rrqvymXoRGXoQGYBDH@AwA "R – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 44 bytes
```
([]#)
x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
_#e=e
```
[Try it online!](https://tio.run/##XU/NToNAEL7zFBPwAOlW@Wm1Nt2TV28e140hdPoTKWB3m1LSsw/gI/og4ixdGpQFZub7G9ik6h3zvF3x19YX0guc2vNP8ybg6rAT0TldjGuWcn6Sc4LrwGucNw85trt0WwCHZekAKPw4YJEhYJ3uqhwVYf7355eQAdzCHtMl8MUC1qifykJjoZXj1ApIAY2ikOqgX/T@uYAbUJvyCMSNRuB2Ate0HXrqUKwrzDQuacVxg3ukCobisCJfNw0k5job@o6bVaRyX7XfC@aD9OayM3CvrlJT/nGr0Lhcx@l/DjhJBAjZfZ@QNDEQk9jOoQUeGJ0eYxGLLR6FLA5ZEl4pOpaasihmxJu3aYYSk8AiK4wpO2IzQmZ9/aM16qhzxCyxnoTmCT1T9kjoPdXE9P92DP12n2xFl3a52bWXP9kqT9eqHWdV9Qs "Haskell – Try It Online")
## Explanation
Traverses the list from left to right keeping the list `x` of visited elements, initially `[]`:
For every encounter of a `y` count all equal elements in the list `x`.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 15 bytes
```
*>>.&{%.{$_}++}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwX8vOTk@tWlWvWiW@Vlu79r81V3FipUKaRnSsJpxpYoTEMdcBQiS@oYGOkYGOsQGSkKmOoZEOUBxEghhIUkZA3YY6FjpGQAylkWSNgWImQGyqYwmUMQPSxiA2UMV/AA "Perl 6 – Try It Online")
You can move the `++` to before the `%` for a one based index.
### Explanation:
```
*>>.&{        }  # Map the input to
      %          # An anonymous hash
       .{$_}     # The current element indexed
            ++   # Incremented
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~47~~ 46 bytes
```
(#(*0))
(x:r)#g=g x:r# \y->0^(y-x)^2+g y
e#g=e
```
[Try it online!](https://tio.run/##XU/NToNAEL7vU0yoB7BbhaXV2nS9ePXmkdKE0CltpIDsNoXGsw/gI/og4ixCg7JhZ@b7mQ92kXrFNG22ctXYI/vadRxmV4vSGSUyAWpGsKonj@7aria1sxbjBGqGRGJziPYZSNjkDEDh2xGzGAGr6FCkqAizvz4@g9CBGygx2oBcLiFB/ZRnGjOtGKsUkALOipYUR/2iy@cMrkDt8hMQNx6D1Qos07Zo3aJYFRhr3FDEaYclUgVDSdiSr50GEvO8G/pWmihSWStt94LFYPv5N9OxLq5c0/7TXqFxWYz1PweSJAEEYft9QUgTh2AqutntgHtOp8e4x0WHey4XLvfdC0Wno2bcE5x4c5tmKDEbuNcJBe32@JyQeV//aI3aax2C@53Hp3lK74w/EHpH1Tf9v4yhv8sLmyD8jrdplKhmEhfFDw "Haskell – Try It Online")
A different approach than [BMO's answer](https://codegolf.stackexchange.com/a/178549/56433) which turned out a bit longer. (And kindly borrows their nice test suit.)
The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function `g`. Ungolfed:
```
f (const 0)
f g (x:r) = g x : f (\ y -> if x==y then 1 + g y else g y) r
f g []    = []
```
Two interesting golfing opportunities arose. First for the initial value of `g`, a constant function which disregards its argument and returns `0`:
```
const 0  -- the idiomatic way
(\_->0)  -- can be shorter if parenthesis are not needed
min 0    -- only works as inputs are guaranteed to be non-negative
(0*)     -- obvious in hindsight but took me a while to think of
```
And secondly an expression over variables `x` and `y` which yields `1` if `x` equals `y` and `0` otherwise:
```
if x==y then 1else 0  -- yes you don't need a space after the 1
fromEnum$x==y         -- works because Bool is an instance of Enum
sum[1|x==y]           -- uses that the sum of an empty list is zero
0^abs(x-y)            -- uses that 0^0=1 and 0^x=0 for any positive x
0^(x-y)^2             -- Thanks to  Christian Sievers!
```
There still might be shorter ways. Anyone got an idea?
[Answer]
# [Java (JDK)](http://jdk.java.net/), 76 bytes
```
a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}
```
[Try it online!](https://tio.run/##hVFdT4MwFH3fr7ghMQFXCB9T5zowxmeffCQ81A5mZymkLTPLwm/HUpySGGPS3p6ec3pvb3sgR@Ifdu8Dq9tGajiYfdBpxoNrvPjFVZ2gmjViFCknSsEzYQLOC4C2e@WMgtJEm@XYsB3URnNftGRinxdA5F551grw1AjV1aXcMqHzIoMK0oH42blqpGso4CkJeCn2@g0xRDH3/SzEJOdFSr3RQ1OWhphtOfboMrWCiWy5LB6iTYj7AdsyRyJBl0orSEGUH2Cr5cV0B4Az9OgbruL57g7ZMaeiEEFsZhLO2RsEUYysaFeL54bYZooQrNGI13M89yVWWNlokt5bx63FycRc3P3UnA3jY1y63Ey9Xt4Y4OWkdFkHTaeD1nyCrlznyk9CBX4GDoJHKclJBbqZvsgdT3uBLFtOaOk6xuI4noe/klUBobRs9WTDf5Tgwv0/Lfzk7Rfj7IdP "Java (JDK) – Try It Online")
## Credits
* -2 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
[Answer]
# [Tcl](http://tcl.tk/), 48 bytes
```
proc C L {lmap n $L {dict g [dict inc D $n] $n}}
```
[Try it online!](https://tio.run/##LY7NCsIwEITveYo59AGSTevPuR59g7YHiSCFGoPGU9hnj5Miy@x8OwwkOWy1pvcrYMQVZXveEiI64n0NGQ9Mu68x4IIuLpRq3WvsmKKm9MJ1BIfuLMTCW@IAJ@DddgNGwpbDCUL9nakn99SAM5MD3TdWGEVJ3/zBXKaRn1pmvv0D "Tcl – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 34 bytes
```
->a{r=[];a.map{|x|(r<<x).count x}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6xusg2OtY6US83saC6pqJGo8jGpkJTLzm/NK9EoaK29n@BQlp0dGwsF5g2MYKxzHWAEMYxNNAxMtAxNoDxTXUMjXSAgiASxICJGwE1GepY6BgBMZSGSRkDBUyA2FTHEihsBqSNQezY2P8A "Ruby – Try It Online")
[Answer]
# bash, ~~37~~ 24 bytes
```
f()(for x;{ r+=$[a[x]++]\ ;};echo $r)
```
[TIO](https://tio.run/##NYo7CoAwEER7TzGFhZImH78ET6IWKgY7ITaCePY4W8iy894Ouy7XkVIoyiKcEbd/ENWQj8t4z0rNE/zr9@04kccyhSygsoxWhjQaVsNpag1j5ZYUYWX5ZdCR3U@2jl5xa/RsGtKJpw8)
if valid, there is also this variation, as suggested by DigitalTrauma
```
for x;{ echo $[a[x]++];}
```
[TIO](https://tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/Df@bALHpf8v/Rv/NgLQxiA0A)
[Answer]
# Perl 5, 11 bytes
```
$_=$h{$_}++
```
[TIO](https://tio.run/##K0gtyjH9/18l3lYlo1olvlZb@/9/Yy5DLhMgNuWy5DLiMgPSxiD2v/yCksz8vOL/ugU5AA)
explanations following comment
* `$_` perl's special variable containing current line when looping over input (`-p` or `-n` switches)
* `$h{$_}++` autovivifies the map `%h` and creates an entry with key `$_` and increments and gives the value before increment
* the special variable is printed because of `-p` switch, `-l` switch removes end of line on input and adds end of line on output
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 32 bytes
```
a->p=0;[polcoeff(p+=x^t,t)|t<-a]
```
The \$k\$-th element in the answer is the coefficient of the \$x^{a\_k}\$ term in the polynomial \$\sum\_{i=1}^kx^{a\_i}\$.
[Try it online!](https://tio.run/##LYrbCsIwEER/JfQpwQ3k0npB0x8pERYxUijtUvKg4L/HXZBlZs4MS7jP9kWtqNTQjpTcdaJteWzPUjQd0vteoZpvvVnMDYmWj0ZlR0X7vFbGTkqnikZjQE1TZuuD@An4BLyD4CA64QF8AB7EBWQL/OjhDIH1T5kjl541wIWnI2cUztm0Hw "Pari/GP – Try It Online")
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 23 bytes
```
{`~&>Zip[_,_[0:#_::0]]}
```
[Try it online!](https://tio.run/##NYs7C0IxDIX3/oqC4pShj3t9FHRxFwcnS6jl2qt3kWK7if71mqJNSM45X4jP2Q/3UEZutry8Lp/F7jxF68BZYWbOGIH4LocQrsnOYxxuyI7P6ZFPIeW9TyHZEbhlnMoi/LRTza2AugUpQAnQouUepAKCdVfTuKInCWtQNH9tJ02go@lhQ3hJqqtHhli@ "Attache – Try It Online")
## Explanation
```
{`~&>Zip[_,_[0:#_::0]]}
{                     }    _: input (e.g., [5, 12, 10, 12, 12, 10])
             0:#_          range from 0 to length of input (inclusive)
                           e.g., [0, 1, 2, 3, 4, 5, 6]
                 ::0       descending range down to 0 for each element
                           e.g., [[0], [1, 0], [2, 1, 0], [3, 2, 1, 0], [4, 3, 2, 1, 0], [5, 4, 3, 2, 1, 0], [6, 5, 4, 3, 2, 1, 0]]
           _[       ]      get input elements at those indices
                           e.g., [[5], [12, 5], [10, 12, 5], [12, 10, 12, 5], [12, 12, 10, 12, 5], [10, 12, 12, 10, 12, 5], [nil, 10, 12, 12, 10, 12, 5]]
     Zip[_,          ]     concatenate each value with this array
                           e.g., [[5, [5]], [12, [12, 5]], [10, [10, 12, 5]], [12, [12, 10, 12, 5]], [12, [12, 12, 10, 12, 5]], [10, [10, 12, 12, 10, 12, 5]]]
   &>                      using each sub-array spread as arguments...
 `~                            count frequency
                               e.g. [12, [12, 10, 12, 5]] = 12 ~ [12, 10, 12, 5] = 2
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~65~~ 62 bytes
```
c,d;f(a,b)int*a;{for(;c=d=b--;a[b]=d)for(;c--;d-=a[c]!=a[b]);}
```
[Try it online!](https://tio.run/##JUtLCsIwEN33FLUgZGwCrWA345wkZDGdUJmFVYq7kLPHRDfv/8Q9RMqTdTeQOt0/PftA6Wbnq52nHzaRsdsM2wUqvw7TdkoT6n1BHUd4HzXZzHCO/WDZa6i7XMRGbK8VanthTO2KQpFW55D9GijCP6s@OmIv4UStAMylfAE "C (gcc) – Try It Online")
-2 bytes thanks to [ASCII-only](https://codegolf.stackexchange.com/questions/178500/enumerate-each-series-of-identical-numbers-in-place/178724?noredirect=1#comment430784_178724)
---
This felt too straightforward, but I couldn't seem to get any shorter with a different approach.
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), 18 bytes
```
(,/.!'#'=x)@<,/.=x
```
[Try it online!](https://tio.run/##y9bNS8/7X2FlrGCoYALEpgqWCkYKZkDaGMT@r6Gjr6eorqxuW6HpYANk21b8/w8A "K (ngn/k) – Try It Online")
---
**OLD APPROACH**
# [K (ngn/k)](https://gitlab.com/n9n/k), ~~27 23~~ 22 bytes
```
{x[,/.=x]:,/.!'#'=x;x}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/NqroiWkdfz7Yi1gpIKaorq9tWWFfU/k9TMFYwVDABYlMFSwUjBTMgbQxi/wcA "K (ngn/k) – Try It Online")
---
this is not pretty... quick and dirty solution, i will be refining this later when i get the chance to think of a better approach
explanation:
* `=x` returns a dict where keys are items of x and values are their indices (`3 1 4 5 9 2 6!(0 9;1 3;,2;4 8 10;5 11;,6;,7)`)
* `i:` assign dict to `i`
* `#:'` count values for each key (`3 1 4 5 9 2 6!2 2 1 3 2 1 1`)
* `!:'` enumerate each value (`3 1 4 5 9 2 6!(0 1;0 1;,0;0 1 2;0 1;,0;,0)`)
* `,/.:` extract values and flatten list (`0 1 0 1 0 0 1 2 0 1 0 0`)
* `x[,/.:i]:` extract indices from i, flatten, and assign each value from the right-side list at these indices
annoyingly, the list is updated but a null value is returned by the assignment, so i need to return the list after the semicolon (`;x`)
**edit:** removed extraneous colons
**edit2:** removed unnecessary assignment 
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
KƛtO
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJLxpt0TyIsIiIsIls1LDEyLDEwLDEyLDEyLDEwXSJd)
`KƛṫO` is also valid for 4 bytes
Simply count the number of occurrences of the tail of each prefix in each prefix.
[Answer]
# [Factor](https://factorcode.org/), 48 bytes
```
[ dup [ head [ = ] with count ] with map-index ]
```
[Try it online!](https://tio.run/##PY5BDoJADEX3c4p/AQ0MoKhxbdy4Ma4ICwI1EHUYhyFqCGcfCwHatO/3N016z3JbG3e7ni@nPR5kFD3R0LsllVMDbcjanzaVsjgI0QlwdOgnhnKR2zHnyfcgPQTeYkTw5eAOfRTzQvKVj5gZL5x3ATshV4Qd@xtmMOpe9C5B0WokKCkrGEek@FS2RF63/Os0vDK9qlRBX6SONdbuDw "Factor – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
z#ḣ¹
```
[Try it online!](https://tio.run/##yygtzv7/v0r54Y7Fh3b@//8/2lTH0EjH0ABMghixAA "Husk – Try It Online")
### Explanation
one-indexed
```
z#ḣ¹  transforms to z#ḣ⁰⁰
z     zip
  ḣ⁰  prefixes of input
    ⁰ and input
 #    with count
```
]