Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = open(r'27A_1355.txt')
- groups = list()
- buff = list()
- n = int(f.readline())
- for s in f:
- t = int(s)
- buff.append(t)
- if t % 2 == 0 and len(buff) != 1:
- groups.append(buff.copy())
- buff.clear()
- e = 10**100
- sm = 0
- md10 = e
- for group in groups:
- m1dn2 = e
- m2dn2 = e
- md2 = e
- group_sm = 0
- for el in group:
- group_sm += el
- if el % 2 == 1:
- if el < m1dn2:
- m2dn2 = m1dn2
- m1dn2 = el
- elif el >= m1dn2:
- m2dn2 = min(el, m2dn2)
- else:
- if el % 10 != 0:
- md2 = min(el, md2)
- if group_sm % 2 != 0:
- group_sm -= m1dn2
- if (m2dn2 - m1dn2) % 10 != 0:
- md2 = min(md2, m2dn2 - m1dn2)
- sm += group_sm
- md10 = min(md10, md2, m1dn2 + m2dn2)
- if sm % 10 == 0:
- sm = sm - md10
- print(sm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement