#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
int row1[100001];
int row2[100001];
int row3[100001];
int n;
vector<int> Lists[100001];
int Seen[4][100001];
bool Removed[100001];
vector<int> ToKill;
bool TFO[100001];
int ctr;
void Try(int x)
{
if (TFO[x])
return;
if (Seen[1][x]!=0 && Seen[2][x]!=0 && Seen[3][x]!=0)
return;
TFO[x]=true;
ToKill.push_back(x);
return;
}
void RemoveColumn(int x)
{
if (Removed[x])
return;
ctr++;
Removed[x]=true;
Seen[1][ row1[x] ]--;
Seen[2][ row2[x] ]--;
Seen[3][ row3[x] ]--;
Try(row1[x]); ///Other potential forced columns may come if some of the numbers in this one
Try(row2[x]); ///become extinct from some row, so the three checks are enough
Try(row3[x]); ///to find the newly forced columns
return;
}
int FastSolve()
{
int i;
int uk;
int V;
ctr=0;
for (i=1;i<=n;i++)
{
Lists[ row1[i] ].push_back(i); ///The lists hold the rows in which each number is
Lists[ row2[i] ].push_back(i);
Lists[ row3[i] ].push_back(i);
Seen[1][ row1[i] ]++; ///The "Seen" array holds the amount of times we've seen a number on some row
Seen[2][ row2[i] ]++;
Seen[3][ row3[i] ]++;
}
for (i=1;i<=n;i++)
{
Try(i); ///Try checks whether a number is present in all three rows
}
uk=0;
while(uk<ToKill.size()) ///While there are numbers not present in all three rows
{
V=ToKill[uk];
for (i=0;i<Lists[V].size();i++) ///Remove all columns that contain those numbers
{
RemoveColumn(Lists[V][i]);
}
uk++;
}
return ctr;
}
int main()
{
//freopen("test.txt","r",stdin);
int i;
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&row1[i]);
}
for (i=1;i<=n;i++)
{
scanf("%d",&row2[i]);
}
for (i=1;i<=n;i++)
{
scanf("%d",&row3[i]);
}
printf("%d\n",FastSolve());
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmN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