Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N)]
for i in range(N):
    for w in range(W+1):
        dp[i][w] = dp[i-1][w]
        if w-wv[i][0] >= 0:
            dp[i][w] = max(dp[i][w],dp[i-1][w-wv[i][0]]+wv[i][1])
print(dp[-1][-1])

Fixed submission:
N, W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N)]
for i in range(N):
    for w in range(W+1):
        dp[i][w] = dp[i-1][w]
        if w-wv[i][0] >= 0:
            dp[i][w] = max(dp[i][w],dp[i-1][w-wv[i][0]]+wv[i][1])
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

dp = [None] * (N+1)

def get_dp(i):
    if dp[i] != None:
        return dp[i]
    yListSub = yList[i]
    if yListSub == []:
        dp[i] = 0
        return 0
    else:
        dp[i] = 1+ max(map(get_dp,yListSub))
        return dp[i]

yList = [[] for _ in range(N+1)]
for x,y in xy:
    yList[x].append(y)

[get_dp(i) for i in range(0,N+1)]
print(max(dp))

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

N,M = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

dp = [None] * (N+1)

def get_dp(i):
    if dp[i] != None:
        return dp[i]
    yListSub = yList[i]
    if yListSub == []:
        dp[i] = 0
        return 0
    else:
        dp[i] = 1+ max(map(get_dp,yListSub))
        return dp[i]

yList = [[] for _ in range(N+1)]
for x,y in xy:
    yList[x].append(y)

[get_dp(i) for i in range(0,N+1)]
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(float,input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
#dp[i][j] i枚投げた時 j枚 表が出る確率
for i in range(1,N+1):
    for j in range(i+1):
        dp[i][j] = dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1])
