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

Fixed submission:
a,b,c=map(int,input().split())
print(len(set([a,b,c])))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(len(set(a,b,c)))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
n=[a,b,c]
if a!=b!=c:
  print(3)
elif a=b!=c or a!=b=c or b=a!=c:
  print(2)
else:
  print(1)
Problem p03997 (python)

Fixed submission:
a,b,c=[int(input()) for i in range(3)]
print(((a+b)*c)//2)

Buggy submission (verdict: Runtime Error):
a,b,c=[int(input()) for i range(3)]
print(((a+b)*c)/2)
Problem p04043 (python)

Fixed submission:
a,b,c=map(int,input().split())
n=[a,b,c]
m=len([i for i in n if i==5])
p=len([i for i in n if i==7])
if m==2 and p==1:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=sorted([input() for i in range(a)])
print(*n,sep='')
Problem p04044 (python)

Fixed submission:
a,b=map(int,input().split())
n=sorted([input() for i in range(a)])
print(*n,sep='')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=sorted([input() for i in range(a)])
print(*s,sep='')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=sorted([input() for i in range(b)])
print(*s,sep='')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=list([input() for i in range(b)])
for i in n:
    p=sorted(n)
    q=''.join(p)
print(q)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=list([str(input()) for i in range(b)])
for i in n:
    p=sorted(n)
    q=''.join(p)
print(q)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=list([str(input()) for i in range(b)])
p=sorted(n)
q=''.join(p)
print(q)
Problem p02582 (python)

Fixed submission:
ss = input().split('S')
m = 0
for li in ss:
  m = max(m,len(li))
  
print(m)

Buggy submission (verdict: Runtime Error):
# 入力
R, C, K = map(int, input().split())
point_map = [[0 for _ in range(C+1)] for _ in range(R+1)]
max_point = [[[0 for _ in range(4)] for _ in range(C + 1)]
             for _ in range(R + 1)]
maxmax_point = [[0 for _ in range(C + 1)] for _ in range(R + 1)]


for i in range(K):
    _r, _c, _k = map(int, input().split())
    point_map[_r][_c] = _k

for i in range(1, R+1):
    itemss = [[]]
    im = i-1
    for j in range(1, C + 1):
        jm = j - 1
        mxi = max_point[i]
        mxij = mxi[j]
        mxijm = mxi[jm]
        point = point_map[i][j]
        mxij[0] = max(
            mxijm[0], maxmax_point[im][j])
        if point == 0:
            mxij[1] = mxijm[1]
            mxij[2] = mxijm[2]
            mxij[3] = mxijm[3]
        else:
            itemss = [[]] + [items + [point]
                             for items in itemss]  # items[1] アイテム一つ
            itemss_len = len(itemss)
            #print(i, j, itemss)

            mxij[1] = max(
                mxijm[0] + point, maxmax_point[i - 1][j]+point)
            mxij[2] = mxijm[1] + point

            if itemss_len > 4:
                items = itemss[4]  # 4 こアイテムがあるやつ
                del_item = min(items)
                items.remove(del_item)
                sa = mxijm[3] - del_item
                #print("aaaaa", sa, mxijm[2])
                if sa > mxijm[2]:
                    mxij[3] = sa + point
                    itemss = itemss[:3] + [items]
                else:
                    mxij[3] = mxijm[2] + point
                    itemss = itemss[:4]
            else:
                mxij[3] = mxijm[2] + point

            #print(i, j, itemss)

        #[print(i, j, n, mxij[n])
        # for n in range(len(mxij))]
        maxmax_point[i][j] = max(mxij)
        #print(i, j, maxmax_point[i][j])

print(maxmax_point[R][C])
Problem p02639 (python)

Fixed submission:
l = list(map(int, input().split()))
for i in range(5):
  if not i+1 == l[i]:
    print(i+1)

Buggy submission (verdict: Runtime Error):
l = map(int, input().split())
for i in range(5):
  if not i+1 == l[i]:
    print(i+1)
Problem p02755 (python)

Fixed submission:
import math

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

c = math.ceil
min8, max8 = c(a*12.5), c((a+1)*12.5)
min10, max10 = c(b*10), c((b+1)*10)

l8, l10 = list(range(min8, max8)), list(range(min10, max10))
s8, s10 = set(l8), set(l10)

ss = s8 & s10
#print(min8, max8, min10, max10)
print(min(ss) if len(ss) >0 else -1)
#print(238*0.08)

Buggy submission (verdict: Runtime Error):
import math

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

f = math.floor
min8, max8 = f(a*12.5), f((a+1)*12.5)
min10, max10 = f(b*10), f((b+1)*10)

l8, l10 = list(range(min8, max8)), list(range(min10, max10))
s8, s10 = set(l8), set(l10)

ss = s8 & s10
print(min(ss))
Problem p03694 (python)

Fixed submission:
n = int(input())
A = [int(m) for m in input().split()]
print(max(A)-min(A))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(input().split())
print(max(A)-min(A))
Problem p04012 (python)

Fixed submission:
s = input()
di = {}
for c in s:
  di[c] = 0
for c in s:
  di[c] +=1
  
is_beautiful = True
for c in s:
  if di[c] %2 ==1:
    is_beautiful = False

print('Yes' if is_beautiful else 'No')

Buggy submission (verdict: Runtime Error):
s = input()
di = {}
for c in s:
  di[c] = 0
for c in s:
  di[c] +=1
  
is_beautiful = True
for c in s:
  if di[c] %2 ==1:
    is_beautiful = False

print('Yes' is is_beautiful else 'No')

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(m) for m in input().split()]
print(max(A)-min(A))
Problem p04029 (python)

