#include <stdio.h>
#include <string.h>

#define N	100000
#define M	100000
#define A	200000
#define L_	18	/* L_ = ceil(log2(A + 1)) */
#define N_	(1 << L_)
#define M0	469762049	/* M0 = 56 * 2^23 + 1 */
#define M1	595591169	/* M1 = 71 * 2^23 + 1 */

int MM[2] = { M0, M1 };

long long power(int a, int k, int md) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % md;
		b = b * b % md;
		k >>= 1;
	}
	return p;
}

int wu[2][L_ + 1], wv[2][L_ + 1], VV[2], V01;

void init() {
	int g, l, u, v;

	V01 = power(M0, M1 - 2, M1);
	for (g = 0; g < 2; g++) {
		int md = MM[g];

		u = power(3, md - 1 >> L_, md), v = power(u, md - 2, md);
		VV[g] = power(N_, md - 2, md);
		for (l = L_; l > 0; l--) {
			wu[g][l] = u, wv[g][l] = v;
			u = (long long) u * u % md, v = (long long) v * v % md;
		}
	}
}

void ntt(int *aa, int g, int inverse) {
	int md = MM[g], i, j, l, r;

	for (i = 0, j = 1; j < N_; j++) {
		int n, tmp;

		n = N_ >> 1;
		while ((i ^= n) < n)
			n >>= 1;
		if (i < j)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	for (l = 1; l <= L_; l++) {
		int n = 1 << l, m = n >> 1;
		long long u = inverse ? wv[g][l] : wu[g][l], w = 1;

		for (r = 0; r < m; r++) {
			for (i = r; (j = i + m) < N_; i += n) {
				int a = aa[i], b = aa[j] * w % md;

				if ((aa[i] = a + b) >= md)
					aa[i] -= md;
				if ((aa[j] = a - b) < 0)
					aa[j] += md;
			}
			w = w * u % md;
		}
	}
}

long long garner(int r0, int r1) {
	r1 = (long long) (r1 - r0) * V01 % M1;
	if (r1 < 0)
		r1 += M1;
	return (long long) r1 * M0 + r0;
}

int main() {
	static long long ans[A + 1];
	static int aa[N], bb[M], aaa[2][2][N_], bbb[2][2][N_], cc[2][N_];
	int n, m, q, g, h, h1, h2, i, j, x, y, z, c;

	init();
	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < m; j++)
		scanf("%d", &bb[j]);
	if (n == 1 && m == 1)
		ans[aa[0] + bb[0]] = 1;
	else if (n == 1) {
		if (bb[0] > bb[1])
			ans[aa[0] + bb[0]]--;
		if (bb[m - 1] >= bb[m - 2])
			ans[aa[0] + bb[m - 1]]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[0] + bb[j];
			if (!x && !y)
				ans[c]--;
			else if (x && y)
				ans[c]++;
		}
	} else if (m == 1) {
		if (aa[0] > aa[1])
			ans[aa[0] + bb[0]]--;
		if (aa[n - 1] >= aa[n - 2])
			ans[aa[n - 1] + bb[0]]--;
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[0];
			if (!x && !y)
				ans[c]--;
			else if (x && y)
				ans[c]++;
		}
	} else {
		z = aa[0] > aa[1];
		y = bb[0] > bb[1], c = aa[0] + bb[0];
		if (z == y)
			ans[c]--;
		x = bb[m - 1] >= bb[m - 2], c = aa[0] + bb[m - 1];
		if (z == x)
			ans[c]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[0] + bb[j];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = aa[n - 1] >= aa[n - 2];
		y = bb[0] > bb[1], c = aa[n - 1] + bb[0];
		if (z == y)
			ans[c]--;
		x = bb[m - 1] >= bb[m - 2], c = aa[n - 1] + bb[m - 1];
		if (z == x)
			ans[c]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[n - 1] + bb[j];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = bb[0] > bb[1];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[0];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = bb[m - 1] >= bb[m - 2];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[m - 1];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1];
			if (!x && !y)
				aaa[0][0][aa[i]]++;
			else if (x && y)
				aaa[1][0][aa[i]]++;
		}
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1];
			if (!x && !y)
				bbb[0][0][bb[j]]++;
			else if (x && y)
				bbb[1][0][bb[j]]++;
		}
		for (h = 0; h < 2; h++) {
			memcpy(aaa[h][1], aaa[h][0], sizeof aaa[h][0]);
			for (g = 0; g < 2; g++)
				ntt(aaa[h][g], g, 0);
		}
		for (h = 0; h < 2; h++) {
			memcpy(bbb[h][1], bbb[h][0], sizeof bbb[h][0]);
			for (g = 0; g < 2; g++)
				ntt(bbb[h][g], g, 0);
		}
		for (h1 = 0; h1 < 2; h1++)
			for (h2 = 0; h2 < 2; h2++)
				for (g = 0; g < 2; g++) {
					int md = MM[g], d = h1 == h2 ? md - 2 : 2;

					for (i = 0; i < N_; i++)
						cc[g][i] = (cc[g][i] + (long long) aaa[h1][g][i] * bbb[h2][g][i] % md * d) % md;
				}
		for (g = 0; g < 2; g++) {
			int md = MM[g], v = VV[g];

			ntt(cc[g], g, 1);
			for (i = 0; i < N_; i++)
				cc[g][i] = (long long) cc[g][i] * v % md;
		}
		for (i = 0; i <= A; i++) {
			long long x = garner(cc[0][i], cc[1][i]);

			if (x > (long long) M0 * M1 - x)
				x -= (long long) M0 * M1;
			ans[i] += x;
		}
	}
	ans[0]++;
	for (i = 1; i <= A; i++)
		ans[i] += ans[i - 1];
	while (q--) {
		int x;

		scanf("%d", &x);
		printf("%lld\n", ans[x - 1]);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>

#define N	100000
#define M	100000
#define A	200000
#define L_	18	/* L_ = ceil(log2(A + 1)) */
#define N_	(1 << L_)
#define M0	469762049	/* M0 = 56 * 2^23 + 1 */
#define M1	595591169	/* M1 = 71 * 2^23 + 1 */

int MM[2] = { M0, M1 };

long long power(int a, int k, int md) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % md;
		b = b * b % md;
		k >>= 1;
	}
	return p;
}

int wu[2][L_ + 1], wv[2][L_ + 1], VV[2], V01;

void init() {
	int g, l, u, v;

	V01 = power(M0, M1 - 2, M1);
	for (g = 0; g < 2; g++) {
		int md = MM[g];

		u = power(3, md - 1 >> L_, md), v = power(u, md - 2, md);
		VV[g] = power(N_, md - 2, md);
		for (l = L_; l > 0; l--) {
			wu[g][l] = u, wv[g][l] = v;
			u = (long long) u * u % md, v = (long long) v * v % md;
		}
	}
}

void ntt(int *aa, int g, int inverse) {
	int md = MM[g], i, j, l, r;

	for (i = 0, j = 1; j < N_; j++) {
		int n, tmp;

		n = N_ >> 1;
		while ((i ^= n) < n)
			n >>= 1;
		if (i < j)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	for (l = 1; l <= L_; l++) {
		int n = 1 << l, m = n >> 1;
		long long u = inverse ? wv[g][l] : wu[g][l], w = 1;

		for (r = 0; r < m; r++) {
			for (i = r; (j = i + m) < N_; i += n) {
				int a = aa[i], b = aa[j] * w % md;

				if ((aa[i] = a + b) >= md)
					aa[i] -= md;
				if ((aa[j] = a - b) < 0)
					aa[j] += md;
			}
			w = w * u % md;
		}
	}
}

long long garner(int r0, int r1) {
	r1 = (long long) (r1 - r0) * V01 % M1;
	if (r1 < 0)
		r1 += M1;
	return (long long) r1 * M0 + r0;
}

int main() {
	static long long ans[A + 1];
	static int aa[N], bb[M], aaa[2][2][N_], bbb[2][2][N_], cc[2][N_];
	int n, m, q, g, h, h1, h2, i, j, x, y, z, c;

	init();
	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < m; j++)
		scanf("%d", &bb[j]);
	if (n == 1 && m == 1)
		ans[aa[0] + bb[0]] = 1;
	else if (n == 1)
		ans[aa[0] + bb[0]]--, ans[aa[0] + bb[m - 1]]--;
	else if (m == 1)
		ans[aa[0] + bb[0]]--, ans[aa[n - 1] + bb[0]]--;
	else {
		z = aa[0] > aa[1];
		y = bb[0] > bb[1], c = aa[0] + bb[0];
		if (z == y)
			ans[c]--;
		x = bb[m - 1] >= bb[m - 2], c = aa[0] + bb[m - 1];
		if (z == x)
			ans[c]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[0] + bb[j];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = aa[n - 1] >= aa[n - 2];
		y = bb[0] > bb[1], c = aa[n - 1] + bb[0];
		if (z == y)
			ans[c]--;
		x = bb[m - 1] >= bb[m - 2], c = aa[n - 1] + bb[m - 1];
		if (z == x)
			ans[c]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[n - 1] + bb[j];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = bb[0] > bb[1];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[0];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = bb[m - 1] >= bb[m - 2];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[m - 1];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1];
			if (!x && !y)
				aaa[0][0][aa[i]]++;
			else if (x && y)
				aaa[1][0][aa[i]]++;
		}
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1];
			if (!x && !y)
				bbb[0][0][bb[j]]++;
			else if (x && y)
				bbb[1][0][bb[j]]++;
		}
		for (h = 0; h < 2; h++) {
			memcpy(aaa[h][1], aaa[h][0], sizeof aaa[h][0]);
			for (g = 0; g < 2; g++)
				ntt(aaa[h][g], g, 0);
		}
		for (h = 0; h < 2; h++) {
			memcpy(bbb[h][1], bbb[h][0], sizeof bbb[h][0]);
			for (g = 0; g < 2; g++)
				ntt(bbb[h][g], g, 0);
		}
		for (h1 = 0; h1 < 2; h1++)
			for (h2 = 0; h2 < 2; h2++)
				for (g = 0; g < 2; g++) {
					int md = MM[g], d = h1 == h2 ? md - 2 : 2;

					for (i = 0; i < N_; i++)
						cc[g][i] = (cc[g][i] + (long long) aaa[h1][g][i] * bbb[h2][g][i] % md * d) % md;
				}
		for (g = 0; g < 2; g++) {
			int md = MM[g], v = VV[g];

			ntt(cc[g], g, 1);
			for (i = 0; i < N_; i++)
				cc[g][i] = (long long) cc[g][i] * v % md;
		}
		for (i = 0; i <= A; i++) {
			long long x = garner(cc[0][i], cc[1][i]);

			if (x > (long long) M0 * M1 - x)
				x -= (long long) M0 * M1;
			ans[i] += x;
		}
	}
	ans[0]++;
	for (i = 1; i <= A; i++)
		ans[i] += ans[i - 1];
	while (q--) {
		int x;

		scanf("%d", &x);
		printf("%lld\n", ans[x - 1]);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>

#define N	100000
#define M	100000
#define A	200000
#define L_	18	/* L_ = ceil(log2(A + 1)) */
#define N_	(1 << L_)
#define M0	469762049	/* M0 = 56 * 2^23 + 1 */
#define M1	595591169	/* M1 = 71 * 2^23 + 1 */

int MM[2] = { M0, M1 };

long long power(int a, int k, int md) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % md;
		b = b * b % md;
		k >>= 1;
	}
	return p;
}

int wu[2][L_ + 1][N_], wv[2][L_ + 1][N_], VV[2], V01;

void init() {
	int g, l, u, v;

	V01 = power(M0, M1 - 2, M1);
	for (g = 0; g < 2; g++) {
		int md = MM[g], i;

		u = power(3, md - 1 >> L_, md), v = power(u, md - 2, md);
		VV[g] = power(N_, md - 2, md);
		for (l = L_; l > 0; l--) {
			wu[g][l][0] = wv[g][l][0] = 1;
			for (i = 1; i < 1 << l; i++)
				wu[g][l][i] = (long long) wu[g][l][i - 1] * u % md, wv[g][l][i] = (long long) wv[g][l][i - 1] * v % md;
			u = (long long) u * u % md, v = (long long) v * v % md;
		}
	}
}

