#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    double a[n];
    pair<int,int>p[n];
    int fac[20][20]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        long long x=(a[i]+0.0000000001)*1000000000;
        int two=0,five=0;
        while(x%2==0)two++,x/=2;
        while(x%5==0)five++,x/=5;
        two=min(18,two),five=min(18,five);
        fac[two+1][five+1]++;
        p[i]={18-two,18-five};
    }
    for(int i=0;i<20;i++)for(int j=0;j<19;j++)fac[i][j+1]+=fac[i][j];
    for(int i=0;i<20;i++)for(int j=0;j<19;j++)fac[j+1][i]+=fac[j][i];
    long long ans=0;
    for(int i=0;i<n;i++){
        int x=fac[19][19]-fac[p[i].first][19]-fac[19][p[i].second]+fac[p[i].first][p[i].second];
        if(p[i].first<10 && p[i].second<10)x--;
        ans+=x;
}
    cout<<ans/2<<endl;
    return 0;
}

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>

using ll = long long ;
#define MAXN 200009
#define MAXL 29
std::map<std::pair<int,int>, int> bucket;

class Rat
{
    private:
        int cofp2,cofp5;
    public:
        Rat(){}
        Rat(ll nn,ll dd)
        {
           ll tn = nn;
           ll td = dd;
           cofp2 = 0;
           while( tn%2==0){
               cofp2++;
               tn/=2;
           }
           while(td%2==0){
               cofp2--;
               td/=2;
           }
           cofp5=0;
           while(tn%5==0){
               cofp5++;
               tn/=5;
           }
           while(td%5==0){
               cofp5--;
               td/=5;
           }
        }
        void output()
        {
            printf("2^{%d}*5^{%d}\n",cofp2,cofp5);
        }
        int getcofp2()
        {
            return cofp2;
        }
        int getcofp5()
        {
            return cofp5;
        }
};

int main(void)
{
    char theNumber[MAXL];
    int N,i,j;
    scanf("%d",&N);
    Rat *a ;

    for (i=0;i<N;i++){
        scanf("%s",theNumber);
        char* ret = strchr(theNumber,'.');
        if (ret==NULL){
            a = new Rat(atoi(theNumber),1);
        } else {
            int lenOfDen = strlen(&theNumber[ret-&theNumber[0]+1]);
            ll den = pow(10,lenOfDen);
            ll num = atoi(theNumber)*den
            +atoi(&theNumber[ret-&theNumber[0]+1]);
            a = new Rat(num,den);
        }
        bucket[std::make_pair(a->getcofp2(),a->getcofp5())] ++;
    }

    ll s=0;
    for (auto it:bucket) {
        int x1 = it.first.first;
        int y1 = it.first.second;
        int r1 = it.second;
        for (auto it2:bucket) {
            int x2 = it2.first.first;
            int y2 = it2.first.second;
            int r2 = it2.second;

            if(x1+x2>=0 && y1+y2>=0)
            {
                if(it<it2){
                    s+=((ll)r1)*r2;
                } else if (it==it2) {
                    s+=((ll)r1*(r1-1))/2;
                }
            }
        }
    }

    printf("%lld\n",s);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
int read(){
    int s = 0,ne = 1; char c = getchar();
    while(c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
    while(c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
    return s * ne;
}
int n, ai, sum = 0, mx = 0;
signed main(){
    n = read(); for(int i = 1; i <= n; i++) ai = read(), mx = max(mx, ai), sum += mx - ai;
    printf("%lld", sum);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];

int main(){
int n;cin>>n;
ll sum=0;
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=1;i<n;i++){
    if(a[i]<a[i-1])
        sum+=a[i-1]-a[i],a[i]=a[i-1];
}
cout<<sum<<endl;
return 0;
}


#include <stdio.h>
int main (){
	char tanggal[20];
	scanf("2017/01/%s",tanggal);
	printf("2018/01/%s",tanggal);

	return 0;
}

#include <stdio.h>

int main()
{
    char op[11];
    int ans[2];

    scanf("%s", op);

    for (int i = 8 ; i <= 9 ; i++){
        ans[i-8] = op[i]-48;
    }

    printf("2018/01/%d%d", ans[0], ans[1]);
    return 0;
}


#include<bits/stdc++.h>
const int N = 5005;
const long long inf = 1e18;
using namespace std;

typedef pair <int, int> ii;
vector <ii> mv;

int n, ans;
long long dp[N][N], Min[N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        x += y;
        mv.push_back(ii(x, y));
    }
    sort(mv.begin(), mv.end());
    for (int i = 0; i < N; i++) Min[i] = inf;
    Min[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j >= 1; j--){
            if (mv[i-1].first - mv[i-1].second >= Min[j-1]) dp[i][j] = Min[j-1] + mv[i-1].second;
            else dp[i][j] = inf;
            Min[j] = min(Min[j], dp[i][j]);
            if (dp[i][j] != inf) ans = max(ans, j);
        }
    }
    cout << ans;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, a[15], x[15][15], y[15][15];

int cnt(int i)
{
    if (!i) return 0;
    return (i & 1) + cnt(i >> 1);
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        for (int j = 0; j < a[i]; j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int ok = 1;
        for (int i = 0; i < n; i++)
        {
            if ((bit >> i) & 1)
            {
                for (int j = 0; j < a[i]; j++)
                {
                    if (((bit >> (x[i][j] - 1)) & 1) ^ y[i][j]) ok = 0;
                }
            }
        }
        if (ok) ans = max(ans, cnt(bit));
    }
    cout << ans << "\n";
}


//Name: Space Coconut Crab
//Level: 2
//Category: 数学,探索
//Note:

/**
 * zの範囲は0≦z≦E^(1/3)、yの範囲は0≦y≦E^(1/2)で表される。
 * zとyが決まればxも一意に決まるので、zとyを全探索し、x,y,z≧0を満たすような組み合わせについてx+y+zの最小値を求めればよい。
 *
 * オーダーは O(E^(5/6))。
 */
#include <iostream>
#include <algorithm>

using namespace std;

bool solve(bool first) {
    int E;
    if(!(cin >> E)) return false;
    if(!E) return false;

    int ans = E;
    for(int z = 0; z*z*z <= E; ++z) {
        for(int y = 0; y*y <= E; ++y) {
            const int x = E - z*z*z - y*y;
            if(x >= 0) {
                ans = min(ans, x+y+z);
            }
        }
    }
    cout << ans << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int solve2(int xy){
  int y=0;
  int ans=INF;
  while(y*y<=xy){
    ans=min(ans, y + xy-y*y);
    y++;
  }
  return ans;
}

void solve(int e){
  int z=0;
  int ans=INF;
  while(z*z*z<=e){
    ans = min(ans, z+solve2(e-z*z*z));
    z++;
  }
  cout << ans << endl;
}

int main(){
  while(true){
    int e;
    scanf("%d", &e);
    if(e==0) break;
    solve(e);
  }
}


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

#define loop(i, a, b) for (int i = (a); i < (b); i++)
const int MAX = 405;
char grid[MAX][MAX];
int  visited[MAX][MAX];
int h, w;

bool inside(int x, int y)
{
    return 0 <= x && x < h && 0 <= y && y < w;
}

bool check(int x, int y, int a, int b){
    if (!inside(x + a, y + b))
        return false;
    return grid[x][y] != grid[x + a][y + b] && !visited[x + a][y + b];
}

int main()
{
    cin >> h >> w;
    loop(i, 0, h) loop(j, 0, w)
    {
        cin >> grid[i][j];
    }
    long long ans = 0;
    loop(i, 0, h) loop(j, 0, w) {
        if (visited[i][j]) continue;
        queue<pair<int, int>> queue;
        queue.emplace(make_pair(i, j));
        visited[i][j] = 1;
        long long black = 0;
        long long white = 0;
        while(queue.size()){
            pair<int, int> p = queue.front();
            queue.pop();
            if (grid[p.first][p.second] == '#')
                black += 1;
            else
                white += 1;
            for (int a: {-1, 0, 1}){
                for (int b: {-1, 0, 1}){
                    if(abs(a) == abs(b)) continue;
                    if(check(p.first, p.second, a, b)){
                        queue.emplace(make_pair(p.first + a, p.second + b));
                        visited[p.first + a][p.second + b] = 1;
                    }
                }
            }
        }
        ans += white * black;
    }
    cout << ans << "\n";
    return 0;
}

// https://atcoder.jp/contests/aising2019/tasks/aising2019_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

struct UnionFind {
  struct Node {
    ll parent;
    ll size;
  };
  vector<Node> tree;

  UnionFind(ll size) : tree(size) {
    for (ll i = 0; i < size; i++) {
      tree[i].parent = i;
      tree[i].size = 1;
    }
  }

  ll find(ll x) {
    while (tree[x].parent != x) {
      ll p = tree[x].parent;
      tree[x].parent = tree[p].parent;
      x = p;
    }
    return x;
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (tree[x].size < tree[y].size) swap(x, y);
    tree[y].parent = x;
    tree[x].size += tree[y].size;
  }

  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
};

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vi dx = {0, 0, 1, -1};
  vi dy = {1, -1, 0, 0};
  UnionFind uf(h*w);
  rep(i, h) rep(j, w) rep(k, 4) {
    int ni = i+dx[k];
    int nj = j+dy[k];
    if (0 <= ni && ni < h && 0 <= nj && nj < w && s[i][j] != s[ni][nj]) {
      uf.unite(i*w + j, ni*w + nj);
    }
  }

  vector<ll> black(h*w, 0), white(h*w, 0);
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#') black[uf.find(i*w + j)]++;
    else white[uf.find(i*w + j)]++;
  }

  ll ans = 0;
  rep(i, h*w) {
    ans += black[i] * white[i];
  }
  cout << ans << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	map<string, bool> memo;
	string s;
	int n, m;
	cin >> n;
	rep(i, n){
		cin >> s;
		memo[s] = 1;
	}
	cin >> m;
	int cnt = 0;
	rep(i, m){
		cin >> s;
		if(memo[s])cnt++;
	}
	FIN(cnt);

	return 0;
}

int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

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