Fixed submission:
a = input()
print a*(a+1)/2

Buggy submission (verdict: Runtime Error):
a = input()
print a*(a+1)/2
Problem p03356 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(i, g, visited):
  visited.add(i)
  for j in g[i]:
    if not (j in visited):
      dfs(j, g, visited)

def main():
  n, m = map(int, input().split())
  p = (list(map(int, input().split())))
  g = [[] for i in range(n + 1)]
  for i in range(m):
    x, y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
  seen = [False for i in range(n + 1)]
  ans = 0
  for i in range(1, n):
    if not seen[i]:
      visited = set()
      dfs(i, g, visited)
      for j in visited:
        seen[j] = True
        if p[j - 1] in visited:
          ans += 1
  print(ans)

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(100000)

def dfs(i, g, visited):
  visited.add(i)
  for j in g[i]:
    if not (j in visited):
      dfs(j, g, visited)

def main():
  n, m = map(int, input().split())
  p = (list(map(int, input().split())))
  g = [[] for i in range(n + 1)]
  for i in range(m):
    x, y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
  seen = [False for i in range(n + 1)]
  ans = 0
  for i in range(1, n):
    if not seen[i]:
      visited = set()
      dfs(i, g, visited)
      for j in visited:
        seen[j] = True
        if p[j - 1] in visited:
          ans += 1
  print(ans)

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def dfs(i, g, visited):
  visited.add(i)
  for j in g[i]:
    if not (j in visited):
      dfs(j, g, visited)

def main():
  n, m = map(int, input().split())
  p = (list(map(int, input().split())))
  g = [[] for i in range(n + 1)]
  for i in range(m):
    x, y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
  seen = [False for i in range(n + 1)]
  ans = 0
  for i in range(1, n):
    if not seen[i]:
      visited = set()
      dfs(i, g, visited)
      for j in visited:
        seen[j] = True
        if p[j - 1] in visited:
          ans += 1
  print(ans)

if __name__ == "__main__":
  main()
Problem p02817 (python)

Fixed submission:
a = input().split()
print(a[1] + a[0])

Buggy submission (verdict: Runtime Error):
a = input.split()
print(a[1] + a[0])

Buggy submission (verdict: Runtime Error):
a = input.split()
print(''.join(a))
Problem p02586 (python)

Fixed submission:
import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype=int)
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype=int))
    print(dp[-1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype=int)
    for RR in range(R):
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype=int))
    print(dp[-1])


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

Fixed submission:
n=int(input())
x=input()

xre = x[::-1]

cou = x.count('1')

if cou == 0:
    for _ in range(n):
        print(1)
    exit()

