Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03215 (python)

Fixed submission:
N, K = map(int,input().split())
a = list(map(int,input().split()))
S = [0]*N
S[0] = a[0]
for k in range(1,N):
    S[k] = S[k-1] + a[k]
S = [0] + S
T = []
for k in range(N):
    for l in range(k+1,N+1):
        T.append(S[l]-S[k])
ans = 0
for d in range(41,-1,-1):
    c = 0
    for e in T:
        if (ans+2**d)&e == ans+2**d:
            c += 1
    if c >= K:
        ans += 2**d
print(ans)

Buggy submission (verdict: Runtime Error):
import copy
N, K = map(int,input().split())
a = list(map(int,input().split()))
# まず累積和で美しさを全列挙
S = [0]*N
S[0] = a[0]
for k in range(1,N):
    S[k] = S[k-1] + a[k]
S = [0] + S
T = []
for k in range(N):
    for l in range(k+1,N+1):
        T.append(S[l]-S[k])
U = []
C = [0]*32
for e in T:
    t = []
    for d in range(32,-1,-1):
        if e >= 2**d:
            t.append(1)
            C[d] += 1
            e -= 2**d
        else:
            t.append(0)
    U.append(t[::-1])
d = -1
for k in range(31,-1,-1):
    if C[k] >= K:
        d = k
        break
if d == -1:
    print(0)
    exit(0)
ans = 2**d
V = []
for e in U:
    if e[d] == 1:
        V.append(e[:d+1][::-1])

W = copy.deepcopy(V)
for k in range(1,d+1):
    n = []
    for e in W:
        if e[k] == 1:
            n.append(e)
    if len(n) >= K:
        ans += 2**(d-k)
        W = copy.deepcopy(n)
    else:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import copy
N, K = map(int,input().split())
a = list(map(int,input().split()))
# まず累積和で美しさを全列挙
S = [0]*N
S[0] = a[0]
for k in range(1,N):
    S[k] = S[k-1] + a[k]
S = [0] + S
T = []
for k in range(N):
    for l in range(k+1,N+1):
        T.append(S[l]-S[k])
U = []
C = [0]*32
for e in T:
    t = []
    for d in range(32,-1,-1):
        if e >= 2**d:
            t.append(1)
            C[d] += 1
            e -= 2**d
        else:
            t.append(0)
    U.append(t[::-1])
d = -1
for k in range(31,-1,-1):
    if C[k] >= K:
        d = k
        break
if d == -1:
    print(0)
    exit(0)
ans = 2**d
V = []
for e in U:
    if e[d] == 1:
        V.append(e[:d+1][::-1])

W = copy.deepcopy(V)
for k in range(1,d+1):
    n = []
    for e in W:
        if e[k] == 1:
            n.append(e)
    if len(n) >= K:
        ans += 2**(d-k)
        W = copy.deepcopy(n)
    else:
        break

print(ans)
Problem p03262 (python)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

N, S = map(int,input().split())
x = list(map(int,input().split()))
x.append(S)
x = sorted(x)
t = x[1]-x[0]

for k in range(N):
    t = gcd(t,x[k+1]-x[k])

print(t)

Buggy submission (verdict: Runtime Error):
import math

N, S = map(int,input().split())
x = list(map(int,input().split()))
x.append(S)
x = sorted(x)
t = x[1]-x[0]

for k in range(N-1):
    t = math.gcd(t,x[k+1]-x[k])

print(t)
Problem p03309 (python)

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

if N == 1:
    print(0)
    exit(0)

for k in range(N):
    B.append(A[k]-(k+1))

