1 #include <algorithm>
2 #include <cstring>
3 #include <cstdio>
4 using namespace std;
5
6 #define p 19
7 #define mod 100007
8 const int N(100000+10);
9 char s1[N][11],s2[N][11];
10 int ans,n,m,num[N],need[N],vis[N],have[N];
11
12 int Hash(char a[])
13 {
14 int ret=0;
15 for(int i=0;i<strlen(a);i++)
16 ret=(ret*p+a[i]-‘a‘)%mod;
17 return ret;
18 }
19
20 int main()
21 {
22 scanf("%d",&n);
23 for(int i=1;i<=n;i++) scanf("%s",s1[i]);
24 scanf("%d",&m); int len=m;
25 for(int i=1;i<=m;i++)
26 scanf("%s",s2[i]),have[Hash(s2[i])]=1;
27 for(int i=1;i<=n;i++)
28 {
29 int ha=Hash(s1[i]);
30 if(have[ha]) ans++,need[ha]=1;
31 }
32 for(int cnt=0,head=1,tail=0;tail<=m;)
33 {
34 int ha=Hash(s2[++tail]);
35 if(need[ha])
36 {
37 if(!vis[ha]) cnt++;
38 num[ha]++; vis[ha]=1;
39 }
40 if(cnt==ans&&ans)
41 {
42 int x=Hash(s2[head]);
43 for(;head<tail&&(num[x]>1||!need[x]);)
44 {
45 if(need[x]) num[x]--;
46 x=Hash(s2[++head]);
47 }
48 len=min(len,tail-head+1);
49 }
50 }
51 if(!ans) printf("0\n0");
52 else printf("%d\n%d",ans,len);
53 return 0;
54 }