# Who owes who money?

The Dank Memes Casino is one of the best casinos of the world. They have a rule that if you win or lose money, you will be paid at the beginning of the next month.

But, catastrophe struck and there was an earthquake, which demolished the casino.

Now, all the poker players have gathered and realised that the casino is not the person that owes them money or they do not owe the casino money, but as a matter of fact, they owe each other!

Your mission, should you choose to accept, will be to find out who owes who money.

Also, do keep in mind that the shortest code wins.

## Input

The first line contains the names of the people separated by spaces (Let there be n names).

The second line contains n integers, the ith of which denotes the ith person's winnings or losings at poker. A positive number means that he is owed money from someone, whereas a negative number entails that he owes someone money.

Flexible input methods are accepted.

## Output

Print out as many lines as required. Each line should contain the name of the person who owes the money, the name of the person who is owed money, the amount of money that is owed separated by a space.

## Input Constraints

2 <= n <= 6

-100000 <= amount of money <= 100000

## Guaranteed Constraints

Sum of all integers in the array = 0

# Sample Test Cases

## Test Case 1

Sample Input

Messi Ronaldo Hazard Ibrahimovich
1000 1000 -2000 0


Sample Output

Hazard Messi 1000
Hazard Ronaldo 1000


## Test Case 2

Sample Input

Maradona Pele
20000 -20000


Sample Output

Pele Maradona 20000


## Test Case 3

Sample Input

A B C D E
1 1 1 1 -4


Sample Output

E A 1
E B 1
E C 1
E D 1


## Test Case 4

Sample Input

A B C D E F
3 3 1 2 -4 -5


Sample Output

F D 2
F C 1
F B 2
E B 3
E B 1
E A 3


## Clarification

There may be multiple answers, anyone of them will be accepted. For example:

A B C
1 1 -2


can yield both of the following:

C A 1
C B 1


or

C B 1
C A 1


both are correct.

• What if multiple people have debts? Do the payments need to be equally distributed? Jun 24, 2017 at 9:01
• Typiclly, we allow for much more relaxed input; in this case, normally we would allow to take input as key-value pairs in the language's implementation; normally, functions are allowed in place of programs. Ultimately it's the challenger's decision but that's typically what happens. Jun 24, 2017 at 9:09
• No negotiation on the output format. -1, most competitive entries will want to return a list of strings from a function Jun 24, 2017 at 12:13
• "readability" ...This is Code Golf. "Readability" is meaningless here. Jun 24, 2017 at 19:18
• I hope the strictness in outputs are just discouraged not completely boycotted, otherwise there would be no meaning of specifiying output requirements. Jun 25, 2017 at 6:31

# Python 3, 173 bytes

a=lambda:input().split()
m={x:int(y)for x,y in zip(a(),a())}
l=lambda k:m[k]
while any(map(l,m)):d=min(m,key=l);s=max(m,key=l);t=min(m[s],-m[d]);m[d]+=t;m[s]-=t;print(d,s,t)


Try it online!

-6 bytes thanks to ppperry using dictcomps instead of dict of a listcomp

• You can save five bytes by converting the second line to a dictcomp: m={x:int(y)for x,y in zip(a(),a()))} Jul 21, 2017 at 1:26
• @ppperry I did not know that works :o thanks! Jul 21, 2017 at 1:28
• @HyperNeutrino has anyone ever told you how awesome you are? Jul 21, 2017 at 17:27
• @KoishoreRoy hm? Jul 21, 2017 at 17:37

# Python 2, 146 bytes

def f(p,b):
a=sorted(zip(b,p))
while a:
d,D,c,C=a[0]+a[-1];t=d+c;a[0]=(t,D);a[-1]=(t,C);a=a[t>=0:[len(a),-1][t<=0]]
if d:print D,C,min(-d,c)


Try it online!