Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))
D.sort()
T.sort()
if n<=m:
    if D==T:
        print('YES')
        exit()
    else:
        print('NO')
        exit()

r = 'YES'
for i in range(m):
    if T[i] in D:
        idx = D.index(T[i])
        D = D[idx+1:]
    else:
        r = 'NO'
        break
print(r)

Fixed submission:
n = int(input())
dD = input().split()
m = int(input())
dT = input().split()
d = dict()

for di in dD:
    if di in d:
        d[di] += 1
    else:
        d[di] = 1

ans = 'YES'
for ti in dT:
    if ti not in d or d[ti]==0:
        ans = 'NO'
        break
    else:
        d[ti] -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))
D.sort()
T.sort()
if n=<m:
    if D==T:
        print('YES')
        exit()
    else:
        print('NO')
        exit()

r = 'YES'
for i in range(m):
    if T[i] in D:
        idx = D.index(T[i])
        D = D[idx+1:]
    else:
        r = 'NO'
        break
print(r)

Fixed submission:
n = int(input())
dD = input().split()
m = int(input())
dT = input().split()
d = dict()

for di in dD:
    if di in d:
        d[di] += 1
    else:
        d[di] = 1

ans = 'YES'
for ti in dT:
    if ti not in d or d[ti]==0:
        ans = 'NO'
        break
    else:
        d[ti] -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))

r = 'YES'
for i in range(m):
    if T[i] in D:
        D.remove(T[i])
    else:
        r = 'NO'
        break
print(r)

Fixed submission:
n = int(input())
dD = input().split()
m = int(input())
dT = input().split()
d = dict()

for di in dD:
    if di in d:
        d[di] += 1
    else:
        d[di] = 1

