Problem:
Sum of Sequences
Problem
n
個の要素を持つ数列
A
、
m
個の要素を持つ数列
B
、
それぞれが整数
c
からなる
q
個のクエリが与えられる。
各クエリについて、
数列
A
の[
l
a
,
r
a
]を全て足した数と数列
B
の[
l
b
,
r
b
]を全て足した数の差の絶対値が
c
になる
l
a
,
r
a
,
l
b
,
r
b
(0 ≤
l
a
≤
r
a
≤
n
−1, 0 ≤
l
b
≤
r
b
≤
m
−1, 配列の番号は0番から始まる) の組み合わせの数を求めよ。
Input
n
m
q
a
0
a
1
...
a
n−1
b
0
b
1
...
b
m−1
c
0
c
1
...
c
q−1
入力は全て整数で与えられる。
1行目に数列の要素数
n
と
m
、クエリ数
q
が与えられる。
2行目に数列
A
の要素、3行目に数列
B
の要素が空白区切りで与えられる。
4行目から
q
行に各クエリの値
c
i
が与えられる。
Constraints
1 ≤
n
,
m
≤ 4×10
4
1 ≤
q
≤ 10
5
1 ≤
a
i
,
b
i
≤ 5
0 ≤
c
i
≤ 2×10
5
Output
出力は
q
行からなる。各クエリの組み合わせの数を順番に一行に出力せよ。
Sample Input 1
3 3 1
1 2 3
3 1 2
3
Sample Output 1
6
Sample Input 2
5 4 2
1 2 3 4 5
2 2 2 2
11
12
Sample Output 2
3
4

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 25
#define MAX_N 40005
#define MAX 200000

typedef complex<double> COMPLEX;

struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
int LR_rev[1000005];
vector<Info> info;
vector<COMPLEX> V[SIZE];

int A[MAX_N],B[MAX_N];
int rui_A[MAX_N],rui_B[MAX_N];


void calc_swap_pair(int N,int num_pow){

	LR_rev[0] = 0;

	for(int i = 1; i < N; i++){

		if(i%2 == 1){

			LR_rev[i] = LR_rev[i-1]+POW[num_pow-1]; //1を足す代わりにPOW[num_pow-1]を足す

		}else{

			LR_rev[i] = LR_rev[i/2]/2; //半分のインデックスの値に、2を掛ける代わりに2で割る
		}

		if(i < LR_rev[i]){
			info.push_back(Info(i,LR_rev[i]));
		}
	}
}

