Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    while A!=B:
        b = True
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            if B[i] > d > 0:
                b = False
                c = (B[i]-A[i]) // d
                B[i] -= d * c
                count += c
        if b:
            if A == B:
                print(count)
            else:
                print(-1)
            break
    else:
        if A == B:
            print(count)
        else:
            print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    while A!=B:
        b = True
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            if B[i] > d > 0:
                b = False
                c = (B[i]-A[i]) // d
                B[i] -= d * c
                count += c
        if b:
            if A == B:
                print(count)
            else:
                print(-1)
            break
    else:
        if A == B:
            print(count)
        else:
            print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    while A!=B:
        b = True
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            if B[i] > d:
                b = False
                c = B[i] // d
                B[i] -= d * c
                count += c
        if b:
            print(-1)
            break
    else:
        print(count)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    while A!=B:
        b = True
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            if B[i] > d:
                b = False
                c = B[i] // d
                B[i] -= d * c
                count += c
        if b:
            print(-1)
            break
    else:
        print(count)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))
    q = deque()
    cq = deque()
    q.appendleft(B)
    cq.appendleft(0)

    while len(q) > 0:
        b = q.pop()
        c = cq.pop()
        if b == A:
            print(c)
            break
        else:
            for i in range(N):
                _tmp = b[0:N]
                _tmp[i] = b[i] - b[i-1 if i>=1 else N-1] - b[i+1 if i<N-1 else 0]
                if  A[i] <= _tmp[i]:
                    #print(_tmp)
                    q.appendleft(_tmp)
                    cq.appendleft(c+1)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))
    q = deque()
    cq = deque()
    q.appendleft(B)
    cq.appendleft(0)

    while len(q) > 0:
        b = q.pop()
        c = cq.pop()
        if b == A:
            print(c)
            break
        else:
            for i in range(N):
                _tmp = b[0:N]
                _tmp[i] = b[i] - b[i-1 if i>=1 else N-1] - b[i+1 if i<N-1 else 0]
                if _tmp[i] >= 1:
                    q.appendleft(_tmp)
                    cq.appendleft(c+1)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()