#include <iostream.h>
#include <fstream.h>

typedef int bool;

# define true 1
# define false 0

long int a[26], b[26], n, tot = 0, restot = 0;
char tast[8][4];
int clicks[26], resclicks[26];
bool ok = false, notok = false;
bool used[26];

void init()
{
	for (int i = 0; i <= 25; i++) 
	{
		a[i] = 0;
		clicks[i] = 0;
		used[i] = false;
	}

	for (i = 0; i <= 7; i++)
	{
		for (int j = 0; j <= 3; j++) tast[i][j] = 0;
	}

}
void loaddat(char *fn)
{
	ifstream gin(fn);
	char inBuf[25];

	gin >> n;
	gin.getline(inBuf, 25);

	for (long int i = 1; i <= n; i++)
	{
		gin.getline(inBuf, 25);

		for (long int j = 0; inBuf[j] != 0; j++) a[inBuf[j] - 97]++;
	}
}

void solve()
{
	long int m;
	int spot, i, j, k;

	for (i = 0; i <= 25; i++) b[i] = a[i];

	for (i = 0; i <= 2; i++)
	{
		for (j = 0; j <= 7; j++)
		{
			m = -1;
			spot = 0;
			for (k = 0; k <= 25; k++)
			{
				if (a[k] > m)
				{
					m = a[k];
					spot = k;
				}
			}

			tast[j][i] = spot + 97;
			a[spot] = -1;
			clicks[spot] = i + 1;
		}
	}

	for (i = 0; a[i] == -1; i++); tast[5][3] = i + 97; clicks[i] = 4; a[i] = -1;
	for (; a[i] == -1; i++); tast[7][3] = i + 97; clicks[i] = 4;

	tot = 0;
	for (i = 0; i <= 25; i++) tot += clicks[i] * b[i];

	tot += n - 1;

}

void loadres(char *fn)
{
	ifstream gin(fn);
	char inBuf[10];
		
	gin >> restot;
	notok = restot != tot;
	gin.getline(inBuf, 4);

	for (int i = 2; (i <= 9) && (!notok); i++)
	{
		gin.getline(inBuf, 10);
		for (int j = 0; j < 3; j++)
		if ((inBuf[j] >= 97) && (inBuf[j] <= 122)) 
		{
			resclicks[inBuf[j] - 97] = j + 1;
			used[inBuf[j] - 97] = true;
		}

		if ((i == 7) || (i == 9))
		{
			if ((inBuf[3] >= 97) && (inBuf[3] <= 122)) 
			{
				resclicks[inBuf[3] - 97] = 4;
				used[inBuf[3] - 97] = true;
			}
		}
		else
			notok = notok || (inBuf[3] != 0);
		
		
	}

	for (i = 0; (i <= 25) && (!notok); i++) notok = notok || (!used[i]); 
	tot = 0;
	for (i = 0; i <= 25; i++) tot += resclicks[i] * b[i];
	tot += n - 1;

	notok = notok || (restot != tot);

	ok = !notok;


}

int main(int argc, char *argv[])
{
	loaddat(argv[1]);
	solve();
	loadres(argv[2]);

	ofstream tm("tmp.txt");

	if (ok)	tm << "10" << endl; else tm << "0" << endl;
	tm.close();
	if (ok) cout << "10" << endl; else cout << "0" << endl;

	return 0;

}
