#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
#define ll long long
#define ull unsigned long long
using namespace std;
string s;
string text[10010];
char line[100010];
int T;
int ans;
int main()
{
int i=1;
while(getline(cin,s))
{
if(s=="EOF")
{
break;
}
text[i]=s;
int l=s.length();
for(int k=0;k<l;k++)
{
int loc1=k-1,loc2=k;
if(text[i][k]=='<')
{
while(text[i][loc2]=='<'&&loc1>=0)
{
text[i][loc1]='&';
loc1--;
loc2++;
}
}
}
i++;
}
int j=1;
while(getline(cin,s))
{
if(s=="EOF")
{
break;
}
int t=1,sum=0;
int l=s.length();
line[0]=s[0];
for(int k=1;k<l;k++)
{
if(s[k]=='<')
{
t--;
continue;
}
line[t]=s[k];
t++;
}
int u=0;
for(int p=0;p<t;p++)
{
while(text[j][u]=='&'||text[j][u]=='<')
{
u++;
}
if(line[p]==text[j][u])
{
sum++;
}
u++;
}
j++;
ans+=sum;
}
cin>>T;
cout<<round(double(ans)/double(T)*60);
return 0;
}