There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission. 

Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k_1 knights with lightsabers of the first color, k_2 knights with lightsabers of the second color, ..., k_{m} knights with lightsabers of the m-th color. Help her find out if this is possible.


-----Input-----

The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k_1, k_2, ..., k_{m} (with $1 \leq \sum_{i = 1}^{m} k_{i} \leq n$) – the desired counts of lightsabers of each color from 1 to m.


-----Output-----

Output YES if an interval with prescribed color counts exists, or output NO if there is none.


-----Example-----
Input
5 2
1 1 2 2 1
1 2

Output
YES

Difficulty: interview

Starter code:

Solutions:
s = input().split()
n, m = int(s[0]), int(s[1])
cl = list(map(int, input().split()))
com = list(map(int, input().split()))
res = False
for i in range(n):
  for j in range(i, n):
    e = True
    t = cl[i:j+1]
    for k in range(1, m+1):
      e = t.count(k)==com[k-1] and e
    if e:
      res = True
      break
    
if res: print('YES')
else: print('NO')

from collections import Counter


n, m = list(map(int, input().split()))

ns = list(map(int, input().split()))
ms = list(map(int, input().split()))

target = Counter({i: m for i, m in enumerate(ms, 1) if m != 0})


def check():
    for i in range(n - summs + 1):
        if target == Counter(ns[i:i + summs]):
            return True
    return False


summs = sum(ms)
print(['NO', 'YES'][check()])


import sys

n, m = [int(x) for x in input().split(' ')]
arr = [int(x)-1 for x in input().split(' ')]
k = [int(x) for x in input().split(' ')]

summ = 0
for i in range(m):
	summ += k[i]

for i in range(n):
	if i >= summ:
		k[arr[i-summ]] += 1
	k[arr[i]] -= 1
	done = True
	for j in range(m):
		if k[j] != 0:
			done = False
	if done:
		print('YES')
		return
print('NO')

n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
for i in range(n):
    for j in range(i + 1, n + 1):
        cur = a[i:j]
        c = [0] * m
        for l in cur:
            c[l - 1] += 1
        if c == k:
            print("YES")
            return
print("NO")
            


n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(k)
for i in range(n - s + 1):
    v = [0] * m
    for j in range(i, i + s):
        v[c[j] - 1] += 1
    if v == k:
        print('YES')
        return
print('NO')

import sys

n, m = map(int, input().split())

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

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

c = 0
s = sum(k)

if m==1:
	if a.count(1)==k[0] or k[0] in a:
		print("YES")
	else:
		print("NO")
	return

for i in range(n):
		
	if i+s-1<=n-1:
		k0 = [0]*m
		for j in a[i:i+s]:
			k0[j-1]+=1
	

		if k0==k:
			print("YES")
			return

print("NO")

from collections import Counter

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

s = sum(k)

C_orig = {i + 1: k[i] for i in range(m)}

for k in set(range(1, m + 1)):
    if C_orig[k] == 0:
        del C_orig[k]

C = Counter(c[:s])

if C == C_orig:
    print('YES')
    return

for i in range(n - s):
    C[c[i]] -= 1

    if C[c[i]] == 0:
        del C[c[i]]

    C[c[i + s]] += 1

    if C == C_orig:
        print('YES')
        return

print('NO')


n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(k)
for i in range(n-s+1):
    v = [0] * m
    for j in range(i, i+s):
        v[c[j]-1]+=1
    if v == k:
        print('YES')
        return
print('NO')


n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(k)
for i in range(n-s+1):
    v = [0] * m
    for j in range(i, i+s):
        v[c[j]-1]+=1
    if v == k:
        print('YES')
        return
print('NO')


n, m = list(map(int,input().split()))
a = list(map(int,input().split()))
z = list(map(int,input().split()))
ch = 0
if  n == sum(z):
    t = 0
    for i in a:
        z[i-1] -= 1
    if z.count(0) == m:
        print('YES')
    else:
        print('NO')

else:
    for i in range(n-sum(z)+1):
        t = 0
        for j in range(1,m+1):
            if a[i:i+sum(z)].count(j) == z[j-1]:
                t+=1
        if t == m:
            print('YES')
            ch = 1
            break
    if ch == 0:
        print('NO')


n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
s = sum(k)
for i in range(n - s + 1):
    v = [0] * m
    for j in range(i, i + s):
        v[c[j] - 1] += 1
    if v == k:
        print('YES')
        return
print('NO')

n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(m):
    for j in range(b[i]):
        c.append(i+1)
flag=1 
for i in range(n-len(c)+1):
    temp=a[i:i+len(c)]
    if(sorted(temp)==sorted(c)):
        print("YES")
        flag=0
        break
if flag:
    print("NO")
    
    


n,m=map(int,input().split())
a=input().split()
for i in range(n):
    a[i]=int(a[i])
k=input().split()
for i in range(m):
    k[i]=int(k[i])
sum1=sum(k) 
b=[]
c=[0 for i in range(m)]
flag=False
for i in range(n):
    if(len(b)<sum1):
        b.append(a[i])
        c[a[i]-1]+=1
    elif(len(b)==sum1):
        if(c==k):
            flag=True
        c[b[0]-1]-=1
        b.pop(0)
        b.append(a[i])
        c[a[i]-1]+=1
if(c==k):flag=True        
if(flag):print("YES")
else:print("NO")

n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sum(b)
d=[0]*m
for i in range(c):
    d[a[i]-1]+=1
e=0
for i in range(n-c+1):
    if i!=0:
        d[a[i-1]-1]-=1
        d[a[i+c-1]-1]+=1
    if d==b:
        e=1
        break
if e==0:
    print("NO")
else:
    print("YES")

n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
t=list(map(int,input().split()))
x=sum(t)
for i in range(n-x+1):
    freq=[0]*m
    for j in range(i,i+x):
        freq[a[j]-1]+=1
    flag=True
    for j in range(m):
        if freq[j]!=t[j]:
            flag=False
            break 
    if flag:
        break
if flag:
    print("YES")
else:
    print("NO")