Skip to content

Instantly share code, notes, and snippets.

@keddad
Last active June 23, 2021 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keddad/a2dc599d526929c6fd66aecd4a3d5ecd to your computer and use it in GitHub Desktop.
Save keddad/a2dc599d526929c6fd66aecd4a3d5ecd to your computer and use it in GitHub Desktop.
with open("27-29b.txt", "rt") as f:
n = int(f.readline())
data = []
for line in f.readlines():
data.append(sorted(list(map(int, line.split())), reverse=True))
sum = 0
df = 1000000000001
for line in data:
a_b = line[0] + line[1]
b_c = line[1] + line[2]
a_c = line[0] + line[2]
sum += a_b
if 0 != b_c % 5:
df = min(df, a_b - b_c)
if 0 != a_c % 5:
df = min(df, a_b - a_c)
if sum % 5 == 0:
sum -= df
print(sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment