#include <bits/stdc++.h>

using namespace std;

#define dump(x) cerr << "~ " << #x << " = " << x << endl


int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n;
    string s,mat[5];
    long long len = 3e10;

    cin >> n;
    cin >> s;

    if(n == 1) {
        cout << len/3 + (s[0] == '1' ? len/3 : 0) << endl;
        return 0; 
    }

    mat[0] = "110";
    mat[1] = "101";
    mat[2] = "011";

    for(int i = 0; i < 3; i++) {
        int flag = 0;
        for(int j = 0; j < n; j++) {
            if(s[j] != mat[i][j%3]) {
                flag = 1; break;
            }
        }
        if(!flag) {
            long long id = len-n;
            while(id%3 != i) id--;
            cout << id/3+1 << endl;
            return 0;
        }
    }
                                            
    cout << 0 << endl;
    
    return 0;
}
#include<bits/stdc++.h>
typedef long long ll ;
#define int ll 
using namespace std ;
signed main( )
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int testcases = 1 ;
    // cin >> testcases ;
    while( testcases -- )
    {
        int a , b ;
        cin >> a >> b ;
        int sum = 0 ;
        for(int i = 1 ; i <=a ; i++)
        {
        	for(int j = 1 ; j <= b ; j++)
        	{
        		int n = i*100 ;
        		n += j ;
        		sum += n ;
        	}
        }
        cout << sum ;
        cout << endl ;
    }
    return 0 ;
}    