#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t,k;
char s[maxn];
LL ksm(LL a, LL b, const LL mod) {
    LL res = 1;
    while(b){
        if(b&1){
            res = res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

int main(){
    LL a, b, c;
    read(a); read(b); read(c);
//    if (c == 1) printf("%lld\n", ksm(a, b, 10));
//    else if(b == 1) printf("%lld\n", a % 10);
//    else if(b == 2 && c == 2) printf("%lld\n", ksm(a, 4, 10));
//    else 
        printf("%lld\n", ksm(a, ksm(b, c, 4) + 4, 10));
    Please AC;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll sizeofS = 30000000000;

int main() {
    int n;
    cin >> n;
    string t;
    cin >> t;

    ll ans;
    if (t == "1") {
        ans = sizeofS * 2 / 3;
    } else if (t == "11") {
        ans = sizeofS / 3;
    } else {
        map<char, int> mp;
        rep(i, 3) mp[t[i]]++;
        if (mp['0'] != 1) {
            cout << 0 << endl;
            return 0;
        }

        ll pos0 = -1;
        vector<int> v(3, -1);
        rep(i, n) {
            if (v[i % 3] == -1) {
                v[i % 3] = t[i] - '0';
            } else {
                if (v[i % 3] != t[i] - '0') {
                    cout << 0 << endl;
                    return 0;
                }
            }
            if (pos0 == -1 && t[i] == '0') pos0 = i;
        }
        ans = 1 + (sizeofS - n - (2 - pos0)) / 3;
    }
    cout << ans << endl;
}