Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=input()
a=[int(i) for i in N
b=sum(a)

if b%9==0:
	print("Yes")
else:
	print("No")

Fixed submission:
N=input()
a=[int(i) for i in N]
b=sum(a)

if b%9==0:
	print("Yes")
else:
	print("No")

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

if N%9==0:
	print("Yes")
else:
	print("No")

Fixed submission:
N=input()
a=[int(i) for i in N]
b=sum(a)

if b%9==0:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
N = int(input())
A = list(map(int, input().split()))

gcd = A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
if gcd != 1:
    print("not coprime")
    sys.exit()



NUM = 10**6
T = [True]*(NUM+1)
prime = []
for i in range(2, NUM+1):
    if T[i]:
        prime.append(i)
        tmp = i
        while tmp <= NUM:
            T[tmp] = False
            tmp += i
L = len(prime)
T = [False]*L

for num in A:
    for i in range(L):
        if num%prime[i] == 0:
            if T[i]:
                print("setwise coprime")
                sys.exit()
            T[i] = True
            while num%prime[i] == 0:
                num //= prime[i]
print("pairwise coprime")



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

NUM = 10**6

gcd = A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
if gcd != 1:
    print("not coprime")
    sys.exit()


def osa_k(num):
    S = list(i for i in range(num+1))
    for i in range(2, int(num**0.5)+1):
        if S[i] < i:
            continue
        j = i**2
        while j <= num:
            if S[j] == j:
                S[j] = i
            j += i
    return S


prime = osa_k(NUM)
S = [False]*(NUM+1)
for num in A:
    tmp = prime[num]
    while num > 1:
        num //= tmp
        if tmp == prime[num]:
            # S[tmp] = True
            continue
        if S[tmp]:
            print("setwise coprime")
            sys.exit()
        S[tmp] = True
        tmp = prime[num]
print("pairwise coprime")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
N = int(input())
A = list(map(int, input().split()))

gcd = A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
if gcd != 1:
    print("not coprime")
    sys.exit()



NUM = 10**6
T = [True]*(NUM+1)
prime = []
for i in range(2, NUM+1):
    if T[i]:
        prime.append(i)
        tmp = i
        while tmp <= NUM:
            T[tmp] = False
            tmp += i
L = len(prime)
T = [False]*L

for num in A:
    for i in range(L):
        if num%prime[i] == 0:
            if T[i]:
                print("setwise coprime")
                sys.exit()
            T[i] = True
            while num%prime[i] == 0:
                num //= prime[i]
print("pairwise coprime")



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

NUM = 10**6

gcd = A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
if gcd != 1:
    print("not coprime")
    sys.exit()


def osa_k(num):
    S = list(i for i in range(num+1))
    for i in range(2, int(num**0.5)+1):
        if S[i] < i:
            continue
        j = i**2
        while j <= num:
            if S[j] == j:
                S[j] = i
            j += i
    return S


prime = osa_k(NUM)
S = [False]*(NUM+1)
for num in A:
    tmp = prime[num]
    while num > 1:
        num //= tmp
        if tmp == prime[num]:
            # S[tmp] = True
            continue
        if S[tmp]:
            print("setwise coprime")
            sys.exit()
        S[tmp] = True
        tmp = prime[num]
print("pairwise coprime")
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
num = 0
if K%2 == 0:
    print(-1)
else:
    for i in range(1, 100000000):
        num = num*10 + 7
        num %= K
        if num == 0:
            print(i)
            break

Fixed submission:
K = int(input())
num = 0
if K%2 == 0:
    print(-1)
else:
    for i in range(1, 1000000):
        num = num*10 + 7
        num %= K
        if num == 0:
            print(i)
            break
    else:
        print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
S = [A[0], A[1]]
for i in range(2, len(A)):
    m = min(A[0], A[-1])
    cnt = -1
    for j in range(len(A)-1):
        if min(A[j], A[j+1]) > m:
            m = min(A[j], A[j+1])
            cnt = j
    S = S[:cnt] + [A[i]] + S[cnt:]
    ans += m
print(ans)




Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
N -= 2
for i in range(1, N):
    if N >= 2:
        ans += A[i]*2
        N -= 2
    elif N  == 1:
        ans += A[i]
        N -= 1
    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
S = list(map(int, input().split()))
Q = int(input())

d = dict()
for num in S:
    d.setdefault(num, 0)
    d[num] += 1

for _ in range(Q):
    b, c = map(int, input().split())
    d.setdefault(c, 0)
    d.setdefault(b, 0)
    d[c] += d[b]
    d[b] = 0
    ans = sum(s*t for s, t in d.items())
    print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = list(map(int, input().split()))
Q = int(input())

d = dict()
for num in S:
    d.setdefault(num, 0)
    d[num] += 1


ans = sum(s*t for s, t in d.items())

for _ in range(Q):
    b, c = map(int, input().split())
    d.setdefault(c, 0)
    d.setdefault(b, 0)
    ans += (c-b)*d[b]
    d[c] += d[b]
    d[b] = 0
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
S = list(map(int, input().split()))
Q = int(input())

d = dict()
for num in S:
    d.setdefault(num, 0)
    d[num] += 1

for _ in range(Q):
    b, c = map(int, input().split())
    d.setdefault(c, 0)
    d.setdefault(b, 0)
    d[c] += d[b]
    d[b] = 0
    ans = sum(s*t for s, t in d.items())
    print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = list(map(int, input().split()))
Q = int(input())

d = dict()
for num in S:
    d.setdefault(num, 0)
    d[num] += 1


ans = sum(s*t for s, t in d.items())

for _ in range(Q):
    b, c = map(int, input().split())
    d.setdefault(c, 0)
    d.setdefault(b, 0)
    ans += (c-b)*d[b]
    d[c] += d[b]
    d[b] = 0
    print(ans)
Buggy python submission (verdict: Runtime Error):
37564
whydidyoudesertme

Fixed submission:
P = 10**9 + 7

K = int(input())
S = input()
L = len(S)

d = [0]*(L+K+1)
d[0] = 1
for i in range(1, L+K+1):
    d[i] = (d[i-1]*i)%P

ans = 0
for i in range(K+1):
    temp = pow(26, i, P) * pow(25, K-i, P)
    temp %= P
    temp *= d[L-1+K-i]
    temp %= P
    temp *= pow(d[L-1], P-2, P)
    temp %= P
    temp *= pow(d[K-i], P-2, P)
    temp %= P
    ans += temp
    ans %= P

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(int, input().split()))
S.sort()
ans = 0
if N > 1:
    if S[0] < S[1]:
        ans += 1
