Problem:


Score : 500 points

Problem Statement

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

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

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

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

Constraints

1 \leq M

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

Input

Input is given from Standard Input in the following format:

N M

Output

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

a_1 b_1
a_2 b_2
:
a_M b_M

Sample Input 1

4 1

Sample Output 1

2 3

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

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

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

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

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

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

Sample Input 2

7 3

Sample Output 2

1 6
2 5
3 4



Sample input:
4 1


Sample output:
2 3

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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")

#solve
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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
(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 # num of even
    m1 = M - m0 # num of odd
    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))

Submission status: Accepted

Solution code:
[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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

if n % 2 == 1:
    for i in range(m):
        print(i+1,n-i)
else:
    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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if N%2 == 1:
    for i in range (M):
        print(i + 1,N - i)
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

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

import heapq


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
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)]

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

######Combination######
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

######Factorization######
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

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

#############
# Main Code #
#############

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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
# input=sys.stdin.readline
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)
# elif n%4==2:
#     print(1,n)
#     for i in range(m-1):
#         print(i+2,n-(i+2))
# elif n%4==0:
#     print(1,n)
#     if m==1:
#         exit()
#     print(2,n-1)
#     for i in range(m-2):
#         print(i+3,n-(i+2))

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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}')

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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}")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])