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:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    if m % 2 == 0:
        rem = m
        for i in range(m // 2):
            print(i + 1, m + 1 - i)
            rem -= 1
            if rem == 0:
                return
        for i in range(n):
            print(m + 2 + i, 2 * m + 1 - i)
            rem -= 1
            if rem == 0:
                return
    else:
        rem = m
        for i in range((m - 1) // 2):
            print(i + 1, m - i)
            rem -= 1
            if rem == 0:
                return
        for i in range(n):
            print(m + 1 + i, 2 * m + 1 - i)
            rem -= 1
            if rem == 0:
                return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

l=1
r=n
used = set()
while len(used) < m * 2:
  diff = r - l
  rdiff = n - diff
  if diff == rdiff:
    r -= 1
    continue
  if diff in used:
    r -= 1
    continue
  print(l,r)
  used.add(diff)
  used.add(rdiff)
  l += 1
  r -= 1

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
odd_l = 1
odd_r = M
even_l = M + 1
even_r = 2 * M + 1
i = 0
while i < M:
    print(even_l, even_r)
    i += 1
    if i == M:
        break
    print(odd_l, odd_r)
    i += 1
    odd_l += 1
    odd_r -= 1
    even_l += 1
    even_r -= 1

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    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-2*i+1 > n//2:
                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())
piv = N//4+(N%4==3)
pairs = [(str(piv-i), str(piv+1+i)) for i in range(N//4+(N%4==3))]
piv = N - N//4 + (N%4==0)
pairs += [(str(piv-1-i), str(piv+1+i)) for i in range(N//4-(N%4==0))]
for pair in pairs[:M]:
    print(' '.join(pair))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, m = map(int, input().split())
if n % 2 == 0:
    n -= 1
ans = []
left_range = n//2
right_range = n//2 - 1
left1 = 1
right1 = 1 + left_range
left2 = right1 + 1
right2 = left2 + right_range

while True:
    if left1 >= right1:
        break
    ans.append([left1, right1])
    left1 += 1
    right1 -= 1

while True:
    if left2 >= right2:
        break
    ans.append([left2, right2])
    left2 += 1
    right2 -= 1
    
for i in range(m):
    print(*ans[i])

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    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-2*i+1 > n//2:
                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())
sets=[]
if N%2==1:
    for i in range(M):
        sets.append((i+1,i+1+(N-3-2*i)+1))
elif N%2==0:
    count=0
    kukan=[]
    for i in range(N//2-1):
        kukan.append(count)
        count+=2
        if count==N//2 or count==N//2-1:
            count+=1
    kukan.reverse()
    for i in range(M):
        sets.append((i+1,i+1+kukan[i]+1))
for set1 in sets:
    print(set1[0],set1[1])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if m % 2 == 1:

    cnt = 0

    for i in range(m // 2):
        num1 = 1 + i
        num2 = m - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
    for i in range(m // 2 + 1):
        num1 = m + 1 + i
        num2 = 2 * m + 1 - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
else:
    cnt = 0

    for i in range(m // 2):
        num1 = 1 + i
        num2 = m + 1 - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
    for i in range(m // 2):
        num1 = m + 2 + i
        num2 = 2 * m + 1 - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()

Submission status: Accepted

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

right = 2*m+1

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

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

Submission status: Accepted

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

n = 2*M+1
# Mが奇数の場合
if M%2==1:
    for i in range(1, M//2+1):
        print('{} {}'.format(i,M+1-i))
    for i in range(1, (M+1)//2+1):
        print('{} {}'.format(M+i,2*M+2-i))
# Mが偶数の場合
else:
    for i in range(1, M//2+1):
        print('{} {}'.format(i,M+2-i))
    for i in range(1, M//2+1):
        print('{} {}'.format(M+i+1,2*M+2-i))

Submission status: Accepted

Solution code:
import sys
def main():
    N,M=tuple(map(int,sys.stdin.readline().split()))
    if M%2==1:
        m1,m2=M//2,M//2+1
        for i in range(m1):
            l,r=i+1,M-i
            print(str(l)+' '+str(r))
        for i in range(m2):
            l,r=M+1+i,2*M+1-i
            print(str(l)+' '+str(r))
    else:
        m=M//2
        for i in range(m):
            l,r=i+1,M+1-i
            print(str(l)+' '+str(r))
        for i in range(m):
            l,r=M+2+i,2*M+1-i
            print(str(l)+' '+str(r))
if __name__=='__main__':main()

Submission status: Accepted

Solution code:
def resolve():
    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
            # 円として配置したとき、b-aが半分以上になったら片方だけ進める
            if b-a <= N//2:
                a += 1
            print(a, b)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

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

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

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)
  for i in range(M//2):
    print(M+i+1,2*M-i+1)  
else:
  for i in range(M//2):
    print(i+1,M-i)
  for i in range(M//2+1):
    print(M+i+1,2*M-i+1)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    if n & 1:
        for i in range(m):
            print(i+1, n-i)
    else:
        i = 0
        flag = False
        for i in range(m):
            if n-2*i-1 > n//2:
                print(i+1, n-i)
            else:
                print(i+1, n-i-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
for i in range(M, 0, -2):
    cur_start = (M - i) // 2
    print(cur_start + 1, cur_start + i + 1)
start = M + 2
for i in range(M -1, 0, -2):
    cur_start = start + (M -  1 - i) // 2
    print(cur_start, cur_start + i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if n%2 == 1:
    a = 1
    b = n+1
    ans = []
    for i in range(m):
        a += 1
        b -= 1
        ans.append((a, b))
else:
    a = 1
    b = n+1
    S = set()
    ans = []
    for i in range(m):
        a += 1
        b -= 1
        r = min(b-a, n-(b-a))
        if r in S or r == n//2:
            b -= 1
            r = min(b-a, n-(b-a))
        ans.append((a, b))
        S.add(r)
for i in range(m):
    print(*ans[i])

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    used = set()
    Ans = [None for _ in range(M)]
    left = 1
    right = N
    for i in range(M):
        if right - left in used or 2 * (right - left) == N: right -= 1
        Ans[i] = (left, right)
        diff = right - left
        used |= {diff, N - diff}
        left += 1
        right -= 1
    for i in range(M): print(*Ans[i], sep=" ")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = []
if n % 2 == 1:
    for i in range(m):
        ans.append((i+1, n-i))


else:
    for i in range(m):
        if i <= (m+1)//2-1:
            ans.append((i+1, n-i))
        else:
            ans.append((i+1, n-i-1))

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

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
if n%2==1:
    for i in range(1,m+1):
        print('{} {}'.format(i,n-i))
elif n%4==0:
    e = min(m+1,n//4)
    for i in range(1,e):
        print('{} {}'.format(i,n//2-i))
    if m>=n//4:
        for i in range(m-n//4+1):
            print('{} {}'.format(n-1-i,n//2+i))
else:
    e = min(m+1,n//4+1)
    for i in range(1,e):
        print('{} {}'.format(i,n//2-i+1))
    if m>=n//4+1:
        for i in range(m-n//4):
            print('{} {}'.format(n-1-i,n//2+i+1))

Submission status: Accepted

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

if N%2 == 1:
  for i in range(1,M+1):
    print(i, N-i)
else:
  # N=8 M=3 (8,1), (4,6), (7,2)
  # N=10, M=4 (10,1), (5,7), (9,2), (4,8)
  for i in range(M):
    if i%2 == 0:
      x = i//2
      print(N-x, 1+x)
    else:
      cent = N//2+1
      x = i//2+1
      print(cent-x, cent+x)

Submission status: Accepted

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

oddflag=True
for i in range(1,m+1):
	mid=(1+n)//2
	if oddflag:
		oddflag = False
		print(i//2 + 1 , n - i//2)
	else:
		oddflag = True
		print(mid + i//2, mid - i//2)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = 1
b = N
d = set([1, N - 1])
for _ in range(M):
    print(a, b)
    a += 1
    b -= 1
    while (b - a) in d or (N - b + a) in d or (b - a) == (N - b + a): b -= 1
    d.add(b - a)
    d.add(N - b + a)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=M//2
b=M-a
c=1
d=2*a+1
for i in range(a):
  print(c,d)
  c+=1
  d-=1
e=2*a+2
f=2*M+1
for i in range(b):
  print(e,f)
  e+=1
  f-=1

Submission status: Accepted

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

even = m // 2
odd = m - even

odd_left = 1
odd_right = 2 * odd

even_left = odd_right + 1
even_right = even_left + 2 * even

for _ in range(odd):
    print(odd_left, odd_right)
    odd_left += 1
    odd_right -= 1

for _ in range(even):
    print(even_left, even_right)
    even_left += 1
    even_right -= 1

Submission status: Accepted

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

if N%2==1:
  for i in range(M):
    print(str(i+1) + " " + str(N-(i+1)))
else:
  flag = False
  l = 1
  r = N-1
  cnt = 0
  while cnt < M and l < r:
    if not flag and r-l <= N//2:
      r -= 1
      flag = True
    print(str(l) + " " + str(r))
    l += 1
    r -= 1
    cnt += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
# check_ans(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 解説を参考に作成


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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())  # N must be an odd number

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())  # N must be an odd number

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())  # N must be an odd number

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
#print(arr)

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
#print(max_arr)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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