#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define FOR(i,f,n) for(int i=f;i<n;i++)
#define FORI(i,f,n) for(int i=f;i>=n;i--)
#define sz(a) ((int)(a).size())
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define alli(a) (a).rbegin(),(a).rend()
#define approx(a) fixed<<setprecision(a)
#define trav(a,x) for(auto& a : x)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,bool> pib;
typedef pair<ll,bool> plb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <class T> void ckmax(T &a, const T &b) { a = max(a, b); }
 
template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T> void read(T &x) {cin>>x;}
template <class R, class... T> void read(R& r, T&... t){read(r); read(t...);};
template <class T> void read(vector<T> &v) {trav(x, v) read(x);}
template <class F, class S> void read(pair<F, S> &p) {read(p.ff, p.ss);}
 
template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {cout<<x;}
template <class R, class... T> void pr(const R& r, const T&... t) {pr(r); pr(t...);}
template <class F, class S> void pr(const pair<F, S> &x) {pr("{", x.ff, ", ", x.ss, "}");}
void ps() {pr("\n");}
template <class T> void ps(const T &x) {pr(x); ps();}
template <class T> void ps(vector<T> &v) {trav(x, v) pr(x, ' '); ps();}
template <class F, class S> void ps(const pair<F, S> &x) {pr(x.ff, ' ', x.ss); ps();}
template <class R, class... T> void ps(const R& r, const T &...t) {pr(r, ' '); ps(t...);}

void solve(){
    string s; read(s);
    int cnt = 0;
    FOR(i,0,sz(s)){
        if(s[i] == 'o') cnt++;
    }
    set<string> ans;
    FOR(i,0,10){
        FOR(j,0,10){
            FOR(k,0,10){
                FOR(l,0,10){
                    vb v(10);
                    string t = "....";
                    t[0] = ('0'+i);
                    t[1] = ('0'+j);
                    t[2] = ('0'+k);
                    t[3] = ('0'+l);
                    bool id=0;
                    int check=0;
                    FOR(m, 0, 4){
                        if(s[t[m]-'0'] == 'o' && !v[t[m]-'0']){
                            v[t[m]-'0'] = 1;
                            check++;
                        }else if(s[t[m]-'0'] == 'x') id=1;
                    }
                    if(id) continue;
                    if(check == cnt) ans.insert(t); 
                }
            }
        }
    }
    ps(sz(ans));
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
using ll=long long;
using pa=pair<ll,ll>;
using tup=tuple<ll,ll,ll>;


int main() {
ll n;
cin>>n;
vector<ll> a(n);
vector<ll> b(n);
vector<ll> c(n);
vector<ll> anum(n+1);
vector<ll> bnum(n);
for (int i = 0; i < n; i++)
{
  cin>>a[i];
  anum[a[i]]++;
}
for (int i = 0; i < n; i++)
{
  cin>>b[i];
}
for (int i = 0; i < n; i++)
{
  cin>>c[i];
 
  bnum[c[i]-1]++;
}
ll ans=0;
for (int i = 0; i < n; i++)
{
  ans+=bnum[i]*anum[b[i]];

}
cout<<ans<<endl;
}