C = sorted(B)
ans = 0
if N%2==1:
    b = C[N//2]
    for k in B:
        ans += abs(k-b)
else:
    b1 = (C[N//2]+C[-1+N//2])//2
    b2 = 1+(C[N//2]+C[-1+N//2])//2
    ans1 = 0
    ans2 = 0
    for k in B:
        ans1 += abs(k-b1)
        ans2 += abs(k-b2)
    ans = min(ans1,ans2)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = []
 
for k in range(N):
    B.append(A[k]-(k+1))

C = sorted(B)

if N%2==0:
    b = C[N//2]
else:
    b = (C[N//2]+C[1+N//2])//2

ans = 0
for k in B:
    ans += abs(k-b)

print(ans)
Problem p03319 (python)

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

print(math.ceil((N-1)/(K-1)))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
p = A.index(1)

if p+1<=K or N-p<=K:
    print(N//(K-1))
    exit(0)
if K%2==1:
    print(1+((p+1)-(K-1)//2)//(K-1) + (N-(p+(K-1)//2))//(K-1))
else:
    print(1+min(((p+1)-K//2-1)//(K-1) + (N-(p+K//2))//(K-1)),((p+1)-K//2)//(K-1) + (N-(p+K//2-1))//(K-1))
Problem p03356 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100010)

def main():
    def input():
        return sys.stdin.readline()[:-1]

    N, M = map(int,input().split())

    p = list(map(lambda x: int(x)-1, input().split()))
    parent = [k for k in range(N)]

    def find(x):
        if parent[x] == x:
            return x
        else:
            parent[x] = find(parent[x])
            return find(parent[x])

    def unite(x,y):
        parent[find(x)] = find(y)

    for k in range(M):
        x, y = map(int,input().split())
        unite(x-1,y-1)

    ans = 0
    for k in range(N):
        if find(k) == find(p[k]):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

def main():
    def input():
        return sys.stdin.readline()[:-1]

    N, M = map(int,input().split())

    p = list(map(int,input().split()))
    p = [p[k]-1 for k in range(N)]
    parent = [k for k in range(N)]

    def find(x):
        if parent[x] == x:
            return x
        else:
            return find(parent[x])

    def unite(x,y):
        if find(x) != find(y):
            parent[find(x)] = find(y)

    for k in range(M):
        x, y = map(int,input().split())
        unite(x-1,y-1)

    ans = 0
    for k in range(N):
        if find(k) == find(p[k]):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()
Problem p03379 (python)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(A)
Problem p03380 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(map(int,input().split())))
M = max(A)

t = 7+10*9
if M%2 == 0:
    m = M//2
    p = 0
    for k in range(N):
        if abs(m-A[k]) < t:
            t = abs(m-A[k])
            p = k
    print(M,A[p])
else:
    m = M//2
    l = 1 + M//2
    for k in range(N):
        if abs(m-A[k]) < t:
            t = abs(m-A[k])
            p = k
        elif abs(l-A[k]) < t:
            t = abs(l-A[k])
            p = k
    print(M,A[p])
Problem p03488 (python)

Fixed submission:
S = input()
x, y = map(int, input().split())

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

X = [a[0]]
Y = [0]

for k in range(1,len(a)):
    if k%2 == 0:
        nx = []
        for e in X:
            nx.append(e+a[k])
            nx.append(e-a[k])
        X = list(set(nx))
    else:
        ny = []
        for e in Y:
            ny.append(e+a[k])
            ny.append(e-a[k])
        Y = list(set(ny))

print("Yes" if x in X and y in Y else "No")

Buggy submission (verdict: Runtime Error):
S = input()
x, y = map(int, input().split())

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

d = [[a[0],0]]
for k in range(1,len(a)):
    n = []
    if k%2 == 1:
        for e in d:
            n.append([e[0],e[1]+a[k]])
            n.append([e[0],e[1]-a[k]])
    else:
        for e in d:
            n.append([e[0]+a[k],e[1]])
            n.append([e[0]-a[k],e[1]])
    d = list(set(n))

print("Yes" if [x,y] in d else "No")
Problem p03504 (python)

Fixed submission:
N, C = map(int, input().split())
T = [[0 for k in range(100001)] for l in range(C)]

for k in range(N):
    s, t, c = map(int, input().split())
    T[c-1][s-1] += 1
    T[c-1][t] -= 1
for l in range(C):
    for k in range(1,100001):
        T[l][k] += T[l][k-1]

ans = 0
for k in range(100001):
    t = 0
    for l in range(C):
        if T[l][k] >= 1:
            t += 1
    ans = max(ans, t)

print(ans)

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
T = [[0 for k in range(100000)] for l in range(C)]

for k in range(N):
    s, t, c = map(int, input().split())
    T[c-1][s-1] += 1
    T[c-1][t] -= 1
for l in range(C):
    for k in range(1,100000):
        T[l][k] += T[l][k-1]

ans = 0
for k in range(100000):
    t = 0
    for l in range(C):
        if T[l][k]:
            t += 1
    ans = max(ans, t)

print(ans)

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
T = [[0 for k in range(100000)] for k in range(C)]

for k in range(N):
    s, t, c = map(int, input().split())
    T[c-1][s-1] += 1
    T[c-1][t] -= 1
for l in range(C):
    for k in range(1,100000):
        T[l][k] += T[l][k-1]

ans = 0
for k in range(100000):
    t = 0
    for l in range(C):
        if T[l][k]:
            t += 1
    ans = max(ans, t)

print(ans)
Problem p03633 (python)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)

N = int(input())
ans = 1
for k in range(N):
    ans = lcm(ans, int(input()))

print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    if a<b:
        t = a
        a = b
        b = t
    if b == 0:
        return a
    t = b
    b = a%b
    a = t
    return gcd(a,b)

def lcm(a,b):
    return a*b/gcd(a,b)

N = int(input())
ans = int(input())
for k in range(N-1):
    ans = int(lcm(ans, int(input())))

print(ans)
Problem p03651 (python)

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

if K in A:
    print("POSSIBLE")
    exit(0)
if K > max(A) or N == 1:
    print("IMPOSSIBLE")
    exit(0)

g = 1000000000
for k in range(1,N):
    g = min(g,gcd(A[k-1],A[k]))

if K%g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int,input().split())
A = sorted(list(map(int,input().split())))

if K in A:
    print("POSSIBLE")
    exit(0)
if K > max(A) or N == 1:
    print("IMPOSSIBLE")
    exit(0)

t = abs(A[1]-A[0])
if K%t==0:
    print("POSSIBLE")
    exit(0)

g = 1000000000
for k in range(1,N):
    g = min(g,math.gcd(A[k-1],A[k]))

if K%g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03660 (python)

Fixed submission:
# ABC 067 D
import sys
sys.setrecursionlimit(200000)

N = int(input())
G = [[] for k in range(N+1)]
for k in range(N-1):
    a, b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)

kyori1 = [100000 for k in range(N+1)]
kyori2 = [100000 for k in range(N+1)]

def dfs1(now, dist):
    for tsugi in G[now]:
        if kyori1[tsugi] == 100000:
            kyori1[tsugi] = dist + 1
            dfs1(tsugi, dist+1)

def dfs2(now, dist):
    for tsugi in G[now]:
        if kyori2[tsugi] == 100000:
            kyori2[tsugi] = dist + 1
            dfs2(tsugi, dist+1)

kyori1[1] = 0
dfs1(1,0)

kyori2[N] = 0
dfs2(N,0)

s = 0
f = 0
for k in range(1,N+1):
    if kyori1[k] <= kyori2[k]:
        f += 1
    else:
        s += 1

print("Fennec" if f > s else "Snuke")

Buggy submission (verdict: Runtime Error):
# ABC 067 D
import sys
sys.setrecursionlimit(100000)

N = int(input())
G = [[] for k in range(N+1)]
for k in range(N-1):
    a, b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)

kyori1 = [100000 for k in range(N+1)]
kyori2 = [100000 for k in range(N+1)]

def dfs1(now, dist):
    for tsugi in G[now]:
        if kyori1[tsugi] == 100000:
            kyori1[tsugi] = dist + 1
            dfs1(tsugi, dist+1)

def dfs2(now, dist):
    for tsugi in G[now]:
        if kyori2[tsugi] == 100000:
            kyori2[tsugi] = dist + 1
            dfs2(tsugi, dist+1)

kyori1[1] = 0
dfs1(1,0)

kyori2[N] = 0
dfs2(N,0)

s = 0
f = 0
for k in range(1,N+1):
    if kyori1[k] <= kyori2[k]:
        f += 1
    else:
        s += 1

print("Fennec" if f > s else "Snuke")

Buggy submission (verdict: Runtime Error):
# ABC 067 D
N = int(input())
G = [[] for k in range(N+1)]
for k in range(N-1):
    a, b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)

kyori1 = [100000 for k in range(N+1)]
kyori2 = [100000 for k in range(N+1)]

def dfs1(now, dist):
    for tsugi in G[now]:
        if kyori1[tsugi] == 100000:
            kyori1[tsugi] = dist + 1
            dfs1(tsugi, dist+1)

def dfs2(now, dist):
    for tsugi in G[now]:
        if kyori2[tsugi] == 100000:
            kyori2[tsugi] = dist + 1
            dfs2(tsugi, dist+1)

kyori1[1] = 0
dfs1(1,0)

kyori2[N] = 0
dfs2(N,0)

s = 0
f = 0
for k in range(1,N+1):
    if kyori1[k] <= kyori2[k]:
        f += 1
    else:
        s += 1

print("Fennec" if f > s else "Snuke")
Problem p03761 (python)

Fixed submission:
N = int(input())
S = [input() for k in range(N)]
A = "abcdefghijklmnopqrstuvwxyz"
C = [[0 for k in range(26)] for l in range(N)]

for k in range(N):
    for u in S[k]:
        C[k][A.find(u)] += 1

ans = ""
for p in range(26):
    t = 100
    for q in range(N):
        t = min(t,C[q][p])
    ans += A[p]*t
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
W = [Counter(input()) for k in range(N)]
A = [100000]*26
S = "abcdefghijklmnopqrstuvwxyz"
for e in W:
    for s in S:
        A[ord(s)-97] = min(A[ord(s)-97],e[s])
ans = ""
for k in range(N):
    ans += S[k]*A[k]
print(ans)
Problem p03837 (python)

Fixed submission:
# ABC 051 D
INF = 7+10**9
N, M = map(int,input().split())
P = []
D = [[INF for k in range(N)] for l in range(N)]
for k in range(N):
    D[k][k] = 0
for k in range(M):
    a, b, c = map(int,input().split())
    P.append([a-1,b-1,c])
    D[a-1][b-1] = c
    D[b-1][a-1] = c

# Floyd-Warshall
for k in range(N):
    for l in range(N):
        for m in range(N):
            D[l][m] = min(D[l][m], D[l][k]+D[k][m])

ans = M
for p in P:
    a, b, c = p[0], p[1], p[2]
    for k in range(N):
        if D[a][k] + c == D[b][k]:
            ans -= 1
            break 
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC 051 D
INF = 7+10**9
N, M = map(int,input().split())
P = []
D = [[INF for k in range(N)] for l in range(N)]
for k in range(N):
    D[k][k] = 0
for k in range(M):
    a, b, c = map(int,input().split())
    P.append([a-1,b-1,c])
    D[a-1][b-1] = c
    D[b-1][a-1] = c

# Floyd-Warshall
for k in range(M):
    for l in range(M):
        for m in range(M):
            D[l][m] = min(D[l][m], D[l][k]+D[k][m])

ans = M
for p in P:
    a, b, c = p[0], p[1], p[2]
    for k in range(N):
        if D[a][k] + c == D[b][k]:
            ans -= 1
            break 
print(ans)
Problem p03919 (python)

Fixed submission:
H, W = map(int, input().split())
S = [input().split() for k in range(H)]
A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for k in range(H):
    for l in range(W):
        if S[k][l]=="snuke":
            print("".join([A[l],str(k+1)]))
            exit(0)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [input().split() for k in range(H)]
A = "ABCDEFGHIJ"

for k in range(H):
    for l in range(W):
        if S[k][l]=="snuke":
            print("".join([A[l],str(k+1)]))
            exit(0)
Problem p03921 (python)

Fixed submission:
N, M = map(int,input().split())
H = []
L = [[] for k in range(M+1)]

for k in range(N):
    P = list(map(int,input().split()))[1:]
    H.append(P)
    for e in P:
        L[e].append(k+1)

G = [0 for k in range(N+1)]
G[1] = 1
Q = [H[0]]
while len(Q) > 0:
    ima = Q.pop()
    for tsugi in ima:
        for e in L[tsugi]:
            if G[e] == 0:
                G[e] = 1
                if len(H[e-1]) > 1:
                    Q.append(H[e-1])

for k in range(1,N+1):
    if G[k] == 0:
        print("NO")
        exit(0)
print("YES")

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
H = []
L = [[] for k in range(M+1)]

for k in range(N):
    P = list(map(int,input().split()))[1:]
    H.append(P)
    for e in P:
        L[e].append(k+1)

G = [0 for k in range(N+1)]
G[1] = 1
Q = [H[0]]
while len(Q) > 0:
    ima = Q.pop()
    if len(ima) == 1 and G[ima[0]] == 1:
        pass
    for tsugi in ima:
        for e in L[tsugi]:
            if G[e] == 0:
                G[e] = 1
                if len(H[e-1]) > 1:
                    Q.append(H[e-1])

for k in range(1,N+1):
    if G[k] == 0:
        print("NO")
        exit(0)
print("YES")
Problem p02613 (python)

Fixed submission:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

c = Counter(s)

for k in ['AC', 'WA', 'TLE', 'RE']:
    if k in c:
        print('{} x {}'.format(k, c[k]))
    else:
        print('{} x {}'.format(k, c[k]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

c = Counter(s)

for k in ['AC', 'WA', 'TLE', 'RE']:
    if k in c:
        print('{k} x {}'.format(k, c[k]))
    else:
        print('{} x {}'.format(k, c[k]))
Problem p02632 (python)

Fixed submission:
k = int(input())
s = input()
mod = 10**9+7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

modp = mod
max_n = k + len(s)+1 # 必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod modp)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1]  # factinv 計算用

for i in range(2, max_n + 1):
    fact.append((fact[-1] * i) % modp)
    inv.append((-inv[modp % i] * (modp // i)) % modp)
    factinv.append((factinv[-1] * inv[-1]) % modp)

ans = 0
for i in range(k+1):
    now = pow(26, k-i, mod)
    now = (now * pow(25, i, mod))%mod
    now = (now * cmb(i+len(s)-1, len(s)-1, mod))%mod
    ans += now
print(ans%mod)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = input()
mod = 10**9+7

def cmb(n, r, p):
    assert n < p, 'n is less than modp'
    assert n < max_n, 'n in less than max_n'
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

modp = mod
max_n = k + len(s)+1 # 必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod modp)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1]  # factinv 計算用

for i in range(2, max_n + 1):
    fact[i] = (fact[i-1] * i) % modp
    inv[i] = (-inv[modp % i] * (modp // i)) % modp
    factinv[i] = (factinv[i-1] * inv[i]) % modp


ans = 0
for i in range(k+1):
    now = pow(26, k-i, mod)
    now = (now * pow(25, i, mod))%mod
    now = (now * cmb(i+len(s)-1, len(s)-1, mod))%mod
    ans += now
print(ans%mod)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = input()
mod = 10**9+7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

modp = mod
max_n = 10 ** 6+2  # 必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod modp)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1]  # factinv 計算用

for i in range(2, max_n + 1):
    fact.append((fact[-1] * i) % modp)
    inv.append((-inv[modp % i] * (modp // i)) % modp)
    factinv.append((factinv[-1] * inv[-1]) % modp)

ans = 0
for i in range(k+1):
    now = pow(26, k-i, mod)
    now = (now * pow(25, i, mod))%mod
    now = (now * cmb(i+len(s)-1, len(s)-1, mod))%mod
    ans += now
print(ans%mod)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = input()
mod = 10**9+7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

modp = mod
max_n = 10 ** 6  # 必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod modp)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1]  # factinv 計算用

for i in range(2, max_n + 1):
    fact.append((fact[-1] * i) % modp)
    inv.append((-inv[modp % i] * (modp // i)) % modp)
    factinv.append((factinv[-1] * inv[-1]) % modp)


ans = 0
for i in range(k+1):
    now = pow(26, k-i, mod)
    now = (now * pow(25, i, mod))%mod
    now = (now * cmb(i+len(s)-1, len(s)-1, mod))%mod
    ans += now
print(ans%mod)
Problem p02664 (python)

Fixed submission:
t = list(input())
for i in range(len(t)-1, -1, -1):
    if t[i] == '?':
        t[i] = 'D'
print(''.join(list(map(str, t))))

Buggy submission (verdict: Runtime Error):
 t = list(input())


for i in range(len(t)-1, -1, -1):
    if t[i] == '?':
        t[i] = 'D'
print(''.join(list(map(str, t))))
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [i-1 for i in a]
visited = [-1]*n
route = []
now = 0
hop = 0
while visited[now] == -1:
    visited[now]=hop
    route.append(now)
    now = a[now]
    hop+=1
loop_st = 0
for r in route:
    if r==now: break
    loop_st+=1
loop = route[loop_st:]
if k < len(route):
    print(route[k]+1)
else:
    print(loop[(k-loop_st)%len(loop)]+1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [i-1 for i in a]
visited = [-1]*n
route = []
now = 0
hop = 0
while visited[now] == -1:
    visited[now]=hop
    route.append(now)
    now = a[now]
    hop+=1
loop_st = 0
for r in route:
    if r==now: break
    loop_st+=1
loop = route[loop_st:]
if k-1 < len(route):
    print(route[k]+1)
else:
    print(loop[(k-loop_st)%len(loop)]+1)
Problem p02732 (python)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

c = dict(Counter(a))
dp_on = {}
dp_off = {}
for k, v in c.items():
    if v == 1:
        dp_on[k] = 0
        dp_off[k] = 0
    elif v == 2:
        dp_on[k] = 1
        dp_off[k] = 0
    else:
        dp_on[k] = int(v*(v-1)/2)
        dp_off[k] = int((v-1)*(v-2)/2)
comb_sum = sum([v for v in dp_on.values()])
for i in range(n):
    print(comb_sum - dp_on[a[i]] + dp_off[a[i]])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

c = dict(Counter(a))
dp_on = {}
dp_off = {}
for k, v in c.items():
    if v == 1:
        dp_on[k] = 0
        dp_off[k] = 0
    elif v == 2:
        dp_on[k] = 1
        dp_off[k] = 0
    else:
        dp_on[k] = int(v*(v-1)/2)
        dp_off[k] = int((v-1)*(v-2)/2)
    comb_sum = sum([v for v in dp_on.values()])
    for i in range(n):
        print(comb_sum - dp_on[a[i]] + dp_off[a[i]])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

c = dict(Counter(a))
dp_on = {}
dp_off = {}
for k, v in c.items():
if v < 2:
        dp_on[k] = 0
        dp_off[k] = 0
elif v < 3:
        dp_on[k] = 1
        dp_off[k] = 0
else:
        dp_on[k] = int(v*(v-1)/2)
        dp_off[k] = int((v-1)*(v-2)/2)
comb_sum = sum([v for v in dp_on.values()])
for i in range(n):
print(comb_sum - dp_on[a[i]] + dp_off[a[i]])