void ntt(int *aa, int g, int inverse) {
	int md = MM[g], h, i, j, l, r;

	for (i = 0, j = 1; j < N_; j++) {
		int n, tmp;

		n = N_ >> 1;
		while ((i ^= n) < n)
			n >>= 1;
		if (i < j)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	for (l = 1; l <= L_; l++) {
		int n = 1 << l, m = n >> 1;

		for (h = 0; h < N_; h += n)
			for (r = 0; r < m; r++) {
				int a, b;

				i = h + r, j = i + m;
				a = aa[i], b = (long long) aa[j] * (inverse ? wv[g][l][r] : wu[g][l][r]) % md;
				if ((aa[i] = a + b) >= md)
					aa[i] -= md;
				if ((aa[j] = a - b) < 0)
					aa[j] += md;
			}
	}
}

long long garner(int r0, int r1) {
	r1 = (long long) (r1 - r0) * V01 % M1;
	if (r1 < 0)
		r1 += M1;
	return (long long) r1 * M0 + r0;
}

int main() {
	static long long ans[A + 1];
	static int aa[N], bb[M], aaa[2][2][N_], bbb[2][2][N_], cc[2][N_];
	int n, m, q, g, h, h1, h2, i, j, x, y, z, c;

	init();
	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < m; j++)
		scanf("%d", &bb[j]);
	if (n == 1 && m == 1)
		ans[aa[0] + bb[0]] = 1;
	else if (n == 1)
		ans[aa[0] + bb[0]]--, ans[aa[0] + bb[m - 1]]--;
	else if (m == 1)
		ans[aa[0] + bb[0]]--, ans[aa[n - 1] + bb[0]]--;
	else {
		z = aa[0] > aa[1];
		y = bb[0] > bb[1], c = aa[0] + bb[0];
		if (z == y)
			ans[c]--;
		x = bb[m - 1] >= bb[m - 2], c = aa[0] + bb[m - 1];
		if (z == x)
			ans[c]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[0] + bb[j];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = aa[n - 1] >= aa[n - 2];
		y = bb[0] > bb[1], c = aa[n - 1] + bb[0];
		if (z == y)
			ans[c]--;
		x = bb[m - 1] >= bb[m - 2], c = aa[n - 1] + bb[m - 1];
		if (z == x)
			ans[c]--;
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1], c = aa[n - 1] + bb[j];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = bb[0] > bb[1];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[0];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		z = bb[m - 1] >= bb[m - 2];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1], c = aa[i] + bb[m - 1];
			if (!z) {
				if (!x && !y)
					ans[c]--;
				else if (x && y)
					ans[c]++;
			} else {
				if (!x && !y)
					ans[c]++;
				else if (x && y)
					ans[c]--;
			}
		}
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1];
			if (!x && !y)
				aaa[0][0][aa[i]]++;
			else if (x && y)
				aaa[1][0][aa[i]]++;
		}
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1];
			if (!x && !y)
				bbb[0][0][bb[j]]++;
			else if (x && y)
				bbb[1][0][bb[j]]++;
		}
		for (h = 0; h < 2; h++) {
			memcpy(aaa[h][1], aaa[h][0], sizeof aaa[h][0]);
			for (g = 0; g < 2; g++)
				ntt(aaa[h][g], g, 0);
		}
		for (h = 0; h < 2; h++) {
			memcpy(bbb[h][1], bbb[h][0], sizeof bbb[h][0]);
			for (g = 0; g < 2; g++)
				ntt(bbb[h][g], g, 0);
		}
		for (h1 = 0; h1 < 2; h1++)
			for (h2 = 0; h2 < 2; h2++)
				for (g = 0; g < 2; g++) {
					int md = MM[g], d = h1 == h2 ? md - 2 : 2;

					for (i = 0; i < N_; i++)
						cc[g][i] = (cc[g][i] + (long long) aaa[h1][g][i] * bbb[h2][g][i] % md * d) % md;
				}
		for (g = 0; g < 2; g++) {
			int md = MM[g], v = VV[g];

			ntt(cc[g], g, 1);
			for (i = 0; i < N_; i++)
				cc[g][i] = (long long) cc[g][i] * v % md;
		}
		for (i = 0; i <= A; i++) {
			long long x = garner(cc[0][i], cc[1][i]);

			if (x > (long long) M0 * M1 - x)
				x -= (long long) M0 * M1;
			ans[i] += x;
		}
	}
	ans[0]++;
	for (i = 1; i <= A; i++)
		ans[i] += ans[i - 1];
	while (q--) {
		int x;

		scanf("%d", &x);
		printf("%lld\n", ans[x - 1]);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>

#define N	100000
#define M	100000
#define A	200000
#define L_	18	/* L_ = ceil(log2(A + 1)) */
#define N_	(1 << L_)
#define M0	469762049	/* M0 = 56 * 2^23 + 1 */
#define M1	595591169	/* M1 = 71 * 2^23 + 1 */

int MM[2] = { M0, M1 };

long long power(int a, int k, int md) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % md;
		b = b * b % md;
		k >>= 1;
	}
	return p;
}

int wu[2][L_ + 1][N_], wv[2][L_ + 1][N_], VV[2], V01;

void init() {
	int g, l, u, v;

	V01 = power(M0, M1 - 2, M1);
	for (g = 0; g < 2; g++) {
		int md = MM[g], i;

		u = power(3, md - 1 >> L_, md), v = power(u, md - 2, md);
		VV[g] = power(N_, md - 2, md);
		for (l = L_; l > 0; l--) {
			wu[g][l][0] = wv[g][l][0] = 1;
			for (i = 1; i < 1 << l; i++)
				wu[g][l][i] = (long long) wu[g][l][i - 1] * u % md, wv[g][l][i] = (long long) wv[g][l][i - 1] * v % md;
			u = (long long) u * u % md, v = (long long) v * v % md;
		}
	}
}

void ntt(int *aa, int g, int inverse) {
	int md = MM[g], h, i, j, l, r;

	for (i = 0, j = 1; j < N_; j++) {
		int n, tmp;

		n = N_ >> 1;
		while ((i ^= n) < n)
			n >>= 1;
		if (i < j)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	for (l = 1; l <= L_; l++) {
		int n = 1 << l, m = n >> 1;

		for (h = 0; h < N_; h += n)
			for (r = 0; r < m; r++) {
				int a, b;

				i = h + r, j = i + m;
				a = aa[i], b = (long long) aa[j] * (inverse ? wv[g][l][r] : wu[g][l][r]) % md;
				if ((aa[i] = a + b) >= md)
					aa[i] -= md;
				if ((aa[j] = a - b) < 0)
					aa[j] += md;
			}
	}
}

long long garner(int r0, int r1) {
	r1 = (long long) (r1 - r0) * V01 % M1;
	if (r1 < 0)
		r1 += M1;
	return (long long) r1 * M0 + r0;
}

int main() {
	static long long ans[A + 1];
	static int aa[N], bb[M], aaa[2][N_], bbb[2][N_], cc[2][N_];
	int n, m, q, g, i, j, x, y, z;

	init();
	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < m; j++)
		scanf("%d", &bb[j]);
	if (n == 1 && m == 1)
		ans[aa[0] + bb[0]] = 1;
	else if (n == 1)
		ans[aa[0] + bb[0]]--, ans[aa[0] + bb[m - 1]]--;
	else if (m == 1)
		ans[aa[0] + bb[0]]--, ans[aa[n - 1] + bb[0]]--;
	else {
		x = bb[m - 1] >= bb[m - 2], y = bb[0] > bb[1];
		z = aa[0] > aa[1];
		if (z == y)
			ans[aa[0] + bb[0]]--;
		if (z == x)
			ans[aa[0] + bb[m - 1]]--;
		z = aa[n - 1] >= aa[n - 2];
		if (z == y)
			ans[aa[n - 1] + bb[0]]--;
		if (z == x)
			ans[aa[n - 1] + bb[m - 1]]--;
		z = aa[0] > aa[1];
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1];
			ans[aa[0] + bb[j]] += (z ? -1 : 1) * (x != y ? 0 : (x ? 1 : -1));
		}
		z = aa[n - 1] >= aa[n - 2];
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1];
			ans[aa[n - 1] + bb[j]] += (z ? -1 : 1) * (x != y ? 0 : (x ? 1 : -1));
		}
		z = bb[0] > bb[1];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1];
			ans[aa[i] + bb[0]] += (z ? -1 : 1) * (x != y ? 0 : (x ? 1 : -1));
		}
		z = bb[m - 1] >= bb[m - 2];
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1];
			ans[aa[i] + bb[m - 1]] += (z ? -1 : 1) * (x != y ? 0 : (x ? 1 : -1));
		}
		for (i = 1; i < n - 1; i++) {
			x = aa[i] >= aa[i - 1], y = aa[i] > aa[i + 1];
			aaa[0][aa[i]] += x != y ? 0 : (x ? -1 : 1);
		}
		for (j = 1; j < m - 1; j++) {
			x = bb[j] >= bb[j - 1], y = bb[j] > bb[j + 1];
			bbb[0][bb[j]] += x != y ? 0 : (x ? -1 : 1);
		}
		memcpy(aaa[1], aaa[0], sizeof aaa[0]);
		memcpy(bbb[1], bbb[0], sizeof bbb[0]);
		for (g = 0; g < 2; g++) {
			for (i = 0; i < N_; i++) {
				if (aaa[g][i] < 0)
					aaa[g][i] += MM[g];
				if (bbb[g][i] < 0)
					bbb[g][i] += MM[g];
			}
			ntt(aaa[g], g, 0);
			ntt(bbb[g], g, 0);
		}
		for (g = 0; g < 2; g++) {
			int md = MM[g];

			for (i = 0; i < N_; i++)
				cc[g][i] = (long long) aaa[g][i] * bbb[g][i] % md * 2 % md;
		}
		for (g = 0; g < 2; g++) {
			int md = MM[g], v = VV[g];

			ntt(cc[g], g, 1);
			for (i = 0; i < N_; i++)
				cc[g][i] = (long long) cc[g][i] * v % md;
		}
		for (i = 0; i <= A; i++) {
			long long x = garner(cc[0][i], cc[1][i]);

			if (x > (long long) M0 * M1 - x)
				x -= (long long) M0 * M1;
			ans[i] -= x;
		}
	}
	ans[0]++;
	for (i = 1; i <= A; i++)
		ans[i] += ans[i - 1];
	while (q--) {
		int x;

		scanf("%d", &x);
		printf("%lld\n", ans[x - 1]);
	}
	return 0;
}


#include <stdio.h>

int func (long long x, int n, int ans, int num, long long *pow10, long long *pow9) {
  int cnt = 0;
  int digit[10] = {};

  long long tmp = x;

  if (num >= ans) {
    return ans;
  }

  while (tmp > 0LL) {
    digit[(int)(tmp%10LL)] = 1;
    tmp /= 10LL;
    cnt++;
  }

  if (cnt > n) {
    return 100;
  }

  if (cnt == n) {
    return num;
  }

  for (int i = 9; i > 1; i--) {
    if (digit[i] > 0) {
      long long nx = x*((long long)i);
      if (ans-num-2 >= n || (pow10[n-1]-1LL)/pow9[ans-num-2] < nx) {
        int tmp = func(nx, n, ans, num+1, pow10, pow9);
        if (tmp < ans) {
          ans = tmp;
        }
      }
    }
  }

  return ans;
}

int main () {
  int n = 0;
  long long x = 0LL;

  int res = 0;

  long long pow10[19] = {};
  long long pow9[19] = {};

  int ans = 0;

  res = scanf("%d", &n);
  res = scanf("%lld", &x);

  pow10[0] = 1LL;
  for (int i = 1; i < n; i++) {
    pow10[i] = 10LL*pow10[i-1];
  }

  pow9[0] = 1LL;
  for (int i = 1; i < n; i++) {
    pow9[i] = 9LL*pow9[i-1];
  }

  ans = func(x, n, 100, 0, pow10, pow9);
  if (ans >= 100) {
    ans = -1;
  }

  printf("%d\n", ans);

  return 0;
}


#include <stdio.h>

int func (long long x, int n, int ans, int num, long long *pow10, long long *pow9) {
  int cnt = 0;
  int digit[10] = {};

  long long tmp = x;

  if (num >= ans) {
    return ans;
  }

  while (tmp > 0LL) {
    digit[(int)(tmp%10LL)] = 1;
    tmp /= 10LL;
    cnt++;
  }

  if (cnt > n) {
    return 100;
  }

  if (cnt == n) {
    return num;
  }

  for (int i = 9; i > 1; i--) {
    if (digit[i] > 0) {
      long long nx = x*((long long)i);
      if (ans-num-2 > n || (pow10[n-1]-1LL)/pow9[ans-num-2] < nx) {
        int tmp = func(nx, n, ans, num+1, pow10, pow9);
        if (tmp < ans) {
          ans = tmp;
        }
      }
    }
  }

  return ans;
}

int main () {
  int n = 0;
  long long x = 0LL;

  int res = 0;

  long long pow10[19] = {};
  long long pow9[19] = {};

  int ans = 0;

  res = scanf("%d", &n);
  res = scanf("%lld", &x);

  pow10[0] = 1LL;
  for (int i = 1; i < n; i++) {
    pow10[i] = 10LL*pow10[i-1];
  }

  pow9[0] = 1LL;
  for (int i = 1; i < n; i++) {
    pow9[i] = 9LL*pow9[i-1];
  }

  ans = func(x, n, 100, 0, pow10, pow9);
  if (ans >= 100) {
    ans = -1;
  }

  printf("%d\n", ans);

  return 0;
}


#include <stdio.h>

typedef unsigned long long ll;
#define rll register ll
#define rint register int
#define rep(i,a,b) for(rint i=(a);i<(b);i++)
#define repe(i,a,b) for(rint i=(a);i<=(b);i++)
#define repr(i,a,b) for(rint i=(a)-1;(b)<=i;i--)

int writeBuffer[20];
void write(ll num) { if (num == 0) putchar('0'); else { rint size = 0; rll current; if (0 < num) current = num; else current = -num, putchar('-'); while (0 < current) writeBuffer[size++] = current%10+'0', current /= 10; while (0 < size) putchar(writeBuffer[--size]); } }
ll read() { rint sign = 1; rll num = 0; while (1) { rint ch = getchar(); if (ch == '-') { sign = -sign; continue; } if (ch <= 32) break; num = num*10+(ch-'0'); } return sign*num; }

ll dp[100][1<<10];

int main() {
    rint n = read();
    rll x = read();

    {
        rint mask = 0;
        for (rll temp=x;temp;temp/=10) mask |= 1<<(temp%10);
        dp[0][mask] = x;
    }

    rint depth = 0;
    while (1) {
        rint found = 0;
        rep(j,0,1024) {
            rll num = dp[depth][j];
            if (num) {
                rep(k,2,10) if (j&(1<<k)) {
                    rll newNum = num*k;
                    found = 1;
                    rint mask = 0;
                    rint digit = 0;
                    for (rll temp=newNum;temp;temp/=10,digit++) mask |= 1<<(temp%10);
                    if (n == digit) {
                        write(depth+1), putchar('\n');
                        return 0;
                    }
                    if (dp[depth+1][mask] < newNum) dp[depth+1][mask] = newNum;
                }
            }
        }
        if (!found) {
            putchar('-'), putchar('1'), putchar('\n');
            return 0;
        }
        depth++;
    }
}


#include <stdio.h>

int func (long long x, int n, int num, long long *pow10, int *lim) {
  int cnt = 0;
  int digit[10] = {};

  long long tmp = x;

  int ans = -1;

  while (tmp > 0LL) {
    digit[(int)(tmp%10LL)] = 1;
    tmp /= 10LL;
    cnt++;
  }

  if (cnt > n) {
    return -1;
  }

  if (cnt == n) {
    return num;
  }

  for (int i = 9; i > 1; i--) {
    if (digit[i] > 0) {
      long long nx = x*((long long)i);
      if (nx >= pow10[cnt] && lim[cnt] > num) {
        int tmp = 0;
        lim[cnt] = num+1;
        tmp = func(nx, n, num+1, pow10, lim);
        if (ans < 0 || (tmp >= 0 && tmp < ans)) {
          ans = tmp;
        }
      } else if (lim[cnt] > num+1) {
        int tmp = 0;
        tmp = func(nx, n, num+1, pow10, lim);
        if (ans < 0 || (tmp >= 0 && tmp < ans)) {
          ans = tmp;
        }
      }
    }
  }

  return ans;
}

