Problem:


Score : 500 points

Problem Statement

You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)
N players will participate in this competition, and they are given distinct integers from 1 through N.
The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive).
You cannot assign the same integer to multiple playing fields.
The competition consists of N rounds, each of which proceeds as follows:

For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.

Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.

You want to ensure that no player fights the same opponent more than once during the N rounds.
Print an assignment of integers to the playing fields satisfying this condition.
It can be proved that such an assignment always exists under the constraints given.

Constraints

1 \leq M

M \times 2 +1 \leq N \leq 200000

Input

Input is given from Standard Input in the following format:

N M

Output

Print M lines in the format below.
The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.

a_1 b_1
a_2 b_2
:
a_M b_M

Sample Input 1

4 1

Sample Output 1

2 3

Let us call the four players A, B, C, and D, and assume that they are initially given the integers 1, 2, 3, and 4, respectively.

The 1-st round is fought by B and C, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 2, 3, 4, and 1, respectively.

The 2-nd round is fought by A and B, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 3, 4, 1, and 2, respectively.

The 3-rd round is fought by D and A, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 4, 1, 2, and 3, respectively.

The 4-th round is fought by C and D, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 1, 2, 3, and 4, respectively.

No player fights the same opponent more than once during the four rounds, so this solution will be accepted.

Sample Input 2

7 3

Sample Output 2

1 6
2 5
3 4



Sample input:
4 1


Sample output:
2 3

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

anss = []
if N % 2:
    for x in range(1, N+1):
        y = N-x
        if x >= y:
            break
        anss.append((x, y))
else:
    K1 = (N-1)//2
    K2 = K1-1
#    print('K1:', K1, '/ K2:', K2)
    for x in range(1, K1+1):
        y = K1+2-x
        if x >= y:
            break
        anss.append((x, y))
    for x in range(1, K2+1):
        y = K2+2-x
        if x >= y:
            break
        anss.append((K1+1+x, K1+1+y))

print('\n'.join(map(lambda x: str(x[0])+' '+str(x[1]), anss[:M])))

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

used = [False] * N

