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

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

for i in range(5):
  ra.append(a[i]%10)

tot=0
for i in range(5):
  if ra[i]==0:
    tot+=a[i]

  else:
    tot+=a[i]+10-ra[i]
    

ra.sort()
for i in range(5):
  if ra[i]==0:
    continue
  else:
    tot-=10-ra[i]
    break
print(tot)

Buggy submission (verdict: Runtime Error):
a=[]
ra=[]
for i in range(5):
  a.append(int(input()))

for i in range(5):
  ra.append(a[i]%10)

rmin=10
mi=10
for i in range(5):
  if ra[i]!=0 and ra[i]<rmin:
    rmin=ra[i]
    mi=i
    
mintime=0
for i in range(5):
  if ra[i]==0:
    mintime+=a[i]
  else:
    mintime+=a[i]+10-ra[i]
mintime-=10-ra[mi]
print(mintime)
Problem p03106 (python)

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

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)

if a==1 and b==1:
  print(1)
else:
  for i in range(1,g):
    if g%i==0:
      l.append(i)
  l.append(g)
  print(l[(-1)*k])

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)
q=g
i=1

if a==1 and b==1:
  print(1)
else:
  for i in range(1,int(g/2)+1):
   
    if q%i==0:
      if int(g/i)==i:
        l.append(i)
      else:
        l.append(int(g/i))
        l.append(i)
  l.sort()
  l=set(l)
  l=list(l)
  print(l[(-1)*k])

Buggy submission (verdict: Runtime Error):
import math

a,b,k=map(int,input().split())
l=[]
g=math.gcd(a,b)
q=g
i=1

if a==1 and b==1:
  print(1)
else:
  for i in range(1,int(g/2)+1):
   
    if q%i==0:
      if int(g/i)==i:
        l.append(i)
      else:
        l.append(int(g/i))
        l.append(i)
  l.sort()
  l=set(l)
  l=list(l)
  print(l[(-1)*k])
Problem p03220 (python)

Fixed submission:
n=int(input())
t,a=map(int,input().split())

h=list(map(int,input().split()))

min=1000
for i in range(n):
  temp=abs(a-t+0.006*h[i])
  if min>temp:
    min=temp
    id=i
print(id+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().split())

h=[int(input()) for i in range(n)]

min=1000
for i in range(n):
  temp=abs(t-0.006*h[i]-a)
  if min>temp:
    min=temp
    id=i
print(id+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().split())

h=[int(input()) for i in range(n)]

min=1000
for i in range(n):
  temp=abs(t-0.006*h[i]-a)
  print(temp)
  if min>temp:
    min=temp
    id=i
print(i+1)
Problem p03231 (python)

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

n,m=map(int,input().split())
s=input()
t=input()
cnt=1
i=0
flag=0

l=int(n*m/gcd(n,m))

r=l/m

while cnt<n:
  if s[int(i*l/m)]==t[int(i*l/n)]:
    flag=1
    cnt+=r
    i+=1
  else:
    flag=0
    break

if flag==1:
  print(l)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
s=input()
t=input()
cnt=1
i=0
flag=0

l=int(n*m/math.gcd(n,m))

r=l/m

while cnt<n:
  if s[int(i*l/m)]==t[int(i*l/n)]:
    flag=1
    cnt+=r
    i+=1
  else:
    flag=0
    break

if flag==1:
  print(l)
else:
  print(-1)
Problem p03241 (python)

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

