#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
//#define int long long
void solve(){
  int n; cin >> n;
  string s; cin >> s;
  s = "#" + s;
  int dp[n+4][30];memset(dp,0,sizeof dp);
  rep(i,1,n) dp[i][s[i] - 'A']++;
  fr(j,30)
  rep(i,1,n){
  	dp[i][j] += dp[i-1][j];
  }
  int ans = 0;
  auto gfr = [&](int l,int r,char c){
  	return dp[r][c-'A'] - dp[l-1][c-'A'];
  };
  rep(i,1,n){
  	for(int j = i+1; j<=n; j+=2){
  		if(gfr(i,j,'A') == gfr(i,j,'T') and gfr(i,j,'C') == gfr(i,j,'G'))
  			ans++;
  	}
  }
  cout << ans << "\n";
}
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int tst; cin >> tst; while(tst--)
   {
   	solve();
   }
}

//Solution By SlavicG
#include "bits/stdc++.h"

using namespace std;

#define              ll              long long

#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()

#define            pb                push_back
#define          sz(a)               (int)a.size()
#define         fastio               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll pw(ll a,ll b,ll m){a%=m;ll r=1;while(b>0){if(b&1)r=(r*a)%m;a=(a*a)%m;b/=2;}return r;}
ll gcd(ll a, ll b) {if(!b)return a;return gcd(b,a % b);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}
ll fact(ll n, ll mod){ll ret=1;for(ll i=1;i<=n;i++)ret=(ret*i)%mod;return ret;}
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(ll i=5;i*i <= n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
const int N  = 2000;
char c[N][N];
int dist[N][N];
bool vis[N][N];
vector<pair<pair<int,int>,int>> adj[N][N];
void solve() {
 	int n,m;
 	cin >> n >> m;
 	char c[n][m];
 	int startI = -1, startJ = -1;
 	int endI = -1, endJ = -1;
 	vector<pair<pair<int,int>,int>> v[26];
 	for(int i =0;i < n;i++)
 	{
 		string s;
 		cin >> s;
 		for(int j= 0;j < m;j++)
 		{
 			c[i][j] = s[j];
 			if(c[i][j] >= 'a' && c[i][j] <= 'z')
 			{
 				v[c[i][j] - 'a'].pb({{i,j},1});
 			}
 			if(c[i][j] == 'S'){
 				startI = i, startJ = j;
 			}
 			if(c[i][j] == 'G'){
 				endI = i, endJ = j;
 			}
 		}
 	}

 	for(int i =0;i < n;i++)
 	{
 		for(int j = 0;j < m;j++)
 		{
 			if(c[i][j] == '#')continue;
 				if(j + 1 < m)
 				{
 					if(c[i][j+1] != '#')
 					{
 						adj[i][j].pb({{i,j + 1},1});
 						adj[i][j+1].pb({{i,j}, 1});
 					}
 				}
 				if(i +1 < n)
 				{
 					if(c[i+1][j] != '#')
 					{
 						adj[i][j].pb({{i+1,j},1});
 						adj[i+1][j].pb({{i,j},1});
 					}
 				}
 		}
 	}
 	bool taken[26];
 	for(int i= 0;i < 26;i++)
 		taken[i] = false;
 	priority_queue<pair<int,pair<int,int>>> q;
 	q.push({0,{startI,startJ}});
 	for(int i =0;i < n;i++)
 		for(int j = 0; j < m;j++){
 			dist[i][j] = 1e8;
 		}
 	dist[startI][startJ] = 0;
 	while(!q.empty())
	{
		int a = q.top().second.first, b = q.top().second.second;
		q.pop();
		if(vis[a][b])continue;
		vis[a][b] = true;
		if(c[a][b] >= 'a' && c[a][b] <='z' && !taken[c[a][b] - 'a'])
		{
			taken[c[a][b] - 'a'] = true;
			for(auto i : v[c[a][b]-'a'])
			{
				int x = i.first.first;
				int y = i.first.second;
				int weight = i.second;
				if(dist[x][y] > dist[a][b] + weight){
					dist[x][y] = dist[a][b] + weight;
					q.push({-dist[x][y], {x,y}});
				}
			}
		}
		for(auto i : adj[a][b])
		{
			int x = i.first.first;
			int y = i.first.second;
			int weight = i.second;
			if(dist[x][y] > dist[a][b] + weight){
				dist[x][y] = dist[a][b] + weight;
				q.push({-dist[x][y], {x,y}});
			}
		}
	}
	if(dist[endI][endJ] == 1e8){
		cout << -1;
		return;
	}
 	cout << dist[endI][endJ];
}

int32_t main()
{
    fastio;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;

int main(void){
    string S[3];
    cin >> S[0] >> S[1] >> S[2];

    int frag[3][10]={};

    int count=0;//文字数のカウント
    for(int i=0;i<3;i++){
        for(int k=0;k<S[i].size();k++){
            if(frag[i][k]==0){
                count++;
                frag[i][k]=count;
            }
            for(int j=0;j<3;j++){
                for(int h=0;h<S[j].size();h++){
                    if(S[i][k]==S[j][h]) frag[j][h]=frag[i][k];
                }
            }
        }
    }
    /*for(int i=0;i<3;i++){
        for(int j=0;j<S[i].size();j++){
            cout << frag[i][j] << " ";
        }
        cout << endl;
    }*/

    vector<int> v={0,1,2,3,4,5,6,7,8,9};
    bool ok=false;
    long long int N[3];
    do{
        if(count>10) break;
        bool mozisuu=true;

        for(int i=0;i<3;i++){
            N[i]=0;
            if(v[frag[i][0]-1]==0) mozisuu=false;
            for(int j=0;j<S[i].size();j++){
                N[i]+=pow(10,S[i].size()-1-j)*v[frag[i][j]-1];
            }
        }

        if(N[0]+N[1]==N[2] && mozisuu) ok=true;

    }while(next_permutation(v.begin(),v.end()) && !ok );

    if(ok){
        cout << N[0] << endl;
        cout << N[1] << endl;
        cout << N[2] << endl;
    }
    else cout << "UNSOLVABLE" << endl;
}

#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

#define no cout << "UNSOLVABLE\n";
vii pos[30];
string str[3],res[3];
vector<char> unicos;

bool can(string tmp){
	if(tmp[0] == '0')return 0;
	for(auto &c : tmp)if(c < '0' || c > '9')return 0;
	return 1;
}
ll conv(string tmp){
	stringstream ss(tmp);
	ll x; ss >> x;
	return x;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	forn(i,0,3){
		cin >> str[i];
		res[i] = str[i];
		forn(j,0,(int)str[i].size()){
			unicos.pb(str[i][j]);
			pos[str[i][j]-'a'].pb({i,j});
		}
	}
	sort(all(unicos));
	unicos.erase(unique(all(unicos)),unicos.end());

	//for(auto &x : unicos)cout << x << ' ';
	//cout << '\n';

	if(unicos.size() > 10){
		no;
		return 0;
	}
	vi vals;
	forn(i,0,10)vals.pb(i);
	do{

		forn(k,0,(int)unicos.size()){
			for(auto &x : pos[unicos[k]-'a']){
				res[x.fi][x.se] = (char)(vals[k]+'0');
			}
		}
		bool es = true;
		forn(i,0,3)if(!can(res[i]))es = false;

		if(!es)continue;
		ll n1 = conv(res[0]);
		ll n2 = conv(res[1]);
		ll n3 = conv(res[2]);
		if(n1+n2 == n3){
			cout << n1 << '\n';
			cout << n2 << '\n';
			cout << n3 << '\n';
			return 0;
		}

	}while(next_permutation(all(vals)));

	no;
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string t;
    cin >> t;
    if (n == 1) {
        if (t == "1") {
            cout << (long long)2e10 << '\n';
        } else {
            cout << (long long)1e10 << '\n';
        }
        return 0;
    } else if (n == 2) {
        if (t == "11") {
            cout << (long long)1e10 << '\n';
        } else if (t == "10") {
            cout << (long long)1e10 << '\n';
        } else if (t == "01") {
            cout << (long long)(1e10) - 1 << '\n';
        } else {
            cout << 0 << '\n';
        }
        return 0;
    }
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        a[i] = t[i] - '0';
    }
    if (a[0] + a[1] + a[2] != 2) {
        cout << 0 << '\n';
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (a[i % 3] != t[i] - '0') {
            cout << 0 << '\n';
            return 0;
        }
    }
    int b;
    if (a[0] == 0) {
        b = 2;
    } else if (a[1] == 0) {
        b = 1;
    } else {
        b = 0;
    }
    long long i = (long long)(3e10) - 1;
    i -= n - 1;
    while (i % 3 != b) {
        i--;
    }
    cout << i / 3 + 1 << '\n';
    return 0;
}

/*
You're my honeybunch, sugar plum
Pumpy-umpy-umpkin
You're my sweetie pie
You're my cuppycake, gumdrop
Snoogums, boogums, you're
The apple of my eye

And I love you so
And I want you to know
That I'm always be right here
And I want to sing
Sweet songs to you
Because you are so dear...

*/
#include <bits/stdc++.h>
#include<iostream>

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define pai pair<int, int>
#define ar array

using namespace std;
int const nax=2e5;
int const M=1e9;
const int64_t Leng = int64_t(3e10);
void solve(){
    int n;
    cin >>n ;
    ll answer =0 ;
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        bool valid = true;
        for(int j=0;j<n;j++){
            int index = i+j;
            char want = index % 3 < 2 ? '1' : '0';
            valid = valid && s[j]==want;
        }
        if(valid){
            int64_t lastindex = Leng - n;
            while(lastindex%3!=i)lastindex--;
            answer += (lastindex-i)/3 +1;
        }
    }
    cout << answer<< endl;

}

