Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

L = [0]*(N+1)
R = [0]*(N+1)
for i in range(0,N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N-1,-1,-1):
    R[i] = gcd(R[i+1],A[i])
print(L)
print(R)
M = [0]*N
for i in range(N):
    M[i] = gcd(L[i],R[i+1])
print(max(M))


Fixed submission:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

L = [0]*(N+1)
R = [0]*(N+1)
for i in range(0,N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N-1,-1,-1):
    R[i] = gcd(R[i+1],A[i])

M = [0]*N
for i in range(N):
    M[i] = gcd(L[i],R[i+1])
print(max(M))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

L = [0]*(N+1)
R = [0]*(N+1)
for i in range(0,N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N-1,-1,-1):
    R[i] = gcd(R[i+1],A[i])
print(L)
print(R)
M = [0]*N
for i in range(N-1):
    M[i] = gcd(L[i],R[i+1])
print(max(M))


Fixed submission:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

L = [0]*(N+1)
R = [0]*(N+1)
for i in range(0,N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N-1,-1,-1):
    R[i] = gcd(R[i+1],A[i])

M = [0]*N
for i in range(N):
    M[i] = gcd(L[i],R[i+1])
print(max(M))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0
tmp = A[0]
for i in range(1,N):
    tmp = gcd(A[i],tmp)
A = A//tmp
num = 0
numtmp = 10**10
hantei = False
judge = False
for i in range(N-1):
    tmp2 = gcd(A[i],A[i+1])
    if tmp2 == 1 and (i == 0 or i == N-2):
        num += 1
        numtmp = i
        hantei = True
        continue
    if tmp2 == 1 and judge == False:
        num += 1
        judge = True
        continue
    if tmp2 == 1 and judge == True:
        if num == 1:
            numtmp = i
        num += 1
        hantei = True
    judge = False
if hantei == True and num <= 2:
    ans = 0
    tmp3 = A[0]
    if numtmp == 0:
        tmp3 =A[1]
    for i in range(1,N):
        if i == numtmp:
            continue
        tmp3 = gcd(A[i],tmp3)
    print(tmp*tmp3)
else:
    print(tmp)


Fixed submission:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

L = [0]*(N+1)
R = [0]*(N+1)
for i in range(0,N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N-1,-1,-1):
    R[i] = gcd(R[i+1],A[i])

M = [0]*N
for i in range(N):
    M[i] = gcd(L[i],R[i+1])
print(max(M))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
num = 1
T = []
T_append = T.append
if S[0] == 0:
    T.append(0)
tmp = S[0]
for i,s in enumerate(S):
    if i == 0:
        continue
    if tmp != s:
        T_append(num)
        num = 0
    tmp = s
    if i == N-1:
        T_append(num+1)
        continue
    num += 1
if S[N-1] == 0:
    T.append(0)
#index 0,2,4...に1の連続数、1,3,5...に0の連続数
if K >= len(T)//2:
    print(N)
