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

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M = lr()
    if N%2 == 1:
        for i in range(0, M):
            print(f'{2+i} {1+2*M-i}')
    else:
        k = N//4
        for i in range(M):
            if i < k:
                print(f'{i+1} {N-i}')
            else:
                print(f'{i+2} {N-i}')
resolve()

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

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

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

a = 1
b = m + 1
while a < b:
  print(a, b)
  a += 1
  b -= 1

a = m + 2
b = 2 * m + 1
while a < b:
  print(a, b)
  a += 1
  b -= 1

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

a = 1
b = m - 1
c = m
d = [i for i in range(n + 1)]

for i in range(m):
    if m % 2 == 0 and i < m / 2:
        print(d[a], d[a+b])
        print(d[-a-c],d[-a])
        a = a + 1
        b = b - 2
        c = c - 2

    elif m % 2 != 0 and i < m / 2:
        print(d[-a-c],d[-a])
        if i == (m + 1) / 2 - 1:
            break
        print(d[a], d[a+b])
        a = a + 1
        b = b - 2
        c = c - 2

Solution (Python):
def main():
    n, m = map(int, input().split())
    ans = []
    t = [True]*(n+1)
    l = n//2 - 1
    for i in range(1, n//2):
        if l <= 0:
            break
        if not t[i] or not t[i+l]:
            continue
        ans.append([i, i+l])
        t[i] = False
        t[i+l] = False
        l -= 2
    if n % 2 == 1:
        l = n//2
        for i in range(n//2, n):
            if l <= 0:
                break
            if not t[i] or not t[i+l]:
                continue
            ans.append([i, i+l])
            t[i] = False
            t[i+l] = False
            l -= 2
    else:
        l = n//2 - 2
        for i in range(n//2, n):
            if l <= 0:
                break
            if not t[i] or not t[i+l]:
                continue
            ans.append([i, i+l])
            t[i] = False
            t[i+l] = False
            l -= 2
    for i in range(m):
        print(ans[i][0], ans[i][1])

if __name__ == "__main__":
    main()

Solution (Python):
N,M = map(int,input().split())
k = 0
t = 0
j = 0
before = N
for i in range(1,M+1):
    if N - before + i == N//2 and N%2 == 0:
        j = 1
    else:
        if N - before + t + i == k:
            t = 1
        k = before - t - i
        print(i,before-t)
        before -= 1
if j == 1:
    i += 1
    print(i,before-t)

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

a = 1
b = 1+M

while(a < b) :
  print(a, b)
  a += 1
  b -= 1

a = M+2
b = 2*M+1
while(a < b) :
  print(a, b)
  a += 1
  b -= 1

Solution (Python):
N,M = list(map(int,input().strip().split()))

K = N//2
ans = []

if N == 3:
    ans = [(1,2)]
elif N == 4:
    ans = [(1,2)]
elif N == 5:
    ans = [(1,2),(3,5)]
else:
    left = 1
    right = K
    while left<right:
        ans += [(left,right)]
        left+=1
        right-=1

    left = K+1
    right = N
    if (right-left)%2 == (K-1)%2:
        right -= 1
    while left<right:
        ans += [(left,right)]
        left += 1
        right -= 1

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

Solution (Python):

import numpy as np
n, m = list(map(int, input().split()))
lists = list(np.arange(1, n+1))
list1 = lists[:m]
list2 = lists[m:]
num = m
for i in range(m//2 +1):
    if num == 0:
        break
    print(list2[i],list2[m+1-i-1])
    num -= 1
    if num == 0:
        break
    print(list1[i],list1[m-i-1])
    num -= 1

Solution (Python):


n,m = map(int,input().split())
point_s = 0
point_e = n + 1

if n % 2 == 0:
    for i in range(1,m+1):
        point_s += 1
        point_e -= 1
        print("{} {}".format(point_s,point_e))
        if n % 4 == 0 and (point_e - point_s - 1) * 2 == n:
            point_e -= 1
        elif n % 4 != 0 and (point_e - point_s - 1) * 2 == n + 2:
            point_e -= 1
elif n % 2 == 1:
    for i in range(1,m+1):
        point_s += 1
        point_e -= 1
        print("{} {}".format(point_s,point_e))

Solution (Python):
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

head = 1
tail = N

while head <= M:
    if (N % 2 == 0 and tail - head == N // 2) or (N % 4 == 0 and tail - head == N // 2 - 1):
        tail -= 1
    print(head, tail)
    head += 1
    tail -= 1

Solution (Python):


import sys


def solve(N: int, M: int):
    f = M % 2 == 0
    for i in range(M//2):
        print(f'{i+1} {M-i+f}')
    for i in range((M+1)//2):
        print(f'{M+i+1+f} {2*M-i+1}')


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    solve(N, M)


if __name__ == '__main__':
    main()

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

if n % 2 == 1:
    for i in range(m):
        print("{} {}".format(2 + i, n - i))
else:
    for i in range(m):
        if i % 2 == 0:
            print("{} {}".format(int(n / 2 - i / 2), int(n / 2 + 1 + i / 2)))
        else:
            print("{} {}".format(int(2 + i // 2), int(n - i // 2)))

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

def dist(a,b):
  return min(abs(a-b),n-abs(a-b))

a,b = n,1
S=set()
for i in range(m):
  distab = dist(a,b)
  
  if 2*distab == n or distab in S:
    a -= 1
  print(a,b)
  S.add(distab)
  a -= 1
  b += 1

Solution (Python):

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


A = [int(i) for i in range(N)]

B = [] 

if N % 2 == 0:
    

    center = N // 2
    c1 = center // 2
    c2 = center + c1
    

    for i in range(1, M+1):
        
        j = i // 2
        
        if i % 2 == 1:
            B.append((c1-j, c1+j+1))
        else:
            B.append((c2-(j-1), c2 - (j-1) + 2*j ))

else:
    

    center = N // 2 + 1
    
    for i in range(1, M+1):
        B.append((center - i, center + i))
        
for i in B:
    print(i[0], i[1])

Solution (Python):

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


A = [int(i) for i in range(N)]

B = [] 

if N % 2 == 0:
    

    center = N // 2
    c1 = center // 2
    c2 = center + c1
    

    for i in range(1, M+1):
        
        j = i // 2
        
        if i % 2 == 1:
            B.append((c1-j, c1+j+1))
        else:
            B.append((c2-(j-1), c2 - (j-1) + 2*j ))

else:
    

    center = N // 2 + 1
    
    for i in range(1, M+1):
        B.append((center - i, center + i))

for i in B:
    print(i[0], i[1])

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

ans = []

for i in range(M):
    if N % 2 != 0 or (M + (i + 1)) - (M - (i)) < N // 2:
        tmp = [str(M - (i)), str(M + (i + 1))]
    else:
        tmp = [str(M - (i)), str(M + (i + 2))]
    tmp = ' '.join(tmp)
    ans.append(tmp)
print(*ans, sep='\n')

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

def dist(a, b):
    return min(abs(a - b), n - abs(a - b))

a, b = n, 1
S = set()
for i in range(m):
    if 2 * dist(a, b) == n or dist(a, b) in S:
        a -= 1
    print(a, b)
    S.add(dist(a, b))
    a -= 1
    b += 1

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

def ark(a, b):
    return min(abs(a - b), n - abs(a - b))

a, b = n, 1
S = set()
for i in range(m):
    if 2 * ark(a, b) == n or ark(a, b) in S:
        a -= 1
    print(a, b)
    S.add(ark(a, b))
    a -= 1
    b += 1

Solution (Python):
n, m = map(int, input().split())
a, b = n, 1
V = [False for d in range(1, n + 1)]
for i in range(m):
    d = min(a - b, n - (a - b))
    if 2 * d == n or V[d]:
        a -= 1
    print(a, b)
    d = min(a - b, n - (a - b))
    V[d] = True
    a -= 1
    b += 1

Solution (Python):

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

if(N % 2 == 1):
    pairs = []
    s = 2
    g = N
    for i in range(M):
        pairs.append([s, g])
        s += 1
        g -= 1
elif(N % 4 != 0):
    MAX = int(N/2) - 1
    half = int(MAX/2)
    pairs = []
    s = 1
    g = N
    for i in range(half):
        pairs.append([s, g])
        s += 1
        g -= 1
    g -= 1
    for i in range(half):
        pairs.append([s, g])
        s += 1
        g -= 1
else:
    odd_pairs = int(N/4)
    even_pairs = odd_pairs - 1
    pairs = []
    s = 1
    g = N
    for i in range(odd_pairs):
        pairs.append([s, g])
        s += 1
        g -= 1
    g -= 1
    for i in range(even_pairs):
        pairs.append([s, g])
        s += 1
        g -= 1







for i in range(M):
    print('{} {}'.format(pairs[i][0], pairs[i][1]))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M = LI()
    used = [0 for _ in range(N)]
    cur = 0
    pairs = []
    used = set()
    if N % 2 == 0:
        a = 1
        b = N
        while len(pairs) < M:
            if b-a in used or N + a -b in used or b - a == N//2:
                b -= 1
            pairs.append((a, b))
            used.add(b-a)
            used.add(N+a - b)
            a += 1
            b -= 1

    else:
        a = 1
        b = N - 1
        while len(pairs) < M:
            pairs.append((a, b))
            a += 1
            b -= 1
    for p in pairs:
        print(p[0], p[1])



main()

Solution (Python):
n,m = map(int,input().split())
if(n % 2 == 0):
    d = n // 2 - 1
    c = 0
    i = 1
    while(d > 0):
        print(i,i+d)
        d -= 2
        i += 1
        c += 1
        if(c == m):exit()
    d = n // 2 - 2
    i = n // 2 + 1
    while(d > 0):
        print(i,i+d)
        d -= 2
        i += 1
        c += 1
        if(c == m):exit()


else:
    for i in range(m):
        print(i+1,n-i)

Solution (Python):
N,M=list(map(int, input().split()))
src=[i+1 for i in range(M*2+1)]
if M%2==0:
  for m in range(M//2):
    a=src[m]
    b=src[M-m]
    print('{} {}'.format(a,b))
  for m in range(M//2):
    a=src[M+1+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))
else:
  for m in range(M//2):
    a=src[m]
    b=src[M-1-m]
    print('{} {}'.format(a,b))
  for m in range(M-(M//2)):
    a=src[M+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))

Solution (Python):
N,M=list(map(int, input().split()))
src=[i+1 for i in range(M*2+1)]
if M%2==0:
  for m in range(M//2):
    a=src[m]
    b=src[M-m]
    print('{} {}'.format(a,b))
  for m in range(M//2):
    a=src[M+1+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))
else:
  for m in range(M//2):
    a=src[m]
    b=src[M-1-m]
    print('{} {}'.format(a,b))
  for m in range(M-(M//2)):
    a=src[M+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))

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

for i in range(1, M + 1):
    if i % 2 == 1:
        j = (i - 1) // 2
        print(1 + j, M + 1 - j)
    else:
        j = (i - 2) // 2
        print(M + 2 + j, 2 * M + 1 - j)

Solution (Python):
N,M=map(int,input().split())
ans=[]
if N%2==1:
  for i in range(M):
    ans.append([i+1,N-i])
else:
  for i in range(M//2):
    ans.append([i+1,2*M-i+1])
  for j in range(M-M//2):
    ans.append([j+M//2+1,2*M-M//2-j])
for k in ans:
  print(*k,sep=' ')

Solution (Python):

from sys import stdin, stdout
import math
import bisect
from collections import defaultdict
import datetime
import random




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

if m == 1:
    stdout.writelines('1 2\n')
else:
    m1 = m // 2
    m2 = m - m1
    a = m2
    b = a + 1
    for i in range(m2):
        stdout.writelines('%d %d\n' % (a, b))
        a -= 1
        b += 1
    a = b
    b = a + m1 * 2
    for i in range(m1):
        stdout.writelines('%d %d\n' % (a, b))
        a += 1
        b -= 1

Solution (Python):
N, M = map(int, input().split())
 
if M % 2 == 0:
  l = 1
  for i in range(M//2):
    L = []
    L.append(l)
    L.append(2*(M//2-i)+l)
    print(*L)
    l += 1
  l = 2*(M//2)+2
  for i in range(M//2):
    L = []
    L.append(l)
    L.append(2*(M//2-i)+l-1)
    print(*L)
    l += 1
  
  
elif M % 2 == 1:
  l = 1
  for i in range(M//2):
    L = []
    L.append(l)
    L.append(2*(M//2-i)+l)
    print(*L)
    l += 1
  l = 2*(M//2)+2
  for i in range(M//2+1):
    L = []
    L.append(l)
    L.append(2*(M//2+1-i)+l-1)
    print(*L)
    l += 1

Solution (Python):
n, m = map(int, input().split())
if n%2 == 1:
    l = 1
    r = n-1
    for i in range(m):
        print(l, r)
        l += 1
        r -= 1
else:
    l = 1
    r = n-1
    flag = False
    for i in range(m):
        if (not flag) and r-l <= n//2:
            r -= 1
            flag = True
        print(l, r)
        l += 1
        r -= 1

Solution (Python):
n, m = map(int, input().split())
if n%2 == 1:
    l = 1
    r = n-1
    for i in range(m):
        print(l, r)
        l += 1
        r -= 1
else:
    l = 1
    r = n-1
    flag = False
    for i in range(m):
        if (not flag) and r-l <= n//2:
            r -= 1
            flag = True
        print(l, r)
        l += 1
        r -= 1

Solution (Python):
import math

n, m = map(int, input().split(" "))

start = 1
end = n

wq = n // 4
for i in range(m):
    if i == wq and n % 2 == 0:
        start += 1
    print(start, end)
    start += 1
    end -= 1

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

x=list(range(1,N+1,1))

if N%2==1:
    for i in range(M):
        print(x.pop(0),x.pop(-1))
        
else:
    x_f=x[1:int(N/2+1)]
    x_l=x[int(N/2+1):]
    
    count=0
    
    for i in range(M):
        if len(x_f)>1:
            print(x_f.pop(0),x_f.pop(-1))
            count+=1
            
        if count==M:
            break
        
        if len(x_l)>1:
            print(x_l.pop(0),x_l.pop(-1))
            count+=1
            
        if count==M:
            break

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


result=[]
if m%2==1:
    j=1
    for i in range(m//2):
        result.append((j,2*(m//2-i)+j))
        j+=1
    j=2*(m//2)+2
    for i in range(m//2+1):
        result.append((j,2*(m//2+1-i)+j-1))
        j+=1

else:
    j=1
    for i in range(m//2):
        result.append((j,2*(m//2-i)+j))
        j+=1
    j=2*(m//2)+2
    for i in range(m//2):
        result.append((j,2*(m//2-i)+j-1))
        j+=1

    
for item in result:
    print(item[0],item[1])

Solution (Python):
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, M+1):
        if N-2*i <= N//2:
            print(i, N-i-1)
        else:
            print(i, N-i)

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

import math
ans = []
if M == 1:
    ans.append((1, 2))
else:
    m0 = (1, M+1)
    m1 = (M+2, 2*M+1)
    for _ in range(math.ceil(M/2)):
        if m0[0] < m0[1]:
            ans.append(m0)
        if m1[0] < m1[1]:
            ans.append(m1)
        m0 = (m0[0]+1, m0[1]-1)
        m1 = (m1[0]+1, m1[1]-1)

for a in ans:
    print(a[0], a[1])

Solution (Python):
import numpy as np
N,M=map(int,input().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 i in range(M):
  print(A[i],B[i])

Solution (Python):

n, m = map(int, input().split())
ans = []
i = 1
while i < m + 2 - i:
    ans.append([i, m + 2 - i])
    i += 1
i = m + 2
while i < 3 * m + 3 - i:
    ans.append([i, 3 * m + 3 - i])
    i += 1
for i in ans:
    print(*i)

Solution (Python):
N,M = map(int,input().split())
if N % 4 in [1,2]:
    odd_pair = [N//2//2 , N//2//2+1]
    even_pair = [N-N//2//2-1,N-N//2//2+1]
elif N%4==3:
    odd_pair = [N-N//2//2-1 , N-N//2//2]
    even_pair = [N//2//2,N//2//2+2]
elif N%4==0:
    odd_pair = [N-N//2//2 , N-N//2//2+1]
    even_pair = [N//2//2,N//2//2+2]
cnt = 0
while True:
    print(*odd_pair)
    cnt += 1
    if cnt == M:
        break
    odd_pair[0] -= 1
    odd_pair[1] += 1
    print(*even_pair)
    cnt += 1
    if cnt == M:
        break
    even_pair[0] -= 1
    even_pair[1] += 1

Solution (Python):
import math

nums = [int(e) for e in input().split()]
n = nums[0]
m = nums[1]

x = -1
y = -1

ms = []

if n%2 == 0:
    x = 1
    y = n
    count = True

    while x < y:
        if y-x <= n/2 and count:
            y -= 1
            count = False
        ms += [[x,y]]
        x += 1
        y -= 1


else:
    x = 1
    y = n
    while x < y:
        ms += [[x, y]]
        x += 1
        y -= 1




for i in range(m):
    print(str(ms[i][0]) + " " + str(ms[i][1]))

Solution (Python):
N, M = map(int, input().split()) 
ans = []
if M % 2 != 0:
    for i in range((M + 1)//2):
        ans.append((1 + i, M + 1 - i))
        
    for j in range((M - 1)//2):
        ans.append((M + 2 + j, 2*M + 1 - j))
else:
    for i in range(M//2):
        ans.append((1 + i, M + 1 - i))
        ans.append((M + 2 + i, 2*M + 1 - i))
              
for i in range(M):
    print(*ans[i])