AtCoder Beginner Contest 165 - Rotation Matching

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-----
4 1

-----Sample Output-----
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.

Difficulty: MEDIUM

Starter code:

Solutions:
(N, M) = map(int, input().split())
i = 0
K = M
while K > 0:
	if (M - K) % 2 == 0:
		print(i // 2 + 1, i // 2 + 1 + K)
	else:
		print(M + 2 + (i - 1) // 2, M + 2 + (i - 1) // 2 + K)
	K -= 1
	i += 1


(N, M) = map(int, input().split())
even = M // 2
odd = (M + 1) // 2
B = odd * 2
K = B + even * 2
ans = []
for n in range(1, odd + 1):
	print(n, B - n + 1)
for n in range(1, even + 1):
	print(B + n, K - n + 2)


def main():
	(N, M) = list(map(int, input().split()))
	if N % 2 == 1:
		for i in range(M):
			print((i + 1, N - i - 1))
	else:
		s = set()
		t = 0
		for i in range(M):
			(a, b) = (i + 1, N - i - t)
			if b - a in s or a + N - b in s or b - a == a + N - b:
				t += 1
				b = N - i - t
			print((a, b))
			s.add(b - a)
			s.add(N + a - b)
main()


(N, M) = map(int, input().split())
if N % 2 == 1:
	for i in range(M):
		j = N - i
		print(f'{i + 1} {j}')
else:
	for i in range(M):
		j = N - i
		if i < M / 2:
			print(f'{i + 1} {j}')
		else:
			print(f'{i + 1} {j - 1}')


(N, M) = map(int, input().split())
piv = N // 4 + (N % 4 == 3)
pairs = [(str(piv - i), str(piv + 1 + i)) for i in range(N // 4 + (N % 4 == 3))]
piv = N - N // 4 + (N % 4 == 0)
pairs += [(str(piv - 1 - i), str(piv + 1 + i)) for i in range(N // 4 - (N % 4 == 0))]
for pair in pairs[:M]:
	print(' '.join(pair))


def getN():
	return int(input())

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

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

def getArray(intn):
	return [int(input()) for i in range(intn)]

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

def rand_N(ran1, ran2):
	return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):
	return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):
	ns = []
	while len(ns) < rantime:
		n = random.randint(ran1, ran2)
		if not n in ns:
			ns.append(n)
	return sorted(ns)

def rand_query(ran1, ran2, rantime):
	r_query = []
	while len(r_query) < rantime:
		n_q = rand_ints_nodup(ran1, ran2, 2)
		if not n_q in r_query:
			r_query.append(n_q)
	return sorted(r_query)
from collections import defaultdict, deque, Counter
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
(N, M) = getNM()
A = []
B = []
if N % 2 != 0:
	for i in range(M):
		A.append(i + 1)
		B.append(N - i)
else:
	for i in range(M):
		A.append(i + 1)
		if i <= N // 4 - 1:
			B.append(N - i)
		else:
			B.append(N - i - 1)
for i in range(M):
	print((A[i], B[i]))


(N, M) = map(int, input().split())
if N % 2 == 0:
	N -= 1
li = []
(i, j) = (1, (N + 1) // 2)
while i < j:
	li.append((i, j))
	i += 1
	j -= 1
(i, j) = (N, (N + 3) // 2)
while i > j:
	li.append((j, i))
	i -= 1
	j += 1
for m in range(M):
	print(li[m][0], li[m][1])


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


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


def resolve():
	(N, M) = map(int, input().split())
	if M == 1:
		print(1, 2)
		return
	i1 = 1
	i2 = M + 2
	for diff in range(M, 0, -1):
		print(i1, i1 + diff)
		i1 += 1
		(i1, i2) = (i2, i1)

def __starting_point():
	resolve()
__starting_point()


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


(n, m) = map(int, input().split())
if m % 2 == 1:
	cnt = 0
	for i in range(m // 2):
		num1 = 1 + i
		num2 = m - i
		print(num1, num2, sep=' ')
		cnt += 1
		if cnt == m:
			return
	for i in range(m // 2 + 1):
		num1 = m + 1 + i
		num2 = 2 * m + 1 - i
		print(num1, num2, sep=' ')
		cnt += 1
		if cnt == m:
			return
else:
	cnt = 0
	for i in range(m // 2):
		num1 = 1 + i
		num2 = m + 1 - i
		print(num1, num2, sep=' ')
		cnt += 1
		if cnt == m:
			return
	for i in range(m // 2):
		num1 = m + 2 + i
		num2 = 2 * m + 1 - i
		print(num1, num2, sep=' ')
		cnt += 1
		if cnt == m:
			return


(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


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


(N, M) = map(int, input().split())
a = 1
b = N
d = set([1, N - 1])
for _ in range(M):
	print(a, b)
	a += 1
	b -= 1
	while b - a in d or N - b + a in d or b - a == N - b + a:
		b -= 1
	d.add(b - a)
	d.add(N - b + a)


(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


(n, m) = map(int, input().split())
a = int(n / 2)
b = a + 1
offset = False
if n % 2 == 0:
	offset = True
for i in range(m):
	if offset and b - a >= n / 2:
		b += 1
		offset = False
	print(a, b)
	a -= 1
	b += 1


(N, M) = map(int, input().split())
if N % 2 == 1:
	S = 1
	L = N
	for i in range(M):
		print(S + i, L - i)
else:
	S = 1
	L = N
	for i in range(M):
		if S + i > N / 4:
			print(S + i, L - i - 1)
		else:
			print(S + i, L - i)


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


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


(n, m) = list(map(int, input().split()))
oddflag = True
for i in range(1, m + 1):
	mid = (1 + n) // 2
	if oddflag:
		oddflag = False
		print((i // 2 + 1, n - i // 2))
	else:
		oddflag = True
		print((mid + i // 2, mid - i // 2))


(n, k) = list(map(int, input().split()))
if n % 2 == 1:
	p = 1
	q = n
	for i in range(k):
		print(f'{p} {q}')
		p += 1
		q -= 1
else:
	p = 1
	q = n
	for i in range(k):
		print(f'{p} {q}')
		if abs(p - q) == n // 2 + 1:
			p += 1
		p += 1
		q -= 1
		if abs(p - q) == n // 2:
			p += 1


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


(N, M) = map(int, input().split())
(a, b) = (1, N)
S = set()
for _ in range(M):
	print(a, b)
	S.add(b - a)
	S.add(a + N - b)
	a += 1
	b -= 1
	if b - a in S or a + N - b in S or b - a << 1 == N:
		b -= 1


(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


def main():
	(n, m) = list(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]))

def __starting_point():
	main()
__starting_point()


(N, M) = map(int, input().split())
if N % 2:
	for i in range(M):
		print(2 + i, N - i)
else:
	used = set()
	s = 1
	for i in list(range(2, M + 1, 2)[::-1]) + list(range(1, M + 1, 2)[::-1]):
		while 1:
			if not s in used and (not s + i in used):
				used.add(s)
				used.add(s + i)
				print(s, s + i)
				break
			s += 1


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


(n, m) = map(int, input().split())
l = []
if n % 2 == 0:
	i = 1
	while i < n // 2 + 1 - i:
		l.append((i, n // 2 + 1 - i))
		i += 1
	j = 1
	while j < n // 2 - j:
		l.append((n // 2 + j, n - j))
		j += 1
else:
	for i in range(1, n // 2 + 1):
		l.append((i, n - i))
for (a, b) in l[:m]:
	print(a, b)


(N, M) = map(int, input().split())
(l, r) = (1, N // 2)
while M and l < r:
	print(l, r)
	l += 1
	r -= 1
	M -= 1
(l, r) = (N // 2 + 2 - N % 2, N)
while M:
	print(l, r)
	l += 1
	r -= 1
	M -= 1


(N, M) = map(int, input().split())
if N % 2 == 0:
	N -= 1
H = N // 2
if H % 2 == 1:
	H += 1
m = 0
i = 1
while m < M:
	print(i, H - i + 1)
	i += 1
	m += 1
	if i >= H - i + 1:
		break
i = 1
while m < M:
	print(H + i, N + 1 - i)
	i += 1
	m += 1


import sys
readline = sys.stdin.readline
(n, m) = map(int, readline().split())
l = 1
r = n
used = set()
while len(used) < m * 2:
	diff = r - l
	rdiff = n - diff
	if diff == rdiff:
		r -= 1
		continue
	if diff in used:
		r -= 1
		continue
	print(l, r)
	used.add(diff)
	used.add(rdiff)
	l += 1
	r -= 1


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


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


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	(n, m) = list(map(int, input().split()))
	if n % 2:
		left = 1
		right = n - 1
		while left < right and m:
			print((left, right))
			left += 1
			right -= 1
			m -= 1
	else:
		left = 1
		right = n - 1
		flg = False
		while left < right and m:
			if not flg and right - left <= n // 2:
				right -= 1
				flg = True
			print((left, right))
			left += 1
			right -= 1
			m -= 1

def __starting_point():
	resolve()
__starting_point()


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


(N, M) = map(int, input().split())
res = []
for i in range(M):
	if i % 2 == 0:
		j = i // 2
		print('{} {}'.format(1 + j, M + 1 - j))
	else:
		j = i // 2
		print('{} {}'.format(M + 2 + j, 2 * M + 1 - j))


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
(N, M) = map(int, input().split())
res = []

def solve(l, r):
	global res
	if r <= l:
		return
	res.append((l, r))
	solve(l + 1, r - 1)
solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res:
	print(*r)


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


(n, m) = map(int, input().split())
cand = list(range(1, n + 1))
ans = []
for i in range(1, (m + 1) // 2 + 1):
	ans.append((cand[1 - i], i + 1))
n_odd = m // 2
start = ans[-1][1] + n_odd
for i in range(1, n_odd + 1):
	ans.append((start - i + 1, start + i + 1))
for aa in ans:
	print(*aa)


(n, m) = map(int, input().split())
x = (n + 1) // 2
cnt_l = -(-m // 2)
cnt_r = m // 2
ans = []
for i in range(cnt_l):
	ans.append((i + 1, x - i))
for i in range(cnt_r):
	ans.append((x + 1 + i, 2 * x - i - 1))
for i in range(m):
	print(*ans[i])


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


import math
bl = input().split()
n = int(bl[0])
s = int(bl[1])
for a in range(math.ceil(s / 2)):
	print(str(a + 1) + ' ' + str(s - a + 1))
for b in range(math.floor(s / 2)):
	print(str(s + b + 2) + ' ' + str(2 * s - b + 1))


(n, m) = map(int, input().split())
k = n // 2
c = 0
while c < m:
	d = c // 2
	if c % 2 == 0:
		print(k - d, k + 1 + d)
	else:
		print(d + 1, n - 1 - d)
	c += 1


def main():
	import sys

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

def __starting_point():
	main()
__starting_point()


(N, M) = map(int, input().split())
order = [i for i in range(2, N + 1)]
reverse = order[::-1]
d = 0
for i in range(M):
	if N % 4 == 0 and reverse[i] - order[i] == N // 2:
		d = 1
	if N % 2 == 0 and i == (N // 2 - 1) // 2:
		d = 1
	print(order[i + d], reverse[i])


(n, m) = [int(i) for i in input().split()]
i = 0
j = 1
k = 0
while j < n // 2 and k < m:
	print(i % n + 1, (i + j) % n + 1)
	i -= 1
	j += 2
	k += 1
i = (i + j - 1 + (m - k)) % n
j = 2
while k < m:
	print(i % n + 1, (i + j) % n + 1)
	i -= 1
	j += 2
	k += 1


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


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


(n, m) = list(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:
			return
	d = n // 2 - 2
	i = n // 2 + 1
	while d > 0:
		print((i, i + d))
		d -= 2
		i += 1
		c += 1
		if c == m:
			return
else:
	for i in range(m):
		print((i + 1, n - i))


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


(N, M) = list(map(int, input().split()))
n = 2 * M + 1
if M % 2 == 1:
	for i in range(1, M // 2 + 1):
		print('{} {}'.format(i, M + 1 - i))
	for i in range(1, (M + 1) // 2 + 1):
		print('{} {}'.format(M + i, 2 * M + 2 - i))
else:
	for i in range(1, M // 2 + 1):
		print('{} {}'.format(i, M + 2 - i))
	for i in range(1, M // 2 + 1):
		print('{} {}'.format(M + i + 1, 2 * M + 2 - i))


(N, M) = map(int, input().split())
cnt = 0
i = 0
j = M
while i + 1 < j and cnt < M:
	print(i + 1, j)
	i += 1
	j -= 1
	cnt += 1
i = M
j = 2 * M + 1
while i + 1 < j and cnt < M:
	print(i + 1, j)
	i += 1
	j -= 1
	cnt += 1


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


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


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


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


(n, m) = map(int, input().split())
a = 0
for i in range(m):
	if n % 2 == 0 and n % 4 != 0 and (n - 4 * i - 2 == 0):
		a = 1
	elif n % 4 == 0 and i == (n // 2 - 1) // 2 + 1:
		a = 1
	print('{} {}'.format(i + 1, n - i - a))


(N, M) = map(int, input().split())
if M % 2 != 0:
	center = M + 1
else:
	center = M
c = center // 2
d = (center + 1 + 2 * M + 1) // 2
i = 0
while i < c:
	print(c - i, c + 1 + i)
	i += 1
j = 0
while i < M:
	print(d - (j + 1), d + (j + 1))
	i += 1
	j += 1


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


(N, M) = map(int, input().split())
a = M // 2
b = M - a
c = 1
d = 2 * a + 1
for i in range(a):
	print(c, d)
	c += 1
	d -= 1
e = 2 * a + 2
f = 2 * M + 1
for i in range(b):
	print(e, f)
	e += 1
	f -= 1


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


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


def solve():
	(N, M) = list(map(int, input().split()))
	m = 0
	oddN = M
	oddN += (oddN + 1) % 2
	for i in range(oddN // 2):
		print((i + 1, oddN - i))
		m += 1
		if m == M:
			return
	for i in range(M):
		print((oddN + i + 1, M * 2 + 1 - i))
		m += 1
		if m == M:
			return

def __starting_point():
	solve()
__starting_point()


(N, M) = map(int, input().split())
halfPos = -(-N // 2)
qPos = halfPos // 2
q3Pos = qPos + halfPos
for m in range(1, M + 1):
	if m % 2:
		print(qPos - m // 2, qPos + m // 2 + 1)
	else:
		print(q3Pos - m // 2, q3Pos + m // 2)


(n, m) = map(int, input().split())
ans = [1] * n
for i in range(1, n):
	if ans[i] == 1:
		ans[n - i] = 0
c = 0
x = []
for i in range(1, n):
	if ans[i] == 1:
		if len(x) % 2 == 0:
			x.append(n - i)
		else:
			x.append(i)
x.sort(reverse=1)
for i in range(m):
	print(i + 1, i + 1 + x[i])


(n, m) = map(int, input().split())
ans = []
i = 1
while i < m + 2 - i:
	ans.append([i, m + 2 - i])
	i += 1
i = m + 2
while i < 3 * m + 3 - i:
	ans.append([i, 3 * m + 3 - i])
	i += 1
for i in ans:
	print(*i)


(N, M) = list(map(int, input().split()))
A = [i + 1 for i in range(N)]
mid = N // 2
ans = []
for i in range(M + 1 // 2):
	ans.append([A[mid - i], A[mid + 1 + i]])
	ans.append([A[-1 - i], A[1 + i]])
for i in range(M):
	print(*ans[i])


(N, M) = map(int, input().split())
(a, b) = (1, N // 2)
(c, d) = (N // 2 + 1, N)
if N % 2 == 0:
	a += 1
i = 0
while i < M:
	if i < M:
		print(c, d)
		i += 1
		(c, d) = (c + 1, d - 1)
	else:
		break
	if i < M:
		print(a, b)
		(a, b) = (a + 1, b - 1)
		i += 1
	else:
		break


(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


import sys

def solve():
	input = sys.stdin.readline
	(N, M) = map(int, input().split())
	used = set()
	Ans = [None for _ in range(M)]
	left = 1
	right = N
	for i in range(M):
		if right - left in used or 2 * (right - left) == N:
			right -= 1
		Ans[i] = (left, right)
		diff = right - left
		used |= {diff, N - diff}
		left += 1
		right -= 1
	for i in range(M):
		print(*Ans[i], sep=' ')
	return 0

def __starting_point():
	solve()
__starting_point()


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

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

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

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

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

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

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

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

def __starting_point():
	main()
__starting_point()


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


(N, M) = map(int, input().split())
M1 = M // 2
M2 = M - M1
for i in range(M1):
	a = i + 1
	b = 2 * M1 + 1 - i
	print(a, b)
for i in range(M2):
	a = i + 1
	b = 2 * M2 - i
	print(2 * M1 + 1 + a, 2 * M1 + 1 + b)


import sys

def main():
	(N, M) = tuple(map(int, sys.stdin.readline().split()))
	if M % 2 == 1:
		(m1, m2) = (M // 2, M // 2 + 1)
		for i in range(m1):
			(l, r) = (i + 1, M - i)
			print(str(l) + ' ' + str(r))
		for i in range(m2):
			(l, r) = (M + 1 + i, 2 * M + 1 - i)
			print(str(l) + ' ' + str(r))
	else:
		m = M // 2
		for i in range(m):
			(l, r) = (i + 1, M + 1 - i)
			print(str(l) + ' ' + str(r))
		for i in range(m):
			(l, r) = (M + 2 + i, 2 * M + 1 - i)
			print(str(l) + ' ' + str(r))

def __starting_point():
	main()
__starting_point()


import sys

def main():
	input = sys.stdin.buffer.readline
	(N, M) = list(map(int, input().split()))
	skip = N // 2 // 2 + 1 if N % 2 == 0 else None
	count = 0
	(left, right) = (0, N + 1)
	while count < M:
		left += 1
		if left == skip:
			continue
		right -= 1
		print((left, right))
		count += 1

def __starting_point():
	main()
__starting_point()


def main():
	(N, M) = list(map(int, input().split()))
	skip = N // 2 // 2 + 1 if N % 2 == 0 else None
	count = 0
	(left, right) = (0, N + 1)
	while count < M:
		left += 1
		if left == skip:
			continue
		right -= 1
		print((left, right))
		count += 1

def __starting_point():
	main()
__starting_point()


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

def __starting_point():
	main()
__starting_point()


(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


import sys
import math
input = lambda : sys.stdin.readline().strip()
(n, m) = map(int, input().split())
k = 0
j = 0
for i in range(m):
	if n % 2 == 0 and (n - j - (i + 1)) * 2 <= n and (k == 0):
		j += 1
		k += 1
	print(i + 1, n - j)
	j += 1


(n, m) = list(map(int, input().split()))
a = n // 2
b = a + 1
abset = set()
for i in range(m):
	print(a, b)
	abset.add(b - a)
	abset.add(n - b + a)
	a -= 1
	b += 1
	if n % 2 == 0 and (b - a == abs(n - b + a) or b - a in abset or n - b + a in abset):
		b += 1


(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):
	distab = dist(a, b)
	if 2 * distab == n or distab in S:
		a -= 1
	print(a, b)
	S.add(distab)
	a -= 1
	b += 1


(n, m) = list(map(int, input().split()))
d = m
r = d + 1
for i in range(m):
	if d <= 0:
		break
	a = i + 1
	b = a + d
	print((a, b))
	d -= 2
d = m - 1
for i in range(m):
	if d <= 0:
		break
	a = r + i + 1
	b = a + d
	print((a, b))
	d -= 2


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


import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
ni = lambda : int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda : list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda : float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda : list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda : stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda : stdin.readline().split()
(n, m) = na()
if m == 1:
	print(1, 2)
	return
if m % 2 == 0:
	l = (m + 1) // 2
	r = (m + 1) // 2 + 2
	cnt = 0
	while cnt < m and l >= 1 and (r <= m + 1):
		print(l, r)
		l -= 1
		r += 1
		cnt += 1
	l = (n - m - 1) // 2
	r = (n - m - 1) // 2 + 1
	while cnt < m and l >= 1 and (r <= n - m - 1):
		print(m + 1 + l, m + 1 + r)
		l -= 1
		r += 1
		cnt += 1
else:
	l = m // 2
	r = m // 2 + 2
	cnt = 0
	while cnt < m and l >= 1 and (r <= m):
		print(l, r)
		l -= 1
		r += 1
		cnt += 1
	l = (n - m) // 2
	r = (n - m) // 2 + 1
	while cnt < m and l >= 1 and (r <= n - m):
		print(m + l, m + r)
		l -= 1
		r += 1
		cnt += 1


(n, m) = list(map(int, input().split()))
even = m // 2
odd = m - even
odd_left = 1
odd_right = 2 * odd
even_left = odd_right + 1
even_right = even_left + 2 * even
for _ in range(odd):
	print((odd_left, odd_right))
	odd_left += 1
	odd_right -= 1
for _ in range(even):
	print((even_left, even_right))
	even_left += 1
	even_right -= 1


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


(N, M) = map(int, input().split())
k = (M + 1) // 2
(s, e) = (1, 2 * k)
for _ in range(k):
	print(s, e)
	(s, e) = (s + 1, e - 1)
k = M // 2
(s, e) = (N - 2 * k, N)
for _ in range(k):
	print(s, e)
	(s, e) = (s + 1, e - 1)


(N, M) = map(int, input().split())
for i in range(min(M, N // 4)):
	print('{} {}'.format(i + 1, N - i))
center = (N + 1) // 2
for i in range(max(0, M - N // 4)):
	print('{} {}'.format(center - i - 1, center + i + 1))


(n, m) = list(map(int, input().split()))
mm = int((m + 1) / 2 + 0.01)
for i in range(mm):
	print(1 + i, 2 * mm - i)
for i in range(m - mm):
	print(2 * mm + i + 1, 2 * m - i + 1)


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


(n, m) = map(int, input().split())
ans = []
if n % 2:
	for i in range(m):
		ans.append('{} {}'.format(i + 1, n - i))
else:
	for i in range(m):
		if i + 1 <= m // 2 + m % 2:
			ans.append('{} {}'.format(i + 1, n - i))
		else:
			ans.append('{} {}'.format(i + 1, n - 1 - i))
print('\n'.join(ans))


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


(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


(n, m) = map(int, input().split())
ans = []
for i in range(2, m + 1, 2):
	ans.append([n - i // 2, i // 2])
for i in range(1, m + 1, 2):
	ans.append([n // 2 - (i - 1) // 2, n // 2 + 1 + (i - 1) // 2])
for i in range(m):
	print(*ans[i])


(n, m) = map(int, input().split())
od = (m + 1) // 2
x = 2 * od + 1
for i in range(1, od + 1):
	print(i, x - i)
ev = m - od
y = 2 * ev
for i in range(m - od):
	print(x + i, x + y - i)


(N, M) = map(int, input().split())
if N % 2 == 1:
	for i in range(1, M + 1):
		print(i, 2 * M + 1 - i)
else:
	used = {N // 2}
	j = 1
	for i in range(M, 0, -1):
		while j in used:
			j += 1
		print(i, i + j)
		used.add(j)
		used.add(N - j)
		j += 2


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


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


(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


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


def __starting_point():
	nm = input()
	nm = nm.split()
	n = int(nm[0])
	m = int(nm[1])
	if n % 2 == 1:
		for i in range(1, m + 1):
			print((i, n + 1 - i))
	if n % 2 == 0:
		t = n
		f = 0
		for i in range(1, m + 1):
			p = i - 1 + t - n
			if p >= n - i - 1 and f == 0:
				f = 1
				n -= 1
			print((i, n))
			n -= 1
__starting_point()


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


(n, m) = list(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):
		if i <= (m + 1) // 2 - 1:
			ans.append((i + 1, n - i))
		else:
			ans.append((i + 1, n - i - 1))
for (a, b) in ans:
	print((a, b))


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


(n, m) = list(map(int, input().split()))
k = 1
k_even = n // 2 + 1
p_even = k_even + 1

def rotate(s, diff):
	if s + diff < 1:
		return s + diff + n
	elif s + diff > n:
		return s + diff - n
	return s + diff
for i in range(m + 1):
	if i != 0 and i % 2 == 0:
		print((rotate(k, -(i // 2)), rotate(k, i // 2)))
	if i % 2 == 1:
		print((rotate(k_even, -(i // 2)), rotate(p_even, i // 2)))


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
(n, m) = [int(i) for i in input().split()]
tmp_l = m + 1
tmp_r = m - 1
res = []
while tmp_r > 0:
	res.append([tmp_l + 1, tmp_l + tmp_r + 1])
	tmp_l += 1
	tmp_r -= 2
tmp_l = 0
tmp_r = m
while tmp_r > 0:
	res.append([tmp_l + 1, tmp_l + tmp_r + 1])
	tmp_l += 1
	tmp_r -= 2
res = '\n'.join([' '.join([str(i) for i in j]) for j in res])
print(res)


[N, M] = [int(s) for s in input().rstrip().split(' ')]
if M == 1:
	print('1 2')
else:
	for i in range(1, M // 2 + 1):
		print('{} {}'.format(i, M + 1 - i))
	for i in range(1, -(-M // 2) + 1):
		print('{} {}'.format(M + i, 2 * M + 2 - i))


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


def main():
	(N, M) = map(int, input().split())
	if N & 1:
		gen = ((i + 1, N - i) for i in range(M))
	else:
		gen = ((i + 1, N - i) if 2 * i < N / 2 - 1 else (i + 1, N - i - 1) for i in range(M))
	[print(*s) for s in gen]

def __starting_point():
	main()
__starting_point()


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


(N, M) = [int(i) for i in input().split()]
if N % 2 == 1:
	for i in range(1, M + 1):
		print(i, end=' ')
		print(N + 1 - i)
	return
L = min(M, N // 4)
for i in range(1, L + 1):
	print(i, end=' ')
	print(N + 1 - i)
if L < M:
	for i in range(L + 1, M + 1):
		print(i, end=' ')
		print(N - i)


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, m) = LI()
	rr = []
	if n % 2 == 1:
		t = n // 2 + 1
		for i in range(1, m + 1):
			rr.append((t - i, t + i))
	else:
		t1 = (m + 1) // 2
		t2 = n - m // 2
		for i in range(t1):
			rr.append((t1 - i, t1 + 1 + i))
		for i in range(1, m // 2 + 1):
			rr.append((t2 - i, t2 + i))
	return JAA(rr, '\n', ' ')
print(main())


def main():
	(N, M) = list(map(int, input().split()))
	is_odd = N - 1 & 1
	bias = 0
	for (i, distance) in enumerate(range(N - 1, 0, -2)):
		if is_odd and distance <= -distance % N:
			bias = 1
		left = i + 1
		right = left + distance - bias
		print((left, right))
		if i == M - 1:
			return

def __starting_point():
	main()
__starting_point()


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


(N, M) = map(int, input().split())
ans = []
if N % 2:
	for i in range(N // 2):
		ans.append((i + 1, N - 1 - i))
else:
	m = N // 2
	for i in range(m // 2):
		ans.append((i + 1, m - i))
	for i in range((m - 1) // 2):
		ans.append((m + i + 1, N - 1 - i))
for (a, b) in ans[:M]:
	print(a, b)


def main():
	import sys
	input = sys.stdin.readline
	(n, m) = map(int, input().split())
	l = 1
	r = n
	if n % 2 == 1:
		for i in range(m):
			print(f'{l} {r}')
			l += 1
			r -= 1
	else:
		flag = True
		for i in range(m):
			if flag and r - l <= n // 2:
				r -= 1
				flag = False
			print(f'{l} {r}')
			l += 1
			r -= 1
main()


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


from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque, Counter
from operator import mul
import copy
import heapq
(n, m) = list(map(int, input().split()))
p = m // 2
for i in range(p):
	print((p - i, p + 2 + i))
q = m // 2 + 1
if m % 2 == 1:
	for i in range(q):
		print((m + q - i, m + q + i + 1))
else:
	for i in range(q - 1):
		print((m + q - i, m + q + i + 1))


(n, m) = map(int, input().split())
if n % 2 == 1:
	ab = []
	a = n // 2
	b = n // 2 + 1
	ab.append([str(a), str(b)])
	for _ in range(m - 1):
		a -= 1
		b += 1
		ab.append([str(a), str(b)])
	for (a, b) in ab:
		print(a, b)
else:
	l = m
	ab = []
	cnt = 0
	for i in range(m):
		if i % 2 == 0:
			a = i // 2 + 1
			b = a + l
		else:
			a = n - (i // 2 + 1)
			b = a - l
		ab.append([str(a), str(b)])
		l -= 1
	for (a, b) in ab:
		print(a, b)


(N, M) = map(int, input().split())
A = list(range(M))
B = list(range(M, 2 * M))[::-1]
B = [-2 - i for i in range(M // 2)] + B[M // 2:]
for (a, b) in zip(A, B):
	print(a % N + 1, b % N + 1)


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


(N, M) = map(int, input().split())
A = [int(i) for i in range(N)]
B = []
if N % 2 == 0:
	center = N // 2
	c1 = center // 2
	c2 = center + c1
	for i in range(1, M + 1):
		j = i // 2
		if i % 2 == 1:
			B.append((c1 - j, c1 + j + 1))
		else:
			B.append((c2 - (j - 1), c2 - (j - 1) + 2 * j))
else:
	center = N // 2 + 1
	for i in range(1, M + 1):
		B.append((center - i, center + i))
for i in B:
	print(i[0], i[1])


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


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


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


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


(N, M) = list(map(int, input().split()))
num = list(range(1, N + 1))
ans = []
if M % 2 == 0:
	for i in range(M // 2):
		ans.append([i + 1, M + 1 - i])
	for i in range(M // 2):
		ans.append([i + 2 + M, 2 * M + 1 - i])
if M % 2 != 0:
	for i in range(M // 2):
		ans.append([i + 1, M - i])
	for i in range(M - M // 2):
		ans.append([i + 1 + M, 2 * M + 1 - i])
for an in ans:
	print((an[0], an[1]))


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


(N, M) = map(int, input().split())
sets = []
if N % 2 == 1:
	for i in range(M):
		sets.append((i + 1, i + 1 + (N - 3 - 2 * i) + 1))
elif N % 2 == 0:
	count = 0
	kukan = []
	for i in range(N // 2 - 1):
		kukan.append(count)
		count += 2
		if count == N // 2 or count == N // 2 - 1:
			count += 1
	kukan.reverse()
	for i in range(M):
		sets.append((i + 1, i + 1 + kukan[i] + 1))
for set1 in sets:
	print(set1[0], set1[1])


(N, M) = map(int, input().split())
ans = []
s = 1
e = M + 1
while e > s:
	ans.append([s, e])
	s += 1
	e -= 1
s = M + 2
e = 2 * M + 1
while e > s:
	ans.append([s, e])
	s += 1
	e -= 1
for (s, e) in ans:
	print(s, e)


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


(N, M) = map(int, input().split())
ans = []
l1 = 1
l2 = 1 + M + 1
for i in range(M):
	now = M - i
	if i % 2 == 0:
		ans.append([l1, l1 + now])
		l1 += 1
	else:
		ans.append([l2, l2 + now])
		l2 += 1
for row in ans:
	print(row[0], row[1])


inf = 10 ** 15
mod = 10 ** 9 + 7
(n, m) = map(int, input().split())
tmp = n // 2
for i in range(m):
	if i % 2 == 0:
		print('{} {}'.format(tmp - i // 2, tmp + 1 + i // 2))
	else:
		print('{} {}'.format(1 + i // 2, n - i // 2 - 1))


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


(N, M) = map(int, input().split())
(x, y) = (1, N)
used = [False for i in range(N + 1)]
for i in range(M):
	if N % 2 == 0 and (y - x == N // 2 or used[y - x]):
		y -= 1
		print(x, y)
	else:
		print(x, y)
	used[y - x] = True
	used[N - (y - x)] = True
	x += 1
	y -= 1


(N, M) = list(map(int, input().split()))
odd_l = 1
odd_r = M
even_l = M + 1
even_r = 2 * M + 1
i = 0
while i < M:
	print((even_l, even_r))
	i += 1
	if i == M:
		break
	print((odd_l, odd_r))
	i += 1
	odd_l += 1
	odd_r -= 1
	even_l += 1
	even_r -= 1


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


(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


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


import math
(n, m) = map(int, input().split(' '))
start = 1
end = n
wq = n // 4
for i in range(m):
	if i == wq and n % 2 == 0:
		start += 1
	print(start, end)
	start += 1
	end -= 1


(n, m) = map(int, input().split())
center1 = (m + 1) // 2
center2 = center1 + m
for i in range(m):
	if i % 2 == 0:
		a = center1 - i // 2
		b = center1 + i // 2 + 1
	else:
		a = center2 - i // 2
		b = center2 + (i + 1) // 2 + 1
	print(f'{a} {b}')


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


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


(n, m) = map(int, input().split())
e = 0
for i in range(m):
	if n / 2 == 2 * i + 1 or 4 * i == n:
		e = 1
	print(str(n // 2 - i) + ' ' + str(n // 2 + 1 + i + 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


(n, m) = map(int, input().split())
cnt = 0
k = (n - 1) // 2
a = (k + 1) // 2
b = k - a
for i in range(1, a + 1):
	print(i, 2 * a + 1 - i)
	cnt += 1
	if cnt == m:
		exit()
for i in range(b):
	print(2 * a + 1 + i, n - (n + 1) % 2 - i)
	cnt += 1
	if cnt == m:
		exit()


(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


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


(n, m) = map(int, input().split())
a = (n - 1) // 2
d = 1
memo = set([])
for i in range(m):
	if n - d in memo or 2 * d == n:
		d += 1
	memo.add(d)
	print(a, a + d)
	a -= 1
	d += 2


(n, m) = map(int, input().split())
a = 1
b = 1 + m
c = 2 + m
d = 1 + 2 * m
for i in range(m):
	if i % 2 == 0:
		print(str(a) + ' ' + str(b))
		a += 1
		b -= 1
	else:
		print(str(c) + ' ' + str(d))
		c += 1
		d -= 1


(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


(N, M) = map(int, input().split())
for i in range(M, 0, -2):
	cur_start = (M - i) // 2
	print(cur_start + 1, cur_start + i + 1)
start = M + 2
for i in range(M - 1, 0, -2):
	cur_start = start + (M - 1 - i) // 2
	print(cur_start, cur_start + i)


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


def main():
	(N, M) = list(map(int, input().split()))
	left = 1
	count = 0
	buff = 0
	for d in range(N - 1, 0, -2):
		if N - 1 & 1 and d <= -d % N:
			buff = 1
		right = left + d - buff
		print((left, right))
		left += 1
		count += 1
		if count == M:
			return

def __starting_point():
	main()
__starting_point()


from collections import deque
(n, m) = map(int, input().split())
x = deque(range(1, n + 1))
aaa = []
bbb = []
flag = True
if n % 2 == 1:
	for i in range(m):
		a = x.popleft()
		aaa.append(a)
		b = x.pop()
		bbb.append(b)
else:
	for i in range(m):
		a = x.popleft()
		aaa.append(a)
		b = x.pop()
		bbb.append(b)
		if x[-1] - x[0] <= n // 2 and flag:
			a = x.popleft()
			flag = False
for (aa, bb) in zip(aaa, bbb):
	print(aa, bb)


(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


(N, M) = map(int, input().split())
ans = []
diff = M
now = 1
while diff >= 1:
	ans.append([now, now + diff])
	diff -= 2
	now += 1
diff = M - 1
now = N
while diff >= 1:
	ans.append([now - diff, now])
	diff -= 2
	now -= 1
for a in ans:
	print(*a)


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


(n, m) = map(int, input().split())
k = m // 2
for i in range(0, k):
	a = i + 1
	b = 2 * k + 1 - i
	print(a, b)
c = 2 * k + 2
k = (m + 1) // 2
j = 1
for i in range(c, c + k):
	a = i
	b = c + 2 * k - j
	j += 1
	print(a, b)


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


(N, M) = map(int, input().split())
ans = []
t = 1
for _ in range(M // 2):
	ans.append((t, M - t + 1))
	t += 1
t = M + 1
for _ in range(-(-M // 2)):
	ans.append((t, M * 3 + 2 - t))
	t += 1
[print(a, b) for (a, b) in ans]


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

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
ans = []
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])


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
(n, m) = inm()
if n % 2 == 1:
	for i in range(1, m + 1):
		print('{} {}'.format(i, n - i))
elif n % 4 == 0:
	e = min(m + 1, n // 4)
	for i in range(1, e):
		print('{} {}'.format(i, n // 2 - i))
	if m >= n // 4:
		for i in range(m - n // 4 + 1):
			print('{} {}'.format(n - 1 - i, n // 2 + i))
else:
	e = min(m + 1, n // 4 + 1)
	for i in range(1, e):
		print('{} {}'.format(i, n // 2 - i + 1))
	if m >= n // 4 + 1:
		for i in range(m - n // 4):
			print('{} {}'.format(n - 1 - i, n // 2 + i + 1))


(n, m) = map(int, input().split())
i = 0
c = 0
while i + 1 + i < n - i - (i + 1) and c < m:
	print(i + 1, n - i)
	c += 1
	i += 1
a = n // 2 + n % 2
for i in range(m - c):
	print(a - i - 1, a + i + 1)


(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