int main () {
  int n = 0;
  long long x = 0LL;

  int res = 0;

  long long pow10[19] = {};
  int ans[20] = {};

  res = scanf("%d", &n);
  res = scanf("%lld", &x);

  pow10[0] = 1LL;
  for (int i = 1; i <= n; i++) {
    pow10[i] = 10LL*pow10[i-1];
  }

  for (int i = 0; i < n; i++) {
    ans[i] = 100;
  }

  printf("%d\n", func(x, n, 0, pow10, ans));

  return 0;
}


#include <stdio.h>

typedef unsigned long long ll;
#define rll register ll
#define rint register int
#define rep(i,a,b) for(rint i=(a);i<(b);i++)
#define repe(i,a,b) for(rint i=(a);i<=(b);i++)
#define repr(i,a,b) for(rint i=(a)-1;(b)<=i;i--)

int writeBuffer[20];
void write(ll num) { if (num == 0) putchar('0'); else { rint size = 0; rll current; if (0 < num) current = num; else current = -num, putchar('-'); while (0 < current) writeBuffer[size++] = current%10+'0', current /= 10; while (0 < size) putchar(writeBuffer[--size]); } }
ll read() { rint sign = 1; rll num = 0; while (1) { rint ch = getchar(); if (ch == '-') { sign = -sign; continue; } if (ch <= 32) break; num = num*10+(ch-'0'); } return sign*num; }

ll dp[100][1<<10];

int main() {
    rint n = read();
    rll target = 1;
    rep(i,0,n) target *= 10;

    rll x = read();

    {
        rint mask = 0;
        for (rll temp=x;temp;temp/=10) mask |= 1<<(temp%10);
        dp[0][mask] = x;
    }

    rint depth = 0;
    while (1) {
        rint found = 0;
        rep(j,0,1024) {
            rll num = dp[depth][j];
            if (num) {
                rep(k,2,10) if (j&(1<<k)) {
                    rll newNum = num*k;
                    if (target <= newNum) {
                        write(depth), putchar('\n');
                        return 0;
                    }
                    found = 1;
                    rint mask = 0;
                    for (rll temp=newNum;temp;temp/=10) mask |= 1<<(temp%10);
                    if (dp[depth+1][mask] < newNum) dp[depth+1][mask] = newNum;
                }
            }
        }
        if (!found) {
            putchar('-'), putchar('1'), putchar('\n');
            return 0;
        }
        depth++;
    }
}


#include <stdio.h>

#define rint register int
#define rep(i,a,b) for(rint i=(a);i<(b);i++)
#define repe(i,a,b) for(rint i=(a);i<=(b);i++)
#define repr(i,a,b) for(rint i=(a)-1;(b)<=i;i--)

void writePositive(int num) {
    if (num > 0) {
        writePositive(num / 10);
        putchar(num % 10 + '0');
    }
}

void write(int num) {
    if (num == 0) putchar('0');
    else if (num < 0) {
        putchar('-');
        writePositive(-num);
    } else writePositive(num);
}

int read() {
    rint sign = 1;
    rint num = 0;
    rint ch;
    while(1) {
        ch = getchar();
        if (ch == '-') {
            sign = -sign;
            continue;
        }
        ch = ch-'0';
        if (ch < 0 || 10 < ch) break;
        num = num*10+ch;
    }
    return sign*num;
}

#define MOD 998244353

int dp[50001][1024];
int pairs[10][10], masks[10][1024];

int main() {
    rint n = read();
    rint m = read();
    rep(i,0,m) {
        rint u = read();
        rint v = read();
        pairs[u][v] = 1;
        pairs[v][u] = 1;
    }

    rep(k,0,10) rep(j,0,1024) {
        rint mask = 1<<k;
        rep(l,0,10) if (j&(1<<l)) if (pairs[l][k]) {
            if (l < k) {
                mask = -1;
                break;
            }
            mask |= 1<<l;
        }
        masks[k][j] = mask;
    }

    dp[0][0] = 1;
    rep(i,0,n) rep(j,0,1024) if (dp[i][j]) rep(k,0,10) {
        rint mask = masks[k][j];
        if (0 <= mask) dp[i+1][mask] = (dp[i+1][mask]+dp[i][j]) % MOD;
    }

    rint total = 0;
    rep(j,0,1024) total = (total+dp[n][j]) % MOD;
    write(total), putchar('\n');

    return 0;
}


#include <stdio.h>

#define rint register int
#define rep(i,a,b) for(rint i=(a);i<(b);i++)
#define repe(i,a,b) for(rint i=(a);i<=(b);i++)
#define repr(i,a,b) for(rint i=(a)-1;(b)<=i;i--)

void writePositive(int num) {
    if (num > 0) {
        writePositive(num / 10);
        putchar(num % 10 + '0');
    }
}

void write(int num) {
    if (num == 0) putchar('0');
    else if (num < 0) {
        putchar('-');
        writePositive(-num);
    } else writePositive(num);
}

int read() {
    rint sign = 1;
    rint num = 0;
    rint ch;
    while(1) {
        ch = getchar();
        if (ch == '-') {
            sign = -sign;
            continue;
        }
        ch = ch-'0';
        if (ch < 0 || 10 < ch) break;
        num = num*10+ch;
    }
    return sign*num;
}

#define MOD 998244353

int dp[50001][1024];
int pairs[10][10], masks[10][1024];

int main() {
    rint n = read();
    rint m = read();
    rep(i,0,m) {
        rint u = read();
        rint v = read();
        pairs[u][v] = 1;
        pairs[v][u] = 1;
    }

    rep(k,0,10) rep(j,0,1024) {
        rint mask = 1<<k;
        rep(l,0,10) if (j&(1<<l)) if (pairs[l][k]) {
            if (l < k) {
                mask = -1;
                break;
            }
            mask |= 1<<l;
        }
        masks[k][j] = mask;
    }

    dp[0][0] = 1;
    rep(i,0,n) rep(j,0,1024) rep(k,0,10) {
        rint mask = masks[k][j];
        if (0 <= mask) dp[i+1][mask] = (dp[i+1][mask]+dp[i][j]) % MOD;
    }

    rint total = 0;
    rep(j,0,1024) total = (total+dp[n][j]) % MOD;
    write(total), putchar('\n');

    return 0;
}


#include <stdio.h>
#include <string.h>

#define MOD 998244353

int main() {
	int n, m;
	scanf("%d%d", &n, &m);

	static int c[10];

	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		c[u] |= 1 << v;
		c[v] |= 1 << u;
	}

	for (int u = 0; u < 10; ++u) {
		c[u] |= 1 << u;
	}

	static int dp[1024];

	for (int u = 0; u < 10; ++u) {
		dp[1 << u] = 1;
	}

	while (--n) {
		static int tmp[1024];

		memset(tmp, 0, sizeof(tmp));

		for (int i = 0; i < 1024; ++i) {
			for (int x = 0; x < 10; ++x) {
				int j = i & c[x] | (1 << x);
				if (j & ((1 << x) - 1))
					continue;
				if ((tmp[j] += dp[i]) >= MOD)
					tmp[j] -= MOD;
			}
		}

		memcpy(dp, tmp, sizeof(dp));
	}

	int res = 0;
	for (int i = 0; i < 1024; ++i) {
		if ((res += dp[i]) >= MOD)
			res -= MOD;
	}

	printf("%d\n", res);
}


#include <stdio.h>

typedef long long ll;
#define rll register ll
#define rint register int
#define rep(i,a,b) for(rll i=(a);i<(b);i++)
#define repe(i,a,b) for(rll i=(a);i<=(b);i++)
#define repr(i,a,b) for(rll i=(a)-1;(b)<=i;i--)

void writePositive(ll num) {
    if (num > 0) {
        writePositive(num / 10);
        putchar(num % 10 + '0');
    }
}

void write(ll num) {
    if (num == 0) putchar('0');
    else if (num < 0) {
        putchar('-');
        writePositive(-num);
    } else writePositive(num);
}

ll read() {
    rint sign = 1;
    rll num = 0;
    rint ch;
    while(1) {
        ch = getchar();
        if (ch == '-') {
            sign = -sign;
            continue;
        }
        ch = ch-'0';
        if (ch < 0 || 10 < ch) break;
        num = num*10+ch;
    }
    return sign*num;
}

#define MOD 998244353

ll dp[50001][1024];
int pairs[10][10], masks[10][1024];

int main() {
    rll n = read();
    rll m = read();
    rep(i,0,m) {
        rll u = read();
        rll v = read();
        pairs[u][v] = 1;
        pairs[v][u] = 1;
    }

    rep(k,0,10) rep(j,0,1024) {
        rint mask = 1<<k;
        rep(l,0,10) if (j&(1<<l)) if (pairs[l][k]) {
            if (l < k) {
                mask = -1;
                break;
            }
            mask |= 1<<l;
        }
        masks[k][j] = mask;
    }

    dp[0][0] = 1;
    rep(i,0,n) rep(j,0,1024) rep(k,0,10) {
        rint mask = masks[k][j];
        if (0 <= mask) dp[i+1][mask] = (dp[i+1][mask]+dp[i][j]) % MOD;
    }

    rll total = 0;
    rep(j,0,1024) total = (total+dp[n][j]) % MOD;
    write(total), putchar('\n');

    return 0;
}


#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	if (n < 0)
		return 0;
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a % p;
		a = a * a % p;
		n /= 2;
	}
	return res;
}
int main()
{
	long long int n, m, l, r;
	scanf("%lld %lld %lld %lld", &n, &m, &l, &r);
	long long int p = 998244353;
	if (n * m % 2 > 0)
		printf("%lld\n", modpow(r - l + 1, n * m, p));
	else if ((r - l) % 2 > 0)
		printf("%lld\n", modpow(r - l + 1, n * m, p) * modpow(2, p - 2, p) % p);
	else
		printf("%lld\n", (modpow(r - l + 1, n * m, p) + 1) * modpow(2, p - 2, p) % p);
}


#include <stdio.h>

#define MD	998244353

long long power(int a, long long k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k >> 1);
	p = p * p % MD;
	if (k & 1)
		p = p * a % MD;
	return p;
}

void mult(int aa[][2], int bb[][2], int cc[][2]) {
	int i, j;

	for (i = 0; i < 2; i++)
		for (j = 0; j < 2; j++)
			cc[i][j] = ((long long) aa[i][0] * bb[0][j] + (long long) aa[i][1] * bb[1][j]) % MD;
}

void power_(int aa[][2], int pp[][2], int tt[][2], long long k) {
	if (k == 0) {
		int i, j;

		for (i = 0; i < 2; i++)
			for (j = 0; j < 2; j++)
				pp[i][j] = i == j;
		return;
	}
	if ((k & 1) == 0) {
		power_(aa, tt, pp, k >> 1);
		mult(tt, tt, pp);
	} else {
		power_(aa, pp, tt, k >> 1);
		mult(pp, pp, tt);
		mult(tt, aa, pp);
	}
}

int main() {
	static int aa[2][2], pp[2][2], tt[2][2];
	int n, m, l, r, e, o;

	scanf("%d%d%d%d", &n, &m, &l, &r);
	if ((long long) n * m % 2 != 0) {
		printf("%lld\n", power(r - l + 1, (long long) n * m));
		return 0;
	}
	e = r / 2 - (l - 1) / 2, o = r - l + 1 - e;
	aa[0][0] = e, aa[0][1] = o;
	aa[1][0] = o, aa[1][1] = e;
	power_(aa, pp, tt, (long long) n * m);
	printf("%d\n", pp[0][0]);
	return 0;
}


#include <stdio.h>

#define MD	998244353

void mult(int aa[][2], int bb[][2], int cc[][2]) {
	int i, j;

	for (i = 0; i < 2; i++)
		for (j = 0; j < 2; j++)
			cc[i][j] = ((long long) aa[i][0] * bb[0][j] + (long long) aa[i][1] * bb[1][j]) % MD;
}

void power(int aa[][2], int pp[][2], int tt[][2], long long k) {
	if (k == 0) {
		int i, j;

		for (i = 0; i < 2; i++)
			for (j = 0; j < 2; j++)
				pp[i][j] = i == j;
		return;
	}
	if ((k & 1) == 0) {
		power(aa, tt, pp, k / 2);
		mult(tt, tt, pp);
	} else {
		power(aa, pp, tt, k / 2);
		mult(pp, pp, tt);
		mult(tt, aa, pp);
	}
}

int main() {
	static int aa[2][2], pp[2][2], tt[2][2];
	int n, m, l, r, e, o;

	scanf("%d%d%d%d", &n, &m, &l, &r);
	e = r / 2 - (l - 1) / 2, o = r - l + 1 - e;
	aa[0][0] = e, aa[0][1] = o;
	aa[1][0] = o, aa[1][1] = e;
	power(aa, pp, tt, (long long) n * m);
	printf("%d\n", pp[0][0]);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#define N	500000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
}

int rand_() {
	return (X *= 3) >> 1;
}

long long ss[N + 1];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (ss[ii[j]] == ss[i_])
				j++;
			else if (ss[ii[j]] < ss[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int search(int *ii, int n, long long s) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int h = (lower + upper) / 2;

		if (ss[ii[h]] >= s)
			upper = h;
		else
			lower = h;
	}
	return lower;
}

int ft1[N + 1], ft2[N + 1];

void update(int *ft, int i, int n, int x) {
	while (i < n) {
		ft[i] = min(ft[i], x);
		i |= i + 1;
	}
}

