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

class Node{
public:
	vector< int > e_to;
	vector< int > e_cost;

	bool def;
	int min_cost;

	Node(){
		def = false;
		min_cost = -1;
	}
};
bool operator==(const Node& ot1, const Node& ot2){
	return ot1.min_cost == ot2.min_cost;
}
bool operator!=(const Node& ot1, const Node& ot2){
	return !(ot1 == ot2);
}
bool operator<(const Node& ot1, const Node& ot2){
	return ot1.min_cost < ot2.min_cost;
}
bool operator>(const Node& ot1, const Node& ot2){
	return ot1.min_cost > ot2.min_cost;
}
bool operator<=(const Node& ot1, const Node& ot2){
	return !(ot1 > ot2);
}
bool operator>=(const Node& ot1, const Node& ot2){
	return !(ot1 < ot2);
}

int main(){
	int v, e, r, s, t, d;
	vector< Node > nodes;
	priority_queue< Node, vector< Node >, greater< Node > > que;

	cin >> v >> e >> r;
	nodes.resize(v);

	for(int i = 0; i < v; ++i){
		nodes[i] = Node();
	}

	for(int i = 0; i < e; ++i){
		cin >> s >> t >> d;
		nodes[s].e_to.push_back(t);
		nodes[s].e_cost.push_back(d);
	}

	nodes[r].min_cost = 0;

	que.push(nodes[r]);

	while(!que.empty()){
		Node def_node = que.top();
		que.pop();

		if(def_node.def)continue;

		def_node.def = true;

		for(int i = 0; i < def_node.e_to.size(); ++i){
			int to = def_node.e_to[i];
			int cost = def_node.min_cost + def_node.e_cost[i];

			if(nodes[to].min_cost == -1 || cost < nodes[to].min_cost){
				nodes[to].min_cost = cost;
				que.push(nodes[to]);
			}
		}
	}

	for(int i = 0; i < v; ++i){
		if(nodes[i].min_cost == -1) cout << "INF" << endl;
		else cout << nodes[i].min_cost << endl;
	}

	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int a[100][100],b[100][100];
main()
{
	while(cin>>m>>n,n)
	{
    	for(int i=0;i<n;i++)for(int j=0;j<n;j++)
    	{
    		if(i==j)continue;
    		a[i][j]=1e9;
    		b[i][j]=1e9;
    	}
    	for(int i=0;i<m;i++)
    	{
    		int s,t,u,v;cin>>s>>t>>u>>v;
    		s--,t--;
    		a[s][t]=min(a[s][t],u);
    		a[t][s]=min(a[t][s],u);
    		b[s][t]=min(b[s][t],v);
    		b[t][s]=min(b[t][s],v);
    	}
    	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
    	{
    		a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    		b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
    	}
    	int k;cin>>k;
    	for(;k--;)
    	{
    		int p,q,r;cin>>p>>q>>r;
    		p--,q--;
    		if(r)cout<<b[p][q]<<endl;
    		else cout<<a[p][q]<<endl;
    	}
	}
}


#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, H, W;

signed main(){
    cin >> N >> H >> W;
    cout << max(0, N-H+1)*max(0, N-W+1) << endl;
}

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

int main() {
  int n,h,w;
  cin >> n >> h >> w;
  int a = 0;
  int b = 0;
  for(int i = 1; i <= n; i++){
    if(i+w-1 <= n) a++;
    if(i+h-1 <= n) b++;
  }
  cout << a*b << endl;
  return 0;
}


#include<iostream>
using namespace std;

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

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

int abs(int x) {

    if (x < 0) {
        return -x;
    } else {
        return x;
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum = sum + a.at(i);
    }

    int ans = 100000;
    int memo;
    for (int i = 0; i < N; i++) {
        if (ans > abs(a.at(i)*N-sum)) {
            ans = abs(a.at(i)*N-sum);
            memo = i;
        }
    }
    cout << memo << endl;
}


# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int m, d;
	while (cin >> m >> d&&m != 0 && d != 0) {
		int sum = 0;
		for (int i = 1; i < m; i++) {
			if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
				sum += 31;
			}
			else if (i == 2) {
				sum += 29;
			}
			else {
				sum += 30;
			}
		}
		sum += d;
		if (sum % 7 == 1) {
			cout << "Thursday" << endl;
		}
		else if (sum % 7 == 2) {
			cout << "Friday" << endl;
		}
		else if (sum % 7 == 3) {
			cout << "Saturday" << endl;
		}
		else if (sum % 7 == 4) {
			cout << "Sunday" << endl;
		}
		else if (sum % 7 == 5) {
			cout << "Monday" << endl;
		}
		else if (sum % 7 == 6) {
			cout << "Tuesday" << endl;
		}
		else {
			cout << "Wednesday" << endl;
		}
	}
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
	int a,b,month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	string week[]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
	while(cin>>a>>b){
		if(a==0 && b==0)break;
		for(int i=1;i<a;i++){
			b+=month[i];
		}
		cout<<week[b%7]<<endl;
	}
	return 0;
}


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

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
int main(void) {
    Int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}

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

/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/

