1 2 3 4 5 6 7 8 9 10 11
S = [5,4,0,3,1,2,6] items = set() index = 0 while True: a = S[index] if index not in items: items.add(index) index = a else: print(len(items)) break
1
3