#include #include #include using namespace std; #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define double long double typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vec; typedef vector mat; const ll inf=1e9+7; const ll mod=1e9+7; //gcd ll gcd(ll a,ll b){ if(min(a,b)==0)return max(a,b); if(max(a,b)%min(a,b)==0)return min(a,b); return gcd(min(a,b),max(a,b)%min(a,b)); } int main(){ ll n,m,k;cin>>n>>m>>k; vectora(n),b(m); char c;cin>>c; bool f=c=='+'; rep(i,m)cin>>b[i]; rep(i,n)cin>>a[i]; if(f){ mapma; rep(i,m){ ll s=b[i]%k; if(ma.find(s)!=ma.end())ma[s]++; else ma[s]=1; } ll ans=0; rep(i,n){ ll s=a[i]%k; ans+=ma[k-s]; } cout<c(0); REP(i,1,sqrt(k)+1){ if(k%i==0){ c.pb(i); c.pb(k/i); } } sort(all(c)); mapma; c.pb(c[c.size()-1]); vectord(c.size()); rep(i,c.size()){ rep(j,m){ if(b[j]%c[i]==0&&c[i]!=c[i+1])d[i]++; } } rep(i,c.size()){ if(c[i]!=c[i+1])ma[c[i]]=d[i]; } ll ans=0; rep(i,n){ ll s=gcd(k,a[i]); ans+=ma[k/s]; } cout<