Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,M = map(int,(input().split()))
x = [0]*M
y = [0]*M
z = [0]*M
line = [[] for _ in range(N+1)]
dot = []
for i in range(M):
    x[i],y[i],z[i] = map(int,(input().split()))
    line[x[i]].append(y[i])
    line[y[i]].append(x[i])
    dot.append(x[i])
    dot.append(y[i])

f = [0]*N
nohint = 0
hint = [0]*(N+1)
for i in range(1,N+1):
    f[i-1] = dot.count(i)
    if f[i-1] == 0:
        nohint += 1
    else:
        hint[i] = 1

not_visit = [False]*(N+1)
for i in range(len(hint)):
    if hint[i] == 1:
        not_visit[i] = True

ans = 0
stack = []
while sum(hint):
    stack.append(hint.index(1))
    while stack:
        now = stack.pop()
        if not_visit[now]:
            hint[now] = 0
            for i in line[now]:
                stack.append(i)
                hint[i] = 0
        not_visit[now] = False
    ans += 1
print(ans + nohint)

Fixed submission:
import copy
N,M = map(int,(input().split()))
x = [0]*M
y = [0]*M
z = [0]*M
line = [[] for _ in range(N+1)]
dot = []

for i in range(M):
    x[i],y[i],z[i] = map(int,(input().split()))
    line[x[i]].append(y[i])
    dot.append(x[i])
    dot.append(y[i])

class UnionFind:

    def __init__(self, n):
        self.par =  [-1] * n
        self.rank = [0] * n
    
    def root(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        else:
            if self.rank[x] <self.rank[y]:
                self.par[y] += self.par[x] # 負+負でsize管理 
                self.par[x] = y
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]: # 負+負でsize管理 
                    self.rank[x] += 1
    
    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.par[self.root(x)]

Tree = UnionFind(N)

for i in range(N):
    for j in line[i]:
        Tree.union(i-1,j-1)

nohint = 0
hint = []
for i in range(N):
    if Tree.size(i) == 1:
        nohint += 1
    else:
        hint.append(Tree.root(i))

print(nohint + len(set(hint)))
Buggy python submission (verdict: Time Limit Exceeded):
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    return functools.reduce(euclid, nums)

N = int(input())
A = list(map(int,(input().split())))
L = [0]*N
R = [0]*N

for i in range(N):
    L[i] = gcd(A[0:i+1])
for i in range(N):
    R[i] = gcd(A[N-1-i:N])

p = []

for i in range(N):
    if i == 0:
        p.append(R[N-2])
    elif i == N-1:
        p.append(L[N-2])
    else:
        p.append( gcd([L[i-1], R[N-2-i]]) )

print(max(p))

Fixed submission:
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    return functools.reduce(euclid, nums)

N = int(input())
A = list(map(int,(input().split())))
L = [0]*N
R = [0]*N
L[0] = A[0]
R[0] = A[N-1]
for i in range(1,N):
    L[i] = gcd([L[i-1],A[i]])
for i in range(1,N):
    R[i] = gcd([R[i-1],A[N-1-i]])

p = []

for i in range(N):
    if i == 0:
        p.append(R[N-2])
    elif i == N-1:
        p.append(L[N-2])
    else:
        p.append( gcd([L[i-1], R[N-2-i]]) )

print(max(p))

Buggy python submission (verdict: Time Limit Exceeded):
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    return functools.reduce(euclid, nums)

N = int(input())
A = list(map(int,(input().split())))
L = [0]*N
R = [0]*N

for i in range(N):
    L[i] = gcd(A[0:i+1])
for i in range(N):
    R[i] = gcd(A[N-1-i:N])

p = []

for i in range(N):
    if i == 0:
        p.append(gcd(R[0:N-1]))
    elif i == N-1:
        p.append(gcd(L[0:N-1]))
    else:
        p.append(gcd ( [gcd(L[0:i]),gcd(R[0:N-1-i])]) )

print(max(p))

Fixed submission:
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    return functools.reduce(euclid, nums)

N = int(input())
A = list(map(int,(input().split())))
L = [0]*N
R = [0]*N
L[0] = A[0]
R[0] = A[N-1]
for i in range(1,N):
    L[i] = gcd([L[i-1],A[i]])
for i in range(1,N):
    R[i] = gcd([R[i-1],A[N-1-i]])

