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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split());[print(i+1,n-i-((i>=m/2)&~n)) for i in range(m)]

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
def main():
    n,m = map(int,input().split())
    x = m//2
    y = m - x
    for i in range(x):
        print(i+1,2*x+1-i)
    for i in range(y):
        print(2*x+2+i,2*x+2*y+1-i)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# E - Rotation Matching

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

Submission status: Accepted

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


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

elif N%4 == 0:
    total = 0
    count = 1
    for i in range(N//4,0,-1):
        print(i,i+count)
        count += 2
        total += 1
        if total >= M:
            sys.exit()
    count = 2
    for i in range(3*(N//4)-1,N//2,-1):
        print(i,i+count)
        count += 2
        total += 1
        if total >= M:
            sys.exit()
else:
    total = 0
    count = 1
    for i in range(N//4,0,-1):
        print(i,i+count)
        count += 2
        total += 1
        if total >= M:
            sys.exit()
    count = 2
    for i in range(3*(N//4),N//2-1,-1):
        print(i,i+count)
        count += 2
        total += 1
        if total >= M:
            sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M//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:
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    n,m = map(int,input().split())
    ans = [[0]*2 for _ in range(m)]
    cnt = 1
    if n%2 == 1:
        for i in range(m):
            ans[i][0] = cnt
            cnt += 1
        for i in range(m - 1,-1,-1):
            ans[i][1] = cnt
            cnt += 1
        for i in range(m):
            print(*ans[i])
    else:
        for i in range(m):
            ans[i][0] = cnt
            cnt += 1
        cnt = n
        flag = True
        for i in range(m):
            if flag and cnt - ans[i][0] <= n//2:
                flag = False
                cnt -= 1
            ans[i][1] = cnt
            cnt -= 1
        for i in range(m):
            print(*ans[i])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, read().split())
if n % 2 == 1:
    for i in range(1, m + 1):
        print(i, n - i)
else:
    x, y = 0, 0
    for i in range(m):
        a, b = 2 * i, n - 2 * (i + 1)
        if a == b or (a == y and b == x):
            n -= 1
        x, y = a, b
        print(i + 1, n - i)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def out(s, e):
    while s < e:
        print("{} {}".format(s, e))
        s += 1
        e -= 1

odd = m % 2
out(1, m + odd)
out(m + 1 + odd, 2 * m + 1)

Submission status: Accepted

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

def out(s, e):
    while s < e:
        print("{} {}".format(s, e))
        s += 1
        e -= 1

if m % 2 == 0:
    out(1, m)
    out(m + 1, 2 * m + 1)
else:
    out(1, m + 1)
    out(m + 2, 2 * m + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    if n%2:
        for i in range(m):
            print(1+i,n-i)
    else:
        i=1
        j=n//2
        while m and i<j:
            print(i,j)
            i+=1
            j-=1
            m-=1

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

def sol(N):
    if N == 1:
        return []

    N += 1
    ans = [[] for _ in range(N)]

    K = 0
    for i, n in enumerate(range(1, N // 2)):
        ans[i].append(n)
        K += 1
    for i, n in enumerate(range(N // 2, N - 1)):
        ans[K - 1 - i].append(n)

    return ans

if N % 2 == 1:
    ans = sol(N)
    for a in ans[:M]:
        print(*a)
else:
    L = N // 2
    ans = []

    if L % 2 == 0:
        for a in sol(L + 1):
            if len(a) == 0:
                continue
            ans.append(a)
        for a in sol(L - 1):
            if len(a) == 0:
                continue
            a[0] += L + 1
            a[1] += L + 2
            ans.append(a)
        for a in ans[:M]:
            print(*a)
    else:
        for a in sol(L):
            if len(a) == 0:
                continue
            ans.append(a)
        for a in sol(L):
            if len(a) == 0:
                continue
            a[0] += L
            a[1] += L + 1
            ans.append(a)
        for a in ans[:M]:
            print(*a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    l = 1
    r = N - 1
    if N % 2 == 0:
        flag = True
        for i in range(M):
            if r - l <= N // 2 and flag:
                l += 1
                flag = False
            print(l,r)
            l += 1
            r -= 1
    else:
        for i in range(M):
            print(l,r)
            l += 1
            r -= 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 i<m/2:
            print(i+1,n-i)
        else:
            print(i+1,n-i-1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if m & 1:
    if n & 1:
        left_1 = 1
        right_1 = n // 2
        left_2 = (n // 2) + 1
        right_2 = n
    else:
        left_1 = 1
        right_1 = n // 2 - 1
        left_2 = (n // 2) + 1
        right_2 = n
else:
    if n & 1:
        left_1 = 1
        right_1 = n // 2
        left_2 = (n // 2) + 1
        right_2 = n
    else:
        left_1 = 1
        right_1 = n // 2 - 1
        left_2 = (n // 2) + 1
        right_2 = n
for _ in range(m // 2):
    print(left_1, right_1)
    left_1 += 1
    right_1 -= 1
for _ in range(m // 2, m):
    print(left_2, right_2)
    left_2 += 1
    right_2 -= 1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if (m & 1):
    if n & 1:
        left_1 = 1
        right_1 = n // 2
        left_2 = (n // 2) + 1
        right_2 = n
    else:
        left_1 = 1
        right_1 = n // 2 - 1
        left_2 = (n // 2) + 1
        right_2 = n
else:
    if n & 1:
        left_1 = 1
        right_1 = n // 2
        left_2 = (n // 2) + 1
        right_2 = n
    else:
        left_1 = 1
        right_1 = n // 2 - 1
        left_2 = (n // 2) + 1
        right_2 = n
for _ in range(m // 2):
    print(left_1, right_1)
    left_1 += 1
    right_1 -= 1
for _ in range(m // 2, m):
    print(left_2, right_2)
    left_2 += 1
    right_2 -= 1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if (m & 1):
    if n & 1:
        left_1 = 1
        right_1 = n // 2
        for _ in range(m // 2):
            print(left_1, right_1)
            left_1 += 1
            right_1 -= 1
        left_2 = (n // 2) + 1
        right_2 = n
        for _ in range(m // 2, m):
            print(left_2, right_2)
            left_2 += 1
            right_2 -= 1
    else:
        left_1 = 1
        right_1 = n // 2 - 1
        for _ in range(m // 2):
            print(left_1, right_1)
            left_1 += 1
            right_1 -= 1
        left_2 = (n // 2) + 1
        right_2 = n
        for _ in range(m // 2, m):
            print(left_2, right_2)
            left_2 += 1
            right_2 -= 1
else:
    if n & 1:
        left_1 = 1
        right_1 = n // 2
        for _ in range(m // 2):
            print(left_1, right_1)
            left_1 += 1
            right_1 -= 1
        left_2 = (n // 2) + 1
        right_2 = n
        for _ in range(m // 2, m):
            print(left_2, right_2)
            left_2 += 1
            right_2 -= 1
    else:
        left_1 = 1
        right_1 = n // 2 - 1
        for _ in range(m // 2):
            print(left_1, right_1)
            left_1 += 1
            right_1 -= 1
        left_2 = (n // 2) + 1
        right_2 = n
        for _ in range(m // 2, m):
            print(left_2, right_2)
            left_2 += 1
            right_2 -= 1

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
# E - Rotation Matching

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

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

Submission status: Accepted

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

odd = (m + 1) // 2
even = m - odd

l = 1
r = 2 * odd
while l < r:
    print(l, r)
    l += 1
    r -= 1

l = n - 2 * even
r = n
while l < r:
    print(l, r)
    l += 1
    r -= 1

Submission status: Accepted

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

# M個の対戦場は、それぞれ違う距離の対戦相手と対戦するようにする
# そのために、1~Nのうち前半を奇数差、後半を偶数差で構成する
a = 1
if M%2 == 1:
    # M~1までの奇数を順に
    for i in range(M,0,-2):
        print(str(a) + ' ' + str(a+i))
        a+=1
    a = N
    # M-1~2までの偶数を順に
    for i in range(M-1, 1, -2):
        print(str(a) + ' ' + str(a - i))
        a-=1
elif M%2 == 0:
    # M-1~1までの奇数を順に
    for i in range(M-1,0,-2):
        print(str(a) + ' ' + str(a+i))
        a+=1
    a = N
    # M~2までの偶数を順に
    for i in range(M, 1, -2):
        print(str(a) + ' ' + str(a - i))
        a-=1

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    ans = [[] for j in range(M)]

    if N % 2:
        for i in range(M):
            ans[i].append(i + 1)
            ans[i].append(N - i - 1)
    else:
        memo = 0
        f = False
        for i in range(M):
            memo = i
            if (i + 1) * 4 >= N:
                f = True
                break
            ans[i].append(i + 1)
            ans[i].append(N - i - 1)

        if f:
            for j in range(memo, M):
                ans[j].append(j + 1)
                ans[j].append(N - j - 2)
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    ans = [[] for j in range(M)]

    if N % 2:
        for i in range(M):
            ans[i].append(i + 1)
            ans[i].append(N - i - 1)
    else:
        memo = 0
        for i in range(M):
            memo = i
            if (i + 1) * 4 >= N:
                break
            ans[i].append(i + 1)
            ans[i].append(N - i - 1)
            memo += 1

        for j in range(memo, M):
            ans[j].append(j + 1)
            ans[j].append(N - j - 2)
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().rstrip().split(" "))
ans = []
K = (N - 1) // 2
if K % 2 == 0:
    for i in range(K // 2):
        ans.append([K // 2 - i,K // 2 + i + 1])
    for i in range(K // 2):
        ans.append([N - K // 2 -1  - i,N - K // 2 + i + 1])
else:
    for i in range(K // 2 + 1):
        ans.append([K // 2 + 1 - i,K // 2 + i + 2])
    for i in range(K // 2):
        ans.append([N - K // 2 - 1  - i,N - K // 2 + i + 1])
for i in range(M):
    print(str(ans[i][0]) + " " + str(ans[i][1]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
INF = 2**62-1

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

def slv(N, M):
    if N % 2 != 0:
        ans = [(i+1, N-i) for i in range(M)]
    else:
        ans = [(i+1 +(1 if i+1 > N//4 else 0), N-i) for i in range(M)]

    for a in ans:
        print(*a)


def main():
    N, M = read_int_n()
    (slv(N, M))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
INF = 2**62-1

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

def slv(N, M):
    if N % 2 != 0:
        ans = [ (i+1, N-i) for i in range(M)]
    else:
        ans = []
        for i in range(M):
            l = i+1
            r = N-i
            if l > N //4:
                l += 1

            ans.append((l, r))

    for a in ans:
        print(*a)


def main():
    N, M = read_int_n()
    (slv(N, M))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import *
n,m = map(int,input().split())
d = dict()
i,j = 1,n
for y in range(m):
	if(n%2 == 0 and i == (m+1)//2+1):
		i += 1
	print(i,j)
	i += 1
	j -= 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
left=m//2
right=(m+1)//2

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


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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if(n%2==1):
    for i in range(1,m+1):
        print(' '.join(map(str,[i,n+1-i])))
    exit()

m1,m2 = (m+1)//2 ,m//2
sum1 = 1 + n//2
sum2 = (n//2+1) + (n-1)
for i in range(m1):
    print(' '.join(map(str,[1+i,n//2 -i])))
for i in range(m2):
    print(' '.join(map(str,[n//2+1+i,n-1-i])))

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
if n % 2:
    for i in range(m):
        print(i+1, n-i-1)
else:
    flag = False
    for i in range(m):
        if not flag and (n-i-1) - (i+1) <= n // 2:
            flag = True
        if flag:
            print(i+1, n-i-2)
        else:
            print(i+1, n-i-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:
    middle = int((m+1)/2)
    for i in range(middle):
        print(i+1, n-i)
    for i in range(middle, m):
        print(i+2, 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-i)
else:
    for i in range(m):
        if i%2==0:
            print(i//2+1,n-i//2)
        else:
            print(n//2-i//2-1,n//2+i//2+1)

Submission status: Accepted

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

if N %2 == 0:
    L1 = list(range(1,N//2+1))
    L2 = list(range(N//2+1,N+1))
    L = len(L1)
    i = 0
    j = 0
    # print(L)
    for m in range(M):
        if m %2 == 0:
            ans.append([L1[L//2-1-i],L1[L//2+i]])
            i += 1
        else:
            ans.append([L2[L//2-1-j], L2[L//2+1+j]])
            j += 1

else:
    for i in range(1,M+1):
        ans.append([i,N+1-i])

for a in ans:
    print(*a)

Submission status: Accepted

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

l = 1
r = n
cnt = 0
dp = [False] * (n+1)
while cnt < m:
    if dp[r-l]: r -= 1
    if r-l == (l-r)%n: r-=1
    print(l,r)
    dp[r-l] = True
    dp[(l-r)%n] = True
    r -= 1
    l += 1
    cnt += 1

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

Submission status: Accepted

Solution code:
def main():
    from collections import deque
    N, M = (int(i) for i in input().split())
    if N % 2 == 0:
        A = deque([i+1 for i in range(N)])
        for i in range(1, M+1):
            if (N-i)-i > N//2:
                print(A[i], A[N-i])
            else:
                print(A[i], A[N-i-1])
    else:
        A = deque([i for i in range(N)])
        for i in range(1, M+1):
            print(A[i], A[N-i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X = str(input())
N = int(X.split(' ')[0])
M = int(X.split(' ')[1])



if N % 2 ==1:

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

Submission status: Accepted

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

    pairs = []
    a = 1
    for d in range(M, 0, -2):
        pairs.append((a, a + d))
        a += 1

    a = 1 + M + 1
    for d in range(M - 1, 0, -2):
        pairs.append((a, a + d))
        a += 1

    for pair in pairs:
        print(*pair)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()

ans = list2d(M, 2, 0)
cnt = 1
for i in range(M//2):
    ans[i][0] = cnt
    cnt += 1
cnt += 1
for i in range(M//2-1, -1, -1):
    ans[i][1] = cnt
    cnt += 1
for i in range(M//2, M):
    ans[i][0] = cnt
    cnt += 1
for i in range(M-1, M//2-1, -1):
    ans[i][1] = cnt
    cnt += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


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

    """
    奇数人のときは１飛ばし、３飛ばし、５飛ばし、、、とすればよい。
    偶数人のときは１飛ばし、３飛ばし、、、で途中から偶数飛ばしに切り替えるとよい。
    （「カークマンの組み分け」を参照）
    構成問題苦手だ。。。
    """

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

    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
n,m = (int(i) for i in input().split())

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