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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()

    rr = []
    if n % 2 == 1:
        t = n // 2 + 1
        for i in range(1, m+1):
            rr.append((t-i,t+i))
    else:
        t1 = (m+1) // 2
        t2 = n - m // 2
        for i in range(t1):
            rr.append((t1-i,t1+1+i))
        for i in range(1, m // 2 + 1):
            rr.append((t2-i, t2+i))

    return JAA(rr, "\n", " ")

print(main())

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

if N%2:
    for i in range(M):
        print(2+i, N-i)
else:
    used = set()
    s = 1
    for i in list(range(2, M+1, 2)[::-1])+list(range(1, M+1, 2)[::-1]):
        while 1:
            if not s in used and not (s+i) in used:
                used.add(s)
                used.add(s+i)
                print(s, s+i)
                break
            s += 1

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

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

Solution (Python):
n, m = map(int, input().split())
def check_ans(list_pairs):
  dict_people = {i: i for i in range(1, n+1)}
  for i in range(n):
    for k in range(m):
      val1 = dict_people[list_pairs[k][0]]
      val2 = dict_people[list_pairs[k][1]]
      if val1>val2:
        print(val2, val1, end=" / ")
      else:
        print(val1, val2, end=" / ")
    print("")
    for j in range(1, n+1):
      dict_people[j] = (dict_people[j]+1)%n
      if dict_people[j] == 0: dict_people[j] = n
ans = list()
if n%2 == 1:
  for i in range(m):
    node1 = (1-i)%n
    if node1 == 0: node1 = n
    node2 = 2+i
    ans.append((node1, node2))
else:
  distance = -1
  node2 = 1
  for i in range(m):
    node1 = (1-i)%n
    if node1 == 0: node1 = n
    node2 = node2+1
    distance += 2
    if distance == n//2 or distance == n//2 + 1:
      node2 += 1
    ans.append((node1, node2))
[print(str(values[0])+" "+str(values[1])) for values in ans]

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

if n % 2 == 1:
    for i in range(1,m+1):
        print(i,n-i)
else:
    used=set()
    prev = n+1
    for i in range(1,m+1):
        prev-=1
        if abs(i-prev)*2==n:
            prev-=1
        while abs(i-prev) in used:
            prev-=1
        print(i,prev)
        used.add(abs(i-prev))
        used.add(n-abs(i-prev))

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

Solution (Python):



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

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


if __name__ == '__main__':
    solve()

Solution (Python):

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

    if M == 1:
        print(1, 2)
        return

    i1 = 1
    i2 = M+2
    for diff in range(M, 0, -1):
        print(i1, i1+diff)
        i1 += 1
        i1, i2 = i2, i1

if __name__ == "__main__":
    resolve()

Solution (Python):


def main():
    N, M = map(int, input().split())
    skip = (N // 2) // 2 + 1 if N % 2 == 0 else None
    count = 0
    left, right = 0, N + 1
    while count < M:
        left += 1
        if left == skip:
            continue
        right -= 1
        print(left, right)
        count += 1


if __name__ == '__main__':
    main()

Solution (Python):
import sys


def main():
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())
    skip = (N // 2) // 2 + 1 if N % 2 == 0 else None
    count = 0
    left, right = 0, N + 1
    while count < M:
        left += 1
        if left == skip:
            continue
        right -= 1
        print(left, right)
        count += 1


if __name__ == '__main__':
    main()

Solution (Python):
import sys


def main():
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())
    skip = (N // 2) // 2 + 1 if N % 2 == 0 else None
    count = 0
    left, right = 0, N + 1
    while count < M:
        left += 1
        if left == skip:
            continue
        right -= 1
        print(left, right)
        count += 1


if __name__ == '__main__':
    main()

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

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


main()

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

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

Solution (Python):

n, m = map(int, input().split())
d = m
r = d + 1
for i in range(m):
    if d <= 0:
        break
    a = i + 1
    b = a + d
    print(a, b)
    d -= 2
d = m - 1
for i in range(m):
    if d <= 0:
        break
    a = r + i + 1
    b = a + d
    print(a, b)
    d -= 2

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

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

Solution (Python):

if __name__ == '__main__':
    nm = input()
    nm = nm.split()
    n = int(nm[0])
    m = int(nm[1])

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


    if n%2==0:
        t = n
        f = 0

        for i in range(1,m+1):
            p = i-1+t-n
            if p>=n-i-1 and f==0:
                f = 1
                n -= 1
            print(i,n)
            n -= 1

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()

if m == 1:
    print(1, 2)
    exit()

if m % 2 == 0:
    l = (m + 1) // 2
    r = (m + 1) // 2 + 2
    cnt = 0
    while cnt < m and l >= 1 and r <= (m + 1):
        print(l, r)
        l -= 1
        r += 1
        cnt += 1
    l = (n - m - 1) // 2
    r = (n - m - 1) // 2 + 1
    while cnt < m and l >= 1 and r <= (n - m - 1):
        print(m + 1 + l, m + 1 + r)
        l -= 1
        r += 1
        cnt += 1
else:
    l = m // 2
    r = m // 2 + 2
    cnt = 0
    while cnt < m and l >= 1 and r <= m:
        print(l, r)
        l -= 1
        r += 1
        cnt += 1
    l = (n - m) // 2
    r = (n - m) // 2 + 1
    while cnt < m and l >= 1 and r <= (n - m):
        print(m + l, m + r)
        l -= 1
        r += 1
        cnt += 1

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

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

count = 1
if N % 2 == 0:
    for m in range(1, M + 1):

        if m <= (N // 2 - 1) // 2:
            start = m
            end = N // 2 - m
            print(start, end)
        else:
            start = N // 2 + count
            end = N - count + 1
            print(start, end)
            count += 1

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

    if N & 1:
        gen = ((i+1, N-i) for i in range(M))
    else:
        gen = ((i+1, N-i) if 2*i < N/2-1 else (i+1, N-i-1) for i in range(M))

    [print(*s) for s in gen]


if __name__ == "__main__":
    main()

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

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

    for s in gen:
        print(*s)


if __name__ == "__main__":
    main()

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

    is_odd = (N-1) & 1
    bias = 0

    for i, distance in enumerate(range(N-1, 0, -2)):

        if is_odd and distance <= -distance % N:
            bias = 1

        left = i + 1
        right = left + distance - bias
        print(left, right)

        if i == M-1:
            return


if __name__ == "__main__":
    main()

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

    left = 1
    count = 0
    buff = 0
    for d in range(N-1, 0, -2):

        if (N-1) & 1 and d <= -d % N:
            buff = 1

        right = left + d - buff
        print(left, right)

        left += 1
        count += 1
        if count == M:
            return


if __name__ == "__main__":
    main()

Solution (Python):
N,M = [int(i) for i in input().split()]
if N%2 == 1:
    for i in range(1,M+1):
        print(i, end=" ")
        print(N+1-i)
    exit()
L = min(M,N//4)
for i in range(1,L+1):
    print(i,end=" ")
    print(N+1-i)
if L < M:
    for i in range(L+1,M+1):
        print(i,end=" ")
        print(N-i)

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


ans = []
s = 1
e = M+1
while e>s:
    ans.append([s,e])
    s += 1
    e -= 1

s = M+2
e = 2*M+1
while e>s:
    ans.append([s,e])
    s += 1
    e -= 1

for s,e in ans:
    print(s,e)

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

num = list(range(1,N+1))
ans = []


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


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


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

Solution (Python):
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

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

arr = []
for i in range(M):
    arr.append([1, i + 2])
arr = arr[::-1]


max_arr = -1
plus = 0
for a, b in arr[::2]:
    print(a + plus, b + plus)
    max_arr = max(max_arr, b + plus)
    plus += 1


plus = 0
for a, b in arr[1::2]:
    print(max_arr + a + plus, max_arr + b + plus)
    plus += 1

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

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

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

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

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

Solution (Python):
def main():
    N, M = list(map(int, input().split()))
    if N % 2 == 1:
        for i in range(M):
            print(i + 1, N - i - 1)
            
    else:
        s = set()
        t = 0
        for i in range(M):
            a, b = i + 1, N - i - t
            if (b - a) in s or (a + N - b) in s or b - a == a + N - b:
                t += 1
                b = N - i - t
            print(a, b)
            s.add(b - a)
            s.add(N + a - b)

main()

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

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(1,0),(-1,0),(0,1),(0,-1)];EightNb=[(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('EWNS',FourNb))
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def __str__(self):
        return  str(self.edges)

    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v

    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]

class SparseTable: 
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1

        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    
    def query(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][r-(1<<N)])
    
    
    def query_id(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][r-(1<<N)]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][r-(1<<N)]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])

    def print(self):
        for i in self.table:
            print(*i)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True
