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

Fixed submission:
def solve():
    ans = []
    for x, y in s:
        if(num[x]>num[y]): x, y = y, x
        num[x]+=1
        num[y]-=1
        ans.append(x)
        if num[y]<0: return False
    return ans
from collections import defaultdict
import sys
n, a, b, c = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
id.sort(key = lambda x:num[x])
if a+b+c == 0:
    print('No')
    sys.exit()
elif a+b+c == 1:
    ans = solve()
    if ans: 
        print('Yes')
        print(*ans, sep = '\n')
    else:
        print('No')
elif a+b+c == 2:
    ans = []
    flag = True
    for i, (x, y) in enumerate(s):
        if num[x]>num[y]: x, y = y, x
        if num[x]==num[y] and i < n-1:
            if y == s[i+1][0] or y == s[i+1][1]:
                x, y = y, x
        num[x]+=1
        num[y]-=1
        ans.append(x)
        if num[y]<0:
            flag = False
    if flag:
        print('Yes')
        print(*ans, sep = '\n')
    else:
        print('No')
elif num[id[0]] == 0 and num[id[1]] == 0 and (s[0]==id[0]+id[1] or s[0]==id[1]+id[0]):
    print('No')
else:
    ans = solve()
    print('Yes')
    print(*ans, sep = '\n')

Buggy submission (verdict: Runtime Error):
def solve():
    ans = []
    for i, (x, y) in enumerate(s):
        if num[x]>num[y]: x, y = y, x
        if num[x]==num[y] and i < n-1:
            if y == s[i+1][0] or y == s[i+1][1]:
                x, y = y, x
        num[x]+=1
        num[y]-=1
        ans.append(x)
        if num[y]<0: return False
    return True
from collections import defaultdict
import sys
n, a, b, c = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
ans = solve()
if ans:
    print('Yes')
    print(*ans, sep = '\n')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
def solve():
    ans = []
    for x, y in s:
        if(num[x]>num[y]): x, y = y, x
        num[x]+=1
        num[y]-=1
        ans.append(x)
        if num[y]<0: return False
    return ans
from collections import defaultdict
import sys
n, a, b, c = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
id.sort(key = lambda x:num[x])
if a+b+c == 0:
    print('No')
    sys.exit()
elif a+b+c == 1:
    ans = solve()
    if ans: 
        print('Yes')
        print(*ans, sep = '\n')
    else:
        print('No')
elif a+b+c == 2:
    ans = []
    flag = True
    for i, (x, y) in enumerate(s):
        if num[x]>num[y]: x, y = y, x
        if num[x]==num[y] and i < n-1:
            if y == s[i+1][0] or y == s[i+1][1]:
                x, y = y, x
        num[x]+=1
        num[y]-=1
        ans.append(x)
        if num[y]<0:
            flag = False
    if flag:
        print('Yes')
        print(*ans, sep = '\n')
    else:
        print('No')
elif num[id[0]] == 0 and num[id[1]] == 0 and (s[i]==id[0]+id[1] or [i]==id[1]+id[0]):
    print('No')
else:
    ans = solve()
    print('Yes')
    print(*ans, sep = '\n')
Problem p02703 (python)

Fixed submission:
import heapq
inf = 10**18
def dijkstra(s, n, G):#スタート, 頂点数, グラフ:[[(cost, v)], ...]
    dist = [inf]*n
    edges = []#(sからvまでのコストの候補, v)
    dist[s] = 0
    for e in G[s]:
        heapq.heappush(edges, e)
    while edges:
        cost, v = heapq.heappop(edges)
        if dist[v] != inf:
            continue
        dist[v] = cost
        for c, nv in G[v]:
            if dist[nv] == inf:
                heapq.heappush(edges, (cost + c, nv))
    return dist
mx = 5005
n, m, s = map(int, input().split())
g = [[] for _ in range(n*mx)]
for i in range(m):
    u, v, a, b = map(int, input().split())
    u-=1
    v-=1
    for j in range(mx):
        if j>=a:
            g[u*mx+j].append((b, v*mx+j-a))
            g[v*mx+j].append((b, u*mx+j-a))
