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

Fixed submission:
a, b, n = map(int, input().split())
ans1 = (a*min(n, b-1))//b
ans2 = a*(min(n, b-1)//b)
print(ans1-ans2)

Buggy submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
ans = 0
if b > n:
    ans = (a*n)//b
    print(ans)
else:
    c = n//b
    max_c = [0]*(c+1)
    for i in range(1, c):
        max_c[i] = (a * (b*(i+1) - 1))//b - i
    max_c[c] = (a*n)//b - c
    print(max(max_c))

Buggy submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
ans = 0
if b > n:
    ans = (a*n)//b
else:
    c = n//b
    max_c = [0]*(c+1)
    for i in range(1, c):
        max_c[i] = (a * (b*(i+1) - 1))//b - i
    max_c[c] = (a*n)//b - c
    print(max(max_c))

Buggy submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
ans = 0
if b > n:
    ans = (a*n)//b
else:
    c = n//b
    max_c = [0]*(c+1)
    for i in range(1, c+1):
        max_c[i] = (a * (b*(i+1) - 1))//b - i
    print(max(max_c))
Problem p02720 (python)

Fixed submission:
from collections import deque
k = int(input())
q = deque([i for i in range(1, 10)])
if k <= 9:
    print(k)
    quit()

k -= 9

while k > 0:
    a = q.popleft()
    b = a % 10
    if b == 0:
        q.append(10*a)
        q.append(10*a + 1)
        k -= 2
    elif b != 0 and b != 9:
        q.append(10*a + b - 1)
        q.append(10*a + b)
        q.append(10*a + b + 1)
        k -= 3
    elif b == 9:
        q.append(10*a + b-1)
        q.append(10*a + b)
        k -= 2

if k == 0:
    print(q[-1])
elif k == -1:
    print(q[-2])
elif k == -2:
    print(q[-3])

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for _ in range(n)]
count = []
max_list = []

for item in s:
    count_i = s.count(item)
    count.append(count_i)

for i in range(n):
    if count[i] == max(count) and not (s[i] in max_list):
        max_list.append(s[i])

max_list = sorted(max_list)
for item in max_list:
    print(item)
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]

flag = True

if n == 1 and m == 0:
    print(0)
elif n == 1 and m != 0:
    if len(set(sc)) != 1:
        print(-1)
    else:
        print(sc[0][1])
        
        
elif n > 1 and m == 0:
    print(10**(n-1))
    
elif n > 1 and m != 0:
    for i in range(10**(n-1), 10**n):
        i_str = str(i)
        i_list = list(i_str)
        for item in set(sc):
            if i_list[item[0]-1] != str(item[1]):
                break
        else:
            print(i)
            flag = False
            break
    if flag:
        print(-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
ans =[0]*n
flag = False
for i in range(m):
    for j in range(m):
        if sc[i][0] == sc[j][0] and sc[i][1] != sc[j][1]:
            flag = True
            

for i in range(m):
    ans[sc[i][0]-1] = sc[i][1]

if flag or ans[0] == 0:
    print(-1)
else:
    print(ans[0]*100 + ans[1]*10 + ans[2])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
ans =[0]*n
flag = False
for i in range(m):
    for j in range(m):
        if sc[i][0] == sc[j][0] and sc[i][1] != sc[j][1]:
            flag = True
            break
    else:
        break

for i in range(m):
    ans[sc[i][0]-1] = sc[i][1]

if flag or ans[0] == 0:
    print(-1)
else:
    print(ans[0]*100 + ans[1]*10 + ans[2])
Problem p02765 (python)

Fixed submission:
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r+100*(10 - n))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def comb(n, r):
    res = 1
    for i in range(1, r+1):
        res = res*(n-i+1) % mod
        res = res*pow(i, mod-2, mod) % mod
    return res


ans = (pow(2, n, mod) - comb(n, a)) % mod - comb(n, b) % mod
print(ans)
Problem p02767 (python)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = []
total = 0
for p in range(min(x), max(x) + 1):
    for i in range(n):
        total += (x[i] - p)**2
    ans.append(total)
    total = 0