else:
    ans = 1
for i in range(N-1, 0, -1):
    num = S[i]
    M = num//2
    flg = True
    for j in range(i):
        if num%S[j] == 0:
            flg = False
            break
        elif S[j] > M:
            break
    if num == S[i-1]:
        flg = False
    elif i < N-1:
        if num == S[i+1]:
            flg = False
    if flg:
        ans += 1
print(ans)

        
    

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

ans = 0
A = [True]*(10**6+1)

for i in range(0, N):
    if not A[S[i]]:
        continue
    if 0 < i:
        if S[i-1] == S[i]:
            continue
    if i < N-1:
        if S[i] == S[i+1]:
            for j in range(1, 10**6//S[i]+1):
                A[S[i]*j] = False
            continue
    ans += 1
    for j in range(1, 10**6//S[i]+1):
        A[S[i]*j] = False

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
S = list(map(int, input().split()))

K = min(K, math.log(2*10**5))
dp = [[0]*N for _ in range(K)]

for i in range(N):
    temp = S[i]
    m = max(0, i-temp)
    dp[0][m] += 1
    if N > i+temp+1:
        dp[0][i+temp+1] -= 1

for i in range(K-1):
    temp = 0
    for j in range(N):
        temp += dp[i][j]
        m = max(0, j-temp)
        dp[i+1][m] += 1
        if N > j+temp+1:
            dp[i+1][j+temp+1] -= 1

ans = [0]*N
ans[0] = dp[K-1][0]

for i in range(1, N):
    ans[i] = ans[i-1] + dp[K-1][i]

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


Fixed submission:
import math
N, K = map(int, input().split())
S = list(map(int, input().split()))

K = min(K, 41)
dp = [[0]*N for _ in range(K)]

for i in range(N):
    temp = S[i]
    m = max(0, i-temp)
    dp[0][m] += 1
    if N > i+temp+1:
        dp[0][i+temp+1] -= 1

for i in range(K-1):
    temp = 0
    for j in range(N):
        temp += dp[i][j]
        m = max(0, j-temp)
        dp[i+1][m] += 1
        if N > j+temp+1:
            dp[i+1][j+temp+1] -= 1

ans = [0]*N
ans[0] = dp[K-1][0]

for i in range(1, N):
    ans[i] = ans[i-1] + dp[K-1][i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = list(map(int, input().split()))

dp = [[0]*N for _ in range(K+1)]
for i in range(N):
    dp[0][i] = S[i]

for i in range(K):
    for j in range(N):
        m = max(0, j-dp[i][j])
        M = min(N, j+dp[i][j]+1)
        for k in range(m, M):
            dp[i+1][k] += 1
ans = ""
for i in range(N):
    ans += str(dp[K][i]) + " "
print(ans[:-1])

Fixed submission:
import math
N, K = map(int, input().split())
S = list(map(int, input().split()))

K = min(K, 41)
dp = [[0]*N for _ in range(K)]

for i in range(N):
    temp = S[i]
    m = max(0, i-temp)
    dp[0][m] += 1
    if N > i+temp+1:
        dp[0][i+temp+1] -= 1

for i in range(K-1):
    temp = 0
    for j in range(N):
        temp += dp[i][j]
        m = max(0, j-temp)
        dp[i+1][m] += 1
        if N > j+temp+1:
            dp[i+1][j+temp+1] -= 1

ans = [0]*N
ans[0] = dp[K-1][0]

for i in range(1, N):
    ans[i] = ans[i-1] + dp[K-1][i]

print(" ".join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
P = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for i in range(N+1)]
# dp = [[0]*(S+1) for i in range(N)]
# dp[i][j] i番目まで見た時に和がjになる組み合わせの個数
dp[0][0] = 1
for i in range(N):
    num = A[i]
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        if j-num >= 0:
            dp[i+1][j] += dp[i][j-num]
        dp[i+1][j] %= P
print(dp[N][S])

Fixed submission:
P = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for i in range(N+1)]
# dp = [[0]*(S+1) for i in range(N)]
# dp[i][j] i番目まで見た時に和がjになる組み合わせの個数
dp[0][0] = 1
for i in range(N):
    num = A[i]
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        if j-num >= 0:
            dp[i+1][j] += dp[i][j-num]
        dp[i+1][j] %= P
print(dp[N][S])
Buggy python submission (verdict: Runtime Error):
T = input()
ans = ""
i = 0
while i < len(T)-1:
    if T[i] == "D":
        if T[i+1] != "D":
            ans += "DP"
        else:
            ans += "DD"
        i += 1
    elif T[i] == "P":
        if T[i+1] == "D":
            ans += "PD"
            i += 1
        elif T[i+1] == "?":
            ans += "PD"
            i += 1
        else:
            ans += "P"
    else:
        if T[i+1] == "D":
            ans += "PD"
            i += 1
        elif T[i+1] == "P":
            ans += "D"
        else:
            if ans[-1] == "D":
                ans += "P"
            else:
                ans += "D"
    i += 1
if len(ans) != len(T):
    if T[-1] == "P":
        ans += "P"
    else:
        ans += "D"
print(ans)

Fixed submission:
T = input()
ans = ""
# i = 0
# while i < len(T)-1:
#     if T[i] == "D":
#         ans += "D"
#     elif T[i] == "P":
#         ans += "P"
#     else:
#         if ans == "":
#             ans += "D"
#         elif ans[-1] == "P":
#             ans += "D"
#         else:

#     i += 1
# if len(ans) != len(T):
#     if T[-1] == "P":
#         ans += "P"
#     else:
#         ans += "D"
for i in range(len(T)):
    if T[i] == "?":
        ans += "D"
    else:
        ans += T[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N, K = map(int, input().split())
S = list(map(int, input().split()))
d = [[0]*(N+1) for _ in range(math.ceil(math.log2(K)))]

for i in range(N):
    d[0][i+1] = S[i]

for i in range(1, math.ceil(math.log2(K))):
    for j in range(1, N+1):
        d[i][j] = d[i-1][d[i-1][j]]

ans = 1
for i in range(math.ceil(math.log2(K))):
    if (K >> i)&1:
        ans = d[i][ans]
print(ans)


Fixed submission:
N, K = map(int, input().split())
S = list(num-1 for num in map(int, input().split()))
loc = 0

arrived = [0]*N
ar = set()
cnt = 0
while not loc in ar:
    arrived[cnt] = loc
    ar.add(loc)
    loc = S[loc]
    cnt += 1

if K < cnt:
    print(arrived[K]+1)
else:
    for i in range(cnt):
        if arrived[i] == loc:
            K -= i
            roop = cnt-i
            K %= roop
            print(arrived[i+K]+1)
            break
Buggy python submission (verdict: Time Limit Exceeded):
# ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)
import sys
# X = int(input())
# a = 1
# for i in range(1, 10**9):
#     a = i**5
#     if a-X > 0:
#         b = 1
#         while True:
#             if a-X == b**5:
#                 print(i, b)
#                 sys.exit()
#             elif a-X > b:
#                 b += 1
#             else:
#                 break
#     elif a-X < 0:
#         b = -1
#         while True:
#             if a-X == b**5:
#                 print(i, b)
#                 sys.exit()
#             elif a-X < b:
#                 b -= 1
#             else:
#                 break
#     else:
#         print(i, 0)
#         break

from itertools import combinations
X = int(input())
num = X
fact = []
i = 2
# 素因数分解
while num > 1:
    if num%i == 0:
        num //= i
        fact.append(i)
    else:
        i += 1

for i in range(len(fact)+1):
    for item in combinations(fact, i):
        a = 0
        b = -1
        for num in item:
            b *= num
        while a**5 - b**5 >= X:
            if a**5 - b**5 == X:
                print(a, b)
                sys.exit()
            else:
                a += 1
                b += 1



Fixed submission:
from sys import exit
X = int(input())
p = [0]*122
for i in range(122):
    p[i] = pow(i , 5)
for i in range(122):
    a = p[i]
    for j in range(i):
        if a-p[j] == X:
            print(i, j)
            exit()
    for j in range(i, 122):
        if a+p[j] == X:
            print(i, -1*j)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
# ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)
import sys
X = int(input())
a = 1
for i in range(1, 10**9):
    a = i**5
    if a-X > 0:
        b = 1
        while True:
            if a-X == b**5:
                print(i, b)
                sys.exit()
            elif a-X > b:
                b += 1
            else:
                break
    elif a-X < 0:
        b = -1
        while True:
            if a-X == b**5:
                print(i, b)
                sys.exit()
            elif a-X < b:
                b -= 1
            else:
                break
    else:
        print(i, 0)
        break

Fixed submission:
from sys import exit
X = int(input())
p = [0]*122
for i in range(122):
    p[i] = pow(i , 5)
for i in range(122):
    a = p[i]
    for j in range(i):
        if a-p[j] == X:
            print(i, j)
            exit()
    for j in range(i, 122):
        if a+p[j] == X:
            print(i, -1*j)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
cnt = 0
dp = [0]*N
for i in range(N-1):
    t = A[i]
    if t > 2 * 10**5:
        continue
    for j in range(i+t, N):
        if j-i == t+A[j]:
            cnt += 1
print(cnt)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
# dp = [0]*N
# for i in range(N-1):
#     t = A[i]
#     if t > 200000:
#         continue
#     for j in range(i+t+1, N):
#         if j-i == t+A[j]:
#             cnt += 1
# print(cnt)

# i<j
# j-i = A[i]+A[j]
# j-A[j] = i+A[i]
# j+A[j] = i-A[i]
MAX = 2*10**5

dpL = [0]*(MAX)
dpR = [0]*(MAX)
for i in range(N):
    num = A[i]
    if num > 200000:
        continue   
    if i+num < MAX:
        dpL[i+num] += 1
    if i >= num:
        dpR[i-num] += 1

for i in range(MAX):
    l = dpL[i]
    r = dpR[i]
    cnt += l*r

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(map(int, input().split()))

data = [0]*N
for i, item in enumerate(S):
    data[i] = [item, i]
data.sort(reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
# dp[i][j] i+j-1番目までの幼児がi人0から、j人N-1から並んだ時の最大値

for i in range(N):
    for j in range(N):
        if i+j >= N:
            break
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]+data[i+j][0]*(data[i+j][1]-(i)))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j]+data[i+j][0]*((N-1-j)-data[i+j][1]))

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])