else:
    ans = 0
    for i in range(len(T)//2 -K+1):
        ans = max(ans,sum(T[2*i:2*i+2*K+1]))
    print(ans)

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
num = 1
T = []
if S[0] == 0:
    T.append(0)
for i in range(1,N):
    if S[i-1] != S[i]:
        T.append(num)
        num = 0
    num += 1
T.append(num)
if S[N-1] == 0:
    T.append(0)
#index 0,2,4...に1の連続数、1,3,5...に0の連続数
if K >= len(T)//2:
    print(N)
else:
    x = sum(T[0:2*K+1])
    ans = x
    for i in range(1,(len(T)//2)-K+1):
        x = x-(T[2*i-2]+T[2*i-1])+(T[2*i+2*K-1]+T[2*i+2*K])
        ans = max(ans,x)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
num = 1
T = []
if S[0] == 0:
    T.append(0)
for i in range(1,N):
    if S[i-1] != S[i]:
        T.append(num)
        num = 0
    if i == N-1:
        T.append(num+1)
        continue
    num += 1
if S[N-1] == 0:
    T.append(0)

#index 0,2,4...に1の連続数、1,3,5...に0の連続数
if K >= len(T)//2:
    print(N)
else:
    ans = 0
    for i in range(len(T)//2 -K+1):
        ans = max(ans,sum(T[2*i:2*i+2*K+1]))
    print(ans)

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
num = 1
T = []
if S[0] == 0:
    T.append(0)
for i in range(1,N):
    if S[i-1] != S[i]:
        T.append(num)
        num = 0
    num += 1
T.append(num)
if S[N-1] == 0:
    T.append(0)
#index 0,2,4...に1の連続数、1,3,5...に0の連続数
if K >= len(T)//2:
    print(N)
else:
    x = sum(T[0:2*K+1])
    ans = x
    for i in range(1,(len(T)//2)-K+1):
        x = x-(T[2*i-2]+T[2*i-1])+(T[2*i+2*K-1]+T[2*i+2*K])
        ans = max(ans,x)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
S = list(map(int,input()))
num = 1
T = []
if S[0] == 0:
    T.append(0)
for i in range(1,N):
    if S[i-1] != S[i]:
        T.append(num)
        num = 0
    if i == N-1:
        T.append(num+1)
        continue
    num += 1
if S[N-1] == 0:
    T.append(0)

#index 0,2,4...に1の連続数、1,3,5...に0の連続数
if K >= len(T)//2:
    print(N)
else:
    ans = 0
    for i in range(len(T)//2 -K+1):
        ans = max(ans,sum(T[2*i:2*i+2*K+1]))
    print(ans)

Fixed submission:
N,K = map(int,input().split())
S = list(map(int,input()))
num = 1
T = []
if S[0] == 0:
    T.append(0)
for i in range(1,N):
    if S[i-1] != S[i]:
        T.append(num)
        num = 0
    num += 1
T.append(num)
if S[N-1] == 0:
    T.append(0)
#index 0,2,4...に1の連続数、1,3,5...に0の連続数
if K >= len(T)//2:
    print(N)
else:
    x = sum(T[0:2*K+1])
    ans = x
    for i in range(1,(len(T)//2)-K+1):
        x = x-(T[2*i-2]+T[2*i-1])+(T[2*i+2*K-1]+T[2*i+2*K])
        ans = max(ans,x)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1
L = [0]*(N+1)

R = [0]*N

tmp = 0
for i in range(0,N):
    if s[i] == 1:
        tmp += 1
    L[i+1] += tmp
tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] += tmp
R += [0]
for i in range(Q):
    ans = sum(s)-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []

@lru_cache(maxsize=None)
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        lis.append(i)
for i in range(Q):
    ans = 0
    for j in lis:
        if LR[i][0]-1 <= j and j+1 <= LR[i][1]-1:
            ans += 1
        if LR[i][1]-1<j+1:
            break
    print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        lis.append(i)
for i in range(Q):
    ans = 0
    for j in lis:
        if LR[i][0]-1 <= j and j+1 <= LR[i][1]-1:
            ans += 1
        if LR[i][1]-1<j+1:
            break
    print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())
ans = A
for i in range(A+1,B+1):
    ans ^= i
print(ans)

Fixed submission:
A,B = map(int,input().split())

At = A%4
Bt = B%4

ans = 0
if At>0:
    for i in range(4-At):
        ans ^= A+i
if Bt<4:
    for i in range(Bt+1):
        ans ^= B-i
print(ans)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    ans = gcd(ans,i)
    if ans ==1:
        break
print(ans)


Fixed submission:
from fractions import gcd
#from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    ans = gcd(ans,i)
    if ans ==1:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[float("inf")]*(N-1)
for i in range(N):
    for k in range(1,K+1):
        if i+k > N-1:
            break
        dp[i+k] = min(dp[i+k],dp[i]+abs(h[i+k]-h[i]))
print(dp[N-1])


Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[float("inf")]*(N-1)
for i in range(N):
    for k in range(1,K+1):
        if i+k > N-1:
            break
        dp[i+k] = min(dp[i+k],dp[i]+abs(h[i+k]-h[i]))
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

Fixed submission:
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
else:
    for i in range(101):
        for j in range(101):
            if lis[i][j] == 1:
                s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

Fixed submission:
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
else:
    for i in range(101):
        for j in range(101):
            if lis[i][j] == 1:
                s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))
Buggy python submission (verdict: Runtime Error):
from collections import gcd
#from math import gcd
N,X =map(int,input().split())
x = list(map(int,input().split()))
dif = [x[0]-X]+[x[i+1]-x[i] for i in range(N-1)]
ans = dif[0]
for i in range(1,N):
    ans = gcd(ans,dif[i])
print(ans)


Fixed submission:
from fractions import gcd
#from math import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
dif = [abs(x[i+1]-x[i]) for i in range(N-1)]
ans = abs(x[0]-X)
for i in range(N-1):
    ans = gcd(ans,dif[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M,Q = map(int,input().split())
lis = np.zeros((N,N))
for i in range(M):
    L,R = map(int,input().split())
    lis[0:L,R-1:] += 1
for i in range(Q):
    p,q = map(int,input().split())
    print(int(lis[p-1,q-1]))




Fixed submission:
import numpy as np
N,M,Q = map(int,input().split())
lis = np.zeros((N,N))
for i in range(M):
    L,R = map(int,input().split())
    lis[L-1,R-1] += 1
#二次元累積和
for i in range(N-2,-1,-1):
    lis[i] += lis[i+1]
for j in range(1,N):
    lis[:,j] += lis[:,j-1]

for _ in range(Q):
    p,q = map(int,input().split())
    print(int(lis[p-1,q-1]))
Buggy python submission (verdict: Runtime Error):
import re
S = input()
c = r"A[a-z]+C[a-z]+$"
print("AC" if re.match(c,s) else "WA")



Fixed submission:
import re
S = input()
c = r"A[a-z]+C[a-z]+$"
print("AC" if re.match(c,S) else "WA")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
def sad(b):
    ret = 0
    for i in range(N):
        ret += abs(A[i]-b-i)
    return ret
L = -(10**10)
R = 10**10
tmp = sad(R)
while L+1<R:
    mid = (L+R)//2
    sm = sad(mid)
    sm1 = sad(mid-1)
    if sm1 < sm:
        R = mid
    elif sm1 == sm:
        ans = sm
        break
    else:
        L = mid
else:
    ans = sad(L)
print(ans)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
def sad(b):
    ret = 0
    for i in range(N):
        ret += abs(A[i]-b-i)
    return ret
L = -(10**10)
R = 10**10
tmp = sad(R)
while L+1<R:
    mid = (L+R)//2
    sm = sad(mid)
    sm1 = sad(mid-1)
    if sm1 < sm:
        R = mid
    elif sm1 == sm:
        ans = sm
        break
    else:
        L = mid
else:
    ans = sad(L)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [0]
tmp = 0
for a in A:
    tmp += a
    B.append(tmp)

l = 1
r = 3
cut = []
for i in range(2,N-1):
    Lm = float("inf")
    Rm = float("inf")
    c = [0,i,0]
    for j in range(l,i):
        tmp = abs(B[i]-2*B[j])
        if tmp > Lm:
            c[0] = j-1
            l = j-1
            break
        Lm = tmp
    else:
        c[0] = i-1
        l = i-1
    for k in range(r,N):
        tmp = abs((B[N]-B[k])-(B[k]-B[i]))
        if tmp > Rm:
            c[2] = k-1
            r = k-1
            break
        Rm = tmp
    else:
        c[2] = N-1
        r = N
    cut.append(c)
p#rint(cut)
ans = float("inf")
for p,q,r in cut:
    P = B[p]
    Q = B[q]-B[p]
    R = B[r]-B[q]
    S = B[N]-B[r]
    ans = min(ans,max(P,Q,R,S)-min(P,Q,R,S))
print(ans)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [0]
tmp = 0
for a in A:
    tmp += a
    B.append(tmp)

l = 1
r = 3
cut = []
for i in range(2,N-1):
    Lm = float("inf")
    Rm = float("inf")
    c = [0,i,0]
    for j in range(l,i):
        tmp = abs(B[i]-2*B[j])
        if tmp > Lm:
            c[0] = j-1
            l = j-1
            break
        Lm = tmp
    else:
        c[0] = i-1
        l = i-1
    for k in range(r,N):
        tmp = abs((B[N]-B[k])-(B[k]-B[i]))
        if tmp > Rm:
            c[2] = k-1
            r = k-1
            break
        Rm = tmp
    else:
        c[2] = N-1
        r = N
    cut.append(c)
#print(cut)
ans = float("inf")
for p,q,r in cut:
    P = B[p]
    Q = B[q]-B[p]
    R = B[r]-B[q]
    S = B[N]-B[r]
    ans = min(ans,max(P,Q,R,S)-min(P,Q,R,S))
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import itertools
import sys
input = sys.stdin.readline  #文字列入力では注意！

N,C = map(int,input().split())
D = np.array([list(map(int,input().split()))for _ in range(C)], dtype=np.int64)
c = np.array([list(map(int,input().split()))for _ in range(N)], dtype=np.int64)
c0 = np.zeros(C)
c1 = np.zeros(C)
c2 = np.zeros(C)
for i in range(N):
    for j in range(N):
        if (i+j)%3 == 0:
            c0[c[i,j]-1] += 1
        if (i+j)%3 == 1:
            c1[c[i,j]-1] += 1
        if (i+j)%3 == 2:
            c2[c[i,j]-1] += 1
# c0~2はXの情報
lis = itertools.permutations([i for i in range(C)])
ans = float("inf")
for l0,l1,l2 in lis:    # l0~2はYの情報
    tmp = np.sum(D[:,l0]*c0+D[:,l1]*c1+D[:,l2]*c2, dtype=np.int64)
    ans = min(ans,tmp)
print(ans)


Fixed submission:
import numpy as np
import itertools
import sys
input = sys.stdin.readline  #文字列入力では注意！

N,C = map(int,input().split())
D = np.array([list(map(int,input().split()))for _ in range(C)], dtype=np.int64)
c = np.array([list(map(int,input().split()))for _ in range(N)], dtype=np.int64)
c0 = np.zeros(C)
c1 = np.zeros(C)
c2 = np.zeros(C)
for i in range(N):
    for j in range(N):
        if (i+j)%3 == 0:
            c0[c[i,j]-1] += 1
        if (i+j)%3 == 1:
            c1[c[i,j]-1] += 1
        if (i+j)%3 == 2:
            c2[c[i,j]-1] += 1
# c0~2はXの情報
lis = itertools.permutations([i for i in range(C)],3)
ans = float("inf")
for l0,l1,l2 in lis:    # l0~2はYの情報
    tmp = np.sum(D[:,l0]*c0+D[:,l1]*c1+D[:,l2]*c2, dtype=np.int64)
    ans = min(ans,tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

l = 0
r = 1
tmp = A[0]
ans = 0
while l<n:
    if r==n:
        ans += r-l
        l += 1
    elif tmp+a[r] == tmp^A[r]:
        tmp = tmp+A[r]
        r += 1
    else:
        ans = r-l
        tmp = tmp-A[l]
        l += 1
print(ans)

Fixed submission:
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

l = 0
r = 1
tmp = A[0]
ans = 0
while l<N:
    if r==N:
        ans += r-l
        l += 1
    elif tmp+A[r] == tmp^A[r]:
        tmp = tmp+A[r]
        r += 1
    else:
        ans += r-l
        tmp = tmp-A[l]
        l += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

l = 0
r = 1
tmp = A[0]
ans = 0
while l<n:
    if r==n:
        ans += r-l
        l += 1
    elif tmp+a[r] == tmp^a[r]:
        tmp = tmp+a[r]
        r += 1
    else:
        ans = r-l
        tmp = tmp-a[l]
        l += 1
print(ans)

Fixed submission:
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

l = 0
r = 1
tmp = A[0]
ans = 0
while l<N:
    if r==N:
        ans += r-l
        l += 1
    elif tmp+A[r] == tmp^A[r]:
        tmp = tmp+A[r]
        r += 1
    else:
        ans += r-l
        tmp = tmp-A[l]
        l += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))
Bb = [0]
tmp = 0
for i in range(N):
    tmp ^= A[i]
    Bb.append(tmp)
Bs = [0]+list(accumulate(A))
ans = 0
for l in range(1,N+1):
    for r in range(l,N+1):
        if Bb[r]^Bb[l-1] == Bs[r]-Bs[l-1]:
            ans += 1
print(ans)

Fixed submission:
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))

l = 0
r = 1
tmp = A[0]
ans = 0
while l<N:
    if r==N:
        ans += r-l
        l += 1
    elif tmp+A[r] == tmp^A[r]:
        tmp = tmp+A[r]
        r += 1
    else:
        ans += r-l
        tmp = tmp-A[l]
        l += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,len(s)):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()


Fixed submission:
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,min(i+5,len(s))):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,len(s)):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()


Fixed submission:
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,min(i+5,len(s))):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [["."] *(W+2)]+[["."]+list(input())+["."] for _ in range(W)]+[["."] *(W+2)]
#print(*s, sep="\n")
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "#":
            if s[i-1][j]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i][j+1]==".":
                print("No")
                exit()
print("Yes")


Fixed submission:
H,W = map(int,input().split())
s = [["."]*(W+2)]+[["."]+list(input())+["."] for _ in range(H)]+[["."]*(W+2)]
#print(*s, sep="\n")
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "#":
            if s[i-1][j]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i][j+1]==".":
                print("No")
                exit()
print("Yes")