if let T = Int(readLine() ?? ""), let n = Int(readLine() ?? ""), let inputA = readLine(), let A = inputA.split(separator: " ").compactMap({Int($0)}) as? [Int], let m = Int(readLine() ?? ""), let inputB = readLine(), let B = inputB.split(separator: " ").compactMap({Int($0)}) as? [Int], A.count == n , B.count == m { var sumA: [Int] = [] for i in 0..= 0 { let temp = sumA[left] + sumB[right] if T > temp { left += 1 } else if T < temp { right -= 1 } else { var sameCountA = 0 let currentSumA = sumA[left] while left < sumA.count && sumA[left] == currentSumA { sameCountA += 1 left += 1 } var sameCountB = 0 let currentSumB = sumB[right] while right >= 0 && sumB[right] == currentSumB { sameCountB += 1 right -= 1 } ans += sameCountA * sameCountB } } print(ans) }