#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	freopen("frozen.in", "r", stdin);
	freopen("frozen.out", "w", stdout);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pair<int, int> > b(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i].first;

	for (int i = 0; i < n; i++)
		cin >> b[i].second;


	if (n == 1)
	{
		cout << 2 - (b[0].first == 0) - (b[0].second == a[0]);
		return 0;
	}
	if (n == 2)
	{
		cout << 4 - (b[0].first == 0) - (b[0].second == a[0]) - (b[1].first == 0) - (b[1].second == a[1]);
		return 0;
	}
	return 1;

}