#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=;
inline ll rd(){
ll x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
}
int N,A,B;
int opa[maxn],opb[maxn];
int res[][]={{,-,,,-},
{,,-,,-},
{-,,,-,},
{-,-,,,},
{,,-,-,}};
int ansa,ansb;
int main(){
//freopen(".in","r",stdin);
int i,j,k;
N=rd(),A=rd(),B=rd();
for(i=;i<A;i++) opa[i]=rd();
for(i=;i<B;i++) opb[i]=rd();
for(i=;i<N;i++){
int x=res[opa[i%A]][opb[i%B]];
if(x==) ansa++;
else if(x==-) ansb++;
}
printf("%d %d\n",ansa,ansb);
return ;
}