Buggy python submission (verdict: Runtime Error):
# c
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            B[i] -= (a+c)*((B[i]-A[i]+a+c-1)//(a+c))
            cnt += 1
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Fixed submission:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Buggy python submission (verdict: Runtime Error):
# c
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            B[i] -= (a+c)*((B[i]-A[i]+a+c)//(a+c))
            cnt += 1
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Fixed submission:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        while (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            B[i] -= a+c
            cnt += 1
        if B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Fixed submission:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        while (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            B[i] -= a+c
            cnt += 1
        if B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Fixed submission:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, b, c = B[i-1], B[i], B[(i+1)%n]
        if (b > A[i]) &\
           (b > a) &\
           (b > c):
            B[i] -= a+c
            cnt += 1
        elif b < A[i]:
            print(-1)
            exit()
print(cnt)

Fixed submission:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, b, c = B[i-1], B[i], B[(i+1)%n]
        if (b > A[i]) &\
           (b > a) &\
           (b > c):
            B[i] -= a+c
            cnt += 1
        elif b < A[i]:
            print(-1)
            exit()
print(cnt)

Fixed submission:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)