p = []

for i in range(N):
    if i == 0:
        p.append(R[N-2])
    elif i == N-1:
        p.append(L[N-2])
    else:
        p.append( gcd([L[i-1], R[N-2-i]]) )

print(max(p))
Buggy python submission (verdict: Runtime Error):
import bisect

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

l = []
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)
s = 0
for i in range(Q):
    a,b = map(int,(input().split()))
    if l:
        print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))
    else:
        print(0)

Fixed submission:
import bisect

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

l = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)

for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))

Buggy python submission (verdict: Runtime Error):
import bisect

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

l = []
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)
s = 0
for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))

Fixed submission:
import bisect

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

l = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)

for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

A,B,Q = map(int,(input().split()))
s = [[0]*3 for _ in range(A)]
t = [[0]*3 for _ in range(B)]
x = [[0]*3 for _ in range(Q)]
slen = []
tlen = []
road = []
for i in range(A):
    s[i][0] = int(input())
    slen.append(s[i][0])
    s[i][1] = "s"
    road.append(s[i])
for i in range(B):
    t[i][0] = int(input())
    tlen.append(t[i][0])
    t[i][1] = "t"
    road.append(t[i])
for i in range(Q):
    x[i][0] = int(input())
road.sort()

for i in range(len(s)):
    index = bisect.bisect_left(tlen,s[i][0])
    if index < B:
        s[i][2] = min(abs(s[i][0]-tlen[index-1]),abs(tlen[index]-s[i][0]))
    else:
        s[i][2] = abs(s[i][0]-tlen[index-1])
for i in range(len(t)):
    index = bisect.bisect_left(slen,t[i][0])
    if index < A:
        t[i][2] = min(abs(t[i][0]-slen[index-1]),abs(slen[index]-t[i][0]))
    else:
        t[i][2] = abs(t[i][0]-slen[index-1])

for i in range(Q):
    index = bisect.bisect_left(road,x[i])
    if index < A+B:
        print(min(abs(x[i][0]-road[index-1][0])+road[index-1][2],abs(x[i][0]-road[index][0])+road[index][2]))
    else:
        print(abs(x[i][0]-road[index-1][0])+road[index-1][2])

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

A,B,Q = map(int,(input().split()))
s = [[0]*3 for _ in range(A)]
t = [[0]*3 for _ in range(B)]
x = [[0]*3 for _ in range(Q)]
slen = []
tlen = []
road = []
for i in range(A):
    s[i][0] = int(input())
    slen.append(s[i][0])
    s[i][1] = "s"
    road.append(s[i])
for i in range(B):
    t[i][0] = int(input())
    tlen.append(t[i][0])
    t[i][1] = "t"
    road.append(t[i])
for i in range(Q):
    x[i][0] = int(input())
road.sort()

for i in range(len(s)):
    index = bisect.bisect_left(tlen,s[i][0])
    if index < B:
        s[i][2] = min(abs(s[i][0]-tlen[index-1]),abs(tlen[index]-s[i][0]))
    else:
        s[i][2] = abs(s[i][0]-tlen[index-1])
for i in range(len(t)):
    index = bisect.bisect_left(slen,t[i][0])
    if index < A:
        t[i][2] = min(abs(t[i][0]-slen[index-1]),abs(slen[index]-t[i][0]))
    else:
        t[i][2] = abs(t[i][0]-slen[index-1])

for i in range(Q):
    index = bisect.bisect_left(road,x[i])
    if index < A+B:
        print(min(abs(x[i][0]-road[index-1][0])+road[index-1][2],abs(x[i][0]-road[index][0])+road[index][2]))
    else:
        print(abs(x[i][0]-road[index-1][0])+road[index-1][2])
Buggy python submission (verdict: Runtime Error):
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

Fixed submission:
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

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

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:j+1])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

Fixed submission:
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

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

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:j+1])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
        dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

Fixed submission:
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])
Buggy python submission (verdict: Runtime Error):
H,W = map(int,(input().split()))
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int,(input().split())))

ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] %2 == 1:
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1] %2 == 1:
        a[i+1][W-1] += 1
        ans.append(i+1,W,i+2,W)

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

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

ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] %2 == 1:
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1] %2 == 1:
        a[i+1][W-1] += 1
        ans.append([i+1,W,i+2,W])

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N,M,Q = map(int,(input().split()))
s = [[0]*(N+1) for _ in range(N+1)]
L = [0]*M
d = collections.defaultdict(int)
for i in range(M):
    L,R = map(int,(input().split()))
    d[(L,R)] += 1