if N % 2 == 1:
    for i in range(M):
        print(N // 2 - i, N // 2 + i + 1)
else:
    for i in range(M):
        # 左に作る
        if i % 2 == 0:
            c = N // 2 // 2
            d = i // 2
            print(c - d, c + d + 1)
        # 右に作る
        else:
            c = N // 2 + (N // 2 + 1) // 2
            d = (i + 1) // 2
            print(c - d, c + d)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
if N % 2 == 1:
    for i in range(1, M+1):
        print(i, N-i+1)
else:
    for i in range(1, M+1):
        if i % 2 == 1:
            print(N//2+M//2  -i//2, N//2+ M//2  - i//2 + i)
        else:
            print(M//2 + 1 - i//2, M//2 + 1 - i//2 + i)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A = [i + 1 for i in range(N)]
mid = N//2
ans = []
for i in range(M+1//2):
    ans.append([A[mid - i], A[mid + 1 + i]])
    ans.append([A[-1 - i], A[1 + i]])
for i in range(M):
    print(*ans[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

if n % 2 == 1:
    for i in range(1, m+1):
        print(i, n - i)
else:
    for i in range(1, min(n//4+1, m+1)):
        print(i, n - i + 1)
    for i in range(n//4+1, m+1):
        print(i, n - i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=[]
if n%2:
  for i in range(m):
    ans.append("{} {}".format(i+1,n-i))
else:
  for i in range(m):
    if i+1<=m//2+m%2:
      ans.append("{} {}".format(i+1,n-i))
    else:
      ans.append("{} {}".format(i+1,n-1-i))
print("\n".join(ans))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())



cnt = 0
i = 0
j = M
while i+1 < j and cnt < M:
    print(i+1, j)
    i += 1
    j -= 1
    cnt += 1

i = M
j = 2*M+1
while i+1 < j and cnt < M:
    print(i+1, j)
    i += 1
    j -= 1
    cnt += 1

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict
from sys import exit
import math


def main():
    n, m = getList()
    if n % 2 == 0:
        mx = (n-2) // 2
    else:
        mx = n // 2

    a,b,c,d = 1, 1+mx-1, n - mx, n
    diff = 0
    cnt = 0
    while(True):
        print(c+diff, d-diff)
        cnt += 1
        if cnt == m:
            return
        print(a+diff, b-diff)
        cnt += 1
        if cnt == m:
            return
        diff += 1
    # for i in range(m):
    #     print(i+1, n-i)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


def main():
    n,m=map(int,input().split())

    if n%2:
        for i in range(1,m+1):
            print(i,2*m-i+1)
    else:
        i,j=1,n
        a=[]
        while i<=n//4:
            a.append([i,j])
            i,j=i+1,j-1
        j-=1
        while i<j:
            a.append([i,j])
            i,j=i+1,j-1
        for i in range(m):
            print(a[i][0],a[i][1])
        # print(a)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M = map(int, input().split())

if N % 2 == 1:
    for i in range(M):
        print(i+1,N-i)
else:
    M1 = -(-M//2)
    M2 = M - M1
    for j in range(M1):
        print(j+1,N-j)
    for k in range(M2):
        print(int(N/2-1-k),int(N/2+1+k))

Submission status: Accepted

Solution code:
[n,m] = list(map(int,input().split(" ")))

if m%2 == 0:
    t = int(m/2)
    for i in range (t):
        print(i+1,2*t-i)
    for i in range (t):
        print(2*t+1+i,4*t+1-i)
else:
    t = int(m/2)+1
    for i in range (t):
        print(i+1,2*t-i)
    for i in range (t-1):
        print(2*t+1+i,4*t-1-i)

Submission status: Accepted

Solution code:
# coding: utf-8

def run():
    N, M = map(int, input().split())
    left1 = 1
    left2 = M
    right1 = N -M
    right2 = N
    for idx, i in enumerate((range(1,M,2))):
        print('{} {}'.format(left1+idx, left2-idx))
    for idx, _ in enumerate(range(M+1, 2*M+1, 2)):
        print('{} {}'.format(right1+idx, right2-idx))

if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

for i in range(min(M, N // 4)):
    print("{} {}".format(i + 1, N - i))

center = (N + 1) // 2

for i in range(max(0, M - N // 4)):
    print("{} {}".format(center - i - 1, center + i + 1))

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split()))
mm=int((m+1)/2+0.01)
for i in range(mm):
  print(1+i,2*mm-i)
for i in range(m-mm):
  print(2*mm+i+1,2*m-i+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, m = map(int,input().split())
    
    if n & 1: 
        left = 1
        right = n - 1
        for _ in range(m):
            print(left, right)
            left += 1
            right -= 1
        return

    # 最初に 1 から n/2 - 1 を埋める
    left = 1
    right = n // 2 - 1
    while left < right:
        print(left, right)
        m -= 1
        if m == 0:
            return
        left += 1
        right -= 1

    left = n // 2
    right = n - 1
    while left < right:
        print(left, right)
        m -= 1
        if m == 0:
            return
        left += 1
        right -= 1
resolve()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
x = (n + 1) // 2
cnt_l = -(-m // 2)
cnt_r = m // 2
ans = []
for i in range(cnt_l):
    ans.append((i+1, x-i))
for i in range(cnt_r):
    ans.append((x+1+i, 2*x-i-1))

for i in range(m):
    print(*ans[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())

if n %2 == 1:
    for i in range(1,m+1):
        print(i,n-i)
else:
    for i in range(m//2):
        print(n//2-i,n//2+1+i)
        print(i+1,n-i-1)
    if m%2 == 1:
        print(n//2-m//2,n//2+1+m//2)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

ans = []
diff = M
now = 1
while diff >= 1:
  ans.append([now, now+diff])
  diff -= 2
  now += 1

diff = M-1
now = N
while diff >= 1:
  ans.append([now-diff, now])
  diff -= 2
  now -= 1

for a in ans:
  print(*a)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if n%2 == 1:
  for i in range(1,m+1):
    print(i,n+1-i)
else:
  c = 0
  for i in range(1,(n//4)+1):
    print(i,n+1-i)
    c += 1
    if c == m:
      exit()
  j = n//2
  while True:
    print(j,n+2-j)
    c += 1
    if c == m:
      exit()
    j -= 1

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
x,y = 1, N
used = [False for i in range(N+1)]
for i in range(M):
	if N % 2 == 0 and ((y-x) == N // 2 or used[y-x]):
		y -= 1
		print(x,y)
	else:
		print(x,y)
	used[y-x] = True
	used[N-(y-x)] = True
	x += 1
	y -= 1

Submission status: Accepted

Solution code:
import math
N,M=map(int,input().split())

if(N%2==1):
  for i in range(M):
    print(i+1,N-i)
else:
  for i in range(min(M,N//4)):
    print(i+1,N//2-i)
  for i in range(max(M-N//4,0)):
    print(N//2+1+i,N-1-i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if n == 3:
  print(1,2)
elif n == 4:
  print(1,2)
else:
  ansst = set()
  if n%2:
    for i in range(m):
      print(i+1,n-i-1)
  else:
    for i in range(min(m,n//4)):
      if abs(i+1-(n-i-1))*2 == n:
        print(i+1,n-i-2)
      else:
        print(i+1,n-i-1)
    if m >= n//4:
      for i in range(n//4,m):
        print(i+1,n-i-2)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())

    ans = [None for _ in range(m)]
    used = set()
    a = 1
    b = n
    good = True
    for i in range(m):
        if b - a == n - (b - a):
            a += 1
            b -= 1
        ans[i] = (a, b)
        if (b - a) in used:
            good = False
            break
        else:
            used.add(b - a)
        if (n - (b - a)) in used:
            good = False
            break
        else:
            used.add(n - (b - a))
        a += 1
        b -= 1

    if not good:
        ans = [None for _ in range(m)]
        used = set()
        a = 1
        b = n-1
        good = True
        for i in range(m):
            if b - a == n - (b - a):
                a += 1
                b -= 1
            ans[i] = (a, b)
            if (b - a) in used:
                good = False
                break
            else:
                used.add(b - a)
            if (n - (b - a)) in used:
                good = False
                break
            else:
                used.add(n - (b - a))
            a += 1
            b -= 1

    if not good:
        ans = [None for _ in range(m)]
        used = set()
        a = 1
        b = n
        good = True
        dec = False
        for i in range(m):
            if b - a == n - (b - a):
                b -= 1
            if not dec and ((b - a) in used or (n - (b - a)) in used):
                b -= 1
            ans[i] = (a, b)
            if (b - a) in used:
                good = False
                break
            else:
                used.add(b - a)
            if (n - (b - a)) in used:
                good = False
                break
            else:
                used.add(n - (b - a))
            a += 1
            b -= 1


    for i in range(m):
        print(ans[i][0], ans[i][1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
if n%2:
    a=1
    b=n
    for i in range(m):
        print(a,b)
        a+=1
        b-=1
else:
    a=1
    b=n
    m2=(m+1)//2
    for i in range(m2):
        print(a,b)
        a+=1
        b-=1
    m3=m-m2
    a=1+m2
    b=n-m2-1
    for i in range(m3):
        print(a,b)
        a+=1
        b-=1

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    used = set()
    left = 1
    right = N
    for i in range(M):
        if right - left not in used:
            if N - (right - left) not in used and N - (right - left) != right - left:
                print(left, right)
                used |= {right - left}
                used |= {N - (right - left)}
                left += 1
                right -= 1
            else:
                print(left, right - 1)
                used |= {right - left - 1}
                used |= {N - (right - left - 1)}
                left += 1
                right -= 2
        else:
            print(left, right - 1)
            used |= {right - left - 1}
            used |= {N - (right - left - 1)}
            left += 1
            right -= 2

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

if n % 2 == 0:
    if n % 4 == 0:
        flag = True
        for i in range(m):
            if i == n//4:
                flag = False
            if flag == True:
                print(i+1,n-i)
            else:
                print(i+1,n-i-1)
    else:
        flag = True
        for i in range(m):
            if n-i - (i+1) == n//2:
                flag = False
            if flag == True:
                print(i+1,n-i)
            else:
                print(i+1,n-i-1)
else:
    for i in range(m):
        print(i+1,n-i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N % 2 == 1:
    for i in range(M):
        print(str(i + 1) + " " + str(N - i))
else:
    if M <= N // 4:
        for i in range(M):
            print(str(i + 1) + " " + str(N - i))
    else:
        for i in range(N // 4):
            print(str(i + 1) + " " + str(N - i))
        for i in range(N // 4, M):
            print(str(i + 1) + " " + str(N - i - 1))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
li = []
if N&1 == 1:
    a, b = 1, N-1
    li.append([a, b])
    for i in range(min(M-1,(N-1)//2-1)):
        a += 1
        b -= 1
        li.append([a,b])
else:
    a, b = 1, N
    li.append([a,b])
    for i in range(min(M-1,(N-1)//2-1)):
        a += 1
        b -= 1
        if b - a <= N+a-b and - b + a + N+a-b <= 2:
            b -= 1
        li.append([a,b])
for x in li:
    print(*x)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

ansl = []

start = n // 2
end = n // 2 + 1
for i in range(m):
    if n % 2 == 0 and end - start + 2 * i >= n // 2:
        ansl.append((start - i-1, end + i))
    else:
        ansl.append((start-i, end+i))

for a,b in sorted(ansl):
    print(a,b)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = []
l1 = 1
l2 = 1 + M + 1
for i in range(M):
    now = M - i
    if i % 2 == 0:
        ans.append([l1, l1 + now])
        l1 += 1
    else:
        ans.append([l2, l2 + now])
        l2 += 1
for row in ans:
    print(row[0], row[1])

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
if N%2==1:
    for i in range(1,M+1):
        print(i,N-i)
else:
    ANS=[]
    for i in range(1,N//4+1):
        ANS.append((i,N//2-i))
    for i in range(1,N//4+1):
        ANS.append((N//2+i,N+1-i))

    check=0
    for a,b in ANS:
        if a!=b:
            print(a,b)
            check+=1

        if check==M:
            break

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if n % 2 == 1:
  n = 2*m+1
  for i in range(m):
    print(m-i,m+1+i)
else:
  n = 2*m+2
  for i in range(m):
    l = m-i
    r = m+1+i
    if r-l >= m+1:
      r += 1
    print(l,r)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

last_odd, last_even = m, m-1

if last_odd % 2 ==0:
    last_odd, last_even = last_even, last_odd
    

oddl = 1
oddr = oddl + last_odd

evenl = oddr + 1
evenr = evenl + last_even

while oddl < oddr:
    print(oddl, oddr)
    oddl += 1
    oddr -=1
while evenl < evenr:
    print(evenl, evenr)
    evenl += 1
    evenr -= 1

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
if N%2:
    x,y=N,1
    for i in range(M):
        print(x,y)
        x-=1
        y+=1
else:
    x,y=N,1
    for i in range(M):
        print(x,y)
        x-=1
        y+=1
        if x-y in (y+N-x,y+N-x-2):break
    x-=1
    for j in range(M-i-1):
        print(x,y)
        x-=1
        y+=1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
od = (m + 1) // 2
x = 2 * od + 1
for i in range(1, od + 1):
    print(i, x - i)
ev = m - od
y = 2 * ev
for i in range(m - od):
    print(x + i, x + y - i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=[1]*n
for i in range(1,n):
  if ans[i]==1:ans[n-i]=0
c=0
x=[]
for i in range(1,n):
  if ans[i]==1:
    if len(x)%2==0:x.append(n-i)
    else:x.append(i)
x.sort(reverse=1)
for i in range(m):print(i+1,i+1+x[i])

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


def inpl():
    return list(map(int, input().split()))


N, M = inpl()

if N % 2 == 1:
    for i in range(M):
        print(i + 1, N - i - 1)
else:
    if M == 1:
        print(1, 2)
    else:
        for i in range(M):
            a, b = i + 1, N - i
            if b - a <= N // 2:
                b -= 1

            print(a, b)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
idx = n//2
offset = 0
for i in range(m):
    if n%2==0 and (2*i+1)*2 >= n:
        offset = 1
    print(idx-i, idx+i+1+offset)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
b=m//2
a=m-b

for i in range(a):
    print(1+i,2*a-i)
for i in range(b):
    print(2*a+1+i,2*a+2*b+1-i)

Submission status: Accepted

Solution code:
N , M = map(int,input().split())
if N % 2 != 0:
    start = 1
    end = N
    for i in range(M):
        print(start,end)
        start += 1
        end -= 1
else:
    start = 1
    end = N
    judge = True
    for i in range(M):
        print(start,end)
        start += 1
        end -= 1
        if (end - start) <= N // 2 and judge:
            start += 1
            judge = False

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

if N % 2:
    for a in range(1, M + 1):
        b = N - a
        print(a, b)
else:
    even = min(N // 4, M)
    odd = M - even
    for a in range(1, 1 + even):
        b = N + 1 - a
        print(a, b)
    for a in range(even + 1, M + 1):
        b = N - a
        print(a, b)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

z = (N-1)//2
left = z//2
right = z - left

Ans = []
for i in range(left):
    Ans.append((i, i-2*(i+1)))
ss = 2*left+2*right-1
for i in range(right):
    st = left + i
    Ans.append((st, ss-st))

AA = []
for a, b in Ans[:M]:
    AA.append((a%N+1, b%N+1))

print('\n'.join(['{} {}'.format(*a) for a in AA]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if n%2 == 1:
	for i in range(m):
		print(i+1, n-i)
else:
	ans = []
	M = n//2-1
	for i in range((M+1)//2):
		ans.append((i+1, n-i))
	for i in range((M+1)//2, M+1):
		ans.append((i+1, n-i-1))
	for i in range(m):
		print(*ans[i])

Submission status: Accepted

Solution code:
def examA():
    K = I()
    A, B = LI()
    for i in range(A,B+1):
        if i%K==0:
            print("OK")
            return
    print("NG")
    return

def examB():
    X = I()
    now = 100
    ans = 0
    while(now<X):
        ans += 1
        now += now//100
    print(ans)
    return

def examC():
    N, M, Q = LI()

    ans = 0
    print(ans)
    return

def examD():
    A, B, N = LI()
    if N>=B-1:
        ans = (A*(B-1))//B
    else:
        ans = (A*N)//B
    print(ans)
    return

def examE():
    N, M = LI()
    ans = []
    if N%2==1:
        for i in range(N // 2):
            ans.append((i + 1, N - i))
    else:
        flag = False
        for i in range(N // 2):
            if N-i-(i+1)<=N//2:
                flag = True
            if flag:
                ans.append((i+1,N-i-1))
            else:
                ans.append((i + 1, N - i))
    #print(ans)
    for v in ans[:M]:
        print(" ".join(map(str,v)))
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
odd = m if m%2 else m-1 # m以下の最大の奇数
even = m-1 if m%2 else m # m以下の最大の偶数
mid = 1 + odd + 1 # 右半分の開始点

for i in range(1, (1+odd)//2+1):
    print(i, i+odd)
    odd -= 2
    
for i in range(mid, mid + even//2):
    print(i, i+even)
    even -= 2

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
for i in range(1, M+1):
    if N % 2 == 1:
        print(i, N+1-i)
    else:
        if i <= N//4:
            print(i, N+1-i)
        else:
            print(i, N-i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ANS = [[0] * 2 for i in range(m)]

a = 0
b = 1
c = 0
f = 1
for i in range(m):
    if n%2 == 0 and (c+2) > n//2 and f == 1:
        b = (b+1) % n
        f = 0
    ANS[i] = [a, b]
    c += 2
    a = (a-1) % n
    b = (b+1) % n
    

for i in range(m):
    print(ANS[i][0]+1, ANS[i][1]+1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
ans = []
a = N
b = 1
if N % 2 == 1:
    while a != b and M > 0:
        ans.append((a, b))
        a -= 1
        b += 1
        M -= 1
else:
    a = N
    b = 1
    for i in range(((N-2)//2+1)//2):
        if M == 0:
            break
        ans.append((a, b))
        a -= 1
        b += 1
        M -= 1
    a -= 1
    for i in range(((N-2)//2)//2):
        if M == 0:
            break
        ans.append((a, b))
        a -= 1
        b += 1
        M -= 1
for a, b in ans:
    print(a, b)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m = [int(i) for i in readline().split()]

x = m
y = m+1
if n%2==1:
    for i in range(m):
        print(x-i,y+i)
else:
    num = 0
    while 1+num*2 < n//2 and num < m:
        print(x-num,y+num)
        num += 1
    while num < m:
        print(x-num,y+num+1)
        num += 1

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
h = set()
mi = 0
for i in range(m):
    if n-i-mi-(i+1) in h:
        mi += 1
    if (n-i-mi) -(i+1) == (i+1+n) - (n-i-mi):
        mi += 1
    print(i+1, n-i-mi)
    h.add(n+i+1 - (n-i-mi))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b = 1, N
S = set()
for _ in range(M):
    print(a, b)
    S.add(b - a)
    S.add(a + N - b)
    a += 1
    b -= 1
    if b - a in S or a + N - b in S or b - a << 1 == N:
        b -= 1

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

even = M//2
odd = (M+1)//2
B = odd*2
K = B+even*2
ans = []
for n in range(1, odd+1):
    print(n, B-n+1)
for n in range(1, even+1):
    print(B+n, K-n+2)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())

odd = 0
even = 0

minimum_number = 0
maximum_number = 0

for i in range(m):
    number = i + 1
    if number % 2 == 1:
        minimum_number = 1 + odd
        maximum_number = (1+m) - odd
        odd += 1
    else:
        minimum_number = m + 2 + even
        maximum_number = 2 * m + 1 - even
        even += 1
    print("{} {}".format(minimum_number, maximum_number))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
if m == 1:
    print(1, 2)
else:
    l1 = 1
    r1 = l1 + m
    l2 = r1 + 1
    r2 = l2 + m - 1
    while True:
        if l1 >= r1:
            break
        print(l1, r1)
        if l2 >= r2:
            break
        print(l2, r2)
        l1 += 1
        l2 += 1
        r1 -= 1
        r2 -= 1

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
for i in range(m//2):
    print(1+i,m//1-i)
for i in range((m+1)//2):
    print(m//1+1+i,m*2+1-i)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,M = map(int, input().split())

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

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    if N & 1:
        for i in range(1, M+1):
            print(i, N - i)
    else:
        flg = 1
        for i in range(1, M+1):
            if flg:
                a = i
                b = N + 1 - i
                if b - a <= N - (b-a):
                    flg = 0
                    b -= 1
                print(a, b)
            else:
                print(i, N-i)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
printn = lambda x: print('\n'.join(x))

n, m = nm()
if n % 2:
    for i in range(m):
        print(i+1, m*2-i)
else:
    m2 = m // 2
    m1 = m - m2
    for i in range(m1):
        print(i+1, m1*2-i)
    for i in range(m2):
        print(i+1+m1*2, 2*m+1-i)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = []
p = 1
q = 2 * ((m + 1) // 2)
for i in range((m + 1) // 2):
    ans.append((p, q))
    p += 1
    q -= 1
p = 2 * ((m + 1) // 2) + 1
q = p + (m // 2) * 2
for i in range(m // 2):
    ans.append((p, q))
    p += 1
    q -= 1
for row in ans[:m]:
    print(row[0], row[1])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
done = 0
for i in range(1,m+1)[::-1]:
    if (m-i)&1:
        print(m+1+(m+1-i)//2,m+1+(m+1-i)//2+i)
    else:
        print((m-i)//2 + 1,(m-i)//2 + 1 + i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n%2==1:
  for i in range(m):
    print(str(i+1)+" ",str(n-i))
else:
  k=n//4
  for i in range(m):
    if i<k:
      print(str(i+1),str(n-i))
    else:
      print(str(i+2),str(n-i))

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

A = np.arange(M)
B = 2 * M - 1 - A
B[:M//2] -= (2*M+1)

A %= N
B %= N
A += 1
B += 1
for a, b in zip(A.tolist(), B.tolist()):
    print(a,b)