void calc_COMPLEX(int N){

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		V[num_pow].resize(LEN/2);

		V[num_pow][0] = COMPLEX(cos(0),sin(0));

		COMPLEX mult = COMPLEX(cos((2*M_PI)/LEN),sin((2*M_PI)/LEN));

		for(int i = 1; i < LEN/2; i++){

			if(i%2 == 1){
				V[num_pow][i] = V[num_pow][i-1]*mult;
			}else{
				V[num_pow][i] = V[num_pow-1][i/2];
			}
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[num_pow][i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}


//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	info.clear();
	for(int i = 0; i < SIZE; i++){

		V[i].clear();
	}

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	calc_swap_pair(N,num_pow);
	calc_COMPLEX(N);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_Q;
	scanf("%d %d %d",&N,&M,&num_Q);

	rui_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&A[i]);
		rui_A[i] = A[i];
		rui_A[i] += rui_A[i-1];
	}

	vector<COMPLEX> F1(MAX+1),Q1(MAX+1);

	for(int i = 0; i <= N; i++){

		F1[rui_A[i]] += 1;
		Q1[rui_A[i]] += 1;
	}

	reverse(Q1.begin(),Q1.end());

	vector<COMPLEX> ret1 = convolution(F1,Q1);

	rui_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&B[i]);
		rui_B[i] = B[i];
		rui_B[i] += rui_B[i-1];
	}


	vector<COMPLEX> F2(MAX+1),Q2(MAX+1);


	for(int i = 0; i <= M; i++){

		F2[rui_B[i]] += 1;
		Q2[rui_B[i]] += 1;
	}

	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(F2,Q2);

	vector<COMPLEX> F3(MAX+1),Q3(MAX+1);

	for(int i = 0; i <= MAX; i++){

		if(i == 0)continue; //区間和が0を除く
		F3[i] = ret1[MAX-i];
	}
	for(int i = 0; i <= MAX; i++){

		if(i == 0)continue; //区間和が0を除く
		Q3[i] = ret2[MAX-i];
	}
	reverse(Q3.begin(),Q3.end());

	vector<COMPLEX> ANS = convolution(F3,Q3);

	int C;

	for(int loop = 0; loop < num_Q; loop++){

		scanf("%d",&C);

		if(C == 0){

			printf("%lld\n",(ll)round(ANS[MAX].real()));
		}else{

			printf("%lld\n",(ll)round(ANS[MAX-C].real())+(ll)round(ANS[MAX+C].real()));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 104440
final_rank: 2

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
int LR_rev[2000005];
vector<Info> info;
vector<COMPLEX> V[SIZE];


void calc_swap_pair(int N,int num_pow){

	LR_rev[0] = 0;

	for(int i = 1; i < N; i++){

		if(i%2 == 1){

			LR_rev[i] = LR_rev[i-1]+POW[num_pow-1]; //1を足す代わりにPOW[num_pow-1]を足す

		}else{

			LR_rev[i] = LR_rev[i/2]/2; //半分のインデックスの値に、2を掛ける代わりに2で割る
		}

		if(i < LR_rev[i]){
			info.push_back(Info(i,LR_rev[i]));
		}
	}
}

void calc_COMPLEX(int N){

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		V[num_pow].resize(LEN/2);

		V[num_pow][0] = COMPLEX(cos(0),sin(0));

		COMPLEX mult = COMPLEX(cos((2*M_PI)/LEN),sin((2*M_PI)/LEN));

		for(int i = 1; i < LEN/2; i++){

			if(i%2 == 1){
				V[num_pow][i] = V[num_pow][i-1]*mult;
			}else{
				V[num_pow][i] = V[num_pow-1][i/2];
			}
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[num_pow][i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}




//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	info.clear();
	for(int i = 0; i < SIZE; i++){

		V[i].clear();
	}

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);
	calc_COMPLEX(N);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}

	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());


	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){ //★★累積和テーブル上の区間で、left==rightは除く(空になってしまうから)★★

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)round(ret3[MAX].real()));
		}else{

			printf("%lld\n",(ll)round(ret3[MAX-tmp].real())+(ll)round(ret3[MAX+tmp].real()));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 107164
final_rank: 3

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
int LR_rev[2000005];
vector<Info> info;
vector<COMPLEX> V[SIZE];


void calc_swap_pair(int N,int num_pow){

	LR_rev[0] = 0;

	for(int i = 1; i < N; i++){

		if(i%2 == 1){

			LR_rev[i] = LR_rev[i-1]+POW[num_pow-1]; //1を足す代わりにPOW[num_pow-1]を足す

		}else{

			LR_rev[i] = LR_rev[i/2]/2; //半分のインデックスの値に、2を掛ける代わりに2で割る
		}

		if(i < LR_rev[i]){
			info.push_back(Info(i,LR_rev[i]));
		}
	}
}

void calc_COMPLEX(int N){

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		V[num_pow].resize(LEN/2);

		V[num_pow][0] = COMPLEX(cos(0),sin(0));

		COMPLEX mult = COMPLEX(cos((2*M_PI)/LEN),sin((2*M_PI)/LEN));

		for(int i = 1; i < LEN/2; i++){

			if(i%2 == 1){
				V[num_pow][i] = V[num_pow][i-1]*mult;
			}else{
				V[num_pow][i] = V[num_pow-1][i/2];
			}
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[num_pow][i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}




//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);
	calc_COMPLEX(N);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)round(ret3[MAX].real()));
		}else{

			printf("%lld\n",(ll)round(ret3[MAX-tmp].real())+(ll)round(ret3[MAX+tmp].real()));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 400
memory_kb: 107124
final_rank: 5

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
int LR_rev[2000005];
vector<Info> info;
vector<COMPLEX> V[SIZE];


void calc_swap_pair(int N,int num_pow){

	LR_rev[0] = 0;

	for(int i = 1; i < N; i++){

		if(i%2 == 1){

			LR_rev[i] = LR_rev[i-1]+POW[num_pow-1]; //1を足す代わりにPOW[num_pow-1]を足す

		}else{

			LR_rev[i] = LR_rev[i/2]/2; //半分のインデックスの値に、2を掛ける代わりに2で割る
		}

		if(i < LR_rev[i]){
			info.push_back(Info(i,LR_rev[i]));
		}
	}
}

void calc_COMPLEX(int N){

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		V[num_pow].resize(LEN/2);

		V[num_pow][0] = COMPLEX(cos(0),sin(0));

		COMPLEX mult = COMPLEX(cos((2*M_PI)/LEN),sin((2*M_PI)/LEN));

		for(int i = 1; i < LEN/2; i++){

			if(i%2 == 1){
				V[num_pow][i] = V[num_pow][i-1]*mult;
			}else{
				V[num_pow][i] = V[num_pow-1][i/2];
			}
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[num_pow][i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}




//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	if(info.size() == 0){
		calc_swap_pair(N,num_pow);
	}
	calc_COMPLEX(N);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)round(ret3[MAX].real()));
		}else{

			printf("%lld\n",(ll)round(ret3[MAX-tmp].real())+(ll)round(ret3[MAX+tmp].real()));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 107092
final_rank: 4

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
bool check[2000005];
vector<Info> info;
vector<COMPLEX> V[SIZE];


void calc_swap_pair(int N,int num_pow){

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int tmp;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		tmp = 0;

		for(int loop = 0; loop < num_pow; loop++){
			if(i & (1 << loop)){
				tmp += POW[(num_pow-1)-loop];
			}
		}

		if(i < tmp){
			info.push_back(Info(i,tmp));
			check[tmp] = true;
		}
	}
}

