Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = open("27-B (2).txt").readlines()
- n = int(data[0])
- a = list(map(int, data[1:]))
- q = [[], [], []]
- for e in a:
- q[e % 3].append(e)
- for i in range(3):
- q[i].sort()
- answ = 100000000
- for x in range(3):
- for y in range(x, 3):
- for z in range(y, 3):
- if (x + y + z) % 3 != 0:
- continue
- s = 0
- for i in range(3):
- cnt = (x, y, z).count(i)
- if len(q[i]) >= cnt:
- s += sum(q[i][:cnt])
- else:
- s = -1
- break
- if s != -1:
- answ = min(answ, s)
- print(answ)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement