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

Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if 0 <= l < n and s[l] == t:
            l = l + 1

        if 0 <= r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n - 1)
    else:
        if 0 <= l-1 < n and s[l - 1] == t:
            l = max(0, l - 1)

        if 0 <= r < n and s[r] == t:
            r = r - 1


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))

Buggy submission (verdict: Runtime Error):
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if s[l] == t:
            l = min(l + 1, n)

        if r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n)
    else:
        if 0 < l and s[l - 1] == t:
            l = max(0, l - 1)

        if s[r] == t:
            r = max(0, r - 1)


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))

Buggy submission (verdict: Runtime Error):
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if s[l] == t:
            l = min(l + 1, n)

        if r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n)
    else:
        if 0 < l and s[l - 1] == t:
            l -= 1

        if s[r] == t:
            r -= 1


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))
Problem p03164 (python)

Fixed submission:
n, w = [int(i) for i in input().split()]
dp = [10 ** 18] * (10 ** 5 + 1)
dp[0] = 0
for _ in range(n):
    u, v = [int(i) for i in input().split()]
    for i in reversed(range(len(dp))):
        if i + v < len(dp) and dp[i]+u <= w:
            dp[i + v] = min(dp[i + v], dp[i] + u)
ans = 0
for i, j in enumerate(dp):
    if j != 10 ** 18:
        ans = max(ans, i)
print(ans)

Buggy submission (verdict: Runtime Error):
n, w = [int(i) for i in input().split()]
a = [0] * (w + 1)
for _ in range(n):
    b, c = [int(i) for i in input().split()]
    for i in reversed(range(w + 1)):
        if i + b >= w + 1:
            continue
        d = i + b
        a[d] = max(a[d], a[i] + c)
print(a[-1])
Problem p03175 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

mod = 10**9+7

def dfs(i=0, r=-1):
    b = w = 1
    for j in e[i]:
        if j == r:
            continue
        bb, ww = dfs(j, i)
        b = b * ww % mod
        w = w * (bb + ww) % mod
    return b, w

print(sum(dfs())%mod)

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

mod = 10**9+7

def dfs(i=0, r=-1):
    b = w = 1
    for j in e[i]:
        if j == r:
            continue
        bb, ww = dfs(j, i)
        b = b * ww % mod
        w = w * (bb + ww) % mod
    return b, w

print(sum(dfs()))
Problem p03238 (python)

Fixed submission:
n = int(input())
if n == 1:
  print("Hello World")
else:
  a = int(input())
  b = int(input())
  print(a+b)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1:
  orint("Hello World")
else:
  a = int(input())
  b = int(input())
  print(a+b)
Problem p03579 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)


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


n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0, r=-1):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        if j == r:
            continue
        dfs(j, (c + 1) % 2, i)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)

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

ok = False
tag = [-1] * n


def dfs(i=0, c=0):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        dfs(j, (c + 1) % 2)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)
Problem p03628 (python)

Fixed submission:
n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
ans = 3
i = 0
j = -1
while i < n:
    if s1[i] == s2[i]:
        if j == 0:
            ans *= 2
        i += 1
        j = 0
    else:
        if j == 1:
            ans *= 3
        else:
            ans *= 2
        j = 1
        i += 2
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, p = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for _ in range(m)]

for i in e:
    i[0] -= 1
    i[1] -= 1
    i[2] -= p

d = [0] * n
ok = [False] * n
ok[0] = True

for _ in range(n):
    for a, b, c in e:
        if ok[a]:
            d[b] = max(d[b], d[a] + c)
            ok[b] = True

aa = d[-1]

for _ in range(2*n):
    for a, b, c in e:
        if ok[a]:
            d[b] = max(d[b], d[a] + c)
            ok[b] = True

bb = d[-1]

if aa != bb:
    print("-1")
else:
    print(max(aa, 0))
Problem p03746 (python)

Fixed submission:
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i)-1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

used = [False] * n
used[0] = True
ans1 = [1]
ans2 = []
i = 0
while True:
    for j in e[i]:
        if not used[j]:
            i = j
            ans1.append(j + 1)
            used[j] = True
            break
    else:
        break
i = 0
while True:
    for j in e[i]:
        if not used[j]:
            i = j
            ans2.append(j + 1)
            used[j] = True
            break
    else:
        break

ans = list(reversed(ans2)) + ans1

print(len(ans))
print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import heapq

