-
Notifications
You must be signed in to change notification settings - Fork 0
/
1462B.py
48 lines (42 loc) · 920 Bytes
/
1462B.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#######puzzleVerma#######
import sys
import math
mod = 10**9+7
LI=lambda:[int(k) for k in input().split()]
input = lambda: sys.stdin.readline().rstrip()
IN=lambda:int(input())
S=lambda:input()
r=range
for t in r(IN()):
n=IN()
s=S()
if n<4:
print("NO")
continue
if s[:4]=="2020":
print("YES")
elif s[-4:]=="2020":
print("YES")
else:
tar="2020"
ans=0
for i in range(4):
if s[i]==tar[i]:
ans+=1
else:
break
if ans==4:
print("YES")
else:
rest=4-ans
tar="0202"
tar=tar[:rest]
for i in range(rest):
if s[n-1-i]==tar[i]:
ans+=1
else:
break
if ans==4:
print("YES")
else:
print("NO")