Cucumber boy is fan of Kyubeat, a famous music game.

Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel.

Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.

You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.


-----Input-----

The first line contains a single integer k (1 ≤ k ≤ 5) — the number of panels Cucumber boy can press with his one hand.

Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit i was written on the panel, it means the boy has to press that panel in time i. If period was written on the panel, he doesn't have to press that panel.


-----Output-----

Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).


-----Examples-----
Input
1
.135
1247
3468
5789

Output
YES

Input
5
..1.
1111
..1.
..1.

Output
YES

Input
1
....
12.1
.2..
.2..

Output
NO



-----Note-----

In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
k = int(input())
panel1 = input()
panel2 = input()
panel3 = input()
panel4 = input()
can = True
for i in range(1, 10):
	counter = panel1.count(str(i)) + panel2.count(str(i)) + panel3.count(str(i)) + panel4.count(str(i))
	if counter > k * 2:
		can = False
		break
if can:
	print('YES')
else:
	print('NO')


k = int(input())
b = []
for i in range(4):
	c = input()
	b.append(c)
a = ''.join(b)
if a.count('1') > 2 * k:
	print('NO')
elif a.count('2') > 2 * k:
	print('NO')
elif a.count('3') > 2 * k:
	print('NO')
elif a.count('4') > 2 * k:
	print('NO')
elif a.count('5') > 2 * k:
	print('NO')
elif a.count('6') > 2 * k:
	print('NO')
elif a.count('7') > 2 * k:
	print('NO')
elif a.count('8') > 2 * k:
	print('NO')
elif a.count('9') > 2 * k:
	print('NO')
else:
	print('YES')


k = int(input())
l = []
c = []
for i in range(4):
	l.append(input())
for i in range(10):
	c.append(l[0].count(str(i)) + l[1].count(str(i)) + l[2].count(str(i)) + l[3].count(str(i)))
print('YES') if max(c) <= 2 * k else print('NO')


n = int(input())
l = []
flag = 0
for i in range(4):
	l1 = input()
	l.append(l1)
for i in range(1, 10):
	count = 0
	for j in l:
		count = count + j.count(str(i))
	if count > 2 * n:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')


fing = 2 * int(input())
Hit = [0] * 9
for i in range(4):
	S = input()
	for c in S:
		if c != '.':
			Hit[int(c) - 1] += 1
if max(Hit) > fing:
	print('NO')
else:
	print('YES')


c = int(input())
arr = []
for i in range(4):
	arr.append(list(input()))
count = dict()
for x in arr:
	for y in x:
		if y != '.':
			if y not in count:
				count[y] = 1
			else:
				count[y] += 1
c *= 2
dec = False
for x in count:
	if count[x] > c:
		dec = True
		break
if dec:
	print('NO')
else:
	print('YES')


from collections import Counter
I = input
k = int(I())
c = Counter(I() + I() + I() + I())
print('NO' if any((t != '.' and c[t] > 2 * k for t in c)) else 'YES')


m = int(input()) * 2
l = [input() for i in range(4)]
for i in range(1, 10):
	if sum([l[j].count(str(i)) for j in range(4)]) > m:
		exit(print('NO'))
print('YES')


k = int(input())
arr = [0] * 10
for i in range(4):
	s = input()
	for j in s:
		if j == '.':
			continue
		else:
			arr[int(j)] += 1
m = 0
for i in arr:
	m = max(m, i)
if m > 2 * k:
	print('NO')
else:
	print('YES')


k = int(input()) * 2
s = []
d = []
for i in range(16):
	d.append(0)
for i in range(4):
	s = input().split()[0]
	for j in s:
		if j != '.':
			d[int(j)] += 1
			if d[int(j)] > k:
				print('NO')
				exit()
print('YES')


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return '\n'.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
k = ii()
s = ''
for i in range(4):
	s += input()
for i in range(1, 10):
	if s.count(str(i)) > 2 * k:
		print('NO')
		exit()
print('YES')


k = input()
k = 2 * int(k)
count_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
flag = False
for i in range(4):
	line = input()
	a = [int(number) for number in line if number != '.']
	for j in range(len(a)):
		if len(a) > 0:
			count_list[a[j]] += 1
for count in count_list:
	if count > k:
		print('NO')
		flag = True
if flag == False:
	print('YES')


mao = int(input())
mao *= 2
vet = [0] * 10
flag = True
for i in range(4):
	string = input()
	for letra in string:
		try:
			vet[int(letra)] += 1
		except:
			continue
for i in range(1, 10):
	if vet[i] > mao:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


I = input
k = int(I()) * 2
s = ''
for _ in '0' * 4:
	s += I()
print('YNEOS'[any((s.count(str(i)) > k for i in range(10)))::2])


n = int(input()) * 2
d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0}
for i in range(4):
	s = list(input())
	for j in s:
		if j != '.':
			d[int(j)] += 1
flag = True
for (i, v) in d.items():
	if v > n:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


k = int(input())
c = [0] * 9
for i in range(4):
	a = input().strip()
	for i in a:
		if i != '.':
			c[int(i) - 1] += 1
if max(c) <= 2 * k:
	print('YES')
else:
	print('NO')


import sys
import bisect
from collections import Counter, defaultdict as dd

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def strl():
	return list(strsp())

def sp():
	return map(int, data().split())

def strsp():
	return map(str, data().split())
n = int(data())
a = []
for i in range(4):
	a.append(list(data()))
b = [0] * 10
b[1] += a[0].count('1') + a[1].count('1') + a[2].count('1') + a[3].count('1')
b[2] += a[0].count('2') + a[1].count('2') + a[2].count('2') + a[3].count('2')
b[3] += a[0].count('3') + a[1].count('3') + a[2].count('3') + a[3].count('3')
b[4] += a[0].count('4') + a[1].count('4') + a[2].count('4') + a[3].count('4')
b[5] += a[0].count('5') + a[1].count('5') + a[2].count('5') + a[3].count('5')
b[6] += a[0].count('6') + a[1].count('6') + a[2].count('6') + a[3].count('6')
b[7] += a[0].count('7') + a[1].count('7') + a[2].count('7') + a[3].count('7')
b[8] += a[0].count('8') + a[1].count('8') + a[2].count('8') + a[3].count('8')
b[9] += a[0].count('9') + a[1].count('9') + a[2].count('9') + a[3].count('9')
m = max(b)
if m > 2 * n:
	print('NO')
else:
	print('YES')


k = int(input())
lines = [input() for _ in range(4)]
cnt = dict()
for x in lines:
	for c in x:
		if c not in cnt:
			cnt[c] = 1
		else:
			cnt[c] += 1
if '.' in cnt:
	cnt.pop('.')
for u in cnt:
	if cnt[u] > 2 * k:
		print('NO')
		exit(0)
print('YES')


import sys
k = 2 * int(input())
string = ''
dic = {}
for i in range(4):
	string += input()
string = string.replace('.', '')
for i in string:
	if i not in dic:
		dic[i] = 1
	else:
		dic[i] += 1
for i in dic:
	if dic[i] > k:
		print('NO')
		sys.exit()
print('YES')