ans=0

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(1,a):
    if m%i==0:
      if i*n<=m:
        ans=max(ans,i)
      if (m//i)*n<=m:
        ans=max(ans,m//i)
  print(ans)

Buggy submission (verdict: Runtime Error):
vn,m=map(int,input().split())

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(a+1,0,-1):
    if m%i==0 and i*n<=m:
      print(i)
      break
Problem p03262 (python)

Fixed submission:
import fractions

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=fractions.gcd(gcm,y[i])
  print(gcm)

Buggy submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=y[0]
  for i in range(n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)

Buggy submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  for i in range(n):
    if i<2:
      gcm=math.gcd(y[0],y[1])
    else:
      gcm=math.gcd(gcm,y[i])
  print(gcm)

Buggy submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]
y=[]
z=list(map(int, input().split()))

for i in range(n):
  y.append(abs(x-z[i]))

if n==1:
  print(y[0])
else:
  gcm=math.gcd(y[0],y[1])
  for i in range(2,n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)

Buggy submission (verdict: Runtime Error):
import math

n,x=map(int,input().split())
z=[]

y=[]
z=list(map(int, input().split()))
z.append(x)
z.sort()

for i in range(n):
  y.append(z[i+1]-z[i])

if n==1:
  print(y[0])
else:
  gcm=math.gcd(y[0],y[1])
  for i in range(2,n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)

Buggy submission (verdict: Runtime Error):
import functools
import math

n,x=map(int,input().split())
z=[]

y=[]
z=list(map(int, input().split()))
z.append(x)

z.sort()
for i in range(n):
  y.append(z[i+1]-z[i])
  
gcd = functools.reduce(math.gcd, y)
print(gcd)
Problem p02573 (python)

Fixed submission:
"""
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
size = [1 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if not same(a - 1, b - 1):
        unite(a - 1, b - 1)
x = [0] * n
ans = 0
for i in range(n):
    j = get_root(i)
    x[j] += 1
    ans = max(ans, x[j])
print(ans)
"""

from collections import deque

def bfs(s):
    q = deque()
    q.append(s)
    visit[s] = 1
    cnt = 1
    while q:
        p = q.popleft()
        for j in G[p]:
            if visit[j] == 0:
                q.append(j)
                visit[j] = 1
                cnt += 1
    global ans
    ans = max(ans, cnt)
    return

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
visit = [0] * (n + 1)
ans = 0
for i in range(1, n + 1):
    if visit[i] == 0:
        bfs(i)
print(ans)

Buggy submission (verdict: Runtime Error):
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
size = [1 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if not same(a - 1, b - 1):
        unite(a - 1, b - 1)
x = [0] * n
ans = 0
for i in range(n):
    j = get_root(i)
    x[j] += 1
    ans = max(ans, x[j])
print(ans)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = list(input())
y = x.count("1")
s, t = y - 1, y + 1
p = [1] * 20
for i in range(1, 20):
    p[i] = p[i - 1] * 2
p.sort(reverse = True)
a, b, u, v = 1 / 2, 1 / 2, 0, 0
m1, m2 = [0] * n, [0] * n
if not s == 0:
    for i in range(1, n + 1):
        a += a
        a %= s
        b += b
        b %= t
        m1[i - 1] = a
        m2[i - 1] = b
        if x[-i] == "1":
            u += a
            v += b
else:
    for i in range(1, n + 1):
        b += b
        b %= t
        m2[i - 1] = b
        if x[-i] == "1":
            v += b
ans = [1] * n
if not s == 0:
    for i in range(1, n + 1):
        if x[-i] == "1":
            j = (u - m1[i - 1]) % s
        else:
            j = (v + m2[i - 1]) % t
        if not j == 0:
            while not j == 0:
                ans[-i] += 1
                l = j
                cnt = 0
                for k in p:
                    if l == 0:
                        break
                    if k <= l:
                        cnt += 1
                        l -= k
                j = j % cnt
else:
    for i in range(1, n + 1):
        if x[-i] == "1":
            ans[-i] = 0
        else:
            j = (v + m2[i - 1]) % t
            if not j == 0:
                while not j == 0:
                    ans[-i] += 1
                    l = j
                    cnt = 0
                    for k in p:
                        if l == 0:
                            break
                        if k <= l:
                            cnt += 1
                            l -= k
                    j = j % cnt
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(input())
y = x.count("1")
s, t = y - 1, y + 1
p = [1] * 20
for i in range(1, 20):
    p[i] = p[i - 1] * 2
p.sort(reverse = True)
a, b, u, v = 1 / 2, 1 / 2, 0, 0
m1, m2 = [0] * n, [0] * n
for i in range(1, n + 1):
    a += a
    a %= s
    b += b
    b %= t
    m1[i - 1] = a
    m2[i - 1] = b
    if x[-i] == "1":
        u += a
        v += b
ans = [1] * n
for i in range(1, n + 1):
    if x[-i] == "1":
        j = (u - m1[i - 1]) % s
    else:
        j = (v + m2[i - 1]) % t
    if not j == 0:
        while not j == 0:
            ans[-i] += 1
            l = j
            cnt = 0
            for k in p:
                if l == 0:
                    break
                if k <= l:
                    cnt += 1
                    l -= k
            j = j % cnt
for i in ans:
    print(i)
Problem p02720 (python)

Fixed submission:
from collections import deque

k = int(input())
q = deque()
for i in range(1, 10):
    q.append(i)
for _ in range(k):
    p = q.popleft()
    r = p % 10
    if r != 0:
        q.append(10 * p + r - 1)
    q.append(10 * p + r)
    if r != 9:
        q.append(10 * p + r + 1)
print(p)

Buggy submission (verdict: Runtime Error):
def f(i):
    global ans
    if i == n:
        u = [0] * n
        for j in range(1, 10):
            u[0] = j
            for l in range(1, n):
                if s[l] == 0:
                    if u[l - 1] - 1 >= 0:
                        u[l] = u[l - 1] - 1
                    else:
                        return
                elif s[l] == 2:
                    if u[l - 1] + 1 <= 9:
                        u[l] = u[l - 1] + 1
                    else:
                        return
                else:
                    u[l] = u[l - 1]
            v = "".join(map(str, u))
            ans.append(int(v))
        return
    f(i + 1)
    s[i] = 2
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0

k = int(input())
dp = [[0] * 12 for _ in range(11)]
for i in range(1, 11):
    dp[i - 1][0], dp[i - 1][11] = 0, 0
    for j in range(1, 11):
        if i == 1 and j >= 2:
            dp[i][j] = 1
        else:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1]
t = 0
for i in range(1, 11):
    t += sum(dp[i])
    m = t - sum(dp[i])
    if k <= t:
        n = i
        break

ans = []
s = [0] * n
f(0)
ans = list(set(ans))
ans.sort()

print(ans[k - m - 1])
Problem p02804 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
a.sort()
b = 1
ans = 0
for i in range(k - 1, n):
    ans += b * (a[i] - a[n - i - 1])
    ans %= mod
    b = (i + 1) * b
    c = i + 1 - (k - 1)
    b = pow(c, mod - 2, mod) * b % mod
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
a.sort()
b = 1
ans = 0
for i in range(k - 1, n):
    ans += b * a[i]
    ans -= b * a[n - i - 1]
    ans %= mod
    b *= (i + 1) / (i + 1 - (k - 1))
    b = int(b)
print(ans)
Problem p03106 (python)

Fixed submission:
a, b, k = map(int, input().split())
c = []
for i in range(min(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        c.append(i)
print(c[k - 1])

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
c = 0
for i in range(min(a, b), 1, -1):
    if a % i == 0 and b % i == 0:
        c += 1
    if c == k:
        ans = i
        break
print(ans)
Problem p03148 (python)

Fixed submission:
import heapq

n, k = map(int, input().split())
a = [0] * (n + 1)
typecnt = 0
h = []
heapq.heapify(h)
for _ in range(n):
    t, d = map(int, input().split())
    if a[t] == 0:
        typecnt += 1
        a[t] = 1
    heapq.heappush(h, [-d, t])
ans = 0
mintype = 0
m = []
heapq.heapify(m)
for _ in range(k):
    d, t = heapq.heappop(h)
    if a[t] == 1:
        mintype += 1
        a[t] = 0
    else:
        heapq.heappush(m, -d)
    ans -= d
cnt = ans
ans += mintype * mintype
for j in range(mintype, typecnt):
    if not m:
        break
    bonus = (j + 1) * (j + 1)
    while h:
        d, t = heapq.heappop(h)
        if not m:
            break
        if a[t] == 1:
            a[t] = 0
            l = heapq.heappop(m)
            cnt -= (d + l)
            ans = max(ans, cnt + bonus)
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

n, k = map(int, input().split())
a = [0] * (n + 1)
typecnt = 0
h = []
heapq.heapify(h)
for _ in range(n):
    t, d = map(int, input().split())
    if a[t] == 0:
        typecnt += 1
        a[t] = 1
    heapq.heappush(h, [-d, t])
ans = 0
mintype = 0
m = []
heapq.heapify(m)
for _ in range(k):
    d, t = heapq.heappop(h)
    if a[t] == 1:
        mintype += 1
        a[t] = 0
    else:
        heapq.heappush(m, -d)
    ans -= d
cnt = ans
ans += mintype * mintype
for j in range(mintype, typecnt):
    bonus = (j + 1) * (j + 1)
    while h:
        d, t = heapq.heappop(h)
        if a[t] == 1:
            a[t] = 0
            l = heapq.heappop(m)
            cnt -= (d + l)
            ans = max(ans, cnt + bonus)
            break
print(ans)
Problem p03240 (python)

Fixed submission:
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
s = [list(map(int, input().split())) for _ in range(n)]
for i in range(101):
    for j in range(101):
        h = -1
        ok = 1
        for t in s:
            if t[2] == 0:
                ok += 1
            elif h == -1:
                h = abs(t[0] - i) + abs(t[1] - j) + t[2]
            else:
                h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                if h == h0:
                    ok += 1
        if ok == n:
            for t in s:
                if abs(t[0] - i) + abs(t[1] - j) <= h:
                    if not h == abs(t[0] - i) + abs(t[1] - j) + t[2]:
                        ok = 0
                else:
                    if not t[2] == 0:
                        ok = 0
            if ok == n:
                print(i, j, h)
                exit()

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
for _ in range(n):
    s = [list(map(int, input().split())) for _ in range(n)]
    for i in range(101):
        for j in range(101):
            h = -1
            ok = 1
            for t in s:
                if t[2] == 0:
                    ok += 1
                elif h == -1:
                    h = abs(t[0] - i) + abs(t[1] - j) + t[2]
                else:
                    h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                    if h == h0:
                        ok += 1
            if ok == n:
                ok = 0
                for t in s:
                    if h == abs(t[0] - i) + abs(t[1] - j) + t[2] or (t[2] == 0 and abs(t[0] - i) + abs(t[1] - j) <= h):
                        ok += 1
                if ok == n:
                    print(i, j, h)
                    exit()

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
for _ in range(n):
    s = [list(map(int, input().split())) for _ in range(n)]
    for i in range(101):
        for j in range(101):
            h = -1
            ok = 1
            for t in s:
                if h == -1:
                    h = abs(t[0] - i) + abs(t[1] - j) + t[2]
                else:
                    h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                    if h == h0:
                        ok += 1
            if ok == n:
                print(i, j, h)
                exit()

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
if not n == 1:
    for i in range(101):
        for j in range(101):
            c = s[0][2] + abs(i - s[0][0]) + abs(j - s[0][1])
            d = 0
            for k in range(1, n):
                if not abs(i - s[k][0]) + abs(j - s[k][1]) == c - s[k][2]:
                    d = 1
                    break
            if d == 0:
                ans = [i, j, c]
                break
else:
    ans = s[0]
print(" ".join(map(str, ans)))
Problem p03309 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n == 1:
    ans = 0
elif n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)
Problem p03340 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m, x, c = 0, 0, 0
j = 0
ans = 0
for i in range(n):
    m += a[i]
    x ^= a[i]
    c += 1
    if not m == x:
        while True:
            if m == x:
                break
            x ^= a[j]
            m -= a[j]
            j += 1
            c -= 1
    ans += c
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [[0] * 21 for _ in range(n)]
for i in range(n):
    j = 0
    k = 1
    while True:
        if a[i] == 0:
            break
        if (a[i] // k) % 2 == 1:
            b[i][j] = 1
            a[i] -= k
        k *= 2
        j += 1
ans = 0
for i in range(n):
    s = b[i]
    j = 1
    ans += 1
    while True:
        if i + j >= n or j >= 21:
            break
        for k in range(n):
            s[k] += b[i + j][k]
        if max(s) >= 2:
            break
        else:
            ans += 1
        j += 1
print(ans)
Problem p03450 (python)

Fixed submission:
from collections import deque

def bfs():
    visit = [0] * (n + 1)
    e = [0] * (m + 1)
    x = [0] * (n + 1)
    q = deque()
    for i in range(1, n + 1):
        if not visit[i]:
            q.append(i)
            visit[i] = 1
            while q:
                j = q.popleft()
                for g in G[j]:
                    if not e[g[2]]:
                        #print(e, visit, q, x, j)
                        e[g[2]] = 1
                        if not visit[g[0]]:
                            x[g[0]] = g[1] + x[j]
                            visit[g[0]] = 1
                            q.append(g[0])
                        else:
                            #print(x[g[0]], g[1] + x[j])
                            if not x[g[0]] == g[1] + x[j]:
                                return False
    return True

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for i in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d, i])
    G[r].append([l, -d, i])
print("Yes" if bfs() else "No")

Buggy submission (verdict: Runtime Error):
from collections import deque

def bfs(s):
    global dist, visit
    q = deque()
    q.append(s)
    dist[s] = 0
    visit[s] = s
    x = 0
    y = deque()
    while q:
        p = q.popleft()
        for g in G[p]:
            if dist[g[0]] == a:
                dist[g[0]] = dist[p] + g[1] + x
                y.append(dist[g[0]])
                visit[g[0]] = s
                q.append(g[0])
            else:
                if not dist[g[0]] == dist[p] + g[1] + x:
                    if visit[g[0]] == s:
                        print("No")
                        exit()
                    else:
                        if x == 0:
                            x = dist[g[0]] - (dist[p] + g[1])
                            while y:
                                z = y.popleft()
                                dist[z] += x
                        else:
                            print("No")
                            exit()
                    

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d])
a = -pow(10, 9)
dist = [a] * (n + 1)
visit = [0] * (n + 1)
for i in range(1, n + 1):
    if dist[i] == a:
        bfs(i)