void calc_COMPLEX(int N){

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		V[num_pow].resize(LEN/2);

		V[num_pow][0] = COMPLEX(cos(0),sin(0));

		COMPLEX mult = COMPLEX(cos((2*M_PI)/LEN),sin((2*M_PI)/LEN));

		for(int i = 1; i < LEN/2; i++){

			if(i%2 == 1){
				V[num_pow][i] = V[num_pow][i-1]*mult;
			}else{
				V[num_pow][i] = V[num_pow-1][i/2];
			}
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;

	for(int LEN = 2,num_pow = 0; LEN <= N; LEN *= 2,num_pow++){

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[num_pow][i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}




//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);
	calc_COMPLEX(N);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)round(ret3[MAX].real()));
		}else{

			printf("%lld\n",(ll)round(ret3[MAX-tmp].real())+(ll)round(ret3[MAX+tmp].real()));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 430
memory_kb: 105556
final_rank: 6

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
bool check[5000005];
vector<Info> info;

void calc_swap_pair(int N,int num_pow){

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int tmp;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		tmp = 0;

		for(int loop = 0; loop < num_pow; loop++){
			if(i & (1 << loop)){
				tmp += POW[(num_pow-1)-loop];
			}
		}

		if(i < tmp){
			info.push_back(Info(i,tmp));
			check[tmp] = true;
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;
	vector<COMPLEX> V(N);

	for(int LEN = 2; LEN <= N; LEN *= 2){

		for(int i = 0; i < LEN/2; i++){

			V[i] = COMPLEX(cos((2*M_PI*i)/LEN),sin((2*M_PI*i)/LEN));
		}

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}



//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)round(ret3[MAX].real()));
		}else{

			printf("%lld\n",(ll)round(ret3[MAX-tmp].real())+(ll)round(ret3[MAX+tmp].real()));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 600
memory_kb: 105504
final_rank: 7

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
bool check[5000005];
vector<Info> info;

void calc_swap_pair(int N,int num_pow){

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int tmp;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		tmp = 0;

		for(int loop = 0; loop < num_pow; loop++){
			if(i & (1 << loop)){
				tmp += POW[(num_pow-1)-loop];
			}
		}

		if(i < tmp){
			info.push_back(Info(i,tmp));
			check[tmp] = true;
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;
	vector<COMPLEX> V(N);

	for(int LEN = 2; LEN <= N; LEN *= 2){

		for(int i = 0; i < LEN/2; i++){

			V[i] = COMPLEX(cos((2*M_PI*i)/LEN),sin((2*M_PI*i)/LEN));
		}

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}



//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)(ret3[MAX].real()+0.5));
		}else{

			printf("%lld\n",(ll)(ret3[MAX-tmp].real()+0.5)+(ll)(ret3[MAX+tmp].real()+0.5));
		}
	}

	return 0;
}
accuracy: 1
time_ms: 600
memory_kb: 105516
final_rank: 8

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
bool check[5000005];
vector<Info> info;

void calc_swap_pair(int N,int num_pow){

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int tmp;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		tmp = 0;

		for(int loop = 0; loop < num_pow; loop++){
			if(i & (1 << loop)){
				tmp += POW[(num_pow-1)-loop];
			}
		}

		if(i < tmp){
			info.push_back(Info(i,tmp));
			check[tmp] = true;
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;
	vector<COMPLEX> V(N);

	for(int LEN = 2; LEN <= N; LEN *= 2){

		for(int i = 0; i < LEN/2; i++){

			V[i] = COMPLEX(cos((2*M_PI*i)/LEN),sin((2*M_PI*i)/LEN));
		}

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}



//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%lld\n",(ll)(ret3[MAX].real()+0.5));
		}else{

			printf("%lld\n",(ll)(ret3[MAX-tmp].real()+0.5)+(int)(ret3[MAX+tmp].real()+0.5));
		}
	}

	return 0;
}
accuracy: 0.2
time_ms: 590
memory_kb: 105472
final_rank: 18

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
bool check[5000005];
vector<Info> info;

void calc_swap_pair(int N,int num_pow){

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int tmp;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		tmp = 0;

		for(int loop = 0; loop < num_pow; loop++){
			if(i & (1 << loop)){
				tmp += POW[(num_pow-1)-loop];
			}
		}

		if(i < tmp){
			info.push_back(Info(i,tmp));
			check[tmp] = true;
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;
	vector<COMPLEX> V(N);

	for(int LEN = 2; LEN <= N; LEN *= 2){

		for(int i = 0; i < LEN/2; i++){

			V[i] = COMPLEX(cos((2*M_PI*i)/LEN),sin((2*M_PI*i)/LEN));
		}

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}



//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%d\n",(int)(ret3[MAX].real()+0.5));
		}else{

			printf("%d\n",(int)(ret3[MAX-tmp].real()+0.5)+(int)(ret3[MAX+tmp].real()+0.5));
		}
	}

	return 0;
}
accuracy: 0.2
time_ms: 570
memory_kb: 105556
final_rank: 17

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




