---
# System prepended metadata

title: j354. 積木對接 (Blocks)

---

# j354. 積木對接 (Blocks)
## 題目連結: [j354](https://zerojudge.tw/ShowProblem?problemid=j354)
我遇到的困難是我會把變數搞混，因為我習慣幫變數取很短的名稱，像是這次我就把變數down和d搞混，花了一段時間才看出錯誤，之後的命名要在明確一點。然後我發現用 t= 0或1(True or False) 來判斷是否有對接蠻方便的。

```python=
n = int(input())
down = list(map(int,input().split()))
m = int(input())
up = list(map(int,input().split()))
d = []
u = []

for i in range(2*n+1):
    if i % 2 == 0:
        for j in range(down[i]):
            d.append(1)
    else:
        for j in range(down[i]):
            d.append(2)
for i in range(2*m-1):
    if i % 2 == 0:
        for j in range(up[i]):
            u.append(2)
    else:
       
        for j in range(up[i]):
            u.append(1)
for i in range(len(d)-len(u)+1):
    t = 1
    for j in range(len(u)):
        
        if d[i+j]+u[j]>3:
            t = 0
    if t == 1:
        print("YES")
        break
if t == 0:
    print("NO")
```