Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
n = len(s)

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

ans = 0

if s[0] != s[-1]:
    for d in data:
        ans += d//2
    ans *= k
elif len(data) == 1:
    ans = n*k//2
else:
    for i in range(1,n-1):
        ans += data[i]//2
    ans *= k
    ans += data[0]//2 + data[-1]//2 + (data[0] + data[-1])//2 * (k-1)

print(ans)

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

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

ans = 0

if s[0] != s[-1]:
    for d in data:
        ans += d//2
    ans *= k
elif len(data) == 1:
    ans = n*k//2
else:
    for i in range(1,len(data)-1):
        ans += data[i]//2
    ans *= k
    ans += data[0]//2 + data[-1]//2 + (data[0] + data[-1])//2 * (k-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()

ans = 0
c = 0
for i in range(1,n):
    if s[i] == s[i-1]:
     ans += 1
    else:
        c += 1
if c == 1:
    print(ans+1)
    exit()

t = -1
for i in range(1,n):
    now = s[i-1]
    if s[i] != now:
        t += 1
    if t == 1 and k > 0:
        k -= 1
        ans += 2
        t = -1
    #print(ans)

if k > 0 and now != s[n-1]:
    ans += 1
print(ans)

Fixed submission:
n,k = map(int,input().split())
s = input()
if len(s) == 1:
    print(0)
    exit()

ans = 0
c = 0
for i in range(1,n):
    if s[i] == s[i-1]:
        ans += 1
    else:
        c += 1

if c == 1:
    print(n-1)
    exit()


t = -1
left = s[0]
q = -1
for i in range(1,n):
    if s[i] != left:
        t += 1
        left = s[i]
    if t == 1 and k > 0:
        k -= 1
        ans += 2
        t = -1