int main(){
    int n;
    cin >> n;
    vector<pii> s(n),l(n);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        s[i] = make_pair(b,a);
    }
    rep(i,n){
        int c,d;
        cin >> c >> d;
        l[i] = make_pair(c,d);
    }
    sort(l.begin(),l.end());
    int ans = 0;
    rep(i,n){
        sort(s.rbegin(),s.rend());
        rep(j,s.size()){
            if(s[j].second < l[i].first && s[j].first < l[i].second){
                ans++;
                s.erase(s.begin() + j);
                break;
            }
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int n;

const int INF = 1 << 29;

typedef pair<int,int> P;
vector<P> teams;
bool sortSecond(const P& p1, const P& p2)
{
	if(p1.second != p2.second) return p1.second < p2.second;
	if(p1.first != p2.first) return p1.first < p2.first;
	return false;
}

int main(void)
{
	while(cin >> n && n)
	{
		teams.resize(n);
		for (int i = 0; i < n; i++)
		{
			teams[i] = P(0, i);
		}
		for (int i = 0, leags = n * (n - 1) / 2; i < leags; i++)
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if(c == d)
			{
				teams[a - 1].first++;
				teams[b - 1].first++;
			}
			else if(c > d) teams[a - 1].first += 3;
			else teams[b - 1].first += 3;
		}
		sort(teams.begin(), teams.end(), greater<P>());
		int hikiwake = 0;
		for (int i = 0; i < n; i++)
		{
			int tmp = teams[i].first;
			teams[i].first = i + 1 - hikiwake;
			if(i + 1 < n && tmp == teams[i + 1].first)
			{
				hikiwake++;
			}
			else hikiwake = 0;
		}
		sort(teams.begin(), teams.end(), sortSecond);
		for (int i = 0; i < n; i++)
		{
			cout << teams[i].first << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main() {
  int N = 0;
  cin >> N;
  int cnt_w = 0, cnt_e = 0;
  int ans = pow(10, 6);
  vector<char> A(N);
  vector<int> S_W(N, 0);
  vector<int> S_E(N, 0);
  rep(i, N){
    cin >> A[i];
  }
  rep(i, N){
    if (A[i]=='W'){
      cnt_w++;
      S_W[i] = cnt_w;
      S_E[i] = cnt_e;
    }
    if (A[i]=='E'){
      cnt_e++;
      S_W[i] = cnt_w;
      S_E[i] = cnt_e;
    }
  }
  rep(i, N){
    if (i==0) ans = min(ans, S_E[N-1] - S_E[i]);
    if (i==N-1) ans = min(ans, S_W[N-1]);
    else ans = min(ans, (S_W[i] + (S_E[N-1] - S_E[i])));
  }
  cout << ans << endl;
}

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

int main() {
	int N;
	string S;
	int LW = 0;
	int LE = 0;
	int RW = 0;
	int RE = 0;
	cin >> N >> S;
	for (int i = 1;i<N;++i) {
		if ('E' == S[i]) {
			RE++;
		}
		else {
			RW++;
		}
	}
	int ans = 1e9;
	for (int i = 0; i < N; ++i) {
		ans = min(ans,LW+RE);
		if ('E' == S[i]) {
			LE++;
		}
		else {
			LW++;
		}
		if (i != N-1) {
			if ('E' == S[i + 1]) {
				RE--;
			}
			else {
				RW--;
			}
		}
	}
	cout <<ans << endl;
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin("../data.txt");

char sa[104], sb[104], sc[104], *s;
int ia, ib, ic, *i;
char winner;

int main() {

  cin.getline(sa, 104);
  cin.getline(sb, 104);
  cin.getline(sc, 104);

  s = sa;
  i = &ia;
  while (*i < strlen(s)) {
    *i += 1;
    if (s[(*i)-1] == 'a') {
      s = sa;
      i = &ia;
      winner = 'A';
    } else if (s[(*i)-1] == 'b') {
      s = sb;
      i = &ib;
      winner = 'B';
    } else if (s[(*i)-1] == 'c') {
      s = sc;
      i =
      winner = 'C';
    }
  }

  cout << winner;
  return 0;
}

#include <bits/stdc++.h>

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n,r;
    cin>>n>>r;

    if(n>=10)
    {
        cout<<r;
    }
    else
    {
        cout<<r+100*(10-n);
    }

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <list>
#include <algorithm>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while( 1 ) {
		int e;
		cin >> e;
		if( e == 0 ) break;
		unsigned long long int ans = e;
		for(long long int z = 0; z*z*z <= e; z++) {
			for(long long int y = 0; z*z*z + y*y <= e; y++) {
				long long int x = e - z*z*z - y*y;
				if( x + y + z <= ans ) ans = x + y + z;
			}
		}
		cout << ans << endl;
	}

	//while(1){}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<ctime>
#include<cstdlib>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=610;
bool vis[N][N];
int col[N][N];int f[N][N];
int sz[5];
vector<pair<int,int> > fob;
int n,m;

void dfs(int x,int y){
	int i,dx,dy;
	vis[x][y]=1;
	rep(i,0,(int)fob.size()-1){
		dx=x+fob[i].fi;
		dy=y+fob[i].se;
		if(0<=dx&&dx<2*n&&0<=dy&&dy<2*n&&!vis[dx][dy]){
			col[dx][dy]=col[x][y]^1;
			dfs(dx,dy);
		}
	}
}

void work(int D,int B){
	register int i,j;
	fob.clear();
	memset(vis,0,sizeof(vis));
	memset(col,0,sizeof(col));
	rep(i,0,2*n-1) rep(j,0,2*n-1) if(i*i+j*j==D){
		fob.pb(MP(i,j));
		fob.pb(MP(-i,j));
		fob.pb(MP(i,-j));
		fob.pb(MP(-i,-j));
	}
	rep(i,0,2*n-1)	rep(j,0,2*n-1) if(!vis[i][j]) dfs(i,j);
	rep(i,0,2*n-1)	rep(j,0,2*n-1) if(col[i][j]) f[i][j]^=B;
}

void print(int ty){
	int cnt=0;
	int i,j;
	rep(i,0,2*n-1)	rep(j,0,2*n-1) if(f[i][j]==ty){
		cnt++;
		printf("%d %d\n",i,j);
		//cerr<<cnt<<endl;
		if(cnt==n*n)	return;
	}
}

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	//srand(20010102);
	register int i,j;
	int D;
	scanf("%d",&n);
	scanf("%d",&D);work(D,1);
	scanf("%d",&D);work(D,2);
	rep(i,0,2*n-1)	rep(j,0,2*n-1)	sz[f[i][j]]++;
	rep(i,0,3)	if(sz[i]>=n*n)	{print(i);return 0;}
	return 0;
}

#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
const int N = 605;

inline int input() {
	int x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

inline void chkmin(int &x, int y) { x = x < y ? x : y; }
template <class T> T sqr(T x) { return x * x; }

int n, m, D1, D2;
int ansx[N * N], ansy[N * N], tot;
bool col[N][N];

void work(int D) {
	int tmp = 0;
	while(D % 4 == 0) D >>= 2, ++tmp;
	if (D % 4 == 3) return void();
	if (D % 4 == 1) {
		for (int x = 0; x <= n; ++x)
			for (int y = 0; y <= n; ++y)
				if (((x >> tmp) + (y >> tmp)) & 1) col[x][y] = true;
	}
	if (D % 4 == 2) {
		for (int x = 0; x <= n; ++x)
			for (int y = 0; y <= n; ++y)
				if ((x >> tmp) & 1) col[x][y] = true;
	}
}

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
//	freopen("log", "w", stderr);
#endif
	ios::sync_with_stdio(false);

	cin >> n >> D1 >> D2;
	m = n, n = n * 2 - 1;

	work(D1), work(D2);

	for (int x = 0; x <= n; ++x)
		for (int y = 0; y <= n; ++y) {
			if (!col[x][y]) ansx[++tot] = x, ansy[tot] = y;
			if (tot == m * m) goto Get;
		}
Get:;

	for (int i = 1; i <= tot; ++i)
		printf("%d %d\n", ansx[i], ansy[i]);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;

int main(){
  int g;
  cin >>g;
  int a,b;
  cin >>a >>b;
  if(g==1){cout << "Hello World" << endl;}else{cout << a+b << endl;}
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define drep(i,cc,n) for(int i=cc;i>n;--i)
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 long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    if(n == 1) cout<<"Hello World"<<endl;
    else{
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
/*Graph t;
void dfs(int v, int pv=-1){
    for(int vn: t[v]){
        if (vn == pv) continue;
        dfs(vn, v);
    }
}*/
int main() {
  ll n,k;
  cin >> n >> k;
  ll ma;
  cin >> ma;
  ll g=ma;
  rep(i,n-1){
    ll o;
    cin >> o;
    ma=max(o,ma);
    g=gcd(g,o);
  }
  if(n==1){
    if(ma==k)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
  }
  else if(k%g==0&&ma>=k) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

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

int gcd(int a, int b)
{
	if(a%b==0)
	{
		return b;
	}
	else
	{
		return gcd(b, a%b);
	}
}

int main()
{
	int n, k;
	bool ans = 0, ma = 0;
	cin >> n >> k;
	int A[100001];
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i];
		if(A[i] == k)
		{
			ans = 1;
		}
		if(A[i] > k)
		{
			ma = 1;
		}
	}
	sort(A, A+n);
	bool ok = 0;
	int g = gcd(A[1],A[0]);
	for (int i = 1; i < n - 1; ++i)
	{
		g = gcd(g, A[i]);

	}
	ok = (k % g == 0);
	if(ma && ok)
	{
		ans = 1;
	}
	cout << (ans?"POSSIBLE":"IMPOSSIBLE") << endl;

	return 0;
}


#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)

int n,x[101],y[101];
const double PI=acos(-1);
double k[101];

int main(){
	scanf("%d",&n);
	if(n==2){puts("0.5\n0.5");return 0;}
	F(i,1,n) scanf("%d%d",x+i,y+i);
	F(i,1,n){
		int cnt=0;
		F(j,1,n) if(j!=i){
			k[++cnt]=atan2(x[j]-x[i],y[j]-y[i]);
		}
		std::sort(k+1,k+cnt+1);
		double t;
		t=k[1]-k[cnt]+PI+PI;
		if(t>=PI) {printf("%.15lf\n",(t-PI)/(PI+PI)); continue;}
		bool ok=0;
		F(j,1,cnt-1){
			t=k[j+1]-k[j];
			if(t>=PI) {printf("%.15lf\n",(t-PI)/(PI+PI)); ok=1; break;}
		} if(!ok) printf("%.15lf\n",0.);
	}
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

double cross(pair<double, double> a, pair<double, double> b, pair<double, double> c) {
	pair<double, double> u = { a.first - c.first, a.second - c.second };
	pair<double, double> v = { a.first - b.first ,a.second - b.second };
	return u.first*v.second - u.second*v.first;
}

double abs(pair<double, double> a) {
	return sqrt(a.first*a.first + a.second*a.second);
}

int main() {
	int n; cin >> n;
	if (n == 2) {
		cout << 0.5 << endl;
		cout << 0.5 << endl;
		return 0;
	}
	vector<pair<pair<double, double>, int>> pi(n);
	for (int i = 0; i < n; i++) cin >> pi[i].first.first >> pi[i].first.second, pi[i].second = i;
	sort(pi.begin(), pi.end());
	double lm = 1e9; int idx = 0;
	vector<pair<pair<double, double>, int>> chi;
	bool used[103] = {};
	chi.push_back(pi[0]);
	used[idx] = true;
	for (int iter = 1; iter < n; iter++) {
		const auto &pr = chi.back().first;
		for (int i = 0; i < n; i++) {
			if (used[i]) continue;
			const auto &p = pi[i].first;
			int sgn = 0;
			bool flag = true;
			for (int j = 0; j < n; j++) {
				if (j == i) continue;
				if (p.first == pr.first && p.second == pr.second) continue;
				int s = cross(pr, p, pi[j].first) > 0 ? 1 : -1;
				flag &= sgn == 0 || s == sgn;
				sgn = s;
			}
			if (flag) {
				if (chi.size() >= 2) {
					const auto &pb = chi[chi.size() - 2].first;
					double s = (pr.first - p.first)*(pb.second - p.second);
					s -= (pb.first - p.first)*(pr.second - p.second);
					s /= 2.;
					s = abs(s);
					if (s < 1e-8) {
						chi.pop_back();
					}
				}
				chi.push_back(pi[i]);
				used[i] = true;
				break;
			}
		}
	}
	if (chi.size() >= 3) {
		const auto &pr = chi.back().first;
		const auto &pb = chi[chi.size() - 2].first;
		const auto &p = chi[0].first;
		double s = (pr.first - p.first)*(pb.second - p.second);
		s -= (pb.first - p.first)*(pr.second - p.second);
		s /= 2.;
		s = abs(s);
		if (s < 1e-8) {
			chi.pop_back();
		}
	}
	vector<double> ans(n);
	int m = chi.size();
	if (m >= 3) {
		for (int i = 0; i < m; i++) {
			const auto &pr = chi[(i - 1 + m) % m].first;
			const auto &pn = chi[(i + 1) % m].first;
			const auto &p = chi[i].first;
			pair<double, double> u = { p.first - pr.first, p.second - pr.second };
			pair<double, double> v = { p.first - pn.first, p.second - pn.second };
			double ang = acos((u.first*v.first + u.second*v.second) / abs(u) / abs(v));
			double r = acos(-1) - ang;
			ans[chi[i].second] = r / (2 * acos(-1));
		}
	}
	else {
		for (int i = 0; i < m; i++) {
			ans[chi[i].second] = 0.5;
		}
	}
	for (int i = 0; i < n; i++) printf("%.15f\n", ans[i]);
	int b = 2 * 0.;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

map<ll,int> prf(ll n){
  map<ll,int> ret;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
     ret[i]++;
      n/=i;
    }
  }
  if(n!=1){
    ret[n]=1;
  }
  return ret;
}

int main(){cout<<fixed<<setprecision(10);
		   int n,h,w;
           cin>>n>>h>>w;
           n++;
           cout<<(n-w)*(n-h)<<endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n, h, w; cin >> n >> h >> w;

    cout << (n-h+1) * (n-w+1) << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=2e5+50;
vec l(N),r(N);
vec a(N);

ll cal(ll x) {
  if(x<3) {
    return 0;
  }
  return max({l[x-1],r[x-1],cal(x-2)+a[x]});
}

int main() {
  ll n;
  cin >> n;
  for(ll i=1;i<=n;i++) cin >> a[i];
  for(ll i=2;i<=n;i+=2) {
    l[i]=l[i-2]+a[i-1];
    r[i]=max(r[i-2],l[i-2])+a[i];
  }
  if(n%2) {
    cout << cal(n) << endl;
  }
  else {
    cout << max(l[n],r[n]) << endl;
  }
}

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

int n;
ll a[200005],dp[200005][3],ans=-0x3f3f3f3f3f3f3f3fll;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",a+i);
    memset(dp,0xc0,sizeof(dp));
    dp[0][1]=0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<3;j++)
        {
            for(int k=i==1?1:2;k<=4;k++) if(i-k>=0)
                for(int g=0;g<3;g++) if(i/2+j-(i-k)/2-g==1)
                    dp[i][j]=max(dp[i][j],dp[i-k][g]+a[i]);
            if(i/2+j-1==n/2) ans=max(ans,dp[i][j]);
        }
    printf("%lld",ans);
    return 0;
}


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

signed main() {
  int n;
  cin >> n;
  int a[100] = {0};
  double sum;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  int minIndex = 0;
  double avr = sum / n;
  double minDist = abs(avr - a[0]);
  for(int i = 1; i < n; i++){
    if(minDist > abs(avr - a[i])){
      minIndex = i;
      minDist = abs(avr - a[i]);
    }
  }
  cout << minIndex << endl;
}

#include <bits/stdc++.h>

using namespace std;

const int md = 998244353;

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }

  int maxd = *max_element(d.begin(), d.end());
  vector<int> cnt(maxd + 1);
  for (int i = 0; i < n; i++) {
    cnt[d[i]]++;
  }

  if (d[0] != 0 || cnt[0] != 1) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 1; i <= maxd; i++) {
    if (cnt[i] == 0) {
      cout << 0 << '\n';
      return 0;
    }
  }

  int ans = 1;
  for (int i = 1; i <= maxd; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      ans = mul(ans, cnt[i - 1]);
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<ll> a(n); rep(i, n) cin >> a[i];
    vector<ll> acum(n+1, 0);
    rep(i, n) {
        acum[i+1] = acum[i] + a[i];
    }

    int l = 1;
    int r = 3;
    ll ans = LINF;
    for (int i = 2; i < n-1; i++) {
        if (r <= i) r = i+1;
        while (l+1 < i && abs(acum[l+1] - (acum[i] - acum[l+1])) <= abs(acum[l] - (acum[i] - acum[l]))) {
            l++;
        }
        while (r+1 < n && abs(acum[r+1] - acum[i] - (acum[n] - acum[r+1])) <= abs(acum[r] - acum[i] - (acum[n] - acum[r]))) {
            r++;
        }
        ll mn = min({acum[l], (acum[i] - acum[l]), acum[r] - acum[i], acum[n] - acum[r]});
        ll mx = max({acum[l], (acum[i] - acum[l]), acum[r] - acum[i], acum[n] - acum[r]});
        ans = min(ans, mx-mn);
    }

    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<string.h>
using namespace std;

int D[6];
void spin(char c)
{
  if(c=='E'){
    swap(D[0],D[3]);swap(D[3],D[5]);swap(D[5],D[2]);
  }
  else if(c=='W'){
    swap(D[0],D[2]);swap(D[2],D[5]);swap(D[5],D[3]);
  }
  else if(c=='S'){
    swap(D[0],D[1]);swap(D[0],D[4]);swap(D[4],D[5]);
  }
  else if(c=='N'){
    swap(D[0],D[1]);swap(D[1],D[5]);swap(D[5],D[4]);
  }
}
int main()
{
  char M[101];

  for(int i=0;i<6;i++)cin>>D[i];
  cin>>M;

  for(int i=0;i<strlen(M);i++)spin(M[i]);

  cout<<D[0]<<endl;

  return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && b != c) || (b == c && c != a) || (c == a && a != b)) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool flag = false;
    for(int i=0;i<s.size();i++){
        if(s[i+1]=='C'&&s[i]=='A'){
            flag = true;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

ll a[100009];

int main() {
	set<ll> A;
	vector<ll> B;
	ll N;
	cin >> N;
	rep(i, N) {
		ll a;
		cin >> a;
		if (A.count(a)) {
			B.push_back(a);
			A.erase(a);
		}
		else {
			A.insert(a);
		}

	}
	if (B.size() < 2) {
		cout << 0 << endl;
		return 0;
	}

	sort(B.begin(), B.end());
	reverse(B.begin(), B.end());
	cout << B.at(0) * B.at(1) << endl;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout);
  #endif
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL) ;
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
int sum(int n)
{
    int m,s=0;
    while(n)
    {
        m=n%10;
        s+=m;
        n/=10;
    }
    return s;
}
signed main()
{
    fastio();
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n%(sum(n))==0)
        cout<<"Yes";
        else
        cout<<"No";
    }
}
// 🍪 🍪 🍪


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const ll inf=1e18;
struct edge{
	int to,cost;
};
class DIJ{
	public:
	vector<vector<edge> >G;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
//		G[b].pb(ee);
	}
	void dij(int s){
		d=vi(n,inf);
		d[s]=0;
		priority_queue<pii>q;
		q.push(pii(0,s));
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
};
int main(){
	int n,m,s;
	cin>>n>>m>>s;
	DIJ dij(n);
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		dij.add_edge(a,b,c);
	}
	dij.dij(s);
	rep(i,n)if(dij.d[i]!=inf)cout<<dij.d[i]<<endl;
		else cout<<"INF"<<endl;
}

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define eb emplace_back
typedef long long ll;
#define int ll
auto const inf = numeric_limits<int>::max()/4;