print(ans)

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

data = [0]*N
for i, item in enumerate(S):
    data[i] = [item, i]
data.sort(reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
# dp[i][j] i+j-1番目までの幼児がi人0から、j人N-1から並んだ時の最大値

for i in range(N):
    for j in range(N):
        if i+j >= N:
            break
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]+data[i+j][0]*(data[i+j][1]-(i)))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j]+data[i+j][0]*((N-1-j)-data[i+j][1]))

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])

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

cnt = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if s[i] == s[j]:
            continue
        for k in range(j+1, N):
            if j-i == k-j:
                continue
            if s[i] == s[k] or s[j] == s[k]:
                continue
            cnt += 1

print(cnt)


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


# for i in range(N-2):
#     for j in range(i+1, N-1):
#         if s[i] == s[j]:
#             continue
#         for k in range(j+1, N):
#             if j-i == k-j:
#                 continue
#             if s[i] == s[k] or s[j] == s[k]:
#                 continue
#             cnt += 1

r = 0
g = 0
b = 0

for t in s:
    if t == "R":
        r += 1
    elif t == "G":
        g += 1

b = N - r - g
cnt = r * g * b

for i in range(1, N-1):
    j = 1
    while 0 <= i-j and i+j <= N-1:
        if s[i] != s[i-j] and s[i] != s[i+j] and s[i-j] != s[i+j]:
            cnt -= 1
        j += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

