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: Runtime Error

Solution code:
import random
N,M = map(int, input().split())
player=[i for in range(1,N+1)]
dis=[]
for i in range(M):
    q=True
    while q:
        a=random.sample(player,2)
        x=a[0]
        y=a[1]
        if abs(x-y) not in dis:
            print(x,y)
            dis.append(abs(x-y))
            dis.append(N-abs(x-y))
            player.remove(x)
            player.remove(y)
            q=False

Submission status: Runtime Error

Solution code:
        print(a, b)
        pair += 1
        a += 1
        b -= 1

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m  = map(int, input().split())
a = n // 2
d = 1
memo = []
for i in range(m):
    for mi in memo:
        if d + mi == n:
            print(1 / 0)
    memo.append(d)
    print(a, a+d)
    a -= 1
    d += 2

Submission status: Runtime Error

Solution code:
def resolve():
    n, m = map(int, input().split())
    ans = []
    diff = {}
    used = [0]*(n+1)
    for i in range(1,n+1):
        if used[i] == 1:
            continue
        else:
            for j in range(i+1, n+1):
                if used[j] != 1 and abs(i-j) not in diff:
                    ans.append([i, j])
                    used[i] = 1
                    used[j] = 1
                    diff[abs(i-j)] = 1
                    diff[n-abs(i-j)] = 1
                    break
    for i in range(m):
        print(" ".join(map(str, ans[i])))

resolve()

Submission status: Runtime Error

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

n -= 1
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
primes[0] = 1

for i in range(m):
    a = primes[-i-1]
    print(i+1,i+a+1)

Submission status: Runtime Error

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

a=1
b=n

if((4*m-2)==n):
    print(1/0)

for i in range(m):
    print(a,b)
    a+=1
    b-=1

Submission status: Runtime Error

Solution code:
from collections import deque

N, M = map(int, input().split())
matches = []
used = [False] * N
q = deque(range(N))
l = 1
while q and len(matches) < M:
    i = q.popleft()
    j = i + l
    if used[i] or used[j]: continue
    used[i], used[j] = True, True
    matches.append((i+1, j+1))
    l += 1
for a, b in matches:
    print(a, b)

Submission status: Runtime Error

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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

if not N%2:
    print(unko)


x,y=N//2,N//2+1
for i in range(M):
    print(x-i,y+i)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
dist=[0 for i in range(n)]
A=deque([i+1 for i in range(n)])
i=0
while 1:
    a=A.popleft()
    b=A.pop()
    if dist[b-a]==0 and dist[a+n-b]==0:
        print(a,b)
        dist[b-a]=1
        dist[a+n-b]=1
        i+=1
    else:
        A.appendleft(a)
        a=A.popleft(a)
        continue
    if i==m:
        exit()

Submission status: Runtime Error

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

empty = [True]*N

for m in range(M, 0, -1):
  i = 0
  while not(empty[i] and empty[i + m]):
    i += 1
  empty[i] = False
  empty[i+m] = False
  print(i+1, i+m+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
flag = [False]*(10**5+10)
plu = 1
for i in range(1,N+1):
  if M==0:
    break
  if flag[i] or flag[i+plu]:
    continue
  else:
    flag[i]=True
    flag[i+plu]=True
    print(i,i+plu)
    plu+=1
    M-=1

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()

if N%2:
    count = 0
    for i in range(1,(N+1)//2):
        if count < M:
            print(i,N+1-i)
            count += 1
else:
    count = 0
    for i in range(1,N//2+1):
        if count < M and N+1-2*i != N//2:
            print(i,N+1-i)
            count += 1
            raise(ValueError())

Submission status: Runtime Error

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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

if N%2:
    print(unko)


x,y=N//2,N//2+1
for i in range(M):
    print(x-i,y+i)

Submission status: Runtime Error

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

L = set([])
for i in range(N):
  L.add(i+1)
#print(L)

for i in range(M):
  d = i+1 #差分
  a = min(L)
  L.remove(a)
  b = a+d
  L.remove(b)
  print(a,b)

Submission status: Runtime Error

Solution code:
from collections import deque
def main():
    n,m = map(int, input().split())
    lst = deque([i for i in range(1,n+1)])
    for i in range(1,m+1):
        a = lst.popleft()
        b = a + i
        lst.remove(b)
        print(str(a)+' '+str(b))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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()))
ans=[False for _ in range(a)]
t=0
for i in range(a):
    if ans[i]:
        continue
    t+=1
    n=i+1
    ans[i+t]=True
    print(n,n+t)
    if t==b:
        exit()

Submission status: Runtime Error

Solution code:
def main():
    n,m = map(int, input().split())
    lst = [i for i in range(1,n+1)]
    for i in range(1,m+1):
        a = lst.pop(0)
        b = a + i
        lst.remove(b)
        print('{} {}'.format(a,b))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
if 2*m+1 == n:
    for i in range(1, m+1):
        print(f"{i} {n-i}")
else:
    array = [0]*(n+1)
    now = 1
    for i in range(1, m+1):
        while array[now] == 1:
            now += 1
        print(f"{now} {now+i}")
        array[now+i] = 1
        now += 1

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

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

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

P=callIsPrime(100000)
P.pop(0)
L=[1]
L.extend(P)
cnt=1
for i in range(M):
    print(cnt,cnt+L[M-i-1])
    cnt+=1

Submission status: Runtime Error

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values()

    if N % 2 == 1: 
        L = N // 2
        R = L + 1
        for _ in range(M):
            print(L, R)
            L -= 1
            R += 1
    else:
        F = [False] * N
        d = 1
        f = 0
        for _ in range(M):
            while F[f]:
                f += 1

            print(f + 1, f + d + 1)
            F[f + d] = True
            d += 1
            f += 1


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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


s = -1
b = 1
used = [False]*100000
for i in range(M):
    while(True):
        s+=1
        if not used[s]:
            break

    print(s%N+1, (s+b)%N+1)
    
    used[s] = True
    used[s+b] = True
    b += 1

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
const int MAX_V = 200001;
vvl G = VV(MAX_V, 0, 0, ll);
int root;
vll dat(200001, 0);

//-------------------------------------------------------------------
struct segtree{
  ll M=1, INIT;
  vector<ll> dat;
  segtree(ll N, ll num){
    INIT = num;
    while(M<N) M*=2;
    for(int i=0;i<M*2-1;i++)  dat.push_back(num);
  }
  void update(ll x, ll k, ll l=0, int r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] = x;
    while(k>0) k = (k-1)/2, dat[k] = max(dat[k*2+1],dat[k*2+2]);
  }
  ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INIT;
    if(a<=l && r<=b) return dat[k];
    ll A = query(a, b, k*2+1, l, (l+r)/2);
    ll B = query(a, b, k*2+2, (l+r)/2, r);
    return max(A, B);
  }
};

