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:
def odd():
    for i in range(M):
        print(order[i], reverse[i])

def multipule4():
    d = 0
    for i in range(M):
        if reverse[i] - order[i] == N//2:
            d = 1
        print(order[i+d], reverse[i])

def even():
    d = 0
    for i in range(M):
        if i == (N//2-1) //2:
            d = 1
        print(order[i+d], reverse[i])
    

N, M = map(int, input().split())
order = [i for i in range(2, N+1)]
reverse = order[::-1]

if N%2 != 0:
    odd()
elif N%4 == 0:
    multipule4()
else:
    even()

Submission status: Accepted

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

if N % 2 == 1:
    for i in range(M):
        j = N - i
        print(f'{i + 1} {j}')
else:
    for i in range(M):
        j = N - i
        if i < M / 2:
            print(f'{i + 1} {j}')
        else:
            print(f'{i + 1} {j - 1}')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, M: int):
    # N <= 10**5

    # 差が異なる組み合わせならば、N回を通して同じ組み合わせにはならない。
    # 前に奇数差、後ろに偶数差を作る
    ans = []

    if N % 2 == 0:
        # 差は偶数
        a, b = (0, N//2-1)
        # print(a, b)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
        # 差は奇数
        a, b = (N//2, N-2)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
    if N % 2 == 1:
        # 差は偶数
        a, b = (0, N//2)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
        # 差は奇数
        a, b = (N//2+1, N-1)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
    for i in range(M):
        print(*ans[i], sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n, m = map(int, input().split())
    a = 1
    d = n - 1
    for _ in range(m):
        if d % 2 == 1 and (d == n // 2 or d == n // 2 - 1):
            d -= 1
        print(a, a + d)
        a += 1
        d -= 2

main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


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

    if N % 2 == 1:
        pairs = []
        for i in range(N//2):
            pairs.append((i+1, N-i))

        # print(pairs)
        for i in range(M):
            print(*pairs[i])
            # print((pairs[i][0] - pairs[i][1]) % N)
            # print((pairs[i][1] - pairs[i][0]) % N)
    else:
        pairs = []
        for i in range(N//2//2):
            pairs.append((i+1, N-i))

        for i in range(N//2//2+1, N//2):
            pairs.append((i+1, N-i+1))

        # print(pairs)
        for i in range(M):
            print(*pairs[i])
            # print((pairs[i][0] - pairs[i][1]) % N)
            # print((pairs[i][1] - pairs[i][0]) % N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

bl=input().split()
n=int(bl[0])
s=int(bl[1])

for a in range(math.ceil(s/2)):
  print(str(a+1)+" "+str(s-a+1))
for b in range(math.floor(s/2)):
  print(str(s+b+2)+" "+str(2*s-b+1))

Submission status: Accepted

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

Submission status: Accepted

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

res = []

if N % 2 == 0:
    x = 0
    for i in range(N // 2 // 2):
        res.append((x + 1, (x + 2 * i + 1) % N + 1))
        x -= 1
        x %= N
    for i in range((N // 2 - 1) // 2):
        res.append((x + 1, (x - (N // 2 - 1) // 2 * 2 + 2 * i) % N + 1))
        x -= 1
        x %= N

else:
    for i in range(N // 2):
        res.append((i + 1, N - i - 1))

for i in range(M):
    a, b = res[i]
    print(a, b)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
venue=[]
if N%2==0:
    l=1
    r=N//2
    while l<r:
        venue.append([l,r])
        l+=1
        r-=1
    l=N//2+1
    r=N-1
    while l<r:
        venue.append([l,r])
        l+=1
        r-=1
else:
    l=1
    r=N//2
    while l<r:
        venue.append([l,r])
        l+=1
        r-=1
    l=N//2+1
    r=N
    while l<r:
        venue.append([l,r])
        l+=1
        r-=1
for a,b in venue:
    M-=1
    print(a,b)
    if M==0:
        break

Submission status: Accepted

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

a = 0
b = M+1

for i in range(M//2):
    a += 1
    b -= 1
    print(a,b)

a = M
b = 2*M+2

for i in range((M+1)//2):
    a += 1
    b -= 1
    print(a,b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=m//2
for i in range (0,k):
    a=i+1
    b=2*k+1-i
    print (a,b)
c=2*k+2
k=(m+1)//2
j=1
#print(c,k)
for i in range (c,c+k):
    a=i
    b=c+2*k-j
    j+=1
    print(a,b)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

if m % 2 == 1:
    #first half
    c = m // 2
    for i in range(c):
        print(i + 1, c * 2 + 1 - i)
        
    #second half
    f = (m // 2) * 2 + 2
    c = m // 2 + 1
    for i in range(c):
        print(f + i, f + c * 2 - 1 - i)
              
else:
    #first half
    c = m // 2
    for i in range(c):
        print(i + 1, c * 2 + 1 - i)
    #second half
    f = (m // 2) * 2 + 2
    c = m // 2
    for i in range(c):
        print(f + i, f + c * 2 - 1 - i)

Submission status: Accepted

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

# process
ans = []

t = 1
for _ in range(M//2):
    ans.append((t, M-t+1))
    t += 1

t = M+1
for _ in range(-(-M//2)):
    ans.append((t, M*3+2-t))
    t += 1

# output
[print(a, b) for a, b in ans]

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

odd_head, odd_tail = 1, 0
even_head, even_tail = 0, 0

if M & 1:
    odd_tail = M + 1
    even_head = M + 2
    even_tail = M + 2 + M - 1
else:
    odd_tail = 1 + (M - 1)
    even_head = M + 1
    even_tail = M + 1 + M

while odd_tail - odd_head > 0:
    print(odd_head, odd_tail)
    odd_head += 1
    odd_tail -= 1

while even_tail - even_head > 0:
    print(even_head, even_tail)
    even_head += 1
    even_tail -= 1

Submission status: Accepted

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

# if N is odd
if M & 1:
    odd_head = 1
    odd_tail = M + 1
    even_head = M + 2
    even_tail = M + 2 + M - 1
    while odd_tail - odd_head > 0:
        print(odd_head, odd_tail)
        odd_head += 1
        odd_tail -= 1

    while even_tail - even_head > 0:
        print(even_head, even_tail)
        even_head += 1
        even_tail -= 1

else:
    odd_head = 1
    odd_tail = 1 + (M - 1)
    even_head = M + 1
    even_tail = M + 1 + M
    while odd_tail - odd_head > 0:
        print(odd_head, odd_tail)
        odd_head += 1
        odd_tail -= 1

    while even_tail - even_head > 0:
        print(even_head, even_tail)
        even_head += 1
        even_tail -= 1

Submission status: Accepted

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = MI()
for i in range(M):
    if N%4==0 and i >= N/4:
        print((-i)%N + 1,3+i)
    elif N%2==0 and 2*i+1 >= N/2:
        print((-i)%N + 1,3+i)
    else:
        print((-i)%N + 1,2+i)

Submission status: Accepted

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

# 左パート
l, r = 1, N // 2
while M and l < r :
  print(l, r)
  l += 1
  r -= 1
  M -= 1
  
# 右パート
l, r = N // 2 + 2 - N % 2, N
while M :
  print(l, r)
  l += 1
  r -= 1
  M -= 1

Submission status: Accepted

Solution code:
def main():
    N,M=map(int,input().split())
    if N%2!=0:
        for i in range(1,M+1):
            print(i,N-i+1)
    else:
        for i in range(1,(M+1)//2+1):
            print(i,N-i+1)
        for i in range((M+1)//2+1,M+1):
            print(i,N-i)
if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

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

    table_num = deque()
    if N % 2 == 1:
        for i in range(1, M+1):
            table_num.append('%s %s' % (i, N-i))

    else:
        for i in range(1, M+1):
            if i <= N // 4:
                table_num.append('%s %s' % (i, N+1 - i))

            else:
                table_num.append('%s %s' % (i, N - i))
    
    for i_table in table_num:
        print(i_table)
    
    return

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


def solve(N: int, M: int):
    if M % 2 == 0:
        for m in range(1, M+1):
            if m % 2 == 1:
                k = (m+1) // 2
                print(k, M+1-k)
            elif m % 2 == 0:
                k = m // 2
                print(M+k, 2*M+2-k)
    if M % 2 == 1:
        for m in range(1, M+1):
            if m % 2 == 1:
                k = (m+1) // 2
                print(k, M+2-k)
            elif m % 2 == 0:
                k = m // 2
                print(M+1+k, 2*M+2-k)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

li = []
i, j = 1, (N + 1) // 2
while i < j:
    li.append((i, j))
    i += 1
    j -= 1
i, j = N, (N + 3) // 2
while i > j:
    li.append((j, i))
    i -= 1
    j += 1

for m in range(M):
    print(li[m][0], li[m][1])

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
ge = []
l = 1
r = n-1
for i in range(m):
    if i%2:
        ge.append(l)
    else:
        ge.append(r)
    l += 1; r -= 1
ge.sort(reverse = True)
for i in range(m):
    print(i+1,i+1+ge[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range((M+1)// 2):
    print(1+i, (M+1)//2*2 - i)

for j in range(M//2):
    print((M+1)//2*2+1 + j, 2*M + 1 - j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if M & 1:
    print(M, M+1)
m=M//2
for i in range(m):
    print(i+1, (-2-i)%N+1)
    print(i+m+1, 2*M-m-i)

Submission status: Accepted

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

a,b=1,N//2
c,d=N//2+1,N
if N%2==0:
    a+=1
i=0
while i<M:
    if i<M:
        print(c,d)
        i+=1        
        c,d=c+1,d-1
    else:
        break
    if i<M:
        print(a,b)
        a,b=a+1,b-1
        i+=1
    else:
        break

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+1
        print(a,b)
else:
    t=0
    for i in range(1,M+1):
        a,b=i,N-i
        if (a-1)+(N+1-b)>=b-a:
            t=1
        a+=t
        print(a,b)

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

A = list(range(M))
B = list(range(M, 2*M))[::-1]
B = [-2-i for i in range(M//2)] + B[M//2:]

for a, b in zip(A, B):
    print(a % N + 1, b % N + 1)

Submission status: Accepted

Solution code:
def e_rotation_matching():
    N, M = [int(i) for i in input().split()]

    if N % 2 == 1:
        ans = [(left, N - left) for left in range(1, (N // 2) + 1)]
    else:
        ans = []
        flag = False
        left, right = 1, N - 1
        while left < right:
            if not flag and right - left <= N // 2:
                right -= 1
                flag = True
            ans.append((left, right))
            left += 1
            right -= 1
    return '\n'.join([f'{a} {b}' for a, b in ans[:M]])

print(e_rotation_matching())

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
ans = []
if N%2==1:
  for i in range(2,N//2+2):
    ans.append((i,N+2-i))
else:
  l = 2
  r = N
  while r-l>N//2:
    ans.append((l,r))
    l += 1
    r -= 1
  l += 1
  while r>l:
    ans.append((l,r))
    l += 1
    r -= 1
for i in range(M):
  print(*ans[i])

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = (n-1) // 2
d = 1
memo = set([])
for i in range(m):
    if n-d in memo or 2*d == n:
        d += 1
    memo.add(d)
    print(a, a+d)
    a -= 1
    d += 2

Submission status: Accepted

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

if N & 1:
    for m in range(1, M+1):
        print(m, N-m)

    exit()

n1, n2 = N//2, N//2
cnt = 0
for n in range(N//2):
    if n+1 >= N//2-n:
        break
    print(n+1, N//2-n)
    cnt += 1
    if cnt == M:
        exit()

for n in range(N//2):
    if n+1 >= N//2-n-1:
        break
    print(n+1+N//2, N-n-1)
    cnt += 1
    if cnt == M:
        exit()

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l=1
r=N
dis=set()
if N%2==1:
    for i in range(M):
        print(l,r)
        l=l+1
        r=r-1
else:
    for _ in range(M):
        print(l,r)
        a,b=r-l,N+l-r
        dis.add(a)
        dis.add(b)
        l=l+1
        r=r-1
        if r-l in dis or N+l-r in dis or r-l==N+l-r:
            r=r-1

Submission status: Accepted

Solution code:
#!python3

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

# odd
def solve1():
    return [(i + 2, N - i) for i in range(M)]        


# even
def solve2():
    t = (N - 2) // 4
    l = [(i + 2, N - i) for i in range(t)]
    n = (N - 2) // 2 - t
    l = l + [(N // 2 + 1 + i, N // 2 - i) for i in range(n)]
    return l[:M]


def main():
    l = solve1() if N % 2 else solve2()
    for ans in l:
        print(*ans)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if n%2:
  k1, k2 = n//2, n//2+1
  for i in range(m):
    print(k1, k2)
    k1 -= 1
    k2 += 1
else:
  key = [False]*(n)
  key[0] = True
  for i in range(1, n):
    if i == n//2-1 or key[i-1] or key[n-2-i]:
      continue
    key[i] = True
  k1, k2 = n//2, n//2+1
  count = 0
  for i in range(n-1):
    if key[i]:
      print(k1, k2)
      count += 1
    if i%2:
      k1 -= 1
    else:
      k2 += 1
    if count == m:
      break

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = 0
for i in range(m):
    if n % 2 == 0 and n % 4 != 0 and n-4*i-2 == 0:
        a = 1
    elif n % 4 == 0 and i == (n//2-1) // 2 + 1:
        a = 1
    print('{} {}'.format(i+1, n-i-a))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
diffs=set()
idxs=set()
i=1
diff=n-1
cnt=0
while 1:
    if i>m:
      break
    while (diff in diffs and n-diff in diffs) or (i+diff in idxs) or (diff==n-diff):
        diff-=1
    diffs.add(n-diff)
    diffs.add(diff)
    idxs.add(i+diff)
    print(i,i+diff)
    i+=1

Submission status: Accepted

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

Submission status: Accepted

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

M1 = M//2
M2 = M-M1

for i in range(M1):
    a=i+1
    b=2*M1+1-i
    print(a,b)
for i in range(M2):
    a=i+1
    b=2*M2-i
    print(2*M1+1 + a,2*M1+1 + b)

Submission status: Accepted

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

a = (n - 1) // 2
d = 1
memo = set([])
cnt = 0
for i in range(m):

    if (n - d in memo) or (2*d == n):
        cnt += 1
        d += 1
    memo.add(d)
    if cnt > 1 or a < 1 or a+d > n:
        print(1/0)
    print(a, a+d)
    a -= 1
    d += 2

Submission status: Accepted

Solution code:
import sys
import math
input = lambda:sys.stdin.readline().strip()
n,m = map(int,input().split())
k = 0
j = 0
for i in range(m):
    if n%2==0 and ((n-j)-(i+1))*2<=n and k==0:
        j+=1
        k+=1
    print(i+1,n-j)
    j+=1

Submission status: Accepted

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

if n % 2 == 1:
    a = [i for i in range(1, m+1)]
    b = [i for i in reversed(range(m+1, 2*m+1))]
    ab = [(x, y) for x, y in zip(a, b)]
else:
    ab = []
    x, y = (n-1)//2, n//2
    if x % 2 != 0:
        x, y = y, x

    evenl = 1
    evenr = x
    while evenl < evenr:
        ab.append((evenl, evenr))
        evenl += 1
        evenr -= 1

    oddl = x+1
    oddr = n-1
    while oddl < oddr:
        ab.append((oddl, oddr))
        oddl += 1
        oddr -= 1

    ab = ab[:m]


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

Submission status: Accepted

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

def main():
    N,M = map(int,input().split())
    cl = []
    for i in range(M//2):
        cl.append((i+1,(M//2)*2+1-i))
    for i in range(-(-M//2)):
        l = (M//2)*2+i+2
        cl.append((l,l+(-(-M//2)-i)*2-1))
    
    for i in range(M):
        print(*cl[i])
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = map(int, input().split())
res = []

def solve(l, r):
  global res
  if r <= l: return
  res.append((l, r))
  solve(l + 1, r - 1)


solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res: print(*r)

Submission status: Accepted

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

Submission status: Accepted

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

if n%2 == 1:
    for i in range(m):
        print(n//2-i,n//2+i+1)
else:
    ni = 1
    l = 1
    r = n
    while ni <= n//4 and ni <= m:
        print(l,r)
        l += 1
        r -= 1
        ni += 1
    r -= 1
    while ni <= m:
        print(l,r)
        l += 1
        r -= 1
        ni += 1

Submission status: Accepted

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

if m%2 == 0:
    gu_max, ki_max = m, m-1
else:
    gu_max, ki_max = m-1, m
gu_start = 1
ki_start = 1 + gu_max + 1

for sa in range(m)[::-1]:
    sa += 1
    if sa%2 == 0:
        print(gu_start, gu_start+sa)
        gu_start += 1
    else:
        print(ki_start, ki_start+sa)
        ki_start += 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:
    left_end = 1+m if m%2 == 1 else m
    left_start = left_end//2
    right_start = left_end+m//2
    for i in range(1,m+1):
        if i%2 == 1:
            print(left_start,left_start+i)
            left_start-=1
        else:
            print(right_start,right_start+i)
            right_start-=1

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
assert 2*M+1 <= N

if M % 2 == 1:
    step_m1 = M
    step_m2 = M - 1
else:
    step_m1 = M - 1
    step_m2 = M
assert step_m1 + 1 + step_m2 + 1 <= N
ans = []
a = 0
for step in range(step_m1, -1, -2):
#     print(step)
#     print(a, a+step)
    ans.append([a+1, a+step+1])
    a += 1
a = step_m1 + 1
for step in range(step_m2, 0, -2):
#     print(step)
#     print(a, a+step)
    ans.append([a+1, a+step+1])
    a += 1
print('\n'.join(map(lambda L: ' '.join(map(str, L)), ans)))

Submission status: Accepted

Solution code:
def e_rotation_matching():
    # 参考: https://maspypy.com/atcoder-参加感想-2020-05-02abc-165
    import numpy as np
    N, M = [int(i) for i in input().split()]

    A = np.arange(M)  # 剰余計算の簡便のため、0-origin とする
    B = 2 * M - 1 - A  # N >= 2*M - 1 だが、N = 2*M - 1 の場合と同じ構築でよい
    # 剰余を取ったときに mod N に対して A, B の全要素が互いに異なるようにしたい
    B[:M // 2] -= (2 * M + 1)

    A %= N  # 全要素は正整数でないといけない
    B %= N
    A += 1  # A, B は 0-origin としていたため
    B += 1
    return '\n'.join([f'{a} {b}' for a, b in zip(A.tolist(), B.tolist())])

print(e_rotation_matching())

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split())
    if n%2==1:
        x=[f"{i+1} {n-i}" for i in range(m)]
        print(" ".join(x))
    else:
        x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
        print(" ".join(x))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n%2==1:
    x=[f"{i+1} {n-i}" for i in range(m)]
    print(" ".join(x))
else:
    x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
    print(" ".join(x))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if M%2 != 0:
    center = M + 1
else:
    center = M
c = center//2
d = (center + 1 + 2*M + 1) // 2

i = 0
while i < c:
    print(c-i, c+1+i)
    i += 1
j = 0
while i < M:
    print(d-(j+1), d+(j+1))
    i += 1
    j += 1

Submission status: Accepted

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

from collections import deque

l = deque([i for i in range(1, n + 1)])

if n % 2 ==0:
    for i in range(1, m + 1):
        a, b = l.popleft(), l.pop()
        if (b - a) == n / 2 or (len(l) < n // 2 and (b-a) % 2 == 1):
            b = l.pop()
        print(a, b)
else:
    for i in range(1, m + 1):
        print(i, n - i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n%2==1:
    x=""
    for i in range(m):
        x+=f"{i+1} {n-i} "
    print(x)
else:
    x=""
    for i in range(m):
        x+=(f"{i+1} {n-i} " if i<m/2 else f"{i+1} {n-i-1}\n")
    print(x)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n%2==1:
    x=""
    for i in range(m):
        x+=f"{i+1} {n-i}\n"
    print(x)
else:
    x=""
    for i in range(m):
        x+=(f"{i+1} {n-i}\n" if i<m/2 else f"{i+1} {n-i-1}\n")
    print(x)

Submission status: Accepted

Solution code:
#ABC165-E Rotation Matching
"""
各頂点を円形に並べた時に、距離が等しくならないようにm個の辺を張れば良い。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m = map(int,readline().split())
mod = n
lst1 = []
for i in range(m):
    lst1.append(i)

lst2 = []
for i in range(m):
    lst2.append(2*m-1-lst1[i])

for i in range(m//2):
    lst2[i] -= 2*m+1

for i,j in zip(lst1,lst2):
    print(i%mod+1,j%mod+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+1-i)
else:
    for i in range(1,M+1):
        if i == N//4+1:
            break
        print(i,N+1-i)
        if i == M:
            quit()
    for j in range(i,M+1):
        print(j+1,N+1-j)