if t == 0 and k > 0:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import time
start = time.time()
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
s = [0 for i in range(n)] #それぞれ何試合目か
ans = 0
need = n*(n-1)//2
while need:
    c = [0 for i in range(n)] #今日試合をするかどうか
    ans += 1
    for first in range(n):
        if c[first] == 0 and s[first] < n-1:
            second = a[first][s[first]]-1 # firstが対戦したい相手
            second_num = s[second] # #secondの対戦番号
            if c[second] == 0 and a[second][second_num]-1 == first:
                c[first] = 1
                c[second] = 1
                s[first] += 1
                s[second] += 1
                need -= 1
    if sum(c) == 0:
        print(-1)
        exit()
    now = time.time()-start
    if now > 1.83:
        print(n*(n-1)//2)
        exit()
print(ans)

Fixed submission:
s = input()
t = input()
ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
import time
start = time.time()
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
s = [0 for i in range(n)] #それぞれ何試合目か
ans = 0
need = n*(n-1)//2
while need:
    c = [0 for i in range(n)] #今日試合をするかどうか
    ans += 1
    for first in range(n):
        if c[first] == 0 and s[first] < n-1:
            second = a[first][s[first]]-1 # firstが対戦したい相手
            second_num = s[second] # #secondの対戦番号
            if c[second] == 0 and a[second][second_num]-1 == first:
                c[first] = 1
                c[second] = 1
                s[first] += 1
                s[second] += 1
                need -= 1
    if sum(c) == 0:
        print(-1)
        exit()
    now = time.time()-start
    if now > 1.81:
        print(n*(n-1)//2)
        exit()
print(ans)

Fixed submission:
s = input()
t = input()
ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right
alphabet_small = [chr(i) for i in range(97, 97+26)]
s = input()
t = input()
m = len(s)
n = len(t)

alpha = [[] for i in range(26)]
for i,let in enumerate(s):
    for j,al in enumerate(alphabet_small):
        if let == al:
            alpha[j].append(i)

#alpha　はsのどこに文字があるか

dp = [0 for i in range(n+1)] #i文字目までの最小
#求めるのはdp[n]
t_num = []
append = t_num.append
for let in t:
    for j,al in enumerate(alphabet_small):
        if let == al:
            t_num.append(j)

#t_num　はtの文字を数字に変換
now = -1
for i,let_num in enumerate(t_num):
    #print(i,let_num,alpha[let_num])
    if len(alpha[let_num]) == 0:
        print(-1)
        exit()
    else:
        if alpha[let_num][-1] >= now:
            q = bisect_right(alpha[let_num],now)
            next = alpha[let_num][q]
            #print(next)
            dp[i+1] = dp[i] + next - now
        else:
            next = alpha[let_num][0]
            #print(next)
            dp[i+1] = dp[i] + next - now + m
        now = next


print(dp[n])

Fixed submission:
from bisect import bisect_right,bisect_left
alphabet_small = [chr(i) for i in range(97, 97+26)]
s = input()
t = input()
m = len(s)
n = len(t)

alpha = [[] for i in range(26)]
for i,let in enumerate(s):
    for j,al in enumerate(alphabet_small):
        if let == al:
            alpha[j].append(i)

#alpha　はsのどこに文字があるか

dp = [0 for i in range(n+1)] #i文字目までの最小
#求めるのはdp[n]
t_num = []
append = t_num.append
for let in t:
    for j,al in enumerate(alphabet_small):
        if let == al:
            t_num.append(j)

#t_num　はtの文字を数字に変換
now = -1
for i,let_num in enumerate(t_num):
    #print(i,let_num,alpha[let_num])
    if len(alpha[let_num]) == 0:
        print(-1)
        exit()
    else:
        q = bisect_right(alpha[let_num], now)
        #print(q)
        if q != len(alpha[let_num]):
            next = alpha[let_num][q]
            #print(now,next,1)
            if now == next:
                dp[i+1] += m
                #print(dp[i+1])
            dp[i+1] += dp[i] + next - now
        else:
            next = alpha[let_num][0]
            dp[i+1] += dp[i] + next - now + m
        now = next



print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = [0 for i in range(n)]
used = [False for _ in range(n)]
for i in range(n):
    if used[i]:
        continue
    else:
        used[i] = True
        stand = [1,0]
        pre = -1
        now = i
        next = 0
        count = 1
        if s[now] == 'R':
            next = now+1
        else:
            next = now-1
        while pre != next:
            count *= -1
            pre = now
            now = next
            if s[now] == 'R':
                next = now + 1
            else:
                next = now - 1
            if not used[now]:
                if count == 1:
                    stand[0] += 1
                else:
                    stand[1] += 1
            used[now] = True
        used[next] = True
        if (pre-i)%2 == 1:
            ans[pre] += stand[1]
            ans[now] += stand[0]
        else:
            ans[pre] += stand[0]
            ans[now] += stand[1]

for i in range(n):
    print(ans[i],end=' ')
print()


Fixed submission:
s = input()
n = len(s)
ans  =[0 for i in range(n)]
i = 0
while i < n:
    le = i
    while i+1 < n and s[i] == s[i+1]:
        i += 1
    length = i - le + 1
    if s[i] == 'L':
        ans[le]+=(length+1)//2
        ans[le-1] += length//2
    else:
        ans[i] += (length+1)//2
        ans[i+1] += length//2
    i += 1

for i in range(n):
    print(ans[i],end=' ')

print()

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = [0 for i in range(n)]
used = [False for _ in range(n)]
for i in range(n):
    if used[i]:
        continue
    else:
        used[i] = True
        stand = [1,0]
        pre = -1
        now = i
        next = 0
        count = 1
        if s[now] == 'R':
            next = now+1
        else:
            next = now-1
        while pre != next:
            count *= -1
            pre = now
            now = next
            if s[now] == 'R':
                next = now + 1
            else:
                next = now - 1
            if not used[now]:
                if count == 1:
                    stand[0] += 1
                else:
                    stand[1] += 1
            used[now] = True
        used[next] = True
        if (pre-i)%2 == 1:
            ans[pre] += stand[1]
            ans[now] += stand[0]
        else:
            ans[pre] += stand[0]
            ans[now] += stand[1]

for i in range(n):
    print(ans[i],end=' ')
print()


Fixed submission:
s = input()
n = len(s)
ans  =[0 for i in range(n)]
i = 0
while i < n:
    le = i
    while i+1 < n and s[i] == s[i+1]:
        i += 1
    length = i - le + 1
    if s[i] == 'L':
        ans[le]+=(length+1)//2
        ans[le-1] += length//2
    else:
        ans[i] += (length+1)//2
        ans[i+1] += length//2
    i += 1

for i in range(n):
    print(ans[i],end=' ')

print()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
MOD = 10**9 + 7
n = len(s)

data = [0 for i in range(n+2)] #10**iを13で割ったあまり
data[0] = 1
for i in range(1,n+2):
    data[i] = (data[i-1]*10)%13


dp = [[0 for i in range(13)] for j in range(10**5+100)]

if s[0] ==  '?':
    for i in range(10):
        dp[0][i] = 1
else:
    i = int(s[0])
    dp[0][i] = 1


for i in range(1,n):
    for j in range(13):
        if s[i] == '?':
            for k in range(10):
                dp[i][(k*data[i] + j)%13] += dp[i-1][j]
        else:
            num = int(s[i])
            dp[i][(num*data[i]+j)%13] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %=MOD

print(dp[n-1][5])


Fixed submission:
s = input()[::-1]
MOD = 10**9 + 7
n = len(s)

data = [0 for i in range(n+2)] #10**iを13で割ったあまり
data[0] = 1
for i in range(1,n+2):
    data[i] = (data[i-1]*10)%13


dp = [[0 for i in range(13)] for j in range(10**5+100)]

if s[0] ==  '?':
    for i in range(10):
        dp[0][i] = 1
else:
    i = int(s[0])
    dp[0][i] = 1


for i in range(1,n):
    for j in range(13):
        if s[i] == '?':
            for k in range(10):
                dp[i][(k*data[i] + j)%13] += dp[i-1][j]
        else:
            num = int(s[i])
            dp[i][(num*data[i]+j)%13] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %=MOD

print(dp[n-1][5])
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
n = int(input())
ans = [int(input())]
for i in range(n-1):
    now = int(input())
    j = bisect_left(ans,now)
    if j == 0:
        ans.insert(0,now)
    else:
        ans[j-1] = now

print(len(ans))

Fixed submission:
n = int(input())


def divisor(n):  # 約数全列挙
    ans = [1, n]
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            ans.append(i)
            if i ** 2 < n:
                ans.append(n // i)
        i += 1
    ans.sort()
    return ans
a = list(map(int,input().split()))
ans = []
for num in range(n-1,-1,-1):
    if a[num] %2== 1:
        ans.append(num+1)
        q = divisor(num+1)
        for j in q:
            a[j-1] += 1

print(len(ans))
for i in ans:
    print(i,end=' ')

print()
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
MOD = 10**9 + 7


def combination(n, r,mod):# nCrを求める
    if r == -1 or n < r:
        return 0
    r = min(n-r, r)
    result = 1
    for i in range(n, n-r, -1):
        result *= i
    for i in range(1, r+1):
        result //= i
    return result%mod
q = [combination(n-k-1,i,MOD) for i in range(k+1)]

for i in range(k):
    ans = 0
    if i == 0:
        print(n-k+1)
    else:
        p = combination(k-1,i,MOD)
        r = q[i-1] + q[i]*2 + q[i+1]
        r %=MOD
        ans +=p*r
        ans %=MOD
        print(ans)

Fixed submission:
n,k = map(int,input().split())
MOD = 10**9 + 7

memo = [-1 for i in range(k+1)]
memo[0] = 1
now = 1
for i in range(1,k+1):
    now = now*(n-k-i)//i
    memo[i] = now%MOD

memo2 = [-1 for i in range(k)]
memo2[0] = 1
now = 1
for i in range(1,k):
    now = now*(k-i)//i
    memo2[i] = now%MOD

for i in range(k):
    ans = 0
    if i == 0:
        print(n-k+1)
    else:
        p = memo2[i]
        r = memo[i-1] + memo[i]*2 + memo[i+1]
        r %=MOD
        ans +=p*r
        ans %=MOD
        print(ans)

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


def combination(n, r,mod):# nCrを求める
    if r == -1 or n < r:
        return 0
    r = min(n-r, r)
    result = 1
    for i in range(n, n-r, -1):
        result *= i
    for i in range(1, r+1):
        result //= i
    return result%mod


for i in range(k):
    ans = 0
    if i == 0:
        print(n-k+1)
    else:
        p = combination(k-1,i,MOD)
        q = combination(n-k-1,i-1,MOD)+combination(n-k-1,i,MOD)*2 + combination(n-k-1,i+1,MOD)
        q %=MOD
        ans +=p*q
        ans %=MOD
        print(ans)

Fixed submission:
n,k = map(int,input().split())
MOD = 10**9 + 7

memo = [-1 for i in range(k+1)]
memo[0] = 1
now = 1
for i in range(1,k+1):
    now = now*(n-k-i)//i
    memo[i] = now%MOD

memo2 = [-1 for i in range(k)]
memo2[0] = 1
now = 1
for i in range(1,k):
    now = now*(k-i)//i
    memo2[i] = now%MOD

for i in range(k):
    ans = 0
    if i == 0:
        print(n-k+1)
    else:
        p = memo2[i]
        r = memo[i-1] + memo[i]*2 + memo[i+1]
        r %=MOD
        ans +=p*r
        ans %=MOD
        print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
pq = []
for i in range(n):
    for j in range(n):
        r = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        if i!=j:
            pq.append(r)
#print(pq)
ans = Counter(pq).most_common()
print(n-ans[0][1])

Fixed submission:
from collections import Counter
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
pq = []
if n == 1:
    print(1)
    exit()
for i in range(n):
    for j in range(n):
        r = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        if i!=j:
            pq.append(r)
#print(pq)
ans = Counter(pq).most_common()
print(n-ans[0][1])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
MOD = 10**9 + 7

q = [1,2]
append = q.append
for i in range(10**5+10):
    if i >= 2:
        t = q[i-1]+q[i-2]
        t%= MOD
        append(t)
ans = 1
a_pre = 0
for i in range(m+1):
    if i == m:
        if a_now == n-1:
            print(0)
            exit()
        else:
            ans *= q[n-a_now-2]
            ans %=MOD
            break
    if i>0:
        a_pre = a_now
    a_now = int(input())
    if i == 0:
        if a_now != 1:
            ans*=q[a_now-2]
            ans%=MOD
    if i>0:
        if a_pre + 1 == a_now:
            print(0)
            exit()
        else:
            if a_now-a_pre-3!=-1:
                ans*=q[a_now-a_pre-3]
            ans %=MOD

print(ans)

Fixed submission:
n,m = map(int,input().split())
MOD = 10**9 + 7
dp = [0 for i in range(n+1)]
t = [True for _ in range(n+1)]
for i in range(m):
    a = int(input())
    t[a] = False

dp[0] = 1
for now in range(n):
    for next in range(now+1,min(n+1,now+3)):
        if t[next]:
            dp[next] += dp[now]
            dp[next] %= MOD

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [input() for i in range(h)]


p = []
append1 = p.append
for i in range(h):
    q = []
    t = False
    now = 0
    for j in range(w):
        if s[i][j] == '.':
            t = True
            now += 1
            if j == w-1:
                q = q + [now for _ in range(now)]
        else:
            if t:
                q = q + [now for _ in range(now)] + [0]
                t = False
                now = 0
            else:
                q = q + [0]
                now = 0
    append1(q)
p2 = []
append2 = p2.append
for i in range(w):
    r = []
    t = False
    now = 0
    for j in range(h):
        if s[j][i] == '.':
            t = True
            now += 1
            if j == h-1:
                r = r + [now for _ in range(now)]
        else:
            if t:
                r = r + [now for _ in range(now)] + [0]
                t = False
                now = 0
            else:
                r = r + [0]
                now = 0
    append2(r)

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,p[i][j] + p2[j][i]-1)

print(ans)

Fixed submission:
h,w = map(int,input().split())
s = [input() for i in range(h)]

left =[[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                left[i][j] = 1
        else:
            if s[i][j] == '.':
                left[i][j] = left[i][j-1] + 1
            else:
                left[i][j] = 0

right =[[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    for j in range(w-1,-1,-1):
        if j == w-1:
            if s[i][j] == '.':
                right[i][j] = 1
        else:
            if s[i][j] == '.':
                right[i][j] = right[i][j+1] + 1
            else:
                right[i][j] = 0

forward =[[0 for _ in range(w)] for _ in range(h)]

for j in range(w):
    for i in range(h):
        if i == 0:
            if s[i][j] == '.':
                forward[i][j] = 1
        else:
            if s[i][j] == '.':
                forward[i][j] = forward[i-1][j] + 1
            else:
                forward[i][j] = 0

backward =[[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    for i in range(h-1,-1,-1):
        if i == h-1:
            if s[i][j] == '.':
                backward[i][j] = 1
        else:
            if s[i][j] == '.':
                backward[i][j] = backward[i+1][j] + 1
            else:
                backward[i][j] = 0

ans = 0
for i in range(h):
    for j in range(w):
        now = right[i][j]+left[i][j]+forward[i][j]+backward[i][j]-3
        ans = max(ans,now)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
n,a,b,c,d = map(int,input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
truth = [[0 for i in range(n)],[0 for j in range(n)]]

def solve(now,dest):
    for i in  range(now,dest):
        if s[i] == '#' and s[i+1] == '#':
            return False
    return True
if c < d:
    if solve(a,c,0) and solve(b,d,1):
        print('Yes')
    else:
        print('No')

else:
    q = False
    for i in range(b,d):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            q = True
            break
        if s[i-1] == '#' and s[i] == '#':
            print('No')
            exit()
    if q and solve(a,c,0) and solve(b,d,1):
        print('Yes')
    else:
        print('No')

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
n,a,b,c,d = map(int,input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
truth = [[0 for i in range(n)],[0 for j in range(n)]]

def solve(now,dest):
    for i in  range(now,dest):
        if s[i] == '#' and s[i+1] == '#':
            return False
    return True
if c < d:
    if solve(a,c) and solve(b,d):
        print('Yes')
    else:
        print('No')

else:
    q = False
    for i in range(b,d+1):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            q = True
            break
    if q and solve(a,c) and solve(b,d):
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
sp = []
for i in range(n):
    s,t = map(str,input().split())
    sp.append([s,-t,i+1])

sp.sort()
for i in range(n):
    print(sp[i][2])

Fixed submission:
n = int(input())
sp = []
for i in range(n):
    s,t = map(str,input().split())
    t = int(t)
    sp.append([s,-t,i+1])

sp.sort()
for i in range(n):
    print(sp[i][2])
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = [-1]*(n+1)
data =[[] for i in range(n+1)]

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

ans[1] = 1
def color(i):
    for v, w in data[i]:
        if ans[v] == -1:
            if w % 2 == 0:
                ans[v] = ans[i]
            else:
                ans[v] = 1 - ans[i]
            color(v)
    return

color(1)
for i in range(n):
    print(ans[i+1])

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

n = int(input())
ans = [-1]*(n+1)
data =[[] for i in range(n+1)]

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

ans[1] = 1
def color(i):
    for v, w in data[i]:
        if ans[v] == -1:
            if w % 2 == 0:
                ans[v] = ans[i]
            else:
                ans[v] = 1 - ans[i]
            color(v)
    return

color(1)
for i in range(n):
    print(ans[i+1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = [-1]*n
data =[[] for i in range(n+1)]

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

ans[0] = 1
def color(i):
    for v,w in data[i]:
        if ans[v] == -1:
            if w % 2 == 0:
                ans[v] = ans[i]
            else:
                ans[v] = 1 - ans[i]
            color(v)
    return

color(0)
for i in range(n):
    print(ans[i])

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

n = int(input())
ans = [-1]*(n+1)
data =[[] for i in range(n+1)]

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

ans[1] = 1
def color(i):
    for v, w in data[i]:
        if ans[v] == -1:
            if w % 2 == 0:
                ans[v] = ans[i]
            else:
                ans[v] = 1 - ans[i]
            color(v)
    return

color(1)
for i in range(n):
    print(ans[i+1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = [-1]*n
data =[[] for i in range(n)]

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

ans[0] = 0
def color(i):
    for v,w in data[i]:
        if ans[v]== -1:
            if w%2 == 0:
                ans[v] = ans[i]
            else:
                ans[v] = 1 - ans[i]
            color(v)
    return

color(0)
for i in range(n):
    print(ans[i])

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

n = int(input())
ans = [-1]*(n+1)
data =[[] for i in range(n+1)]

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

ans[1] = 1
def color(i):
    for v, w in data[i]:
        if ans[v] == -1:
            if w % 2 == 0:
                ans[v] = ans[i]
            else:
                ans[v] = 1 - ans[i]
            color(v)
    return

color(1)
for i in range(n):
    print(ans[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
import functools
from fractions import gcd
ans = 0
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    ans = max(ans,functools.reduce(gcd,a[:i] + a[i+1:]))

print(ans)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mae = [a[0]]
for i in range(n-1):
    mae.append(gcd(mae[i],a[i+1]))
ushiro = [a[n-1]]
for i in range(n-1):
    ushiro.append(gcd(ushiro[i],a[n-i-2]))

ans = ushiro[n-2]

for i in range(n-1):
    if i != n-2:
        ans = max(ans,gcd(mae[i],ushiro[n-i-3]))
    else:
        ans = max(ans,mae[n-2])

print(ans)