print(sum(dp[N][(N+1)//2:]))

Fixed submission:
N = int(input())
p = list(map(float,input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
#dp[i][j] i枚投げた時 j枚 表が出る確率
for i in range(1,N+1):
    for j in range(i+1):
        dp[i][j] = dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1])
print(sum(dp[N][(N+1)//2:]))
Buggy python submission (verdict: Runtime Error):
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while 1:
    b,n = B.pop()
    if not B : break
    c = (1<<(len(bin(b))-2)) - b
    i = bl(B,[c,0])
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)

Fixed submission:
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while B:
    b,n = B.pop()
    c = (1<<(len(bin(b))-2)) - b
    if c==b :
        ans += n//2
        continue
    i = bl(B,[c,0])
    if i>=len(B): continue
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())

def factoring(M,n=2):
    for i in range(n,int(M**0.5)+1):
        if M%i==0:
            ret = factoring(M//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {M:1}

p = {}
for i in range(2,N+1):
    for k,v in factoring(i).items():
        p[k] = p.get(k,0)+v

c = [0]*4
for n in p.values():
    if n>=24:c[3]+=1
    elif n>=14:c[2]+=1
    elif n>=4:c[1]+=1
    elif n>=2:c[0]+=1

ans = 0
ans += p[2]>=74
ans += c[3]*(sum(c)-1)
c[2] += c[3]
ans += c[2]*(c[1]+c[2]-1)
c[1] +=c[2]
ans += c[0]*c[1]*(c[1]-1)//2
ans += c[1]*(c[1]-1)*(c[1]-2)//2
print(ans)

Fixed submission:
N = int(input())

def get_soinsu(n):
    if n ==1:
        return
    for p in soinsu.keys():
        if n%p == 0:
            soinsu[p] += 1
            get_soinsu(n//p)
            break
    else:
        soinsu[n] = 1

soinsu = {}
for i in range(2,N+1):
    get_soinsu(i)

tmp3 = soinsu.values()
    
#素因数が(74)個の数の選び方
num_74 = len([tmp for tmp in tmp3 if tmp >= 74])

#素因数が(2,24)個の数の選び方
num_24_2 = len([tmp for tmp in tmp3 if tmp >= 24]) * (len([tmp for tmp in tmp3 if tmp >= 2])-1)

#素因数が(4,14)個の数の選び方
num_14_4 = len([tmp for tmp in tmp3 if tmp >= 14]) * (len([tmp for tmp in tmp3 if tmp >= 4])-1)

#素因数が(2,4,4)個の数の選び方
tmp2 = len([tmp for tmp in tmp3 if tmp >= 4])
num_4_4_2 = max(0,tmp2*(tmp2-1)*(len([tmp for tmp in tmp3 if tmp >= 2])-2)//2)

print(num_74 + num_24_2 + num_14_4 + num_4_4_2)
Buggy python submission (verdict: Time Limit Exceeded):
class cumulative_sum:
    def __init__(self,A):
        N = len(A)
        self.S = [0]*(N+1)
        for i in range(N):
            self.S[i+1] = self.S[i] + A[i]
    def get(self,i,j=None):
        if j==None:j=len(self.S)-1
        if j<=i:return 0
        return self.S[j]-self.S[i]
def main():
    N,K = map(int,input().split())
    *A, = map(int,input().split())
    SA = cumulative_sum(A)
    B = {}

    for i in range(N):
        for j in range(i+1,N+1):
            s = SA.get(i,j)
            B[s] = B.get(s,0)+1

    ans = 0
    for i in range(40,-1,-1):
        x = ans + (1<<i)
        c = sum(n for b,n in B.items() if b&x==x)
        if c>=K:ans = x
    print(ans)
main()

Fixed submission:
class cumulative_sum:
    def __init__(self,A):
        N = len(A)
        self.S = [0]*(N+1)
        for i in range(N):
            self.S[i+1] = self.S[i] + A[i]
    def get(self,i,j=None):
        if j==None:j=len(self.S)-1
        if j<=i:return 0
        return self.S[j]-self.S[i]
def main():
    N,K = map(int,input().split())
    *A, = map(int,input().split())
    SA = cumulative_sum(A)
    B = {}

    for i in range(N):
        for j in range(i+1,N+1):
            s = SA.get(i,j)
            B[s] = B.get(s,0)+1

    ans = 0
    for i in range(40,-1,-1):
        x = ans + (1<<i)
        c = sum(n for b,n in B.items() if b&x==x)
        if c>=K:ans = x
    print(ans)
main()
Buggy python submission (verdict: Runtime Error):
S=input()
if S.len()==2:print(S)
else:print(S[::-1])

Fixed submission:
S=input()
if len(S)==2:print(S)
else:print(S[::-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
sorted_data = sorted(data,key=lambda x: x[2])

def get_H(x,y,h,Cx,Cy):
    return max(0,h+abs(x-Cx)+abs(y-Cy))
def estimate_H(data,Cx,Cy):
    H = get_H(*data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp = get_H(*cur_data,Cx,Cy)
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(sorted_data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Fixed submission:
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
data.sort(key=lambda x:-x[2])

def get_H(data,Cx,Cy):
    x,y,h = data
    return h+abs(x-Cx)+abs(y-Cy) , h==0
def estimate_H(data,Cx,Cy):
    H,_ = get_H(data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp,isZero = get_H(cur_data,Cx,Cy)
        if isZero and H <= tmp:
            continue
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Buggy python submission (verdict: Runtime Error):
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]

sorted_data = sorted(data,key=lambda x: x[2])

def estimate_H(data,Cx,Cy):
    H = get_H(*data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp = get_H(*cur_data,Cx,Cy)
        if H != tmp:
            break
    else:
        return H
    return None
def get_H(x,y,h,Cx,Cy):
    return max(0,h+abs(x-Cx)+abs(y-Cy))

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(sorted_data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Fixed submission:
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
data.sort(key=lambda x:-x[2])

def get_H(data,Cx,Cy):
    x,y,h = data
    return h+abs(x-Cx)+abs(y-Cy) , h==0
def estimate_H(data,Cx,Cy):
    H,_ = get_H(data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp,isZero = get_H(cur_data,Cx,Cy)
        if isZero and H <= tmp:
            continue
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int,input().split()))

for i in range(M//N,0,-1):
    if M % i ==0:
        break
print(i)

Fixed submission:
N,M = list(map(int,input().split()))

if M//N < 10**7:
    for i in range(M//N,0,-1):
        if M % i ==0:
            break
    print(i)
else:
    for i in range(N,int(M**0.5)):
        if M % i == 0:
            break
    else:
        i = M
    print(M//i)
Buggy python submission (verdict: Runtime Error):
D,G = list(map(int,input().split()))
pc = [[i]+list(map(int,input().split())) for i in range(D)]

for i,row in enumerate(pc):
    s = (i+1)*row[1] * 100 + row[2]
    ave = s/row[1]
    pc[i].append(s)
    pc[i].append(ave)

out = 0
while 1:
    check=False
    i_list = []
    for i,row in enumerate(pc):
        if G<row[3]:
            check=True
            i_list.append(i)
    if check == False:
        #どれをコンプリートしても目標を超えない
        #問題数当たり平均が最高の問題セットを解く
        tmp = [row[4] for row in pc]
        i = tmp.index(max(tmp))
        out += pc[i][1]
        G -= pc[i][3]
        pc.pop(i)
    else:
        #どれかをコンプリートすると目標を達成
        #最小問題数のセット または 最高得点問題での必要数
        tmp = [pc[i][1] for i in i_list]
        m = min(tmp)
        if pc[-1][3] > G:
            m = min(m,(G-1)//((pc[-1][0]+1)*100)+1)
        out += m
        break
print(out)

Fixed submission:
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split())) for i in range(D)]

ans = sum([p for p,c in pc])
for i in range(2**D-1):
    score = 0
    unused_max = D-1
    sum_p = 0
    for j in range(D-1,-1,-1):
        if (i>>j)%2:
            score += pc[j][1] + pc[j][0]*(j+1)*100
            sum_p += pc[j][0]
            if unused_max == j:
                unused_max -= 1
    if G - score <= (pc[unused_max][0]-1)*(unused_max+1)*100:
        ans = min(ans,sum_p+max(0,(G-score-1)//(100*(unused_max+1))+1))
print(ans)

Buggy python submission (verdict: Runtime Error):
D,G = list(map(int,input().split()))
pc = [[i]+list(map(int,input().split())) for i in range(D)]

for i,row in enumerate(pc):
    s = (i+1)*row[1] * 100 + row[2]
    ave = s/row[1]
    pc[i].append(s)
    pc[i].append(ave)

out = 0
while 1:
    check=False
    i_list = []
    for i,row in enumerate(pc):
        if G<row[3]:
            check=True
            i_list.append(i)
    if check == False:
        #どれをコンプリートしても目標を超えない
        #問題数当たり平均が最高の問題セットを解く
        tmp = [row[4] for row in pc]
        i = tmp.index(max(tmp))
        out += pc[i][1]
        G -= pc[i][3]
        pc.pop(i)
    else:
        #どれかをコンプリートすると目標を達成
        #最小問題数のセット または 最高得点問題での必要数
        tmp = [pc[i][1] for i in i_list]
        m = min(tmp)
        if pc[-1][3] > G:
            m = min(m,G//((pc[-1][0]+1)*100))
        out += m
        break
print(out)

Fixed submission:
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split())) for i in range(D)]

ans = sum([p for p,c in pc])
for i in range(2**D-1):
    score = 0
    unused_max = D-1
    sum_p = 0
    for j in range(D-1,-1,-1):
        if (i>>j)%2:
            score += pc[j][1] + pc[j][0]*(j+1)*100
            sum_p += pc[j][0]
            if unused_max == j:
                unused_max -= 1
    if G - score <= (pc[unused_max][0]-1)*(unused_max+1)*100:
        ans = min(ans,sum_p+max(0,(G-score-1)//(100*(unused_max+1))+1))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
b = sorted([a-i for i,a in enumerate(A,1)])

minus = 0
plus = 0
for c in b:
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m1 = b[N//2]
m2 = b[N//2+1]
out = min(sum([abs(c-m1) for c in b]),sum([abs(c-m2) for c in b]))
print(out)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
b = sorted([a-i for i,a in enumerate(A,1)])

minus = 0
plus = 0
for c in b:
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m1 = b[N//2]
m2 = b[0] if N==1 else b[N//2+1]
out = min(sum([abs(c-m1) for c in b]),sum([abs(c-m2) for c in b]))
print(out)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
b = sorted([b-i for i,b in enumerate(A,1)])

minus = 0
plus = 0
for i,c in enumerate(b,1):
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m = b[(N-minus+plus)//2]
out = sum([abs(c-m) for c in b])
print(out)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
b = sorted([a-i for i,a in enumerate(A,1)])

minus = 0
plus = 0
for c in b:
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m1 = b[N//2]
m2 = b[0] if N==1 else b[N//2+1]
out = min(sum([abs(c-m1) for c in b]),sum([abs(c-m2) for c in b]))
print(out)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def f(n):
    if n<6:
        return n
    i,j = 0,0
    a,b = n,n
    while a >= 6:
        i += 1
        a //= 6
    while b >= 9:
        j += 1
        b //= 9
    return min(1+f(n-6**i),1+f(n-9**j))

print(f(N))

Fixed submission:
N = int(input())

memo = {i:i for i in range(6)}
def f(n):
    tmp = memo.get(n,None)
    if tmp != None:
        return tmp
    i,j = 0,0
    a,b = n,n
    while a >= 6:
        i += 1
        a //= 6
    while b >= 9:
        j += 1
        b //= 9
    ret = min(1+f(n-6**i),1+f(n-9**j))
    memo[n] = ret
    return ret

print(f(N))
Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(lambda x:int(x)-1,input().split())) for _ in range(N)]

ans = 10000*N*N
for i in range(C):
    cur_score = 0
    for x in range(N):
        for y in range((-x)%3,N,3):
            cur_score += D[c[x][y]][i]
    if cur_score>ans:
        continue
    for j in range(C):
        cur_score2 = 0
        if j == i:
            continue
        for x in range(N):
            for y in range((1-x)%3,N,3):
                cur_score2 += D[c[x][y]][j]
        if cur_score+cur_score2>ans:
            continue
        
        for k in range(C):
            cur_score3 = 0
            if k == j or k == i:
                continue
            for x in range(N):
                for y in range((2-x)%3,N,3):
                    cur_score3 += D[c[x][y]][k]
            ans = min(ans,cur_score+cur_score2+cur_score3)
print(ans)

Fixed submission:
N,C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(lambda x:int(x)-1,input().split())) for _ in range(N)]

n = [[0]*C for _ in range(3)]
for i in range(N):
    for j in range(N):
        n[(i+j)%3][c[i][j]] += 1

ans = 500*500*1000
for c0 in range(C):
    for c1 in range(C):
        if c1 == c0:
            continue
        for c2 in range(C):
            if c2 in (c0,c1):
                continue
            score = 0
            for a in range(C):
                score += n[0][a] * D[a][c0] + n[1][a] * D[a][c1] + n[2][a] * D[a][c2]
            ans = min(ans,score)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K=int(input())

subs = set()
L = len(s)
for l in range(1,L+1):
    for i in range(L-l+1):
        subs.add(s[i:i+l])
print(sorted(list(subs))[K-1])

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

subs = set()
L = len(s)
for l in range(1,min(L,5)+1):
    for i in range(L-l+1):
        subs.add(s[i:i+l])
print(sorted(list(subs))[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a=list(map(int,input().split()))

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

def comb(n,r):
    r = min(r,n-r)
    ret = 1
    for i in range(1,r+1):
        ret *= (n+1-i)
        ret /= i
    return int(ret)

ans = ""
m = 0
for c in b[:1]:
    if m > c**(c//2):
        break
    r = binary_search(c/2)
    comb_c_r = comb(c,r)
    if m < comb_c_r:
        m = comb_c_r
        ans = str(c)+" "+str(r)
print(ans)

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

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

def comb(n,r):
    r = min(r,n-r)
    ret = 1
    for i in range(1,r+1):
        ret *= (n+1-i)
        ret /= i
    return int(ret)

ans = ""
m = 0
for c in b[:1]:
    r = binary_search(c/2)
    #comb_c_r = comb(c,r)
    #if m < comb_c_r:
        #m = comb_c_r
    ans = str(c)+" "+str(r)
print(ans)

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

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

def comb(n,r):
    r = min(r,n-r)
    ret = 1
    for i in range(1,r+1):
        ret *= (n+1-i)
        ret /= i
    return int(ret)

ans = ""
m = 0
for c in b[:-1]:
    if m > c**(c//2):
        break
    r = binary_search(c/2)
    comb_c_r = comb(c,r)
    if m < comb_c_r:
        m = comb_c_r
        ans = str(c)+" "+str(r)
print(ans)

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

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

def comb(n,r):
    r = min(r,n-r)
    ret = 1
    for i in range(1,r+1):
        ret *= (n+1-i)
        ret /= i
    return int(ret)

ans = ""
m = 0
for c in b[:1]:
    r = binary_search(c/2)
    #comb_c_r = comb(c,r)
    #if m < comb_c_r:
        #m = comb_c_r
    ans = str(c)+" "+str(r)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N=int(input())
    ans = [None]*N
    
    print(0)
    s=input()
    if s=="Vacant":return
    ans[0] = s=="Male"
    l=1
    r=N-1
    while l+1<r:
        i = (l+r)//2
        print(i)
        s=input()
        if s=="Vacant":return
        ans[i] = s=="Male"
        if ans[i]==ans[0] and i%2==0:
            l = i
        else:
            r = i
    print(l)
    s=input()
    if s=="Vacant":return
    print(r)
    return

main()

Fixed submission:
def main():
    N=int(input())
    ans = [None]*N
    
    print(0)
    s=input()
    if s=="Vacant":return
    ans[0] = s=="Male"
    l=1
    r=N-1
    while l+1<r:
        i = (l+r)//2
        print(i)
        s=input()
        if s=="Vacant":return
        ans[i] = s=="Male"
        if (ans[i]==ans[0]) ^ (i%2!=0):
            l = i
        else:
            r = i
    print(l)
    s=input()
    if s=="Vacant":return
    print(r)
    return

main()
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
XYC = [[int(x)%(2*K),int(y)%(2*K),int(c=="B")] for x,y,c in [input().split() for _ in [0]*N]]

score = [{} for _ in [0]*2]
for x,y,c in XYC:
    score[c][(y,x)] = score[c].get((y,x),0) + 1

for c in range(2):
    for x in range(K):
        for y in range(2*K):
            if (y,x) in score[c]:
                score[c][(y,x+2*K)] = score[c][(y,x)]
for c in range(2):
    for x in range(3*K):
        for y in range(K):
            if (y,x) in score[c]:
                score[c][(y+2*K,x)] = score[c][(y,x)]
    
S = [[[0]*(3*K+1) for _ in [0]*(3*K+1)] for _ in [0]*2]
for c in range(2):
    for i in range(3*K):
        for j in range(3*K):
            S[c][i+1][j+1] = S[c][i][j+1] + score[c].get((i,j),0)
    for i in range(3*K):
        for j in range(3*K):
            S[c][i+1][j+1] += S[c][i+1][j]

def get_sum(c,si,sj,i,j):
    i+=1
    j+=1
    return S[c][i][j] + S[c][si][sj] - S[c][i][sj] - S[c][si][j]

ans = 0
for i in range(K):
    for j in range(2*K):
        tmp = 0
        tmp += get_sum(0,i,j,i+K-1,j+K-1)
        tmp += get_sum(1,i+K,j,i+2*K-1,j+K-1)
        j = (j+K)%(2*K)
        tmp += get_sum(1,i,j,i+K-1,j+K-1)
        tmp += get_sum(0,i+K,j,i+2*K-1,j+K-1)
        ans = max(ans,tmp)
print(ans)

Fixed submission:
N,K = map(int,input().split())
XYC = [[int(x)%(2*K),int(y)%(2*K),int(c=="B")] for x,y,c in [input().split() for _ in [0]*N]]

score = [[[0]*(3*K+1) for _ in [0]*(3*K+1)] for _ in [0]*2]
for x,y,c in XYC:
    x+=1
    y+=1
    score[c][y][x] += 1
    if x<K: score[c][y][x+2*K] += 1
    if y<K: score[c][y+2*K][x] += 1
    if x<K and y<K: score[c][y+2*K][x+2*K] += 1

S = score
for c in range(2):
    for j in range(3*K):
        for i in range(3*K):
            S[c][i+1][j+1] += S[c][i][j+1]
    for i in range(3*K):
        for j in range(3*K):
            S[c][i+1][j+1] += S[c][i+1][j]

def get_sum(c,si,sj,i,j):
    i+=1
    j+=1
    return S[c][i][j] + S[c][si][sj] - S[c][i][sj] - S[c][si][j]

ans = 0
for i in range(K):
    for j in range(2*K):
        tmp = 0
        tmp += get_sum(0,i,j,i+K-1,j+K-1)
        tmp += get_sum(1,i+K,j,i+2*K-1,j+K-1)
        j = (j+K)%(2*K)
        tmp += get_sum(1,i,j,i+K-1,j+K-1)
        tmp += get_sum(0,i+K,j,i+2*K-1,j+K-1)
        ans = max(ans,tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
l = len(S)
if l%2:
    c = S[l//2]
    for i in range(1,l//2+1):
        if S[l//2-i] != c or S[l//2 + i] != c:
            break
    else:
        i += 1
    print(l//2+i)
else:
    c = S[l//2]
    for i in range(l//2+1):
        if S[l//2-i] != c or S[l//2 - 1 + i] != c:
            break
    else:
        i += 1
    print(l//2 + i)

Fixed submission:
S = input()
l = len(S)
i = 0
if l%2:
    c = S[l//2]
    for i in range(1,l//2+1):
        if S[l//2-i] != c or S[l//2 + i] != c:
            break
    else:
        i += 1
    print(l//2+i)
else:
    c = S[l//2]
    for i in range(l//2):
        if S[l//2-1-i] != c or S[l//2 + i] != c:
            break
    else:
        i += 1
        pass
    print(l//2 + i)
Buggy python submission (verdict: Runtime Error):
Amax = max(A)
Amin = min(A)
ans = []
if Amax >= -Amin:
    im = A.index(Amax)+1
    i = 2
    while i <= N:
        if A[i-2] > A[i-1]:
            ans.append(str(im) + " " + str(i))
            A[i-1] += Amax
            if Amax < A[i-1]:
                im = i
                Amax = A[i-1]
        else:
            i += 1
else:
    im = A.index(Amin)+1
    i = N-1
    while i >= 1:
        if A[i-1] > A[i]:
            ans.append(str(im) + " " + str(i))
            A[i-1] += Amin
        if Amin > A[i-1]:
            im = i
            Amin = A[i-1]
        else:
            i -= 1
print(len(ans))
for out in ans:
    print(out)

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

Amax = max(A)
Amin = min(A)
ans = []
if Amax >= -Amin:
    im = A.index(Amax)+1
    i = 2
    while i <= N:
        if A[i-2] > A[i-1]:
            ans.append(str(im) + " " + str(i))
            A[i-1] += Amax
            if Amax < A[i-1]:
                im = i
                Amax = A[i-1]
        else:
            i += 1
else:
    im = A.index(Amin)+1
    i = N-1
    while i >= 1:
        if A[i-1] > A[i]:
            ans.append(str(im) + " " + str(i))
            A[i-1] += Amin
            if Amin > A[i-1]:
                im = i
                Amin = A[i-1]
        else:
            i -= 1
print(len(ans))
for out in ans:
    print(out)