Problem:
Score : 700 points

Problem Statement

Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3.
Let x_{i,j} defined as follows:

x_{1,j} := a_j \quad (1 \leq j \leq N)

x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)

Find x_{N,1}.

Constraints

2 \leq N \leq 10^6

a_i = 1,2,3 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
a_1a_2\ldotsa_N

Output

Print x_{N,1}.

Sample Input 1

4
1231

Sample Output 1

1

x_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.

x_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.

x_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.

Finally, x_{4,1} = |0-1| = 1, so the answer is 1.

Sample Input 2

10
2311312312

Sample Output 2

0

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

//string f(string s){
//    string t(sz(s)-1,' ');
//    rep(i,sz(s)-1)
//        t[i] = abs(s[i+1]-s[i])+'0';
//    return t;
//}
//int g(string s){
//    while(sz(s) > 1){
//        s = f(s);
//    }
//    return s[0]-'0';
//}
//int x(int n){
//    if(n == 0) return 0;
//    return n/2 + x(n/2);
//}
//int w(string s){
//    int total = 0;
//    int n = sz(s);
//    rep(i,n){
//        s[i] = (s[i]-'0')%2;
//        int contrib = x(n-1)-x(i)-x(n-1-i);
//        if(contrib == 0)
//            total ^= s[i];
//    }
//    return total;
//}
//void __(){
//    _(int,n);
//    _(string,s);
//    s = f(s);
//    --n;
//    int m = 1;
//    if(count(all(s),'1') == 0){
//        for(char &c : s){
//            c = (c-'0')/2+'0';
//        }
//        m *= 2;
//    }
//    print w(s)*m;
//}
//
#include <iomanip>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_ZERO_INT(i,r) for(int i = 0; i < r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
string f(string s){
    string t(sz(s)-1,' ');
    rep(i,sz(s)-1)
        t[i] = abs(s[i+1]-s[i])+'0';
    return t;
}
int g(string s){
    while(sz(s) > 1){
        s = f(s);
    }
    return s[0]-'0';
}
int x(int n){
    if(n == 0) return 0;
    return n/2 + x(n/2);
}
int w(string s){
    int total = 0;
    int n = sz(s);
    rep(i,n){
        s[i] = (s[i]-'0')%2;
        int contrib = x(n-1)-x(i)-x(n-1-i);
        if(contrib == 0)
            total ^= s[i];
    }
    return total;
}
void __(){
    _(int,n);
    _(string,s);
    s = f(s);
    --n;
    int m = 1;
    if(count(all(s),'1') == 0){
        for(char &c : s){
            c = (c-'0')/2+'0';
        }
        m *= 2;
    }
    print w(s)*m;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}