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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools

# 標準入力の取得
N, M = list(map(int, input().split()))

# 求解処理
paticipants = list(range(1, N+1))
result = []
eigenvalues = []
match_count = 0
while match_count < M:
    for a, b in itertools.combinations(paticipants, 2):
        eigenvalue1 = b - a - 1
        eigenvalue2 = a - b + 7
        if eigenvalue1 in eigenvalues or eigenvalue2 in eigenvalues:
            continue

        result.append([a, b])
        eigenvalues.append(eigenvalue1)
        eigenvalues.append(eigenvalue2)
        paticipants.remove(a)
        paticipants.remove(b)
        match_count += 1
        break

for a, b in result:
    print(f"{a} {b}")

Submission status: Time Limit Exceeded

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

a = N//2
b = a+1
dist = []

for i in range(M):
    print(a, b)
    dist.append(b-a)
    dist.append(N-b + a)
    a -= 1
    b += 1
    if b-a == N-b + a:
        b += 1
    if b-a in dist:
        b += 1
    if N-b + a in dist:
        b += 1

Submission status: Time Limit Exceeded

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

l = 0
num = set()
step = set()
for k in range(1, M + 1):
    while True:
        if l in num:
            l += 1
            l %= N
            continue
        if (l + k) % N not in num:
            break
        if (l + (N - k)) % N not in num:
            l = (l + (N - k)) % N
            break
        l += 1
        l %= N

    print(l + 1, (l + k) % N + 1)
    num.add(l)
    num.add((l + k) % N)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N,M = map(int, input().split())
N = 2 * M + 1