for i in range(1,N+1):
    for j in range(1,N+1):
        s[i][j] = s[i][j-1] + d[(i,j)]
for i in range(Q):
    p,q = map(int,(input().split()))
    ans = 0
    for j in range(p,q+1):
        ans += s[j][q]-s[j][p-1]
    print(ans)

Fixed submission:
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,M,Q = map(int,(input().split()))
s = [[0]*(N+1) for _ in range(N+1)]
L = [0]*M
d = defaultdict(int)
for i in range(M):
    L,R = map(int,(input().split()))
    d[(L,R)] += 1
for i in range(1,N+1):
    for j in range(1,N+1):
        s[i][j] = s[i][j-1] + d[(i,j)]
for i in range(Q):
    p,q = map(int,(input().split()))
    ans = 0
    for j in range(p,q+1):
        ans += s[j][q]-s[j][p-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
R = int(input())
if R < 1200:
    print("ABC")
elif: R < 2800:
    print("ARC")
else:
    print("AGC")

Fixed submission:
R = int(input())
if R < 1200:
    print("ABC")
elif R < 2800:
    print("ARC")
else:
    print("AGC")
Buggy python submission (verdict: Runtime Error):
N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)
        else:
            print(M-i)
            print(now-(M-i))
            break

Fixed submission:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
print(math.ceil((N-1)/(K-1)))
Buggy python submission (verdict: Runtime Error):
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1000101):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])

Fixed submission:
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1010001):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])

Buggy python submission (verdict: Runtime Error):
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1000001):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])

Fixed submission:
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1010001):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])

Buggy python submission (verdict: Runtime Error):
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1000000):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])

Fixed submission:
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1010001):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])
Buggy python submission (verdict: Runtime Error):
a,b = map(int,(input().split()))
print(min(a+b,a-b.a*b))

Fixed submission:
a,b = map(int,(input().split()))
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = []
for i in range(2,35):
    for j in range(2,11):
        if i**j <= N:
            ans.append(i**j)
print(max(ans))


Fixed submission:
N = int(input())
ans = []
for i in range(1,35):
    for j in range(2,11):
        if i**j <= N:
            ans.append(i**j)
print(max(ans))
Buggy python submission (verdict: Runtime Error):
H,W,D = map(int,(input().split()))

A = [[] for _ in range(H)]
for i in range(H):
    A[i] = list(map(int,(input().split())))

d = {}
for i in range(H):
    for j in range(W):
        d[A[i][j]] = (i,j)

m = [0]*(H*W)
for i in range(1,H*W):
    if i+D <= H*W:
        m[i] = abs(d[i][0] - d[i+D][0]) + abs(d[i][1] - d[i+D][1])
s = [[] for _ in range(D+1)]
for i in range(1,D+1):
    cost = 0
    for j in range(i,H*W-D+1,D):
        cost += abs(d[j][0] - d[j+D][0]) + abs(d[j][1] - d[j+D][1])
        s[i].append(cost)