int query(int *ft, int i) {
	int x = INF;

	while (i >= 0) {
		x = min(x, ft[i]);
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	int t;

	srand_();
	scanf("%d", &t);
	while (t--) {
		static int aa[N + 1], qu[2][N + 1], head[2], cnt[2], ii[N], ll[N + 1], ll_[N + 1], rr_[N + 1], pp[N + 1], dp[N + 1], dq[N + 1];
		int n, h, h_, i, j;
		long long sum;

		scanf("%d", &n);
		for (i = 1; i <= n; i++)
			scanf("%d", &aa[i]), aa[i] -= 2;
		for (i = 1; i <= n; i++)
			ss[i] = aa[i] - (i == 0 ? 0 : ss[i - 1]);
		head[0] = cnt[0] = head[1] = cnt[1] = 0;
		for (i = 0, j = 0; j <= n; j++) {
			while (cnt[j % 2] && ss[qu[j % 2][head[j % 2] + cnt[j % 2] - 1]] >= ss[j])
				cnt[j % 2]--;
			qu[j % 2][head[j % 2] + cnt[j % 2]++] = j;
			while (ss[qu[0][head[0]]] + ss[qu[1][head[1]]] < 0) {
				if (qu[i % 2][head[i % 2]] == i)
					head[i % 2]++, cnt[i % 2]--;
				i++;
			}
			ll[j] = i;
			if (j > 0 && aa[j] % 2 == 0) {
				h = search(qu[j % 2] + head[j % 2], cnt[j % 2], ss[j] - aa[j] / 2);
				ll_[j] = h == -1 ? 0 : qu[j % 2][head[j % 2] + h] + 1;
				h = search(qu[j % 2 ^ 1] + head[j % 2 ^ 1], cnt[j % 2 ^ 1], aa[j] / 2 - ss[j]);
				ll_[j] = max(ll_[j], h == -1 ? 0 : qu[j % 2 ^ 1][head[j % 2 ^ 1] + h] + 1);
			}
		}
		cnt[0] = cnt[1] = 0;
		for (i = n; i > 0; i--) {
			while (cnt[i % 2] && ss[qu[i % 2][cnt[i % 2] - 1]] >= ss[i])
				cnt[i % 2]--;
			qu[i % 2][cnt[i % 2]++] = i;
			if (i > 0 && aa[i] % 2 == 0) {
				h = search(qu[i % 2], cnt[i % 2], ss[i] - aa[i] / 2);
				rr_[i] = h == -1 ? n : qu[i % 2][h] - 1;
				h = search(qu[i % 2 ^ 1], cnt[i % 2 ^ 1], aa[i] / 2 - ss[i]);
				rr_[i] = min(rr_[i], h == -1 ? n : qu[i % 2 ^ 1][h] - 1);
			}
		}
		sum = 0;
		for (i = 1; i <= n; i++) {
			ss[i] = sum + (i % 2 == 0 ? aa[i] / 2 : -aa[i] / 2);
			sum += i % 2 == 0 ? aa[i] : -aa[i];
			ii[i - 1] = i;
		}
		sort(ii, 0, n);
		for (h = 0; h < n; h = h_) {
			long long s = ss[ii[h]];

			h_ = h, i = 0;
			while (h_ < n && ss[ii[h_]] == s) {
				if (aa[ii[h_]] % 2 == 0)
					pp[ii[h_]] = i, i = ii[h_];
				else
					pp[ii[h_]] = 0;
				h_++;
			}
		}
		memset(ft1, 0x3f, (n + 1) * sizeof *ft1);
		memset(ft2, 0x3f, (n + 1) * sizeof *ft2);
		update(ft1, n - 0, n + 1, 0);
		for (i = 1; i <= n; i++) {
			dp[i] = min(query(ft2, n - i), query(ft1, n - ll[i]) + 1);
			if (aa[i] % 2 == 0) {
				dq[i] = query(ft1, n - ll_[i]);
				if (pp[i] && ll_[i] <= pp[i])
					dq[i] = min(dq[i], dq[pp[i]] - 1);
			} else
				dq[i] = INF;
			update(ft1, n - i, n + 1, dp[i]);
			if (dq[i] != INF) {
				update(ft1, n - i, n + 1, dq[i]);
				update(ft2, n - rr_[i], n + 1, dq[i]);
			}
		}
		printf("%d\n", n + min(dp[n], dq[n]));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#define N	500000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
}

int rand_() {
	return (X *= 3) >> 1;
}

long long ss[N + 1];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = ss[ii[j]] != ss[i_] ? ss[ii[j]] - ss[i_] : ii[j] - i_;

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int search(int *ii, int n, long long s) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int h = (lower + upper) / 2;

		if (ss[ii[h]] >= s)
			upper = h;
		else
			lower = h;
	}
	return lower;
}

int ft1[N + 1], ft2[N + 1];

void update(int *ft, int i, int n, int x) {
	while (i < n) {
		ft[i] = min(ft[i], x);
		i |= i + 1;
	}
}

