There are $n$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.

The $i$-th student has integer programming skill $a_i$. All programming skills are distinct and between $1$ and $n$, inclusive.

Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and $k$ closest students to the left of him and $k$ closest students to the right of him (if there are less than $k$ students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).

Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.


-----Input-----

The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the number of students and the value determining the range of chosen students during each move, respectively.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the programming skill of the $i$-th student. It is guaranteed that all programming skills are distinct.


-----Output-----

Print a string of $n$ characters; $i$-th character should be 1 if $i$-th student joins the first team, or 2 otherwise.


-----Examples-----
Input
5 2
2 4 5 3 1

Output
11111

Input
5 1
2 1 3 5 4

Output
22111

Input
7 1
7 2 1 3 5 4 6

Output
1121122

Input
5 1
2 4 5 3 1

Output
21112



-----Note-----

In the first example the first coach chooses the student on a position $3$, and the row becomes empty (all students join the first team).

In the second example the first coach chooses the student on position $4$, and the row becomes $[2, 1]$ (students with programming skills $[3, 4, 5]$ join the first team). Then the second coach chooses the student on position $1$, and the row becomes empty (and students with programming skills $[1, 2]$ join the second team).

In the third example the first coach chooses the student on position $1$, and the row becomes $[1, 3, 5, 4, 6]$ (students with programming skills $[2, 7]$ join the first team). Then the second coach chooses the student on position $5$, and the row becomes $[1, 3, 5]$ (students with programming skills $[4, 6]$ join the second team). Then the first coach chooses the student on position $3$, and the row becomes $[1]$ (students with programming skills $[3, 5]$ join the first team). And then the second coach chooses the remaining student (and the student with programming skill $1$ joins the second team).

In the fourth example the first coach chooses the student on position $3$, and the row becomes $[2, 1]$ (students with programming skills $[3, 4, 5]$ join the first team). Then the second coach chooses the student on position $1$, and the row becomes empty (and students with programming skills $[1, 2]$ join the second team).

Difficulty: MEDIUM_HARD
Tags: Sorting

Data structures

Implementation
Skill types: Sorting

Data structures

Starter code:

Solutions:
(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
dict1 = {i: a for (a, i) in enumerate(list1)}
right = {i: i + 1 for i in range(n)}
left = {i: i - 1 for i in range(n)}
ans = [0] * n
t = 1
for i in range(n, 0, -1):
	idx = dict1.get(i)
	if ans[idx] == 0:
		ans[idx] = t
		(r, l) = (right[idx], left[idx])
		for p in range(k):
			if l == -1:
				break
			ans[l] = t
			l = left[l]
		for p in range(k):
			if r >= n:
				break
			ans[r] = t
			r = right[r]
		if l >= 0:
			right[l] = r
		if r < n:
			left[r] = l
		t = 3 - t
print(''.join(list(map(str, ans))))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
pre = {}
nex = {}
d = {}
for i in range(n):
	d[a[i]] = i
for i in range(n):
	pre[i] = i - 1
	nex[i] = i + 1
t = 1
ans = [-1] * n
for i in range(n, 0, -1):
	j = d[i]
	if ans[j] != -1:
		continue
	ans[j] = t
	(l, r) = (pre[j], nex[j])
	for p in range(k):
		if l == -1:
			break
		ans[l] = t
		l = pre[l]
	for p in range(k):
		if r == n:
			break
		ans[r] = t
		r = nex[r]
	if l >= 0:
		nex[l] = r
	if r < n:
		pre[r] = l
	t = 3 - t
print(''.join(map(str, ans)))


import heapq
import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = [0] * n
h = []
for i in range(n):
	heapq.heappush(h, (-a[i], i))
(l, r) = ([i - 1 for i in range(n)], [i + 1 for i in range(n)])
(l[0], r[-1]) = (-1, -1)
c = 1
while h:
	(ai, i) = heapq.heappop(h)
	if ans[i]:
		continue
	ans[i] = c
	j = i
	for _ in range(k):
		if l[j] == -1:
			break
		if ans[l[j]]:
			break
		j = l[j]
		ans[j] = c
	l0 = l[j]
	j = i
	for _ in range(k):
		if r[j] == -1:
			break
		if ans[r[j]]:
			break
		j = r[j]
		ans[j] = c
	r0 = r[j]
	if not r0 == -1:
		l[r0] = l0
	if not l0 == -1:
		r[l0] = r0
	c ^= 3
print(''.join(map(str, ans)))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
indices = range(n)
indices = sorted(indices, key=lambda x: -arr[x])
team_num = [0] * n
list_nxt = list(range(1, n + 1))
list_nxt[-1] = -1
list_prev = list(range(-1, n - 1))
cur_team = 1
for ind in indices:
	if team_num[ind] != 0:
		continue
	(left_neigh, right_neigh) = (ind, ind)
	for i in range(k + 1):
		(team_num[right_neigh], right_neigh) = (cur_team, list_nxt[right_neigh])
		if right_neigh == -1:
			break
	for i in range(k + 1):
		(team_num[left_neigh], left_neigh) = (cur_team, list_prev[left_neigh])
		if left_neigh == -1:
			break
	if left_neigh != -1:
		list_nxt[left_neigh] = right_neigh
	if right_neigh != -1:
		list_prev[right_neigh] = left_neigh
	cur_team = 3 - cur_team
print(''.join(list(map(str, team_num))))


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		k = self.next_int()
		x = [self.next_int() for _ in range(0, n)]
		bf = [x - 1 for x in range(0, n)]
		nx = [x + 1 for x in range(0, n)]
		t = [0 for _ in range(0, n)]
		od = [0 for _ in range(0, n)]
		for i in range(0, n):
			od[x[i] - 1] = i
		tt = 1
		for i in range(n - 1, -1, -1):
			if t[od[i]] == 0:
				o = od[i]
				t[o] = tt
				for _ in range(0, k):
					o = bf[o]
					if o == -1:
						break
					t[o] = tt
				oo = od[i]
				for _ in range(0, k):
					oo = nx[oo]
					if oo == n:
						break
					t[oo] = tt
				if o != -1 and bf[o] != -1:
					nx[bf[o]] = oo if oo == n else nx[oo]
				if oo != n and nx[oo] != n:
					bf[nx[oo]] = o if o == -1 else bf[o]
				tt = 3 - tt
		print(''.join(map(lambda xx: str(xx), t)))
Main().solve()


import sys
import copy

def makepair(a, b):
	return (a, b)
line = sys.stdin.readline().strip('\n')
(n, k) = list(map(int, line.split()))
line = sys.stdin.readline().strip('\n')
nb = list(map(int, line.split()))
num = list(map(makepair, nb, [i for i in range(n)]))
num.sort(key=lambda x: x[0], reverse=True)
prev = [i for i in range(-1, n - 1)]
next = [i for i in range(1, n + 1)]

def delnum(curt, x):
	if curt < n and curt >= 0:
		nb[curt] = x
		if next[curt] < n:
			prev[next[curt]] = prev[curt]
		if prev[curt] >= 0:
			next[prev[curt]] = next[curt]
i = 1
for p in num:
	if nb[p[1]] > 0:
		i = 1 - i
		nb[p[1]] = i - 2
		curt = next[p[1]]
		for x in range(k):
			delnum(curt, i - 2)
			if curt < n:
				curt = next[curt]
		curt = prev[p[1]]
		for x in range(k):
			delnum(curt, i - 2)
			if curt >= 0:
				curt = prev[curt]
		delnum(p[1], i - 2)
for i in range(len(nb)):
	print(nb[i] + 3, end='')


(n, k) = [int(x) for x in input().split()]
l1 = [int(x) - 1 for x in input().split()]
l2 = [0 for x in range(0, n)]
l3 = [0 for x in range(0, n)]
l4 = [[] for x in range(0, n)]
for i in range(0, n):
	l4[i].append(i - 1)
	l4[i].append(i + 1)
for i in range(0, n):
	l3[l1[i]] = i
i = n - 1
x = 1
while i >= 0:
	t = l3[i]
	if l2[t] != 0:
		i -= 1
		continue
	else:
		l2[t] = x
		j = 1
		m = l4[t][1]
		while j <= k and m < n:
			if l2[m] != 0:
				if l4[m][1] > n - 1:
					break
				m = l4[m][1]
				continue
			l2[m] = x
			if l4[m][1] > n - 1:
				break
			m = l4[m][1]
			j += 1
		a = m
		j = 1
		m = l4[t][0]
		while j <= k and m > -1:
			if l2[m] != 0:
				if l4[m][0] < 0:
					break
				m = l4[m][0]
				continue
			l2[m] = x
			if l4[m][0] < 0:
				break
			m = l4[m][0]
			j += 1
		b = m
		if a < n:
			l4[a][0] = b
		if b > -1:
			l4[b][1] = a
	if x == 1:
		x = 2
	else:
		x = 1
	i -= 1
for element in l2:
	print(element, end='')


(n, k) = map(int, input().split())
numbers = list(map(int, input().split()))
teams = [0 for i in range(len(numbers))]
import sys
sys.setrecursionlimit(5000)

class Value:

	def __init__(self, skill, index, previousVal=None, nextVal=None):
		self.skill = skill
		self.index = index
		self.previousVal = previousVal
		self.nextVal = nextVal

	def __gt__(self, other):
		return self.skill > other.skill

	def __repr__(self):
		return str(self)

	def __str__(self):
		return '(skill: ' + str(self.skill) + ',index: ' + str(self.index) + ')'

def addPrevious(value, team, k):
	myValues.pop(value.index)
	teams[value.index] = team
	if value.nextVal:
		value.nextVal.previousVal = value.previousVal
	if value.previousVal:
		value.previousVal.nextVal = value.nextVal
	if k > 0 and value.previousVal:
		addPrevious(value.previousVal, team, k - 1)

def addNext(value, team, k):
	myValues.pop(value.index)
	teams[value.index] = team
	if value.nextVal:
		value.nextVal.previousVal = value.previousVal
	if value.previousVal:
		value.previousVal.nextVal = value.nextVal
	if k > 0 and value.nextVal:
		addNext(value.nextVal, team, k - 1)

def addToTeam(value, team, k):
	myValues.pop(value.index)
	teams[value.index] = team
	if value.nextVal:
		value.nextVal.previousVal = value.previousVal
	if value.previousVal:
		value.previousVal.nextVal = value.nextVal
	if k > 0:
		if value.nextVal:
			addNext(value.nextVal, team, k - 1)
		if value.previousVal:
			addPrevious(value.previousVal, team, k - 1)

def getValue(someObject):
	return someObject[1].skill
if k < 2000:
	myValues = {}
	currValue = Value(numbers[0], 0)
	myValues[0] = currValue
	for i in range(1, len(numbers)):
		newValue = Value(numbers[i], i, currValue)
		myValues[i] = newValue
		currValue = newValue
	while True:
		if currValue.previousVal:
			currValue.previousVal.nextVal = currValue
			currValue = currValue.previousVal
		else:
			break
	currTeam = 1
	sortedList = sorted(myValues.items(), key=getValue, reverse=True)
	for i in sortedList:
		if i[0] in myValues:
			currTeam = (currTeam + 1) % 2
			addToTeam(i[1], currTeam + 1, k)
else:

	def value(doubleValues):
		return doubleValues[1]

	def addToTeam(values, team):
		for i in values:
			teams[i[0]] = team
	myValues = []
	currTeam = 1
	for i in range(len(numbers)):
		myValues.append((i, numbers[i]))
	while len(myValues) > 0:
		currTeam = (currTeam + 1) % 2
		maxIndex = myValues.index(max(myValues, key=value))
		if maxIndex < k and maxIndex + k >= len(myValues):
			addToTeam(myValues, currTeam + 1)
			myValues = []
		elif maxIndex < k:
			addToTeam(myValues[:maxIndex + k + 1], currTeam + 1)
			myValues = myValues[maxIndex + k + 1:]
		elif maxIndex + k >= len(myValues) - 1:
			addToTeam(myValues[maxIndex - k:], currTeam + 1)
			myValues = myValues[:maxIndex - k]
		else:
			addToTeam(myValues[maxIndex - k:maxIndex + k + 1], currTeam + 1)
			myValues = myValues[:maxIndex - k] + myValues[maxIndex + k + 1:]
teamString = ''
for i in teams:
	teamString += str(i)
print(teamString)


(n, k) = tuple([int(i) for i in input().split()])
data = [int(i) for i in input().split()]
nextup = {}
nextdown = {}
nextup[data[n - 1]] = -1
nextdown[data[0]] = -1
for i in range(n - 1):
	nextup[data[i]] = data[i + 1]
	nextdown[data[i + 1]] = data[i]
l = list(range(1, n + 1))
switch = {'1': '2', '2': '1'}
char = '2'
for j in range(n - 1, -1, -1):
	i = l[j]
	if type(i) == int:
		char = switch[char]
		b = i
		c = i
		l[i - 1] = char
		found = 0
		while found < k:
			t = nextdown[b]
			if t == -1:
				break
			found += 1
			l[t - 1] = char
			b = t
		found = 0
		while found < k:
			t = nextup[c]
			if t == -1:
				break
			found += 1
			l[t - 1] = char
			c = t
		nextdown[nextup[c]] = nextdown[b]
		nextup[nextdown[b]] = nextup[c]
for i in data:
	print(l[i - 1], end='')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def mysolution(n, k, a):
	pre = {}
	nex = {}
	d = {}
	for i in range(n):
		pre[i] = i - 1
		nex[i] = i + 1
		d[a[i]] = i
	a.sort(reverse=True)
	res = [0] * n
	turn = 1
	for x in a:
		index = d[x]
		if res[index]:
			continue
		res[index] = turn
		left = right = index
		for i in range(k):
			left = pre[left]
			if left <= -1:
				break
			res[left] = turn
		for i in range(k):
			right = nex[right]
			if right >= n:
				break
			res[right] = turn
		if left >= 0:
			left = pre[left]
		if right < n:
			right = nex[right]
		nex[left] = right
		pre[right] = left
		turn = 3 - turn
	return ''.join(map(str, res))
print(mysolution(n, k, a))


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
d = {arr[i]: i for i in range(n)}
cur_max = n
ans = [0 for i in range(n)]
turn = 1
(pre, nxt) = ([i - 1 for i in range(n)], [i + 1 for i in range(n)])
for i in range(n, 0, -1):
	if i not in d:
		continue
	left = d[i]
	right = d[i]
	ans[d[i]] = turn
	cur = k
	while left >= 0 and cur > 0:
		if pre[left] < 0:
			break
		ans[pre[left]] = turn
		del d[arr[pre[left]]]
		left = pre[left]
		cur -= 1
	cur = k
	while right < n and cur > 0:
		if nxt[right] >= n:
			break
		ans[nxt[right]] = turn
		del d[arr[nxt[right]]]
		right = nxt[right]
		cur -= 1
	if pre[left] >= 0:
		nxt[pre[left]] = nxt[right]
	if nxt[right] < n:
		pre[nxt[right]] = pre[left]
	turn = 1 if turn == 2 else 2
print(''.join((str(i) for i in ans)))


def main(argc, argv) -> {}:
	sync_with_stdio(false)
	cin.tie(0)
	cout.tie(0)
	n = k = 0
	n <<= cin
	k <<= cin
	A = vector << int >> n
	A <<= cin
	S = vector << pii >> n
	i = 0
	while i < len(S) or {}:
		S[i] = [A[i], i]
		i += 1
		{}
	S.sort()
	R = vector << int >> n
	nxt = vector << int >> n
	prev = vector << int >> n
	i = 0
	while i < len(S) or {}:
		nxt[i] = i + 1
		prev[i] = i - 1
		i += 1
		{}
	prev[0] = 0
	nxt[n - 1] = n - 1
	team = 1
	i = len(S) - 1
	while i >= 0 or {}:
		(v, j) = S[i]
		if R[j] or {}:
			i -= 1
			continue
			{}
		R[j] = team
		z = 0
		cur = j
		while z < k or {}:
			cur = prev[cur]
			if not R[cur]:
				R[cur] = team
			z += 1
			{}
		lft = prev[cur]
		z = 0
		cur = j
		while z < k or {}:
			cur = nxt[cur]
			if not R[cur]:
				R[cur] = team
			z += 1
			{}
		rgt = nxt[cur]
		prev[rgt] = lft
		nxt[lft] = rgt
		team = 2 - team + 1
		i -= 1
		{}
	i = 0
	while i < len(R) or {}:
		cout << R[i]
		i += 1
		{}
	cout << endl
	{}
import base64
exec(base64.decodebytes('cHkyID0gcm91bmQoMC41KQoKaWYgcHkyOgogICAgZnJvbSBmdXR1cmVfYnVpbHRpbnMgaW1wb3J0IGFzY2lpLCBmaWx0ZXIsIGhleCwgbWFwLCBvY3QsIHppcAogICAgcmFuZ2UgPSB4cmFuZ2UKCmRlZiBzeW5jX3dpdGhfc3RkaW8oYik6CiAgICBpZiBiOiByZXR1cm4KICAgIGltcG9ydCBvcywgc3lzCiAgICBmcm9tIGlvIGltcG9ydCBCeXRlc0lPLCBJT0Jhc2UKICAgIAogICAgIyBGYXN0SU8gZm9yIFB5UHkyIGFuZCBQeVB5MyAod29ya3Mgd2l0aCBpbnRlcmFjdGl2ZSkgYnkgUGFqZW5lZ29kCiAgICBjbGFzcyBGYXN0SShvYmplY3QpOgogICAgICAgIGRlZiBfX2luaXRfXyhzZWxmLCBmZD0wLCBidWZmZXJzaXplPTIqKjE0KToKICAgICAgICAgICAgc2VsZi5zdHJlYW0gPSBzdHJlYW0gPSBCeXRlc0lPKCk7IHNlbGYuYnVmZW5kbCA9IDAKICAgICAgICAgICAgZGVmIHJlYWQyYnVmZmVyKCk6CiAgICAgICAgICAgICAgICBzID0gb3MucmVhZChmZCwgYnVmZmVyc2l6ZSArIG9zLmZzdGF0KGZkKS5zdF9zaXplKTsgcG9zID0gc3RyZWFtLnRlbGwoKQogICAgICAgICAgICAgICAgc3RyZWFtLnNlZWsoMCwyKTsgc3RyZWFtLndyaXRlKHMpOyBzdHJlYW0uc2Vlayhwb3MpOyByZXR1cm4gcwogICAgICAgICAgICBzZWxmLnJlYWQyYnVmZmVyID0gcmVhZDJidWZmZXIKICAgICAgICAjIFJlYWQgZW50aXJlIGlucHV0CiAgICAgICAgZGVmIHJlYWQoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYucmVhZDJidWZmZXIoKTogcGFzcwogICAgICAgICAgICByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZCgpIGlmIHNlbGYuc3RyZWFtLnRlbGwoKSBlbHNlIHNlbGYuc3RyZWFtLmdldHZhbHVlKCkKICAgICAgICBkZWYgcmVhZGxpbmUoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYuYnVmZW5kbCA9PSAwOiBzID0gc2VsZi5yZWFkMmJ1ZmZlcigpOyBzZWxmLmJ1ZmVuZGwgKz0gcy5jb3VudChiIlxuIikgKyAobm90IHMpCiAgICAgICAgICAgIHNlbGYuYnVmZW5kbCAtPSAxOyByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZGxpbmUoKQogICAgICAgIGRlZiBpbnB1dChzZWxmKTogcmV0dXJuIHNlbGYucmVhZGxpbmUoKS5yc3RyaXAoYidcclxuJykKICAgICAgICAKICAgICAgICAjIFJlYWQgYWxsIHJlbWFpbmluZyBpbnRlZ2VycywgdHlwZSBpcyBnaXZlbiBieSBvcHRpb25hbCBhcmd1bWVudAogICAgICAgIGRlZiByZWFkbnVtYmVycyhzZWxmLCB6ZXJvPTApOgogICAgICAgICAgICBjb252ID0gb3JkIGlmIHB5MiBlbHNlIGxhbWJkYSB4OngKICAgICAgICAgICAgQSA9IFtdOyBudW1iID0gemVybzsgc2lnbiA9IDE7IGMgPSBiIi0iWzBdCiAgICAgICAgICAgIGZvciBjIGluIHNlbGYucmVhZCgpOgogICAgICAgICAgICAgICAgaWYgYyA+PSBiIjAiWzBdOiBudW1iID0gMTAgKiBudW1iICsgY29udihjKSAtIDQ4CiAgICAgICAgICAgICAgICBlbGlmIGMgPT0gYiItIlswXTogc2lnbiA9IC0xCiAgICAgICAgICAgICAgICBlbGlmIGMgIT0gYiJcciJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYik7IG51bWIgPSB6ZXJvOyBzaWduID0gMQogICAgICAgICAgICBpZiBjID49IGIiMCJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYikKICAgICAgICAgICAgcmV0dXJuIEEKICAgIAogICAgY2xhc3MgRmFzdE8oSU9CYXNlKToKICAgICAgICBkZWYgX19pbml0X18oc2VsZiwgZmQ9MSk6CiAgICAgICAgICAgIHN0cmVhbSA9IEJ5dGVzSU8oKQogICAgICAgICAgICBzZWxmLmZsdXNoID0gbGFtYmRhOiBvcy53cml0ZSgxLCBzdHJlYW0uZ2V0dmFsdWUoKSkgYW5kIG5vdCBzdHJlYW0udHJ1bmNhdGUoMCkgYW5kIHN0cmVhbS5zZWVrKDApCiAgICAgICAgICAgIHNlbGYud3JpdGUgPSBzdHJlYW0ud3JpdGUgaWYgcHkyIGVsc2UgbGFtYmRhIHM6IHN0cmVhbS53cml0ZShzLmVuY29kZSgpKQogICAgCiAgICBzeXMuc3RkaW4sIHN5cy5zdGRvdXQgPSBGYXN0SSgpLCBGYXN0TygpCiAgICBnbG9iYWwgaW5wdXQKICAgIGlucHV0ID0gc3lzLnN0ZGluLmlucHV0CgoKaW1wb3J0IHN5cwoKY2xhc3Mgb3N0cmVhbToKICAgIGRlZiBfX2xzaGlmdF9fKHNlbGYsYSk6CiAgICAgICAgaWYgYSA9PSBlbmRsOgogICAgICAgICAgICBzeXMuc3Rkb3V0LndyaXRlKCJcbiIpCiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoc3RyKGEpKQogICAgICAgIHJldHVybiBzZWxmCiAgICBkZWYgdGllKHNlbGYsIHZhbCk6cGFzcwpjb3V0ID0gb3N0cmVhbSgpCmVuZGwgPSBvYmplY3QoKQoKY2xhc3MgaXN0cmVhbToKICAgIHRpZWR0byA9IGNvdXQKICAgIGlucCA9IE5vbmUKICAgIGRlZiBfX3Jsc2hpZnRfXyhhLGIpOgogICAgICAgIGlmIGEudGllZHRvID09IGNvdXQ6CiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGlmIHR5cGUoYik9PXR1cGxlIG9yIHR5cGUoYik9PWxpc3Q6CiAgICAgICAgICAgIHJldHVybiB0eXBlKGIpKHR5cGUoYykoYS5nZXQoKSkgZm9yIGMgaW4gYikKICAgICAgICByZXR1cm4gdHlwZShiKShhLmdldCgpKQogICAgZGVmIHRpZShzZWxmLCB2YWwpOgogICAgICAgIHNlbGYudGllZHRvID0gdmFsCiAgICBkZWYgZ2V0KGEpOgogICAgICAgIHdoaWxlIG5vdCBhLmlucDoKICAgICAgICAgICAgYS5pbnAgPSBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpWzo6LTFdCiAgICAgICAgcmV0dXJuIGEuaW5wLnBvcCgpCmNpbiA9IGlzdHJlYW0oKQoKY2xhc3MgVmVjdG9yOgogICAgZGVmIF9fbHNoaWZ0X18oc2VsZiwgb3RoZXIpOgogICAgICAgIHNlbGYudHlwZSA9IG90aGVyCiAgICAgICAgcmV0dXJuIHNlbGYKICAgIGRlZiBfX3JzaGlmdF9fKHNlbGYsIG90aGVyKToKICAgICAgICBpZiB0eXBlKG90aGVyKSA9PSB0dXBsZToKICAgICAgICAgICAgcmV0dXJuIFtzZWxmLnR5cGUob3RoZXJbMV0pXSpvdGhlclswXQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBbc2VsZi50eXBlKCldKm90aGVyCnZlY3RvciA9IFZlY3RvcigpCg=='.encode()))
true = True
false = False
pii = lambda : [0, 0]
main(len(sys.argv), sys.argv)


import heapq
(n, k) = [int(i) for i in input().split(' ')]
stus = [int(i) for i in input().split(' ')]
ss = sorted(list(enumerate(stus)), key=lambda x: -x[1])
nb = [[i - 1, i + 1] for i in range(n)]
ssid = 0
res = [-1] * n
turn = 0
count = 0
for (idx, val) in ss:
	if res[idx] != -1:
		continue
	res[idx] = turn % 2 + 1
	(left, right) = nb[idx]
	for i in range(k):
		if right < n and res[right] == -1:
			res[right] = turn % 2 + 1
			nb[idx][1] = nb[right][1]
			right = nb[right][1]
		if left >= 0 and res[left] == -1:
			res[left] = turn % 2 + 1
			nb[idx][0] = nb[left][0]
			left = nb[left][0]
		if nb[idx][1] < n:
			nb[nb[idx][1]][0] = nb[idx][0]
		if nb[idx][0] >= 0:
			nb[nb[idx][0]][1] = nb[idx][1]
	turn += 1
print(''.join([str(i) for i in res]))


class Node:

	def __init__(self, v, i):
		self.v = v
		self.i = i
		self.left = None
		self.right = None
(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
nodes = [Node(v, i) for (i, v) in enumerate(nums)]
sort = [[v, i] for (i, v) in enumerate(nums)]
sort = sorted(sort, key=lambda x: [x[0], x[1]], reverse=True)
for i in range(len(nodes)):
	if i < len(nodes) - 1:
		nodes[i].right = nodes[i + 1]
	if i > 0:
		nodes[i].left = nodes[i - 1]
ans = [0] * n
team = 1
for pair in sort:
	(v, i) = pair
	if nodes[i].i == None:
		continue
	ans[i] = team if team == 1 else 2
	cur = nodes[i].right
	right = None
	for j in range(k):
		if cur == None:
			break
		right = cur.right
		ans[cur.i] = team if team == 1 else 2
		cur.i = None
		cur = right
	cur = nodes[i].left
	left = None
	for j in range(k):
		if cur == None:
			break
		left = cur.left
		ans[cur.i] = team if team == 1 else 2
		cur.i = None
		cur = left
	if left:
		left.right = right
	if right:
		right.left = left
	team = team ^ 1
print(''.join([str(i) for i in ans]))


def delete(i, grp):
	l = left[i]
	r = right[i]
	if l != -1:
		right[l] = r
	if r != n:
		left[r] = l
	used[i] = grp
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
left = [-1] * n
right = [n] * n
used = [-1] * n
for i in range(n):
	left[i] = i - 1
	right[i] = i + 1
order = sorted(range(n), key=lambda i: arr[i], reverse=True)
grp = 1
for i in order:
	if used[i] != -1:
		continue
	l = left[i]
	r = right[i]
	delete(i, grp)
	cnt = 0
	while l != -1 and cnt < k:
		cnt += 1
		temp = left[l]
		delete(l, grp)
		l = temp
	cnt = 0
	while r != n and cnt < k:
		cnt += 1
		temp = right[r]
		delete(r, grp)
		r = temp
	if grp == 1:
		grp = 2
	else:
		grp = 1
print(*used, sep='')


from sys import stdin
import math
from copy import deepcopy
import collections

def doc(s):
	if hasattr(s, '__call__'):
		s = s.__doc__

	def f(g):
		g.__doc__ = s
		return g
	return f

class heapdict(collections.MutableMapping):
	__marker = object()

	@staticmethod
	def _parent(i):
		return i - 1 >> 1

	@staticmethod
	def _left(i):
		return (i << 1) + 1

	@staticmethod
	def _right(i):
		return i + 1 << 1

	def __init__(self, *args, **kw):
		self.heap = []
		self.d = {}
		self.update(*args, **kw)

	@doc(dict.clear)
	def clear(self):
		self.heap.clear()
		self.d.clear()

	@doc(dict.__setitem__)
	def __setitem__(self, key, value):
		if key in self.d:
			self.pop(key)
		wrapper = [value, key, len(self)]
		self.d[key] = wrapper
		self.heap.append(wrapper)
		self._decrease_key(len(self.heap) - 1)

	def _min_heapify(self, i):
		l = self._left(i)
		r = self._right(i)
		n = len(self.heap)
		if l < n and self.heap[l][0] < self.heap[i][0]:
			low = l
		else:
			low = i
		if r < n and self.heap[r][0] < self.heap[low][0]:
			low = r
		if low != i:
			self._swap(i, low)
			self._min_heapify(low)

	def _decrease_key(self, i):
		while i:
			parent = self._parent(i)
			if self.heap[parent][0] < self.heap[i][0]:
				break
			self._swap(i, parent)
			i = parent

	def _swap(self, i, j):
		(self.heap[i], self.heap[j]) = (self.heap[j], self.heap[i])
		self.heap[i][2] = i
		self.heap[j][2] = j

	@doc(dict.__delitem__)
	def __delitem__(self, key):
		wrapper = self.d[key]
		while wrapper[2]:
			parentpos = self._parent(wrapper[2])
			parent = self.heap[parentpos]
			self._swap(wrapper[2], parent[2])
		self.popitem()

	@doc(dict.__getitem__)
	def __getitem__(self, key):
		return self.d[key][0]

	@doc(dict.__iter__)
	def __iter__(self):
		return iter(self.d)

	def popitem(self):
		wrapper = self.heap[0]
		if len(self.heap) == 1:
			self.heap.pop()
		else:
			self.heap[0] = self.heap.pop(-1)
			self.heap[0][2] = 0
			self._min_heapify(0)
		del self.d[wrapper[1]]
		return (wrapper[1], wrapper[0])

	@doc(dict.__len__)
	def __len__(self):
		return len(self.d)

	def peekitem(self):
		return (self.heap[0][1], self.heap[0][0])
del doc
__all__ = ['heapdict']

def heap_delete(mypq, index):
	if index in mypq:
		mypq[index] = -float('inf')
		mypq.popitem()

def get_left_right(arr, n):
	aux = []
	for i in range(n):
		aux.append([arr[i], i - 1, i + 1])
	return aux

def add_left(arr, mypq, myset, index, k):
	left = index
	count = 0
	while left != -1 and count < k:
		left = arr[left][1]
		if left == -1:
			break
		myset.add(arr[left][0])
		heap_delete(mypq, left)
		count += 1
	if left == -1:
		arr[index][1] = -1
	else:
		arr[index][1] = arr[left][1]
		arr[left][2] = index

def add_right(arr, mypq, myset, index, k):
	right = index
	count = 0
	while right != len(arr) and count < k:
		right = arr[right][2]
		if right == len(arr):
			break
		myset.add(arr[right][0])
		heap_delete(mypq, right)
		count += 1
	if right == len(arr):
		arr[index][2] = len(arr)
	else:
		arr[index][2] = arr[right][2]
		arr[right][1] = index
(n, k) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
arr = get_left_right(arr, n)
mypq = heapdict()
for i in range(n):
	mypq[i] = -arr[i][0]
first = set()
second = set()
chance = 0
while len(mypq) > 0:
	if chance == 0:
		(index, value) = mypq.popitem()
		value = abs(value)
		first.add(value)
		heap_delete(mypq, index)
		add_left(arr, mypq, first, index, k)
		add_right(arr, mypq, first, index, k)
		if arr[index][1] != -1:
			arr[arr[index][1]][2] = arr[index][2]
		if arr[index][2] != n:
			arr[arr[index][2]][1] = arr[index][1]
		chance = 1
	else:
		(index, value) = mypq.popitem()
		value = abs(value)
		second.add(value)
		heap_delete(mypq, index)
		add_left(arr, mypq, second, index, k)
		add_right(arr, mypq, second, index, k)
		if arr[index][1] != -1:
			arr[arr[index][1]][2] = arr[index][2]
		if arr[index][2] != n:
			arr[arr[index][2]][1] = arr[index][1]
		chance = 0
for i in arr:
	element = i[0]
	if element in first:
		print(1, end='')
	else:
		print(2, end='')


(n, k) = list(map(int, input().split()))
row = list(map(int, input().split()))
ranked = list([x[1] for x in sorted([(-x[1], x[0]) for x in enumerate(row)])])
prev = list(range(-1, n - 1))
nxt = list(range(1, n + 1))
teams = [0] * n
current = 1
total = 0
for i in ranked:
	if total > n:
		break
	if not teams[i]:
		teams[i] = current
		took = 1
		count = k
		left = prev[i]
		while count > 0 and left != -1:
			teams[left] = current
			left = prev[left]
			took += 1
			count -= 1
		count = k
		right = nxt[i]
		while count > 0 and right != n:
			teams[right] = current
			right = nxt[right]
			took += 1
			count -= 1
		if left != -1:
			nxt[left] = right
		if right != n:
			prev[right] = left
		total += took
		current = 2 if current == 1 else 1
print(''.join(map(str, teams)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
pos = {}
pre = [i - 1 for i in range(n + 2)]
nex = [i + 1 for i in range(n + 2)]
for (i, j) in enumerate(a):
	pos[j] = i + 1
group = 1
taken = [0 for _ in range(n + 2)]
right = left = 0
for i in range(n, 0, -1):
	if taken[pos[i]] != 0:
		continue
	group = (group + 1) % 2
	p = k
	now = pos[i]
	taken[now] = group + 1
	while p > 0 and now <= n:
		now = nex[now]
		if taken[now] == 0:
			taken[now] = group + 1
			p -= 1
		right = now
	p = k
	now = pos[i]
	while p > 0 and now > 0:
		now = pre[now]
		if taken[now] == 0:
			taken[now] = group + 1
			p -= 1
		left = now
	nex[left] = right
	pre[right] = left
ans = [str(i) for i in taken]
print(''.join(ans[1:n + 1]))


(n, k) = map(int, input().split())
skill = list(map(int, input().split()))
who = 1
stu = [1] * (n + 1)
lstu = [0] * (n + 1)
rstu = [0] * (n + 1)
take = [0] * n
stu_pos = {}
for i in range(n):
	stu_pos[skill[i]] = i
for i in skill:
	if stu_pos[i] == 0:
		lstu[i] = -1
	else:
		lstu[i] = skill[stu_pos[i] - 1]
	if stu_pos[i] == n - 1:
		rstu[i] = -1
	else:
		rstu[i] = skill[stu_pos[i] + 1]
for i in range(n):
	key = n - i
	if stu[key] == 0:
		continue
	pick = []
	pick.append(key)
	stu[key] = 0
	pos = key
	for _ in range(k):
		pos = lstu[pos]
		if pos == -1:
			break
		pick.append(pos)
		stu[pos] = 0
	if pos != -1:
		pos = lstu[pos]
	lpos = pos
	pos = key
	for _ in range(k):
		pos = rstu[pos]
		if pos == -1:
			break
		pick.append(pos)
		stu[pos] = 0
	if pos != -1:
		pos = rstu[pos]
	rpos = pos
	lstu[rpos] = lpos
	rstu[lpos] = rpos
	for j in pick:
		if who % 2 == 1:
			take[stu_pos[j]] = 1
		if who % 2 == 0:
			take[stu_pos[j]] = 2
	who += 1
s = ''
for i in take:
	s += str(i)
print(s)


def turn(maxgen, V, A, k, val):
	max_node = next(maxgen)
	left_node = get_prev(max_node)
	right_node = get_next(max_node)
	V[remove(max_node, A)] = val
	rcnt = 0
	while rcnt < k and right_node is not None:
		V[remove(right_node, A)] = val
		right_node = get_next(right_node)
		rcnt += 1
	lcnt = 0
	while lcnt < k and left_node is not None:
		V[remove(left_node, A)] = val
		left_node = get_prev(left_node)
		lcnt += 1
	return lcnt + rcnt + 1

def get_next(node):
	return node[1][1]

def get_prev(node):
	return node[1][0]

def pushback(value, prev_node):
	next_node = None
	new_node = [value, [prev_node, next_node]]
	if prev_node[1][1] is None:
		prev_node[1][1] = new_node
	else:
		raise Exception
	return new_node

def remove(node, A):
	((node_value, node_index), (node_prev, node_next)) = node
	if node_prev is not None:
		node_prev[1][1] = node_next
	if node_next is not None:
		node_next[1][0] = node_prev
	A[node_value - 1] = None
	return node_index

def parseraw(raw, A):
	head = [None, [None, None]]
	temp = ''
	sep = ' '
	ind = 0
	lasti = len(raw) - 1
	for (i, v) in enumerate(raw):
		if v == sep or i == lasti:
			if i == lasti:
				temp += v
			j = int(temp)
			if head[0] is None:
				head[0] = (j, ind)
				last_node = head
			else:
				last_node = pushback((j, ind), last_node)
			A[j - 1] = last_node
			ind += 1
			temp = ''
		else:
			temp += v

def max_gen(A):
	for i in reversed(A):
		if i is not None:
			yield i
(n, k) = map(int, input().split())
raw = input()
A = [None] * n
V = [None] * n
parseraw(raw, A)
maxgen = max_gen(A)
first = -1
while n:
	val = 1 if first else 2
	n -= turn(maxgen, V, A, k, val)
	first = ~first
print(*V, sep='')


import sys
from bisect import bisect_left, bisect_right, insort
from itertools import chain, repeat, starmap
from math import log
from operator import add, eq, ne, gt, ge, lt, le, iadd
from textwrap import dedent
try:
	from collections.abc import Sequence, MutableSequence
except ImportError:
	from collections import Sequence, MutableSequence
from functools import wraps
from sys import hexversion
if hexversion < 50331648:
	from itertools import imap as map
	from itertools import izip as zip
	try:
		from thread import get_ident
	except ImportError:
		from dummy_thread import get_ident
else:
	from functools import reduce
	try:
		from _thread import get_ident
	except ImportError:
		from _dummy_thread import get_ident

def recursive_repr(fillvalue='...'):

	def decorating_function(user_function):
		repr_running = set()

		@wraps(user_function)
		def wrapper(self):
			key = (id(self), get_ident())
			if key in repr_running:
				return fillvalue
			repr_running.add(key)
			try:
				result = user_function(self)
			finally:
				repr_running.discard(key)
			return result
		return wrapper
	return decorating_function

class SortedList(MutableSequence):
	DEFAULT_LOAD_FACTOR = 1000

	def __init__(self, iterable=None, key=None):
		assert key is None
		self._len = 0
		self._load = self.DEFAULT_LOAD_FACTOR
		self._lists = []
		self._maxes = []
		self._index = []
		self._offset = 0
		if iterable is not None:
			self._update(iterable)

	def __new__(cls, iterable=None, key=None):
		if key is None:
			return object.__new__(cls)
		elif cls is SortedList:
			return object.__new__(SortedKeyList)
		else:
			raise TypeError('inherit SortedKeyList for key argument')

	@property
	def key(self):
		return None

	def _reset(self, load):
		values = reduce(iadd, self._lists, [])
		self._clear()
		self._load = load
		self._update(values)

	def clear(self):
		self._len = 0
		del self._lists[:]
		del self._maxes[:]
		del self._index[:]
		self._offset = 0
	_clear = clear

	def add(self, value):
		_lists = self._lists
		_maxes = self._maxes
		if _maxes:
			pos = bisect_right(_maxes, value)
			if pos == len(_maxes):
				pos -= 1
				_lists[pos].append(value)
				_maxes[pos] = value
			else:
				insort(_lists[pos], value)
			self._expand(pos)
		else:
			_lists.append([value])
			_maxes.append(value)
		self._len += 1

	def _expand(self, pos):
		_load = self._load
		_lists = self._lists
		_index = self._index
		if len(_lists[pos]) > _load << 1:
			_maxes = self._maxes
			_lists_pos = _lists[pos]
			half = _lists_pos[_load:]
			del _lists_pos[_load:]
			_maxes[pos] = _lists_pos[-1]
			_lists.insert(pos + 1, half)
			_maxes.insert(pos + 1, half[-1])
			del _index[:]
		elif _index:
			child = self._offset + pos
			while child:
				_index[child] += 1
				child = child - 1 >> 1
			_index[0] += 1

	def update(self, iterable):
		_lists = self._lists
		_maxes = self._maxes
		values = sorted(iterable)
		if _maxes:
			if len(values) * 4 >= self._len:
				values.extend(chain.from_iterable(_lists))
				values.sort()
				self._clear()
			else:
				_add = self.add
				for val in values:
					_add(val)
				return
		_load = self._load
		_lists.extend((values[pos:pos + _load] for pos in range(0, len(values), _load)))
		_maxes.extend((sublist[-1] for sublist in _lists))
		self._len = len(values)
		del self._index[:]
	_update = update

	def __contains__(self, value):
		_maxes = self._maxes
		if not _maxes:
			return False
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			return False
		_lists = self._lists
		idx = bisect_left(_lists[pos], value)
		return _lists[pos][idx] == value

	def discard(self, value):
		_maxes = self._maxes
		if not _maxes:
			return
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			return
		_lists = self._lists
		idx = bisect_left(_lists[pos], value)
		if _lists[pos][idx] == value:
			self._delete(pos, idx)

	def remove(self, value):
		_maxes = self._maxes
		if not _maxes:
			raise ValueError('{0!r} not in list'.format(value))
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			raise ValueError('{0!r} not in list'.format(value))
		_lists = self._lists
		idx = bisect_left(_lists[pos], value)
		if _lists[pos][idx] == value:
			self._delete(pos, idx)
		else:
			raise ValueError('{0!r} not in list'.format(value))

	def _delete(self, pos, idx):
		_lists = self._lists
		_maxes = self._maxes
		_index = self._index
		_lists_pos = _lists[pos]
		del _lists_pos[idx]
		self._len -= 1
		len_lists_pos = len(_lists_pos)
		if len_lists_pos > self._load >> 1:
			_maxes[pos] = _lists_pos[-1]
			if _index:
				child = self._offset + pos
				while child > 0:
					_index[child] -= 1
					child = child - 1 >> 1
				_index[0] -= 1
		elif len(_lists) > 1:
			if not pos:
				pos += 1
			prev = pos - 1
			_lists[prev].extend(_lists[pos])
			_maxes[prev] = _lists[prev][-1]
			del _lists[pos]
			del _maxes[pos]
			del _index[:]
			self._expand(prev)
		elif len_lists_pos:
			_maxes[pos] = _lists_pos[-1]
		else:
			del _lists[pos]
			del _maxes[pos]
			del _index[:]

	def _loc(self, pos, idx):
		if not pos:
			return idx
		_index = self._index
		if not _index:
			self._build_index()
		total = 0
		pos += self._offset
		while pos:
			if not pos & 1:
				total += _index[pos - 1]
			pos = pos - 1 >> 1
		return total + idx

	def _pos(self, idx):
		if idx < 0:
			last_len = len(self._lists[-1])
			if -idx <= last_len:
				return (len(self._lists) - 1, last_len + idx)
			idx += self._len
			if idx < 0:
				raise IndexError('list index out of range')
		elif idx >= self._len:
			raise IndexError('list index out of range')
		if idx < len(self._lists[0]):
			return (0, idx)
		_index = self._index
		if not _index:
			self._build_index()
		pos = 0
		child = 1
		len_index = len(_index)
		while child < len_index:
			index_child = _index[child]
			if idx < index_child:
				pos = child
			else:
				idx -= index_child
				pos = child + 1
			child = (pos << 1) + 1
		return (pos - self._offset, idx)

	def _build_index(self):
		row0 = list(map(len, self._lists))
		if len(row0) == 1:
			self._index[:] = row0
			self._offset = 0
			return
		head = iter(row0)
		tail = iter(head)
		row1 = list(starmap(add, zip(head, tail)))
		if len(row0) & 1:
			row1.append(row0[-1])
		if len(row1) == 1:
			self._index[:] = row1 + row0
			self._offset = 1
			return
		size = 2 ** (int(log(len(row1) - 1, 2)) + 1)
		row1.extend(repeat(0, size - len(row1)))
		tree = [row0, row1]
		while len(tree[-1]) > 1:
			head = iter(tree[-1])
			tail = iter(head)
			row = list(starmap(add, zip(head, tail)))
			tree.append(row)
		reduce(iadd, reversed(tree), self._index)
		self._offset = size * 2 - 1

	def __delitem__(self, index):
		if isinstance(index, slice):
			(start, stop, step) = index.indices(self._len)
			if step == 1 and start < stop:
				if start == 0 and stop == self._len:
					return self._clear()
				elif self._len <= 8 * (stop - start):
					values = self._getitem(slice(None, start))
					if stop < self._len:
						values += self._getitem(slice(stop, None))
					self._clear()
					return self._update(values)
			indices = range(start, stop, step)
			if step > 0:
				indices = reversed(indices)
			(_pos, _delete) = (self._pos, self._delete)
			for index in indices:
				(pos, idx) = _pos(index)
				_delete(pos, idx)
		else:
			(pos, idx) = self._pos(index)
			self._delete(pos, idx)

	def __getitem__(self, index):
		_lists = self._lists
		if isinstance(index, slice):
			(start, stop, step) = index.indices(self._len)
			if step == 1 and start < stop:
				if start == 0 and stop == self._len:
					return reduce(iadd, self._lists, [])
				(start_pos, start_idx) = self._pos(start)
				if stop == self._len:
					stop_pos = len(_lists) - 1
					stop_idx = len(_lists[stop_pos])
				else:
					(stop_pos, stop_idx) = self._pos(stop)
				if start_pos == stop_pos:
					return _lists[start_pos][start_idx:stop_idx]
				prefix = _lists[start_pos][start_idx:]
				middle = _lists[start_pos + 1:stop_pos]
				result = reduce(iadd, middle, prefix)
				result += _lists[stop_pos][:stop_idx]
				return result
			if step == -1 and start > stop:
				result = self._getitem(slice(stop + 1, start + 1))
				result.reverse()
				return result
			indices = range(start, stop, step)
			return list((self._getitem(index) for index in indices))
		else:
			if self._len:
				if index == 0:
					return _lists[0][0]
				elif index == -1:
					return _lists[-1][-1]
			else:
				raise IndexError('list index out of range')
			if 0 <= index < len(_lists[0]):
				return _lists[0][index]
			len_last = len(_lists[-1])
			if -len_last < index < 0:
				return _lists[-1][len_last + index]
			(pos, idx) = self._pos(index)
			return _lists[pos][idx]
	_getitem = __getitem__

	def __setitem__(self, index, value):
		message = 'use ``del sl[index]`` and ``sl.add(value)`` instead'
		raise NotImplementedError(message)

	def __iter__(self):
		return chain.from_iterable(self._lists)

	def __reversed__(self):
		return chain.from_iterable(map(reversed, reversed(self._lists)))

	def reverse(self):
		raise NotImplementedError('use ``reversed(sl)`` instead')

	def islice(self, start=None, stop=None, reverse=False):
		_len = self._len
		if not _len:
			return iter(())
		(start, stop, _) = slice(start, stop).indices(self._len)
		if start >= stop:
			return iter(())
		_pos = self._pos
		(min_pos, min_idx) = _pos(start)
		if stop == _len:
			max_pos = len(self._lists) - 1
			max_idx = len(self._lists[-1])
		else:
			(max_pos, max_idx) = _pos(stop)
		return self._islice(min_pos, min_idx, max_pos, max_idx, reverse)

	def _islice(self, min_pos, min_idx, max_pos, max_idx, reverse):
		_lists = self._lists
		if min_pos > max_pos:
			return iter(())
		if min_pos == max_pos:
			if reverse:
				indices = reversed(range(min_idx, max_idx))
				return map(_lists[min_pos].__getitem__, indices)
			indices = range(min_idx, max_idx)
			return map(_lists[min_pos].__getitem__, indices)
		next_pos = min_pos + 1
		if next_pos == max_pos:
			if reverse:
				min_indices = range(min_idx, len(_lists[min_pos]))
				max_indices = range(max_idx)
				return chain(map(_lists[max_pos].__getitem__, reversed(max_indices)), map(_lists[min_pos].__getitem__, reversed(min_indices)))
			min_indices = range(min_idx, len(_lists[min_pos]))
			max_indices = range(max_idx)
			return chain(map(_lists[min_pos].__getitem__, min_indices), map(_lists[max_pos].__getitem__, max_indices))
		if reverse:
			min_indices = range(min_idx, len(_lists[min_pos]))
			sublist_indices = range(next_pos, max_pos)
			sublists = map(_lists.__getitem__, reversed(sublist_indices))
			max_indices = range(max_idx)
			return chain(map(_lists[max_pos].__getitem__, reversed(max_indices)), chain.from_iterable(map(reversed, sublists)), map(_lists[min_pos].__getitem__, reversed(min_indices)))
		min_indices = range(min_idx, len(_lists[min_pos]))
		sublist_indices = range(next_pos, max_pos)
		sublists = map(_lists.__getitem__, sublist_indices)
		max_indices = range(max_idx)
		return chain(map(_lists[min_pos].__getitem__, min_indices), chain.from_iterable(sublists), map(_lists[max_pos].__getitem__, max_indices))

	def irange(self, minimum=None, maximum=None, inclusive=(True, True), reverse=False):
		_maxes = self._maxes
		if not _maxes:
			return iter(())
		_lists = self._lists
		if minimum is None:
			min_pos = 0
			min_idx = 0
		elif inclusive[0]:
			min_pos = bisect_left(_maxes, minimum)
			if min_pos == len(_maxes):
				return iter(())
			min_idx = bisect_left(_lists[min_pos], minimum)
		else:
			min_pos = bisect_right(_maxes, minimum)
			if min_pos == len(_maxes):
				return iter(())
			min_idx = bisect_right(_lists[min_pos], minimum)
		if maximum is None:
			max_pos = len(_maxes) - 1
			max_idx = len(_lists[max_pos])
		elif inclusive[1]:
			max_pos = bisect_right(_maxes, maximum)
			if max_pos == len(_maxes):
				max_pos -= 1
				max_idx = len(_lists[max_pos])
			else:
				max_idx = bisect_right(_lists[max_pos], maximum)
		else:
			max_pos = bisect_left(_maxes, maximum)
			if max_pos == len(_maxes):
				max_pos -= 1
				max_idx = len(_lists[max_pos])
			else:
				max_idx = bisect_left(_lists[max_pos], maximum)
		return self._islice(min_pos, min_idx, max_pos, max_idx, reverse)

	def __len__(self):
		return self._len

	def bisect_left(self, value):
		_maxes = self._maxes
		if not _maxes:
			return 0
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			return self._len
		idx = bisect_left(self._lists[pos], value)
		return self._loc(pos, idx)

	def bisect_right(self, value):
		_maxes = self._maxes
		if not _maxes:
			return 0
		pos = bisect_right(_maxes, value)
		if pos == len(_maxes):
			return self._len
		idx = bisect_right(self._lists[pos], value)
		return self._loc(pos, idx)
	bisect = bisect_right
	_bisect_right = bisect_right

	def count(self, value):
		_maxes = self._maxes
		if not _maxes:
			return 0
		pos_left = bisect_left(_maxes, value)
		if pos_left == len(_maxes):
			return 0
		_lists = self._lists
		idx_left = bisect_left(_lists[pos_left], value)
		pos_right = bisect_right(_maxes, value)
		if pos_right == len(_maxes):
			return self._len - self._loc(pos_left, idx_left)
		idx_right = bisect_right(_lists[pos_right], value)
		if pos_left == pos_right:
			return idx_right - idx_left
		right = self._loc(pos_right, idx_right)
		left = self._loc(pos_left, idx_left)
		return right - left

	def copy(self):
		return self.__class__(self)
	__copy__ = copy

	def append(self, value):
		raise NotImplementedError('use ``sl.add(value)`` instead')

	def extend(self, values):
		raise NotImplementedError('use ``sl.update(values)`` instead')

	def insert(self, index, value):
		raise NotImplementedError('use ``sl.add(value)`` instead')

	def pop(self, index=-1):
		if not self._len:
			raise IndexError('pop index out of range')
		_lists = self._lists
		if index == 0:
			val = _lists[0][0]
			self._delete(0, 0)
			return val
		if index == -1:
			pos = len(_lists) - 1
			loc = len(_lists[pos]) - 1
			val = _lists[pos][loc]
			self._delete(pos, loc)
			return val
		if 0 <= index < len(_lists[0]):
			val = _lists[0][index]
			self._delete(0, index)
			return val
		len_last = len(_lists[-1])
		if -len_last < index < 0:
			pos = len(_lists) - 1
			loc = len_last + index
			val = _lists[pos][loc]
			self._delete(pos, loc)
			return val
		(pos, idx) = self._pos(index)
		val = _lists[pos][idx]
		self._delete(pos, idx)
		return val

	def index(self, value, start=None, stop=None):
		_len = self._len
		if not _len:
			raise ValueError('{0!r} is not in list'.format(value))
		if start is None:
			start = 0
		if start < 0:
			start += _len
		if start < 0:
			start = 0
		if stop is None:
			stop = _len
		if stop < 0:
			stop += _len
		if stop > _len:
			stop = _len
		if stop <= start:
			raise ValueError('{0!r} is not in list'.format(value))
		_maxes = self._maxes
		pos_left = bisect_left(_maxes, value)
		if pos_left == len(_maxes):
			raise ValueError('{0!r} is not in list'.format(value))
		_lists = self._lists
		idx_left = bisect_left(_lists[pos_left], value)
		if _lists[pos_left][idx_left] != value:
			raise ValueError('{0!r} is not in list'.format(value))
		stop -= 1
		left = self._loc(pos_left, idx_left)
		if start <= left:
			if left <= stop:
				return left
		else:
			right = self._bisect_right(value) - 1
			if start <= right:
				return start
		raise ValueError('{0!r} is not in list'.format(value))

	def __add__(self, other):
		values = reduce(iadd, self._lists, [])
		values.extend(other)
		return self.__class__(values)
	__radd__ = __add__

	def __iadd__(self, other):
		self._update(other)
		return self

	def __mul__(self, num):
		values = reduce(iadd, self._lists, []) * num
		return self.__class__(values)
	__rmul__ = __mul__

	def __imul__(self, num):
		values = reduce(iadd, self._lists, []) * num
		self._clear()
		self._update(values)
		return self

	def __make_cmp(seq_op, symbol, doc):

		def comparer(self, other):
			if not isinstance(other, Sequence):
				return NotImplemented
			self_len = self._len
			len_other = len(other)
			if self_len != len_other:
				if seq_op is eq:
					return False
				if seq_op is ne:
					return True
			for (alpha, beta) in zip(self, other):
				if alpha != beta:
					return seq_op(alpha, beta)
			return seq_op(self_len, len_other)
		seq_op_name = seq_op.__name__
		comparer.__name__ = '__{0}__'.format(seq_op_name)
		doc_str = 'Return true if and only if sorted list is {0} `other`.\n\n        ``sl.__{1}__(other)`` <==> ``sl {2} other``\n\n        Comparisons use lexicographical order as with sequences.\n\n        Runtime complexity: `O(n)`\n\n        :param other: `other` sequence\n        :return: true if sorted list is {0} `other`\n\n        '
		comparer.__doc__ = dedent(doc_str.format(doc, seq_op_name, symbol))
		return comparer
	__eq__ = __make_cmp(eq, '==', 'equal to')
	__ne__ = __make_cmp(ne, '!=', 'not equal to')
	__lt__ = __make_cmp(lt, '<', 'less than')
	__gt__ = __make_cmp(gt, '>', 'greater than')
	__le__ = __make_cmp(le, '<=', 'less than or equal to')
	__ge__ = __make_cmp(ge, '>=', 'greater than or equal to')
	__make_cmp = staticmethod(__make_cmp)

	@recursive_repr()
	def __repr__(self):
		return '{0}({1!r})'.format(type(self).__name__, list(self))

	def _check(self):
		try:
			assert self._load >= 4
			assert len(self._maxes) == len(self._lists)
			assert self._len == sum((len(sublist) for sublist in self._lists))
			for sublist in self._lists:
				for pos in range(1, len(sublist)):
					assert sublist[pos - 1] <= sublist[pos]
			for pos in range(1, len(self._lists)):
				assert self._lists[pos - 1][-1] <= self._lists[pos][0]
			for pos in range(len(self._maxes)):
				assert self._maxes[pos] == self._lists[pos][-1]
			double = self._load << 1
			assert all((len(sublist) <= double for sublist in self._lists))
			half = self._load >> 1
			for pos in range(0, len(self._lists) - 1):
				assert len(self._lists[pos]) >= half
			if self._index:
				assert self._len == self._index[0]
				assert len(self._index) == self._offset + len(self._lists)
				for pos in range(len(self._lists)):
					leaf = self._index[self._offset + pos]
					assert leaf == len(self._lists[pos])
				for pos in range(self._offset):
					child = (pos << 1) + 1
					if child >= len(self._index):
						assert self._index[pos] == 0
					elif child + 1 == len(self._index):
						assert self._index[pos] == self._index[child]
					else:
						child_sum = self._index[child] + self._index[child + 1]
						assert child_sum == self._index[pos]
		except:
			import sys
			import traceback
			traceback.print_exc(file=sys.stdout)
			print('len', self._len)
			print('load', self._load)
			print('offset', self._offset)
			print('len_index', len(self._index))
			print('index', self._index)
			print('len_maxes', len(self._maxes))
			print('maxes', self._maxes)
			print('len_lists', len(self._lists))
			print('lists', self._lists)
			raise
fin = sys.stdin.readline
(n, k) = [int(elem) for elem in fin().split()]
a_list = sorted([(int(elem), i) for (i, elem) in enumerate(fin().split())], reverse=True)
idx_to_team = [0] * n
programmers_in_row = SortedList(range(n))
coach = 1
for (a, i) in a_list:
	if idx_to_team[i] != 0:
		continue
	cur_idx = programmers_in_row.bisect_left(i)
	cur_added = []
	for j in range(max(0, cur_idx - k), min(len(programmers_in_row), cur_idx + k + 1)):
		neighbor = programmers_in_row[j]
		idx_to_team[neighbor] = coach
		cur_added.append(neighbor)
	for added_programmer in cur_added:
		programmers_in_row.remove(added_programmer)
	coach = 2 if coach == 1 else 1
print(''.join((str(coach) for coach in idx_to_team)))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
A = [(a, i) for (i, a) in enumerate(A)]
A.sort(key=lambda x: x[0])
A.reverse()
left = [-1] * n
for i in range(1, n):
	left[i] = i - 1
right = [-1] * n
for i in range(n - 1):
	right[i] = i + 1
vis = [0] * n
join = [0] * n
jo = 1
for i in range(n):
	if not vis[A[i][1]]:
		cur = A[i][1]
		vis[cur] = 1
		join[cur] = jo
		if left[cur] != -1:
			right[left[cur]] = right[cur]
		if right[cur] != -1:
			left[right[cur]] = left[cur]
		for j in range(k):
			cur = left[cur]
			if cur == -1:
				break
			vis[cur] = 1
			join[cur] = jo
			if left[cur] != -1:
				right[left[cur]] = right[cur]
			if right[cur] != -1:
				left[right[cur]] = left[cur]
		cur = A[i][1]
		for j in range(k):
			cur = right[cur]
			if cur == -1:
				break
			vis[cur] = 1
			join[cur] = jo
			if left[cur] != -1:
				right[left[cur]] = right[cur]
			if right[cur] != -1:
				left[right[cur]] = left[cur]
		jo = 1 if jo == 2 else 2
print(*join, sep='')


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
left = [i - 1 for i in range(n)]
right = [i + 1 for i in range(n)]
ans = [0] * n

def next(i):
	upd = [i]
	i = right[i]
	while i < n and ans[i] != 0:
		upd.append(i)
		i = right[i]
	for x in upd:
		right[x] = i
	return i

def prev(i):
	upd = [i]
	i = left[i]
	while i >= 0 and ans[i] != 0:
		upd.append(i)
		i = left[i]
	for x in upd:
		left[x] = i
	return i
a = list(map(int, input().split()))
pos = [0] * (n + 1)
for i in range(n):
	pos[a[i]] = i
team = 1
for x in range(n, 0, -1):
	i = pos[x]
	if ans[i] != 0:
		continue
	ans[i] = team
	j = i
	for _ in range(k):
		j = next(j)
		if j >= n:
			break
		ans[j] = team
	j = i
	for _ in range(k):
		j = prev(j)
		if j < 0:
			break
		ans[j] = team
	team = 3 - team
print(''.join(map(str, ans)))


def input_ints():
	return [int(x) for x in input().split()]

class Node:

	def __init__(self, val):
		self.prev = None
		self.next = None
		self.val = val
		self.team = None
(_, k) = input_ints()
nodes = [Node(x) for x in input_ints()]
order = [i for (i, x) in sorted(enumerate(nodes), key=lambda x: x[1].val, reverse=True)]
for (a, b) in zip(nodes, nodes[1:]):
	a.next = b
	b.prev = a
team = 1
for i in order:
	node = nodes[i]
	if node.team:
		continue
	left = node
	for _ in range(k + 1):
		if left:
			left.team = team
			left = left.prev
		else:
			break
	right = node
	for _ in range(k + 1):
		if right:
			right.team = team
			right = right.next
		else:
			break
	if left:
		left.next = right
	if right:
		right.prev = left
	team = (team == 1) + 1
print(''.join((str(x.team) for x in nodes)))


__version__ = '1.0'
__date__ = '2019-04-17'
import sys

def remove_me(to_left, to_right, index):
	left_id = to_left[index]
	right_id = to_right[index]
	if right_id < len(to_left):
		to_left[right_id] = left_id
	if left_id >= 0:
		to_right[left_id] = right_id
	return (left_id, right_id)

def join_team(n, k, students):
	teams = ['0'] * n
	mydict = dict(zip(students, range(n)))
	to_left = [i - 1 for i in range(n)]
	to_right = [i + 1 for i in range(n)]
	next_chosen = n
	chosen_total = 0
	while chosen_total < n:
		for couch in ['1', '2']:
			while teams[mydict[next_chosen]] != '0':
				next_chosen -= 1
				if next_chosen < 1:
					return teams
			teams[mydict[next_chosen]] = couch
			chosen_total += 1
			(left_id, right_id) = remove_me(to_left, to_right, mydict[next_chosen])
			for i in range(k):
				if left_id < 0:
					break
				teams[left_id] = couch
				chosen_total += 1
				(left_id, right_id) = remove_me(to_left, to_right, left_id)
			for i in range(k):
				if right_id >= n:
					break
				teams[right_id] = couch
				chosen_total += 1
				(left_id, right_id) = remove_me(to_left, to_right, right_id)
	return teams

def main(argv=None):
	(n, k) = map(int, input().split())
	students = list(map(int, input().split()))
	print(''.join(join_team(n, k, students)))
	return 0
STATUS = main()
sys.exit(STATUS)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
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) = list(map(int, input().split()))
l = list(map(int, input().split()))
for i in range(n):
	l[i] -= 1
taken = [0] * n
place = [0] * n
nast = [i + 1 for i in range(n)]
poprz = [i - 1 for i in range(n)]
for i in range(n):
	place[l[i]] = i
best = n - 1
turn = 2
while True:
	turn = 3 - turn
	p = place[best]
	pp = p
	taken[p] = turn
	for i in range(k):
		if nast[pp] < n:
			pp = nast[pp]
			taken[pp] = turn
		else:
			pp = n
			break
	if pp < n:
		right = nast[pp]
	else:
		right = n
	pp = p
	for i in range(k):
		if poprz[pp] >= 0:
			pp = poprz[pp]
			taken[pp] = turn
		else:
			pp = -1
			break
	if pp >= 0:
		left = poprz[pp]
	else:
		left = -1
	if left > -1:
		nast[left] = right
	if right < n:
		poprz[right] = left
	while True:
		if best < 0:
			for f in taken:
				print(f, end='')
			sys.exit(0)
		if taken[place[best]] != 0:
			best -= 1
		else:
			break


import heapq
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
first = [False] * n
second = [False] * n
pq = []
nexts = [None] * n
prevs = [None] * n
for i in range(n):
	heapq.heappush(pq, (-a[i], i))
	if i < n - 1:
		nexts[i] = i + 1
	if i > 0:
		prevs[i] = i - 1
turn = 0
while pq:
	(_, curIdx) = heapq.heappop(pq)
	if first[curIdx] or second[curIdx]:
		continue
	if turn == 0:
		first[curIdx] = True
	else:
		second[curIdx] = True
	fromLeft = 0
	i = prevs[curIdx]
	while fromLeft < k and i != None:
		if turn == 0:
			first[i] = True
		else:
			second[i] = True
		i = prevs[i]
		fromLeft += 1
	prevs[curIdx] = i
	fromRight = 0
	i = nexts[curIdx]
	while fromRight < k and i != None:
		if turn == 0:
			first[i] = True
		else:
			second[i] = True
		i = nexts[i]
		fromRight += 1
	nexts[curIdx] = i
	if prevs[curIdx] != None:
		nexts[prevs[curIdx]] = nexts[curIdx]
	if nexts[curIdx] != None:
		prevs[nexts[curIdx]] = prevs[curIdx]
	turn ^= 1
for i in range(n):
	print(1 if first[i] else 2, end='')


import heapq

class chain:

	def __init__(self, n):
		self.right = [i + 1 for i in range(0, n + 1)] + [None]
		self.left = [None] + [i - 1 for i in range(1, n + 2)]
		self.n = n

	def remove(self, i):
		l = self.left[i]
		r = self.right[i]
		self.right[l] = r
		self.left[r] = l
		self.right[i] = None
		self.left[i] = None

	def next_left(self, pos):
		if self.left[pos] == 0:
			return None
		return self.left[pos]

	def next_right(self, pos):
		if self.right[pos] == self.n + 1:
			return None
		return self.right[pos]
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
used = {}
group = {}
C = chain(n)
Q = []
for (i, x) in enumerate(a):
	heapq.heappush(Q, (-x, i + 1))
cur = 0
while len(Q) > 0:
	while len(Q) > 0 and Q[0][1] in used:
		heapq.heappop(Q)
	if len(Q) == 0:
		break
	(x, i) = Q[0]
	group[i] = cur + 1
	used[i] = True
	remove = [i]
	pos = i
	k_ = k
	while k_ > 0 and C.next_left(pos) is not None:
		k_ -= 1
		pos = C.next_left(pos)
		remove.append(pos)
		used[pos] = True
		group[pos] = cur + 1
	pos = i
	k_ = k
	while k_ > 0 and C.next_right(pos) is not None:
		k_ -= 1
		pos = C.next_right(pos)
		remove.append(pos)
		used[pos] = True
		group[pos] = cur + 1
	for r in remove:
		C.remove(r)
	cur = 1 - cur
ans = [str(group[k + 1]) for k in range(n)]
print(''.join(ans))


(n, k) = map(int, input().split())
students = list(map(int, input().split()))
order = sorted(range(n), key=lambda x: -students[x])
neighbours = [[t - 1, t + 1] for t in range(n)]
neighbours[-1][1] = -1
turn = 0
team = [0] * n
for i in range(n):
	if team[order[i]] == 0:
		team[order[i]] = turn % 2 + 1
		(left, right) = neighbours[order[i]]
		for _ in range(k):
			if left != -1:
				team[left] = turn % 2 + 1
				neighbours[order[i]][0] = neighbours[left][0]
				if neighbours[left][0] != -1:
					neighbours[neighbours[left][0]][1] = order[i]
				left = neighbours[left][0]
			if right != -1:
				team[right] = turn % 2 + 1
				neighbours[order[i]][1] = neighbours[right][1]
				if neighbours[right][1] != -1:
					neighbours[neighbours[right][1]][0] = order[i]
				right = neighbours[right][1]
		(left, right) = neighbours[order[i]]
		if left != -1:
			neighbours[left][1] = right
		if right != -1:
			neighbours[right][0] = left
		turn += 1
print(*team, sep='')


(N, K) = list(map(int, input().split()))
A = [int(a) - 1 for a in input().split()]
T = [0] * N
inv = [0] * N
for i in range(N):
	inv[A[i]] = i
L = [a - 1 for a in range(N)]
R = [a + 1 for a in range(N)]
c = 0
t = 2
i = N - 1
while c < N and i >= 0:
	j = inv[i]
	if T[j]:
		i -= 1
		continue
	t = 3 - t
	T[j] = t
	c += 1
	k = K
	pj = j
	while True:
		nj = L[pj]
		if k == 0 or nj < 0:
			break
		T[nj] = t
		c += 1
		k -= 1
		pj = nj
	ll = nj
	k = K
	pj = j
	while True:
		nj = R[pj]
		if k == 0 or nj >= N:
			break
		T[nj] = t
		c += 1
		k -= 1
		pj = nj
	rr = nj
	if rr < N:
		L[rr] = ll
	if ll >= 0:
		R[ll] = rr
	i -= 1
print(''.join(map(str, T)))


(n, k) = list(map(int, input().split()))
sk = list(map(int, input().split()))
new_sk = [(j, i) for (i, j) in enumerate(sk)]
new_sk = sorted(new_sk, key=lambda x: x[0], reverse=True)
prevs = [-1] * n
nexts = [-1] * n
for i in range(n):
	if i < n - 1:
		nexts[i] = i + 1
	if i > 0:
		prevs[i] = i - 1
maxi = new_sk[-1]
used = set()
i = 0
t = -1
flag = False
while i <= n:
	while new_sk[i][0] in used:
		i += 1
		if i >= n:
			flag = True
			break
	if flag:
		break
	idx = new_sk[i][1]
	maxi = new_sk[i][0]
	used.add(maxi)
	sk[idx] = t
	l = 0
	l_idx = prevs[idx]
	while l < k and l_idx != -1:
		used.add(sk[l_idx])
		sk[l_idx] = t
		l_idx = prevs[l_idx]
		l += 1
	prevs[idx] = l_idx
	r = 0
	r_idx = nexts[idx]
	while r < k and r_idx != -1:
		used.add(sk[r_idx])
		sk[r_idx] = t
		r_idx = nexts[r_idx]
		r += 1
	nexts[idx] = r_idx
	if prevs[idx] != -1:
		nexts[prevs[idx]] = nexts[idx]
	if nexts[idx] != -1:
		prevs[nexts[idx]] = prevs[idx]
	t = -1 if t == -2 else -2
for i in sk:
	if i == -1:
		print(1, end='')
	else:
		print(2, end='')


(n, k) = map(int, input().split())
bin_ = list(map(int, input().split()))
sorted_bin = []
command = [0] * n
next_ = [i for i in range(1, n)] + [-1]
prev_ = [-1] + [i for i in range(0, n - 1)]
for elem in enumerate(bin_):
	sorted_bin.append(elem)
sorted_bin.sort(key=lambda x: -x[1])
flag = 0
for (ind, value) in sorted_bin:
	if command[ind] != 0:
		continue
	command[ind] = flag + 1
	next_i = ind
	for _ in range(k):
		next_i = next_[next_i]
		if next_i != -1:
			command[next_i] = 1 + flag
		else:
			break
	prev_i = ind
	for _ in range(k):
		prev_i = prev_[prev_i]
		if prev_i != -1:
			command[prev_i] = 1 + flag
		else:
			break
	if prev_i != -1:
		prev_i = prev_[prev_i]
	if next_i != -1:
		next_i = next_[next_i]
	if prev_i != -1:
		next_[prev_i] = next_i
	if next_i != -1:
		prev_[next_i] = prev_i
	flag = 1 - flag
for i in command:
	print(i, end='')


import sys
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
A_INV = [-1] * n
for i in range(n):
	A_INV[A[i] - 1] = i
L = list(range(-1, n - 1))
R = list(range(1, n + 1))
USELIST = [0] * n
ANS = [0] * n
NOW = 1
for a in A_INV[::-1]:
	if USELIST[a] == 1:
		continue
	USELIST[a] = 1
	ANS[a] = NOW
	if 0 <= a < n and 0 <= L[a] < n:
		R[L[a]] = R[a]
	if 0 <= a < n and 0 <= R[a] < n:
		L[R[a]] = L[a]
	r = a
	for step in range(k):
		r = R[r]
		if r < 0 or r >= n:
			break
		ANS[r] = NOW
		USELIST[r] = 1
		if 0 <= r < n and 0 <= L[r] < n:
			R[L[r]] = R[r]
		if 0 <= r < n and 0 <= R[r] < n:
			L[R[r]] = L[r]
	l = a
	for step in range(k):
		l = L[l]
		if l < 0 or l >= n:
			break
		ANS[l] = NOW
		USELIST[l] = 1
		if 0 <= l < n and 0 <= L[l] < n:
			R[L[l]] = R[l]
		if 0 <= l < n and 0 <= R[l] < n:
			L[R[l]] = L[l]
	NOW = 3 - NOW
print(''.join(map(str, ANS)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
connect_node = [[-1, -1] for x in range(n)]
mark = [-1 for _ in range(n)]
completed = [0 for _ in range(n)]
done = [0 for _ in range(n)]
for i in range(n):
	mark[a[i] - 1] = i
	if i < n - 1:
		connect_node[i][1] = i + 1
	if i > 0:
		connect_node[i][0] = i - 1
total = 0
idex = n - 1
team = '1'
while total < n:
	if completed[idex] == 0:
		found = mark[idex]
	else:
		while completed[idex] != 0:
			idex -= 1
		found = mark[idex]
	completed[idex] = 1
	total += 1
	done[found] = team
	count = k
	right = connect_node[found][1]
	while right != -1 and count and (connect_node[right] != [-1, -1]):
		num = a[right]
		completed[num - 1] = 1
		done[right] = team
		total += 1
		count -= 1
		temp = right
		right = connect_node[right][1]
		connect_node[temp] = [-1, -1]
	count = k
	left = connect_node[found][0]
	while left != -1 and count and (connect_node[left] != [-1, -1]):
		num = a[left]
		completed[num - 1] = 1
		done[left] = team
		total += 1
		count -= 1
		temp = left
		left = connect_node[left][0]
		connect_node[temp] = [-1, -1]
	connect_node[found] = [-1, -1]
	if left != -1 and right != -1:
		connect_node[left][1] = right
		connect_node[right][0] = left
	else:
		connect_node[right][0] = -1
		connect_node[left][1] = -1
	if team == '1':
		team = '2'
	else:
		team = '1'
print(''.join(done))


class BitTree:

	def __init__(self, size):
		self.size = size
		self.arr = [0 for _ in range(size + 1)]

	def add(self, idx, val):
		i = idx
		while i <= self.size:
			self.arr[i] += val
			i += i & -i

	def sum(self, idx):
		ret = 0
		i = idx
		while i > 0:
			ret += self.arr[i]
			i -= i & -i
		return ret

	def find_left(self, idx, k):
		x = self.sum(idx)
		(l, r) = (1, idx)
		while l <= r:
			m = (l + r) // 2
			tmp = self.sum(idx) - self.sum(m - 1)
			if tmp > k:
				l = m + 1
			else:
				r = m - 1
		return l

	def find_right(self, idx, k):
		x = self.sum(idx)
		(l, r) = (idx, self.size)
		while l <= r:
			m = (l + r) // 2
			tmp = self.sum(m - 1) - self.sum(idx)
			if tmp < k:
				r = m - 1
			else:
				l = m + 1
		return r

def find_left(lst, ans, idx, k, tag):
	idx = lst[idx][0]
	while k > 0 and idx >= 1:
		ans[idx] = tag
		k -= 1
		idx = lst[idx][0]
	return max(idx, 0)

def find_right(lst, ans, idx, k, tag, n):
	idx = lst[idx][1]
	while k > 0 and idx <= n:
		ans[idx] = tag
		k -= 1
		idx = lst[idx][1]
	return min(idx, n + 1)

def main():
	line = input()
	(n, k) = (int(line.split(' ')[0]), int(line.split(' ')[1]))
	line = input()
	ans = ['0' for _ in range(n + 2)]
	arr = []
	lst = []
	for i in range(n + 2):
		lst.append([max(i - 1, 0), min(i + 1, n + 1)])
	for (i, val) in enumerate(line.split(' ')):
		arr.append((i + 1, int(val)))
	arr.sort(key=lambda x: x[1], reverse=True)
	tag = 1
	for item in arr:
		idx = item[0]
		if ans[idx] != '0':
			continue
		ans[idx] = str(tag)
		left = find_left(lst, ans, idx, k, str(tag))
		right = find_right(lst, ans, idx, k, str(tag), n)
		lst[left][1] = right
		lst[right][0] = left
		tag = 3 - tag
	print(''.join(ans[1:-1]))
main()


import collections
from collections import defaultdict
(n, k) = input().split()
(n, k) = [int(n), int(k)]
skills = [int(g) for g in input().split()]
indexed_list = [0] * (n + 1)
l1 = []
previous = {}
next_ = {}
for i in range(n):
	indexed_list[skills[i]] = i
	l1.append(skills[i])
	previous[i] = i - 1
	next_[i] = i + 1
group = [0] * n
i = 1
for ij in range(n, 0, -1):
	if group[indexed_list[ij]] != 0:
		continue
	group[indexed_list[ij]] = i
	(l, r) = (previous[indexed_list[ij]], next_[indexed_list[ij]])
	for p in range(k):
		if l == -1:
			break
		group[l] = i
		l = previous[l]
	for p in range(k):
		if r == n:
			break
		group[r] = i
		r = next_[r]
	if l >= 0:
		next_[l] = r
	if r < n:
		previous[r] = l
	i = 3 - i
group = ''.join(map(str, group))
print(group)


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = [0] * n
l = list(range(-1, n))
r = list(range(1, n + 2))
l[-1] = -1
r[-1] = -1
flag = 1
d = [-1] * n
for i in range(n):
	d[a[i] - 1] = i
maxv = n - 1
maxi = None
while True:
	for i in range(maxv, -1, -1):
		if d[i] >= 0:
			maxv = i
			maxi = d[i]
			d[i] = -1
			break
	else:
		break
	left = maxi
	right = maxi
	a[maxi] = 0
	ans[maxi] = flag
	for i in range(k):
		left = l[left]
		if left == -1:
			break
		ans[left] = flag
		d[a[left] - 1] = -1
		a[left] = 0
	for i in range(k):
		right = r[right]
		if right == -1 or right == n:
			break
		ans[right] = flag
		d[a[right] - 1] = -1
		a[right] = 0
	if l[left] != -1:
		r[l[left]] = r[right]
	if r[right] != -1:
		l[r[right]] = l[left]
	flag -= 1
	flag ^= 1
	flag += 1
print(*ans, sep='')


import heapq

def main():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	q = []
	for i in range(n):
		heapq.heappush(q, (-a[i], i))
	teams = [0] * n
	nextLeft = [i - 1 for i in range(n)]
	nextRight = [i + 1 for i in range(n)]
	used = [False] * n
	team = 0
	while q:
		(item, pos) = heapq.heappop(q)
		while q and used[pos]:
			(item, pos) = heapq.heappop(q)
		if used[pos]:
			break
		teams[pos] = team + 1
		used[pos] = True
		deletedLeft = 0
		currLeft = pos
		while deletedLeft < k and nextLeft[currLeft] >= 0:
			currLeft = nextLeft[currLeft]
			used[currLeft] = True
			teams[currLeft] = team + 1
			deletedLeft += 1
		deletedRight = 0
		currRight = pos
		while deletedRight < k and nextRight[currRight] < n:
			currRight = nextRight[currRight]
			used[currRight] = True
			teams[currRight] = team + 1
			deletedRight += 1
		if currLeft >= 0:
			currLeft = nextLeft[currLeft]
		if currRight < n:
			currRight = nextRight[currRight]
		if currLeft >= 0:
			nextRight[currLeft] = currRight
		if currRight < n:
			nextLeft[currRight] = currLeft
		team = (team + 1) % 2
	print(''.join(map(str, teams)))

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
aga = {}
pore = {}
d = {}
for i in range(n):
	d[lst[i]] = i
for i in range(n):
	aga[i] = i - 1
	pore[i] = i + 1
team = 1
result = [-1] * n
for i in range(n, 0, -1):
	j = d[i]
	if result[j] != -1:
		continue
	result[j] = team
	(left, right) = (aga[j], pore[j])
	for _ in range(k):
		if left == -1:
			break
		result[left] = team
		left = aga[left]
	for _ in range(k):
		if right == n:
			break
		result[right] = team
		right = pore[right]
	if left >= 0:
		pore[left] = right
	if right < n:
		aga[right] = left
	team = 3 - team
print(''.join(map(str, result)))


import math
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
res = [0] * n
l = list(range(-1, n))
r = list(range(1, n + 2))
l[-1] = -1
r[-1] = -1
flag = 1
ar_map = [-1] * n
for i in range(n):
	ar_map[ar[i] - 1] = i
max_val = n - 1
max_id = None
while True:
	for i in range(max_val, -1, -1):
		if ar_map[i] >= 0:
			max_val = i
			max_id = ar_map[i]
			ar_map[i] = -1
			break
	else:
		break
	l_id = max_id
	r_id = max_id
	ar[max_id] = 0
	res[max_id] = flag
	for _ in range(k):
		l_id = l[l_id]
		if l_id == -1:
			break
		res[l_id] = flag
		ar_map[ar[l_id] - 1] = -1
		ar[l_id] = 0
	for _ in range(k):
		r_id = r[r_id]
		if r_id == -1 or r_id == n:
			break
		res[r_id] = flag
		ar_map[ar[r_id] - 1] = -1
		ar[r_id] = 0
	if l[l_id] != -1:
		r[l[l_id]] = r[r_id]
	if r[r_id] != -1:
		l[r[r_id]] = l[l_id]
	flag = flag % 2 + 1
print(''.join(map(str, res)))


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0] * n
s = sorted(enumerate(a), key=lambda x: x[1], reverse=True)
p = 1
first = 0
last = n - 1
spaces = []
sn = 10
ssn = 100
fl = True
for i in s:
	j = i[0]
	if b[j] > 0:
		continue
	jk = k + 1
	g = 0
	while j >= first and jk > 0:
		if b[j] == 0:
			b[j] = p
			jk -= 1
		else:
			g += 1
			if fl and g > sn:
				g = 0
				fl = False
				for sp in spaces[::-1]:
					if sp[0] < j < sp[1]:
						j = sp[0]
						fl = True
						break
		j -= 1
	if jk > 0:
		first = i[0] + k
	jf = j
	j = i[0]
	jk = k
	g = 0
	while j <= last and jk > 0:
		if b[j] == 0:
			b[j] = p
			jk -= 1
		else:
			g += 1
			if fl and g > sn:
				g = 0
				fl = False
				for sp in spaces[::-1]:
					if sp[0] < j < sp[1]:
						j = sp[1]
						fl = True
						break
		j += 1
	if jk > 0:
		last = i[0] - k
	jl = j
	if jl - jf > ssn:
		spaces = [x for x in spaces if not jf <= x[0] <= x[1] <= jl]
		spaces.append((jf + 1, jl - 1))
		fl = True
	p = 1 if p == 2 else 2
print(*b, sep='')


from heapq import heappop, heapify

def get_max(l, r):
	return max(a[l:r + 1])
(n, k) = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
coaches = [set(), set()]
coach = 0
taken = 0
(l, r) = (0, 0)
still_map = {0: n - 1}
done_map_l = {}
done_map_r = {}
global_map = {}
for i in range(n):
	global_map[a[i]] = i
done = [0] * (n + 1)
h = [-(i + 1) for i in range(n)]
heapify(h)
while taken < n:
	local_max = -heappop(h)
	while done[local_max]:
		local_max = -heappop(h)
	max_index = global_map[local_max]
	(l_search, r_search) = (max_index - 1, max_index + 1)
	(l_count, r_count) = (0, 0)
	l_last = max_index
	while l_search >= 0 and l_count < k:
		if l_search in done_map_r:
			new_l_search = done_map_r[l_search] - 1
			done_map_l[done_map_r[l_search]] = l_last
			done_map_r[l_last] = done_map_r[l_search]
			l_search = new_l_search
		else:
			l_count += 1
			coaches[coach].add(l_search)
			done[a[l_search]] = 1
			taken += 1
			l_search -= 1
	r_last = l_search + 1
	while r_search < n and r_count < k:
		if r_search in done_map_l:
			new_r_search = done_map_l[r_search] + 1
			done_map_r[done_map_l[r_search]] = r_last
			done_map_l[r_last] = done_map_l[r_search]
			r_search = new_r_search
		else:
			r_count += 1
			coaches[coach].add(r_search)
			done[a[r_search]] = 1
			taken += 1
			r_search += 1
	done[local_max] = 1
	coaches[coach].add(max_index)
	taken += 1
	coach ^= 1
	done_map_l[l_search + 1] = r_search - 1
	done_map_r[r_search - 1] = l_search + 1
print(''.join(('1' if i in coaches[0] else '2' for i in range(n))))


(n, k) = [int(x) for x in input().split(' ')]
skills = [int(x) for x in input().split(' ')]
skills_sorted = sorted(skills)
skills_sorted.reverse()
dict_skills = {}
left = []
right = []
for idx in range(len(skills)):
	dict_skills[skills[idx]] = [idx, False]
	left.append(idx - 1)
	right.append(idx + 1)
right[-1] = -1
unselected = len(skills)
pointer_max = 0
turn = '2'
res = ''
while unselected > 0:
	if turn == '2':
		turn = '1'
	else:
		turn = '2'
	while pointer_max < len(skills):
		max_num = skills_sorted[pointer_max]
		if dict_skills[max_num][1] != False:
			pointer_max += 1
			max_num = skills_sorted[pointer_max]
		else:
			pointer_max += 1
			max_num_idx = dict_skills[max_num][0]
			dict_skills[max_num][1] = turn
			unselected -= 1
			break
	if unselected == 0:
		break
	left_idx = max_num_idx
	right_idx = max_num_idx
	for i in range(k):
		left_idx = left[left_idx]
		if left_idx != -1:
			dict_skills[skills[left_idx]][1] = turn
			unselected -= 1
			if unselected == 0:
				break
		else:
			break
	for i in range(k):
		right_idx = right[right_idx]
		if right_idx != -1:
			dict_skills[skills[right_idx]][1] = turn
			unselected -= 1
			if unselected == 0:
				break
		else:
			break
	if right_idx != -1:
		right_idx = right[right_idx]
	if left_idx != -1:
		left_idx = left[left_idx]
	if right_idx != -1:
		left[right_idx] = left_idx
	if left_idx != -1:
		right[left_idx] = right_idx
_str = ''
for num in skills:
	_str += dict_skills[num][1]
print(_str)


import sys
sys.setrecursionlimit(200000)

class LL(object):

	def __init__(self, val, left=None, right=None):
		self.used = False
		self.left = left
		if self.left:
			self.left.right = self
		self.right = right
		if self.right:
			self.right.left = self
		self.val = val
		self.leftc = 0
		self.rightc = 0
		self.team = -1

	def rem(self):
		if self.left:
			self.left.right = self.right
		if self.right:
			self.right.left = self.left
		self.left = self.right = None
		self.used = True

	def collect(self):
		if self.leftc and self.left:
			self.left.team = self.team
			self.left.leftc = self.leftc - 1
			tbc.append(self.left)
		if self.rightc and self.right:
			self.right.team = self.team
			self.right.rightc = self.rightc - 1
			tbc.append(self.right)
		self.rem()
		teams[self.val] = str(self.team + 1)
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, k) = kk()
ls = ll()
prev = None
d = {}
teams = [-1] * n
for (i, l) in enumerate(ls):
	d[l] = LL(i, left=prev)
	prev = d[l]
currteam = 0
tbc = []
for i in range(n, 0, -1):
	if d[i].used:
		continue
	d[i].leftc = d[i].rightc = k
	d[i].team = currteam
	tbc.append(d[i])
	while tbc:
		x = tbc.pop()
		x.collect()
	currteam ^= 1
print(''.join(teams))


(n, k) = (int(i) for i in input().split())
j = 0
ratings = [[pos, rat, 1, 1] for (pos, rat) in enumerate([int(i) for i in input().split()])]
sorted_by_rating = sorted(ratings, key=lambda r: r[1], reverse=True)
final = [0 for i in range(n)]
t = 0
for i in range(n):
	index = sorted_by_rating[i][0]
	if final[index] == 0:
		t = 1 + t % 2
		final[index] = t
		left_x = 0
		right_x = n - 1
		num = k
		x = index - 1
		while x >= 0 and num != 0:
			if final[x] == 0:
				final[x] = t
				left_x = x
				x -= ratings[x][2]
				num -= 1
			else:
				x -= ratings[x][2]
		num = k
		x = index + 1
		while x < n and num != 0:
			if final[x] == 0:
				final[x] = t
				right_x = x
				x += ratings[x][3]
				num -= 1
			else:
				x += ratings[x][3]
		ratings[left_x][3] = right_x - left_x
		ratings[right_x][2] = right_x - left_x
for i in final:
	print(i, end='')


import heapq
(n, k) = map(int, input().split())
if n == 1 or n == 2:
	print('1' * n)
	exit()
arr = list(map(int, input().split()))
ll = []
q = []
for i in range(n):
	heapq.heappush(q, (-arr[i], i))
	if i == 0:
		ll.append([-1, 1])
	elif i == n - 1:
		ll.append([n - 2, -1])
	else:
		ll.append([i - 1, i + 1])
ans = [0] * n
s = set()
flag = True
while len(q) != 0:
	(val, pos) = heapq.heappop(q)
	val *= -1
	if val in s:
		continue
	cnt = 0
	pos1 = pos
	pos2 = pos
	val1 = val
	val2 = val
	while cnt <= k and pos1 != -1:
		s.add(val1)
		if flag == True:
			ans[pos1] = 1
		else:
			ans[pos1] = 2
		pos1 = ll[pos1][1]
		val1 = arr[pos1]
		cnt += 1
	cnt = 0
	while cnt <= k and pos2 != -1:
		s.add(val2)
		if flag == True:
			ans[pos2] = 1
		else:
			ans[pos2] = 2
		pos2 = ll[pos2][0]
		val2 = arr[pos2]
		cnt += 1
	if pos1 != -1 and pos2 != -1:
		ll[pos1][0] = pos2
		ll[pos2][1] = pos1
	elif pos1 == -1 and pos2 != -1:
		ll[pos2][1] = -1
	elif pos1 != -1 and pos2 == -1:
		ll[pos1][0] = -1
	if flag == True:
		flag = False
	else:
		flag = True
print(''.join(map(str, ans)))


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
import sys
for i in range(n):
	l[i] -= 1
taken = [0] * n
place = [0] * n
nast = [i + 1 for i in range(n)]
poprz = [i - 1 for i in range(n)]
for i in range(n):
	place[l[i]] = i
best = n - 1
turn = 2
while True:
	turn = 3 - turn
	p = place[best]
	pp = p
	taken[p] = turn
	for i in range(k):
		if nast[pp] < n:
			pp = nast[pp]
			taken[pp] = turn
		else:
			pp = n
			break
	if pp < n:
		right = nast[pp]
	else:
		right = n
	pp = p
	for i in range(k):
		if poprz[pp] >= 0:
			pp = poprz[pp]
			taken[pp] = turn
		else:
			pp = -1
			break
	if pp >= 0:
		left = poprz[pp]
	else:
		left = -1
	if left > -1:
		nast[left] = right
	if right < n:
		poprz[right] = left
	while True:
		if best < 0:
			for f in taken:
				print(f, end='')
			return
		if taken[place[best]] != 0:
			best -= 1
		else:
			break


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
team = [0] * n
nxt = [x + 1 for x in range(len(a))]
nxt[-1] = n + 2 * k
prv = [x - 1 for x in range(len(a))]
prv[0] = -2 * k
loc = [0] * (len(a) + 1)
for (i, v) in enumerate(a):
	loc[v] = i
left = n
val = 1
while left > 0:
	start = loc[left]
	left = left - 1
	if team[start] > 0:
		continue
	team[start] = val
	nx = nxt[start]
	pv = prv[start]
	if pv >= 0:
		nxt[pv] = nx
	if nx < n:
		prv[nx] = pv
	ctdown = k
	while nx < n and ctdown > 0:
		team[nx] = val
		if prv[nx] >= 0:
			nxt[prv[nx]] = nxt[nx]
		if nxt[nx] < n:
			prv[nxt[nx]] = prv[nx]
		nx = nxt[nx]
		ctdown = ctdown - 1
	ctdown = k
	while pv >= 0 and ctdown > 0:
		team[pv] = val
		if prv[pv] >= 0:
			nxt[prv[pv]] = nxt[pv]
		if nxt[pv] < n:
			prv[nxt[pv]] = prv[pv]
		pv = prv[pv]
		ctdown = ctdown - 1
	val = 3 - val
print(''.join((str(x) for x in team)))


import sys
ilist = [int(i) for i in input().split()]
(n, k) = (ilist[0], ilist[1])
a = [int(i) for i in input().split()]
(left, right) = ([], [])
for i in range(n):
	left.append(i - 1)
	right.append(i + 1)
val_idx = [[a[i], i] for i in range(n)]
val_idx = sorted(val_idx, key=lambda x: x[0], reverse=True)
result = [0 for i in range(n)]
finished = 0
team = 1
for (val, idx) in val_idx:
	if finished == n:
		break
	if result[idx] != 0:
		continue
	result[idx] = team
	finished += 1
	left_k = k
	most_left = left[idx]
	while left_k > 0 and most_left >= 0:
		result[most_left] = team
		finished += 1
		most_left = left[most_left]
		left_k -= 1
	right_k = k
	most_right = right[idx]
	while right_k > 0 and most_right < n:
		result[most_right] = team
		finished += 1
		most_right = right[most_right]
		right_k -= 1
	if most_left >= 0:
		right[most_left] = most_right
	if most_right < n:
		left[most_right] = most_left
	if team == 1:
		team = 2
	else:
		team = 1
print(''.join([str(i) for i in result]))


(n, k) = map(int, input().split())
lst = map(int, input().split())

def debug():
	print('-')
	lst = [0 for _ in range(n)]
	for i in range(n):
		node = table[i]
		lst[node.index] = node.team
	print(''.join((str(x) for x in lst)))
	print('-')

class Node:

	def __init__(self, index):
		self.index = index
		self.team = 0
		self.prev = None
		self.next = None
table = [None for _ in range(n)]
prev_node = None
for (index, element) in enumerate(lst):
	node = Node(index)
	if prev_node:
		prev_node.next = node
	node.prev = prev_node
	table[element - 1] = node
	prev_node = node
team = 1
for i in reversed(range(n)):
	if table[i].team != 0:
		continue
	node = table[i]
	node.team = team
	next_node = node.next
	for j in range(k):
		if next_node is None:
			break
		next_node.team = team
		next_node = next_node.next
	prev_node = node.prev
	for j in range(k):
		if prev_node is None:
			break
		prev_node.team = team
		prev_node = prev_node.prev
	if prev_node is not None:
		prev_node.next = next_node
	if next_node is not None:
		next_node.prev = prev_node
	team = 1 if team == 2 else 2
lst = [0 for _ in range(n)]
for i in range(n):
	node = table[i]
	lst[node.index] = node.team
print(''.join((str(x) for x in lst)))


(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
list3 = list(list1)
cur = 1
list4 = [0] * n
llist = [1] * (n + 7)
rlist = [1] * (n + 7)
dict1 = {}
list5 = [1] * (n + 7)
for i in range(n):
	foo = list1[i]
	if i == 0:
		llist[foo] = -1
	else:
		llist[foo] = list1[i - 1]
	if i == n - 1:
		rlist[foo] = -1
	else:
		rlist[foo] = list1[i + 1]
	dict1[foo] = i
for r in range(n):
	key = n - r
	if list5[key] == 0:
		continue
	list2 = []
	list2.append(key)
	list5[key] = 0
	lpos = -1
	rpos = -1
	tmp = key
	for o in range(k):
		if tmp == -1:
			break
		nxt_x = llist[tmp]
		if nxt_x == -1:
			break
		list2.append(nxt_x)
		list5[nxt_x] = 0
		tmp = nxt_x
	pl_x = llist[tmp]
	tmp = key
	for o in range(k):
		if tmp == -1:
			break
		nxt_x = rlist[tmp]
		if nxt_x == -1:
			break
		list2.append(nxt_x)
		list5[nxt_x] = 0
		tmp = nxt_x
	pr_x = rlist[tmp]
	rlist[pl_x] = pr_x
	llist[pr_x] = pl_x
	for h in list2:
		if cur % 2 == 1:
			list4[dict1[h]] = 1
		if cur % 2 == 0:
			list4[dict1[h]] = 2
	cur += 1
s = ''
for g in list4:
	s += str(g)
print(s)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {a[i]: i for i in range(n)}
pre = {i: i - 1 for i in range(n)}
nxt = {i: i + 1 for i in range(n)}
ans = [-1] * n
who = 1
for i in range(n, 0, -1):
	idx = d[i]
	if ans[idx] == -1:
		ans[idx] = who
		(l, r) = (pre[idx], nxt[idx])
		for p in range(k):
			if l != -1:
				ans[l] = who
				l = pre[l]
		for p in range(k):
			if r != n:
				ans[r] = who
				r = nxt[r]
		if l >= 0:
			nxt[l] = r
		if r < n:
			pre[r] = l
		who = 3 - who
print(''.join(map(str, ans)))


inf = 10 ** 6
(n, k) = map(int, input().split())
a = [-inf] + list(map(int, input().split()))
ans = [-1] * (n + 10)
leftnext = [-1] * (n + 10)
rightnext = [-1] * (n + 10)
for i in range(1, n + 1):
	rightnext[i] = i + 1
	leftnext[i] = i - 1
visited = [False] * (n + 10)
stack = [(a[i], i) for i in range(1, n + 1)]
stack.sort()
phase = 0
loop = 0
while stack:
	loop += 1
	while stack and visited[stack[-1][1]] == True:
		stack.pop()
	if not stack:
		continue
	(value, index) = stack.pop()
	ans[index] = phase + 1
	(rightcnt, leftcnt) = (0, 0)
	(lend, rend) = (-1, -1)
	now = index
	while rightcnt <= k and now <= n:
		rightcnt += 1
		now = rightnext[now]
		if rightcnt <= k:
			visited[now] = True
			ans[now] = phase + 1
	rend = now
	now = index
	while leftcnt <= k and now >= 1:
		leftcnt += 1
		now = leftnext[now]
		if leftcnt <= k:
			visited[now] = True
			ans[now] = phase + 1
	lend = now
	leftnext[rend] = lend
	rightnext[lend] = rend
	phase += 1
	phase %= 2
print(''.join(map(str, ans[1:n + 1])))


import sys
input = sys.stdin.readline

def main():
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = []
	for (i, a) in enumerate(A):
		B.append((a, i + 1))
	B.sort()
	bit = [0] * (n + 1)

	def bit_query(i, bit):
		res = 0
		while i > 0:
			res += bit[i]
			i -= i & -i
		return res

	def bit_update(i, x, bit, n):
		while i <= n:
			bit[i] += x
			i += i & -i

	def lower_bound(x, bit, n):
		s = 0
		pos = 0
		depth = n.bit_length()
		v = 1 << depth
		for i in range(depth, -1, -1):
			k = pos + v
			if k <= n and s + bit[k] < x:
				s += bit[k]
				pos += v
			v >>= 1
		return pos + 1
	for i in range(1, n + 1):
		bit_update(i, 1, bit, n)
	ans = [0] * n
	who = 0
	while bit_query(n, bit):
		while B:
			(a, i) = B.pop()
			if bit_query(i, bit) - bit_query(i - 1, bit) == 0:
				continue
			else:
				break
		temp = []
		pos = bit_query(i, bit)
		temp.append(i)
		for d in range(1, k + 1):
			j = pos - d
			if j == 0:
				break
			else:
				p = lower_bound(j, bit, n)
				temp.append(p)
		for d in range(1, k + 1):
			j = pos + d
			if j > bit_query(n, bit):
				break
			else:
				p = lower_bound(j, bit, n)
				temp.append(p)
		for p in temp:
			bit_update(p, -1, bit, n)
			ans[p - 1] = str(1 + who)
		who = 1 - who
	print(''.join(ans))
main()


import sys

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

def slv():
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	ans = [0] * n
	v = [(s[i], i) for i in range(n)]
	v.sort(key=lambda x: x[0])
	leftperson = [i - 1 for i in range(n)]
	rightperson = [i + 1 for i in range(n)]
	seen = [False] * n
	sign = 0
	while v:
		(skill_val, idx) = v.pop()
		if seen[idx] == True:
			continue
		seen[idx] = True
		if sign == 0:
			ans[idx] = sign + 1
		else:
			ans[idx] = sign + 1
		left_addition = 0
		p = idx
		while left_addition < k and leftperson[p] >= 0:
			p = leftperson[p]
			left_addition += 1
			seen[p] = True
			ans[p] = sign + 1
		L = leftperson[p]
		right_addition = 0
		p = idx
		while right_addition < k and rightperson[p] < n:
			p = rightperson[p]
			right_addition += 1
			seen[p] = True
			ans[p] = sign + 1
		R = rightperson[p]
		if L >= 0:
			rightperson[L] = R
		if R < n:
			leftperson[R] = L
		sign ^= 1
	res = ''.join(map(lambda x: str(x), ans))
	print(res)
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


IN = input
rint = lambda : int(IN())
rmint = lambda : map(int, IN().split())
rlist = lambda : list(rmint())
(n, k) = rmint()
pr = [i for i in range(-1, n - 1)]
nx = [i for i in range(+1, n + 1)]
ans = [0] * n
p = [0] * n
i = 0
for g in rlist():
	p[n - (g - 1) - 1] = i
	i += 1

def dl(x, t):
	ans[x] = t
	if nx[x] < n:
		pr[nx[x]] = pr[x]
	if pr[x] >= 0:
		nx[pr[x]] = nx[x]
t = 1
for c in p:
	if ans[c]:
		continue
	dl(c, t)
	j = pr[c]
	for i in range(k):
		if j < 0:
			break
		dl(j, t)
		j = pr[j]
	j = nx[c]
	for i in range(k):
		if j >= n:
			break
		dl(j, t)
		j = nx[j]
	t = 3 - t
for o in ans:
	print(o, end='')


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
res = {}
avail = {}
left = {}
right = {}
left[0] = -1
for i in range(1, n):
	left[i] = i - 1
right[n - 1] = -1
for i in range(n - 1):
	right[i] = i + 1
for i in range(n):
	avail[i] = True
ls = [(ls[i], i) for i in range(n)]
ls.sort(key=lambda x: x[0])
ls.reverse()
turn = 1
for i in range(n):
	if avail[ls[i][1]] == True:
		avail[ls[i][1]] = False
		cur = ls[i][1]
		res[cur] = turn
		if left[cur] != -1:
			right[left[cur]] = right[cur]
		if right[cur] != -1:
			left[right[cur]] = left[cur]
		for _ in range(k):
			cur = right[cur]
			if cur == -1:
				break
			avail[cur] = False
			res[cur] = turn
			if left[cur] != -1:
				right[left[cur]] = right[cur]
			if right[cur] != -1:
				left[right[cur]] = left[cur]
		cur = ls[i][1]
		for _ in range(k):
			cur = left[cur]
			if cur == -1:
				break
			avail[cur] = False
			res[cur] = turn
			if left[cur] != -1:
				right[left[cur]] = right[cur]
			if right[cur] != -1:
				left[right[cur]] = left[cur]
		if turn == 1:
			turn = 2
		else:
			turn = 1
for i in range(n):
	print(res[i], end='')


from heapq import heapify, heappop

def two_teams(players, k, n):
	corresponding_team = [0] * n
	zeros = n
	t = 0
	players = [(-val, index) for (index, val) in enumerate(players)]
	heapify(players)
	max_index = n - 1
	players_left = OrderedSet([x for x in range(n)])
	while zeros > 0:
		while True:
			(_, max_index) = heappop(players)
			if corresponding_team[max_index] == 0:
				break
		add = players_left.my_iter(max_index, k)
		for p in add:
			corresponding_team[p] = t + 1
			zeros -= 1
		t = (t + 1) % 2
	return corresponding_team

class OrderedSet(object):

	def __init__(self, arr):
		self.arr = arr
		self.len = len(arr)
		self.s = set()
		self.hash_table = [None] * self.len
		self.dl = DoublyLinkedList()
		self.insert_list(arr)

	def traverse(self):
		self.dl.traverse()

	def get_hash(self, key):
		try:
			return key % self.len
		except TypeError:
			return None

	def insert_list(self, arr: list):
		for a in arr:
			index_obj = Index(a)
			self.dl.insert(index_obj)
			self.hash_table[self.get_hash(a)] = index_obj

	def remove(self, key: int):
		hash_ = self.get_hash(key)
		if hash_ >= 0 and self.hash_table[hash_]:
			index_obj = self.hash_table[hash_]
			val = index_obj.index
			self.dl.remove(index_obj)
			del index_obj
			self.hash_table[hash_] = None
			return val

	def my_iter(self, key: int, k: int):
		hash_ = self.get_hash(key)
		key_index_obj = self.hash_table[hash_]
		if not key_index_obj:
			return
		keys = [key]
		t1 = t2 = key
		for _ in range(k):
			if t1 >= 0 and self.previous(t1) >= 0:
				t1 = self.previous(t1)
				keys.append(t1)
			if t2 >= 0 and self.next(t2) >= 0:
				t2 = self.next(t2)
				keys.append(t2)
		for key in keys:
			self.remove(key)
		return keys

	def previous(self, key: int):
		hash_ = self.get_hash(key)
		if hash_ >= 0 and self.hash_table[hash_]:
			index_obj = self.hash_table[hash_]
			return self.dl.previous(index_obj)
		else:
			pass

	def next(self, key: int):
		hash_ = self.get_hash(key)
		if hash_ >= 0 and self.hash_table[hash_]:
			index_obj = self.hash_table[hash_]
			return self.dl.next(index_obj)
		else:
			pass

class Index(object):

	def __init__(self, index: int):
		self.index = index
		self.prev = None
		self.next = None

class DoublyLinkedList(object):

	def __init__(self):
		self.head = None
		self.tail = None

	def insert(self, index: Index):
		if not self.head:
			self.head = index
			self.tail = index
			return self.head
		self.tail.next = index
		index.prev = self.tail
		self.tail = index

	def remove(self, index: Index):
		if index.next == None and index.prev == None:
			self.tail = None
			self.head = None
			return None
		if self.tail == index:
			self.tail = index.prev
			self.tail.next = None
			return self.head
		if self.head == index:
			self.head = index.next
			index.next.prev = None
			return self.head
		index.prev.next = index.next
		index.next.prev = index.prev
		return self.head

	def previous(self, index: Index):
		if index and index.prev:
			return index.prev.index
		else:
			return -1

	def next(self, index: Index):
		if index and index.next:
			return index.next.index
		else:
			return -1

	def traverse(self):
		t = self.head
		while t:
			t = t.next

def main():
	l1 = [int(x) for x in input().split()]
	(n, k) = (l1[0], l1[1])
	l2 = [int(x) for x in input().split()]
	data = two_teams(l2, k, n)
	print(*data, sep='')
main()