multi = int(input())
s = [0 for x in range(9)]
for x in range(4):
	l1 = list(input())
	for x in l1:
		if x != '.':
			s[int(x) - 1] += 1
if max(s) > 2 * multi:
	print('NO')
else:
	print('YES')


n = int(input())
tempo = {}
painel = []
boolean = True
for i in range(4):
	painel.append([int(i) for i in input() if i != '.'])
	for k in painel[i]:
		if not k in tempo:
			tempo[k] = 1
		else:
			tempo[k] += 1
for i in tempo:
	if tempo[i] > 2 * n:
		boolean = False
if boolean == False:
	print('NO')
else:
	print('YES')


k = int(input())
g = ''
for i in range(4):
	g = g + input()
valid = True
for i in range(1, 10):
	if g.count(str(i)) > 2 * k:
		valid = False
		break
if valid:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for _ in range(4):
	l.append(list(input()))
k = []
press = n * 2
for i in l:
	for j in i:
		if j != '.':
			k.append(int(j))
knew = k
knew = list(set(knew))
for xx in knew:
	if k.count(xx) > press:
		print('NO')
		break
else:
	print('YES')


class CodeforcesTask373ASolution:

	def __init__(self):
		self.result = ''
		self.k = 0
		self.panels = ''

	def read_input(self):
		self.k = int(input())
		for x in range(4):
			self.panels += input()

	def process_task(self):
		times = [str(x) for x in range(1, 10)]
		can = True
		for time in times:
			if self.panels.count(time) > self.k * 2:
				can = False
				break
		if can:
			self.result = 'YES'
		else:
			self.result = 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask373ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
a = []
c = 0
for i in range(4):
	for j in input():
		if j != '.':
			a.append(j)
for i in range(len(a)):
	a[i] = int(a[i])
for i in a:
	if a.count(i) <= 2 * n:
		continue
	else:
		c += 1
if c == 0:
	print('YES')
else:
	print('NO')


from collections import defaultdict
Panels = defaultdict(int)
Size = int(input())
for i in range(4):
	X = input()
	for i in X:
		Panels[i] += 1
if '.' in Panels.keys():
	Panels.__delitem__('.')
for i in Panels.keys():
	if Panels[i] > 2 * Size:
		print('NO')
		exit()
print('YES')


__author__ = 'asmn'
k = int(input())
cnt = dict(((i, 0) for i in range(1, 10)))
for i in range(4):
	for j in input():
		if ord('1') <= ord(j) <= ord('9'):
			cnt[ord(j) - ord('0')] += 1
print('YES' if len(list(filter(lambda x: x[1] > 2 * k, cnt.items()))) == 0 else 'NO')


k = int(input())
my_dict = {}
for _ in range(4):
	s = input()
	for i in s:
		if i.isdigit():
			if i not in my_dict:
				my_dict[i] = 0
			my_dict[i] += 1
can = True
for (key, value) in my_dict.items():
	if value > k * 2:
		can = False
		break
if can:
	print('YES')
else:
	print('NO')


3

def readln():
	return tuple(map(int, input().split()))
(k,) = readln()
cnt = {}
for c in list(''.join([input() for _ in range(4)])):
	if c != '.':
		cnt[c] = cnt.get(c, 0) + 1
print('YES' if len([1 for v in list(cnt.values()) if v <= 2 * k]) == len(cnt) else 'NO')


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter

def solve():
	k = IN() * 2
	ans = 'YES'
	d = [0 for i in range(10)]
	for i in range(4):
		s = S()
		for i in s:
			if i != '.':
				d[int(i)] += 1
				if d[int(i)] > k:
					ans = 'NO'
	print(ans)
for i in range(1):
	solve()


n = int(input())
arr = ''
for i in range(4):
	arr = arr + input()
for i in range(1, 10):
	if arr.count(str(i)) > 2 * n:
		print('NO')
		exit()
print('YES')


n = int(input())
l = [0] * 12
for u in range(4):
	s = list(input())
	for i in s:
		if i.isdigit():
			l[int(i)] += 1
for i in l:
	if i > 2 * n:
		print('NO')
		break
else:
	print('YES')


n = int(input())
a = [0] * 10
for i in range(4):
	s = input()
	for t in s:
		if t != '.':
			a[int(t)] += 1
rs = 0
for i in a:
	rs = max(rs, i)
if rs <= n * 2:
	print('YES')
else:
	print('NO')


from collections import defaultdict
n = int(input())
a = []
for i in range(4):
	x = list(input())
	a.append(x)
d = defaultdict(lambda : 0)
for i in range(len(a)):
	for j in range(len(a[i])):
		d[a[i][j]] += 1
n = 2 * n
for key in d:
	if d[key] > n and key != '.':
		print('NO')
		exit()
print('YES')


def main():
	k = int(input()) * 2
	panel = input() + input() + input() + input()
	counts = {}
	for c in panel:
		if c != '.':
			counts[c] = counts.get(c, 0) + 1
	print('YES' if len(counts) < 1 or max(counts.values()) <= k else 'NO')
main()


k = int(input())
res = 0
num = {chr(i): 0 for i in range(49, 58)}
for i in range(4):
	s = input()
	for j in s:
		if j != '.':
			num[j] += 1
for i in num.values():
	if i > k * 2:
		res = 1
		break
print('YNEOS'[res::2])


k = 2 * int(input())
l1 = input()
l2 = input()
l3 = input()
l4 = input()
times = [0, 0, 0, 0, 0, 0, 0, 0, 0]
for cont in range(0, 4):
	for tmp in range(1, 10):
		if l1[cont] == str(tmp):
			times[tmp - 1] += 1
		if l2[cont] == str(tmp):
			times[tmp - 1] += 1
		if l3[cont] == str(tmp):
			times[tmp - 1] += 1
		if l4[cont] == str(tmp):
			times[tmp - 1] += 1
l = True
for tmp in times:
	if tmp > k:
		l = False
if l == True:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for j in range(4):
	b = list(input())
	for i in range(4):
		if b[i] != '.':
			l.append(int(b[i]))
l = sorted(l)
g = 2 * n
f = True
c = 1
for i in range(1, len(l)):
	if l[i] == l[i - 1]:
		c += 1
	else:
		c = 1
	if c > g:
		f = False
if f:
	print('YES')
else:
	print('NO')


def main():
	k = int(input()) * 2
	cnt = [0] * 9
	for _ in range(4):
		for e in [int(c) for c in input() if c != '.']:
			cnt[e - 1] += 1
			if cnt[e - 1] > k:
				print('NO')
				return
	print('YES')
main()


import sys
k = int(input())
num = []
for i in range(4):
	n = input()
	for j in n:
		if j != '.':
			num.append(j)
for i in set(num):
	if num.count(i) > 2 * k:
		print('NO')
		sys.exit(0)
print('YES')


n = int(input())
n2 = n * 2
x = {}
o = 'YES'
for _ in range(4):
	r = input()
	for c in r:
		if c == '.':
			continue
		x.setdefault(c, 0)
		x[c] += 1
		if x[c] > n2:
			o = 'NO'
			break
print(o)