typedef complex<double> COMPLEX;
#define MAX 200000
#define SIZE 30

int table_A[40005],table_B[40005];


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int POW[SIZE];
bool check[5000005];
vector<Info> info;

void calc_swap_pair(int N,int num_pow){

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int tmp;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		tmp = 0;

		for(int loop = 0; loop < num_pow; loop++){
			if(i & (1 << loop)){
				tmp += POW[(num_pow-1)-loop];
			}
		}

		if(i < tmp){
			info.push_back(Info(i,tmp));
			check[tmp] = true;
		}
	}
}

//離散フーリエ変換
vector<COMPLEX> DFT(vector<COMPLEX> A) {

	int N = A.size();

	/*偶数項を左に、奇数項を右に仕分けるルールで要素数1まで仕分けした場合の、
	 * 最終結果を先に作っておく(ビットが左右反転したものがその位置に来る)*/
	for(int i = 0; i < info.size(); i++){

		swap(A[info[i].left],A[info[i].right]);
	}

	COMPLEX a,add;
	vector<COMPLEX> V(N);

	for(int LEN = 2; LEN <= N; LEN *= 2){

		for(int i = 0; i < LEN/2; i++){

			V[i] = COMPLEX(cos((2*M_PI*i)/LEN),sin((2*M_PI*i)/LEN));
		}

		for(int start = 0; start < N; start += LEN){
			for(int i = 0; i < LEN/2; i++){
				//マージソートの容量で、配列を更新していく
				a = A[start+i];
				add = V[i]*A[start+LEN/2+i];

				A[start+i] = a+add;
				A[start+LEN/2+i] = a-add;
			}
		}
	}
	return A;
}



//離散逆フーリエ変換
vector<COMPLEX> inverseDFT(vector<COMPLEX> A){

	int N = A.size();

	vector<COMPLEX> TMP = DFT(A);

	//係数を入れ替える&サイズNで各要素を割る
	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = TMP[(N-i)%N];
		RET[i] = RET[i]/COMPLEX(N,0);
	}

	return RET;
}

