---
# System prepended metadata

title: j354. 積木對接 (Blocks)

---

# j354. 積木對接 (Blocks)
## 題目連結: [j354](https://zerojudge.tw/ShowProblem?problemid=j354)

## 解題想法
* 先把輸入資料轉換成兩個陣列，1代表凸起; 2代表凹下
* 拿短的去接長的，從頭試看看可不可以
* 如果短的是0，沒問題; 如果短的是1長的是0; 沒問題，其他都有問題

## 程式碼
```py=
# 轉換輸入資料
nlong = int(input())
a = [int(i) for i in input().split()]
nshort = int(input())
b = [int(i) for i in input().split()]

long = []
spark = False
for i in range(len(a)):
    if spark == True:
        for j in range(a[i]): long.append(1)
        spark = False
    else:
        for j in range(a[i]): long.append(0)
        spark = True
short = []
spark = True
for i in range(len(b)):
    if spark == True:
        for j in range(b[i]): short.append(1)
        spark = False
    else:
        for j in range(b[i]): short.append(0)
        spark = True
    
        
#start
isprint = False
idx = 0
while idx <= len(long) - len(short):
    for i in range(len(short)):
        if short[i] == 0: pass
        elif long[i+idx] == 0: pass
        else: break

        if i == len(short)-1:
            print("YES")
            isprint = True
            idx = len(long)

    idx += 1
    
if isprint == False: print("NO")

```