n = int(input())
l = []
for _ in range(4):
	l.extend(list(input()))
dots = l.count('.')
for _ in range(dots):
	l.remove('.')
for i in set(l):
	if l.count(i) > 2 * n:
		print('NO')
		exit()
print('YES')


k = int(input())
d = {}
for _ in range(4):
	for j in input():
		if j == '.':
			continue
		if j not in d:
			d[j] = 1
		else:
			d[j] += 1
		if d[j] > 2 * k:
			print('NO')
			exit()
print('YES')


k = 2 * int(input())
table = []
for i in range(4):
	table += input().strip()
t = dict()
for c in table:
	if c in t:
		t[c] += 1
	else:
		t[c] = 1
t['.'] = 0
ans = True
for kk in t:
	v = t[kk]
	if v > k:
		ans = False
print('YES' if ans else 'NO')


k = int(input())
a = [0] * 10
for i in range(4):
	s = input()
	for j in range(4):
		if s[j] != '.':
			a[int(s[j])] += 1
for ai in a:
	if ai > k * 2:
		print('NO')
		break
else:
	print('YES')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
k = L()[0]
A = [input() for i in range(4)]
d = {}
for i in range(4):
	for j in range(4):
		if A[i][j] != '.':
			d[A[i][j]] = d.get(A[i][j], 0) + 1
for ele in d:
	if d[ele] > 2 * k:
		print('NO')
		exit()
print('YES')
endtime = time.time()


k = int(input())
a = ''
for _ in range(4):
	a = a + input()
f = 1
for el in set(a):
	if el == '.':
		continue
	if a.count(el) > 2 * k:
		print('NO')
		f = 0
		break
if f:
	print('YES')


k = int(input())
L = {}
s = '.123456789'
for i in s:
	L[i] = 0
for j in range(4):
	s = input()
	for i in s:
		L[i] += 1
s = '123456789'
done = True
for i in s:
	if L[i] > 2 * k:
		print('NO')
		done = False
		break
if done:
	print('YES')


k = int(input())
A = []
B = [0] * 16
p = 0
for i in range(4):
	A.extend(list(input()))
for j in A:
	if j == '.':
		continue
	B[int(j)] += 1
for m in B:
	if m > 2 * k:
		print('NO')
		p = 1
		break
if p == 0:
	print('YES')


k = int(input())
d = {}
t = []
for i in range(10):
	d[i] = 0
for i in range(4):
	arr = input()
	t.append(arr)
for i in range(4):
	for j in range(4):
		if t[i][j] == '.':
			continue
		else:
			d[int(t[i][j])] += 1
for i in range(10):
	if d[i] > 2 * k:
		print('NO')
		break
else:
	print('YES')


k = int(input())
li = [0] * 10
for _ in range(4):
	a = input()
	for x in a:
		if x != '.':
			li[int(x)] += 1
maxm = max(li)
if maxm <= 2 * k:
	print('YES')
else:
	print('NO')


k = int(input().strip())
lst = []
valid = True
for i in range(4):
	row = list(input().strip())
	for j in range(4):
		if row[j] != '.':
			lst.append(int(row[j]))
lst.sort()
i = 0
while i < len(lst):
	count = lst.count(lst[i])
	if count > 2 * k:
		valid = False
		break
	i += count
if valid:
	print('YES')
else:
	print('NO')


k = int(input())
s = ''
for i in range(4):
	s += input()
m = max([s.count(str(i)) for i in range(1, 10)])
if m > 2 * k:
	print('NO')
else:
	print('YES')


n = int(input())
arr = [0] * 10
for _ in range(4):
	for i in list(input()):
		if i.isdigit():
			arr[int(i)] += 1
for i in arr:
	if i > 2 * n:
		print('NO')
		break
else:
	print('YES')


from collections import Counter
s = ''
h = int(input())
for _ in range(4):
	s += input()
s = s.replace('.', '')
temp = Counter(s)
f = 1
for i in range(1, 10):
	if temp[str(i)] > 2 * h:
		f = 0
		break
if f == 1:
	print('YES')
else:
	print('NO')


k = int(input())
l = [0] * 10
for i in range(4):
	for j in input():
		if j != '.':
			l[int(j)] += 1
for i in range(10):
	if l[i] > k * 2:
		print('NO')
		exit()
print('YES')


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip())
from collections import defaultdict as df
import heapq
infinite = float('inf')
n = int(input())
l = [[] for i in range(4)]
d = df(int)
for i in range(4):
	l[i] = ls()
for i in range(4):
	for j in range(4):
		d[l[i][j]] += 1
f = 0
m = 2 * n
for i in d:
	if d[i] > m and i != '.':
		f = 1
		break
if f == 0:
	print('YES')
else:
	print('NO')


k = int(input())
A = [input().strip() for i in range(4)]
cnt = [0 for i in range(10)]
flag = False
for y in range(4):
	if flag:
		break
	for x in range(4):
		c = A[y][x]
		if c == '.':
			continue
		cnt[int(c)] += 1
		if cnt[int(c)] > 2 * k:
			print('NO')
			flag = True
			break
if not flag:
	print('YES')


import sys
import math
n = int(sys.stdin.readline())
k = [0] * 9
for i in range(4):
	tt = sys.stdin.readline()
	for j in range(4):
		if tt[j] != '.':
			ind = ord(tt[j]) - ord('0') - 1
			k[ind] += 1
			if k[ind] > n * 2:
				print('NO')
				return
print('YES')


k = int(input())
k = 2 * k
jk = [0] * 10
for i in range(4):
	line = list(input())
	for j in line:
		if j != '.':
			j = int(j)
			jk[j] = jk[j] + 1
flag = 0
for i in range(10):
	if jk[i] > k:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')


import os, sys
from io import BytesIO, IOBase

def main():
	k = int(input())
	arr = [list(input().strip()) for _ in range(4)]
	x = [0] * 10
	for i in range(4):
		for j in range(4):
			if arr[i][j] != '.':
				x[int(arr[i][j])] += 1
	if max(x) > 2 * k:
		print('NO')
	else:
		print('YES')
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()


k = int(input()) * 2
l = [0] * 10
for i in range(4):
	s = input()
	for j in s:
		if j != '.':
			l[int(j)] += 1
print('NO' if max(l) > k else 'YES')


k = int(input())
arr = []
for i in range(4):
	x = input()
	for item in reversed(x):
		if item != '.':
			arr.append(item)
y = set(arr)
a = 1
for item in y:
	if arr.count(item) > 2 * k:
		a = 0
		break
	else:
		a = 1
if a == 0:
	print('NO')
else:
	print('YES')


a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
k = int(input())
for i in range(0, 4):
	b = input()
	for j in range(0, 4):
		if b[j] != '.':
			a[int(b[j])] += 1
for i in range(0, 10):
	if a[i] > k * 2:
		print('NO')
		return
print('YES')


k = int(input())
z = []
x1 = input()
for i in range(0, len(x1)):
	if x1[i] != '.':
		z.append(int(x1[i]))
	else:
		continue
x2 = input()
for l in range(0, len(x2)):
	if x2[l] != '.':
		z.append(int(x2[l]))
	else:
		continue