vector<COMPLEX> convolution(vector<COMPLEX> A,vector<COMPLEX> B){

	int degree = (A.size()-1)+(B.size()-1)+1;

	int N = 1,num_pow = 0;
	while(N < degree){
		N *= 2;
		num_pow++;
	}

	info.clear();
	calc_swap_pair(N,num_pow);

	A.resize(N);
	B.resize(N);

	A = DFT(A);
	B = DFT(B);

	vector<COMPLEX> RET(N);

	for(int i = 0; i < N; i++){

		RET[i] = A[i]*B[i];
	}

	return inverseDFT(RET);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	int N,M,num_query;

	scanf("%d %d %d",&N,&M,&num_query);

	table_A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%d",&table_A[i]);
		table_A[i] += table_A[i-1];
	}

	table_B[0] = 0;
	for(int i = 1; i <= M; i++){

		scanf("%d",&table_B[i]);
		table_B[i] += table_B[i-1];
	}


	vector<COMPLEX> P(MAX+1),Q(MAX+1),R(MAX+1);

	for(int i = 0; i <= N; i++){

		P[table_A[i]] += 1;
		Q[table_A[i]] += 1;
	}
	reverse(Q.begin(),Q.end());

	vector<COMPLEX> ret = convolution(P,Q);

	for(int i = 0; i <= MAX-1; i++){

		R[i] = ret[(MAX-1)-i];
	}

	vector<COMPLEX> P2(MAX+1),Q2(MAX+1),R2(MAX+1);

	for(int i = 0; i <= M; i++){

		P2[table_B[i]] += 1;
		Q2[table_B[i]] += 1;
	}
	reverse(Q2.begin(),Q2.end());

	vector<COMPLEX> ret2 = convolution(P2,Q2);

	for(int i = 0; i <= MAX-1; i++){

		R2[i] = ret2[(MAX-1)-i];
	}

	reverse(R2.begin(),R2.end());

	vector<COMPLEX> ret3 = convolution(R,R2);

	int tmp;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);
		if(tmp == 0){

			printf("%d\n",(int)round(ret3[MAX].real()));
		}else{

			printf("%d\n",(int)round(ret3[MAX-tmp].real())+(int)round(ret3[MAX+tmp].real()));
		}
	}

	return 0;
}
accuracy: 0.2
time_ms: 590
memory_kb: 105592
final_rank: 19

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
namespace FastFourierTransform
{
	using C = complex< double >;

	void DiscreteFourierTransform(vector< C > &F, bool rev)
	{
		const int N = (int)F.size();
		const double PI = (rev ? -1 : 1) * acos(-1);
		for (int i = 0, j = 1; j + 1 < N; j++) {
			for (int k = N >> 1; k > (i ^= k); k >>= 1);
			if (i > j) swap(F[i], F[j]);
		}
		C w, s, t;
		for (int i = 1; i < N; i <<= 1) {
			for (int k = 0; k < i; k++) {
				w = polar(1.0, PI / i * k);
				for (int j = 0; j < N; j += i * 2) {
					s = F[j + k];
					t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
						F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
					F[j + k] = s + t, F[j + k + i] = s - t;
				}
			}
		}
		if (rev) for (int i = 0; i < N; i++) F[i] /= N;
	}

	vector< long long > Multiply(const vector<long long int > &A, const vector<long long int > &B)
	{
		int sz = 1;
		while (sz <= A.size() + B.size()) sz <<= 1;
		vector< C > F(sz), G(sz);
		for (int i = 0; i < A.size(); i++) F[i] = A[i];
		for (int i = 0; i < B.size(); i++) G[i] = B[i];
		DiscreteFourierTransform(F, false);
		DiscreteFourierTransform(G, false);
		for (int i = 0; i < sz; i++) F[i] *= G[i];
		DiscreteFourierTransform(F, true);
		vector< long long > X(A.size() + B.size() - 1);
		for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
		return (X);
	}
};
const int asize = 2e5+100;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c= FastFourierTransform::Multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c= FastFourierTransform::Multiply(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<1e9);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 820
memory_kb: 29908
final_rank: 1

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+f1;
		f[1]=f0-f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+100;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<1e9);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1520