print(min(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
mid = int(sum(x)/n)
ans = []
total = 0
for p in range(x[0], x[n-1] + 1):
    for i in range(n):
        total += (x[i] - p)**2
    ans.append(total)
    total = 0
print(min(ans))
Problem p02801 (python)

Fixed submission:
a = input()
al = "abcdefjhijklmopqrstuvwxyz"
for i in range(24):
    if a == al[i]:
        print(al[i+1])

Buggy submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]


def bfs(i, j):  # 引数はスタートの位置(i, j)
    q = deque()
    q.append((i, j))
    log = [[-1] * w for _ in range(h)]
    log[i][j] = 0
    distance = 0
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]  # 右、上、左、下
    while q:
        p = q.popleft()
        for item in d:
            nx = p[0] + item[0]
            ny = p[1] + item[1]
            if not(0 <= nx < h and 0 <= ny < w):  # 迷路の外にはでれない
                continue
            elif s[nx][ny] == "#":  # 壁には進めない
                continue
            elif log[nx][ny] >= 0:  # 探索済みは探索しない
                continue
            else:
                log[nx][ny] = log[p[0]][p[1]] + 1
                q.append((nx, ny))
                if distance < log[nx][ny]:
                    distance = log[nx][ny]
    return distance


distance = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":  # start地点は壁でない
            continue
        else:
            temp = bfs(i, j)
            if temp >= distance:
                distance = temp
print(distance)
Problem p02803 (python)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]


def bfs(i, j):  # 引数はスタートの位置(i, j)
    q = deque()
    q.append((i, j))
    log = [[-1] * w for _ in range(h)]
    log[i][j] = 0
    distance = 0
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while q:
        p = q.popleft()
        for x, y in d:
            nx = p[0] + x
            ny = p[1] + y
            if not(0 <= nx < h and 0 <= ny < w):  # 迷路の外にはでれない
                continue
            elif s[nx][ny] == "#":  # 壁には進めない
                continue
            elif log[nx][ny] >= 0:  # 探索済みは探索しない
                continue
            else:
                log[nx][ny] = log[p[0]][p[1]] + 1
                q.append((nx, ny))
                if distance < log[nx][ny]:
                    distance = log[nx][ny]
    return distance


distance = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":  # start地点は壁でない
            continue
        else:
            temp = bfs(i, j)
            if temp >= distance:
                distance = temp
print(distance)

Buggy submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
s = [list(map(str, input().split())) for _ in range(h)]


def bfs(i, j):  # 引数はスタートの位置(i, j)
    q = deque()
    q.append((i, j))
    log = [[-1] * w for _ in range(h)]
    log[i][j] = 0
    distance = 0
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while q:
        p = q.popleft()
        for x, y in d:
            nx = p[0] + x
            ny = p[1] + y
            if not(0 <= nx < h and 0 <= ny < w):  # 迷路の外にはでれない
                continue
            elif s[nx][ny] == "#":  # 壁には進めない
                continue
            elif log[nx][ny] >= 0:  # 探索済みは探索しない
                continue
            else:
                log[nx][ny] = log[p[0]][p[1]] + 1
                q.append((nx, ny))
                if distance < log[nx][ny]:
                    distance = log[nx][ny]
    return distance


distance = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":  # start地点は壁でない
            continue
        else:
            temp = bfs(i, j)
            if temp >= distance:
                distance = temp
print(distance)
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 = input()

def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        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_algorythm(s[i:])
    for j, len in enumerate(LCP):
        tmp = min(len, j)
        ans = max(ans, tmp)
print(ans)
Problem p02913 (python)

Fixed submission:
N = int(input())
S = input()
ok, ng = 0, N + 1
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    check = set()
    for i in range(N - x + 1):
        check.add(S[i: i + x])
        if S[i + x: i + 2 * x] in check:
            ok = x
            break
    else:
        ng = x