i = 0
j = 0
k = 0
ans = 0
while  i+j+k < X+Y:
    if i == X:
        for n in range(Y-(j+k)):
            if Q[j] > R[k]:
                ans += Q[j]
                j += 1
            else:
                ans += R[k]
                k += 1
    elif j == Y:
        for n in range(X-(i+k)):
            if P[i] > R[k]:
                ans += P[i]
                i += 1
            else:
                ans += R[k]
                k += 1
    else:
        if P[i] >= max(Q[j], R[k]):
            ans += P[i]
            i += 1
        elif Q[j] >= max(P[i], R[k]):
            ans += Q[j]
            j += 1
        else:
            ans += R[k]
            k += 1

print(ans)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

i = 0
j = 0
k = 0
ans = 0
while  i+j+k < X+Y:
    if i == X:
        for n in range(Y-(j+k)):
            if k == C:
                ans += Q[j]
                j += 1
            elif Q[j] > R[k]:
                ans += Q[j]
                j += 1
            else:
                ans += R[k]
                k += 1
    elif j == Y:
        for n in range(X-(i+k)):
            if k == C:
                ans += P[i]
                i += 1
            elif P[i] > R[k]:
                ans += P[i]
                i += 1
            else:
                ans += R[k]
                k += 1
    elif k == C:
        if P[i] > Q[j]:
            ans += P[i]
            i += 1
        else:
            ans += Q[j]
            j += 1
    else:
        if P[i] >= max(Q[j], R[k]):
            ans += P[i]
            i += 1
        elif Q[j] >= max(P[i], R[k]):
            ans += Q[j]
            j += 1
        else:
            ans += R[k]
            k += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]

