#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  vector<int> c(N + 1, 0);
  c[0] = 3;

  LL v = 1;
  int index = 0;
  for (int i = 0; i < N; ++i) {
    int x; cin >> x;
    LL y = c[x];
    v = (v * y) % kMod;

    --c[x];
    ++c[x+1];

#if 0
    index = max(index, x + 1);
    cout << x << ":";
    for (int i = 0; i <=index; ++i) cout << c[i] << " ";
    cout << "->" << y << endl;
#endif
  }
  cout << v << endl;
}

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    int n;
    string a,b,c;
    cin >> n >> a >> b >> c;
    int cnt=0;
    rep(i,n){
        char aa=a.at(i);
        char bb=b.at(i);
        char cc=c.at(i);
        if(aa!=bb && aa!=cc && bb!=cc)cnt+=2;
        else if(aa==bb && aa!=cc)cnt++;
        else if(aa==cc && aa!=bb)cnt++;
        else if(bb==cc && bb!=aa)cnt++;
    }
    cout << cnt << endl;
}