int main(){
   boost;
   int t=1,z=1;
   //cin>>t;
   while(t--){
   //cout<< "Case #"<< z++ <<  ": " ;
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;

using P = pair<long long, long long>;

int n;
vector<P> v;

long long solve();

int main() {
  cin >> n;
  v.resize(n);
  for (auto &p : v) cin >> p.first >> p.second;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  vector<int> id(n), p;
  iota(id.begin(), id.end(), 0);
  sort(id.begin(), id.end(), [](int l, int r) { return v[l] < v[r]; });
  for (int i = 0; i < min(4, n); ++i) {
    p.push_back(id[i]);
    p.push_back(id[n - 1 - i]);
  }
  for (auto &p : v) swap(p.first, p.second);
  sort(id.begin(), id.end(), [](int l, int r) { return v[l] < v[r]; });
  for (int i = 0; i < min(4, n); ++i) {
    p.push_back(id[i]);
    p.push_back(id[n - 1 - i]);
  }
  sort(p.begin(), p.end());
  p.erase(unique(p.begin(), p.end()), p.end());
  n = p.size();
  vector<int> res;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      res.push_back(max(abs(v[p[i]].first - v[p[j]].first),
                        abs(v[p[i]].second - v[p[j]].second)));
  sort(res.begin(), res.end());
  res.pop_back();
  return res.back();
}

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

double xs[200000+10];
double ys[200000+10];

bool g[105][105];
int visited[105];
int counter;

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lf%lf", &xs[i], &ys[i]);
  }
  int start = n;
  int goal = n+1;
  double left = 0;
  double right = 100;
  REP(iTry, 100) {
    double mid = (left + right) / 2;
    REP(i, n) {
      g[i][i] = true;
      g[i][start] = g[start][i] = (ys[i] + 100) <= 2*mid;
      g[i][goal] = g[goal][i] = (100 - ys[i]) <= 2*mid;
      REP(j, i) {
        g[i][j] = g[j][i] = sqrt((xs[i]-xs[j])*(xs[i]-xs[j]) + (ys[i]-ys[j])*(ys[i]-ys[j])) <= 2*mid;
      }
    }
    ++counter;
    queue<int> q;
    q.push(start);
    visited[start] = counter;
    while(!q.empty()){
      int cur = q.front(); q.pop();
      REP(i, n+2) {
        if(g[cur][i] && visited[i] != counter) {
          q.push(i);
          visited[i] = counter;
        }
      }
    }
    if(visited[goal] == counter) {
      right = mid;
    } else {
      left = mid;
    }
  }
  printf("%.10f\n", left);

  return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N;
int to[400001], ne[400001], he[200001];
int Q[200001], vis[200001], p, q;
ll are[200001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	rep1(i, N * 2 - 2) {
		int a, b;
		cin >> a >> b;
		to[i] = b;
		ne[i] = he[a];
		he[a] = i++;
		to[i] = a;
		ne[i] = he[b];
		he[b] = i;
	}

	Q[q++] = 1;
	while (p < q) {
		int u = Q[p++];
		vis[u] = -1;
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] == 0) {
				Q[q++] = to[i];
			}
		}
	}
	int tmp = Q[N - 1];
	p = 0;
	q = 0;
	Q[q++] = tmp;
	vis[tmp] = 0;
	while (p < q) {
		int u = Q[p++];
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] < 0) {
				vis[to[i]] = u;
				Q[q++] = to[i];
			}
		}
	}
	ll m = (1ll << 20) - 1, m0 = ~m, m1 = 1ll << 20;
	for (int i = N - 1; i >= 0; i--) {
		int u = Q[i];
		ll kari = (are[u] & m0) + m1 + u;
		if (are[vis[u]] < kari) are[vis[u]] = kari;
	}

	int k = 0;
	q = 0;
	Q[q++] = tmp;
	while (q) {
		k++;
		int u = Q[q - 1];
		if (u < 0) q--;
		else {
			vis[u] = -k;
			Q[q - 1] = -u;
			int nanika = are[u] & m;
			if(nanika) Q[q++] = nanika;
			for (int i = he[u]; i; i = ne[i]) {
				int v = to[i];
				if (vis[v] >= 0 && v != nanika) {
					Q[q++] = v;
				}
			}
		}
	}

	rep1(i, N) cosp(-vis[i]);

	Would you please return 0;
}

#include <iostream>
#include <cstdio>
const int nn = 2e5 + 5;
int n, ans[nn], tot;
int cnt, prev[nn << 1], last[nn], to[nn << 1];
void addedge(int p, int q) {
	prev[++cnt] = last[p];
	to[last[p] = cnt] = q;
}
int dep[nn], son[nn];
void dfs1(int p, int fa) {
	for (int i = last[p]; i; i = prev[i]) {
		if (to[i] != fa) {
			dfs1(to[i], p);
			if (dep[p] < dep[to[i]] + 1) {
				dep[p] = dep[to[i]] + 1;
				son[p] = to[i];
			}
		}
	}
}
void dfs2(int p, int fa) {
	ans[p] = ++tot;
	for (int i = last[p]; i; i = prev[i])
		if (to[i] != fa && to[i] != son[p])
			dfs2(to[i], p);
	if (son[p]) dfs2(son[p], p);
	++tot;
}
int main() {
	scanf("%d", &n);
	for (int i = 1, p, q; i < n; i++) {
		scanf("%d %d", &p, &q);
		addedge(p, q);
		addedge(q, p);
	}
	dfs1(1, 0);
	int p = 1;
	while (son[p]) p = son[p];
	for (int i = 1; i <= n; i++)
		dep[i] = son[i] = 0;
	dfs1(p, 0); dfs2(p, 0);
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
}


// Problem: A - Star
// Contest: AtCoder - AtCoder Beginner Contest 192
// URL: https://atcoder.jp/contests/abc192/tasks/abc192_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)

const int inf=0x3f3f3f3f3f3f3f3f;
int dx[]={0,1,1,1,0,-1,-1,-1};
int dy[]={1,1,0,-1,-1,-1,0,1};

// <--------------------Code Begins Here-------------------->

