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

Fixed submission:
from collections import defaultdict
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

if N == 1:
    print(1)
else:
    d = defaultdict(int)
    for i, pp1 in enumerate(p):
        for j in range(i + 1, N):
            pp2 = p[j]
            d[(pp1[0] - pp2[0], pp1[1] - pp2[1])] += 1
        # print(d)

    cnt = 0
    keys = tuple(d.keys())
    for k in keys:
        x, y = k
        cnt = max(cnt, d[k] + d[(-x, -y)])

    print(N - cnt)

Buggy submission (verdict: Runtime Error):
def main():
    from collections import Counter, namedtuple

    pt = namedtuple('pt', 'x y')

    def delta(a: pt, b: pt) -> pt:
        x = a.x - b.x
        y = a.y - b.y
        if x < 0:
            x = -x
            y = -y
        return pt(x=x, y=y)

    n = int(input())
    ps = [pt(*map(int, input().split())) for _ in range(n)]

    c = Counter(
        delta(a, b)
        for i, a in enumerate(ps)
        for j, b in enumerate(ps)
        if i < j
    )

    ma = max(c.values())

    print(n - ma)


if __name__ == '__main__':
    main()

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

N = int(input())

p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))

d = []
for i, p1 in enumerate(p):
    for j, p2 in enumerate(p):
        if i == j:
            continue
        x = p1[0] - p2[0]
        y = p1[1] - p2[1]
        d.append((x, y))

c = Counter(d)
# print(c)
print(N - c.most_common()[0][1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

d = []
for i, pp1 in enumerate(p):
    for j in range(i + 1, N):
        pp2 = p[j]
        d.append((pp1[0] - pp2[0], pp1[1] - pp2[1]))

c = Counter(d)

print(N - c.most_common()[0][1])
Problem p03040 (python)

Fixed submission:
from heapq import heappush, heappop

Q = int(input())

update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
    # print(f'al:{al}, sl:{sl}')
    # print(f'ar:{ar},sr:{sr}')
    # print(f'b:{b}')
    # print()
    s = tuple(map(int, input().split()))
    if s[0] == 1:
        # 更新クエリ
        b += s[2]
        if update_count % 2 == 0:
            # 左に追加
            heappush(ar, s[1])  # 右に追加
            sr += s[1]
            x = heappop(ar)  # 右の最小値
            sr -= x
            heappush(al, -x)  # 左に追加
            sl += x
        else:
            # 右に追加
            heappush(al, -s[1])  # 左に追加
            sl += s[1]
            x = heappop(al)  # 左の最小値
            sl -= (-x)
            heappush(ar, -x)  # 右に追加
            sr += (-x)
        update_count += 1
        # 左キューalの最大値が中央値になっている
        # 左キューにheappushする際,負値に変換したので,heappopで最大値*(-1)が求まる
    else:
        # 求値クエリ
        x = heappop(al)  # 中央値
        heappush(al, x)
        x *= (-1)
        cnt_l = (update_count + 1) // 2
        cnt_r = update_count - cnt_l
        print(x, (cnt_l * x - sl) + (sr - cnt_r * x) + b)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappushpop

Q = int(input())

b = 0
la = []
sl = 0
ra = []
sr = 0

cnt = 0
for _ in range(Q):
    q = map(int, input().split())
    # print(la, ra)
    if q[0] == 2:
        # 求値
        x = -la[0]
        cl = (cnt + 1) // 2
        cr = cnt - cl
        print(x, (cl * x - sl) + (sr - cr * x) + b)
    else:
        # 更新
        b += q[2]
        cnt += 1
        if cnt % 2 == 1:
            sr += q[1]
            x = heappushpop(ra, q[1])
            sr -= x
            sl += x
            heappush(la, -x)
        else:
            sl += q[1]
            x = heappushpop(la, -q[1])
            x *= -1
            sl -= x
            sr += x
            heappush(ra, x)
Problem p03044 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 9)


class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)

    def find(self, x):  # xを含む木における根の頂点番号を返す
        if self.v[x] < 0:  # (負)は根
            return x
        else:  # 根の頂点番号
            self.v[x] = self.find(self.v[x])  # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
            return self.v[x]

    def unite(self, x, y):  # 違う根に属していたらrankが低くなるように連結
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  # size比較, 　(-1) * (連結頂点数 * (-1)), (正)同士の大小比較
            x, y = y, x  # 連結頂点数が少ない方をyにすると, findでの更新回数が減る？
        self.v[x] += self.v[y]  # 連結頂点数の和を取る, 連結頂点数 * (-1)
        self.v[y] = x  # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする

    def root(self, x):
        return self.v[x] < 0  # (負)は根

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 同じ根に属するか

    def size(self, x):
        return -self.v[self.find(x)]  # 連結頂点数を返す


