链接:https://codeforces.ml/contest/1316/problem/C

It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.

You are given two polynomials f(x)=a0+a1x+⋯+an−1xn−1f(x)=a0+a1x+⋯+an−1xn−1 and g(x)=b0+b1x+⋯+bm−1xm−1g(x)=b0+b1x+⋯+bm−1xm−1, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 11 for both the given polynomials. In other words, gcd(a0,a1,…,an−1)=gcd(b0,b1,…,bm−1)=1gcd(a0,a1,…,an−1)=gcd(b0,b1,…,bm−1)=1. Let h(x)=f(x)⋅g(x)h(x)=f(x)⋅g(x). Suppose that h(x)=c0+c1x+⋯+cn+m−2xn+m−2h(x)=c0+c1x+⋯+cn+m−2xn+m−2.

You are also given a prime number pp. Professor R challenges you to find any tt such that ctct isn't divisible by pp. He guarantees you that under these conditions such tt always exists. If there are several such tt, output any of them.

As the input is quite large, please use fast input reading methods.

Input

The first line of the input contains three integers, nn, mm and pp (1≤n,m≤106,2≤p≤1091≤n,m≤106,2≤p≤109),  — nn and mm are the number of terms in f(x)f(x) and g(x)g(x) respectively (one more than the degrees of the respective polynomials) and pp is the given prime number.

It is guaranteed that pp is prime.

The second line contains nn integers a0,a1,…,an−1a0,a1,…,an−1 (1≤ai≤1091≤ai≤109) — aiai is the coefficient of xixi in f(x)f(x).

The third line contains mm integers b0,b1,…,bm−1b0,b1,…,bm−1 (1≤bi≤1091≤bi≤109)  — bibi is the coefficient of xixi in g(x)g(x).

Output

Print a single integer tt (0≤t≤n+m−20≤t≤n+m−2)  — the appropriate power of xx in h(x)h(x) whose coefficient isn't divisible by the given prime pp. If there are multiple powers of xx that satisfy the condition, print any.

Examples

input

Copy

3 2 2
1 1 2
2 1

output

Copy

1

input

Copy

2 2 999999937
2 1
3 1

output

Copy

2

Note

In the first test case, f(x)f(x) is 2x2+x+12x2+x+1 and g(x)g(x) is x+2x+2, their product h(x)h(x) being 2x3+5x2+3x+22x3+5x2+3x+2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.

In the second test case, f(x)f(x) is x+2x+2 and g(x)g(x) is x+3x+3, their product h(x)h(x) being x2+5x+6x2+5x+6, so the answer can be any of the powers as no coefficient is divisible by the given prime.

代码

#include<bits/stdc++.h>
using namespace std;
long long n,m,t,k,p;
long long a[1000001]={0},b[1000001]={0};
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
	n=read();
	m=read();
	p=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
	}
	for(int i=1;i<=m;i++)
	{
		b[i]=read();
	}
	{
		if((a[1]*b[1])%p!=0)
		{
			cout<<0;
			return 0;
		}
		else
		{
			if(a[1]%p==0&&b[1]%p==0)
			{
				int l=2,r=2;
				while(a[l]%p==0)
				{
					l++;
				}
				while(b[r]%p==0)
				{
					r++;
				}
				cout<<l+r-2;
				return 0;
				
			}
			else if(a[1]%p!=0)
			{
				for(int i=2;i<=m;i++)
				{
					if(b[i]%p==0)
					continue;
					else
					{
						cout<<i-1;
						return 0;
					}
				}
			}
			else
			{
				for(int i=2;i<=n;i++)
				{
					if(a[i]%p==0)
					continue;
					else
					{
						cout<<i-1;
						return 0;
					}
				}
			}
		}
	}
	
}