ans = 'YES'
for ti in dT:
    if ti not in d or d[ti]==0:
        ans = 'NO'
        break
    else:
        d[ti] -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n%2==0:
    print(n, n, n//2)
else:
    f = False
    for i in range(1, 3500):
        _h = n/i
        for j in range(1,3500):
            _n = n/j
            w = n/(4-_h-_n)
            if w>0 and w%1==0:
                print(i, j, int(w))
                f = True
            if f: break
        if f: break

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h>0 and (N*h*n)%(4*h*n-N*n-N*h)==0:
            print(h, n, (N*h*n)//(4*h*n-N*n-N*h))
            exit()

Buggy python submission (verdict: Runtime Error):
n = int(input())
if n%2==0:
    print(n, n, n//2)
else:
    f = False
    for i in range(1, 3500):
        _h = n/i
        for j in range(1,3500):
            _n = n/j
            w = n/(4-_h-_n)
            if w>0 and w%1==0:
                print(i, j, int(w))
                f = True
            if f: break
        if f: break

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h>0 and (N*h*n)%(4*h*n-N*n-N*h)==0:
            print(h, n, (N*h*n)//(4*h*n-N*n-N*h))
            exit()
Buggy python submission (verdict: Runtime Error):
from collections import Counter
h, w = map(int, input().split())
A = []
for i in range(h):
    A.extend(list(input()))
cA = Counter(A)

l1 = h*w%2
l2 = (h//2)*(w%2) + (w//2)*(h%2)
l3 = (h//2)*(w//2)
if l1:
    for key, val in cA.items():
        if val%2==1:
            cA[key] -= 1
            break
for _ in range(l2):
    for key, val in cA.items():
        if val%4=-2:
            cA[key] -= 2
            break
print('Yes' if sum(val%4 for val in cA.values()) == 0 else 'No')

Fixed submission:
from collections import Counter
h, w = map(int, input().split())
A = []
for i in range(h):
    A.extend(list(input()))
cA = Counter(A)

l1 = h*w%2
l2 = (h//2)*(w%2) + (w//2)*(h%2)
l3 = (h//2)*(w//2)
if l1:
    for key, val in cA.items():
        if val%2==1:
            cA[key] -= 1
            break
for _ in range(l2):
    for key, val in cA.items():
        if val%4==2:
            cA[key] -= 2
            break
print('Yes' if sum(val%4 for val in cA.values()) == 0 else 'No')

Buggy python submission (verdict: Runtime Error):
from collections import Counter
h, w = map(int, input().split())
A = []
for i in range(h):
    A.extend(list(input()))
cA = Counter(A)

l1 = h*w%2
l2 = (h//2)*(w%2) + (w//2)*(h%2)
l3 = (h//2)*(w//2)
if l1:
    for key, val in cA.items():
        if val%2==1:
            cA[key] -= 1
            break
for _ in range(l2):
    for key, val in cA.items():
        if val%4=-2:
            cA[key] -= 2
            break
print('Yes' if sum(a[i]%4 for i in a) == 0 else 'No')

Fixed submission:
from collections import Counter
h, w = map(int, input().split())
A = []
for i in range(h):
    A.extend(list(input()))
cA = Counter(A)

l1 = h*w%2
l2 = (h//2)*(w%2) + (w//2)*(h%2)
l3 = (h//2)*(w//2)
if l1:
    for key, val in cA.items():
        if val%2==1:
            cA[key] -= 1
            break
for _ in range(l2):
    for key, val in cA.items():
        if val%4==2:
            cA[key] -= 2
            break
print('Yes' if sum(val%4 for val in cA.values()) == 0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = []
for i in range(n):
    a = int(input())
    if a not in A:
        A.append(a)
    else:
        A.remove(a)
print(len(A))

Fixed submission:
from collections import Counter
n = int(input())
A = [0]*n
for i in range(n):
    A[i] = int(input())

cA = Counter(A).values()
r = 0
for i in cA:
    r += i%2
print(r)
Buggy python submission (verdict: Runtime Error):
n = int(input())
P = list(map(int, input().split()))

r = 0
for i in range(n):
    if P[i] == i+1:
        if i!=n:
            P[i+1] = P[i]
            r += 1
        else:
            r += 1
print(r)

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

r = 0
for i in range(n):
    if P[i] == i+1:
        if i!=n-1:
            P[i+1] = P[i]
            r += 1
        else:
            r += 1
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
A2 = [a for a in A if A.count(a)>=2]
A2.sort()
print(A2[-1]*A2[-4] if len(A2)>=4 else 0)

Fixed submission:
from collections import Counter
n = int(input())
A = Counter(list(map(int, input().split())))
E = [0, 0]
for k, v in A.items():
    if v>=2:
        E.append(k)
    if v>=4:
        E.append(k)
E.sort()
print(E[-1]*E[-2])
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline
n = int(readline())
D = [[-1]*n for _ in range(n)]
for i in  range(n): D[i][i]=0
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(lambda x:int(x)-1, map(int, readline().split()))
    G[a].append(b)
    G[b].append(a)
    D[a][b] = c+1
    D[b][a] = c+1

q, k = map(int, readline().split())
k -= 1
que = deque([k])
_D = [-1]*n
_D[k] = 0
while que:
    nw = que.popleft()
    d = _D[nw]
    for nx in G[nw]:
        if nw!=k and _D[nx]!=-1: continue
        _D[nx] = d+D[nw][nx]
        que.append(nx)

for i in range(q):
    x, y = map(lambda x: int(x)-1, readline().split())
    print(_D[x]+_D[y])

Fixed submission:
import sys
sys.setrecursionlimit(pow(10,6))
readline = sys.stdin.readline

def dfs(nw, d):
    V[nw] = d
    for nx in G[nw]:
        if V[nx[0]]==-1:
            dfs(nx[0], d+nx[1])

n = int(readline())
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int, readline().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q, k = map(int, readline().split())

V = [-1]*n
dfs(k-1, 0)

for i in range(q):
    x,y = map(lambda x:int(x)-1, readline().split())
    print(V[x]+V[y])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
readline = sys.stdin.readline
n = int(readline())
D = [[-1]*n for _ in range(n)]
for i in  range(n): D[i][i]=0
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(lambda x:int(x)-1, map(int, readline().split()))
    G[a].append(b)
    G[b].append(a)
    D[a][b] = c+1
    D[b][a] = c+1

q, k = map(int, readline().split())
k -= 1
que = deque([k])
_D = [-1]*n
_D[k] = 0
while que:
    nw = que.popleft()
    d = _D[nw]
    for nx in G[nw]:
        if nw!=k and _D[nx]!=-1: continue
        _D[nx] = d+D[nw][nx]
        que.append(nx)

for i in range(q):
    x, y = map(lambda x: int(x)-1, readline().split())
    print(_D[x]+_D[y])

Fixed submission:
import sys
sys.setrecursionlimit(pow(10,6))
readline = sys.stdin.readline

def dfs(nw, d):
    V[nw] = d
    for nx in G[nw]:
        if V[nx[0]]==-1:
            dfs(nx[0], d+nx[1])

n = int(readline())
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int, readline().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q, k = map(int, readline().split())

V = [-1]*n
dfs(k-1, 0)

for i in range(q):
    x,y = map(lambda x:int(x)-1, readline().split())
    print(V[x]+V[y])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
Ton = [False]*n
Fr1 = [False]*n
for i in range(m):
    a, b = map(int, input().split())
    if b==n:
        Ton[a] = True
    if a==1:
        Fr1[b] = True

r = 'IMPOSSIBLE'
for i in range(m):
    if Ton[i]==Fr1[i]==True:
        r = 'POSSIBLE'
print(r)

Fixed submission:
def main():
    n, m = map(int, input().split())
    Ton, Fr1 = set(), set()
    for _ in range(m):
        a, b = map(int, input().split())
        if b==n:
            Ton.add(a)
        if a==1:
            Fr1.add(b)

    print('POSSIBLE' if Ton&Fr1 else 'IMPOSSIBLE')

main()

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
Ton = []
Fr1 = []
for i in range(m):
    a, b = map(int, input().split())
    if b==n:
        Ton.append(a)
    if a==1:
        Fr1.append(b)

r = 'IMPOSSIBLE'
for a in Fr1:
    if a in Ton:
        r = 'POSSIBLE'
print(r)

Fixed submission:
def main():
    n, m = map(int, input().split())
    Ton, Fr1 = set(), set()
    for _ in range(m):
        a, b = map(int, input().split())
        if b==n:
            Ton.add(a)
        if a==1:
            Fr1.add(b)

    print('POSSIBLE' if Ton&Fr1 else 'IMPOSSIBLE')

main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ne = n%2
B = []
for i in range(n):
    if (i+1)%2 == ne:
        B = [A[i]]+B
    else:
        B = B + [A[i]]
print(*B)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
if n%2==0:
    B = A[1::2][::-1] + A[::2]
    print(*B)
else:
    B = A[::2][::-1] + A[1::2]
    print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
if n==1:
    print(*A)
else:
    B = [0]*n
    for i in range(n):
        B[i] = A[i]
        B = B[i::-1] + B[i+1:]
    print(*B)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
if n%2==0:
    B = A[1::2][::-1] + A[::2]
    print(*B)
else:
    B = A[::2][::-1] + A[1::2]
    print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(n):
    B.append(A[i])
    B = B[::-1]
print(*B)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
if n%2==0:
    B = A[1::2][::-1] + A[::2]
    print(*B)
else:
    B = A[::2][::-1] + A[1::2]
    print(*B)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
k = [0]*n
mk = [0]*8
for i in range(n):
    k[i] = A[i]//400
    mk[k[i]-1] += 1
r1 = len(set(k))-min(1, mk[-1])
r2 = r1+mk[-1]
print(str(r1)+" "+str(r2))

Fixed submission:
#cant fix re, just copy and paste.
n = int(input())
a = list(map(int, input().split()))
a.sort()
free=0
cset=set()
for rate in a:
    color = int(rate / 400)
    if color >=8:
        free+=1
    else:
        cset.add(color)

colormin=len(cset)
colormax=colormin+free
 
print(str(max(1,colormin)), colormax)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
k = [0]*n
mk = [0]*8
for i in range(n):
    k[i] = A[i]//400
    mk[k[i]-1] += 1
if mk[-1]:
    print(len(set(k))-1, min(len(set(k))-1+mk[-1], 8))
else:
    print(len(set(k)), len(set(k)))

Fixed submission:
#cant fix re, just copy and paste.
n = int(input())
a = list(map(int, input().split()))
a.sort()
free=0
cset=set()
for rate in a:
    color = int(rate / 400)
    if color >=8:
        free+=1
    else:
        cset.add(color)

colormin=len(cset)
colormax=colormin+free
 
print(str(max(1,colormin)), colormax)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
r = 1
d = A[1]-A[0]
if n>2:
    for i in range(2, n):
        if d:
            if (A[i]-A[i-1])*d<0:
                r += 1
                d = 0
        else:
            d = A[i]-A[i-1]
print(r)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
r = 1
if n>2:
    d = A[1]-A[0]
    for i in range(2, n):
        if d:
            if (A[i]-A[i-1])*d<0:
                r += 1
                d = 0
        else:
            d = A[i]-A[i-1]
print(r)
Buggy python submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
T = [0]*n
for i in range(n):
    T[i] = int(input())
T.sort()
ans = 0
jk = 0
t = T[0]
for i in range(n):
    if T[i]-t>k:
        ans += 1
        jk = 0
        t = T[i]
        continue
    jk += 1
    if jk==c:
        ans += 1
        jk = 0
        t = T[i]
print(ans if jk== else ans+1)

Fixed submission:
n, c, k, *T = map(int, open(0).read().split())
T.sort()
ans = 1
p = 0
t = T[0]
for i in range(n):
    p += 1
    if T[i]>t+k or p>c:
        t = T[i]
        ans += 1
        p = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
r = 1
for i in range(2, n+1):
    r *= i%(10**9+7)
print(r%(10**9+7))

Fixed submission:
n = int(input())
r = 1
for i in range(2, n+1):
    r *= i
    r %= 10**9+7
print(r)
Buggy python submission (verdict: Runtime Error):
import itertools
from math import factorial as fa
P = itertools.permutations(list(range(n)))
n, m = map(int, input().split())
G = [set() for _ in range(n)]
for _ in range(m):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].add(b)
    G[b].add(a)

ans = 0
for _ in range(fa(n)):
    p = next(P)
    if p[0] != 0:
        break
    f = True
    for pnw,pnx in zip(p,p[1:]):
        if not pnx in G[pnw]:
            f = False
            break
    if f:
        ans += 1
print(ans)

Fixed submission:
import itertools
n, m = map(int, input().split())
G = [set() for _ in range(n)]
for _ in range(m):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].add(b)
    G[b].add(a)

P = [*itertools.permutations(range(1,n))]
ans = 0
for p in P:
    nw = 0
    for nx in p:
        if nx in G[nw]:
            nw = nx
        else:
            break
    else:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()replace('dreamer', '').replace('eraser', '').replace('dream', '').replace('erase', '').
print('YES' if s=='' else 'NO')

Fixed submission:
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print('YES' if s=='' else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
X = input()
X_ = ''
while X!=X_:
    X_ = X
    X = X.replace('ST', '')
print(len(X))

Fixed submission:
from collections import deque
X = input()
que = deque()
for x in X:
    if x=='S':
        que.append('S')
    elif x=='T' and (not que or que[-1]=='T'):
        que.append('T')
    elif x=='T' and que[-1]=='S':
        _ = que.pop()
print(len(que))

Buggy python submission (verdict: Runtime Error):
X = input()
while X!=X_:
    X_ = X
    X = X.replace('ST', '')
print(len(X))

Fixed submission:
from collections import deque
X = input()
que = deque()
for x in X:
    if x=='S':
        que.append('S')
    elif x=='T' and (not que or que[-1]=='T'):
        que.append('T')
    elif x=='T' and que[-1]=='S':
        _ = que.pop()
print(len(que))
Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline())
ans = 0
t = 0
for i in range(n):
    a = int(sys.stdin.readline())
    if a==0:
        ans += t//2
        t = 0
    else:
        t += a
if t>0: ans += t//2
pritn(ans)

Fixed submission:
import sys
n = int(sys.stdin.readline())
ans = 0
t = 0
for i in range(n):
    a = int(sys.stdin.readline())
    if a==0:
        ans += t//2
        t = 0
    else:
        t += a
if t>0: ans += t//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_right, bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T = [i + 1 - A[i] for i in range(N)]
    idx = sorted(range(N), key=lambda k: T[k])
    T.sort()

    ans = 0
    for i in range(N):
        target = A[i] + i + 1
        left = bisect_left(T, target)
        if left > N - 1:
            continue
        if T[left] != target:
            continue
        else:
            right = bisect_right(T, target)
            for k in range(left, min(right, N)):
                j = idx[k]
                if i < j:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from bisect import bisect_right, bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T = [i + 1 - A[i] for i in range(N)]
    idx = sorted(range(N), key=lambda k: T[k])
    T.sort()

    ans = 0
    for i in range(N):
        target = A[i] + i + 1
        left = bisect_left(T, target)
        if left > N - 1:
            continue
        if T[left] != target:
            continue
        else:
            right = bisect_right(T, target)
            ans += right - left
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_right, bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T = [i + 1 - A[i] for i in range(N)]
    idx = sorted(range(N), key=lambda k: T[k])
    T.sort()

    ans = 0
    for i in range(N):
        target = A[i] + i + 1
        left = bisect_left(T, target)
        if left > N - 1:
            continue
        if T[left] != target:
            continue
        else:
            right = bisect_right(T, target)
            for k in range(left, min(right, N)):
                j = idx[k]
                if i < j:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from bisect import bisect_right, bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T = [i + 1 - A[i] for i in range(N)]
    idx = sorted(range(N), key=lambda k: T[k])
    T.sort()

    ans = 0
    for i in range(N):
        target = A[i] + i + 1
        left = bisect_left(T, target)
        if left > N - 1:
            continue
        if T[left] != target:
            continue
        else:
            right = bisect_right(T, target)
            ans += right - left
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    M = 0
    for i in range(N, max(0, N - 10 ** 7), -1):
        tmp = func(i)
        if tmp > M:
            M = tmp

    print(M)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    print(func(min(N, B - 1)))


if __name__ == "__main__":
    main()

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


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    M = 0
    for i in range(N, max(0, N - 10 ** 8), -1):
        tmp = func(i)
        print(i, tmp)
        if tmp > M:
            M = tmp

    print(M)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    print(func(min(N, B - 1)))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    if N % 2 == 0:
        used = [False] * (N + 1)
        i = 0
        span = 1
        cnt = 0
        while cnt < M:
            cnt += 1
            while used[i]:
                i += 1
            print(i + 1, i + 1 + span)
            used[i] = True
            used[i + span] = True
            span += 1
    else:
        for i in range(M):
            print(i + 1, N - i)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    if N % 2 == 0:
        for i in range(M):
            x = i + 1
            y = N - i - 1
            if y - x > (N - y + x):
                print(x, y)
            else:
                print(x, y - 1)
    else:
        for i in range(M):
            print(i + 1, N - i)


if __name__ == "__main__":
    main()

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


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    if N % 2 == 0:
        used = [False] * (N + 1)
        i = 1
        span = 1
        cnt = 0
        while cnt < M:
            cnt += 1
            while used[i]:
                i += 1
            print(i, i + span)
            used[i] = True
            used[i + span] = True
            i += 1
            span += 1
    else:
        for i in range(M):
            print(i + 1, N - i)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    if N % 2 == 0:
        for i in range(M):
            x = i + 1
            y = N - i - 1
            if y - x > (N - y + x):
                print(x, y)
            else:
                print(x, y - 1)
    else:
        for i in range(M):
            print(i + 1, N - i)


if __name__ == "__main__":
    main()