Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
DP = [[0]*5005 for _ in range(5005)]

for i in range(N):
    for j in range(N):
        if S[i] == S[j]:
            DP[N-i][N-j] = DP[N-i+1][N-j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(DP[i][j], j-i)
        ans = max(ans, now)

print(ans)

Fixed submission:
N = int(input())
S = input()
DP = [[0]*5005 for _ in range(5005)]

for i in range(N):
    for j in range(N):
        if S[i] == S[j]:
            DP[N-i][N-j] = DP[N-i+1][N-j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(DP[i][j], j-i)
        ans = max(ans, now)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
for i in range(N-1):
    for j in range(i+1+ans, N-ans):
        for l in range(ans+1, min(j-i, N-j)+1):
            if S[i:i+l] == S[j:j+l]:
                ans = max(ans, l)
            else:
                break

print(ans)


Fixed submission:
N = int(input())
S = input()
DP = [[0]*5005 for _ in range(5005)]

for i in range(N):
    for j in range(N):
        if S[i] == S[j]:
            DP[N-i][N-j] = DP[N-i+1][N-j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(DP[i][j], j-i)
        ans = max(ans, now)

print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]
    id = [[0]*n for _ in range(n)]
    V = 0
    for i in range(n):
        for j in range(n):
            if i<j:
                id[i][j] = V
                V += 1
    def toID(i, j):
        if i<j:
            return id[i][j]
        else:
            return id[j][i]
    
    to = [[] for _ in range(V)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] = toID(i, a[i][j])
        for j in range(n-2):
            to[a[i][j+1]].append(a[i][j])

    dp, visited, calculated = [1] * V, [0] * V, [0] * V

    def dfs(v, dp, visited, calculated):
        if visited[v]:
            if not calculated[v]:
                return -1
            return dp[v]
        visited[v] = 1
        for u in to[v]:
            res = dfs(u, dp, visited, calculated)
            if res == -1:
                return -1
            dp[v] = max(dp[v], res+1)
        calculated[v] = 1
        return dp[v]

    ans = 0
    for v in range(V):
        res = dfs(v, dp, visited, calculated)
        if res == -1:
            print(-1)
            return
        ans = max(ans, res)
    print(ans)
    return

main()


Fixed submission:
def main():
    n = int(input())
    a = [list(map(lambda x : int(x)-1, input().split())) for _ in range(n)]
    for i in range(n):
        a[i].reverse()
    # print(a)
    s = set()

    def check(i, s):
        if len(a[i]) == 0:
            return
        j = a[i][-1]
        if len(a[j]) == 0:
            return
        if a[j][-1] == i:
            if i < j:
                s.add((i, j))
            else:
                s.add((j, i))
    
    for i in range(n):
        check(i, s)
    day = 0
    while s:
        day += 1
        prevS = set()
        s, prevS = prevS, s
        for p in prevS:
            i = p[0]
            j = p[1]
            a[i].pop()
            a[j].pop()
        for p in prevS:
            i = p[0]
            j = p[1]
            check(i, s)
            check(j, s)
    
    for i in range(n):
        if len(a[i]):
            print(-1)
            return
    print(day)
    return

main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ss = []
for i in range(N):
    s = list(input())
    s.sort()
    ss.append(s)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if ss[i] == ss[j]:
            ans += 1

print(ans)


Fixed submission:
N = int(input())
ss = []
for i in range(N):
    s = list(input())
    s.sort()
    ss.append(s)

ss.sort()
ans = 0
tmp = 1
for i in range(N-1):
    if ss[i] == ss[i+1]:
        tmp += 1
        if i == N-2:
            ans += (tmp * (tmp-1)) // 2
    else:
        ans += (tmp * (tmp-1)) // 2
        tmp = 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ss = []
for i in range(N):
    s = list(input())
    s.sort()
    ss.append(s)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if ss[i] == ss[j]:
            ans += 1

print(ans)


Fixed submission:
N = int(input())
ss = []
for i in range(N):
    s = list(input())
    s.sort()
    ss.append(s)

ss.sort()
ans = 0
tmp = 1
for i in range(N-1):
    if ss[i] == ss[i+1]:
        tmp += 1
        if i == N-2:
            ans += (tmp * (tmp-1)) // 2
    else:
        ans += (tmp * (tmp-1)) // 2
        tmp = 1

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

N = 13
# dp[k] -> 13で割った余りがKのパターン数
dp = [0] * N
dp[0] = 1

# 後ろから解くアルゴリズム
# 1?2?3   0 -> 3 -> ?3 -> 2?3 -> ...
mod = 10**9 + 7

mul = 1
for i in range(len(S))[::-1]:
    # 次の状態
    nextDP = [0] * N
    if S[i] == '?':
        for k in range(10):
            for j in range(N):
                nextDP[(k * mul + j) % N] += dp[j]
                nextDP[(k * mul + j) % N] %= mod
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * mul + j) % N] += dp[j]
            nextDP[(k * mul + j) % N] %= mod
    mul *= 10
    mul %= N
    dp = nextDP

