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

Submission status: Accepted

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

l = m // 2 * 2 + 1
for i in range(1, l + 1):
    if i < l - i + 1:
        print(i, l - i + 1)

r = (m + 1) // 2 * 2 + l
for i in range(l + 1, r + 1):
    if i < r - i + l + 1:
        print(i, r - i + l + 1)

Submission status: Accepted

Solution code:
def solve(n, m):
    res_list = []
    if n % 2 == 1:
        for i in range(m):
            res_list.append([i + 1, 2 * m - i])
    else:
        k = (m + 1) // 2
        for i in range(k):
            res_list.append([i + 1, 2 * k - i])
        for i in range(m - k):
            res_list.append([2 * k + i + 1, 2 * m + 1 - i])
    return res_list


def main():
    n, m = map(int, input().split())
    res = solve(n, m)
    for r in res:
        print(" ".join([str(a) for a in r]))


def eval_res(n, ab_list):
    eval_dict = dict()
    for a, b in ab_list:
        d = (a - b) % n
        if d in eval_dict.keys():
            return False
        eval_dict[d] = 1
        d = (b - a) % n
        if d in eval_dict.keys():
            return False
        eval_dict[d] = 1
    return True


def test():
    assert eval_res(4, solve(4, 1))
    assert eval_res(7, solve(7, 3))


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
N,M = list(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())
list=list(range(1,n+1))
if n%2==1:
  for i in range(m):
    print(list[i],list[-1-i])
elif n%4==0:
  h=n//2
  hh=n//4
  if hh>=m:
    for i in range(m):
      print(list[i],list[-1-i])
  else:
    for i in range(hh):
      print(list[i],list[-h-1-i])
    for i in range(m-hh):
      print(list[h+i],list[-2-i])
else:
  h=n//2
  hh=(h-1)//2
  if hh>=m:
    for i in range(m):
      print(list[i],list[-1-i])
  else:
    for i in range(hh):
      print(list[i],list[-h-1-i])
    for i in range(m-hh):
      print(list[h+i],list[-2-i])

Submission status: Accepted

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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int):
    if N % 2 == 1:
        s = N // 2
        for i in range(M):
            v = i * 2 + 1
            print(s, s + v)
            #print(s, s + v, v, N - v)
            s -= 1
    else:
        s = N // 2
        cnt = 0
        used = set()
        for i in range(M // 2 + 1):
            v = i * 2 + 1
            if v == N // 2 or v in used:
                continue
            print(s, s + v)
            #print(s, s + v, v, N - v)
            s -= 1
            cnt += 1
            used.add(v)
            used.add(N - v)
        s = 1
        for i in range(M - cnt):
            v = N - s - s
            print(s, N - s)
            #print(s, N - s, v, N - v)
            s += 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] = list(map(int,input().split()))