print(ok)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    c = 0
    for i in range(1, n):
        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_algorythm(s[i:])
    for j, len in enumerate(LCP):
        tmp = min(len, j)
        ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

def z_algorythm(s):
    n = len(s)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0
    for i in range(1, n):
        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_algorythm(s[i:])
    for j, len in enumerate(LCP):
        tmp = min(len, j)
        ans = max(ans, tmp)
print(ans)
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
count = 0
for i in range(3):
    if s[i] == t[i]:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = (n-1)*n*0.5
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x
visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for c in edges[parent]:
        if visited[c] == 1:
            continue
        else:
            counter[c] += counter[parent]
            dfs(c)


dfs(0)
print(*counter)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] = x

visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for child in edges[parent]:
        if visited[child] == 1:
            continue
        else:
            counter[child] += counter[parent]
            dfs(child)


dfs(0)
print(*counter)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] = x

visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for child in edges[parent]:
        if visited[child] == 1:
            continue
        else:
            counter[child] += counter[parent]
            dfs(child)


dfs(0)
print(*counter)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    counter[p-1] = x

visited = [0]*n


def dfs(parent):
    visited[parent] = 1
    for child in edges[parent]:
        if visited[child] == 1:
            continue
        else:
            counter[child] += counter[parent]
            dfs(child)

        
dfs(0)
print(counter)
Problem p02937 (python)

Fixed submission:
from bisect import bisect_left, bisect_right
s = input()
t = input()
n_s = len(s)
n_t = len(t)


idx = [[] for _ in range(26)]
#print(ord("a"))
#print(ord("z"))

def a_idx(a):
    idx = ord(a)
    idx -= 97
    return idx


for i in range(n_s):
    idx[a_idx(s[i])].append(i)

t_syutugenkasyo = []
for i in range(n_t):
    t_syutugenkasyo.append(idx[a_idx(t[i])])
#print(t_syutugenkasyo)

now = -1
ans = 0
for i in range(n_t):
    if len(t_syutugenkasyo[i]) == 0:
        print(-1)
        exit()
    ni = bisect_right(t_syutugenkasyo[i], now)
    if ni >= len(t_syutugenkasyo[i]):
        ans += n_s
        now = -1
        ni = bisect_right(t_syutugenkasyo[i], now)
        now = t_syutugenkasyo[i][ni]
    else:
        now = t_syutugenkasyo[i][ni]
ans += now+1
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right
s = input()
t = input()
n_s = len(s)
n_t = len(t)

for i in range(n_t):
    if t[i] not in s:
        print(-1)
        exit()

idx = [[] for _ in range(26)]
#print(ord("a"))
#print(ord("z"))

def a_idx(a):
    idx = ord(a)
    idx -= 97
    return idx


for i in range(n_s):
    idx[a_idx(s[i])].append(i)

t_junnban = []
for i in range(n_t):
    t_junnban.append(idx[a_idx(t[i])])
print(t_junnban)

now = 0
ans = 0
for i in range(n_t):
    ni = bisect_right(t_junnban[i], now)
    if ni >= len(t_junnban[i]):
        now = 0
        ans += n_s
        ni = bisect_right(t_junnban[i], now)
        now = t_junnban[i][ni-1]
    else:
        now = t_junnban[i][ni]
ans += now+1
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
s = input()
t = input()
n_s = len(s)
n_t = len(t)

for i in range(n_t):
    if t[i] not in s:
        print(-1)
        exit()

idx = [[] for _ in range(26)]
#print(ord("a"))
#print(ord("z"))

def a_idx(a):
    idx = ord(a)
    idx -= 97
    return idx


for i in range(n_s):
    idx[a_idx(s[i])].append(i)

t_junnban = []
for i in range(n_t):
    t_junnban.append(idx[a_idx(t[i])])
print(t_junnban)

now = 0
ans = 0
for i in range(n_t):
    ni = bisect_left(t_junnban[i], now)
    if ni >= len(t_junnban[i]):
        now = 0
        ans += n_s
        ni = bisect_left(t_junnban[i], now)
        now = t_junnban[i][ni]
    else:
        now = t_junnban[i][ni]