ans = 10000
for i in range(2**H):
    cnt = 0
    temp = i
    group = [0]*H
    for j in range(H):
        group[j] = cnt
        if temp & 1:
            cnt += 1
        temp >>= 1
    div = [0]*H
    for l in range(H):
        div[group[l]] += S[l][0]
    for j in range(W-1):
        for k in range(H):
            if div[group[k]] + S[k][j+1] > K:
                cnt += 1
                div = [0]*H
                for l in range(H):
                    div[group[l]] += S[l][j+1]
                break
            else:
                div[group[k]] += S[k][j+1]
    ans = min(ans, cnt)
print(ans)
    


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

ans = 100000
for i in range(2**H):
    cnt = 0
    temp = i
    group = [0]*H
    for j in range(H):
        group[j] = cnt
        if temp & 1:
            cnt += 1
        temp >>= 1
    div = [0]*H
    for j in range(W):
        for k in range(H):
            if div[group[k]] + S[k][j] > K:
                cnt += 1
                div = [0]*H
                for l in range(H):
                    div[group[l]] += S[l][j]
                    if div[group[l]] > K:
                        cnt = 100000
                break
            else:
                div[group[k]] += S[k][j]
    ans = min(ans, cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, P = map(int, input().split())
S = input()

l = len(S)
if P == 2:
    ans = 0
    for i in range(l):
        if int(S[i])%2 == 0:
            ans += i+1
elif P == 5:
    ans = 0
    for i in range(l):
        if int(S[i])%5 == 0:
            ans += i+1
else:
    data = [0]*P
    temp = 0
    for i in range(l-1, -1, -1):
        temp += int(S[i])*10**i
        temp %= P
        data[temp] += 1
    ans = data[0]
    for item in data:
        if item > 1:
            ans += item*(item-1)//2

print(ans)

Fixed submission:
S = input()
if S[0] != S[1] or S[1] != S[2]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = deque(input())
Q = int(input())

head = 1
for _ in range(Q):
    cmd = input()
    if cmd == "1":
        head *= -1
    elif "2 1" == cmd[:3]:
        if head == 1:
            S.appendleft(cmd[4])
        else:
            S.append(cmd[4])
    else:
        if head == 1:
            S.append(cmd[4])
        else:
            S.appendleft(cmd[4])

ans = ""
for _ in range(len(S)):
    if head == 1:
        ans += S.popleft()
    else:
        ans += S.pop()

print(ans)


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

head = 1
for _ in range(Q):
    cmd = input()
    if cmd == "1":
        head *= -1
    elif "2 1" == cmd[:3]:
        if head == 1:
            S.appendleft(cmd[4])
        else:
            S.append(cmd[4])
    else:
        if head == 1:
            S.append(cmd[4])
        else:
            S.appendleft(cmd[4])

ans = ""
for _ in range(len(S)):
    if head == 1:
        ans += S.popleft()
    else:
        ans += S.pop()

print(ans)