#include <bits/stdc++.h>

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli n;
	cin>>n;

	string s[3];
	REP(i,0,3)cin>>s[i];

	lli cnt = 0;
	REP(i,0,n){
		set<char> c;
		REP(j,0,3){
			c.insert(s[j][i]);
		}
		if(c.size()==3)cnt+=2;
		else if(c.size()==2)cnt++;
	}

	cout<<cnt<<endl;

	return 0;
}

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

int main(){

    int N;
    string A,B,C;
    cin >> N;
    cin >> A >> B >> C;
    int ans = 0;
    for(int i = 0; i < N;i++){

        if(A[i] == B[i] && B[i] != C[i] && C[i] != A[i])ans++;
        else if(A[i] != B[i] && B[i] == C[i] && C[i] != A[i])ans++;
        else if(A[i] != B[i] && B[i] != C[i] && C[i] == A[i])ans++;
        else if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i])ans+=2;
    }
    cout << ans << endl;

}


#include <iostream>
#include <string>

int main(){
	int n;
	std::string str;

	std::cin >> n;
	std::getline(std::cin, str);

	for (int i = 0; i < n; ++i){

		std::getline(std::cin, str);

		while(str.find("Hoshino") != std::string::npos){

			str.replace(str.find("Hoshino"), 7, "Hoshina");

		}

		std::cout << str << std::endl;

	}

	return 0;
}


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

int N;
#define MAX_N 100000
int A[MAX_N];
bool F;

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];
  F = true;
  while(true) {
    int c = 0, o = -1;
    for(int i = 0; i < N; ++i) {
      if(A[i] % 2 == 0) ++c;
      else o = i;
    }
    if(c % 2 == 1) break;
    F = !F;
    if(c != N - 1 || A[o] == 1) break;
    --A[o];
    int g = 0; for(int i = 0; i < N; ++i) g = gcd(g, A[i]);
    for(int i = 0; i < N; ++i) A[i] /= g;
  }
  cout << (F ? "First" : "Second") << endl;
  return 0;
}

#include <cstdio>
typedef long long lint;
int const N=1e5+10;
int n,a[N];
int gcd(int x,int y)
{
    if(x==-1 || y==-1) return -x*y;
    if(x==0) return y;
    else return gcd(y%x,x);
}
int g1[N],g2[N];
int main()
{
    scanf("%d",&n);
    lint sum=0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
    if(n%2==0)
    {
        if(sum%2==1) printf("First");
        else printf("Second");
        return 0;
    }
    if(sum%2==0) {printf("First"); return 0;}
    int cur=0;
    while(true)
    {
        bool flag=false;
        sum=0;
        for(int i=1;i<=n;i++) sum+=a[i];
        g1[0]=-1; g2[n+1]=-1;
        for(int i=2;i<=n;i++) g1[i]=gcd(g1[i-1],a[i]);
        for(int i=n-1;i>=1;i--) g2[i]=gcd(g2[i+1],a[i]);
        int g;
        for(int i=1;i<=n&&!flag;i++)
        {
            if(a[i]==1) continue;
            g=gcd(gcd(g1[i-1],g2[i+1]),a[i]-1);
            if(((sum-1)/g)%2==1) flag=true;
        }
        if(flag)
            for(int i=1;i<=n;i++) a[i]/=g;
        else
        {
            if(cur==0) printf("Second");
            else printf("First");
            return 0;
        }
        cur^=1;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N>>M>>Q;
    vector<string> grid(N);
    rep(i,N) cin>>grid[i];
    mat edge(N, vec(M, 0)), num(N + 1, vec(M + 1, 0)), addr(N, vec(M,0)), addc(N, vec(M,0));
    rep(i,N){
        rep(j,M){
            bool blue = grid[i][j] == '1';
            if(i > 0) {
                edge[i][j] += edge[i-1][j] + (blue && grid[i-1][j] == '1');
                addc[i][j] = addc[i-1][j] + (blue && grid[i-1][j] == '1');
            }
            if(j > 0) {
                edge[i][j] += edge[i][j-1] + (blue && grid[i][j-1] == '1');
                addr[i][j] = addr[i][j-1] + (blue && grid[i][j-1] == '1');
            }
            if(i > 0 && j > 0) edge[i][j] -= edge[i-1][j-1];
            num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j] + blue;
        }
    }
    vec x(2), y(2);
    rep(i,Q){
        rep(j,2) cin>>x[j]>>y[j];
        --x[0], --y[0];
        ll res = 0;
        rep(j,2) rep(k,2) res += (j^k ? -1 : 1) * num[x[j]][y[k]];
        --x[1], --y[1];
        rep(j,2) rep(k,2) res += (j^k ? 1 : -1) * edge[x[j]][y[k]];
        res -= addr[x[0]][y[1]] - addr[x[0]][y[0]];
        res -= addc[x[1]][y[0]] - addc[x[0]][y[0]];
        cout<<res<<endl;
    }
    /*rep(i,N){
        rep(j,M) cout<<edge[i][j]<<' ';
        cout<<endl;
    }*/
}


#include <iostream>
#include <numeric>
#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++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {

	ll N,K;
	cin >> N>>K;

	cout << N-K+1 << endl;

}

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
	int n, i, j;
	ios::sync_with_stdio();
	string s;

	scanf("%d", &n); cin.get();
	for (i=0; i<n; i++) {
		getline(cin, s);

		for (j=0; j+6 < s.size(); j++) {
			if (s.substr(j, 7) == "Hoshino") s[j+6] = 'a';
		}

		cout << s << endl;

	}
	return 0;
}


#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 1<<17, mlg = 17, mod = 1e9 + 7;
ll n, l, q, x[maxn], go[maxn][mlg];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	cin >> l >> q;
	for(int i = 1, j = 1; i <= n; i++) {
		while(j < n && x[j+1]-x[i] <= l) j++;
		go[i][0] = j;
		//cout << j << " ";
	}
	for(int j = 1; j < mlg; j++)
		for(int i = 1; i <= n; i++)
			go[i][j] = go[go[i][j-1]][j-1];
	int a, b;
	while(q--) {
		cin >> a >> b;
		if(a > b) swap(a, b);
		int ans = (a!=b);
		for(int i = mlg; i--;) if(go[a][i] && go[a][i] < b) {
			//cout << a << " " << i << '\n';
			a = go[a][i], ans += 1<<i;
		}
		cout << ans << '\n';
	}
}

//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int n,k;
int f,to,from,cost;
const int INF=222222222;

vector<P> G[1000];//first→終点 second→cost
int dist[1000];//頂点iへの最小距離

