///1292f
#include <bits/stdc++.h>
#pragma GCC target ("sse4.2")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize ("unroll-loops")
using namespace std;

typedef long long ll;
typedef long double ld;
#define sp(x) fixed<<setprecision(x)
#define pb push_back
#define eb emplace_back
#define die(x) return cout << x << endl, 0
#define fastio ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define file ifstream cin("input.txt"); ofstream cout("output.txt")
//#define endl '\n'
#define pii pair<int, int>
#define F first
#define S second
#define int long long
const int MAXN = 120 + 7, MOD = 1000 * 1000 * 1000 + 7;
const ld EPS = ld(1e-10);
int n, a[MAXN], sum, c[MAXN][MAXN], indeg[MAXN];
vector<int>adj[MAXN], t, s;
int ans = 1, cur= 0;
bool mark[MAXN];
int calc_cnt(){

	int ss = s.size(), ts = t.size();
	vector<int>num(ts, 0), cnt(1 << ss, 0);
	vector<vector<int>>dp(ts + 1, vector<int>(1 << ss, 0);
	for(int i = 0; i < ss; i ++)
		for(int j = 0; j < ts; j ++)
			if(t[j] % s[i] == 0)
				num[j] |= (1 << i);
	for(int i = 0; i < (1 << ss); i ++)
		for(int j = 0; j < ts; j ++)
			if((num[j] & i) == num[j])
				cnt[i] ++;
	for(int i = 0; i < ts; i ++)
		dp[1][num[i]] ++;
	for(int k = 1; k < ts; k ++){
		for(int mask = 0; mask < (1 << ss); mask ++){
			dp[k][mask] %= MOD;
			for(int i = 0; i < ts; i ++){
				int ands = (num[i] & mask);
				if(ands != num[i] && ands != 0){
					dp[k + 1][mask | num[i]] %= MOD;
					dp[k + 1][mask | num[i]] += dp[k][mask];
					dp[k + 1][mask | num[i]] %= MOD;
				}
			}
			dp[k + 1][mask] = ((dp[k + 1][mask]% MOD) + (1ll * (dp[k][mask] % MOD * ((cnt[mask] - k) % MOD)) % MOD) % MOD);
		}
	}
	return dp[ts][(1 << ss) - 1];
}

void dfs(int v){
    mark[v] = 1;
    if(indeg[v] == 0){
        s.pb(a[v]);
    }else{
    	t.pb(a[v]);
    }
    for(auto u : adj[v]){
        if(!mark[u]){
            dfs(u);
        }
    }
    return;
}
void dfs_all(){
    for(int i = 0; i < n; i ++){
        if(!mark[i]){
        	s.clear(), t.clear();
            dfs(i);
            if(!t.empty()){
				int cnt = calc_cnt(), tt = t.size() - 1;
				ans = 1ll * (ans%MOD) * (cnt % MOD) % MOD;
				ans = 1ll * (ans % MOD) * (c[cur + tt][tt] % MOD) % MOD;
				cur += tt;
			}
        }
    }
    return;
}
int32_t main(){
    fastio;
    for(int i = 0; i < MAXN; i ++){
    	c[i][0]  = 1;
    	for(int j = 1; j <= i; j ++){
    		c[i][j] = (c[i - 1][j - 1] + c[i - 1][j])%MOD;
    	}
    }
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    sort(a, a + n);
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < n; j ++)if(i != j){
            if(a[j] % a[i] == 0){
                adj[j].pb(i);
                adj[i].pb(j);
                indeg[j] ++;
            }
        }
    }

    dfs_all();
	cout << ans % MOD << endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector < ll >prime;