n, x = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
tt = [[] for _ in range(10 ** 5 + 1)]
for i in range(n):
    tt[t[i]].append(-a[i])


def max_score(time):
    q = []
    heapq.heapify(q)
    for i in range(time, 10 ** 5 + 1):
        for j in tt[i]:
            heapq.heappush(q, j)

    ans = 0
    for i in reversed(range(time)):
        if q:
            ans += heapq.heappop(q)
        for j in tt[i]:
            heapq.heappush(q, j)
    return -ans


if max_score(10 ** 5) < x:
    print(-1)
    exit()

mi = 0
ma = 10 ** 5

while mi != ma:
    m = (mi + ma) // 2
    if max_score(m) >= x:
        ma = m
    else:
        mi += 1
print(mi)
Problem p03846 (python)

Fixed submission:
i=input
n=int(i())
print([0,pow(2,n//2,10**9+7)][sorted(i().split(),key=int)==[str((j+n%2)//2*2+1-n%2)for j in range(n)]])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
if n%2 == 1:
  if a[0]!=0:
    print(0)
    exit()
  for i,j,k in zip(a[1::2],a[2::2],range(,n,2)):
    if not i==j==k:
      print(0)
      exit()
  print(2**(n//2))
  exit()
for i,j,k in zip(a[::2],a[1::2],range(,n,2)):
  if not i==j==k:
    print(0)
    exit()
print(2**(n//2))
Problem p04033 (python)

Fixed submission:
a,b=[int(i) for i in input().split()]
if 0<a and 0<b:
  print("Positive")
elif a*b<=0:
  print("Zero")
elif (b-a)%2==1:
  print("Positive")
else:
  print("Negative")

Buggy submission (verdict: Runtime Error):
a,b=[int(i) fro i in input().split()]
if 0<a and 0<b:
  print("Positive")
elif a*b<=0:
  print("Zero")
elif (b-a)%2==1:
  print("Positive")
else:
  print("Negative")
Problem p02537 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()

N = 300000

# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


for i in range(n):
    a = ni()
    s = a-k if a-k > 0 else 0
    e = a+k+1 if a+k+1 < 300001 else 300001
    update(a, min(query(s,e)-1, -1))


print(-query(0,300000))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()

N = n

# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


for i in range(n):
    a = ni()
    s = a-k-1 if a-k-1 > 0 else 0
    e = a+k-1 if a+k < n else n
    update(a-1, query(s,e)-1)


print(-query(0,n)+1)
Problem p02573 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

N = 3*10**5

*p, = range(N)
size = [1]*N
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    sx = size[px]; sy = size[py]
    if sy < sx:
        p[py] = px
        size[px] += sy
    else:
        p[px] = py
        size[py] += sx
    return 1

n,m = na()
ans = 0

for i in range(m):
    a,b = na()
    unite(a,b)

print(max(size))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

N = 10**5

*p, = range(N)
size = [1]*N
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    sx = size[px]; sy = size[py]
    if sy < sx:
        p[py] = px
        size[px] += sy
    else:
        p[px] = py
        size[py] += sx
    return 1

n,m = na()
ans = 0

for i in range(m):
    a,b = na()
    unite(a,b)

print(max(size))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import collections
import itertools
import operator

class UnionFind:
  def __init__(self, elems=None):
    class KeyDict(dict):
      def __missing__(self, key):
        self[key] = key
        return key

    self.parent = KeyDict()
    self.rank = collections.defaultdict(int)
    self.size_ = collections.defaultdict(lambda: 1)

    if elems is not None:
      for elem in elems:
        _, _, _ = self.parent[elem], self.rank[elem], self.size_[elem]

  def find(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find(self.parent[x])
      return self.parent[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] < self.rank[y]:
      self.parent[x] = y
      self.size_[y] += self.size_[x]
    else:
      self.parent[y] = x
      self.size_[x] += self.size_[y]
    if self.rank[x] == self.rank[y]:
      self.rank[x] += 1

  def are_same(self, x, y):
    return self.find(x) == self.find(y)

  def grouper(self):
    roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
    root = operator.itemgetter(1)
    for _, group in itertools.groupby(sorted(roots, key=root), root):
      yield [x for x, _ in group]

  def size(self,x):
    return self.size_[self.find(x)]


n,m = na()
g = UnionFind()
ans = 0

for i in range(m):
    a,b = na()
    g.unite(a,b)

a = [len(i) for i in list(g.grouper())]

print(max(a))
Problem p02585 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
p = na()
c = na()

s = set(range(n))

ans = 0
loops = []
while s:
    loop = [0]
    a = s.pop()
    while True:
        loop.append(loop[-1]+c[p[a]-1])
        if p[a]-1 not in s:
            break
        a = p[a]-1
        s.discard(a)
    loops.append(loop[1:])

ans = -1000000000000000
for tmp in loops:
    kk = k
    if k > len(tmp): kk = k%len(tmp)+len(tmp)
    loop = [0]+tmp+[tmp[-1]+u for u in tmp]+[tmp[-1]*2+u for u in tmp]
    x = -1000000000000
    for i in range(1,kk+1):
        for j in range(len(tmp)+1):
            x = max(x,loop[j+i]-loop[j])
    if k > len(tmp) and tmp[-1] > 0:
        x += tmp[-1]*(k//len(tmp)-1)
    ans = max(ans,x)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
p = na()
c = na()

s = set(range(n))

ans = 0
loops = []
while s:
    loop = [0]
    a = s.pop()
    while True:
        loop.append(loop[-1]+c[p[a]-1])
        if p[a]-1 not in s:
            break
        a = p[a]-1
        s.discard(a)
    loops.append(loop[1:])

ans = -1000000000000000
for tmp in loops:
    kk = k
    if k > len(tmp): kk = len(tmp) if k%len(tmp)==0 else k%len(tmp)
    loop = [0]+tmp+[tmp[-1]+u for u in tmp]
    print(loop)
    x = -1000000000
    for i in range(1,kk+1):
        for j in range(len(tmp)+1):
            print(j,i,loop)
            x = max(x,loop[j+i]-loop[j])
    if k > len(tmp) and tmp[-1] > 0:
        x += tmp[-1]*(k//len(tmp))
    ans = max(ans,x)

print(ans)
Problem p02632 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6*3
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**3*3
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)
Problem p02684 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
a = na()
dp = [-1]*n
dp[0] = 0
i = 1
now = 0
loop = -1
start = -1

while True:
    now = a[now]-1
    if i == k:
        print(now+1)
        exit()
    if dp[now] == -1:
        dp[now] = i
    else:
        loop = i - dp[now]
        start = dp[now]
        break
    i+=1

print(dp.index((k-start)%loop+start)+1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
a = na()
dp = [-1]*n
dp[0] = 0
i = 1
now = 0
loop = -1
start = -1

while True:
    now = a[now]-1
    if i == k:
        print(now+1)
        exit()
    if dp[now] == -1:
        dp[now] = i
    else:
        loop = i - dp[now]
        start = now
        break
    i+=1

print(dp.index((k-start)%loop+start)+1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
a = na()
dp = [-1]*n
i = 1
now = 0
loop = -1
start = -1

while True:
    now = a[now]-1
    if i == k:
        print(now+1)
        exit()
    if dp[now] == -1:
        dp[now] = i
    else:
        loop = i - dp[now]
        start = now
        break
    i+=1

print(dp.index((k-start)%loop+start)+1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
a = na()
dp = [-1]*n
i = 1
now = 0
loop = -1
start = -1

while True:
    now = a[now]-1
    if i == k:
        print(now+1)
        exit()
    if dp[now] == -1:
        dp[now] = i
    else:
        loop = i - dp[now]
        start = now
        break
    i+=1

print(dp.index(k%loop)+1)
Problem p02697 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()

a,b = 1,n-(n%2)
for i in range(m):
    if n%2 == 0 and i == (m+1)//2:
        a += 1
    print(a,b)
    a,b = a+1, b-1

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()

if n%2 == 0:
    a,b = n//2,n//2+1
    for i in m:
        print(a,b)
        a,b = a-1,b+1
else:
    a,b = 1,n
    for i in m:
        print(a,b)
        a,b = a+1,b-1
Problem p02702 (python)

Fixed submission:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import defaultdict

s = ns()
d = defaultdict(int)
d[0] += 1
k = 1
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*k%2019
    n%=2019
    d[n] += 1
    k = (k*10)%2019

ans = 0

for j in d.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
b = [0]
k = 0
n = 0
for i in range(len(s), reversed=True):
    n += s[i]*(10**k)
    n%=2019
    b.append(n)
    k+=1

import collections

c = collections.Counter(b)
ans = 0

for j in c.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)