x3 = input()
for y in range(0, len(x3)):
	if x3[y] != '.':
		z.append(int(x3[y]))
	else:
		continue
x4 = input()
for s in range(0, len(x4)):
	if x4[s] != '.':
		z.append(int(x4[s]))
	else:
		continue
key = len(set(z))
copy = list(set(z))
count = 0
for j in range(0, len(copy)):
	if z.count(copy[j]) <= 2 * k:
		count += 1
	else:
		count = count
if count == key:
	print('YES')
else:
	print('NO')


from collections import Counter
k = int(input())
s = ''
for i in range(4):
	s += input()
s = Counter(s)
if '.' in s.keys():
	s.pop('.')
while s:
	if s.popitem()[1] > 2 * k:
		print('NO')
		break
else:
	print('YES')


n = int(input())
l = []
maxy = -1
for i in range(4):
	l.extend(input())
for i in l:
	if i == '.':
		continue
	else:
		maxy = max(l.count(i), maxy)
if maxy > n * 2:
	print('NO')
else:
	print('YES')


k = int(input())
panel = ''
for i in range(4):
	line = input()
	panel += line
keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
for key in keys:
	if panel.count(key) > k * 2:
		print('NO')
		exit()
print('YES')


k = int(input()) * 2
s = ''
for i in range(4):
	s += input()
ls = []
for c in '0123456789':
	ls.append(s.count(c))
if max(ls) > k:
	print('NO')
else:
	print('YES')


d = [0] * 10
k = int(input())
ch = True
for i in range(4):
	for c in input():
		if c != '.':
			d[int(c)] += 1
			if d[int(c)] > 2 * k:
				ch = False
print('YES' if ch else 'NO')


hit = int(input())
times = [0] * 9
for i in range(4):
	gained = input()
	for j in range(4):
		if gained[j] != '.':
			times[int(gained[j]) - 1] += 1
yes = True
for i in times:
	if i > hit * 2:
		yes = False
		break
if yes:
	print('YES')
else:
	print('NO')


k = int(input())
k *= 2
m = ''
for _ in range(0, 4):
	m += input()
for i in range(1, 10):
	if m.count(str(i)) > k:
		print('NO')
		exit(0)
print('YES')


k = int(input()) * 2
l = [list(input()) for _ in range(4)]
ll = [0 for _ in range(10)]
for i in l:
	for x in i:
		if x != '.':
			ll[int(x)] += 1
for x in ll:
	if x > k:
		print('NO')
		break
else:
	print('YES')


x = int(input())
string = ''
teste = True
for i in range(4):
	string += input('')
for i in string:
	if x * 2 < string.count(i) and i != '.':
		teste = False
		break
if teste:
	print('YES')
else:
	print('NO')


n = int(input())
m = []
for i in range(4):
	s = input()
	l = list(s)
	m.append(l)
d = {}
for i in range(4):
	for j in range(4):
		if m[i][j] != '.':
			if m[i][j] in d:
				d[m[i][j]] = d[m[i][j]] + 1
			else:
				d[m[i][j]] = 1
flag = True
for key in d:
	if d[key] > 2 * n:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


k = int(input())
n = k * 2
Range = [0 for i in range(10)]
for i in range(4):
	lst = map(int, input().replace('.', ''))
	for ii in lst:
		Range[ii] += 1
if max(Range) <= n:
	print('YES')
else:
	print('NO')


def collecting_beats_is_fun(k_int: int, beats_list: list) -> str:
	timing_dict = dict()
	for each in beats_list:
		for beat in each:
			if beat != '.':
				if timing_dict.get(beat, 0) == 0:
					timing_dict[beat] = 1
				else:
					timing_dict[beat] += 1
	for (beat, timing) in timing_dict.items():
		if timing > k_int * 2:
			return 'NO'
	return 'YES'
k = int(input())
beats = [input() for i in range(4)]
print(collecting_beats_is_fun(k, beats))


from collections import defaultdict
k = int(input())
p = defaultdict(int)
for i in range(4):
	s = input()
	for j in s:
		if j != '.':
			p[j] += 1
for i in p.keys():
	if p[i] > k * 2:
		print('NO')
		exit()
print('YES')


k = int(input())
b = input()
c = input()
d = input()
e = input()
s = b + c + d + e
a = [0] * 10
for i in s:
	if i == '0':
		a[0] = a[0] + 1
	elif i == '1':
		a[1] = a[1] + 1
	elif i == '2':
		a[2] = a[2] + 1
	elif i == '3':
		a[3] = a[3] + 1
	elif i == '4':
		a[4] = a[4] + 1
	elif i == '5':
		a[5] = a[5] + 1
	elif i == '6':
		a[6] = a[6] + 1
	elif i == '7':
		a[7] = a[7] + 1
	elif i == '8':
		a[8] = a[8] + 1
	elif i == '9':
		a[9] = a[9] + 1
d = 0
for i in a:
	if i <= k * 2:
		d = d + 1
if d == 10:
	print('YES')
else:
	print('NO')


import sys
k = int(input())
l = []
for x in range(4):
	l.append(input().strip())
k = 2 * k
count = 0
max_time = 0
for x in range(4):
	for y in range(4):
		if l[x][y] == '.':
			count += 1
		if l[x][y] != '.':
			max_time = max(max_time, int(l[x][y]))
if count == 16:
	print('YES')
	sys.exit()
possible = True
time = 1
while time <= max_time:
	count = 0
	for x in range(4):
		for y in range(4):
			if l[x][y] != '.':
				if int(l[x][y]) == time:
					count += 1
	if count > k:
		possible = False
		break
	time += 1
if possible:
	print('YES')
else:
	print('NO')


k = int(input())
x = [0 for i in range(9)]
y = []
for i in range(4):
	y.append(list(input()))
for i in range(4):
	for j in range(4):
		if y[i][j] != '.':
			x[int(y[i][j]) - 1] += 1
if max(x) > 2 * k:
	print('NO')
else:
	print('YES')


k = int(input())
a = []
for i in range(4):
	for j in input():
		if j == '.':
			continue
		else:
			a.append(j)
for i in a:
	if a.count(i) <= 2 * k:
		continue
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
n *= 2
c = [0] * 11
k = []
for i in range(4):
	k.append(input())
for i in k:
	for t in i:
		if t != '.':
			c[ord(t) - ord('0')] += 1
if max(c) > n:
	print('NO')
else:
	print('YES')


from collections import Counter
k = int(input())
panels = [int(v) for i in range(4) for v in input() if v != '.']
counts = Counter(panels)
flag = True
for key in counts:
	if counts[key] > k * 2:
		print('NO')
		flag = False
		break
if flag:
	print('YES')


n = int(input())
li = []
li1 = []
flag = 0
for i in range(4):
	ki = list(input())
	li.extend(ki)
li = filter(lambda x: x != '.', li)
for i1 in li:
	li1.append(int(i1))
for i2 in set(li1):
	if li1.count(i2) > n * 2:
		flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


k = int(input())
a = ''.join([input() for _ in [0] * 4])
print('YNEOS'[max((a.count(str(x)) for x in range(10)), default=0) > 2 * k::2])