ans += now+1
print(ans)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())
ans = b-a+1
lcm_cd = (c*d)//gcd(c, d)

under_a = (a-1)//c + (a-1)//d - (a-1)//lcm_cd
under_b = b//c + b//d - b//lcm_cd
print(ans-(under_b-under_a))

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b, c, d = map(int, input().split())
ans = b-a+1

amari_ac = a % c
amari_ad = a % d
if amari_ac == 0:
    c_min = a
else:
    c_min = a+c - amari_ac
if amari_ad == 0:
    d_min = a
else:
    d_min = a+d - amari_ad

amari_bc = b % c
amari_bd = b % d
c_max = b-amari_bc
d_max = b-amari_bd

c_count = (c_max-c_min)//c + 1
d_count = (d_max-c_min)//d + 1

lcm_cd = c*d // gcd(c, d)
amari_acd = a % lcm_cd
if amari_acd == 0:
    cd_min = a
else:
    cd_min = a+lcm_cd - amari_acd

amari_bcd = b % lcm_cd
cd_max = b - amari_bcd

cd_count = (cd_max-cd_min)//lcm_cd + 1

if cd_max < a or b < cd_max:
    cd_count = 0
if cd_min < a or cd_min > b:
    cd_count = 0

print(ans-c_count-d_count+cd_count)
Problem p03032 (python)

Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
min_nk = min(n, k)
for l in range(min_nk+1):
    for r in range(min_nk-l+1):
        hand = []
        for i in range(l):
            hand.append(v[i])
        for i in range(r):
            hand.append(v[n-1-i])
        hand.sort()
        
        for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
        ans = max(ans, sum(hand))
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
import heapq
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
min_nk = min(n, k)
for l in range(k+1):
    if k-l > 0:
        for r in range(k-l+1):
            hand = []
            for i in range(1, l+1):
                hand.append(v[i-1])
            for i in range(1, r+1):
                hand.append(v[n-i])
            hand.sort()
            if k-l-r > 0:
                for back in range(k-l-r):
                    if len(hand) != 0:
                        if min(hand) < 0:
                            x = hand.index(min(hand))
                            hand[x] = 0
                ans = max(ans, sum(hand))
print(ans)
Problem p03061 (python)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
gcd_l = a[0]
gcd_r = a[-1]
gcd_l_li = []
gcd_r_li = []
for i in range(n):
    gcd_l = gcd(gcd_l, a[i])
    gcd_l_li.append(gcd_l)
for i in range(n)[::-1]:
    gcd_r = gcd(gcd_r, a[i])
    gcd_r_li.append(gcd_r)
#print(gcd_l_li)
#print(gcd_r_li)

ans = max(gcd_r_li[n-2], gcd_l_li[n-2])  # かきかえる整数が右端のときと左端のとき
for target in range(1, n-1):
    ans = max(ans, gcd(gcd_l_li[target-1], gcd_r_li[n-2-target]))
print(ans)

Buggy submission (verdict: Runtime Error):
from　fractions import gcd
n = int(input())
a = list(map(int, input().split()))
gcd_l = a[0]
gcd_r = a[-1]
gcd_l_li = []
gcd_r_li = []
for i in range(n):
    gcd_l = gcd(gcd_l, a[i])
    gcd_l_li.append(gcd_l)
for i in range(n)[::-1]:
    gcd_r = gcd(gcd_r, a[i])
    gcd_r_li.append(gcd_r)
#print(gcd_l_li)
#print(gcd_r_li)

