#include <iostream>
#include <limits.h>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
#pragma region 상하좌우 / 위치
const pair<int, int> dir[]
{
{ 1, 0 },
{ -1, 0 },
{ 0, -1 },
{ 0, 1 },
};
#define _y first
#define _x second
#pragma endregion
#pragma region 빠른 입출력
#define FAST_IO() \
{\
ios::sync_with_stdio(false);\
cin.tie(NULL); \
cout.tie(NULL); \
}\
#pragma endregion
int main()
{
FAST_IO();
vector<int> a, b, v, w;
int t, n;
cin >> t >> n;
a.resize(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int m;
cin >> m;
b.resize(m);
for (int i = 0; i < m; i++)
cin >> b[i];
// a로 만들 수 있는 부분합
for (int i = 0; i < n; i++)
{
int sum = a[i];
v.push_back(sum);
for (int j = i + 1; j < n; j++)
{
sum += a[j];
v.push_back(sum);
}
}
// b로 만들 수 있는 부분합
for (int i = 0; i < m; i++)
{
int sum = b[i];
w.push_back(sum);
for (int j = i + 1; j < m; j++)
{
sum += b[j];
w.push_back(sum);
}
}
sort(w.begin(), w.end());
long long ans = 0;
for (auto item : v)
{
int diff = t - item;
auto s = w.begin(), e = w.end();
auto ub = upper_bound(s, e, diff);
auto lb = lower_bound(s, e, diff);
ans += (ub - lb);
}
cout << ans;
}