#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int long long
#define reset(x) memset(x,0,sizeof(x))
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define PI 3.1415926535897932384626433832795
#define INF 1000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int MAXN = 100005;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    int n; cin >> n;
    int arr[n + 1], brr[n + 1], crr[n + 1];

    vector<vector<int>> equal(n + 1, vector<int>());
    int exist[n + 1];
    reset(exist);
    for (int i = 0; i < n; i++)
    {
    	cin >> arr[i + 1];
    	exist[arr[i + 1]]++;
    }
    for (int i = 0; i < n; i++)
    {
    	cin >> brr[i + 1];
    	equal[brr[i + 1]].pb(i + 1);
    }
    int num_time[n + 1];
    reset(num_time);
    for (int i = 0; i < n; i++)
    {
    	cin >> crr[i + 1];
    	num_time[crr[i + 1]]++;
    }
    int sum = 0;
    bool used[n + 1]; reset(used);
    for (int i = 1; i <= n; i++)
    {
    	int tmp = 0;
    	if (used[arr[i]] == true)
    	{
    		continue;
    	}
    	for (int x : equal[arr[i]])
    	{
    		tmp += num_time[x];
    	}
    	sum += (tmp * exist[arr[i]]);
    	used[arr[i]] = true;
    }
    cout << sum;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define iambharatks                   \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

#define bitcount __builtin_popcount
#define setbits(x) __builtin_popcountll(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define fo(i, j, n) for (int i = j; i <= n; i++)
#define rev(i, j, n) for (int i = n; i >= j; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define INF 2e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<pll>> vvpll;
typedef vector<pll> vpll;
typedef vector<pi> vpi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 998244353;
const int N = 2e5 + 5;
double eps = 1e-12;
const int mod = 1e9 + 7;

void solve()
{

    string s;
    cin >> s;
    for (char &c : s)
    {
        if (c == '9')
            c = '6';
        else if (c == '6')
            c = '9';
    }
    reverse(all(s));
    cout << s << ln;
}

int main()
{
    iambharatks;
    // ll t;
    // cin >> t;
    // for (int it = 1; it <= t; it++)
    // {
    // cout << "Case #" << it << ": ";
    solve();
    // }
    return 0;
}