int query(int *ft, int i) {
	int x = INF;

	while (i >= 0) {
		x = min(x, ft[i]);
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	int t;

	srand_();
	scanf("%d", &t);
	while (t--) {
		static int aa[N + 1], qu[2][N + 1], head[2], cnt[2], ii[N], ll[N + 1], ll_[N + 1], rr_[N + 1], pp[N + 1], dp[N + 1], dq[N + 1];
		int n, h, h_, i, j;
		long long sum;

		scanf("%d", &n);
		for (i = 1; i <= n; i++)
			scanf("%d", &aa[i]), aa[i] -= 2;
		for (i = 1; i <= n; i++)
			ss[i] = aa[i] - (i == 0 ? 0 : ss[i - 1]);
		head[0] = cnt[0] = head[1] = cnt[1] = 0;
		for (i = 0, j = 0; j <= n; j++) {
			while (cnt[j % 2] && ss[qu[j % 2][head[j % 2] + cnt[j % 2] - 1]] >= ss[j])
				cnt[j % 2]--;
			qu[j % 2][head[j % 2] + cnt[j % 2]++] = j;
			while (ss[qu[0][head[0]]] + ss[qu[1][head[1]]] < 0) {
				if (qu[i % 2][head[i % 2]] == i)
					head[i % 2]++, cnt[i % 2]--;
				i++;
			}
			ll[j] = i;
			if (j > 0 && aa[j] % 2 == 0) {
				h = search(qu[j % 2] + head[j % 2], cnt[j % 2], ss[j] - aa[j] / 2);
				ll_[j] = h == -1 ? 0 : qu[j % 2][head[j % 2] + h] + 1;
				h = search(qu[j % 2 ^ 1] + head[j % 2 ^ 1], cnt[j % 2 ^ 1], aa[j] / 2 - ss[j]);
				ll_[j] = max(ll_[j], h == -1 ? 0 : qu[j % 2 ^ 1][head[j % 2 ^ 1] + h] + 1);
			}
		}
		cnt[0] = cnt[1] = 0;
		for (i = n; i > 0; i--) {
			while (cnt[i % 2] && ss[qu[i % 2][cnt[i % 2] - 1]] >= ss[i])
				cnt[i % 2]--;
			qu[i % 2][cnt[i % 2]++] = i;
			if (i > 0 && aa[i] % 2 == 0) {
				h = search(qu[i % 2], cnt[i % 2], ss[i] - aa[i] / 2);
				rr_[i] = h == -1 ? n : qu[i % 2][h] - 1;
				h = search(qu[i % 2 ^ 1], cnt[i % 2 ^ 1], aa[i] / 2 - ss[i]);
				rr_[i] = min(rr_[i], h == -1 ? n : qu[i % 2 ^ 1][h] - 1);
			}
		}
		sum = 0;
		for (i = 1; i <= n; i++) {
			ss[i] = sum + (i % 2 == 0 ? aa[i] / 2 : -aa[i] / 2);
			sum += i % 2 == 0 ? aa[i] : -aa[i];
			ii[i - 1] = i;
		}
		sort(ii, 0, n);
		for (h = 0; h < n; h = h_) {
			long long s = ss[ii[h]];

			h_ = h, i = 0;
			while (h_ < n && ss[ii[h_]] == s) {
				if (aa[ii[h_]] % 2 == 0)
					pp[ii[h_]] = i, i = ii[h_];
				else
					pp[ii[h_]] = 0;
				h_++;
			}
		}
		memset(ft1, 0x3f, (n + 1) * sizeof *ft1);
		memset(ft2, 0x3f, (n + 1) * sizeof *ft2);
		update(ft1, n - 0, n + 1, 0);
		for (i = 1; i <= n; i++) {
			dp[i] = min(query(ft2, n - i), query(ft1, n - ll[i]) + 1);
			if (aa[i] % 2 == 0) {
				dq[i] = query(ft1, n - ll_[i]);
				if (pp[i] && ll_[i] <= pp[i])
					dq[i] = min(dq[i], dq[pp[i]] - 1);
			} else
				dq[i] = INF;
			update(ft1, n - i, n + 1, dp[i]);
			if (dq[i] != INF) {
				update(ft1, n - i, n + 1, dq[i]);
				update(ft2, n - rr_[i], n + 1, dq[i]);
			}
		}
		printf("%d\n", n + min(dp[n], dq[n]));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#define N	500000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
}

int rand_() {
	return (X *= 3) >> 1;
}

long long ss[N + 1];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (ss[ii[j]] == ss[i_])
				j++;
			else if (ss[ii[j]] < ss[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int search(int *ii, int n, long long s) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int h = (lower + upper) / 2;

		if (ss[ii[h]] >= s)
			upper = h;
		else
			lower = h;
	}
	return lower;
}

int ft1[N + 1], ft2[N + 1];

void update(int *ft, int i, int n, int x) {
	while (i < n) {
		ft[i] = min(ft[i], x);
		i |= i + 1;
	}
}

int query(int *ft, int i) {
	int x = INF;

	while (i >= 0) {
		x = min(x, ft[i]);
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	int t;

	srand_();
	scanf("%d", &t);
	while (t--) {
		static int aa[N + 1], qu[2][N + 1], head[2], cnt[2], ii[N], ll[N + 1], ll_[N + 1], rr_[N + 1], pp[N + 1], dp[N + 1], dq[N + 1];
		int n, h, h_, i, j;
		long long sum;

		scanf("%d", &n);
		for (i = 1; i <= n; i++)
			scanf("%d", &aa[i]), aa[i] -= 2;
		for (i = 1; i <= n; i++)
			ss[i] = aa[i] - (i == 0 ? 0 : ss[i - 1]);
		head[0] = cnt[0] = head[1] = cnt[1] = 0;
		for (i = 0, j = 0; j <= n; j++) {
			while (cnt[j % 2] && ss[qu[j % 2][head[j % 2] + cnt[j % 2] - 1]] >= ss[j])
				cnt[j % 2]--;
			qu[j % 2][head[j % 2] + cnt[j % 2]++] = j;
			while (ss[qu[0][head[0]]] + ss[qu[1][head[1]]] < 0) {
				if (qu[i % 2][head[i % 2]] == i)
					head[i % 2]++, cnt[i % 2]--;
				i++;
			}
			ll[j] = i;
			if (j > 0 && aa[j] % 2 == 0) {
				h = search(qu[j % 2] + head[j % 2], cnt[j % 2], ss[j] - aa[j] / 2);
				ll_[j] = h == -1 ? 0 : qu[j % 2][head[j % 2] + h] + 1;
				h = search(qu[j % 2 ^ 1] + head[j % 2 ^ 1], cnt[j % 2 ^ 1], aa[j] / 2 - ss[j]);
				ll_[j] = max(ll_[j], h == -1 ? 0 : qu[j % 2 ^ 1][head[j % 2 ^ 1] + h] + 1);
			}
		}
		cnt[0] = cnt[1] = 0;
		for (i = n; i > 0; i--) {
			while (cnt[i % 2] && ss[qu[i % 2][cnt[i % 2] - 1]] >= ss[i])
				cnt[i % 2]--;
			qu[i % 2][cnt[i % 2]++] = i;
			if (i > 0 && aa[i] % 2 == 0) {
				h = search(qu[i % 2], cnt[i % 2], ss[i] - aa[i] / 2);
				rr_[i] = h == -1 ? n : qu[i % 2][h] - 1;
				h = search(qu[i % 2 ^ 1], cnt[i % 2 ^ 1], aa[i] / 2 - ss[i]);
				rr_[i] = min(rr_[i], h == -1 ? n : qu[i % 2 ^ 1][h] - 1);
			}
		}
		sum = 0;
		for (i = 1; i <= n; i++) {
			ss[i] = sum + (i % 2 == 0 ? aa[i] / 2 : -aa[i] / 2);
			sum += i % 2 == 0 ? aa[i] : -aa[i];
			ii[i - 1] = i;
		}
		sort(ii, 0, n);
		for (h = 0; h < n; h = h_) {
			long long s = ss[ii[h]];

			h_ = h, i = 0;
			while (h_ < n && ss[ii[h_]] == s) {
				if (aa[ii[h_]] % 2 == 0)
					pp[ii[h_]] = i, i = ii[h_];
				else
					pp[ii[h_]] = 0;
				h_++;
			}
		}
		memset(ft1, 0x3f, (n + 1) * sizeof *ft1);
		memset(ft2, 0x3f, (n + 1) * sizeof *ft2);
		update(ft1, n - 0, n + 1, 0);
		for (i = 1; i <= n; i++) {
			dp[i] = min(query(ft2, n - i), query(ft1, n - ll[i]) + 1);
			if (aa[i] % 2 == 0) {
				dq[i] = query(ft1, n - ll_[i]);
				if (pp[i] && ll_[i] <= pp[i])
					dq[i] = min(dq[i], dq[pp[i]] - 1);
			} else
				dq[i] = INF;
			update(ft1, n - i, n + 1, dp[i]);
			update(ft1, n - i, n + 1, dq[i]);
			update(ft2, n - rr_[i], n + 1, dq[i]);
		}
		printf("%d\n", n + min(dp[n], dq[n]));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#define N	500000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
}

int rand_() {
	return (X *= 3) >> 1;
}

long long ss[N + 1];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = ss[ii[j]] != ss[i_] ? ss[ii[j]] - ss[i_] : ii[j] - i_;

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int search(int *ii, int n, long long s) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int h = (lower + upper) / 2;

		if (ss[ii[h]] >= s)
			upper = h;
		else
			lower = h;
	}
	return lower;
}

int ft1[N + 1], ft2[N + 1];

void update(int *ft, int i, int n, int x) {
	while (i < n) {
		ft[i] = min(ft[i], x);
		i |= i + 1;
	}
}

int query(int *ft, int i) {
	int x = INF;

	while (i >= 0) {
		x = min(x, ft[i]);
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	int t;

	srand_();
	scanf("%d", &t);
	while (t--) {
		static int aa[N + 1], qu[2][N + 1], head[2], cnt[2], ii[N], ll[N + 1], ll_[N + 1], rr_[N + 1], pp[N + 1], dp[N + 1], dq[N + 1];
		int n, h, h_, i, j;
		long long sum;

		scanf("%d", &n);
		for (i = 1; i <= n; i++)
			scanf("%d", &aa[i]), aa[i] -= 2;
		for (i = 1; i <= n; i++)
			ss[i] = aa[i] - (i == 0 ? 0 : ss[i - 1]);
		head[0] = cnt[0] = head[1] = cnt[1] = 0;
		for (i = 0, j = 0; j <= n; j++) {
			while (cnt[j % 2] && ss[qu[j % 2][head[j % 2] + cnt[j % 2] - 1]] >= ss[j])
				cnt[j % 2]--;
			qu[j % 2][head[j % 2] + cnt[j % 2]++] = j;
			while (i < j && ss[qu[0][head[0]]] + ss[qu[1][head[1]]] < 0) {
				if (qu[i % 2][head[i % 2]] == i)
					head[i % 2]++, cnt[i % 2]--;
				i++;
			}
			ll[j] = i;
			if (j > 0 && aa[j] % 2 == 0) {
				h = search(qu[j % 2] + head[j % 2], cnt[j % 2], ss[j] - aa[j] / 2);
				ll_[j] = h == -1 ? i : qu[j % 2][head[j % 2] + h] + 1;
				h = search(qu[j % 2 ^ 1] + head[j % 2 ^ 1], cnt[j % 2 ^ 1], aa[j] / 2 - ss[j]);
				ll_[j] = max(ll_[j], h == -1 ? i : qu[j % 2 ^ 1][head[j % 2 ^ 1] + h] + 1);
			}
		}
		cnt[0] = cnt[1] = 0;
		for (i = n; i > 0; i--) {
			while (cnt[i % 2] && ss[qu[i % 2][cnt[i % 2] - 1]] >= ss[i])
				cnt[i % 2]--;
			qu[i % 2][cnt[i % 2]++] = i;
			if (i > 0 && aa[i] % 2 == 0) {
				h = search(qu[i % 2], cnt[i % 2], ss[i] - aa[i] / 2);
				rr_[i] = h == -1 ? n : qu[i % 2][h] - 1;
				h = search(qu[i % 2 ^ 1], cnt[i % 2 ^ 1], aa[i] / 2 - ss[i]);
				rr_[i] = min(rr_[i], h == -1 ? n : qu[i % 2 ^ 1][h] - 1);
			}
		}
		sum = 0;
		for (i = 1; i <= n; i++) {
			ss[i] = sum + (i % 2 == 0 ? aa[i] / 2 : -aa[i] / 2);
			sum += i % 2 == 0 ? aa[i] : -aa[i];
			ii[i - 1] = i;
		}
		sort(ii, 0, n);
		for (h = 0; h < n; h = h_) {
			long long s = ss[ii[h]];

			h_ = h, i = 0;
			while (h_ < n && ss[ii[h_]] == s) {
				if (aa[ii[h_]] % 2 == 0)
					pp[ii[h_]] = i, i = ii[h_];
				else
					pp[ii[h_]] = 0;
				h_++;
			}
		}
		memset(ft1, 0x3f, (n + 1) * sizeof *ft1);
		memset(ft2, 0x3f, (n + 1) * sizeof *ft2);
		update(ft1, n - 0, n + 1, 0);
		for (i = 1; i <= n; i++) {
			dp[i] = min(query(ft2, n - i), query(ft1, n - ll[i]) + 1);
			if (aa[i] % 2 == 0) {
				dq[i] = query(ft1, n - ll_[i]);
				if (pp[i] && ll_[i] <= pp[i])
					dq[i] = min(dq[i], dq[pp[i]] - 1);
			} else
				dq[i] = INF;
			update(ft1, n - i, n + 1, dp[i]);
			if (dq[i] != INF) {
				update(ft1, n - i, n + 1, dq[i]);
				update(ft2, n - rr_[i], n + 1, dq[i]);
			}
		}
		printf("%d\n", n + min(dp[n], dq[n]));
	}
	return 0;
}


/* https://codeforces.com/contest/1206/submission/59041923 (Dukkha) */
#include <stdio.h>
#include <stdlib.h>

#define N	1000

int next[1 + (N - 1) * 2], jj[1 + (N - 1) * 2];

int link(int l, int j) {
	static int l_ = 1;

	next[l_] = l;
	jj[l_] = j;
	return l_++;
}

int n;
int ao[N], cc[N];
int i_, j_, n_;

int dfs(int p, int i) {
	int l, j, c_, c;

	c = 1;
	for (l = ao[i]; l; l = next[l]) {
		j = jj[l];
		if (j != p)
			c += dfs(i, j);
	}
	c_ = c < n - c ? c : n - c;
	if (n_ < c_) {
		n_ = c_;
		if (c <= n - c) {
			i_ = i;
			j_ = p;
		} else {
			i_ = p;
			j_ = i;
		}
	}
	cc[i] = c;
	return c;
}

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return cc[i] - cc[j];
}

int a, b;

void dfs_(int p, int i, int c) {
	int l, j;

	a += b;
	printf("%d %d %d\n", p + 1, i + 1, a - c);
	c = a;
	for (l = ao[i]; l; l = next[l]) {
		j = jj[l];
		if (j != p)
			dfs_(i, j, c);
	}
}

int main() {
	static int tt[N];
	int h, i, j, k, l, s, n_, changed;

	scanf("%d", &n);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		ao[i] = link(ao[i], j);
		ao[j] = link(ao[j], i);
	}
	i_ = -1, j_ = -1, n_ = -1;
	dfs(-1, 0);
	s = j_;
	dfs(-1, s);
	k = 0;
	for (l = ao[s]; l; l = next[l])
		tt[k++] = jj[l];
	qsort(tt, k, sizeof *tt, compare);
	n_ = 1;
	b = 1, a = 0;
	changed = 0;
	for (h = 0; h < k; h++) {
		j = tt[h];
		dfs_(s, j, 0);
		n_ += cc[j];
		if (!changed && n_ * 3 >= n) {
			changed = 1;
			b = n_, a = 0;
		}
	}
	return 0;
}


#include <stdio.h>
#include <ctype.h>

// program by Mircea Rebengiuc
// written for codeforces round 740D2
// written on 2021.08.24

#define MAXN 200000

int psum[1 + MAXN + 1];

int mod;
int n;

static inline int getSum( int l, int r ){
  return (psum[l] - psum[(r < n ? r : n) + 1] + mod) % mod;
}

int main(){
  int i, j, d;

  scanf("%d%d", &n, &mod);
  psum[n] = 1;
  psum[n + 1] = 0;
  for( i = n - 1 ; i > 0 ; i-- ){
    psum[i] = getSum(i + 1, n);
    for( d = 2 ; i * d <= n ; d++ )
      psum[i] = (psum[i] + getSum(i * d, (i + 1) * d - 1)) % mod;

    psum[i] = (psum[i + 1] + psum[i]) % mod;
  }

  printf("%d\n", getSum(1, 1));

  return 0;
}


#include<stdio.h>

long long MOD=(long long)(1e9+7);

int main(){
	int n, m, i, prev, curr;
	long long tab[2][2], res;
	scanf("%d %d", &n, &m);
	curr=1;
	tab[1][0]=2;
	tab[1][1]=0;
	for(i=0;i<n-1;++i){
		curr=i&1;
		prev=(curr+1)&1;
		tab[curr][0]=(tab[prev][0]+tab[prev][1])%MOD;
		tab[curr][1]=tab[prev][0];
	}
	res=tab[curr][0]+tab[curr][1];
	if(m==1){
		printf("%I64d\n", res);
		return 0;
	}
	tab[1][0]=res-2+(n==1?2:0);
	tab[1][1]=0;
	for(i=0;i<m-1;++i){
		curr=i&1;
		prev=(curr+1)&1;
		tab[curr][0]=(tab[prev][1]+(tab[curr][1]=tab[prev][0]%MOD))%MOD;
	}
	printf("%I64d\n", ((n==1?0:2)+tab[curr][0]+tab[curr][1])%MOD);
	return 0;
}


#include<stdio.h>

long long MOD=(long long)(1e9+7);

int main(){
	int n, m, i, prev, curr;
	long long tab[2][2], res;
	scanf("%d %d", &n, &m);
	curr=1;
	tab[1][0]=2;
	tab[1][1]=0;
	for(i=0;i<n-1;++i){
		curr=i&1;
		prev=(curr+1)&1;
		tab[curr][0]=(tab[prev][0]+tab[prev][1])%MOD;
		tab[curr][1]=tab[prev][0];
	}
	res=tab[curr][0]+tab[curr][1];
	if(m==1){
		printf("%I64d\n", res);
		return 0;
	}
	res-=2;
	tab[1][0]=2;
	tab[1][1]=0;
	for(i=0;i<m-1;++i){
		curr=i&1;
		prev=(curr+1)&1;
		tab[curr][0]=(tab[prev][1]+(tab[curr][1]=tab[prev][0]%MOD))%MOD;
	}
	printf("%I64d\n", (res+tab[curr][0]+tab[curr][1])%MOD);
	return 0;
}


#include<stdio.h>

long long MOD=(long long)1e9+7;

int main(){
	int n, m, i, prev, curr;
	long long tab[2][2], res;
	scanf("%d %d", &n, &m);
	curr=1;
	tab[1][0]=2;
	tab[1][1]=0;
	for(i=0;i<n-1;++i){
		curr=i&1;
		prev=(curr+1)&1;
		tab[curr][0]=(tab[prev][0]+tab[prev][1])%MOD;
		tab[curr][1]=tab[prev][0];
	}
	res=tab[curr][0]+tab[curr][1];
	if(m==1){
		printf("%I64d\n", res);
		return 0;
	}
	tab[1][0]=res-2+(n==1?2:0);
	tab[1][1]=0;
	for(i=0;i<m-1;++i){
		curr=i&1;
		prev=(curr+1)&1;
		tab[curr][0]=(tab[prev][1]+(tab[curr][1]=tab[prev][0]%MOD))%MOD;
	}
	printf("%I64d\n", ((n==1?0:2)+tab[curr][0]+tab[curr][1])%MOD);
	return 0;
}


#include <bits/stdc++.h>

#define forin(i, start, end) for (auto (i) = (start); (i) != (end); ++(i))
#define forup(i, end) forin((i), 0, (end))

using ll = long long;

using namespace std;
ll N, A, B;
int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> A >> B;
	string bitstring;
	cin >> bitstring;
	ll num_adults = 0;
	for (char c : bitstring) {
		if (c == '1') num_adults++;
	}
	ll mini = LLONG_MAX;
	forin (p, 1, num_adults + 1) {
		ll child = N - p;
		ll in_each = child / p;
		ll left = child % p;
		ll total = p * (A + B * in_each * in_each) + B * left * (2*in_each + 1);
		mini = min(mini, total);
	}
	cout << mini << endl;
	return 0;
}


//#include <iostream>
//#include <string.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <sys/time.h>
//#include <unistd.h>
//#include <arpa/inet.h>
//#include <memory>
//#include <signal.h>
//#include <thread>
//#include <unistd.h>
//#include <sys/un.h>
//#include <string>

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
const int MAXN = 100000;

int n, m, d;

struct pair
{
	int c;
	int w;
}phys[MAXN], info[MAXN];

uint64_t phys_pref_cost[MAXN], phys_pref_width[MAXN];
uint64_t info_pref_cost[MAXN], info_pref_width[MAXN];

uint64_t total_cost = 0;

int comp (const void *a, const void *b)
{
	const struct pair * pa = (struct pair *)a;
	const struct pair * pb = (struct pair *)b;
	if (pa->c > pb->c) return -1;
	if (pa->c < pb->c) return 1;
	if (pa->w < pb->w) return -1;
	if (pa->w > pb->w) return 1;
	return 0;
}

