#!/usr/bin/env python3 with open('input.txt', 'r') as f: in_list = f.readlines() in_list = [x.strip() for x in in_list] in_list = [int(x) for x in in_list] # print(in_list) freq = set() res = 0 i = 0 while True: if i == len(in_list): i = 0 res += in_list[i] if res in freq: break freq.add(res) i += 1 print(res)