bool IsPrime(int n){
    if (n<2) return false;
    else if (n==2) return true;
    else if (n%2==0) return false;
    double q=sqrt(n);
    for(int i=3;i<q+1;i+=2){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    // 1~55555 で 5の倍数+1 の素数を列挙
    Vl sosu;
    for(ll i = 1; i <= 55555; i += 5){
        if(IsPrime(i)) sosu.push_back(i);
    }
    ll n; cin >> n;
    rep(i, 0, n) cout << sosu[i] << " \n"[i==n-1];

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod ll(1e9+7)
ll exp(ll a,ll b)
{
  if(b==0)
    return 1;
  if(b%2==0)
    return exp(a*a%mod,b/2);
  return a*exp(a*a%mod,(b-1)/2)%mod;
}
int main()
{
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
   int n,k;
   cin>>n>>k;
   vector<int>arr(n+1);
   for(int i=1; i<=n; i++){
    cin>>arr[i];
   }
   int mx=0;
   for(int i=0; i<=k; i++){
    for(int j=0; j<=(k-i); j++){
      if(i+j>=n){
        vector<int>ans;
        int sum=0;
        for(int x=1; x<=n; x++){
          sum+=arr[x];
          ans.push_back(arr[x]);
        }
        sort(ans.begin(),ans.end());
        int num=min(n,k-n);
        for(int x=0; x<num; x++){
          if(ans[x]>=0)
            break;
          sum-=ans[x];
        }
        mx=max(sum,mx);
      }
      else{
        vector<int>ans;
        int sum=0;
        for(int x=1; x<=i; x++){
          ans.push_back(arr[x]);
          sum+=arr[x];
        }
        for(int x=n; x>=(n-j+1); x--){
          ans.push_back(arr[x]);
          sum+=arr[x];
        }
        int num=min(i+j,k-(i+j));
        sort(ans.begin(),ans.end());
        for(int x=0; x<num; x++){
          if(ans[x]>=0)
            break;
          sum-=ans[x];
        }
        mx=max(sum,mx);
      }
    }
   }
   cout<<mx;
   return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    int N,K;
    cin >> N >> K;
    deque<int> V_origin;
    REP(i,N){
        int v;
        cin >> v;
        V_origin.push_back(v);
    }

    int ans = 0;
    int KK = K;
    K = min(K,N);

    REP(i,K/2+1){
        REP(j,K-i+1){
            //cout << "front: "<< j <<  ", back: " << K-i-j << ", return: " << i << endl;
            deque<int> V(V_origin);
            vector<int> my;
            REP(k,j){
                int d = V.front();
                V.pop_front();
                my.push_back(d);
            }
            FOR(k,j+1,K-i+1){
                int d = V.back();
                V.pop_back();
                my.push_back(d);
            }
            sort(ALL(my));

            REP(x,KK-K+i+1){
                int count = 0;
                FOR(k,x,my.size()){
                    count += my[k];
                }
                ans = max(ans,count);
                //cout << count << endl;
            }
        }
    }
    ans = max(ans, 0);
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>
#define INF 2147483647
#define max_n 1000000
using namespace std;
int a[max_n+1];
long long psm[max_n+2],nsm[max_n+2];
long long calc(long long a,long long b,long long c,long long d){
	a>b&&(swap(a,b),1),c>d&&(swap(c,d),1);
	return max(b,d)-min(a,c);
}
template<typename T>void minify(T&x,const T&y){
	y<x&&(x=y);
}
int main(){
	int n,i;
	scanf("%d",&n),psm[0]=0;
	for(int i=0; ++i<=n; psm[i]=psm[i-1]+a[i])
		scanf("%d",a+i);
	nsm[n+1]=0;
	for(int i=n+1; --i; nsm[i]=nsm[i+1]+a[i]);
	long long x,y,ans=INF;
	for(int j=0,i=0,k=0; ++j<=n; minify(ans,calc(psm[i],psm[j]-psm[i],psm[k]-psm[j],psm[n]-psm[k]))){
		for(y=(x=psm[j])>>1; psm[++i]<=y; );
		y-psm[i-1]<psm[i]-y&&(--i);
		for(y=(x=nsm[j+1])>>1; nsm[++k+1]>y; );
		nsm[k]-y<=y-nsm[k+1]&&(--k);
//		printf("*(%d,%d,%d)\n",i,j,k);
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
vector<int> c2is[26];
vector<int> ls,rs;
int N;
string S,T;
int solve(){
	cin>>N;
	cin>>S>>T;
	if(S==T){
		return 0;
	}
	rep(i,N){
		c2is[S[i]-'a'].pb(i);
	}
	int now=N-1;
	int r=N-1;
	for(int i=N-2;i>=-1;i--){
		if(i==-1 || T[i]!=T[i+1]){
			int l=i+1;
			int c = T[i+1] -'a';
			int id = upper_bound(all(c2is[c]),min(now,l))-c2is[c].begin()-1;
			if(id==-1){
				return -1;
			}
			int v = c2is[c][id];
			// show(l);
			// show(r);
			// show(v);
			// puts("");
			ls.pb(v);
			rs.pb(r);

			r=i;
			now=v-1;
		}
	}
	reverse(all(ls));
	reverse(all(rs));
	int K=ls.size();
	// show(ls);
	// show(rs);
	rep(i,K) ls[i]-=i;
	int ans=0;
	rep(i,K){
		int r = rs[i];
		int id = lower_bound(all(ls),r-i)-ls.begin()-i;
//		show(id);
		chmax(ans,id);
	}
	return ans;
}
int main(){
	cout<<solve()<<endl;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
#include <fstream>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}

/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll gp(ll r, ll n)
{
	return (pow(r,n)-1)/(r-1);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> arr(n,0);
	ll sum=0;
	f(i,0,n)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	ll ans=0;
	f(i,0,n-1)
	{
		sum-=arr[i];
		ans+=(arr[i])*(sum%N);
		ans%=N;
	}
	cout<<ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const long mod=1e9+7;
long long sum,t;
int n;
long long a;
int main()
{
    cin>>n;
    while(n>0)
    {
        cin>>a;
        (sum+=a*t)%=mod;
        (t+=a)%=mod;
        n--;
    }
    cout<<sum<<endl;
    return 0;
}


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

void fnInput(int &rnMaxSiz, vector<int> &rvnNum)
{
  cin >> rnMaxSiz;

  rvnNum.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
    cin >> rvnNum[i];
}

void fnPartition(vector<int> &rvnNum, int nStart, int nEnd, int &nCur)
{
  for (int i = nStart; i < nEnd; i++)
    if (rvnNum[i] <= rvnNum[nEnd])
      swap(rvnNum[nCur++], rvnNum[i]);

  swap(rvnNum[nCur], rvnNum[nEnd]);
}

void fnResult(const vector<int> &cnrvnNum, int nCur)
{
  for (int i = 0; i < cnrvnNum.size(); i++)
  {
    if (i)  cout << " ";
    if (i == nCur) cout << "[";
    cout << cnrvnNum[i];
    if (i == nCur) cout << "]";
  }
  cout << endl;
}

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

  int nMaxSiz;
  vector<int> vnNum;

  fnInput(nMaxSiz, vnNum);
  int nStart = 0;
  int nEnd = vnNum.size() - 1;
  int nCur = nStart;

  fnPartition(vnNum, nStart, nEnd, nCur);
  fnResult(vnNum, nCur);

  return 0;
}

#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector<int> S;

int partition(int p, int r)
{
    int x=S[r];
    int i=p-1;
    for(int j=p; j<r; j++){
        if(S[j]<=x){
            i++;
            swap(S[i], S[j]);
        }
    }
    swap(S[i+1], S[r]);
    return i+1;
}

int main()
{
    int n;
    scanf("%d", &n);
    S=vector<int>(n);
    for(auto &it : S){
        scanf("%d", &it);
    }
    int q=partition(0, n-1);
    int i=0;
    for(; i<q; i++){
        if(i!=0){
            printf(" ");
        }
        printf("%d", S[i]);
    }
    printf(" [%d]", S[i]);
    i++;
    for(; i<n; i++){
        printf(" %d", S[i]);
    }
    printf("\n");
    return 0;
}


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

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

    int x;
    cin >> x;
    cout << x*x*x << endl;
}

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

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

  x = pow(x, 3);
  cout << x << "\n";
}


#include<iostream>
using namespace std;

int main(){

	int n, x, y, sumx=0, sumy=0;

	while(cin >> n && n > 0){
		sumx=0, sumy=0;
		for(int i=0; i<n; i++){
			x=0,y=0;
			cin >> x >> y;
			if(x > y){
				sumx = sumx + x + y;
			}
			else if(x < y){
				sumy = sumy + x + y;
			}
			else if(x == y){
				sumx = sumx + x;
				sumy = sumy + y;
			}
		}

		cout << sumx << " " << sumy << endl;
	 }
	return 0;
}

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

bool SortComp(pair<int, int> num1, pair<int, int> num2)
{
	if(num1.second > num2.second)
		return true;
	else if(num1.second < num2.second)
		return false;
	else if(num1.first < num2.first)
		return true;
	else
		return false;
}

int main(void)
{
	while(1)
	{
		int num, min;
		cin>>num>>min;
		if(num == 0 && min == 0)
			break;

		vector<pair<int, int> > arr(101);
		for(int i= 0; i < 101; i++)
			arr[i].first= i+1;

		for(int i= 0; i < num; i++)
		{
			int days;
			cin>>days;

			for(int j= 0; j < days; j++)
			{
				int input;
				cin>>input;
				arr[input-1].second++;
			}
		}

		sort(arr.begin(), arr.end(), SortComp);
		if(arr[0].second < min)
			cout<<0<<endl;
		else
			cout<<arr[0].first<<endl;
	}
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

char grid[1002][1002];

int main()
{
    fastInp;
    ll n;
    cin >> n;
    if (n == 2) {
        cout << "-1";
        return 0;
    }

    if (n == 3) {
        cout << "aa.\n..b\n..b";
        return 0;
    }

    if (n == 6) {
        cout << "aa....\n";
        cout << "..b...\n";
        cout << "..b...\n";
        cout << "...aa.\n";
        cout << ".....b\n";
        cout << ".....b\n";
        return 0;
    }

    if (n == 7) {
        cout << ".aabbcc\n";
        cout << "d.eett.\n";
        cout << "dc....k\n";
        cout << "rc....k\n";
        cout << "rf....d\n";
        cout << "kf....d\n";
        cout << "k.aabb.\n";
        return 0;
    }

    if (n == 11) {
        cout << "laabbccddee\n";
        cout << "lmmrqqx...z\n";
        cout << "hf.rs.x...z\n";
        cout << "hfjjsmm...x\n";
        cout << "g...tkkdllx\n";
        cout << "g...t.fd.hy\n";
        cout << "f...eefrrhy\n";
        cout << "fbgg...vuut\n";
        cout << "ab.q...v.pt\n";
        cout << "awwq...sspu\n";
        cout << "ddccbbooiiu\n";
        return 0;
    }

    for (int i = 0; i <= n; i++) {
        if (4 * i <= n) {
            ll left = n - 4 * i;
            if (left % 5 == 0) {
                ll i2 = left / 5, prevX = 0;
                for (int j = 0; j < i; j++) {
                    grid[prevX][prevX] = 'a'; grid[prevX + 1][prevX] = 'a'; grid[prevX + 2][prevX] = 'b'; grid[prevX + 3][prevX] = 'c';
                    grid[prevX][prevX + 1] = 'd'; grid[prevX + 1][prevX + 1] = 'd'; grid[prevX + 2][prevX + 1] = 'b'; grid[prevX + 3][prevX + 1] = 'c';
                    grid[prevX][prevX + 2] = 'a'; grid[prevX + 1][prevX + 2] = 'b'; grid[prevX + 2][prevX + 2] = 'y'; grid[prevX + 3][prevX + 2] = 'y';
                    grid[prevX][prevX + 3] = 'a'; grid[prevX + 1][prevX + 3] = 'b'; grid[prevX + 2][prevX + 3] = 'x'; grid[prevX + 3][prevX + 3] = 'x';
                    prevX += 4;
                }

                for (int j = 0; j < i2; j++) {
                    grid[prevX][prevX] = 'a'; grid[prevX + 1][prevX] = 'a'; grid[prevX + 2][prevX] = 'b'; grid[prevX + 3][prevX] = 'b'; grid[prevX + 4][prevX] = 'c';
                    grid[prevX][prevX + 1] = 'd'; grid[prevX + 1][prevX + 1] = '.'; grid[prevX + 2][prevX + 1] = 'f'; grid[prevX + 3][prevX + 1] = 'f'; grid[prevX + 4][prevX + 1] = 'c';
                    grid[prevX][prevX + 2] = 'd'; grid[prevX + 1][prevX + 2] = 'r'; grid[prevX + 2][prevX + 2] = '.'; grid[prevX + 3][prevX + 2] = '.'; grid[prevX + 4][prevX + 2] = 'z';
                    grid[prevX][prevX + 3] = 't'; grid[prevX + 1][prevX + 3] = 'r'; grid[prevX + 2][prevX + 3] = '.'; grid[prevX + 3][prevX + 3] = '.'; grid[prevX + 4][prevX + 3] = 'z';
                    grid[prevX][prevX + 4] = 't'; grid[prevX + 1][prevX + 4] = 'k'; grid[prevX + 2][prevX + 4] = 'k'; grid[prevX + 3][prevX + 4] = 'y'; grid[prevX + 4][prevX + 4] = 'y';
                    prevX += 5;
                }

                for (int i= 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        if (grid[i][j] == 0) grid[i][j] = '.';
                        cout << grid[i][j];
                    }
                    cout << "\n";
                }
                return 0;
            }
        }
    }

    return 0;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

char piece[10][10][10];

bool DONE = false;

typedef pair<int, int> pii;

vector<pair<pii, pii>> placement[10];

int done[10][10];

vector<pair<pii, pii>> doms;

class CDominoQuality {
public:
  bool okrow(int n, int row) {
    if (row < 0) return true;
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (!done[row][j]) continue;
      if (j == 0 || (done[row][j] != done[row][j - 1])) cnt++;
    }
    return cnt == 3;
  }

  bool okcol(int n, int col) {
    if (col < 0) return true;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (!done[i][col]) continue;
      if (i == 0 || (done[i][col] != done[i - 1][col])) cnt++;
    }
    return cnt == 3;
  }

  void dfs(int n, int p) {
    if (DONE) return;
    if (p % n == 0) {
      int row = p / n - 1;
      if (!okrow(n, row - 1)) return;
      if (p == n * n) {
        for (int i = 0; i < n; i++) {
          if (!okcol(n, i)) {
            return;
          }
        }
        placement[n] = doms;
        DONE = true;
        return;
      }
    }
    dfs(n, p + 1);
    int r = p / n, c = p % n;
    if (c < n - 1 && !done[r][c + 1] && !done[r][c]) {
      doms.push_back({{r, c}, {r, c + 1}});
      done[r][c + 1] = done[r][c] = p + 1;
      dfs(n, p + 1);
      done[r][c + 1] = done[r][c] = 0;
      doms.pop_back();
    }
    if (r < n - 1 && !done[r + 1][c] && !done[r][c]) {
      doms.push_back({{r, c}, {r + 1, c}});
      done[r + 1][c] = done[r][c] = p + 1;
      dfs(n, p + 1);
      done[r + 1][c] = done[r][c] = 0;
      doms.pop_back();
    }
  }

  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    if (n == 2) {
      out << -1 << endl;
      return;
    }
    if (n == 3) {
      out << "aa.\n";
      out << "..b\n";
      out << "..b\n";
      return;
    }
    memset(piece, '.', sizeof piece);
    for (int i = 4; i <= 7; i++) {
      DONE = false;
      dfs(i, 0);
      for (int j = 0; j < placement[i].size(); j++) {
        auto p = placement[i][j];
        int r1 = p.first.first, c1 = p.first.second, r2 = p.second.first, c2 = p.second.second;
        piece[i][r1][c1] = piece[i][r2][c2] = j + 'a';
      }
    }
    int rep = n / 4 - 1, left = n % 4 + 4;
    vector<vector<char>> res(n, vector<char>(n, '.'));
    for (int k = 0; k < rep; k++) {
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
          res[k * 4 + i][k * 4 + j] = piece[4][i][j];
        }
      }
    }
    for (int i = 0; i < left; i++) {
      for (int j = 0; j < left; j++) {
        res[rep * 4 + i][rep * 4 + j] = piece[left][i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
      out << res[i][j];
      out << "\n";
    }
	}
};

int main() {
	CDominoQuality solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){

  unsigned long long l,r;
  cin >> l >> r;

unsigned long long mi=INT_MAX,i=0,j=0;

 if(r/2019-l/2019!=0)
    cout << 0 << endl;
 else{
   l%=2019;
   r%=2019;
   while(l+i!=r){
     j=l+i;
     while(j!=r){
       j++;
       mi=min((l+i)%2019*j%2019%2019,mi);

     }
     i++;
   }

  cout << mi << endl;
}

}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
    vector<ll> a(300);
    a[0] = 300000;
    a[1] = 200000;
    a[2] = 100000;
    int x, y;
    cin >> x >> y; x--; y--;
    ll ans = a[x] + a[y];
    if(x == y && x == 0)ans += 400000;
    cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
const int MOD = 998244353;
const int MAXN = 5e5 + 10;

int n, m;
namespace {
  inline int add(int x) { return x >= MOD ? x - MOD : x; }
  inline int sub(int x) { return x < 0 ? x + MOD : x; }
  inline int mul(int x, int y) { return 1ll * x * y % MOD; }
  inline int pwr(int x, int y) {
    int ans = 1;
    for (; y; y >>= 1, x = mul(x, x)) {
      if (y & 1) ans = mul(ans, x);
    }
    return ans;
  }
}
int fact[MAXN << 1], invf[MAXN << 1];
int choose(int x, int y) {
  return x < y ? 0 : mul(fact[x], mul(invf[y], invf[x - y]));
}
int main() {
  scanf("%d%d", &n, &m);
  fact[0] = 1, invf[0] = 1;
  if (n < m) std::swap(n, m);
  for (int i = 1; i <= 2 * n; i++) {
    fact[i] = mul(fact[i - 1], i);
    invf[i] = pwr(fact[i], MOD - 2);
  }

  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = add(ans + mul(choose(2 * i - 1, i), choose(n + m - 2 * i, n - i)));
  }
  printf("%d\n", add(n + mul(ans, pwr(choose(n + m, n), MOD - 2))));
}

#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
#define ls(_o) (_o << 1)
#define rs(_o) ((_o << 1) | 1)
#define abs(_o) ((_o < 0) ? -(_o) : _o)
using namespace std;
namespace ywy {
    inline int get() {
        int n = 0;
        char c;
        while ((c = getchar()) || 23333) {
            if (c >= '0' && c <= '9')
                break;
            if (c == '-')
                goto s;
        }
        n = c - '0';
        while ((c = getchar()) || 23333) {
            if (c >= '0' && c <= '9')
                n = n * 10 + c - '0';
            else
                return (n);
        }
    s:
        while ((c = getchar()) || 23333) {
            if (c >= '0' && c <= '9')
                n = n * 10 - c + '0';
            else
                return (n);
        }
    }
    ll min1[1000001], min2[1000001], adds[1000001];
    int x[200001];
    inline void down(int tree) {
        if (!adds[tree])
            return;
        ll c = adds[tree];
        adds[tree] = 0;
        adds[ls(tree)] += c;
        adds[rs(tree)] += c;
        min1[ls(tree)] += c;
        min2[ls(tree)] += c;
        min1[rs(tree)] += c;
        min2[rs(tree)] += c;
    }
    inline void up(int tree) {
        min1[tree] = min(min1[ls(tree)], min1[rs(tree)]);
        min2[tree] = min(min2[ls(tree)], min2[rs(tree)]);
    }
    void setpt(int l, int r, int tree, int pt, ll num) {
        if (l == r) {
            min1[tree] = min(min1[tree], num - l);
            min2[tree] = min(min2[tree], num + l);
            return;
        }
        int mid = (l + r) >> 1;
        down(tree);
        if (pt <= mid)
            setpt(l, mid, ls(tree), pt, num);
        else
            setpt(mid + 1, r, rs(tree), pt, num);
        up(tree);
    }
    ll query1(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min1[tree]);
        int mid = (l + r) >> 1;
        down(tree);
        if (rl > mid)
            return (query1(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query1(rl, rr, l, mid, ls(tree)));
        return (min(query1(rl, mid, l, mid, ls(tree)), query1(mid + 1, rr, mid + 1, r, rs(tree))));
    }
    ll query2(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min2[tree]);
        int mid = (l + r) >> 1;
        down(tree);
        if (rl > mid)
            return (query2(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query2(rl, rr, l, mid, ls(tree)));
        return (min(query2(rl, mid, l, mid, ls(tree)), query2(mid + 1, rr, mid + 1, r, rs(tree))));
    }
    ll query(int l, int r, int tree) {
        if (l == r)
            return (min1[tree] + l);
        int mid = (l + r) >> 1;
        down(tree);
        return (min(query(l, mid, ls(tree)), query(mid + 1, r, rs(tree))));
    }
    void ywymain() {
        int n = get(), q = get(), a = get(), b = get();
        x[0] = a;
        memset(min1, 0x3f, sizeof(min1));
        memset(min2, 0x3f, sizeof(min2));
        setpt(1, n, 1, b, 0);
        for (register int i = 1; i <= q; i++) {
            x[i] = get();
            ll cjr = min(query1(1, x[i], 1, n, 1) + x[i], query2(x[i], n, 1, n, 1) - x[i]);
            adds[1] += abs(x[i] - x[i - 1]);
            min1[1] += abs(x[i] - x[i - 1]);
            min2[1] += abs(x[i] - x[i - 1]);
            setpt(1, n, 1, x[i - 1], cjr);
        }
        cout << query(1, n, 1) << endl;
    }
}
int main() {
    ywy::ywymain();
    return (0);
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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;}

int main(){
    int n,y;cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            int k=(y-10000*i-5000*j)/1000;
            if(i+j+k==n && 0<=k && k<=n){
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

%:pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

const int N = 2e3 + 5;
const int M = 4e6 + 5;
const int mod = 1e9 + 7;

int n, k, dp[N][N], fac[M], ifac[M];

inline int mul(int a, int b) {
	return (long long) a * b % mod;
}
inline int add(int a, int b) {
	return (a += b) >= mod ? a - mod : a;
}
inline int Pow(int a, int b) {
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a))
		if(b & 1) r = mul(r, a);
	return r;
}

void pre(int n) {
	fac[0] = 1;
	for(int i = 1; i <= n; ++i)
		fac[i] = mul(fac[i - 1], i);
	ifac[n] = Pow(fac[n], mod - 2);
	for(int i = n - 1; ~i; --i)
		ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int C(int n, int m) {
	if(n < 0 || m < 0 || n < m) return 1;
	return mul(fac[n], mul(ifac[m], ifac[n - m]));
}

int main() {
	cin >> n >> k;
	if(k == 1) return 0 * putchar('1');
	pre(M - 1);
	dp[0][0] = 1;
	for(int i = 0; i <= n; ++i)
		for(int j = i +(!i); j <= n; ++j) {
			if(i) dp[i][j] = dp[i - 1][j];
			dp[i][j] = add(dp[i][j], mul(dp[i][j - 1], C(i + j * (k - 1) - 1, k - 2)));
		}
	printf("%d\n", mul(dp[n][n], fac[n]));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<62;
const ll MOD=1000000007;

ll N,Q,K;
vector<ll> a(100007,0);
vector<ll> b(100007,0);
vector<ll> c(100007,0);
vector<ll> x(100007,0);
vector<ll> y(100007,0);
vector<ll> d(100007,INF);
vector<vector<P>> G(100007, vector<P>(0));

void dfs(ll x){
    for(auto p: G[x]){
        ll s=p.first,t=p.second;
        if(d[s]==INF){d[s]=d[x]+t;dfs(s);}
    }
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin >> N;
    for(ll i=0;i<N-1;++i){cin>>a[i]>>b[i]>>c[i];a[i]--;b[i]--;}
    for(ll i=0;i<N-1;++i){
        G[a[i]].emplace_back(P(b[i],c[i]));
        G[b[i]].emplace_back(P(a[i],c[i]));
    }
    cin>>Q>>K;K--;
    for(ll i=0;i<Q;++i){cin>>x[i]>>y[i];x[i]--;y[i]--;}
    d[K]=0;
    dfs(K);

    for(ll i=0;i<Q;++i)prt(d[x[i]]+d[y[i]])

    return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

vector<lint> G[200050]; // MAX_V,隣接リスト
lint root;

lint parent[20][200050]; // logMAX_V,MAX_V
lint depth[200050];

void LCAdfs(lint v,lint p,lint d){
    parent[0][v]=p;
    depth[v]=d;
    rep(i,G[v].size()) if(G[v][i]!=p) LCAdfs(G[v][i],v,d+1);
}

void LCAinit(lint V){
    LCAdfs(root,-1,0);
    for(int k=0;k+1<20;k++){
        for(int v=0;v<V;v++){
            if(parent[k][v]<0) parent[k+1][v]=-1;
            else parent[k+1][v]=parent[k][parent[k][v]];
        }
    }
}

lint LCA(lint u,lint v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int k=0;k<20;k++){
        if((depth[v]-depth[u])>>k&1) v=parent[k][v];
    }
    if(u==v) return u;
    for(int k=20-1;k>=0;k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
        }
    }
    return parent[0][u];
}

vector<int> path(int s,int t){
    int lca=LCA(s,t);
    vector<int> ps,pt;
    int now=s;
    while(true){
        if(now==lca) break;
        ps.push_back(now);
        now=parent[0][now];
    }
    now=t;
    while(true){
        pt.push_back(now);
        if(now==lca) break;
        now=parent[0][now];
    }
    reverse(pt.begin(),pt.end());
    ps.insert(ps.end(),pt.begin(),pt.end());
    return ps;
}

vector<pint> edge[MAX_N];
bool reach[MAX_N];
lint dis[MAX_N];

void dfs(int now,lint sum){
    if(reach[now]) return;
    reach[now]=true;
    dis[now]=sum;
    rep(i,edge[now].size()){
        dfs(edge[now][i].fi,sum+edge[now][i].se);
    }
}

int main(void){
    int N;
    cin >> N;
    rep(i,N-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
        edge[u].push_back(pint(v,w));
        edge[v].push_back(pint(u,w));
    }
    LCAinit(N);
    dfs(0,0);
    int Q,K;
    cin >> Q >> K;
    K--;
    rep(i,Q){
        int x,y;
        cin >> x >> y;
        x--,y--;
        int lca=LCA(x,K);
        lint ans=dis[x]+dis[K]-2*dis[lca];
        lca=LCA(K,y);
        ans+=dis[K]+dis[y]-2*dis[lca];
        cout << ans << endl;
    }
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;

ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}

ll powM(ll a,ll b,ll m )
{
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll poww(ll a,ll b)
{

  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e6+5;

ll sp[N];

void fill(){
  for(int i=1;i<N;i++)sp[i]=i;

    for(int i=2;i<N;i++){
      for(int j=i;j<N;j+=i){
        if(sp[j]==j)sp[j]=i;
      }
    }
}

//vl f(N);

bool prime(ll x){
  if(x<=3)return true;

  for(ll i=2;i*i<=x;i++)if(x%i==0)return false;

    return 1;
}

int main()
{

IOS;

fill();

ll a,b;cin>>a>>b;

ll mn=min(a,b);

ll c=0;

set<ll>s;

for(ll i=1;i*i<=a;i++){
  if(a%i==0){
    if(prime(i))s.insert(i);
    if(prime(a/i))s.insert(a/i);
  }
}

for(ll i=1;i*i<=b;i++){
if(b%i==0){
 if( prime(i)&&s.count(i))++c;
 if(i*i!=b&&prime(b/i)&&s.count(b/i))++c;

}

}

//for(auto d:s)cout<<d<<" ";

cout<<c;

return 0;

}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define in read()
#define re register
#define fur(i,a,b) for(re int i=a;i<=b;++i)
#define fdr(i,a,b) for(re int i=a;i>=b;--i)
#define cl(a,b) memset(a,b,sizeof(a))
#define jinitaimei signed
#define int long long
inline int read()
{
	int x=0;
	char ch=getchar();
	for(;!isalnum(ch);ch=getchar());
	for(;isalnum(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}
const int mod=1e9+7,xx=5e5+1;
inline int power(int b,int k)
{
	int res=1;
	for(;k;k>>=1,b=b*b%mod) if(k&1) res=res*b%mod;
	return res;
}
int jc[xx],ny[xx];
inline int C(int m,int n)
{
	if(!m) return 1;
	return jc[n]*ny[m]%mod*ny[n-m]%mod;
}
jinitaimei main()
{
	jc[0]=1;
	ny[0]=1;
	int H=in,W=in;
	fur(i,1,H+W) jc[i]=jc[i-1]*i%mod,ny[i]=power(jc[i],mod-2);
	int A=in,B=in,ans=0;
	A=H-A+1;
	int up=min(A-1,W-B);
	fur(k,1,up)
	{
		int x=A-k,y=B+k;
		int tmp=C(x-1,x+y-2)*C(H-x,W-x+H-y)%mod;
		(ans+=tmp)%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
	int n; cin>>n;
	set<int> st;
	rep(i,n){
		int a; cin>>a;
		if(st.count(a)==1) st.erase(a);
		else st.insert(a);
	}
	cout<<st.size()<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const ll MOD = 1000000007;
using pint = pair<ll, ll>;

int main() {
  ll N;
  cin >> N;
  map<ll, ll> A;
  for (int i = 0; i < N; i++){
    ll tmp = 0;
    cin >> tmp;
    A[tmp]++;
  }
  ll cnt = 0;
  for (auto i : A){
    if (i.second % 2 == 0) continue;
    else{
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  ll n, a, b, c, d, e;
  cin >> n;
  vector<ll> vi(5);
  rep (i, 5) cin >> vi[i];

  ll tmp = n;
  rep (i, 5) {
    if (tmp > vi[i]) tmp = vi[i];
  }

  ll ans = 5;
  ans += (n - tmp) / tmp;
  if ( (n - tmp) % tmp != 0) ++ans;
  cout << ans << endl;

  return 0;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

//ceil(n/m)
int int_ceil(int n, int m)
{
	if (n % m == 0) return n / m;
	return n / m + 1;
}

signed main()
{
	int N;
	int A[5];
	cin >> N;
	REP(i, 5) cin >> A[i];

	int cur = N;
	for (int i = 0; i < 5; i++)
	{
		cur = min(cur, A[i]);
	}

	int n = int_ceil(N, cur);
	cout << n + 4 << endl;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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

int main(){

	while(1){
		int n;
		cin>>n;
		if(n==0)break;

		int in[5555];
		rep(i,n)cin>>in[i];

		int ans = -1000000000;
		reps(i,1,n+1){

			int sum = 0;
			rep(j,i)sum += in[j];

			ans = max(ans,sum);
			reps(j,i,n){
				sum-=in[j-i];
				sum+=in[j];
				ans = max(ans,sum);
			}
		}
		printf("%d\n",ans);
	}

}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

int N, M;
int p[1010];

int main() {
	while (cin >> N >> M, N) {
		for_(i,0,N) cin >> p[i];

		vector<int> vp;
		vp.push_back(0);
		for_(i,0,N) vp.push_back(p[i]);

		vector<int> sum2;
		for_(i,0,N + 1) for_(j,0,N + 1) sum2.push_back(vp[i] + vp[j]);

		sort(allof(sum2));
		int s_size = size_of(sum2);
		int ans = 0;
		for_(i,0,s_size) {
			int sum = sum2[i];
			if (sum <= M) {
				int sub = M - sum;
				int lb = *(upper_bound(allof(sum2), sub) - 1);
				//cout << sub << " " << lb << endl;
				sum += lb;
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
    int n,h,w;
    cin>>n>>h>>w;
    cout<<max(0,(n-h+1)*(n-w+1))<<endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, H, W;
    bool flag = false;
    cin >> N >> H >> W;
    int count = 0;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            if (j + W - 1 <= N) {
                flag = true;
            } else {
                flag = false;
            }

            if (flag && i + H - 1 <= N) {
                ++count;
            }
        }
    }
    cout << count << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}

#define  mx 200004
#define base 193ll

typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
char ar[ MX +2], br [MX+2];
int main(){

    string s;
    cin>>s;
    if(s[0] != 'A'){
        PC("WA");
    }
    else {
        bool fl =0;
        int cnt = 0;
        for(int i = 1; i < s.size(); i++){
            if(s[i] >= 'A' && s[i] <= 'Z'){
                if(s[i] == 'C' && i >= 2 && i < s.size() - 1){

                    cnt++;
                }
                else fl = 1;
            }

        }
        if(fl || cnt != 1)PC("WA");
        else PC("AC");
    }
    NL;
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    bool ans=true,ccheck=false;
    for(int i=0;i<s.size();i++){
        if(i==0){
            if(s[i]!='A'){
                ans=false;
                break;
            }
        }else if(i>=2 && i<=s.size()-2 && s[i]=='C'){
            if(ccheck){
                ans = false;
                break;
            }else{
                ccheck=true;
            }
        }else{
            if(isupper(s[i])){
                ans=false;
                break;
            }
        }
    }

    if(ans && ccheck)cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}


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

int arr[100003] , N;

int main(){
	cin >> N; for(int i = 1 ; i <= N ; ++i) cin >> arr[i];
	bool flag = 0;
	while(1){
		flag ^= 1; int cnt = 0; for(int i = 1 ; i <= N ; ++i) cnt ^= arr[i] - 1;
		if(cnt & 1){puts(!flag ? "Second" : "First"); return 0;}
		int id = 0;
		for(int i = 1 ; i <= N ; ++i)
			if(arr[i] & 1) if(arr[i] == 1 || id){puts(flag ? "Second" : "First"); return 0;} else id = i;
		--arr[id]; int Gcd = 0; for(int i = 1 ; i <= N ; ++i) Gcd = __gcd(arr[i] , Gcd);
		for(int i = 1 ; i <= N ; ++i) arr[i] /= Gcd;
	}
	return 0;
}

// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=100111;
int n,s,x[maxn];
LL p[maxn],ans;

int calc(int l,int r)
{
	if(x[r]<s)
	{
		ans+=s-x[l];
		return l;
	}
	if(x[l]>s)
	{
		ans+=x[r]-s;
		return r;
	}
	if(p[l]>=p[r])
	{
		p[l]+=p[r];
		ans+=x[r]-x[calc(l,r-1)];
		return r;
	}
	else
	{
		p[r]+=p[l];
		ans+=x[calc(l+1,r)]-x[l];
		return l;
	}
}

int main()
{
	get2(n,s);
	for(int i=1;i<=n;i++)get2(x[i],p[i]);
	calc(1,n);
	printendl(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
#define fo(i, n) for(ll i = 0; i < n; i++)
#define endl "\n"
#define of(i, n) for(ll i = n - 1; i >= 0; i--)
#define ll long long
#define vec vector<ll>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define rep(i,j,n) for (ll i = j; i <= n; ++i)
#define EB emplace_back
#define mem(i,j) memset( i, j,sizeof(i))
#define ff first
#define ss second
#define ii pair<ll,ll>
#define iii pair<ll,pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(i) i.begin(),i.end()
#define pr(a) cout<<a<<endl
#define pr
#define prv(a) for(int jkl=0; jkl<a.size();jkl++) cout<<a[jkl]<<" "; cout<<endl;
ll mod = 1e9+7;
string l,r;
ll d;
int dp[10100][2][2][101];

ll getAns(int level, int tlow, int thi, int rem)
{
    if(level>=l.length())
    {
        if(rem==0) return 1;
        else return 0;
    }
    if(dp[level][tlow][thi][rem]==-1)
    {
        int blow = 0;
        int bhigh = 9;
        if(tlow) blow =l[level] - '0';
        if(thi) bhigh = r[level]-'0';
        ll ans =0;

        for(int i=blow;i<=bhigh;i++)
        {
            int ntlow = tlow;
            int nthi = thi;
            if( i > l[level]-'0') ntlow =0 ;
            if(i<r[level]-'0') nthi =0;

            ans += getAns(level+1, ntlow,nthi,(rem + i)%d);
            ans%=mod;
        }
        dp[level][tlow][thi][rem] = ans;
    }
    return dp[level][tlow][thi][rem];

}

int main()
{
    string n;
    cin>>n;
    r = n;
    l = "1";

    while(l.length()<r.length()) l += '0';
    reverse(all(l));
    cin>>d;
    mem(dp,-1);
    //cout<<r<<" "<<l<<endl;

    cout<<getAns(0,1,1,0)<<endl;;
}

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

typedef int in;
#define int long long
int MAX=1e9;
int MAXEST=1e18;
int MOD=1e9+7;

int d;
string s;
int dp[10005][101][2];

int f(int idx,int cur,bool gr)
{
    if(idx==s.size())
    {
        return (!cur);
    }
    int &ret=dp[idx][cur][gr];
    if(ret!=-1)
        return ret;
    ret=0;
    if(!gr)
    {
        for(int i=0; i<s[idx]-'0'; i++)
        {
            ret+=f(idx+1,(cur+i)%d,1);
            ret%=MOD;
        }
        ret+=f(idx+1,(cur+(s[idx]-'0'))%d,0);
        ret%=MOD;
    }
    else{
        for(int i=0;i<=9;i++){
            ret+=f(idx+1,(cur+i)%d,1);
            ret%=MOD;
        }
    }
    return ret;
}

in main()
{
    int tc=1;
//    cin>>tc;
    while(tc--)
    {
        cin>>s>>d;
        memset(dp,-1,sizeof dp);
        cout<<(f(0,0,0)+MOD-1)%MOD<<endl;
    }
    return 0;
}


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

int W,H;
int sy, sx, gy, gx;

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

bool movable(vector<vector<char>> &c, vector<vector<int>> &mat, int h, int w, int hb, int wb) {
  if ((h<0) || (h>=H) || (w<0) || (w>=W)) {
    return false;
  }
  else if (mat[h][w]!=INF || (c[h][w]==c[hb][wb])) {
    return false;
  }
  else {
    return true;
  }
}

ll bfs(vector<vector<char>> &c, vector<vector<int>> &mat, pair<int,int> &q) {
  ll k,s;
  s=0;
  k = 1;
  queue<P> que;
  que.push(q);

  if (mat[q.first][q.second] != INF) return 0;
  else (mat[q.first][q.second] = 0);

  while(que.size()) {
    P p = que.front();
    que.pop();

    rep(i,4){
      if (movable(c,mat,p.first+dy[i],p.second+dx[i],p.first,p.second)) {
        que.push(P(p.first+dy[i],p.second+dx[i]));
        mat[p.first+dy[i]][p.second+dx[i]]=mat[p.first][p.second]+1;
        if (c[p.first+dy[i]][p.second+dx[i]]=='.') s++;
        else k++;
      }
    }
  }
  return k*s;
}

int main() {
  cin >> H >> W;

  vector<vector<char>> c(H,vector<char> (W));
  vector<pair<int,int>> P;
  rep(h,H) {
      string s;
      cin >> s;
    rep(w,W) {
      c[h][w] = s[w];
      if (s[w]=='#') {
          P.push_back(make_pair(h,w));
      }
    }
  }
  vector<vector<int>> mat(H,vector<int> (W, INF));
  ll ans = 0;
  for (auto p: P) {
    ll tmp = bfs(c,mat,p);
    ans += tmp;

  }
    cout << ans << endl;
}

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

ll dp[11][210000];
const int INF=1e9;

int main() {
  ll d,g;
  cin>>d>>g;
  g/=100;

  vector<int> P(d+1),C(d+1);
  int x;
  rep(i,d){
    cin>>P[i+1]>>x;
    C[i+1]=x/100;
  }

  rep(i,11){
    rep(j,210000) dp[i][j]=INF;
  }
  dp[0][0]=0;

  for(int i=1;i<=d;i++){
    for(int j=0;j<=g+20000;j++){
      for(int k=0;k<P[i];k++){
        if(j-k*i<0) continue;
        dp[i][j]=min(dp[i][j],dp[i-1][j-k*i]+k);
      }
      if(j-P[i]*i-C[i]<0) continue;
      dp[i][j]=min(dp[i][j],dp[i-1][j-P[i]*i-C[i]]+P[i]);
    }
  }
  ll ans=INF;
  for(int i=g;i<=g+20000;i++){
    ans=min(ans,dp[d][i]);
  }
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int a = Z;
  Z = Y; Y = X; X = a;
  cout << X << ' ' << Y << ' ' << Z << '\n';
  return 0;
}

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

// double mathdist(double, double, double, double);

int main()
{
    /* 始めからdouble型で読み込むべし */
    /* 読み込み時のキャストは危険 */
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    // cout << mathdist(x1, x2, y1, y2) << endl;
    cout << fixed << setprecision(cout.precision()) << sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2)) << endl;
    return 0;
}

// double mathdist(double x1, double x2, double y1, double y2)
// {
//     double dxsq, dysq, res;

//     constexpr double EPS = numeric_limits<double>::epsilon();
//     if (abs(x1 - x2) <= EPS)
//     {
//         dxsq = 0.0;
//     }
//     else
//     {
//         dxsq = pow(abs(x1 - x2), 2);
//     }
//     if (abs(y1 - y2) <= EPS)
//     {
//         dysq = 0.0;
//     }
//     else
//     {
//         dysq = pow(abs(y1 - y2), 2);
//     }

//     return res = sqrt(dxsq + dysq);
// }


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int n;
  cin >> n;
  vector<int> odd(100001);
  vector<int> even(100001);
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (i % 2 == 0) {
      odd[v]++;
    } else {
      even[v]++;
    }
  }
  int oddMax = 0, evenMax = 0;
  int oddMax2 = 0, evenMax2 = 0;
  int oddMaxNum = 0, evenMaxNum = 0;
  for (int i = 0; i < 100001; i++) {
    if (odd[i] >= oddMax) {
      oddMax2 = oddMax;
      oddMax = odd[i];
      oddMaxNum = i;
    } else if(odd[i] > oddMax2){
      oddMax2 = odd[i];
    }
    if (even[i] >= evenMax) {
      evenMax2 = evenMax;
      evenMax = even[i];
      evenMaxNum = i;
    } else if(even[i] > evenMax2){
      evenMax2 = even[i];
    }
  }
  if (oddMaxNum == evenMaxNum) {
    if (oddMax - oddMax2 > evenMax - evenMax2) {
      evenMax = evenMax2;
    } else {
      oddMax = oddMax2;
    }
  }
  cout << n - oddMax - evenMax << endl;
}

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

int main(void){
   int N;
   cin>>N;
   vector<int> X(N);
   for(int i=0;i<N;i++){
      cin>>X[i];
   }
   int sum=0;
   for(int i=0;i<N-1;i++){
      sum+=abs(X[i+1]-X[i]);
   }
   for(int i=0;i<N;i++){
      if(i==N-1){
         cout<<sum+abs(X[0])+abs(X[N-2])-abs(X[i]-X[i-1])<<endl;
      }else if(i==0){
         cout<<sum+abs(X[1])+abs(X[N-1])-abs(X[1]-X[0])<<endl;
      }else{
         cout<<sum+abs(X[0])+abs(X[N-1])+abs(X[i+1]-X[i-1])-abs(X[i+1]-X[i])-abs(X[i]-X[i-1])<<endl;
      }
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> hw(h);
  for(int i=0; i<h; ++i) cin >> hw[i];
  queue<P> que;
  vector<vector<int>> dis(h, vector<int>(w, -1));
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    if(hw[i][j] == '#'){
      que.push(make_pair(i,j));
      dis[i][j] = 0;
    }
  }
  int ans = 0;
  while(!que.empty()){
    int x, y;
    tie(x,y) = que.front();
    que.pop();
    if(x>0 && dis[x-1][y] == -1){
      dis[x-1][y] = dis[x][y] + 1;
      ans = max(ans, dis[x-1][y]);
      que.push(make_pair(x-1,y));
    }
    if(x<h-1 && dis[x+1][y] == -1){
      dis[x+1][y] = dis[x][y] + 1;
      ans = max(ans, dis[x+1][y]);
      que.push(make_pair(x+1,y));
    }
    if(y>0 && dis[x][y-1] == -1){
      dis[x][y-1] = dis[x][y] + 1;
      ans = max(ans, dis[x][y-1]);
      que.push(make_pair(x,y-1));
    }
    if(y<w-1 && dis[x][y+1] == -1){
      dis[x][y+1] = dis[x][y] + 1;
      ans = max(ans, dis[x][y+1]);
      que.push(make_pair(x,y+1));
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int H, W, ans=1; cin >> H >> W; string A[H];
REP(i, H){ cin >> A[i]; }
int B[H][W]={}; vector< pair<int, int> > C;
REP(i, H){ REP(j, W){
  if(A[i][j]=='#'){  B[i][j]=1; C.push_back(make_pair(i, j)); }
} }
REP(i, H*W){
if((int)C.size()==H*W){ cout << ans-1 << "\n"; return 0; }
int a=C[i].first, b=C[i].second, c=B[a][b]+1;
if(a>0&&!B[a-1][b]){ B[a-1][b]=c; C.push_back(make_pair(a-1, b)); }
if(b>0&&!B[a][b-1]){ B[a][b-1]=c; C.push_back(make_pair(a, b-1)); }
if(a<H-1&&!B[a+1][b]){ B[a+1][b]=c; C.push_back(make_pair(a+1, b)); }
if(b<W-1&&!B[a][b+1]){ B[a][b+1]=c; C.push_back(make_pair(a, b+1)); }
ans=c;
}
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vvi A(N,vi(M));
  rep(i,N) {
    rep(j,M) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  int ans = INF;
  vi except(M,0);
  while(1) {
    vi cnt(M,0);
    bool ok = true;
    rep(i,N) {
      int idx=0;
      rep(j,M) {
        if(except[A[i][j]]) {
          idx++;
        } else {
          break;
        }
      }
      if(idx==M) {
        cout << ans << endl;
        return 0;
      }
      cnt[A[i][idx]]++;
    }
    int n = 0;
    rep(i,M) {
      n = max(n,cnt[i]);
    }
    ans = min(ans,n);
    rep(i,M) {
      if(cnt[i]==n) {
        except[i]++;
      }
    }
  }
  return 0;
}

#include <iostream>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

class node {
public:
	int parent,children[2],sib,val;
	node() {
		parent = -1;
		children[0] = -1;
		children[1] = -1;
		sib = -1;
		val = -1;
	}
	int deg() {
		int c = 0;
		for(int i=0;i<2;i++)if(children[i]!=-1)c++;
		return c;
	}
	string typ() {
		if(parent == -1)return "root";
		else if(deg() == 0)return "leaf";
		else return "internal node";
	}
	int get1() {
		if(children[0] == -1) return children[1];
		return children[0];
	}
};

int n = 0,c = 0;
node d[600000];

void pre(int i) {
	cout << " " << d[i].val;
	if(d[i].children[0] != -1) pre(d[i].children[0]);
	if(d[i].children[1] != -1) pre(d[i].children[1]);
}

void ino(int i) {
	if(d[i].children[0] != -1)ino(d[i].children[0]);
	cout << " " << d[i].val;
	if(d[i].children[1] != -1)ino(d[i].children[1]);
}

void pos(int i) {
	if(d[i].children[0] != -1)pos(d[i].children[0]);
	if(d[i].children[1] != -1)pos(d[i].children[1]);
	cout << " " << d[i].val;
}

void ins(int v) {
	d[c].val = v;
	if(c == 0){c++;return;}
	int h = 0;
	while(1) {
		int g;
		if(d[h].val < v) {
			g = d[h].children[1];
			if(g == -1) {
				d[c].parent = h;
				d[h].children[1] = c;
				break;
			} else {
				h = g;
			}
		} else {
			g = d[h].children[0];
			if(g == -1) {
				d[c].parent = h;
				d[h].children[0] = c;
				break;
			} else {
				h = g;
			}
		}
	}
	c++;
}

void find(int v) {
	int h = 0;
	while(1) {
		int g;
		if(h == -1) {
			cout << "no" << endl;
			return;
		}
		if(d[h].val < v) {
			h = d[h].children[1];
		} else if (d[h].val > v){
			h = d[h].children[0];
		} else {
			cout << "yes" << endl;
			return;
		}
	}
}

void del(int v) {
	int h = 0;
	while(1) {
		int g;
		if(h == -1) {
			return;
		}
		if(d[h].val < v) {
			h = d[h].children[1];
		} else if (d[h].val > v){
			h = d[h].children[0];
		} else {
			int p = d[h].parent;
			if(d[h].deg() == 0) {
				if(d[p].val < v){
					d[p].children[1] = -1;
				}
				else {
					d[p].children[0] = -1;
				}
			}
			if(d[h].deg() == 1) {
				if(d[p].val < v){
					d[p].children[1] = d[h].get1();
					d[d[h].get1()].parent = p;
				}
				else {
					d[p].children[0] = d[h].get1();
					d[d[h].get1()].parent = p;
				}
			}
			if(d[h].deg() == 2) {
				int z = d[h].children[1];
				while(1){
					if(d[z].children[0] != -1) z = d[z].children[0];
					else break;
				}
				int vv = d[z].val;
				int pp = d[z].parent;
				if(d[z].deg() == 0) {
					if(d[pp].val < vv){
						d[pp].children[1] = -1;
					}
					else {
						d[pp].children[0] = -1;
					}
				}
				if(d[h].deg() == 1) {
					if(d[pp].val < vv){
						d[pp].children[1] = d[z].get1();
						d[d[z].get1()].parent = pp;
					}
					else {
						d[pp].children[0] = d[z].get1();
						d[d[z].get1()].parent = pp;
					}
				}
				d[h].val = d[z].val;
			}

			return;
		}
	}
}

int main(void) {
	cin >> n;
	string s;
	int t;
	for(int i = 0;i < n;i++) {
		cin >> s;
		if(s == "insert") {cin >> t;ins(t);}
		else if(s == "find"){cin >> t;find(t);}
		else if(s == "delete"){cin >> t;del(t);}
		else {ino(0);cout << endl;pre(0);cout << endl;}
	}
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

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

    return 0;
}

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

int main(void)
{
	int R, G, x;
	cin >> R >> G;
	x = G * 2 - R;
	cout << x << endl;
}


#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <string.h>

using namespace std;
typedef pair<int, int> P;
struct edge
{
	int to;
	int cost;
};

vector<edge> G[101];
bool isUsed[101];

void solve()
{
	int n;
	cin >> n;
	vector< vector<int> > data((n), vector<int>(n));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			int c;
			cin >> data[i][j];
		}
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = i; j < n; ++j)
		{
			if (data[i][j] != -1)
			{
				edge e1, e2;
				e1.to = j;
				e1.cost = data[i][j];
				e2.to = i;
				e2.cost = data[j][i];
				G[i].push_back(e1);
				G[j].push_back(e2);
			}
		}
	}
	memset(isUsed, 0, sizeof(isUsed));
	int ans = 0;
	priority_queue < P, vector<P>, greater<P> > pque;
	pque.push(P(0, 0));
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int v = p.second;
		if (isUsed[v])
		{
			continue;
		}
		isUsed[v] = true;
		ans += p.first;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge e = G[v][i];
			pque.push(P(e.cost, e.to));
		}
	}
	cout << ans << endl;
}

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

#include<bits/stdc++.h>
using namespace std;
int n,m,a[310][310];
int c[310],u[310],ans;

int main(){
    scanf("%d %d",&n,&m);
    ans=n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int x=1;x<=m;x++){
    	memset(u,0,sizeof(u));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(c[a[i][j]]) continue;
                u[a[i][j]]++;
                break;
            }
        }
        int maxn=0,p;
        for(int i=1;i<=m;i++){
            if(u[i]>maxn)  maxn=u[i],p=i;
        }
        c[p]=1;
        ans=min(ans,maxn);
    }
    printf("%d\n",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
struct dice {
	P x[3];
	dice(int x_[6]) {
		x[0] = P(x_[0], x_[5]);
		x[1] = P(x_[1], x_[4]);
		x[2] = P(x_[2], x_[3]);
	}
	int X(int n) {
		return n < 3 ? x[n].first : x[5 - n].second;
	}
	void N() {
		swap(x[0], x[1]);
		swap(x[1].first, x[1].second);
	}
	void E() {
		swap(x[0], x[2]);
		swap(x[0].first, x[0].second);
	}
	void W() {
		swap(x[0], x[2]);
		swap(x[2].first, x[2].second);
	}
	void S() {
		swap(x[0], x[1]);
		swap(x[0].first, x[0].second);
	}
};

int main()
{
	int x[6];
	string s;
	for (int i = 0; i < 6; i++) {
		cin >> x[i];
	}
	dice d(x);
	cin >> s;
	for (auto c : s) {
		switch (c)
		{
		case 'N':
			d.N();
			break;
		case 'E':
			d.E();
			break;
		case 'W':
			d.W();
			break;
		case 'S':
			d.S();
			break;
		}
	}
	cout << d.X(0) << endl;
	return 0;
}

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

int top, S, E, W, N, bot;

void what(char c)
{
		int tmp;
		switch (c) {
				case 'S':
						tmp = top;
						top = N;
						N = bot;
						bot = S;
						S = tmp;
						break;
				case 'E':
						tmp = top;
						top = W;
						W = bot;
						bot = E;
						E = tmp;
						break;
				case 'W':
						tmp = top;
						top = E;
						E = bot;
						bot = W;
						W = tmp;
						break;
				case 'N':
						tmp = top;
						top = S;
						S = bot;
						bot = N;
						N = tmp;
						break;
		}
}

int main()
{
		int i;
		string op;
		cin >> top >> S >> E >> W >> N >> bot;
		cin >> op;
		for (i=0; i<op.size(); i++) {
				what(op[i]);		}
		cout << top << "\n";
}


#include<iostream>
using namespace std;
#include<map>
#include<vector>
#include<cmath>
#include<set>
#include<algorithm>
#define int long long int
#define mod 1000000007
int binary_search(int arr[],int start,int end,int val)
{
	if(start>end)
	     return -1;
	else
	{
		int mid=(start+end)/2;
		if(arr[mid]<=val)
		    return binary_search(arr,mid+1,end,val);
		else
		{
			int x=mid;
			int y=binary_search(arr,start,mid-1,val);
			if(y==-1)
			    return x;
			else
			    return y;
		}
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int j,arr1[n],arr2[n],arr3[n];
	for(j=0;j<n;j++)
	   cin>>arr1[j];
	for(j=0;j<n;j++)
	    cin>>arr2[j];
	for(j=0;j<n;j++)
	     cin>>arr3[j];
	sort(arr1,arr1+n);
	sort(arr2,arr2+n);
	sort(arr3,arr3+n);
	int value[n]={0};
	for(j=0;j<n;j++)
	{
		int index=binary_search(arr3,0,n-1,arr2[j]);
		if(index!=-1)
		{
			value[j]=(n-index);
		}
	}
	int suffix[n]={0};
	suffix[n-1]=value[n-1];
	for(j=n-2;j>=0;j--)
	{
		suffix[j]=value[j]+suffix[j+1];
	}
	int answer=0;
	for(j=0;j<n;j++)
	{
		int index=binary_search(arr2,0,n-1,arr1[j]);
		if(index!=-1)
		{
			answer+=suffix[index];
		}
	}
	cout<<answer<<endl;
}

#include <fstream>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 998244353
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N, a;
lli dp [200000][2]; // best with i picked. 0: floor((i+1)/2); 1: ceil((i+1)/2)
// transition cands: i-2, i-3

// Helper Functions

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    lli ans = -__LONG_LONG_MAX__;
    cin >> a;
    dp[0][0] = 0; dp[0][1] = a;
    if (N <= 3) ans = max(ans, (lli) a);
    cin >> a;
    dp[1][0] = a; dp[1][1] = a;
    if (N <= 3) ans = max(ans, (lli) a);

    FOR(i,2,N) {
        cin >> a;
        dp[i][0] = dp[i-2][0];
        dp[i][1] = dp[i-2][1];
        // skip 2 cells
        if (i-3 >= 0) {
            if ((i+1)&1 == 0) dp[i][1] = max(dp[i][1], dp[i-3][1]);
            dp[i][0] = max(dp[i][0], dp[i-3][1]);
        }
        // skip 3 cells
        if (i-4 >= 0 && (i-2)/2 + 1 == (i+1)/2) dp[i][0] = max(dp[i][0], dp[i-4][1]);
        dp[i][0] += a;
        dp[i][1] += a;
        if (i&1) {
            lli mx = max(dp[i][0], dp[i][1]);
            dp[i][0] = mx;
            dp[i][1] = mx;
        }
        // cout << i+1 << '\n';
        // cout << dp[i][0] << "   " << dp[i][1] << '\n';
        if ((i+1)/2 == N/2) ans = max(ans, dp[i][0]);
        if ((i+2)/2 == N/2) ans = max(ans, dp[i][1]);
    }
    cout << ans << '\n';
}


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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a.begin(), a.end());
	int ans = 0, sum = 0;
	for (int i = 0; i < n; i++) {
      	if (sum + a[i] > x) break;
		sum += a[i];
		ans++;
      	if (i==n-1 && x > sum) ans--;
	}

	cout << ans << endl;
}

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

bool check(int x, vector<int> &d){
    while(x > 0){
        int c = x % 10;
        for (int i=0; i<d.size(); i++){
            if(c == d[i]) return false;
        }
        x /= 10;
    }
    return true;
}

int main(void){
    // Your code here
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    for (int i=0; i<k; i++){
        cin >> d[i];
    }

    while(1){
        if(check(n, d)){
            cout << n << endl;
            return 0;
        }
        n++;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}

void solve(){
    ll n;
    cin >> n;
    ll mn = inf;
    ll ans = 0;
    fo(i, n){
        ll x;
        cin >> x;
        mn = min(mn ,x);
        if(mn >= x)ans++;
    }
    ANS;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=310;
int n,k,dp[N][N][N];
char s[N];
//
int go(int l,int r,int x){
	if(l>r)return 0;
	if(l==r)return 1;
	if(dp[l][r][x]!=-1)return dp[l][r][x];
	int ans=max(go(l+1,r,x),go(l,r-1,x));
	if(s[l]==s[r])ans=max(ans,go(l+1,r-1,x)+2);
	if(x>0)ans=max(ans,go(l+1,r-1,x-1)+2);
	return dp[l][r][x]=ans;
}
int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%s",s);
	n=strlen(s);
	scanf("%d",&k);
	printf("%d\n",go(0,n-1,k));
	return 0;
}

#include <stdio.h>
#include <math.h>

int n;
int a[1000000];
int cnt;

void insertionSort(int g) {
	for (int i = g; i < n; i ++) {
		int v = a[i];
		int j = i - g;
		while (j >= 0 && a[j] > v) {
			a[j + g] = a[j];
			j -= g;
			cnt ++;
		}
		a[j + g] = v;
	}
}

void shellSort() {
	int g[100000];
	g[0] = 1;
	int m = 0;
	while (g[m] <= n) {
		g[m + 1] = 3 * g[m] + 1;
		m ++;
	}
	printf("%d\n", m);
	for (int i = m - 1; i >= 0; i --) {
		if (i < m - 1) printf(" ");
		printf("%d", g[i]);
	}
	puts("");
	for (int i = m - 1; i >= 0; i --) {
		insertionSort(g[i]);
	}
	printf("%d\n", cnt);
	for (int i = 0; i < n; i ++) {
		printf("%d\n", a[i]);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i ++) {
		scanf("%d", &a[i]);
	}
	shellSort();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  str s; cin >>s;
  if(s.size()==3) reverse(all(s));
  fin(s)
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <map>
using namespace std;
const int MAXN = 1000005;
char S[MAXN], T[MAXN];
int n, q[MAXN], head = 1, tail;
signed main () {
	scanf("%d%s%s", &n, S+1, T+1);
	if(strcmp(S+1, T+1) == 0) { puts("0"); return 0; }
	int ans = 0;
	for(int i = n, j = n; i >= 1; --i) {
		if(T[i] == T[i-1]) continue;
		j = min(j, i);
		for(; j && S[j] != T[i]; --j);
		if(!j) { puts("-1"); return 0; }
		while(head <= tail && q[head] - (tail-head+1) + 1 > i) ++head;
		q[++tail] = j;
		if(i != j) ans = max(ans, tail-head+1);
	}
	printf("%d\n", ans+1);
}


#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> l(n * 2);
  rep(i, 0, n * 2) cin >> l[i];
  sort(l.begin(), l.end());

  int ans = 0;
  rep(i, 1, n * 2) {
    ans += min(l[i], l[i - 1]);
    i++;
  }

  cout << ans << endl;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int n,s,x[N];
ll t[N],p[N];

void solve(int l,int r) {
	if (x[r]<s) {
		fo(i,l,r) t[i]=s-x[i];
		return;
	}
	if (x[l]>s) {
		fo(i,l,r) t[i]=x[i]-s;
		return;
	}
	if (p[l]>=p[r]) {
		p[l]+=p[r];
		solve(l,r-1);
		t[r]=t[l]+x[r]-x[l];
	} else {
		p[r]+=p[l];
		solve(l+1,r);
		t[l]=t[r]+x[r]-x[l];
	}
}

int main() {
	n=read();s=read();
	fo(i,1,n) x[i]=read(),p[i]=read();
	solve(1,n);
	printf("%lld\n",max(t[1],t[n]));
	return 0;
}


#include <bits/stdc++.h>

struct Point
{
    long long x, y, distance{1000000000000};
    std::vector<std::pair<int, long long>> edge;
};

using pli = std::pair<long long, int>;

int main()
{
    int n;
    Point points[100000];

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld%lld", &points[i].x, &points[i].y);
    {
        int sort_p[100000];
        for (int i = 0; i < n; i++)
            sort_p[i] = i;
        std::sort(sort_p, sort_p + n, [&](const int &a, const int &b) { return points[a].x < points[b].x; });
        for (int i = 0; i < n - 1; i++)
            points[sort_p[i]].edge.push_back({sort_p[i + 1], points[sort_p[i + 1]].x - points[sort_p[i]].x});
        for (int i = 1; i < n; i++)
            points[sort_p[i]].edge.push_back({sort_p[i - 1], points[sort_p[i]].x - points[sort_p[i - 1]].x});

        std::sort(sort_p, sort_p + n, [&](const int &a, const int &b) { return points[a].y < points[b].y; });
        for (int i = 0; i < n - 1; i++)
            points[sort_p[i]].edge.push_back({sort_p[i + 1], points[sort_p[i + 1]].y - points[sort_p[i]].y});
        for (int i = 1; i < n; i++)
            points[sort_p[i]].edge.push_back({sort_p[i - 1], points[sort_p[i]].y - points[sort_p[i - 1]].y});
    }

    bool connected[100000]{};
    long long sum{};
    int rest{n - 1};
    std::priority_queue<pli, std::vector<pli>, std::greater<pli>> pq;
    connected[0] = true;
    for (auto &e : points[0].edge)
    {
        points[e.first].distance = e.second;
        pq.push({e.second, e.first});
    }
    while (rest)
    {
        auto next = pq.top();
        pq.pop();
        if (connected[next.second]) continue;
        rest--;
        connected[next.second] = true;
        sum += next.first;
        for (auto &e : points[next.second].edge)
        {
            if (e.second >= points[e.first].distance) continue;
            points[e.first].distance = e.second;
            pq.push({e.second, e.first});
        }
    }

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

    return 0;
}

#include<bits/stdc++.h>
#define INF 100000000
using namespace std;
int n,m[101][101],p[101];
void dp();

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i-1]>>p[i];
  dp();
  cout<<m[1][n]<<endl;

  return 0;
}
void dp(){
  for(int l=2;l<=n;l++)
    for(int i=1;i<=n-l+1;i++){
     int j=i+l-1;
     m[i][j]=INF;
     for(int k=i;k<j;k++){
       int a=m[i][k]+m[k+1][j]+p[i-2]*p[k-1]*p[j-1];
       if(m[i][j]>a)m[i][j]=a;
     }
    }
}


#include <iostream>
using namespace std;

int n = 0, a[100000] = { 0 };

int partition(int a[100000], int p, int r) {
	int x = a[r - 1];
	int i = p - 1;

	for (int j = p; j < r; j++) {
		if (a[j - 1] <= x) {
			i++;
			swap(a[i - 1], a[j - 1]);
		}
	}
	swap(a[i], a[r - 1]);
	return i + 1;
}

int main()
{
	cin >> n;

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

	int k = 0;

	k = partition(a, 1, n);

	for (int i = 0; i < k - 1; i++)
		cout << a[i] << " ";

	if (k < n) {
		cout << "[" << a[k - 1] << "] ";

		if (k < n - 1) {
			for (int i = k; i < n - 1; i++)
				cout << a[i] << " ";
		}

		cout << a[n - 1] << endl;
	}
	else
		cout << "[" << a[n - 1] << "]" << endl;

    return 0;
}

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

using namespace std;

void swap(int &a, int &b) {
	int t = a;
	a = b;
	b = t;
}

int partition(vector<int> &A, int p, int r) {
	int x = A[r];
	int i = p;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			swap(A[i], A[j]);
			i++;
		}
	}
	swap(A[i], A[r]);
	return i;
}

int main() {
	int n = 0;
	cin >> n;
	vector<int> v;
	v.resize(n);

	{
		vector<int>::iterator i = v.begin();
		copy(istream_iterator<int>(cin), istream_iterator<int>(), i++);
	}
	int p = partition(v, 0, n-1);

	for (int i = 0; i < n; i++) {
		if (i == p) {
			cout << "[" << v[i] << "] ";
		}
		else if (i == n - 1) {
			cout << v[i] << "\n";
		}
		else {
			cout << v[i] << " ";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

const double pi = 3.141592653589793238462643383279;

using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

// ここから編集

void solve(){
  int N;cin >> N;
  vector<ll>a(N);
  REP(i,N)cin >> a[i];

  string s; cin >> s;
  vector<ll> b;
  for(int i=N-1; i>=0; i--){
    ll v = a[i];
    for(auto x:b) chmin(v, v^x);
    if(v){
      if(s[i] == '1'){
        cout << 1 << endl;
        return;
      }
      b.push_back(v);
    }
  }
  cout << 0 << endl;
  return;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int t;
    cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  2e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, a[N], basis[64];
string s;

bool check(ll x){
	for(int j = 0; j < 60; j++){
		if(((1ll<<j)&x) == 0) continue;
		if(!basis[j]) return false;
		x ^= basis[j];
	}
	return true;
}

void insert(ll x){
	for(int j = 0; j < 60; j++){
		if(((1ll<<j)&x) == 0) continue;
		if(basis[j]) x ^= basis[j];
		else{
			basis[j] = x;
			break;
		}
	}
}

void solve(){
	for(int i = 0; i < 60; i++) basis[i] = 0;
	cin>>n;
	for(int i = 1; i <= n; i++) cin>>a[i];
	cin>>s; s = '0'+s;
	for(int i = n; i >= 0; i--){
		if(s[i] == '0') insert(a[i]);
		else if(!check(a[i])){ deb1(1) return; }
	}
	deb1(0)
}

int main(){
	GODSPEED;
	cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}


#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

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

using namespace std;

typedef long long LL;
static const LL INF = 1LL << 60;

template<typename T, int SIZE, T DEF_VAL, const T& Compare(const T&, const T&)>
class SegmentTree {
	vector<T> val;
public:
	SegmentTree() : val(SIZE * 2, DEF_VAL) { }
	void update(int i, const T& value) {
		i += SIZE;
		val[i] = value;
		while (i > 1) i >>= 1, val[i] = Compare(val[i * 2], val[i * 2 + 1]);
	}
	T get(LL a, LL b, int l = 0, int r = SIZE, size_t i = 1) {
		if (r <= a || b <= l) return DEF_VAL;
		if (a <= l && r <= b) return val[i];
		return Compare(get(a, b, l, (l + r) / 2, i * 2), get(a, b, (l + r) / 2, r, i * 2 + 1));
	}
	LL find_leftmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
		if (Compare(val[i], value) != val[i]) return -1;
		if (r <= a || b <= l) return -1;
		if (i >= SIZE) return i - SIZE;
		LL leftmost_index = find_leftmost_index(a, b, value, l, (l + r) / 2, i * 2);
		if (leftmost_index >= 0) return leftmost_index;
		return find_leftmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
	}
	LL find_rightmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
		if (Compare(val[i], value) != val[i]) return -1;
		if (r <= a || b <= l) return -1;
		if (i >= SIZE) return i - SIZE;
		LL rightmost_index = find_rightmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
		if (rightmost_index >= 0) return rightmost_index;
		return find_rightmost_index(a, b, value, l, (l + r) / 2, i * 2);
	}
};

void solve(long long H, long long W, std::vector<long long> &A, std::vector<long long> &B) {
	SegmentTree<long long, 1 << 18, INF, min> st;
	for (int i = 0; i < W; ++i) {
		st.update(i, 0);
	}
	for (LL y = 0; y < H; ++y) {
		LL a = A[y], b = B[y];
		while (true) {
			LL min_value = st.get(a, b);
			if (min_value == INF) break;
			LL index = st.find_leftmost_index(a, b, min_value);
			LL next_cost = min_value + b - index;
			if (b < W && next_cost < st.get(b, b + 1)) {
				st.update(b, next_cost);
			}
			st.update(index, INF);
		}
		LL cost = y + 1 + st.get(0, W);
		cout << (cost < INF ? cost : -1) << endl;
	}
}

int main() {
    long long H;
	scanf("%lld", &H);
	long long W;
	scanf("%lld", &W);
	std::vector<long long> A(H);
	std::vector<long long> B(H);
	for (int i = 0; i < H; i++) {
		scanf("%lld", &A[i]); A[i]--;
		scanf("%lld", &B[i]);
	}
	solve(H, W, A, B);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,ans[N],a[N],b[N],t[N<<2],t1[N<<2],t2[N<<2];
void update(int l,int r,int k)
{
    t1[k]=t[k]+r-l;t2[k]=t[k];
    if(l!=r)
    {
        int m=l+r>>1;
        t[k<<1]=t[k];t[k<<1|1]=t[k]+m+1-l;
    }
    t[k]=0;
}
int query(int l,int r,int k,int x)
{
    if(t[k]) update(l,r,k);
    if(l>x) return m+1;
    if(r<=x) return t1[k];
    int m=l+r>>1;
    int a=query(l,m,k<<1,x),b=query(m+1,r,k<<1|1,x);
    if(x<=r) a+=x>=m?x-m:0;
    else a+=r-m;
    t2[k]=min(t2[k<<1],t2[k<<1|1]);
    t1[k]=min(t1[k<<1]+r-m,t1[k<<1|1]);
    return min(a,b);
}
void update(int l,int r,int k,int x,int y,int d)
{
    if(t[k]) update(l,r,k);
    if(r<x||l>y) return;
    if(l>=x&&r<=y)
    {
        t[k]=d+l-x;
        update(l,r,k);
        return;
    }
    int m=l+r>>1;
    update(l,m,k<<1,x,y,d);update(m+1,r,k<<1|1,x,y,d);
    t2[k]=min(t2[k<<1],t2[k<<1|1]);
    t1[k]=min(t1[k<<1]+r-m,t1[k<<1|1]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    for(int i=1;i<=n;i++)
    {
        int d=min(m+1,query(1,m,1,a[i]-1)+1);
        update(1,m,1,a[i],b[i],d);
        ans[i]=t2[1];
    }
    for(int i=1;i<=n;i++)
    {
        if(ans[i]>=m) ans[i]=-1;
        else ans[i]+=i;
        printf("%d\n",ans[i]);
    }
}


#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003

int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);

	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);

	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);

	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);

	return ret;

}

int number(State &begin){
	int ret =0;

	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}

int main(void){

	int n;

	while(cin>>n,n!=0){
		vector<ll> c(n);

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

		string s;
		cin>>s;

		ll k=0;
		for(int i=0;i<s.size();i++){
			if(s[i]>='A'&&s[i]<='Z'){
				if(s[i]-'A'<c[k%n]){
					int tmp=c[k%n]-(s[i]-'A'+1);
					if('z'-'a'<tmp)
					s[i]='Z'-(tmp-('z'-'a'+1));
					else
					s[i]='z'-tmp;
				}
				else
					s[i]=s[i]-c[k%n];
			}
			else if(s[i]>='a'&&s[i]<='z'){
				if(s[i]-'a'<c[k%n]){
					int tmp=c[k%n]-(s[i]-'a'+1);
					if('Z'-'A'<tmp)
					s[i]='z'-(tmp-('Z'-'A'+1));
					else
					s[i]='Z'-tmp;
				}
				else
					s[i]=s[i]-c[k%n];
			}
				k++;
			}
		cout<<s<<endl;

		}

}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k[1000];
string s;

int main(){
	while (cin >> n&&n){
		REP(i, n)cin >> k[i];
		cin >> s;
		int key = 0;
		REP(i, s.size()){
			REP(j, k[key]){
				if (s[i] == 'a'){
					s[i] = 'Z';
				}
				else if (s[i] == 'A'){
					s[i] = 'z';
				}
				else{
					s[i]--;
				}
			}
			key++;
			if (key >= n)key = 0;
		}
		cout << s << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	vint w(10),k(10);
	int sw=0,sk=0;
	rep(i,0,10) cin>>w[i];
	rep(i,0,10) cin>>k[i];
	sort(all(w));
	sort(all(k));
	rep(i,7,10) sw+=w[i];
	rep(i,7,10) sk+=k[i];
	o(sw<<" "<<sk);
}