memory_kb: 50668
final_rank: 15

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+f1;
		f[1]=f0-f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<1e9);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1700
memory_kb: 50756
final_rank: 20

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+f1;
		f[1]=f0-f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<1e12);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1520
memory_kb: 50628
final_rank: 14

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+f1;
		f[1]=f0-f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<1e6);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1520
memory_kb: 50464
final_rank: 13

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+f1;
		f[1]=f0-f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<100);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1510
memory_kb: 50476
final_rank: 12

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+f1;
		f[1]=f0-f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(aaa*bbb==accumulate(ans.begin(),ans.end(),0ll));
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1400
memory_kb: 50436
final_rank: 9

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+1.0*f1;
		f[1]=f0-1.0*f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c=multiply<long long int>(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(aaa*bbb==accumulate(ans.begin(),ans.end(),0ll));
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1410
memory_kb: 50480
final_rank: 10

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+1.0*f1;
		f[1]=f0-1.0*f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}

template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	auto c=multiply(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(aaa*bbb==accumulate(ans.begin(),ans.end(),0ll));
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1420
memory_kb: 50464
final_rank: 11

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/*
?????????????????¨?????? FFT ???????????????
n?¬??????????g(x) = \sum_{i=0}^n a_i x^i , h(x) = \sum_{i=0}^n b_i x^i ???????????????
f(x) = (g*h)(x) = \sum_{k=0}^{2n} \sum_{i=0}^{k} a_i b_{k-i} x^k
???O(n log n)??§?±??????????

?????????:
g(x)????????°??? vector<T> g
h(x)????????°??? vector<T> h
??¨????????¨???
f = multiply(g, h);
??§f(x)????????°vector<T> f????±??????????

verified by: http://atc001.contest.atcoder.jp/tasks/fft_c
(AtCoder Typical Contest 001 C)

complex, vector, algorithm ?????????????????????????????????????????????
*/
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const double PI = 3.141592653589793;
/*
*
 * n?¬??????????f????????????????????¨????????????
 * is_inv = false => ?????????
 * is_inv = true  => ?????????
 * ?????????????????¨??????multiply????????§n??§?????£?????????
 */
using comp=complex<double>;
void fft(vector<comp> &f, int n, bool is_inv) {
	if (n == 1) return;
	if (n == 2) {
		comp zeta = comp(-1,0);
		comp pow_zeta = 1.0;

		comp f0(f[0]);
		comp f1(f[1]);

		f[0]=f0+1.0*f1;
		f[1]=f0-1.0*f1;
		return;
	}
	vector<comp> f0(n / 2), f1(n / 2);
	for (int i = 0; i < n / 2; i++) {
		f0[i] = f[2 * i];
		f1[i] = f[2 * i + 1];
	
	}
	fft(f0, n / 2, is_inv);
	fft(f1, n / 2, is_inv);
	comp zeta = comp(cos(2 * PI / n), sin(2 * PI / n));
	if (is_inv) zeta = 1.0 / zeta;
	comp pow_zeta = 1.0;
	for (int i = 0; i < n; i++) {
		f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
	}
}
template<typename T>
vector<T> multiply(vector<T> &g, vector<T>& h) {
	int n = 1;
	int gs = g.size();
	int hs = h.size();
	int fs = gs + hs - 1;
	while (n <= fs + 1) n *= 2;
	vector<comp> gg(n), hh(n), ff(n);
	for (int i = 0; i < n; i++) {
		gg[i] = (i < gs) ? g[i] : 0;
		hh[i] = (i < hs) ? h[i] : 0;
	}
	fft(gg, n, false);
	fft(hh, n, false);
	for (int i = 0; i < n; i++) ff[i] = gg[i] * hh[i];
	fft(ff, n, true);
	
	vector<T> f(fs);
	for (int i = 0; i < fs; i++) {
		f[i] = (T)round(ff[i].real() / n);
	}
	
	return f;
	
}
const int asize = 2e5+1;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	auto c=multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	auto c=multiply(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans;
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0l));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0l));
	auto ans(solve(a_mp,b_mp));
	//assert(num==accumulate(ans.begin(),ans.end(),0l));
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 1520
memory_kb: 50772
final_rank: 16