int keiro(int from,int to){
	for(int i=0;i<=n;i++)dist[i]=INF;
	//dist[from]=0;
	priority_queue<P,vector<P>,greater<P> >bfs;//first→頂点へのコスト second→頂点

	bfs.push(mp(0,from));

	while(!bfs.empty()){
		P now=bfs.top();
		bfs.pop();

		int index=now.second,ncost=now.first;

		if(dist[index]!=INF)continue;
		//cout<<index<<" "<<ncost<<endl;
		dist[index]=ncost;

		for(int i=0;i<G[index].size();i++){

			bfs.push(mp(ncost+G[index][i].second,G[index][i].first));
			//cout<<G[index][i].first<<" "<<G[index][i].second<<endl;
		}
	}

//rep(i,n+1)cout<<dist[i]<<" ";
	if(dist[to]==INF)return -1;
	return dist[to];
}
int main(){
while(cin>>n>>k,n||k){
for(int i=0;i<200;i++)G[i].clear();

for(int i=0;i<k;i++){
	cin>>f;
	if(!f){
		cin>>from>>to;
		cout<<keiro(from,to)<<endl;
	}
	else{
		cin>>from>>to>>cost;
		G[from].push_back(mp(to,cost));
		G[to].push_back(mp(from,cost));
	}
}
}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int d[110];
    int n, q;
    while(cin >> n >> q, n+q){
        fill(d, d+110, 0);
        for(int i=0; i< n; i++){
            int q;
            cin >> q;
            rep(j, q){
                int r; cin >> r; d[r]++;
            }
        }
        int m = 0, ret = -1;
        rep(i, 110){
            if(q <= d[i] && m < d[i]){ret = i; m = d[i];}
        }
        cout << (ret==-1?0:ret) << endl;
    }
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<char> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        if (n != 1)
        {
            if (a[i] == 1)
            {
                if (b[i] == '0')
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }

        a[i]--;
    }

    for (int i = 0; i < m - 1; i++)
    {
        for (int j = i + 1; j < m; j++)
        {
            if (a[i] == a[j])
            {
                if (b[i] != b[j])
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    int nx = pow(10, n);

    for (int i = 0; i < nx; i++)
    {
        string str = to_string(i);
        if (str.size() != n) continue;

        int flg = 1;
        for (int j = 0; j < m; j++)
        {
            if (str[a[j]] != b[j]) flg = 0;
        }
        if (flg)
        {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    int f = 0;
    for (int j = 0; i + j < n; j++) {
      if (a[j + i] != b[j]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      cout << n + i << '\n';
      return;
    }
  }
  cout << n + n << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a);
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}
int n,q;
hei(ll) seg, lazy;

void aaa(int k) {
	if (lazy[k] == 0)return ;
	if (k < n - 1) {
		lazy[k * 2 + 1] += lazy[k];
		lazy[k * 2 + 2] += lazy[k];
	}
	seg[k] += lazy[k];
	lazy[k] = 0;
}

void update(int a, int b, ll x,int k,int l,int r) {
	aaa(k);
	if (a<=l && b>=r) {
		lazy[k] += x;
		aaa(k);
	}
	else if(a<r&&l<b){
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1]+seg[k * 2 + 2];
	}
}

ll query(int a,int b,int k,int l,int r){
	aaa(k);
	if (l >= b || r <= a)return 0;
	if (a <=l  && b >= r) {
		return seg[k];
	}
	ll v1 = query(a, b, k*2+1, l, (l + r) / 2);
	ll v2 = query(a, b, k*2+2, (l + r) / 2, r);
	return v1 + v2;
}

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	int x = 0;
	rep(i, 1, n + 1) {
		if (s.substr(n - i, i) == t.substr(0, i))x = i;
	}
	int ans = (2 * n) - x;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], n, cnt, m;
int main() {
    scanf("%d %d", &n, &m);
    for (int i  = 1; i <= m; i++) scanf("%d", &a[i]);
    for (int i  = 1; i <= m; i++) if (a[i] & 1) cnt ++;
    if (cnt > 2) {
    	puts("Impossible");
    	return 0;
    }
	for (int i = 1; i <= m; i++)
        if ((a[i] & 1) && (!(a[1] & 1))) swap(a[i], a[1]);
        else if (a[i] & 1) swap(a[i], a[m]);
	for (int i = 1; i <= m; i++) cout << a[i] << " " ; cout << endl;
	if (!cnt) {
		int ans = m + 2;
		if (a[1] == 2) ans--;
		cout << ans << endl;
		if (a[1] != 2) cout << a[1] - 2 << " " ; cout << "1 ";
		for (int i = 2; i <= m; i++) cout << a[i] << " " ; cout << 1 << endl;
	}
	else if (cnt == 1) {
		int ans = m + 1;
		if (a[1] == 1) ans--;
        cout << ans << endl;
		if (a[1] != 1) cout << a[1] - 1 << " " ;
		for (int i = 2; i <= m; i++) cout << a[i] << " " ; cout << 1 << endl;
	}
	else if (cnt == 2) {
		int ans = m;
		if (a[1] == 1) ans--;
        cout << ans << endl;
		if (a[1] != 1) cout << a[1] - 1 << " " ;
		for (int i = 2; i < m; i++) cout << a[i] << " " ; cout << a[m] + 1 << endl;
	}
	return 0;
}


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

int main(){
    int n,m;
    while(cin>>n,n){
        set<pair<int,int> > sp;

        for(int i=0;i<n;i++){
            int x,y;
            cin>>x>>y;
            sp.insert(make_pair(y,x));
        }

        cin>>m;
        int c=0;
        pair<int,int> now(10,10);

        for(int i=0;i<m;i++){
            char d;
            int len;

            cin>>d>>len;
            cin.ignore();

            for(int j=0;j<len;j++){
                switch(d){
                    case 'N':
                        now.first++;
                        break;
                    case 'S':
                        now.first--;
                        break;
                    case 'E':
                        now.second++;
                        break;
                    case 'W':
                        now.second--;
                        break;
                }

                decltype(sp.end()) it;
                if((it=sp.find(now)) != sp.end()){
                    c++;
                    sp.erase(it);
                }
            }
        }

        cout << (c==n ? "Yes" : "No") << endl;
    }
}

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

#define N 0
#define E 1
#define S 2
#define W 3

int dir[4][2] = { {0,1}, {1,0}, {0,-1}, {-1,0} };
int map[21][21];

int main(void)
{
    while(true) {
        int n, m;
        int px=10, py=10, s=0;

        memset(map, 0, sizeof(map));

        scanf("%d\n", &n);
        if(n==0) break;

        for(int i=0; i < n; i++)
        {
            int x,y;
            scanf("%d%d\n", &x, &y);

            map[x][y] = 1;
        }

        scanf("%d\n", &m);

        map[10][10] = 0;
        for(int i=0; i < m; i++)
        {
            char d;
            int *D, l;
            scanf("%c %d\n", &d, &l);
            switch(d) {
                case 'N':
                    D = dir[N];
                    break;
                case 'E':
                    D = dir[E];
                    break;
                case 'S':
                    D = dir[S];
                    break;
                case 'W':
                    D = dir[W];
                    break;
            }

            for(int i=0; i < l; i++)
            {
                px += *D;
                py += *(D+1);
                map[px][py] = 0;
            }
        }

        for(int i=0; i <= 20; i++)
            for(int j=0; j <= 20; j++)
                s += map[i][j];

        printf( s ? "No\n" : "Yes\n");
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
        int E;
        while(cin >> E && E){
                int m=1000000;
                for(int z=0; z*z*z<=E; ++z){
                        for(int y=0; y*y+z*z*z<=E; ++y){
                                int x = E-z*z*z-y*y;
                                m = min(m,x+y+z);
                        }
                }
                cout << m << endl;
        }

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  while (int e = in()){
    int m = 1e8;
    for (int z = 0; z <= 100; ++z){
      for (int y = 0; y <= 1000; ++y){
        int x = e - (sq(z) * z + sq(y));
        if (x < 0) continue;
        m = min(m, z + y + x);
      }
    }
    printf("%d\n", m);
  }
  return (0);
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false),cin.tie(0);
#define ll long long
#define inf 0x3f3f3f3f
const int N=105;
//set<string>b;
//set<string>::iterator it;

int main()
{
	IO;
	double d,t,s,x;
	cin>>d>>t>>s;
	x=1.0*d/s;
	if(x>t) cout<<"No\n";
	else cout<<"Yes\n";
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    set<int> set;
    set.insert(a);
    set.insert(b);
    set.insert(c);
    if(set.size()==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit
//	freopen ("testcase.RL", "r", stdin );
	string str = "";
	while (getline (cin, str ) ){
		if (str.empty() ) break;
		int n = str.length();
		rep (i, n ){
			if (str[i] == ',' ) str[i] = ' ';
		} // end rep
		vector<int> l (12, 0 ), sum (12, 0 );
		int v1, v2;
		stringstream ss (str );
		for (int i = 1; i <= 10; i++ ){
			ss >> l[i];
		} // end rep
		l[11] = 100000;
		ss >> v1 >> v2;
		for (int i = 1; i <= 11; i++ ){
			sum[i] = sum[i-1] + l[i];
		} // end for
/*
		cerr << "sum: " << endl;
		rep (i, 10+1 ){
			cerr << sum[i] << (i != 10 ? ' ' : '\n' );
		} // end rep
*/
		double t = (double)sum[10]/(double)(v1 + v2 );
//		cerr << "t: " << t << endl;
		double cl = (double)v1*t;
//		cerr << "cl: " << cl << endl;
		int res = 0;
		for (int i = 1; i <= 10; i++ ){
			if ((double)sum[i-1] < cl && cl <= (double)sum[i] ){
				res = i;
				break;
			} // end if
		} // end for
		printf ("%d\n", res );

	} // end loop

	return 0;
}

#include <iostream>

using namespace std;

void solve()
{
	int l[10];
	while(cin >> l[0])
	{
		for(int i = 1; i <= 9; ++i)
		{
			scanf(",%d", &l[i]);
		}
		int v[2];
		scanf(",%d,%d", &v[0], &v[1]);
		int sum = 0;
		for(int i = 0; i < 10; ++i)
		{
			sum += l[i];
		}
		double time = (double)sum / (v[0] + v[1]);
		double dist = time * (double)v[0];
		int pos = 0;
		int d = 0;
		while(true)
		{
			d += l[pos];
			if(d >= dist)
			{
				cout << pos + 1 << endl;
				break;
			}
			++pos;
		}
	}
}

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


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

int main() {
  int N;
  cin >> N;
  int s = 0;
  int M = N;
    while(M != 0){
      s += M % 10;
      M = M / 10;
    }
	if ( N % s == 0)
      cout << "Yes" << endl;
  	if ( N % s != 0)
      cout << "No" <<endl;
}


///f. fizzbuzz sequence
#include <stdio.h>
#include <math.h>

int main()
{
    long long int n;
    scanf("%lld",&n);
    long long int d3,d5,d15;
    d3=n/3; d5=n/5; d15=n/15;

    long long sum = (n*(n+1)-3*d3*(d3+1)-5*d5*(d5+1)+15*d15*(d15+1))/2;
    printf("%lld",sum);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int x;
    cin >> x;
    int happy = 0;
    happy += (x / 500) * 1000;
    happy += ((x % 500) / 5) * 5;
    cout << happy << endl;
}

//https://atcoder.jp/contests/abc160/tasks/abc160_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin>>x;
	ll a;
	a=x/500;
	ll fin1;
	fin1=a*1000;
	ll b;
	b=x%500;
	ll c;
	c=b/5;
	ll fin2;
	fin2=c*5;
	ll sum=0;
	sum=fin1+fin2;
	cout<<sum<<"\n";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q,a,b;
vector<ll>v[100001];
ll vis[100001]={0},ans=0;
pair<ll,ll> dfs(ll x,ll lvl){
   vis[x]=1;
   ll mx=0;
   ll d2=1e9;
   if(x==a)d2=0;
   for(int i=0;i<v[x].size();i++){
     if(vis[v[x][i]]==0){
       pair<ll,ll> p=dfs(v[x][i],lvl+1);
       d2=min(d2,p.second);
       mx=max(mx,1+p.first);
     }
   }
   if(d2<lvl) ans=max(ans,mx+lvl);
   return {mx,d2+1};
}
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>a>>b;
      for(int i=0;i<n-1;i++){
      	cin>>x>>y;
      	v[x].push_back(y);
      	v[y].push_back(x);
      }
      if(a==b)cout<<0;
      else{
      	dfs(b,0);
      	cout<<ans-1;
      }
}

#include <bits/stdc++.h>

int main(){
    int N, u, v;
    std::cin >> N >> u >> v;
    u--; v--;
    std::vector< std::vector< int > > AB(N);
    for(int i=1; i<N; i++){
        int tmpa, tmpb;
        std::cin >> tmpa >> tmpb;
        tmpa--; tmpb--;
        AB[tmpa].push_back(tmpb);
        AB[tmpb].push_back(tmpa);
    }

    std::vector< int > min_dist(N, 1e9);
    std::vector< int > min_route;
    std::deque< int > pos;
    std::deque< int > prepos;
    std::deque< int > dist;
    std::vector< int > route;
    pos.push_back(v);
    prepos.push_back(-1);
    dist.push_back(0);

    while(!pos.empty()){
        int c_pos = pos[0];
        int c_prepos = prepos[0];
        int c_dist = dist[0];
        pos.pop_front();
        prepos.pop_front();
        dist.pop_front();

        if(min_dist[c_pos] <= c_dist){
            continue;
        }

        route.resize(c_dist);
        route.push_back(c_pos);

        min_dist[c_pos] = c_dist;
        if(c_pos == u){
            min_route = route;
            break;
        }

        for(int i=0; i<AB[c_pos].size(); i++){
            if(AB[c_pos][i] == c_prepos){
                continue;
            }
            pos.push_front(AB[c_pos][i]);
            prepos.push_front(c_pos);
            dist.push_front(c_dist+1);
        }
    }

    int center = (min_route.size() % 2 == 0) ? min_route[min_route.size() / 2] : min_route[min_route.size() / 2 + 1];
    int pre_center = (min_route.size() % 2 == 0) ? min_route[min_route.size() / 2 - 1] : min_route[min_route.size() / 2];
    int center_dist = (min_route.size() % 2 == 0) ? min_route.size() / 2 : min_route.size() / 2 + 1;

    pos.clear();
    prepos.clear();
    dist.clear();
    pos.push_back(center);
    prepos.push_back(-1);
    dist.push_back(0);
    min_dist.assign(N, 1e9);
    int max_dist = 0;

    while(!pos.empty()){
        int c_pos = pos[0];
        int c_prepos = prepos[0];
        int c_dist = dist[0];
        pos.pop_front();
        prepos.pop_front();
        dist.pop_front();

        if(c_pos == pre_center){
            continue;
        }
        if(min_dist[c_pos] <= c_dist){
            continue;
        }

        min_dist[c_pos] = c_dist;
        if(max_dist < c_dist){
            max_dist = c_dist;
        }

        for(int i=0; i<AB[c_pos].size(); i++){
            if(AB[c_pos][i] == c_prepos){
                continue;
            }
            pos.push_back(AB[c_pos][i]);
            prepos.push_back(c_pos);
            dist.push_back(c_dist+1);
        }
    }

    std::cout << center_dist + max_dist - 1 << std::endl;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    double x[n];
    double y[n];
    for(int i=0;i<n;i++)cin >> x[i] >> y[i];
    vector<int>v(n);
    for(int i=0;i<n;i++)v[i] = i;
    double summ = 0.0;
    double cnt = 0;
    do{
        cnt+=1.0;
        for(int i=0;i<n-1;i++){
            summ += sqrt((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]]) + (y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]));
        }
    }while(next_permutation(v.begin(),v.end()));

    printf("%.10lf", summ/cnt);
}

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

