[Question]
  [
Given a non-empty matrix of non-negative integers, answer which unique rows contribute most to the sum total of elements in the matrix.
Answer by any reasonable indication, for example a mask of the unique rows order of appearance (or sort order), or indices (zero- or one- based) of those, or a submatrix consisting of the rows (in any order) or some kind of dictionary construct… — but do explain it!
## Examples
`[[1,2,3],[2,0,4],[6,3,0],[2,0,4],[6,3,0],[2,0,4]]`:
The unique rows are `[1,2,3]`, `[2,0,4]`, and `[6,3,0]` each respectively contributing 6, 6, and 9 each time they occur. However, they occur once, thrice and twice respectively, so all of their respective occurrences contribute 6, 18, and 18 to the total (42), so the latter two rows are the ones that contribute most. Valid answers are therefore:
`[false,true,true]` mask in appearance/sort order or  
`[1,2]`/`[2,3]` zero/one-based indices of the above or  
`[[2,0,4],[6,3,0]]` the actual rows  
⋮
---
`[[1,2],[3,1],[2,3],[1,2],[3,1],[2,3],[1,2]]`
`[false,false,true]`(appearance order) / `[false,true,false]`(sort order)  
`[2]`/`[3]`(appearance order) / `[1]`/`[2]`(sort order)  
`[[2,3]]`  
⋮
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
Ġị§§M
```
[Try it online!](https://tio.run/##y0rNyan8///Igoe7uw8tP7Tc9////9HRhjpGOsaxOtFGOgY6JkDaTMdYxwAnPxYA "Jelly – Try It Online")
1-based indices of sorted unique elements of input.
[Answer]
# [R](https://www.r-project.org/), 64 bytes
```
function(M)max(x<-tapply(rowSums(M),apply(M,1,toString),sum))==x
```
[Try it online!](https://tio.run/##fY4xbsMwDEX3nIJAFglg0zguOtVDh3Rqljg9gKLIsQCbdCWqdk7vKgk6dGg34pH/8Ye5qeYmkRXPpHa6N5OaXh7EDEN3UYHHOvUxc7yDHRYoXEvwdNYYU691VU3zEvZOUqAIBo7MnTMEX84KBxi9tHDYf2wf317f6y14gshBgMPJBVCdm7zlczBD661ewWIJh9ZBIv@ZHOT/WRkcxJZHAhN/rGR6FzGbwAv4CM7ECwjnXLZGMXSCMQvbW1iysOcoYJly82OS3B6YXFysFo0KR08nZVWBGyw1WrXBNT5dh2cscf0f0fp3/ropsbgf3Fx/whydvwE "R – Try It Online")
Returns a boolean vector with TRUE/FALSE in sort order (lexicographic).  
The unique rows are shown as vector names, so it is easy to identify the most contributing ones.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
-1 thanks to FryAmTheEggman!
```
{s.MssZ.g
```
[Try it online!](https://tio.run/##K6gsyfj/v7pYz7e4OEov/f//6GhDHSMd41idaCMdAx0TIG2mY6xjgJMfCwA "Pyth – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~153~~ ~~145~~ 129 bytes
*-8 bytes thanks to @Mr. Xcoder!*
```
from itertools import*
def f(l):a=[[sum(map(sum,[*s])),k]for k,s in groupby(sorted(l))];return[v[1]for v in a if v[0]==max(a)[0]]
```
[Try it online!](https://tio.run/##dY7NDsIgEITvPgVHaPbQH@NB0yfZcMAUlFRYstDGPj2id08zk3xfMukoT4pTrY4pCF8sF6JXFj4k4tKdFuuEky91NTNi3oIMJsmWgF3WSsGqHbFYoRlRPJi2dD9kbqpdmqX0jW3ZOOKOw4/cv5wR3okdez3PwbylUa3qmtjHIp1EHGCESQOO0MO55QUm6P/udqN@AA)
[Answer]
## Haskell, 60 bytes
```
import Data.Lists
f x=nub$argmaxes(\e->sum e*countElem e x)x
```
Returns a list of the rows.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 25 bytes
```
ＩΦθ∧⁼κ⌕θι⁼×№θιΣι⌈Ｅθ×№θλΣλ
```
[Try it online!](https://tio.run/##dYvLCsIwEEV/JcsJjFBbceNKit0VBN2FLEItODjpIw/x72MsdSM4m8u590x3N64bDad0djQEqI0P0BCH3sGM4jjc4DRHwx4eKBrKmFuSEsVaX8n2Huox5udlQnGJFhalNS@yGVozfbYflVeV5fcOKSmltlhipVGVWOAu5x4rLP6y1mnz5Dc "Charcoal – Try It Online") Link is to verbose version of code. Default output format is each row element on its own line and rows double-spaced. Explanation:
```
  θ                         Input array
 Φ                          Filtered where
     κ                      Current index
    ⁼                       Equals
      ⌕                     First index of
        ι                   Current row
       θ                    In input array
   ∧                        Logical And
           №                Count of
             ι              Current row
            θ               In input array
          ×                 Multiplied by
              Σ             Sum of
               ι            Current row
         ⁼                  Equals
                ⌈           Maximum of
                  θ         Input array
                 Ｅ          Mapped over rows
                    №       Count of
                      λ     Current row
                     θ      In input array
                   ×        Multiplied by
                       Σ    Sum of
                        λ   Current row
Ｉ                           Cast to string
                            Implicitly printed
```
[Answer]
# Mathematica, 48 bytes
```
Last[SortBy[Gather[m], Total[Flatten[#]] &]][[1]]
```
or
```
TakeLargestBy[Gather[m], Total[#, 2] &, 1][[1, 1]]
```
where (for example)
```
m = {{1, 2, 3}, {2, 0, 4}, {7, 9, 5}, {6, 3, 0}, {2, 0, 4}, 
     {6, 3, 0}, {2, 0, 4}, {7, 9, 5}};
```
[Answer]
# JavaScript (ES6), 88 bytes
Outputs an array of Boolean values in appearance order.
```
m=>m.map(h=o=r=>h=(v=o[r]=~~o[r]+eval(r.join`+`))<h?h:v)&&Object.keys(o).map(x=>o[x]==h)
```
[Try it online!](https://tio.run/##dYxLDoIwFEXnLoS04dnwMQ6MD5fgAhoSKhYLAo8U0uCErVdgrKOb@zuNcmosbT1Mx56e2lfoO8w60amBGSS0mBlkDknaHJdlk1A71TIrGqr7Iiw4v5qbuTgeBPdHo8tJvPVnZMR3xowZyTlHNNyX1I/UatHSi1VMyhgSSHOQCURwWvUMKUR/fc754Qdh7VOI99XG@p2sX/8F "JavaScript (Node.js) – Try It Online")
[Answer]
# [Groovy](http://groovy-lang.org/), 76 bytes
```
{l->m=l.toSet().sort().collect{it.sum()*l.count(it)}
m.collect{it==m.max()}}
```
[Try it online!](https://tio.run/##dYkxDsIwDAB3XmIjE5UWsYVPMEYdUNWiSHaMUheBqrw9lI2F6XR396z6fNfJ15UPF/HsTK@jAbpZ8xeDMo@DrdHcvAjgnre0JINoWHby870XJ7cXYCn1kWMyTjBBCEdqqesptNTQaeOZOmr@eo9YPw "Groovy – Try It Online")
Returns as booleans in sort order
[Answer]
# [Scala](http://www.scala-lang.org/), 63 bytes
```
l=>{var m=l.distinct.map(n=>n.sum*l.count(n==))
m.map(m.max==)}
```
[Try it online!](https://tio.run/##jY1NCsIwEIX3PUWWrYTQH3EhpKALQdATSBYxjRBJJqFJpVB69pi2HsBZfLx5jzfjBdc82udbioDuXAGSY5DQeXRybso@vEev42UAEZSF6nFTPmy4QmAMr/JsrZYcGKNR03ZaOoZq0qVMpSIx3OVAWyB@MDtNhB0gJIMWRWbWcOGY9jm6XkHQkL/y5fKGCte4KdZXeY1LvP/pA25w@ZefJpvjFw "Scala – Try It Online")
Returns booleans in appearance order
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 12 [bytes](https://github.com/abrudz/SBCS)
```
(⌈/=⊢)+.×∘⍴⌸
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X@NRT4e@7aOuRZraeoenP@qY8ah3y6OeHf/THrVNeNTbZ/Soq/lR39TgIGcgGeLhGcwFpIFSaRqPejcbaz7qXWWqYAzUYqRgoGCiYKZgrGAAU6FgrmAEMgyo7j8A "APL (Dyalog Unicode) – Try It Online")
-2 thanks to [Adám](https://codegolf.stackexchange.com/users/43319/ad%c3%a1m). -1 thanks to alternate output format.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 42 bytes
```
#~Position~Max@#&@(Total[#,2]&/@Gather@#)&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277X7kuIL84syQzP6/ON7HCQVnNQSMkvyQxJ1pZxyhWTd/BHaS8yEFZU@1/ukN1taGOkY5xrU61kY6BjgmQNtMx1jHAya/9DwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), 17 bytes
```
{&a=|/a:+//'x@=x}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/Nqlot0bZGP9FKW19fvcLBtqL2f4lVtUp0ZV2RVZpChXVCfra1RkJaYmaOdYV1pXWRZmwtV0m0hqGCkYKxtZGCgYKJtZmCsYIBJluTS0FBA0lUMxaq0dpYwdAapB2NDdKgA2TH/gcA "K (ngn/k) – Try It Online")
`{` `}` function with argument `x`
`=x` group - form a dictionary in which the keys are rows and the values are lists of their indices in the matrix
`x@` index the original matrix with that. the result is again a dictionary with the rows as keys. the values are multiple copies of the corresponding key
`+//'` sum until convergence each (acts only on the values; keys remain as they are)
`a:` assign to `a`
`|/` maximum (of the values)
`a=|/a` a row-to-boolean dictionary of which rows contribute the most
`&` "where", i.e. which keys correspond to values of 1
[Answer]
# [Python 2](https://docs.python.org/2/), ~~81~~ 78 bytes
```
lambda a:{u for u in a if a.count(u)*sum(u)==max(a.count(t)*sum(t)for t in a)}
```
[Try it online!](https://tio.run/##dYxBCgIxDEX3niLLRILMtOJC6E3cRKVYsO0wpjAinr12RlwIuvr8l7w/3PWSk6neHepV4vEsIPtHAZ9HKBASCAQPsjnlkhQLrW8ltnAuyoQfrG@sNFu6WPSswxiSgkdA7NmwJUbDHW9b7thy97cT0OpbbifL/fIwz/wmTasv "Python 2 – Try It Online")
3 bytes thx to [Black Owl Kai](https://codegolf.stackexchange.com/users/81238/black-owl-kai).
Given a collection of tuples, the output is a set of those tuples having the desired maximal property.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~10~~ 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ês{γOOZQÏ
```
[Try it online](https://tio.run/##yy9OTMpM/f//8Kri6nOb/f2jAg/3//8fHW2kY6BjEqsTbahjpGMMpM10jHUMgDRMHJUfCwA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9WeXiCvZLCo7ZJCkr2/w@vKq4@t9nfPyrwcP9/nf/R0dFGOgY6JrE60YY6RjrGQNpMx1jHAEjDxFH5sToK0SClQAFjHUOwsDFEMxaR2FgA).
**Explanation:**
```
ê          # Sort and uniquify the (implicit) input list of lists
           #  i.e. [[2,0,4],[1,2,3],[6,3,0],[2,0,4],[6,3,0],[2,0,4]]
           #   → [[1,2,3],[2,0,4],[6,3,0]]
 s         # Swap so the (implicit) input list of lists is at the top again
  {        # Sort it
           #  i.e. [[2,0,4],[1,2,3],[6,3,0],[2,0,4],[6,3,0],[2,0,4]]
           #   → [[1,2,3],[2,0,4],[2,0,4],[2,0,4],[6,3,0],[6,3,0]]
   γ       # Group the sorted list of lists
           #  i.e. [[1,2,3],[2,0,4],[2,0,4],[2,0,4],[6,3,0],[6,3,0]]
           #   → [[[1,2,3]],[[2,0,4],[2,0,4],[2,0,4]],[[6,3,0],[6,3,0]]]
    O      # Take the sum of each inner-most lists
           #  i.e. [[[1,2,3]],[[2,0,4],[2,0,4],[2,0,4]],[[6,3,0],[6,3,0]]]
           #   → [[6],[6,6,6],[9,9]]
     O     # Take the sum of each inner list
           #  i.e. [[6],[6,6,6],[9,9]] → [6,18,18]
      Z    # Get the max (without popping the list of sums)
           #  i.e. [6,18,18] → 18
       Q   # Check for each if this max is equal to the sum
           #  i.e. [6,18,18] and 18 → [0,1,1]
        Ï  # Filter the uniquified list of lists on truthy values (and output implicitly)
           #  i.e. [[1,2,3],[2,0,4],[6,3,0]] and [0,1,1] → [[2,0,4],[6,3,0]]
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~13~~ 11 bytes
*-2 bytes from @Shaggy*
```
ü¬®xx
m¥Urw
```
[Try it online!](https://ethproductions.github.io/japt/?v=1.4.6&code=/KyueHgKbaVVcnc=&input=W1sxLDIsM10sWzIsMCw0XSxbNiwzLDBdLFsyLDAsNF0sWzYsMywwXSxbMiwwLDRdXSAtUQ==)
[Answer]
# [J](http://jsoftware.com/), 16 bytes
```
[:(=>./)+/^:2/.~
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o600bO309DW19eOsjPT16v5r/s9VsNVTMFQwUjDWMQKqNNExUzBWMEBhW4E5XGkKuQA "J – Try It Online")
A monadic verb that gives the boolean result in appearance order.
### How it works
```
[:(=>./)+/^:2/.~
             /.~  Self-classify; collect identical rows in appearance order
                  For each collected rows (= a matrix),
        +/^:2       Sum all the elements into one value
[:(=>./)          Compute the boolean vector:
    >./             Is the max of the array
   =                equal to this element?
```
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), 15 bytes
```
l2(*)fo<fce>~sB
```
Sorts the input by how much they contribute, ascending.
## Explanation
So first we have `sB` which sorts the list by some conversion function. So we want to come up with the correct conversion function. `fo` will give the sum of the element and `fce` will count the number of times the element appears in the matrix. To get our metric we multiply them.
So put it together and you have:
```
f x=sB(\y->fo y*fce x y)x
```
So now we want to get rid of that lambda since it's pretty expensive. We can do this with `l2`/`(**)`:
```
f x=sB(l2(*)fo$fce x)x
f x=sB(ml**fo$fce x)x
```
Now we want to get rid of the `x`. We can do that by using `>~`, the monadic bind.
```
f=l2(*)fo<fce>~sB
f=(ml**fo)<fce>~sB
```
Operator precedence is not in favor of us using `(**)` so the `l2` version is what we go with.
## Reflections
I'm pretty happy overall with this. But some tweaks can be made.
* `(**)` should be given higher precedence. Right now it's just the default, it should be higher than `(<)`.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 126 bytes
```
n=>{var i=n.OrderBy(a=>a.Sum()*n.Count(a.SequenceEqual));return i.Where((a,b)=>i.Take(b).Count(a.SequenceEqual)<1).Reverse();}
```
[Try it online!](https://tio.run/##rY5NS8QwEIbv/RWhpxmNYT/ES5sclBUEQVBhz2kdd0N3p2yarEjtb68bEWVRbx7f532HeerurO7ceB25Lm8WHLfkbbWh8tZ1oXQcjJG/Y9PokbXp99YLp1nd@Sfyl69gtbHqIW4BT1hdtZEDHDLtInFNi120G8TCU4iehVPLNXkCsLJCbZx6tA1BhX/clVNU97Qn3xFgMYxFlp63mulFfIh92wH2XzSBfipncj7II3gYzeREnv/EF3IuJ/@zHorsufVk6zUk2yAciwZaxKw/KlapCJgtvQsEq9Nc5lhknzF/S2EY3wE "C# (Visual C# Interactive Compiler) – Try It Online")
# 
Most of this code is spent taking out all duplicate values, since the default comparer for lists do not compare the values inside the lists. That means that I cannot use `Distinct()`, `GroupBy()`, or `Contains` to filter the list.
[Answer]
# Japt, ~~11~~ 10 bytes
```
ü¬ü_xxÃÌmâ
```
[Run it online](https://ethproductions.github.io/japt/?v=1.4.6&code=/Kz8X3h4w8xt4g==&input=W1sxLDIsM10sWzIsMCw0XSxbNiwzLDBdLFsyLDAsNF0sWzYsMywwXSxbMiwwLDRdXQoKLVI=)
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 10 bytes
```
ȯẋ_¦Σ¦:⌉=¦
```
[Try it online!](https://tio.run/##S0/MTPz//8T6h7u64w8tO7f40DKrRz2dtoeW/Y@ONlQwUjCOVYg2UjBQMAHSZgrGCgY4@bGP2ib@BwA "Gaia – Try It Online")
Since Gaia doesn't accept lists through inputs very easily, this is a *function* that accepts a list from the top from the top of the stack and leaves the result on top (as masks of sorted order).
```
ȯ           Sort the list
 ẋ          Split it into runs of the same element (in this case, runs of the same row)
  _¦        Flatten each sublist
    Σ¦      Sum each sublist
      :⌉    Find the maximum sum
        =¦  Compare each sum for equality with the maximum
```
]