ans = max(gcd_r_li[n-2], gcd_l_li[n-2])  # かきかえる整数が右端のときと左端のとき
for target in range(1, n-1):
    ans = max(ans, gcd(gcd_l_li[target-1], gcd_r_li[target-1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))
gcd_l = a[0]
gcd_r = a[-1]
gcd_l_li = []
gcd_r_li = []
for i in range(n):
    gcd_l = math.gcd(gcd_l, a[i])
    gcd_l_li.append(gcd_l)
for i in range(n)[::-1]:
    gcd_r = math.gcd(gcd_r, a[i])
    gcd_r_li.append(gcd_r)
#print(gcd_l_li)
#print(gcd_r_li)

ans = max(gcd_r_li[n-2], gcd_l_li[n-2])  # かきかえる整数が右端のときと左端のとき
for target in range(1, n-1):
    ans = max(ans, math.gcd(gcd_l_li[target-1], gcd_r_li[target-1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)


def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass #sortされていない


li = divisor(max_a)
li.sort(reverse=True)
#print(li)
ans = 0
for i in li:
    gcd = []
    for j in range(n):
        gcd.append(math.gcd(i, a[j]))
    if gcd.count(i) >= n-1 and ans < i:
        ans = i
print(ans)
Problem p03161 (python)

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(n)]
dp[0] = 0

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

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(n)]
dp[0] = 0

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

print(dp(n-1))
Problem p03165 (python)

Fixed submission:
s = input()
t = input()
len_s = len(s)
len_t = len(t)
dp = [[0]*(len_t+1) for _ in range(len_s+1)]
# dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])

        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])
#print(dp)
ans = ""
while len_t > 0 and len_s > 0:
    if dp[len_s][len_t] == dp[len_s-1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t-1]:
        len_t -= 1
    else:
        ans += s[len_s-1]
        len_s -= 1
        len_t -= 1
print(ans[::-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
len_s = len(s)
len_t = len(t)
dp = [[0]*(len_t+1) for _ in range(len_s+1)]
# dp[i][j]はs[i],t[j]までで、最長の部分列の長さ
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])

        dp[i+1][i+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])
#print(dp)
ans = ""
while len_t>0 and len_s>0:
    if dp[len_s][len_t] == dp[len_s-1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t-1]:
        len_t -= 1
    else:
        ans += s[len_s-1]
        len_s -= 1
        len_t -= 1
print(ans[::-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
len_s = len(s)
len_t = len(t)
dp = [[0]*(len_t+1) for _ in range(len_s+1)]
# dp[i][j]はs[i],t[j]までで、最長の部分列の長さ
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i+1][i+1] = max(dp[i+1][j], dp[i][j+1])
#print(dp)
ans = ""
while len_t>0 and len_s>0:
    if dp[len_s][len_t] == dp[len_s-1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t-1]:
        len_t -= 1
    else:
        ans += s[len_s-1]
        len_s -= 1
        len_t -= 1
print(ans[::-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
len_s = len(s)
len_t = len(t)
dp = [[0]*(len_t+1) for _ in range(len_s+1)]
# dp[i][j]はs[i],t[j]までで、最長の部分列の長さ
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i+1][i+1] = max(dp[i+1][j], dp[i][j+1])
print(dp)
ans = ""
while len_t>0 and len_s>0:
    if dp[len_s][len_t] == dp[len_s-1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t-1]:
        len_t -= 1
    else:
        ans += s[len_s-1]
        len_s -= 1
        len_t -= 1
print(ans[::-1])
Problem p03262 (python)

Fixed submission:
from fractions import gcd
n, start = map(int, input().split())
x = list(map(int, input().split()))

x.append(start)
x.sort()

distance = []
for i in range(n):
    dis = abs(x[i+1] - x[i])
    distance.append(dis)
if len(distance) == 1:
    D = distance[0]
else:
    D = gcd(distance[0], distance[1])
    for i in range(2, n):
        D = gcd(D, distance[i])
print(D)

Buggy submission (verdict: Runtime Error):
from math import gcd
n, start = map(int, input().split())
x = list(map(int, input().split()))

x.append(start)
x.sort()

distance = []
for i in range(n):
    dis = abs(x[i+1] - x[i])
    distance.append(dis)
if len(distance) == 1:
    D = distance[0]
else:
    D = gcd(distance[0], distance[1])
    for i in range(2, n):
        D = gcd(D, distance[i])
print(D)