for i in range(n):
    c, d = map(int, input().split())
    for j in range(mx-c):
        g[i*mx+j].append((d, i*mx+j+c))
dist = dijkstra(min(s, mx-1), len(g), g)
for i in range(1, n):
    res = inf
    for j in range(mx):
        res = min(res, dist[i*mx+j])
    print(res)

Buggy submission (verdict: Runtime Error):
import heapq
inf = 10**18
def dijkstra(s, n, G):#スタート, 頂点数, グラフ:[[(cost, v)], ...]
    dist = [inf]*n
    edges = []#(sからvまでのコストの候補, v)
    dist[s] = 0
    for e in G[s]:
        heapq.heappush(edges, e)
    while edges:
        cost, v = heapq.heappop(edges)
        if dist[v] != inf:
            continue
        dist[v] = cost
        for c, nv in G[v]:
            if dist[nv] == inf:
                heapq.heappush(edges, (cost + c, nv))
    return dist
mx = 5005
n, m, s = map(int, input().split())
g = [[] for _ in range(n*mx)]
for i in range(m):
    u, v, a, b = map(int, input().split())
    u-=1
    v-=1
    for j in range(mx):
        if j>=a:
            g[u*mx+j].append((b, v*mx+j-a))
            g[v*mx+j].append((b, u*mx+j-a))
for i in range(n):
    c, d = map(int, input().split())
    for j in range(mx-c):
        g[i*mx+j].append((d, i*mx+j+c))
dist = dijkstra(s, len(g), g)
for i in range(1, n):
    res = inf
    for j in range(mx):
        res = min(res, dist[i*mx+j])
    print(res)
Problem p02788 (python)

