Advertisement
qekaqeka

1355

Jun 8th, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. f = open(r'27A_1355.txt')
  2.  
  3. groups = list()
  4. buff = list()
  5.  
  6. n = int(f.readline())
  7.  
  8. for s in f:
  9. t = int(s)
  10. buff.append(t)
  11.  
  12. if t % 2 == 0 and len(buff) != 1:
  13. groups.append(buff.copy())
  14. buff.clear()
  15.  
  16.  
  17. e = 10**100
  18.  
  19. sm = 0
  20. md10 = e
  21. for group in groups:
  22. m1dn2 = e
  23. m2dn2 = e
  24. md2 = e
  25. group_sm = 0
  26. for el in group:
  27. group_sm += el
  28.  
  29. if el % 2 == 1:
  30. if el < m1dn2:
  31. m2dn2 = m1dn2
  32. m1dn2 = el
  33. elif el >= m1dn2:
  34. m2dn2 = min(el, m2dn2)
  35. else:
  36. if el % 10 != 0:
  37. md2 = min(el, md2)
  38.  
  39. if group_sm % 2 != 0:
  40. group_sm -= m1dn2
  41.  
  42. if (m2dn2 - m1dn2) % 10 != 0:
  43. md2 = min(md2, m2dn2 - m1dn2)
  44.  
  45. sm += group_sm
  46.  
  47. md10 = min(md10, md2, m1dn2 + m2dn2)
  48.  
  49. if sm % 10 == 0:
  50. sm = sm - md10
  51.  
  52. print(sm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement