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):
n,m=map(int,input().split())
if n%4==0:
  l=m//2+1
else:
  l=m//2
if n%2==0:
  for i in range(l):
    print(i+1,n-i)

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

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

    
    
    
    
    
    
    



    i = 0
    j = 0
    cnt = 0
    d = set()
    ans = []
    while cnt < M:
        d1 = N - i * 2 - j - 1
        d2 = N - d1
        if d1 in d or d2 in d or d1 * 2 == N or d2 * 2 == N:
            j += 1
            continue
        ans.append((1 + i + j, N - i))
        d.add(d1)
        d.add(d2)
        cnt += 1
        i += 1

    for row in ans:
        print(*row)

if __name__ == '__main__':
    main()

Solution (Python):
n,M =map(int,input().split())
s=0
t=1
list1=[]
list2=[]
u=0
if M==1:
    print("1 2")
else:    
    while s< M:
        while (t<=((n+1)//2)//2 and s<M):
            lis=t
            list1.append(lis)
            lis2=(n+1)//2+1-t
            list2.append(lis2)
            t+=1
            s+=1
        lis=(n+1)//2+1+u
        list1.append(lis)
        lis2=2*((n+1)//2)-1-u
        list2.append(lis2)
        u+=1
        s+=1
    for i in range(0,M):
        print(list1[i],list2[i])

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

halfPos = -(-N//2)

qPos = halfPos // 2

q3Pos = qPos + halfPos

for m in range(1, M+1):
  if m % 2:
    print(qPos-m//2, qPos+m//2+1)
  else:
    print(q3Pos-m//2, q3Pos+m//2)

Solution (Python):
n,m=map(int,input().split())
ans=[]
if n%2==1:
    for j in range(m):
        ans.append(((n-1)//2 - j, (n+1)//2 +j))
else:
    w = (n//2)//2
    u = (n//2)-1 -w
    
    for j in range(w):
        p,q = n//2-1 -j,n//2 +j
        ans.append((p,q))
        
    for j in range(1,u+1):
        ans.append((p-j,q+1+j))
for i in range(m):
    print(*ans[i])

Solution (Python):
def main():
    n, m = map(int, input().split())
    n2 = n//2
    if n%2:
        for i in range(1, m+1):
            print(i, n-i+1)
    else:
        for i in range(1, m+1):
            if n+1-2*i <= n2:
                print(i, n-i)
            else:
                print(i, n-i+1)
                
    
    
if __name__ == "__main__":
    main()

Solution (Python):
n,m = [int(i) for i in input().split()]

if n % 2 == 1:
  a=1
  b=2*m

  for _ in range(m):
    print(a, b)
    a += 1
    b -= 1
else:
  a = 1
  th = n-1
  count = 0
  half = n//2
  flag = True
  while True:
    if flag and th <= half:
      th -= 1
      flag = False
    count += 1
    print(a, a+th)
    a += 1
    th -= 2
    if count == m:
      break

Solution (Python):


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

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

Solution (Python):

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


b=(n-1)//2
a=b//2
ll=[[0,0]for i in range(b)]
ll[0]=[1,2]

if b//2==b/2:
    for i in range(1,b):
        if i//2!=i/2:
            ll[i]=[2+a-(i//2),2+a-(i//2)+i+1]
        else:
            if i==b-2:
                ll[i]=[3+b//2,3+b//2+b-2+1]
            else:
                ll[i]=[3+b//2+b-2+1-i//2,3+b//2+b-2+1-i//2+i+1]
else:
    for i in range(1,b):
        if i//2==i/2:
            ll[i]=[3+b//2-i//2,3+b//2-i//2+i+1]
        else:
            if i==b-2:
                ll[i]=[3+b//2+1,3+b//2+b-1+1]
            else:
                ll[i]=[3+b//2+b-1+1-(i+1)//2,3+b//2+b-1+1-(i+1)//2+i+1]            

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

Solution (Python):
N, M = map(int, input().split())
d = (N-1)//2
ans = []

while d>0:
    if len(ans)==0:
        ans.append((0, d))
    else:
        a, b = ans[-1]
        ans.append((a+1, b-1))
    
    if len(ans)==M:
        for a, b in ans:
            print(a+1, b+1)
        exit()
        
    d -= 2

d = (N-1)//2
ans.append((d+1, d+1+(d-1)))

if len(ans)==M:
    for a, b in ans:
        print(a+1, b+1)
    exit()

while True:
    a, b = ans[-1]
    ans.append((a+1, b-1))
    
    if len(ans)==M:
        for a, b in ans:
            print(a+1, b+1)
        exit()

Solution (Python):
N, M = map(int, input().split())
if N % 2 == 1:
    for a, b in zip(range(1, M+1), range(2*M, M, -1)):
        print(a, b)
else:
    for a, b in zip(range(1, M+1), range(M+1, 0, -1)):
        if a < b:
            print(a, b)
        else:
            break

    for a, b in zip(range(M+3, 2*M+2), range(2*M+2, M, -1)):
        if a < b:
            print(a, b)
        else:
            break

Solution (Python):
from sys import stdin


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


def main():
    N, M = map(int, input().split())
    if N % 2 == 1:
        for i in range(1, M + 1):
            print(i, N - i)
    else:
        left1 = 1
        left2 = N // 2 + 1
        for i in range(M, 0, -1):
            if i % 2 == 1:
                print(left1, left1 + i)
                left1 += 1
            else:
                print(left2, left2 + i)
                left2 += 1


if __name__ == "__main__":
    main()

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

li = [True] * n

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

else:
    for i in range((m+1)//2):
        print(1+i, a-i)
    for i in range(m//2):
        print(a+1+i, a+m-i)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


def main():
	N, M = getlist()
	n = int(N // 2)
	if N % 2 == 0:
		cnt = 0
		jud = 0
		for i in range(M + 1):
			if jud == 0 and 4 * i + 2 >= N:
				jud = 1
			else:
				if jud == 0:
					print(n - i, n + 1 + i)
				else:
					print(n - i + 1, n + 1 + i)
				cnt += 1
			if cnt == M:
				break

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


	


if __name__ == '__main__':
	main()

Solution (Python):
def check(pairs, N):
    games = set()
    for p1, p2 in pairs:
        l = abs(p2 - p1) - 1
        r = N - l - 2
        if l > r:
            l, r = r, l
        if (l, r) in games:
            return False
        games.add((l, r))
    return True


def main() -> None:
    N, M = map(int, input().split())
    left, right = (1, M + 1), (M + 2, M + M + 1)
    ans = []
    for i in range(M):
        if i % 2 == 0:
            ans.append(left)
            left = (left[0] + 1, left[1] - 1)
        else:
            ans.append(right)
            right = (right[0] + 1, right[1] - 1)
    
    
    for p in ans:
        print(*p)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

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

    start = 1
    end = N

    used = set()
    for m in range(M):
        print("{} {}".format(start, end))
        fdiff = end - start
        bdiff = N - fdiff
        used.add(fdiff)
        used.add(bdiff)

        start += 1
        end -= 1

        fdiff = end - start
        if fdiff in used or 2 * fdiff == N:
            start += 1

if __name__ == '__main__':
    main()

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

Solution (Python):
n,m = map(int,input().split())
if n%2 == 0:
  na = n//2
  m1 = m//2
  m2 = m-m1
  for i,j in enumerate(range(n,n-m2,-1)):
    print(i+1,j)
  for i in range(na,na-m1,-1):
    print(i,n-i+2)
  
else:
  for i,j in enumerate(range(n,n-m,-1)):
    print(i+1,j)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N,M = LI()

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

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

Solution (Python):
N,M=map(int,input().split())
a=[0 for i in range(M)]
b=[0 for i in range(M)]
B=(N+1)//2
A=B-1
C=N-1
D=1
for i in range(M):
    if i%2==0:
        a[i]=A
        b[i]=B
        A-=1
        B+=1
        A%=N
        B%=N
    else:
        a[i]=C
        b[i]=D
        C-=1
        D+=1
        C%=N
        D%=N
for i in range(M):
    print(a[i]+1,b[i]+1)

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

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

for a, b in ans:
    print(a, b)

Solution (Python):
inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
tmp = n//2
for i in range(m):
    if i % 2 == 0:
        print('{} {}'.format(tmp-i//2, tmp+1+i//2))
    else:
        print('{} {}'.format(1+i//2, n-i//2-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:
  if m>n//4:
    for i in range(1,n//4+1):
      print(i,n-i+1)
    for i in range(1,m-n//4+1):
      print(n//2-i,n//2+i)
  else:
    for i in range(1,m+1):
      print(i,n-i+1)

Solution (Python):
from math import floor

N, M = map(int, input().split())
if N%2 == 1:
    for p1 in range(1, M+1):
        p2 = M*2+1-p1
        print(p1, p2)
else:
    for p1 in range(1, min(M,floor(N/4))+1):
        p2 = N-p1+1
        print(p1, p2)
    for p1 in range(p1+1, M+1):
        p2 = N-p1
        print(p1, p2)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve():
    n, m = LI()
    ans = [[i + 1, None] for i in range(m)]
    v = n
    j = m + 1
    d = defaultdict(int)
    d[0] = 1
    d[n] = 1
    for i in range(m - 1, -1, -1):
        while d[n - (j - ans[i][0])]: j += 1
        if (j - ans[i][0]) * 2 == n: j += 1
        d[j - ans[i][0]] = 1
        ans[i][1] = j
        j += 1
    for a in ans:
        print(*a)
    return



if __name__ == '__main__':
    solve()

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

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

Solution (Python):
def main():
    N, M = map(int, input().split())
    t = N // 2
    if N % 2 == 1:
        m = N // 2
    else:
        m = -1 + (N // 2)
    l = []
    x = m
    for i in range((m//2)+1):
        l.append((i+1, x-i+1))
    for i in range(m//2):
        l.append((N-i, N-x+1+i))
    i = 0
    f = 0
    while f < M:
        if l[i][0] == l[i][1]:
            i += 1
            continue
        print(l[i][0], l[i][1])
        i += 1
        f += 1
main()

Solution (Python):
import sys
import math

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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(m):
        if i < (n/2)//2:
            print(i+1, n-i)
        else:
            print(i+1, n-i-1)

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

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

Solution (Python):
n, m = map(int, input().split())
s = 0
if n%2 == 1:
    for i in range(1, m+1):
        s = 2*m+1-i
        print(str(i) + ' ' + str(s))
elif n%2 == 0:
    for i in range(1, m//2 +1):
        s = 2*m+2-i
        print(str(i) + ' ' + str(s))
    for i in range(m//2 +1, m+1):
        s = 2*m+1-i
        print(str(i) + ' ' + str(s))

Solution (Python):
n,m=map(int,input().split())
if n%2==1:
    for i in range(1,m+1):
        print(f"{i} {n+1-i}")
else:
    count = 0
    q = n//2
    if q%2==0:
        for j in range(1,q//2+1):
            print(f"{j} {q+1-j}")
            count += 1
            if count == m:
                exit(0)
        for j in range(1,q//2):
            print(f"{q+j} {q+j+(q-2*j)}")
            if count == m:
                exit(0)
    else:
        for j in range(1,q//2+1):
            print(f"{j} {q+1-j}")
            count += 1
            if count == m:
                exit(0)
        for j in range(1,q//2+1):
            print(f"{q+j} {q+j+(q-2*j)}")
            if count == m:
                exit(0)

Solution (Python):
import sys,math,copy,queue,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(-1,0),(0,1),(0,-1))

N,M = LI()
p = []
i = 1
for j in range(M,0,-2):
    p.append([i,i+j])
    i += 1
i = M+2
for j in range(M-1,0,-2):
    p.append([i,i+j])
    i += 1
for ans in p:
    print (*ans)

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

maxdist = (n-1)//2
maxodd = maxdist if not maxdist%2 == 0 else maxdist-1
maxgusu = maxdist if maxdist%2 == 0 else maxdist-1

count=0

for i,sa in enumerate(range(1,maxodd+1)[::-2]):
    j = i+1
    print(j,j+sa)
    count+=1
    if count==m:
        exit()
for i,sa in enumerate(range(2,maxgusu+1)[::-2]):
    j=i+1
    print(1+maxodd+j,1+maxodd+j+sa)
    count+=1
    if count==m:
        exit()

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

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    if N%2==1:
        a=1
        b=N
        for i in range(M):
            print(a,b)
            a+=1
            b-=1
    else:
        ans=[]
        a=1
        b=N//2
        for i in range(M):
            ans.append([a,b])
            a+=1
            b-=1
            if a>=b:
                break

            
        a=N//2+1
        b=N-1
        for i in range(M):
            ans.append([a,b])
            a+=1
            b-=1
            if a>=b:
                break
            
        for i in range(M):
            print(' '.join(map(str, ans[i])))
            
            
            
            
            
            
                    
            
            
        
        
    

main()

Solution (Python):
(N, M) = [int(n) for n in input().split()]

if N % 2 == 1:
    for m in range(M):
        print('{} {}'.format(m+1, 2*M-m))
else:
    m0 = M // 2 
    m1 = M - m0 
    for m in range(m1):
        print('{} {}'.format(m+1, 2*m1-m))
    base = 2*m1
    for m in range(m0):
        print('{} {}'.format(base+m+1, 2*m0+1-m+base))

Solution (Python):
[N,M] = [int(s) for s in input().rstrip().split(' ')]
if M == 1:
    print("1 2")
else:
    for i in range(1,M//2+1):
        print("{} {}".format(i,M+1-i))
    for i in range(1,-(-M//2)+1):
        print("{} {}".format(M+i,2*M+2-i))

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

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

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

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

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

if N%2==1:
    for i in range(1,M+1):
        print(i,2*M+1-i)
else:
    used = {N//2}
    j = 1
    for i in range(M,0,-1):
        while j in used:
            j += 1
        print(i,i+j)
        used.add(j)
        used.add(N-j)
        j += 2

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

Solution (Python):
def main():
    n, m = map(int, input().split())
    p = (m+1)//2
    q = m//2
    l = 0
    r = 2*p-1
    for i in range(p):
        print(l+1, r+1)
        l += 1
        r -= 1
    l = 2*p
    r = l+2*q
    for i in range(q):
        print(l+1, r+1)
        l += 1
        r -= 1


main()

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

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

Solution (Python):
import math
n,m=map(int,input().split())
A=[]
if n%2==1:
    for i in range(m):
        A.append([i+1,n-i])
else:
    d=n//2-1
    h=math.ceil(d/2)
    for i in range(min(h,m)):
        A.append([i+1,n-i])
    if h<m:
        for j in range(m-h):
            A.append([i+j+2,n-i-j-2])
for a in A:
    print(*a)

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

Solution (Python):
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

Solution (Python):
def main():
    N, M = map( int, input().split())
    ANS = []
    if N%2 == 1:
        n = N//2
        for i in range(M):
            ANS.append([n-i, n+1+i])
    else:
        n = N//2
        t = 0
        for i in range(M):
            if i%2 == 0:
                ANS.append([n-i//2, n+1+i//2])
            else:
                ANS.append([(i+1)//2, N-(i+1)//2])

    print( "\n".join( [" ".join( map( str,ans)) for ans in ANS]))
if __name__ == '__main__':
    main()

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

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

ans = [[0, 0] for _ in range(m)]

import math
M = math.ceil(m / 2)
for i in range(M):
    ans[i][0] = i + 1
    ans[i][1] = ans[i][0] + (M * 2 - 1 - 2 * i)

cur = M * 2

M2 = m // 2
for i in range(M2):
    ans[i + M][0] = cur + i + 1
    ans[i + M][1] = ans[i + M][0] + M2 * 2 - 2 * i


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

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values()

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


if __name__ == "__main__":
    main()

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

Solution (Python):
n,m = map(int,input().split())
a = 1
b = 1+m
c = 2+m
d = 1+2*m
for i in range(m):
    if i%2 == 0:
        print(str(a)+' '+str(b))
        a += 1
        b -= 1
    else:
        print(str(c)+' '+str(d))
        c += 1
        d -= 1

Solution (Python):
def solve(n,m):
    Ans=[]
    if n%2==1:
        for i in range(1,m+1):
            Ans.append((i,n-i))
        return Ans
    a=1; b=n
    d1=n-1; d2=1
    while d1>d2 and a<=m:
        Ans.append((a,b))
        a+=1; b-=1
        d1-=2; d2+=2
    b-=1
    while a<=m:
        Ans.append((a,b))
        a+=1
        b-=1
    return Ans
    
def main():
    n,m=map(int,input().split())
    Ans=solve(n,m)
    for ans in Ans:
        print(*ans)
    
if __name__=='__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
ans=[[] for _ in range(n//2)]
if n%2==1:
  for i in range(1,k+1):
    ans[i-1].append(i)
  for i in range(1,k+1):
    ans[i-1].append(n-i+1)
  for i in range(k):
    print(*ans[i])
else:
  if n%4==0:
    for i in range(1,k+1):
      ans[i-1].append(i)
    for i in range(1,k+1):
      if i<=k//2+1:
        ans[i-1].append(n-i+1)
      else:
        ans[i-1].append(n-i)
  else:
    for i in range(1,k+1):
      ans[i-1].append(i)
    for i in range(1,k+1):
      if i<=k//2:
        ans[i-1].append(n-i+1)
      else:
        ans[i-1].append(n-i)
  for i in range(k):
    print(*ans[i])

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

    odd = []
    even = []
    for d in range(1, M + 1):
        if d % 2 == 1:
            if not odd:
                odd.append((1, 2))
            else:
                x = odd[-1][0] - 1
                y = x + d
                odd.append((x, y))
        else:
            if not even:
                even.append((1, 3))
            else:
                x = even[-1][0] - 1
                y = x + d
                even.append((x, y))

    if odd:
        start = 1
        d = start - odd[-1][0]
        for x, y in odd:
            print(x + d, y + d)
    if even:
        start = odd[-1][1] + d + 1
        d = start - even[-1][0]
        for x, y in even:
            print(x+d, y+d)


if __name__ == "__main__":
    main()

Solution (Python):


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

if n % 2 == 0:
    count = 1
    while(count<=m):
        if count <= n // 4:
            print(str(count) + ' ' + str(n-count+1))
        else:
            c = count - n // 4
            print(str(int(n/2-c+1)) + ' ' + str(int(n/2+1+c)))
        count += 1
else:
    for i in range(m):
        print(str(i+1) + ' ' + str(n-i))

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

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

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

Solution (Python):
n,m = list(map(int,input().split()))
x = n//2
y = n//2+1

temp_used = [0] * (n+1)

for i in range(m):
    print("{x} {y}".format(x=x,y=y))
    temp_used[y-x]+=1
    temp_used[n+x-y]+=1
    x-=1
    y+=1
    if temp_used[y-x]==1 or temp_used[n+x-y]==1 or y-x==n/2:
        y+=1

print("")

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

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

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

Solution (Python):
n,m=map(int,input().split())
if n%2==1:
    for i in range(m):
        print(i+1,2*m-i)
else:
    if n==4:print(2,3);exit()
    d=n//2-1
    ans=[]
    if d%2:
        s=n//2
        for i in range(d//2+1):
            ans.append((i+1,s-i))
        dsa=n*2-(d//2)*2
        for i in range(d//2):
            ans.append(((dsa+(i+1)*2)//2,(dsa-(i+1)*2)//2))
    else:
        s=n//2-1
        for i in range(d//2):
            ans.append((i+1,s-i))
        dsa=n*2-d
        for i in range(d//2):
            ans.append(((dsa+(i+1)*2)//2,(dsa-(i+1)*2)//2))
    for i in range(m):
        print(*ans[i])

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