Fixed submission:

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [XH[i][0] for i in range(N)]
ans = 0
res = 0
from bisect import bisect_left
cnt = [0]*(N+1)
for i in range(N):
    x, h = XH[i]
    res-=cnt[i]
    h-=res
    if h<=0:
        continue
    n = ((h-1)//A+1)
    j = bisect_left(X, x+D*2+1)
    cnt[j]+=n*A
    res += n*A
    ans+=n
print(ans)

Buggy submission (verdict: Runtime Error):

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [XH[i][0] for i in range(N)]
S = SegmentTree(N, 0, lambda x, y:x+y)
ans = 0
res = 0
from bisect import bisect
cnt = [0]*(N+1)
for i in range(N):
    x, h = XH[i]
    res-=cnt[i]
    h-=res
    if h<=0:
        continue
    n = ((h-1)//A+1)
    j = bisect(X, x+D*2+1)
    cnt[j]+=n*A
    res+= n*A
    ans+=n
print(ans)
Problem p02799 (python)

Fixed submission:
import sys
N, M = map(int, input().split())
D = list(map(int, input().split()))
DI = list(zip(D, list(range(N))))
G = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    G[u-1].append((v-1, i))
    G[v-1].append((u-1, i))
DI.sort()
V = [-1]*N
j = 0
used = [False]*N
ans = [10**9]*M
BW = ['']*N
for j in range(N):
    d, v = DI[j]
    if used[v]:
        continue
    for nv, i in G[v]:
        if d == D[nv]:
            if BW[nv] == '':
                BW[nv] = 'B'
                BW[v] = 'W'
                ans[i] = d
                used[v] = True
                used[nv] = True
            elif BW[nv] == 'W':
                BW[v] = 'B'
                ans[i] = d
                used[v] = True
            else:
                BW[v] = 'W'
                ans[i] = d
                used[v] = True
            break
        elif used[nv]:
            if BW[nv] == 'B':
                BW[v] = 'B'
                ans[i] = d-D[nv]
                used[v] = True
            else:
                BW[v] = 'W'
                ans[i] = d-D[nv]
                used[v] = True
            break
    if not used[v]:
        print(-1)
        sys.exit()
print(*BW, sep = '')
print(*ans, sep = '\n')

Buggy submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
D = list(zip(list(map(int, input().split())), list(range(N))))
G = [[] for _ in range(N)]
for i in range(N):
    u, v = map(int, input().split())
    G[u-1].append((v-1, i))
    G[v-1].append((u-1, i))
E = [e for e in D]
D.sort()
V = [-1]*N
j = 0
used = [False]*N
ans = [10**9]*M
BW = ['']*N
while j<N:
    d, v = D[j]
    for nv, i in G[v]:
        nd, k = E[nv]
        if used[nv] and d>nd:
            ans[i] = d-nd
            used[v] = True
            j+=1
            BW[v] = BW[nv]
            break
        if nd == d:
            used[v] = used[nv] = True
            ans[i] = d
            if BW[nv] == '':
                BW[nv] = 'B'
                BW[v] = 'W'
                j+=2
            elif BW[nv] == 'B':
                BW[v] = 'W'
                j+=1
            else:
                BW[v] = 'B'
                j+=1
            break
    if not used[v]:
        print(-1)
        sys.exit()
print(*BW, sep = '')
print(*ans, sep = '\n')

Buggy submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
D = list(zip(list(map(int, input().split())), list(range(N))))
G = [[] for _ in range(N)]
for i in range(N):
    u, v = map(int, input().split())
    G[u-1].append((v-1, i))
    G[v-1].append((u-1, i))
E = [e for e in D]
D.sort()
V = [-1]*N
j = 0
used = [False]*N
ans = [10**9]*M
BW = ['']*N
while j<N:
    d, v = D[j]
    for nv, i in G[v]:
        nd, k = E[nv]
        if used[nv]:
            ans[i] = d-nd
            used[v] = True
            j+=1
            BW[v] = BW[nv]
            break
        if nd == d:
            used[v] = used[nv] = True
            ans[i] = d
            BW[nv] = 'B'
            BW[v] = 'W'
            j+=2
            break
    if not used[v]:
        print(-1)
        sys.exit()
print(*BW, sep = '')
print(*ans, sep = '\n')
Problem p02822 (python)

Fixed submission:
import sys 
sys.setrecursionlimit(10**9)
N = int(input())
G = [[] for _ in range(N)]
mod = 10**9+7
for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
cnt = [[] for _ in range(N)]
que = [0]
depth = [-1]*N
depth[0] = 0
while que:
    v = que.pop()
    d = depth[v]
    for nv in G[v]:
        if depth[nv]>=0:
            continue
        depth[nv] = d+1
        que.append(nv)
d_to_i = [[] for _ in range(N)]
for i in range(N):
    d_to_i[depth[i]].append(i)
for d in range(N)[::-1]:
    for v in d_to_i[d]:
        for nv in G[v]:
            if depth[nv]<depth[v]:
                continue
            if cnt[nv]:
                cnt[v].append(sum(cnt[nv])+1)
            else:
                cnt[v].append(1)
for i in range(N):
    res = N-1
    for j in cnt[i]:
        res-=j
    cnt[i].append(res)
ans = 0
p = [1]*N
for i in range(1, N):
    p[i] = p[i-1]*2%mod
for v in range(N):
    if len(cnt[v])<=1:
        continue    
    res = p[N-1]-1
    for a in cnt[v]:
        res-=p[a]-1
    ans+=res
    ans%=mod
inv = pow(2, (mod-2)*N, mod)
print(ans*inv%mod)

Buggy submission (verdict: Runtime Error):
import sys 
sys.setrecursionlimit(10**9)
N = int(input())
G = [[] for _ in range(N)]
mod = 10**9+7
for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
cnt = [[] for _ in range(N)]
def dfs(p, v):
    s = 0
    for nv in G[v]:
        if nv == p:
            continue
        res = dfs(v, nv)
        cnt[v].append(res)
        s+=res
    cnt[v].append(N-s-1)
dfs(-1, 0)

Buggy submission (verdict: Runtime Error):
N = int(input())
G = [[] for _ in range(N)]
mod = 10**9+7
for _ in range(N-1):
    A, B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
cnt = [[] for _ in range(N)]
def dfs(p, v, n):
    s = 0
    for nv in G[v]:
        if nv == p:
            continue
        res = dfs(v, nv, n+1)
        cnt[v].append(res)
        s+=res
    cnt[v].append(N-s-1)
    return s+1
dfs(-1, 0, 0) 

ans = 0
for v in range(N):
    if len(cnt[v])<=1:
        continue    
    res = pow(2, N-1, mod)-1
    for a in cnt[v]:
        res-=pow(2, a, mod)-1
    ans+=res
    ans%=mod
inv = pow(2, (mod-2)*N, mod)
print(ans*inv%mod)
Problem p02837 (python)

Fixed submission:
N = int(input())
B = [[] for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        B[i].append((x-1, y))
ans = 0
for s in range(1<<N):
    flag1 = True
    cnt = 0
    for i in range(N):
        if s&(1<<i):
            cnt+=1
            flag2 = True
            for x, y in B[i]:
                if ((s>>x)&1) != y:
                    flag2 = False
                    break
            if not flag2:
                flag1 = False
    if flag1:
        ans = max(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        C[i][j] = A[i][j]-B[i][j]
M = 80*(H+W)
dp = [[set() for i in range(W)] for j in range(H)]
c = C[0][0]
dp[0][0].add(c)
dp[0][0].add(-c)
for s in range(1, H+W):
    for b in range(max(s-H+1, 0), min(s, W)):
        a = s-b
        c = C[a][b]
        if a>=1:
            for i in dp[a-1][b]:
                dp[a][b].add(i+c)
                dp[a][b].add(i-c)

        if b>=1:
            for i in dp[a][b-1]:
                dp[a][b].add(i+c)
                dp[a][b].add(i-c)
ans = min(abs(i) for i in dp[-1][-1])
print(ans)
Problem p02840 (python)

Fixed submission:
from fractions import gcd
import sys
n, x, d = map(int, input().split())
if d < 0:
    d = -d
    x = -x
if d == 0:
    print(n+1 if x != 0 else 1)
    sys.exit()
g = gcd(d, x)
mod = abs(d//g)
hani = [[] for _ in range(n+1)]
for k in range(n+1):
    l = x*k+k*(k-1)//2*d
    r = x*k+k*(n*2-k-1)//2*d+d
    hani[k%mod].append((l, 0))
    hani[k%mod].append((r, 1))
ans = 0
for i in range(n+1):
    if not hani[i]:
        break
    hani[i].sort()
    cnt = 0
    l = None
    for a, f in hani[i]:
        if f == 0:#l
            if cnt == 0:
                l = a
            cnt+=1
        else:
            cnt-=1
            if cnt == 0:
                ans+=(a-l)//d
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
n, x, d = map(int, input().split())
if d < 0:
    d = -d
    x = -x
if d == 0:
    print(n+1 if x != 0 else 0)
    sys.exit()
g = gcd(d, x)
mod = d//g
hani = [[] for _ in range(n+1)]
for k in range(n+1):
    l = x*k+k*(k-1)//2*d
    r = x*k+k*(n*2-k-1)//2*d+d
    hani[k%mod].append((l, 0))
    hani[k%mod].append((r, 1))
ans = 0
for i in range(n+1):
    if not hani[i]:
        break
    hani[i].sort()
    cnt = 0
    l = None
    for a, f in hani[i]:
        if f == 0:#l
            if cnt == 0:
                l = a
            cnt+=1
        else:
            cnt-=1
            if cnt == 0:
                ans+=(a-l)//d
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
n, x, d = map(int, input().split())
if d < 0:
    d = -d
    x = -x
if d == 0:
    print(n+1 if x != 0 else 0)
    sys.exit()
g = gcd(d, x)
mod = d//g
hani = [[] for _ in range(n)]
for k in range(n+1):
    l = x*k+k*(k-1)//2*d
    r = x*k+k*(n*2-k-1)//2*d+d
    hani[k%mod].append((l, 0))
    hani[k%mod].append((r, 1))
ans = 0
for i in range(n):
    if not hani[i]:
        break
    hani[i].sort()
    cnt = 0
    l = None
    for a, f in hani[i]:
        if f == 0:#l
            if cnt == 0:
                l = a
            cnt+=1
        else:
            cnt-=1
            if cnt == 0:
                ans+=(a-l)//d
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sys
n, x, d = map(int, input().split())
if d < 0:
    d = -d
    x = -x
if d == 0:
    print(n+1 if x != 0 else 0)
    sys.exit()
g = math.gcd(d, x)
mod = d//g
hani = [[] for _ in range(n)]
for k in range(n+1):
    l = x*k+k*(k-1)//2*d
    r = x*k+k*(n*2-k-1)//2*d+d
    hani[k%mod].append((l, 0))
    hani[k%mod].append((r, 1))
ans = 0
for i in range(n):
    if not hani[i]:
        break
    hani[i].sort()
    cnt = 0
    l = None
    for a, f in hani[i]:
        if f == 0:#l
            if cnt == 0:
                l = a
            cnt+=1
        else:
            cnt-=1
            if cnt == 0:
                ans+=(a-l)//d
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
d = [0]*N
G = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    d[a-1]+=1
    d[b-1]+=1
    G[a-1].append((i, b-1))
    G[b-1].append((i, a-1))
K = max(d)
ans = [0]*(N-1)
def dfs(v, p, c):
    if G[v] == [p]:
        return 
    nc = 1
    for i, nv in G[v]:
        if nv == p:
            continue
        if nc == c:
            nc+=1
        ans[i] = nc
        dfs(nv, v, nc)
        nc+=1
    return
dfs(0, -1, -1)
print(K)
print(*ans, sep = '\n')

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [0]*N
G = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    d[a-1]+=1
    d[b-1]+=1
    G[a-1].append((i, b-1))
    G[b-1].append((i, a-1))
K = max(d)
ans = [0]*(N-1)
def dfs(v, p, c):
    if G[v] == [p]:
        return 
    nc = 1
    for i, nv in G[v]:
        if nv == p:
            continue
        if nc == c:
            nc+=1
        ans[i] = nc
        dfs(nv, v, nc)
        nc+=1
    return
dfs(0, -1, -1)
print(K)
print(*ans, sep = '\n')
Problem p02874 (python)

Fixed submission:
N = int(input())
LR = []
L, R = [], []
for _ in range(N):
    l, r = map(int,  input().split())
    LR.append((l, r))
    L.append(l)
    R.append(r)
L.sort()
R.sort()
ans = 0
for l, r in LR:
    m = L[-1]
    M = R[0]
    if l == m:
        m = L[-2]
    if M == r:
        M = R[1]
    ans = max(max(0, M-m+1)+r-l+1, ans)
LR.sort()
tmp = [LR[-1]]
Rmin = LR[-1][1]
for i in range(N-1)[::-1]:
    if LR[i][1]<=Rmin:
        tmp.append(LR[i])
        Rmin = LR[i][1]
LR = tmp[::-1]
rmin = LR[0][1]
lmax = LR[-1][0]
for i in range(len(LR)-1):
    l0, r0 = LR[i]
    l1, r1 = LR[i+1]
    res1 = max(0, rmin-l0+1)
    res2 = max(0, r1-lmax+1)
    ans = max(ans, res1+res2)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
lr = []
L, R = [], []
for _ in range(N):
    l, r = map(int, input().split())
    lr.append((l, r))
    L.append(l)
    R.append(r)
lr.sort()
L.sort()
R.sort()
ans = 0
for l, r in lr:  
    m = L[-1]
    if L[-1] == l:
        m = L[-2]
    M = R[0]
    if R[0] == r:
        M = R[1]
    ans = max(ans, M-m+1+r-l+1)
tmp = [lr[0]]
for i in range(1, N):
    if lr[i][0] == lr[i][1]:
        continue
    else:
        tmp.append(lr[i])
lr = tmp
R = lr[-1][1]
tmp = [lr[-1]]
for l, r in lr[-2::-1]:
    if R<=r:
        continue
    tmp.append((l, r))
    R = r
lr = tmp[::-1]
ans1 = [0]
ans2 = [0]
R = lr[0][1]
for l, r in lr:
    if l>R:
        ans1.append(0)
    else:
        ans1.append(R-l+1)
L = lr[-1][0]
for l, r in lr1[::-1]:
    if L>r:
        ans2.append(0)
    else:
        ans2.append(r-L+1)
for a, b in zip(ans1, ans2[::-1]):
    ans = max(ans, a+b)
print(ans)
Problem p02909 (python)

Fixed submission:
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S== 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())
dp = [[0 for i in range(N+1)] for i in range(N+1)]

for i in reversed(range(N)):
    for j in reversed(range(N)):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if j > i:
            tmp = min(j-i,dp[i][j])
            ans = max(tmp,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(N)[::-1]:
    for j in range(N)[::-1]:
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

print(max(max(min(dp[a][b], a-b) for a in range(b, N)) for b in range(N)))
Problem p02913 (python)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(N):
    if N-i<ans:
        break
    if S[i+1:].find(S[i-ans:i+1])>=0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
S = list(map(ord, list(input())))
mod = 10**9+7
base = 1234
power = [1]*(N+1)
for i in range(1, N+1):
    power[i] = power[i-1]*base%mod
def check(m):
    if N-m<m:
        return False
    res = 0
    for i in range(m):
        res+=S[i]*power[m-i-1]
        res%=mod
    dic = {res:0}
    for i in range(N-m):
        res = ((res-S[i]*power[m-1])*base
                             +S[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False
ok = 0
ng = N+1
while ng-ok>1:
    mid = (ok+ng)//2
    
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
S = list(map(ord, list(input())))
mod = 10**9+7
base = 100
power = [1]*(N+1)
for i in range(1, N+1):
    power[i] = power[i-1]*base%mod
def check(m):
    if N-m<m:
        return False
    rolling_hash = [0]*(N-m+1)
    res = 0
    for i in range(m):
        res+=S[i]*power[m-i-1]
        res%=mod
    rolling_hash[0] = res
    dic = {res:0}
    for i in range(N-m):
        tmp = ((rolling_hash[i]-S[i]*power[m-1])*base
                             +S[i+m])%mod
        rolling_hash[i+1] = tmp
        if tmp in dic.keys():
            index = dic[tmp]
            if index +m<=i+1:
                return True
        else:
            dic[rolling_hash[i+1]] = i+1
    return False
ok = 0
ng = N+1
while ng-ok>1:
    mid = (ok+ng)//2
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Buggy submission (verdict: Runtime Error):
def Z_algo(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0#最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        #i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP
ans = 0
for i in range(N):
    LCP = Z_algo(S[i:])
    for j, l in enumerate(LCP):
        tmp = min(l, j-i+1)
        ans = max(ans, tmp)
print(ans)
Problem p02920 (python)

Fixed submission:
import sys
N = int(input())
S = sorted(list(map(int, input().split())))
parent = [S[-1]]
rest = S[:-1]
for i in range(N):
    next_generation = []
    next_rest = []
    for p in parent[::-1]:
        while True:
            if len(rest) == 0:
                print('No')
                sys.exit()
            q = rest.pop()
            if p>q:
                next_generation.append(q)
                break
            else:
                next_rest.append(q)
    parent+=next_generation
    parent.sort()
    rest += next_rest
    rest.sort()
print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = sorted(list(map(int, input().split())), reverse = True)
def C(N, S):
    for i in range(N):
        if any(S[(1<<i)-1+j] == S[(1<<(i+1))-1+j] for j in range(1<<i)):
            return False
    return True
if C(N, S):
    print('Yes')
else:
    print('No')