Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M, L = (int(i) for i in input().split())

import heapq
def Dijkstra(graph, start):
    N = len(graph)
    d = {}
    prev = {}
    for i in range(N):
        prev[i] = None
        if i == start:
            d[i] = 0
        else:
            d[i] = float('inf')
    Q = []
    heapq.heappush(Q, (0, start))
    while Q:
        d_u, u = heapq.heappop(Q)
        if d[u] < d_u:#ダブりを回避
            continue
        for i in range(N):
            if graph[u][i]:
                temp = d_u + graph[u][i]
                if d[i] > temp:
                    d[i] = temp
                    prev[i] = u
                    heapq.heappush(Q, (d[i], i))
    return (d, prev)

graph = [[0]*N for i in range(N)]
for i in range(M):
    a, b, c = (int(i) for i in input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

new_graph = [[0]*N for i in range(N)]
for i in range(N):
    d, prev = Dijkstra(graph, i)
    for j in range(N):
        if d[j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1

ans = []
for i in range(N):
    d, prev = Dijkstra(new_graph, i)
    ans.append(d)

Q = int(input())
for i in range(Q):
    s, t = (int(i) for i in input().split())
    if ans[s-1][t-1] == float("inf"):
        print("-1")
    else:
        print(ans[s-1][t-1]-1)

Fixed submission:
N, M, L = (int(i) for i in input().split())

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

graph = [[0]*N for i in range(N)]
for i in range(M):
    a, b, c = (int(i) for i in input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

graph = csr_matrix(graph)
d = floyd_warshall(csgraph=graph, directed=False)

new_graph = [[0]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if d[i][j] <= L:
            new_graph[i][j] = 1
            new_graph[j][i] = 1

graph = csr_matrix(new_graph)
d = floyd_warshall(csgraph=graph, directed=False)
Q = int(input())
for i in range(Q):
    s, t = (int(i) for i in input().split())
    if d[s-1][t-1] == float("inf"):
        print("-1")
    else:
        print(int(d[s-1][t-1]-1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g = [[-1, -1] for i in range(n*n)]
z = [0] * (n*n)

a = []
for _ in range(n):
    a.append([int(i) for i in input().split()])

for i in range(n):
    for j in range(n-2):
        p, q = (i, a[i][j]-1)
        r, s = (i, a[i][j+1]-1)
        r, s = (min(r, s), max(r ,s))
        if p < q:
            g[p*n+q][0] = r*n + s
        else:
            g[q*n+p][1] = r*n + s
        z[r*n+s] += 1

from collections import deque
qu = set([])
for i in range(n):
    p, q = (i, a[i][0]-1)
    p, q = (min(p, q), max(p ,q))
    if z[p*n+q] == 0:
        qu.add(p*n+q)

ans = 0
re = 0
qu = deque(qu)
while True:
    nqu = deque()
    while qu:
        s = qu.popleft()
        re += 1
        for t in g[s]:
            if t != -1:
                z[t] -= 1
                if z[t] == 0:
                    nqu.append(t)
    ans += 1    
    qu = nqu
    if not qu:
        break

if re == n*(n-1)//2:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
g = [[-1, -1] for i in range(n*n)]
z = [0] * (n*n)

a = []
for _ in range(n):
    a.append([int(i) for i in input().split()])

for i in range(n):
    for j in range(n-2):
        p, q = (i, a[i][j]-1)
        r, s = (i, a[i][j+1]-1)
        r, s = (min(r, s), max(r ,s))
        if p < q:
            g[p*n+q][0] = r*n + s
        else:
            g[q*n+p][1] = r*n + s
        z[r*n+s] += 1

qu = set([])
for i in range(n):
    p, q = (i, a[i][0]-1)
    p, q = (min(p, q), max(p ,q))
    if z[p*n+q] == 0:
        qu.add(p*n+q)

ans = 0
re = 0
while True:
    nqu = []
    while qu:
        s = qu.pop()
        re += 1
        for t in g[s]:
            if t != -1:
                z[t] -= 1
                if z[t] == 0:
                    nqu.append(t)
    ans += 1    
    qu = nqu
    if not qu:
        break

if re == n*(n-1)//2:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
def BF(N, edges, start):
    D = {}
    P = {}
    for i in range(N):
        P[i] = None
        if i == start:
            D[i] = 0
        else:
            D[i] = float("inf")

    for i in range(N-1):
        for edge in edges:
            a, b, c = edge
            if D[b] > D[a] + c:
                D[b] = D[a] + c
                P[b] = a

    ret = (D, P)

    Nega = {}
    for i in range(N):
        Nega[i] = False
    
    for i in range(N):
        for edge in edges:
            a, b, c = edge
            if Nega[a] == True:
                Nega[b] = True
            if D[b] > D[a] + c:
                D[b] = D[a] + c
                P[b] = a
                Nega[b] = True
        
    return (D, P, Nega)

N, M, P = (int(i) for i in input().split())
edges = []
for i in range(M):
    A, B, C = (int(i) for i in input().split())
    edges.append((A-1, B-1, P-C))
D, P, Nega = BF(N, edges, 0)
if Nega[N-1] == True:
    print(-1)
else:
    if D[N-1] <= 0:
        print(-D[N-1])
    else:
        print(0)

Fixed submission:
def BF(v, start, edges):
    INF = 10**18
    nega = False
    d = [INF] * v
    d[start] = 0
    for _ in range(v):
        f = False
        for a, b, c in edges:
            cost = d[a] + c
            if cost < d[b]:
                d[b] = cost
                f = True
        if not f:
            break
    else:
        nega = True
    return d, nega

from collections import deque
def BFS(N, graph, start):
    d = [-1 for i in range(N)]
    Q = deque([])
    Q.append(start)
    d[start] = 0
    while Q:
        v = Q.popleft()
        for u in graph[v]:
            if d[u] == -1:
                d[u] = d[v] + 1
                Q.append(u)
    return d

N, M, P = (int(i) for i in input().split())
graph = [[] for i in range(N)]
graphr = [[] for i in range(N)]
edges = []
for i in range(M):
    A, B, C = (int(i) for i in input().split())
    graph[A-1].append(B-1)
    graphr[B-1].append(A-1)
    edges.append((A-1, B-1, P-C))
d_start = BFS(N, graph, 0)
d_end = BFS(N, graphr, N-1)
nodes_start = [i for i in range(N) if d_start[i] >= 0]
nodes_end = [i for i in range(N) if d_end[i] >= 0]
new_edges = []
for A, B, C in edges:
    if A in nodes_start and B in nodes_start and A in nodes_end and B in nodes_end:
        new_edges.append((A, B, C))
d, Nega = BF(N, 0, new_edges)
if Nega == True:
    print(-1)
else:
    print(max(-d[N-1], 0))
Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
L = [0]*N
P = [-1]*(2*10**5+1)
for i in range(2*N):
    j = i%N
    a = A[j]
    if P[a] == -1:
        P[a] = i
    else:
        L[P[a]] = j
        P[a] = j
s = 0
start = 0
v = [True]*N
h = [(0, 0)]
h_app = h.append
while v[start]:
    v[start] = False
    if start < L[start]:
        s += (L[start] - start +1)
    else:
        s += (L[start] - start +N +1)
    start = (L[start]+1)%N
    h_app((s, start))

r = (N*K)%s
import bisect
if r == 0:
    print("")
else:
    res = bisect.bisect(h, (r, 10**10))-1
    s, start = h[res]
    s = r-s
    ans = []
    P = [-1]*(2*10**5+1)
    if s:
        cou = 0
        for i in range(s):
            if P[A[(start+i)%N]] == -1:
                P[A[(start+i)%N]] = i
                ans.append(str(A[(start+i)%N]))
            else:
                sr = P[A[(start+i)%N]]
                P[A[(start+i)%N]] = -1
                for j in range(cou-sr):
                    ans.pop()
                cou = sr-1
            cou += 1
    print(" ".join(ans))

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

N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
L = [0]*N
P = [-1]*(2*10**5+1)
for i in range(2*N):
    j = i%N
    a = A[j]
    if P[a] == -1:
        P[a] = i
    else:
        L[P[a]] = j
        P[a] = j
s = 0
start = 0
v = [True]*N
h = [(0, 0)]
h_app = h.append
while v[start]:
    v[start] = False
    if start < L[start]:
        s += (L[start] - start +1)
    else:
        s += (L[start] - start +N +1)
    start = (L[start]+1)%N
    h_app((s, start))

r = (N*K)%s
import bisect
if r == 0:
    print("")
else:
    res = bisect.bisect(h, (r, 10**10))-1
    s, start = h[res]
    s = r-s
    ans = []
    P = [-1]*(2*10**5+1)
    if s:
        cou = 0
        for i in range(s):
            if P[A[(start+i)%N]] == -1:
                P[A[(start+i)%N]] = cou
                ans.append(str(A[(start+i)%N]))
            else:
                sr = P[A[(start+i)%N]]
                P[A[(start+i)%N]] = -1
                for j in range(cou-sr):
                    a = ans.pop()
                    P[int(a)] = -1
                cou = sr-1
            cou += 1
    print(" ".join(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
DP = [0] * (N+1)
DP[0] = 1
su = [0] * (2*(10**5))
prev = None
for i in range(N):
    C = int(input())
    if prev == C:
        DP[i+1] = DP[i]
    else:
        su[C] += DP[i]
        DP[i+1] = su[C]
    prev = C
print(DP[N])

Fixed submission:
N = int(input())
DP = [0] * (N+1)
DP[0] = 1
su = [0] * (2*(10**5)+1)
prev = None
MOD = 10**9+7
for i in range(N):
    C = int(input())
    if prev == C:
        DP[i+1] = DP[i]
    else:
        su[C] += DP[i]
        su[C] %= MOD
        DP[i+1] = su[C]
    DP[i+1] %= MOD
    prev = C
print(DP[N])
Buggy python submission (verdict: Runtime Error):
, B = (int(i) for i in input().split())
if A%2 == 0:
  a = 0
else:
  a = A
  A = A + 1
if B%2 == 1:
  b = 0
else:
  b = B
  B = B - 1
if (B-A+1)%4==0:
  c = 0
else:
  c = 1
print(a^b^c)

Fixed submission:
A, B = (int(i) for i in input().split())
if A%2 == 0:
  a = 0
else:
  a = A
  A = A + 1
if B%2 == 1:
  b = 0
else:
  b = B
  B = B - 1
if (B-A+1)%4==0:
  c = 0
else:
  c = 1
print(a^b^c)
Buggy python submission (verdict: Runtime Error):
N, M = (int(i) for i in input().split())
L = []
for i in range(M):
    a, b = (int(j) for j in input().split())
    L.append((a-1, b-1))
L.reverse()

uf = [-1]*N
def parent(v):
    if uf[v] < 0:
        return v
    else:
        uf[v] = parent(uf[v])
        return uf[v]

res = [0]*M
ans = (N*(N-1))//2
res[0] = ans

for i in range(1, M):
    a, b = L[i-1]
    pa = parent(a)
    pb = parent(b)
    if pa != pb:
        sa = -uf[pa]
        sb = -uf[pb]
        ans -= sa * sb
        uf[pb] = pa
        uf[pa] = -(sa + sb)
    res[i] = ans

res.reverse()
for i in range(M):
    print(res[i])

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

sys.setrecursionlimit(100000)

N, M = (int(i) for i in input().split())
L = []
for i in range(M):
    a, b = (int(j) for j in input().split())
    L.append((a-1, b-1))
L.reverse()

uf = [-1]*N
def parent(v):
    if uf[v] < 0:
        return v
    else:
        uf[v] = parent(uf[v])
        return uf[v]

res = [0]*M
ans = (N*(N-1))//2
res[0] = ans

for i in range(1, M):
    a, b = L[i-1]
    pa = parent(a)
    pb = parent(b)
    if pa != pb:
        sa = -uf[pa]
        sb = -uf[pb]
        ans -= sa * sb
        uf[pb] = pa
        uf[pa] = -(sa + sb)
    res[i] = ans

res.reverse()
for i in range(M):
    print(res[i])
Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
C = [[0]*2 for i in range(40)]
for i in range(40):
  cc = 0
  for a in A:
    if a & (2**(39-i)):
      cc += 1
  C[i][0] = cc * 2**(39-i)
  C[i][1] = (N-cc) * 2**(39-i)
INF = float("inf")
dp = [[-INF]*2 for i in range(41)]
dp[0][0] = 0
for i in range(40):
  d = (K>>(39-i))&1
  dp[i+1][0] = dp[i][0] + C[i][d]
  dp[i+1][1] = dp[i][1] + max(C[i])
  if d == 1:
    dp[i+1][1] = max(dp[i][0] + C[i][0], dp[i+1][1]
print(max(dp[40]))

Fixed submission:
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A = [format(a,'b').zfill(40) for a in A]
C = [0]*40
for i in range(40):
    cc = 0
    for a in A:
        keta = 39 - i
        if a[keta] == "1":
            cc += 1
    C[keta] = cc
ans = 0
for i in range(40):
    b = 39 - i
    if C[i] < N - C[i]:#0の方が個数が多い→1を採用したいとき
        if K < 2**b:
            ans += (2**b * C[i])
        else:
            ans += (2**b * (N-C[i]))
            K -= 2**b
    else:
        ans += (2**b * C[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
C = [0]*40
for i in range(40):
  for a in A:
    if a & (2**(39-i)):
      C[i] += 1
dp = [[0]*2 for in range(41)]
for i in range(40):
  if K ＆ (2**(39-i)):
    temp1 = dp[i][0] + 2**(39-i)*C[i]
    temp2 = dp[i][1] + 2**(39-i)*max(C[i],N-C[i])
    dp[i+1][1] = max(temp1, temp2)
    dp[i+1][0] = dp[i][1] + 2**(39-i)*(N-C[i])
  else:
    dp[i+1][1] =  dp[i][1] + 2**(39-i)*max(C[i],N-C[i])
    dp[i+1][0] = dp[i][0] + 2**(39-i)*C[i]
print(max(dp[40]))
    

Fixed submission:
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A = [format(a,'b').zfill(40) for a in A]
C = [0]*40
for i in range(40):
    cc = 0
    for a in A:
        keta = 39 - i
        if a[keta] == "1":
            cc += 1
    C[keta] = cc
ans = 0
for i in range(40):
    b = 39 - i
    if C[i] < N - C[i]:#0の方が個数が多い→1を採用したいとき
        if K < 2**b:
            ans += (2**b * C[i])
        else:
            ans += (2**b * (N-C[i]))
            K -= 2**b
    else:
        ans += (2**b * C[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
s = int(input())
if s == 1 or s == 2:
    print(4)
    res = 1
else:
    while True:
        if s == 4:
            break
        else:
            if s % 2 == 0:
                s = s // 2
            else:
                s = 3 * s + 1
            res += 1

    print(res+3)

Fixed submission:
s = int(input())
if s == 1 or s == 2:
    print(4)
else:
    res = 1
    while True:
        if s == 4:
            break
        else:
            if s % 2 == 0:
                s = s // 2
            else:
                s = 3 * s + 1
            res += 1

    print(res+3)
Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
L = []
for i in range(N):
    t,d = (int(i) for i in input().split())
    L.append((t,d))

L = sorted(L, key = lambda x:(x[0], -x[1]))
for i in range(N):
    if i == 0:
        ra = 0
        L[i] = (L[i][0], L[i][1], ra)
    else:
        if L[i][0] == L[i-1][0]:
            ra += 1
        else:
            ra = 0
        L[i] = (L[i][0], L[i][1], ra)

L = sorted(L, key = lambda x:(-x[1], x[0]))

if N != K:
    kouho = L[:K]
    amari = L[K:]
else:
    kouho = L
    
nowval = len(set([sushi[0] for sushi in kouho]))
nowder = sum([sushi[1] for sushi in kouho])
point = nowval ** 2 + nowder

if N == K:
    print(point)
else:
    weaks = []
    for sushi in kouho:
        if sushi[2] > 0:
            weaks.append(sushi)
    weaks.reverse()
    kaburan = []
    for sushi in amari:
        if sushi[2] == 0:
            kaburan.append(sushi)
    
    ma = max(len(weaks), len(kaburan))
    newpoint = point
    for i in range(ma):
        newpoint = newpoint - weaks[i][1] + kaburan[i][1]
        newpoint = newpoint - nowval ** 2 + (nowval + 1) ** 2
        nowval += 1
        point = max(point, newpoint)
    print(point)


Fixed submission:
N, K = (int(i) for i in input().split())
L = []
for i in range(N):
    t,d = (int(i) for i in input().split())
    L.append((t,d))

L = sorted(L, key = lambda x:(x[0], -x[1]))
for i in range(N):
    if i == 0:
        ra = 0
        L[i] = (L[i][0], L[i][1], ra)
    else:
        if L[i][0] == L[i-1][0]:
            ra += 1
        else:
            ra = 0
        L[i] = (L[i][0], L[i][1], ra)

L = sorted(L, key = lambda x:(-x[1], x[0]))

if N != K:
    kouho = L[:K]
    amari = L[K:]
else:
    kouho = L
    
nowval = len(set([sushi[0] for sushi in kouho]))
nowder = sum([sushi[1] for sushi in kouho])
point = nowval ** 2 + nowder

if N == K:
    print(point)
else:
    weaks = []
    for sushi in kouho:
        if sushi[2] > 0:
            weaks.append(sushi)
    weaks.reverse()
    kaburan = []
    for sushi in amari:
        if sushi[2] == 0:
            kaburan.append(sushi)
    
    ma = min(len(weaks), len(kaburan))
    newpoint = point
    if ma:
        for i in range(ma):
            newpoint = newpoint - weaks[i][1] + kaburan[i][1]
            newpoint = newpoint - nowval ** 2 + (nowval + 1) ** 2
            nowval += 1
            point = max(point, newpoint)
        print(point)
    else:
        print(point)
Buggy python submission (verdict: Runtime Error):
H, W = ( int(i) for i in input().split() )
S = [input() for i in range(H)]

cc = 0
for ss in S:
    for st in ss:
        if st == ".":
            cc += 1

for i in range(len(S)):
    S[i] = "#" + S[i] + "#"

temp = ["#" * (W + 2)]
S = temp + S + temp

dd = [[float("inf")] * W for i in range(H)]

def DFS(a, b, d):
    dd[a-1][b-1] = d
    for x, y in [(a+1, b), (a-1, b), (a, b+1), (a, b-1)]:
        if S[x][y] == "#":
            continue
        else:
            if dd[x-1][y-1] > d + 1:
                DFS(x, y, d + 1)

DFS(1,1,0)

print(cc - dd[H-1][W-1] -1)

Fixed submission:
import sys

H, W = ( int(i) for i in input().split() )
S = [input() for i in range(H)]

cc = 0
for ss in S:
    for st in ss:
        if st == ".":
            cc += 1

for i in range(len(S)):
    S[i] = "#" + S[i] + "#"

temp = ["#" * (W + 2)]
S = temp + S + temp

dd = [[float("inf")] * W for i in range(H)]

def DFS(a, b, d):
    dd[a-1][b-1] = d
    for x, y in [(a+1, b), (a-1, b), (a, b+1), (a, b-1)]:
        if S[x][y] == "#":
            continue
        else:
            if dd[x-1][y-1] > d + 1:
                DFS(x, y, d + 1)

sys.setrecursionlimit(10000)

DFS(1,1,0)
if dd[H-1][W-1] != float("inf"):
    print(cc - dd[H-1][W-1] -1)
else:
    print("-1")
Buggy python submission (verdict: Time Limit Exceeded):
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()

hp = H
res = 0
for b in kb:
	if b < max(ka):
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + max(ka) - 1)//max(ka)
	
print(res)
		

Fixed submission:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()
ma = max(ka)

hp = H
res = 0
for b in kb:
	if b < ma:
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + ma - 1)//ma
	
print(res)

Buggy python submission (verdict: Runtime Error):
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()

hp = H
res = 0
for b in kb:
	if b < max(a):
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + max(ka) - 1)//max(ka)
	
print(res)
		

Fixed submission:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()
ma = max(ka)

hp = H
res = 0
for b in kb:
	if b < ma:
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + ma - 1)//ma
	
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, C = (int(i) for i in input().split())

pp = [[0] * 100000 for i in range(C)]

for i in range(N):
    s, t, c = (int(i) for i in input().split())
    for j in range(s, t+1):
        pp[c-1][j] = 1

res = 0
for i in range(100000):
    cc = 0
    for j in range(C):
        if pp[j][i]:
            cc += 1
    res = max(res, cc)

print(res)


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

N, C = (int(i) for i in input().split())

pp = [[0] * 100001 for i in range(C)]

for i in range(N):
    s, t, c = (int(i) for i in input().split())
    for j in range(s, t+1):
        pp[c-1][j] = 1

res = 0
for i in range(100001):
    cc = 0
    for j in range(C):
        if pp[j][i]:
            cc += 1
    res = max(res, cc)

print(res)
Buggy python submission (verdict: Runtime Error):
Sdash = str(input())
T = str(input())

reslis = []
N = len(Sdash) - len(T) + 1
for i in range(N):
    Tdash = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if Tdash[j] == T[j] or Tdash[j] == "?":
            pass
        else:
            break
    else:
        if i == 0:
            reslis.append(T + Sdash[i+len(T)])
        elif i == N - 1:
            reslis.append(Sdash[:i] + T)
        else:
            reslis.append(Sdash[:i] + T + Sdash[i+len(T)])

if reslis:
    reslis = [st.replace("?","a") for st in reslis]
    reslis.sort()
    print(reslis[0])

else:
    print("UNRESTORABLE")
        

Fixed submission:
Sdash = str(input())
T = str(input())

reslis = []

if len(Sdash) >= len(T):
    for i in range(len(Sdash) - len(T) + 1):
        res = Sdash
        temp = Sdash[i:i+len(T)]
        for k in range(len(T)):
            if T[k] == temp[k] or temp[k] == "?":
                res = list(res)
                res[k+i] = T[k]
                res = "".join(res)
            else:
                break
        else:
            reslis.append(res) 

if reslis:
    reslis = [st.replace("?", "a") for st in reslis]
    print(min(reslis))
else:
    print("UNRESTORABLE")

Buggy python submission (verdict: Runtime Error):
Sdash = str(input())
T = str(input())

reslis = []
N = len(Sdash) - len(T) + 1
for i in range(N):
    Tdash = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if Tdash[j] == T[j] or Tdash[j] == "?":
            pass
        else:
            break
    else:
        print(Tdash)
        if i == 0:
            reslis.append(T + Sdash[i+len(T)])
        elif i == N - 1:
            reslis.append(Sdash[:i] + T)
        else:
            reslis.append(Sdash[:i] + T + Sdash[i+len(T)])

if reslis:
    reslis = [st.replace("?","a") for st in reslis]
    reslis.sort()
    print(reslis[0])

else:
    print("UNRESTORABLE")
        

Fixed submission:
Sdash = str(input())
T = str(input())

reslis = []

if len(Sdash) >= len(T):
    for i in range(len(Sdash) - len(T) + 1):
        res = Sdash
        temp = Sdash[i:i+len(T)]
        for k in range(len(T)):
            if T[k] == temp[k] or temp[k] == "?":
                res = list(res)
                res[k+i] = T[k]
                res = "".join(res)
            else:
                break
        else:
            reslis.append(res) 

if reslis:
    reslis = [st.replace("?", "a") for st in reslis]
    print(min(reslis))
else:
    print("UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for i in range(N):
    a = int(input())
    if a in L:
        L.remove(a)
    else:
        L.append(a)

L = set(L)
print(len(L))

Fixed submission:
N = int(input())
L = []
for i in range(N):
    a = int(input())
    L.append(a)

L.sort()
ptr = 0
temp = 0
num = 1
ans = 0
while ptr < N:
    cc = L[ptr]
    f = 0
    while ptr < N and L[ptr] == cc:#同じ数字が続く終了条件
        f += 1
        ptr += 1
    ans += f%2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
bit = 0
for i in range(N):
    a = int(input())
    bit = bit ^ 2 ** a

bit = str(bin(bit))

count = 0
for i in bit:
    if i == "1":
        count += 1

print(count)

Fixed submission:
N = int(input())
L = []
for i in range(N):
    a = int(input())
    L.append(a)

L.sort()
ptr = 0
temp = 0
num = 1
ans = 0
while ptr < N:
    cc = L[ptr]
    f = 0
    while ptr < N and L[ptr] == cc:#同じ数字が続く終了条件
        f += 1
        ptr += 1
    ans += f%2

print(ans)