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
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache

import heapq






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N,M = inputIL()

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)

from collections import deque
import heapq
from itertools import combinations

n,m=map(int,input().split())
if n%2==1:
    for i in range(m):
        print(i+1,n-(i+1))
else:
    if n%4==0:
        p=m//2+1
    else:
        p=m//2
    for i in range(p):
        print(i+1,n-(i))
    for i in range(m-p):
        print(n//2-1-i,n//2+1+i)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    if(N&1):
        N+=1
        for i in range(M):
            print(i+1+1,N-i-2+1)
    else:
        used = set()
        for i in range(1,M+1):
            if(i<=N/4):
                print(i,N-i+1)
            else:
                print(i,N-i)

if __name__ == '__main__':
    main()

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

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

if N%2==0:
  for i in range(1,M+1):
    if i > N/4:
      print(f'{i+1} {N+1-i}')
    else:
      print(f'{i} {N+1-i}')
else:
  for i in range(1,M+1):
    print(f'{i} {N+1-i}')

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

k = (M + 1) // 2
s, e = 1, 2 * k
for _ in range(k):
    print(s, e)
    s, e = s + 1, e - 1

k = M // 2
s, e = N - 2 * k, N
for _ in range(k):
    print(s, e)
    s, e = s + 1, e - 1

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

a = 1
b = n

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

Solution (Python):
n, m = map(int, input().split())
center1 = (m+1) // 2
center2 = center1 + m
for i in range(m):
    if i % 2 == 0:
        a = center1 - i // 2
        b = center1 + i // 2 + 1
    else:
        a = center2 - i // 2
        b = center2 + (i+1) // 2 + 1
    print(f"{a} {b}")

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 i % 2 == 1:
      k = i // 2 
      print(k+1, N-k)
    else: 
      k = i // 2
      print( N // 2 + k, N // 2 - k)

Solution (Python):
N,M=map(int,input().split())
i=0
K=M
while K>0:
    if (M-K)%2==0:
        print(i//2+1,i//2+1+K)
    else:
        print(M+2+(i-1)//2,M+2+(i-1)//2+K)
    K-=1
    i+=1

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

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

Solution (Python):
def resolve():
    n, m = map(int, input().split())
    if n % 2 == 0:
        x = (m + 1) // 2
        for i in range(x):
            print(x - i, x + i + 1)
        x = m // 2
        for i in range(x):
            print(n - (x - i - 1), n - (x + i + 1))
    else:
        for i in range(m):
            print(i + 1, n - i)


if __name__ == '__main__':
    resolve()

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

for i in range(2,m+1,2):
    ans.append([n-(i//2),(i//2)])
for i in range(1,m+1,2):
    ans.append([n//2-(i-1)//2,n//2+1+(i-1)//2])
for i in range(m):
    print(*ans[i])

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

Solution (Python):
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq

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



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

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

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 i <= N // 4:
            print(*[i, N-i+1])
        else:
            print(*[i, N-i])

Solution (Python):
N,M=map(int,input().split())
if N%2:
    for i in range(1,M+1):
        print(i,N-i)
else:
    if N==4:
        print(2,3)
    else:
        t=1
        l=[]
        a,b=1,N
        while a<b:
            l.append((a,b))
            a+=1
            b-=1
            if N//2>=b-a and t:
                b-=1
                t=0
        for i in range(M):
            print(*l[i])

Solution (Python):
n,m=map(int,input().split())
if n%2==0:
  counter=0
  for i in range(min(m,n//4)):
    print(i+1)
    print(n-i)
    counter+=1
  if counter<m:
    for i in range(n//4,m):
      print(i+1)
      print(n-i-1)
else:
  for i in range(m):
    print(i+1)
    print(n-i)

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

l = m // 2 * 2 + 1
for i in range(1, l + 1):
    if i < l - i + 1:
        print(i, l - i + 1)

r = (m + 1) // 2 * 2 + l
for i in range(l + 1, r + 1):
    if i < r - i + l + 1:
        print(i, r - i + l + 1)

Solution (Python):
def solve(n, m):
    res_list = []
    if n % 2 == 1:
        for i in range(m):
            res_list.append([i + 1, 2 * m - i])
    else:
        k = (m + 1) // 2
        for i in range(k):
            res_list.append([i + 1, 2 * k - i])
        for i in range(m - k):
            res_list.append([2 * k + i + 1, 2 * m + 1 - i])
    return res_list


def main():
    n, m = map(int, input().split())
    res = solve(n, m)
    for r in res:
        print(" ".join([str(a) for a in r]))


def eval_res(n, ab_list):
    eval_dict = dict()
    for a, b in ab_list:
        d = (a - b) % n
        if d in eval_dict.keys():
            return False
        eval_dict[d] = 1
        d = (b - a) % n
        if d in eval_dict.keys():
            return False
        eval_dict[d] = 1
    return True


def test():
    assert eval_res(4, solve(4, 1))
    assert eval_res(7, solve(7, 3))


if __name__ == "__main__":
    test()
    main()

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

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

Solution (Python):
n,m=map(int,input().split())
list=list(range(1,n+1))
if n%2==1:
  for i in range(m):
    print(list[i],list[-1-i])
elif n%4==0:
  h=n//2
  hh=n//4
  if hh>=m:
    for i in range(m):
      print(list[i],list[-1-i])
  else:
    for i in range(hh):
      print(list[i],list[-h-1-i])
    for i in range(m-hh):
      print(list[h+i],list[-2-i])
else:
  h=n//2
  hh=(h-1)//2
  if hh>=m:
    for i in range(m):
      print(list[i],list[-1-i])
  else:
    for i in range(hh):
      print(list[i],list[-h-1-i])
    for i in range(m-hh):
      print(list[h+i],list[-2-i])

Solution (Python):


import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int):
    if N % 2 == 1:
        s = N // 2
        for i in range(M):
            v = i * 2 + 1
            print(s, s + v)
            
            s -= 1
    else:
        s = N // 2
        cnt = 0
        used = set()
        for i in range(M // 2 + 1):
            v = i * 2 + 1
            if v == N // 2 or v in used:
                continue
            print(s, s + v)
            
            s -= 1
            cnt += 1
            used.add(v)
            used.add(N - v)
        s = 1
        for i in range(M - cnt):
            v = N - s - s
            print(s, N - s)
            
            s += 1
    return

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()))
s = 1
if N%2==0:
    t = N
    flag = 0
    for i in range(M):
        if (flag==0)and(s>N//4):
            s+=1
            flag =1
        print(s,t)
        s += 1
        t += -1
else:
    t = N-1
    for i in range(M):
        print(s,t)
        s += 1
        t += -1

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

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

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    from math import gcd

    
    

    n,m = map(int, input().split())
    res = []
    kisuu = n
    guusuu = n//2
    for i in range(1, m+1):
        if i%2 == 1:
            res.append([(kisuu+i)%n, kisuu])
            kisuu -= 1
        else:
            res.append([guusuu, guusuu+i])
            guusuu -= 1
    for a,b in res:
        print(a,b)


if __name__ == '__main__':
    main()

Solution (Python):
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, math.floor(int(n/4)))):
        print(i+1, n-i)
    for i in range(max(0, m-math.floor(int(n/4)))):
        print(i+1+min(m, math.floor(int(n/4))), n-i-min(m, math.floor(int(n/4)))-1)

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

for i in range(m):
  if n / 2 == 2 * i + 1 or 4 * i == n:
    e = 1
  print(str(n // 2 - i) + " " + str(n // 2 + 1 + i + e))

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

if N % 2 == 0:
	N -= 1

H = N // 2
if H % 2 == 1:
	H += 1

m = 0
i = 1
while m < M:
	print(i, H - i + 1)
	i += 1
	m += 1
	if i >= H - i + 1:
		break

i = 1
while m < M:
	print(H + i, N + 1 - i)
	i += 1
	m += 1

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    if N%2==1:
        left=1
        right=N-1
        for _ in range(M):
            print(left,right)
            left+=1
            right-=1
    else:
        for right in [N,N-1]:
            ans=[]
            f=True
            left=1
            for i in range(1,M+1):
                if (right-left)*2==N:
                    break
                ans.append((left,right))
                left+=1
                right-=1
                if right-left<=N//2 and f:
                    right-=1
                    f=False
            else:
                for a in ans:
                    print(*a)
                exit()
            
    

if __name__ == '__main__':
    main()

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

if n %2 == 0:
    left = 1
    right = 2*m+1
    al = set()
    for i in range(m):
        if right -left in al:
            right -= 1
        if right-left == n//2:
            right -= 1
        print(left,right)
        outs = n - (right-left)
        al.add(outs)
        left += 1
        right -= 1

else:
    left = 1
    right = 2*m
    for i in range(m):
        print(left,right)
        left += 1
        right -= 1

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7

n,m = get_nums_l()
if n%2 == 1:
    for l in range(1,m+1):
        r = n - l + 1
        print(l, r)
else:
    
    for l in range(1,m+1):
        r = n - l + 1
        if r-l <= n//2:
            r-=1
        print(l, r)

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

from collections import defaultdict
d = defaultdict(int)
a=1
b=n

def nxt(a,b):
    b-=1
    while True:
        a+=1
        if b-a != n-b+a and d[b-a] != 1 and d[n-b+a] != 1:
            break
    d[b-a]+=1
    d[n-b+a]+=1
    return a,b


for i in range(m):
    print(a,b)
    a,b = nxt(a,b)

Solution (Python):
n,m=map(int,input().split())
ans=[]
for i in range(m):
  ans.append([i+1,2*m-i])
if n%2==0:
  ans.reverse()
  flag=0
  for i in range(len(ans)):
    if ans[i][1]-ans[i][0]>=n//2:
      flag=1
    if flag==1:
      ans[i][1]+=1
  ans.reverse()
for i in range(len(ans)):
  print(ans[i][0],ans[i][1])

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m = map(int,input().split())
if n % 2 == 1:
  a = 1; b = n
  for i in range(m):
    print(a,b)
    a += 1;b -= 1
else:
  a = 1; b = n
  tmp = n
  while b-a > n//2:
    print(a,b)
    a += 1
    b -= 1
    count += 1
    if count >= m:exit()
  b-=1
  for i in range(m-count):
    print(a,b)
    a += 1
    b -= 1

Solution (Python):
n,m=map(int,input().split())
l=[]
if n%2==0:
  i=1
  while i<n//2+1-i:
    l.append((i,n//2+1-i))
    i+=1
  j=1
  while j<n//2-j:
    l.append((n//2+j,n-j))
    j+=1
else:
  for i in range(1,n//2+1):
    l.append((i,n-i))
for a,b in l[:m]:
  print(a,b)

Solution (Python):
N, M = list(map(int,input().split()))
base = N
if N%2==1:
  for i in range(1,M+1):
    print(i,base-i)
else:
  if N%4==0:
    candidate = []
    for i in range(1,N//4+1):
      candidate.append((i,N+1-i))
    for i in range(N//4+1,N//2):
      candidate.append((i,N-i))
  else:
    candidate = []
    for i in range(1,N//4+1):
      candidate.append((i,N+1-i))
    for i in range(N//4+1,N//2):
      candidate.append((i,N-i))
  for i in range(M):
    a,b = candidate[i]
    print(a,b)

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

ans = []

q = []

for i in range(1,M+1):

    if i % 2 == 1:
        q.append(N-i)
    else:
        q.append(i)

q.sort()
ind = 0
q.reverse()
q.append(float("inf"))
ind = 0

use = [True] * (N+1)

cnt = 0
for i in range(1,N//2+1):

    if use[i + q[ind]]:
        print (i , i+q[ind])
        ind += 1
        cnt += 1

    if cnt == M:
        sys.exit()

Solution (Python):

"""
Created on Sat May  2 21:39:58 2020
"""

import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


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







odd = (N % 2 != 0)
ans = []
if odd:
    x = N - 1
    for i in range(M):
        ans.append([i+1,x])
        x -= 1
else:
    x = N
    flg = True
    for i in range(M):
        if flg and x - (i+1) <= N//2:
            x -= 1
            flg = False
        ans.append([i+1,x])
        x -= 1





for a in ans:
    print(' '.join(map(str,a)))

Solution (Python):
def solve(N, M):
  U = [False]*N
  a = 1
  b = N
  ans = []
  for i in range(M):
    while U[b-a] or U[a+N-b] or (b-a)*2==N:
      b -= 1
    ans += [(a, b)]
    U[b-a] = U[a+N-b] = True
    a += 1
    b -= 1
  return ans

def check(N, M, ans):
  S = set()
  for i in range(N):
    for a in ans:
      s = tuple(sorted(((a[0]+i)%N, (a[1]+i)%N)))
      if s in S:
        return False
      S.add(s)
  return True

"""
for M in range(1, 10):
  for N in range(M*2+1, 100):
    ans = solve(N, M)
    if not check(N, M, ans):
      print(N, M)
      exit(0)
"""

N, M = map(int, input().split())
for a, b in solve(N, M):
  print(a, b)

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

Solution (Python):

MOD = 10 ** 9 + 7

def main():
    for _ in inputt(1):
        N, M = inputi()
        if N % 2:
            for i in range(M):
                print(i + 1, N - i)
        else:
            for i in range(M):
                if i % 2:
                    print((N - i) // 2, (N + i + 1) // 2)
                else:
                    print(i // 2 + 1, N - i // 2)






from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)





BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.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(io.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")
def print(*args, **kwargs):
    if args:
        sys.stdout.write(str(args[0]))
        split = kwargs.pop("split", " ")
        for arg in args[1:]:
            sys.stdout.write(split)
            sys.stdout.write(str(arg))
    sys.stdout.write(kwargs.pop("end", "\n"))
def debug(*args, **kwargs):
    print("debug", *args, **kwargs)
    sys.stdout.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda k = int: map(k, inputs())
inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k())





def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError






class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass





class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        if n <= self._list[-1]: return
        maxbase = int(n ** 0.5) + 1
        self.extend(maxbase)
        begin = self._list[-1] + 1
        newsieve = [i for i in range(begin, n + 1)]
        for p in self.primerange(2, maxbase):
            for i in range(-begin % p, len(newsieve), p):
                newsieve[i] = 0
        self._list.extend([x for x in newsieve if x])
    def extend_to_no(self, i):
        while len(self._list) < i: 
            self.extend(int(self._list[-1] * 1.5))
    def primerange(self, a, b):
        a = max(2, a)
        if a >= b: return
        self.extend(b)
        i = self.search(a)[1]
        maxi = len(self._list) + 1
        while i < maxi:
            p = self._list[i - 1]
            if p < b:
                yield p
                i += 1
            else: return
    def search(self, n):
        if n < 2: raise ValueError
        if n > self._list[-1]: self.extend(n)
        b = bisect(self._list, n)
        if self._list[b - 1] == n: return b, b
        else: return b, b + 1
    def __contains__(self, n):
        if n < 2: raise ValueError
        if not n % 2: return n == 2
        a, b = self.search(n)
        return a == b
    def __getitem__(self, n):
        if isinstance(n, slice):
            self.extend_to_no(n.stop + 1)
            return self._list[n.start: n.stop: n.step]
        else:
            self.extend_to_no(n + 1)
            return self._list[n]

sieve = Sieve()
def isprime(n):
    if n <= sieve._list[-1]:
        return n in sieve
    for i in sieve:
        if not n % i: return False
        if n < i * i: return True
prime = sieve.__getitem__
primerange = lambda a, b = 0: sieve.primerange(a, b) if b else sieve.primerange(2, a)
def factorint(n):
    factors = []
    for i in sieve:
        if n < i * i: break
        while not n % i:
            factors.append(i)
            n //= i
    if n != 1: factors.append(n)
    return factors
factordict = lambda n: Counter(factorint(n))





if __name__ == "__main__":
    main()

Solution (Python):
n, m = [int(i) for i in input().split()]
i = 0
j = 1
k = 0
while j < n//2 and k < m:
    print(i % n + 1, (i + j) % n + 1)
    i -= 1
    j += 2
    k += 1
i = (i + j - 1 + (m - k)) % n
j = 2
while k < m:
    print(i % n + 1, (i + j) % n + 1)
    i -= 1
    j += 2
    k += 1