print(dp[5])

Fixed submission:
S = input()

N = 13
# dp[k] -> 13で割った余りがKのパターン数
dp = [0] * N
dp[0] = 1

# 後ろから解くアルゴリズム
# 1?2?3   0 -> 3 -> ?3 -> 2?3 -> ...
mod = 10**9 + 7

mul = 1
for i in range(len(S))[::-1]:
    # 次の状態
    nextDP = [0] * N
    if S[i] == '?':
        for k in range(10):
            for j in range(N):
                nextDP[(k * mul + j) % N] += dp[j]
                nextDP[(k * mul + j) % N] %= mod
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * mul + j) % N] += dp[j]
            nextDP[(k * mul + j) % N] %= mod
    mul *= 10
    mul %= N
    dp = nextDP

print(dp[5])
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]

diff = []

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            if xy[i][0] > xy[j][0]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] >= xy[j][1]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] < xy[j][1]:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
            else:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
c = collections.Counter(diff)
ans = N - sorted(list(c.values()))[-1] // 2
print(ans)


Fixed submission:
import collections
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]

diff = []

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            if xy[i][0] > xy[j][0]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] >= xy[j][1]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] < xy[j][1]:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
            else:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))

if N == 1:
    ans = 1
else:
    c = collections.Counter(diff)
    ans = N - sorted(list(c.values()))[-1] // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
s = np.array(list(input()))
n = len(s)
ans = 0
i = 0
while i < n-2:  # 3文字なので
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        s[i:i+3] = ['B', 'C', 'A']
        ans += 1
        i = max(i-1, 0)   # 1つ前がAの場合をチェック
    else:
        i += 1

print(ans)

Fixed submission:
s = input()
n = len(s)
ans = 0
numa = 0
i = 0
while i < n-1:  # 最後'BC'以外は、最後の文字は関係ないので s[n-1]は不要
    if s[i] == 'A':
        numa += 1   # Aが連続で続く場合は数える
    elif s[i:i+2] == 'BC':
        ans += numa # AAAA と BC を入れ替える回数。またBCが来たら加算する
        i += 1  # BCの場合は、2文字進めるので+1
    else:
        numa = 0
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = len(s)
ans = 0
i = 0
while i < n-2:  # 3文字なので
    if s[i:i+3] == ['A', 'B', 'C']:
        s[i:i+3] = ['B', 'C', 'A']
        ans += 1
        i = max(i-1, 0)   # 1つ前がAの場合をチェック
    else:
        i += 1

print(ans)


Fixed submission:
s = input()
n = len(s)
ans = 0
numa = 0
i = 0
while i < n-1:  # 最後'BC'以外は、最後の文字は関係ないので s[n-1]は不要
    if s[i] == 'A':
        numa += 1   # Aが連続で続く場合は数える
    elif s[i:i+2] == 'BC':
        ans += numa # AAAA と BC を入れ替える回数。またBCが来たら加算する
        i += 1  # BCの場合は、2文字進めるので+1
    else:
        numa = 0
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ss = list(s)
ans = 0
i = 0
while i < n-2:  # 3文字なので
    if ss[i:i+3] == ['A', 'B', 'C']:
        ss[i:i+3] = ['B', 'C', 'A']
        ans += 1
        i = max(i-1, 0)   # 1つ前がAの場合をチェック
    else:
        i += 1

print(ans)


Fixed submission:
s = input()
n = len(s)
ans = 0
numa = 0
i = 0
while i < n-1:  # 最後'BC'以外は、最後の文字は関係ないので s[n-1]は不要
    if s[i] == 'A':
        numa += 1   # Aが連続で続く場合は数える
    elif s[i:i+2] == 'BC':
        ans += numa # AAAA と BC を入れ替える回数。またBCが来たら加算する
        i += 1  # BCの場合は、2文字進めるので+1
    else:
        numa = 0
    i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
        
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        if A[0] < C:
            heapq.heapreplace(A, C)
        else:
            break

