Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for x in b:
    for i in range(60):
        if x[59-i]=='0':
            ans += ones[i]*pow_two[i]
        else:
            ans += (n-ones[i])*pow_two[i]


print((ans//2)%mod)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for i in range(60):
    ans += ones[i]*(n-ones[i])*pow_two[i]
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]
b = [list(reversed(x)) for x in b]


ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for i in range(60):
    ans += ones[i]*(n-ones[i])*pow_two[i]
    ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for i in range(60):
    ans += ones[i]*(n-ones[i])*pow_two[i]
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import accumulate
import bisect


n,k = map(int, input().split())

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

s = list(accumulate([0]+a))

b = [(s[i]-i)%k for i in range(n+1)]

d = defaultdict(int)

# 初期化
for i in range(k-1):
    d[b[i]]+=1

ans = 0
for i in range(n):
    # 自分を除外し、k-1個先が存在すれば加える。
    d[b[i]]-=1
    if i+k-1<=n:
        d[b[i+k-1]]+=1
    ans += d[b[i]]

print(ans)




Fixed submission:
from collections import defaultdict
from itertools import accumulate
import bisect


n,k = map(int, input().split())

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

s = list(accumulate([0]+a))

b = [s[i]-i for i in range(n+1)]

d = defaultdict(list)

for i in range(n+1):
    d[b[i]%k].append(i)

ans = 0
for x in d.keys():
    l = d[x]
    for j in range(len(l)):
        y = l[j]
        ans += max(0,bisect.bisect_right(l,k+y-1)-j-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
def factorials(n,m):
    # 0~n!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    # 0~n!の逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

x,y = map(int, input().split())

m = 10**9+7

b = (2*y-x)//3
a = y-2*b

if a+2*b!=y or 2*a+b!=x:
    print(0)
    exit()

f,g = factorials(a+b,m)

nCr = f[a+b]*g[b]*g[a]

print(nCr%m)

Fixed submission:
def factorials(n,m):
    # 0~n!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    # 0~n!の逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

x,y = map(int, input().split())

m = 10**9+7

if (2*y-x)%3!=0:
    print(0)
    exit()

b = (2*y-x)//3
a = y-2*b

if a<0 or b<0:
    print(0)
    exit()

f,g = factorials(a+b,m)

nCr = f[a+b]*g[b]*g[a]

print(nCr%m)
Buggy python submission (verdict: Runtime Error):
import math

a,b,x = map(int, input().split())


if a**2*b/2<=x:
    ans = 90-math.degrees(math.atan(a**3/2/(a**2*b-x)))
else:
    ans = 90-math.degrees(math.atan(2*x/a/b**2))
print(ans)

Fixed submission:
import math

a,b,x = map(int, input().split())

if x==a**2*b:
    print(0)
    exit()

if a**2*b/2<=x:
    ans = 90-math.degrees(math.atan(a**3/2/(a**2*b-x)))
else:
    ans = 90-math.degrees(math.atan(2*x/a/b**2))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
a = []

for i in range(n):
    for j in range(i+1,n+1):
        a.append([s[i:j],i,j-1])

a.sort()
a.reverse()

ans = 0
for i in range(len(a)-1):
    if a[i][0]==a[i+1][0]:
        if a[i][2]<a[i+1][1] or a[i][1]>a[i+1][2]:
            ans = max(ans,len(a[i][0]))
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


def z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        z[i] = j

        if j==0:
            i+=1
            continue

        k = 1
        while k+z[k]<j:
            z[i+k] = z[k]
            k+=1
        
        i+=k
        j-=k
    
    return z

n = readint()
s = readstr()

ans = 0
for i in range(n):
    z = z_algorithm(s[i:])
    for j in range(n-i):
        if z[j]<=j:
            ans = max(ans,z[j])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import time

start = time.time()

n = int(input())
s = list(map(int, input().split()))

s.sort()
s.reverse()

flag = True
for i in range(n):
    a = s[0:2 ** i]
    b = s[2 ** i:2 ** (i + 1)]
    for j in range(len(a)):
        if b[j] >= a[j]:
            flag = False
            break
if flag:
    print('Yes')
    exit()

s.reverse()

a = []
a.append(s[-1])
s.pop(-1)
for i in range(n):
    for j in range(len(a)):
        for k in range(len(s)):
            if a[j]>s[-1-k]:
                a.append(s[-1-k])
                s.pop(-1-k)
                break
    if len(a)!=2**(i+1):
        print('No')
        exit()
    if time.time() -start > 1.8:
        print('Yes')
        exit()
print('Yes')


Fixed submission:
import time

start = time.time()

n = int(input())
s = list(map(int, input().split()))

s.sort()
s.reverse()

flag = True
for i in range(n):
    a = s[0:2 ** i]
    b = s[2 ** i:2 ** (i + 1)]
    for j in range(len(a)):
        if b[j] >= a[j]:
            flag = False
            break
if flag:
    print('Yes')
    exit()

s.reverse()

a = []
a.append(s[-1])
s.pop(-1)
for i in range(n):
    for j in range(len(a)):
        for k in range(len(s)):
            if a[j]>s[-1-k]:
                a.append(s[-1-k])
                s.pop(-1-k)
                break
        if time.time() - start > 1.8:
            print('Yes')
            exit()
    if len(a)!=2**(i+1):
        print('No')
        exit()

print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(map(int, input().split()))

s.sort()

a = []
a.append(s[-1])
s.pop(-1)
for i in range(n):
    for j in range(len(a)):
        for k in range(len(s)):
            if a[j]>s[-1-k]:
                a.append(s[-1-k])
                s.pop(-1-k)
                break
    if len(a)!=2**(i+1):
        print('No')
        exit()
print('Yes')


Fixed submission:
import time

start = time.time()

n = int(input())
s = list(map(int, input().split()))

s.sort()
s.reverse()

flag = True
for i in range(n):
    a = s[0:2 ** i]
    b = s[2 ** i:2 ** (i + 1)]
    for j in range(len(a)):
        if b[j] >= a[j]:
            flag = False
            break
if flag:
    print('Yes')
    exit()

s.reverse()

a = []
a.append(s[-1])
s.pop(-1)
for i in range(n):
    for j in range(len(a)):
        for k in range(len(s)):
            if a[j]>s[-1-k]:
                a.append(s[-1-k])
                s.pop(-1-k)
                break
        if time.time() - start > 1.8:
            print('Yes')
            exit()
    if len(a)!=2**(i+1):
        print('No')
        exit()

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import queue

n,q = map(int, input().split())

d = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

c = [0]*n

for i in range(q):
    p,x = map(int,input().split())
    c[p-1]+=x

ans = [0]*n
visited = [0]*n

que = queue.Queue()

que.put(0)
visited[0]=1
ans[0]+=c[0]

while not que.empty():
    x = que.get()
    for y in d[x]:
        if visited[y]==1:
            continue
        else:
            ans[y]+=ans[x]+c[y]
            visited[y]=1
            que.put(y)



print(' '.join(map(str,ans)))


Fixed submission:
n,q = map(int, input().split())

d = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

c = [0]*n

for i in range(q):
    p,x = map(int,input().split())
    c[p-1]+=x

ans = [0]*n
visited = [0]*n

que = []

que.append(0)
visited[0]=1
ans[0]+=c[0]

while que:
    x = que.pop()
    for y in d[x]:
        if visited[y]==1:
            continue
        else:
            ans[y]+=ans[x]+c[y]
            visited[y]=1
            que.append(y)



print(' '.join(map(str,ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import queue

n,q = map(int, input().split())

d = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

c = [0]*n

for i in range(q):
    p,x = map(int,input().split())
    c[p-1]+=x

ans = [0]*n
visited = [0]*n

que = queue.Queue()

que.put(0)
visited[0]=1
ans[0]+=c[0]

while not que.empty():
    x = que.get()
    for y in d[x]:
        if visited[y]==1:
            continue
        else:
            ans[y]+=ans[x]+c[y]
            visited[y]=1
            que.put(y)



print(' '.join(map(str,ans)))


Fixed submission:
n,q = map(int, input().split())

d = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

c = [0]*n

for i in range(q):
    p,x = map(int,input().split())
    c[p-1]+=x

ans = [0]*n
visited = [0]*n

que = []

que.append(0)
visited[0]=1
ans[0]+=c[0]

while que:
    x = que.pop()
    for y in d[x]:
        if visited[y]==1:
            continue
        else:
            ans[y]+=ans[x]+c[y]
            visited[y]=1
            que.append(y)



print(' '.join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
import heapq

n,m = map(int, input().split())

c = [[]for i in range(10**5)]

for i in range(n):
    a,b = map(int,input().split())
    c[a].append(-b)


h = []
heapq.heapify(h)
ans = 0

for i in range(m):
    for x in c[i+1]:
        heapq.heappush(h,x)
    if h:
        ans += heapq.heappop(h)

print(-ans)


Fixed submission:
import heapq

n,m = map(int, input().split())

c = [[]for i in range(10**5+10)]

for i in range(n):
    a,b = map(int,input().split())
    c[a].append(-b)


h = []
heapq.heapify(h)
ans = 0

for i in range(m):
    for x in c[i+1]:
        heapq.heappush(h,x)
    if h:
        ans += heapq.heappop(h)

print(-ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

n = len(s)
mod = 10**9+7

dp = [[0]*13 for i in range(n+1)]
dp[0][0]=1

for i in range(n):
    if s[-1-i]=='?':
        p = [(x*10**i)%13 for x in range(0,10)]
    else:
        p = [(int(s[-1-i])*10**i)%13]
    for j in range(13):
        for x in p:
            dp[i+1][(j+x)%13] += dp[i][j]
    for j in range(13):
        dp[i+1][j]%=mod

print(dp[-1][5])


Fixed submission:
s = input()

n = len(s)
mod = 10**9+7

dp = [[0]*13 for i in range(n+1)]
dp[0][0]=1

for i in range(n):
    if s[-1-i]=='?':
        p = [x*pow(10,i,13) for x in range(0,10)]
    else:
        p = [int(s[-1-i])*pow(10,i,13)]
    for j in range(13):
        for x in p:
            dp[i+1][(j+x)%13] += dp[i][j]
    for j in range(13):
        dp[i+1][j]%=mod

print(dp[-1][5])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

t = sum(a)//2

for i in range(n):
    b = t
    if i==0 or i==1:
        b-= sum(a[i+1::2])
    else:
        b -= sum(a[i+1::2]+a[i-2::-2])
    print(b*2,end=' ')



Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = sum(a)//2

b = [0]*n

b[0]=sum(a[1::2])
b[1]=sum(a[2::2])

for i in range(2,n):
    b[i] =b[i-2]-a[i-1]+a[i-2]

for i in range(n):
    print((t-b[i])*2, end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
m = 10**9+7

n,k = map(int, input().split())

l = [0 for i in range(n)]
ll = [[]for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    l[a]+=1
    l[b]+=1
    ll[a].append(b)
    ll[b].append(a)

if n==1:
    print(k)
    exit()
if k<3:
    if n==1:
        print(k)
        exit()
    elif n==2:
        print(k*(k-1))
        exit()
    else:
        print(0)
        exit()

q = max(l)
if k<q+1:
    print(0)
    exit()

f = [1,1]
for i in range(2,k+1):
    f.append(f[-1]*i%m)

g = [1]
for i in range(k):
    g.append(pow(f[i+1],m-2,m))


ans = k

ans *= f[k-1]*g[k-1-l[0]]%m

visited = [0]*n
visited[0]==1
for x in ll[0]:
    visited[x]==1

for i in range(1,n):
    if visited[i] ==0:
        ans *= f[k-2]*g[k-1-l[i]]%m
        for x in ll[i]:
            visited[x]==1

print(ans%m)



Fixed submission:
m = 10**9+7

n,k = map(int, input().split())

l = [0 for i in range(n)]
ll = [[]for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    l[a]+=1
    l[b]+=1
    ll[a].append(b)
    ll[b].append(a)

if n==1:
    print(k)
    exit()

q = max(l)
if k<q+1:
    print(0)
    exit()

f = [1,1]
for i in range(2,k+1):
    f.append(f[-1]*i%m)

g = [1]
for i in range(k):
    g.append(pow(f[i+1],m-2,m))


ans = k

ans *= f[k-1]*g[k-1-l[0]]
ans %= m

visited = [0]*n
visited[0]==1
for x in ll[0]:
    visited[x]==1

for i in range(1,n):
    if visited[i] ==0:
        ans *= f[k-2]*g[k-1-l[i]]
        ans %= m
        for x in ll[i]:
            visited[x]==1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import queue

n,m = map(int, input().split())
a = [[] for i in range(n)]

for i in range(m):
    u,v = map(int, input().split())
    u-=1
    v-=1
    a[u].append(v)

s,t = map(int, input().split())
s-=1
t-=1

inf = float('inf')
d = [[inf, inf, inf] for i in range(n)]
d[s][0]=0

q = queue.Queue()
for i in range(len(a[s])):
    q.put(a[s][i])
    d[a[s][i]][1]=1


while not q.empty():
    p = q.get()
    for i in range(len(a[p])):
        r = a[p][i]
        c = []
        if d[r][0]==inf:
            c.append(0)
        if d[r][1]==inf:
            c.append(1)
        if d[r][2]==inf:
            c.append(2)
        if not c:
            continue

        flag = False
        for j in range(len(c)):
            if c[j]==0:
                if d[p][2]!=inf:
                    break
            elif c[j]==1:
                if d[p][0]!=inf:
                    break
            elif c[j]==2:
                if d[p][1]!=inf:
                    break
            if j==len(c)-1:
                flag=True
        if flag:
            continue

        q.put(r)
        if d[r][0]==inf:
            d[r][0]=d[p][2]+1
        if d[r][1]==inf:
            d[r][1]=d[p][0]+1
        if d[r][2]==inf:
            d[r][2]=d[p][1]+1
        if r==t and d[r][0]!=inf:
            print(d[r][0]//3)
            exit()
print(-1)






Fixed submission:
import queue

n,m = map(int, input().split())
a = [[] for i in range(n)]

for i in range(m):
    u,v = map(int, input().split())
    u-=1
    v-=1
    a[u].append(v)

s,t = map(int, input().split())
s-=1
t-=1

inf = float('inf')
d = [[inf, inf, inf] for i in range(n)]
d[s][0]=0

q = queue.Queue()
for i in range(len(a[s])):
    q.put(a[s][i])
    d[a[s][i]][1]=1


while not q.empty():
    p = q.get()
    for i in range(len(a[p])):
        r = a[p][i]
        c = []
        if d[r][0]==inf:
            c.append(0)
        if d[r][1]==inf:
            c.append(1)
        if d[r][2]==inf:
            c.append(2)
        if not c:
            continue

        flag = False
        for j in range(len(c)):
            if c[j]==0:
                if d[p][2]!=inf:
                    break
            elif c[j]==1:
                if d[p][0]!=inf:
                    break
            elif c[j]==2:
                if d[p][1]!=inf:
                    break
            if j==len(c)-1:
                flag=True
        if flag:
            continue

        q.put(r)
        for j in range(len(c)):
            if c[j]==0:
                d[r][0] = d[p][2] + 1
            elif c[j]==1:
                d[r][1] = d[p][0] + 1
            elif c[j]==2:
                d[r][2] = d[p][1] + 1

        if r==t and d[r][0]!=inf:
            print(d[r][0]//3)
            exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
l = input()

a3 = [3**i for i in range(len(l)+5)]
a2 = [2**i for i in range(len(l)+5)]

ans = 0
a = 0
for i in range(len(l)):
    if l[i]=='1':
        ans += (a3[len(l)-i-1]*a2[a])
        a+=1
    if i==len(l)-1:
        ans += a2[a]
    ans %= 10**9+7

print(ans)


Fixed submission:
l = input()

a3 = [1]
a2 = [1]

for i in range(len(l)+5):
    a3.append((a3[-1]*3)%(10**9+7))
    a2.append((a2[-1]*2)%(10**9+7))

ans = 0
a = 0
for i in range(len(l)):
    if l[i]=='1':
        ans += (a3[len(l)-i-1]*a2[a])
        a+=1
    if i==len(l)-1:
        ans += a2[a]
    ans %= 10**9+7

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l = input()

ans = 0
a = 0
for i in range(len(l)):
    if l[i]=='1':
        ans += ((3**(len(l)-i-1))*(2**a))
        a+=1
    if i==len(l)-1:
        ans += (2**a)
    ans %= 10**9+7

print(ans)


Fixed submission:
l = input()

a3 = [1]
a2 = [1]

for i in range(len(l)+5):
    a3.append((a3[-1]*3)%(10**9+7))
    a2.append((a2[-1]*2)%(10**9+7))

ans = 0
a = 0
for i in range(len(l)):
    if l[i]=='1':
        ans += (a3[len(l)-i-1]*a2[a])
        a+=1
    if i==len(l)-1:
        ans += a2[a]
    ans %= 10**9+7

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

if len(s)<3:
    print(0)
    exit()

i = 0
while True:
    if s[i:i+2]=='BC':
        s=s[:i]+'D'+s[i+2:]
    i+=1
    if i>=len(s):
        break


s1 = s.split('B')
s2 = []
for i in range(len(s1)):
    s2+= s1[i].split('C')


ans = 0

for i in range(len(s2)):
    d = s2[i].count('D')
    for j in range(len(s2[i])):
        if s2[i][j]=='A':
            ans += d
        else:
            d-=1

print(ans)

Fixed submission:
s = input()

if len(s)<3:
    print(0)
    exit()

i = 0
while True:
    if s[i:i+2]=='BC':
        s=s[:i]+'D'+s[i+2:]
    i+=1
    if i>=len(s):
        break


s1 = s.split('B')
s2 = []
for i in range(len(s1)):
    s2+= s1[i].split('C')


ans = 0

for i in range(len(s2)):
    d = s2[i].count('D')
    for j in range(len(s2[i])):
        if s2[i][j]=='A':
            ans += d
        else:
            d-=1
            if d == 0:
                break

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n,k = map(int, input().split())

ans = 0
for i in range(1,n+1):
    x = max(0,math.ceil(math.log2(k/i)))
    ans += 0.5**x

print(ans/n)

Fixed submission:
import math

n,k = map(int, input().split())

ans = 0
for i in range(1,n+1):
    x = max(0,math.ceil(math.log2(k/i)))
    ans += 0.5**x

print(ans/n)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))

ans = 0

if n <= 10**3:
    for i in range(n):
        ans = max(gcd_list(a[:i]+a[i+1:]), ans)

    print(ans)
    exit()
else:
    n1 = n//10**3
    n2 = n%10**3

    g = []

    for i in range(n1):
        g.append(gcd_list(a[i*(10**3):(i+1)*(10**3)]))

    if n2 >0:
        g.append(gcd_list(a[n1*(10**3):]))

    for i in range(n):
        memo = g[i//(10**3)]
        g[i//(10**3)] = gcd_list(a[(i//10**3)*(10**3):i] + a[i+1:(i//10**3+1)*(10**3)])
        ans = max(gcd_list(g), ans)
        g[i // (10 ** 3)] = memo
    print(ans)


Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

ans = 0

l = [0]
r = [0]

for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[n-i-1]))

ans = 0

for i in range(n):
    ans = max(ans, fractions.gcd(l[i],r[n-i-1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))

ans = 0

if n <= 10**3:
    for i in range(n):
        ans = max(gcd_list(a[:i]+a[i+1:]), ans)

    print(ans)
    exit()
else:
    n1 = n//10**3
    n2 = n%10**3

    g = []

    for i in range(n1):
        g.append(gcd_list(a[i*(10**3):(i+1)*(10**3)]))

    if n2 >0:
        g.append(gcd_list(a[n1*(10**3):]))

    for i in range(n):
        memo = g[i//(10**3)]
        g[i//(10**3)] = gcd_list(a[(i//10**3)*(10**3):i] + a[i+1:(i//10**3+1)*(10**3)])
        ans = max(gcd_list(g), ans)
        g[i // (10 ** 3)] = memo
    print(ans)
    

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

ans = 0

l = [0]
r = [0]

for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[n-i-1]))

ans = 0

for i in range(n):
    ans = max(ans, fractions.gcd(l[i],r[n-i-1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
    ans = max(gcd_list(a[:i]+a[i+1:]), ans)

print(ans)


Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

ans = 0

l = [0]
r = [0]

for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[n-i-1]))

ans = 0

for i in range(n):
    ans = max(ans, fractions.gcd(l[i],r[n-i-1]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

l = []
for i in range(n):
    if i == 0:
        l.append(1)
        continue
    if s[i] == s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

if s[0]=='.':
    l = l[1:]
if s[-1]=='#':
    l = l[:-1]

bw = sum(l[1::2])

for i in range(len(l)//2+1):
    bw = min(bw, sum(l[:2*i+1:2])+sum(l[2*i+1::2]))

print(bw)


Fixed submission:
n = int(input())
s = input()

black = 0
white = s.count('.')

ans = white + black

for i in range(n):
    if s[i] == '#':
        black += 1
    else:
        white -= 1
    ans = min(ans, white + black)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
s = input()

if s[0]=='1':
    l = [1]
else:
    l = [0,1]

for i in range(1,n):
    if s[i] ==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

ans = 0
for i in range(len(l)//2+1):
    ans = max(ans, sum(l[2*i:2*i+2*k+1]))

print(ans)


Fixed submission:
n,k = map(int, input().split())
s = input()

if s[0]=='1':
    l = [1]
else:
    l = [0,1]

for i in range(1,n):
    if s[i] ==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

prev = sum(l[0:2*k+1])
ans = prev
for i in range(len(l)//2+1):
    prev = prev-sum(l[2*i:2*i+2]) + sum(l[2*i+2*k+1:2*i+2*k+3])
    ans = max(ans, prev)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
s = input()

if s[0]=='1':
    l = [1]
else:
    l = [0,1]

for i in range(1,n):
    if s[i] ==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

ans = 0
for i in range(len(l)//2+1):
    ans = max(ans, sum(l[2*i:2*i+2*k+1]))

print(ans)


Fixed submission:
n,k = map(int, input().split())
s = input()

if s[0]=='1':
    l = [1]
else:
    l = [0,1]

for i in range(1,n):
    if s[i] ==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

prev = sum(l[0:2*k+1])
ans = prev
for i in range(len(l)//2+1):
    prev = prev-sum(l[2*i:2*i+2]) + sum(l[2*i+2*k+1:2*i+2*k+3])
    ans = max(ans, prev)

print(ans)