using namespace std;

int main(){

    int n, m;
    cin >> n >> m;

    int l[m], r[m];
    for(int i=0; i<m; i++){
        cin >> l[i] >> r[i];
    }

    int l_prime = *max_element(l, l+m);
    int r_prime = *min_element(r, r+m);

    if(l_prime > r_prime){
        cout << '0' << endl;
        return 0;
    }

    cout << r_prime - l_prime + 1 << endl;

    return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999

struct cost{
	string name;
	double eff;

	bool operator<(const cost& a) const{
		if(eff != a.eff) return eff > a.eff;
		if(name != a.name) return name < a.name;
	}
};

int main(){
	double p, a, b, c, d, e, f, s, m;
	int n, i, j;
	string l;
	cost ls[51];
	while(1){
		cin >> n;
		if(!n) break;
		for(i=0;i<n;i++){
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			ls[i].name = l;
			ls[i].eff = (s*f*m-p)/(a+b+c+(d+e)*m);
		}
		sort(&ls[0], &ls[n]);
		for(i=0;i<n;i++){
			cout << ls[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

struct UF{
    vector<int> d;
    UF(int size):d(size,-1){}
    bool u(int x,int y){
        x = r(x); y = r(y);
        if(x != y){
            if(d[y] < d[x]) swap(x,y);
            d[x] += d[y]; d[y] = x;
        }
        return x!=y;
    }
    bool f(int x,int y){
        return r(x) == r(y);
    }
    int r(int x){
        return d[x] < 0 ? x:d[x] = r(d[x]);
    }
    int s(int x){
        return -d[r(x)];
    }
};

//const ll MAX_PRIME = 200000;
//vector<int> primes;
//vector<int> is_prime(MAX_PRIME + 1,true);
//void init_primes(){
//    is_prime[0] = is_prime[1] = false;
//    for(int i = 2; i <= MAX_PRIME;i++){
//        if(is_prime[i]){
//            primes.push_back(i);
//            for(int j = i*2;j<=MAX_PRIME;j+=i) is_prime[j] = false;
//        }
//    }
//}
//void solveF(){
//    init_primes();
//    ll N,P;
//    vector<ll> sum;
//    while(cin >> N >> P){
//        if(N == -1 && P == -1) break;
//        sum.clear();
//        auto idx = upper_bound(primes.begin(),primes.end(),N) - primes.begin();
//        for(int i = 0; i <= P;i++){
//            for(int j = i; j <= P;j++){
//                ll S = primes[idx+i] + primes[idx+j];
//                sum.push_back(S);
//            }
//        }
//        sort(sum.begin(),sum.end());
//        cout << sum[P-1] << endl;
//    }
//}

double func(ll P,ll A,ll B,ll C,ll D,ll E,ll F,ll S,ll M){
    double ret = 0;
    ll sum = M*F*S;
    ll kouritu = sum - P;
    ll T = A + B + C + D + E + (D + E)*(M-1);
    ret = kouritu/(double)T;
    return ret;
}
void solveG(){
    int N;
    while(cin >> N,N){
        vector<pair<double,string>> ans(N);
        for(int i = 0; i < N;i++){
            string L; cin >> L;
            ll P,A,B,C,D,E,F,S,M; cin >> P >> A >> B >> C >> D >> E >> F >> S >> M;
            ans[i] = {pair<double,string>{-func(P,A,B,C,D,E,F,S,M),L}};
        }
        sort(ans.begin(),ans.end());
        for(int i = 0; i < N;i++){
            cout << ans[i].second << endl;
        }
        cout << "#" << endl;
    }
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    //solveF();
    solveG();
    return 0;
}


#include<stdio.h>

int main(void){
int a,i;
scanf("%d",&a);
int x[a];
for(i=0;i<a;i++){
	scanf("%d",&x[i]);
}
for(i=0;i<a;i++){
	printf("%d",x[a-i-1]);
	if(i!=a-1){
	printf(" ");
	}else{
	printf("\n");
	}
}
}

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int n, num[105];
    while(cin >> n){
        rep(i,n){
            cin >> num[i];
        }
        for(int i = n - 1; i >= 0; i--){
            if(i != n - 1) cout << ' ';
             cout << num[i];
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin>>N;
    int a[N+1];
    rep(i, 1, N+1) {
        cin>>a[i];
    }
    int b[N+1]={};
    // memset(b, -1, sizeof(int));
    for (int i=N;i>0;--i) {
        for (int j=2*i;j<=N;j+=i) {
            b[i]^=b[j];
        }
        b[i]^=a[i];
    }
    int ans=0;
    rep(i, 1, N+1) {
        if (b[i])++ans;
    }
    cout<<ans<<endl;
    if (ans) {
        rep(i, 1, N+1) {
            if (b[i])cout<<i<<' ';
        }
        cout<<endl;
    }

}
int main()
{
    func();
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
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; }
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

queue<pint> que;

int main(){

    int h,w; cin >> h >> w;
    Graph G(h,vi(w));
    rep(i,h){
        rep(j,w){
        int a; cin >>a;
        G.at(i).at(j) = a;
        }
        if(i%2 == 0){
            rep(k,w){
                if(G.at(i).at(k)%2 == 1) que.push(make_pair(i,k));
            }
        }
        else{
            for(int k = w-1; k>=0; --k){
                if(G.at(i).at(k)%2 == 1) que.push(make_pair(i,k));
            }
        }
    }
    queue<pint> ans;
    while(que.size() > 1){
        int m = que.front().first;
        int n = que.front().second;
        que.pop();
        int mn = que.front().first;
        int nn = que.front().second;
        bool ok = false;
        ans.push(make_pair(m+1,n+1));
        for(int i = m; i < h; ++i){
            if(i%2 == 0){
                for(int j = n+1; j < w; ++j){
                    ans.push(make_pair(i+1,j+1));
                    if(i == mn && j == nn) ok = true;
                    else ans.push(make_pair(i+1,j+1));
                    if(ok) break;
                }
                n = w;
            }
            else{
                for(int j = n-1; j >= 0; --j){
                    ans.push(make_pair(i+1,j+1));
                    if(i == mn && j == nn) ok = true;
                    else ans.push(make_pair(i+1,j+1));
                    if(ok) break;
                }
                n = -1;
            }

            if(ok){
                que.pop();
                break;
            }
        }
    }
    cout << ans.size()/2 << endl;
    while(!ans.empty()){
        cout << ans.front().first sp ans.front().second << " ";
        ans.pop();
        cout << ans.front().first sp ans.front().second << endl;
        ans.pop();
    }
    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<pair<int, int>> pos, neg;
    REP(i, 0, N) {
        string s; cin >> s;
        int lowest = 0, inc = 0;
        for (auto c : s) {
            if (c == '(') {
                inc++;
            } else {
                inc--;
                lowest = min(lowest, inc);
            }
        }
        if (inc > 0) pos.push_back({lowest, inc});
        else neg.push_back({lowest - inc, -inc});
    }

    sort(ALL(pos), greater<pair<int, int>>());
    sort(ALL(neg), greater<pair<int, int>>());

    int curp = 0, curn = 0;
    for (auto p : pos) {
        if (curp + p.first < 0) {
            cout << "No" << endl;
            return 0;
        }
        curp += p.second;
    }
    for (auto n : neg) {
        if (curn + n.first < 0) {
            cout << "No" << endl;
            return 0;
        }
        curn += n.second;
    }

    if (curp == curn) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

const string YES = "Yes";
const string NO = "No";

// up, down, l or r
vector<int> parse(string s)
{
  int cur = 0;
  int minim = 0;
  for (auto c : s)
  {
    if (c == '(')
      cur++;
    else
      cur--;
    chmin(minim, cur);
  }
  if (cur > 0)
  {
    return vector<int>({cur, minim, true});
  }
  return vector<int>({-cur, min(minim - cur, 0), false});
}

bool can_construct(vector<PII> input)
{

  priority_queue<PII> ord;
  for (auto elem : input)
  {
    ord.push(PII(elem.second, elem.first));
  }

  LL cur = 0;
  while (!ord.empty())
  {
    auto val = ord.top();

    if (cur + val.first < 0)
      return false;
    ord.pop();
    cur += val.second;
  }
  return true;
}

bool solve(long long N, std::vector<std::string> S)
{

  vector<PII> left, right;

  LL parity = 0;
  for (auto s : S)
  {
    auto ret = parse(s);
    if (ret[2])
      left.emplace_back(ret[0], ret[1]);
    else
      right.emplace_back(ret[0], ret[1]);
    if (ret[2])
      parity += ret[0];
    else
      parity -= ret[0];
  }
  if (parity != 0)
    return false;

  return can_construct(left) && can_construct(right);
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++)
  {
    std::cin >> S[i];
  }
  if (solve(N, std::move(S)))
    cout << YES << endl;
  else
    cout << NO << endl;
  return 0;
}


#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, t);
  vector<pair<int, int>> f(n);
  rep(i, n) cin >> f[i].first >> f[i].second;
  sort(all(f));
  vector<int> dp(t + 3001);
  int ans = 0;
  rep(i, n) {
    for (int j = t - 1; j >= 0; --j) {
      dp[j + f[i].first] = max(dp[j + f[i].first], dp[j] + f[i].second);
      ans = max(ans, dp[j + f[i].first]);
    }
  }
  out(ans);
}

#include<bits/stdc++.h>

using namespace std;

const int N = 123456;

int n, m, color[N];
vector<int> adj[N];
bool visit[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int a = 0, b = 0, c = 0, number;
  bool ok;
  for (int i = 1; i <= n; ++i) {
    if (!visit[i]) {
      function<void (int, int)> dfs = [&] (int x, int z) {
        ++number;
        visit[x] = true;
        color[x] = z;
        for (auto y : adj[x]) {
          if (!visit[y]) {
            dfs(y, !z);
          } else if (color[y] != (!z)) {
            ok = false;
          }
        }
      };
      number = 0;
      ok = true;
      dfs(i, 0);
      if (number == 1) {
        ++a;
      } else if (!ok) {
        ++b;
      } else {
        ++c;
      }
    }
  }
  long long answer = 0;
  answer += (long long) a * a;
  answer += (long long) a * (n - a) << 1;
  answer += (long long) b * b;
  answer += (long long) b * c << 1;
  answer += (long long) c * c << 1;
  cout << answer << '\n';
  return 0;
}


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

class Dice{
public:
	int l1,l2,l3,l4,l5,l6;

	void East(){
		int t = l1;
		l1 = l4;
		l4 = l6;
		l6 = l3;
		l3 = t;
	}
	void West(){
		int t = l1;
		l1 = l3;
		l3 = l6;
		l6 = l4;
		l4 = t;
	}
	void South(){
		int t=l1;
		l1 = l5;
		l5 = l6;
		l6 = l2;
		l2 = t;
	}
	void North(){
		int t=l1;
		l1 = l2;
		l2 = l6;
		l6 = l5;
		l5 = t;
	}
};

int main() {

	Dice dice;
	int l1,l2,l3,l4,l5,l6;
	char d;

	cin>>l1>>l2>>l3>>l4>>l5>>l6;
	dice.l1 = l1;
	dice.l2 = l2;
	dice.l3 = l3;
	dice.l4 = l4;
	dice.l5 = l5;
	dice.l6 = l6;

	while(cin>>d){
		if(d=='E')dice.East();
		else if(d=='W')dice.West();
		else if(d=='S')dice.South();
		else dice.North();
	}

	cout<<dice.l1<<endl;
}

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

#define DEBUG(x) cerr << #x << " = " << x << endl

enum FACE { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM }; // 1..6
typedef array<int, 6> Dice;

FACE tbl[6][4] = {
  { TOP, BACK, BOTTOM, FRONT },
  { TOP, RIGHT, BOTTOM, LEFT },
  { TOP, FRONT, BOTTOM, BACK },
  { TOP, LEFT, BOTTOM, RIGHT },
  { FRONT, RIGHT, BACK, LEFT },
  { FRONT, LEFT, BACK, RIGHT }
};

enum MOVE { TOP_TO_BACK, TOP_TO_RIGHT, TOP_TO_FRONT, TOP_TO_LEFT, FRONT_TO_RIGHT, FRONT_TO_LEFT };

void rotate(Dice &d, FACE t[4]) {
  int tmp = d[t[3]];
  d[t[3]] = d[t[2]]; d[t[2]] = d[t[1]]; d[t[1]] = d[t[0]]; d[t[0]] = tmp;
}

vector<Dice> generate_all(Dice dice) {
  vector<Dice> res;
  for(int i = 0; i < 6; ++i) {
    for(int j = 0; j < 4; ++j) {
      res.emplace_back(dice);
      rotate(dice, tbl[FRONT_TO_RIGHT]);
    }
    if(i % 2 == 0) rotate(dice, tbl[TOP_TO_BACK]);
    else rotate(dice, tbl[TOP_TO_RIGHT]);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  Dice d;
  cin >> d[TOP];
  cin >> d[FRONT];
  cin >> d[RIGHT];
  cin >> d[LEFT];
  cin >> d[BACK];
  cin >> d[BOTTOM];
  string s; cin >> s;
  for(char c : s) {
    if(c == 'S') {
      rotate(d, tbl[TOP_TO_FRONT]);
    }
    if(c == 'E') {
      rotate(d, tbl[TOP_TO_RIGHT]);
    }
    if(c == 'W') {
      rotate(d, tbl[TOP_TO_LEFT]);
    }
    if(c == 'N') {
      rotate(d, tbl[TOP_TO_BACK]);
    }
  }
  cout << d[TOP] << endl;
}


#include<bits/stdc++.h>
#define MAXN 1000005
#define P int(998244353)
using namespace std;
typedef long long ll;

int N,M;
ll fac[MAXN], ifac[MAXN];

ll qpow(ll x, int n){
	ll res = 1;
	while(n){
		if(n&1) res = res * x % P;
		x = x * x % P;
		n /= 2;
	}
	return res;
}

void init(){
	fac[0] = ifac[0] = 1;
	for(int i=1;i<=N+M;i++){
		fac[i] = fac[i-1] * i % P;
		ifac[i] = qpow(fac[i], P-2);
	}
}

ll comb(int n, int k){
	if(k > n) return 0;
	return fac[n] * ifac[k] % P * ifac[n-k] % P;
}

int main(){

//	freopen("1.in", "r", stdin);
//	freopen("1.ans", "w", stdout);

 	cin>>N>>M;
 	if(N < M) swap(N,M);
 	init();

 	ll ans = 0;
 	for(int i=1;i<=M;i++){
 		ans = (ans + comb(N+M-2*i,M-i) * comb(2*i,i) % P) % P;
	}
 	ans = ans * qpow(comb(N+M, M), P-2) % P * qpow(2, P-2) % P;
 	ans = (ans + N) % P;

    cerr<<"ans = "<<ans<<endl;
    printf("%lld\n", ans);

    return 0;
}

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

int n, a[610][610];

void solve(int d)
{
	int num = 0;
	while(d % 4 == 0)
	{
		d /= 4;
		++num;
	}
	if(d % 4 == 1)
	{
		for(int i = 0; i < 2 * n; ++i)
			for(int j = 0; j < 2 * n; ++j)
				if(((i >> num) + (j >> num)) & 1) a[i][j] = 1;
	}
	else
	{
		for(int i = 0; i < 2 * n; ++i)
			for(int j = 0; j < 2 * n; ++j)
				if((i >> num) & 1) a[i][j] = 1;
	}
}

int main()
{
	int d1, d2, sum = 0, flag = 0;
	scanf("%d", &n);
	scanf("%d", &d1); solve(d1);
	scanf("%d", &d2); solve(d2);
	for(int i = 0; i < 2 * n && !flag; ++i)
		for(int j = 0; j < 2 * n && !flag; ++j)
			if(!a[i][j])
			{
				printf("%d %d\n", i, j);
				if(++sum == (n * n)) flag = 1;
			}
	return 0;
}


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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xv(n);
  vector<int> yv(m);
  int xmax = x;
  int ymin = y;
  rep(i, n) {
    cin >> xv[i];
    xmax = max(xmax, xv[i]);
  }
  rep(i, m) {
    cin >> yv[i];
    ymin = min(ymin, yv[i]);
  }

  if(xmax < ymin) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}

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

void Input(int*,int*);
int Calc(int*,int*);
void Output(int*,int*,int*);

int main(int argc,char* argv[]){
  int n,count=0;
  int arr[100];

  Input(&n,arr);
  count=Calc(&n,arr);

  Output(&n,&count,arr);

  return 0;
}

void Input(int* pn,int *arr){

  cin>>*pn;
  for(int i=0;i<*pn;i++){
    cin>>*arr++;
  }
}

int Calc(int* pn,int* arr){
  int count=0;

  for(int i=0;i<*pn;i++){
    for(int j=*pn-1;j>i;j--){
      if(arr[j]<arr[j-1]){
	swap(arr[j],arr[j-1]);
	count++;
      }
    }
  }
  return count;
}

void Output(int* pn,int* pcount,int* arr){

  printf("%d",*arr++);
  for(int i=1;i<*pn;i++)
    printf(" %d",*arr++);
  puts("");

  printf("%d\n",*pcount);
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define int ll

main(){
	ll a,b;
	int k;

	cin >> a >> b >> k;

	for(int i=0;i<k;i++){
		if(i%2==0){
			a -= a%2;
			b += a/2;
			a -= a/2;
		}else{
			b -= b%2;
			a += b/2;
			b -= b/2;
		}
	}

	cout << a << " " << b << endl;

	return 0;
}

#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

//ミョ(-ω- ?)
int main() {
    ll a,b;
    cin >> a >> b;
    auto p = prime_factorize(gcd(a,b));
    cout << p.size()+1 << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

class XorBase {
public:
    explicit XorBase(){}
    long long reduce(long long t) const {
        for(auto& b : base) t = min(t, t^b);
        return t;
    }
    bool add(long long t){
        t = reduce(t);
        if(!t) return false;
        base.push_back(t);
        for(int i=base.size()-2;i>=0;i--) if(base[i] < base[i+1]) swap(base[i], base[i+1]);
        return true;
    }
    long long getMax() const {
        long long res = 0;
        for(auto& b : base) res = max(res, res^b);
        return res;
    }
    bool represent(long long t) const { return reduce(t) == 0; }
private:
    vector<long long> base;
};

int solve(const vector<long long>& A, const string& S){
    const int N = A.size();
    XorBase xb;
    for(int i=N-1;i>=0;i--){
        if(S[i] == '0'){
            xb.add(A[i]);
        } else {
            if(!xb.represent(A[i])) return 1;
        }
    }
    return 0;
}

int main(){
    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        vector<long long> A(N);
        for(auto& t : A) cin >> t;
        string S; cin >> S;
        cout << solve(A, S) << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int n;
int a[225];
int main(){
	cin>>n;
	for(int i=1;i<=2*n;i++)cin>>a[i];
	sort(a+1,a+2*n+1);
	int summ=0;
	for(int i=2*n;i>=1;i-=2){
		summ+=a[i-1];
	}
	cout<<summ;
}


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

int main(){
	string S;
	cin >> S;
	if(S.size()==2) {
		cout << S << endl;
	}
	else cout << S[2] << S[1] << S[0] << endl;
}

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

int main(){
  int N,t;

  cin >> N;
  t=N;

  int f=0;

  for(int i=0;i<9;i++){
    f = f+ (t%10);
    t=t/10;
  }

  if(N%f==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}


#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

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

// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k)cout<< ":("<<endl;
    else cout<<"Yay!"<<endl;

    return 0;
}


#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int main(){

  string s;
  int kmax = 0;

  cin >> s;

  for(int i = 0; i < s.size(); i++){
    bool j1, j2;
    int cnt = 0;
    if(s[i] == 'O'){
      j1 = false, j2 = false;
      cnt = 1;
      for(int j = i + 1; s[j] == 'O' && j < s.size(); j++) cnt++;
      for(int j = i - 1, c = 1; s[j] == 'J' && j >= 0; j--, c++){
        if(c == cnt){
          j1 = true;
          break;
        }
      }
      for(int j = i + cnt, c = 1; s[j] == 'I' && j < s.size(); j++, c++){
        if(c == cnt){
          j2 = true;
          break;
        }
      }
    }
    if(j1 && j2) kmax = max(kmax, cnt);
    i += cnt;
  }

  cout << kmax << endl;

}

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

void fail(){
	puts("No");
	exit(0);
}

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

	int n;
	cin >> n;
	vector<vi> a(3, vi(n));
	trav(v, a) trav(x, v) cin >> x;
	vi perm(n);
	bool sign[2] = {};
	rep(i,0,n){
		int ix = (a[0][i]-1)/3;
		if(a[1][i] != 3*ix+2) fail();
		if(min(a[0][i], a[2][i]) != 3*ix+1
			|| max(a[0][i],a[2][i]) != 3*ix+3) fail();
		sign[i&1] ^= a[0][i] > a[2][i];
		perm[i] = ix;
		if((i+ix)&1) fail();
	}
	int numofcycles[2] = {};
	vector<bool> vis(n);
	rep(i,0,n) if(!vis[i]){
		++numofcycles[i&1];
		int j = i;
		do {
			vis[j] = 1;
			j = perm[j];
		} while(j != i);
	}
	int nn[2] = {n/2+(n&1), n/2};
	if(sign[0] != (nn[1]+numofcycles[1])%2
		|| sign[1] != (nn[0]+numofcycles[0])%2)
		fail();
	puts("Yes");
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    rep(i,0,n) {
        int outcnt = 0, ans = 0;
        int bit = 0;
        while(1) {
            string s; cin >> s;
            if(s == "OUT") outcnt++;
            if(outcnt >= 3) break;

            if(s == "HIT") {
                if(bit >> 2 & 1) ans++;
                bit = (bit << 1 | 1) & ((1 << 3) - 1);
            }
            else if(s == "HOMERUN") {
                ans += (__builtin_popcount(bit) + 1);
                bit = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

#include<iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {

	char str[20];
	int i, len=0;

	cin >> str;

	while (str[len])
		len++;

	for (i = len - 1; i >= 0; i--)
		cout << str[i];

	putchar('\n');

	return 0;

}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string s,ans;cin>>s;
    if(s.size()!=26){
        vector<int> vec(26);
        for(char c:s){
            vec[(c-'a')]++;
        }
        for(int i=0;i<26;i++){
            if(vec[i]==0){
                ans=s+(char)('a'+i);
                break;
            }
        }
    }
    else{
        bool answer=false;
        vector<int> vec(26);
        for(int i=25;i>=0;i--){
            int tmp=s[i]-'a';
            vec[tmp]++;
            for(int j=tmp+1;j<26;j++){
                if(vec[j]){
                    ans=s.substr(0,i)+(char)('a'+j);
                    answer=true;
                    break;
                }
            }
            if(answer)break;
        }
        if(!answer)ans="-1";
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  string s;
  cin>>s;
  int n=len(s);
  vi T(26);
  string t=tr;
  rep(i,n){
    rep(j,26){
      if(s[i]==t[j]){
        T[j]++;
      }
    }
  }
  if(n<26){
    rep(i,26){
      if(T[i]==0){
        s+=t[i];
        break;
      }
    }
    cout<<s<<endl;
    return 0;
  }
  if(n==26){
    vector<char> vec;
    for (int i = 0; i < s.size(); ++i) {
    vec.push_back(s[i]);
    }
    if (next_permutation(s.begin(), s.end())) {
                string res = "";
                for (int i = 0; i < s.size(); ++i) {
                    res += s[i];
                    if (vec[i] != s[i]) break;
                }
                cout << res << endl;
            }
            else {
                cout << -1 << endl;
            }
  }
}


#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  vector<int> c(n+1);
  c[0] = 3;
  ll ans = 1;
  REP(i,n) {
    ans*=c[a[i]];
    ans%=MOD;
    c[a[i]]--;
    c[a[i]+1]++;
  }
  COUT(ans);
  return 0;
}

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

int main() {
    int n;
    long long int ans = 3;
    cin >> n;
    int a[n], rgb[3] = {0};
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
  	if(a[0] != 0) {
    	cout << 0 << '\n';
      	return 0;
    }
    rgb[0] = 1;
    for(int i = 1; i < n; ++i) {
        int sum = 0;
        for(int j = 0; j < 3; ++j) {
            if(rgb[j] == a[i]) sum++;
        }
        ans *= sum;
        ans %= MOD;
        for(int j = 0; j < 3; ++j) {
            if(rgb[j] == a[i]) {
                rgb[j]++;
                break;
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2;
    cout << (t2-k-t1) << endl;
    return 0;
}

#include<iostream>
#include<cstdio>

int main() {
    int n;
    std::cin >> n;
    printf("%d\n", n * n * n);
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 205;

int arr [MAX_N];

int main () {
  int n;
  cin >> n;

  n *= 2;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  sort(arr, arr + n);

  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    ans += arr[i];
  }

  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[2*n];
	for(int i=0;i<2*n;i++)
	cin>>a[i];
	sort(a,a+2*n);
	int sum=0;
	for(int i=0;i<2*n-1;i+=2)
	sum+=min(a[i],a[i+1]);
	cout<<sum;

}


#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N;
	cin >> N;

	vector<int> A(N), v(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<int> C;
	for (int i = N - 1; i >= 0; i--) {
		int n = i + 1;
		int c = 0;
		for (int j = i; j < N; j += n) {
			if (v[j]) c++;
		}
		c %= 2;
		//cout << c << endl;
		v[i] = A[i] - c;
		if (v[i]) C.push_back(i + 1);
	}
	sort(C.begin(), C.end());

	cout << C.size() << endl;
	if (C.size()) {
		for (int i = 0; i < C.size(); i++) {
			if (i) cout << ' ';
			cout << C[i];
		}
		cout << endl;
	}
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;

const ll INF = 1e18;
const ll N =(2e5+5); // TODO : change value as per problem
const ll MOD = 1e9+9;
const ll p = 1000003;
long long compute_hash(vll v){
    ll ans = 0;
    ll p_pow = 1;
    for(int i =0;i<5;i++){
        ans = (ans + v[i] * p_pow) % MOD;
        p_pow = (p_pow * p)%MOD;
    }
    return ans;
}
ll a[N];
ll cnt[N];
void solve(){
    ll n;
    cin >> n;
    for(int i =1;i<=n;i++) cin >> a[i];

    for(int i =n;i>=1;i--){
        ll co = 0;
        for(ll j = 2*i;j<=n;j+=i){
            co += cnt[j];
        }
        if((co&1) == (a[i]&1)){
            cnt[i] = 0;
        }
        else{
            cnt[i] = 1;
        }
    }
    vll ans;
    bool poss = true;
    for(int i = 1;i<=n;i++){
        ll co = 0;
        for(int j = i;j<=n;j+=i){
            co += cnt[j];
        }
        if(cnt[i] == 1) ans.pb(i);
        poss &= ((co&1) == (a[i]&1));
    }
    if(!poss){
        cout << -1 << endl;
        return;
    }
    cout << sz(ans) << endl;
    for(auto x:ans) cout << x << " ";cout << endl;
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

     ll tt=1;
     // cin >> tt;
    while(tt--){
        solve();
    }
}


#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

long long GCD(long long a, long long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N);

    rep(i, N) {
        cin >> A[i];
        if (A[i] == K) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    ll m = *max_element(all(A));
    ll gcd = A[0];
    rep(i, N) { gcd = GCD(gcd, A[i]); }

    if (m < K) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    if (gcd == 1) {
        cout << "POSSIBLE" << endl;
        return 0;
    }
    if (K % gcd == 0) {
        cout << "POSSIBLE" << endl;
        return 0;
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
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; }
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
Vi a;
ll cal(ll n){
	switch(n){
		case 1:
			return 2;
			break;
		case 2:
		case 3:
		case 5:
			return 5;
			break;
		case 4:
			return 4;
			break;
		case 6:
			return 6;
			break;
		case 7:
			return 3;
			break;
		case 8:
			return 7;
			break;
		case 9:
			return 6;
			break;
		default:
			return 0;
			break;
	}
}

vector<string> dp;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n>>m;
	a.resize(m);
	rep(i,m){
		cin>>a[i];
	}
	dp.resize(n+10,"-1");
	dp[0]="";
	rep(i,n){
		if(dp[i]=="-1")continue;
		rep(j,a.size()){
			ll tmp = i+cal(a[j]);
			string fig = dp[i]+(char)('0'+a[j]);
			string now = dp[tmp];
			if(now=="-1" || now.size()<fig.size()){
				dp[tmp] = fig;
			}else if(now.size()>fig.size()){

			}else{
				chmax(dp[tmp],fig);
			}
		}
	}
	print(dp[n]);
	return 0;
}


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

int main(){
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for(int i = 1; i <= N - K + 1; ++i) {
		ans++;
	}
	cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
}


#include <bits/stdc++.h>

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   string s;cin >>s;
   if(s.size()==3)reverse(all(s));
   cout << s<< endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

int main(){
	string s; cin>>s;
  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
  else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << 2 << endl;
  else if (s[0] == s[1] && s[1] == s[2] && s[0] == 'S') cout << 0 << endl;
  else cout << 1 << endl;
}


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

int main()
{
  string s;
  int cnt = 0;
  cin >> s;

  if (s[0] != 'A')
  {
    cout << "WA" << endl;
    return 0;
  }

  for (int i = 1; i < s.length(); i++)
  {
    if (i > 1 && i < s.length() - 1)
    {
      if (s[i] == 'C')
      {
        if (cnt == 0)
        {
          cnt = 1;
          continue;
        }
        else
        {
          cout << "WA" << endl;
          return 0;
        }
      }
    }
    if (s[i] - '0' >= 17 && s[i] - '0' <= 42)
    {
      cout << "WA" << endl;
      return 0;
    }
  }
  if (cnt == 0)
  {
    cout << "WA" << endl;
    return 0;
  }

  cout << "AC" << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    string s; cin >> s;
	int n = s.size();
	if(s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	if(n != 26) {
		for(char a = 'a'; a <= 'z'; a++) {
			if(count(s.begin(), s.end(), a) == 0) {
				cout << s << a << endl;
				return 0;
			}
		}
	}
	string k = s;
	next_permutation(k.begin(), k.end());
	for(int i = 0; i < n; i++){
		if(s[i] != k[i]) {
			cout << k.substr(0, i + 1) << endl;
            system("pause");
			return 0;
		}
	}

    system("pause");
}


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

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

#include <iostream>
using namespace std;

int main()
{
  string test;
  getline(cin,test);

  if (test[0] == 'A' && test[1] == 'C')
  {
    cout << "Yes" << endl;
  }
  else if(test[1] == 'A' && test[2] == 'C')
  {
    cout << "Yes" << endl;
  }
  else if(test[2] == 'A' && test[3] == 'C')
  {
    cout << "Yes" << endl;
  }
  else if(test[3] == 'A' && test[4] == 'C')
  {
    cout << "Yes" << endl;
  }
  else
  cout << "No" << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for(i = 0; i < n; i++) {
        cin >> x[i];
    }
    for(i = 0; i < m; i++) {
        cin >> y[i];
    }
    ll retx = 0;
    for(k=0;k<n;k++){
        retx = (retx + k*x[k] - (n-1-k)*x[k])%MOD;
    }
    ll rety=0;
    for(k = 0; k < m; k++) {
        rety = (rety + k * y[k] - (m - 1 - k) * y[k]) % MOD;
    }

    cout << (rety*retx)%MOD << endl;
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;
struct edge{int to, cost;};

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

template <typename T>
vector<pair<T, T>> prime_factor(T n){
    vector<pair<T, T>> ret;
    for(T i=2; i*i<=n; i++){
        T tmp=0;
        while(n%i == 0){
            tmp++;
            n/=i;
        }
        if(tmp > 0) ret.push_back({i, tmp});
    }
    if(n != 1) ret.push_back({n, 1});
    return ret;
}

const int MAX=1001001;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD; //i!の計算
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; //iの逆元の計算
        finv[i] = finv[i - 1] * inv[i] % MOD; //i!の逆元の計算
    }
}

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

int main(){
    ll N, M; cin >> N >> M;

    vector<pii> p=prime_factor((int)M);
    COMinit();
    ll ans=1;
    for(int i=0; i<(int)p.size(); i++){
        ans=(ans*COM(p[i].second+N-1, N-1))%MOD;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m>>n>>o>>p)
    {
        if(m+n>o+p)
            cout<<"Left"<<endl;
        else if(m+n<o+p)
            cout<<"Right"<<endl;
        else
            cout<<"Balanced"<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int left = a + b, right = c + d;

  if (left > right) cout << "Left" << "\n";
  else if (left < right) cout << "Right" << "\n";
  else cout << "Balanced" << "\n";
}


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

int main() {
  int N;
  cin >> N;
  int f = 0, j = 1;
  while(N >= (j / 10)){
      j *= 10;
      f += N % j / (j / 10);
  }
  if (N % f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

vector<bool> isp;
vector<ll> prime;

void sieve(int x=pow(10,6)+10) {
  isp.resize(x,true);
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=x; i++) {
    if (isp[i]) for(int j=2; i*j<=x; j++) isp[i*j] = false;
  }
  rep(i,x+1) if (isp[i]) prime.push_back(i);
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  sieve();
  int N; cin >> N;
  int tn = N%2==0 ? N+1 : N;
  ll result[tn][tn] = {}; rep(i,tn) fill_n(result[i],tn,1);
  rep(i,tn) rep(j,tn) if ((i+j)%2==0) result[i][j] = prime[(i+j)/2] * prime[tn+((tn-1-i)+j)/2];
  rep(i,tn) rep(j,tn) {
    if ((i+j)%2==1) {
      if (i!=0)    result[i][j] = lcm(result[i][j], result[i-1][j]);
      if (i!=tn-1) result[i][j] = lcm(result[i][j], result[i+1][j]);
      if (j!=0)    result[i][j] = lcm(result[i][j], result[i][j-1]);
      if (j!=tn-1) result[i][j] = lcm(result[i][j], result[i][j+1]);
      result[i][j]++;
    }
  }
  // ll r = 0; rep(i,N) rep(j,N) r = max(r, result[i][j]);
  // cout << r << endl;
  rep(i,N) debug(result[i],result[i]+N);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
const int64_t MOD = 1000000007;
int64_t fac[MAX], finv[MAX], inv[MAX];

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

int64_t COM(int64_t n, int64_t k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<int64_t, int64_t>> prime_factorize(int64_t N)
{
  vector<pair<int64_t, int64_t>> res;
  for (int64_t a = 2; a * a <= N; a++)
  {
    if (N % a != 0)
      continue;
    int64_t ex = 0;
    while (N % a == 0)
    {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int64_t nHk(int64_t n, int64_t k)
{
  if (k == 1)
  {
    return n;
  }
  return COM(n + k - 1, k);
}

int main()
{
  int64_t N, M, ans = 1;
  cin >> N >> M;
  const auto &res = prime_factorize(M);
  COMinit();
  for (auto p : res)
  {
    (ans *= nHk(N, p.second)) %= MOD;
  }
  cout << ans << endl;
}

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

vector<int> primes={2,3,5,7};
int primes_extend(int calc_from, int calc_to);
int factoring(int n, map<int,int> &factors);

const int combination_max=100000+1000;
const int combination_modulo=1000000007;
vector<int64_t> factorials(combination_max);
vector<int64_t> factorials_inv(combination_max);
vector<int64_t> inverse(combination_max);
int combination_mod(int n, int k);
int prepare_combination_mod();

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

	primes_extend(10,100);
	primes_extend(100,10000);
	primes_extend(10000,32767);

	map<int,int> factors;
	factoring(m,factors);
	for (pair<int,int> p:factors)
	{
	 	// fprintf(stderr,"%d: %d\n",p.first,p.second);
	}

	prepare_combination_mod();

	int64_t patterns=1;
	for (pair<int,int> p:factors)
	{
		int c=combination_mod(p.second+n-1,n-1);
		// fprintf(stderr,"%d: %d patterns\n",p.first,c);
		patterns*=c;
		patterns%=combination_modulo;
	}
	cout << patterns << endl;
}

int primes_extend(int calc_from, int calc_to)
{

	for (int i=calc_from;i<=calc_to;++i)
	{
		int j;
		int loop_max=sqrt(i);
		for (j=0;(primes[j]<=loop_max)&&(j<primes.size());++j)
		{
			if ((i%primes[j])==0)
			{
				// not prime...
				break;
			}
		}
		if ((j>=primes.size())||(primes[j]>loop_max))
		{
			primes.push_back(i);
		}
	}
	//fprintf(stderr,"count: %d\n",primes.size());
}

int factoring(int n, map<int,int> &factors)
{
	int maxfactor=sqrt(n);
	for (int i=0;(n>1)&&(primes[i]<=maxfactor);++i)
	{
		while ((n%primes[i])==0)
		{
			n/=primes[i];
			factors[primes[i]]++;
		}
	}
	if (n!=1)
	{
		factors[n]++;
	}

	return 0;
}

int prepare_combination_mod()
{
	factorials[0]=1;
	factorials[1]=1;
	factorials_inv[0]=1;
	factorials_inv[1]=1;
	inverse[1]=1;
	for (int i=2;i<combination_max;++i)
	{
		factorials[i]=factorials[i-1]*i%combination_modulo;
		inverse[i]=combination_modulo - inverse[combination_modulo%i]*(combination_modulo/i)%combination_modulo;
		factorials_inv[i]=factorials_inv[i-1]*inverse[i]%combination_modulo;
	}
}

int combination_mod(int n, int k)
{
	return factorials[n]*(factorials_inv[k]*factorials_inv[n-k]%combination_modulo)%combination_modulo;
}


#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int n,k;
        cin>>n>>k;
        double arr[n];
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            arr[i] = (arr[i]+1)/2;
        }
        double sum = 0;
        for(int i=0;i<k;i++)
        {
            sum+=arr[i];
        }
        double maxi = sum;
        for(int i=k;i<n;i++)
        {
            sum+=arr[i];
            sum-=arr[i-k];
            maxi = max(sum,maxi);
        }
        cout<<fixed<<setprecision(15)<<maxi;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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 gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  ll N,K; cin>>N>>K;
  vector<ll> v(N);
  rep(i,0,N){
    cin >> v[i];
    v[i]++;
  }
  vector<ll> v2(N+1, 0);
  rep(i,0,N) v2[i+1] = v2[i] + v[i];
  ll res = 0;
  for(ll i=0 ; i+K<=N ; i++){
    chmax(res, v2[i+K] - v2[i]);
  }
  printf("%.7f", (double)res/2);
  return 0;
}


#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
using namespace std;
typedef pair<int,int> pii;
const int N = 1e4+10;

string dp[N], val[15];
string num = "123456789";
int c[] = {2,5,5,4,5,6,3,7,6}, cs[200], n, m;
string a[15];

void update (string &x, string y, string z)
{
    if (x.size() > y.size() + 1) return;
    if (z[0] > y[0]) z += y, swap(y, z);
    else y += z;
    if (x.size() < y.size()) x = y;
    else
    {
        for (int i=0; i<x.size(); i++)
        {
            if (x[i] > y[i]) return;
            else if (x[i] < y[i])
            {
                x = y;
                break;
            }
        }
    }
}

signed main()
{
    XinAi
    for (int i=0; i<9; i++) cs[num[i]] = c[i];
    cin >> n >> m;
    for (int i=0; i<m; i++) cin >> a[i];
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
        {
            if (i!=0 && dp[i]=="") continue;
            update(dp[i+cs[a[j][0]]], dp[i], a[j]);
        }
    cout << dp[n] << '\n';
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  rep(_, q) {
    int k;
    cin >> k;
    i64 d = 0;
    i64 m = 0;
    i64 dm = 0;
    i64 ans = 0;
    for (int r = 1; r <= n; r++) {
      if (s[r - 1] == 'D') {
        d++;
      } else if (s[r - 1] == 'M') {
        m++;
        dm += d;
      }
      if (r - k > 0) {
        int rem = r - k - 1;
        if (s[rem] == 'D') {
          d--;
          dm -= m;
        } else if (s[rem] == 'M') {
          m--;
        }
      }
      if (s[r - 1] == 'C') {
        ans += dm;
      }
    }
    cout << ans << 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;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    rep(i, n) {
        ll x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll y = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += x * y;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,cnt = 0;
  cin >> N;
  int bubble[N];
  for(int i=0;i<N;i++){
    cin >> bubble[i];
  }

  double flag = true;
  while(flag){
    flag = false;
    for(int j=N-1;j>=1;j--){
      if(bubble[j] < bubble[j-1]){
	swap(bubble[j],bubble[j-1]);
	cnt++;
	flag = 1;
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i!= N-1){
    cout << bubble[i] << " ";
    }
    else{
      cout << bubble[i] << endl;
    }
  }
  cout << cnt << endl;
}


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

#define ll long long
#define pll pair<ll,ll>

#define left 2*node+1
#define right left+1
#define mid (s+e>>1)

const ll N=5e5+5;
vector<ll> T[4*N];

void build(ll A[], ll node, ll s, ll e){
	if(s==e){
		T[node].push_back(A[s]);
		return;
	}
	build(A, left, s, mid);
	build(A, right, mid+1, e);
	merge(T[left].begin(), T[left].end(), T[right].begin(), T[right].end(), back_inserter(T[node]));
}

ll query(ll node,ll s, ll e, ll x, ll y){
	if(e<s || s>y || e<x)
		return 0;
	if(x<=s && e<=y){
		ll a=upper_bound(T[node].begin(), T[node].end(), y)-T[node].begin();
		return T[node].size()-a;
	}
	ll p1=query(left, s, mid, x, y);
	ll p2=query(right, 1+mid,e, x, y);
	return p1+p2;
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n, q;
	cin>>n>>q;
	ll A[n];
	ll B[n];
	for(ll i=0;i<n;i++)
		cin>>A[i];
	map<ll,ll> M;
	for(ll i=n-1;i>=0;i--){
		if(M.count(A[i]))
			B[i]=M[A[i]];
		else
			B[i]=INT_MAX;
		M[A[i]]=i;
	}

	build(B,0,0, n-1);

	while(q--){
		ll x, y;
		cin>>x>>y;
		ll ans=query(0,0,n-1,x-1,y-1);
		cout<<ans<<"\n";
	}

}

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

int main()
{
	int D, G, p[11], c[11];
	cin >> D >> G;
	for (int i = 0; i < D; ++i)
		cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int mask = 0; mask < 1 << D; ++mask)
	{
		int sum = 0, num = 0;
		for (int i = 0; i < D; ++i)
		{
			if (mask & 1 << i)
			{
				sum += (i + 1) * 100 * p[i] + c[i];
				num += p[i];
			}
		}
		if (sum >= G)
		{
			ans = min(ans, num);
		}
		else
		{
			for (int i = D - 1; i >= 0; --i)
			{
				if (mask & 1 << i)
				{
					continue;
				}
				for (int j = 0; j < p[i]; j++)
				{
					if (sum >= G)
					{
						break;
					}
					sum += 100 * (i + 1);
					num++;
				}
			}
			ans = min(ans, num);
		}
	}
	cout << ans << endl;
}


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

int n, k;
int a[10];
int v[10000] = {};
int s;

void set_vec(int t, int f, int sum) {
	if(t>=k) {
		v[s] = sum;
		s++;
	}else {
		for(int i=0;i<n;i++) {
			if((1<<i) & f)continue;
			set_vec(t+1, f+(1<<i), sum*(a[i]<10?10:100)+a[i]);
		}
	}
}

int main() {

	while(1) {
		scanf("%d", &n);
		scanf("%d", &k);
		if(n==0 && k==0)break;
		s = 0;
		for(int i=0;i<n;i++) {
			scanf("%d", &a[i]);
		}

		set_vec(0, 0, 0);

		sort(v, v+s);

		int t = 0;
		int sum = 0;

		for(int i=0;i<s;i++) {
			if(t==v[i])continue;
			sum++;
			t=v[i];
		}

		printf("%d\n", sum);

	}

	return  0;
}

#include <cstdio>

int main(){
	int n, table[20][20];

	while( scanf("%d", &n) , n ){
		for(int i=0 ; i<20 ; i++){
			for(int j=0 ; j<20 ; j++){
				table[i][j] = 0;
			}
		}
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n ; j++){
				scanf("%d", &table[i][j]);
			}
		}
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n ; j++){
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
		}
		for(int i=0 ; i<n ; i++){
			table[n][n] += table[n][i];
		}
		for(int i=0 ; i<=n ; i++){
			for(int j=0 ; j<=n ; j++){
				printf("%5d", table[i][j]);
			}
			printf("\n");
		}

	}

	return 0;
}


#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int size;

    cin >> size;
    long long a[size];
    int i;

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

    long long max=0;

    for(i=0; i<size; i++){
        if(max < a[i] || i==0){
            max = a[i];
        }
        else{
        }
    }

    long long min=0;

    for(i=0; i<size; i++){
        if(min > a[i] || i==0){
            min = a[i];
        }
        else{
        }
    }

    long long sum=0;

    for(i=0; i<size; i++){
        sum+= a[i];
    }

    cout << min << " " << max << " " << sum << endl;
    return 0;
}

#include <stdio.h>

const static int MAX = 100;

void print(int *array, int n){
    for(int i=0;i<n;i++){
        printf("%d", array[i]);
        if(i<n-1) printf(" ");
    }
    printf("\n");
}

int bubble_sort(int *array, int n){
    bool flag = true;
    int k, count=0;
    while(flag){
        flag = false;
        for(int i=n-1;i>0;i--){
            if(array[i] < array[i-1]){
                k = array[i-1];
                array[i-1] = array[i];
                array[i] = k;
                flag = true;
                count++;
            }
        }
    }
    print(array, n);
    return count;
}

int main(){
    int n, array[MAX], c;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &array[i]);
    }
    c = bubble_sort(array, n);
    printf("%d\n", c);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

int main(void){

int cd[5]={0},cnt=0;

char k;
	while(!cin.eof()){
		cin >> cd[0] >> k >>cd[1] >>k >>cd[2] >>k >>cd[3] >>k >>cd[4];
		if(cin.eof()) break;

		sort(cd,cd+5);
		int mxp=0,cn1,cn2=0;
		rep(i,5){
			cn1=0;
			rep2(j,i+1,5) if(cd[i]==cd[j]) cn1++;
			cn2 += cn1;
			mxp = max(mxp,cn1);
		}
//		printf("%d,%d\n",mxp,cn2);
		string yak = "straight";
		rep(i,4) if(cd[i] +1 != cd[i+1]) yak="null";
		if(cd[0]==1 && cd[1]==10 && cd[2]==11 && cd[3]==12 && cd[4]==13)
					yak = "straight";
		if(mxp==1 && cn2==1) yak ="one pair";
		if(mxp==1 && cn2==2) yak ="two pair";
		if(mxp==2 && cn2==3) yak ="three card";
		if(mxp==2 && cn2==4) yak ="full house";
		if(mxp==3) yak ="four card";
		cout << yak << endl;
		cnt++; if(cnt>50) break;
	}

	return 0;

}