Q = int(input())
for i in range(Q):
    L,R = map(int,(input().split()))
    r = L%D
    if r == 0:
        r = D
    ans = s[r][(R-1)//D-1]-s[r][(L-1)//D-1]
    print(ans)

Fixed submission:
H,W,D = map(int,(input().split()))

A = [[] for _ in range(H)]
for i in range(H):
    A[i] = list(map(int,(input().split())))

d = {}
for i in range(H):
    for j in range(W):
        d[A[i][j]] = (i,j)

s = [[] for _ in range(D+1)]
for i in range(1,D+1):
    cost = 0
    s[i].append(0)
    for j in range(i,H*W-D+1,D):
        cost += abs(d[j][0] - d[j+D][0]) + abs(d[j][1] - d[j+D][1])
        s[i].append(cost)

Q = int(input())
for i in range(Q):
    L,R = map(int,(input().split()))
    r = L%D
    if r == 0:
        r = D
    ans = s[r][(R-r)//D]-s[r][(L-r)//D]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,(input().split()))

A = [[] for _ in range(H)]
for i in range(H):
    A[i] = list(map(int,(input().split())))

d = {}
for i in range(H):
    for j in range(W):
        d[A[i][j]] = (i,j)

m = [0]*(H*W)
for i in range(1,H*W):
    if i+D <= H*W:
        m[i] = abs(d[i][0] - d[i+D][0]) + abs(d[i][1] - d[i+D][1])

Q = int(input())
for i in range(Q):
    L,R = map(int,(input().split()))
    ans = 0
    for j in range(L,R,D):
        ans += m[j]
    print(ans)

Fixed submission:
H,W,D = map(int,(input().split()))

A = [[] for _ in range(H)]
for i in range(H):
    A[i] = list(map(int,(input().split())))

d = {}
for i in range(H):
    for j in range(W):
        d[A[i][j]] = (i,j)

s = [[] for _ in range(D+1)]
for i in range(1,D+1):
    cost = 0
    s[i].append(0)
    for j in range(i,H*W-D+1,D):
        cost += abs(d[j][0] - d[j+D][0]) + abs(d[j][1] - d[j+D][1])
        s[i].append(cost)

Q = int(input())
for i in range(Q):
    L,R = map(int,(input().split()))
    r = L%D
    if r == 0:
        r = D
    ans = s[r][(R-r)//D]-s[r][(L-r)//D]
    print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)

if 0 in A:
    print(0)
    exit()

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

T = [0]
W = []
for k in d.keys():
    if d[k] >= 2:
        T.append(k)
        T.append(24-k)
    else:
        W.append(k)
#print(T,W)

ans = []

w = len(W)
K = 2 # 選択肢の数
for i in range(K**w):
    TF=[0]*w

    for j in range(w):
        TF[w-j-1] = i % K
        i //= K
    
    l = copy.deepcopy(T)
    for j in range(w):
        if TF[j] == 1:
            l.append(24-W[j])
        else:
            l.append(W[j])
    
    l.sort()
    m = 24
    for j in range(1,N+1):
        m = min(m,l[j] - l[j-1])
    ans.append(m)

print(max(ans))

Fixed submission:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)

if 0 in A:
    print(0)
    exit()

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

T = [0]
W = []
for k in d.keys():
    if d[k] > 2:
        print(0)
        exit()
    if d[k] == 2:
        T.append(k)
        T.append(24-k)
    else:
        W.append(k)
#print(T,W)

ans = []

w = len(W)
K = 2 # 選択肢の数
for i in range(K**w):
    TF=[0]*w

    for j in range(w):
        TF[w-j-1] = i % K
        i //= K
    
    l = copy.deepcopy(T)
    for j in range(w):
        if TF[j] == 1:
            l.append(24-W[j])
        else:
            l.append(W[j])
            
    l.sort()
    l.append(24)
    #print(l)
    m = 24
    for j in range(1,len(l)):
        m = min(m,l[j] - l[j-1])
    ans.append(m)

print(max(ans))
Buggy python submission (verdict: Runtime Error):
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = S.copy()
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

a = []
if exist == 1: 
    L = len(l)
    for i in range(L):
        tmp = l[i].copy()
        for j in range(N):
            if tmp[j] == "?":
                tmp[j] = "a"
        a.append(tmp)
    a.sort()
    ans = "".join(a[0])
    print(ans)
else:
    print("UNRESTORABLE")

Fixed submission:
from copy import copy
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = copy(S)
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

a = []
if exist == 1: 
    L = len(l)
    for i in range(L):
        tmp = copy(l[i])
        for j in range(N):
            if tmp[j] == "?":
                tmp[j] = "a"
        a.append(tmp)
    a.sort()
    ans = "".join(a[0])
    print(ans)
else:
    print("UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        if (4*a*b) - N*(a+b) != 0:
            r = (N*a*b) % ( (4*a*b) - N*(a+b) )
            if r == 0:
                c = (N*a*b) // ( (4*a*b) - N*(a+b) )
                if c > 0:
                    break
    else:
        continue
    break
print(a,b,c)

Fixed submission:
N = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        if (4*a*b) - N*(a+b) != 0:
            r = (N*a*b) % ( (4*a*b) - N*(a+b) )
            if r == 0:
                c = (N*a*b) // ( (4*a*b) - N*(a+b) )
                if c > 0:
                    break
    else:
        continue
    break
print(a,b,c)