정렬, 딕셔너리 이용했음.
from collections import defaultdict
n = int(input())
aNo = int(input())
a = list(map(int, input().split()))
bNo = int(input())
b = list(map(int, input().split()))
aSum = defaultdict(int)
answer = 0
for i in range(aNo):
for j in range(aNo):
if i<=j:
aSum[sum(a[i:j+1])]+=1
for i in range(bNo):
for j in range(bNo):
if i<=j:
answer+=aSum[n-sum(b[i:j+1])]
print(answer)