Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
  n = int(input())
  a = [0]*n
  for n in range(n):
    a[n]=int(sys.stdin.readline())-1
  sw = [0]
  while True:
    nextsw = a[sw[-1]]
    if nextsw == 1:
      print(len(sw))
      return
    if nextsw in sw:
      print(-1)
      return
    sw.append(nextsw)
if __name__ == '__main__':    
  main()

Fixed submission:
import sys


def main():
    n = int(input())
    a = [0] * n
    for i in range(n):
        a[i] = int(sys.stdin.readline()) - 1
    sw = [False for _ in range(n)]
    nextsw = 0
    while True:
        if nextsw == 1:
            print(sw.count(True))
            return
        if sw[nextsw]:
            print(-1)
            return
        sw[nextsw] = True
        nextsw = a[nextsw]


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n = int(input())
  a = []
  for n in range(n):
    a.append(int(input())-1)
  sw = [0]
  while True:
    nextsw = a[sw[-1]]
    if nextsw == 1:
      print(len(sw))
      return
    if nextsw in sw:
      print(-1)
      return
    sw.append(nextsw)
                                
main()

Fixed submission:
import sys


def main():
    n = int(input())
    a = [0] * n
    for i in range(n):
        a[i] = int(sys.stdin.readline()) - 1
    sw = [False for _ in range(n)]
    nextsw = 0
    while True:
        if nextsw == 1:
            print(sw.count(True))
            return
        if sw[nextsw]:
            print(-1)
            return
        sw[nextsw] = True
        nextsw = a[nextsw]


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n = int(input())
  a = []
  for n in range(n):
    a.append(int(input())-1)
  sw = [0]
  while True:
    nextsw = a[sw[-1]]
    if nextsw == 1:
      print(len(sw))
      return
    if nextsw in sw:
      print(-1)
      return
    sw.append(nextsw)
                                
main()

Fixed submission:
import sys


def main():
    n = int(input())
    a = [0] * n
    for i in range(n):
        a[i] = int(sys.stdin.readline()) - 1
    sw = [False for _ in range(n)]
    nextsw = 0
    while True:
        if nextsw == 1:
            print(sw.count(True))
            return
        if sw[nextsw]:
            print(-1)
            return
        sw[nextsw] = True
        nextsw = a[nextsw]


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
  n = int(input())
  a =[]
  for n in range(n):
    a.append(int(input())-1)
  sw = [0]
  while True:
    nextsw = sw[-1]
    if nextsw = 1:
      print(len(sw))
      return
    if nextsw in sw:
      print(-1)
      return
    sw.append(nextsw)

main()

Fixed submission:
import sys


def main():
    n = int(input())
    a = [0] * n
    for i in range(n):
        a[i] = int(sys.stdin.readline()) - 1
    sw = [False for _ in range(n)]
    nextsw = 0
    while True:
        if nextsw == 1:
            print(sw.count(True))
            return
        if sw[nextsw]:
            print(-1)
            return
        sw[nextsw] = True
        nextsw = a[nextsw]


if __name__ == '__main__':
    main()