# [K (oK)], <strike>40</strike> 33 bytes {|/+/'x./:/:(!#x),'/:-1_'prm@#*x} [Try it online!][TIO-jpsqlecw] [K (oK)]: https://github.com/JohnEarnest/ok [TIO-jpsqlecw]: https://tio.run/##y9bNz/7/P82qukZfW1@9Qk/fSt9KQ1G5QlNHXd9K1zBevaAo10FZq6L2f5qChqGCkYKxgom1gqmCCZBhZK1gBhQxVzDU/A8A "K (oK) – Try It Online" Initial solution: - {|/+/'x./:/:(*t),'/:t:{x~?x}#+!(#x)##*x} [Try it online!][TIO-jpsdiv8q] [K (oK)]: https://github.com/JohnEarnest/ok [TIO-jpsdiv8q]: https://tio.run/##Dcg7DoAgDADQq9R04Kc2IGpSBm/DwuDC0ETx6sj28spyl94zPy85UrISE2tbzayIKz/yXdLQTRrFIFppPYP2EGCDmGCHOBASHGNO8Kb/ "K (oK) – Try It Online" Note: Doesn't work for the first test case [[1]] Explanation: - `{ }` - function with argument `x` # - creata a list (#x) - with length number of rows of x #*x - of the length of the first row ! - odometer (ranged permutations) + - transpose # - filter out the rows {x~?x} - that have duplicates t: - save it to t ,'/: - pair up each number in each row with (*t) - a number from the first row x./:/: - index x with each of the above +/' - find the sum of each row |/ - reduce by max