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:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    a=1
    b=N-1
    if N%2==1:
        for _ in range(M):
            print(a,b)
            a+=1
            b-=1
    else:
        flag=False
        for _ in range(M):
            if flag==False and b-a<=N//2:
                flag=True
                b-=1
                print(a,b)
                a+=1
                b-=1
            else:
                print(a,b)
                a+=1
                b-=1

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if n % 2 == 0:
    i = 1
    while i <= m:
        a_i = str(i)
        
        if i <= (n - 2) // 4:
            b_i = str(n - i)
        else:
            b_i = str(n - i - 1)
        
        print(a_i + " " + b_i)
        i += 1
        
elif n % 2 == 1:
    for i in range(1, m + 1):
        a_i = str(i)
        b_i = str(n - i)
        
        print(a_i + " " + b_i)

Submission status: Accepted

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

s = 1
e = 2 * -(-M // 2)
for _ in range(M):
    if s >= e:
        s = N - 2 * (M // 2)
        e = N
    print(s, e)
    s += 1
    e -= 1

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = []
if N % 2 == 1:
    l, r = 1, N - 1
    while l < r:
        ans.append((l, r))
        l += 1
        r -= 1
else:
    l, r = 1, N - 1
    flag = False
    while l < r:
        if not flag and r - l <= N // 2:
            r -= 1
            flag = True
        ans.append((l, r))
        l += 1
        r -= 1
for i in range(M):
    print(ans[i][0], ans[i][1])

Submission status: Accepted

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

s = []; e = [];
s.append(1)
e.append(2 * -(-M // 2)) # 2 * ceiling(M/2)
s.append(N - 2 * (M // 2))
e.append(N)

n = 0
while True:
    for i in range(2):
        if n >= M: sys.exit()
        print(s[i], e[i])
        s[i] += 1
        e[i] -= 1
        n += 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m=n1()

if n%2==0:
    if m>=2:
        e=n//2
        s=1
        l=e-s
        c=0
        while e>s and c<m:
            print(s,e)
            s+=1
            e-=1
            c+=1
        e=n
        s=n-l+1
        while e>s and c<m:
            print(s,e)
            s+=1
            e-=1
            c+=1
    else:
        print(1,2)
else:
    if m>=2:
        e=n//2+1
        s=1
        l=e-s
        c=0
        while e>s and c<m :
            print(s,e)
            s+=1
            e-=1
            c+=1
        e=n
        s=n-l+1
        while e>s and c<m:
            print(s,e)
            s+=1
            e-=1
            c+=1
    else:
        print(1,2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    p = (m+1)//2
    q = m//2
    l = 0
    r = 2*p-1
    for i in range(p):
        print(l+1, r+1)
        l += 1
        r -= 1
    l = 2*p
    r = l+2*q
    for i in range(q):
        print(l+1, r+1)
        l += 1
        r -= 1


main()

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
half=n//2
lst=[]
if n%2==1:
    for i in range(m):
        lst.append([half-i,half+i+1])
else:
    for i in range(m):
        if i%2==0:
            lst.append([half-i//2,half+i//2+1])
        else:
            lst.append([1+i//2,n-1-i//2])

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

# dic=defaultdict(int)
# for i in range(m):
#     tmp=lst[i]
#     dic[tmp[1]-tmp[0]]+=1
#     dic[n-tmp[1]+tmp[0]]+=1
# print(dic)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=[]
if n%2==1:
  a=1
  b=n
  for _ in range(k):
    ans.append([a,b])
    a+=1
    b-=1
else:
  a=1
  b=n
  s=set()
  for _ in range(k):
    s.add(abs(a-b))
    s.add(abs(n+a-b)%n)
    ans.append([a,b])
    a+=1
    b-=1
    if abs(a-b) in s or abs(n+a-b)%n in s or abs(a-b)==abs(n+a-b):
      b-=1
for i in range(k):
  print(*ans[i])

Submission status: Accepted

Solution code:
import math
import fractions
import collections
import itertools
import pprint
N,M=map(int,input().split())

#rotateすれば他の部屋で同じ組み合わせが出てしまう<=>他の部屋の2数の数字の差が同じになってしまう
#前半分を偶数差、後ろ半分を奇数差と言った感じで上から詰めれば良い
#部屋数をMとして、1,2,...,Mの差を考える
l=[]
maemin=1
usiromax=N
for i in range(M,0,-1):
    if i%2==0:
        l.append([maemin,maemin+i])
        maemin=maemin+1
    else:
        l.append([usiromax-i,usiromax])
        usiromax=usiromax-1
#print(l)

for i in range(M):
    print(*l[i],sep=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    
    left = [i for i in range(M)]
    right = [2 * M - 1 - v for v in left]
    
    for i in range(M // 2):
        right[i] -= 2 * M + 1
    
    for i in range(M):
        left[i] %= N
        left[i] += 1
        right[i] %= N
        right[i] += 1
    
    for a, b in zip(left, right):
        print(a, b)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(100000000)


def main():
    n, m = map(int, input().split())
    res = []
    # n = 2m+1を考える
    if m % 2 == 0:
        half_m = int(m / 2)
        for i in range(half_m):
            res.append((half_m - i, half_m + 1 + i))
            res.append((m + half_m - i, m + half_m + 2 + i))
    else:
        half_m = int(m / 2)
        for i in range(half_m):
            res.append((half_m - i, half_m + 2 + i))
            res.append((m + half_m + 1 - i, m + half_m + 2 + i))
        res.append((m + 1, m + 2 * half_m + 2))

    for r in res:
        print(str(r[0]) + " " + str(r[1]))


main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
start = 1
end = M
while True:
  if start>=end:
    break
  print(start,end)
  start+=1
  end-=1
  
start = M+1
end = 2*M+1
while True:
  if start>=end:
    break
  print(start,end)
  start = start+1
  end = end-1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
half=n//2
lst=[]

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

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

Submission status: Accepted

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


N,M = nm()
used = [0] * N

start = 0
if N % 2 != 0:
    s = (N-1)//2
else:
    s = N//2 - 1 

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

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split())
c = 0
f = [math.floor(n/2), math.floor(n/2) + 1]
if n % 2 == 0:
    while c < m:
        c += 1
        if c == math.floor(n/4) + 1:
            if (f[1] + 1) % n == 0:
                f[1] = n
            else:
                f[1] = (f[1] + 1) % n
        print(str(f[0]) + ' ' + str(f[1]))
        if (f[0] - 1) % n == 0:
            f[0] = n
        else:
            f[0] = (f[0] - 1) % n
        if (f[1] + 1) % n == 0:
            f[1] = n
        else:
            f[1] = (f[1] + 1) % n
else:
    while c < m:
        c += 1
        print(str(f[0]) + ' ' + str(f[1]))
        if (f[0] - 1) % n == 0:
            f[0] = n
        else:
            f[0] = (f[0] - 1) % n
        if (f[1] + 1) % n == 0:
            f[1] = n
        else:
            f[1] = (f[1] + 1) % n

Submission status: Accepted

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

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

for i in range(M - n):
    ans.append([m + i + 1, l - i])

for v in ans:
    print(*v)

Submission status: Accepted

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

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

half=N//2

if half%2==0:
    for i in range(half//2):
        ans.append((i+1,half-i))
    for j in range(half//2):
        ans.append((half+1+j,N-j))
else:
    for i in range(half//2):
        ans.append((i+1,half-i))
    for j in range(half//2+1):
        ans.append((half+1+j,N-j))

#print(ans)
for i in range(M):
    print(*ans[i])

Submission status: Accepted

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

cnt = 0

l = 0
k = M
while cnt < M and k > 0:
    print(l + 1, l + k + 1)
    cnt += 1
    l += 1
    k -= 2

l = M + 1
k = M - 1
while cnt < M:
    print(l + 1, l + k + 1)
    cnt += 1
    l += 1
    k -= 2

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:
    used = [False]*n
    next = [i+1 for i in range(m)][::-2]+[i+1 for i in range(m)][-2::-2]
    i=0
    now=0
    count=0
    while True:
        if used[now]==False and used[now+next[i]]==False:
            print(now+1, now+next[i]+1)
            count+=1
            if count==m:
                break
            used[now]=True
            used[now+next[i]]=True
            i+=1
            now+=1
        else:
            now+=1

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
half=n//2
lst=[]
tmp=0
if n%2==0:
    for i in range(m):
        if i%2==1:
            lst.append([half-i//2,half+i//2+2])
        else:
            lst.append([1+i//2,n-i//2])

else:
    for i in range(m):
        lst.append([half-i,half+i+1])

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

# dic=defaultdict(int)
# for i in range(m):
#     tmp=lst[i]
#     dic[tmp[1]-tmp[0]]+=1
#     dic[n-tmp[1]+tmp[0]]+=1
# print(dic)

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(min(M,N//4)):
        print(i+1,N-i)
    for i in range(max(0,M-N//4)):
        print(N//4+i+1,N-N//4-i-1)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
half=n//2
lst=[]
tmp=0
if n%2==0:
    tmp=1
for i in range(m):
    if i%2==1:
        lst.append([half-i//2,half+i//2+2])
    else:
        lst.append([1+i//2,n-i//2])

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

# dic=defaultdict(int)
# for i in range(m):
#     tmp=lst[i]
#     dic[tmp[1]-tmp[0]]+=1
#     dic[n-tmp[1]+tmp[0]]+=1
# print(dic)

Submission status: Accepted

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

s1 = 1
f1 = n // 2
s2 = f1 + 1
f2 = n
if (f1 - s1) % 2 == (f2 - s2) % 2:
    f2 -= 1
ans = []
while f1 > s1:
    ans.append(f"{s1} {f1}")
    s1 += 1
    f1 -= 1

while f2 > s2:
    ans.append(f"{s2} {f2}")
    s2 += 1
    f2 -= 1

print("\n".join(ans[:m]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pprint import pprint as pp
from pprint import pformat as pf

def solve_odd(n, m):
    for i in range(m):
        print(i + 1, n - (i + 1))

def solve_even(n, m):
    offset = 1
    half = int(n / 2)
    diff = half - 1
    for i in range(m):
        start = offset
        end = start + diff
        if i % 2 != 0:
            start += half
            end += half
            # for next 2 loop
            offset += 1
        print(start, end)
        # for next loop
        diff -= 1



if __name__ == '__main__':
    n, m = map(int, input().split())
    if n % 2 == 0:
        solve_even(n, m)
    else:
        solve_odd(n, m)

Submission status: Accepted

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

if M % 2 == 0:
    m = (2 * M + 1) // 2 + 1
else:
    m = (2 * M + 1) // 2

i = 1
while i <= m // 2:
    print(i, m - i + 1)
    i += 1

j = 1
while j <= (2 * M + 1 - m) // 2:
    print(m + j, (2 * M + 1) - j + 1)
    j += 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
ans = []
front = deque([item for item in range(1, (n+1) // 2 + 1)])
back = deque([item for item in range(n // 2 + 2, n + 1)])
while len(front) > 1:
    l = front.popleft(); r = front.pop()
    ans.append((l, r))
while len(back) > 1:
    l = back.popleft(); r = back.pop()
    ans.append((l, r))
for i in range(m):
    print(*ans[i])

Submission status: Accepted

Solution code:
def solve(n, m):
    assert m * 2 + 1 <= n
    res = []

    maxi = (n - 1) / 2
    if maxi % 2 == 0:
        maxi -= 1
    p = 1
    for i in xrange(maxi, 0, -2):
        q = p + i
        res.append([p, q])
        p += 1

    p = maxi + 1 + 1
    maxi += 1
    for i in xrange(maxi, 1, -2):
        q = p + i
        if q > n:
            continue
        res.append([p, q])
        p += 1

    st1 = set()
    st2 = set()
    assert len(res) >= m
    for (a, b) in res:
        assert 1 <= a <= n
        assert 1 <= b <= n
        assert a != b
        assert not (set([a, b]) & st1)
        st1 |= set([a, b])
        diff = abs(a - b)
        assert not (set([diff, n - diff]) & st2)
        st2 |= set([diff, n - diff])
    return res[:m]

solve(9, 4)
solve(6, 2)
solve(7, 3)
solve(15, 6)
solve(12, 5)
solve(10000, 4999)

'''
for i in xrange(1, 100):
    for j in xrange(1, (i - 1) / 2 + 1):
        # print i, j
        solve(i, j)
'''

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

assert m * 2 + 1 <= n

for a, b in solve(n, m):
    print a, b

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():

    N, M = map(int, input().split())
    lv = []
    if M % 2 == 0:
        for i in range(1, M//2+1):
            lv.append([i, M+2-i])
        for i in range(1, M//2+1):
            lv.append([M+1+i, 2*M+2-i])
    else:
        for i in range(1, M//2+1):
            lv.append([i, M+1-i])
        for i in range(1, (M+1)//2+1):
            lv.append([M+i, 2*M+2-i])

    for i, j in lv:
        print(i, j)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# E

inp = input().split(' ')
N, M = int(inp[0]), int(inp[1])

import math
def get_pairs(N, M):
    sizes_even, sizes_odd = sorted(list(range(0, M, 2)), reverse=True), sorted(list(range(1, M, 2)), reverse=True)
    M2_ceil = math.ceil(M/2.0)
    M2_flor = math.floor(M/2.0)
    pairs = []
    for i in range(M2_ceil):
        pairs.append([1+i, 1+i+sizes_even[i]+1])
    half = 2+sizes_even[0]
    for i in range(M2_flor):
        pairs.append([half+i+1, half+i+1+sizes_odd[i]+1])
    return pairs
pairs = get_pairs(N, M)
for pair in pairs:
    print(pair[0], pair[1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, m = _ia()
    ret = []
    if n % 2 == 1:
        ai, bi = 1, n
        for _ in range(m):
            ret.append(f"{ai} {bi}")
            ai+=1
            bi-=1
    else:
        ai = n // 2
        bi = ai + 1
        for _ in range(n//4):
            ret.append(f"{ai} {bi}")
            ai -= 1
            bi += 1

        rept = n - bi
        ai, bi = 1, n - 1
        for _ in range(rept):
            ret.append(f"{ai} {bi}")
            ai += 1
            bi -= 1

    return "\n".join(ret[:m])


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

Submission status: Accepted

Solution code:
import queue

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

    q = queue.Queue()
    q.put((1, 1 + M))
    q.put((N - M + 1, N))
    ans = []

    for i in range(M):
        a, b = q.get()

        ans.append(f'{a} {b}')
        q.put((a+1, b-1))
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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)]
lis1 = deque(lis[:N//2+1])
lis2 = deque(lis[N//2+1:])
if M % 2 == 0:
    
    for i in range(M//2):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a,b)
else:
    for i in range(M//2+1):
        a = lis1.popleft()
        b = lis1.pop()
        print(a,b)
    for i in range(M//2):
        a = lis2.popleft()
        b = lis2.pop()
        print(a, b)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    n,m = map(int,input().split())
    ans = []
    r = 2*m+1
    if m%2:
        for i in range(1,m//2+1):
            ans.append([i,m+1-i])
        for i in range(m+1,(m+1+r)//2+1):
            ans.append([i,m+1+r-i])
    else:
        for i in range(1,m//2+1):
            ans.append([i,m+1-i])
        for i in range(m+1,(m+1+r)//2):
            ans.append([i,m+1+r-i])            
    for a in ans:
        print(*a)


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(m-i, m+1+i)
else:
  for i in range(m):
    if 4*(i+1) > n:
      print(m-i, m+2+i)
    else:
      print(m-i, m+1+i)

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

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


if __name__ == '__main__':
	format_input()

	get_answer()

Submission status: Accepted

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

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

Submission status: Accepted

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

if M%2 == 1:
    a = 1
    b = M
    for _ in range(M//2):
        print(a,b)
        a += 1
        b -= 1
    a = M+1
    b = 2*M + 1
    for _ in range(M - M//2):
        print(a,b)
        a += 1
        b -= 1
else:
    a = 1
    b = M+1
    for _ in range(M//2):
        print(a,b)
        a += 1
        b -= 1
    a = M+2
    b = 2*M + 1
    for _ in range(M - M//2):
        print(a,b)
        a += 1
        b -= 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq
a,b=list(map(int,input().split()))
b_i=a
a_i=1
for i in range(b,0,-1):
    if i%2==1:
        print(b_i-i,b_i)
        b_i-=1

    else:
        print(a_i,a_i+i)
        a_i+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


n, m = inpl()
n = 2 * m + 1
#left
for i in range(m//2):
    print(i + 1, m - i)
#right
base=m+1
for i in range((n-m)//2):
    print(base + i, n - i)

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)
elif N == 4:
    print (1, 2)
else:
    lst = [True] * N

    #奇数の個数
    n = (M + 1) // 2
    for i in range(n):
        print (1 + i, 1 + i + 2 * n - 1 - 2 * i)
    
    #偶数の個数
    m = M // 2
    for i in range(m):
        print (2 * n + 1 + i, 2 * n + 1 + i + 2 * (m - i))