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

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    L = [i for i in range(1, n+1)]
    if n % 2 == 1:
        for dist in range(m):   
            print(f"{L[dist]} {L[-1-dist]}")
    else:
        if (n - 2) % 4 == 0:
            tmp = (n - 2) // 4
        else:
            tmp = (n - 2) // 4 + 1
        for dist in range(m):
            if dist + 1 <= tmp: 
                print(f"{L[dist]} {L[-1-dist]}")
            else:
                print(f"{L[dist]} {L[-2-dist]}")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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

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

else:

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,m = map(int, input().split())
    if n%2==0 and 2*(m+1)==n:
        if n%4:
            for i in range(1,n//4+1):
                print(i,n//2-i)
            j = n

            for i in range(n//2+1,n//2+n//4+1):
                print(i,j)
                j -= 1
        else:
            for i in range(1,n//4+1):
                print(i,n//2+1-i)
            j = n-1
            for i in range(n//2+1,n//2+n//4):
                print(i,j)
                j -= 1
    else:
        for i in range(1,m+1):
            print(i,n-i)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:


n, m = [0] * 2

def format_input(filename = None):
	global n, m
	if filename == None:
		n, m = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(3, 10**5)
		m = rng(1, (n-1) // 2)
		print(n, m)

def get_answer():
	median = n // 2

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


if __name__ == '__main__':
	format_input()

	get_answer()

Submission status: Accepted

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

from math import gcd

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n,m = l_in()

#n = 12
#m = n//2-1



i = 1
s = set()
if n%2 == 0:
    s.add(n//2)
    j = n
    for cnt in range(m):
        while True:
            if min(j-i, n-(j-i)) in s:
                j -=1
            else:
                break
            
        print(i,j)
        s.add(min(j-i, n-(j-i)))

        i+=1
        j-=1
        
else:
    j = n-1
    for cnt in range(m):
        print(i,j)
#        print(min(j-i,n-(j-i)))
        i+=1

        j-=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+1)
else:
  if N/4 >= M:
    for i in range(1,M+1):
      print(i,N-i+1)
  else:
    for i in range(1,(N//4)+1):
      print(i,N-i+1)
    for j in range(1,M-(N//4)+1):
      print(N//2-j,N//2+j)

Submission status: Accepted

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

x = int(M // 2)

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

Submission status: Accepted

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

end = n
dif = set()
count = 0
for i in range(1, n+1):
    while end-i in dif or n+i-end in dif or end-i == n+i-end:
        end -= 1
    print(i, end)
    dif.add(end-i)
    dif.add(n+i-end)
    end -= 1
    count += 1
    if count == m:
        break

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N % 2 == 1:
    for i in range(M):
        print(1+i, 2*M-i)
elif (N // 2) % 2 == 1:
    amari = N-(M*2)
    n = amari+1
    for i in range(M):
        if n * 2 == N:
            break
        n += 2
    else:
        for i in range(M):
            print(1+i, 2*M-i)
        exit()
    for k in range(M):
        if k <= i:
            print(1+k, 2*M-k+1)
        else:
            print(1+k, 2*M-k)
else:
    amari = N-(M*2)
    n = amari + 2
    for i in range(1, M):
        if n * 2 == N:
            break
        n += 2
    else:
        for i in range(M):
            print(1+i, 2*M-i)
        exit()
    for k in range(M):
        if k < i:
            print(1+k, 2*M-k+1)
        else:
            print(1+k, 2*M-k)

Submission status: Accepted

Solution code:
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, read().split())
l = M
checked = [False] * (N + 10)

if N % 2 == 1:
    for i in range(1, M + 1):
        r = l + 2 * i - 1
        print(l, r)
        l -= 1

else:
    p = (M + 1) // 2
    for i in range(1, p + 1):
        r = l + 2 * i - 1
        print(l, r)
        l -= 1
    for i in range(p + 1, M + 1):
        r = l + 2 * i - 1 + 1
        print(l, r)
        l -= 1

Submission status: Accepted

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

if N%2 == 1:
    for i in range(1,M+1):
        print(i,N+1-i)
        
else:
    f = True
    l,r = 1,N
    for i in range(1,M+1):
        print(l,r)
        l+=1
        r-=1
        if f and (4*l > N):
            l+=1
            f = False

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: #こっちに問題あり
    for i in range(M):
        if i<N//4:
            print(i+1,N-i)
        else:
            print(i+1,N-i-1)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    import math
    input = stdin.readline

    # import random

    n, m = map(int, input().split())
    """
    a = random.randint(1, 10**6)
    b  = random.randint(1, 10**6)
    n = random.randint(1, 10**12)
    """
    # print(a, b, n)
    
    for i in range(1,m+1):
        if (m-i)%2 == 1:
            print((m+1-i)//2, (m+1-i)//2+i)
        else:
            print(m+(m+2-i)//2, m+(m+2-i)//2+i)

Submission status: Accepted

Solution code:
# E - Rotation Matching

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

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

Submission status: Accepted

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

if M % 2 == 0:
    k = M // 2
    s1 = 1
    e1 = 2 * k
    s2 = 2 * k + 1
    e2 = 4 * k + 1
else:
    k = (M + 1) // 2
    s1 = 1
    e1 = 2 * k
    s2 = 2 * k + 1
    e2 = 4 * k - 1

n = 0
for _ in range(M):
    if s1 >= e1 or n >= M: break
    print(s1, e1)
    s1 += 1
    e1 -= 1
    n += 1

for _ in range(M):
    if s2 >= e2 or n >= M: break
    print(s2, e2)
    s2 += 1
    e2 -= 1
    n += 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)
    exit()
ans = []
if n % 4 == 0:
    for i in range(1,n//4+1):
        ans.append((i,n//2-i+1))
    for i in range(m-len(ans)):
        ans.append((n//2+2+i,n-i))
else:
    for i in range(2,n//4+2):
        ans.append((i,n//2-i+2))
    for i in range(m-len(ans)):
        ans.append((n//2+i+1,n-i))
for i in range(m):
    print(ans[i][0],ans[i][1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
f = [False]*N
l = 0
r = N+1
for i in range(M):
    l += 1
    r -= 1
    while True:
        if N % 2 == 0:
            if r-l == N//2:
                r -= 1
                continue
        if f[min(r-l, N-(r-l))]:
            r -= 1
            continue
        break
            
    f[min(r-l, N-(r-l))] = True
    print(l, r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    left = 1
    right = N if N%2 == 0 else N-1
    count = 0
    if N%2 == 0:
        p = set()
        while count < M:
            if right-left == N//2 or N-(right-left) in p:
                left += 1
                continue
            print(left,right)
            p.add(right-left)
            left += 1
            right -= 1
            count += 1
    else:
        while count < M:
            print(left,right)
            left += 1
            right -= 1
            count += 1
    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())
k=n//2
c=0
while c<m:
    d=c//2
    if c%2==0:
        print(k-d,k+1+d)
    else:
        print(d+1,n-1-d)
    c+=1

Submission status: Accepted

Solution code:
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys,heapq,math
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N, M = map(int, read().split())
    ans1 = N // 2
    ans2 = N // 2 + 1
    action = 0
    if N%2 == 0:
        action = -(-N//4)
    for _ in range(M):
        print(ans1, ans2)
        ans1 -= 1
        ans2 += 1
        if ans1 == action:
            ans2 += 1
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
c = 1
if n%2 == 1:
    aida = n//2
    flag = 0
    while m > 0:
        if flag == 0:
            print(c, c+aida)
            flag = 1
            m-=1
            aida -= 1
        else:
            print(n-c+1,n-c+1-aida)
            flag = 0
            m-=1
            aida -= 1
            c+=1
else:
    aida = n//2-1
    flag = 0
    while m > 0:
        if flag == 0:
            print(c, c+aida)
            flag = 1
            m-=1
            aida -= 1
        else:
            print(n-c+1,n-c+1-aida)
            flag = 0
            m-=1
            aida -= 1
            c+=1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N % 2 == 0:
    num = 0
    mid = N // 2
    for i in range(M):
        print(mid - i, mid + 1 + i)
        num += 1
        if num == M:
            break
        print(1 + i, N - 1 - i)
        num += 1
        if num == M:
            break
else:
    mid = (N + 1) // 2
    for i in range(M):
        print(mid - i, mid + 1 + i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = int(n/2)
b = a+1
offset = False
if n%2 == 0:
	offset = True
for i in range(m):
	if offset and b-a >= n/2:
		b += 1
		offset = False
	print(a,b)
	a -= 1
	b += 1

Submission status: Accepted

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

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,r])
    else:
        ge.append([r,l])
    l+= 1; r-= 1
ge.sort(reverse = True)
# print(ge)
x = 1
for i in range(m):
    a,b = ge[i]
    print(x,x+a)
    x += 1

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# M個用意する対戦場の数字の差が異なるようにする
N, M = lr()
answer = [[0, 0] for _ in range(M)]
if N&1:
    for i in range(M):
        answer[i][0] = i+1

    cur = M+1
    used = set()
    for i in range(M-1, -1, -1):
        while cur - answer[i][0] in used:
            cur += 1
        answer[i][1] = cur
        diff = answer[i][1] - answer[i][0]
        used.add(diff)
        cur += 1
else:
    l = list(range(1, M+1))
    odd = [x for x in l if x&1]
    even = [x for x in l if x%2==0]
    cur = 0
    for x in odd[::-1]:
        answer[cur] = [cur+1, cur+1+x]
        cur += 1
    now = 1 + odd[-1] + 1
    for x in even[::-1]:
        answer[cur] = [now, now+x]
        now += 1
        cur += 1

for a in answer:
    if a[0] == 0:
        continue
    print(*a)

Submission status: Accepted

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

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

Submission status: Accepted

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

    # i = 0
    # cnt = 0
    # while cnt < M:
    #     if (N - i * 2 - 1) * 2 != N:
    #         print(1 + i, N - i)
    #         cnt += 1
    #     i += 1



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

    for row in ans:
        print(*row)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

halfPos = -(-N//2)

qPos = halfPos // 2

q3Pos = qPos + halfPos

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# E - Rotation Matching

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

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

Submission status: Accepted

Solution code:
#n=int(input())
n,m=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(q)]
b=(n-1)//2
a=b//2
ll=[[0,0]for i in range(b)]
ll[0]=[1,2]

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

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

li = [True] * n

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

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

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

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

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


	


if __name__ == '__main__':
	main()

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

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

    start = 1
    end = N

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

        start += 1
        end -= 1

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

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

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

mod = 10**9 + 7

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

#################

N,M = LI()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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