if cou == 1:
    for i in range(n):
        if i == n-1 and x[i] == '0':
            print(2)
        elif  x[i] == '0' and x[n-1] == '1':
            print(2)
        elif  x[i] == '0' and x[n-1] == '0':
            print(1)
        else:
            print(0)
    exit()

basepl = int(x, 2) % (cou+1)
basemi = int(x, 2) % (cou-1)

li = [0]*n
pl = 1
mi = 1


for i in range(n):
    if xre[i] == '0':
        li[i] = (basepl + pl)  % (cou+1)
    else:
        li[i] = (basemi - mi)  % (cou-1)
    mi = (mi * 2) % (cou-1)
    pl = (pl * 2) % (cou+1)

def f(n):
    m = n
    k = 1
    while m > 0:
        co = str(bin(m)).count('1')
        m = m % co
        k +=1
    return k


for x in li[::-1]:
    print(f(x))

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

xre = x[::-1]

cou = x.count('1')
basepl = int(x, 2) % (cou+1)
basemi = int(x, 2) % (cou-1)

li = [0]*n
pl = 1
mi = 1
for i in range(n):
    if xre[i] == '0':
        li[i] = (basepl + pl)  % (cou+1)
    else:
        li[i] = (basepl + mi)  % (cou-1)
    mi = (mi * 2)% (cou-1)
    pl = (pl * 2)% (cou+1)

def f(n):
    m = n
    k = 1
    while m > 0:
        co = str(bin(m)).count('1')
        m = m % co
        k +=1
    return k

for x in li[::-1]:
    print(f(x))
Problem p02639 (python)

Fixed submission:
a,b,c,d,e = map(int,input().split())

if a == 0:
    print(1)
if b == 0:
    print(2)
if c == 0:
    print(3)
if d == 0:
    print(4)
if e == 0:
    print(5)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(max(a))
Problem p02658 (python)

Fixed submission:
a = int(input())
b = list(map(int, input().split()))
c = 1

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

for n in b:
    c = c*n
    if c > 10**18:
        print(-1)
        exit()

print(c)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = list(map(int, input().split()))
c = 1

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

for n in b:
    c = c*n
    if c > 10**18:
        print(-1)
        exit()

print(c)
Problem p02576 (python)

Fixed submission:
N, X, T = map(int,input().split())
n = 0

if N % X == 0:
    n = N / X
else:
    n = N // X + 1

print(int(n * T))

Buggy submission (verdict: Runtime Error):
, X, T = map(int,input().split())
n = 0
total = 0

if N % X == 0:
    n = N / X
    total = n * T
else:
    n = N // X + 1
    total = n * T

print(int(total))
Problem p03493 (python)

Fixed submission:
s1s2s3 = input()

print(s1s2s3.count('1'))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
count = 0
K = True

while K:
    for i in range(N):
        if A[i] % 2 ==1:
            K = False
        A[i] / 2

    if not K:
            break
    count += 1

print(count)
Problem p03061 (python)

Fixed submission:
import fractions

N = int(input())
A = [int(a) for a in input().split(" ")]

firstgcds = [0]
lastgcds = [0]
for i in range(0, N):
    firstgcds.append(fractions.gcd(firstgcds[i], A[i]))
    lastgcds.append(fractions.gcd(lastgcds[i], A[-i-1]))
ans = 0
for i in range(0, N):
    preans = fractions.gcd(firstgcds[i], lastgcds[-i-2])
    if ans < preans:
        ans = preans
if ans < firstgcds[N-1]:
    ans = firstgcds[N-1]
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
A = [int(a) for a in input().split(" ")]

firstgcds = [0]
lastgcds = [0]
for i in range(0, N):
    firstgcds.append(math.gcd(firstgcds[i], A[i]))
    lastgcds.append(math.gcd(lastgcds[i], A[-i-1]))
ans = 0
for i in range(0, N):
    preans = math.gcd(firstgcds[i], lastgcds[-i-2])
    if ans < preans:
        ans = preans
if ans < firstgcds[N-1]:
    ans = firstgcds[N-1]
print(ans)
Problem p02553 (python)

Fixed submission:
a,b,c,d = map(int, input().split())
list = [a*c, a*d, b*c, b*d]
print(max(list))