int32_t main() {
    SPEED;
    int t = 1;
    // cin>>t;
    while(t--) {
    	int n;
    	cin>>n;
    	if(n % 100 == 0)cout<<100;
    	else {
    		int x = n - (100 * ((n + 99) / 100));
    		cout<<-x;
    	}
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using llu = unsigned long long;
using ld = long double;

#define CEIL(x, y) (ll)ceil((ld)(x) / (ld)(y))

#define dbgLST(ds) for(auto it : ds) cout << it << ' ';
#define dbgMP(ds) for(auto it : ds) cout << it.first << ' ' << it.second << '\n';

const double PI = acos(-1.0), g = 9.80665;
const ll unseen = 0, pinf = 1e18 + 505, ninf = -1e18 - 505, md = 1000000007;
ll i, j, k, n, m;
bool is;

void solve(void)
{
    ll n;
    cin >> n;

    ll lb = 1000;
    ll sz = 3;
    ll ans = 0;

    while(lb <= n) {
        ans += min((n - lb + 1), (lb * 9)) * (sz / 3);
        lb *= 10;
        sz++;
    }

    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int testcase = 1;
    // cin >> testcase;
    while(testcase--) {
        solve();
    }
    return 0;
}


#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <functional>
#include <limits.h>
#include <numeric>

using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf INT_MAX
#define linf LLONG_MAX
#define ninf INT_MIN
#define nlinf LLONG_MIN
#define mod 0
ll solve(int now,int h,int w,int a,int b,vector<vector<int>> board){
    int y=now/h,x=now%h;
    if(now==h*w)return 1;
    if(board[x][y]==1)return solve(now+1,h,w,a,b,board);
    board[x][y]=1;
    ll count=0;
    if(board[x+1][y]==0){
        board[x+1][y]=1;
        if(a>0)count+=solve(now+1,h,w,a-1,b,board);
        board[x+1][y]=0;
    }
    if(board[x][y+1]==0){
        board[x][y+1]=1;
        if(a>0)count+=solve(now+1,h,w,a-1,b,board);
        board[x][y+1]=0;
    }
    if(b>0)count+=solve(now+1,h,w,a,b-1,board);
    return count;
}
int main(){
    int h,w;cin>>h>>w;
    int a,b;cin>>a>>b;
    vector<vector<int>> board(h+1,vector<int>(w+1));
    rep(i,h+1)board[i][w]=1;
    rep(i,w+1)board[h][i]=1;
    cout<<solve(0,h,w,a,b,board)<<endl;
    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!

#ifndef ONLINE_JUDGE // setting up print debugging
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif

typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<#x<<"="<<x<<endl
#define ERR2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define all(v) v.begin(),v.end()

ll ans = 0;
ll H,W,A,B;

void dfs(ll i, ll bit, ll A, ll B){
    if(i == H*W){
        ans++;
        return;
    }
    if(bit & 1LL << i){
        dfs(i+1, bit, A, B);
        return;
    }
    if(B){
        dfs(i+1, bit | 1LL << i, A, B-1);
    }
    if(A){
        if(i % W != W-1 && ~bit & 1LL << i+1){
            dfs(i+1, bit | 1LL << i | 1LL << i+1,  A-1, B);
        }
        if(i+W < H*W){
            dfs(i+1, bit | 1LL << i | 1LL << i+W,  A-1, B);
        }
    }
}

int main()
{
	int t;
	t = 1;
	int Case = 0;
	while(t--)
	{
        cin >> H >> W >> A >> B;
        dfs(0,0,A,B);
        cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int A,B;cin>>A>>B;
  map<int,int>mp;
  for(int i=A;i<=B;i++){
    for(int j=1;j*j<=i;j++){
      if(i%j==0){
        mp[j]++;
        if(j!=i/j){
          mp[i/j]++;
        }
      }
    }
  }
  int ans=0;
  for(auto i:mp){
    if(i.second>=2){
      ans=i.first;
    }
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;

int findMaxGCD(int arr[], int n)
{
    int high = 0;
    for (int i = 0; i < n; i++)
        high = max(high, arr[i]);
    int count[high + 1] = {0};
    for (int i = 0; i < n; i++)
        count[arr[i]]++;
    int counter = 0;
    for (int i = high; i >= 1; i--)
    {
        int j = i;
       counter = 0;
        while (j <= high)
        {
            if(count[j] >=2)
               return j;

           else if (count[j] == 1)
                counter++;
            j += i;
            if (counter == 2)
                return i;
        }
    }
}

int main()
{
    int a,b;
    cin >> a >> b;
    int arr[b-a+1];
    for(int i = a; i <= b; ++i){
        arr[i-a] = i;
    }
    int n = sizeof(arr) / sizeof(arr[0]);

    cout << findMaxGCD(arr, n);

    return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007LL
#define INF 0x3f3f3f3f3f3f3f3fLL
#define EPS 1e-6
#define rep(i, l, r) for (int i = l; i < (int)(r); i++)
#define rrep(i, l, r) for (int i = ((int)(r) - 1); i >= l; i--)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
struct edge { int to, cost; };
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a, int b) { while(b){ int c = b; b = a % b; a = c; } return a; }
int lcm(int a, int b) { if(!a || !b) return 0; return a * b / gcd(a, b); }

#include<bits/stdc++.h>
using namespace std;
int main(){
    int N; cin >> N;
    vector<double> a(N),b(N),c(N),d(N);
    for(int _=0; _<2; _++){
        for(int i=0; i<N; i++) cin >> a[i] >> b[i];
        int x = 0, y = 0;
        for(int i=0; i<N; i++){
            x += a[i];
            y += b[i];
            a[i] *= N;
            b[i] *= N;
        }
        for(int i=0; i<N; i++){
            a[i] -= x;
            b[i] -= y;
        }
        swap(a,c);
        swap(b,d);
    }
    for(int i=0; i<N; i++){
        if(a[i]!=0 || b[i]!=0){
            swap(a[i],a[0]);
            swap(b[i],b[0]);
        }
    }
    string ans = "No";
    const double eps = 1e-6;
    for(int i=0; i<N; i++){
        double angle = atan2(d[i],c[i])-atan2(b[0],a[0]);
        bool flag = true;
        for(int j=0; j<N; j++){
            double A = a[j]*cos(angle)-b[j]*sin(angle);
            double B = a[j]*sin(angle)+b[j]*cos(angle);
            bool flag2 = false;
            for(int k=0; k<N; k++){
                if(std::abs(A-c[k])<=eps && std::abs(B-d[k])<=eps) flag2 = true;
            }
            flag &= flag2;
        }
        if(flag) ans = "Yes";
    }
    cout << ans << endl;
}

//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//~ while (clock()<=69*CLOCKS_PER_SEC)

#define ll long long
#define ld long double
#define pi pair<int,int>
#define pd pair<ld,ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i,a,b) for(int i=(a); i<=(b);i++)
#define F(i,a,b) FOR(i,(a),(b)-1)
#define REV(i,a,b) for(int i=(a); i>=(b);i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long K = 1000;
const long long KK = K*K;
const long long MIL = KK*K;
const long long INF = MIL*MIL;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 10, M=10;

void solve() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    if (r1 == r2 && c1 == c2) {
        cout << "0\n";
        return;
    }

    if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2 || (abs(r1 - r2) + abs(c1 - c2) <= 3)) {
        cout << "1\n";
        return;
    }

    if ((r1 + c1) % 2 == (r2 + c2)%2 && ((r1 - c1) % 2 + 2) % 2 == ((r2 - c2 + 2) % 2 + 2) % 2) {
        cout << "2\n";
        return;
    }

    FOR(i,-3, 3) {
        FOR(j, -3, 3) {
            if (abs(i) + abs(j) <= 3) {
                int a = r1 + i, b = c1 + j;
                if (a + b == r2 + c2 || a - b == r2 - c2 || (abs(a - r2) + abs(b - c2) <= 3)) {
                    cout << "2\n";
                    return;
                }
            }
        }
    }

    FOR(i,-3, 3) {
        FOR(j, -3, 3) {
            if (abs(i) + abs(j) <= 3) {
                int c = r2 + i, d = c2 + j;
                if (r1 + c1 == c + d || r1 - c1 == c - d || (abs(r1 - c) + abs(c1 - d) <= 3)) {
                    cout << "2\n";
                    return;
                }
            }
        }
    }

    cout << "3\n";

}

int32_t main() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
    cerr.tie(0);
    cout << setprecision(9) << fixed;
    cerr << setprecision(6) << fixed;
    int test = 1, f;
//    cin >> test;
    F(_test, 0, test) {
        //cout<<"Case #"<<_test + 1<<": ";
        solve();
//		if(_test == 1)
//            return 0;
    }
}
/*
 */


#include<bits/stdc++.h>
using namespace std;

long long dp[67][2],ara[67];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=1,cnt=0,res=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        long long idx,sta;

        scanf("%lld",&n);

        for(i=1;i<=n;i++)
        {
            cin>>str;

            if(str=="AND")ara[i]=3;
            else{ ara[i]=5;   }

        }

        for(idx=n+1;idx>=0;idx--)
        {

            for(sta=0;sta<=1;sta++)
            {

                if(idx==n+1)
                {
                    if(sta==1)dp[idx][sta]=y;
                    else{  dp[idx][sta]=x;  }
                }
                else
                {

                    if(idx==0)
                    {
                        dp[idx][sta]=dp[idx+1][sta];
                    }
                    else
                    {

                        if(ara[idx]==3){  p=sta&1; q=sta&0;   }
                        else{  p=sta|1; q=sta|0;   }

                        dp[idx][sta]=dp[idx+1][p]+dp[idx+1][q];

                    }

                }

            }

        }

        printf("%lld\n",dp[0][0]+dp[0][1]);

       return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define yes {cout<<"Yes"<<endl;return 0;}
#define no {cout<<"No"<<endl;return 0;}
#define INF 2147483647
#define LINF 9223372036854775807

int main()
{
    int i,j,n;
    ll int dpt[61],dpf[61];
    string x[61];
    cin>>n;
    for(i=1;i<=n;i++)cin>>x[i];
    dpt[0]=1;
    dpf[0]=1;
    for(i=1;i<n+1;i++)
    {
        if(x[i]=="AND")
        {
            dpt[i]=dpt[i-1];
            dpf[i]=dpt[i-1]+2*dpf[i-1];
        }
        else if(x[i]=="OR")
        {
            dpt[i]=dpt[i-1]*2+dpf[i-1];
            dpf[i]=dpf[i-1];
        }

    }
    cout<<dpt[n]<<endl;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;

#define PB push_back

#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

using namespace std;

ll power(ll a,ll b){
    int result=1;
    while(b>0){
        if(b%2 == 1){
            result *= a;
        }
        a *= a;
        b /= 2;
    }
    return result;
}

ll gcd(ll x,ll y){
    ll r;
    while(y!=0&&(r=x%y)!=0){
        x=y;
        y=r;
    }
    return y==0?x:y;
}

void solve(){
    ll n;cin>>n;
   // ll m=1000000007;
    vector<string> v(n);
    string A;
    A="AND";
    string O;
    O="OR";
    for(auto &w:v) cin>>w;
    vector<pair<ll,ll>> sto(n);
    sto[0].first=1;
    sto[0].second=1;
    for(ll i=1;i<n;i++){
        if(v[i-1]==A){
            sto[i].first=sto[i-1].first;
            sto[i].second=sto[i-1].first+(2*sto[i-1].second);
        }else{
            sto[i].second=sto[i-1].second;
            sto[i].first=(2*sto[i-1].first)+sto[i-1].second;
        }
    }
    if(v[n-1]==A){
        cout<<sto[n-1].first<<endl;
    }else{
        cout<<(2*sto[n-1].first)+sto[n-1].second<<endl;
    }

}

int main(){
    Fas;
//    ll t{};
//    cin>>t;
//
//    while(t--){
        solve();
//    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#define ll long long
//Functionn for sorting
int main()
{

    unordered_map<long long int,long long int>mp;
    long long int n;
    cin>>n;
    vector<long long int>a(n);
    for(auto &x: a){
        cin>>x;
        mp[x]++;
    }
    long long int c=(n*(n-1))/2;
    vector<long long int>freq;
    for(auto &x:mp){
        freq.push_back(x.second);
    }
    for(auto &x: freq){
        c-=(x*(x-1))/2;
    }
    cout<<c;

}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit
const int lim = 100000007;
ll v2l[lim]; // 重さがv以上の橋の内、最も短いもの

ll get_l(ll v) {
    if (v < lim) return v2l[v];
    else return v2l[lim - 1];
}

ll func(const vector<ll> &v) {
    vector<ll> dist(v.size(), 0);
    dist[0] = 0;

    for (int i = 0; i < v.size(); ++i) {
        ll sum = 0;
        for (int j = i; j < v.size(); ++j) {
            sum += v[j];
            ll l = get_l(sum - 1);
            chmax(dist[j], dist[i] + l);
        }
    }

    return dist.back();
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> w(n);
    REP(i, n) cin >> w[i];
    vector<pair<ll, ll>> lv(m);
    REP(i, m) {
        cin >> lv[i].first >> lv[i].second;
        chmax(v2l[lv[i].second], lv[i].first);
    }

    for (int i = 0; i + 1 < lim; ++i) {
        chmax(v2l[i + 1], v2l[i]);
    }
    {
        ll max_w = *max_element(ALL(w));
        ll min_v = LINF;
        REP(i, m) {
            chmin(min_v, lv[i].second);
        }
        cerr << max_w << " " << min_v << endl;
        if (max_w > min_v) {
            cout << -1 << endl;
            return;
        }
    }

    ll ans = LINF;
    sort(ALL(w));
    do {
        ll val = func(w);
        chmin(ans, val);
    } while (next_permutation(ALL(w)));
    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=100010; //check the limits, dummy
int a[11];
int n, m;
int mp[100000010], mp1[100000010], l[N], v[N];
int main(){
	int t;
	scanf("%d%d",&n,&m);
	int mx1= 0;
	for(int i=0; i<n; ++i){
		scanf("%d",a+i);
		mx1=max(mx1, a[i]);
	}
	int mx = 0;
	bool bl =1;
	for(int i=0; i<m; ++i){
		scanf("%d%d",&l[i], &v[i]);
		mp[v[i]]=max(mp[v[i]], l[i]);
		mx=max(mx, v[i]);
		if(mx1>v[i]){
			bl=0;
		}
	}
	if(!bl){
		cout<<"-1"<<endl;
		return 0;
	}
	int tmp = 0;
	mp1[0]=0;
	++mx;
	for(int i=1; i<=mx; ++i){
		mp1[i]=max(mp1[i-1], mp[i-1]);
	}
	sort(a, a+n);
	int ans = 1e9;
	int cnt = 0;
	do{
		++cnt;
		int dis[10]={0};
		for(int i=0; i<n; ++i){
			tmp=a[i];
			dis[i]=0;
			for(int j=i-1; j>=0; --j){
				tmp+=a[j];
				tmp = min(tmp, mx);
				dis[i]=max(dis[i], mp1[tmp]+dis[j]);
			}
		}
		ans=min(ans, dis[n-1]);
	}while(next_permutation(a, a+n));
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define nl "\n"
#define ll long long
#define vii(N,M,x) vector<vector<long long>> x(N,vector<long long>(M))
#define pb push_back
#define ii pair<int,int>
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()

const int INF=1e9+5;
const int MOD=1e9+7;

using namespace std;

void solve(/*int caseN*/)
{
	int x,y; cin>>x>>y;

	if(x==y)
	{
		cout<<x;
	}
	else
	{
		int ans=-1;
		for(int i=0;i<3;i++)
		{
			if(i!=x && i!=y)
			{
				ans=i;
			}
		}
		cout<<ans;
	}
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    //int T; cin>>T;
    //while(T--)
        solve(/*T*/);
}

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  cout << fixed << setprecision(10);
  double n,b;
  cin >> n >> b;
  double s = n - b;
  double x = s/n;
  cout << x*100 << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
using P = pair<int,int>;

const int INF = 1001001001;

int main(){
   string s;
   cin >> s;
   int n = s.size();
   vector<int> c(3);
   for(int i = 0; i < n; i++){
       c[(s[i] - '0')%3]++;
   }
   int x = 0;
   for(int i = 0; i < 3; i++){
       x += c[i]*i;
   }
   int ans = INF;
   for(int i1 = 0; i1 < 3; i1++){
       for(int i2 = 0; i2 < 3; i2++){
           if(c[1] < i1) continue;
           if(c[2] < i2) continue;
           if(i1 + i2 == n) continue;
           int nx = x;
           nx -= i1*1;
           nx -= i2*2;
           if(nx%3 == 0) ans = min(ans, i1 + i2);
       }
   }
    if(ans == INF){
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int64 n;
  cin >> n;
  int a[10] = {};
  int s = 0, t = 0;
  for (; n; n /= 10, ++t) {
    ++a[n % 10 % 3];
    s += n % 10;
  }
  if (s % 3 == 0) {
    cout << "0\n";
    return;
  }
  if (s % 3 == 1) {
    if (a[1] && t > 1) {
      cout << "1\n";
      return;
    }
    if (a[2] >= 2 && t > 2) {
      cout << "2\n";
      return;
    }
    cout << "-1\n";
    return;
  }
  if (a[2] && t > 1) {
    cout << "1\n";
    return;
  }
  if (a[1] >= 2 && t > 2) {
    cout << "2\n";
    return;
  }
  cout << "-1\n";
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n , m , t, i , j , k ;
    cin >> n ;
    ll a[n] ;
    for(i=0;i<n;i++)
    {
        cin >> a[i] ;
    }
    map<ll, ll> mp ;
    ll ct = 0 ;
    for(i=0;i<n;i++)
    {
        ll temp = ((a[i])%200) ;
        mp[temp]++ ;
    }
    for(auto it: mp)
    {
        if((it.second) >= 2)
        {
            ct+= ((it.second)*(it.second - 1))/2 ;
        }
    }
    cout << ct ;
  return 0 ;
}

#include <bits/stdc++.h>
using namespace std;

struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;

using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;

#define pb push_back
#define mp make_pair
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" <<endl;
#define kd(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m";
#define kdl(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << ", \033[m";
#define kde(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m" << endl;

inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}

int main()
{
    int n = in_int();
    vll b(200, 0);
    rep(i,n) b[in_int() % 200]++;
    ll ans = 0;
    rep(i,200) {
        if (b[i]>=2) {
            ans += b[i] * (b[i] - 1) / 2;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int bs(int a[],int n,int val)
{
	if(a[0]>val) return -1;
	if(a[n-1]<=val) return n-1;
	int l=0;int u=n-2;
	while(l<=u)
	{
	 int mid=(l+u)/2;
	 if(a[mid]<=val && a[mid+1]>val)
	  return mid;
	 else if(a[mid]>val)
	  u=mid-1;
	 else l=mid+1;
	}
}
int main() {
	int n,m;
	cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
     cin>>a[i];
    sort(a,a+n);
    int p[n];
    int nn[n];
    nn[n-1]=-a[n-1];
    p[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
    	p[i]=a[i]+nn[i+1];
    	nn[i]=-a[i]+p[i+1];
    }
    int pf[n];
    int nnf[n];
    nnf[0]=-a[0];
    pf[0]=a[0];
    for(int i=1;i<n;i++)
    {
    	pf[i]=a[i]+nnf[i-1];
    	nnf[i]=-a[i]+pf[i-1];
    }
    int mini=INT_MAX;
    for(int i=0;i<m;i++)
    {
    	int val;cin>>val;
    	int x=bs(a,n,val);//x is last element less than , equal to val
    	//cout<<x<<endl;
    	int ans=INT_MAX;
    	if((x+1)%2==0)
    	 {
    	 	int a=0,b=0;
    	 	if(x!=-1) a=pf[x];
    	 	if(x+1<n) b=p[x+1];
    	    ans=a-val+b;
    	 }
    	else
    	{
    	 	int a=0,b=0;
    	 	if(x!=-1) a=nnf[x];
    	 	if(x+1<n) b=nn[x+1];
    	    ans=a+val+b;
    	}
    	mini=min(mini,ans);
    }
    cout<<mini<<endl;
	return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 1000;
char C[MAX * 4];
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

int N, Q;
int D[200001], dmemo[200001];
int ne[200001], he[200001];
int ne2[200001], he2[200001];
int dcnt[200001];
int que[200001], q, d;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	N = getint();
	for (int i = 2; i <= N; i++) {
		int a = getint();
		ne[i] = he[a];
		he[a] = i;
	}
	Q = getint();
	rep1(q, Q) {
		int u = getint();
		ne2[q] = he2[u];
		he2[u] = q;
		D[q] = getint();
	}
	que[q++] = 1;
	while (q) {
		int p = que[q - 1];
		if (p > 0) {
			que[q - 1] = -p;
			for (int i = he2[p]; i; i = ne2[i]) {
				dmemo[i] = dcnt[D[i]];
			}
			dcnt[d]++;
			d++;
			for (int i = he[p]; i; i = ne[i]) {
				que[q++] = i;
			}
		}
		else {
			for (int i = he2[-p]; i; i = ne2[i]) {
				dmemo[i] = dcnt[D[i]] - dmemo[i];
			}
			d--;
			q--;
		}
	}

	rep(i, MAX) {
		int X = i;
		rep(j, 3) {
			C[i * 4 + 2 - j] = '0' + X % 10;
			X /= 10;
		}
		C[i * 4 + 3] = ' ';
	}
	rep1(i, Q) putint(dmemo[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

const ll OO = 0x3f3f3f3f;
const ll mod =   1e9 + 7;
const double pi = 3.14159265359;

//freopen("window.in", "r", stdin);
//freopen("output.out", "w", stdout);
void skrrrt() {
    ios_base::sync_with_stdio(0), cin.tie(0);
}
//###############################Spaggetti############################
int n;
int a[22];
ll ans=1e15;
void solve(int ind,ll num){
    if(ind==n){
        ans=min(ans,num);
        return ;
    }

    int orr=0;
    for(int i=ind;i<n;i++){
        orr|=a[i];
        solve(i+1,orr^num);
    }

}
int main(){
    skrrrt();
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    solve(0,0);
    cout<<ans;
}

// In god we trust

#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>

#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define Si set<int>
#define Ui unordered_map<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000
#define LINF 1000000000000000000
#define _USE_MATH_DEFINES
#define int long long
using namespace std;
using namespace std::chrono;

int mod_power(int x, int y, int mod){
  int ans = 1;
  x %= mod;
  while(y){
    if (y & 1)
      ans *= x, ans %= mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}

int mod_inverse(int n, int mod){
  return mod_power(n, mod - 2, mod);
}

// Returns factorial of n
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
}

int ncr(int n, int r)
{
  if (r > n)
    return 0;
  if (r == 0 or r == n)
    return 1;
  int fact = 1;
  for (int i = 1; i <= r; i++)
    fact *= i;
  int ans = 1;
  for (int i = n; i > n - r; i--)
    ans *= i;
  ans /= fact;
  return ans;
}

int mod_ncr(int n, int r, int mod){
  if (r > n)
    return 0;
  if (r == 0 or r == n)
    return 1;
  int fact = 1;
  for (int i = 1; i <= r; i++)
    fact *= i, fact %= mod;
  int ans = 1;
  for (int i = n; i > n - r; i--)
    ans *= i, ans %= mod;
  ans *= mod_inverse(fact, mod), ans %= mod;
  return ans;
}

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;

    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;

  return m;
}

Vi divisors(int n){
  Vi front;
  Vi back;

  for (int i = 1; i <= sqrt(n); i++){
    if (n % i == 0)
      if (i == n / i)
	front.pb(i);
      else
	front.pb(i), back.pb(n / i);
  }
  for (int i = back.size() - 1; i >= 0 ; i--)
    front.pb(back[i]);
  return front;
}

int DCNT(int a){
  int ans = 0;
  while(a)
    ans++, a/=10;

  return ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int min_ = pow(2, 30) + 10;
  for (int i = 0; i < pow(2, n - 1); i++){
    int ii = i;
    Vi v;
    while(ii)
      v.pb(ii % 2), ii /= 2;
    int x = n - 1 - v.size();
    for (int j = 0; j < x; j++)
      v.pb(0);
    int ans = 0;
    int p = a[0];
    for (int j = 0; j < n - 1; j++){
      if (v[j])
	ans ^= p, p = 0;
      p |= a[j + 1];
    }

    ans ^= p;
    min_ = min(min_, ans);
  }

  cout << min_ << endl;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <tuple>

template <class E> struct FenwickTree {
    int _n;
    std::vector<E> data;

    FenwickTree(int n) : _n(n), data(n) { }

    void add(int p, E x) {
        ++p;
        while (p <= _n) {
            data[p - 1] += x;
            p += p & -p;
        }
    }
    E sum(int r) const {
        E s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
    E sum(int l, int r) const {
        return sum(r) - sum(l);
    }
};

long long proc(
    std::vector<int>             &cur,
    int                          x,
    int                          y,
    FenwickTree<int>             &ftcnt0,
    FenwickTree<long long>       &ftsum0,
    const FenwickTree<int>       &ftcnt1,
    const FenwickTree<long long> &ftsum1,
    const std::vector<int>       &arr)
{
    int v = cur[x];
    long long dem = (long long)ftcnt1.sum(0, v) * arr[v];
    long long cre = (long long)ftcnt1.sum(0, y) * arr[y];
    long long adj = (long long)ftsum1.sum(y, v);

    ftsum0.add(v, -arr[v]);
    ftcnt0.add(v, -1);
    cur[x] = y;
    ftsum0.add(y, arr[y]);
    ftcnt0.add(y, 1);

    return cre + adj - dem;
}

int main(int argc, char **argv)
{
    int n, m, q;
    std::cin >> n >> m >> q;
    std::vector<std::tuple<int, int, int>> txy;
    std::set<int> s = { 0 };

    for (int i = 0; i < q; i++) {
        int t, x, y;
        std::cin >> t >> x >> y;
        txy.push_back(std::make_tuple(t, x - 1, y));
        s.insert(y);
    }
    std::vector<int> arr(s.begin(), s.end());
    std::map<int, int> map;
    int ll = s.size();

    for (int i = 0; i < ll; i++) map.emplace(arr[i], i);

    FenwickTree<long long> ftsuma(ll);
    FenwickTree<long long> ftsumb(ll);
    FenwickTree<int>       ftcnta(ll);
    FenwickTree<int>       ftcntb(ll);
    std::vector<int> cura(n);
    std::vector<int> curb(m);
    ftcnta.add(0, n);
    ftcntb.add(0, m);
    long long sum = 0;

    for (const auto&e : txy) {
        int cy = map[std::get<2>(e)];
        sum += (std::get<0>(e) == 1) ? proc(cura, std::get<1>(e), cy, ftcnta, ftsuma, ftcntb, ftsumb, arr)
                                     : proc(curb, std::get<1>(e), cy, ftcntb, ftsumb, ftcnta, ftsuma, arr);
        std::cout << sum << std::endl;
    }
    return 0;
}

/***************************************************************
	File name: HaHa
	Author: ljfcnyali
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 1e5 + 10;
const int INF = 1e18;

int K, n, m, a[maxn], b[maxn];
pii p[maxn];

inline bool Check(int x)
{
	int sum = 0;
	REP(i, 1, K)
	{
		int r = x + a[i] * m, l = a[i] * m - x;
		l = max(l, 0ll);
		p[i] = pii((l + n - 1) / n, r / n);
		p[i].first = max(p[i].first , 0ll);
		if ( p[i].first > p[i].second ) return false;
		sum += p[i].first; b[i] = p[i].first;
	}
	if ( sum > m ) return false;
	int i = K;
	while ( sum <= m && i >= 1 )
	{
		int val = min(p[i].second - p[i].first, m - sum);
		sum += val; b[i] += val;
		if ( sum == m ) return true;
		-- i;
	}
	return false;
}

signed main()
{
	scanf("%lld%lld%lld", &K, &n, &m);
	REP(i, 1, K) scanf("%lld", &a[i]);
	int L = 0, R = INF, ans;
	while ( L <= R )
	{
		int Mid = L + R >> 1;
		if ( Check(Mid) ) { ans = Mid; R = Mid - 1; }
		else L = Mid + 1;
	}
	Check(ans);
	REP(i, 1, K) printf("%lld ", b[i]); puts("");
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
int c[510][510];
int sumr[510],sumc[510];
int a[510],b[510];
bool check(){
	for(int i=1;i<=n;i++)if(a[i]<0)return 0;
	for(int i=1;i<=n;i++)if(b[i]<0)return 0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(c[i][j]!=a[i]+b[j])return 0;
		}
	return 1;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			cin>>c[i][j];
			sumr[i]+=c[i][j];
			sumc[j]+=c[i][j];
		}
	int mn1=INF,mn2=INF;
	for(int i=1;i<=n;i++)mn1=min(mn1,c[i][1]);
	for(int i=1;i<=n;i++)mn2=min(mn2,c[1][i]);
	for(int i=1;i<=n;i++)a[i]=c[i][1]-mn1;
	for(int i=1;i<=n;i++)b[i]=c[1][i]-mn2;
	int ex=c[1][1]-a[1]-b[1];
//	cout<<ex<<endl;
//	for(int i=1;i<=n;i++)cout<<a[i]<<' ';
//	puts("");
//	for(int i=1;i<=n;i++)cout<<b[i]<<' ';
//	puts("");
	if(ex<0){
		puts("No");
		return 0;
	}
	for(int i=1;i<=n;i++)b[i]+=ex;
	if(!check()){
		puts("No");
		return 0;
	}
	puts("Yes");
	for(int i=1;i<=n;i++)cout<<a[i]<<' ';
	puts("");
	for(int i=1;i<=n;i++)cout<<b[i]<<' ';
	puts("");
	return 0;
}
/*
a1+b1		a1+b2		a1+b3
a2+b1		a2+b2		a2+b3
a3+b1		a3+b2		a3+b3
sumall=3*(a1+a2+a3+b1+b2+b3)
sumr1=12=3*a1+b1+b2+b3
sumr2=6=3*a2+b1+b2+b3
sumr3=9=3*a3+b1+b2+b3
sumc1=3*b1+a1+a2+a3
a2-a1=(sumr2-sumr1)/3
a3-a2=(sumr3-sumr2)/3

2 0 1
1 0 2
*/

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int GetDigit(ll num){
    return std::to_string(num).length();
}

int main(){
  int N;
  cin>>N;
  vector<vector<int>> data(N, vector<int>(N));

    for (int j = 0; j < N; j++) {
      cin >> data.at(0).at(j);
    }

    vector<int> V(N);
    for(int i=0;i<N-1;i++){
      V[i]=data.at(0).at(i+1)-data.at(0).at(i);
    }
  bool flag=false;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> data.at(i).at(j);
      if(j!=0 && data.at(i).at(j-1)+V[j-1]!=data.at(i).at(j)) flag=true;
    }
  }

  if(flag) cout<<"No"<<endl;
  else{
    vector<int> V(N);
    int M=1000000007;
    for(int i=0;i<N;i++){
      V[i]=data.at(i).at(0)-data.at(0).at(0);
      M=min(M,V[i]);
    }
    for(int i=0;i<N;i++){
      V[i]-=min(M,0);
    }
    flag=false;
    for(int i=0;i<N;i++){
      data.at(0).at(i)+=min(M,0);
      if(data.at(0).at(i)<0) flag=true;
    }
    if(flag) cout<<"No"<<endl;
    else{
      cout<<"Yes"<<endl;
      for(int i=0;i<N;i++){
        cout<<V[i]<<" ";
      }
      cout<<endl;
      for(int i=0;i<N;i++){
        cout<<data.at(0).at(i)<<" ";
      }
    }
  }

return 0;}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)
template<unsigned MOD_> struct ModInt {
    static constexpr unsigned MOD = MOD_;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

    ModInt inv() const { return pow(MOD-2); }
    ModInt pow(long long y) const {
	ModInt b = *this, r = 1;
	if (y < 0) { b = b.inv(); y = -y; }
	for (; y; y>>=1) {
	    if (y&1) r *= b;
	    b *= b;
	}
	return r;
    }

    friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
    friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
    friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
    friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
    friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
    friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
    friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};

constexpr LL MOD = 1000000007;
using Mint = ModInt<MOD>;

int N;
int A[100011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);
    sort(A, A+N);

    Mint ans = 1;
    int prv = 0;
    REP (i, N) {
	ans *= A[i] - prv + 1;
	prv = A[i];
    }

    printf("%d\n", ans.geti());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repab(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repr(i, n) for (ll i = (ll)(n); i >= 0; i--)
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.rbegin(), v.rend())

//定数
#define INF32 2147483647           // 2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807  // 9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007             //問題による

int main() {
  ll a, b;
  cin >> a >> b;

  ll ans = 0;
  if (a + b >= 15 && b >= 8) {
    ans = 1;
  } else if (a + b >= 10 && b >= 3) {
    ans = 2;
  } else if (a + b >= 3) {
    ans = 3;
  } else {
    ans = 4;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vint> vvint;
typedef pair<ll, ll> iPair;
#define ff first
#define ss second

static ll n;
static vector<iPair> arr;

int main(){
	cin >> n;
	arr.resize(n);
	for(int i = 0; i < n; i++)
		cin >> arr[i].ff >> arr[i].ss;

	bool res = false;
	for(int i = 0; i < n && !res; i++){
		for(int j = i+1; j < n && !res; j++){
			for(int k = j+1; k < n && !res; k++){
				if((arr[i].ff == arr[j].ff) && arr[i].ff == arr[k].ff){
					res = true;
				}

				else if((arr[i].ss == arr[j].ss) && arr[i].ss == arr[k].ss){
					res = true;
				}

				else if((arr[i].ff - arr[j].ff)*(arr[i].ss - arr[k].ss) == (arr[i].ff - arr[k].ff)*(arr[i].ss - arr[j].ss))
					res = true;
			}
		}
	}

	if(res)
		cout << "Yes";

	else
	{
		cout << "No";
	}

	return 0;
}

#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a * b / gcd(a, b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}

static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=1e9+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位

class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
	int getsize(){
		set<int> ma;
		rep(i,table.size())ma.insert(root(i));
		int re=ma.size();
		return re;
	}
};

lint culc(lint a,lint b){
	return((a+b-1)/b);
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(16);
	lint n,t;
	int m;
	in(n,m,t);
	vlint a(m),b(m);
	rep(i,m)in(a[i],b[i]);
	bool flg=true;
	lint now=n;
	rep(i,m){

		if(i==0)now=now-a[i];
		else now=now-(a[i]-b[i-1]);
		//cout<<i<<" "<<now;
		if(now<=0)flg=false;
		now=now+(b[i]-a[i]);
		now=min(n,now);
		//out("",now);
	}
	if(now-(t-b[m-1])<=0)flg=false;
	if(flg)out("Yes");
	else out("No");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
const int mxN=30001,M=1e9+7;

int main() {
int n,k;
cin>>n>>k;
vector<int>v;
for(int i=1;i <=n;i ++){
    int x;cin>>x;
    if(x!=k)v.push_back(x);
}
for(int a: v)cout<<a<<" ";
 return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n,q;
    cin>>n>>q;
    long long int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    long long int b[n]={0};
    b[0]=a[0]-1;
    for(int i=1;i<n;i++){
        b[i]=a[i]-a[i-1]-1;
    }
    for(int i=1;i<n;i++){
        b[i]=b[i]+b[i-1];
    }
    long long int k;
    for(int i=0;i<q;i++){
        cin>>k;
        int p=lower_bound(b,b+n,k)-b;
        if(p==0){
            cout<<k;
        }
        else{
            cout<<a[p-1]+(k-b[p-1]);
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(998244353);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        ans %= mod;
        a = a * a;
        a %= mod;
        b >>= 1;
    }
    return ans % mod;
}

string solve(string s){
    string t = "";
    rep0(i, s.size()){
        if(s[i] == s[i + 1]){
            t.push_back(s[i]);
        }else if(s[i] + s[i + 1] == 163){
            t.push_back('S');
        }else if(s[i] + s[i + 1] == 165){
            t.push_back('R');
        }else t.push_back('P');
        ++i;
    }
    s = t;
    return s;
}

//modの値の確認をすること
int main(){
    ll n,k;
    string s;
    cin >> n >> k >> s;
    rep0(i, k)s = solve(s + s);
    pf(s[0]);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,int>

int main(){
  int N;
  cin >> N;
  vector<vector<string>> S(9,vector<string> (256));
  S[1][1] = "AB";
  int k = 1;
  rep(i,N-1){
    rep(j,k){
      S[i+2][j+1] = S[i+1][j+1] + S[i+1][j+1];
    }
    rep(j,k){
      string T,R;
      T = S[i+1][j+1];
      rep(l,T.size()){
        if(T.at(l)=='A') R = R+"B";
        else R = R+"A";
      }
      S[i+2][k+j+1] = T + R;
    }
    rep(j,k+1){
      S[i+2][2*k+1] = S[i+2][2*k+1] + "A";
    }
    rep(j,k+1){
      S[i+2][2*k+1] = S[i+2][2*k+1] + "B";
    }
    k= 2*k+1;
  }
  cout << k << endl;
  rep(i,k){
    cout << S[N][i+1] << endl;
  }
}


#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include <math.h>
#include<climits>
using namespace std;
#define int long long
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define print(x) cout<<x<<"\n"
#define printt(x,y) cout<<x<<" "<<y<<"\n"
#define printtt(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define pb push_back
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define all(v) v.begin(),v.end()
#define vvi vector<vector<int>>
#define maxq priority_queue<int>
#define minq priority_queue<int,vector<int>,greater<int>>
#define mod 1000000007
#define N 200009

void solve() {
	int n;
	cin >> n;

	if (n < 10) {
		cout << "Yes" << endl; return;
	}

	vi v;
	while (n > 0) {
		v.pb(n % 10);
		n = n / 10;
	}

	int z = v.size();
	int ok = 1;
	for (int i = 0; i < z / 2; i++) {
		//print(v[i]);
		if (v[i] != v[z - i - 1])
			ok = 0;
	}
	if (ok == 1) {
		cout << "Yes" << endl;
		return;
	}

	int c = 0;
	for (int i = 0; i < z; i++)
		if (v[i] != 0)
			break;
		else
			c++;

	//print(c);
	reverse(all(v));
	int i = 0, j = z - 1 - c;
	ok = 1;
	//printt(i, j);
	while (i < j) {
		//printt(v[i], v[j]);
		if (v[i] != v[j])
			ok = 0;
		i++, j--;
	}

	if (ok == 0)
		cout << "No";
	else
		cout << "Yes";

}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ans=-1;
void Exgcd(ll A,ll B,ll &x,ll &y,ll &d)
{
	if(B==0)
	{
		x=1;y=0;d=A;
		return;
	}
	Exgcd(B,A%B,x,y,d);
	ll tmp=y;
	y=x-(A/B)*y;
	x=tmp;

}
void Solve(ll A,ll B,ll C,ll a,ll b)
{
	ll x,y,d;
	Exgcd(A,B,x,y,d);
	if(C%d!=0)return;
	x*=C/d;
	x=(x%(B/d)+(B/d))%(B/d);
	if(ans==-1)ans=A*x+a;
	else ans=min(ans,A*x+a);
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		ans=-1;
		ll X,Y,P,Q,A,B;
		cin>>X>>Y>>P>>Q;
		A=2ll*X+2ll*Y;
		B=P+Q;
		for(ll a=X;a<X+Y;a++)
			for(ll b=P;b<P+Q;b++)Solve(A,B,b-a,a,b);
		if(ans==-1)puts("infinity");
		else cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define lli long long
#define test int t;cin>>t;while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define  mod 1000000007
using namespace std;
void solve()
{
	double n , x , y , ans;
	cin >> n >> x >> y;
	lli dist = ceil(sqrt(x * x + y * y));
	if(dist == n)
	{
		ans = 1;
	}
	else
	{
		if(dist <= 2*n)
		{
			ans = 2;
		}
		else
		{
            ans = ceil(dist / (double)n);
		}
	}
	cout << ans;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
#endif
    fast_io;
	//test
	{
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using P=pair<int,int>;
using T=tuple<LL,int,int,int>;
constexpr LL mod=1000000007;
constexpr LL inf=1e9;
constexpr double eps=1e-13;
constexpr double pi=3.141592653589;
int in(){
    int x;
    scanf("%d",&x);
    return x;
}
int main(){
    LL r=in(),x=in(),y=in();
    LL d=x*x+y*y,L=0,R=inf/r;
    if(r*r>d){
        cout<<2<<endl;
        return 0;
    }
    while(R-L>1){
        LL mid=(L+R)/2;
        if((r*mid)*(r*mid)>=d)R=mid;
        else L=mid;
    }
    cout<<R<<endl;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
//const ll mod = 1e9 + 7;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int r1, c1, r2, c2;

int solve() {
    if (r1 == r2 && c1 == c2) return 0;
    if (r1+c1 == r2+c2 ||
        r1-c1 == r2-c2 ||
        abs(r1-r2)+abs(c1-c2) <= 3) {
        return 1;
    }
    if ((r1+c1)%2 == (r2+c2)%2) return 2;
    for (int i = -4; i <= 4; i++) {
        for (int j = -4; j <= 4; j++) {
            if (abs(i)+abs(j)<=3) {
                int r3 = r2+i;
                int c3 = c2+j;
                if (r1+c1 == r3+c3 ||
                    r1-c1 == r3-c3 ||
                    abs(r1-r3)+abs(c1-c3) <= 3) {
                    return 2;
                }
            }
        }
    }

    return 3;
}

void input() {
    cin >> r1 >> c1 >> r2 >> c2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define debug(args...){ string _s = #args;replace(_s.begin(),_s.end(),',', ' ');stringstream _ss(_s);istream_iterator<string>_it(_ss);err(_it, args);} cout<<endl;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}

#define ll              long long int
#define MAX             2134567891
#define pf(a)           printf("%lld", a)
#define sf(a)           scanf("%lld", &a)
#define sf2(a,b)        scanf("%lld %lld", &a, &b)
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define rev(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define TC(t)           printf("Case %lld: ",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb              push_back
#define eb              emplace_back
#define ff              first
#define ss              second
#define NL              printf("\n");
#define bug(a)          cout<<#a<<" "<<a<<" ";
#define hlw             printf("hlw\n");
#define NN              111
#define MOD             1000000007///10^9
#define N               1000007 ///10^6->6 zero after 1 **

ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
//bitset<N>B;
//map <ll,ll> mp;
ll fun(ll in,ll cur,ll tot)
{
    if(in==n)return cur^tot;
    return min(fun(in+1,cur|x[in],tot), fun(in+1,x[in],cur^tot));
}
int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc=1,in,loc,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
//cin>>tc;
rep(t,tc)
{
    cin>>n;
    fr(i,n)cin>>x[i];
    cout<<fun(0,0,0)<<endl;
}
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// Division MOD needs BigMod(a,n-2)
/// long long or double? sqrt or division will work fine??
/// sort(begin(v), end(v), [] (int a, int b) { return a > b; });    /// Lambda Function for manual Sort


#include <bits/stdc++.h>
using namespace std;

class DSU {
private:
  vector<int> rank, parent;
  vector<unordered_map<int, int>> freq;

public:
  DSU(vector<int> &init) {
    int sz = init.size();
    rank = vector<int>(sz, 0);
    parent = vector<int>(sz, 0);
    iota(parent.begin(), parent.end(), 0);
    freq = vector<unordered_map<int, int>>(sz);
    for (int i = 0; i < sz; ++i) {
      freq[i][init[i]] = 1;
    }
  }

  int Find(int x) {
    if (parent[x] != x) {
      parent[x] = Find(parent[x]);
    }
    return parent[x];
  }

  bool Union(int x, int y) {
    int rootX = Find(x), rootY = Find(y);
    if (rootX == rootY) {
      return false;
    }

    if (rank[rootX] == rank[rootY]) {
      ++rank[rootX];
    }

    if (rank[rootX] < rank[rootY]) {
      swap(x, y);
      swap(rootX, rootY);
    }

    // rootX has higher rank
    parent[rootY] = rootX;

    for (pair<int, int> class_freq : freq[rootY]) {
      freq[rootX][class_freq.first] += class_freq.second;
    }
    return true;
  }

  int GetCount(int x, int c) {
    int root = Find(x);
    return freq[root][c];
  }
};

int32_t main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> C(N);
  for (int i = 0; i < N; ++i)
    cin >> C[i];

  DSU dsu(C);
  for (int q = 0; q < Q; ++q) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b;
      cin >> a >> b;
      dsu.Union(a - 1, b - 1);
    } else {
      int x, y;
      cin >> x >> y;
      cout << dsu.GetCount(x - 1, y) << '\n';
    }
  }

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=2e5+1;
struct BIT{
	ll bit[200004];
	int dat[200004];
	void init(){
		for(int i=0;i<=M;i++)bit[i]=dat[i]=0;
	}
	void add(int id,int a,int b){
		for(;id;id-=(id&-id))dat[id]+=a,bit[id]+=b;
	}
	ll got1(int id){
		ll res=0;
		for(;id<=M;id+=(id&-id))res+=bit[id];
		return res;
	}
	int got2(int id){
		int res=0;
		for(;id<=M;id+=(id&-id))res+=dat[id];
		return res;
	}
}X,Y;
vector<int>all;
int n,m,Q;
ll ans=0;
int a[200005],b[200004];
int x[200004],y[200004],t[200004];
ll gotx(int t){
	return Y.got1(t)+(ll)(m-Y.got2(t))*all[t];
}
ll goty(int t){
	return X.got1(t)+(ll)(n-X.got2(t))*all[t];
}
int main(){
	X.init(),Y.init();
	cin>>n>>m>>Q;
	all.push_back(0);
	for(int i=1;i<=Q;i++){
		cin>>t[i]>>x[i]>>y[i],all.push_back(y[i]);
	}
	all.push_back(-1);
	sort(all.begin(),all.end()),all.erase(unique(all.begin(),all.end()),all.end());
	for(int i=1;i<=n;i++)a[i]=1,X.add(1,1,0);
	for(int i=1;i<=m;i++)b[i]=1,Y.add(1,1,0);
	for(int i=1;i<=Q;i++){
		y[i]=lower_bound(all.begin(),all.end(),y[i])-all.begin();
		if(t[i]==1){
			ans-=gotx(a[x[i]]);X.add(a[x[i]],-1,-all[a[x[i]]]);
			a[x[i]]=y[i];
			ans+=gotx(a[x[i]]);X.add(a[x[i]],1,all[a[x[i]]]);
		}else{
			ans-=goty(b[x[i]]);Y.add(b[x[i]],-1,-all[b[x[i]]]);
			b[x[i]]=y[i];
			ans+=goty(b[x[i]]);Y.add(b[x[i]],1,all[b[x[i]]]);
		}
		cout<<ans<<"\n";
	}
}


//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<ll, ll> p;
const int INF = 1e9;
const double eps = 1e-7;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long double pi = 4 * atan(1);
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &x : v)
        is >> x;
    return is;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//素数判定(O(√n))
bool is_prime(int n)
{
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return n != 1;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> x(n);
    cin >> x;
    vector<ll> y;
    for (int i = 2; i <= 50; i++)
    {
        if (is_prime(i))
            y.push_back(i);
    }
    ll ans = LINF;
    //cout << y.size() << "\n";
    rep(i, (1 << y.size()))
    {
        ll sum = 1;
        rep(j, y.size())
        {
            if ((1 << j) & i)
            {
                sum *= y[j];
            }
        }
        bool check = false;
        rep(j, n)
        {
            if (gcd(sum, x[j]) == 1)
            {
                check = true;
            }
        }
        if (!check)
            chmin(ans, sum);
    }
    cout << ans << "\n";
}

#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  998244353;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // long longの1次元の型に vll という別名をつける
using vvll = vector<vll>; // long longの2次元の型に vvll という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pll という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
    ll ans=0;
  int h,w;
  cin>>h>>w;
    vi dx={-1,0,1,0};
   vi dy={0,-1,0,1};
  vvll a(h,vll(w));
  rep(i,h)rep(j,w){
      char s;
      cin>>s;
      if(s=='.')a.at(i).at(j)=0;
      else a.at(i).at(j)=1;
  }

  rep(i,h)rep(j,w){

      if(a.at(i).at(j)==1)continue;
      else{
          int nh,nw;
          rep(k,4){
              nh=i+dx.at(k);
              nw=j+dy.at(k);
              if(nh<0||nh>=h||nw<0||nw>=w)continue;
              else{
                  if(a.at(nh).at(nw)==0)ans++;
              }
          }
          a.at(i).at(j)=1;
      }

  }
  cout<<ans<<endl;
  //rep(i,h)rep(j,w)cout<<a.at(i).at(j);
}


#include<cstdio>
#ifdef WIN64
#define LL "%I64d"
#elif WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
const int mo=998244353;
long long a,b,c;
long long sigma(long long a)
{
	if(a%2==0)
		return (a/2)*(a+1)%mo;
	else
		return a*((a+1)/2)%mo;
}
int main()
{
	scanf(LL LL LL,&a,&b,&c);
	long long ans=sigma(c)%mo*sigma(b)%mo*sigma(a)%mo;
	printf(LL,ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int X,Y,Z; cin >> X >> Y >> Z;
  double t = (double)Y/X;
  for (int i =1000000; i>=0; i--) {
    if (t > (double)i/Z) {
      cout << i << endl; break; } }
  return 0;
}


#include<cstdio>
int n;
int gao(int x)
{
	for (int j=10;j>=0&&x>n;--j)
		if (x&(1<<j)) x^=1<<j;
	return x?x:1;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) printf("%d %d\n",gao(i<<1),gao(i<<1|1));
	return 0;
}

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int j0 = i * 2, j1 = i * 2 + 1;
    printf("%d %d\n", j0 % n + 1, j1 % n + 1);
  }
  return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,a[20][20],ok[300000],dp[300000];

int main()
{
  cin>>n>>m;
  int x,y;
  rep(i,m)
  {
    scanf("%d%d",&x,&y);
    --x;
    --y;
    a[x][y]=a[y][x]=1;
  }
  rep(i,1<<n)
  {
    bool b=true;
    rep(j,n)
    {
      for(int k=j+1;k<n;k++)
      {
        if((i&(1<<j))==0||(i&(1<<k))==0) continue;
        if(a[j][k]==0)
        {
          b=false;
          break;
        }
      }
      if(!b) break;
    }
    ok[i]=(int)b;
  }
  rep(i,(1<<n)+5) dp[i]=1e9;
  dp[0]=0;
  rep(i,1<<n)
  {
    if(dp[i]==1e9) continue;
    int lft=(1<<n)-1-i;
    for(int sub=lft;sub>0;sub=(sub-1)&lft) if(ok[sub]==1) dp[i|sub]=min(dp[i|sub],dp[i]+1);
  }
  cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
#include <numeric>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int> >;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int> >; // クラスカル法とかで、{cost, {from,
                                      // to}}的に使う。
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n, m;
    cin >> n >> m;
    if(n == 1){
        if(m == 0){
            cout << 1 << " " << 2 << endl;
            return 0;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    if(abs(m) >= n-1){
        cout << "-1" << endl;
        return 0;
    }
    if(m == 0){
        ll tmp = 1;
        for(int i=0;i<n;i++){
            cout << tmp << " ";
            tmp++;
            cout << tmp << endl;
            tmp++;
        }
        return 0;
    }
    if(m > 0){
        ll tmp = 0;
        for(int i=0;i<m+1;i++){
            cout << n-m+2*i << " " << n-m+2*i+1 << endl;
            tmp = n-m+2*i+1;
        }
        for(int i=0;i<n-m-1;i++){
            tmp++;
            cout << n-m-1-i << " " << tmp << endl;
        }
    }
    else{
        cout << "-1" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

// 組合せを素数で割った値
const int MAX = 510000;
const ll MOD = 1e9 + 7;
ll fac[MAX], finv[MAX], inv[MAX];

// 前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = ((res * res % m) * x) % m;
  }
  return res;
}

// A*B(行列の掛け算, 各項はmで割った余り)
vector<vector<ll>> mul(const vector<vector<ll>> &A, const vector<vector<ll>> &B, ll m) {
  vector<vector<ll>> C(A.size(), vector<ll>(B[0].size(), 0));
  for (int i = 0; i < A.size(); i++) {
    for (int k = 0; k < B.size(); k++) {
      for (int j = 0; j < B[0].size(); j++) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m;
      }
    }
  }
  return C;
}

// A^n(行列累乗, 各項はmで割った余り)
vector<vector<ll>> power_M(vector<vector<ll>> A, ll n, ll m) {
  vector<vector<ll>> B(A.size(), vector<ll>(A.size(), 0));
  for (int i = 0; i < A.size(); i++) B[i][i] = 1;

  while (n > 0) {
    if (n & 1) B = mul(B, A, m);
    A = mul(A, A, m);
    n >>= 1;
  }
  return B;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  COMinit();

  ll n, m, kk;
  cin >> n >> m >> kk;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);

  vector<ll> x(m), y(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }

  ll inv_2 = power(2, MOD - 2, MOD);

  vector<vector<ll>> M(n, vector<ll>(n, 0));
  for (int k = 0; k < m; k++) {
    M[x[k]][y[k]] += inv_2;
    M[x[k]][y[k]] %= MOD;
    M[x[k]][x[k]] += inv_2;
    M[x[k]][x[k]] %= MOD;
    M[y[k]][x[k]] += inv_2;
    M[y[k]][x[k]] %= MOD;
    M[y[k]][y[k]] += inv_2;
    M[y[k]][y[k]] %= MOD;
    for (int i = 0; i < n; i++) {
      if (i == x[k] || i == y[k]) continue;
      M[i][i] += 1;
      M[i][i] %= MOD;
    }
  }

  vector<vector<ll>> M2 = power_M(M, kk, MOD);

  ll keep = power(power(m, kk, MOD), MOD - 2, MOD);

  vector<ll> ans(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
//      cout << M2[i][j] << " ";
      ans[i] += M2[i][j] * a[j] % MOD;
      ans[i] %= MOD;
    }
//    cout << endl;
    cout << (ans[i] * keep) % MOD << '\n';
  }
}

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<PI> VPI;

template<class T> bool tmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool tmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define F first
#define S second
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int _n(b),i(a);i<_n;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define TRAV(a,x) for (auto& a : x)

void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

const int mod = 998244353;

int madd(int a, int b) {
    a = a + b;
    while (a < 0) a += mod;
    while (a >= mod) a -= mod;
    return a;
}

int mmul(int a, int b) {
    return (a * 1ll * b) % mod;
}

int mpow(int a, int n) {
    int r = 1;
    for(; n; n >>= 1) {
        if (n&1) r = mmul(r, a);
        a = mmul(a, a);
    }
    return r;
}

int minv(int a) {
    return mpow(a, mod-2);
}

int mdiv(int a, int b) {
    return mmul(a, minv(b));
}

const int MX = 5005;
char g[MX][MX];
int n, m, k;
int mem[MX][MX];
int tot, b3;

int f(int i, int j) {
    if (i == n && j == m)
        return tot;
    if (i > n || j > m)
        return 0;

    int &r = mem[i][j];
    if (r != -1) return r;

    if (g[i][j] == 'R')
        r = f(i, j+1);
    else if (g[i][j] == 'D')
        r = f(i+1, j);
    else if (g[i][j] == 'X')
        r = madd(f(i, j+1), f(i+1, j));
    else
        r = mmul(mmul(2, madd(f(i, j+1), f(i+1, j))), b3);

    return r;
}

int solve() {
    tot = mpow(3, n * m - k);
    b3 = minv(3);
    memset(mem, -1, sizeof mem);
    return f(1, 1);
}

int main() {
    setIO();
    int t=1; // cin>>t;
    while(t--) {
        cin>>n>>m>>k;
        REP(i, n+1) REP(j, m+1) g[i][j] = '?';
        REP(l, k) {
            int i, j; cin >> i >> j;
            cin >> g[i][j];
        }
        cout<<solve()<<"\n";
    }

    return 0;
}


#include "bits/stdc++.h"
using namespace std;

using ll = long long;

signed main(){
	ll n,x;
	cin >> n >> x;

	cout << (n/x) << "\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
  ll n,w,t=0,cnt=0;
  cin>>n>>w;
  while(t<=n)
  {
    t+=w;
    cnt++;
  }
  cout<<cnt-1<<endl;
  return 0;
}