N = int(input())
e = [[] for _ in range(N)]
uf = UnionFind(N)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    # 0-indexedに直した
    e[u].append((v, w))
    e[v].append((u, w))

    uf.same(u, v)

# e[点]:=(隣接頂点,長さ)

root = uf.find(0)
# 根

ans = [None] * N
ans[root] = 0

# print(e)


def rec(vv):
    for nv, w in e[vv]:
        if ans[nv] is not None: continue
        ans[nv] = (ans[vv] + w) % 2
        rec(nv)


rec(root)

print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
def dfs(v):
    for u, w in e[v]:
        if c[u] != -1:
            continue
        c[u] = (c[v] + w) % 2
        dfs(u)


n = int(input())
e = tuple(set() for _ in range(n))
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    e[u].add((v, w))
    e[v].add((u, w))

c = [-1] * n
c[0] = 0

dfs(0)

print(*c, sep='\n')
Problem p03046 (python)

Fixed submission:
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    t = 0
    for i in range(1, 2 ** M):
        if i == K: continue
        t ^= i
    if t == K:
        x = [i for i in range(0, 2 ** M) if i != K]
        ans = [K] + x + [K] + list(reversed(x))
        print(*ans)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    t = 0
    for i in range(1, 2 ** M):
        if i == K: continue
        t ^= i
    if t == K:
        x = [i for i in range(0, 2 ** M) if i != K]
        ans = [K] + x + [K] + reversed(x)
        print(*ans)
    else:
        print(-1)
Problem p03062 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))

sa = 0
min_v = float('inf')
minus_count = 0
for aa in a:
    if aa < 0:
        minus_count += 1
        aa = abs(aa)
    min_v = min(min_v, aa)
    sa += aa

if minus_count % 2 == 0:
    print(sa)
else:
    print(sa - min_v * 2)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n = int(input())
a = tuple(sorted(map(int, input().split())))
j = bisect_left(a, 0)

p = a[j:]
m = a[:j]

if len(m) % 2 == 0:
    print(sum(p) - sum(m))
else:
    print(sum(p[1:]) - sum(m[:-1]) + abs(p[0] + m[-1]))

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import inf

N = int(input())
a = map(int, input().split())

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値

for i, aa in enumerate(a, 0):
    dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
    dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print(dp[N][0])
Problem p03089 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 9)


def rec(arr, l, lst):
    # lstは操作の逆順
    # print(arr, l, lst[::-1])
    if l == 0:
        for p in lst[::-1]:
            print(p)
        exit()
        return

    for i in sorted(range(1, l + 1), reverse=True):
        # 1-indexed
        if arr[i-1] == i:
            # print(aa, '除去')
            # 最後に入れた数は、何番目と数の大きさが一致する
            rec(arr[:i - 1] + arr[i:], l - 1, lst + [i])
        elif arr[i-1] > i:
            # 何番目よりも数が大きい
            return
    return


N = int(input())
b = list(map(int, input().split()))

rec(b, N, [])

print(-1)

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

N = int(input())
b = list(map(int, input().split()))

# 最後に挿入した数字は
# k番目のkとなる

# 1 2 2 1 2 3 2
# 複数通り該当するときは
# 最後の数が該当する
# 0 0 3 0 0 6
# 3を取り除くと
# 0 0 0 0 6 -> 矛盾

ans = deque()

q = deque(enumerate(b, 1))
r = deque()

flg = False
while q:
    idx, bb = q.pop()
    # print(idx, bb, r)
    if idx == bb:
        ans.appendleft(bb)
        if len(ans) == N:
            flg = True
            break
        q = q + r
        r = deque()
    else:
        r.appendleft((idx - 1, bb))

if flg:
    for aa in ans:
        print(aa)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 9)


def rec(arr, l, lst):
    # lstは操作の逆順
    # print(arr, l, lst[::-1])
    if l == 0:
        for p in lst[::-1]:
            print(p)
        exit()
        return

    for i in sorted(range(1, l + 1), reverse=True):
        # 1-indexed
        if arr[i] == i:
            # print(aa, '除去')
            # 最後に入れた数は、何番目と数の大きさが一致する
            rec(arr[:i - 1] + arr[i:], l - 1, lst + [i])
        elif arr[i] > i:
            # 何番目よりも数が大きい
            return
    return