def STR():
	return list(input())

def INT():
	return int(input())

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

def MAP2():
	return map(float, input().split())

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

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
k = INT()
x = []
for i in range(4):
	s = input()
	for j in s:
		if j != '.':
			x.append(int(j))
y = Counter(x)
z = y.values()
f = 2 * k
flag = True
for i in z:
	if i > f:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


beats = 2 * int(input())
ans = 'YES'
array = []
(row1, row2, row3, row4) = (input(), input(), input(), input())
for i in range(4):
	array
array = row1 + row2 + row3 + row4
for i in range(1, 10):
	if array.count(str(i)) > beats:
		ans = 'NO'
print(ans)


k = int(input())
panels = list(input())
for _ in range(3):
	panels.extend(list(input()))
ans = 'YES'
for i in range(1, 10):
	num = 0
	for j in range(16):
		if panels[j] != '.':
			if int(panels[j]) == i:
				num += 1
		if num > k * 2:
			ans = 'NO'
print(ans)


k = int(input())
p = {i: 0 for i in '123456789.'}
for i in range(4):
	for j in input():
		p[j] += 1
p['.'] = 0
print('YNEOS'[max(p.values()) > 2 * k::2])


n = int(input())
memo = {}
for _ in range(4):
	s = input()
	for i in s:
		if i != '.':
			if i not in memo:
				memo[i] = 1
			else:
				memo[i] += 1
res = True
for (k, v) in memo.items():
	if v > n * 2:
		res = False
if res:
	print('YES')
else:
	print('NO')


d = {}

def addDict(p):
	if p in d:
		d[p] = d[p] + 1
	elif p != '.':
		d[p] = 1
k = int(input())
for i in range(4):
	n = input()
	addDict(n[0])
	addDict(n[1])
	addDict(n[2])
	addDict(n[3])
ans = 'YES'
for i in d:
	if d[i] > k * 2:
		ans = 'NO'
		break
print(ans)


k = int(input())
l = ''
for _ in range(4):
	s = input()
	l += s
y = []
for i in l:
	if i != '.' and i not in y:
		y.append(i)
for i in y:
	if l.count(i) > 2 * k:
		print('NO')
		break
else:
	print('YES')


n = int(input(''))
p = {}
for x in range(4):
	ar1 = list(str(input('')))
	for i in ar1:
		if i != '.':
			if i in p:
				p[i] += 1
			else:
				p[i] = 1
if len(p) > 0:
	sort = sorted(p.items(), key=lambda x: x[1])
	if sort[-1][1] > 2 * n:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


k = int(input())
d = {'.': 0}
for _ in range(4):
	for c in input():
		if c == '.':
			continue
		d[c] = d.get(c, 0) + 0.5
print('NO' if max(d.values()) > k else 'YES')


from collections import deque as de
import math
import sys
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def ceildiv(x, y):
	return (x + y - 1) // y

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

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

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

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic
n = ii()
dic = {}
for i in range(4):
	for (index, value) in enumerate(input()):
		if value != '.':
			if int(value) in dic:
				dic[int(value)] += 1
			else:
				dic[int(value)] = 1
if not dic:
	print('YES')
elif max(list(dic.values())) > 2 * n:
	print('NO')
else:
	print('YES')


k = int(input())
freq = [0] * 10
for _ in range(4):
	for x in input():
		if x != '.':
			freq[int(x)] += 1
if max(freq) <= k * 2:
	print('YES')
else:
	print('NO')


k = int(input())
ans = 'YES'
panels = ''
for i in range(4):
	panels += str(input())
for i in range(1, 10, 1):
	if panels.count(str(i)) > 2 * k:
		ans = 'NO'
		break
print(ans)
exit(0)


k = int(input())
hs = [0 for i in range(10)]
for i in range(4):
	s = input()
	for j in range(4):
		if s[j] != '.':
			hs[int(s[j])] += 1
res = True
for i in range(len(hs)):
	if hs[i] > 2 * k:
		res = False
if res:
	print('YES')
else:
	print('NO')


a = int(input())
b1 = list(input())
b2 = list(input())
b3 = list(input())
b4 = list(input())
b = []
b = b + b1 + b2 + b3 + b4
if b.count('1') <= 2 * a and b.count('2') <= 2 * a and (b.count('3') <= 2 * a) and (b.count('4') <= 2 * a) and (b.count('5') <= 2 * a) and (b.count('6') <= 2 * a) and (b.count('7') <= 2 * a) and (b.count('8') <= 2 * a) and (b.count('9') <= 2 * a):
	print('YES')
else:
	print('NO')


from collections import Counter
n = int(input())
cnt = Counter()
for i in range(4):
	cnt += Counter(input())
for (a, b) in cnt.items():
	if a != '.' and b > 2 * n:
		print('NO')
		break
else:
	print('YES')


n = int(input())
panels = [y for x in [list(map(int, filter(lambda x: x != '.', list(input())))) for x in range(4)] for y in x]
times = set(panels)
for x in times:
	if n * 2 < panels.count(x):
		print('NO')
		break
else:
	print('YES')


n = int(input())
arr = []
for i in range(4):
	arr.append(input())
flag = True
for i in arr:
	for j in i:
		if j == '.':
			continue
		else:
			c = 0
			for k in arr:
				c += k.count(j)
			if c > 2 * n:
				flag = False
				break
		if not flag:
			break
	if not flag:
		break
if flag:
	print('YES')
else:
	print('NO')


k = int(input())
s = []
for i in range(4):
	a = list(input())
	s = s + a
c = [0 for i in range(9)]
for j in s:
	if j != '.':
		c[int(j) - 1] += 1
for f in c:
	if f > 2 * k:
		print('NO')
		exit()
print('YES')


n = int(input())
list1 = []
for i in range(4):
	ll = list(map(int, input().replace('.', '')))
	list1 = list1 + ll
f = 0
for i in range(1, 10):
	x = list1.count(i)
	if x > n * 2:
		f = 1
		break
if f == 0:
	print('YES')
else:
	print('NO')


k = int(input())
a = []
for i in range(4):
	s = input()
	for j in s:
		if j.isdigit():
			a.append(int(j))
for i in range(1, 10):
	if a.count(i) > k * 2:
		print('NO')
		break
else:
	print('YES')


k = int(input())
a = []
for i in range(4):
	s = str(input())
	for j in s:
		if j != '.':
			a.append(int(j))
flag = 0
for i in range(1, 10):
	if a.count(i) > 2 * k:
		flag = 1
if flag == 0:
	print('YES')
else:
	print('NO')


k = int(input())
l = []
for i in range(4):
	l.append(input())
f = []
for i in range(4):
	for j in range(4):
		if l[i][j] != '.':
			f.append(int(l[i][j]))
c = 0
k = 2 * k
x = len(f)
i = 1
while x > 0 and i <= 9:
	if f.count(i) <= k:
		x = x - f.count(i)
		i = i + 1
	else:
		c = 1
		break
if c == 1:
	print('NO')
else:
	print('YES')


