import itertools


def splitter(balances):

	if len(balances) == 2:
		return [[list(balances.items())[0][0], list(balances.items())[1][0]]]

	# global transactions
	transactions = 1000000000
	trans_lst = []
	global saved, kaun, kise

	for person1 in balances:
		for person2 in balances:

			# temp_tran = 10000000
			if person2 != person1:

				bal1 = balances[person1]
				bal2 = balances[person2]
				print("productt, ", bal1*bal2)

				if bal1*bal2 < 0:
					print("Jaay")
					temp_dicti = balances.copy()
					
					if(abs(bal1) > abs(bal2)):
						if bal1 > 0:
							balances[person1] = bal1+bal2
							temp_dicti.pop(person2)
							temp_tran = 1+len(splitter(temp_dicti.copy()))
						else:
							balances[person2] = bal1+bal2
							temp_dicti.pop(person1)
							temp_tran = 1+len(splitter(temp_dicti.copy()))
					elif(abs(bal1) < abs(bal2)):
						if bal1 > 0:
							balances[person2] = bal1+bal2
							temp_dicti.pop(person1)
							temp_tran = 1+len(splitter(temp_dicti.copy()))
						else:
							balances[person1] = bal1+bal2
							temp_dicti.pop(person2)
							temp_tran = 1+len(splitter(temp_dicti.copy()))
					else:
						temp_dicti.pop(person2)
						temp_dicti.pop(person1)
						temp_tran = 1+len(splitter(temp_dicti.copy()))
						

					# transactions = min(transactions, temp_tran)
					print("temp_tran ", temp_tran)
					if temp_tran < transactions:
						print("Jaay che")
						# print(temp_dicti)
						saved = dict(temp_dicti)
						print(saved)
						kaun = person1
						kise = person2
						transactions = temp_tran
	print("ssss, ", saved)
	prev = splitter(saved)
	# print(prev, kaun, kise)
	prev.append([kaun, kise])
	print(len(saved))
	return prev

dicti = {}
# dicti['A'] = 2
dicti['B'] = -1
dicti['C'] = -2
dicti['D'] = 3
# dicti['E'] = -2
# dicti['F'] = -1
# dicti['G'] = -1
# dicti['H'] = -1
# dicti['I'] = -1
# dicti['J'] = -1
# dicti['K'] = -1

print(str(splitter(dicti)))


		