ans=0

n,m=LI()
ans=[]
if n%2==0:
    l1,r1=1,1+n//2-1
    l2,r2=1+n//2+1,n
    for i in range(n//4+1):
        ans+=[(l1,r1)]
        ans+=[(l2,r2)]
        l1+=1
        r1-=1
        l2+=1
        r2-=1
    
elif n%2==1:
    l1,r1=2,n
    for i in range(n//2):
        ans+=[(l1,r1)]
        l1+=1
        r1-=1
    
for i in range(m):
    a,b=ans[i]
    print(*ans[i])

Solution (Python):
import os
from collections import Counter

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N, M = list(map(int, sys.stdin.buffer.readline().split()))


def test(ans):
    hist = []
    for a, b in ans:
        hist.append((0, (b - a) % N))
        hist.append((0, (a - b) % N))
    print(len(set(hist)) == M * 2)
    print(Counter(hist))


ans = []
if N % 2 == 1:
    for i in range(M):
        a, b = i + 1, N - i
        ans.append((a, b))
else:
    hist = set()
    d = 0
    for i in range(M):
        a, b = i + 1, N - i - d
        if (a - b) % N in hist or (b - a) % N in hist or (a - b) % N == (b - a) % N:
            d += 1
            a, b = i + 1, N - i - d
        hist.add((a - b) % N)
        hist.add((b - a) % N)
        ans.append((a, b))

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

Solution (Python):
N, M = (int(_) for _ in input().split())

if N % 2 == 0:
    s = (N - 1) // 4 + 1
    ret = []
    for i in range(1, s):
        ret.append((i, N - i))
    for i in range(s, N // 2):
        ret.append((i, N - i - 1))
else:
    ret = []
    for i in range(1, (N // 2) + 1):
        ret.append((i, N - i))


for r0, r1 in ret[:M]:
    print(r0, r1)

Solution (Python):
'''
N人を円周上に配置し、M本の線分で結ぶ。
このとき、線分を回転させていっても同じ人のペアが生まれないようにする。

基本的には、上から順に結べばよい。
'''

from collections import deque

def main():
    N, M = map(int, input().split())
    if N&1:
        '''
        ・Nが奇数の場合
        
        上から順に結ぶだけ。
        dequeに 1,2,3,...,M*2 を突っ込んで、両端から取り出してペアにする。
        '''
        q = deque(range(M*2))
        while q:
            print(q.popleft()+1, q.pop()+1)
    else:
        '''
        [Nが偶数の場合]
        
        上から順に結ぶと、上下の線対称になり、同じ間隔のペアが生まれるためNG。
        → 半分以降は、1つずらしてペアを作っていく

        簡単に解決するため、
        ・上から順に奇数間隔ペアを作る
        ・下から順に偶数間隔ペアを作る
        この2つから、M個を順に、交互に取り出す。
        '''
        q1 = deque(range(N))
        q2 = deque(range(N-1))
        p1 = []
        while q1:
            p1.append((q1.popleft()+1, q1.pop()+1))
        p2 = []
        while len(q2)>=2:
            p2.append((q2.popleft()+1, q2.pop()+1))
        p2.reverse()
        for _ in range(M):
            print(*p1.pop())
            p1, p2 = p2, p1


main()

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










div_point=int((N/2))

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

re_point=div_point+int((N-div_point)/2)


i=0 
while 1<div_point-i*2 and i<re_point and i<M:
    ent1=i+1 
    ent2=div_point-i 
    print(str(ent1) + ' ' + str(ent2))
    i+=1
for j in range(M-i):
    ent1=re_point-j 
    ent2=re_point+j+1 
    print(str(ent1) + ' ' + str(ent2))

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, M = mis()
    if N&1:
        q = deque(range(M*2))
        while q:
            print(q.popleft()+1, q.pop()+1)
    else:
        q1 = deque(range(N))
        q2 = deque(range(N-1))
        p1 = []
        while q1:
            p1.append((q1.popleft()+1, q1.pop()+1))
        p2 = []
        while len(q2)>=2:
            p2.append((q2.popleft()+1, q2.pop()+1))
        p2.reverse()
        for _ in range(M):
            print(*p1.pop())
            p1, p2 = p2, p1


main()

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

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

Solution (Python):
n,m = map(int,input().split())
l=1
if n%2==1:
    r=n
    for i in range(m):
        d=min(abs(l-r),n-abs(l-r))
        print(l,r)
        l+=1
        r-=1
else:
    if n%4==0:
        r=n-1
    else:
        r=n
    rev=False
    for i in range(m):
        d=min(abs(l-r),n-abs(l-r))
        if d == n//2:
            rev=True
            l+=1
            print(l,r)
        else:
            print(l,r)
        l+=1
        r-=1

Solution (Python):
def main():
    n, m = map(int, input().split())
    left = 1
    right = n
    is_shift = False
    ans = []
    while left < right:
        if right - left <= n // 2 and not is_shift and n % 2 == 0:
            left += 1
            is_shift = True
        ans.append([left, right])
        left += 1
        right -= 1

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


if __name__ == "__main__":
    main()

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

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

while True:
    a, b = ans[-1][0]+1, ans[-1][1]-1
    
    if a<b:
        ans.append((a, b))
    else:
        break

ans.append((2+d, 1+2*d))

while True:
    a, b = ans[-1][0]+1, ans[-1][1]-1
    
    if a<b:
        ans.append((a, b))
    else:
        break

for a, b in ans[:M]:
    print(a, b)

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

gu = 1
ki = m - m%2 + 2

for i in range(1, m+1)[::-1]:
    if i % 2 == 0:
        print(gu, gu+i)
        gu += 1
    else:
        print(ki, ki+i)
        ki += 1

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):
        print(a, N - a + (a <= N // 4))

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

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

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

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

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

for a, b in ans[:M]:
    print(a, b)

Solution (Python):
n, m = map(int, input().split())
if n%2 == 1:
    ans = []
    a = 1
    b = n-1
    for i in range(m):
        ans.append((a, b))
        a += 1
        b -= 1
else:
    ans = []
    a = 1
    b = n-1
    flag = True
    for i in range(m):
        if flag and b-a <= n//2:
            b -= 1
            flag = False
        ans.append((a, b))
        a += 1
        b -= 1
for i in range(m):
    print(*ans[i])

Solution (Python):
n,m=map(int,input().split())
lange=[1]*(n+1)
for i in range(1,n+1):
  a=i
  b=n-a
  if lange[a]:lange[b]=0
langes=[]
for i in range(1,n):
  if lange[i]:
    if len(langes)%2:langes.append(i)
    else:langes.append(n-i)
langes.sort(reverse=1)
for i in range(m):print(i+1,i+1+langes[i])