print("Yes")
Problem p03565 (python)

Fixed submission:
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i < ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i <= ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")
Problem p03689 (python)

Fixed submission:
h, w, h0, w0 = map(int, input().split())
if h0 == w0 == 1:
    print("No")
    exit()
x, y = h // h0, w // w0
a1cnt = h0 * w0 - 1
a1sum, a2sum = h * w - x * y, x * y
a1 = ((pow(10, 9) - 1) // a1cnt)
a2 = -(a1 * a1cnt + 1)
asum = a1 * a1sum + a2 * a2sum
print("Yes" if asum > 0 else "No")
if asum > 0:
    for i in range(1, h + 1):
        a = [0] * w
        for j in range(1, w + 1):
            a[j - 1] = a2 if i % h0 == j % w0 == 0 else a1
        print(*a)

Buggy submission (verdict: Runtime Error):
h, w, h0, w0 = map(int, input().split())
x, y = h // h0, w // w0
a1cnt = h0 * w0 - 1
a1sum, a2sum = h * w - x * y, x * y
a1 = ((pow(10, 9) - 1) // a1cnt)
a2 = -(a1 * a1cnt + 1)
asum = a1 * a1sum + a2 * a2sum
print("Yes" if asum > 0 else "No")
if asum > 0:
    for i in range(1, h + 1):
        a = [0] * w
        for j in range(1, w + 1):
            a[j - 1] = a2 if i % h0 == j % w0 == 0 else a1
        print(*a)