#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 301
#define INF (int)1e8 
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
 
const int lim=18;
ll P10[20],cnt[20];
 
void pre_work(void){
    P10[0]=1LL;
    for (int i=1;i<=lim;i++){
        P10[i]=P10[i-1]*10LL;
    }
    for (int i=0;i<=9;i++){
        for (int j=0;j<=9;j++){
            cnt[i-j+10]++;
        }
    }
    return;
}
 
ll D,ans=0;
 
void dfs(int step,ll x,ll sum,int len){
    if (step>len/2-1){
        if (len&1){
            sum*=10LL;
        }
        if (x==D){
            ans+=sum;
        }
        return;
    }
    ll now=-9;
    while (now<=9 && x+now*(P10[len-step-1]-P10[step])<=D){
        now++;
    }
    now--;
    dfs(step+1,x+now*(P10[len-step-1]-P10[step]),sum*(cnt[now+10]-(step==0 && now>=0)),len);
    now++;
    if (now>9){
        return;
    }
    dfs(step+1,x+now*(P10[len-step-1]-P10[step]),sum*(cnt[now+10]-(step==0 && now>=0)),len);
    return;
}
 
int main(){
    rd(D)
    pre_work();
    for (int i=1;i<=18;i++){
        dfs(0,0LL,1LL,i);
    }
    printf("%lld\n",ans);
    return 0;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


LL solve(vector<LL>& a){
    LL res = 0;
    for(LL d = 60; d >= 0; --d){
        LL cur = -1;
        for(LL i = 0; i < a.size(); ++i){
            if(a[i] & (1LL<<d)) cur = i;
        }
        if(cur < 0) continue;
        if((res & (1LL<<d)) == 0){
            res ^= a[cur];
        }
        for(LL i = 0; i < a.size(); ++i){
            if(a[i] & (1LL<<d)) a[i] ^= a[cur];
        }
    }
    return res;
}

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<LL> cnt(61);
    for(LL i = 0; i < n; ++i){
        for(LL j = 0; j < 61; ++j){
            if((a[i]>>j)&1) cnt[j] += 1;
        }
    }
    LL ans = 0;
    LL mask = 0;
    for(LL j = 0; j < 61; ++j){
        if(cnt[j] % 2 == 1){
            ans += (1LL << j);
        }else{
            mask |= (1LL << j);
        }
    }
    for(LL i = 0; i < n; ++i){
        a[i] = (a[i] & mask);
    }
    ans += solve(a) * 2;
    cout << ans << endl;
    return 0;
}