using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

pair<vector<Weight>, bool> spfa(const Graph &g, int s){
    const Weight inf = numeric_limits<Weight>::max()/4;
    const int n = g.size(); priority_queue<int> q;
    vector<Weight> dist(n, inf); vector<int> inQ(n);
    vector<int> count(n);
    dist[s] = 0; q.emplace(s); inQ[s] = true; ++count[s];
    bool negCycle = false;
    for(int i = 0; q.size(); i++){
        int v = q.top(); q.pop(); inQ[v] = false;
        for(auto &e : g[v]){
            if(dist[v] != inf && dist[e.dst] > dist[v] + e.weight){
                dist[e.dst] = dist[v] + e.weight;
                if(!inQ[e.dst]){
                    q.emplace(e.dst); inQ[e.dst] = true; ++count[e.dst];
                    if(count[e.dst] >= n){ negCycle = true; goto END; }
                }
            }
        }
    }
 END:;
    return make_pair(dist, !negCycle);
}

signed main(){
    int V,E,r;
    while(cin >> V >> E >> r){
        Graph g(V);
        rep(i,E){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
        }
        bool ok;
        vector<Weight> dist;
        tie(dist, ok) = spfa(g,r);
        if(ok){
            for(int i = 0; i < (int)dist.size(); i++){
                if(dist[i] == inf) cout << "INF";
                else cout << dist[i];
                cout << endl;
            }
        } else {
            cout << "NEGATIVE CYCLE" << endl;
        }
    }
}


