The king of Berland organizes a ball! $n$ pair are invited to the ball, they are numbered from $1$ to $n$. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from $1$ to $k$, inclusive.

Let $b_i$ be the color of the man's costume and $g_i$ be the color of the woman's costume in the $i$-th pair. You have to choose a color for each dancer's costume (i.e. values $b_1, b_2, \dots, b_n$ and $g_1, g_2, \dots g_n$) in such a way that:  for every $i$: $b_i$ and $g_i$ are integers between $1$ and $k$, inclusive;  there are no two completely identical pairs, i.e. no two indices $i, j$ ($i \ne j$) such that $b_i = b_j$ and $g_i = g_j$ at the same time;  there is no pair such that the color of the man's costume is the same as the color of the woman's costume in this pair, i.e. $b_i \ne g_i$ for every $i$;  for each two consecutive (adjacent) pairs both man's costume colors and woman's costume colors differ, i.e. for every $i$ from $1$ to $n-1$ the conditions $b_i \ne b_{i + 1}$ and $g_i \ne g_{i + 1}$ hold. 

Let's take a look at the examples of bad and good color choosing (for $n=4$ and $k=3$, man is the first in a pair and woman is the second):

Bad color choosing:   $(1, 2)$, $(2, 3)$, $(3, 2)$, $(1, 2)$ — contradiction with the second rule (there are equal pairs);  $(2, 3)$, $(1, 1)$, $(3, 2)$, $(1, 3)$ — contradiction with the third rule (there is a pair with costumes of the same color);  $(1, 2)$, $(2, 3)$, $(1, 3)$, $(2, 1)$ — contradiction with the fourth rule (there are two consecutive pairs such that colors of costumes of men/women are the same). 

Good color choosing:   $(1, 2)$, $(2, 1)$, $(1, 3)$, $(3, 1)$;  $(1, 2)$, $(3, 1)$, $(2, 3)$, $(3, 2)$;  $(3, 1)$, $(1, 2)$, $(2, 3)$, $(3, 2)$. 

You have to find any suitable color choosing or say that no suitable choosing exists.


-----Input-----

The only line of the input contains two integers $n$ and $k$ ($2 \le n, k \le 2 \cdot 10^5$) — the number of pairs and the number of colors.


-----Output-----

If it is impossible to find any suitable colors choosing, print "NO".

Otherwise print "YES" and then the colors of the costumes of pairs in the next $n$ lines. The $i$-th line should contain two integers $b_i$ and $g_i$ — colors of costumes of man and woman in the $i$-th pair, respectively.

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.


-----Examples-----
Input
4 3

Output
YES
3 1
1 3
3 2
2 3

Input
10 4

Output
YES
2 1
1 3
4 2
3 4
4 3
3 2
2 4
4 1
1 4
3 1

Input
13 4

Output
NO

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation

Constructive algorithms


Solutions:
from collections import *
from math import *
(k, n) = map(int, input().split())
K = k
ans = []
for i in range(1, n + 1):
	for j in range(i + 1, n + 1):
		if k <= 0:
			break
		ans.append([i, j])
		ans.append([j, i])
		k -= 2
if len(ans) >= K:
	print('YES')
	for i in range(K):
		print(*ans[i])
else:
	print('NO')


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	cnt = 0
	for delta in range(k):
		for c in range(1, k + 1):
			if cnt < n:
				cnt += 1
				print(c, 1 + (c + delta) % k)
			else:
				break


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
	exit(0)
else:
	print('YES')
	cnt = 0
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			if cnt == n:
				exit(0)
			print(i, j)
			cnt += 1
			if cnt == n:
				exit(0)
			cnt += 1
			print(j, i)


(n, k) = map(int, input().split())
c = 0
t = k * (k - 1)
if n > t:
	print('NO')
else:
	print('YES')
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			print(i, j)
			c += 1
			if c == n:
				break
			print(j, i)
			c += 1
			if c == n:
				break
		if c == n:
			break


(n, k) = map(int, input().split())
if k * (k - 1) < n:
	print('NO')
	exit()
print('YES')
p = 1
while n > 0:
	for i in range(p + 1, k + 1):
		if n <= 0:
			exit()
		print(p, i)
		if n >= 2:
			print(i, p)
		n -= 2
	p += 1


(p, c) = map(int, input().split())
if c * c - c < p:
	print('NO')