int main()
{
	int i, j;
	int phys_width_pos = 0;
	int info_width_pos = 0;
	scanf("%d %d %d", &n, &m, &d);
	for (i = 0; i < n; ++i)
	{
		scanf("%d %d", &phys[i].c, &phys[i].w);
	}
	for (i = 0; i < m; ++i)
	{
		scanf("%d %d", &info[i].c, &info[i].w);
	}
	qsort(phys, n, sizeof(phys[0]), comp);
	qsort(info, m, sizeof(info[0]), comp);

	phys_pref_cost[0] = phys[0].c;
	phys_pref_width[0] =phys[0].w;
	for (i = 1; i < n; ++i)
	{
		phys_pref_cost[i] = phys_pref_cost[i - 1] + phys[i].c;
		phys_pref_width[i] = phys_pref_width[i - 1] + phys[i].w;
	}
	info_pref_cost[0] = info[0].c;
	info_pref_width[0] =info[0].w;
	for (i = 1; i < m; ++i)
	{
		info_pref_cost[i] = info_pref_cost[i - 1] + info[i].c;
		info_pref_width[i] = info_pref_width[i - 1] + info[i].w;
	}
	if (phys[0].w + info[0].w > d)
	{
		printf ("0\n");
		return 0;
	}
	{
		uint64_t max_width = d - info[0].w;
		i = 1;
		while (i < n && phys_pref_width[i] <= max_width)
		{
			++i;
		}
		phys_width_pos =  --i;
		if (total_cost < phys_pref_cost[i] + info[0].c)
		{
			total_cost = phys_pref_cost[i] + info[0].c;
		}
	}
	{
		uint64_t max_width = d - phys[0].w;
		i = 1;
		while (i < m && info_pref_width[i] <= max_width)
		{
			++i;
		}
		info_width_pos = --i;
		if (total_cost < info_pref_cost[i]+ phys[0].c)
		{
			total_cost = info_pref_cost[i] + phys[0].c;
		}
	}

	{
		int c_info_pos = 1;
		while(phys_width_pos &&
			  info_pref_width[c_info_pos] +
			  phys_pref_width[phys_width_pos] > d)
		{
			--phys_width_pos;
		}
		while (phys_width_pos && c_info_pos < m)
		{
			while (info_pref_width[c_info_pos] +
				   phys_pref_width[phys_width_pos] <= d)
			{
				++c_info_pos;
			}
			--c_info_pos;
			if (info_pref_cost[c_info_pos] +
				phys_pref_cost[phys_width_pos] > total_cost)
			{
				total_cost = info_pref_cost[c_info_pos] +
							 phys_pref_cost[phys_width_pos];
			}
			--phys_width_pos;
		}
	}
	{
		int c_phys_pos = 1;
		while (info_width_pos &&
			   (info_pref_width[info_width_pos] +
								  phys_pref_width[c_phys_pos] > d))
		{
			--info_width_pos;
		}
		while (info_width_pos && c_phys_pos < n)
		{
			while (info_pref_width[info_width_pos] +
				   phys_pref_width[c_phys_pos] <= d)
			{
				++c_phys_pos;
			}
			--c_phys_pos;
			if (info_pref_cost[info_width_pos] +
				phys_pref_cost[c_phys_pos] > total_cost)
			{
				total_cost = info_pref_cost[info_width_pos] +
							 phys_pref_cost[c_phys_pos];
			}
			--info_width_pos;
		}
	}
	printf ("%I64d\n", total_cost);
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define N 100*1000+7

int a[N], A[N];
int b[N], B[N];
int ia[N], ib[N];

int comp1 (const void * elem1, const void * elem2)
{
    int f = a[*((int*)elem1)];
    int s = a[*((int*)elem2)];
    if (f == s)
    {
        int F = A[*((int*)elem1)];
        int S = A[*((int*)elem2)];
        if (F > S) return -1;
        if (F < S) return 1;
        return 0;
    }
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}

int comp2 (const void * elem1, const void * elem2)
{
    int f = b[*((int*)elem1)];
    int s = b[*((int*)elem2)];
    if (f == s)
    {
        int F = B[*((int*)elem1)];
        int S = B[*((int*)elem2)];
        if (F > S) return -1;
        if (F < S) return 1;
        return 0;
    }
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}

void main()
{
    int n, m, w;
    scanf("%d %d %d", &n, &m, &w);
    for (int i=0; i<n; i++)
        scanf("%d %d", a + i, A + i);
    for (int i=0; i<m; i++)
        scanf("%d %d", b + i, B + i);
    for (int i=0; i<n; i++)
        ia[i] = i;
    for (int i=0; i<m; i++)
        ib[i] = i;
    qsort (ia, n, sizeof(*ia), comp1);
    qsort (ib, m, sizeof(*ib), comp2);
    long long sum = 0, res = 0;
    for (int i=0; i<m; i++)
        sum += B[ib[i]], res += b[ib[i]];
    int p = 0;
    long long SUM = 0, RES = 0;
    long long ans = 0;
    for (int i=n-1; i>=0; i--)
    {
        SUM += A[ia[i]];
        RES += a[ia[i]];
        while (p+1 < m && SUM + sum > w)
            sum -= B[ib[p]], res -= b[ib[p]], p++;
        if (SUM + sum <= w && ans < RES + res)
            ans = RES + res;
    }
    printf("%I64d\n", ans);
}


#include <stdio.h>
#include <stdint.h>
#define ll int64_t

struct pr
{
    ll f, s;
} a[100001], b[100001];

int cmp(const void* p1, const void* p2)
{
    ll d = - ((const struct pr*)p1)->f + ((const struct pr*)p2)->f;
    if (d) return d < 0 ? -1 : 1;
    return ((const struct pr*)p1)->s - ((const struct pr*)p2)->s > 0 ? 1 : -1;
}

int main()
{
    int n, m; ll d;
    scanf("%d%d%I64d", &n, &m, &d);
    for(int i = 0; i < n; ++i)
    {
        scanf("%I64d%I64d", &(a[i].f), &(a[i].s));
    }
    for(int i = 0; i < m; ++i)
    {
        scanf("%I64d%I64d", &(b[i].f), &(b[i].s));
    }
    //printf("%lld %lld %lld %lld\n", a[0].f, a[0].s, b[0].f, b[0].s);
    qsort(a, n, sizeof(struct pr), cmp);
    qsort(b, m, sizeof(struct pr), cmp);
 //printf("%lld %lld %lld %lld\n", a[0].f, a[0].s, b[0].f, b[0].s);
    for(int i = 1; i < n; ++i)
    {
        a[i].f += a[i-1].f;
        a[i].s += a[i-1].s;
    }
    for(int i = 1; i < m; ++i)
    {
        b[i].f += b[i-1].f;
        b[i].s += b[i-1].s;
    }
    int i = 0, j = 0;
    if (a[0].s + b[0].s > d)
    {
        printf("0");
        return 0;
    }
    while(i < n && a[i].s + b[0].s <= d) ++i;
    ll ans = 0;
    //printf("%lld %lld %lld %lld\n", a[0].f, a[0].s, b[0].f, b[0].s);
    while(j < m && i >= 0)
    {
        if (a[i].s + b[j].s <= d)
        {
            if (a[i].f + b[j].f > ans) ans = a[i].f + b[j].f;
            ++j;
        }
        else --i;
    }
    printf("%I64d", ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define MAXN 100100

struct cup {
	int w;
	int v;
} phys[MAXN], inf[MAXN];
typedef struct cup cup;

int cupcmp(const void *a, const void *b)
{
	return -((const cup *)a)->v  + ((const cup *)b)->v;
}

int main()
{
	int N, M, D;
	scanf("%d%d%d", &N, &M, &D);
	for (int i = 0; i < N; ++i) {
		scanf("%d%d", &phys[i].v, &phys[i].w);
	}
	for (int i = 0; i < M; ++i) {
        scanf("%d%d", &inf[i].v, &inf[i].w);
    }
	qsort(phys, N, sizeof (phys[0]), cupcmp);
	qsort(inf, M, sizeof (inf[0]), cupcmp);
    int f = 0;
    int c = 0;
    long long sum = phys[0].v + inf[0].v;
    long long maxsum = sum;
    long long width = phys[0].w + inf[0].w;
    if (width > D) {
	    printf("0\n");
	    return 0;
    }
    for (f = 1; f < N; ++f) {
	    if (phys[f].w + width > D) {
		    break;
	    } else {
		    width += phys[f].w;
		    sum += phys[f].v;
		    maxsum = maxsum < sum ? sum : maxsum;
	    }
    }
    f--;
    while (1) {
	    if (c + 1 < M && width + inf[c + 1].w <= D) {
		    c++;
		    width += inf[c].w;
		    sum += inf[c].v;
            maxsum = maxsum < sum ? sum : maxsum;
	    } else if (f != 0) {
		    width -= phys[f].w;
		    sum -= phys[f].v;
		    f--;
            maxsum = maxsum < sum ? sum : maxsum;
	    } else {
		    break;
	    }
    }
    printf("%I64d\n", maxsum);
	return 0;
}


#include<stdio.h>

int slen, tlen, dar[202][202][402], soln[202][202][402];
char s[202], t[202], finale[2003];

int dp(int i, int j, int k){
  if(i >= slen && j >= tlen)return k;
  if(dar[i][j][k] == -1){
    int req[2];
    req[0] = req[1] = 0;
    if(i < slen)req[s[i] == ')']++;
    if(j < tlen)req[t[j] == ')']++;
    int toret = 2003;
    if(req[1] && k){
      int got, newi, newj;
      newi = i + (i < slen && s[i] == ')');
      newj = j + (j < tlen && t[j] == ')');
      got = 1 + dp(newi, newj, k - 1);
      if(got < toret){
	soln[i][j][k] = ')';
	toret = got;
      }
    }
    if(req[0] || !k){
      int got, newi, newj;
      newi = i + (i < slen && s[i] == '(');
      newj = j + (j < tlen && t[j] == '(');
      got = 1 + dp(newi, newj, k + 1);
      if(got < toret){
	soln[i][j][k] = '(';
	toret = got;
      }
    }
    dar[i][j][k] = toret;
  }
  return dar[i][j][k];
}

int main(){
  scanf("%s", s);
  for(slen = 0;s[slen] != '\0';slen++);
  scanf("%s", t);
  for(tlen = 0;t[tlen] != '\0';tlen++);
  int i, j , k, idx, ans;
  for(i = 0;i <= slen;i++)for(j = 0;j <= tlen;j++)for(k = 0;k < 402;k++){
	dar[i][j][k] = -1;
	soln[i][j][k] = 'X';
      };
  idx = 0;
  ans = dp(0, 0, 0);
  i = j = k = 0;
  while(soln[i][j][k] != 'X'){
    finale[idx++] = soln[i][j][k];
    if(soln[i][j][k] == '('){
      if(i < slen && s[i] == '(')i++;
      if(j < tlen && t[j] == '(')j++;
      k++;
    }
    else{
      if(i < slen && s[i] == ')')i++;
      if(j < tlen && t[j] == ')')j++;
      k--;
    }
  }
  while(idx < ans)finale[idx++] = ')';
  finale[ans] = '\0';
  i = j = k = 0;
  printf("%s\n", finale);
  return 0;
}


#include <stdio.h>
#include <string.h>

#define N	202

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int vv[N + 1], ff[N + 1], gg[N + 1];

void init(int md) {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - md % i] * (md / i + 1) % md;
		ff[i] = (long long) ff[i - 1] * i % md;
		gg[i] = (long long) gg[i - 1] * vv[i] % md;
	}
}

int main() {
	static int dp[N + 1][N + 1];
	int n, md, a, b, k, l, s, ans;

	scanf("%d%d", &n, &md), init(md);
	ans = 0;
	for (a = 1; a <= n + 1; a++) {
		for (k = 0; k <= n; k++)
			memset(dp[k], 0, (a + 1) * sizeof *dp[k]);
		dp[0][0] = 1;
		for (b = a; b <= n + 1; b++) {
			for (k = n; k >= 0; k--)
				for (s = 0; s + (n - k) * (b - a) <= a && s + k * a <= a * (b - 1); s++) {
					int x = dp[k][s], k_, s_, lower, upper;

					if (x == 0)
						continue;
					/* l >= 1
					 * k + l <= n
					 * s + l * (b - a) + (n - (k + l)) * (b + 1 - a) <= a
					 * s + l * (b - a) + (k + l) * a <= a * b
					 *
					 * l >= 1
					 * l <= n - k
					 * l >= s + (n - k) * (b + 1 - a) - a
					 * l <= (a * b - s - k * a) / b
					 */
					lower = max(1, s + (n - k) * (b + 1 - a) - a);
					upper = min(n - k, (a * b - s - k * a) / b);
					for (l = lower; l <= upper; l++) {
						k_ = k + l, s_ = s + l * (b - a);
						dp[k_][s_] = (dp[k_][s_] + (long long) dp[k][s] * gg[l]) % md;
					}
				}
			if (b == a)
				dp[0][0] = 0;
		}
		for (s = 0; s <= a; s++)
			ans = (ans + (long long) dp[n][s] * ff[n]) % md;
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>
#define N (10000000 + 5)
int p, q, pi[N], rub[N], prime[N], mark[N];
void make_prime(){
	for (int i = 2; i < N; ++i){
		if (!mark[i]) prime[++prime[0]] = i;
		for (int j = 1; j <= prime[0] && i * prime[j] < N; ++j){
			mark[i * prime[j]] = 1;
			if (i % prime[j] == 0) break;
		}
	}
	int ptr = 1;
	for (int i = 2; i < N; ++i)
		if (prime[ptr] == i) pi[i] = pi[i - 1] + 1, ++ptr;
		else pi[i] = pi[i - 1];
}
int ispalin(const int x){
	int tmp1 = 0, tmp2 = x;
	for (; tmp2; tmp2 /= 10) tmp1 = tmp1 * 10 + tmp2 % 10;
	return x == tmp1;
}
void make_palin(){
	for (int i = 1; i < N; ++i) rub[i] = rub[i - 1] + ispalin(i);
}
int main(int argc, char **argv){
	make_prime();
	make_palin();
	scanf("%d%d", &p, &q);
	for (int i = N - 1; i; --i)
		if (pi[i] <= (double)rub[i] * p / q){
			printf("%d\n", i);
			return 0;
		}
	printf("Palindromic tree is better than splay tree\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define MAX (1L << 22)

char iscomp[MAX];

typedef long long ll;
void
do_comp (void)
{
	int i;

	iscomp[1] = 1;

        for (i = 2; i < MAX; i++) {
                int     jx;
                int     sx;

                if (iscomp[i]) {
                        continue;
                }

		if (i * i > MAX) {
			break;
		}
                for (jx = i; (jx * i) < MAX ;jx++) {
                        sx = jx * i;
                        if (!iscomp[sx]) iscomp[sx] = 1;
                }
        }
}

int
ispal (int inp)
{
	int	i, j;
	char	tmp[32];
	int	len;

	sprintf(tmp, "%d", inp);
	len = strlen(tmp)-1;

	for (i = 0, j = len; i <= j; i++, --j) {
		if (tmp[i] != tmp[j]) {
			return 0;
		}
	}

	return 1;
}

int
main ()
{
	int	i,n = 1;
	int	p, q;
	int	npr = 0, npa = 0;
	int	ans = 0;

	do_comp();
	scanf ("%d%d", &p, &q);

	for (i = 1; i < MAX; i++) {
		npa += ispal (i);
		npr += !(iscomp[i]);

		if ((ll)q * npr <= (ll)p * npa) {
			ans = i;
		}
	}
	if (ans) {
		printf ("%d\n", ans);
	} else {
		puts ("Palindromic tree is better than splay tree");
	}

	return 0;
}


#include <stdio.h>
#define max 2000001
int prime[max],pal[max],digits[10];

int isPalindrome(int a){
    int temp=a,i=0;
    while(temp!=0){
        digits[i++]=temp%10;
        temp/=10;
    }
    int k=i-1;
    i=0;
    while(i<k && digits[i]==digits[k]){
        i++;
        k--;
    }
    if(i<k)
        return 0;
    else{
        return 1;
    }
}

void set(){
int i=2;
while(i<max){
    int j=2;
    int p=j*i;
    while(p<max){
        prime[p]=1;
        j++;
        p=i*j;
    }
    i++;
    while(prime[i]==1)
        i++;
}
int count=0;
for(i=2;i<max;i++){
    if(prime[i]==0)
        prime[i]=(++count);
    else
        prime[i]=count;
}

i=1;
//printf("test\n");
while(i<max){
        pal[i]=pal[i-1];
    if(isPalindrome(i))
        pal[i]+=1;
 i++;
}
}

int main(){
int p,q,i=1;
set();
int res=-1;
scanf("%d%d",&p,&q);
while(i<max){
    if(q*prime[i]<=p*pal[i]){
        res=i;
    }
    i++;
}
if(res==-1)
printf("Palindromic tree is better than splay tree");
else
    printf("%d\n",res);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define SQR 1097
#define MAX 1200000
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define chkbit(ar, i) (((ar[(i) >> 6]) & (1 << (((i) >> 1) & 31))))
#define setbit(ar, i) (((ar[(i) >> 6]) |= (1 << (((i) >> 1) & 31))))
#define isprime(x) (( (x) && ((x)&1) && (!chkbit(ar, (x)))) || ((x) == 2))

char str[12];
long long p, q;
unsigned int ar[(MAX >> 6) + 5] = {0};
int m = 0, counter[MAX] = {0}, P[12010];

void Sieve(){
    int i, j, k;
    setbit(ar, 0), setbit(ar, 1);

    for (i = 3; i < SQR; i++, i++){
        if (!chkbit(ar, i)){
            k = i << 1;
            for (j = (i * i); j < MAX; j += k) setbit(ar, j);
        }
    }

    k = 0, counter[2] = ++k;
    for (i = 3; (i + 1) < MAX; i++, i++){
        if (isprime(i)) k++;
        counter[i] = counter[i + 1] = k;
    }
}

void backtrack(int i, int j){
    if (i > j){
        int x = atoi(str);
        if (x < MAX) P[m++] = x;
        return;
    }

    int k;
    for (k = 0; k < 10; k++){
        if (!i && !k) continue;
        str[i] = str[j] = k + 48;
        backtrack(i + 1, j - 1);
    }
}

void Generate(){
    m = 0;
    int i, j;
    for (i = 1; i <= 7; i++){
        str[i] = 0;
        backtrack(0, i - 1);
    }
}

bool Check(int n, int i){
    long long x = q * counter[n];
    long long y = p * (i + 1);
    return (x <= y);
}

int main(){
    Sieve();
    Generate();
    int n, i, j, low, high, mid, res;

    while (scanf("%I64d %I64d", &p, &q) != EOF){

        res = -1;
        for (i = m - 2; i >= 0; i--){
            if (Check(P[i], i)){
                low = P[i], high = P[i + 1] - 1;

                while ((low + 1) < high){
                    mid = (low + high) >> 1;
                    if (Check(mid, i)) low = mid;
                    else high = mid;
                }

                if (Check(high, i)) res = high;
                else if (Check(low, i)) res = low;
                if (res != -1) break;
            }
        }

        if (res == -1) puts("Palindromic tree is better than splay tree");
        else printf("%d\n", res);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define MAX (1L << 22)

char iscomp[MAX];

void
do_comp (void)
{
	int i;

	iscomp[1] = 1;

        for (i = 2; i < MAX; i++) {
                int     jx;
                int     sx;

                if (iscomp[i]) {
                        continue;
                }

		if (i * i > MAX) {
			break;
		}
                for (jx = i; (jx * i) < MAX ;jx++) {
                        sx = jx * i;
                        if (!iscomp[sx]) iscomp[sx] = 1;
                }
        }
}

int
ispal (int inp)
{
	int	i, j;
	char	tmp[32];
	int	len;

	sprintf(tmp, "%d", inp);
	len = strlen(tmp)-1;

	for (i = 0, j = len; i <= j; i++, --j) {
		if (tmp[i] != tmp[j]) {
			return 0;
		}
	}

	return 1;
}

int
main ()
{
	int	i,n = 1;
	int	p, q;
	int	npr = 0, npa = 0;
	int	ans = 0;

	do_comp();
	scanf ("%d%d", &p, &q);

	for (i = 1; i < MAX; i++) {
		npa += ispal (i);
		npr += !(iscomp[i]);

		if (q * npr <= p * npa) {
			ans = i;
		}
	}
	if (ans) {
		printf ("%d\n", ans);
	} else {
		puts ("Palindromic tree is better than splay tree");
	}

	return 0;
}


//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int main(void){
  long long i,j,n,m,k,a,b,c,h,w,r=0,l,t,p;
  scanf("%lld%lld",&n,&p);
  for(i=1;i<=60;i++){
    if((n-i*p)<=0){continue;}
    if(lldsumb(n-i*p,2)<=i && i<=(n-i*p)){
      printf("%lld\n",i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


#include <stdio.h>
#define A(x) (x > 0 ? x : -x)
long long dC(long long a)
{
	long long r = 0;
	a = A(a);
	while (a)
	{
		a -= a & -a;
		r++;
	}
	return r;
}
int main()
{
	long long t;
	long long n, p;
	long long B = 1;
	long long temp;
	scanf("%I64d %I64d", &n, &p);
	for (t = 1; B + t * p <= n; t++)
	{
		temp = n - t * p;
		if (t >= dC(temp))
		{
			break;
		}
		B++;
		B <<= 1;
		B--;
	}
	if (B + t * p <= n)
	{
		printf("%I64d", t);
	}
	else
	{
		printf("-1");
	}
	return 0;
}


#include<stdio.h>

int bitc(int x){
  int toret;
  for(toret = 0;x;x&=(x - 1))toret++;
  return toret;
}

int main(){
  int n, p;
  scanf("%d %d", &n, &p);
  int i, ans;
  ans = -1;
  for(i = 1;i < 900;i++){
    int rem = n - i*p;
    if(rem >= i && bitc(rem) <= i) {ans = i;break;}
  }
  printf("%d\n", ans);
  return 0;
}


#include<stdio.h>
int main()
{
    long long int n,i,k=0,x,d,r,p;
    scanf("%lld %lld",&n,&p);
    i=1;
    while(k==0)
    {
      d=0;

      x=n-i*p;
      if(x<=0)
      {printf("-1");
       break;
      }
      else
      {
       while(x!=0)
       {
         r=x%2;
         if(r==1)
         {d++;}
         if(d>i)
         {
          break;
         }
         x=x/2;
       }
       x=n-i*p;
       if(d<=i&&i<=x)
       {
        printf("%lld",i);
        break;
       }
      }
      i++;
    }
    return 0;
}


#define l long long
l n;
c;
f(x) {
	for (c = 0; x; c++) x ^= x & -x;
	return c;
}
main(k, i) {
	scanf("%lld%d", &n, &k);
	for (i = 1; i <= 1.1e6; i++)
		if (n - k * i >= i && f(n - k * i) <= i) return !printf("%lld", i);
	puts("-1");
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N_LIMIT 1000003 // 1e6+3
typedef long long ll;

ll a_pows[N_LIMIT];

ll inv(ll x, ll p)
{
    ll result = 1, y;
    //printf("inverse of %lld is ", x);
    while (x != 1)
    {
        y = (x+p)/x;
        result *= y;
        result %= p;
        x = (x*y)%p;
    }
    //printf("%lld\n", result);
    return result;
}

int main(int argc, char *argv)
{
    ll a, b, p, x, d = 1;

    ll n, m, y, z;
    ll pdi;
    ll count;
    int i;
    scanf("%lld %lld %lld %lld", &a, &b, &p, &x);
    a_pows[0] = 1;
    a_pows[1] = a;
    while (a != 1)
    {
        d++;
        a = (a*a_pows[1]) % p;
        a_pows[d] = a;
    }
    //printf("d: %lld\n", d);
    count = 0;
    pdi = inv(p-d, p);
    for (m=0; m<d; m++)
    {
        n = (a_pows[d-m] * b) % p;
        z = (pdi * (m-n)) % p;
        if (z < 0)
        {
            z += p;
        }

        //printf("m:%lld n:%lld z:%lld count:%lld\n", m, n, z, count);
        count += (x-m)/(p*d);
        if (x%(p*d) >= z*d+m)
        {
            count += 1;
        }
    }
    printf("%lld\n", count);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N_LIMIT 1000003 // 1e6+3
typedef long long ll;

ll a_pows[N_LIMIT];

ll inv(ll x, ll p)
{
    ll result = 1, y;
    //printf("inverse of %lld is ", x);
    while (x != 1)
    {
        y = (x+p)/x;
        result *= y;
        x = (x*y)%p;
    }
    //printf("%lld\n", result);
    return result;
}

int main(int argc, char *argv)
{
    ll a, b, p, x, d = 1;

    ll n, m, y, z;
    ll pdi;
    ll count;
    int i;
    scanf("%lld %lld %lld %lld", &a, &b, &p, &x);
    a_pows[0] = 1;
    a_pows[1] = a;
    while (a != 1)
    {
        d++;
        a = (a*a_pows[1]) % p;
        a_pows[d] = a;
    }
    //printf("d: %lld\n", d);
    count = 0;
    pdi = inv(p-d, p);
    for (m=0; m<d; m++)
    {
        n = (a_pows[d-m] * b) % p;
        z = (pdi * (m-n)) % p;
        if (z < 0)
        {
            z += p;
        }

        //printf("m:%lld n:%lld z:%lld count:%lld\n", m, n, z, count);
        count += (x-m)/(p*d);
        if (x%(p*d) >= z*d+m)
        {
            count += 1;
        }
    }
    printf("%lld\n", count);

    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#define SORT(a,n) qsort(a,n,sizeof(int),intcmp)
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%Lf",&n)
#define ss(n)                       scanf("%s",n)
#define fill(a,v)                   memset(a, v, sizeof a)
int intcmp(const void *f,const void *s)
{
   return (*(int *)f-*(int *)s);
}
int gcd(int a,int b){ return ((b==0)?a:gcd(b,a%b));}

#define MAX
#define MODBY 1000000007
#define NIL (1e-8)

typedef long long int lld;
typedef long double Lf;

int i,j,n;
Lf x,y,z;
int vix,viy,viz;
int a,b;
Lf vx,vy,vz;
Lf tmin,t1;
int cmp(Lf f,Lf s)
{ return ((fabs(f-s)<NIL));}
int main()
{
   s(a);s(b);sf(y);
   s(vix);s(viy);s(viz);
   vx=vix;vy=viy;vz=viz;
   z=0;x=a/2.0;

   //printf("ball is at %Lf,%Lf,%Lf\n",x,y,z);
   //   while(!cmp(y,0)){
   int cnt=18;
   while(y>0){
      tmin=INT_MAX;
      if(vix){
         t1=-x/vx;//x=0 plane

         if((t1>0)&&(t1<tmin)){
            tmin=t1;
         }
         t1=-(x-a)/vx;
         if((t1>0)&&(t1<tmin)){
            tmin=t1;
         }
      }
      if(viz){
         t1=-z/vz;//z=0 plane
         if((t1>0)&&(t1<tmin)){
            tmin=t1;
         }
         t1=-(z-b)/vz;
         if((t1>0)&&(t1<tmin)){
            tmin=t1;
         }
      }
      if(viy){
         t1=-y/vy;//y=0 plane
         if((t1>0)&&(t1<tmin)){
            tmin=t1;
         }
      }
      x=x+vx*tmin;
      y=y+vy*tmin;
      z=z+vz*tmin;
   //   printf("ball is at %Lf,%Lf,%Lf\n",x,y,z);
      if(vix!=0)
         if((x==0)||(x==a)) vx*=-1;
      if(viz!=0){
         if((z==0)||(z==b)) vz*=-1;
      }
      //else break;
   }
   printf("%Lf %Lf\n",x,z);
   return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#define SORT(a,n) qsort(a,n,sizeof(int),intcmp)
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%Lf",&n)
#define ss(n)                       scanf("%s",n)
#define fill(a,v)                   memset(a, v, sizeof a)
int intcmp(const void *f,const void *s)
{
   return (*(int *)f-*(int *)s);
}
int gcd(int a,int b){ return ((b==0)?a:gcd(b,a%b));}

#define MAX
#define MODBY 1000000007
#define NIL (1e-8)

typedef long long int lld;
typedef long double Lf;

int i,j,n;
Lf x,y,z;
int vix,viy,viz;
int a,b;
Lf vx,vy,vz;
Lf tmin,t1;
int cmp(Lf f,Lf s)
{ return ((fabs(f-s)<NIL));}
int main()
{
   s(a);s(b);sf(y);
   s(vix);s(viy);s(viz);
   vx=vix;vy=viy;vz=viz;
   z=0;x=a/2.0;

   //printf("ball is at %Lf,%Lf,%Lf\n",x,y,z);
   //   while(!cmp(y,0)){
   int cnt=18;
   while(y>0){
      tmin=INT_MAX;
      if(vix){
         t1=-x/vx;//x=0 plane
         if((t1>NIL)&&(t1<tmin)){
            tmin=t1;
         }
         t1=-(x-a)/vx;
         if((t1>NIL)&&(t1<tmin)){
            tmin=t1;
         }
      }
      if(viz){
         t1=-z/vz;//z=0 plane
         if((t1>NIL)&&(t1<tmin)){
            tmin=t1;
         }
         t1=-(z-b)/vz;
         if((t1>NIL)&&(t1<tmin)){
            tmin=t1;
         }
      }
      if(viy){
         t1=-y/vy;//y=0 plane
         if((t1>NIL)&&(t1<tmin)){
            tmin=t1;
         }
      }
      x=x+vx*tmin;
      y=y+vy*tmin;
      z=z+vz*tmin;
   //   printf("ball is at %Lf,%Lf,%Lf\n",x,y,z);
      if(vix!=0)
         if((x==0)||(x==a)) vx*=-1;
      if(viz!=0){
         if((z==0)||(z==b)) vz*=-1;
      }
      //else break;
   }
   printf("%Lf %Lf\n",x,z);
   return 0;
}


#include<stdio.h>
#include <math.h>

int main(){
	//freopen("in.txt", "r", stdin);
	int a, b, m, speedx, speedy, speedz;
	scanf("%d%d%d%d%d%d", &a, &b, &m, &speedx, &speedy, &speedz);
	double posx, posy=m, posz;
	double costtime = -posy / speedy;
	double xpass = fabs(speedx * costtime), zpass = fabs(speedz * costtime);
	if(speedz == 0)
		posz = 0;
	else{
		int round = zpass/b;
		posz = zpass - round*b;
		if(round%2==1)
			posz = b - posz;
	}
	if(speedx == 0)
		posx = 0.5 * a;
	else{
		xpass += 0.5 * a;
		if(speedx < 0)
			xpass += a;
		int round = xpass/a;
		posx = xpass - round*a;
		if(round%2==1)
			posx = a - posx;
	}
	printf("%.8lf %.8lf\n", posx, posz);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(){
    double a, b, m, vx, vy, vz, x, z, t;
    scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &m, &vx, &vy, &vz);
    t = m / -vy;
    x = a / 2 + vx * t;
    z = vz * t;
    if (x < 0)x = -x;
    if ((int)(x / a) % 2)
       x = a - (x - (int)(x / a) * a);
    else x -= (int)(x / a) * a;
    if ((int)(z / b) % 2)
       z = b - (z - (int)(z / b) * b);
    else z -= (int)(z / b) * b;
    printf("%.7lf %.7lf\n", x, z);
    scanf(" ");
    return 0;
}


/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:28/09/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define REP(i,n)        for(long long i=0;i<(n);i++)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);i--)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((int)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)            strlen(a)
#define MOD             1000000007
#define MAX             10000000005
#define MIN             -10000000005
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))

const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
int main()
{
	ll n,m;
	SC2(n,m);
	unsigned long long ans=0;
	n++;
	ll x=2*n;
	unsigned long long z=binpow(x,m,MOD);
	z=z%MOD;
	unsigned long long z1=(n-m)%MOD;
	unsigned long long z2=(z*z1)%MOD;
	ans=(z2/n);
	ans=ans%MOD;
	printf("%llu\n",ans);

	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return -1;
    if( *(ll*)a - *(ll*)b > 0 ) return 1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}


#include <stdio.h>
int main (void)
{
    int *a;
    int b,i,k=100,x=0;
    scanf("%d",&b);
    a = malloc(b*sizeof(int));
    for(i=0;i<b;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<k)
            k=a[i];
    }
    for(i=0;i<b;i++)
        if(a[i]==k)
            x++;
    if(x>b/2)
    printf("Bob\n");
    else
    printf("Alice\n");
    return 0;
}


#include<stdio.h>
int main(){
    int n, i;
    scanf("%d", &n);
    int a[n], j;
    for(i = 0; i < n; i++)
        scanf("%d", &a[i]);

/*
    for(i = 0; i < n - 1; i++){
        for(j = i + 1; j < n; j++){
            if(a[i] < a[j]){
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    if(a[0] == a[n/2])
        printf("Bob");
    else
        printf("Alice");
    return 0;
}
*/
    int count = 0;
    j = a[0];
    for(i = 0; i < n; i++){
        if(a[i] < j)
            j = a[i];
    }
    for(i = 0; i < n; i++){
        if(a[i] == j)
            count++;
    }
    if(count <= (n/2))
        printf("Alice");
    else
        printf("Bob");
    return 0;
}


#include <stdio.h>
int main(void)
{
    int *a;
    int b,i,k=100,x=0;
    scanf("%d",&b);
    a = malloc(b*sizeof(int));
    for(i=0;i<b;i++)
    {
        scanf("%d", &a[i]);
        if(a[i]<k)k=a[i];
    }
    for(i=0; i<b; i++)
        if(a[i]==k)x++;
    if(x>b/2)printf("Bob\n");
    else printf("Alice\n");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main (void)
{
	int pilas, i;
	int *numeros;
	scanf("%d",&pilas);
	numeros = (int*)malloc(pilas * sizeof(int));
	for(i=0;i<pilas;i++)
		scanf("%d",&numeros[i]);

	i=0;
	while(1)
	{
		pilas=pilas/2;
		i++;
		if((pilas%2)!=0)
		{
			if((i%2)==0)
			{
				printf("Alice");
				exit(0);
			}
			else
			{
				printf("Bob");
				exit(0);
			}
		}
	}
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	24

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int cc[N], ss[N], aa[1 << N - 1], dp[1 << N - 1];
	int n, m, i, j, k, b;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &cc[i]);
	qsort(cc, n, sizeof *cc, compare);
	k = 0;
	while (k < n && cc[k] == 1)
		k++;
	m = n - k;
	for (i = k; i < n; i++)
		ss[i - k] = cc[i] - 1;
	for (j = 1; j < m; j++)
		ss[j] += ss[j - 1];
	n--;
	for (b = 1; b < 1 << n; b++) {
		i = 0;
		while ((b & 1 << i) == 0)
			i++;
		aa[b] = aa[b ^ 1 << i] + cc[i];
	}
	memset(dp, -1, (1 << n) * sizeof *dp), dp[0] = 0;
	for (b = 0; b < 1 << n; b++) {
		j = dp[b];
		if (j == -1 || j == m)
			continue;
		for (i = 0; i < n; i++)
			if ((b & 1 << i) == 0) {
				int b_ = b ^ 1 << i;

				if (aa[b_] < ss[j])
					dp[b_] = j;
				else if (aa[b_] == ss[j] && aa[b] > (j == 0 ? 0 : ss[j - 1]))
					dp[b_] = j + 1;
			}
	}
	printf(dp[(1 << n) - 1] == m ? "YES\n" : "NO\n");
	return 0;
}


/* upsolve using zigzag */
/* https://codeforces.com/blog/entry/73563 */
#include <stdio.h>
#include <string.h>

#define N	1024

int query(int i) {
	if (i == -1) {
		printf("R\n"), fflush(stdout);
		return 0;
	} else {
		static char s[2];

		printf("? %d\n", i + 1), fflush(stdout);
		scanf("%s", s);
		return s[0] == 'N';
	}
}

int main() {
	static char alive[N];
	int n, k, m, g, h, i, ans;

	scanf("%d%d", &n, &k), m = n / k;
	memset(alive, 1, n * sizeof *alive);
	for (g = 0; g < m; g++) {
		query(-1);
		for (h = 0; h < m; h++) {
			int g_ = (g + (h % 2 == 0 ? h / 2 : m - (h + 1) / 2)) % m, l = g_ * k, r = (g_ + 1) * k;

			for (i = l; i < r; i++)
				if (alive[i] && !query(i))
					alive[i] = 0;
		}
	}
	ans = 0;
	for (i = 0; i < n; i++)
		if (alive[i])
			ans++;
	printf("! %d\n", ans), fflush(stdout);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 2000010
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

short len[MAX];
char mu[MAX], flag[MAX];
int prime[MAX], dp[MAX], sum[MAX], power[MAX], L[MAX], *divisors[MAX];

int expo(int a, int b){
    int res = 1;

    while (b){
        if (b & 1) res = (long long)res * a % MOD;
        a = (long long)a * a % MOD;
        b >>= 1;
    }
    return res;
}

void mobius(){
    mu[1] = 1;
    int i, j, k, p = 0;

    for (i = 2; i < MAX; i++){
        if (!flag[i]) mu[i] = -1, prime[p++] = i;
        for (j = 0; j < p && (k = i * prime[j]) < MAX; j++){

            flag[k] = true;
            if (!(i % prime[j])){
                mu[k] = 0;
                break;
            }
            else mu[k] -= mu[i];
        }
    }
    for (i = 1; i < MAX; i++) sum[i] = sum[i - 1] + mu[i];
}

void generate(){
    mobius();
    int i, j, k, c, d, x;

    len[0] = len[1] = L[0] = L[1] = 1;
    for (i = 4; i < MAX; i++, i++) len[i] = 2;

    for (i = 3; (i * i) < MAX; i += 2){
        if (!len[i]){
            for (j = (i * i), d = i << 1; j < MAX; j += d){
                if (!len[j]) len[j] = i;
            }
        }
    }

    for (i = 2; i < MAX; i++){
        if (!len[i]) L[i] = i;
        else{
            L[i] = len[i];
            x = L[i /len[i]];
            if (x > L[i]) L[i] = x;
        }
    }

    divisors[1] = (int *) malloc(sizeof(int));
    divisors[1][0] = 1, len[1] = 1;

    for (i = 2; i < MAX; i++){
        c = 0, k = i;
        while (k > 1 && L[k] == L[i]){
            c++;
            k /= L[k];
        }

        len[i] = (c + 1) * len[k];
        divisors[i] = (int *) malloc(sizeof(int) * len[i]);

        for (x = 1, j = 0, len[i] = 0; j <= c; j++, x *= L[i]){
            for (d = 0; d < len[k]; d++){
                divisors[i][len[i]++] = divisors[k][d] * x;
            }
        }
    }
}

int count(int n, int m){
    int z, y, x = m;
    long long v, res = 0;

    while (x >= 1){
        y = m / x, z = m / (y + 1);
        v = (long long)power[y] * (sum[x] - sum[z]);
        x = z, res += v;
    }

    res = (res % MOD + MOD) % MOD;
    return res;
}

int solve(int n, int k){
    long long res = 0;
    int i, j, v, m, x, y, z;
    for (i = 0; i < MAX; i++) power[i] = expo(i, n);

    dp[1] = count(n, 1);
    for (m = 2; m <= k; m++){
        res = dp[m - 1];
        for (j = 0; j < len[m]; j++){
            x = 0, y = 0, z = 0;
            x = divisors[m][j], v = m / x;
            y = power[v] * mu[x];
            z = power[v - 1] * mu[x];
            res = res + y - z;
        }
        dp[m] = ((res % MOD) + MOD) % MOD;
    }

    for (m = 1, res = 0; m <= k; m++) res += (m ^ dp[m]);
    return res % MOD;
}

int main(){
    generate();
    int n, k, res;

    while (scanf("%d %d", &n, &k) != EOF){
        printf("%d\n", solve(n, k));
    }
    return 0;
}


/* practice with Dukkha */
#include <stdio.h>

#define K	2000000
#define MD	1000000007

long long power(int a, int k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k >> 1);
	p = p * p % MD;
	if (k & 1)
		p = p * a % MD;
	return p;
}

int main() {
	static int cc[K + 1], pp[K + 1], dd[K + 1];
	int n, k, a, a2, b, i, ans;

	scanf("%d%d", &n, &k);
	for (a = 2; a <= k; a++) {
		if (cc[a])
			continue;
		for (b = a; b <= k; b += a)
			cc[b]++;
	}
	for (a = 2; (a2 = a * a) <= k; a++)
		for (b = a2; b <= k; b += a2)
			cc[b] = 0;
	for (i = 1; i <= k; i++)
		pp[i] = power(i, n);
	for (a = 2; a <= k; a++) {
		if (cc[a] == 0)
			continue;
		for (i = 1; i * a <= k; i++) {
			int l = i * a, r = (i + 1) * a;
			int p = cc[a] % 2 == 0 ? pp[i] : -pp[i];

			dd[l] = (dd[l] + p) % MD;
			if (r <= k)
				dd[r] = (dd[r] - p) % MD;
		}
	}
	ans = 0;
	for (i = 1; i <= k; i++) {
		int x;

		dd[i] = (dd[i] + dd[i - 1]) % MD;
		x = (pp[i] + dd[i]) % MD;
		if (x < 0)
			x += MD;
		ans = (ans + (x ^ i)) % MD;
	}
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>

#define MIN(x,y) (((x)<(y))?(x):(y))

struct{
  short com;
  short flg[3];
  short num;
  short bef[199];
}game[200]={{0}};

int chk_clear(int k,int f);

int main(void){
  int i,j,k,in,n,room;
  int count[3]={0},cleard[3]={0};

  scanf("%d%*c",&n);
  for(i=0;i<n;i++) scanf("%hd%*c",&game[i].com);
  for(i=0;i<n;i++){
    scanf("%hd",&game[i].num);
    for(j=0;j<game[i].num;j++){
      scanf("%hd",&game[i].bef[j]);
    }
  }

  //puts("end set-data");

  for(i=0;i<3;i++){
    room=i;
    do{
      room%=3;
      room++;
      for(j=0;j<n;j++){
	if(game[j].com!=room) continue;
	if(game[j].flg[i]==1) continue;
	in=chk_clear(j,i);
	if(in==1){
	  game[j].flg[i]=1;
	  cleard[i]++;
	  j=-1;
	}
      }
      //     printf("now cleard[%d]=%d@room=%d\n",i,cleard[i],room);
    }while(cleard[i]<n && ++count[i]);
    count[i]+=n;
  }

  printf("%d\n",MIN(count[0],MIN(count[1],count[2])));
  return 0;
}

int chk_clear(int k,int f){
  int i;
  for(i=0;i<game[k].num;i++){
    if(game[game[k].bef[i]-1].flg[f]==0) return 0;
  }
  return 1;
}


#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

void run (void) {
  const i32 n = read_int();
  i32 *factor = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    factor[i] = i;
  }
  for (i32 i = 2; i * i <= n; ++i) {
    if (factor[i] < i) continue;
    for (i32 j = i * i; j <= n; j += i) {
      factor[j] = i;
    }
  }
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  dp[1] = 0;
  for (i32 i = 2; i <= n; ++i) {
    i32 f[64];
    f[0] = 1;
    i32 len = 1;
    i32 t = i;
    while (t > 1) {
      i32 p = factor[t];
      while (t % p == 0) {
	t /= p;
      }
      for (i32 j = 0; j < len; ++j) {
	f[j + len] = f[j] * p;
      }
      len *= 2;
    }
    if (f[len - 1] != i) {
      dp[i] = dp[f[len - 1]];
      continue;
    }
    i32 prob[64];
    for (i32 j = 0; j < len; ++j) {
      prob[j] = (i64) (n / f[j]) * inv(n) % mod;
    }
    for (i32 j = len - 1; j >= 0; --j) {
      for (i32 k = j - 1; k >= 0; --k) {
	if ((j & k) == k) {
	  prob[k] = (prob[k] - prob[j] + mod) % mod;
	}
      }
    }
    i32 local = 1;
    for (i32 j = 0; j < len - 1; ++j) {
      local = (local + (i64) prob[j] * dp[f[j]]) % mod;
    }
    dp[i] = (i64) local * inv((1 - prob[len - 1] + mod) % mod) % mod;
  }
  i32 ans = 1;
  for (i32 i = 1; i <= n; ++i) {
    ans = (ans + (i64)dp[i] * inv(n)) % mod;
  }
  print_int(ans);
  puts("");
}

int main (void) {
  run ();
  return 0;
}