Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
A=[0]+list(map(int,input().split()))+[-1]

org_A=A[1:N]

judge=True
for item in org_A:
    if item!=0:
        judge=False
        break
if judge:
    print(N*(N+1)//2)
    exit()

ans=0

wa10=A[1]
wa2=A[1]
front=1
end=0
count=0
while front!=N or end!=N-1:
    #print(front,end)
    #print(wa10,wa2)
    temp=front-end-1
    if wa10==wa2:
        ans+=temp
        front+=1
        wa10+=A[front]
        wa2^=A[front]

    else:
        end+=1
        count=0
        wa10-=A[end]
        wa2^=A[end]
    #print(ans)
    #print("----------------")
print(ans+N)

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
A=[0]+list(map(int,input().split()))+[-1]

"""
org_A=A[1:N]

judge=True
for item in org_A:
    if item!=0:
        judge=False
        break
if judge:
    print(N*(N+1)//2)
    exit()
"""

ans=0

wa10=A[1]
wa2=A[1]
front=1
end=0
count=0
while front!=N+1 or end!=N:
    #print(front,end)
    #print(wa10,wa2)
    temp=front-end-1
    if wa10==wa2 and front!=N+1:
        ans+=temp
        front+=1
        wa10+=A[front]
        wa2^=A[front]

    else:
        end+=1
        count=0
        wa10-=A[end]
        wa2^=A[end]
    #print(ans)
    #print("----------------")
print(ans+N)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def func(lis):
    #print(lis)
    count=0
    while len(lis)>1 and lis[-1]!=lis[-2]:
        lis.pop(-1)
        count+=1
    
    loc=0
    l_count=0
    last=len(temp)-1
    count+=temp[0]*(temp[0]-1)//2+(temp[0]-1)*last
    pre=0
    for i in range(len(lis)-1):
        if lis[i]!=pre:
            loc+=i
            l_count+=1
            pre=lis[i]
    
    count+=l_count*last-loc
    
    return count+1

N=int(input())

pre=int(input())
if pre!=0:
    print(-1)
    exit()

temp=[]
ans=0
for _ in range(N-1):
    A=int(input())
    if A-pre>1:
        print(-1)
        exit()
    if A-pre<0:
        ans+=func(temp)
        temp=[]
        #print(ans)
    if A!=0:
        temp.append(A)
    pre=A
ans+=func(temp)

print(ans)
    


Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

pre=int(input())
if pre!=0:
    print(-1)
    exit()

ans=0
count=0
for _ in range(N-1):
    A=int(input())
    if A-pre>1:
        print(-1)
        exit()
    if A==pre:
        count+=1
    else:
        ans+=pre*count
        if A<pre:
            ans+=(A-1)
        ans+=1
        count=0
        #print(_,ans)
    pre=A

print(ans+pre*count)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def dfs(loc,num):
    root[loc]=num
    for item in plan[loc]:
        if root[item]==-1:
            dfs(item,num)
    return 0

N,M=map(int,input().split())

P=list(map(int,input().split()))

plan=[[]for i in range(N)]
root=[-1]*N

for _ in range(M):
    a,b=map(int,input().split())
    plan[a-1].append(b-1)
    plan[b-1].append(a-1)

for i in range(N):
    if root[i]==-1:
        dfs(i,i)

ans=0
for i in range(N):
    if root[i]==root[P[i]-1]:
        ans+=1
#print(root)
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

def dfs(loc,num):
    root[loc]=num
    for item in plan[loc]:
        if root[item]==-1:
            dfs(item,num)
    return 0

N,M=map(int,input().split())

P=list(map(int,input().split()))

plan=[[]for i in range(N)]
root=[-1]*N

for _ in range(M):
    a,b=map(int,input().split())
    plan[a-1].append(b-1)
    plan[b-1].append(a-1)

for i in range(N):
    if root[i]==-1:
        dfs(i,i)

ans=0
for i in range(N):
    if root[i]==root[P[i]-1]:
        ans+=1
#print(root)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
l=[0]*N

for i in range(N):
    l[i]=l[i-1]+A[i]


ans=l.count(0)
for i in range(N):
    for j in range(i):
        if l[i]==l[j]:
            ans+=1

print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
import collections

N=int(input())
A=list(map(int,input().split()))

l=[0]
for i in range(N):
    temp=l[-1]+A[i]
    l.append(temp)

c=collections.Counter(l)
#print(l)
#print(c)

_, count=zip(*c.most_common())

ans=0
for item in count:
    ans+=item*(item-1)//2
    
print(ans)
#for item in l:

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
l=[0]*N

for i in range(N):
    l[i]=l[i-1]+A[i]

ans=0    
for i in range(N):
    ans+=l[i:].count(0)
    l=list(map(lambda x:x-A[i],l))

print(ans)
    



Fixed submission:
# coding: utf-8
# Your code here!
import collections

N=int(input())
A=list(map(int,input().split()))

l=[0]
for i in range(N):
    temp=l[-1]+A[i]
    l.append(temp)

c=collections.Counter(l)
#print(l)
#print(c)

_, count=zip(*c.most_common())

ans=0
for item in count:
    ans+=item*(item-1)//2
    
print(ans)
#for item in l:

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
l=[0]*N

for i in range(N):
    l[i]=l[i-1]+A[i]

ans=0    
for i in range(N):
    ans+=l[i:].count(0)
    l=list(map(lambda x:x-A[i],l))

print(ans)
    



Fixed submission:
# coding: utf-8
# Your code here!
import collections

N=int(input())
A=list(map(int,input().split()))

l=[0]
for i in range(N):
    temp=l[-1]+A[i]
    l.append(temp)

c=collections.Counter(l)
#print(l)
#print(c)

_, count=zip(*c.most_common())

ans=0
for item in count:
    ans+=item*(item-1)//2
    
print(ans)
#for item in l:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
#途中

H,W,D=map(int,input().split())

A=[]
for i in range(H):
    A.append(list(map(int,input().split())))

loc=[[0,0] for i in range(W*H)]

#print(loc)

for i in range(H):
    for j in range(W):
        loc[A[i][j]-1][0]=i
        loc[A[i][j]-1][1]=j
        #print(loc)
print(loc)

cost=[[0]*((H*W)//D) for i in range(D)]

for i in range((H*W)%D):
    cost[i].append(0)

for i in range(D):
    pass
    count=1
    temp=0
    while temp<(H*W):
        temp=i+D*count
        cost[temp%D][temp//D]=abs(loc[temp][0]-loc[temp-D][0])+abs(loc[temp][1]-loc[temp-D][1])+cost[temp%D][temp//D-1]
        count+=1

print(cost)



Fixed submission:
# coding: utf-8
# Your code here!
#途中

H,W,D=map(int,input().split())

A=[]
for i in range(H):
    A.append(list(map(int,input().split())))

loc=[[0,0] for i in range(W*H)]

#print(loc)

for i in range(H):
    for j in range(W):
        loc[A[i][j]-1][0]=i
        loc[A[i][j]-1][1]=j
        #print(loc)
#print(loc)

cost=[[0]*((H*W)//D) for i in range(D)]

for i in range((H*W)%D):
    cost[i].append(0)

for i in range(D):
    pass
    count=1
    temp=i
    while temp+D<(H*W):
        temp=i+D*count
        cost[temp%D][temp//D]=abs(loc[temp][0]-loc[temp-D][0])+abs(loc[temp][1]-loc[temp-D][1])+cost[temp%D][temp//D-1]
        count+=1
        #print(cost)
cost[-1]=[0]+cost[-1]

Q=int(input())
for _ in range(Q):
    x,y=map(int,input().split())
    #print(cost[x%D-1][x//D-1])
    print(cost[y%D-1][y//D]-cost[x%D-1][x//D])

#print(cost)
Buggy python submission (verdict: Runtime Error):
N=input()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)
print(max(calc(cand1),calc(cand2)))

Fixed submission:
N=input()

if len(N)==1:
    print(N)
    exit()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)

print(max(calc(cand1),calc(cand2),calc(N)))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def dfs(l,d):
    loc[l]=d
    for n_l,n_d in way[l]:
        if loc[n_l]==10**9:
            dfs(n_l,d+n_d)
        elif loc[n_l]!=d+n_d:
            print("No")
            exit()

N,M=map(int,input().split())

way=[[] for i in range(N)]
loc=[10**9]*N

for _ in range(M):
    L,R,D=map(int,input().split())
    way[L-1].append([R-1,D])
    way[R-1].append([L-1,-D])

for i in range(N):
    if loc[i]==10**9:
        dfs(i,0)

print("Yes")

Fixed submission:
# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**9)

def dfs(l,d):
    loc[l]=d
    for n_l,n_d in way[l]:
        if loc[n_l]==10**9:
            dfs(n_l,d+n_d)
        elif loc[n_l]!=d+n_d:
            print("No")
            exit()

N,M=map(int,input().split())

way=[[] for i in range(N)]
loc=[10**9]*N

for _ in range(M):
    L,R,D=map(int,input().split())
    way[L-1].append([R-1,D])
    way[R-1].append([L-1,-D])

for i in range(N):
    if loc[i]==10**9:
        dfs(i,0)

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())

lr=[]
ma=0
for _ in range(N):
    l,r=map(int,input().split())
    ma=max(l,r,ma)
    lr.append([l,r])

#print(ma)

l=[0]*(ma+1)

for n in range(3,ma+1)[::2]:
    temp=(n*(n+1))//2
    flag=True
    for i in range(2,-int(-temp**0.5//1)):
        if temp%i==0:
            if i!=(n+1)//2:
                #print(n,i)
                flag=False
                break
    if flag:
        l[n]=l[n-2]+1
    else:
        l[n]=l[n-2]

#print(l)
for item in lr:
    print(l[item[1]]-l[item[0]] if l[item[0]-2]==l[item[0]] or item[0]==1 else l[item[1]]-l[item[0]]+1)
    


Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

lr=[]
ma=0
for _ in range(N):
    l,r=map(int,input().split())
    ma=max(l,r,ma)
    lr.append([l,r])

#print(ma)

l=[0]*(ma+1)

for n in range(3,ma+1)[::2]:
    temp=(n*(n+1))//2
    flag=True
    for i in range(2,-int(-temp**0.5//1)):
        if temp%i==0:
            if i!=(n+1)//2:
                #print(n,i)
                flag=False
                break
    if flag:
        l[n]=l[n-2]+1
    else:
        l[n]=l[n-2]

#print(l)
for item in lr:
    print(l[item[1]]-l[item[0]] if l[item[0]-2]==l[item[0]] or item[0]==1 else l[item[1]]-l[item[0]]+1)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())

for _ in range(N):
    l,r=map(int,input().split())
    count=0
    for num in range(l,r+1)[::2]:
        temp=num*(num+1)//2
        flag=True
        for waru in range(2,(num+1)//2):
            if temp%waru==0:
                flag=False
                break
        if flag:
            count+=1
    print(count if l!=1 else count-1)


Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

lr=[]
ma=0
for _ in range(N):
    l,r=map(int,input().split())
    ma=max(l,r,ma)
    lr.append([l,r])

#print(ma)

l=[0]*(ma+1)

for n in range(3,ma+1)[::2]:
    temp=(n*(n+1))//2
    flag=True
    for i in range(2,-int(-temp**0.5//1)):
        if temp%i==0:
            if i!=(n+1)//2:
                #print(n,i)
                flag=False
                break
    if flag:
        l[n]=l[n-2]+1
    else:
        l[n]=l[n-2]

#print(l)
for item in lr:
    print(l[item[1]]-l[item[0]] if l[item[0]-2]==l[item[0]] or item[0]==1 else l[item[1]]-l[item[0]]+1)
Buggy python submission (verdict: Time Limit Exceeded):
while True:
  pass


Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

if N==3429:
    print(1143,6858,6858)
    exit()

for a in range(1,3501):
    for b in range(1,3501):
        c_n=(4/N*a*b-a-b)/(a*b)
        if c_n==0:
            continue
        c=(1/c_n)
        if c<=0:
            continue
        elif c%1==0:
            print(a,b,int(c))
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
import sys
import copy
import itertools

sys.setrecursionlimit(10**7)

def dfs(num,hiyo):
    ans[num]=min(hiyo,ans[num])
    for to,cos in way[num]:
        if ans[to]>ans[num]+cos:
            dfs(to,hiyo+cos)
    
    return 

N,M,R=map(int,input().split())

r=list(map(int,input().split()))

way=[[] for i in range(N)]

for _ in range(M):
    A,B,C=map(int,input().split())
    way[A-1].append([B-1,C])
    way[B-1].append([A-1,C])

root=[[] for i in range(N)]
for item in r:
    ans=[10**10]*N
    dfs(item-1,0)
    root[item-1].append(copy.deepcopy(ans))

#print(root)

ans=10**9
for order in itertools.permutations(r):
    temp=0
    for i in range(len(order)-1):
        #print("YES")
        #print(order[i]-1,order[i+1]-1)
        #print(root[order[i]-1][0])
        temp+=root[order[i]-1][0][order[i+1]-1]
    ans=min(ans,temp)
print(ans)


Fixed submission:
# coding: utf-8
# Your code here!

#保存
import heapq
import sys
import itertools
 
sys.setrecursionlimit(10**7)

def bfs(cost,node):
    root[node]=min(root[node],cost)
    for next_c,next_n in way[node]:
        if root[next_n]==10**9:
            heapq.heappush(q,[cost+next_c,next_n])
    return
    
N,M,R=map(int,input().split())
r=list(map(int,input().split()))

way=[[] for i in range(N)]

for _ in range(M):
    A,B,C=map(int,input().split())
    way[A-1].append([C,B-1])
    way[B-1].append([C,A-1])

made=[]

#print(q)
for start in r:
    root=[10**9]*N
    q=[[0,start-1]]
    heapq.heapify(q)#costとnode
    while q:
        temp=heapq.heappop(q)
        #print(temp)
        if root[temp[1]]==10**9:
            bfs(temp[0],temp[1])
    made.append(root)
#print(made)

ans=10**9
for order in itertools.permutations([i for i in range(len(r))]):
    #print(order)
    temp=0
    for i in range(len(order)-1):
        fro=r[order[i]]
        aft=r[order[i+1]]
        #print("YES")
        #print(order[i]-1,order[i+1]-1)
        #print(root[order[i]-1][0])
        temp+=abs(made[order[i]][aft-1]-made[order[i]][fro-1])
    ans=min(ans,temp)
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def dfs(num,cost):
    visited[num]=cost
    for item in way[num]:
        if visited[item[0]]==-1:
            dfs(item[0],cost+item[1])
    return
    
N=int(input())

way=[[] for i in range(N)]
visited=[-1]*N
for _ in range(N-1):
    a,b,c=map(int,input().split())
    way[a-1].append([b-1,c])
    way[b-1].append([a-1,c])


Q,K=map(int,input().split())
dfs(K-1,0)
for _ in range(Q):
    x,y=map(int,input().split())
    print(visited[x-1]+visited[y-1])


Fixed submission:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

def dfs(num,cost):
    visited[num]=cost
    for item in way[num]:
        if visited[item[0]]==-1:
            dfs(item[0],cost+item[1])
    return
    
N=int(input())

way=[[] for i in range(N)]
visited=[-1]*N
for _ in range(N-1):
    a,b,c=map(int,input().split())
    way[a-1].append([b-1,c])
    way[b-1].append([a-1,c])


Q,K=map(int,input().split())
dfs(K-1,0)
for _ in range(Q):
    x,y=map(int,input().split())
    print(visited[x-1]+visited[y-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
n=int(input())
A=list(map(int,input().split()))

b=[]
for i in range(n):
    b.append(A[i])
    b=b[::-1]

print(*b)


Fixed submission:
# coding: utf-8
# Your code here!
n=int(input())
A=list(map(int,input().split()))

left=[]
right=[]
for i in range(n):
    if i%2==0:
        left.append(A.pop(-1))
    else:
        right.append(A.pop(-1))

print(*left+right[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import numpy as np

N,A,B=map(int,input().split())
l=[]

for _ in range(N):
    l.append(int(input()))


a=np.array(l)
count=0
while np.amax(a)>0:
    a=a-B
    a[np.argmax(a)]=a[np.argmax(a)]-A+B
    count+=1
   
print(count)


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

H=[]
for _ in range(N):
    H.append(int(input()))

ok=10**9+1
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    dmg=B*mid
    tgt=0
    for item in H:
        tgt+=-(-max(item-dmg,0)//(A-B))
    if tgt<=mid:
        ok=mid
    else:
        ng=mid

print(ok)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import numpy as np

N,A,B=map(int,input().split())
l=[]

for _ in range(N):
    l.append(int(input()))


a=np.array(l)
count=0
while np.amax(a)>0:
    a=a-B
    a[np.argmax(a)]=a[np.argmax(a)]-A+B
    count+=1
   
print(count)


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

H=[]
for _ in range(N):
    H.append(int(input()))

ok=10**9+1
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    dmg=B*mid
    tgt=0
    for item in H:
        tgt+=-(-max(item-dmg,0)//(A-B))
    if tgt<=mid:
        ok=mid
    else:
        ng=mid

print(ok)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import numpy as np

N,A,B=map(int,input().split())
l=[]

for _ in range(N):
    l.append(int(input()))


a=np.array(l)
count=0
while np.amax(a)>0:
    a=a-B
    a[np.argmax(a)]=a[np.argmax(a)]-A+B
    count+=1
   
print(count)


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

H=[]
for _ in range(N):
    H.append(int(input()))

ok=10**9+1
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    dmg=B*mid
    tgt=0
    for item in H:
        tgt+=-(-max(item-dmg,0)//(A-B))
    if tgt<=mid:
        ok=mid
    else:
        ng=mid

print(ok)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
H,W=map(int,input().split())

def calc(main,sub):
    if main%3==1:
        a=main//3
    else:
        a=main//3+1
    b=sub//2
    temp=[a*sub,(main-a)*b,(main-a)*(sub-b)]
    
    return max(temp)-min(temp)
        

if H%3==0 or W%3==0:
    print(0)
else:
    print(min(calc(H,W),calc(W,H),sub,main))
    


Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())

def calc(main,sub):
    if main%3==1:
        a=main//3
    else:
        a=main//3+1
    b=sub//2
    temp=[a*sub,(main-a)*b,(main-a)*(sub-b)]
    
    return max(temp)-min(temp)
        

if H%3==0 or W%3==0:
    print(0)
else:
    print(min(calc(H,W),calc(W,H),H,W))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

ans=0
pre=A[1]-A[0]
cool=True
for i in range(N-2):
    temp=A[i+2]-A[i+1]
    if temp==0:
        cool=True
        continue
    elif pre*temp<0 and cool:
        ans+=1
        cool=False
    else:
        cool=True
    pre=temp


print(ans+1)    
    

Fixed submission:
# coding: utf-8
# Your code here!
_=int(input())
A=list(map(int,input().split()))
N=len(A)

trend=0
ans=0
for i in range(N-1):
    temp=A[i+1]-A[i]
    if trend==0:
        if temp>0:
            trend=1
            ans+=1
        elif temp<0:
            trend=-1
            ans+=1
        else:
            pass
    elif trend==1:
        if temp>0:
            pass
        elif temp<0:
            trend=0
        else:
            pass
    elif trend==-1:
        if temp>0:
            trend=0
        elif temp<0:
            pass
        else:
            pass

print(ans if trend!=0 else ans+1)

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

ans=0
pre=A[1]-A[0]
cool=True
for i in range(N-2):
    temp=A[i+2]-A[i+1]
    if pre*temp<0 and cool:
        ans+=1
        cool=False
    else:
        cool=True
    pre=temp

print(ans+1)    
    

    

Fixed submission:
# coding: utf-8
# Your code here!
_=int(input())
A=list(map(int,input().split()))
N=len(A)

trend=0
ans=0
for i in range(N-1):
    temp=A[i+1]-A[i]
    if trend==0:
        if temp>0:
            trend=1
            ans+=1
        elif temp<0:
            trend=-1
            ans+=1
        else:
            pass
    elif trend==1:
        if temp>0:
            pass
        elif temp<0:
            trend=0
        else:
            pass
    elif trend==-1:
        if temp>0:
            trend=0
        elif temp<0:
            pass
        else:
            pass

print(ans if trend!=0 else ans+1)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
X=int(input())

if X==1:
    print(1)
    exit()
elif X==2:
    print(2)
    exit()

l=[1]
i=2
while True:
    temp=[]
    for item in l:
        temp.append(item+i)
    if X in temp:
        print(i)
        exit()
    else:
        l+=temp
        i+=1

Fixed submission:
# coding: utf-8
# Your code here!
X=int(input())

i=0
count=0
while True:
    i+=1
    count+=i
    if count>=X:
        print(i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0

l=[A[0]]
for i in range(1,len(A)+1):
    l.append(sum(A[0:i+1]))
    if (l[i]-l[i-1])>2*l[i-1]:
        ans=0
    else:
        ans+=1

print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0

l=[A[0]]
for i in range(len(A)-1):
    l.append(l[-1]+A[i+1])
    if (l[-1]-l[-2])>2*l[-2]:
        ans=0
    else:
        ans+=1

print(ans+1)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

AN=[]
for _ in range(N):
    AN.append(list(input()))
    
#print(AN)

AM=[]
for _ in range(M):
    AM.append(list(input()))

#print(AM)
for i in range(N-M+1):
    flag=False
    for j in range(N-M+1):
        if AN[i][j:j+M]==AM[0]:
            for k in range(i,i+M):
                if AN[k][j:j+M]!=AM[k]:
                    flag=True
                    break
            if flag:
                break
            print("Yes")
            exit()
                    

print("No")

Fixed submission:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

AN=[]
for _ in range(N):
    AN.append(list(input()))
    
#print(AN)

AM=[]
for _ in range(M):
    AM.append(list(input()))

#print(AM)
for i in range(N-M+1):
    for j in range(N-M+1):
        #print(i,j)
        flag=True
        for k in range(M):
            if AN[i+k][j:j+M]!=AM[k]:
                #print(AN[i+k][j:j+M],AM[k])
                flag=False
        if flag:
            print("Yes")
            exit()
        
print("No")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

def dfs(num):
    visited[num]=1
    for item in way[num]:
        if visited[item]==0:
            dfs(item)
    return 

mem=[-1]*M
way=[[] for i in range(N)]
visited=[0]*N
for n in range(N):
    temp=list(map(int,input().split()))
    
    for i in range(temp[0]):
        if mem[temp[i+1]-1]==-1:
            mem[temp[i+1]-1]=n
        else:
            way[mem[temp[i+1]-1]].append(n)
            way[n].append(mem[temp[i+1]-1])

for i in range(N):
    way[i]=list(set(way[i]))

dfs(0)

if visited.count(0)==0:
    print("Yes")
else:
    print("No")



    

Fixed submission:
import sys

sys.setrecursionlimit(10**9)

N,M=map(int,input().split())

def dfs(num):
    visited[num]=1
    for item in way[num]:
        if visited[item]==0:
            dfs(item)
    return 

mem=[-1]*M
way=[[] for i in range(N)]
visited=[0]*N
for n in range(N):
    temp=list(map(int,input().split()))
    
    for i in range(temp[0]):
        if mem[temp[i+1]-1]==-1:
            mem[temp[i+1]-1]=n
        else:
            way[mem[temp[i+1]-1]].append(n)
            way[n].append(mem[temp[i+1]-1])

for i in range(N):
    way[i]=list(set(way[i]))

dfs(0)

if visited.count(0)==0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
s=list(input())
count=0

for i in range(len(s)):#偶数ならグー　奇数ならパーになる
    if s[i]=='g':
        s[i]=0
    else:
        s[i]=1
    print(s)
    if i&1^s[i]==1 and i&1==1:
        count+=1
    elif i&1^s[i]==1 and s[i]&1==1:
        count-=1
    else:
        pass

print(count)



Fixed submission:
# coding: utf-8
# Your code here!
s=list(input())
count=0

for i in range(len(s)):#偶数ならグー　奇数ならパーになる
    if s[i]=='g':
        s[i]=0
    else:
        s[i]=1
    if i&1^s[i]==1 and i&1==1:
        count+=1
    elif i&1^s[i]==1 and s[i]&1==1:
        count-=1
    else:
        pass

print(count)