ans = sum(A)
print(ans)


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = [[A[i], 1] for i in range(N)]   # Aのカードは各1枚ずつ

for i in range(M):
    B, C = map(int, input().split())
    p.append([C, B])    # CのカードをB枚追加

p.sort()
p.reverse()

ans = 0
cnt = N
for v, n in p:
    num = min(cnt, n)    # 残り枚数とvのカード枚数の少ない方を採用
    ans += v * num
    cnt -= num
    if cnt == 0:
        break

print(ans)

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

for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        if A[0] < C:
            heapq.heapreplace(A, C)
        else:
            break

ans = sum(A)
print(ans)


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = [[A[i], 1] for i in range(N)]   # Aのカードは各1枚ずつ

for i in range(M):
    B, C = map(int, input().split())
    p.append([C, B])    # CのカードをB枚追加

p.sort()
p.reverse()

ans = 0
cnt = N
for v, n in p:
    num = min(cnt, n)    # 残り枚数とvのカード枚数の少ない方を採用
    ans += v * num
    cnt -= num
    if cnt == 0:
        break

print(ans)

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

for i in range(M):
    B, C = map(int, input().split())
    for j in range(B):
        if A[j] < C:
            A[j] = C
        else:
            break
    A.sort()

ans = sum(A)
print(ans)


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = [[A[i], 1] for i in range(N)]   # Aのカードは各1枚ずつ

for i in range(M):
    B, C = map(int, input().split())
    p.append([C, B])    # CのカードをB枚追加

p.sort()
p.reverse()

ans = 0
cnt = N
for v, n in p:
    num = min(cnt, n)    # 残り枚数とvのカード枚数の少ない方を採用
    ans += v * num
    cnt -= num
    if cnt == 0:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(x, g, vis):
    if vis[x]:
        return
    vis[x] = 1
    for y in g[x]:
        dfs(y, g, vis)

def main():
    N, M = map(int, input().split())
    g = [[] for _ in range(N)]
    for i in range(M):
        X, Y, Z = map(int, input().split())
        X -= 1
        Y -= 1
        g[X].append(Y)
        g[Y].append(X)
    vis = [0] * N

    ans = 0
    for i in range(N):
        if vis[i] == 0:
            dfs(i, g, vis)
            ans += 1
    print(ans)

main()

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

def dfs(x, g, vis):
    if vis[x]:
        return
    vis[x] = 1
    for y in g[x]:
        dfs(y, g, vis)

def main():
    N, M = map(int, input().split())
    g = [[] for _ in range(N)]
    for i in range(M):
        X, Y, Z = map(int, input().split())
        X -= 1
        Y -= 1
        g[X].append(Y)
        g[Y].append(X)
    vis = [0] * N

    ans = 0
    for i in range(N):
        if vis[i] == 0:
            dfs(i, g, vis)
            ans += 1
    print(ans)

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

l = []
for i in range(N):
    A = AA.copy()
    A.pop(i)
    minA = min(A)
    while len(A) > 1:
        minA = min(A)
        tempA = []
        tempA.append(minA)
        for a in A:
            mod = a % minA
            if mod > 0:
                tempA.append(mod)
        A = tempA
    l.append(A[0])
print(max(l))

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

gcd_l = [0]
gcd_r = [0]
for i in range(N):
    gcd_l.append(gcd(gcd_l[i], A[i]))
    gcd_r.append(gcd(gcd_r[i], A[-(i+1)]))

gcds = []
for i in range(N):
    gcds.append(gcd(gcd_l[i], gcd_r[-(i+2)]))