#include<bits/stdc++.h>
#define int long  long

using namespace std ;

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

    int n ;
    cin >> n ;
    string s ;
    cin >> s ;
    set<int> b ;
   	for(int i = 0 ; i< n  ; ++i)
  	{
   		if(s[i] == 'B')
   			b.insert(i);
   	}
	int cnt = 0 ;
	int v = b.size() ;
	for(int i = 0; i < n ; ++i)
	{
		if(s[i] == 'R')
		{
			for(int j = 0; j < n ; ++j)
			{
				if(s[j] == 'G')
				{
					int d = abs(i-j) ;
					int temp = 0 ;
					if(b.find(i - d) != b.end())
						temp++ ;
					if(b.find(i + d) !=  b.end())
						temp++ ;
					if(b.find(j - d) != b.end())
						temp++ ;
					if(b.find(j + d) !=  b.end())
						temp++ ;
					if(d%2 == 0 && b.find(min(i,j) + d/2) != b.end())
						temp++ ;
					cnt += v - temp ;

				}
			}
		}
	}
   	cout << cnt ;

}

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

int main(void){
    ll n, ans = 0;
    string s;
    vector<int> r, g;
    int b[4010], rn = 0, bn = 0, gn = 0;
    for(int i = 0; i < 4010; i++) b[i] = 0;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') {r.push_back(i); rn++;}
        else if(s[i] == 'G') {g.push_back(i); gn++;}
        else {b[i]++; bn++;}
    }
    for(int i = 0; i < rn; i++){
        for(int j = 0; j < gn; j++){
            int minn = min(r[i], g[j]);
            int maxn = max(r[i], g[j]);
            int l = maxn - minn;
            int l2 = minn + maxn;
            int add = bn;
            if(minn-l >= 0 && b[minn-l] > 0){
                add--;
            }
            if(l%2==0 && b[l2/2] > 0){
                add--;
            }
            if(maxn+l < n && b[maxn+l] > 0){
                add--;
            }
            ans += add;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

ll e[100000000];
int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	map<ll,bool>mp;
	string s;
	cin>>n>>k;
	for(ll i=1;i<=k;i++){
		cin>>x>>s;
		if(s=="AC"){
			if(!mp[x])sum++,cnt+=e[x],mp[x]=1;
		}

		else e[x]++;

	}

	cout<<sum<<" "<<cnt;

}

#include<iostream>
#include<vector>
int main() {
	int vec=0;
	int n;
	int a=0;
	int b=0;
	int game_a, game_b;
	std::vector<int>veca, vecb;
	while (1) {
		std::cin >> n;
		if (n == 0)break;
		else {
			for (int i = 0; i < n; ++i) {
				std::cin >> game_a>>game_b;
				if (game_a == game_b) { a += game_a; b += game_b; }
				else if (game_a > game_b)a += game_a + game_b;
				else b += game_a + game_b;
			}
			veca.push_back(a); vecb.push_back(b); a = 0; b = 0;
		}
	}
	for (int i = 0; i < veca.size(); ++i) {
		std::cout << veca[i] <<" "<<vecb[i]<< std::endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int64_t>> a(n, vector<int64_t>(m));
    for (auto i : irange(0L, n)) {
        for (auto j : irange(0L, m)) {
            cin >> a[i][m - j - 1];
            --a[i][m - j - 1];
        }
    }

    int64_t ans = n;
    vector<bool> available(m, true);
    for (auto _ : irange(0L, m)) {
        vector<int64_t> c(m);

        for (const auto& b :
             a | transformed([](const auto& aa) { return aa.back(); })) {
            ++c[b];
        }

        auto b = max_element(c.begin(), c.end()) - c.begin();
        available[b] = false;
        ans = min(ans, c[b]);

        for (auto&& aa : a) {
            while (!aa.empty() && !available[aa.back()]) {
                aa.pop_back();
            }
        }
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
const int N=305;
#define fi first
#define se second
typedef pair<int,int>P;
priority_queue<P>que;
int n,m,b[N],vi[N],cnt[N],a[N][N];
bool check(int mid){
	while(!que.empty())	que.pop();
	for(int i=1;i<=m;i++)	b[i]=0;
	for(int i=1;i<=n;i++)	++b[a[i][cnt[i]=1]];
	for(int i=1;i<=m;i++)	vi[i]=0,que.push(P(b[i],i));
	while(!que.empty()){
		P x=que.top();	que.pop();
		if(vi[x.se])	continue;
		if(x.fi<=mid)	return true;

		vi[x.se]=1;
		for(int i=1;i<=n;i++){
			if(a[i][cnt[i]]!=x.se)	continue;
			while(vi[a[i][cnt[i]]]&&cnt[i]<=m)	++cnt[i];
			if(cnt[i]>m)	return false;
			que.push(P(++b[a[i][cnt[i]]],a[i][cnt[i]]));
		}
	}
	return false;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid))	r=mid;
		else	l=++mid;
	}
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Min(int a,int b){return a<b?a:b;}
const int N=2e5+1,M=(N<<2),oo=(~0u>>2);
int n,m,mn[M],z[M],t[M],g[M],ql,qr,qx;
static inline void pu(int x){z[x]=z[x*2];t[x]=t[x*2+1];mn[x]=Min(mn[x*2],mn[x*2+1]);}
static inline void build(int x,int l,int r){if(l==r){z[x]=l;t[x]=l;return;}int m=(l+r)/2;build(x*2,l,m);build(x*2+1,m+1,r);pu(x);}
static inline void pt(int x,int w,int r){g[x]=w;t[x]=w;z[x]=w;if(w<=m){mn[x]=w-r;}else{mn[x]=oo;}}
static inline void upd(int x,int l,int r)
{
  if(z[x]>qr||t[x]<ql){return;}if(z[x]>=ql&&t[x]<=qr){pt(x,qr+1,r);return;}
  int m=(l+r)/2;if(g[x]){pt(x*2,g[x],m);pt(x*2+1,g[x],r);g[x]=0;}upd(x*2,l,m);upd(x*2+1,m+1,r);pu(x);
}
int main()
{
  n=IN(),m=IN();build(1,1,m);
  for(int i=0;i<n;i++){ql=IN(),qr=IN();upd(1,1,m);if(mn[1]>m){puts(""),puts("-1");}else{OUT(mn[1]+i+1);}}
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;

int main(){
 int N;
     cin>>N;
     vector<pair<int,int>> A,B;
     rep(i,N){
         int x,y;cin>>x>>y;
         A.push_back({y,x});
     }
     rep(i,N){
         int x,y;cin>>x>>y;
         B.push_back({x,y});
     }
     sort(all(A), greater<pair<int, int>>());
     sort(all(B));
     vector<bool> f(N, false);
     //cの小さい順
     rep(i,N){
         int c = B[i].first;
         int d = B[i].second;
         //bの大きい順
         rep(j,N){
             int a = A[j].second;
             int b = A[j].first;
             if(f[j])continue;
             if(a < c && b < d){
                 f[j] = true;
                 break;
             }
         }
     }
     int cnt =0;
     rep(i,N){
         if(f[i])cnt++;
     }
     cout<<cnt<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int fa[101000],n,k,ans,f[101000];
vector<int> e[101000];
void dfs(int x){
	int mx=0;
	for(int v:e[x]) dfs(v),mx=max(mx,f[v]+1);
	if(x==1||fa[x]==1) return;
	if(mx==k-1) ans++,f[x]=-1;
	else f[x]=mx;
}
int main(){
	read(n);read(k);
	for(int i=1;i<=n;i++) read(fa[i]);
	if(fa[1]!=1) fa[1]=1,ans=1;
	for(int i=2;i<=n;i++) e[fa[i]].push_back(i);
	dfs(1);
	cout<<ans<<'\n';
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

int main(int argc, char **argv)
{
        int V, E, r;
        cin >> V >> E >> r;
        vector<vector< pair<int, int>>> A(V);
        for (int i = 0; i < E; i++) {
                int s, t, d;
                cin >> s >> t >> d;
                A[s].push_back({t, d});
        }
        vector<int> d(V, INT_MAX);
        d[r] = 0;
        bool done = false;
        while (!done) {
                done = true;
                for (int i = 0; i < V; i++) {
                        if (d[i] == INT_MAX)
                                continue;
                        for (auto n: A[i]) {
                                int m = d[i] + n.second;
                                if (m < d[n.first]) {
                                        d[n.first] = m;
                                        done = false;
                                }
                        }
                }
        }
        for (int i = 0; i < V; i++) {
                if (d[i] == INT_MAX)
                        cout << "INF";
                else
                        cout << d[i];
                cout << endl;
        }
        return 0;
}


#include <stdio.h>
#include <string.h>

int main(){
	int y;
	char s[5];
	scanf("%d/%s", &y, s);
	printf("%d/%s", y+=1, s);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	char s[4]={};
	cin>>s;
	if(s[0]=='S'){
		if(s[1]=='U'){
			cout<<7<<endl;
		}else{
			cout<<1<<endl;
		}
	}else if(s[0]=='M'){
		cout<<6<<endl;
	}else if(s[0]=='W'){
		cout<<4<<endl;
	}else if(s[0]=='F'){
		cout<<2<<endl;
	}else if(s[0]=='T'){
		if(s[1]=='U'){
			cout<<5<<endl;
		}else{
			cout<<3<<endl;
		}
	}
}


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

char arr[405][405];
bool vis[405][405];
int h, w;
int cb;
int cw;

bool f(int i, int j, int l, int m){
	if(l<0 || l>=h || m<0 || m>=w){
		return 0;
	}
	if(vis[l][m]==1){
		return 0;
	}
	if(arr[i][j]==arr[l][m]){
		return 0;
	}
	return 1;
}

void dfs(int i, int j){
	vis[i][j]=1;
	if(arr[i][j]=='#'){
		cb++;
	}
	else{
		cw++;
	}
	if(f(i, j, i+1, j)){
		dfs(i+1, j);
	}
	if(f(i, j, i, j+1)){
		dfs(i, j+1);
	}
	if(f(i, j, i-1, j)){
		dfs(i-1, j);
	}
	if(f(i, j, i, j-1)){
		dfs(i, j-1);
	}
}

main() {
	cin>>h>>w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>arr[i][j];
		}
	}
	int ans=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(vis[i][j]==0){
				dfs(i, j);
				ans+=(cb*cw);
				cb=0;
				cw=0;
			}
		}
	}
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main()
{
  int H,W;
  cin >> H >> W;
  vector<string> A(H);
  REP(i, H) cin >> A[i];

  vector<vector<int>> dist(H,vector<int> (W,-1));
  ll ans = 0;
  REP(i,H){
    REP(j,W){
      if(A.at(i).at(j)=='#'&&dist[i][j]==-1){
        ll cntblack = 1;
        ll cntwhite = 0;
        queue<P> que;
        que.push(make_pair(i,j));
        dist[i][j]=0;
        while(!que.empty()){
          int vy = que.front().first;
          int vx = que.front().second;
          que.pop();
          REP(k,4){
            int nvy = vy+dy[k];
            int nvx = vx+dx[k];
            if(nvy<0||nvy>H-1||nvx<0||nvx>W-1||dist[nvy][nvx]!=-1||(A[vy][vx]=='#'&&A[nvy][nvx]!='.')||(A[vy][vx]=='.'&&A[nvy][nvx]!='#')) continue;
            dist[nvy][nvx]=0;
            que.push(make_pair(nvy,nvx));
            if(A[nvy][nvx]=='#'){
              cntblack++;
            }else{
              cntwhite++;
            }
          }
        }
        ans+=cntblack*cntwhite;
      }
    }
  }

  cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>
#define INF 1000000007

using namespace std;
typedef long long int ll;

int main(){
    vector<int> dp(31,0);
    dp[0]=1;
    dp[1]=1;
    dp[2]=2;
    for (int i=3; i<31; i++) {
        dp[i] = dp[i-1]+dp[i-2]+dp[i-3];
    }
    for (;;) {
        int n;
        cin >> n;
        if(n==0) break;
        int ans = dp[n]/(10*365)+1;
        cout << ans <<endl;
    }
}

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

pair<int, int> mod(int a, int b){
    int d = a/b;
    int r = a%b;
    if(r<0){
        d++;
        r = a-(d*b);
    }

    return make_pair(d, r);
}
int main(){
    int32_t n;
    int bits[32] = {0};
    scanf("%d", &n);
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    int i=32;
    while(n != 0){
        pair<int, int> div = mod(n, -2);
        n = div.first;
        bits[--i] = div.second;
    }

    int prnt = false;
    for(int i=0; i<32; i++){
        if(!prnt && bits[i]) prnt = true;
        if(prnt) cout << bits[i];
    }
    cout << endl;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    long long sum=3;
    scanf("%d",&n);
    if(n==1) sum=1;
    else if(n==2) sum=2;
    else
        {
           while(n>2)
           {
               if(n%3!=0&&n%5!=0)
                 sum+=n;
               n--;
           }
        }
        printf("%lld",sum);
    return 0;
}

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

int main() {
    ll N;
    cin >> N;
    string A,B,C;
    cin >> A >>B >>C;
    ll ans =0;
    for(int i=0;i<N;i++){
        set<char> s;
        s.insert(A[i]);
        s.insert(B[i]);
        s.insert(C[i]);
        ans += (s.size()-1);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int a[5], k, ans = 0;
    for(int i = 0; i < 5; i++)
        cin >> a[i];
    cin >> k;
    for(int i = 0; i < 5; i++)
        for(int j = 0; j < 5; j++)
            if(a[i] < a[j] && a[j] - a[i] > k)
                ans++;
    if(ans)cout << ":(";
    else cout << "Yay!";
    return 0;
}

#include <string>
#include <vector>
using namespace std;

vector<int> border(vector<int> S)
{
    int n = (int)S.size();
    vector<int> B(n+1);

    B[0] = -1;
    int j = -1;
    for (int i=1; i<=n; i++)
    {
        while (j>=0 && S[i-1]!=S[j])
            j = B[j];
        j++;
        B[i] = j;
    }

    return B;
}

//  B = border(P)
vector<int> search(vector<int> T, vector<int> P, vector<int> B)
{
    int n = (int)T.size();
    int m = (int)P.size();

    vector<int> A;
    int j = 0;
    for (int i=0; i+m<=n;)
    {
        if (j<m && T[i+j]==P[j])
        {
            j++;
            if (j==m)
                A.push_back(i);
        }
        else
        {
            i += j-B[j];
            if (j>0)
                j = B[j];
        }
    }
    return A;
}

#include <iostream>

int main()
{
    int N;
    cin>>N;
    vector<int> a(N), b(N);
    for (int &t: a)
        cin>>t;
    for (int &t: b)
        cin>>t;

    vector<int> ax(N), bx(N);
    for (int i=0; i<N; i++)
    {
        ax[i] = a[i]^a[(i+1)%N];
        bx[i] = b[i]^b[(i+1)%N];
    }
    for (int i=0; i<N-1; i++)
        ax.push_back(ax[i]);

    vector<int> K = search(ax, bx, border(bx));
    for (int k: K)
        cout<<k<<" "<<(a[k]^b[0])<<endl;
}


#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;

struct Debug{
	int cnt = 0;
	bool on = false;
	char debug[10] = "debug";
	template<class T>
	Debug & operator<<(const T & v) {
		if(on && cnt++ == 0) cerr << "debug: ";
		if(on) cerr << v << ' ';
		return *this;
	}
	Debug & operator<<(ostream&(*pManip)(ostream&)) {
		if(on) cerr << (*pManip);
		cnt = 0;
		return *this;
	}
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}

typedef unsigned long long ull;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

struct mint{
    long long x;
    long long mod = 998244353;

    mint(): x(0) {}
    mint(long long _x): x(_x) {}
    operator long long() { return x; }

    mint operator+(const mint & b) const { return (x + b.x) % mod; }
    mint operator-(const mint & b) const { return (x - b.x + mod) % mod; }
    mint operator*(const mint & b) const { return (x * b.x) % mod; }

    template<class T>
    mint operator^(T b) const {
        if(!b) return 1;
        mint tmp = (*this) ^ (b / 2);
        return b % 2 ? tmp * tmp * (*this) : tmp * tmp;
    }

    mint inv() const {
    	static unordered_map<long long, long long> inv_dp;
        if(inv_dp.count(x))
            return inv_dp[x];
        else if(inv_dp.size() < 100000)
            return inv_dp[x] = (*this) ^ (mod - 2);
        else return (*this) ^ (mod - 2);
    }

    mint operator/(const mint & b) const { return (*this) * b.inv(); }
};
// unordered_map<long long, long long> mint::inv_dp;

const int MAXN = 300 + 20, MAXM = 90000 + 20;
int n;
int a[MAXN];
mint dp[MAXM];
mint dp2[MAXM];

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    cin >> n;
    int tot = 0;
    for(int i = 1; i <= n; i++){
    	cin >> a[i];
    	tot += a[i];
    }
    dp[0] = mint(2) ^ n;
    dp2[0] = mint(1);
    for(int i = 1; i <= n; i++) {
    	for(int j = tot; j >= 0; j--) {
    		if(j - a[i] >= 0) {
    			dp[j] = dp[j] + dp[j - a[i]] / mint(2);
    			dp2[j] = dp2[j] + dp2[j - a[i]];
    		}
    	}
    	debug << i << endl;
    	for(int i = 0; i < 10; i++)
    		debug << dp[i].x;
    	debug << endl;
    }

    mint res = 0;
    for(int i = (tot + 1) / 2; i <= tot; i++) {
    	res = res + dp[i];
    	if(i * 2 == tot)
    		res = res - dp2[i];
    	debug << i << res.x << endl;
    }
    debug << (mint(3) ^ n).x << res.x << endl;
    res = (mint(3) ^ n) - res * mint(3);
    debug << res.x << (mint(3) ^ n).x << endl;

    cout << res.x << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using vi = vector<int>;
using pii = pair<int,int>;
#define ST first
#define ND second
#define PB push_back

const int nax = 301;
const int mod = 998244353;
int n,a[nax];
int dp[nax][nax*nax];
int ans,sum,sub;

int main() {
	scanf("%d",&n);
	for(int i=1; i<=n;i++) {
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	ans=1;
	for(int i=1; i<n;i++) {
		ans=((LL)ans*3)%mod;
	}
	dp[0][0] = 1;
	for(int i=1; i<=n;i++) {
		for(int s=0; s<=sum; s++) {
			dp[i][s] = (2*dp[i-1][s])%mod;
			if(s-a[i]>=0) {
				dp[i][s]= (dp[i][s]+dp[i-1][s-a[i]])%mod;
			}
		}
	}
	for(int i=1; i<=sum;i++) {
		if(i>=(sum+1)/2) {
			sub=(sub+dp[n][i])%mod;
		}
	}
	dp[0][0] = 1;
	for(int i=1; i<=n;i++) {
		for(int s=0; s<=sum;s++) {
			dp[i][s] = dp[i-1][s];
			if(s-a[i]>=0) {
				dp[i][s]= (dp[i][s]+dp[i-1][s-a[i]])%mod;
			}
		}
	}
	if(sum%2==0) {
		sub=(sub-dp[n][sum/2]+mod)%mod;
	}
	int res = (((ans-sub)%mod)+mod)%mod;
	res = ((LL)res*3)%mod;
	printf("%d",res);
}


/*
 * Project: AtCoder Beginners Contest 146 A - Can't Wait for Holiday /
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/07
 * Copyright (c) 2020 toms74209200
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
using namespace std;

char s[3];

void solve() {

    const char *week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    for (int i=0;i<7;i++) {
        if (strcmp(s, week[i]) == 0) {
            printf("%d\n", 7-i);
            return;
        }
    }

}

int main() {

    scanf("%s", s);

    solve();

}

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

int main(){
	string s;
	cin >> s;
	if(s == "SUN") cout << 7 << endl;
	if(s == "MON") cout << 6 << endl;
	if(s == "TUE") cout << 5 << endl;
	if(s == "WED") cout << 4 << endl;
	if(s == "THU") cout << 3 << endl;
	if(s == "FRI") cout << 2 << endl;
	if(s == "SAT") cout << 1 << endl;
}


#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////
vector<LL> kai(200001);
vector<LL> kai_inv(200001);

LL powMod(LL num, LL n, LL mod = (LL)MOD) {//(num**n)%mod
	num %= mod;//
	if (n == 0) {
		return (LL)1;
	}
	LL mul = num;
	LL ans = (LL)1;
	while (n) {
		if (n & 1) {
			ans = (ans * mul) % mod;
		}
		mul = (mul * mul) % mod;
		n >>= 1;
	}
	return ans;
}
LL mod_inverse(LL num, LL mod = MOD) {
	return powMod(num, MOD - 2, MOD);
}

LL nCk(LL N, LL k, LL mod = MOD) {
	LL ans = 1;
	if (k == 0 || k == N) {
		return 1;
	}
	ans = (kai[N] * kai_inv[N - k]) % mod;
	ans = (ans * kai_inv[k]) % mod;
	return ans;
}

LL cal(LL H, LL W,LL K) {
	LL ans = 0;
	LL base = nCk(H * W - 2, K - 2);
	base = (base * H) % MOD;
	base = (base * H) % MOD;
	for (LL i = 0; i < W; ++i) {
		ans += i * (W - i);
		ans %= MOD;
	}
	/*
	for (int w1 = 0; w1 < W; ++w1) {
		for (int w2 = w1; w2 < W; ++w2) {
			ans += abs(w1 - w2);
			ans %= MOD;
		}
	}
	*/
	ans = (ans * base) % MOD;
	return ans;
}
void solve() {
	LL N, M, K;
	cin >> N >> M >> K;

	kai[0] = 1; //kai_inv[0] = mod_inverse(1);
	kai[1] = 1; kai_inv[1] = mod_inverse(1);

	for (int i = 2; i <= 200000; ++i) {
		kai[i] = (kai[i - 1] * i) % MOD;
		kai_inv[i] = mod_inverse(kai[i]);
	}
	LL ans = (cal(N, M, K) + cal(M, N, K)) % MOD;
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別

	solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int fact(int n)
{
    if(n==0)
        return 1;
        int ans=1;
    for(int i=1;i<=n;i++)
     ans*=i;
     return ans;
}
int find(int n,int m)
{
  int r=fact(n)/(fact(n-m));
  return r;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int ans=1;
int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
    int mod=pow(10,9)+7;
    map<int,int> mp;
    mp[-1]=1;
for(int i=0;i<n;i++)
{
    int x=arr[i];
    int val=mp[x-1];
    ans*=val;
    ans%=mod;
    mp[x]+=1;
    if(x-1!=-1&&mp[x-1])
    mp[x-1]-=1;
}
int r=0;
for(int i=0;i<n;i++)
{
    if(arr[i]==0)
        r++;
}
if(r<=3)
ans*=find(3,r);
else
    ans=0;
ans%=mod;
cout<<ans<<endl;

    return 0;
}


//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l;
    string s;
    cin>>s;
    if(s.size()%2)
                return no,0;
    bool ok=1,ishi=1;
    for(i=0; i<s.length()-1; i+=2)
    {
        if(s[i]=='h'&&s[i+1]=='i');
        else return no,0;
    }
    if(ishi)
            return yes,0;

    return 0;
}

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        string h;
        forr(i,0,s.size()/2) {h=h+"hi";}
        cout << (s == h ? "Yes" : "No") << endl;
    }
    return 0;
}


 #include <bits/stdc++.h>
 #define f first
 #define s second
 #define endl '\n'
 #define LL long long
 #define pb push_back
 #define sz(a) (int)a.size()
 #define all(a) a.begin(),a.end()
 #define rall(a) a.rbegin(),a.rend()
 #define debug(x) cerr << #x << " is " << x << endl;
 using namespace std;
 int const MAXN = 2e6 + 9;
int n, k;
 int main(){
    ios_base::sync_with_stdio (0),cin.tie(0);
    cin >> n >> k;
    LL ans = 0;
    for (int i = 1; i <= n; i++){
         if (i  + k  - 1<= n) ans++;
    }
     cout << ans;
 }

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

void solve()
{
    int n, k;
    cin >> n >> k;
    int ans = n - k + 1;
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int solve() {
    int n; cin >> n;
    vector<ll> da(n);
    rip(i,n,0) cin >> da[i];
    string s; cin >> s;
    vector<ll> bases(0);
    for(int i = n-1;i>-1;--i) {
        ll now = da[i];
        rip(j, bases.size(), 0) chmin(now, now^bases[j]);
        if(s[i] == '0' && now > 0) bases.push_back(now);
        else if(s[i] == '1' && now > 0) return true;
    }
    return false;
}

int main() {
    int t; cin >> t;
    vector<bool> ans(t);
    rip(i,t,0) ans[i] = solve();
    rip(i,t,0) cout << ans[i] << '\n';
}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=205;
int T;
int n;
long long a[N];
char s[N];
struct Basis
{
	static const int M=60;
	long long d[N];
	void clear()
	{
		memset(d,0,sizeof(d));
		return;
	}
	void insert(long long t)
	{
		for(int i=M;i>=0;i--)
			if(t&(1LL<<i))
			{
				if(d[i]) t^=d[i];
				else
				{
					for(int j=0;j<i;j++)
						if(t&(1LL<<j)) t^=d[j];
					for(int j=i+1;j<=M;j++)
						if(d[j]&(1LL<<i)) d[j]^=t;
					d[i]=t;
					break;
				}
			}
		return;
	}
	bool find(long long t)
	{
		for(int i=M;i>=0;i--)
			if(t&(1LL<<i))
			{
				if(d[i]) t^=d[i];
				else return false;
			}
		return true;
	}
}lb;
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	scanf("%s",s+1);
	lb.clear();
	for(int i=n;i>=1;i--)
		if(s[i]=='1')
		{
			if(!lb.find(a[i]))
			{
				printf("1\n");
				return;
			}
		}
		else if(s[i]=='0') lb.insert(a[i]);
	printf("0\n");
	return;
}
int main()
{
	scanf("%d",&T);
	while(T--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

int main(){
  int k, x;
  cin >> k >> x;

  int l = x - (k-1);
  int r = x + (k-1);

  for(int i = l; i < r ; ++i){
    cout << i << " ";
  }
  cout << r << endl;
  return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  string s;
  int w;
  cin >> s;
  cin >> w;
  string ans = "";
  rep(i,sz(s)) {
    if(i%w!=0) continue;
    ans += s[i];
  }
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAXN=1000010;

int cnt=0,G[100];

void Insertion_Sort(int s,int t,int n,int* A)
{
	for(int i=s+t;i<n;i+=t)
	{
		int key=A[i],j=i-t;
		while(j>=0&&A[j]>key)
		{
			A[j+t]=A[j];
			j-=t;
			cnt++;
		}
		if(A[j+t]!=key)
		{
			A[j+t]=key;
			//cnt++;
		}
	}
}

int main()
{
	for(int i=0;(G[i]=G[i-1]*3+1)<=MAXN;i++);
	static int n,A[MAXN];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&A[i]);
	int t;
	for(t=0;G[t]<=n;t++);
	printf("%d\n",t);
	for(int i=t-1;i>=0;i--)
		printf("%d%c",G[i],i==0?'\n':' ');
	for(int i=t-1;i>=0;i--)
		for(int j=0;j<G[i];j++)
			Insertion_Sort(j,G[i],n,A);
	printf("%d\n",cnt);
	for(int i=0;i<n;i++)
		printf("%d\n",A[i]);
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  reverse(s.begin(),s.end());
  for(int i=N;i<=2*N;i++){
    string S=s.substr(0,2*N-i);
    reverse(S.begin(),S.end());
    if(S==t.substr(0,2*N-i)){cout<<i<<endl;return 0;}
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL<<32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

static const int MAX = 100;
ll d[MAX][MAX];

void floyd()
{
    REP(k, n)
    {
        REP(i, n)
        {
            if (d[i][k] == INF)
            {
                continue;
            }
            REP(j, n)
            {
                if (d[k][j] == INF)
                {
                    continue;
                }
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    ll e, u, v, c;
    cin >> n >> e;
    REP(i, n)
    {
        REP(j, n)
        {
            d[i][j] = ((i == j) ? 0 : INF);
        }
    }
    REP(i, e)
    {
        cin >> u >> v >> c;
        d[u][v] = c;
    }

    floyd();

    bool negative = false;
    REP(i, n)
    {
        if (d[i][i] < 0)
        {
            negative = true;
        }
    }
    if (negative)
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else
    {
        REP(i, n)
        {
            REP(j, n)
            {
                if (j)
                {
                    cout << " ";
                }
                if (d[i][j] == INF)
                {
                    cout << "INF";
                }
                else
                {
                    cout << d[i][j];
                }
            }
            cout << endl;
        }
    }
}

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

typedef long long ll;
const int nax = 5010;
const ll INF = 1e18L;
ll dp[nax][nax];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  for (int i = 0; i < nax; ++i) {
    for (int j = 0; j <= i; ++j) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  int n;
  cin >> n;
  vector<pair<int, int>> q(n);
  for (int i = 0; i < n; ++i) {
    cin >> q[i].first >> q[i].second;
    q[i].first += q[i].second;
  }
  sort(q.begin(), q.end());
  for (int i = 0; i < n; ++i) {
    q[i].first -= q[i].second;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (dp[i][j] == INF) continue;
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      if (dp[i][j] <= q[i].first) {
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + q[i].second);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (dp[n][i] != INF) {
      ans = i;
    }
  }
  cout << ans << '\n';
}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>>
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const ll mod = 998244353;

int main() {
    ll n; cin >> n;
    Vl d(n);
    rep(i, 0, n) cin >> d[i];
    if(d[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    map<ll, ll> cnt;
    rep(i, 0, n) cnt[d[i]]++;

    ll si = sz(cnt);
    rep(i, 0, si) if(cnt[i] == 0) {co(0); return 0;}
    if(cnt[0] != 1) {co(0); return 0;}
    if(d[0] != 0) {co(0); return 0;}

    ll ans = 1;
    rep(i, 0, si){
        // ans *= RepeatSquaring(cnt[i], cnt[i+1], mod);
        ans *= modpow(cnt[i], cnt[i+1], mod);
        ans %= mod;
    }
    co(ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;

ll Ep(int x, int y){
  if(y == 1) return x;
  ll r = Ep(x,y/2);
  if(y%2 == 1) return r *r%MOD *x%MOD;
  else return r *r%MOD;
}

int main(){
  int n, x;
  cin >> n;
  cin >> x;
  if(x != 0){
    cout << 0 << endl;
    return 0;
  }
  map<int, int> mp;
  for(int i=1; i<n; ++i){
    cin >> x;
    if(x == 0){
      cout << 0 << endl;
      return 0;
    }
    ++mp[x];
  }
  ll ans = 1;
  for(auto p: mp){
    if(p.first == 1) continue;
    ans *= Ep(mp[p.first-1], p.second);
    ans %= MOD;
  }
  cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<pair<int,int>> v;
  for(int i = 1; i <= n; i++){
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  int result = 0;
  for(int i = 1; i < v.size(); i++)
    if(v[i].second < v[0].second)
      swap(v[0], v[i]);
  sort(v.begin() + 1, v.end());

  for(int i = 0; i < v.size(); i++)
    result = max(result, v[i].second - v[i].first + 1);

  for(int i = 1;i < v.size() - 1; i++)
    result = max(result, (v[i].second - v[i].first + 1) + (v[0].second - max(v[0].first, v.back().first) + 1));

  int minr = v.back().second;
  for(int i = v.size() - 1; 1 <= i; i--){
    minr = min(minr, v[i].second);
    result = max(result, (minr - v.back().first + 1) + (v[0].second - max(v[0].first, v[i - 1].first) + 1));
  }
  cout << result;
  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>

using namespace std;

int main() {
	int i, j, k, to, min, temp_result;
	int n;
	int r[100], c[100];
	int result[100][100];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> r[i] >> c[i];
		result[i][i] = 0;
	}

	i = 0;
	j = 1;
	to = n - 2;
	while (j <= n - 1) {
		while (i <= to) {
			//computation of result[i][i+j]
			min = INT_MAX;
			k = i;
			while (k <= i + j - 1) {
				temp_result = c[k] * r[i] * c[i + j] + result[i][k] + result[k + 1][i + j];
				if (temp_result < min) {
					min = temp_result;
				}
				k++;
			}
			result[i][i + j] = min;
			i++;
		}
		i = 0;
		j++;
		to--;
	}
	printf("%d\n", result[0][n - 1]);
}


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

int main(){
    string S;
    cin >> S;
    int ans = 753;
    for(int i = 0; i <= S.size()-3; ++i){
        int buf = (S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
        ans = min(ans, abs(buf-753));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
  	cin>>n;
  	cout<<n + (n*n) + (n*n*n);
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "C"
int n;
ll x;
ll start;
class subject{
public:
    ll b, l, u, w;
    void input(){
        read(b);
        read(l);
        read(u);
        start+=b*l;
        w=(x-b)*u+b*l;
    }
    ll cost(ll x){
        if(x<=b*l){
            return (x-1)/l+1;
        }
        else{
            x-=b*l;
            return b+(x-1)/u+1;
        }
    }
} s[100001];
ll f[100001];
int get(int i){
    int res=n;
    int low=0, high=n-1, mid;
    while(low<=high){
        mid=(low+high)/2;
        ll sum=f[mid];
        if(mid<i) sum+=s[i].w;
        if(sum>=start){
            res=mid;
            high=mid-1;
        }
        else low=mid+1;
    }
    return res;
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    read(x);
    FOR(i, 1, n) s[i].input();
    sort(s+1, s+n+1, [](subject A, subject B){
        return A.w>B.w;
    });
    ll ans=x*n;
    FOR(i, 1, n) f[i]=f[i-1]+s[i].w;
    FOR(i, 1, n){
        int j=get(i);
        ll res=x*j;
        if(j>i) res-=x;
        ll now=start-f[j];
        if(j>i) now+=s[i].w;
        if(now>0) ans=min(ans, res+s[i].cost(now));
        else ans=min(ans, res);
    }
    writeln(ans);
}

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <stdint.h>

namespace asl
{
    template <typename T>
    using vec = std::vector<T>;

    template <typename T>
    std::istream &operator>>(std::istream &is, std::vector<T> &vec)
    {
        for (auto &value : vec)
            is >> value;
        return is;
    }

    template <typename T>
    struct fenwick
    {
        int n;
        std::vector<T> f;
        fenwick(int n) : n(n), f(n + 1) {}

        T query(int p)
        {
            T ret = 0;
            for (++p; p > 0; p -= p & -p)
                ret += f[p];
            return ret;
        }

        void update(int p, T x)
        {
            for (++p; p <= n; p += p & -p)
                f[p] += x;
        }

    };

    template <typename T>
    using BIT = fenwick<T>;
}

#include <experimental/optional>

#include <tuple>

namespace asl
{
    typedef long long i64;

}

#include <random>

#include <utility>

#define endl '\n'

using namespace std;
using namespace asl;

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

    vec<int> val(n);
    cin >> val;

    BIT<i64> bit(n);

    for (int i = 0; i < n; ++i)
        bit.update(i, val[i]);

    while (q--)
    {
        int t;
        cin >> t;

        if (t == 0)
        {
            int p, x;
            cin >> p >> x;
            bit.update(p, x);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << bit.query(r - 1) - bit.query(l - 1) << endl;
        }
    }
}

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

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll maxn=1e5+10;
ll mm,m,n,a[60];
ll f[60];
ll ans;
inline void read(ll &x)
{
	ll f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
void dfs(ll x,ll n,ll sum){
    if(x==n/2+1){
        if(sum==m){
           	ll now=a[1]>=0?(9-a[1]):(9+a[1]);
            for(register ll i=2;i<x;i++)
				now*=(a[i]>=0?(10-a[i]):(10+a[i]));
            ans+=n&1?now*10:now;
        }
        return ;
    }
    if(sum+10ll*(f[n-x]-f[x-1])<m||sum-10ll*(f[n-x]-f[x-1])>m)
		return ;
    for(register ll i=-9;i<10;i++){
        a[x]=i;
        dfs(x+1,n,sum+1ll*a[x]*(f[n-x]-f[x-1]));
    }
}
int main(){
    read(m);
	mm=m;f[0]=1;
    while(mm) n++,mm/=10;
    for(register ll i=1;i<=18;i++) f[i]=f[i-1]*10;
    for(register ll i=n;i<=18;i++) dfs(1,i,0);
    printf("%lld\n",ans);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

__int128_t abs128(__int128_t val){return val<0?-val:val;}

ostream &operator<<(ostream &os,__int128_t val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,__int128_t &val){
  string s;
  is>>s;
  val=0;
  for(int i=0;i<(int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}

//INSERT ABOVE HERE
signed main(){
  using ll = __int128_t;

  ll d;
  cin>>d;
  const ll MAX = 37;
  ll ans=0;

  vector<ll> po(MAX,1);
  for(int i=0;i+1<MAX;i++)
    po[i+1]=po[i]*10;

  vector<ll> c1(12,0),c2(12,0);
  for(int i=1;i<10;i++)
    for(int j=1;j<=i;j++)
      c1[abs(i-j)]++;

  for(int i=0;i<10;i++)
    for(int j=0;j<=i;j++)
      c2[abs(i-j)]++;

  for(int l=2;l<=MAX;l++){
    // [s, t]
    ans+=
      MFP([&](auto dfs,ll s,ll t,ll w)->ll{
            if(s>=t){
              if(w!=0) return 0;
              return s==t?10:1;
            }
            ll dif=po[t]-po[s];
            ll x=w/dif;
            if(x>=10) return 0;

            ll res=0;
            res+=(s==0?c1:c2)[x+0]*dfs(s+1,t-1,abs128(w-(x+0)*dif));
            res+=(s==0?c1:c2)[x+1]*dfs(s+1,t-1,abs128(w-(x+1)*dif));
            return res;
          })(0,l-1,d);
  }
  cout<<ans<<endl;
  return 0;
}


#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=1e5+2;
pair<int,pair<int,int> > ar[N];
pair<int,int> wow[N];
int sum[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,x,i,j,k,l=0,val,val1,max1;
	int lef=0,rig=0,mid;
	cin>>n>>x;
	for(i=1;i<=n;i++){
		cin>>ar[i].first>>ar[i].second.first>>ar[i].second.second;
		rig+=ar[i].first;
		l+=-ar[i].first*ar[i].second.first;
		wow[i].first=ar[i].first*(ar[i].second.first-ar[i].second.second)+x*ar[i].second.second;
		wow[i].second=i;
	}
	sort(wow+1,wow+1+n,[&](pair<int,int> cac,pair<int,int> cac1){
		return cac.first>cac1.first;
	});
	for(i=1;i<=n;i++){
		sum[i]=sum[i-1]+wow[i].first;
	}
	while(rig>lef){
		mid=(lef+rig)/2;
		val=mid/x;
		val1=mid%x;
		max1=sum[val];
		for(i=1;i<=n;i++){
			j=wow[i].second;
			if(i<=val){
				if(val1>ar[j].first){
max1=max(max1,sum[val+1]-wow[i].first+ar[j].first*(ar[j].second.first-ar[j].second.second)+val1*ar[j].second.second);
				}
				else{
					max1=max(max1,sum[val+1]-wow[i].first+val1*ar[j].second.first);
				}
			}
			else{
				if(val1>ar[j].first){
				max1=max(max1,sum[val]+ar[j].first*(ar[j].second.first-ar[j].second.second)+val1*ar[j].second.second);
				}
				else{
					max1=max(max1,sum[val]+val1*ar[j].second.first);
				}
			}
		}
		if(max1+l>=0){
			rig=mid;
		}
		else{
			lef=mid+1;
		}
	}
	cout<<rig;
}

#include<bits/stdc++.h>

#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define MREP(i,x) for(int i=beg[x],v;v=to[i],i;i=las[i])
#define debug(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define y1 asdasd
typedef long long ll;

using namespace std;

void File(){
	freopen("speech.in","r",stdin);
	freopen("speech.out","w",stdout);
}

template<typename T>void read(T &_){
	T __=0,mul=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')mul=-1;
		ch=getchar();
	}
	while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
	_=__*mul;
}

const int maxn=2000+10;
int n,m,a[maxn][maxn],b[maxn][maxn],ans;
char s[maxn];
stack<int>stk;

int main(){
	//File();
	read(n); read(m);
	if(n==1 || m==1)return printf("%d\n",n*m),0;
	REP(i,1,n){
		scanf("%s",s+1);
		REP(j,1,m)a[i][j]=(s[j]=='#');
	}
	REP(i,1,n-1)REP(j,1,m-1){
		int c[2]={0};
		++c[a[i][j]];
		++c[a[i+1][j]];
		++c[a[i][j+1]];
		++c[a[i+1][j+1]];
		b[i][j]=!(c[1]%2);
		if(b[i][j])b[i][j]+=b[i-1][j];
	}
	/*REP(i,1,n-1){
		REP(j,1,n-1)
			cout<<b[i][j]<<" ";
		cout<<endl;
	}*/
	REP(i,1,n-1){
		int las;
		REP(j,1,m-1){
			las=j;
			while(!stk.empty() && b[i][stk.top()]>=b[i][j]){
				las=stk.top(); stk.pop();
				if(b[i][las])ans=max(ans,(j-las+1)*(b[i][las]+1));
			}
			b[i][las]=b[i][j];
			stk.push(las);
		}
		while(!stk.empty()){
			las=stk.top(); stk.pop();
			if(b[i][las])ans=max(ans,(m-las+1)*(b[i][las]+1));
		}
	}
	printf("%d\n",max(ans,max(n,m)));
	return 0;
}


#include <iostream>
using namespace std;
int solve(int x){
	if(x == 1) return 3;
	else if(x == 2) return 2;
	else if(x == 3) return 1;
	else return 0;
}
int main() {
	// your code goes here
	int x, y; cin>>x>>y;
	int answer = solve(x);
	answer += solve(y);
	if(x == y && x == 1) answer += 4;
	cout<<answer * 100000;
	return 0;
}

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

int main() {
  double a;  /* 現在のレーティング */
  double b;  /* 目標のレーティング */

  //
  // ( a + x ) / 2 = b
  // x = 2b -a
  //

  cin >> a;
  cin >> b;

  cout << (2.0 * b) - a << endl;

}


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

int main() {
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll ans = 5;
    ll mincap = min(min(min(A, B), min(C, D)), E);
    ans += N / mincap - 1;
    if (N % mincap != 0) ++ans;
    cout << ans << endl;
}

//  Copyright © 2019 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 305
#define MOD 998244353
using namespace std;
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
typedef long long i64;

i64 N, sum;
i64 a[MAX];
i64 memo[MAX][90005];

i64 dp( i64 x , i64 s )
{
    if( x > N )
    {
        if( s >= ( sum + 1 ) / 2 )
            return 1;
        return 0;
    }
    if( memo[x][s] != -1 )
        return memo[x][s];

    i64 ans = 0;
    ans += 2 * dp( x + 1 , s );
    ans += dp( x + 1 , s + a[x] );
    ans %= MOD;
    return memo[x][s] = ans;
}

i64 dp2( i64 x , i64 s )
{
    if( x > N )
    {
        if( s == sum / 2 )
            return 1;
        return 0;
    }
    if( memo[x][s] != -1 )
        return memo[x][s];
    i64 ans = dp2( x + 1 , s ) + dp2( x + 1 , s + a[x] );
    ans %= MOD;
    return memo[x][s] = ans;
}

int main()
{
    optimiza_io
    memset( memo , -1 , sizeof memo );
    cin >> N;
    i64 ansi = 1;
    for( i64 i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        sum += a[i];
        ansi *= 3;
        ansi %= MOD;
    }
    i64 tmp = 3 * dp( 1 , 0 );
    if( sum % 2 == 0 )
    {
        memset( memo , -1 , sizeof memo );
        tmp -= 3 * dp2( 1 , 0 );
        tmp %= MOD;
        tmp += MOD;
        tmp %= MOD;
    }

    cout << ( ( ( ansi - tmp ) % MOD ) + MOD ) % MOD << "\n";
    return 0;
}


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

int main() {
    //
    int num;
    string str;
    long long cnt = 0;
    long long all = 0;

    cin >> num >> str;
    vector<int> r;
    vector<int> g;
    vector<int> b;

    for (int i = 0; i < num; i++) {
        if (str.at(i) == 'R')
            r.push_back(i);
        else if (str.at(i) == 'G')
            g.push_back(i);
        else if (str.at(i) == 'B')
            b.push_back(i);
    }

    all = r.size() * g.size() * b.size();
    for (int i = 0; i < num; i++) {
        for (int j = i+1; j < num; j++) {
            long long k = j * 2 - i;

            if (k >= num || str.at(i) == str.at(j)) continue;
            if (str.at(k) == str.at(i) || str.at(k) == str.at(j)) continue;
            all--;
            /*
            for (int k = 0; k < b.size(); k++) {
                if (g.at(j) - r.at(i) == b.at(k) - g.at(j)) continue;
                if (b.at(k) - g.at(j) == r.at(i) - b.at(k)) continue;
                if (r.at(i) - b.at(k) == g.at(j) - r.at(i)) continue;
                cnt++;
            }
            */
        }
    }

    cout << all;
    //
}

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

int main() {
    int n;
    cin >> n;
    vector<int> r,g,b;

    for(int i = 0; i < n; i++) {
        char x;
        cin >> x;
        if(x=='R') r.push_back(i+1);
        if(x=='G') g.push_back(i+1);
        if(x=='B') b.push_back(i+1);
    }

    ll ans = r.size()*g.size()*b.size();
    if(ans==0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0; i < r.size(); i++) {
        for(int j = 0; j < g.size(); j++) {
            int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin();
            if(y!=b.size()){
                if(b[y]==g[j]+g[j]-r[i]) ans--;
            }
            y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin();
            if(y!=b.size()){
                if(b[y]==r[i]+r[i]-g[j]) ans--;
            }

            if((r[i]+g[j])%2==0){
                y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin();
                if(y!=b.size()){
                if(b[y]==(r[i]+g[j])/2) ans--;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

vii a;
vi p;

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

    int n;
    cin >> n;

    a.assign(n, vi(n));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    p.assign((1 << n), 0);

    for (int j = 0; j < (1 << n); ++j) {
        for (int i = 0; i < n; ++i) {
            if (!(j & (1 << i))) continue;
            for (int k = i + 1; k < n; ++k) {
                if (!(j & (1 << k))) continue;

                p[j] += a[i][k];
            }
        }
    }

    vi dp(1 << n, 0);

    for (int i = 0; i < n; ++i) {
        for (int j = (1 << i); j <= (1 << (i + 1)) - 1; ++j) {
            for (int k = j; k; k = (k - 1) & j) {
                dp[j] = max(dp[j], p[k] + dp[j - k]);
            }
        }
    }

    cout << dp[(1 << n) - 1];
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

ll dp[1<<16], score[1<<16];
ll a[16][16];

ll rec(int S){
    if(dp[S] != -1) return dp[S];
    if(S == 0) return dp[S] = 0;

    ll ret = score[S];
    for(int T=S; T>0; T=T-1&S){
        if(S==T) continue;
        chmax(ret, rec(T) + rec(S^T));
    }

    return dp[S] = ret;
}

int main(void){
    int N; cin >> N; REP(i,1<<N) dp[i] = -1;
    REP(i,N)REP(j,N) cin >> a[i][j];

    REP(S,1<<N){
        REP(i,N)FOR(j,i+1,N) if(S>>i & S>>j & 1) score[S] += a[i][j];
    }

    ll ans = rec((1<<N)-1);
    cout << ans << en;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    ll A = 0;
    REP(i,0,N) {
        ll a;
        cin >> a;
        A |= a;
    }

    ll cnt = 0;
    while((A & 1) == 0) {
        A >>= 1;
        ++cnt;
    }
    PR(cnt);

    return 0;
}

/*

*/

#include <bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int count = 0;
	int result = 200;

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);

		while (true) {
			if (A.at(i) % 2 != 0 || A.at(i) == 0) {
				break;
			}

			else if (A.at(i) % 2 == 0) {
				A.at(i) = A.at(i) / 2;
				count++;
			}
		}

		result = min(result, count);
		count = 0;
	}

	cout << result << endl;
}