k = int(input())
a = [0] * 10
for i in range(4):
	s = input()
	for j in range(4):
		if s[j] != '.':
			a[int(s[j])] += 1
ans = 'YES'
for i in range(10):
	if 2 * k < a[i]:
		ans = 'NO'
print(ans)


n = int(input())
p = []
flag = 0
for i in range(0, 4):
	p.append(input())
for i in range(1, 10):
	count = 0
	for j in range(0, 4):
		for k in range(0, 4):
			if p[j][k] != '.':
				x = int(p[j][k])
				if x == i:
					count = count + 1
	if count > 2 * n:
		flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


k = 2 * int(input())
c = ''
d = 0
for i in range(4):
	c += input()
for i in range(1, 10):
	if c.count(str(i)) > k:
		print('NO')
		d = 1
if d == 0:
	print('YES')


k = int(input())
k = 2 * k
list1 = []
for i in range(4):
	c = list(input())
	for j in range(len(c)):
		if c[j] != '.':
			c[j] = int(c[j])
			list1.append(c[j])
list1.sort()
t = 0
for i in range(len(list1)):
	a = list1[i]
	count = 2
	for j in range(len(list1)):
		if list1[i] != '.':
			if i != j and list1[j] == list1[i] and (t < list1[i]) and (count <= k):
				list1[j] = '.'
				count += 1
	if list1[i] != '.':
		if t < list1[i]:
			t = list1[i]
			list1[i] = '.'
temp = 1
for i in list1:
	if i != '.':
		print('NO')
		temp = 0
		break
if temp == 1:
	print('YES')


k = int(input())
cnt = [0] * 10
for _ in range(4):
	s = input()
	for i in s:
		if i.isdigit():
			cnt[int(i)] += 1
if any((cnt[i] > k * 2 for i in range(10))):
	print('NO')
else:
	print('YES')


def func(dic, k):
	for i in dic:
		if dic[i] > 2 * k:
			return False
	return True
dic = {}
k = int(input())
for i in range(4):
	for j in list(input()):
		if j != '.':
			if j not in dic:
				dic[j] = 1
			else:
				dic[j] += 1
if func(dic, k):
	print('YES')
else:
	print('NO')


a = int(input())
allp = ''
for i in range(4):
	allp += input()
okay = 'YES'
for i in range(9):
	if allp.count(str(i + 1)) > a * 2:
		okay = 'NO'
		break
print(okay)


nums = [0 for i in range(10)]
k = int(input())
for i in range(4):
	s = input()
	for c in s:
		if c != '.':
			nums[int(c)] += 1
if all((nums[i] <= 2 * k for i in range(10))):
	print('YES')
else:
	print('NO')


k = int(input()) * 2
cnt = [0] * 10
for i in range(4):
	s = input()
	for j in s:
		if j != '.':
			cnt[ord(j) - ord('0')] += 1
			if cnt[ord(j) - ord('0')] > k:
				print('NO')
				exit()
print('YES')


import sys
inp = sys.stdin.readline
cnt = [0] * 15
k = int(inp())
for i in range(4):
	line = inp().strip()
	for c in line:
		if c != '.':
			cnt[ord(c) - ord('0')] += 1
for x in cnt:
	if x > k * 2:
		print('NO')
		exit(0)
print('YES')


(k, s) = (int(input()), '')
for i in range(4):
	s = s + input()
for i in range(1, 10):
	if s.count(str(i)) > k * 2:
		exit(print('NO'))
print('YES')


k = 2 * int(input())
A = [0 for i in range(10)]
for i in range(4):
	s = input().replace('.', '')
	s = map(int, list(s))
	for t in s:
		A[t] += 1
if max(A) <= k:
	print('YES')
else:
	print('NO')


lst = []
z = int(input())
for i in range(4):
	x = [t for t in input() if t != '.']
	lst.extend(x)
for i in lst:
	if lst.count(i) > z * 2:
		print('NO')
		exit(0)
print('YES')


k = int(input())
L = list(input())
L += list(input())
L += list(input())
L += list(input())
L.sort()
c = True
if '.' in L:
	L = L[L.count('.'):]
for i in set(L):
	if L.count(i) > 2 * k:
		c = False
		break
if c:
	print('YES')
else:
	print('NO')


from collections import Counter
k = int(input())
string = ''
string += input()
string += input()
string += input()
string += input()
string = list(string)
string = [i for i in string if i != '.']
string = Counter(string)
count = string.most_common(1)
try:
	cnt = count[0][1]
	if cnt <= 2 * k:
		print('YES')
	else:
		print('NO')
except:
	print('YES')


n = int(input())
l = []
st = ''
for _ in range(4):
	s = input()
	st += s
	l.append(s)
arr = []
for i in range(1, 10):
	arr.append(st.count(str(i)))
f = 0
for i in arr:
	if i > 2 * n:
		f = 1
		break
if f == 0:
	print('YES')
else:
	print('NO')


b = dict.fromkeys('.123456789', 0)
k = int(input()) * 2
for i in range(4):
	for j in input():
		b[j] += 1
b.pop('.')
print('YES' if max(b.values()) <= k else 'NO')


bot = True
k = int(input()) * 2
s = ''.join((input() for _ in range(4)))
if max((s.count(c) for c in '0123456789')) > k:
	print('NO')
else:
	print('YES')


k = int(input())
counter = [0] * 10
s = ''.join([input().strip() for i in range(4)])
for c in s:
	if c == '.':
		continue
	counter[int(c)] += 1
m = max(counter)
print('NO' if m > 2 * k else 'YES')


panels = [0 for x in range(10)]
k = int(input())
tabuleiro = []
for i in range(4):
	entrada = input()
	linha = []
	for j in entrada:
		if j != '.':
			linha.append(int(j))
		else:
			linha.append(-1)
	tabuleiro.append(linha)
for i in range(4):
	for j in range(4):
		casa = tabuleiro[i][j]
		if casa != -1:
			panels[casa] += 1
possivel = True
for i in panels:
	if i > 2 * k:
		possivel = False
		break
if possivel:
	print('YES')
else:
	print('NO')


k = int(input())
a = True
arr = [0] * 10
for _ in range(0, 4):
	b = list(input())
	for i in range(0, 4):
		if b[i] != '.':
			arr[int(b[i])] += 1
for i in range(0, 10):
	if arr[i] > 2 * k:
		a = False
if a:
	print('YES')
else:
	print('NO')


k = int(input())
panels = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
flag = True
for i in range(4):
	line = input()
	for ch in line:
		if ch == '.':
			continue
		panels[ch] += 1
v = list(panels.values())
for i in v:
	if i > 2 * k:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
ptimes = {}
for i in range(4):
	a = list(map(str, input()))
	for j in a:
		if j not in '.':
			if int(j) not in ptimes.keys():
				ptimes[int(j)] = 1
			else:
				ptimes[int(j)] += 1
ans = 'YES'
for (key, item) in ptimes.items():
	if item > 2 * n:
		ans = 'NO'
		break
print(ans)


k = int(input())
data = [0] * 10
for _ in range(4):
	s = input()
	for i in s:
		if i != '.':
			data[int(i)] += 1