ans = max(gcds)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
N = int(input())
a = np.array([int(input()) for _ in range(N)])
s = np.sum(a)
m = 998244353
dp1 = np.zeros(N+1, s+1)
dp1[0,0] = 1
dp2 = np.zeros(N+1, s//2+1)
dp2[0,0] = 1
for i, ai in enumerate(a):
    dp1[i+1, :]   += dp1[i, :] * 2
    dp1[i+1, ai:] += dp1[i, :-ai]
    dp2[i+1, :]   += dp2[i, :]
    dp2[i+1, ai:] += dp2[i, :-ai]
subset1 = np.sum(dp1[N][math.ceil(s/2):])
subset2 = 0 if s % 2 == 1 else dp2[N][s/2]
print((3 ** N - 3 * subset1 + 3 * subset2) % m)


Fixed submission:
import math
import numpy as np
N = int(input())
a = np.array([int(input()) for _ in range(N)])
s = np.sum(a)
m = 998244353
dp1 = np.zeros((N+1, s+1), dtype=np.int64)
dp1[0, 0] = 1
dp2 = np.zeros((N+1, s//2+1), dtype=np.int64)
dp2[0, 0] = 1
for i, ai in enumerate(a):
    dp1[i+1, :]   += dp1[i, :] * 2 % m
    dp1[i+1, ai:] += dp1[i, :-ai]
    dp2[i+1, :]   += dp2[i, :] % m
    dp2[i+1, ai:] += dp2[i, :-ai]
subset1 = np.sum(dp1[N, math.ceil(s/2):])
subset2 = 0 if s % 2 == 1 else dp2[N, s//2]
print((3 ** N - 3 * subset1 + 3 * subset2) % m)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()
Nums = []
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか
for i in range(N):
    if S[i] == str(now):
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now   # 0と1を切り替えるときの計算 now ^= 1
        cnt = 1
if cnt != 0:
    Nums.append(cnt)
# 1-0-1-0-1-0-1 って感じの配列が欲しい
# 1-0-1-0-1-0 みたいに0で終わっていたら適当に1つ足す
if len(Nums) % 2 == 0:
    Nums.append(0)

Add = 2 * K + 1
ans = 0
# 1-0-1... の1から始めるので、偶数番目だけ見る
for i in range(0, len(Nums), 2):
    tmp = 0
    left = i
    right = min(i + Add, len(Nums))
    for j in range(left, right):
        tmp += Nums[j]
    ans = max(tmp, ans)

print(ans)

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

l = [0]
curr = '1'
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)

n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
sum_ = sum(l[0:2*k+1])
max_ = sum_
for i in range(k, n_group):
    sum_ -= l[2*i-2*K] + l[2*i+1-2*K]
    sum_ += l[2*i+1] + l[2*i+2]
    max_ = max(max_, sum_)
print(max_)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
Nums = [0]
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか
for i in range(N):
    if s == str(now):
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now   # 0と1を切り替えるときの計算 now ^= 1
        cnt = 1
if cnt != 0:
    Nums.append(cnt)
# 1-0-1-0-1-0-1 って感じの配列が欲しい
# 1-0-1-0-1-0 みたいに0で終わっていたら適当に1つ足す
if len(Nums) % 2 == 0:
    Nums.append(0)

Add = 2 * K + 1
ans = 0
# 1-0-1... の1から始めるので、偶数番目だけ見る
for i in range(0, len(Nums), 2):
    tmp = 0
    left = i
    right = min(i + Add, len(Nums))
    for j in range(left, right):
        tmp += Nums[j]
    ans = max(tmp, ans)

print(ans)

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

l = [0]
curr = '1'
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)

n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
sum_ = sum(l[0:2*k+1])
max_ = sum_
for i in range(k, n_group):
    sum_ -= l[2*i-2*K] + l[2*i+1-2*K]
    sum_ += l[2*i+1] + l[2*i+2]
    max_ = max(max_, sum_)
print(max_)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
l = [0]

for i in range(1, N):
    if S[i] != S[i-1]:
        l.append(i)
l.append(N)

mxcnt = 0
if len(l) <= 2*K+1:
    mxcnt = N
else:
    for i in range(len(l)-2*K):
        if S[i] == '0':
            x = l[i+2*K] - l[i]
            mxcnt = max(mxcnt, x)
        else:
            x = l[i+2*K+1] - l[i]
        mxcnt = max(mxcnt, x)

print(mxcnt)

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

l = [0]
curr = '1'
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)

n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
sum_ = sum(l[0:2*k+1])
max_ = sum_
for i in range(k, n_group):
    sum_ -= l[2*i-2*K] + l[2*i+1-2*K]
    sum_ += l[2*i+1] + l[2*i+2]
    max_ = max(max_, sum_)
print(max_)
Buggy python submission (verdict: Runtime Error):
import itertools

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = []
for p in itertools.product(A, B):
    AB.append(sum(p))
AB.sort(reverse=True)
AB = AB[:K]

l = []
for p in itertools.product(AB, C):
    l.append(sum(p))
l.sort(reverse=True)
for i in range(K):
    print(l[i])

Fixed submission:
l = [int(input()) for _ in range(5)]
k = int(input())
if max(l) - min(l) > k:
    print(':(')
else:
    print('Yay!')
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
bs = list(map(int, input().split()))
ans = [0] * n

def chk(numbers, ans, n):
    m = len(numbers)
    if m == 1:
        if numbers == [1]:
            ans[n-1] = 1
            return True
        else:
            return False
    cnt = 0
    for i, b in enumerate(numbers):
        if b == i+1:
            cnt += 1
            ans[n-m] = b
            tempns = numbers.copy()
            tempns.pop(i)
            if chk(tempns, ans, n):
                return True
    if cnt == 0:
        ans[n-m] = 0
    return False

chk(bs, ans, n)

if 0 in ans:
    print(-1)
else:
    ans = ans[::-1]
    for a in ans:
        print(a)

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

ans = []

for i in range(n):
    for j in range(n-i, 0, -1):
        if bs[j-1] == j:
            ans.append(j)
            del bs[j-1]
            break
if len(ans) == n:
    ans = ans[::-1]
    for a in ans:
        print(a)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
csum = [1]

for i in range(1, n):
    if s[i] in s[:i]:
        csum.append(int(csum[-1] * 1.5 + 0.5))
    else:
        csum.append(csum[-1] * 2 + 1)

print(csum[-1])

Fixed submission:
n = int(input())
s = input()
ans = 1
mod = 10**9 + 7
for x in set(s):
    ans *= s.count(x) + 1
    ans %= mod

print((ans - 1) % mod)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.empty((N, M),dtype=int)
for n in range(N):
    A[n, :] = list(map(int, input().split()))
X = np.matmul(A, B) + C
print(len(X[X>0]))

Fixed submission:
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.empty((N, M),dtype=int)
for n in range(N):
    A[n, :] = list(map(int, input().split()))
X = np.dot(A, B) + C
print(len(X[X>0]))
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
l = []
keta = int(math.log2(B)) + 1
fmt = '0' + str(keta) + 'b'
for i in range(A, B+1):
    l.append(format(i, fmt))
bbin = ['0'] * keta
for j in range(keta):
    for i in range(A, B+1):
        if l[i-A][j] == '1':
            if bbin[j] == '0':
                bbin[j] = '1'
            else:
                bbin[j] = '0'
print(int("".join(bbin), 2))

Fixed submission:
A, B = map(int, input().split())
def xorchk(n):
    if n%4 == 0:
        return n
    elif n%4 == 1:
        return 1
    elif n%4 == 2:
        return n+1
    else:
        return 0
print(xorchk(A-1)^xorchk(B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()

while A[-2] != 0:
    A[-1] -= A[-2] * (A[-1] // A[-2])
    A.sort()

print(A[-1])

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

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.append(mod)
    A = tempA

print(A[0])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N,K = map(int,input().split())
A = np.array(input().split(),dtype=np.int64)

bit_cnt = [((A>>k)&1).sum() for k in range(50)]

def F(K,k = 49):
  # K以下、k-bit目まで見た(inclusive)の和、最大値
  if k == -1:
    return 0
  bit = 1<<k
  # k-bitを使う
  x = 0
  if K >= bit:
    x = ((N-bit_cnt[k])<<k) + F(K-bit,k-1)
  # k-bitを使わない
  y = (bit_cnt[k]<<k) + F(min(K,bit-1),k-1)
  return max(x,y)

answer = F(K)
print(answer)


Fixed submission:
import numpy as np
from functools import lru_cache

N,K = map(int,input().split())
A = np.array(input().split(),dtype=np.int64)

bit_cnt = [((A>>k)&1).sum() for k in range(50)]

@lru_cache(maxsize = None)
def F(K,k = 49):
  # K以下、k-bit目まで見た(inclusive)の和、最大値
  if k == -1:
    return 0
  bit = 1<<k
  # k-bitを使う
  x = 0
  if K >= bit:
    x = ((N-bit_cnt[k])<<k) + F(K-bit,k-1)
  # k-bitを使わない
  y = (bit_cnt[k]<<k) + F(min(K,bit-1),k-1)
  return max(x,y)

answer = F(K)
print(answer)