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:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(1,0),(-1,0),(0,1),(0,-1)];EightNb=[(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('EWNS',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def __str__(self):
        return  str(self.edges)

    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v

    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1

        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][r-(1<<N)])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][r-(1<<N)]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][r-(1<<N)]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])

    def print(self):
        for i in self.table:
            print(*i)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True
ans=0

n,m=LI()
ans=[]
if n%2==0:
    l1,r1=1,1+n//2-1
    l2,r2=1+n//2+1,n
    for i in range(n//4+1):
        ans+=[(l1,r1)]
        ans+=[(l2,r2)]
        l1+=1
        r1-=1
        l2+=1
        r2-=1
    
elif n%2==1:
    l1,r1=2,n
    for i in range(n//2):
        ans+=[(l1,r1)]
        l1+=1
        r1-=1
    
for i in range(m):
    a,b=ans[i]
    print(*ans[i])

Submission status: Accepted

Solution code:
import os
from collections import Counter

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))


def test(ans):
    hist = []
    for a, b in ans:
        hist.append((0, (b - a) % N))
        hist.append((0, (a - b) % N))
    print(len(set(hist)) == M * 2)
    print(Counter(hist))


ans = []
if N % 2 == 1:
    for i in range(M):
        a, b = i + 1, N - i
        ans.append((a, b))
else:
    hist = set()
    d = 0
    for i in range(M):
        a, b = i + 1, N - i - d
        if (a - b) % N in hist or (b - a) % N in hist or (a - b) % N == (b - a) % N:
            d += 1
            a, b = i + 1, N - i - d
        hist.add((a - b) % N)
        hist.add((b - a) % N)
        ans.append((a, b))

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

# test(ans)

Submission status: Accepted

Solution code:
N, M = (int(_) for _ in input().split())