ans = True
for i in range(1, 10):
	if data[i] > 2 * k:
		ans = False
print('YES' if ans else 'NO')


n = int(input())
a = [input() for i in range(4)]
d = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
for i in range(4):
	for j in range(4):
		if a[i][j].isnumeric():
			x = str(a[i][j])
			d[x] += 1
flag = 1
for i in range(1, 10):
	if d[str(i)] > 2 * n:
		print('NO')
		flag = 0
		break
if flag == 1:
	print('YES')


n = int(input()) * 2
l = [0] * 10
for i in range(4):
	a = input()
	for j in a:
		if j != '.':
			l[int(j)] += 1
print('NO' if max(l) > n else 'YES')


k = int(input())
t = ''
for i in range(4):
	t += str(input())
p = list(t)
s = list(set(p))
m = 0
for j in s:
	if j != '.':
		if p.count(j) <= 2 * k:
			pass
		else:
			print('NO')
			m += 1
			break
if m == 0:
	print('YES')


(k, cnt) = (int(input()) * 2, [0] * 10)
for i in range(4):
	for ch in input():
		if ch != '.':
			cnt[int(ch)] += 1
print('NO' if max(cnt) > k else 'YES')


k = int(input())
x = input() + input() + input() + input()
print('NO' if any((x.count(i) > 2 * k for i in set(x) if i != '.')) else 'YES')


k = 2 * int(input())
s = ''
for _ in range(4):
	s += input()
s = s.replace('.', '')
for x in set(s):
	if s.count(x) > k:
		print('NO')
		break
else:
	print('YES')


import sys, os
from math import sqrt, gcd, ceil, log, floor, sin, pi
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
read_f = lambda : list(map(float, input().strip().split()))
MOD = 10 ** 9 + 7

def f(arr):
	for i in range(len(arr) - 1):
		if arr[i] == arr[i + 1]:
			return False
	return True

def main():
	k = int(input())
	d = defaultdict(int)
	arr = [input().strip() for i in range(4)]
	for i in arr:
		for j in i:
			if j != '.':
				d[j] += 1
				if d[j] > 2 * k:
					print('NO')
					return
	print('YES')
main()


def main():
	k = 2 * int(input())
	counts = {}
	for ch in '.1234567890':
		counts[ch] = 0
	for i in range(4):
		s = input()
		for ch in s:
			counts[ch] += 1
			if counts[ch] > k and ch != '.':
				print('NO')
				return
	print('YES')
main()


k = int(input()) * 2
d = {}
impossible = False
v = [input() for i in range(4)]
for i in range(4):
	for j in v[i]:
		if j in d:
			d[j] += 1
			if j != '.':
				if d[j] > k:
					impossible = True
		else:
			d[j] = 1
if impossible:
	print('NO')
else:
	print('YES')


def collecting(k):
	n = [k * 2] * 9
	for t in range(4):
		for c in input():
			if c != '.':
				i = int(c) - 1
				n[i] -= 1
				if n[i] < 0:
					print('NO')
					return
	print('YES')
	return

def main():
	k = int(input())
	collecting(k)

def __starting_point():
	main()
__starting_point()


c = [0] * 10
k = int(input()) * 2
for i in range(4):
	for ch in input():
		if ch.isdigit():
			c[int(ch) - 1] += 1
for i in range(10):
	if c[i] > k:
		print('NO')
		exit()
print('YES')


n = int(input())
a = [0] * 100
for i in range(4):
	s = input()
	for j in s:
		a[ord(j) - ord('0')] += 1
for i in range(10):
	if a[i] > n * 2:
		print('NO')
		exit()
print('YES')


def solve(arr, n):
	d = {}
	for i in arr:
		for j in i:
			if j == '.':
				continue
			if not d.get(j):
				d[j] = 1
			else:
				d[j] += 1
	for i in d:
		if d[i] > 2 * n:
			return 'NO'
	return 'YES'

def main():
	n = int(input())
	arr = []
	for _ in range(4):
		i = input()
		arr.append(i)
	print(solve(arr, n))
main()


import math
import atexit
import io
import sys
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def array_to_string(a):
	s = ''
	for i in a:
		s += str(i)
	return s
n = int(input())
d = dict()
for i in range(4):
	s = input()
	for j in s:
		if j == '.':
			continue
		val = int(j)
		if d.get(val):
			d[val] += 1
			continue
		d[val] = 1
m = n * 2
f = 0
for (k, v) in d.items():
	if v > m:
		f = 1
		break
if f == 0:
	print('YES')
else:
	print('NO')


k = int(input())
d = {}
for i in range(4):
	s = input()
	for char in s:
		if char in d:
			d[char] += 1
		else:
			d[char] = 1
for (key, value) in d.items():
	if key == '.':
		continue
	if value > 2 * k:
		print('NO')
		exit()
print('YES')


WWW = int(input()) * 2
tudo = ''
for i in range(4):
	tudo += input()
nums = {}
for k in tudo:
	if k != '.':
		if not k in nums.keys():
			nums[k] = 0
		nums[k] += 1
deu = True
for j in nums.values():
	if j > WWW:
		deu = False
if deu:
	print('YES')
else:
	print('NO')


k = int(input())
a = [list(input()) for i in range(4)]
x = [0 for i in range(10)]
for i in range(4):
	for j in range(4):
		if a[i][j] == '.':
			continue
		n = int(a[i][j])
		x[n] += 1
ok = True
for i in range(10):
	if x[i] > 2 * k:
		ok = False
if ok:
	print('YES')
else:
	print('NO')


k = int(input())
s = ''.join((input().replace('.', '') for i in range(4)))
print('NO' if len(s) > 0 and max((s.count(c) for c in set(s))) > 2 * k else 'YES')


def main():
	k = int(input()) * 2
	l = [0] * 10
	for _ in range(4):
		for c in input():
			if c != '.':
				l[int(c)] += 1
	print(('NO', 'YES')[max(l) <= k])
main()


k = 2 * int(input())
a = [0] * 9
for i in range(4):
	l = [d for d in input()]
	for j in l:
		if j != '.':
			a[int(j) - 1] += 1
if k >= max(a):
	print('YES')
else:
	print('NO')


import math
from fractions import Fraction as frac

def solve(case_no):
	n = int(input())
	a = []
	for i in range(4):
		temp = str(input())
		a.append(temp)
	cnt = [0 for i in range(100)]
	for i in range(4):
		for j in range(4):
			if 48 <= ord(a[i][j]) & ord(a[i][j]) <= 57:
				cnt[ord(a[i][j]) - 48] += 1
	for i in range(10):
		if cnt[i] > n * 2:
			print('NO')
			return
	print('YES')
t = 1
for i in range(1, t + 1):
	solve(i)


from collections import Counter
k = int(input())
s = ''
for i in range(4):
	s += input()
if s.count('.') == len(s):
	print('YES')
	exit()
s = s.replace('.', '')
print(['YES', 'NO'][Counter(s).most_common()[0][1] > 2 * k])


def check(dic, k):
	for ele in dic:
		if dic[ele] > 2 * k:
			return 'NO'
	return 'YES'