lis = [i for i in range(1,N+1)]
if M % 2 == 0:
    lis1 = lis[:N//2+1]
    lis2 = lis[N//2+1:]
    for i in range(M//2):
        a = lis1.pop(0)
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.pop(0)
        b = lis2.pop()
        print(a,b)
else:
    lis1 = lis[:N//2+1]
    lis2 = lis[N//2+1:]
    for i in range(M//2+1):
        a = lis1.pop(0)
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.pop(0)
        b = lis2.pop()
        print(a, b)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
used = set()
start = 0 
apart = 1
while M > 0 :
    while start in used or (start+apart)%N in used :
        start += 1
        start %= N 
    used.add(start)
    used.add((start+apart)%N)
    print(start%N+1, (start+apart)%N+1)
    apart += 1
    M -= 1

Submission status: Time Limit Exceeded

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

def allans2(N):
    ans = []
    m = (N-1)//2
    n1 = m
    n2 = m-1
    for i in range(n1//2 + n1%2):
        ans.append([i+1,i+1+n1-i*2])
    for i in range(n2//2 + n2%2):
        ans.append([N-i-(n2-i*2),N-i])
    return ans
    

for i in range(M):
    ans = allans2(N)
    print(ans[i][0],ans[i][1])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
x = [True for _ in range(n)]
ans = []
i = 0
j = 1
while len(ans) < m:
    if x[i] and x[j]:
        ans.append((i + 1, j + 1))
        x[i] = False
        x[j] = False
        j += 1
    i += 1
    i %= n
    j += 1
    j %= n
for a in ans:
    print(*a)

Submission status: Time Limit Exceeded

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

import random
import numpy as np


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


def try_get(N: int, M: int) -> (bool, list):
    used_flag = np.zeros(N)
    stage_marks = []  # [(v1,v2)]
    ones = np.ones(N)
    for length in reversed(range(1, M+1)):
        numbers = np.arange(N - length) + 1
        numbers = numbers[np.logical_and(used_flag[:(N-length)]==0,used_flag[length:N]==0)]
        if len(numbers) == 0:
            return False, []
        num = np.random.choice(numbers)
        stage_marks.append((num, num + length))
        used_flag[num-1] = 1
        used_flag[num+length-1] = 1

    return True, stage_marks


ok = False
marks = []
while not ok:
    ok, marks = try_get(N, M)

for src, dst in marks:
    print("{} {}".format(src, dst))

Submission status: Time Limit Exceeded

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:
    #lst=set([i for i in range(1,N//2+1)])
    visited=set()
    c=1
    z=1
    while M:
        if c>N:
            c=1
        if c in visited:
            c+=1
            continue
        else:
            Z=c+z
            if Z>N:
                Z-=N
            if Z in visited:
                c+=1
                continue
            else:
                print(c,Z)
                visited.add(c)
                visited.add(c+z)
                c+=1
                z+=1
                M-=1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
x = [True for _ in range(n)]
k = 1
ans = []
i = 0
while len(ans) < m:
    if x[i % n] and x[(i + k) % n]:
        ans.append((i + 1, i + k + 1))
        x[i] = False
        x[i + k] = False
        k += 1
    i += 1
for a in ans:
    print(*a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = list(map(int, input().split()))
    if N % 2 == 1:
        for i in range(M):
            print(i + 1, N - i - 1)
            
    else:
        A = [False] * N
        t = 0
        for i in range(M):
            while True:
                while A[t%N]:
                    t += 1
                A[t%N] = True
                if A[(t + i + 1)% N]:
                    A[t%N] = False
                    t += 1
                    continue
                break
            A[(t + i + 1) % N] = True
            print(t%N + 1, (t + i + 1)%N + 1)

main()

Submission status: Time Limit Exceeded

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


def allans(N):
    ans = []
    m = (N-1)//2
    start,end =1,m+1
    while end-start >= 1:
        ans.append([start,end])
        start += 1
        end -= 1
    start,end = m+2,m+m+1
    while end-start>=1:
        ans.append([start,end])
        start += 1
        end -= 1
    return ans

for i in range(M):
    ans = allans(N)
    print(ans[i][0],ans[i][1])

Submission status: Time Limit Exceeded

Solution code:
import queue
n,m = map(int,input().split())
point = 1
now = queue.Queue()
for i in range(n):
    now.put(i)
exist = [1 for i in range(n)]
for turn in range(1,m+1):
    while True:
        a = now.get()
        if exist[a]:
            if exist[(a+turn)%n]:
                print(a+1,(a+turn)%n+1)
                exist[a] = 0
                exist[(a+turn)%n] = 0
                break
            else:
                now.put(a)

Submission status: Time Limit Exceeded

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

import random
import numpy as np


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


def try_get(N: int, M: int) -> (bool, list):
    used_flag = np.zeros(N)
    stage_marks = []  # [(v1,v2)]
    ones = np.ones(N)
    for length in reversed(range(1, M+1)):
        numbers = np.arange(N - length) + 1
        numbers = numbers[np.logical_and(used_flag[:(N-length)]==0,used_flag[length:N]==0)]
        if len(numbers) == 0:
            return False, []
        num = np.random.choice(numbers)
        stage_marks.append((num, num + length))
        used_flag[num-1] = 1
        used_flag[num+length-1] = 1

    return True, stage_marks


ok = False
marks = []
while not ok:
    ok, marks = try_get(N, M)

for src, dst in marks:
    print(f"{src} {dst}")

Submission status: Time Limit Exceeded

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:
        unused = set(range(N))
        d = 0
        for done in range(M):
            while True:
                d += 1
                for i in unused:
                    if (i + d) % N in unused:
                        break
                else:
                    continue
                unused.discard(i)
                unused.discard((i+d)%N)
                ans.append([i+1, (i+d)%N+1])
 
    for row in ans:
        print "{} {}".format(*row)

solve(*rrm())

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
res = []
x = 1
vis = [0] * (N + 1)
while len(res) < M:
  if vis[x] or vis[((x + len(res)) % N) + 1]: x = (x % N) + 1
  else:
    vis[x] = 1
    vis[((x + len(res)) % N) + 1] = 1
    res.append((x, ((x + len(res)) % N) + 1))
    x = (x % N) + 1
  #print(x, res, vis)
for r in res: print(*r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
D=[]
E=[]
if M%2==0:
  if N%2==0:
    N-=1
  a=(N+1)//2
  for i in range(a//2):
    D.append((i+1,a-i))
  for d,e in D:
    E.append((d+a,e+a-1))
else:
  if N%2==0:
    N-=1
  a=N//2
  for i in range(a//2):
    D.append((i+1,a-i))
  for d,e in D:
    E.append((d+a+1,e+a))
  E.append((a+1,N))
F=D+E
for i in range(M):
  print(*F[i])

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

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

# 割り当てを一つ求める
# N回Mラウンドを行う 1ラウンドあたりの最大対戦者数はN以下になる

# 対戦者A, B, C, D...にそれぞれ１、２、３、４...を割り当てる
# 試合後、A, B, C, D...の数字は２、３、４、５...になる N + 1になったら１になる
# N, M = 4, 1の時 M1に[1, 2]を割り当てると
#   A B C D
# 1 1 2 3 4 A vs B
# 2 2 3 4 1 D vs A
# 3 3 4 1 2 C vs D
# 4 4 1 2 3 B vs C なのでok
# Nラウンドでちょうど一周するので、M = 1の時は何を入れてもok

# N, M = 5, 2の時
#   A B C D E
# 1 1 2 3 4 5
# 2 2 3 4 5 1
# 3 3 4 5 1 2
# 4 4 5 1 2 3
# 5 5 1 2 3 4

# M1には何を指定してもいい？
# 少なくともM1とM2が同じパターン(i, i+1等)はダメ
# 全てのMについて違うパターンで数字を割り当てられるか
# = 任意のMi(ai, bi), Mj(aj, bj)について abs(bi - ai) != abs(bj - aj)
N, M = getNM()
A = []
B = []
if N % 2 != 0:
    for i in range(M):
        A.append(i + 1)
        B.append(N - i)
else:
    for i in range(M):
        A.append(i + 1)
        if i <= ((N // 4) - 1):
            B.append(N - i)
        else:
            B.append(N - i - 1) # 一つずらす
for i in range(M):
    print(A[i], B[i])


# コーナーケースあり
# 前と後ろから取っていったのではダメなケース？
# ちょうどrotateしたところ
# N, M = 6, 2
# m1に[1, 6], m2に[3, 4]を指定するとダブル
#   A B C D E F
# 1 1 2 3 4 5 6
# 2 2 3 4 5 [6 1] E, F
# 3 3 4 5 6 1 2
# 4 4 5 6 1 2 3
# 5 5 6 1 2 [3 4] E, F
# 6 6 1 2 3 4 5

# rotateしてもダブらないように
# m1に[1, 6], m2に[2, 3]を指定すると
#   A B C D E F
# 1 1 2 3 4 5 6
# 2 2 3 4 5 [6 1] E vs F
# 3 3 4 5 6 1 2
# 4 4 5 6 1 2 3
# 5 5 6 1 2 3 4
# 6 6 1 2 3 4 5

# 偶奇で分かれる？
# 奇数の場合は大丈夫
# m1 間はN - 2(奇数), 0
# m2 間はN - 4(奇数), 2

# 偶数の場合はダメ
# うまくズラして
# m1 間はN - 2(偶数), 0
# m2 間はN - 4(偶数), 2

# m1 間はN - 2, 0
# m2 間はN - 4, 2
# m3 間はN - 6, 4
# ...
# mm-2 間は6, N - 6
# mm-1 間は4, N - 4
# mm 間は2, N - 2
# 関係があるのは1個目とN個目, 2個目とN-1個目...
# 小さい方から半分については１個ずらす

Submission status: Accepted

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

diffs = [False] * N

a = 1
b = N
for _ in range(M):
    while True:
        diff0 = b-a
        diff1 = (N+a-b)
        if not diffs[diff0] and not diffs[diff1]:
            break
        b-=1
    diffs[diff0] = True
    diffs[diff1] = True
    print(str(a) + ' ' + str(b))
    a += 1
    b -= 1
    if b-a == (N+a-b):
        b-=1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if m == 1:
    print(1, 2)
    exit()
l1 = 1
l2 = m + 2
f = True
for length in range(m, 0, -1):
    if f:
        print(l1, l1 + length)
        l1 += 1
        f = not f
    else:
        print(l2, l2 + length)
        l2 += 1
        f = not f

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if m == 1:
    print(1, 2)
    exit()
l1 = 1
l2 = m + 2
f = True
for length in range(m, 0, -1):
    if f:
        print(l1, l1 + length)
        l1 += 1
        f = False
    else:
        print(l2, l2 + length)
        l2 += 1
        f = True

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if n % 2 == 1:
    for i in range(m):
        print(n - i, i + 1)
else:
    used = [False] * (n + 1)
    offset = 0
    for i in range(m):
        a = n - (i + offset)
        b = i + offset + 1
        d = min(a - b, n - (a - b))
        if used[d] or a - b == n - (a - b):
            offset = 1
        used[d] = True
        print(n - i, i + offset + 1)

Submission status: Accepted

Solution code:
from collections import deque

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

x = deque(range(1, n + 1))
aaa = []
bbb = []
flag = True

if n % 2 == 1:
    for i in range(m):
        a = x.popleft()
        aaa.append(a)
        b = x.pop()
        bbb.append(b)

else:
    for i in range(m):
        # ｎが偶数の場合は途中で1個捨てる
        a = x.popleft()
        aaa.append(a)
        b = x.pop()
        bbb.append(b)
        if x[-1] - x[0] <= n // 2 and flag:
            a = x.popleft()
            flag = False

for aa, bb in zip(aaa, bbb):
    print(aa, bb)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,M = MI()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,M = MI()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N%2==0:
    r = N
    f = True
    for i in range(M):
        if f and i*4+2 >= N:
            r -= 1
            f = False
        print(1+i, r)
        r -= 1
else:
    for i in range(M):
        print(1+i, N-i)

Submission status: Accepted

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

k = 1
k_even = n//2+1
p_even = k_even+1

def rotate(s,diff):
    if s + diff < 1:
        return s+diff+n
    elif s + diff > n:
        return s+diff-n
    return s+diff

for i in range(m+1):
    if i != 0 and i % 2 == 0:
        print(rotate(k,-(i//2)),rotate(k,i//2))

    if i % 2 == 1:
        print(rotate(k_even,-(i//2)),rotate(p_even,i//2))

Submission status: Accepted

Solution code:
from collections import deque
from itertools import product
import sys
import math

sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    H = (N-1) // 2
    LL = 0
    LR = (H // 2) * 2 + 1
    RL = N - (H - H//2) * 2
    RR = N
    pairs = []
    while LR - LL > 1:
        pairs.append((LL+1, LR))
        LL += 1
        LR -= 1
    while RR - RL > 1:
        pairs.append((RL+1, RR))
        RL += 1
        RR -= 1
    for i in range(M):
        print(*pairs[i])


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

Submission status: Accepted

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

a = n //2
b = a + 1
abset = set()

for i in range(m):
    print(a,b)
    abset.add(b-a)
    abset.add(n-b+a)
    a -= 1
    b += 1
    if n % 2 == 0 and (b - a == abs(n - b + a) or b - a in abset or n - b + a in abset):
        b += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil

n, m = (int(x) for x in input().split())
if n % 2 == 1:
    for i in range(1, m + 1):
        print(i, n - i)
else:
    k = (n - 2) // 2
    l = ceil(k / 2)
    ANS = []
    for i in range(1, l+1):
        ANS.append((i, n - i + 1))
    for i in range(l+2, k+2):
        ANS.append((i, n - i + 2))
    for a, b in ANS[:m]:
        print(a, b)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

p = m // 2
for i in range(p):
    print(p-i,p+2+i)

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N, M = LI()
    if N % 2 == 1:
        for i in range(1, M+1):
            print(i, N - i)
    else:
        for i in range(1, M + 1):
            x = i
            y = N - i + 1
            if y - x > (x - y) % N:
                print(x, y)
            else:
                print(x, y - 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)
else:
    for i in range(m):
        if 2 * (i + 1) <= m + 1:
            print(i + 1, n - i)
        else:
            print(i + 1, n - i - 1)

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
l = 1
r = N
ans = []
for _ in range(M - M // 2):
    ans += [l, r]
    l += 1
    r -= 1
if (r - l) % 2 == (l + N - r) % 2:
    r -= 1
for _ in range(M // 2):
    ans += [l, r]
    l += 1
    r -= 1
ans = ans[:2 * M]
print('\n'.join(f'{a} {b}' for a, b in zip(ans[::2], ans[1::2])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = list(map(int, input().split()))
    ans = list()
    if N % 2 == 1:
        for k in range(min(N // 2, M)):
            ans.append((k + 1, N - k))
    else:
        K = N // 2 - 1
        for k in range((K + 1) // 2):
            if len(ans) >= M:
                break
            ans.append((k + 1, N - k))
        for k in range(K // 2):
            if len(ans) >= M:
                break
            b = N - (K + 1) // 2 - k
            a = b - 2 * (K // 2 - k)
            ans.append((a, b))
    for row in ans:
        print('{} {}'.format(row[0], row[1]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n,m = map(int, input().split())
    r = m//2
    s = 1
    e = 2*r+1
    for _ in range(r):
        print(s,e)
        s += 1
        e -=1
    
    s = n-2*(m-r)+1
    e = n
    for _ in range(m-r):
        print(s,e)
        s += 1
        e -=1


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

N,M = list(map(int, input().rstrip().split()))
#-----
ans = []
delta = 0
visited = set()


for i in range(M):
    L = 1+i
    R = N-i
    diff = (R - delta) - L
    
    if (2*diff == N) or \
       (diff in visited) or ((N - diff) in visited):
       
        delta = 1
    
    ans.append( [L, R - delta] )
    visited |= {diff , (N - diff)}


for nums in ans:
    print(*nums)

Submission status: Accepted

Solution code:
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N,M = map(int, input().split())
    i = 1
    for m in range(M):
        if N%2 == 0 and i%2 == 1 and i >= N/2:
            i += 1
        print(M-m,M-m+i)
        i += 2
    

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve(N, M):
    ans = []
    now = 0
    for d in range(M, 0, -2):
        ans.append((now, now + d))
        now += 1

    now = M + 1
    for d in range(M - 1, 0, -2):
        ans.append((now, (now + d) % N))
        now += 1

    return ans


def main():
    N, M = map(int, input().split())
    ans = solve(N, M)
    for x in ans:
        print(f"{x[0] + 1} {x[1] + 1}")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(1, M+1):
  a = N+1 - i
  if N % 2 == 0 and i > (N // 4):
    a -= 1
  print(i, a)