if N % 2 == 0:
    s = (N - 1) // 4 + 1
    ret = []
    for i in range(1, s):
        ret.append((i, N - i))
    for i in range(s, N // 2):
        ret.append((i, N - i - 1))
else:
    ret = []
    for i in range(1, (N // 2) + 1):
        ret.append((i, N - i))


for r0, r1 in ret[:M]:
    print(r0, r1)

Submission status: Accepted

Solution code:
'''
N人を円周上に配置し、M本の線分で結ぶ。
このとき、線分を回転させていっても同じ人のペアが生まれないようにする。

基本的には、上から順に結べばよい。
'''

from collections import deque

def main():
    N, M = map(int, input().split())
    if N&1:
        '''
        ・Nが奇数の場合
        
        上から順に結ぶだけ。
        dequeに 1,2,3,...,M*2 を突っ込んで、両端から取り出してペアにする。
        '''
        q = deque(range(M*2))
        while q:
            print(q.popleft()+1, q.pop()+1)
    else:
        '''
        [Nが偶数の場合]
        
        上から順に結ぶと、上下の線対称になり、同じ間隔のペアが生まれるためNG。
        → 半分以降は、1つずらしてペアを作っていく

        簡単に解決するため、
        ・上から順に奇数間隔ペアを作る
        ・下から順に偶数間隔ペアを作る
        この2つから、M個を順に、交互に取り出す。
        '''
        q1 = deque(range(N))
        q2 = deque(range(N-1))
        p1 = []
        while q1:
            p1.append((q1.popleft()+1, q1.pop()+1))
        p2 = []
        while len(q2)>=2:
            p2.append((q2.popleft()+1, q2.pop()+1))
        p2.reverse()
        for _ in range(M):
            print(*p1.pop())
            p1, p2 = p2, p1


main()

Submission status: Accepted

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

#N人の参加者から、M組選ぶ
#これをNセット実施。
#組合わせの距離が重複しなければ、成立


#参加者を半分に分け、
#前半を距離奇数、後半を距離偶数にする

#参加者を半分に分ける
div_point=int((N/2))
#前半グループを奇数にする
if div_point%2==0:
    div_point-=1
#後半グループは更に半分に分ける
re_point=div_point+int((N-div_point)/2)

#組を作る
i=0 #初期化
while 1<div_point-i*2 and i<re_point and i<M:#前半グループ・・・距離が奇数になるように組み分け
    ent1=i+1 #前半グループ：一人目
    ent2=div_point-i #前半グループ：二人目
    print(str(ent1) + ' ' + str(ent2))
    i+=1
for j in range(M-i):#後半グループ
    ent1=re_point-j #後半グループ：一人目
    ent2=re_point+j+1 #後半グループ：二人目
    print(str(ent1) + ' ' + str(ent2))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, M = mis()
    if N&1:
        q = deque(range(M*2))
        while q:
            print(q.popleft()+1, q.pop()+1)
    else:
        q1 = deque(range(N))
        q2 = deque(range(N-1))
        p1 = []
        while q1:
            p1.append((q1.popleft()+1, q1.pop()+1))
        p2 = []
        while len(q2)>=2:
            p2.append((q2.popleft()+1, q2.pop()+1))
        p2.reverse()
        for _ in range(M):
            print(*p1.pop())
            p1, p2 = p2, p1


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    left = 1
    right = n
    is_shift = False
    ans = []
    while left < right:
        if right - left <= n // 2 and not is_shift and n % 2 == 0:
            left += 1
            is_shift = True
        ans.append([left, right])
        left += 1
        right -= 1

    for l in range(m):
        print(*ans[l])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    a, b = ans[-1][0]+1, ans[-1][1]-1
    
    if a<b:
        ans.append((a, b))
    else:
        break

ans.append((2+d, 1+2*d))

while True:
    a, b = ans[-1][0]+1, ans[-1][1]-1
    
    if a<b:
        ans.append((a, b))
    else:
        break

for a, b in ans[:M]:
    print(a, b)

Submission status: Accepted

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

gu = 1
ki = m - m%2 + 2

for i in range(1, m+1)[::-1]:
    if i % 2 == 0:
        print(gu, gu+i)
        gu += 1
    else:
        print(ki, ki+i)
        ki += 1

Submission status: Accepted

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

if N % 2 == 1:
    for a in range(1, M + 1):
        print(a, N - a + 1)
else:
    for a in range(1, M + 1):
        print(a, N - a + (a <= N // 4))

Submission status: Accepted

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

if N % 2 == 1:
    for a in range(1, M + 1):
        print(a, N - a + 1)
else:
    for a in range(1, M + 1):
        if a <= N // 4:
            print(a, N - a + 1)
        else:
            print(a, N - a)

Submission status: Accepted

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

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

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

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

for a, b in ans[:M]:
    print(a, b)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if n%2 == 1:
    ans = []
    a = 1
    b = n-1
    for i in range(m):
        ans.append((a, b))
        a += 1
        b -= 1
else:
    ans = []
    a = 1
    b = n-1
    flag = True
    for i in range(m):
        if flag and b-a <= n//2:
            b -= 1
            flag = False
        ans.append((a, b))
        a += 1
        b -= 1
for i in range(m):
    print(*ans[i])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lange=[1]*(n+1)
for i in range(1,n+1):
  a=i
  b=n-a
  if lange[a]:lange[b]=0
langes=[]
for i in range(1,n):
  if lange[i]:
    if len(langes)%2:langes.append(i)
    else:langes.append(n-i)
langes.sort(reverse=1)
for i in range(m):print(i+1,i+1+langes[i])

Submission status: Accepted

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M = lr()
    if N%2 == 1:
        for i in range(0, M):
            print(f'{2+i} {1+2*M-i}')
    else:
        k = N//4
        for i in range(M):
            if i < k:
                print(f'{i+1} {N-i}')
            else:
                print(f'{i+2} {N-i}')
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

a = 1
b = m + 1
while a < b:
  print(a, b)
  a += 1
  b -= 1

a = m + 2
b = 2 * m + 1
while a < b:
  print(a, b)
  a += 1
  b -= 1

Submission status: Accepted

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

a = 1
b = m - 1
c = m
d = [i for i in range(n + 1)]

for i in range(m):
    if m % 2 == 0 and i < m / 2:
        print(d[a], d[a+b])
        print(d[-a-c],d[-a])
        a = a + 1
        b = b - 2
        c = c - 2

    elif m % 2 != 0 and i < m / 2:
        print(d[-a-c],d[-a])
        if i == (m + 1) / 2 - 1:
            break
        print(d[a], d[a+b])
        a = a + 1
        b = b - 2
        c = c - 2

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    ans = []
    t = [True]*(n+1)
    l = n//2 - 1
    for i in range(1, n//2):
        if l <= 0:
            break
        if not t[i] or not t[i+l]:
            continue
        ans.append([i, i+l])
        t[i] = False
        t[i+l] = False
        l -= 2
    if n % 2 == 1:
        l = n//2
        for i in range(n//2, n):
            if l <= 0:
                break
            if not t[i] or not t[i+l]:
                continue
            ans.append([i, i+l])
            t[i] = False
            t[i+l] = False
            l -= 2
    else:
        l = n//2 - 2
        for i in range(n//2, n):
            if l <= 0:
                break
            if not t[i] or not t[i+l]:
                continue
            ans.append([i, i+l])
            t[i] = False
            t[i+l] = False
            l -= 2
    for i in range(m):
        print(ans[i][0], ans[i][1])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

a = 1
b = 1+M

while(a < b) :
  print(a, b)
  a += 1
  b -= 1

a = M+2
b = 2*M+1
while(a < b) :
  print(a, b)
  a += 1
  b -= 1

Submission status: Accepted

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

K = N//2
ans = []

if N == 3:
    ans = [(1,2)]
elif N == 4:
    ans = [(1,2)]
elif N == 5:
    ans = [(1,2),(3,5)]
else:
    left = 1
    right = K
    while left<right:
        ans += [(left,right)]
        left+=1
        right-=1

    left = K+1
    right = N
    if (right-left)%2 == (K-1)%2:
        right -= 1
    while left<right:
        ans += [(left,right)]
        left += 1
        right -= 1

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

Submission status: Accepted

Solution code:
#E
import numpy as np
n, m = list(map(int, input().split()))
lists = list(np.arange(1, n+1))
list1 = lists[:m]
list2 = lists[m:]
num = m
for i in range(m//2 +1):
    if num == 0:
        break
    print(list2[i],list2[m+1-i-1])
    num -= 1
    if num == 0:
        break
    print(list1[i],list1[m-i-1])
    num -= 1

Submission status: Accepted

Solution code:
#coding:utf-8

n,m = map(int,input().split())
point_s = 0
point_e = n + 1

if n % 2 == 0:
    for i in range(1,m+1):
        point_s += 1
        point_e -= 1
        print("{} {}".format(point_s,point_e))
        if n % 4 == 0 and (point_e - point_s - 1) * 2 == n:
            point_e -= 1
        elif n % 4 != 0 and (point_e - point_s - 1) * 2 == n + 2:
            point_e -= 1
elif n % 2 == 1:
    for i in range(1,m+1):
        point_s += 1
        point_e -= 1
        print("{} {}".format(point_s,point_e))

Submission status: Accepted

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

head = 1
tail = N

while head <= M:
    if (N % 2 == 0 and tail - head == N // 2) or (N % 4 == 0 and tail - head == N // 2 - 1):
        tail -= 1
    print(head, tail)
    head += 1
    tail -= 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys


def solve(N: int, M: int):
    f = M % 2 == 0
    for i in range(M//2):
        print(f'{i+1} {M-i+f}')
    for i in range((M+1)//2):
        print(f'{M+i+1+f} {2*M-i+1}')


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n % 2 == 1:
    for i in range(m):
        print("{} {}".format(2 + i, n - i))
else:
    for i in range(m):
        if i % 2 == 0:
            print("{} {}".format(int(n / 2 - i / 2), int(n / 2 + 1 + i / 2)))
        else:
            print("{} {}".format(int(2 + i // 2), int(n - i // 2)))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
#1とnがつながっているときのa,bの最短距離
def dist(a,b):
  return min(abs(a-b),n-abs(a-b))

a,b = n,1
S=set()
for i in range(m):
  distab = dist(a,b)
  #distabがnの半分のとき
  if 2*distab == n or distab in S:
    a -= 1
  print(a,b)
  S.add(distab)
  a -= 1
  b += 1

Submission status: Accepted

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

# 番号を入力
A = [int(i) for i in range(N)]

B = [] # 台No. リスト

if N % 2 == 0:
    # N が偶数の場合

    center = N // 2
    c1 = center // 2
    c2 = center + c1
    # print(c1,c2)

    for i in range(1, M+1):
        # print(i)
        j = i // 2
        # print("j", j)
        if i % 2 == 1:
            B.append((c1-j, c1+j+1))
        else:
            B.append((c2-(j-1), c2 - (j-1) + 2*j ))

else:
    # N が奇数の場合

    center = N // 2 + 1
    # print(center)
    for i in range(1, M+1):
        B.append((center - i, center + i))
        
for i in B:
    print(i[0], i[1])

Submission status: Accepted

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

# 番号を入力
A = [int(i) for i in range(N)]

B = [] # 台No. リスト

if N % 2 == 0:
    # N が偶数の場合

    center = N // 2
    c1 = center // 2
    c2 = center + c1
    # print(c1,c2)

    for i in range(1, M+1):
        # print(i)
        j = i // 2
        # print("j", j)
        if i % 2 == 1:
            B.append((c1-j, c1+j+1))
        else:
            B.append((c2-(j-1), c2 - (j-1) + 2*j ))

else:
    # N が奇数の場合

    center = N // 2 + 1
    # print(center)
    for i in range(1, M+1):
        B.append((center - i, center + i))

for i in B:
    print(i[0], i[1])

Submission status: Accepted

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

ans = []

for i in range(M):
    if N % 2 != 0 or (M + (i + 1)) - (M - (i)) < N // 2:
        tmp = [str(M - (i)), str(M + (i + 1))]
    else:
        tmp = [str(M - (i)), str(M + (i + 2))]
    tmp = ' '.join(tmp)
    ans.append(tmp)
print(*ans, sep='\n')

Submission status: Accepted

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

def dist(a, b):
    return min(abs(a - b), n - abs(a - b))

a, b = n, 1
S = set()
for i in range(m):
    if 2 * dist(a, b) == n or dist(a, b) in S:
        a -= 1
    print(a, b)
    S.add(dist(a, b))
    a -= 1
    b += 1

Submission status: Accepted

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

def ark(a, b):
    return min(abs(a - b), n - abs(a - b))

a, b = n, 1
S = set()
for i in range(m):
    if 2 * ark(a, b) == n or ark(a, b) in S:
        a -= 1
    print(a, b)
    S.add(ark(a, b))
    a -= 1
    b += 1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b = n, 1
V = [False for d in range(1, n + 1)]
for i in range(m):
    d = min(a - b, n - (a - b))
    if 2 * d == n or V[d]:
        a -= 1
    print(a, b)
    d = min(a - b, n - (a - b))
    V[d] = True
    a -= 1
    b += 1

Submission status: Accepted

Solution code:
## coding: UTF-8
N,M = map(int,input().split())

if(N % 2 == 1):
    pairs = []
    s = 2
    g = N
    for i in range(M):
        pairs.append([s, g])
        s += 1
        g -= 1
elif(N % 4 != 0):
    MAX = int(N/2) - 1
    half = int(MAX/2)
    pairs = []
    s = 1
    g = N
    for i in range(half):
        pairs.append([s, g])
        s += 1
        g -= 1
    g -= 1
    for i in range(half):
        pairs.append([s, g])
        s += 1
        g -= 1
else:
    odd_pairs = int(N/4)
    even_pairs = odd_pairs - 1
    pairs = []
    s = 1
    g = N
    for i in range(odd_pairs):
        pairs.append([s, g])
        s += 1
        g -= 1
    g -= 1
    for i in range(even_pairs):
        pairs.append([s, g])
        s += 1
        g -= 1







for i in range(M):
    print('{} {}'.format(pairs[i][0], pairs[i][1]))
#print(pairs)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M = LI()
    used = [0 for _ in range(N)]
    cur = 0
    pairs = []
    used = set()
    if N % 2 == 0:
        a = 1
        b = N
        while len(pairs) < M:
            if b-a in used or N + a -b in used or b - a == N//2:
                b -= 1
            pairs.append((a, b))
            used.add(b-a)
            used.add(N+a - b)
            a += 1
            b -= 1

    else:
        a = 1
        b = N - 1
        while len(pairs) < M:
            pairs.append((a, b))
            a += 1
            b -= 1
    for p in pairs:
        print(p[0], p[1])



main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if(n % 2 == 0):
    d = n // 2 - 1
    c = 0
    i = 1
    while(d > 0):
        print(i,i+d)
        d -= 2
        i += 1
        c += 1
        if(c == m):exit()
    d = n // 2 - 2
    i = n // 2 + 1
    while(d > 0):
        print(i,i+d)
        d -= 2
        i += 1
        c += 1
        if(c == m):exit()


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

Submission status: Accepted

Solution code:
N,M=list(map(int, input().split()))
src=[i+1 for i in range(M*2+1)]
if M%2==0:
  for m in range(M//2):
    a=src[m]
    b=src[M-m]
    print('{} {}'.format(a,b))
  for m in range(M//2):
    a=src[M+1+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))
else:
  for m in range(M//2):
    a=src[m]
    b=src[M-1-m]
    print('{} {}'.format(a,b))
  for m in range(M-(M//2)):
    a=src[M+m]
    b=src[-(m+1)]
    print('{} {}'.format(a,b))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
ans=[]
if N%2==1:
  for i in range(M):
    ans.append([i+1,N-i])
else:
  for i in range(M//2):
    ans.append([i+1,2*M-i+1])
  for j in range(M-M//2):
    ans.append([j+M//2+1,2*M-M//2-j])
for k in ans:
  print(*k,sep=' ')