ll cnt1[200005] , cnt2[200005] , cntans[200005] , mod = 1e9 + 7;
bool _prime(ll x){
    ll p = sqrt(x);
    for(ll i = 2;i<=p;i++)
        if (x % i == 0)
            return false;
    return true;
}
void fact(ll x , ll num){
    for(ll i = 0;i<prime.size();i++){
        while( x % prime[i] == 0 ){
            x/=prime[i];
            if (num == 1)
                cnt1[ prime[i] ]++;
            else
                cnt2[ prime[i] ]++;
        }
        if (x == 1)
            break;
    }
}
ll binpow(ll base , ll step){
    if (step == 0)
        return 1;
    if (step % 2 == 0){
        ll t = ((binpow(base , step / 2)) % mod);
        return ((t * t) % mod);
    }
    else
        return (((binpow(base , step - 1) % mod) * base) % mod);
}
int main(){
    ll n , i , j;
    cin >> n;
    for(i = 2;i<=2*n;i++)
        if (_prime(i))
            prime.push_back(i);
    for(i = 2 * n - 1;i>=2 * n - n + 1;i--)
        fact(i , 1);
    for(i = 2;i<n;i++)
        fact(i , 2);
    for(i = 0;i<prime.size();i++)
        cntans[ prime[i] ] = cnt1[ prime[i] ] - cnt2[ prime[i] ];
    ll ans = 1;
    for(i = 2;i<=2*n;i++){
        if (cntans[ i ] > 0 ){
            ans*=binpow(i , cntans[ i ] );
        }
        ans%=mod;
    }
    cout << (2 * ans)%mod - n;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
	int m,n,s,ans=0,c=1;
	cin>>n>>m>>s;
	for(int i=0;i<m;i++)
		for(int j=0;j<n;j++){
			int a=(j/s+((n-j-1)/s)+1)*(i/s+((m-i-1)/s)+1);
			if(a>ans){
				ans=a;
				c=1;
			}
			else if(a==ans)
				c++;
		}
	cout<<c<<endl;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

const int N=100000*2+32;  //  字符串最大长度
//const int M=18;        //  M=log2(n)

//int lcp[M][N];
char str[N];  //  在末尾加了'$'的字符串

int num[N];  //  小于等于每个rank的个数

int len;  //  在末尾加了'$'的字符串长度

int *sa,*sa2,*rank,*rank2;
int our[4][N];

int my[N];

void suffix_array()
{
	int i,k;
	sa=our[0];
	sa2=our[1];
	rank=our[2];
	rank2=our[3];
	memset(num,0,sizeof(num));
	for(i=0;i<len;i++)
		num[str[i]]++;
	for(i=1;i<128;i++)  //  128  基于字符集
		num[i]+=num[i-1];
	for(i=len-1;i>=0;i--)
		sa[--num[str[i]]]=i;
	for(rank[sa[0]]=0,i=1;i<len;i++)
	{
		rank[sa[i]]=rank[sa[i-1]];
		if(str[sa[i]]!=str[sa[i-1]])
			rank[sa[i]]++;
	}
	for(k=1;k<len;k+=k)
	{
		//  sa2  开始
		for(i=0;i<len;i++)
			num[rank[sa[i]]]=i+1;
		for(i=len-1;i>=0;i--)
			if(sa[i]>=k)
				sa2[--num[rank[sa[i]-k]]]=sa[i]-k;
		for(i=len-k;i<len;i++)
			sa2[--num[rank[i]]]=i;
		//  sa2  结束

		//  rank2  开始
		for(rank2[sa2[0]]=0,i=1;i<len;i++)
		{
			rank2[sa2[i]]=rank2[sa2[i-1]];
			if(rank[sa2[i]]!=rank[sa2[i-1]]||rank[sa2[i]+k]!=rank[sa2[i-1]+k])  //sa2[i]+k>=n或者sa2[i-1]+k>=n时必有rank[sa2[i]]!=rank[sa2[i-1]
				rank2[sa2[i]]++;
		}
		//  rank2  结束

		swap(sa,sa2);
		swap(rank,rank2);
	}
}

void lcp_rmq()
{
	int i,j,k;
	for(i=0,k=0;i<len;i++)
		if(rank[i]==len-1)
			my[rank[i]]=k=0;
		else
		{
			if(k)
				k--;
			j=sa[rank[i]+1];
			for(;str[i+k]==str[j+k];k++)
				;
			my[rank[i]]=k;
		}
}
int f1[100000+32],f2[100000+32],g1[100000+32],g2[100000+32];
long long z1[100000+32],z2[100000+32];
int main()
{
	int pre,t1,t2,g,i,k;
	long long ans;
	while(true)
	{
        k = 1;
		k--;
		if (1 != scanf("%s",str)) {
              break;
        }
		pre=strlen(str);
		str[pre++]=1;
		scanf("%s",str+pre);
		len=strlen(str)+1;

		suffix_array();
		lcp_rmq();

		ans=0;

		t1=t2=0;

		for(i=2;i<len;i++)
		{
			if(sa[i]<pre)
			{
				if(t2)
					ans+=z2[t2-1];
				if(my[i]<=k)
				{
					t1=0;
					t2=0;
				}
				else
				{
					g=0;
					while(t1&&my[i]<=f1[t1-1])
					{
						g+=g1[t1-1];
						t1--;
					}
					g1[t1]=g+1;
					f1[t1]=my[i];
					if(t1)
						z1[t1]=z1[t1-1]+g1[t1]*(f1[t1]-k);
					else
						z1[t1]=g1[t1]*(f1[t1]-k);
					t1++;

					g=0;
					while(t2&&my[i]<=f2[t2-1])
					{
						g+=g2[t2-1];
						t2--;
					}
					if(g)
					{
						g2[t2]=g;
						f2[t2]=my[i];
						if(t2)
							z2[t2]=z2[t2-1]+g2[t2]*(f2[t2]-k);
						else
							z2[t2]=g2[t2]*(f2[t2]-k);
						t2++;
					}
				}
			}
			else
			{
				if(t1)
					ans+=z1[t1-1];
				if(my[i]<=k)
				{
					t1=0;
					t2=0;
				}
				else
				{
					g=0;
					while(t2&&my[i]<=f2[t2-1])
					{
						g+=g2[t2-1];
						t2--;
					}
					g2[t2]=g+1;
					f2[t2]=my[i];
					if(t2)
						z2[t2]=z2[t2-1]+g2[t2]*(f2[t2]-k);
					else
						z2[t2]=g2[t2]*(f2[t2]-k);
					t2++;

					g=0;
					while(t1&&my[i]<=f1[t1-1])
					{
						g+=g1[t1-1];
						t1--;
					}
					if(g)
					{
						g1[t1]=g;
						f1[t1]=my[i];
						if(t1)
							z1[t1]=z1[t1-1]+g1[t1]*(f1[t1]-k);
						else
							z1[t1]=g1[t1]*(f1[t1]-k);
						t1++;
					}
				}
			}
		}
		printf("%I64d\n",ans % 1000000007);
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#define SZ(a) ((int) (a.size()))
using namespace std;
const int MAXN = 6010;
const int mod = 1000000007;
typedef pair<int,int> ii;
int n;
long long k[MAXN],k2[MAXN];
int main(){
    string asd;
    string asd2
    cin >> asd;
    cin >> asd2;
    n = SZ (asd2);
    long long res=0;
    for(int i=0;i<SZ(asd);i++)
    {
        for(int j=0;j<SZ(asd2);j++)
        {
            if(asd2[j]==asd[i])
            {
                k2[j]=(k2[j]+k[j-1]+1)%mod;
            }
            k2[j+1]=(k2[j+1]+k2[j])%mod;
        }
        res=(res+k2[n])%mod;
        for(int j=0;j<SZ(asd2);j++)
            k[j]=k2[j];
        memset(k2,0,sizeof k2);
    }
    cout << res << endl;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <list>
#include <algorithm>
#include <queue>
#include <string>
#include <set>

using namespace std;

typedef pair<int, int> pii;

int n;
char a[30][30];
long b[10000000]['z'], bc = 1;
char t[50];
int tc = 0;

void rec(int x, int y, int bp){
	if(!b[bp][a[x][y]]){
		b[bp][a[x][y]] = bc++;
	}

	if(x + 1 < n)
		rec(x + 1, y, b[bp][a[x][y]]);
	if(y + 1 < n)
		rec(x, y + 1, b[bp][a[x][y]]);
}

pii doit(int bp, int mark){
	int q = -1;
	pii w;
	char e = ' ';
	tc++;

	for(char c = 'a'; c <= 'z'; c++){
		if(b[bp][c]){
			t[tc - 1] = c;
			pii tmp = doit(b[bp][c], mark ^ 1);
			if(c == 'a')
				tmp.first++;
			if(c == 'b')
				tmp.second++;

			bool res = (mark ? (tmp.second > q) : (tmp.first > q));

//			printf("%7s: %d %d %d %d\n", t, tmp.first, tmp.second, mark, res);

			if(res){
				q = (mark ? tmp.second : tmp.first);
				w = tmp;
				e = c;
			}
		}
	}

	if(q < 0){
		w.first = 0;
		w.second = 0;
	}

	t[tc - 1] = 0;
	tc--;

	return w;
}

int main(){
#if 0
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	gets(a[0]);

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

	rec(0, 0, 0);

	pii q = doit(0, 0);

	if(q.first < q.second)
		printf("SECOND");
	else if(q.first > q.second)
		printf("FIRST");
	else
		printf("DRAW");
}


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

using namespace std;
vector<long long>vec;
vector<long long>vec2;

int main()
{
    int r , l;
    cin >> r >> l;
    vec.push_back(4);
    vec.push_back(7);
    for(int i = 2 ; i <= 10000;i++)
    {
       vec.push_back ( (vec[i-2] * 10)  + 4);
        vec.push_back ( (vec[i-2] * 10)  + 7);
    }

    sort(vec.begin(),vec.end());

    for(int i = 0 ; i <=vec.size();i++)
    {

    	if(r == l+1)
    		break;
    	else
    	{
    	       while(vec[i]>=r && r != l+1)
    	        {
//    	    	   cout << r<<"is "<<vec[i]<<endl;
    	    	   vec2.push_back(vec[i]);
    	    	   r++;
    	        }
    	}

    }
    long long ans = 0;
    for(int i = 0 ; i < vec2.size();i++)
    {
    	ans+=vec2[i];
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int array[n];
	int i=0;
	while(i<n){
		scanf("%d",&array[i]);
		i++;
	}
	sort(array,array+n);
	/*for(int j=0;j<n;j++)
		printf("%d\n",array[j]);*/
	int temp=array[0];
	int count=1;
	int max=1;
	int aux=1;
	while(array[aux]==array[0]){
		count++;
		max++;
		aux;
	}
	for(i=aux;i<n;i++){
		if(array[i]==temp){
			count++;
		}

		else {
			if(count>max) max=count;
			temp=array[i];
			count=1;
		}
		//printf("%d %d %d\n",array[i],count,max);
	}
	printf("%d\n",max);

}


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

using namespace std;

const int mod = 1000000007;

long long c, h[2], w[2];
inline long long joy(long long x) {
	return x * h[0] + (c - x * w[0]) / w[1] * h[1];
}
void getAns(int l, int r) {
	long long s0 = l * w[0], h0 = l * h[0], ans = 0;
	for (int i = l; i <= r; ++i) {
		ans = max(ans, h0 + (c - s0) / w[1] * h[1]);
		s0 += w[0], h0 += h[0];
	}
	cout << ans << endl;
}
int main() {
	// freopen("in", "r", stdin);
	cin >> c >> h[0] >> h[1] >> w[0] >> w[1];
	if (w[0] < w[1]) {
		swap(w[0], w[1]);
		swap(h[0], h[1]);
	}
	long long m = c / w[0];
	if (m < 1000) {
		getAns(0, m);
	} else {
		long long l = 0, r = m;
		while (r - l > 1000) {
			// cout << l << " " << r << endl;
			long long mid1 = (l + r) / 2;
			long long mid2 = (mid1 + r) / 2;
			if (joy(mid1) < joy(mid2)) {
				l = mid1 + 1;
			} else {
				r = mid2 - 1;
			}
		}
		getAns(l, r);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<iterator>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>

using namespace std;

#define ll long long int
#define ull unsingned long long int
#define pi 2*acos(0.0)

int main()
{
    ll t,cases=1;
    char a[1000],b[1000];
    while(true)
    {
        scanf("%s %s",a,b);
        puts(a);
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <climits>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <cmath>

using namespace std;

#define ll long long
#define vt vector
#define inf 1000000000
#define mod 1000000007
#define eps 1e-12
#define M_PI 3.14159265358979323846

int main()
{
	ll n;
	double r, v, si, fi;
	cin >> n >> r >> v;
	for (int i = 0; i < n; i++)
	{
		cin >> si >> fi;
		double dist = fi - si;
		double cir = 2 * M_PI *r;
		double rev = dist / cir;
		rev = floor(rev);
		double time = rev * (cir / v);
		dist -= time*v;
		double left = 0;
		double right = cir/v;
		while (right - left > eps)
		{
			double mid = (left + right) / 2;
			double temp = 2 * r*sin(mid * M_PI / time) + mid * v;
			if (temp >= dist)
				right = mid;
			else
				left = mid;
		}
		time += left;
		printf("%.6f\n", time);
	}
	system("pause");
	return 0;
}


//
//  main.cpp
//  a
//
//  Created by 黄宇凡 on 16/2/29.
//  Copyright © 2016年 黄宇凡. All rights reserved.
//

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

const int R=12;

int grid[R][R];
int a[R][R];

int r,c,n,m;

int main(int argc, const char * argv[]) {
    scanf("%d%d%d%d",&r,&c,&n,&m);
    memset(grid,0,sizeof(grid));
    int x,y;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        grid[x][y]=1;
    }
    memset(a,0,sizeof(a));
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1]+grid[i][j];
        }
    }
    long long ans=0;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            for(int k=i;k<=r;k++){
                for(int l=j;l<=c;l++){
                    if(a[k][l]-a[i-1][l]-a[k][j-1]+a[i-1][j-1]>=m) ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


//Sachin Iyer, VIT Pune
//Jai Shree Ram
//Jai Gajanan
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(n) for(int i=0;i<(n);i++)
#define FOR(a,b) for(int i=(a);i<=(b);i++)
#define FORD(a,b) for(int i=(a);i>=(b);i--)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vll;
typedef long long ll;
long long e = 1000000007;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a % b);
}

void traverse(vector<int> v)
{
    for(int i = 0;i < v.size();++i)
        cout << v[i] << " ";
    cout << endl;
}

/////////////////////////////////////////////////////////////////////
vector <ll> c[31];
void pascal()
{
ll i,j;
	c[1].pb(1);c[1].pb(1);
	for(i=2;i<=30;i++)
	{
		c[i].pb(1);
		for(j=1;j<=i-1;j++)
		{
			c[i].pb(c[i-1][j]+c[i-1][j-1]);
		}
		c[i].pb(1);
	}
}

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

    int i, j, k, l, n, x, y, m, t, z, a, b, test, temp;
    cin>>n;
    ll sum = 1;
    for(int i = n; i>n-5; i++)
        sum *= n;
    cout<<sum;
    return 0;
}


#include <iostream>

int main()
{

    int n, a;
    char b;
    std::cin>>n;

    switch (n % 4)
    {
    case 0:
        std::cout<<1<<"" A";
        break;
    case 1:
        std::cout<<0<<" A";
        break;
    case 2:
        std::cout<<1<<" B";
        break;
    case 3:
        std::cout<<2<<" A";
        break;
    default:
        break;
    }
    // n % 4 = 0 1, 1 0, 2 1, 3 2,

    return 0;

}


#include<bits/stdc++.h>

using namespace std;
int occur(int arr[],int a,int b){
    int i;int res=0;
    sort(arr+a,arr+b);
    for(i=a-1;i<b;i++){
        while(i<b-1 && arr[i]==arr[i+1])i++;
        res++;
    }

return res;

}
int main(){
int t;cin>>t;
while(t){
int n,k,d;cin>>n>>k>>d;int arr[n];int l;int minim=1000000000;
for(int a=0;a<n;a++)cin>>arr[a];

for(int b=0;b<=n-d;b++){
    l=occur(arr,b,b+d);
    if(l<minim)minim=l;
}

cout<<minim;

;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s[300];
    int a,b;
    cin>>s;
    cin>>a;
    int x=0,p;
    p=strlen(s);
    for(int i=0; i<a; i++)
    {

        s[p+x]='?';
        x++;
    }
    s[p+a]='\0';
    int best=0,ok=1;
    for(int i=0; i<strlen(s); i++)
    {

        for(int j=1; (i+(j*2))<strlen(s)+a; j++)
        {
            ok=1;
            for(int g=0; g<j&&ok==1; g++)
            {
                if(s[i+g]==s[g+i+j]) continue;
               else if(s[i+g+j]!='?'&&s[i+g]!=s[i+j+g]) ok=0;
            }
            if(ok) best=max(best,j);

        }

    }

cout<<2*best<<endl;

}


#include <bits/stdc++.h>

typedef long long ll;

ll a, k1, lowerX, upperX, x, xstep;
ll b, k2, lowerY, upperY, y, ystep;
ll l, r, d, D;

ll egcd(ll a, ll b, ll &x0, ll &y0) {
  x0 = 1, y0 = 0;
  ll x1 = 0, y1 = 1, q;

  while (b) {
    q = a/b;
    a = a - q*b;
    std::swap(a, b);
    x0 = x0 - q*x1;
    std::swap(x0, x1);
    y0 = y0 - q*y1;
    std::swap(y0, y1);
  }

  return a;
}

int sgn(ll a) {
  return a < 0 ? -1 : a > 0 ? 1 : 0;
}

bool valid(ll x, ll y) {
  if (x < lowerX || x > upperX) return false;
  if (y < lowerY || y > upperY) return false;
  return true;
}

int main() {
  scanf("%lld%lld%lld%lld%lld%lld", &a, &k1, &b, &k2, &l, &r);
  if (k2 < k1) {
    std::swap(k2, k1);
    std::swap(a, b);
  }

  lowerX = std::max(0LL, ((l - k1) + (a - 1)) / a);
  upperX = (r - k1) < 0 ? - 1 : (r - k1) / a;

  lowerY = std::max(0LL, ((l - k2) + (b - 1)) / b);
  upperY = (r - k2) < 0 ? - 1 : (r - k2) / b;

  D = k2 - k1;
  d = egcd(a, -b, x, y);
  if (D%d) {printf("0\n"); return 0;}
  x *= D/d; y *= D/d;

  xstep = -b/d;
  ystep = a/d;

  if (x < lowerX) {
    ll up = (lowerX - x + std::abs(xstep) - 1) / std::abs(xstep);
    if (xstep > 0) x += xstep * up, y -= ystep * up;
    else x -= xstep * up, y += ystep * up;
  }

  if (x > lowerX) {
    ll drop = (x - std::abs(lowerX)) / std::abs(xstep);
    if (xstep > 0) x -= xstep * drop, y += ystep * drop;
    else x += xstep * drop, y -= ystep * drop;
  }

  if (y < lowerY) {
    ll up = (lowerY - y + std::abs(ystep) - 1) / std::abs(ystep);
    if (ystep < 0) x += xstep * up, y -= ystep * up;
    else x -= xstep * up, y += ystep * up;
  }

  ll up1 = (upperX - x) / std::abs(xstep);
  ll up2 = (upperY - y) / std::abs(ystep);
  assert(up1 == up2);

  printf("%lld\n", std::max(0LL, std::min(up1, up2)) + valid(x, y));
  return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n,a,b,ma;
    cin>>n;
    cin>>a;
    cin>>b;

int bb,aa;
aa=a;
bb=b;
   while((aa/a + bb/b)!=n)
    {
        if(a<b)
        {
            if(b%2!=0)
            {
                b=(b/2)+1;
            }
            else
            {
                b=b/2;
               // bb=-1;
            }
        }
        else
        {
             if(a%2!=0)
            {
                a=(a/2)+1;
               // aa=a/2;
            }
            else
            {
                a=a/2;
               // aa=-1;
            }
        }
    }
    if(a<b)
    {
        cout<<a;
    }
    else
    {
        cout<<b;
    }

}


#include <iostream>
using namespace std;
int total (int a, int s);

int main() {
 int a, b, s, countx=0, county=0, count=0, x, y;
 cin >> a >> b >> s;
 x = 0;
 y = 0;

 if (s < b)
   cout << "NO";
 else
 {
  countx = total(a, s);
  county = total(b, s);
  count = countx + county;
  if (count == s)
	 cout << "YES";
  else
	 cout << "NO";
 }
return(0);
}

int total (int a, int s)
{
 int x = 0;
 int ctr=0;
 for (int i=1; i<=s; i++)
   {
	 if (x < a)
	 {
		 x++;
		 ctr++;
	 }
	 else if (x > a)
	 {
	     x--;
	     ctr++;
	 }
	 else if (x ==0)
	     x=1;
	 else
		break;
   }
  return (ctr);
}


#include<iostream>
using namespace std;
int main()
{
    long long n,a=1,b=1,m;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        a=a*3*3*3%m;
        b=b*7%m;
    }
    cout<<(a-b+m)%m;
}


#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>

using namespace std;

typedef long long int64;

const int64 INF = 1e9;

int main() {
    int64 n;
    cin >> n;
    vector <int> div;
    for (int i = 1; i*i <= n; ++i)
        if (n % i == 0) {
            div.push_back(i);
            if (i*i < n)
                div.push_back(n/i);
        }

    int64 mina = INF, maxa = -INF;

    int size = div.size();
    for (int i = 0; i < size; ++i)
        for (int j = 0; j < size; ++j) {
            if (n / div[i] % div[j] != 0)
                continue;
            int k = n / div[i] / div[j];
            int64 cur = (div[i] + 1)*(div[j] + 2)*(k + 2);
            maxa = max(maxa, cur);
            mina = min(mina, cur);
        }
    cout << mina-n << " " << maxa-n << endl;
    return 0;
}


#include<bits/stdc++.h>
#define mx 105

using namespace std;
vector<int>v1;
vector<int>v2;
int arr[mx];
int n,l;

int main()
{
      cin>>n>>l;
      for(int i=0;i<n;i++)
      {
            cin>>arr[i];
            if(i)
                v1.push_back(arr[i]-arr[i-1]);
      }
      v1.push_back(l-arr[n-1]+arr[0]);

      for(int i=0;i<v1.size();i++)
          v1.push_back(v1[i]);

      for(int i=0;i<n;i++)
      {
           cin>>arr[i];
           if(i)
              v2.push_back(arr[i]-arr[i-1]);
      }
      v2.push_back(l-arr[n-1]+arr[0]);

       for(int i=0;i<v2.size();i++)
          v2.push_back(v2[i]);

       int sig=0;

       for(int i=0;i<n;i++)
       {
            int cnt=0;
            for(int j=i;j<i+n;j++)
            {
                 if(v1[j]==v2[j])
                     cnt++;
            }
            if(cnt==n)
            {
                 sig=1;
                 break;
            }
       }

       if(sig)
           cout<<"YES"<<endl;
       else
           cout<<"NO"<<endl;
       return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,y,u;
int gcd(int x,int z)
{
    if(z==0)
        return x;
    return gcd(z,x%z);
}
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin>>a>>b;
  for(int i=a+1;i<=b;i++)
  {
       u=gcd(a,i);
  }
  cout<<u;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <assert.h>
#include <cctype>
#include <string.h>
#include <string>
using namespace std;

#define INF_MAX 2147483647
#define INF_MIN -2147483647

#define pi acos(-1.0)
#define INF 1e9
#define ll long long

#define For(i, a, b) for( int i = (a); i < (b); i++ )
#define Fors(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define mem(a, s) memset(a, s, sizeof (a))
#define Read() freopen("1.txt", "r", stdin)
#define Write() freopen("2.txt", "w", stdout)
#define sz(c) ((int)(c).size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector <ll> >
typedef pair<int, int> PAIR;
typedef pair<PAIR, int> PAIR2;
string tostring(long long n){ ostringstream ss; ss << n; return ss.str(); }
ll tonumber(string str){ stringstream ss; ss << str; long long n; ss >> n; return n; }

int main()
{
    bool mn = false, mj = false;
    vector<string> v;

    string vs[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

    string a, b, c;
    int ind, on, to;
    cin >> a >> b >> c;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    do
    {
        vector<int> inde;
        on = 0, to = 0;
        for (int i = 0; i < v.size(); i++)
        {
            for (int j = 0; j < 12; j++)
            {
                if (v[i] == vs[j])
                    inde.push_back(j);
            }
        }
        while (inde[0] != inde[1])
        {

            if (inde[0] == 11&& inde[1]!=11)
            {
                inde[0] -= 11;
                on++;
            }
            inde[0]++;
            on++;
        }
        while ( inde[1] != inde[2])
        {

            if (inde[1] == 11&& inde[2]!=11)
            {
                inde[1] -= 11;
                to++;
            }
            inde[1]++;
            to++;
        }
        if (on == 3 && to == 4)
        {
            mn = true;
            break;
        }

        else if (on == 4 && to == 3)
        {
            mj = true;
            break;
        }

    } while (next_permutation(v.begin(), v.end()));
    if (mn == true)
        cout << "minor" << endl;
    else if (mj == true)
        cout << "major" << endl;
    else
        cout << "strange" << endl;
}


#include <vector>
#include <iostream>
#include <bitset>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <utility>
#include <stdio.h>
#include <numeric>
#include <fstream>
#include <queue>
#include <time.h>
#include <stdlib.h>
#pragma warning(disable : 4996)
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define int  long long
#define ll long long
#define $ long long
//#define sz size()
#define fo for(int i=0;i<n;i++)
#define pr_ll pair<long long,long long>
#define pr_int pair<int,int>
//#define pr pair
#define wh while
#define tr true
#define fls false
#define ct cout
#define frs first
#define scn second
#define cn cin
#define fr(i,x,y) for(int i=x;i<y;i++)
#define rfr(i,x,y) for(int i=x;i>=y;i--)
#define main() signed main()
#define all(x) x.begin(),x.end()
/*#define cst const
#define vd void;
#define mp_int map<int,int>
#define mp_ll map<long long,long long>
#define mp map
#define bg begin()
#define en end()
#define srt sort
#define all(x) x.begin(),x.end()
#define chr char
#define strn string*/
//#define стр string
/*#define tmp template
#define tpn typename
#define usn using
#define nms namespace
#define rtn return*/
//#define вілкой_в_глаз else
/*#define el else
#define sw switch
#define brk break
#define rvs reverse
#define cs case*/
//#define нифига 1
/*
#define sgn signed
#define vct vector
#define vct_int vector<int>
#define vct_ll vector<long long>
#define bl bool
#define pshb push_back
#define _ signed main()
#define cntn continue
#define dbl long double
#define frp freopen*/
/*#define mx max
#define mn min*/
//#define DEBUG

using namespace std;
struct ell
{
	int a;
	ell* next;
	ell* previsious;
};
int __gcd(int a, int b)
{
	if (a < b)swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a;
}
class turn
{
private:
	ell* frs = NULL;
	ell* end = NULL;
	int sz = 0;
public:
	void push_front(int a)
	{
		if (sz == 0)
		{
			frs = new ell;
			end = frs;
		}
		else
		{
			ell* q = frs;
			frs = new ell;
			frs->next = q;
			q->previsious = frs;
		}
		frs->a = a;
		sz++;
	}
	void push_back(int a)
	{
		if (sz == 0)
		{
			frs = new ell;
			end = frs;
		}
		else
		{
			end->next = new ell;
			end->next->previsious = end;
			end = end->next;

		}
		end->a = a;
		sz++;
	}
	bool pop_front(int& a)
	{
		if (sz == 0)return false;
		a = frs->a;
		if (sz == 1)
		{
			delete frs;
			frs = NULL;
			end = NULL;
		}
		else
		{
			ell* q = frs->next;
			delete frs;
			frs = q;
		}
		sz--;
		return true;
	}
	bool pop_back(int& a)
	{
		if (sz == 0)return false;
		a = end->a;
		if (sz == 1)
		{
			delete frs;
			frs = NULL;
			end = NULL;
		}
		else
		{
			ell* q = end->previsious;
			delete end;
			end = q;
		}
		sz--;
		return true;
	}
	bool front(int& a)
	{
		if (sz == 0)return false;
		a = frs->a;
		return true;
	}
	bool back(int& a)
	{
		if (sz == 0)return false;
		a = end->a;
		return true;
	}
	int size()
	{
		return sz;
	}
	void clear()
	{
		while (sz > 0)
		{
			int q;
			this->pop_back(q);
		}
	}
};
string Tostring(int a)
{
	string ret = "";
	while (a / 10 > 0)
	{
		ret += a % 10 + 48;
	}
	return ret + char(a + 48);
}
void make_set(int v, int snm[], int rank[])
{
	snm[v] = v;
	rank[v] = 0;
}
int find_set(int v, int snm[])
{
	if (snm[v] == v)return v;
	snm[v] = find_set(snm[v], snm);
	return snm[v];
}
void union_sets(int a, int b, int snm[], int rank[])
{
	a = find_set(a, snm);
	b = find_set(b, snm);
	if (a != b) {
		if (rank[a] < rank[b])
			swap(a, b);
		snm[b] = a;
		if (rank[a] == rank[b])
			++rank[a];
	}
}
vector<int> prefix_function(string s) {
	int n = (int)s.length();
	vector<int> pi(n);
	for (int i = 1; i < n; ++i) {
		int j = pi[i - 1];
		while (j > 0 && s[i] != s[j])
			j = pi[j - 1];
		if (s[i] == s[j])  ++j;
		pi[i] = j;
	}
	return pi;
}
double distance(pair<int, int> a, pair<int, int> b)
{
	return sqrt(abs(a.first - b.first) * abs(a.first - b.first) + abs(a.second - b.second) * abs(a.second - b.second));
}
const int N = 2 * 1e5 + 1, M = 1e3, MOD = 1e9 + 7;
int mas[N];
main()
{
	int n;
	cin >> n;
	fr(i, 0, n)
	{
		cin >> mas[i];
	}
	int ans = 0;
	fr(i, 1, n)
	{
		if (mas[i] != 1 && mas[i - 1] != 1)
		{
			ans = -1;
			break;
		}
		if (mas[i] == 2 || mas[i - 1] == 2)ans += 3;
		if (mas[i] == 3 || mas[i - 1] == 3)ans += 4;
	}
	if (ans == -1)
	{
		cout << "Infinite";
	}
	else
	{
		cout << "Finite\n";
		cout << ans;
	}
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
#define N 2010
using namespace std;
struct node
{
    int x, y;
    friend node operator+(node a, node b)
    {
        return (node){a.x + b.x, a.y + b.y};
    }
    friend node operator-(node a, node b)
    {
        return (node){a.x - b.x, a.y - b.y};
    }
    friend ll operator*(node a, node b)
    {
        return 1ll * a.x * b.y - 1ll * a.y * b.x;
    }
    friend bool operator<(node a, node b)
    {
        return a * b < 0;
    }
} a[N], p[N], u[N];
bool cmp(node a, node b)
{
    if (a.y == b.y)
        return a.x < b.x;
    return a.y < b.y;
}
struct tree
{
    node t[N << 2];
    void update(int v)
    {
        if (t[v << 1] * t[v << 1 | 1] == 0)
            t[v] = t[v << 1];
        else
            t[v].x = 2000001, t[v].y = 0;
    }
    void build(int v, int l, int r)
    {
        if (l == r)
        {
            t[v] = u[N];
            return;
        }
        int mid = l + r >> 1;
        build(v << 1, l, mid);
        build(v << 1 | 1, mid + 1, r);
        update(v);
    }
    void mdf(int v, int l, int r, int x)
    {
        if (l == r)
        {
            t[v] = u[x];
            return;
        }
        int mid = l + 1 >> 1;
        if (x <= mid)
            mdf(v << 1, l, mid, x);
        else
            mdf(v << 1 | 1, mid + 1, r, x);
        update(v);
    }
} T;
int n, m, L, pos[N], ans;
pair<node, int> l[N * N >> 1];
bool pd()
{
    for (int i = 1; i <= m; i++)
        if (u[i].x != 0 || u[i].y != 0)
            return 1;
    return 0;
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &a[i].x, &a[i].y);

    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= (n + 1) / 2; i++)
        p[i] = a[i] + a[n - i + 1];
    m = (n + 1) / 2 - 1;
    for (int i = 1; i <= m; i++)
        u[i] = p[i + 1] - p[i];
    if (!pd())
    {
        puts("-1");
        //system("pause");
        return 0;
    }

    for (int i = 1; i <= n; i++)
        pos[i] = i;
    L = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++)
            l[++L] = make_pair(a[i] - a[j], (i - 1) * n + j - 1);
    sort(l + 1, l + n * (n - 1) / 2 + 1);

    T.build(1, 1, m);
    if (T.t[1].x <= 2000000)
        ans++;
    for (int i = 1; i <= L; i++)
    {
        int a0 = l[i].second / n + 1, a1 = l[i].second % n + 1;

        swap(a[pos[a0]], a[pos[a1]]);
        int p0 = min(pos[a0], n - pos[a0] + 1), p1 = min(pos[a1], n - pos[a1] + 1);
        p[p0] = a[p0] + a[n - p0 + 1];
        p[p1] = a[p1] + a[n - p1 + 1];
        if (p0 > 1)
            u[p0 - 1] = p[p0] - p[p0 - 1], T.mdf(1, 1, m, p0 - 1);
        if (p0 < m)
            u[p0] = p[p0 + 1] - p[p0], T.mdf(1, 1, m, p0);
        if (p1 > 1)
            u[p1 - 1] = p[p1] - p[p1 - 1], T.mdf(1, 1, m, p1 - 1);
        if (p1 < m)
            u[p1] = p[p1 + 1] - p[p1], T.mdf(1, 1, m, p1);
        swap(pos[a0], pos[a1]);
        if (l[i].first * l[i + 1].first != 0 && i < L)
        {

            if (T.t[1].x <= 2000000)
                ans++;
        }
    }
    printf("%d", ans);
    return 0;
}


#pragma GCC optimize("-O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#define LL long long
#define DB double
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

inline void Out(LL x){
    if(x>9) Out(x/10);
    putchar(x%10+'0');
}

LL qpow(LL x,LL y,LL P){
	LL re=1;
	while(y){
		if(y&1) re=re*x%P;
		x=x*x%P;y>>=1;
	}
	return re;
}

int top=0;
int q[10005];

LL GEN(LL x){
	bool flag;LL y=x-1;
	for(LL i=2;i<=y;++i)
		if(y%i==0){
			q[++top]=i;
			while(y%i==0) y/=i;
		}
	for(LL i=2;;++i){
		flag=0;
		for(LL j=1;j<=top;++j)
			if(qpow(i,(x-1)/q[j],x)==1){
				flag=1;break;
			}
		if(!flag) return i;
	}
}

const int N=(1<<20)+10;
const LL mod=998244353;
int rev[N];
struct NTT{
	int n;LL g;

	void init(int m){
		g=3;n=1;int k=0;
		while(n<m){n<<=1;++k;}
		for(int i=0;i<n;++i){
			int t=0;
			for(int j=0;j<k;++j) if(i&(1<<j)) t|=(1<<(k-j-1));
			rev[i]=t;
		}
	}

	void DFT(LL *a,int flag){
		for(int i=0;i<n;++i) if(rev[i]>i) swap(a[i],a[rev[i]]);
		for(int l=2;l<=n;l<<=1){
			int m=l>>1;
			LL wn=qpow(g,flag==1?(mod-1)/l:mod-1-(mod-1)/l,mod);
			for(LL *p=a;p!=a+n;p+=l){
				LL w=1;
				for(int k=0;k<m;++k){
					LL t=w*p[k+m]%mod;
					p[k+m]=(p[k]-t+mod)%mod;
					p[k]=(p[k]+t)%mod;
					w=w*wn%mod;
				}
			}
		}
		if(flag==-1){
			LL ppp=qpow(n,mod-2,mod);
			for(int i=0;i<n;++i) a[i]=a[i]*ppp%mod;
		}
	}

	void Cheng(LL *a,LL *b,int m){
        init(m);
        //for(int i=0;i<n;++i) cout<<(a[i]+mod)%mod<<" ";cout<<endl;
        //for(int i=0;i<n;++i) cout<<(b[i]+mod)%mod<<" ";cout<<endl;
        DFT(a,1);DFT(b,1);
        for(int i=0;i<n;++i) a[i]=a[i]*b[i]%mod;
        DFT(a,-1);

    }

}ntt;

LL A[N],B[N],C[N];
LL f[2][2][N];
int n,M,X,S,g;

int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int a=1,b=2,c,d;
	cin>>n;
	while(a<n){
		a=b*2;
		b=a+1;
		if(n==a||n==b){
			cout<<1<<<endl;
			return 0;
		}
		a=a+b;
		b=a+1;
		if(n==a||n==b){
			cout<<1<<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
	return 0;
}
/*
5 7 1 2
1 2

*/


#pragma comment(linker, "/STACK:256000000")

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <memory.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <random>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pi (3.1415926535897932384626433832795)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define tmin(x,y,d) (min(min((x),(y)),(d)))
#define tmax(x,y,d) (max(max((x),(y)),(d)))
#define sq(x) ((x)*(x))
#define cube(x) (((x)*(x))*(x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define MOD 1000000007
#define MAX 200007
#define INF 1000000228
#define LINF 5000000000000000228
#define EPS 0.00000000001

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

//#define task "veryhard"

int t;
void solve();

string s;
int n;

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

#ifdef _MY_DEBUG
	freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
	//	freopen(task".in", "r", stdin); freopen(task".out", "w", stdout);
#endif

	t = 1;
	//scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		solve();
	}
}

void solve()
{
	cin >> n;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			string s1 = "";
			for (int k = i; k <= j; ++j)
			{
				s1 += s[k];
			}
			if (s1[0] != s1[sz(s1) - 1])
			{
				bool fl = true;
				for (int i1 = 1; i1 < sz(s1) - 2; ++i1)
				{
					if (s1[i1] >= 'A' && s1[i1] <= 'Z')
					{
						fl = false;
					}
				}
				if (fl)
					ans++;
			}
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
long long l, r, n, i, j, k;
string al, ar;
string fun (int a, string s)
{
    while (a>0)
    {
        if (a%2==1) s+='1';
        else s+='0';
        a/=2;
    }

    return s;
}
int main ()
{
    cin>>l>>r;

    if (l==r)
    {cout<<0; return 0; }

    if (l+1==r)
    {
        cout<<(l^r);
        return 0;
    }

    while (true)
    {
        al=fun(l, "");
        ar=fun(r, "");

        for (i=0; i<ar.size()-al.size(); i++)
        {
            al+='0';
        }
//         cout<<al<<" "<<ar<<endl;

        for (i=ar.size()-1; i>=1; i--)
        {
            if (ar[i]!=al[i])
            {
                cout<<(1ll<<(long long)(i+1))-1;
                return 0;
            }
        }

    }

    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <string>
#include <math.h>
#include <queue>
#include <vector>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <utility>
#define LL long long
using namespace std;
vector<int>q;
void rec(int i)
{
	q.push_back(0);
	for (int j =1; j <= i; j++)
	{
		q.push_back(q[j-1]+j);
	}
	return;
}
int main()
{
	int n, k, x;
	scanf("%d %d", &n, &k);
	rec(n);
	for (x = 0; x < n; x++)
	{
		if (q[n - x] - x == k)break;
	}
	cout << x << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define pb push_back
typedef vector<ll,ll> vi;
//const ll M=0;
typedef pair<ll,ll> pi;
//vector< pi > adj[M];
//vector<ll> v;
int mark[105];

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

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

    mark[b]=1;
    rep(i,c)
        mark[b+i*a]=1;

    ll flag=0;
    rep(i,a+1)
    {
        if(mark[d+i*c]==1)
        {
            cout << d+i*c;
            flag=1;
            break;
        }
    }

    if(flag==0)
        cout << "-1\n";
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define mp make_pair
#define pb push_back
#define foreach(i, a) for (__typeof(a) i = a.begin(); i != a.end(); i++)
#define FOR(i, k, n) for (int i = (k); i <= (n); i++)
#define FORD(i, k, n) for (int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n) - 1)
#define CLEAR(a) memset(a, 0, sizeof a)
#define SZ(a) (int) (a).size()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const ll INF = 1000000000000000000ll, base = 1000000007;
const int MAXN = 111111;

int main() {
	string s;
	cin >> s;
	int n = SZ(s);
	if (n == 1) {
		if (s[0] == '1')
			cout << '1'; else
			cout << '0';
		return 0;
	}
	ll ans = 0, p = 2;
	FORD(i, n - 1, 0) {
		if (s[i] == '1')
			ans = (ans + p) % base;
		p = (p * 2) % base;
	}
	cout << ans;
	return 0;


#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cassert>
#include<map>

#define PB push_back
#define SZ(c) ll((c).size())
#define ALL(c) (c).begin(), (c).end()
#define CONTAINS(c, x) ((c).find(x)!=(c).end())
#define foreach(it, c) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define WAIT cout<<flush, system("PAUSE")
using namespace std;
typedef long long ll;
typedef pair<double, double> pii;
#define double long double
#define MAX 100100

double N, l, r, a, b, c;
double A[MAX];
double sol;

void DFS(ll n){
   if (n>1e9) return;
   A[++N]=n;
   DFS(n*10+4);
   DFS(n*10+7);
}

double prob(double lol, double hil, double loa, double hia){
   //cout << lol << " " << hil << " " << loa << " " << hia << endl;
   lol = max(lol, l);
   hil = min(hil, r);
   loa = max(loa, a);
   hia = min(hia, b);
   //cout << lol << " " << hil << " " << loa << " " << hia << endl;
   //cout << endl;

   double cl = (hil-lol+1);
   double ca = (hia-loa+1);
   if (min(cl, ca)<=0) return 0;

   return (cl/(double)(r-l+1))*(ca/(double)(b-a+1));
}

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

   cout << setprecision(15) << fixed;

   DFS(4);
   DFS(7);
   sort(A, A+N);
   //for(double I=0; I<10; I++) cout<<A[I]<<endl;
   A[0]=0;
   //cout << A[N] << endl;
   A[N+1] = 1100100100;

   cin >> l >> r >> a >> b >> c;
   for(double I=c; I<=N; I++){
      if (A[I]>max(b,r)) break;
      //cout << c << endl;
      sol += prob(A[I-c]+1, A[I-c+1], A[I], A[I+1]-1);
      sol += prob(A[I], A[I+1]-1, A[I-c]+1, A[I-c+1]);
   }
   cout << sol << endl;
   //WAIT;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll m,n,q=998244853,sum=1,a=1,b=1,r=0,d,s;
    cin >> n >> m;
    if(n==0){cout << 0; return 0;}
    if(m==0){cout << n; return 0;}
    for(ll i=1; i<min(m,n); i++)
    {
        a=(a*(m+n+1-i))%q;
        b=(b*i)%q;
        r=((a%b)+r*i)%q;
        sum = (sum +a/b)%q;
    }
    s=b
    while(s>1)
    {
       d=__gcd(s,r);
       s=s/d;
       r=r/d;
       r+=q;
    }
    sum = (sum + r)%q;
    if(n>m)
    {
        a = (a*(n+1))%q;
        b = (b*m)%q;
        while(b>1)
        {
            d=__gcd(a,b);
            a=a/d;
            b=b/d;
            a+=q;
        }
        sum = (sum + (n-m)*a)%q;
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define DMAX 3210
#define NMAX
#define MMAX

#define EPS 1e-9

using namespace std;

int n, k;
string s;

struct point{
	double x, y;

	point() {	}
	point(const point &a) {x = a.x, y = a.y;}
	point(double _x, double _y) { x = _x; y = _y; }

	point operator-(point &a) {point r(*this); r.x -= a.x, r.y -= a.y; return r;}
	point operator+(point &a) {point r(*this); r.x += a.x, r.y += a.y; return r;}
	point operator*(double val) {point r(*this); r.x *= val, r.y *= val; return r;}
	point operator/(double val) {point r(*this); r.x /= val, r.y /= val; return r;}

	void rotate(long double alfa) {
		long double cx = x;
		x = x * cos(alfa) - y * sin(alfa);
		y = y * cos(alfa) + cx * sin(alfa);
	}
};

ostream& operator<<(ostream& out, point p) { return out << p.x << ' ' << p.y; }

struct line
{
	double m, n;

	line(point A, point B) {
		m = (A.y - B.y) / (A.x - B.x) ;
		n = A.y - m * A.x;
	}

	line(point A, double _m) {
		// linia de panta _m care trece prin punctul A
		m = _m;
		n = A.y - m * A.x;
	}

	line(double _m, double _n) {
		m = _m;
		n = _n;
	}

	point intersect(line l) {
		// returneaza punctul in care se intersecteaza linia this cu linia l
		point O;
		//if(m == l.m)
		// return
		O.x = (l.n - n) / (m - l.m);
		O.y = m * O.x + n;
		return O;
	}

};

long double dist(point a, point b)
{
	long double X = a.x - b.x;
	long double Y = a.y - b.y;
	return sqrt(X * X + Y * Y);
}

struct circle {
	point o;
	double r;

	circle() {}
	circle(point a, point b, point c) {
		point mab = (a + b) / 2;
		point mbc = (c + b) / 2;
		line ab(a, b), bc(b, c);
		line ab1(mab, -1.0/ab.m);
		line bc1(mbc, -1.0/bc.m);
		o = ab1.intersect(bc1);
		r = dist(o, a);
	}

};

struct seg {
	point a, b;

};

istream& operator>>(istream& in, point &p) { return in >> p.x >> p.y; }

istream& operator>>(istream& in, circle &c) { return in >> c.o >> c.r; }

istream& operator>>(istream& in, seg &s) { return in >> s.a >> s.b; }

long double area(point a, point b, point c) {
	return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}

bool isObtouseAngle(point A, point B, point C) {
	//check if A angle is obtuse
	double a = dist(B, C);
	double b = dist(A, C);
	double c = dist(B, A);
	a *= a;
	b *= b;
	c *= c;
	if(b + c < a)
		return true;
	return false;
}

double dist(point p, seg s) {
	// dbg(p);
	// dbg(s.a);
	// dbg(isObtouseAngle(p, s.a, s.b));
	if(isObtouseAngle(s.a, s.b, p) || dist(s.a, s.b) <= EPS || isObtouseAngle(s.b, s.a, p))
		return min(dist(p, s.a), dist(p, s.b));
	return fabs(area(p, s.a, s.b)) / dist(s.a, s.b);
}

bool checkInt(seg a, seg b)
{
	if(area(a.a, a.b, b.a) * area(a.a, a.b, b.b) >= EPS)
		return false;
	if(area(b.a, b.b, a.a) * area(b.a, b.b, a.b) >= EPS)
		return false;
	return true;
}

circle c[4];

int v[DMAX][DMAX];

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

void dfs(int i, int j) {
	int val = v[i][j];
	v[i][j] = 0;
	for(int ii = 0; ii < 4; ii++) {
		if(v[i + dx[ii]][j + dy[ii]] == val)
			dfs(i + dx[ii], j + dy[ii]);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	int xi, yi;
	double x, y;
	for(xi = 1, x = -11.00000001; x < 11; x += 0.008, xi++)
		for(yi = 1, y = -11.00000001; y < 11; y += 0.008, yi++) {
			point p(x, y);
			int msk = 0;
			for(int i = 1; i <= n; i++) {
				if(dist(c[i].o, p) < c[i].r) msk += (1 << i);
			}
			v[xi][yi] = msk;
			// if(msk)
			// dbg(xi), dbg(yi);
		}

	int ans = 1;

	for(int i = 1; i <= DMAX - 3; i++)
		for(int j = 1; j <= DMAX - 3; j++) {
			if(v[i][j] != 0)
				dfs(i, j), ans++;
		}
		cout << ans << '\n';
}


#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int t;
int a,b,c;
long long mod=998244353ll;
long long f[3010][3010];
void init()
{
	for(int i=1;i<=3000;i++) f[i][1]=f[1][i]=i+1;
	for(int i=2;i<=3000;i++)
		for(int j=2;j<=3000;j++)
			f[i][j]=(f[i-1][j-1]*i%mod+f[i][j-1])%mod;
}
long long calc(int x,int y)
{
	return f[x][y]%mod;
}
int main()
{
	init();
	scanf("%d%d%d",&a,&b,&c);
	printf("%lld\n",calc(a,b)*calc(b,c)%mod*calc(a,c)%mod);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <memory.h>
#include <set>
#include <deque>
#include <queue>
typedef long long ll;
using namespace std;
const int nmax = 100005;
const int mod = 1e9 + 7;
const ll inf = 3 * 1e12;
const double EPS = 1e-6;
ll a[nmax];
int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a + 1, a + n);
    ll res = 0;
    ll cnt = 0;
    for(int j = 1; j < n; ++j){
        if (a[j] >= a[0]){
            res += a[j] - a[0];
            cnt++;
        }
    }
    res = (res - cnt + 1) / cnt;
    cout << res << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>ii;
#define PB push_back
#define MP make_pair
#define IN insert
#define F first
#define S second
#define FOR(i, c, n) for(int i = c; i < (int)n ; i++)
#define FOREARCH(i, v) for (__typeof(v.begin()) i = v.begin(); i != v.end(); i++)
#define BACEARCH(i, v) for (__typeof(v.rbegin()) i = v.rbegin(); i != v.rend(); i++)
//--------Main---------//

int n,a,b,c,d,mat[3][3];
set<map<string,int> >ans;
map<string,int> m;
bool ver(){
	int x = mat[0][0]+mat[0][1]+mat[1][0]+mat[1][1];
	int y = mat[0][1]+mat[0][2]+mat[1][1]+mat[1][2];
	int z = mat[1][0]+mat[1][1]+mat[2][0]+mat[2][1];
	int w = mat[1][1]+mat[1][2]+mat[2][1]+mat[2][2];
	//cout<<"SUM\n";
	//cout<<x<<' '<<y<<' '<<z<<' '<<w<<'\n';
	if(x == y && y == z && z == w)return true;
	return false;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>a>>b>>c>>d;
	mat[0][1]=a;
	mat[1][0]=b;
	mat[1][2]=c;
	mat[2][1]=d;
	ll sol=0LL;
	FOR(un,1,n+1){
		FOR(dos,1,n+1){
			FOR(tr,1,n+1){
				FOR(cu,1,n+1){
					FOR(ci,1,n+1){
						mat[0][0]=un;
						mat[0][2]=dos;
						mat[1][1]=tr;
						mat[2][0]=cu;
						mat[2][2]=ci;
						if(ver()){
							sol++;
							// FOR(i,0,3){
							// 	FOR(j,0,3){
							// 		cout<<mat[i][j]<<" ";
							// 	}cout<<'\n';
							// }
							// cout<<"-----\n";
						}
					}
				}
			}
		}
	}
	cout<<sol<<'\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,k,a[105],t,i,j,mx,s;
int main(){
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a[i];
        t+=a[i];
    }

    for(i=0;i<k;i++){
        s=t;
        for(j=i;j<n;j+=k)
            s-=a[j];
        mx=max(mx,abs(sm));
    }
    cout<<mx<<endl;
}


#include <iostream>

using namespace std;
int prime(int x){
int y;
int e=0;
while(x>0)
{
    y=x%10;
    x=x/10;
if(y==2||y==3||y==5||y==7){
    e++;
}
}

return (e);
}

int main()
{
long long x;
cin>>x;
if(x%2!=0){
    cout<<x/2<<" "<<x/2+1;
}
else{
int w=x/2;
int w1=x-w;
while(true){
w--;
w1++;
int k=prime(w);
int k1=prime(w1);
if(k!=0&&k1!=0&&w!=w1){
    break;
}

//99cout<<w<<" "<<w1<<endl;
}
cout<<w<<" "<<w1;
}
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int>arr2(n);
	vector<int>arr(n);
	for (int i(0);i  < n; i++)
		{int y;
		cin >> y;
		arr[i] = y;
		arr2[i] = y;
		}
	for (int i(0);i  < n-1; i++)
	for (int k(1);k < n; k++)
	{
		if (arr[i] > arr[k])
			swap(arr[i],arr[k]);
	}
	int max = 0;
	int max_l;
	vector <int>arr1(n-2);
	for (int i(1);i  < n-1; i++)
	{
		if ((arr[i] -arr[0]) > (arr[n-1] - arr[i]))
			arr1[i-1] = arr[i] - arr[0];
		else
			arr1[i-1] = arr[n-1] - arr[i];
	}

	for (int k(0);k < n-2; k++)
	{
		if (max < arr1[k])
			{
				max = arr1[k];
				max_l = k;
			}
	}
	cout << arr[max_l+1];
}


#include<bits/stdc++.h>
using namespace std;
int a, b, c, ans, ans1, ans2;
int main()
{
    cin>>a>>b>>c;

    ans=(a+b+c);
    ans1=(b+a)*2;
    ans2=(a+c)*2;
    if(ans<=ans1 && ans<=ans2)
        cout<<ans;
    else if(ans1<=ans && ans1<=ans2)
        cout<<ans1;
    else
        cout<<ans2;
}


#include <iostream>
#include <cstdio>
#include <memory.h>

using namespace std;

int x, n=1;
bool fre[1000000000];

void f(int &x)
{
    fre[x]=false;
    x++;
    while (x % 10 == 0) x/=10;
    if(fre[x]) n++;
}

int main()
{
    memset(fre,true,sizeof(fre));
    scanf("%d", &x);
    while(fre[x]) f(x);
    printf("%d", n);
}


#include <bits/stdc++.h>
#include <vector>

using namespace std;

int n,m;
vector<vector<int> > v1;
vector<vector<int> > v2;

vector <pair<int,int> > p1;
vector <pair<int,int> > p2;

int main()
{
    int flag = 0;
    int flag0 = 0;
    int sz1 = 0;
    int sz2 = 0;
    cin>>n>>m;
    v1.resize(n);
    v2.resize(m);
    int a,b;
    for (int i = 0;i<n;i++){
        cin>>a>>b;
        p1.push_back(make_pair(a,b));
    }
    for (int i = 0;i<m;i++){
        cin>>a>>b;
        p2.push_back(make_pair(a,b));
    }

    for (int i = 0;i<n;i++){
        for (int j = 0;j<m;j++){
            if ((p1[i].first == p2[j].first && p1[i].second != p2[j].second))
            {
                v1[i].push_back(p1[i].first);
                v2[j].push_back(p2[j].first);
            }
                if ((p1[i].first == p2[j].second && p1[i].second != p2[j].first))
            {
                v1[i].push_back(p1[i].first);
                v2[j].push_back(p2[j].second);
            }
                if ((p1[i].second == p2[j].first && p1[i].first != p2[j].second))
            {
                v1[i].push_back(p1[i].second);
                v2[j].push_back(p2[j].first);
            }
                if ((p1[i].second == p2[j].second && p1[i].first != p2[j].first))
            {
                v1[i].push_back(p1[i].second);
                v2[j].push_back(p2[j].second);
            }
        }
    }
    for (int i = 0;i<v1.size();i++){
        if (v1[i].size() > 1){
            for (int j = 1;j<v1[i].size();j++){
                if (v1[i][j] != v1[i][j-1]){
                    flag = 1;
                    break;
                }

            }
        }
        sz1+= v1[i].size();
    }
    for (int i =0;i<v2.size();i++){
        for (int j = 1;j<v2[i].size();j++){
                if (v2[i][j] != v2[i][j-1]){
                    flag = 1;
                    break;
                }

            }

        sz2+= v2[i].size();
    }

    if (flag == 1){
        cout<<-1<<endl;
    }
    else
    {
        if (sz1 != 1){
            int prev = v1[0][0];
           for (int i = 0;i<v1.size();i++){

            for (int j = 0;j<v1[i].size();j++){
                if (v1[i][j] != prev){
                    flag0 = 1;
                    break;
                }
                prev = v1[i][j];

            }
            if(flag0)
                break;
           }
           if (flag0)
            cout<<0<<endl;
           else
            cout<<v1[0][0]<<endl;
        }
        else
        {
            for (int i = 0;i<v1.size();i++){
                if (v1[i].size() == 1)
                cout<<v1[i].at(0)<<endl;
            }
        }
    }
    /*for (int i = 0;i<v1.size();i++){
        for (int j = 0;j<v1[i].size();j++){
            cout<<v1[i][j]<<" ";
        }
    }*/
    return 0;
}


//In the name of God
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int a[24], n, n2, ans = 30, v[1 << 24];
bool d[1 << 24] = {true, true};

bool cmp(int x, int y) { return a[x] < a[y]; }

int main() {
	cin >> n;
	n++;
	for (int i = 1; i < n; i++)
		cin >> a[i];
	n2 = 1 << n;
	d[2] = d[3] = true;
	for (int i = 2; i < n2; i++)
		if (d[i]) {
			int l = 0;
			for (int j = 1, k = 0; j <= i; j <<= 1, k++)
				if (i & j)
					v[l++] = k;
			int t = v[l - 1] + 1;
			if (t == n)
				ans = min(ans, l);
			else {
				sort(v, v + l, cmp);
				for (int j = 0, k = l - 1; k >= 0 && j < l; ) {
					if (a[v[j]] + a[v[k]] == a[t]) {
						int h = i + (1 << t);
						d[h] = true;
						for (int c = 0; c < l; c++)
							d[h - (1 << v[c])] = true;
						break;
					}
					while (j < l && a[v[j]] + a[v[k]] < a[t])
						j++;
					while (k >= 0 && a[v[j]] + a[v[k]] > a[t])
						k--;
				}
			}
		}
	if (ans == 30)
		cout << -1 << '\n';
	else
		cout << ans << '\n';
	cerr << clock() << '\n';
	return 0;
}


#include <iostream>

using namespace std;

int main() {
    int t , s , q , p=0 , ans=0;
    bool lis=true;
    cin>>t>>s>>q;
    while (lis)
    {
          ans++;
          for (int i=1 ; i <= s ; p++ , i++) {
              if (p%q == 0)
                 s+=(q-1);
              if (s == t) {
              lis=false;
              break;
              }
          }
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>

#include <algorithm>
#include <utility>
#include <cmath>
#include <ctime>
#include <functional>
#include <string.h>
#include <cctype>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define sqr(a) ((a) * (a))

struct circle {
    double x, y, r;
};

circle c(double _x, double _y, double _r) {
    circle ci;
    ci.x = _x;
    ci.y = _y;
    ci.r = _r;
    return ci;
}
vector<circle> v;

bool interact(circle a, circle b) {
    if (sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)) + min(a.r, b.r) <= max(a.r, b.r)
            || sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)) >= a.r + b.r) {
        return false;
    }
    return true;
}

bool isIn(circle a, circle b, circle c) {
    if (sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)) <= min(b.r, c.r) && (a.r => min(b.r, c.r) && a.r <= max(b.r, c.r))) {
        return true;
    }
    return false;
}

int main() {
    double x, y, r;
    for (int i = 0; i < 2; i++) {
        cin >> x >> y;
        for (int j = 0; j < 2; j++) {
            cin >> r;
            v.push_back(c(x, y, r));
        }
    }
    int ans = 0;
    for (int i = 0; i < v.size(); i++) {
        bool flag = true;
        for (int j = 0; j < v.size(); j++) {
            if (i != j && (interact(v[i], v[j]))) {
                flag = false;
            }
        }
        if (isIn(v[i], v[i <= 1? 2 : 0], v[i <= 1? 3 : 1]))  {
            flag = false;
        }
        if (flag) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <deque>
#include <algorithm>
#define pb push_back
using namespace std;
deque<char>a;
char t;
int s,n;
int main(){
  while(cin>>t)
    a.pb(t);
  while(a.size()){
    if(a.size()==1){
      s++;
      break;
    }
    int last=0;
    for(int i=0;i<5 && i<a.size();i++)
      if(a[i]!=a[0]){
	last=i;
	break;
      }
    if(!last)
      last=5;
    a.erase(a.begin(),a.begin()+last);
    s++;
  }
  cout<<s<<endl;
  return 0;
}


#pragma comment(linker, "/STACK:16777216")

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <climits>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

using namespace std;

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }

typedef long long ll;

#define eps 1e-10
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL

#define fr(x,y,z) for(int(x)=(y);(x)<(z);(x)++)
#define cast(x,t) *({stringstream ss;static t __ret;ss<<x,ss>>__ret;&__ret;})

#define dbg(x) cout << #x << " == " << x << endl
#define print(x) cout << x << endl

// var
ll a[10], ini;

map< ll, map<ll, map<ll,ll> > > M;
map<ll, map<ll, ll> > M2;

int dfs(ll s, ll l, ll g) {

	if(!M2[s].count(l)) M2[s][l] = (1LL<<62);

	if(M2[s][l] < g) return 1;

	if(s < 0 || l < 0 || g < 0) return 0;

	if(M[s][l][g]++) return 0;

	if(s > ini) return 1;

	if( dfs(s-a[0],l+a[1],g) ) return 1;
	if( dfs(s,l-a[2],g + a[3]) ) return 1;
	if( dfs(s + a[5],l,g - a[4]) ) return 1;

	return 0;
}

int main() {

	// solve
	fr(i,0,6)
		cin >> a[i];

	ini = max(a[0],1LL) * max(a[2],1LL) * max(a[4],1LL);

	if(dfs(ini,0,0)) print("Ron"); else print("Hermione");

	return 0;
}


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

int main() {
    int a[6],sum=0,q;
    bool t=0;
    for(int i=0;i<6;i++)
    cin>>a[i];
     for(int i=0;i<6;i++)
    sum+=a[i];
    if(sum%2==1)
    cout<<"NO"<<endl;
      else
      {
          q=sum/2;
          for(int i=0;i<6;i++)
          for(int j=i+1;j<6;j++)
          for(int t=j+1;t<6;t++)
          if(q==a[i]+a[j]+a[t])
          {
              t=1;

          }
          else

          t=0;
      }
      if(t)
      cout<<"yes"<<endl;
      else cout<<"no"<<endl;
      return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool islucky(uint64_t n)
{
	while(n>0)
	{
		if(n%10!=4&&n%10!=7)
		return 0;
		n=n/10;
	}
	return 1;
}
int main() {
	uint64_t l,r;
	uint64_t s=0;
	cin>>l>>r;
	map<uint64_t,uint64_t> m;
	if(r==1000000000)
		m[r]=4444444444;
		else{
	for(uint64_t i=r;i<=r*10;i++)
	{
		if(islucky(i)){
		m[r]=i;break;}
	}}
	for(uint64_t i=r-1;i>=l;i--)
	{
		if(islucky(i)){
		m[i]=i;}
		else
		m[i]=m[i+1];
	}
	for(uint64_t i=l;i<=r;i++)
	{
		s=s+m[i];
	}
	cout<<s<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int arr[100000000];
int perfact(int n)
{
    int s=0;
    while(n!=0){
        s=s+n%10;
        n=n/10;
    }
    if(s==10)return 1;
    else return 0;
}
int main()
{
    long long int a,b,c,i,n,d;
    while(1)
    {
        cin>>n;
        for(i=1; ; i++){
            if(perfact(i)==1)n--;
            if(n==0){cout<<i<<endl;break;}
        }
    }
    return 0;
}


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

using namespace std;

#define MAXN 101
#define MAXM 101
#define EPS (1e-8)
#define INF (1<<30)
#define FILE "B"
#define PB push_back
#define MP make_pair
#define FT first
#define SD second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int) (x).size())
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

vector <string> v;
char s[100];
void p(int i, int n) {
//	cout << i << ' ' << n << endl;
	if (i == n) {
		v.push_back((string) s);
		return;
	}
	s[i] = '4';
	p(i + 1, n);
	s[i] = '7';
	p(i + 1, n);
}

int main () {

	ios_base :: sync_with_stdio(0);

//	freopen(FILE".in", "r", stdin);
//	freopen(FILE".out", "w", stdout);

	for (int i = 1; i < 20; i++) {
		s[i] = '\0';
		p(0, i);
	}

	string s;
	int c, maxi = 0;
	string ans = "-1";
	cin >> s;
	for (int i = 0; i < v.size(); i++) {
		c = 0;
		for (int j = 0; j < (int) (s.length() - v[i].length() + 1); j++) {
			if (s.substr(j, v[i].length()) == v[i]) c++;
		}
		if (c > maxi) {
			ans = v[i];
			maxi = c;
		}
	}

	cout << ans;

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std ;

#define For( i , _begin , _end ) \
for( int i = (_begin) , i##end = (_end) ; i <= (i##end) ; ++i )
#define Lop( i , _begin , _end ) \
for( int i = (_begin) , i##end = (_end) ; i >= (i##end) ; --i )
#define Rep( i , _begin , _add ) \
for( int i = (_begin) ; i ; i = (_add) )
#define FOR( i , _begin , _end ) \
for( register int i = (_begin) , i##end = (_end) ; i <= (i##end) ; ++i )
#define LOP( i , _begin , _end ) \
for( register int i = (_begin) , i##end = (_end) ; i >= (i##end) ; --i )
#define REP( i , _begin , _add ) \
for( register int i = (_begin) ; i ; i = (_add) )

template < typename tp >
inline bool chkmax( tp& x , const tp& y ) {
	return x >= y ? false : ( x = y , true ) ;
}
template < typename tp >
inline bool chkmin( tp& x , const tp& y ) {
	return x <= y ? false : ( x = y , true ) ;
}

template < typename tp >
inline tp scanf( tp& in ) {
	in = 0 ; char ch = getchar() ; tp f = 1 ;
	for( ;ch> '9'||ch< '0';ch = getchar() )if( ch == '-' )f = -1 ;
	for( ;ch>='0'&&ch<='9';ch = getchar() )in = in * 10 + ch - '0' ;
	return in *= f ;
}

typedef pair < int , int > __ ;
static const int maxn = 25e2 + 11 ;
static const int maxm = 5e3 + 11 ;

int n ;
int m ;
int q ;

int color ;

__ emp ;

inline int def( int l , int r ) { return l + r | l != r ; }

class segment_tree {
	private :
		__ col[maxm] ;
		__ tag[maxm] ;
	public :

		segment_tree() {
			FOR( i , 0 , maxm - 1 )
				col[i] = tag[i] = make_pair( 1e9 , 0 ) ;
		}

		void modify( int l , int r , int L , int R , __ c ) {
			int rt = def( l , r ) ;
			if( l >= L && r <= R ) {
				if( chkmin( col[rt] , c ) ) tag[rt] = c ;
				return ;
			}
			int mid = l + r >> 1 ;
			if( mid >= L ) modify( l , mid , L , R , c ) ;
			if( mid < R ) modify( mid + 1 , r , L , R , c ) ;
		}

		__ query( int l , int r , int x ) {
			int rt = def( l , r ) ;
			if( l == r ) return col[rt] ;
			int mid = l + r >> 1 ; __ res = tag[rt] ;
			if( x <= mid ) chkmin( res , query( l , mid , x ) ) ;
			else chkmin( res , query( mid + 1 , r , x ) ) ;
			return res ;
		}

} T[maxm] ;

namespace Segment_tree {

	void modify( int l , int r , int L , int R , int x , int y , __ c ) {
		int rt = def( l , r ) ;
		if( l >= L && r <= R )
			return T[rt].modify( 1 , m , x , y , c ) ;
		int mid = l + r >> 1 ;
		if( mid >= L ) modify( l , mid , L , R , x , y , c ) ;
		if( mid < R ) modify( mid + 1 , r , L , R , x , y , c ) ;
	}

	__ query( int l , int r , int x , int y ) {
		int rt = def( l , r ) ;
		if( l == r ) return T[rt].query( 1 , m , y ) ;
		int mid = l + r >> 1 ; __ res = T[rt].query( 1 , m , y ) ;
		if( x <= mid ) chkmin( res , query( l , mid , x , y ) ) ;
		else chkmin( res , query( mid + 1 , r , x , y ) ) ;
		return res ;
	}

} using namespace Segment_tree ;

int main() {

	scanf( n ) ; scanf( m ) ; scanf( q ) ;

	modify( 1 , n , 1 , n , 1 , m , make_pair( n * m , ++color ) ) ;

	while( q-- ) {
		int op , x1 , x2 , y1 , y2 , S ;
		scanf( op ) ; scanf( x1 ) ; scanf( y1 ) ; scanf( x2 ) ; scanf( y2 ) ;
		if( op == 3 )
			puts( query( 1 , n , x1 , y1 ).second
				== query( 1 , n , x2 , y2 ).second ? "Yes" : "No" ) ;
		else {
			if( x1 > x2 ) swap( x1 , x2 ) ;
			if( y1 > y2 ) swap( y1 , y2 ) ;
			if( op == 1 )
				modify( 1 , n , x1 , x2 , y1 , y2 , make_pair( S , ++color ) ) ;
			else
				modify( 1 , n , x1 , x2 , y1 , y2 ,
				make_pair( S , query( 1 , n , x1 - 1 , y1 - 1 ).second ) ) ;
		}
	}

	return 0 ;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
using namespace std;

const int N = 1e9;
char cur_year[N];

int main()
{
    memset(cur_year,0,sizeof(cur_year));
    cin>>cur_year;
    int cur_num = atoi(cur_year);
    int len = strlen(cur_year);
    len--;
    char first_ch = cur_year[0];
    int first_num = first_ch - '0';
    first_num++;
    cout<<(first_num*pow(10,len)-cur_num);

    return 0;

}


/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e7+10;
string bfs[SIZE];
int v[SIZE];
set<LL>AA;
vector<LL>gg;
bool u[SIZE];
bool add(string s){
    REP(i,SZ(s)){
        if(s[i]!='0'&&s[i]!='2'&&s[i]!='7'&&s[i]!='5')s[i]='1';
    }
    int it=lower_bound(ALL(gg),atoll(s.c_str()))-gg.begin();
    if(u[it])return 0;
    u[it]=1;
    return 1;
}
bool is25(const string &s){
    if(SZ(s)==1)return 0;
    if(s.back()=='5'){
        char c=s[SZ(s)-2];
        return c=='2'||c=='7';
    }
    else if(s.back()=='0'){
        char c=s[SZ(s)-2];
        return c=='0'||c=='5';
    }
    return 0;
}
int main()  {
    string s;
    R(s);
    if(is25(s)){
        W(0);
        return 0;
    }
    {
        string tmp=s;
        REP(i,SZ(tmp)){
            if(tmp[i]!='0'&&tmp[i]!='2'&&tmp[i]!='7'&&tmp[i]!='5')tmp[i]='1';
        }
        sort(ALL(tmp));
        do{
            if(tmp[0]!='0')gg.PB(atoll(tmp.c_str()));
        }while(next_permutation(ALL(tmp)));
    }
    bfs[0]=s;
    int rr=1;
    REP(i,rr){
        string now=bfs[i];
        REPP(j,1,SZ(now)){
            swap(now[j],now[j-1]);
            if(now[0]!='0'&&add(now)){
                v[rr]=v[i]+1;
                if(is25(now)){
                    W(v[rr]);
                    return 0;
                }
                bfs[rr++]=now;
            }
            swap(now[j],now[j-1]);
        }
    }
    W(-1);
    return 0;
}


#include <iostream>
 using namespace std;

#define i64 long long
int n,m,k;
const int MOD = 1000000009;
int pows [1000005];

void gen () {
    pows[0] = 1;
    for (int i=1; i<=1000000;i++) pows[i] = (2*pows[i-1])%MOD;
}
int main(void) {
    //freopen ("in.txt", "r", stdin);

    gen();
    cin>>n>>m>>k;
    int n1 = n/k; //There should be at least n1 free spaces

    //calculate how many of the free spaces will be occupied
    int a = n-m; //actual free spaces

    int rem = max (n1-a, 0);

    long long res;
    if (rem>0) res = ((pows[rem+1]-2)*k + m - (rem)*k)%MOD;
    else res = m;
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long INF = 1e18;
long long ans = 0;
vector<long long> dpr;
long long solve(long long n){
	if (n==0) return 0;
	if (n<dpr.size() && dpr[n]) return dpr[n];
	long long lastdif = INF;
	long long x = 1, i=0;
	while (abs(x-n)<=lastdif){
		lastdif = abs(x-n);
		x=x*10+1;
		i++;
	}
	x/=10;
	if (x>n && x/10) {
		if (n<dpr.size())return dpr[n]=min(i+solve(abs(x-n)),i-1+solve(abs(x/10-n)));
		return min(i+solve(abs(x-n)),i-1+solve(abs(x/10-n)));
	}
	if (n<dpr.size())
	return dpr[n]= i+solve(abs(x-n));
	return i+solve(abs(x-n));
}
int main(){
#ifdef NEKROLM
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	long long n; cin >> n;
	dpr.resize(1e8);
	cout << solve(n);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,ans=0;
	cin>>n;
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+n);
	if(n<a[0])	ans=0;
	else
	{
		if(n>=a[0])	ans+=a[0];
		//cout<<ans;
		if(ans<n)	ans+=a[1];
		//cout<<ans;
		if(ans<n)	ans+=a[2];
		//cout<<ans;
	}
	//cout<<a[0]<<a[1]<<a[2];
	cout<<ans;
}


#include <iostream>
using namespace std;

int main() {
	while (true) {
		int s, v1, v2, t1, t2, fP, sP;
		cin >> s >> v1 >> v2 >> t1 >> t2;
		fP = t1 * 2 + v1 * s;
		sP = t2 * 2 + v2 * s;

		if (fP == sP) cout << "Friendship" << endl;
		else if (fP < sP) cout << "First" << endl;
		else cout << "Second" << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define F(i,a,b)  for (int i=a;i<b;i++)
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
typedef long long ll;
const int N = 1e4+10;

int a[N][N];
int main()
{
    int n,m,k;
    while(cin>>n>>m>>k) {
        int num=1; mes(a,0);
        for(int j=1; j<2*n; j+=2) {
            for(int i=1; i<=m; ++i) {
                a[i][j]=num++;
                a[i][j+1]=num++;
            }
        }
        for(int j=1; j<=2*n; j++) {
            for(int i=1; i<=m; ++i)
            if(a[i][j]==k) {
                int low=i,cul=j/2; //cout<<i<<" "<<j<<"---"<<endl;
                if(k&1) cout<<cul+1<<" "<<low<<" "<<'L'<<endl;
                else cout<<cul<<" "<<low<<" "<<'R'<<endl;
                break;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;
#define pb push_back
#define vi vector<int>
#define sz(x) ((int)(x).size())

string c[1002];
int a[100];
vector<vi> res;
vi x;

void gen(int n) {
	while (x[0] == 0) {
		res.pb(x);
		int j = n;
		while (x[j-1] > x[j]) j--;
		int k = n;
		while (x[j-1] > x[k]) k--;
		swap(x[j-1], x[k]);
		vi y = vi (n+1);
		for (int i = j; i <= n; i++)
			y[i] = x[n-i+j];
		for (int i = j; i <= n; i++)
			x[i] = y[i];
	}
}

int ToInt(string ss, int k) {
	int ans = 0;
	for (int i = k-1; i >= 0; i--)  {
		ans += ((char)ss[i]-'0')*a[k-1-i];

	}
	return ans;
}

int main() {
	int n, k;
	freopen("input.txt", "r", stdin);
	cin >> n >> k;
	for (int i = 0; i <= k; i++) x.pb(i);
	gen(k);
	a[0] = 1;
	for (int i = 1; i <= k; i++)
		a[i] = a[i-1]*10;
	int minn = 100000000;
	int maxx = -1;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		int tmp = ToInt(c[i], k);
		minn = min(tmp, minn);
		maxx = max(tmp, maxx);
	}
	int ans = maxx-minn;
			for (int i = 0; i < sz(res); i++) {
				minn = 100000000;
				maxx = -1;
				for (int t = 0; t < n; t++) {
				   string ss;
				   for (int j = 1; j < sz(res[i]); j++)
				   	ss.pb(c[t][res[i][j]-1]);
					int tmp = ToInt(ss, k);
					minn = min(tmp, minn);
					maxx = max(tmp, maxx);
				}
				ans = min(ans, (maxx-minn));
			}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long long inf = 1000000000000000000LL;
const int N = 200000 + 5;

int n;
int  x;
int m;
int main() {
    cin >> n;
    cin >> m;
    int arr[n] ={};
    for(int i=0;i<n;i++){
        cin >> x;
        arr[i]=x;
    }
    int maxim =0;
    for(int j=0;j<n;n++){
       maxim = max(maxim,arr[j]);
    }
    int raz;
    for(int g=0;g<n;n++){
        raz= maxim - arr[g];
        m= m-raz;
    }
    int minimal;
    if(m<0){
       minimal = maxim;
    } else{
        int plus = m/n;
        minimal = maxim+plus;
    }
cout << minimal << maxim+m;

}


#include<cstdio>
#include<iostream>
using namespace std;
long f(int n)
{
    if(n==1)
        return 1;
    if(n==2)
        return 2;
    if(n==3)
        return 4;
    if(n!=1&&n!=2&&n!=3)
        return f(n-1)+f(n-2)+f(n-3);
}
int main()
{
    int T;
    long long sum=1;
    cin>>T;
    while(T--)
    {
        sum=1;
        int n,a[51];
        cin>>n;
        for(int i=0;i<=n-1-1;++i)
        {
            cin>>a[i];
        }
        for(int i=0;i<=n-1-1;++i)
        {
            sum*=f(a[i])%10007;
        }
        sum%=10007;
        cout<<sum<<endl;
    }
    return 0;
}


#include <stdio.h>
#include<math.h>
#include<stdlib.h>
struct S
{
    int x,y;
} s[4];
int slove(int n)
{
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(s[i].x!=s[j].x&&s[i].y!=s[j].y)
            {
                return abs((s[i].x-s[j].x)*(s[i].y-s[j].y));
            }
        }
    }
    return -1;
}
int main()
{
    int n;
    while(scanf("%d",&n))
    {
        if(n==1)
        {
            int x;int y;
            scanf("%d%d",&x,&y);
            printf("-1\n");
            continue;
        }
        else
        {
            for(int i=0; i<n; ++i)
            {
                scanf("%d%d",&s[i].x,&s[i].y);
            }
            printf("%d\n",slove(n));
        }
    }
    return 0;
}
/*2018-02-06 19:17:00.351*/


typedef vector<vi> mat;
const int mod=(int)1e9+7;

mat operator*(const mat &a,const mat &b){
  mat res(a.size(),vi(b[0].size()));
  assert(a[0].size()==b.size());
  rep(i,res.size())rep(j,res[0].size())rep(k,a[0].size()){
    res[i][j]+=a[i][k]*(ll)b[k][j]%mod;
    res[i][j]%=mod;
  }
  return res;
}
mat pow(mat m,int n){
  mat res(m.size(),vi(m.size()));
  rep(i,m.size())res[i][i]=1;
  for(;n;n>>=1){
    if(n&1)res=res*m;
    m=m*m;
  }
  return res;
}
int solve(int n){
  mat M(25*2,vi(25*2));
  rep(i,5)rep(j,5){
    for(int k=1;k<5;k++){
      if(j==k||j==1&&k==4||j==4&&k==1||
      j==2&&k==3||j==3&&k==2||
      i==2&&j==1&&k==3||i==3&&j==1&&k==2)continue;
      M[k*5+j][j*5+i]=1;
    }
  }
  rep(i,25)M[i+25][i]=M[i+25][i+25]=1;
  M=pow(M,n+1);
  mat A(50,vi(25));
  rep(i,25)A[i][i]=1;
  mat B=M*A;
  mat C(25,vi(1));
  C[0][0]=1;
  mat D=B*C;
  ll res=0;
  rep(i,25)res+=D[i+25][0];
  return res%mod;
}
int calc(int n){
  int res=((ll)solve(n)+solve((n+1)/2)-solve(2)+mod)%mod;
  if(res%2)res+=mod;
  res/=2;
  return res;
}
void run(){
  int l,r;
  cin>>l>>r;
  ll ans=calc(r)-calc(l-1);
  ans=(ans%mod+mod)%mod;
  cout<<ans<<endl;
}


#include <iostream>
#include<string>
using namespace std;
int main()
{
    string s , s1="";
    cin>>s;
   long long int n=(s.size()-1)/2;
    int j=0;
    s1=s1+s[n];
    while (s1.size ()) s1+=s[n+j];
    {
    if(n-j>=0) s1+=s[n-j];
}
cout<<s1;
return 0;
}


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

long long dp[65][65];
int main()
{
    long long n,t,ans=0;
    cin>>n>>t;
    long long num=0;
    while((1<<num)<t)num++;
    if((1<<num)!=t){
        return puts("0"),0;
    }
    num++;
    if(num==1)ans--;
    n++;
    for(int i=0;i<=60;i++)
        for(int j=0;j<=i;j++)
        {
            if(j==0)dp[i][j]=1;
            else dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
        }
    for(int i=60;i>=0;i--){
        if(num<0)break;
        if(n>=(1LL<<i)){
            ans+=dp[i][num];
            num--;
            n-=1LL<<i;
        }
    }
    if(num==0)ans++;
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,m,i,j,k,l;
long long ans;
int main()
{
    scanf("%d%d",&n,&m);
    for(i=m+1;i<=n-m;i++)
        for(j=n-m;j>m;j--)
        {
            k=((n+1-j)*(-i+2*j)-1)/(i+j)-m;
            if(k<0)k=0;
            if(k>n-m-m)k=n-m-m;
            ans+=k;
        }
    cout<<ans*3<<endl;
    return 0;
}


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

int main()
{
    long long n;
    cin >> n;
    string s= to_string(n);
    long long l=s.length(),ans=1,pro=1,i,j;
    //cout << l << endl;
    if(l==1){
        cout << n << endl;
        return 0;
}
for(i=0;i<n;i++)
{
    ans=ans*(s[i]-'0');
}
pro=max(pro,ans);
    for(i=0;i<l;i++)
    {
        ans=1;
            for(j=0;j<i;j++)
            {
                if(s[j]-'0'!=0)
                    ans*=(s[j]-'0');
            }
            if(((s[i]-'0')-1)!=0)
                ans*=((s[i]-'0')-1);
            //cout << pow(9,l-i-1);
                ans*=(long long)pow(9,l-i-1);
    //cout << ans << endl;
             pro=max(pro,ans);
    }
    cout << pro << endl;
}


#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c；

		int l, z, h;
		cin >> l >> z >> h;
		if (l >= a)
		{
			l -= a;
			if (l + z >= b)
			{
				int lz = l + z - b;
				if (lz + h >= c)
				{
					cout << "YES" << endl;
					continue;
				}
			}
		}
		cout << "NO" << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,i,j,k,l,n,c=0;
	cin>>n>>a>>b;
	if(b>=0)
	{
		int flag=0;

		for(i=a;i<=n;i++)
	{
		flag=1;

		c++;
		//cout<<i<<" ";
		if(c==b)
		break;
			//cout<<i<<" ";
		if(i==n&&c<b)
		i=0;

		}
		if(i==n)
		i=1;
		else
		i=i+1;
		if(n>1)
		cout<<i<<endl;
		else
		cout<<1<<endl;
	}
	else
	{
		long long c=0;

		for(i=a;i>=1;i--)
		{
			c++;
		//	cout<<c<<" "<<i<<endl;
			if(c==abs(b))
			break;
	if(i==1&&c<abs(b))
		i=n+1;
		//cout<<i<<" ";
	}
	if(i==1)
	i=n;
	else
	i=i-1;
	//cout<<i<<endl;
if(n>1)
	cout<<i<<endl;
	else
	cout<<1<<endl;

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
		if(n<abs(b)+a){
			printf("%d\n",(abs(b)+a)%n+a+1);}
		else{printf("%d\n",abs(b)%n+a);}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <iomanip>
#include <vector>
#include <set>
#include <stack>
#include <math.h>
#include <queue>
#include <stdlib.h>
#define F first
#define S second
#define ll long long
#define ull unsigned long long
using namespace std;
ll a,b,w,x,c,r;
int main() {
    cin >> a >>b >> w >> x >> c;
    if (c>a)
	r=(1ll * (c - a) * x - b + w - x - 1) / (w - x);
	cout << c-a+r; else
	cout << 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
int main()
{
	int n,m,p=0,q=0;cin>>n>>m;
	vector<int>a(n);
	fr(i,0,n) cin>>a[i],p=max(p,a[i]);
	if(p<=m) cout<<n;
	else
	{
	for(int i=n-1;i>=0;i--)
	{
		if(a[i]>m && a[i]>(p-(p%m))) q=max(q,i+1);
	}
	cout<<q;
    }
	return 0;
};


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

int main()
{
	int i, j, n, k;
	string c;
	cin >> n;
	char *a = new char[n];
	getline(cin, c);
	getline(cin, c);
	int f = 0;
	for (i = 0; i < n; i++)
		a[i] = '0';
	for (i = 0; i < c.size(); i++)
	{
		j = 0;
		k = 0;
		while (k != 1 && a[j] != '0' && j < n || j < 1)
		{
			if (c[i] == a[j])
				k = 1;
			j++;
		}
		if (k == 0)
		{
			a[j] = c[i];
			f++;
		}
		if (f == 26)
		{
			cout << "YES";
			getchar();
			getchar();
			return 0;
		}
	}
	cout << "NO";
	getchar();
	getchar();
	return 0;
}


/*
 * Author:  Eyelids
 * Created Time:  2013/8/19 0:21:24
 * File Name: 336E.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
using namespace std;
const double eps(1e-8);
typedef long long lint;
#define clr(x) memset( x , 0 , sizeof(x) )
#define sz(v) ((int)(v).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clrs( x , y ) memset( x , y , sizeof(x) )
#define mod 1000000007
int n, m;
int f[210][210][3][5], a[5], b[5];
int c[210][210];
inline void Add(int &a, int b) {
        a += b;
        if (a >= mod) a -= b;
}
inline int Mul(int a, int b) {
        lint ret = a;
        ret *= b;
        return (ret % mod);
}

int Calc(int n, int m, int cur, int type) {
        int ret = f[n][m][cur][type];
        if (ret != -1) return ret;
        ret = 0;

        if (type == 2) {
            Add(ret, Calc(n, m, cur, 1));
            if (cur == 0) {
                if (m >= 1) {
                    Add(ret, Mul(Calc(n, m - 1, 1, 1), 4));
                    Add(ret, Mul(Calc(n, m - 1, 2, 1), 4));
                }
                if (m >= 2) {
                    Add(ret, Mul(Calc(n, m - 2, 4, 1), 2));
                    Add(ret, Mul(Calc(n, m - 2, 2, 1), 4));
                    Add(ret, Mul(Calc(n, m - 2, 3, 1), 8));
                    if (m == 2) Add(ret, 2);
                }
                if (m >= 3) {
                    Add(ret, Mul(Calc(n, m - 3, 3, 1), 4));
                    if (m == 3) Add(ret, 4);
                }
                if (m == 4) Add(ret, 1);
            }
            if (cur == 1) {
                if (m >= 1) {
                    Add(ret, Mul(Calc(n, m - 1, 2, 1), 2));
                    Add(ret, Mul(Calc(n, m - 1, 3, 1), 2));
                    Add(ret, Mul(Calc(n, m - 1, 4, 1), 1));
                }
                if (m >= 2) {
                    Add(ret, Mul(Calc(n, m - 2, 3, 1), 3));
                    if (m == 2) Add(ret, 2);
                }
            }
            if (cur == 2) {
                if (m >= 1) {
                    Add(ret, Mul(Calc(n, m - 1, 3, 1), 2));
                    if (m == 1) Add(ret, 1);
                }
                if (m == 2)
                    Add(ret, 1);
            }
            if (cur == 3 && m == 1) Add(ret, 1);
            if (cur == 4) {
                if (m >= 1)
                    Add(ret, Mul(Calc(n, m - 1, 3, 1), 2));
                if (m == 2)
                    Add(ret, 1);
            }
        }
        if (type == 1) {
            if (n == 0)
                return (m == 0) ? 1 : 0;
            int bits = a[cur] << 1, cons = b[cur];
            for (int i = 0; (i <= cons) && (i <= m); i ++)
                for (int j = 0; (j <= bits - 2 * i) && (j + i <= m); j ++)
                    Add(ret, Mul(Calc(n, m - i - j, cur, 0), Mul(c[cons][i], c[bits - 2 * i][j])));
        }
        if (type == 0) {
            int bits = a[cur];
            for (int i = 0; (i <= m) && (i <= bits); i ++)
                Add(ret, Mul(Calc(n - 1, m - i, cur, 2), c[bits][i]));
        }
        return ret;
}

int main(){
        scanf("%d%d", &n, &m);
        memset(f, -1, sizeof(f));
        a[0] = 4, a[1] = 3, a[2] = 2, a[3] = 1, a[4] = 2;
        b[0] = 4, b[1] = 2, b[2] = 1, b[3] = 0, b[4] = 0;
        for (int i = 0; i <= 200; i ++) {
            c[i][0] = 1;
            for (int j = 1; j <= i; j ++)
                Add(c[i][j], c[i - 1][j]), Add(c[i][j], c[i - 1][j - 1]);
        }
        lint fact = 1;
        for (int i = 1; i <= m; i ++) fact = Mul(fact, i);

        printf("%d\n", Mul(fact, Calc(n, m, 0, 2)));

        return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <ctime>

using namespace std;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll rdtsc() {
    ll tmp;
    asm("rdtsc" : "=A"(tmp));
    return tmp;
}

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1e-9)
#define INF ((int)1e9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int MOD = (int)1e9 + 7;

inline void add(int &x, int y) {
	if ((x += y) >= MOD)
		x -= MOD;
}

inline int mult(int x, int y) {
	return (long long)x * y % MOD;
}

const int maxn = 201;
int d[maxn][maxn][1 << 4];

const int maxCntIds = (int)1e5;
int cntIds;
int prec[maxCntIds][3];

void gen(int iter, int mask, int left, int putk) {
	if (iter == 12 + 4 + 4 + 4) {
		assert(cntIds < maxCntIds);
		prec[cntIds][0] = mask, prec[cntIds][1] = left, prec[cntIds][2] = putk;
		cntIds++;
		return;
	}
	gen(iter + 1, mask, left, putk);
	if (iter < 12)
		gen(iter + 1, mask ^ (1 << iter), left, putk + 1);
	else {
		if (iter - 12 < 4) {
			int addMask = (7 << (3 * (iter - 12))) ^ (7 << (3 * ((iter - 12 + 1) & 3)));
			if (!(addMask & mask))
				gen(iter + 1, mask ^ addMask, left ^ (1 << (iter - 12)) ^ (1 << ((iter - 12 + 1) & 3)), putk + 1);
		} else {
			if (iter - 16 < 4) {
				int addMask = (7 << (3 * (iter - 16)));
				if (!(addMask & mask))
					gen(iter + 1, mask ^ addMask, left ^ (1 << (iter - 16)), putk + 1);
			} else {
				int addMask = (1 << (3 * (iter - 20))) ^ (1 << ((3 * (iter - 20) - 1) & 3));
				if (!(addMask & mask))
					gen(iter + 1, mask ^ addMask, left, putk + 1);
			}
		}
	}
}

void countPrec() {
	cntIds = 0;
	gen(0, 0, 0, 0);
}

const int cnt0 = 8;
const int mask0[cnt0] = {1, 2, 4, 8, 3, 6, 12, 9};

int gen0(int iter, int taken, int left) {
	if (left > cnt0 - iter)
		return 0;
	if (iter == cnt0)
		return 1;
	int ans = gen0(iter + 1, taken, left);
	if (left && !(taken & mask0[iter]))
		add(ans, gen0(iter + 1, taken | mask0[iter], left - 1));
	return ans;
}

void countD(int n0, int k0) {
	countPrec();

	for (int k = 0; k <= k0; k++)
		for (int taken = 0; taken < (1 << 4); taken++)
			d[0][k][taken] = gen0(0, taken, k);

	for (int n = 1; n <= n0; n++) {
		for (int k = 0; k <= k0; k++) {
			for (int taken = 0; taken < (1 << 4); taken++) {
				int &cur = d[n][k][taken];
				cur = 0;
				if (!k) {
					cur = 1;
					continue;
				}
				int maskFail = 0;
				for (int i = 0; i < 4; i++) {
					if (!((taken >> i) & 1))
						continue;
					maskFail ^= (7 << (3 * i));
				}

				for (int maskId = 0; maskId < cntIds; maskId++) {
					int mask = prec[maskId][0], left = prec[maskId][1], putk = prec[maskId][2];
					if (mask & maskFail)
						continue;
					if (putk > k)
						continue;
					left |= taken;
					add(cur, d[n - 1][k - putk][left]);
				}
			}
		}
	}
}

bool solve() {
	int n, k;
	if (scanf("%d%d", &n, &k) < 1)
		return 0;

	countD(n, k);
	int res = d[n][k][0];
	for (int i = 1; i <= k; i++)
		res = mult(res, i);
	printf("%d\n", res);
	return 1;
}

int main() {
	srand(rdtsc());
#ifdef DEBUG
	freopen(TASKNAME".in", "r", stdin);
	freopen(TASKNAME".out", "w", stdout);
#endif

	while (1) {
		if (!solve())
			break;
		#ifdef DEBUG
			eprintf("%.18lf\n", (double)clock() / CLOCKS_PER_SEC);
		#endif
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	int w=a[0],s=3;
	for(i=1;i<n;i++)
	{
		s=6-w-s;
		if(s==a[i])
		{
			cout<<"NO"<<endl;
			return 0;
		}
		w=a[i];
	}
	cout<<"YES"<<endl;
	return 0;
}


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

const int N = 1e9 + 7, P = 130 + 10, Q = 2e6 + 10;
long long soorat[P], choose[P][P], dp[P][P], ans[Q], choose2[2][P];
int n, p, q;
long long finalans;

void fillchoose(int ii, int j){
	int nn = n - ii, jc = j, ss = nn - jc + 1;

	if(j == 0 || nn < 0 || ss < 0)
		return;

	for (int i = ss; i <= nn; i++)
		soorat[i - ss] = (unsigned)i;

	for (; j > 0; j--){
		int x = j, gcdtmp;
		for (int i = ss; i <= nn && x > 1; i++){
			gcdtmp = __gcd(soorat[i - ss], x);
			soorat[i - ss] /= gcdtmp;
			x /= gcdtmp;
		}
	}

	choose[ii][jc] = 1;
	for (int i = ss; i <= nn; i++)
		choose[ii][jc] *= (unsigned)soorat[i - ss];
}

void filldp(int i, int j){
	for (int k = 1; k <= min(i, n - p + i - 1); k++)
		dp[i][j] = (dp[i][j] + (choose[p - i][k] * dp[i - k][j - 1]));
}

void fillans(int t){
	choose2[t % 2][0] = 1;
	for (int i = 1; i <= p; i++)
		choose2[t % 2][i] = choose2[1 - (t % 2)][i] + choose2[1 - (t % 2)][i - 1];

	for (int i = 0; i <= p; i++)
		ans[t] = ans[t] + (choose2[t % 2][i] * dp[p][i]);

	ans[t] = (unsigned)(ans[t] * t);
}

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

	cin >> n >> p >> q;

	for (int i = 0; i <= p; i++)
		for (int j = 0; j <= p; j++)
			fillchoose(i, j);

	for (int i = 0; i <= p; i++)
		dp[i][0] = 1;

	for (int j = 1; j <= p; j++)
		for (int i = 0; i <= p; i++)
			filldp(i, j);

	choose2[0][0] = 1;

	for (int t = 1; t <= q; t++)
		fillans(t);

	for (int i = 1; i <= q; i++)
		finalans ^= ans[i];

	cout << finalans << '\n';

	return 0;
}


#include <bits/stdc++.h>

#define LL long long int
#define ULL unsigned long long int

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REV_FOR(i,a,b) for(int i=a;i>=b;i--)
#define _cin  ios_base::sync_with_stdio(0); cin.tie(0);

#define clear(a) memset(a,0,sizeof(a))

#define MOD 1000000007
#define INF (1<<28)
#define mx = 10e9
#define mn = -1*mx

#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)

#define pb push_back
#define pf pop_front()
#define p push
#define f first
#define s second

using namespace std;

main()
    {
    int val_X = 0, val_0 = 0;
    char a[10][10];
    FOR(i,1,10)
        FOR(j,1,10)
            a[i][j] = '.';
    FOR(i,1,3)
        FOR(j,1,3)
            {
            cin>>a[i][j];
            if(a[i][j] == 'X')
                val_X++;
            if(a[i][j] == '0')
                val_0++;
            }
    bool win_X = false, win_0 = false;
    FOR(i,1,3)
        FOR(j,1,3)
            {
            if(a[i][j] == 'X' && ((a[i+1][j] == 'X' && a[i+2][j] == 'X') || (a[i][j+1]  == 'X' && a[i][j+2] == 'X') || (a[i+1][j+1] == 'X' && a[i+2][j+2] == 'X')))
                win_X = true;
            if(a[i][j] == '0' && ((a[i+1][j] == '0' && a[i+2][j] == '0') || (a[i][j+1]  == '0' && a[i][j+2] == '0') || (a[i+1][j+1] == '0' && a[i+2][j+2] == '0')))
                win_0 = true;

            }
    cout<<win_X<<" "<<win_0;
    if(win_X && (val_X > val_0) && !win_0)
        printf("the first player won");
    else if(win_0 && (val_X == val_0) && !win_X)
        printf("the second player won");
    else if(!win_0 && !win_X)
        {
        if(val_X == val_0)
            printf("first");
        else if (val_X - val_0 == 1)
            printf("second");
        else if(val_X + val_0 == 9)
            printf("draw");
        else
            printf("illegal");
        }
    else
        printf("illegal");
    }


  #include<cstdio>
  #include <iostream>

  int p1, p2, p3, p4, a, b, ans, p;

  using namespace std;

  int min(int a1, int a2, int a3, int a4)  {
  	if (a1 < a2 && a1 < a3 && a1 < a4)
  		return a1;
  	if (a2 < a1 && a2 < a3 && a2 < a4)
  	    return a2;
  	if (a3 < a4)
  	 	return a3;
  	return a4;
  }

  int main()  {
  	cin >> p1 >> p2 >> p3 >> p4 >> a >> b;
  	ans = 0;
  	for (int i = a; i < b; i++)  {
  		p = min(p1, p2, p3, p4);
  		if (i < p)
  			ans++;
  	}
  	cout << ans << endl;
  	return 0;
  }


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

#define isprime(x) (!np[x]&&(x&1))
#define ll long long
#define MUHAMMED_HISHAM ios_base::sync_with_stdio(false);cin.tie(NULL);/*
const int mxxx = 100005;
bool np[mxxx];
int si, primes[mxxx];
void sieve()
{
    si = 0;
    np[0] = np[1] = 1;
    for (long long i = 3; i * i <= mxxx; i += 2)
    {
        if (np[i] == 0)
        {
            for (long long j = i * i; j < mxxx; j += (i * 2))
                np[j] = 1;
        }
    }
    primes[si++] = 2;
    for (int i = 0; i < mxxx; i++)
    {
        if (np[i] == 0 && i % 2)
            primes[si++] = i;
    }
}

void primeFactors(int n)
{
    vector<int>v;
    while (n % 2 == 0)
    {
        v.push_back(2);
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.push_back(i);
            n = n / i;
        }
    }
    if (n > 2)
    {
        v.push_back(n);
    }
    v.push_back(1);
    for (int i=0;i<v.size(),i++)
    {
        cout<<it<<" ";
    }
}
*/
/////////////////////////power////////////////constant, power
long long  power(long long   x, long long  y)
{
    long long   temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if (y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}

long long  fast_power(long long  x, long long  n, long  mood)
{
    if (n == 0)return 1;
    else  if (n % 2 == 0)return fast_power(x * x, n / 2, mood);
    else  return (x * fast_power((x * x) % mood, (n - 1) / 2, mood));
}

/*

ll solve(ll i,ll last,ll cap)
{

    if(i>n)
    {
        // cout<<cap<<endl;
        if(cap==0)
        {
            return 0;
        }
        else return 1e9+100;
    }
    ll &ret=dp[i][last][cap];
    if(ret!=-1)
    {
        return ret;
    }
    ret=1e9+100;
    if(last==0)return ret=min(solve(i+1,i,cap-1),solve(i+1,last,cap));
    return ret=min((cap>0)?solve(i+1,i,cap-1)+(a[i]+a[last])*(i-last):100000500,solve(i+1,last,cap));
}
*/

/*
ll NCR[31][31];

ll compinatorics(int n,int r)
{
    NCR[0][0]=1;
    for (int i = 1; i <= 30; ++i)
    {
        NCR[i][0] = 1;
        NCR[i][i] = 1;
        for (int j = 1; j <= i; ++j)
        {
            NCR[i][j] = NCR[i - 1][j - 1] + NCR[i - 1][j];
        }
    }
    return NCR[n][r];
}
*/
//////////////////////////////////////////////////////////////////
int main()
{
    int  a,b;
    cin>>a>>b;
    unordered_map<ll,int>m,d;
    d[a]=1;ll x=a;
    for (ll i=0; i<9000000; i++,x+=a)
    {
        d[a+x]=d[x]+1;
    }
    m[b]=1; x=b;
    for (ll i=0; i<9000000; i++,x+=b)
    {
        m[b+x]=m[x]+1;
        if (d[x+b]!=0)
        {
            if (a>b)     m[x+b]--;
            else if (a<b)d[x+b]--;
            if (d[x+b]>m[x+b])     cout<<"Dasha";
            else if (d[x+b]<m[x+b])cout<<"Masha";
            else cout<<"Equal";
            break;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int u[102][102];
int main(){
	int n;
	cin >> n;
	int sum = 0, a = (n-1)/2;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> u[i][j];
			if (i == j){
				sum += u[i][j];
			}
			if (j = n - i - 1) {
				sum += u[i][j];
			}
			if (i == a) {
				sum += u[i][j];
			}
			if (j == a) {
				sum += u[i][j];
			}
		}
	}
	cout << sum - (3 * u[a][a]);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
int a[13];
int main(){
	int k;scanf("%d",&k);
	for(int i=1;i=12;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+13);
	int ans=0,cnt=0;
	for(int i=1;i<=12;i++){
		ans+=a[i];
		cnt++;
		if(ans>=k)break;
	}
	if(ans<k){printf("-1");return 0;}
	printf("%d",cnt);
	return 0;

}


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

ll z=998244353;

ll f[200001];

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;

    long long res = binpow(a, b / 2);

    if (b % 2){
        ll xx=res;
        xx*=res;
        xx%=z;
        xx*=a;
        xx%=z;
        return xx;
    }
    else{
        return (res * res)%z;

    }
}

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

    f[0]=1;
    for(int i=1;i<2e5;i++){
        f[i]=f[i-1]*i;
        f[i]%=z;
    }

ll val=0;
for(int i=n-2;i<=m-1;i++){
    ll xx=f[i];
    xx*=binpow(f[n-2],z-2);
    xx%=z;
    xx*=binpow(f[i-n+2],z-2);
    xx%=z;
val+=xx;
val%=z;
}
    ll ans=0;

for(int i=1;i<n-1;i++){
    ll xx=f[n-3];
    xx*=binpow(f[i-1],z-2);
    xx%=z;
    xx*=binpow(f[n-3-x+1],z-2);
    xx%=z;
    xx*=(n-2);
    xx%=z;
    xx*=val;
    xx%=z;
    ans+=xx;
    ans%=z;
}

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


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

vector<int> v;

int cont = 0, sum = 0;
int n, k;

void fun(int i){
	int currV = v[i];
	sum = currV;
	cont = 1;
	i++;

	for(; i < (int)v.size(); i++){
		if(cont == k) return;
		if(abs(v[i] - currV) > 1){
			sum += v[i];
			currV = v[i];
			cont++;
		}
	}
}

int main(){
	string s;

	cin>>n>>k;

	cin>>s;

	sort(s.begin(), s.end());

	for(char &c : s){
		v.push_back(int(c - 'a') + 1);
	}
	int ans = (int) 1e9;
	for(int i = 0; i < (int)v.size()-1; i++){
		fun(i);

		if(cont == k){
			ans = min(ans, sum);
		}
	}
	if(ans == (int) 1e9)
		cout<<"-1\n";
	else
		cout<<ans<<endl;

	return 0;
}