s = 1
if N%2==0:
    t = N
    flag = 0
    for i in range(M):
        if (flag==0)and(s>N//4):
            s+=1
            flag =1
        print(s,t)
        s += 1
        t += -1
else:
    t = N-1
    for i in range(M):
        print(s,t)
        s += 1
        t += -1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    res = []
    kisuu = n
    guusuu = n//2
    for i in range(1, m+1):
        if i%2 == 1:
            res.append([(kisuu+i)%n, kisuu])
            kisuu -= 1
        else:
            res.append([guusuu, guusuu+i])
            guusuu -= 1
    for a,b in res:
        print(a,b)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
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(min(m, math.floor(int(n/4)))):
        print(i+1, n-i)
    for i in range(max(0, m-math.floor(int(n/4)))):
        print(i+1+min(m, math.floor(int(n/4))), n-i-min(m, math.floor(int(n/4)))-1)

Submission status: Accepted

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

for i in range(m):
  if n / 2 == 2 * i + 1 or 4 * i == n:
    e = 1
  print(str(n // 2 - i) + " " + str(n // 2 + 1 + i + e))

Submission status: Accepted

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

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

H = N // 2
if H % 2 == 1:
	H += 1

m = 0
i = 1
while m < M:
	print(i, H - i + 1)
	i += 1
	m += 1
	if i >= H - i + 1:
		break

i = 1
while m < M:
	print(H + i, N + 1 - i)
	i += 1
	m += 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    if N%2==1:
        left=1
        right=N-1
        for _ in range(M):
            print(left,right)
            left+=1
            right-=1
    else:
        for right in [N,N-1]:
            ans=[]
            f=True
            left=1
            for i in range(1,M+1):
                if (right-left)*2==N:
                    break
                ans.append((left,right))
                left+=1
                right-=1
                if right-left<=N//2 and f:
                    right-=1
                    f=False
            else:
                for a in ans:
                    print(*a)
                exit()
            
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n %2 == 0:
    left = 1
    right = 2*m+1
    al = set()
    for i in range(m):
        if right -left in al:
            right -= 1
        if right-left == n//2:
            right -= 1
        print(left,right)
        outs = n - (right-left)
        al.add(outs)
        left += 1
        right -= 1

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7

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

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)
a=1
b=n

def nxt(a,b):
    b-=1
    while True:
        a+=1
        if b-a != n-b+a and d[b-a] != 1 and d[n-b+a] != 1:
            break
    d[b-a]+=1
    d[n-b+a]+=1
    return a,b


for i in range(m):
    print(a,b)
    a,b = nxt(a,b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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:
  a = 1; b = n
  tmp = n
  while b-a > n//2:
    print(a,b)
    a += 1
    b -= 1
    count += 1
    if count >= m:exit()
  b-=1
  for i in range(m-count):
    print(a,b)
    a += 1
    b -= 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = list(map(int,input().split()))
base = N
if N%2==1:
  for i in range(1,M+1):
    print(i,base-i)
else:
  if N%4==0:
    candidate = []
    for i in range(1,N//4+1):
      candidate.append((i,N+1-i))
    for i in range(N//4+1,N//2):
      candidate.append((i,N-i))
  else:
    candidate = []
    for i in range(1,N//4+1):
      candidate.append((i,N+1-i))
    for i in range(N//4+1,N//2):
      candidate.append((i,N-i))
  for i in range(M):
    a,b = candidate[i]
    print(a,b)

Submission status: Accepted

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

ans = []

q = []

for i in range(1,M+1):

    if i % 2 == 1:
        q.append(N-i)
    else:
        q.append(i)

q.sort()
ind = 0
q.reverse()
q.append(float("inf"))
ind = 0

use = [True] * (N+1)

cnt = 0
for i in range(1,N//2+1):

    if use[i + q[ind]]:
        print (i , i+q[ind])
        ind += 1
        cnt += 1

    if cnt == M:
        sys.exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May  2 21:39:58 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
N, M = map(int,input().split())
#A = list(map(int,input().split()))
#graph = [[] for _ in range(N+1)]
#for _ in range(N-1):
#    a, b = map(lambda x : int(x)-1, input().split())
#    graph[a].append(b)
#    graph[b].append(a)

odd = (N % 2 != 0)
ans = []
if odd:
    x = N - 1
    for i in range(M):
        ans.append([i+1,x])
        x -= 1
else:
    x = N
    flg = True
    for i in range(M):
        if flg and x - (i+1) <= N//2:
            x -= 1
            flg = False
        ans.append([i+1,x])
        x -= 1
#        
#    for i in range(M//2 + 1,M):
#        ans.append([i+1,x-1])
#        x -= 1

for a in ans:
    print(' '.join(map(str,a)))

Submission status: Accepted

Solution code:
def solve(N, M):
  U = [False]*N
  a = 1
  b = N
  ans = []
  for i in range(M):
    while U[b-a] or U[a+N-b] or (b-a)*2==N:
      b -= 1
    ans += [(a, b)]
    U[b-a] = U[a+N-b] = True
    a += 1
    b -= 1
  return ans

def check(N, M, ans):
  S = set()
  for i in range(N):
    for a in ans:
      s = tuple(sorted(((a[0]+i)%N, (a[1]+i)%N)))
      if s in S:
        return False
      S.add(s)
  return True

"""
for M in range(1, 10):
  for N in range(M*2+1, 100):
    ans = solve(N, M)
    if not check(N, M, ans):
      print(N, M)
      exit(0)
"""

N, M = map(int, input().split())
for a, b in solve(N, M):
  print(a, b)

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

Submission status: Accepted

Solution code:

MOD = 10 ** 9 + 7

def main():
    for _ in inputt(1):
        N, M = inputi()
        if N % 2:
            for i in range(M):
                print(i + 1, N - i)
        else:
            for i in range(M):
                if i % 2:
                    print((N - i) // 2, (N + i + 1) // 2)
                else:
                    print(i // 2 + 1, N - i // 2)

# region M


# region import

from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)

# endregion

# region fastio

BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    if args:
        sys.stdout.write(str(args[0]))
        split = kwargs.pop("split", " ")
        for arg in args[1:]:
            sys.stdout.write(split)
            sys.stdout.write(str(arg))
    sys.stdout.write(kwargs.pop("end", "\n"))
def debug(*args, **kwargs):
    print("debug", *args, **kwargs)
    sys.stdout.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda k = int: map(k, inputs())
inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k())

# endregion

# region bisect

def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError

# endregion

# region csgraph
# TODO

class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass

# endregion

# region ntheory

class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        if n <= self._list[-1]: return
        maxbase = int(n ** 0.5) + 1
        self.extend(maxbase)
        begin = self._list[-1] + 1
        newsieve = [i for i in range(begin, n + 1)]
        for p in self.primerange(2, maxbase):
            for i in range(-begin % p, len(newsieve), p):
                newsieve[i] = 0
        self._list.extend([x for x in newsieve if x])
    def extend_to_no(self, i):
        while len(self._list) < i: 
            self.extend(int(self._list[-1] * 1.5))
    def primerange(self, a, b):
        a = max(2, a)
        if a >= b: return
        self.extend(b)
        i = self.search(a)[1]
        maxi = len(self._list) + 1
        while i < maxi:
            p = self._list[i - 1]
            if p < b:
                yield p
                i += 1
            else: return
    def search(self, n):
        if n < 2: raise ValueError
        if n > self._list[-1]: self.extend(n)
        b = bisect(self._list, n)
        if self._list[b - 1] == n: return b, b
        else: return b, b + 1
    def __contains__(self, n):
        if n < 2: raise ValueError
        if not n % 2: return n == 2
        a, b = self.search(n)
        return a == b
    def __getitem__(self, n):
        if isinstance(n, slice):
            self.extend_to_no(n.stop + 1)
            return self._list[n.start: n.stop: n.step]
        else:
            self.extend_to_no(n + 1)
            return self._list[n]

sieve = Sieve()
def isprime(n):
    if n <= sieve._list[-1]:
        return n in sieve
    for i in sieve:
        if not n % i: return False
        if n < i * i: return True
prime = sieve.__getitem__
primerange = lambda a, b = 0: sieve.primerange(a, b) if b else sieve.primerange(2, a)
def factorint(n):
    factors = []
    for i in sieve:
        if n < i * i: break
        while not n % i:
            factors.append(i)
            n //= i
    if n != 1: factors.append(n)
    return factors
factordict = lambda n: Counter(factorint(n))

# endregion

# region main

if __name__ == "__main__":
    main()

# endregion


# endregion

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
i = 0
j = 1
k = 0
while j < n//2 and k < m:
    print(i % n + 1, (i + j) % n + 1)
    i -= 1
    j += 2
    k += 1
i = (i + j - 1 + (m - k)) % n
j = 2
while k < m:
    print(i % n + 1, (i + j) % n + 1)
    i -= 1
    j += 2
    k += 1

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    if m&1:
        k = (m>>1)+1
        for i in range(k):
            print(i+1,m+1-i)
        for i in range(k-1):
            print(m+2+i,2*m+1-i)
    else:
        k = m>>1
        for i in range(k):
            print(i+1,m+1-i)
        for i in range(k):
            print(m+i+2,2*m-i+1)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def func(x):
    while True:
        if x <= 0:
            x += N
        else:
            break
    return x


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

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

else:
    a = 1
    b = 2
    for i in range(M):
        print(func(a), func(b))
        a -= 1
        b += 1
        if b == int(2 + N / 4):
            a -= 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
 
####
from collections import deque
def solve(N, M):
    ans = []
    if N & 1:
        tops = deque(xrange(1, 2 * M + 1))
        while tops:
            ans.append([tops.popleft(), tops.pop()])
 
    else:
        # 1, 2, 3, 4, ..., M
        # there are (M+1)/2 odd numbers
        odds = (M + 1) // 2
        evens = M - odds
        i = odds
        d = 1
        for m in range(1, odds + 1):
            ans.append([i, i+d])
            i -= 1
            d += 2
        i = 2 * odds + evens
        d = 2
        for m in range(1, evens + 1):
            ans.append([i, i+d])
            i -= 1
            d += 2
            
 
    for row in ans:
        print "{} {}".format(*row)

solve(*rrm())

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if N % 2:
    for i in range(M):
        print(1+i,N-i,sep=" ")
else:
    even = M // 2
    odd = M - even
    for i in range(odd):
        print(1+i,N-i,sep=" ")
    st = 1 + odd
    en = st + even * 2
    for i in range(even):
        print(st+i,en-i,sep=" ")

Submission status: Accepted

Solution code:
import math
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import heapify, heappop, heappush
from itertools import chain, combinations, permutations, product
from typing import List, Dict

# import numpy as np

sys.setrecursionlimit(10**5 + 1)
input = sys.stdin.readline
write = sys.stdout.write


def read_item(cls=int):
    return cls(input())


def read_n_item(cls=int) -> list:
    return [cls(s) for s in input().split()]


def list2d(row, col, init_val=0) -> List[list]:
    return [[init_val] * col for _ in range(row)]


MOD = 10**9 + 7
# MOD = 998244353


N, M = read_n_item()
if N & 1:
    for i in range(1, M+1):
        print(i, N-i+1)
else:
    used = [False] * (N+1)
    left, right = 1, N
    cnt = 0
    for i in range(1, N//2+1):
        if cnt == M:
            break
        l_d = right-left
        r_d = left+N-right
        if not used[right-left] and not used[left+N-right] and l_d != r_d:
            used[right-left] = used[left+N-right] = True
            print(left, right)
            cnt += 1
            left += 1
            right -= 1
        else:
            left += 1

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

cand=list(range(1,n+1))

ans=[]
for i in range(1,(m+1)//2+1):
    ans.append((cand[1-i],i+1))

n_odd = m//2
start = ans[-1][1]+n_odd
for i in range(1,n_odd+1):
    ans.append((start-i+1,start+i+1))

for aa in ans:
    print(*aa)

Submission status: Accepted

Solution code:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    # N = int(input())
    N, M = [int(a) for a in input().split()]

    D = (M - 1) // 2 + 1
    D2 = M - D

    for ii in range(M):

        if ii % 2 == 0:
            j = (ii) // 2
            a = D - 1 - j
            b = a + 2 * j + 1
        else:
            j = (ii - 1) // 2
            a = 2 * D + (D2 - 1 - j)
            b = a + 2 * j + 2
        print(a + 1, b + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

ans = []

if(n%4==2):
    mmax = n//2 - 1
    for i in range(mmax//2):
        j = 1 + 2*i
        left = n//2 - i
        ans.append([left,left+j])
    for ii in range(mmax//2):
        i = ii + mmax//2
        j = 2+2*i
        left = n//2 - i
        ans.append([left,left+j])
elif(n%4==0):
    mmax = n//2 -1
    for i in range(mmax//2+1):
        j = 1 + 2*i
        left = n//2 - i
        ans.append([left,left+j])
    for ii in range(mmax//2):
        i = ii + mmax//2 + 1
        j = 2+2*i
        left = n//2 - i
        ans.append([left,left+j])
else:
    mmax = n//2
    for i in range(mmax):
        j = 2*i+1
        left = n//2-i
        ans.append([left,left+j])

#print(ans)

for i in range(m):
    print(ans[i][0],ans[i][1])