Buggy submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

x = range(a,b+1)
y = range(c,d+1)

X = list(x)
Y = list(y)

max = X[0] * Y[0]

for i in range(1, len(X)):
	for j in range(1, len(Y)):
		if max < X[i] * Y[j]:
			max = X[i] * Y[j]
print(max)

Buggy submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

x = range(a,b+1)
y = range(c,d+1)

X = list(x)
Y = list(y)

max = X[0] * Y[0]

for i in range(1, len(X)):
	for j in range(1, len(Y)):
		if max < X[i] * Y[j]:
			max = X[i] * Y[j]
print(max)

Buggy submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

x = range(a,b+1)
y = range(c,d+1)

X = list(x)
Y = list(y)
MAX = max(X) * max(Y)
print(MAX)
Problem p02675 (python)

Fixed submission:
N = int(input())
X = (N%100)%10
if X == 3:
  print('bon')
elif X == 0 or X == 1 or X == 6 or X == 8:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
N = int(input())
X = (N%100)%10
if X == 3:
  print('bon')
elif X == 0 or X = 1 or X == 6 or X = 8:
  print('pon')
else:
  print('hon')
Problem p02681 (python)

Fixed submission:
S = input()
T = input()
if S == T[:-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

print(if S == T[:-1]'Yes' else 'No')
Problem p02553 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = max(a*c,b*d)
	if c>=0:
		answer = max(a*c,b*d,b*c)
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			else:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = a*c
	if c>=0:
		answer = a * c
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			elif:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)
Problem p02631 (python)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
b = a
S = 0
for i in range(N):
	S = S^a[i]

for i in range(N):
	b[i] = S^a[i]

print(*b)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
b = a
c= a[1]^a[2]
S = 0
for i in range(N):
	S = S^a[i]

for i in range(N):
	b[i] = S^a[i]

print(*b)
Problem p02700 (python)

Fixed submission:
A,B,C,D = list(map(int,input().split()))

while 1:
	C -= B
	if C<=0:
		print("Yes")
		break
	A -= D 
	if A<=0:
		print("No")
		break

Buggy submission (verdict: Runtime Error):
A,B,C,D = list(map(int,input().split()))

while 1:
	C -= B
	if C<=0
		print("Yes")
		break
	A -= D 
	if A<=0
		print("No")
		break
Problem p02772 (python)

Fixed submission:
N = input()
_list = input().split(" ")
_list = [int(a) for a in _list]
aspect = [a for a in _list if a % 2==0]
ans = []
for a in aspect:
    if a % 3 == 0 or a % 5 == 0:
        ans.append(True)
if len(aspect) ==len(ans):
    print("APPROVED")
else:
    print("DENIED")

Buggy submission (verdict: Runtime Error):
N = input()
_list = input().split(" ")
_list = [int(a) for a in _list]
aspect = [a for a in _list if a % 2==0]
ans = []
for a in even:
    if a % 3 == 0 or a % 5 == 0:
        ans.append(True)
if len(aspect) ==len(ans):
    print("APPROVED")
else:
    print("DENIED")
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

n, q = map(int, input().split())
edges = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p - 1] += x

ans = [0 for _ in range(n)]

visit = [False for _ in range(n)]
visit[0] = True

stack = []
stack.append((0, 0))

while stack:
    pos, val = stack.pop(-1)
    val += cnt[pos]
    ans[pos] = val
    for to in edges[pos]:
        if not visit[to]:
            visit[to] = True
            stack.append((to, val))

for x in ans[:-1]:
    print(x, end=' ')
print(ans[-1])

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

ans = [0 for _ in range(n)]
visit = [False for _ in range(n)]

def rec(pos, val):
    val += cnt[pos]
    ans[pos] = val
    for to in edges[pos]:
        if not visit[to]:
            visit[to] = True
            rec(to, val)

visit[0] = True
rec(0, 0)
for x in ans[:-1]:
    print(x, end=' ')
print(ans[-1])
Problem p03308 (python)

Fixed submission:
import math

n=input()
a=sorted(map(int,input().split()))


print(a[-1]-a[0])

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