else:
	print('YES')
	count = 0
	add = 0
	(p1, p2) = (-1, 0)
	for i in range(p):
		if i % c == 0:
			p2 = (p2 + 1) % c
			p1 = 0
		print(p1 + 1, p2 + 1)
		p1 = (p1 + 1) % c
		p2 = (p2 + 1) % c


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	(n, k) = mi()
	a = []
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			a.append([i, j])
			a.append([j, i])
			if len(a) >= n:
				print('YES')
				for i in range(n):
					print(*a[i])
				exit(0)
	print('NO')
solve()


import sys
input = sys.stdin.buffer.readline
(n, k) = map(int, input().split())
if k * (k - 1) >= n:
	print('YES')
	pairs = []
	for i in range(1, k + 1):
		if len(pairs) == n:
			break
		for j in range(i + 1, k + 1):
			pairs.append([i, j])
			if len(pairs) == n:
				break
			pairs.append([j, i])
			if len(pairs) == n:
				break
	for pair in pairs:
		print(*pair)
else:
	print('NO')


import sys
(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
	sys.exit()
else:
	print('YES')
count = 0
for i in range(1, k):
	for j in range(1, k + 1):
		print(j, (j + i - 1) % k + 1)
		count += 1
		if count == n:
			break
	if count == n:
		break


(n, k) = map(int, input().split())
if n > k ** 2 - k:
	print('NO')
	exit()
print('YES')
for i in range(2, k + 1):
	(b, g) = (1, i)
	for _ in range(k):
		if n == 0:
			exit()
		print(b, g)
		n -= 1
		b += 1
		g += 1
		if g > k:
			g -= k


(n, k) = list(map(int, input().split()))
if n > k * (k - 1):
	print('NO')
else:
	count = 0
	diff = 1
	i = 0
	print('YES')
	while diff < k:
		while i < k and count < n:
			print('{} {}'.format(i + 1, (i + diff) % k + 1))
			i += 1
			count += 1
		i = 0
		diff += 1


(n, k) = map(int, input().split())
m = k * (k - 1)
if n > m:
	print('NO')
else:
	print('YES')
	count = 0
	sector = 1
	while count < n:
		m = sector + 1
		while m <= k and count < n:
			print(sector, m)
			count += 1
			if count == n:
				exit(0)
			print(m, sector)
			count += 1
			m += 1
		sector += 1


from collections import deque
import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
cnt = 0
ans = []
for i in range(1, k + 1):
	for j in range(1, k + 1):
		if i != j:
			ans.append((i, j))
			cnt += 1
		if cnt == n:
			break
	if cnt == n:
		break
if len(ans) < n:
	sys.stdout.write('NO\n')
	exit()
sys.stdout.write('YES\n')
cnt = 0
i = 0
s = set()
while i < len(ans):
	x = ans[i]
	if x in s:
		i = i + 1
		continue
	if cnt == n:
		break
	sys.stdout.write(str(x[0]) + ' ' + str(x[1]) + '\n')
	cnt += 1
	if cnt == n:
		break
	sys.stdout.write(str(x[1]) + ' ' + str(x[0]) + '\n')
	s.add(x)
	s.add((x[1], x[0]))
	cnt += 1
	i = i + 1


(n, k) = list(map(int, input().split()))
arr1 = [i for i in range(1, k + 1)]
arr2 = arr1[1:] + [arr1[0]]
if k * (k - 1) >= n:
	print('YES')
	for i in range(k - 1):
		for j in range(k):
			print(str(arr1[j]) + ' ' + str(arr2[j]))
			n -= 1
			if n == 0:
				break
		if n == 0:
			break
		arr2 = arr2[1:] + [arr2[0]]
else:
	print('NO')


def swap(a):
	temp = a[0]
	a[0] = a[1]
	a[1] = temp
(n, k) = map(int, input().split())

def solve(n, k):
	if n > k * (k - 1):
		return ('No', None)
	k_ = 2
	while k_ * (k_ - 1) < n:
		k_ += 1
	k = k_
	arr = []
	for i in range(2, k + 1):
		for j in range(1, i):
			arr.append([i, j])
	ans = []
	for (a, b) in arr:
		ans.append([a, b])
	for (a, b) in arr[::-1]:
		ans.append([a, b])
	d = {(ans[0][0], ans[0][1]): 1}
	for i in range(1, k * (k - 1) // 2):
		if ans[i - 1][0] == ans[i][0] or ans[i - 1][1] == ans[i][1]:
			swap(ans[i])
		d[ans[i][0], ans[i][1]] = 1
	for (i, p) in enumerate(ans[k * (k - 1) // 2:]):
		if (p[0], p[1]) in d:
			swap(p)
	return ('Yes', ans)
(flg, arr) = solve(n, k)
print(flg)
if flg == 'Yes':
	s = ''
	for p in arr[:n]:
		s += str(p[0]) + ' ' + str(p[1]) + '\n'
	print(s)


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('No')
else:
	print('Yes')
	step = 0
	for i in range(0, n):
		step = step + (i % k == 0)
		first = i % k + 1
		second = (i % k + step) % k + 1
		print(first, second)


(n, m) = map(int, input().split())
a = m * (m - 1)
if a < n:
	print('NO')
	exit(0)
print('YES')
s = 0
cnt = 0
while True:
	s += 1
	if s == m:
		break
	q = s + 1
	while q != m + 1:
		print('{} {}'.format(s, q))
		cnt += 1
		if cnt == n:
			break
		print('{} {}'.format(q, s))
		cnt += 1
		if cnt == n:
			break
		q += 1
	if cnt == n:
		break


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, sin, cos, ceil, floor
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(1000000000)
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 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 euclidean_distance(y1, x1, y2, x2):
	return sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2)

def manhattan_distance(y1, x1, y2, x2):
	return abs(y1 - y2) + abs(x1 - x2)

def main():
	(N, K) = map(int, input().split())
	ans = []
	for i in range(1, K + 1):
		for j in range(i + 1, K + 1):
			ans.append((i, j))
			ans.append((j, i))
			if len(ans) >= N:
				break
		if len(ans) >= N:
			break
	if len(ans) < N:
		print(NO)
	else:
		print(YES)
		for i in range(N):
			print(*ans[i], sep=' ')
main()


import math
(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	(count, ok) = (0, False)
	for i in range(math.ceil(n / k)):
		for j in range(k):
			count += 1
			if (j + i + 2) % k == 0:
				print(j + 1, k)
			else:
				print(j + 1, (j + 1 + i + 1) % k)
			if count == n:
				ok = True
				break
		if ok == True:
			break


l = input().split()
n = int(l[0])
k = int(l[1])
if n > k * k - k:
	print('NO')
else:
	print('YES')
	lo = []
	count = 0
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			lo.append((i, j))
			lo.append((j, i))
			count += 2
			if count >= n:
				break
	for i in range(n):
		print(lo[i][0], lo[i][1])


import sys
(n, k) = map(int, input().split())
if k * (k - 1) < n:
	print('NO')
	sys.exit()
print('YES')
l = 1
e = n
while l <= e:
	m = (l + e) // 2
	if m * (m - 1) >= n:
		e = m - 1
		count = m
	else:
		l = m + 1
c = 0
s = set()
for i in range(1, count + 1):
	for j in range(1, count + 1):
		if i == j or (i, j) in s or (j, i) in s:
			continue
		print(i, j)
		s.add((i, j))
		c += 1
		if c == n:
			break
		print(j, i)
		c += 1
		if c == n:
			break
	if c == n:
		break


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(k, n) = invr()
if n * (n - 1) < k:
	print('NO')
	exit(0)
ans = []
sz = 0
for i in range(1, n + 1):
	for j in range(i + 1, n + 1):
		ans.append([i, j])
		ans.append([j, i])
		sz += 2
		if sz > k:
			break
print('YES')
for i in range(k):
	print(*ans[i])


import os
from io import BytesIO, StringIO

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

def array_of(f, *dim):
	return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f()

def main():
	(n, k) = input_as_list()
	if n > k * (k - 1):
		print('NO')
		return
	out = ['YES']
	c = [1, 0]
	while len(out) <= n:
		out.append(str(c[0] + 1) + ' ' + str(c[1] + 1))
		if c[0] > 0 and c[1] < k - 1:
			c[0] -= 1
			c[1] += 1
			if c[0] == c[1]:
				c[0] -= 1
				c[1] += 1
		else:
			s = sum(c) + 1
			if s >= k - 1:
				c = [k - 1, s - k + 1]
			else:
				c = [s, 0]
	print('\n'.join(out))
main()


def main():
	(n, k) = map(int, input().split())
	if n > k * (k - 1):
		print('NO')
		return
	print('YES')
	printed = 0
	i = 0
	while printed < n:
		first = i % k
		second = (i + i // k + 1) % k
		print(first + 1, second + 1)
		printed += 1
		i += 1
main()


(n, k) = map(int, input().split())
total = k * (k - 1)
if n > total:
	print('NO')
	exit()
out = []
current = 1
change = 2
for i in range(n):
	if i % 2 == 0:
		out.append((current, change))
	else:
		out.append((change, current))
		change += 1
	if change > k:
		current += 1
		change = current + 1
print('YES')
print('\n'.join((str(x) + ' ' + str(y) for (x, y) in out)))


import sys
(n, k) = map(int, input().split())
c = 0
if k * (k - 1) < n:
	print('NO')
else:
	print('YES')
	for i in range(k - 1):
		for j in range(k):
			c += 1
			if c > n:
				return
			print(1 + j, 1 + (j + i + 1) % k)


(n, k) = list(map(int, input().split()))
if n > k * (k - 1):
	print('NO')
else:
	c = 0
	d = []
	print('YES')
	while c < n:
		for i in range(1, k + 1):
			for j in range(i + 1, k + 1):
				d.append([i, j])
				c += 1
				if c < n:
					d.append([j, i])
					c += 1
				if c == n:
					break
			if c == n:
				break
	for i in range(n):
		print(*d[i])


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
ans = 'YES' if n <= k * (k - 1) else 'NO'
print(ans)
if ans == 'YES':
	cnt = 0
	(b, d) = (0, 1)
	while cnt < n:
		cnt += 1
		if b >= k:
			b = 0
			d += 1
		g = (b + d) % k
		print(b + 1, g + 1)
		b += 1


(n, k) = list(map(int, input().split()))
if n > k * (k - 1):
	print('NO')
	exit()
ans = [[0, 0] for i in range(n)]
cnt = 0
for i in range(1, k + 1):
	for j in range(i + 1, k + 1):
		a = i
		b = j
		if cnt != 0:
			if ans[cnt - 1][0] == a or ans[cnt - 1][1] == b:
				(a, b) = (b, a)
		ans[cnt] = [a, b]
		cnt += 1
		if cnt == n:
			break
		ans[cnt] = [b, a]
		cnt += 1
		if cnt == n:
			break
	if cnt == n:
		break
print('YES')
for i in range(n):
	print(*ans[i])


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	for q in range(1, k + 1):
		for q1 in range(q + 1, k + 1):
			if n < 2:
				if n == 1:
					print(q, q1)
				break
			else:
				print(q, q1)
				print(q1, q)
				n -= 2
		else:
			continue
		break


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	arr = [0] * (k + 1)
	for i in range(1, k):
		arr[i] = i + 1
	arr[-1] = 1
	ansarr = []
	count = 0
	index = 1
	while count < n:
		ansarr.append(index)
		ansarr.append(arr[index])
		arr[index] += 1
		if arr[index] > k:
			arr[index] = 1
		index += 1
		count += 1
		if index > k:
			index = 1
	print(*ansarr)


(n, k) = map(int, input().rstrip().split(' '))
if k * k - k < n:
	print('NO')
	exit()
print('YES')
prev1 = 0
prev2 = 0
c = 0
for i in range(1, k + 1):
	for j in range(i + 1, k + 1):
		curr1 = i
		curr2 = j
		if prev1 == curr1 or prev2 == curr2:
			(curr1, curr2) = (curr2, curr1)
		print(curr1, curr2)
		c += 1
		if c == n:
			exit()
		(curr1, curr2) = (curr2, curr1)
		print(curr1, curr2)
		c += 1
		if c == n:
			exit()


(n, k) = map(int, input().split())
i = 1
if k * (k - 1) < n:
	print('NO')
else:
	print('YES')
	l = 0
	j = 0
	while l < n // 2:
		l += 1
		j += 1
		if i == j:
			j += 1
		if j > k:
			i += 1
			j = i + 1
		print(i, j)
		print(j, i)
	j += 1
	if i == j:
		j += 1
	if j > k:
		i += 1
		j = i + 1
	if n % 2 == 1:
		print(i, j)


class Solution(object):

	def getPossibleSolution(self, n, k):
		if n > k * (k - 1):
			return print('NO')
		pairs = []
		for diff in range(1, k):
			for b in range(1, k + 1):
				g = b + diff if b + diff <= k else (b + diff) % k
				pairs.append([b, g])
				if len(pairs) == n:
					break
			else:
				continue
			break
		print('YES')
		for pair in pairs:
			print(pair[0], pair[1])

def read_input():
	return [int(x) for x in input().split()]
line = read_input()
n = line[0]
k = line[1]
sol = Solution()
sol.getPossibleSolution(n, k)


def main():
	tc = 1
	while tc:
		(n, k) = [int(x) for x in input().split()]
		if n <= k * (k - 1):
			print('YES')
			x = 1
			y = 2
			while n:
				print(x, ' ', y)
				n -= 1
				if n == 0:
					break
				n -= 1
				print(y, ' ', x)
				if y == k:
					x += 1
					y = x + 1
				else:
					y += 1
		else:
			print('NO')
		tc -= 1
main()


(m, k) = map(int, input().strip().split())
maxp = k * (k - 1)
mp = {}
if m > maxp:
	print('NO')
else:
	l = 1
	h = 2
	print('YES')
	i = 0
	while i < m:
		if str(l) + ' ' + str(h) not in mp:
			print(l, h)
			i += 1
			if i >= m:
				break
			print(h, l)
			i += 1
			mp[str(l) + ' ' + str(h)] = 1
			mp[str(h) + ' ' + str(l)] = 1
		h += 1
		if h == l:
			h += 1
		if h > k:
			h = 1
			l += 1


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading

def main():
	(n, k) = map(int, input().split())
	if n > k * (k - 1):
		print('NO')
		exit()
	print('YES')
	ans = 0
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			print(i, j)
			ans += 1
			if ans == n:
				exit()
			print(j, i)
			ans += 1
			if ans == n:
				exit()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	ans = [0 for i in range(n)]
	for i in range(len(ans)):
		ans[i] = (i + 1) % k
		if ans[i] == 0:
			ans[i] = k
	count = 1
	temp = [0 for i in range(len(ans))]
	for i in range(len(ans)):
		if i % k == 0:
			temp[i] = count + 1
			count += 1
		else:
			temp[i] = temp[i - 1] + 1
			if temp[i] > k:
				temp[i] %= k
	print('YES')
	for i in range(n):
		print(ans[i], temp[i])


import sys
import io
(n, k) = [int(x) for x in input().split()]
if k * (k - 1) < n:
	print('NO')
	sys.exit()
out = io.BytesIO()
out.write(b'YES\n')
a = 0
diff = 1
counter = 0
while counter < n:
	if a == k:
		diff += 1
		a = 0
	if diff == k:
		break
	out.write(str(a + 1).encode())
	out.write(b' ')
	out.write(str((a + diff) % k + 1).encode())
	out.write(b'\n')
	a += 1
	counter += 1
sys.stdout.buffer.write(out.getvalue())


(n, k) = map(int, input().split())
if n > (k - 1) * k:
	print('NO')
else:
	i = 1
	j = 2
	s = ''
	while True:
		s += '{} {}\n'.format(i, j)
		n -= 1
		if n == 0:
			break
		s += '{} {}\n'.format(j, i)
		n -= 1
		if n == 0:
			break
		j += 1
		if j > k:
			i += 1
			j = i + 1
	print('YES')
	print(s)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	a = list()
	b = list()
	for i in range(1, n + 1):
		t = i % k
		if t == 0:
			t = k
		a.append(t)
	num = [i for i in range(1, k + 1)]
	num = num + num
	j = 1
	for i in range(0, n, k):
		for t in range(j, j + k):
			b.append(num[t])
		j += 1
	for i in range(n):
		print(a[i], b[i])


from itertools import combinations

def f(n, k):
	base = k * (k - 1)
	if base < n:
		return 'NO'
	lst = [i for i in range(1, k + 1)]
	l = combinations(lst, 2)
	cnt = 0
	print('YES')
	for i in l:
		if cnt >= n:
			break
		cnt += 1
		print(*i)
		if cnt < n:
			print(*i[::-1])
			cnt += 1
		else:
			break
	return ''
(a, b) = map(int, input().strip().split())
print(f(a, b))


(n, k) = [int(x) for x in input().split()]
if k * (k - 1) < n:
	print('no')
else:
	print('yes')
	(a, b) = (1, 2)
	for i in range(n):
		print(a, b)
		if a < b:
			(a, b) = (b, a)
		else:
			(a, b) = (b, a)
			if b < k:
				b += 1
				if b == a:
					b += 1
			else:
				a += 1
				b = a + 1


(n, k) = [int(x) for x in input().split()]
if k * (k - 1) < n:
	print('No')
else:
	print('Yes')
	pair = 0
	while pair < n:
		for delta in range(1, k):
			for i in range(1, k + 1):
				j = i + delta
				while j > k:
					j = j - k
				if pair < n:
					print('%d %d' % (i, j))
					pair = pair + 1
				else:
					break
			if pair >= n:
				break


(n, k) = map(int, input().split())
if k * (k - 1) < n:
	print('NO')
	exit()
ans = []
for i in range(n):
	ans.append([0, 0])
f = 1
s = 2
for i in range(0, n, 2):
	ans[i][0] = f
	ans[i][1] = s
	s += 1
	if s > k:
		f += 1
		s = f + 1
f = 1
s = 2
for i in range(1, n, 2):
	ans[i][0] = s
	ans[i][1] = f
	s += 1
	if s > k:
		f += 1
		s = f + 1
print('YES')
for i in range(len(ans)):
	print(ans[i][0], ans[i][1])


l = input().split()
n = int(l[0])
k = int(l[1])
if k * (k - 1) < n:
	print('NO')
else:
	print('YES')
	for i in range(1, k + 1):
		if n == 0:
			break
		for j in range(i + 1, k + 1):
			if n == 0:
				break
			print(i, j)
			n -= 1
			if n == 0:
				break
			print(j, i)
			n -= 1


(n, k) = input().split()
n = int(n)
k = int(k)
count = 0
if k >= n:
	print('YES')
	for i in range(1, n + 1):
		if i < n:
			print(i, i + 1)
		else:
			print(i, 1)
else:
	tot = k * (k - 1)
	if tot >= n:
		print('YES')
		for i in range(1, n + 1):
			u = i + 1
			while u <= k:
				if u == k:
					if count <= n - 2:
						print(i % k, u)
						print(u, i % k)
						count += 2
					elif n - count == 1:
						print(i % k, u)
						count += 1
				elif count <= n - 2:
					print(i % k, u % k)
					print(u % k, i % k)
					count += 2
				elif n - count == 1:
					print(i % k, u % k)
					count += 1
				u += 1
	else:
		print('NO')


(n, k) = map(int, input().split())
if n > k * k - k:
	print('NO')
else:
	print('YES')
	t = set()
	cnt = 0
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			if (i, j) not in t:
				if cnt == n:
					break
				print(i, j)
				cnt += 1
				if cnt == n:
					break
				print(j, i)
				cnt += 1
				t.add((i, j))
				t.add((j, i))


import math
(n, k) = list(map(int, input().strip().split()))
if k <= 2:
	if n == 2:
		print('YES')
		print('1 2')
		print('2 1')
	else:
		print('NO')
	exit()
if k < 700:
	pairs = 2 * math.factorial(k) / (2 * math.factorial(k - 2))
	if pairs < n:
		print('NO')
		exit()
print('YES')
shift = 1
written = 0
for _ in range(k - 1):
	for v in range(k):
		print('{} {}'.format(str(v + 1), str((v + shift) % k + 1)))
		written += 1
		if written == n:
			break
	if written == n:
		break
	shift = (shift + 1) % k


from sys import stdin
(n, k) = map(int, stdin.readline().strip().split())
mx = k * (k - 1)
if mx < n:
	print('NO')
	exit(0)
x = 0
print('YES')
for i in range(1, k):
	for j in range(i + 1, k + 1):
		print(i, j)
		x += 1
		if x == n:
			exit(0)
		print(j, i)
		x += 1
		if x == n:
			exit(0)


import sys
if not sys.warnoptions:
	import warnings
	warnings.simplefilter('ignore')

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
(n, k) = li()
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	index = 0
	for i in range(1, k):
		for j in range(i + 1, k + 1):
			if index < n:
				print(i, j)
				index += 1
			else:
				break
			if index < n:
				print(j, i)
				index += 1
			else:
				break
		if index >= n:
			break


import sys
(m, n) = tuple(map(int, input().split()))
if m > n * (n - 1):
	print('NO')
else:
	print('YES')
	index = 0
	for i in range(2, n + 1):
		for j in range(1, i + 1):
			if i + 1 != 2 * j:
				print(1 + i - j, j)
				index += 1
				if index == m:
					sys.exit()
	for k in range(1, n - 1):
		for j in range(n - k):
			if n - k - 1 != 2 * j:
				print(n - j, k + j + 1)
				index += 1
				if index == m:
					sys.exit()


(n, k) = map(int, input().split())
ist = False
u = []
ch = 0
for i in range(1, k + 1):
	for j in range(i + 1, k + 1):
		u.append((i, j))
		ch += 1
		if ch == n:
			ist = True
			break
		u.append((j, i))
		ch += 1
		if ch == n:
			ist = True
			break
	if ist:
		break
if ch == n:
	print('yes')
	for i in u:
		print(i[0], i[1])
else:
	print('no')


def main():
	(n, k) = map(int, input().split())
	if (k - 1) * k < n:
		print('NO')
	else:
		print('YES')
		z = 0
		for i in range(2, k + 1):
			for j in range(1, i):
				print(j, i)
				z += 1
				if z == n:
					return
				print(i, j)
				z += 1
				if z == n:
					return
main()


import sys
from collections import deque, defaultdict, namedtuple
from math import sqrt, factorial, gcd, ceil, atan, pi

def input():
	return sys.stdin.readline()[:-1]
import string
import operator
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1000000000.0) + 7
INF = float('inf')

def solve():
	(n, k) = [int(x) for x in input().split()]
	if k * (k - 1) < n:
		print('NO')
		return
	print('YES')
	ans = []
	cnt = 0
	for i in range(k):
		for j in range(i + 1, k):
			ans.append((i, j))
			ans.append((j, i))
			cnt += 2
			if cnt >= n:
				break
		if cnt >= n:
			break
	if cnt > n:
		ans.pop()
	if ans[0][0] == ans[-1][0]:
		ans[-1] = (k - 1, k - 2)
	for (a, b) in ans:
		print(a + 1, b + 1)
t = 1
for case in range(1, t + 1):
	ans = solve()


(n, m) = map(int, input().split())
if m * (m - 1) < n:
	print('NO')
else:
	t = 1
	p = 2
	sol = []
	for i in range(n):
		sol.append((t, p))
		sol.append((p, t))
		p += 1
		if p % (m + 1) == 0:
			p = t + 2
			t += 1
		if p > m:
			break
	print('YES')
	for i in range(n):
		print(sol[i][0], sol[i][1])


def is_good_color(n, k):
	if n > k * (k - 1):
		print('NO')
		return
	print('YES')
	p = 0
	for i in range(k, 0, -1):
		z = i - 1
		while z > 0:
			if i != z:
				print(i, z)
				p += 1
				if p == n:
					break
				else:
					print(z, i)
					p += 1
			if p == n:
				break
			z -= 1
		if p == n:
			break
(n, k) = map(int, input().split())
is_good_color(n, k)


import sys
(n, k) = map(int, input().split())
if k * (k - 1) < n:
	print('NO')
else:
	print('YES')
	c = 0
	d = 1
	for i in range(n):
		if c == k:
			d += 1
			c = 0
		if d == k:
			break
		print(c + 1, (c + d) % k + 1)
		c += 1


(n, k) = map(int, input().split())
if n > k * (k - 1):
	print('NO')
else:
	print('YES')
	total = 0
	for i in range(1, k + 1):
		for j in range(i + 1, k + 1):
			if total == n:
				break
			print(f'{i} {j}')
			total += 1
			if total == n:
				break
			print(f'{j} {i}')
			total += 1


from sys import exit, setrecursionlimit
setrecursionlimit(10 ** 6)
inn = lambda : input().strip()
mapp = lambda : map(int, inn().split(' '))
(N, K) = mapp()
if K * (K - 1) < N:
	print('NO')
	exit()
left = N
print('YES')
for a in range(1, K + 1):
	for b in range(a + 1, K + 1):
		if left >= 2:
			print(f'{a} {b}')
			print(f'{b} {a}')
			left -= 2
		elif left == 1:
			print(f'{a} {b}')
			left -= 1
		elif left == 0:
			exit()