k = int(input())
mat = []
dic = {0: 1}
for i in range(4):
	temp = list(input())
	mat.append(temp)
for i in range(4):
	for j in range(4):
		if mat[i][j] not in dic and mat[i][j] != '.':
			dic[mat[i][j]] = 1
		elif mat[i][j] in dic and mat[i][j] != '.':
			dic[mat[i][j]] += 1
		else:
			dic[mat[i][j]] = 1
print(check(dic, k))


import sys

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

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
mat = []
for i in range(4):
	mat.append(list(input()))
mydict = dict()
for i in range(4):
	for j in range(4):
		mydict[mat[i][j]] = mydict.get(mat[i][j], 0) + 1
for i in mydict:
	if i != '.' and mydict[i] > 2 * n:
		print('NO')
		exit()
print('YES')


import collections
k = int(input())
d = collections.defaultdict(int)
ans = 'YES'
for i in range(4):
	s = input()
	for ch in s:
		if ch != '.':
			d[ch] += 1
			if d[ch] > 2 * k:
				ans = 'NO'
print(ans)


k = int(input())
a = []
for i in range(4):
	a.extend([str(X) for X in input()])
f = 0
for i in range(1, 10):
	i = str(i)
	if a.count(i) > 2 * k:
		print('NO')
		f = 1
		break
if f == 0:
	print('YES')


K = int(input())
panels = [None] * 4
for i in range(4):
	panels[i] = input()
all_hands = K * 2
digits_lis = [0] * 9
for i in range(4):
	digits_lis[0] += panels[i].count('1')
	digits_lis[1] += panels[i].count('2')
	digits_lis[2] += panels[i].count('3')
	digits_lis[3] += panels[i].count('4')
	digits_lis[4] += panels[i].count('5')
	digits_lis[5] += panels[i].count('6')
	digits_lis[6] += panels[i].count('7')
	digits_lis[7] += panels[i].count('8')
	digits_lis[8] += panels[i].count('9')
if max(digits_lis) > all_hands:
	print('NO')
else:
	print('YES')


k = int(input())
count = {i: 0 for i in '123456789.'}
for i in range(4):
	for string in input():
		count[string] += 1
count['.'] = 0
if max(count.values()) > 2 * k:
	print('NO')
else:
	print('YES')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
k = int(input())
panels = []
for i in range(4):
	panels.append(input())
timeMap = {}
poss = True
for row in panels:
	for char in row:
		if char == '.':
			continue
		timeMap[char] = timeMap.get(char, 0) + 1
		if timeMap[char] > k * 2:
			poss = False
if poss:
	print('YES')
else:
	print('NO')


k = int(input())
digs = [input() for i in range(4)]
digs = ''.join(digs)
ans = [digs.count(str(i)) for i in range(10)]
if max(ans) > k * 2:
	print('NO')
else:
	print('YES')


k = int(input())
b = {}
for i in range(4):
	s = input()
	for i in s:
		if i in b:
			b[i] += 1
		else:
			b[i] = 1

def fn(b):
	for i in b:
		if i != '.' and b[i] > 2 * k:
			return 'NO'
	return 'YES'
print(fn(b))


k = int(input())
a = ''
dictt = {}
flag = True
for _ in range(4):
	a += input()
for w in a:
	if w in dictt:
		dictt[w] += 1
	else:
		dictt[w] = 1
for (i, j) in dictt.items():
	if i == '.':
		continue
	elif dictt[i] > k * 2:
		flag = False
		break
	else:
		continue
if flag == True:
	print('YES')
else:
	print('NO')


k = int(input())
a = [0] * 9
for i in range(4):
	l1 = list(input())
	for item in l1:
		if item != '.':
			a[int(item) - 1] += 1
if max(a) <= 2 * k:
	print('YES')
else:
	print('NO')


from collections import Counter
k = int(input())
a = ''
for i in range(4):
	s = input()
	s = s.replace('.', '')
	a = a + s
d = Counter(a)
flag = 0
for i in d:
	if d[i] > 2 * k:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


def solve(l, k):
	for i in l:
		if i > 2 * k:
			return 'NO'
	return 'YES'
k = int(input())
count = [0 for x in range(10)]
for _ in range(4):
	s = input()
	for i in range(4):
		if s[i] != '.':
			count[int(s[i])] += 1
print(solve(count, k))


k = int(input())
result = True
dp = dict()
for i in range(4):
	s = list(input())
	for j in s:
		if j in dp.keys():
			dp[j] += 1
			continue
		dp[j] = 1
for i in dp.keys():
	if dp[i] > k * 2 and i != '.':
		result = False
		break
if result:
	print('YES')
else:
	print('NO')


k = int(input())
table = [0] * 10
for i in range(4):
	for j in input():
		try:
			table[int(j)] += 1
		except:
			pass
if max(table) <= k * 2:
	print('YES')
else:
	print('NO')


k = int(input())
book = {'0': 0}
for _ in range(4):
	line = list(str(input()))
	for it in line:
		if it != '.':
			book[it] = book.setdefault(it, 0) + 1
print('NO') if max(book.values()) > 2 * k else print('YES')


k = int(input())
s = ''
n = list()
for i in range(4):
	a = input()
	s = s + a
for i in range(1, 10):
	n.append(s.count(str(i)))
if max(n) > 2 * k:
	print('NO')
else:
	print('YES')


k = int(input())
a = []
d = {}
for _ in range(4):
	for i in input():
		if i != '.':
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
if d:
	if d[0][1] <= k * 2:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


import sys
panels_per_hand = int(input())
panels = []
for x in range(4):
	panels.append(input())
panel_string = ''
for x in panels:
	panel_string += x
freq = None
for x in panel_string:
	if x == '.':
		continue
	freq = 0
	for y in panel_string:
		if x == y:
			freq += 1
	if freq > 2 * panels_per_hand:
		print('NO')
		sys.exit(0)
print('YES')


k = int(input())
k = 2 * k
L = [0 for i in range(10)]
for i in range(4):
	l = list(input())
	for j in range(4):
		if l[j] != '.':
			L[int(l[j])] += 1
co = True
for i in range(1, 10):
	if L[i] > k:
		print('NO')
		co = False
		break
if co:
	print('YES')


flatten = lambda x: [i for row in x for i in row]
n = int(input())
p = []
for _ in range(4):
	p.append(input())
p = flatten(p)
count_list = []
for i in range(1, 10):
	count_list.append(p.count(str(i)))
flag = True
for i in range(9):
	if count_list[i] > 2 * n:
		flag = False
		break
print('YES' if flag else 'NO')


from collections import Counter
k = int(input(''))
total_capacity = 2 * k
panels = str()
for i in range(4):
	panels = panels + input()
count = Counter(panels)
del count['.']
flag = True
for key in count:
	if count[key] > total_capacity:
		print('NO')
		exit()
if flag == True:
	print('YES')


from collections import Counter
k = int(input())
b = Counter()
for i in range(4):
	for j in input().rstrip():
		if 48 <= ord(j) <= 57:
			b[int(j)] += 1
ans = 'YES'
for i in b:
	if b[i] > 2 * k:
		ans = 'NO'
		break
print(ans)