一、内容

You are given an array a of length n and array b of length m both consisting of only integers 0 and 1. Consider a matrix c of size n×m formed by following rule: ci,j=ai⋅bj (i.e. ai multiplied by bj). It's easy to see that cconsists of only zeroes and ones too.How many subrectangles of size (area) kconsisting only of ones are there in c?A subrectangle is an intersection of a consecutive (subsequent) segment of rows and a consecutive (subsequent) segment of columns. I.e. consider four integers x1,x2,y1,y2(1≤x1≤x2≤n, 1≤y1≤y2≤m) a subrectangle c[x1…x2][y1…y2] is an intersection of the rows x1,x1+1,x1+2,…,x2 and the columns y1,y1+1,y1+2,…,y2  The size (area) of a subrectangle is the total number of cells in it.

Input

The first line contains three integers n, m and k (1≤n,m≤40000,1≤k≤n⋅m), length of array a, length of array band required size of subrectangles.The second line contains nintegers a1,a2,…,an (0≤ai≤1), elements of aThe third line contains mintegers b1,b2,…,bm (0≤bi≤1), elements of b

.

Output

Output single integer — the number of subrectangles of cwith size (area) k   consisting only of ones.

Examples

Input

3 3 2
1 0 1
1 1 1

Output

4

Input

3 5 4
1 1 1
1 1 1 1 1

Output

14

二、思路


  • ca[i] 代表 a[]数组中连续1的个数为i的片段有多少个。 cb[i]代表b[]数组。
  • 那么一个矩形 代表x * y , 我们要求面积为k, 那么必然 x * y = k 。
  • 我们只需要在ca里面寻找 x ,在cb里面寻找y即可。 比如 k = 4, 那么ca[1] * cb[4] 就是面积为4的矩形。

三、代码

#include <cstdio>
#include <cstring>
using namespace std;
const int N = 4e4 + 5;
typedef long long ll;
int n, m, k;
int a[N], b[N];
ll ca[N], cb[N];
void get(int a[], ll ca[], int n) { //获取连续的1的个数
int i = 1, t = 0;
while (i <= n) {
//统计连续1的长度
if (a[i] == 0){ i++; continue;}
int j = 0;
while (i <= n && a[i] == 1) j++, i++;
//将连续1的长度累加到ca中
for (int k = 1; k <= j; k++) ca[k] += j - k + 1;
}
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
get(a, ca, n);
get(b, cb, m);
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (k % i || (k / i > m)) continue;
if (ca[i]) ans += cb[k / i] * ca[i];
}
printf("%lld", ans);
return 0;
}