#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef long long int i64;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 mod = 998'244'353ll;

const i64 inf = 1'000'000'000'000'000'000ll / 1'000'000'000ll;

const long double eps = 1e-8;

i64 gcd(i64 a, i64 b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }


    i64 R = 0;
    i64 n;
    string s;
    cin >> n >> s;

    i64 cnt = 0;
    stringstream ss;
    while (cnt < n) {
        ss << "110";
        cnt += 3;
    }
    ss << "110";
    string t = ss.str();


    for (i64 l = 0; l < 3; l++) {
        if (t.substr(l, s.size()) != s) {
            continue;
        }
        const i64 m = 30'000'000'000ll - n - l;
        R += m / 3 + 1;
    }

    cout << R << endl;




    return 0;
}
#include<bits/stdc++.h>
using namespace std;
string ss="",str;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n;
    cin>>n;
    cin>>str;
    for(int i=0;i<=n+100;i++)
    if(i%3==0)ss+="1";
    else if(i%3==1)ss+="1";
    else ss+="0";
    if(str=="1")cout<<20000000000<<"\n";
    else if(ss.substr(0,n)==str){
        int p=(n-1)/3;
        cout<<10000000000-p<<"\n";
    }
    else if(ss.substr(1,n)==str){
        int p=n/3;
        cout<<10000000000-p<<"\n";
    }
    else if(ss.substr(2,n)==str){
        int p=(n+1)/3;
        cout<<10000000000-p<<"\n";
    }
    else cout<<0<<"\n";
    return 0;
}