segtree seg(200001, 0);
vll ans(200001, 0);
vector<multiset<ll>> num(200001);

void f(ll now, ll from){
  ll q = seg.query(0, dat[now]);
  ll t = seg.query(0, 200001);
  ans[now] = max(q+1, t);

  num[dat[now]].insert(q+1);
  auto itr = --num[dat[now]].end();
  seg.update((*itr), dat[now]);

  for(auto to:G[now]){
    if(to==from) continue;
    f(to, now);
  }
  itr = num[dat[now]].find(q+1);
  num[dat[now]].erase(itr);
  if(num[dat[now]].size()==0) seg.update(0, dat[now]);
  else{
    itr = --num[dat[now]].end();
    seg.update((*itr), dat[now]);  
  }
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll a, b, n;std::cin >> n;
  map<ll, ll> mp;

  re(i, n) {
    scanf("%lld", &dat[i+1]);
    mp.emplace(dat[i+1], 0);
  }

  ll cnt = 0;
  for(auto itr=mp.begin();itr!=mp.end();itr++, cnt++) {
    (*itr).second = cnt;
  }

  for(int i=1;i<=n;i++) dat[i] = mp.at(dat[i]);
  re(i, n-1){
    scanf("%lld %lld", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  f(1, -1);

  for(int i=1;i<=n;i++) std::cout << ans[i] << '\n';
  return 0;
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
used = [0] * (N+1)
used[0] = 1
for i in range(1,M+1):
    a = used.index(0)
    b = a + i
    print(a, b)
    used[a] = 1
    used[b] = 1

Submission status: Runtime Error

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

    ans = [None for _ in range(m)]
    used = set()
    a = 1
    b = n
    good = True
    for i in range(m):
        if b - a == n - (b - a):
            a += 1
            b -= 1
        ans[i] = (a, b)
        if (b - a) in used:
            good = False
            break
        else:
            used.add(b - a)
        if (n - (b - a)) in used:
            good = False
            break
        else:
            used.add(n - (b - a))
        a += 1
        b -= 1

    if not good:
        ans = [None for _ in range(m)]
        used = set()
        a = 1
        b = n-1
        good = True
        for i in range(m):
            if b - a == n - (b - a):
                a += 1
                b -= 1
            ans[i] = (a, b)
            if (b - a) in used:
                good = False
                break
            else:
                used.add(b - a)
            if (n - (b - a)) in used:
                good = False
                break
            else:
                used.add(n - (b - a))
            a += 1
            b -= 1

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void yes(bool c) { if (c)print("Yes"); else print("No"); };

int A, B, N;

int f(int x) {
	return A * x / B - A * (x / B);
}

void solve() {
	int N, M; cin >> N >> M;
	vector<bool>used(N);
	int mx = (N - 1) / 2;
	vector<pii>ans;
	int idx = 0;
	for (int d = mx; d > 0; d -= 2) {
		ans.push_back({ idx,idx + d });
		idx++;
	}
	idx = mx + 1;
	for (int d = mx - 1; d > 0; d -= 2) {
		ans.push_back({ idx,idx + d });
		idx++;
	}
	REP(i, M) {
		cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
		solve();
}

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


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


N, M = inpl()

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

Submission status: Runtime Error

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

C = math.floor(N / 2)
D = C+1

for i in range(M):
    print(C, D)
    C = C - 1
    D = D + 1

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
can = set(range(1,n+1))
ans = [[0,0] for _ in range(m)]
done = 0
for i in range(1,n+1):
    if done == m:break
    if i not in can:continue
    else:
        ans[done] = [i,i+done+1]
        can.remove(i+done+1)
        done += 1
for i in range(m):
    print(' '.join(str(i) for i in ans[i]))