把所有情况打表,然后随便暴力。
#include<cstdio>
using namespace std;
int n,an,bn,p1,p2;
int a[],b[];
bool f[][];
int ans1,ans2;
void init()
{
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
f[][]=; f[][]=;
}
int main()
{
scanf("%d%d%d",&n,&an,&bn);
init();
for(int i=;i<=an;i++) scanf("%d",&a[i]);
for(int i=;i<=bn;i++) scanf("%d",&b[i]);
for(int i=;i<=n;i++)
{
p1++; p2++;
if(p1>an) p1=;
if(p2>bn) p2=;
ans1+=f[a[p1]][b[p2]];
ans2+=f[b[p2]][a[p1]];
}
printf("%d %d\n",ans1,ans2);
return ;
}