N = int(input())
b = list(map(int, input().split()))

rec(b, N, [])

print(-1)
Problem p03106 (python)

Fixed submission:
a, b, k = map(int, input().split())
cnt = 0
for i in sorted(range(1, 100 + 1), reverse=True):
    if a % i == 0 and b % i == 0:
        cnt += 1
        if cnt == k:
            print(i)
            exit()

Buggy submission (verdict: Runtime Error):
def main():
    from math import gcd

    A, B, K = map(int, input().split())

    g = gcd(A, B)
    rt = int(pow(g, 0.5))

    divisors = set()
    for d in range(1, rt + 1):
        if g % d == 0:
            divisors.add(d)
            divisors.add(g // d)

    ans = sorted(divisors, reverse=True)[K - 1]
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
Problem p03125 (python)

Fixed submission:
a,b=map(int,input().split())
if b%a==0:
  print(a+b)
else:
  print(b-a)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if b%a=0:
  print(a+b)
else:
  print(b-a)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if b % a = 0:
  print(a+b)
else:
  print(b-a)

Buggy submission (verdict: Runtime Error):
if b % a = 0:
  print(a+b)
else:
  print(b-a)
Problem p03138 (python)

Fixed submission:
from math import log2

N, K = map(int, input().split())
a = list(map(int, input().split()))
sa = sum(a)

if sa == 0:
    print(K * N)
    exit()

b = [0 for _ in range(int(log2(max(sa, K))) + 1)]
# b[2進数の位] = そのbitが立っているAiの数

ls = int(log2(sa))
# print(ls)

for aa in a:
    for i in range(ls + 1):
        # print(aa, aa >> i, i)
        if (aa >> i) & 1 == 1:
            # print('if')
            b[i] += 1
# print(b)

x = []
if K > 0:
    for i in range(int(log2(K)) + 1):
        t = N - 2 * b[i]
        if t > 0:
            x.append((1 << i, t * (1 << i)))
            # (立てるフラグ値、答えの増加量)

    x = sorted(x, key=lambda xx: xx[1], reverse=True)
# print(x)

sx = 0
st = 0
for xx in x:
    if sx + xx[0] <= K:
        sx += xx[0]
        st += xx[1]

ans = sa + st
print(ans)

Buggy submission (verdict: Runtime Error):
from math import log2

N, K = map(int, input().split())
a = list(map(int, input().split()))
sa = sum(a)

if sa == 0:
    print(K * N)
    exit()

b = [0 for _ in range(int(log2(sa)) + 1)]
# b[2進数の位] = そのbitが立っているAiの数

ls = int(log2(sa))
# print(ls)

for aa in a:
    for i in range(ls + 1):
        # print(aa, aa >> i, i)
        if (aa >> i) & 1 == 1:
            # print('if')
            b[i] += 1
# print(b)

x = []
if K > 0:
    for i in range(int(log2(K)) + 1):
        t = N - 2 * b[i]
        if t > 0:
            x.append((1 << i, t * (1 << i)))
            # (立てるフラグ値、答えの増加量)

    x = sorted(x, key=lambda xx: xx[1], reverse=True)
# print(x)

sx = 0
st = 0
for xx in x:
    if sx + xx[0] <= K:
        sx += xx[0]
        st += xx[1]

ans = sa + st
print(ans)

Buggy submission (verdict: Runtime Error):
from math import log2

N, K = map(int, input().split())
a = list(map(int, input().split()))
sa = sum(a)

b = [0 for _ in range(int(log2(sa)) + 1)]
# b[2進数の位] = そのbitが立っているAiの数

ls = int(log2(sa))
# print(ls)

for aa in a:
    for i in range(ls + 1):
        # print(aa, aa >> i, i)
        if (aa >> i) & 1 == 1:
            # print('if')
            b[i] += 1
# print(b)

x = []
if K > 0:
    for i in range(int(log2(K)) + 1):
        t = N - 2 * b[i]
        if t > 0:
            x.append((1 << i, t * (1 << i)))
            # (立てるフラグ値、答えの増加量)

    x = sorted(x, key=lambda xx: xx[1], reverse=True)
# print(x)

sx = 0
st = 0
for xx in x:
    if sx + xx[0] <= K:
        sx += xx[0]
        st += xx[1]

ans = sa + st
print(ans)
Problem p03150 (python)

Fixed submission:
import re

s = input()
t = 'keyence'

for i in range(len(t)):
    ptn = '^' + t[:i] + '.*' + t[i:] + '$'
    # print(ptn)
    m = re.match(ptn, s)
    if m: break

if m:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
s = input()
ls = len(s)

t = 'keyence'
idx = 0

for i in range(ls):
    if s[i] == t[idx]:
        idx += 1

if idx == len(t):
    print('YES')
else:
    print('NO')
Problem p03152 (python)

Fixed submission:
from bisect import bisect_left

MOD = 10 ** 9 + 7

N, M = map(int, input().split())

a = list(map(int, input().split()))
a = sorted(a)
la = len(a)
sa = set(a)
lsa = len(sa)
if la != lsa:
    print(0)
    exit()

b = list(map(int, input().split()))
b = sorted(b)
lb = len(b)
sb = set(b)
lsb = len(sb)
if lb != lsb:
    print(0)
    exit()

ans = 1
ai = 0
bi = 0
k = N * M
d = 0
while k > 0:
    ai = bisect_left(a, k)
    bi = bisect_left(b, k)
    
    if ai == la or bi == lb:
        print(0)
        exit()
        
    if a[ai] == k:
        ta = 1
        if b[bi] == k:
            tb = 1
            t = ta * tb
        else:
            tb = (lb - bi)
            t = ta * tb
    else:
        ta = (la - ai)
        if b[bi] == k:
            tb = 1
            t = ta * tb
        else:
            tb = (lb - bi)
            t = ta * tb - d

    # print(ta, tb)
    ans *= t

    ans %= MOD
    # print(ans)
    k -= 1
    d += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

MOD = 10 ** 9 + 7

N, M = map(int, input().split())

a = list(map(int, input().split()))
a = sorted(a)
la = len(a)
sa = set(a)
lsa = len(sa)
if la != lsa:
    print(0)
    exit()

b = list(map(int, input().split()))
b = sorted(b)
lb = len(b)
sb = set(b)
lsb = len(sb)
if lb != lsb:
    print(0)
    exit()

ans = 1
ai = 0
bi = 0
k = N * M
d = 0
while k > 0:
    ai = bisect_left(a, k)
    bi = bisect_left(b, k)

    if a[ai] == k:
        ta = 1
        if b[bi] == k:
            tb = 1
            t = ta * tb
        else:
            tb = (lb - bi)
            t = ta * tb
    else:
        ta = (la - ai)
        if b[bi] == k:
            tb = 1
            t = ta * tb
        else:
            tb = (lb - bi)
            t = ta * tb - d

    # print(ta, tb)
    ans *= t

    ans %= MOD
    # print(ans)
    k -= 1
    d += 1

print(ans)
Problem p03161 (python)

Fixed submission:
INF = 10 ** 10

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

dp = [INF for _ in range(N)]
dp[0] = 0
# 0-indexed

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

print(dp[N - 1])

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  int INF = pow(10, 9);

  vector<int> dp(N, INF);
  dp[0] = 0;
  
  for (int j = 1; j < N; j++) {
  	for (int i = max(0, j - K); i < j; i++) {
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
    }
  }
  cout << dp[N - 1] << endl;
}
Problem p03166 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 9)


