#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define rep(v,e) for(long v=0;v=p*p){ if(a%p==0){ int k=1; while(a/=p,a%p==0){ ++k; } int n0=n*k; for(int j=0;j1){ int n0=n; for(int j=0;j>8|a[i]<<24; } } int rsbuf[100000]; void radix_sort(unsigned*a,int n){ radix_sort_aux(a,rsbuf,n); radix_sort_aux(rsbuf,a,n); radix_sort_aux(a,rsbuf,n); radix_sort_aux(rsbuf,a,n); } long gcd(long a,long b){ if(a==0||b==0){ return a+b; } long x=__builtin_ctzl(a); long y=__builtin_ctzl(b); a>>=x; b>>=y; long c; while(c=a-b){ c>>=__builtin_ctzl(c); if(c<0){ b=-c; }else{ a=c; } } return a<<(x<=y?x:y); } int sa[100000],sb[100000]; int kdivs[1500]; int ha[1500],hb[1500]; main(){ char*rp=mmap(0l,1l<<25,1,2,0,0ll); rd(n); rd(m); rd(k); int op=*rp; rp+=2; long ans=0; if(op=='+'){ rep(i,m){ rd(bi); sb[i]=bi%k; } radix_sort(sb,m); rep(i,n){ rd(ai); ai=(k-ai)%k; sa[i]=ai+(ai<0?k:0); } radix_sort(sa,n); long i=0,j=0; while(isb[j]){ ++j; }else{ int v=sa[i]; long di=0,dj=0; while(i>1; if(b>1; if(a>=keb; unsigned long ket=~0ul/k; unsigned long ked=k; ked*=2-k*ked; ked*=2-k*ked; ked*=2-k*ked; ked*=2-k*ked; ked*=2-k*ked; rep(i,kdivn){ rep(j,kdivn){ long x=(long)kdivs[i]*(long)kdivs[j]; long xb=__builtin_ctzl(x); if(xb>=keb){ x>>=xb; if(x*ked<=ket){ ans+=(long)ha[i]*(long)hb[j]; } } } } } char wbuf[64],*wp=wbuf+sizeof wbuf; wt(ans); write(1,wp,wbuf+sizeof wbuf-wp); _exit(0); }