[Question]
  [
Very recently, I changed my SE username because I made this account some years ago and wanted to get back into asking questions. However, I’m still planning to post questions and potentially earn votes. We can imagine a site that has some issues dealing with name changes. The problem: given a list of names, reputation changes, and name changes, can you create a leaderboard of reputation? **Assume everyone's reputation starts at 0.**
Input comes in any reasonable format, and has two forms: a *name change* `<String, String>` and a *rep change* `<String, Number>`.
What does *any reasonable format* mean? When I write questions, it usually means the input can be rearranged or repackaged to work with the way your language takes in input (do you want a list of pairs? two lists? a string? that’s all fine) as long as it doesn’t add information or otherwise offload some of the computational work onto the human.
Name changes change a person’s username to any username *not currently in use.* For example, if A changes name to D, and B changes name to C, D (previously known as A) could still change their name to A or to B, even though these names have been used before. However, at any given moment the set of names are unique.
Rep changes represent something like getting up/down votes on a post, receiving a bounty, etc. All rep changes are guaranteed to be integers. They might come in the form <“Bob”, 5> or <“Alice”, -53000>. At the end, you must output all usernames that are currently in existence, and their rep counts, in descending order.
Test case:
```
Alice 5
Bob 7
Bob John
John 113
Alice Cheryl
Daniel 13
John Alice
Alice 12
```
Result:
```
Alice 132
Daniel 13
Cheryl 5
```
Test case, suggested by Unrelated String:
```
Jimmy Adam
Donald 12
Amelia -11
```
Result:
```
Donald 12
Adam 0
Amelia -11
```
Test case:
```
CodegoLfer65 12
Bluman 9
CodegoLfer65 n4me
n4me -3
```
Result:
```
Bluman 9
n4me 9 (note: these two can be in either order)
```
Usernames are composed of only [A-Za-z0-9], i.e. alphanumerics. However, the input will not be a number in your language. This means usernames like `144`, `015`, `0x0F`, `1e7` will not appear in the input. Numbers such as `1/3`, `2.8` do not appear due to the character specification in the first place.
This question seems heavy on data structures, so golfing languages may not perform as well. Maybe other languages will have a fighting chance? Scoring is by lowest number of bytes, i.e. tag:code-golf .
  
[Answer]
# [Python 3](https://docs.python.org/3/), 115 bytes
```
def f(l):
 r={}
 for n,m in l:q=m*0!=0;r[[n,m][q]]=r.pop(n,0)+[m,0][q]
 return sorted(r.items(),key=lambda i:-i[1])
```
[Try it online!](https://tio.run/##VY69bsMgFIV3nuJ2AloSmVpRJVcMSTvlFRADqbGMyo9D6GBVfXaXkFRyt3OOvu/qTnMeY2iXpTcDDMTRDkES3z8IhpggMA82gOvOwj82D6J5TVKWUcmzUiJtpziRwBr6JD1rrmORTf5KAS4xZdOTtLXZ@Auh7NPMwml/6jXYbmMlV3SZkg2ZDEQiiffOfhjMYKdYaYd4KvlllfExjgHXoSYGnLe1/pn4bTRpdjfmXQdr3JVq184d/ufxZ4UUpWj9zdF6P1e@1/5@MQbt@htfdW@c1aVvOC9DubD8Ag "Python 3 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~102~~ ~~101~~ ~~95~~ ~~94~~ ~~93~~ 90 bytes
```
->c{l={};c.map{|a,b|x=l[a]||0;b*0!=0?(l[b],l[a]=x,p):l[a]=x+b};l.compact.sort_by{|a,b|-b}}
```
This takes input in the form of a list of `["name", "new_name"/score]` pairs. And it outputs in an ordered list of `["name", score]`
Golfy Tricks 
* I used `p` with no args to get a `nil` value.
* ~~I used `String===b` instead of `b.is_a?String`~~
* ~~I used ~~`b!=b.ord`~~ `b.ord!=b` to find out if it's a string or not. See [`String.ord`](https://ruby-doc.org/core-2.4.0/String.html#method-i-ord) and [`Integer.ord`](https://ruby-doc.org/core-2.5.0/Integer.html#method-i-ord)~~
* I'm using `b*0!=b` to check if it's a string or not.
* For some reason, `b.ord!=b` means that I don't need a space between the `?` ternary operator and the following `(`, but if I swap it to `b!=b.ord`, then another whitespace is needed.
* I sorted by `-b`, rather than by `b` and then reversing (d'oh!)
## [Try it online!](https://tio.run/##pZHfaoMwGMXvfYosV@0WRefc2MSNtbsqewORkcRYhcSIbaGiPruLf9vZMQbNVc6PL@fk8OUHUjQR8ECjv9KSe2XtUkPgrKwwItXR4z4Oqsp0ya1545lvC@6TALXQO6Js@dLf7kjtcoNKkWG6N3Yy33@RonfQSV03NMbplu1Uiq8BdXz4zhPKIAJOgAaykkTpp5mGGxmncIKdQsCy7AmNTnAds7zgp9kPnCaMt9P2/P3w6MLDulco0DIQGRRzvhj@vdS0ywabRIii8wqxOEuVKebh6DXYC8YTrJhuWf8PWMuQbeVnxPJH56ffih8Ebns8T2g2DNMHcdavUyrevrreiK9u16/X@XvdPbTM322bbw "Ruby – Try It Online")
Edit: Thanks to [Veskah](https://codegolf.stackexchange.com/users/78849/veskah), for pointing out some problems this solution was missing. Somehow adding a temporary variable to hold `l[a]||0` has shortened the code by a byte.
Edit: Thanks to [G B](https://codegolf.stackexchange.com/users/18535/g-b), for suggesting `b*0!=0` instead of `b.ord!=b`, which also allowed me to get rid of the space before the `?`, saving 3 characters.
[Answer]
# [PHP](https://php.net/), 111 bytes
```
for(;$n=$argv[++$i];+$r&&$a[$n]+=$r)if(!+($r=$argv[++$i])&&$a[$r]=+$a[$n])unset($a[$n]);arsort($a);print_r($a);
```
[Try it online!](https://tio.run/##bVDLbsMgELzzFTRCsRHOwY2qHqhV9XHKLzgoog4JSBistVPJqvrtro2txKm8B7QzzAzLVrrqXl4rXSFEGlU3Nc5wjnBf4zlU9GZNoaIER09RcmPf/dfAPS9wO6/dnB4xjtJ0O6evuR9aQWvnV5/SGWWDZ7uUNFkXstLHiRbJ/3/sTFm2wX2U5d1r3kl7vHOPoaWyRg78Jk1vsYIjdPKgZKFxPK1N1jh0FP8EGZFw/u6XKQFkeygVnFWcu4u1IpmEvOszYk5cFrQ5Y8QIzgis10TmxAmWEaDmFD@wmMBcREcFiIyNSnpxtWriCXAJtYcBUl6Bcc0BQt8Nc6lCe7zau8219m7Fw8hTiKF3sDei3@4P "PHP – Try It Online")
Inputs are command arguments (`$argv`) as a plain list like: `Alice`, `5`, `Bob`, `7`. Every item is a separate argument.
### Commented
```
for(;
  $n=$argv[++$i];    // $n is set to the first parameter (name) for each event
  +$r&&$a[$n]+=$r)   // at the end of each iteration if $r is a number
                     //   add it to reputation of $n
  if(
    !+(
      $r=$argv[++$i] // $r is set to the second event parameter (name or reputation change)
    )&&
    $a[$r]=+$a[$n])  // if $r is a name, transfer reputation of $n to $r
      unset($a[$n]); //   and remove $n from $a
arsort($a);          // after the loop, sort $a by its values in descending order
print_r($a);         // print $a as string
```
---
# [PHP](https://php.net/), 98 bytes
This one shows non-existing users too (at the end of the list), but shows nothing as their reputation.
```
for(;$n=$argv[++$i];arsort($a))+($r=$argv[++$i])?$a[$n]+=$r:[$a[$r],$a[$n]]=[+$a[$n]];print_r($a);
```
[Try it online!](https://tio.run/##bZDfaoMwFMbv8xShBFS0F66MwTIp@3PVV0hDyWzWBGIiRzuQsWd3Jkqrw3MRzvnlfN85Sa3q/mVfqxoh0sqmbXCBGcJDjKeP6NXoUkYZjh6j7E7f3KdnTyvs4JSd47HGUZ7v5vjm@64kdGZ@9SGsliZodmtOk3TFK3@YMM/@v@Ogq6oL6rOoFtOcFea8UI@mlTRaeL7N87stpwh9OZCiVDievk00OGQJ/gltRMDle/hMASC6UyXhImNmr8bwbGqk/eARU2KL0MvSlGhOBTQO2piIJEljAvO7ZE8EI5anBYFn5nPg2Yh4wdIpozVo257AW9DeryJL5fDmaLe3ONoNDVtebSOHYTpZlIMQ/fZ/ "PHP – Try It Online")
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 65 bytes
```
{(>x)!x@>x}(0#`!0){(n;a):y;$[`i~@a;@[x;n;+;a];@[x;a;:;0^x@n]_n]}/
```
[Try it online!](https://ngn.bitbucket.io/k#eJxVjd1qAjEQhe99CqW9yCDipmqlOyCr9kr6BrI2o5vVQDIBoZBF7LN3k7WiV3N+vsPU+UUsAgxCsQhXkb2oQQYXwUiQN/i6Vea3ICy2ARmHSGWShDlmu1Bw+c3lddzr1X0h1NKag8YZYF+old/j/K7Uxp84uShQykky3UCtT/rc2JR8Ehtt8dYnuKMeePkG0D3cGOeaFqjIAbZjz2Sr2Ldm6bQ1hCMp/+m1r/TRf9X6/D67QSv744jxI+qnWvHU6ZjGi6MJwB8+Rlcl)
Input is taken as a list of pairs; user names are symbols (rather than strings).
* `(0#`!0){...}/` set up a reduce, seeded with an empty dictionary (mapping symbols to integers) that tracks the active usernames and their respective reputation scores
* `{(n;a):y;...}` destructure the next pair into its `n`ame and `a`ction
* `$[`i~@a;...;...]` check whether or not the `a`ction is an integer (representing a reputation change) or not
* if the action was a reputation adjustment...
	+ `@[x;n;+;a]` add the reputation change to that user (if this is the first time the username appears, use `0` as the fill element)
* if the action was a username change...
	+ `@[x;a;:;0^x@n]` carry over the reputation from the previous name to the new name (if the prior name didn't have any reputation or name changes yet, set its reputation to 0)
	+ `..._n` delete the old user name from our reputation tracker
* once done handling the reputation/name changes...
	+ `{(>x)!x@>x}` sort the users by their reputation, descending (outputting both the username and their "final" reputation)
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-rS`, ~~71~~ 53 bytes
```
{IaNI@ZllPB[a0](lY@Zl@?a1)+:bI+bNEb(ly0):b}MUg^sRVSNl
```
[Try it online!](https://tio.run/##K8gs@P@/2jPRz9MhKicnwCk60SBWIycSyHGwTzTU1LZK8tRO8nNN0sipNNC0Sqr1DU2PKw4KC/bL@f/fMSczOVVB15TLKT9JwRxMeuVn5HGBCAVDQ2Mux5yc1DwF15T0xCIuiGLnjNSiyhwul8S8zNQcBaASsFqwHFSFodF/3aJgAA "Pip – Try It Online")
I'm gonna golf this some more before writing a thorough explanation. The basic idea:
* Keep a list of [name score] pairs in `l`
* Loop through the lines of input, split on spaces, using `MU` (for each line, the first item is `a` and the second item is `b`):
	+ If `a` is not one of the names in `l`, append `[a 0]` to `l`
	+ Add `b` to the score in `l` associated with the name `a` (if `b` is a name, this adds 0\*)
	+ If `b` is not a number, change the name `a` in `l` to `b`
* Once the loop is done, sort `l` in descending numerical order (since all the names are 0 in numeric context\*, this sorts by the scores)
\* Assuming that no names start with a digit, which I argue is the best Pip-specific interpretation of ["whatever the input is, it won't be able to be parsed as a number."](https://codegolf.stackexchange.com/questions/195022/whos-who-in-the-name-change-game/226382#comment464627_195022)
[Answer]
# [Haskell](https://haskell.org), 253 bytes
```
import Text.Read
import Data.List
m l(k,d)=maybe((d,o):n)(\a->(k,a+o):n)(readMaybe d)where o=maybe 0id(lookup k l);n=filter(\(x,_)->x/=k)l
f v=sortBy(\(_,x)(_,y)->compare y x)$filter(\(x,y)->maybe("",0)id(find(\(a,_)->a==x)r)==(x,y))r where r=foldl m[]v
```
The function takes a list of String pairs and returns a list of `(String, Int)` pairs
## Full programme, **355 bytes**
```
module Main where
import Text.Read
import Data.List
m l[k,d]=maybe((d,o):n)(\a->(k,a+o):n)(readMaybe d)where o=maybe 0id(lookup k l);n=filter(\(x,_)->x/=k)l
main=getContents>>= \c->let r=foldl m[]$map words$lines c in putStr$unlines$map(\(x,y)->unwords[x,show y])$sortBy(\(_,x)(_,y)->compare y x)$filter(\(x,y)->maybe("",0)id(find(\(a,_)->a==x)r)==(x,y))r
```
The programme takes input as specified in the testcases via STDIN
## [Try it online!](https://tio.run/##TZDBasMwEETv/ool@GBRJ01aSqFFhiY5lebS9paEoFhKLbySjCwT@etdWW6glwHtvF1mVLG2FojDoAzvUMCOSQ3XSliRSNUY6@BbeLf4FIzfBlvm2OJDti5RgPs650eqWH8WWcZzQ140yQ5sXmR1zu6mpw3Lu5EATuJpMNMGLCXP0Ji6a6AGJK@aXiQ6YbND5vMTmRf@ntYEExVS0R/hNkY7oV1bFBQO5bxA4cDSi0GOoPbHVLEGrsbyNkWpRQslhDZN576cTTsdZyMTz/fhfKcjvfd5W5kr9EeStqHiug/EKfckyIiVRjUsxO7Bk/RfwtGbqs9m@ZKEMhepebBYDM8o9cQSSiNK7DC8oSwFPCVrc4bnqO@m0skosFo9JpO/CX/UY7JlWgqEMI5@9P6I1cMv "Haskell - Try it online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 118 bytes
```
a=>a.flatMap(v=>([p,q]=v,u=a[p])?(q+-q?a[a[u[0]=q]=u,p]=0:u[1]+=q,[]):[q+-q?a[q]=[q,0]:a[p]=v]).sort((a,b)=>b[1]-a[1])
```
[Try it online!](https://tio.run/##VZFbT8IwGIbv9yt6YUIbusFENM50hMONRP0DtYZvrIOZHnYO/HrsJiR68y55n@f90mTf0EG9r/Ki8Y1N5SVjF2AxBJmC5h0K3LEY84KWgnW0ZcALQRa4HPvlAjjwlk8Fc6ylhWDTqOWhGLOSckEifpUc5SWdiqjfsk6QoLZVgzHQhLA4cQsfXJBLI@sGMVQjFqO9NbVVMlD2gDNcB02Va@yWhcobPPo0IxJo97hT755uNRqR3xrzEz0Ld919J1/@4jMd302C/j4@k8VHqxNZBQVUtXw1rqLhlETOJ@TFG6Sdt1T5XqK5t7IJehpya4/G6wOF4ezK10dZnZW3AZNLhVw98IFdjfDe25Hb0W2u9RktU9DexhpQaY@XWqockB@Gf8y1@xMH@5bJ6nHeSyvVajDo@T8wD1p6fSB/5saXHw "JavaScript (Node.js) – Try It Online")
Expect input `([string, string]|[string, number])[]` type.
`q+-q` is used to test whether `q` is a number or string. if `q` is number, `q+-q` will be falsy. If `q` is string, `q+-q` will be truthy.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 48 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
¯svÐ˜y`Uk;©di®èX.ïi`X+‚ëy`:}®ǝëX.ïiyëX¾‚}ª]Σθï}R
```
Input as a list of pairs.
[Try it online](https://tio.run/##yy9OTMpM/f//0PrissMTTs@pTAjNtj60MiXz0LrDKyL0Dq/PTIjQftQw6/DqygSr2kPrjs89vBosXAmkD@0DytQeWhV7bvG5HYfX1wb9/x8dreSYk5mcqqRjGqsTreSUn6SkYw5nKXnlZ@Qpgbhgho6hoTGIA9Wh5JyRWlSZA5Z3SczLTM0BqjBGqIaqQ9JhaBQbCwA) or [verify all test cases](https://tio.run/##yy9OTMpM/V@m5JlXUFpipaBkX6nDpeRfWgLj/T@0vrjs8ITTcyoTQrOtD61MyTy07vCKCL3D6zMTIrQfNcw6vLoywar20Lrjcw@vBgtXAulD@4AytYdW1daeW3xux@H1tUH/dQ5ts/8fHR2t5JiTmZyqpGMaqxOt5JSfpKRjDmcpeeVn5CmBuGCGjqGhMYgD1aHknJFaVJkDlndJzMtMzQGqMEaohqpD0mFoFBurowC00yszN7cSpCIlMReiPz8vMScFrAKkPDc1JzNRSUfX0JB0DSAuSJUOeXqhqmGanfNTUtPzfdJSi8xMYTqcckpzE4EetARxUBUo5ZnkQrwMZujoGkPNAYenKZaQBXMNDaDKEAEFCTWwFIyp5JNYWpQK0QZhgtVaxMbGAgA).
**Explanation:**
```
¯                # Start with an empty list: []
 sv              # Loop over each input-pair `y`
   Ð             #  Triplicate the current list
    ˜            #  Flatten it
     y`          #  Push the key and value of the current item `y` separated to the stack
       U         #  Pop the value, and store it in variable `X`
       k         #  Get the index of the key in the flattened list
        ;©       #  Halve it, and store it in variable `®` (without popping)
    di           #  If this index/2 is non-negative (>= 0):
      ®è         #   Get the `®`'th pair from the current list
        X.ïi     #   If `X` is an integer:
            `    #    Push the key and value of the indexed pair separated to the stack
             X+  #    Add `X` to the value
               ‚ #    And pair the key and this new value back together
           ë     #   Else (it's a rename):
            y`   #    Push the key and value of the current item `y` separated to the stack
              :  #    And replace key with value in the indexed pair
           }     #   After the if-else:
            ®ǝ   #   Insert this modified pair at index `®` back into the list
     ë           #  Else (the current key doesn't exist yet):
      X.ïi       #   If `X` is an integer:
          y      #    Simply use the current item `y`
         ë       #   Else:
          X¾‚    #    Pair `X` with 0
         }       #   After the if-else:
          ª      #   Append this new pair to the list
  ]              # After the loop:
   Σ  }          # Sort the resulting list in ascending order by:
    θ            #  The last item of each pair (the values)
     ï           #  Casted to an integer (because the `:` might have made it a string)
       R         # And then reverse this sorted list to make it descending
                 # (after which it is output implicitly as result)
```
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html) (with shell callout to "sort"), 105 bytes
```
b=$1,d=$2{g=f[b]=d+0==d;f[d]=!g;g?m[b]+=d:m[d]=0+m[b]}END{for(n in m)if(f[n])print n" "m[n]|"sort -k2rn"}
```
[Try it online!](https://tio.run/##VYnLCoJAFED38xW3wYVigk4ZlFyCHrvoB8SFMs4gNndiMlqY3z7pss2Bc0796b1vMMjWEgMxalRlU6GMU0RZqFJWuNKFPpq5xigPZilpvOh0vV9GZV1I0BGYqFOhKqmKnq6jAYgDN7N@@cu6AZJeOOKT92crW21vqnW7HDLBTo@3qQn27G/Q1rRsASSbHw "AWK – Try It Online")
This one builds two arrays, one with the score for a give name, and one that's a boolean flag indicating if a name is active or not. At the end, the code prints the reputation scores for all the active accounts and pipes those lines to a `sort` call. Sorting things in AWK is a nightmare...
Here's a description of the components.
```
b=$1,d=$2{                                              }
```
This test/code-block runs for each input line. The `b=$1` and `d=$2` are just a shortcuts for positional variables used repeatedly in the code. The first one is always truthy, so the code block runs even if the reputation is `0`.
```
g=f[b]=d+0==d;
```
The first expression sets the "is an active account" flag (the `f[]` array) to true or false depending on whether or not the second token on the input line is a number. The test `d+0==d` catches that since AWK converts a non-numeric string to `0` if you try an use it as an integer in a mathematical expression. And `g` is set just to shorten the code when `f[b]` is needed later.
```
f[d]=!g;
```
The "is an active account" flag for the second token is the opposite of the value computed for the first token. That will set some garbage entries for input lines that have a numeric reputation as the second token, but they will be ignored.
```
g?m[b]+=d:m[d]=0+m[b]
```
This ternary sets increments the reputation counter (the `m[]` array) for the first token if we got a numeric second token. Otherwise it sets the reputation token for the second token to the reputation token of the first token. In other words, it copies the reputation to the new name.
```
END{for(n in m)if(f[n])print n" "m[n]|"sort -k2rn"}
```
Once all the input lines have been handles, the code loops through all the names in the reputation array `m[]` and for any that are active users per the `f[]` array, it prints the name and final reputation. The `sort -k2rn` command sorts the whole set and prints the output.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 132 bytes
```
/.* -?[0-9]/{a[$1]+=$2}
!/.* -?[0-9]/{a[$2]=a[$1]+0;delete a[$1]}
END{PROCINFO["sorted_in"]="@val_num_desc";for(k in a)print k,a[k]}
```
[Try it online!](https://tio.run/##XcpPT8JAEIfh@3yKseGgaIUtoiGk0dJqIjFgvDabZmUH2XT/mKVoCOlnr7Zw0cubzO8Z8V02zeC6j@F9PgwnfHAQeY/xy7gX1XD2HyIeH3k4laSpIuzOGh4X2eH1bZk@L56WebB1viJZKBvwOHj4ErqwO1NI2q6C6dr58xKVRXHx6ZWtsLwSecnrpkm0WhGOYebe8a7r3G0stEHGRnD0dEN@ryETVpHG37nzzk4fLIK5MmaPiRQGMmeFlu2YGNJKYMgYpE7Sh3tZk78dtzTTOyMsTv6CvTEEbTAcwQ8 "AWK – Try It Online")
We're careful to `+0` to make sure the new name has reputation.
The hardest part of this problem is printing the list out sorted by values. Thankfully, GNU Awk has an array called `PROCINFO`, and by writing the special value `"@val_num_desc"`, the array will be `num`erically sorted in `desc`ending order by `val`ue.
[Answer]
# [Perl 5](https://www.perl.org/) `-a`, 114 bytes
```
$_=pop@F;/^-?\d+$/?$k{$F[0]}+=$_:($k{$_}=$k{$F[0]}+0,delete$k{$F[0]})}{say"$_ $k{$_}"for sort{$k{$b}-$k{$a}}keys%k
```
[Try it online!](https://tio.run/##RYpNC8IgAEDv@xUyDIpl02CXQtYgdgj6BX2IQ4MxnTK9yPCvZ4ygTo/3eFZOqkoJMmqNPbXH8onquyhgWcNhhu0NP2JBITusF2WR/iveCqmkl7@yibPjIYcMfN/8ZSbgzOTnxbuIFvAYBxncakjp0msdQCO4zs5m5EoAss8aLVXPASLkbazvzegSulY7THBC/AM "Perl 5 – Try It Online")
[Answer]
# Java 10, ~~166~~ 251 bytes
```
import java.util.*;a->{var r=new HashMap<String,Long>();for(var l:a)if(l[1].matches("-?\\d+"))r.merge(l[0],new Long(l[1]),Long::sum);else{var t=r.remove(l[0]);r.put(l[1],t==null?0:t);}return r.entrySet().stream().sorted(Map.Entry.comparingByValue());}
```
+85 bytes because I hadn't noticed the output should be sorted by value.. >.>
Input as a 2D list of Strings, output as a sorted stream of key-value pairs.
[Try it online.](https://tio.run/##tZRdT9swFIbv@yuOchWvxDRj3URCQcCQNgTsAmk3pRcmcRszf0S206lC/e2d7bSMBLZJ09aLNj7nPc/56HEeyJIkD@W3DRO10hYe3Bk3lnH8Jof9fRimh2AV2IrC/crSpFCNtIOCE2PgmjD5OABg0lI9JwWFG3@EZxBjNSUC34afo2tS4wtp9erIGZhc7F0puTg@hiJuz9PZdAYE5Q6yHrgvY4llBdyAhAlsSHL8uCQa9ETS7/CJmMrxOqQY5XOlYy/iGUFsHvNpOsOC2KKiJo6Sk7u7chghpLGgekGdezTb8zQfHsQokLLMNALllBsaUtqJxpoKtWxDUK5x3dgQsGcnE9lwfjLKLMrXmtpGS9CY@j5vqY3Rdgj@wU2YlvHTGHChRE18/Werr4Q3NEYOscl973Vzz13v2xEsFStBuHk/TcrNqR22pcbG0akTUxjfySgY/WcYnal7@PDSdKkq2bV6C6TpQdfaMs8rqle86/lIJKMc@gEBE6JeA6Vvo/DX7kq@ZEKs4LQkogdXkvDSyXsQQTkjkKTpP8L07A4A/wfdYnrsc1XShbqaU/1@/IJ0xhtBJBx2rZ0Q@U70puwtkBxEL@5PWJ6QtV0eMNvVuV0ZSwVWjcW1c1gu4@izdJudwa7YVyRm59ptImeSGndDDTY1Z643V1dP41TMg53KX7etOQRiTuXCVk7Shvgb7BIBm4xyYEfPNe48HKJty4E3ZTOHDBr3uMv/u@p/7Ym@NLbTu8RFHLIg7Iq6IEUV/wzLsm3cX6VKIvc@qSmx8XiE/kBYD9abHw)
**Explanation:**
```
import java.util.*;            // Required import for Map and HashMap
a->{                           // Method with 2D String-array as parameter
                               //  and a Stream of String-Long KeyValue-pairs as return-type
  var r=new HashMap<String,Long>();
                               //  Map, starting empty
  for(var l:a)                 //  Loop over the lines of the input:
    if(l[1].matches("-?\\d+")) //   If the second part is an integer:
      r.merge(l[0],            //    Use the first part as key
              new Long(l[1]),  //    Convert the second part to an integer
              Long::sum);      //    And sum it with a potential existing value for this key
    else{                      //   Else (it's a rename):
      var t=r.remove(l[0]);    //    Remove the first part from the map;
                               //    store the current value (of null if not present) in `t`
      r.put(l[1],              //    Use the second part as new key
            r.remove(l[0]));   //    And remove the first part from the map,
                               //    which will return the current value
                               //    (or null if not present)
  return r                     //  Return the Map as result
    .entrySet().stream()       //  after we've converted it to a steam of KeyValue pairs,
    .sorted(Map.Entry.comparingByValue());}
                               //  and sorted it by value
```
]