def rec(v):
    if dp[v] != -1:
        return dp[v]

    res = 0
    for nv in g[v]:
        res = max(res, rec(nv) + 1)
    dp[v] = res
    return res


N, M = map(int, input().split())
g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1 for _ in range(N)]

ans = 0
for t in range(N):
    ans = max(ans, rec(t))
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    from functools import lru_cache
    import sys
    readline = sys.stdin.readline

    @lru_cache(maxsize=None)
    def dfs(v, par=-1):
        """最長有向パスに含まれる頂点数"""
        ret = 0
        for u in g[v]:
            if u == par: continue
            ret = max(ret, dfs(u, v))
        return ret + 1

    n, m = map(int, readline().split())

    g = tuple(set() for _ in range(n))
    for _ in range(m):
        x, y = (int(c) - 1 for c in input().split())
        g[x].add(y)

    ret = 0
    for i in range(n):
        ret = max(ret, dfs(i))
    print(ret - 1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def dfs(v):
    if d[v] != -1:
        return d[v]
    res = -1
    for u in e[v]:
        res = max(res, dfs(u))
    res += 1
    d[v] = res
    return res


n, m = map(int, input().split())
e = tuple(set() for _ in range(n))
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    e[x].add(y)

d = [-1] * n
res = -1
for v in range(n):
    res = max(res, dfs(v))
print(res)

Buggy submission (verdict: Runtime Error):
def rec(v):
    if dp[v] != -1: return dp[v]
    res = 0
    for nv in es[v]:
        res = max(res, rec(nv) + 1)
    dp[v] = res
    return res


N, M = map(int, input().split())
es = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    es[x].append(y)

dp = [-1] * N

res = 0
for v in range(N):
    res = max(res, rec(v))
print(res)

Buggy submission (verdict: Runtime Error):
def rec(vv):
    res = 0
    for nv in g[vv]:
        if p[nv] >= 0:
            res = max(res, p[nv] + 1)
        else:
            res = max(res, rec(nv) + 1)
    p[vv] = res
    return res


N, M = map(int, input().split())
g = [[] for _ in range(N)]
p = [-1 for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

ans = 0
for v in range(N):
    ans = max(ans, rec(v))
print(ans)
Problem p03171 (python)

Fixed submission:
n = int(input())
a = tuple(int(x) for x in input().split())

memo = tuple([None] * n for _ in range(n))
for i, aa in enumerate(a):
    memo[i][i] = aa

for l in range(n - 1, -1, -1):
    for r in range(l, n):
        if memo[l][r] is None:
            memo[l][r] = max(a[r] - memo[l][r - 1], a[l] - memo[l + 1][r])

print(memo[0][n - 1])

Buggy submission (verdict: Runtime Error):
def func(l, r, taro_turn):
    # [l,r]
    # return taro - jiro
    if l > r:
        return 0

    if taro_turn is None:
        # jiro_turn
        return min(func(l, r - 1, True) - a[r], func(l + 1, r, True) - a[l])
    else:
        # taro_turn
        return max(func(l, r - 1, None) + a[r], func(l + 1, r, None) + a[l])


n = int(input())
a = tuple(int(x) for x in input().split())

print(func(0, n - 1, True))
Problem p03219 (python)

Fixed submission:
x, y =map(int, input().split())
print(x + y // 2)

Buggy submission (verdict: Runtime Error):
x, y = map(int, input.split())
print(x + y // 2)
Problem p03230 (python)

Fixed submission:
n = int(input())

k = int((n * 2) ** 0.5) + 1
if k * (k - 1) != 2 * n:
    print('No')
else:
    print('Yes')
    print(k)
    arr = [list() for _ in range(k)]

    num = 1
    tar1, tar2 = 0, 1
    while True:
        arr[tar1].append(num)
        arr[tar2].append(num)
        if num == n:
            break
        else:
            num += 1
        if len(arr[tar1]) == k - 1:
            tar1 += 1
            tar2 = tar1 + 1
        else:
            tar2 += 1
    for i in range(k):
        print(k - 1, *arr[i])

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    from decimal import Decimal, getcontext

    getcontext().prec = 1000

    N = int(input())

    # {1,...,N}*2を分割
    # k個の集合があって
    # 各集合は他のk-1個の集合に対し共通要素を1個ずつ合わせてk-1個の要素をもつ

    sq = Decimal(N * 8 + 1).sqrt()
    cond = sq % 2 == 1  # 奇数か

    if not cond:
        print('No')
        return
    k = int((1 + sq) // 2)  # Decimalのままだとrangeの引数に使えない
    print('Yes')
    print(k)

    deqs = []
    it = iter(range(1, N + 1))
    for _ in range(k):
        print(k - 1, end=' ')
        t = []
        for deq in deqs:
            x = deq.popleft()
            t.append(x)
        u = []
        for _ in range(k - 1 - len(t)):
            x = next(it)
            u.append(x)
        print(*t, *u)
        deqs.append(deque(u))


if __name__ == '__main__':
    main()
Problem p03231 (python)

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


def lcm(x, y):
    return (x * y) // gcd(x, y)


n, m = map(int, input().split())
s = input()
t = input()

l = lcm(n, m)
g = gcd(n, m)

ng = n // g
mg = m // g
k = 0
flg = True
while True:
    if k * ng >= n or k * mg >= m:
        break
    if s[k * ng] != t[k * mg]:
        flg = False
        break
    k += 1

if flg:
    print(l)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from math import gcd


def lcm(x, y):
    return (x * y) // gcd(x, y)


n, m = map(int, input().split())
s = input()
t = input()

l = lcm(n, m)
g = gcd(n, m)

ng = n // g
mg = m // g
k = 0
flg = True
while True:
    if k * ng >= n or k * mg >= m:
        break
    if s[k * ng] != t[k * mg]:
        flg = False
        break
    k += 1

if flg:
    print(l)
else:
    print(-1)