a.sort()

print(a[-1]-a[0])

Buggy submission (verdict: Runtime Error):
import math

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

a.sort()

print(a[-1]-a[0])
Problem p03962 (python)

Fixed submission:
import math

a,b,c=input().split()
l=[a,b,c]


print(len(set(l)))

Buggy submission (verdict: Runtime Error):
import math

l=[]

for i in range(3):
    a=input()
    l.append(a)

print(len(set(l)))
Problem p02840 (python)

Fixed submission:
def gcd(a: int, b: int)->int:
    a, b = abs(a), abs(b)
    if a < b:
        a, b = b, a
    return gcd(b, a % b) if b else a


def sum_seq1(l: int, r: int)->int:
    if r < l:
        return 0
    return r*(r+1) // 2 - l*(l-1) // 2


def sum_difference(N: int, X: int, D: int)->int:
    if D == 0:
        if X == 0:
            return 1
        return N+1

    # D != 0
    g = gcd(X, D)
    a, b = D // g, -X // g

    if a < 0:
        a *= -1
        b *= -1
    i_range = [(float('inf'), -float('inf'))] * (N+1)

    ans = 0
    for k in range(N+1):
        kl, kr = i_range[k]
        nl = sum_seq1(0, k-1)
        nr = sum_seq1(N-k, N-1)
        # print('k: ({}, {}), n: ({}, {})'.format(kl, kr, nl, nr))

        if k+a <= N:
            i_range[k+a] = (b+min(kl, nl), b+max(kr, nr))

        if kr == -float('inf'):
            ans += nr - nl + 1
        elif kr < nl or nr < kl:
            ans += nr - nl + 1
        elif nl <= kl and kr <= nr:
            ans += (nr-nl+1) - (kr-kl+1)
        elif kl <= nl:
            ans += max(0, nr-kr)
        else:
            ans += kl-nl

    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    ans = sum_difference(N, X, D)
    print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a
    return gcd(b, a % b) if b else a


def sum_seq1(l: int, r: int)->int:
    if r < l:
        return 0
    return r*(r+1) // 2 - l*(l-1) // 2


def sum_difference(N: int, X: int, D: int)->int:
    if D == 0:
        if X == 0:
            return 1
        return N+1

    # D != 0
    D = abs(D)

    g = gcd(X, D)
    a, b = D // g, -X // g

    if a < 0:
        a *= -1
        b *= -1

    i_range = [(float('inf'), -float('inf'))] * (N+1)

    ans = 0
    for k in range(N+1):
        kl, kr = i_range[k]
        nl = sum_seq1(0, k-1)
        nr = sum_seq1(N-k, N-1)
        # print('k: ({}, {}), n: ({}, {})'.format(kl, kr, nl, nr))

        if k+a <= N:
            i_range[k+a] = (b+min(kl, nl), b+max(kr, nr))

        if kr == -float('inf'):
            ans += nr - nl + 1
        elif kr < nl or nr < kl:
            ans += nr - nl + 1
        elif nl <= kl and kr <= nr:
            ans += (nr-nl+1) - (kr-kl+1)
        elif kl <= nl:
            ans += max(0, nr-kr)
        else:
            ans += kl-nl

    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    ans = sum_difference(N, X, D)
    print(ans)
Problem p02997 (python)

Fixed submission:
def friendships(N: int, K: int)->list:
    MAX = (N-1)*(N-2)//2
    if K > MAX:
        return []

    res = []
    for v in range(2, N+1):
        res.append((1, v))

    u = 2
    v = 3
    for _ in range(K, MAX):
        res.append((u, v))
        if v == N:
            u += 1
            v = u + 1
        else:
            v += 1

    return res


if __name__ == "__main__":
    N, K = map(int, input().split())

    ans = friendships(N, K)
    if ans:
        print(len(ans))
        for u, v in ans:
            print(u, v)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
def friendships(N: int, K: int)->list:
    if K >= N:
        return []
    raise Exception()


if __name__ == "__main__":
    N, K = map(int, input().split())

    ans = friendships(N, K)
    if ans:
        print(len(ans))
        for u, v in ans:
            print(u, v)
    else:
        print(-1)