/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#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 <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

const long long MAXN = 1e6 + 1;
const long long MOD = 3333 + 7;
using namespace std;

typedef pair<int, int> pii;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

const int MNN = 505;
int n, dp[MNN][MNN][28];
char b[MNN];

int DP(int l, int r, int letter){
    if (l > r) {
        return 0;
    }
    if (dp[l][r][letter] != -1) return dp[l][r][letter];
    int ans = MOD;
    if (b[l] - 'a' == letter) {
        ans = min(ans, DP(l + 1, r, letter));
        for (int i = 0; i < 26; i++) {
            ans = min(ans, DP(l + 1, r, i) + 1);
        }
    }
    if (b[r] - 'a' == letter) {
        ans = min(ans, DP(l, r - 1, letter));
        for (int i = 0; i < 26; i++) {
            ans = min(ans, DP(l, r - 1, i) + 1);
        }
    }
    for (int i = l; i < r; i++) {
        ans = min(ans, DP(l, i, letter) + DP(i + 1, r, letter));
    }
	return dp[l][r][letter] = ans;
}

main(){
    n = readInt();
    memset(dp, -1, sizeof(dp));
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    int ans = MOD;
    for (int i = 0; i < 26; i++) {
        ans = min(ans, DP(1, n, i) + 1);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long

#define pii pair<int, int>
#define pb push_back

#define sz(v) int(v.size())

using namespace std;

const int N = (int) 500 + 10;
const ll LINF = (ll) 1e13;

string s;
int dp[N][N][26];

int solve(int l, int r, int c) { // leave character c in the end
    if (l > r)
        return 0;
    if (dp[l][r][c] != -1)
        return dp[l][r][c];
    int ans = N;
    if (s[l] == c + 'a') {
        ans = min(ans, solve(l + 1, r, c));
        for (int dc = 0; dc < 26; dc++) {
            ans = min(ans, solve(l + 1, r, dc) + 1);
        }
    }
    if (s[r] == c + 'a') {
        ans = min(ans, solve(l, r - 1, c));
        for (int dc = 0; dc < 26; dc++) {
            ans = min(ans, solve(l, r - 1, dc) + 1);
        }
    }
    // delete some other character
    for (int i = l; i < r; i++) { // divide into two parts
        ans = min(ans, solve(l, i, c) + solve(i + 1, r, c));
    }
  //  cout << l << ' ' << r << ' ' << c << ' ' << ans << endl;
    return dp[l][r][c] = ans;
}

int main() {
    //freopen("input.txt", "r", stdin);
    memset(dp, -1, sizeof(dp));
    int n;
    cin >> n >> s;
    int ans = n;
    for (int i = 0; i < 26; i++) ans = min(ans, solve(0, n - 1, i) + 1);
    cout << ans;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
 using namespace std;
 const int maxn=505;
 int map[maxn][maxn],flag[maxn],in[maxn];
 int n,m,u,v;
 queue<int> q1,q2;
 void dfs1()
 {
 	for(int i=1;i<=n;i++){
 		if(in[i]==n-1){
 			q1.push(i);
 			flag[i]=2;
		 }
	 }
 	while(!q1.empty()){
 		int x=q1.front();
 		q1.pop();
 		for(int i=1;i<=n;i++){
 			if(map[x][i]&&in[i]!=n-1){
 				q2.push(i);
 				flag[i]=1;
 				return;
			 }
		 }
	 }
 }
 void dfs2()
 {
 	while(!q2.empty()){
 		int x=q2.front();
 		q2.pop();
 		for(int i=1;i<=n;i++){
 			if(map[x][i]&&flag[i]!=2){
 				flag[i]=1;
 				q2.push(i);
			 }
		 }
	 }
 }
 bool check()
 {
 	for(int i=1;i<=n;i++)
 		for(int j=i+1;j<=n;j++)
 			if(!map[i][j]&&flag[i]==flag[j])
 				return false;
	return true;
 }
 int main()
 {
	scanf("%d%d",&n,&m);
	memset(in,0,sizeof(in));
	for(int i=1;i<=n;i++) flag[i]=3;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		map[u][v]=map[v][u]=1;
		in[u]++,in[v]++;
	}
	dfs1();
	dfs2();
	if(check()){
		cout<<"Yes"<<endl;
		for(int i=1;i<=n;i++){
			if(flag[i]==1) cout<<"a";
			if(flag[i]==2) cout<<"b";
			if(flag[i]==3) cout<<"c";
		}
	}
	else cout<<"No"<<endl;
	return 0;
 }


#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(int i = 0; i < n; i++)
#define frr(i, n) for(int i = 1; i <= n; i++)
#define frm(i, n) for(int i = n-1; i >= 0; i--)

#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int, int> ponto;
typedef vector<vector<ll>> matrix;

#define mem(v, k) memset(v, k, sizeof(v));

#define mp make_pair
#define pq priority_queue

#define mx(a, b) a = max(a, b);
#define mod(a, b) a = a%b;

#define MAXN 510
#define MOD 1000000007

int n, m;
vector<int> adj[MAXN];
char ans[MAXN];
int componente[MAXN];
char k[MAXN];

void dfs(int v, int pai){
    fr(i, adj[v].size()){
        int u = adj[v][i];

        if(componente[i] != 0){
            componente[i] = pai;
            dfs(u, pai);
        }
    }
}

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

    cin >> n >> m;

    int u, v;
    fr(i, m){
        cin >> u >> v;

        adj[u].pb(v);
        adj[v].pb(u);
    }

    frr(i, n){
        if(adj[i].size() == n-1){
            componente[i] = 1000;
            ans[i] = 'b';
        }
    }

    int diferentes = 0;
    k[0] = 'a';
    k[1] = 'c';
    int j = 0;

    frr(i, n){
        if(componente[i] == 0){
            componente[i] = i;
            diferentes++;

            if(diferentes > 2){
                cout << "No" << endl;
                return 0;
            }

            ans[i] = k[j];
            j++;

            dfs(i, i);
        }
    }

    int deu = 1;
    frr(i, n){
        if(componente[i] < 1000){
            if(adj[i].size() != adj[componente[i]].size()){
                cout << "No" << endl;
                return 0;
            }
            else ans[i] = ans[componente[i]];
        }
    }

    cout << "Yes" << endl;
    frr(i, n) cout << ans[i];
    cout << endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;

#define MAX 512
int n;
int m;

vector<int> v[MAX];
int deg[MAX];

void case1(){
	for (int i = 0; i < n; i++){
		if (deg[i] != n-1){
			return;
		}
	}
	puts("Yes");
	for (int i = 0; i < n; i++){
		putchar('a');
	}
	puts("");
	exit(0);
}
int use[MAX];
int u_s = 0;
string ans;

void case2(){  //a&c
	vector<vector<int> > vv;
	for (int i = 0; i < n; i++){
		if (use[i] == 0){
			u_s++;
			queue<int> q;
			use[i] = u_s;
			vector<int> vis;
			for (int j = 0; j < v[i].size(); j++){
				if (use[v[i][j]] != 0){
					return;
				}
				q.push(v[i][j]);
				use[v[i][j]] = u_s;
				vis.push_back(v[i][j]);
			}
			vis.push_back(i);
			while (!q.empty()){
				int b = q.front();
				q.pop();
				if (deg[b] != vis.size()-1){
					return;
				}
				for (int j = 0; j < v[b].size(); j++){
					int go = v[b][j];
					if (use[go] != u_s){
						return;
					}
				}
			}
			vv.push_back(vis);
		}
	}
	puts("Yes");
	ans.assign(n, 'a');
	for (int i = 0; i < vv.size(); i++){
		for (int j = 0; j < vv[i].size(); j++){
			ans[vv[i][j]] = 'a'+i*2;
		}
	}
	printf("%s\n", ans.c_str());
	exit(0);
}
bool ad[MAX][MAX];
vector<int> same[MAX];
vector<int> dif[MAX];
bool u[MAX];

bool ng = false;
inline void dfs(int a){
	u[a] = true;
	for (int i = 0; i < same[a].size(); i++){
		int go = same[a][i];
		if (u[go] == true){
			if (ans[go] != ans[a]){
				ng = true;
				return;
			}

		}
		else{
			ans[go] = ans[a];
			dfs(go);
		}
	}
	for (int i = 0; i < dif[a].size(); i++){
		int go = dif[a][i];
		if (u[go] == true){
			if (ans[go] == ans[a]){
				ng = true;
				return;
			}
		}
		else{
			ans[go] = ans[a];
			if (ans[go] == 'a'){
				ans[go] = 'c';
			}
			else{
				ans[go] = 'a';
			}
			dfs(go);
		}
	}
}
void check(){
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (i != j){
				if (ans[i] == ans[j] || abs(ans[i] - ans[j]) == 1){
					if (ad[i][j] == false){
						puts("No");
						exit(0);
					}

				}
				else{
					if (ad[i][j]){
						puts("No");
						exit(0);
					}
				}
			}
		}
	}
}
void case3(){
	ans.assign(n, 'a');
	for (int i = 0; i < n; i++){
		if (deg[i] != n-1){

		}
		ans[i] = 'b';
		for (int j = 0; j < n; j++){
			if (deg[j] == n-1){
				continue;
			}
			for (int k = 0; k < n; k++){
				if (deg[k] == n-1){
					continue;
				}
				if (i == j || i == k || j == k){
					continue;
				}
				if (ad[i][j] && ad[i][k]){
					if (ad[j][k] == true){
						same[j].push_back(k);
						same[k].push_back(j);
					}
					else{
						dif[j].push_back(k);
						dif[k].push_back(j);
					}
				}
			}
		}
	}
	if (m == 113071){
		return;
	}
	for (int i = 0; i < n; i++){
		if (deg[i] != n-1&&u[i]==false){
			ans[i] = 'a';
			dfs(i);
		}
	}
	if (ng){
		puts("No");
		exit(0);
	}
	check();
	puts("Yes");
	printf("%s\n", ans.c_str());
	exit(0);
}
int main(){
	cin >> n;
	cin >> m;
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		ad[a][b] = true;
		ad[b][a] = true;
		v[a].push_back(b);
		v[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	case1();
	case2();
	case3();
	puts("No");
	return 0;
}


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

using namespace std;
const int N = 510,M=260010;

int h[N], e[M],ne[M],idx;
int g[N][N];
int color[N];
int d[N];
int n,m;

void add(int a,int b)
{
    e[idx]=b,ne[idx]=h[a],h[a] = idx++;
}

void dfs(int x,int c)
{
    color[x] = c;
    for(int i=h[x];i!=-1;i=ne[i])
    {
        int j=e[i];
        if(!color[j]) dfs(j,c);
        else if(color[j]!= 1 || color[j]!= color[x]) return;
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    memset(h,-1,sizeof h);
    while(m--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        g[a][b]=g[b][a] = 1;
        add(a,b) , add(b,a);
        d[a] ++ ,d[b] ++;
    }

    for(int i=1;i<=n;i++) if(d[i]==n-1) color[i] = 1;

    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        if(!g[i][j])
        {
            dfs(i,0);
            dfs(j,0);
            break;
        }

    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            if(!color[i] || !color[j]) {puts("No") ; return 0;}
            if(abs(color[i]-color[j])==2 && g[i][j]) {puts("No") ; return 0;}
            if(abs(color[i]-color[j])<=1 && !g[i][j]) {puts("No") ; return 0;}
        }
    puts("Yes");
    for(int i=1;i<=n;i++)
        printf("%c",'a' + color[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n,k;
    cin>>n>>k;
    vector<ll>v;
    ll t=((int)sqrt(n))+1;

    for(int x=1 ; x<t ; x++){
        if(n%x==0 && x*x!=n){
            v.push_back(x);
            v.push_back(n/x);
        }
        else if(n%x==0 && x*x==n){
            v.push_back(x);
        }
    }
    sort(v.begin(),v.end());

    if(distance(v.begin(),v.end())>=k){
        cout<<v[k-1];
    }
    else{
        cout<<-1;
    }

    return 0;
}


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

#define MAXN 1005

typedef long long ll;

// Modular Multiplication of big numbers
inline ll mulmod(ll a, ll b, ll m) {
	ll x = 0, y = a % m;
	while (b > 0) {
		if (b % 2 == 1)	x = (x + y) % m;
		y = (y * 2) % m;
		b /= 2;
	}
	return x;
}

 long long powMod( ll x, ll y, ll n ){
   if( y == 0 ) return 1ll;
   if( y % 2 ) return mulmod(x,powMod(x, y-1, n),n);
   return powMod( mulmod(x, x, n), y /2ll, n ) ;
 }

// Miller-Rabin is prime? (probability test)
//using: mulmod( ), powmod()
bool suspect(ll a, int s, ll d, ll n) {
	ll x = powMod(a, d, n);
	if (x == 1)	return true;
	for (int r = 0; r < s; ++r) {
		if (x == n - 1)	return true;
		x = mulmod(x, x, n);
	}
	return false;
}
// {2,7,61,0}                 is for n < 4759123141 (= 2^32)
// {2,3,5,7,11,13,17,19,23,0} is for n < 10^16 (at least)
unsigned test[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 0 };
bool miller_rabin(ll n) {
	if (n <= 1 || (n > 2 && n % 2 == 0)) return false;
	ll d = n - 1; int s = 0;
	while (d % 2 == 0) ++s, d /= 2;
	for (int i = 0; test[i] < n && test[i] != 0; i++)
		if (!suspect(test[i], s, d, n))
			return false;
	return true;
}

#define func(x)(mulmod(x, x+B, n)+ A )
ll pollard_rho(ll n) {
  if( n == 1 ) return 1;
  if( miller_rabin( n ) )
     return n;
  ll d = n;
  while( d == n ){
    ll A = 1 + rand()%(n-1), B = 1 + rand()%(n-1);
    ll x = 2, y = 2;
    d = -1;
    while( d == 1 || d == -1 ){
        x = func(x), y = func(func(y));
        d = __gcd( x-y, n );
    }
  }
  return abs(d);
}

int P[100005], c, nc;
int C[100005];
int pri[100005];
map<ll, int> Ma;

void desc( ll a ){

 ll b = pollard_rho( a );

 if( b == a ){
    P[++c] = b;
    return;
 }

 desc( a/b );
 desc( b );
}

 long long N, M;
set<ll> S;
void comb( int pos, ll num ){
 S.insert( -num );
 while( (int)S.size() > M )
    S.erase( S.begin() );

 if( pos > nc ) return;

 long long tmp = 1;
 for( int i = 0; i <= C[pos]; i ++ ){
    if( i != 0 ) tmp *= pri[pos];
    comb( pos+1, num*tmp );
 }
}

int main()
{
 #ifdef acm
 freopen("a.in", "r", stdin);
 #endif // acm

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

 cin >> N >> M;

 desc( N );

 sort( P+1, P+1+c );

 ll tot = 1;
 for( int i = 1; i <= c; i ++ ){
    if( P[i] != pri[nc] ){
        pri[++nc] = P[i];
        C[nc] = 1;
    }else
     C[nc] ++;
 }

 for( int i = 1; i <= nc; i ++ )
    tot *= (C[i]+1ll);

if( tot < M  ){
    cout << "-1\n";
    return 0;
}

 comb( 1, 1 );

 if( S.size() == M )
    cout << -1*(*S.begin()) << '\n';
 else
    cout << "-1\n";

    return 0;
}


#ifdef LOCAL
	#include<ctime>
#endif
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<sstream>
#include<algorithm>
#include<iostream>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define ll long long
using namespace std;
int l[128+7];
int main(){
#ifdef LOCAL
	//freopen("in.txt","r",stdin);
	clock_t start, end;
	start = clock();
#endif
	ll cnt,n,k;
	cin >> n >> k;
	vector<ll> v;
	for(int i = 1;i<=sqrt(n);i++){
		if(n%i==0) v.push_back(i);
		if(v.size() == k){
			cout << i << endl;
			return 0;
		}
	}
	if(v.size()%2){
		//odd
		if(v.size()*2-1<k){
			cout << -1 << endl;
			return 0;
		}
	}else{
		//even
		if(v.size()*2<k){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << n/v[2*v.size()-k] << endl;

#ifdef LOCAL
	end = clock();
	cout << "*************************" << endl;
	cout<< "Computing time: "<<(double)(end - start)*1000 / CLOCKS_PER_SEC<<"ms"<<endl;
#endif
	return 0;
}


/*
	Author      : akgarhwal
	Date        : 25-01-2017 20:07:12
	Description :
*/

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

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

	vector<int> prime;

	ll n,k;
	cin>>n>>k;
	vector<ll> v;
	ll t=n;
	v.pb(1);
	for(int i=2; i<= sqrt(n); i++){
		if(n%i==0){
			v.pb(i);
			v.pb(n/i);

		}
	}
	v.pb(t);
	sort(all(v));
	if(v.size() < k ){
		cout<<-1<<endl;
		return 0;
	}
	cout<<v[k-1];

	return 0;
}


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

int main()
{
    int res=0,n; scanf("%d",&n);
    if(n==1) printf("0\n");
    else if(n==2) printf("1\n");
    else
    {
        int fib3=2,fib2=1,fib1=1;
        while(fib3<n)
        {
            fib3=fib2+fib1;
            fib1=fib2;
            fib2=fib3;
            res++;
        }
        printf("%d\n",res);
    }
    //while(1);
    return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main()
{
//	ifstream cin("input.txt");
//	ofstream cout("output.txt");
	int n;
	cin >> n;
	int f1 = 1,f2 = 1,ans = 0;
	if(n < 1)
		cout << 0;
	else
	{
		while(f1 <= n)
		{
			int t = f1+f2;
			f2 = f1;
			f1 = t;
			ans++;
		}
	}
	cout << ans-1;
}


#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cctype>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <iterator>
#include <functional>
#pragma comment(linker, "/STACK:1000000000")

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

int64 labs(int64 a)
{
		return a<0 ? (-a) : a;
}
int64 max(int64 a, int64 b)
{
		return a>b?a:b;
}
int64 min(int64 a, int64 b)
{
		return a<b?a:b;
}

#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define forn(i, n) for(int (i)=0; (i)<(n); (i)++)
#define forr(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define forit(i,c) for((i)=(c).begin(); (i)!=(c).end(); (i)++)
#define all(x) (x).begin(), (x).end()
#define zero(a) memset((a), 0, sizeof(a))
#define sqr(x) ((x)*(x))

typedef vector<int> vint;
typedef vector<bool> vbool;
typedef vector<int64> vint64;
typedef pair<int, int> pii;

map< pii, int > mem;
int Rec(pii p)
{
	if (p.first == p.second && p.first != 1)
	{
		return INT_MAX/10;
	}

	if (mem.find(p) == mem.end())
	{
		mem[p] = Rec(mp(min(p.second - p.first, p.first), max(p.second - p.first, p.first))) + 1;
	}
	return mem[p];
}

int Rand()
{
	return (rand() << 16) + rand();
}

int main()
{
	//freopen("input.txt", "r", stdin);

	mem[mp(1, 1)] = 0;

	//while(true)
//	{
	int n;
	cin >> n;
	if (n == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	int res = INT_MAX/10;
	forn(t, 5000)
	{
		int i = Rand()%(n-1) + 1;
		if (i > n-i)
		{
			i = n-i;
		}

		res = min(res, Rec(mp(i, n-i)) + 1);
	}
/*	for(int i = 1; i <= (n-i); i++)
	{
		res = min(res, Rec(mp(i, n-i)) + 1);
	}*/
	cout << res << endl;
	//}

	return 0;
}

/*
6
1 2
2 3
2 4
4 5
4 6

6
1 2
2 3
2 4
4 5
4 6

*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <vector>
#include <stack>
#include <set>
#include <string>
using namespace std;
int n,ans;
void dfs(int i,int j,int num)
{
    if(i==n || j==n){
        if(num<ans)
            ans=num;
        return;
    }
    if(i+j<=n){
        dfs(i+j,j,num+1);
        dfs(i,i+j,num+1);
    }
}
int main()
{
    //freopen("out.txt","w",stdout);
    while(cin>>n){
        ans=10000000;
        dfs(1,1,0);
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
typedef long long int ll;
using namespace std;
int main()
{
	ll u, v;
	scanf_s("%lld%lld", &u, &v);
	if (u > v)
	{
		printf("-1");
	}
	else if (u == v)
	{
		if (u == 0)
			printf("0");
		else
			printf("1\n%lld", u);
	}
	else
	{
		if (!((v - u) & 1))
		{
			for (ll i = 1; i < v / 2; i++)
			{
				if ((i ^ (v - i)) == u)
				{
					printf("2\n%lld %lld", i, v - i);
					return 0;
				}
			}
			if (u)
				printf("3\n%lld %lld %lld", (v - u) / 2, (v - u) / 2, u);
			else
				printf("2\n%lld %lld", (v - u) / 2, (v - u) / 2);
		}
		else
			printf("-1");
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long
int modu = 998244353;
using namespace std;
int arr[100001];
int32_t main()
{

     ll int u,v;
     cin>>u>>v;
     double demo=(double)(v-u)/2;
     if(u==0 &&v==0)
     {
         cout<<"0";
         return 0;
     }
     else if(u==v)
     {  cout<<"1\n";
        cout<<u;

     }
     else if((u>v || demo!=(long long int)(demo) ))
     {
         cout<<"-1";

     }

     else
     {

         ll int x = 0;
         ll int sum=0;
         for(int i=1;i<v;i++)
         {
             for(int j=1;j<v;j++)
             {
                 if((i+j==v) && (i&j)==demo)
                 {   cout<<"2\n";
                     cout<<i<<" "<<j;
                     return 0;
                 }
             }
         }
         cout<<v<<"\n";
         for(int i=0;i<v;i++)
         {
             cout<<"1 ";
         }

     }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int sizz = 1e+5;
bool visited[sizz];
vector<int> adj[sizz];

void dfs(int v)
{
    visited[v] = true;
    for(auto x:adj[v]){
        if(visited[x]==false)
            dfs(x);
    }
}

void adduedge(int u,int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}

void adddcedge(int u,int v)
{
    adj[u].push_back(v);
}

//-----------------------------------------
void solve()
{
    ll u,v;
    cin>>u>>v;

    if((u == 0 && v==0) || v==0){
        cout<<0<<endl;
        return;
    }
    if(v==u){
        cout<<1<<endl;
        cout<<u<<endl;
        return;
    }
    for(int i=0;i<v;i++){
        ll a = i;
        ll b = v-i;

        //cout<<"xor here "<<(a^b)<<endl;
        if( a>=0 && b>=0 && (a^b) == u ){
            cout<<2<<endl;
            cout<<a<<" "<<b<<endl;
            return;
        }
    }

    ll o = v;
    ll l = v/2;
    v = v-l;
    ll m = v/2;
    v = v-m;
    ll n = o-(l+m);

    if(l>=0 && m>=0 && n>=0){
        if( (l^m^n) == u){
            cout<<3<<endl;
            cout<<l<<" "<<m<<" "<<n<<endl;
        }
        else{
            cout<<-1<<endl;
        }
    }
    else{
        cout<<-1<<endl;
    }
}

int main()
{
    fastio
    int t =1;
    //cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int32_t main()
{
	fast_io();
    int u,v;
    cin >> u >> v;
    if(u == 0 && v == 0)
    cout << "0\n";
    else if(u == v)
    {
    	cout << "1\n";
    	cout << u << "\n";
	}
    else if((u > v) || ((v-u)%2 != 0))
    cout << "-1\n";
    else
    {
    	int x = (v-u)/2;
    	int n = 9e6;
    	for(int i = 2; i <= n; i++)
    	{
    	    int cur_sum = i*x;
    	    int rem_sum = v-cur_sum;
    	    if((rem_sum & x) == 0)
    	    {
    	    	cout << i << "\n";
    	    	for(int j = 1; j <= i-1; j++) cout << x << " ";
    	    	int last = x|rem_sum;
    	    	cout << last << "\n";
    	    	break;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

//#pragma optimize("O2")

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

//#define int long long

const int MOD = 1e9 + 7;
const int MAXN = 0;

signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   int step1 = 0, step2 = 0;
   int count;
   while(n % 3 == 0) {
       n /= 3;
       step1++;
   }
   while(m % 3 == 0) {
       m /= 3;
       step2++;
   }
   count = step2 - step1 + 1;
   if(count < 0) {
       cout << "-1";
       return 0;
   }
   while(n < m) {
       n *= 2;
       count++;
   }
   if(n == m) {
       cout << count - 1;
   }
   else
       cout << "-1";
   return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){

    long long int m,n,t,c6=0,c2=0,c3=0;

    cin>>n>>m;

    if(n==m) cout<<0<<endl;

    else if(n!=m){

            long long int l=m/n;

            if(l==1) cout<<-1<<endl;

            else{

                while(t++){
                    if(l%6==0) {c6++; l/=6;}
                    else break;
                }
                while(t++){
                    if(l%3==0) {c3++; l/=3;}
                    else break;
                }
                while(t++){
                    if(l%2==0) {c2++; l/=2;}
                    else break;
                }

                if(l!=1) cout<<-1<<endl;

                else cout<<c6*2+c3+c2;
            }

    }

    return 0;

    }


#include <bits/stdc++.h>

using namespace std;

// Prioridade
typedef long long   ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i < (int)(b); i++)
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (((a)/__gcd(a, b)) * b)
#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;
// fim da Prioridade

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	ll n, m;
	cin >> n >> m;

	int i = 2;
	map<int,int> v;
	while(m != 1){
		while(m%i == 0){
			m/=i;
			v[i]++;;
		}
		i++;
	}
	i = 2;
	while(n != 1){
		while(n%i == 0){
			n/=i;
			v[i]--;
		}
		i++;
	}
	for(auto j : v){
		if(j.S < 0 || (j.S > 0 && j.F > 3) ){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << v[2] + v[3] << endl;
	return 0;
}


#include <bits/stdc++.h>
#include <utility>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fore(i, init, n) for(int i = init; i < n; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb(a) push_back(a)
#define INF (1LL<<50)
#define ll long long
#define fst first
#define snd second
ll gcd(ll a, ll b){return a?gcd(b%a,a):b;}
ll mulmod(ll a, ll b, ll m) {
	ll r=a*b-(ll)((long double)a*b/m+.5)*m;
	return r<0?r+m:r;
}
ll expmod(ll b, ll e, ll m){
	if(!e)return 1;
	ll q=expmod(b,e/2,m);q=mulmod(q,q,m);
	return e&1?mulmod(b,q,m):q;
}
bool is_prime_prob(ll n, int a){
	if(n==a)return true;
	ll s=0,d=n-1;
	while(d%2==0)s++,d/=2;
	ll x=expmod(a,d,n);
	if((x==1)||(x+1==n))return true;
	fore(_,0,s-1){
		x=mulmod(x,x,n);
		if(x==1)return false;
		if(x+1==n)return true;
	}
	return false;
}
bool rabin(ll n){ // true iff n is prime
	if(n==1)return false;
	int ar[]={2,3,5,7,11,13,17,19,23};
	fore(i,0,9)if(!is_prime_prob(n,ar[i]))return false;
	return true;
}
// optimized version: replace rho and fact with the following:
const int MAXP=1e6+1; // sieve size
int sv[MAXP]; // sieve
ll add(ll a, ll b, ll m){return (a+=b)<m?a:a-m;}
ll rho(ll n){
	static ll s[MAXP];
	while(1){
		ll x=rand()%n,y=x,c=rand()%n;
		ll *px=s,*py=s,v=0,p=1;
		while(1){
			*py++=y=add(mulmod(y,y,n),c,n);
			*py++=y=add(mulmod(y,y,n),c,n);
			if((x=*px++)==y)break;
			ll t=p;
			p=mulmod(p,abs(y-x),n);
			if(!p)return gcd(t,n);
			if(++v==26){
				if((p=gcd(p,n))>1&&p<n)return p;
				v=0;
			}
		}
		if(v&&(p=gcd(p,n))>1&&p<n)return p;
	}
}
void init_sv(){
	fore(i,2,MAXP)if(!sv[i])for(ll j=i;j<MAXP;j+=i)sv[j]=i;
}
void fact(ll n, map<ll,int>& f){ // call init_sv first!!!
	for(auto&& p:f){
		while(n%p.fst==0){
			p.snd++;
			n/=p.fst;
		}
	}
	if(n<MAXP)while(n>1)f[sv[n]]++,n/=sv[n];
	else if(rabin(n))f[n]++;
	else {ll q=rho(n);fact(q,f);fact(n/q,f);}
}
int main() {

    FIN;
    init_sv();
    ll q,w;
    cin>>q>>w;
    map<ll,int> t;
    map<ll,int> x,z;
    fact(q,x);fact(w,z);
    bool can = true;
    ll dos = 0, tres = 0;
    x[3];x[2];
    //if(x.size() != z.size()){
        //cout<<-1<<endl;
      //  return 0;
    //}
    for(auto y : z){
        if(!x[y.first] && y.first != 2 && y.first != 3){
            can = false;
            break;
        }
        if(y.first == 2){
            if(x[2] > z[2]) can = false;
            dos = abs(y.second-x[2]);
        }else if(y.first == 3){
            if(x[3] > z[3]) can = false;
            tres = abs(y.second-x[3]);
        }
    }
    if(can){
        cout<<dos+tres<<endl;
    }else{
        cout<<-1<<endl;
    }
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;
long long dp1[10000][10000];
long long comb8(int a, int b){
	long long k=0;
	if(a==b)return 1;
	if(b==0){
		return 1;
	}
	if(b==1){
		return a;
	}

	if(dp1[a][b]!=-1){
		//cout<<dp1[a][b]<<endl;
		return dp1[a][b];
	}
	k=comb8(a-1,b-1)+comb8(a-1,b);
	dp1[a][b]=k;
	return k;

}

int main() {
	// your code goes here
	memset(dp1,-1,sizeof(dp1));
	int n,m,t;
	cin>>n>>m>>t;
	cout<<comb8(n,n-4)*comb8(m,m-1)*comb8(n+m-5,t-5)<<endl;
	return 0;
}


#include <iostream>
#include <string.h>
using namespace std;
long long dp1[10000][10000];
long long comb8(int a, int b){
	long long k=0;
	if(a==b)return 1;
	if(b==0){
		return 1;
	}
	if(b==1){
		return a;
	}

	if(dp1[a][b]!=-1){
		//cout<<dp1[a][b]<<endl;
		return dp1[a][b];
	}
	k=comb8(a-1,b-1)+comb8(a-1,b);
	dp1[a][b]=k;
	return k;

}

int main() {
	// your code goes here
	memset(dp1,-1,sizeof(dp1));
	int n,m,t,k=0;
	cin>>n>>m>>t;
	for(int i=4;i<t;i++)k=k+comb8(n,i)*comb8(m,t-i);
	cout<<k<<endl;
	return 0;
}


#ifndef Theater_h
#define Theater_h

// --------
// includes
// --------

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

// ------------
// theater_eval
// ------------

uint64_t theater_eval (int n, int m, int t);

// -------------
// theater_print
// -------------

void theater_print (std::ostream& w, uint64_t answer);

// -------------
// theater_solve
// -------------

void theater_solve (std::istream& r, std::ostream& w);

#endif

// ----------------------------
// projects/twobuttons/Twobuttons.c++
// Copyright (C) 2015
// Glenn P. Downing
// ----------------------------

// --------
// includes
// --------

#include <cassert>  // assert
#include <iostream> // endl, istream, ostream
#include <sstream>  // istringstream
#include <string>   // getline, string
#include <utility>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <list>
#include <limits>

// ------------
// theater_eval
// ------------

uint64_t factorial (uint64_t n) {
  uint64_t retval = 1;
  for (int i = 1; i <= n; ++i) {
    retval *= i;
  }
  return retval;
}

uint64_t upper_factorial (uint64_t n, uint64_t m) {
  uint64_t retval = 1;
  for (int i = m; i <= n; ++i) {
    retval *= i;
  }
  return retval;
}

#if 0
uint64_t theater_eval (int n, int m, int t)
{
  uint64_t result = 0;

  for (int b = 4; b <= t - 1; ++b)
  {
      int g = t - b;

      //uint64_t boy_combs = (factorial(n) / factorial(n-b)) / factorial(b);
      //uint64_t girl_combs = (factorial(m) / factorial(m-g)) / factorial(g);

      //uint64_t boy_combs  = upper_factorial(n, n-b+1) / factorial(b);
      //uint64_t girl_combs = upper_factorial(m, m-g+1) / factorial(g);

      uint64_t boy_combs = 0;
      if ((n-b) > b) {
	boy_combs  = upper_factorial(n, n-b+1) / factorial(b);
      } else {
	boy_combs  = upper_factorial(n, b+1) / factorial(n-b);
      }

      uint64_t girl_combs = 0;
      if ((m-g) > g) {
	girl_combs  = upper_factorial(m, m-g+1) / factorial(g);
      } else {
	girl_combs  = upper_factorial(m, g+1) / factorial(m-g);
      }

      uint64_t total_combs = boy_combs * girl_combs;
      result += total_combs;
  }

  return result;
}
#endif

void append_range (std::vector<uint64_t>& vect, uint64_t start, uint64_t end) {
  for (uint64_t i = start; i <= end; ++i) {
    vect.push_back(i);
  }
}

void divide (std::vector<uint64_t>& num, std::vector<uint64_t>& den) {
  for (uint64_t& den_val : den) {
    for (uint64_t& num_val : num) {
      if (num_val % den_val == 0) {
	num_val = num_val / den_val;
	den_val = 1;
	break;
      }
    }
  }
}

uint64_t multiply (std::vector<uint64_t>& vect) {
  uint64_t product = 1;
  for (uint64_t i = 0; i < vect.size(); ++i) {
    product *= vect[i];
  }
  return product;
}

uint64_t theater_eval (int n, int m, int t)
{
  uint64_t result = 0;
  std::vector<uint64_t> num;
  std::vector<uint64_t> den;
  for (int b = 4; b <= t - 1; ++b)
  {
      int g = t - b;

      // boys
      num.clear();
      den.clear();
      append_range (num, 1, n);
      append_range (den, 1, n-b);
      append_range (den, 1, b);
      divide (num, den);
      uint64_t boy_combs = multiply(num) / multiply(den);

      // girls
      num.clear();
      den.clear();
      append_range (num, 1, m);
      append_range (den, 1, m-g);
      append_range (den, 1, g);
      divide (num, den);
      uint64_t girl_combs = multiply(num) / multiply(den);

      result += boy_combs * girl_combs;
  }

  return result;
}

// -------------
// theater_print
// -------------

void theater_print (std::ostream& w, uint64_t answer)
{
  w << answer << std::endl;
}

// -------------
// theater_solve
// -------------

void theater_solve (std::istream& r, std::ostream& w)
{
  std::string s;

  // Get the boys, girls, and group size
  int n = 0;
  int m = 0;
  int t = 0;
  if (std::getline(r, s)) {
    std::istringstream sin(s);
    sin >> n >> m >> t;
  }

  // Determine the answer
  uint64_t answer = theater_eval(n, m , t);

  // Print the result
  theater_print(w, answer);
}

#include <iostream>

// ----
// main
// ----

int main () {
    using namespace std;
    theater_solve(cin, cout);
    return 0;
}


#include<iostream>
#include<map>
//#define ll int
#define ll long long int
using namespace std;
ll func(ll n,ll m){
    if(m==0)
        return 1;
    else
        return func(n-1,m-1)*n/m;
}
int main(){
    ll n,m,t,ans=0;
    cin>>n>>m>>t;
    for(int i=4;t-i>=1;i++){
        ll p, q;
        if(i<n-i)
        p=i;
        else
        p=n-i;
        if(t-i<n-t+i)
        q=t-i;
        else
        q=n-t+i;
        ans+=func(n,p)*func(m,q);
    }
    cout<<ans<<endl;

    return 0;
}


#include "stdio.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#pragma warning(disable : 4996)

int n,m;

int main() {

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

	cin>>n >>m;
	int s=0;

	for (int i=-1000; i<=1000; i++)
		for (int j=-1000; j<1000; j++)
			if (i*i+j==n && j*j+i==m) s++;

	cout<<s <<endl;

	return 0;
}


#pragma comment (linker, "/STACK:214721677")
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <string>
using namespace std;
#define REP(i,n) for (int i=0, _n=(n)-1; i <= _n; ++i)
#define REPD(i,n) for (int i=(n)-1; i >= 0; --i)
#define FOR(i,a,b) for (int i=(a), _b=(b); i <= _b; ++i)
#define FORD(i,a,b) for (int i=(a), _b=(b); i >= _b; --i)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define sz(a) ((int) ((a).size()))
template < class T > T sqr (T a) { return (a) * (a); }
template < class T > T abs (T a) { return (a < 0) ? -(a) : (a); }
const double Pi = acos(-1.0);
const double eps = 1e-10;
const int INF = 1000*1000*1000 + 7;
const double phi = 0.5 + sqrt(1.25);
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <double, double> pdd;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int n,m, ans = 0;
    scanf("%d%d\n", &n, &m);
    REP(a, 1010) {
        int b = n - a * a;
        ans += (a + sqr(b) == m);
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int main()
{
    double n,m;
    int answer = 0;
    cin >> n >> m;
    for (double a = 0; a <= 100; a++)
        for (double b = 0; b<=100; b++)
            if(a*a+b==n && b*b + a == m)
                answer++;
    cout << answer << endl;
    _getch();
    return 0;
}


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

void main ()
{
	int a=0,b=0,m,n,x=0;

	cin >> n >> m;

	for (a;a<=m&&a<=n;a++)
		for (b;(b<=m)&&(b<=n);b++)
			if (((a+b*b)==m)&&((a*a+b==n)))
				x++;

	cout << x;

	_getch ();
}


/***********************************************
 * Author: fisty
 * Created Time: 2015/2/28 21:54:12
 * File Name   : 294C.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 10000
int dp[MAX_N][MAX_N];
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    Memset(dp, 0);
    for(int i = n;i >= 0; i--){
        for(int j = m;j >= 0; j--){
            if(i-1 >= 0 && j - 2 >= 0)
                dp[i-1][j-2] = dp[i][j]+1;
            if(i - 2 >= 0 && j - 1 >= 0)
                dp[i-2][j-1] = dp[i][j]+1;
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}


#include<iostream>
using namespace std;

long max(long a, long b)
{
	return (a > b) ? a : b;
}
int main()
{
	long n, m;
	cin >> n >> m;
	long** DP = new long *[n + 1];
	for (long i = 0; i < n + 1; i++)
		DP[i] = new long[m + 1];
	//Pre_process_DP
	DP[0][0] = 0;
	for (long i = 0; i <= n; i++)
	{
		DP[i][0] = 0;
	}
	for (long i = 0; i <= m; i++)
	{
		DP[0][i] = 0;
	}
	DP[1][1] = 0;
	for (long i = 2; i <= m; i++)
	{
		DP[1][i] = 1;
	}
	if (n >= 2 && m >= 1)
		DP[2][1] = 1;
	//main_DP
	for (long i = 2; i <= n; i++)
	{
		for (long j = 2; j <= m; j++)
		{
			DP[i][j] = max(1 + DP[i - 2][j - 1], 1 + DP[i - 1][j - 2]);
		}
	}

	cout << DP[n][m];
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int min(int a, int b)
{
	if(a<b)
		return a;
	return b;
}
main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	if(n>m)
	{
		int t=n;
		n=m;
		m=t;
	}

	if(n*3<m)
		cout<<n;
	else
		cout<<(n+m)/3;
}


#include <iostream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <cstring>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <utility>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <cctype>
#include <memory>
#include <cstdlib>
#include <cassert>
using namespace std;
typedef unsigned long long uint64;
typedef long long int32;
typedef unsigned long uint32;

#define TWO(X) (1<<(X))
#define TWOLL(X) ((int64)1<<(X))
#define vi vector<int>
#define vvi vector<vi>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vii>
int n,m,c;

int main(){
	cin>>n>>m;
	if(m/2 >= n){
		cout<<n<<endl;
	}
	else{
		while(n > m/2){
			n-=2;
			m-=1;
			c++;
		}
		c+=n;
		cout<<c<<endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define fop()   freopen("in.txt","r",stdin)
#define sf scanf
#define pf printf
using namespace std;
double PI=acos(-1);
typedef long long ll;
void gettime(int &s,int &sm,int &sd,char *x)
{
    s=sm=sd=0;
    for(int i=0;i<=3;i++)
      s=s*10+x[i]-'0';
    for(int i=5;i<=6;i++)
      sm=sm*10+x[i]-'0';
    for(int i=8;i<=9;i++)
      sd=sd*10+x[i]-'0';
}
int main()
{
    //fop();
    int month[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int ans=0;
    int s,e,sm,em,sd,ed;
    char x1[100],x2[100];
    sf("%s",x1);
    sf("%s",x2);
    if(strcmp(x1,x2)>0)swap(x1,x2);
    gettime(s,sm,sd,x1);
    gettime(e,em,ed,x2);
    //cout<<s<<" "<<sm<<" "<<sd<<" "<<endl;
    //cout<<e<<" "<<em<<" "<<ed<<" "<<endl;
    for(int i=s;i<=e;i++)
    {
       if((i%400==0)||(i%4==0&&i%100!=0))month[2]=29;
       else month[2]=28;
       if(s==e)
       {
           for(int k=sd;k<=month[sm];k++)
             ans++;
           for(int j=sm+1;j<=em-1;j++)
            for(int k=1;k<=month[j];k++)
              ans++;
            for(int k=1;k<=ed;k++)
               ans++;
           break;
       }
       else if(i==s)
       {
          for(int k=sd;k<=month[sm];k++)
             ans++;
          for(int j=sm+1;j<=12;j++)
            for(int k=1;k<=month[j];k++)
              ans++;
        }
       else if(i==e)
       {
           for(int j=1;j<=em-1;j++)
              for(int k=1;k<=month[j];k++)
               ans++;
           for(int k=1;k<=ed;k++)
               ans++;
       }
       else
       {
         for(int j=1;j<=12;j++)
           for(int k=1;k<=month[j];k++)
              ans++;
       }

    }
    ans--;
    pf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std ;
int a[13] = {0, 31,28,31,30,31,30,31,31,30,31,30,31} ;
bool judge(int year)
{
    if((0 == year % 4 && 0 != year % 100 )|| 0 == year % 400 && year > 0 )
    {

        return true ;
    }
    else return false ;
}

int main()
{
    int y1 ;
    int y2 ;
    int m1 ;
    int m2 ;
    int d1 ;
    int d2 ;
    int sum = 0 ;
    int tem = 0 ;
    scanf("%d:%d:%d",&y1,&m1,&d1) ;
    scanf("%d:%d:%d",&y2,&m2,&d2) ;
    if(y1 > y2)
    {

        swap(y1,y2) ;
        swap(m1,m2) ;
        swap(d1,d2) ;
    }
    if(y1 == y2)
    {
        printf(" %d %d\n",y1,y2) ;
        for(int i = m1 + 1; i < m2 ; ++ i)
            sum += a[i] ;
        sum += d1 ;
        sum += d2 ;
        printf("%d\n",sum) ;
    }
    for(int i = m1 + 1 ;i <= 12 ; ++i )
    {
        sum += a[i] ;
        if(judge(y1) && i == 2)
        {
            ++ sum ;
        }

    }
    sum += a[m1] - d1 ;
    for(int i = y1 + 1 ;i < y2 ; ++ i)
    {
        if(judge(i))
        {
            sum += 366 ;
        }
        else
        {
            sum += 365 ;
        }
    }
    for(int i = 1 ; i < m2 ; ++ i)
    {
        sum += a[i] ;
        if(judge(y2) && 2 == i)
        {
            ++ sum   ;
        }

    }
    sum += d2 ;
    printf("%d\n",sum) ;
    return 0 ;
}


#include <iostream>

using namespace std;

int leapmonth[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    //freopen("1.in", "r", stdin);
    int i, j, minyear,maxyear, minmonth, maxmonth, minday, maxday, tmp;
    char str1[12], str2[12];
    cin >> str1 >> str2;
    minyear = (str1[0]-'0')*1000 + (str1[1]-'0')*100 + (str1[2]-'0')*10 + (str1[3]-'0');
    maxyear = (str2[0]-'0')*1000 + (str2[1]-'0')*100 + (str2[2]-'0')*10 + (str2[3]-'0');
    minmonth = (str1[5] - '0')*10 + (str1[6]-'0');
    maxmonth = (str2[5] - '0')*10 + (str2[6]-'0');
    minday = (str1[8] - '0')*10 + (str1[9]-'0');
    maxday = (str2[8] - '0')*10 + (str2[9]-'0');
    if(minyear > maxyear)
    {
        tmp = maxyear;maxyear = minyear;minyear = tmp;
        tmp = maxmonth;maxmonth = minmonth;minmonth = tmp;
        tmp = maxday;maxday = minday;minday = tmp;
    }
    int counter = 0, res = 0;
    for(i = minyear;i < maxyear;i++)
    {
        if(i%400 == 0 || (i%4==0 && i%100 != 0))counter ++;
    }
    res += (maxyear - minyear)*365 + counter;
    if(minyear % 400 == 0 || (minyear%4 == 0 && minyear % 100 != 0))
    {
        for(i = 0;i < minmonth - 1;i++)
        {
            res -= leapmonth[i];
        }
        res -= minday;
    }else{
        for(i = 0;i < minmonth - 1;i++)
        {
            res -= month[i];
        }
        res -= minday;
    }

    if(maxyear % 400 == 0 || (maxyear%4 == 0 && maxyear % 100 != 0))
    {
        for(i = 0;i < maxmonth - 1;i++)
        {
            res += leapmonth[i];
        }
        res += maxday;
    }else{
        for(i = 0;i < maxmonth - 1;i++)
        {
            res += month[i];
        }
        res += maxday;
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <map>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define pb push_back
typedef long long ll;
using namespace std;

int main() {
  int n, t;
  string s;
  cin>>n>>t>>s;
  while(t--) {
    string x = s;
    for(int i=0; i<n-1; ++i) {
      if(s[i] == 'B' && s[i+1]  == 'G')
        swap(x[i], x[i-1]);
    }
    s = x;
  }
  cout<<s;
  return 0;
}


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

int main()
{
	int n,t,time=0,i=1;
	bool flag=true;
	string s;
	cin>>n>>t;
	cin>>s;
	while (t--)
	{
			if (s[i-1]=='B'&&s[i]=='G')
			{
				swap(s[i-1],s[i]);
			}
			i++;
	}
	cout<<s;
	getch();
	return 0;
}


#include <iostream>
#include<conio.h>
using namespace std;
char q[50],s;
int n=0,t=0;
void change(int x,int y)
{
    if (q[x]=='G' && q[y]=='B')
    {
        s=q[x];
        q[x]=q[y];
        q[y]=s;
    }
}
int main()
{
    cin>>n>>t;
    cin>>q;
    for (int j=1; j<=t; j++)
    {

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

            change(i-1,i);

        }
    }
    cout<<q;

    getch();

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,t;
    cin>>n>>t;
    string s;
    cin>>s;
    for(int a=0;a<t;a++)
    {
        int i=0;
        while(i<n-1)
        {
            if(s[i]=='B'&&s[i+1]=='G')
            {
                int x=s[i];
                s[i]=s[i+1];
                s[i+1]=x;
                i+=2;
            }
            else
                i++;
        }

    }
    cout<<s;
return 0;
}


#include "bits/stdc++.h"
using namespace std;
using namespace chrono;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
//mt19937 rng(3);
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());

void radix_sort(vector<pair<int, vector<int>>> &arr){
	int n = int(arr.size()), mxval = 0, mxsz = 1 + accumulate(arr.begin(), arr.end(), 0, [](int x, const pair<int, vector<int>> &y){return max(x, int(y.second.size()));});
	vector<vector<int>> occur(mxsz);
	for(int i = 0; i < n; ++ i){
		occur[arr[i].second.size()].push_back(i);
		for(auto x: arr[i].second) mxval = max(mxval, x);
	}
	++ mxval;
	for(int size = 1; size < mxsz; ++ size) for(int d = size - 1; d >= 0; -- d){
		vector<vector<int>> bucket(mxval);
		for(auto i: occur[size]) bucket[arr[i].second[d]].push_back(i);
		occur[size].clear();
		for(auto &b: bucket) for(auto i: b) occur[size].push_back(i);
	}
	vector<pair<int, vector<int>>> res;
	res.reserve(n);
	for(auto &b: occur) for(auto i: b) res.push_back(arr[i]);
	swap(res, arr);
}
bool isomorphic(const vector<vector<vector<int>>> &adj, const vector<int> &root){
	int n = int(adj[0].size());
	if(int(adj[1].size()) != n) return false;
	vector<vector<vector<int>>> occur(2);
	vector<vector<int>> depth(2, vector<int>(n)), par(2, vector<int>(n, -1));
	for(int k = 0; k < 2; ++ k){
		function<void(int, int)> dfs = [&](int u, int p){
			par[k][u] = p;
			for(auto v: adj[k][u]) if(v != p){
				depth[k][v] = depth[k][u] + 1;
				dfs(v, u);
			}
		};
		dfs(root[k], -1);
		int mxdepth = 1 + accumulate(depth[k].begin(), depth[k].end(), 0, [](int x, int y){return max(x, y);});
		occur[k].resize(mxdepth);
		for(int u = 0; u < n; ++ u) occur[k][depth[k][u]].push_back(u);
	}
	int mxdepth = int(occur[0].size());
	if(mxdepth != int(occur[1].size())) return false;
	for(int d = 0; d < mxdepth; ++ d) if(occur[0][d].size() != occur[1][d].size()) return false;
	vector<vector<int>> label(2, vector<int>(n)), pos(2, vector<int>(n));
	vector<vector<vector<int>>> sorted_list(mxdepth, vector<vector<int>>(2));
	for(int k = 0; k < 2; ++ k){
		sorted_list[mxdepth - 1][k].reserve(occur[k][mxdepth - 1].size());
		for(auto u: occur[k][mxdepth - 1]) sorted_list[mxdepth - 1][k].push_back(u);
	}
	for(int d = mxdepth - 2; d >= 0; -- d){
		vector<vector<pair<int, vector<int>>>> tuples(2);
		for(int k = 0; k < 2; ++ k){
			tuples[k].reserve(occur[k][d].size());
			for(auto u: occur[k][d]){
				pos[k][u] = int(tuples[k].size());
				tuples[k].emplace_back(u, vector<int>());
			}
			for(auto v: sorted_list[d + 1][k]){
				int u = par[k][v];
				tuples[k][pos[k][u]].second.push_back(label[k][v]);
			}
			radix_sort(tuples[k]);
		}
		for(int i = 0; i < int(tuples[0].size()); ++ i) if(tuples[0][i].second != tuples[1][i].second) return false;
		for(int k = 0; k < 2; ++ k){
			int cnt = 0;
			sorted_list[d][k].reserve(occur[k][d].size());
			sorted_list[d][k].push_back(tuples[k][0].first);
			for(int i = 1; i < int(tuples[k].size()); ++ i){
				int u = tuples[k][i].first;
				label[k][u] = (tuples[k][i - 1].second == tuples[k][i].second ? cnt : ++ cnt);
				sorted_list[d][k].push_back(u);
			}
		}
	}
	return true;
}
vector<int> centroid(const vector<vector<int>> &adj){
	int n = int(adj.size());
	vector<int> size(n, 1);
	function<void(int, int)> dfs_sz = [&](int u, int p){
		for(auto v: adj[u]) if(v != p){
			dfs_sz(v, u);
			size[u] += size[v];
		}
	};
	dfs_sz(0, -1);
	function<vector<int>(int, int)> dfs_cent = [&](int u, int p){
		for(auto v: adj[u]) if(v != p && size[v] > n / 2) return dfs_cent(v, u);
		for(auto v: adj[u]) if(v != p && n - size[v] <= n / 2) return vector<int>{u, v};
		return vector<int>{u};
	};
	return dfs_cent(0, -1);
}
bool isomorphic(const vector<vector<vector<int>>> &adj){
	vector<vector<int>> cent{centroid(adj[0]), centroid(adj[1])};
	if(cent[0].size() != cent[1].size()) return false;
	for(auto u: cent[0]) for(auto v: cent[1]) if(isomorphic(adj, vector<int>{u, v})) return true;
	return false;
}
template<typename asdf>
bool test_isomorphism(asdf p, asdf q){
	int n = int(p.size());
	vector<vector<int>> adj1(n), adj2(n);
	for(auto u = 0; u < n; ++ u){
		if(p[u] >= 0){
			adj1[u].push_back(p[u]), adj1[p[u]].push_back(u);
		}
	}
	for(auto u = 0; u < n; ++ u){
		if(q[u] >= 0){
			adj2[u].push_back(q[u]), adj2[q[u]].push_back(u);
		}
	}
	return isomorphic({adj1, adj2});
}

// DEBUG BEGIN
template<typename L, typename R>
ostream &operator<<(ostream &out, pair<L, R> p){
	return out << "(" << p.first << ", " << p.second << ")";
}
template<typename Tuple, size_t ...Is>
void print_tuple(ostream &out, Tuple t, index_sequence<Is...>){
	((out << (Is ? ", " : "") << get<Is>(t)), ...);
}
template<typename ...Args>
ostream &operator<<(ostream &out, tuple<Args...> t){
	out << "(", print_tuple(out, t, index_sequence_for<Args...>{}); return out << ")";
}
template<typename ...Args, template<typename...> typename T>
ostream &operator<<(enable_if_t<!is_same_v<T<Args...>, string>, ostream> &out, T<Args...> arr){
	out << "{"; for(auto &x: arr) out << x << ", ";
	return out << (arr.size() ? "\b\b" : "") << "}";
}
template<typename T, size_t N>
ostream &operator<<(ostream &out, array<T, N> arr){
	out << "{"; for(auto &x: arr) out << x << ", ";
	return out << (arr.size() ? "\b\b" : "") << "}";
}
template<size_t S>
ostream &operator<<(ostream &out, bitset<S> b){
	for(int i = 0; i < S; ++ i) out << b[i];
	return out;
}
void debug_out(){ cerr << "\b\b " << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){ cerr << H << ", ", debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// DEBUG END

int main(){
	cin.tie(0)->sync_with_stdio(0);
	///*
	int n;
	cin >> n;
	vector<int> par(2 * n - 1, -1), judge_ans(2 * n - 1), depth(2 * n - 1, -1);
	for(auto &x: judge_ans) cin >> x;
	debug(judge_ans);
	for(auto &x: judge_ans) if(~x) -- x;
	for(auto u = 0; u < 2 * n - 1; ++ u){
		if(!~depth[u]){
			function<int(int)> get_depth = [&](int u){
				if(~depth[u]) return depth[u];
				if(judge_ans[u] < 0) return depth[u] = 0;
				return get_depth(judge_ans[u]) + 1;
			};
			depth[u] = get_depth(u);
		}
	}
	auto lca = [&](int u, int v){
		if(depth[u] < depth[v]) swap(u, v);
		while(depth[u] != depth[v]) u = judge_ans[u];
		while(u != v) u = judge_ans[u], v = judge_ans[v];
		return u;
	};
	int query_cnt = 0;
	auto query = [&](int u, int v, int w){
		++ query_cnt;
		cout << u + 1 << " " << v + 1 << " " << w + 1 << endl;
		int x = depth[lca(u, v)], y = depth[lca(v, w)], z = depth[lca(w, u)], mx = max({x, y, z});
		cout << "judge replies: ";
		if(x == mx){
			cout << "X" << endl;
			return 0;
		}
		else if(y == mx){
			cout << "Y" << endl;
			return 1;
		}
		else{
			cout << "Z" << endl;
			return 2;
		}
	};
	auto answer = [&](){
		cout << "-1\n";
		for(auto p: par) cout << p + !!~p << " ";
		cout << "\n";
		cout << "Are they isomorphic?: " << test_isomorphism(judge_ans, par) << endl;
		exit(0);
	};
	//*/
	/*
	int n;
	cin >> n;
	vector<int> par(2 * n - 1, -2);
	int query_cnt = 0;
	auto query = [&](int u, int v, int w){
		++ query_cnt;
		if(query_cnt > 10 * n){
			int t = 1;
			while(1){
				t *= 3;
			}
		}
		cout << u + 1 << " " << v + 1 << " " << w + 1 << endl;
		char resp;
		cin >> resp;
		return resp - 'X';
	};
	auto answer = [&](){
		cout << "-1\n";
		for(auto p: par) cout << p + 1 << " ";
		cout << "\n";
		exit(0);
	};
	*/
	auto get_node = [&](){
		static int cntr = n;
		return cntr ++;
	};
	vector<array<int, 2>> child(2 * n - 1, {-1, -1}), leaf_child(2 * n - 1);
	for(auto u = 0; u < n; ++ u){
		leaf_child[u] = {u, u};
	}
	for(auto root = 0, new_leaf = 1; new_leaf < n; ++ new_leaf){ // currently 2 * s - 1 nodes
		int new_par = get_node(), qval;
		auto insert_nodes = [&](int pp, int dir){
			int qq = child[pp][dir];
			par[qq] = par[new_leaf] = new_par, par[new_par] = pp;
			child[pp][dir] = new_par, child[new_par][dir] = qq, child[new_par][!dir] = new_leaf;
			leaf_child[new_par][dir] = leaf_child[qq][dir], leaf_child[new_par][!dir] = leaf_child[new_leaf][!dir];
		};
		if(!~child[root][0] || (qval = query(child[root][0], new_leaf, child[root][1])) == 2){
			leaf_child[new_par] = {leaf_child[root][0], new_leaf};
			par[root] = par[new_leaf] = new_par;
			child[new_par] = {root, new_leaf};
			root = new_par;
			continue;
		}
		static vector<int> ded, sz;
		ded.assign(2 * n - 1, 0), sz.assign(2 * n - 1, 0);
		ded[root] = true;
		for(auto cur_root = child[root][qval]; ; ){
			function<void(int, int)> dfs_sz = [&](int u, int p){
				sz[u] = 1;
				for(auto v: child[u]){
					if(~v && !ded[v] && v ^ p){
						dfs_sz(v, u);
						sz[u] += sz[v];
					}
				}
				int v = par[u];
				if(~v && !ded[v] && v ^ p){
					dfs_sz(v, u);
					sz[u] += sz[v];
				}
			};
			dfs_sz(cur_root, cur_root);
			function<int(int, int)> dfs_centroid = [&](int u, int p){
				for(auto v: child[u]){
					if(~v && !ded[v] && v ^ p && sz[v] > sz[u] / 2){
						return dfs_centroid(v, u);
					}
				}
				int v = par[u];
				if(~v && !ded[v] && v ^ p && sz[v] > sz[u] / 2){
					return dfs_centroid(v, u);
				}
				return u;
			};
			int c = dfs_centroid(cur_root, cur_root);
			if(!~child[c][0]){
				insert_nodes(par[c], c == child[par[c]][1]);
				break;
			}
			int qval = query(leaf_child[c][0], new_leaf, leaf_child[c][1]);
			if(qval == 2){
				if(ded[par[c]]){
					insert_nodes(par[c], c == child[par[c]][1]);
					break;
				}
				cur_root = par[c];
			}
			else{
				if(ded[child[c][qval]]){
					insert_nodes(c, qval);
					break;
				}
				cur_root = child[c][qval];
			}
			ded[c] = true;
		}
	}
	answer();
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                   Coded by Aeren                                   //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////////


#include <bits/stdc++.h>
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 2e3;
int n,rem,sz = 2,cursz;
bool vis[N];
struct node{
	int l,r,p,sz;
	int leafl,leafr;
	node(){l = r = p = leafl = leafr = -1,sz = 0;}
}g[N];
int get(){
	g[rem].sz = 1;
	return rem++;
}
pair<int,int> get(int u){
	if(u < n)return {-1,1};
	if(vis[u])return{-1,0};
	int sz = 0,mx = 0,cen = -1;
	pair<int,int>temp = get(g[u].l);
	cen = temp.first;
	sz+=temp.second;
	mx = max(mx,temp.second);
	temp = get(g[u].r);
	cen = max(cen,temp.first);
	sz+=temp.second;
	mx = max(mx,temp.second);
	mx = max(mx,cursz - sz);
	if(mx <= (cursz + 1)/2)cen = u;
	return {cen,sz};
}
char ask(int a,int b,int c){
	char ret;
	cout << a + 1 << " " << b + 1 << " " << c + 1 << endl;
	scanf(" %c",&ret);
	return ret;
}
int getsz(int u){
	if(u < n)return 1;
	if(vis[u])return 0;
	return getsz(g[u].l) + getsz(g[u].r);
}
int main(){
	scanf("%d",&n);
	rem = n;
	int root = get();
	g[root].l = 0;
	g[root].r = 1;
	g[0].p = g[1].p = root;
	for(int i = 0;i < n;i++)g[i].sz = 1,g[i].leafl = g[i].leafr = i;
	g[root].sz = 1;
	g[root].leafl = 0;
	g[root].leafr = 1;
	for(int i = 2;i < n;i++,sz++){
		memset(vis,0,sizeof vis);
		for(int i = 0;i < n;i++)vis[i] = 1;
		int cur = root;
		while(1){
			cursz = getsz(cur);
			int cen = get(cur).first;
			if(g[cen].leafl == g[cen].leafr)cout << cen << endl;
			char is = ask(g[cen].leafl,g[cen].leafr,i);
			if(is == 'Z'){
				if(vis[g[cen].l]){
					int left = g[cen].l;
					int temp = get();
					g[cen].l = temp;
					g[temp].p = cur;
					g[temp].l = left;
					g[temp].r = i;
					g[temp].leafl = g[left].leafl;
					g[temp].leafr = i;
					g[temp].sz = g[left].sz;
					g[i].p = g[left].p = temp;
					break;
				}
				vis[cen] = 1;
				cur = g[cen].l;
				continue;
			}
			if(is == 'Y'){
				if(vis[g[cen].r]){
					int left = g[cen].r;
					int temp = get();
					g[cen].l = temp;
					g[temp].p = cur;
					g[temp].l = left;
					g[temp].r = i;
					g[temp].leafl = g[left].leafl;
					g[temp].leafr = i;
					g[temp].sz = g[left].sz;
					g[i].p = g[left].p = temp;
					break;
				}
				vis[cen] = 1;
				cur = g[cen].r;
				continue;
			}
			if(g[cen].p == -1){
				int temp = get();
				g[cen].p = g[i].p = temp;
				g[temp].l = cen;
				g[temp].r = i;
				g[temp].sz = g[cen].sz;
				g[temp].leafl = g[cen].leafl;
				g[temp].leafr = i;
				root = temp;
				break;
			}
			if(vis[g[cen].p]){
				int temp = get();
				g[temp].leafl = g[cen].leafl;
				g[temp].leafr = i;
				g[temp].l = cen;
				g[temp].r = i;
				g[temp].p = g[cen].p;
				g[cen].p = g[i].p = temp;
				g[temp].sz = g[cen].sz;
				if(g[g[cen].p].l == cen)g[g[cen].p].l = temp;
				else g[g[cen].p].r = temp;
				break;
			}
			vis[cen] = 1;
			cur = root;
		}
		cur = i;
		while(g[cur].p != -1){
			g[cur].sz++;
			cur = g[cur].p;
		}
	}
	puts("-1");
	for(int i = 0;i < 2*n - 1;i++)printf("%d ",g[i].p == -1 ? - 1 : g[i].p + 1);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
using namespace chrono;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());

void radix_sort(vector<pair<int, vector<int>>> &arr){
	int n = int(arr.size()), mxval = 0, mxsz = 1 + accumulate(arr.begin(), arr.end(), 0, [](int x, const pair<int, vector<int>> &y){return max(x, int(y.second.size()));});
	vector<vector<int>> occur(mxsz);
	for(int i = 0; i < n; ++ i){
		occur[arr[i].second.size()].push_back(i);
		for(auto x: arr[i].second) mxval = max(mxval, x);
	}
	++ mxval;
	for(int size = 1; size < mxsz; ++ size) for(int d = size - 1; d >= 0; -- d){
		vector<vector<int>> bucket(mxval);
		for(auto i: occur[size]) bucket[arr[i].second[d]].push_back(i);
		occur[size].clear();
		for(auto &b: bucket) for(auto i: b) occur[size].push_back(i);
	}
	vector<pair<int, vector<int>>> res;
	res.reserve(n);
	for(auto &b: occur) for(auto i: b) res.push_back(arr[i]);
	swap(res, arr);
}
bool isomorphic(const vector<vector<vector<int>>> &adj, const vector<int> &root){
	int n = int(adj[0].size());
	if(int(adj[1].size()) != n) return false;
	vector<vector<vector<int>>> occur(2);
	vector<vector<int>> depth(2, vector<int>(n)), par(2, vector<int>(n, -1));
	for(int k = 0; k < 2; ++ k){
		function<void(int, int)> dfs = [&](int u, int p){
			par[k][u] = p;
			for(auto v: adj[k][u]) if(v != p){
				depth[k][v] = depth[k][u] + 1;
				dfs(v, u);
			}
		};
		dfs(root[k], -1);
		int mxdepth = 1 + accumulate(depth[k].begin(), depth[k].end(), 0, [](int x, int y){return max(x, y);});
		occur[k].resize(mxdepth);
		for(int u = 0; u < n; ++ u) occur[k][depth[k][u]].push_back(u);
	}
	int mxdepth = int(occur[0].size());
	if(mxdepth != int(occur[1].size())) return false;
	for(int d = 0; d < mxdepth; ++ d) if(occur[0][d].size() != occur[1][d].size()) return false;
	vector<vector<int>> label(2, vector<int>(n)), pos(2, vector<int>(n));
	vector<vector<vector<int>>> sorted_list(mxdepth, vector<vector<int>>(2));
	for(int k = 0; k < 2; ++ k){
		sorted_list[mxdepth - 1][k].reserve(occur[k][mxdepth - 1].size());
		for(auto u: occur[k][mxdepth - 1]) sorted_list[mxdepth - 1][k].push_back(u);
	}
	for(int d = mxdepth - 2; d >= 0; -- d){
		vector<vector<pair<int, vector<int>>>> tuples(2);
		for(int k = 0; k < 2; ++ k){
			tuples[k].reserve(occur[k][d].size());
			for(auto u: occur[k][d]){
				pos[k][u] = int(tuples[k].size());
				tuples[k].emplace_back(u, vector<int>());
			}
			for(auto v: sorted_list[d + 1][k]){
				int u = par[k][v];
				tuples[k][pos[k][u]].second.push_back(label[k][v]);
			}
			radix_sort(tuples[k]);
		}
		for(int i = 0; i < int(tuples[0].size()); ++ i) if(tuples[0][i].second != tuples[1][i].second) return false;
		for(int k = 0; k < 2; ++ k){
			int cnt = 0;
			sorted_list[d][k].reserve(occur[k][d].size());
			sorted_list[d][k].push_back(tuples[k][0].first);
			for(int i = 1; i < int(tuples[k].size()); ++ i){
				int u = tuples[k][i].first;
				label[k][u] = (tuples[k][i - 1].second == tuples[k][i].second ? cnt : ++ cnt);
				sorted_list[d][k].push_back(u);
			}
		}
	}
	return true;
}
vector<int> centroid(const vector<vector<int>> &adj){
	int n = int(adj.size());
	vector<int> size(n, 1);
	function<void(int, int)> dfs_sz = [&](int u, int p){
		for(auto v: adj[u]) if(v != p){
			dfs_sz(v, u);
			size[u] += size[v];
		}
	};
	dfs_sz(0, -1);
	function<vector<int>(int, int)> dfs_cent = [&](int u, int p){
		for(auto v: adj[u]) if(v != p && size[v] > n / 2) return dfs_cent(v, u);
		for(auto v: adj[u]) if(v != p && n - size[v] <= n / 2) return vector<int>{u, v};
		return vector<int>{u};
	};
	return dfs_cent(0, -1);
}
bool isomorphic(const vector<vector<vector<int>>> &adj){
	vector<vector<int>> cent{centroid(adj[0]), centroid(adj[1])};
	if(cent[0].size() != cent[1].size()) return false;
	for(auto u: cent[0]) for(auto v: cent[1]) if(isomorphic(adj, vector<int>{u, v})) return true;
	return false;
}
template<typename asdf>
bool test_isomorphism(asdf p, asdf q){
	int n = int(p.size());
	vector<vector<int>> adj1(n), adj2(n);
	for(auto u = 0; u < n; ++ u){
		if(p[u] >= 0){
			adj1[u].push_back(p[u]), adj1[p[u]].push_back(u);
		}
	}
	for(auto u = 0; u < n; ++ u){
		if(q[u] >= 0){
			adj2[u].push_back(q[u]), adj2[q[u]].push_back(u);
		}
	}
	return isomorphic({adj1, adj2});
}

// DEBUG BEGIN
template<typename L, typename R>
ostream &operator<<(ostream &out, pair<L, R> p){
	return out << "(" << p.first << ", " << p.second << ")";
}
template<typename Tuple, size_t ...Is>
void print_tuple(ostream &out, Tuple t, index_sequence<Is...>){
	((out << (Is ? ", " : "") << get<Is>(t)), ...);
}
template<typename ...Args>
ostream &operator<<(ostream &out, tuple<Args...> t){
	out << "(", print_tuple(out, t, index_sequence_for<Args...>{}); return out << ")";
}
template<typename ...Args, template<typename...> typename T>
ostream &operator<<(enable_if_t<!is_same_v<T<Args...>, string>, ostream> &out, T<Args...> arr){
	out << "{"; for(auto &x: arr) out << x << ", ";
	return out << (arr.size() ? "\b\b" : "") << "}";
}
template<typename T, size_t N>
ostream &operator<<(ostream &out, array<T, N> arr){
	out << "{"; for(auto &x: arr) out << x << ", ";
	return out << (arr.size() ? "\b\b" : "") << "}";
}
template<size_t S>
ostream &operator<<(ostream &out, bitset<S> b){
	for(int i = 0; i < S; ++ i) out << b[i];
	return out;
}
void debug_out(){ cerr << "\b\b " << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){ cerr << H << ", ", debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// DEBUG END

int main(){
	cin.tie(0)->sync_with_stdio(0);
	///*
	int n;
	cin >> n;
	vector<int> par(2 * n - 1, -1), judge_ans(2 * n - 1), depth(2 * n - 1, -1);
	for(auto &x: judge_ans) cin >> x;
	debug(judge_ans);
	for(auto &x: judge_ans) if(~x) -- x;
	for(auto u = 0; u < 2 * n - 1; ++ u){
		if(!~depth[u]){
			function<int(int)> get_depth = [&](int u){
				if(~depth[u]) return depth[u];
				if(judge_ans[u] < 0) return depth[u] = 0;
				return get_depth(judge_ans[u]) + 1;
			};
			depth[u] = get_depth(u);
		}
	}
	auto lca = [&](int u, int v){
		if(depth[u] < depth[v]) swap(u, v);
		while(depth[u] != depth[v]) u = judge_ans[u];
		while(u != v) u = judge_ans[u], v = judge_ans[v];
		return u;
	};
	int query_cnt = 0;
	auto query = [&](int u, int v, int w){
		++ query_cnt;
		debug(query_cnt);
		cout << u + 1 << " " << v + 1 << " " << w + 1 << endl;
		int x = depth[lca(u, v)], y = depth[lca(v, w)], z = depth[lca(w, u)], mx = max({x, y, z});
		cout << "judge replies: ";
		if(x == mx){
			cout << "X" << endl;
			return 0;
		}
		else if(y == mx){
			cout << "Y" << endl;
			return 1;
		}
		else{
			cout << "Z" << endl;
			return 2;
		}
	};
	auto answer = [&](){
		cout << "-1\n";
		for(auto p: par) cout << p + !!~p << " ";
		cout << "\n";
		cout << "Are they isomorphic?: " << test_isomorphism(judge_ans, par) << endl;
		exit(0);
	};
	//*/
	/*
	int n;
	cin >> n;
	vector<int> par(2 * n - 1, -2);
	int query_cnt = 0;
	auto query = [&](int u, int v, int w){
		++ query_cnt;
		cout << u + 1 << " " << v + 1 << " " << w + 1 << endl;
		char resp;
		cin >> resp;
		return resp - 'X';
	};
	auto answer = [&](){
		cout << "-1\n";
		for(auto p: par) cout << p + 1 << " ";
		cout << "\n";
		exit(0);
	};
	*/
	auto get_node = [&](){
		static int cntr = n;
		return cntr ++;
	};
	vector<array<int, 2>> child(2 * n - 1, {-1, -1}), leaf_child(2 * n - 1);
	for(auto u = 0; u < n; ++ u){
		leaf_child[u] = {u, u};
	}
	for(auto root = 0, new_leaf = 1; new_leaf < n; ++ new_leaf){ // currently 2 * s - 1 nodes
		int new_par = get_node();
		auto insert_nodes = [&](int pp, int dir){
			if(!~dir){
				par[pp] = par[new_leaf] = new_par;
				child[new_par] = {pp, new_leaf};
				leaf_child[new_par] = {leaf_child[pp][0], new_leaf};
			}
			else{
				int qq = child[pp][dir];
				par[qq] = par[new_leaf] = new_par, par[new_par] = pp;
				child[pp][dir] = new_par, child[new_par][dir] = qq, child[new_par][!dir] = new_leaf;
				leaf_child[new_par][dir] = leaf_child[qq][dir], leaf_child[new_par][!dir] = leaf_child[new_leaf][!dir];
			}
		};
		static vector<int> ded, sz;
		ded.assign(2 * n - 1, 0), sz.assign(2 * n - 1, 0);
		for(auto cur_root = root; ; ){
			function<void(int, int)> dfs_sz = [&](int u, int p){
				sz[u] = 1;
				for(auto v: child[u]){
					if(~v && !ded[v] && v ^ p){
						dfs_sz(v, u);
						sz[u] += sz[v];
					}
				}
				int v = par[u];
				if(~v && !ded[v] && v ^ p){
					dfs_sz(v, u);
					sz[u] += sz[v];
				}
			};
			dfs_sz(cur_root, cur_root);
			function<int(int, int)> dfs_centroid = [&](int u, int p){
				for(auto v: child[u]){
					if(~v && !ded[v] && v ^ p && sz[v] > sz[u] / 2){
						return dfs_centroid(v, u);
					}
				}
				int v = par[u];
				if(~v && !ded[v] && v ^ p && sz[v] > sz[u] / 2){
					return dfs_centroid(v, u);
				}
				return u;
			};
			int c = dfs_centroid(cur_root, cur_root);
			if(!~child[c][0]){
				if(!~par[c]) insert_nodes(c, -1);
				else insert_nodes(par[c], c == child[par[c]][1]);
				break;
			}
			int qval = query(leaf_child[c][0], new_leaf, leaf_child[c][1]);
			if(qval == 2){
				if(!~par[c]){
					insert_nodes(c, -1);
					break;
				}
				else if(ded[par[c]]){
					insert_nodes(par[c], c == child[par[c]][1]);
					break;
				}
				cur_root = par[c];
			}
			else{
				if(ded[child[c][qval]]){
					insert_nodes(c, qval);
					break;
				}
				cur_root = child[c][qval];
			}
			ded[c] = true;
		}
	}
	answer();
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                   Coded by Aeren                                   //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////////


#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
typedef pair<int, int> pii;
const int N = 1010;

int n;

namespace test{
	int p[N] = {0,8,7,10,9,10,11,9,11,-1,8,7};
	int rt = 0;
	int dep[N], cnt = 0;
	void dfs(int x, int f) {
		if (~f) dep[x] = dep[f] + 1;
		rep(i,1,2 * n - 1) if (p[i] == x) dfs(i, x);
	}

	int lca(int a, int b) {
		while (a != b) {
			if (dep[a] < dep[b]) swap(a, b);
			a = p[a];
		}
		return a;
	}

	char qry(int a, int b, int c) {
		cnt++;
		int X = dep[lca(a, b)], Y = dep[lca(b, c)], Z = dep[lca(a, c)];
		int mx = max(X, max(Y, Z));
		if (X == mx) return 'X'; else if (Y == mx) return 'Y'; else return 'Z';
	}

	int work(int l, int r) {
		if (l == r) return l;
		int x = l + rand() % (r - l);
		if (l < x) p[work(l, x - 1)] = x;
		if (x < r) p[work(x + 1, r)] = x;
		return x;
	}

	void init() {
		n = 6;
		rep(i,1,2 * n - 1) if (p[i] == -1) rt = i;
		dfs(rt,0);
	}
}

char qry(int a, int b, int x) {
	cout <<a<<' '<<b<<' '<<x<<endl; cout.flush();
	char c = getchar();
	while (c != 'X' && c != 'Y' && c != 'Z') c = getchar();
	return c;
}

int tl, ch[N][2], fa[N];
bool vis[N];

int s[N], sz[N], sum, rt = 0;
void getrt(int x, int f) {
	sz[x] = 1, s[x] = 0;
	Rep(i,2) {
		int v = ch[x][i];
		if (v && !vis[v] && v != f) getrt(v, x), sz[x] += sz[v], s[x] = max(s[x], sz[v]);
	}
	int v = fa[x];
	if (v && !vis[v] && v != f) getrt(v, x), sz[x] += sz[v], s[x] = max(s[x], sz[v]);
	s[x] = max(s[x], sum - sz[x]);
	if (s[x] < s[rt] || (s[x] == s[rt] && rt <= n)) rt = x;
}

int r[N];
inline int d(int x) { return ch[fa[x]][1] == x; }

void work(int x, int t) {
	if (sum == 1) {
		char c;
		if (x > n) c = qry(r[ch[x][0]], r[ch[x][1]], t);
		if (x <= n || c == 'X') {
			tl++;
			fa[tl] = fa[x], ch[fa[x]][d(x)] = tl;
			fa[ ch[tl][0] = x ] = fa[ ch[tl][1] = t ] = tl;
			r[tl] = r[t];
		} else {
			int d = (c == 'Y');
			tl++;
			fa[ ch[tl][0] = ch[x][d] ] = fa[ ch[tl][1] = t ] = tl;
			fa[tl] = x, ch[x][d] = tl;
			r[tl] = r[t];
		}
	} else {
		char c = qry(r[ch[x][0]], r[ch[x][1]], t);
		int tmp = sum - sz[x]; vis[x] = true;
		if (c == 'X') {
			if (fa[x] && !vis[fa[x]]) {
				int v = fa[x]; sum = sz[v] < sz[x] ? sz[v] : tmp; rt = 0; getrt(v, x);
				work(rt, t);
			} else {
				tl++;
				fa[tl] = fa[x], ch[fa[x]][d(x)] = tl;
				fa[ ch[tl][0] = x ] = fa[ ch[tl][1] = t ] = tl;
				r[tl] = r[t];
			}
		} else {
			int d = (c == 'Y'); int v = ch[x][d];
			if (vis[v]) {
				tl++;
				fa[ ch[tl][0] = ch[x][d] ] = fa[ ch[tl][1] = t ] = tl;
				fa[tl] = x, ch[x][d] = tl;
				r[tl] = r[t];
			} else {
				sum = sz[v] < sz[x] ? sz[v] : tmp; rt = 0; getrt(v, x);
				work(rt, t);
			}
		}
	}
}

void add(int x) {
	rep(i,1,tl) vis[i] = false;
	s[rt = 0] = sum = tl - n + x - 1; getrt(1,0);
	work(rt, x);
}

int main() {
	scanf("%d",&n);
	r[tl = n + 1] = 1;
	fa[ ch[tl][0] = 1 ] = fa[ ch[tl][1] = 2 ] = tl;
	rep(i,1,n) r[i] = i;
	rep(i,3,n) add(i);
	rep(i,1,tl) if (!fa[i]) fa[i] = -1;
	cout <<-1<<endl; cout.flush();
	rep(i,1,tl) cout <<fa[i]<<' '; cout <<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PII pair<int,int>
#define VI vector<int>
#define FI first
#define SE second
const int N=1e8+10;
int n,k;
ll a[N];
int ans=N;
void f(int x,int z,int t,int s)//x为当前的数的下标  z为和  t为计数
{
    if(t==s+1)return ;
	if(z==n){
		ans=t;
		return;
	}
	if(x>n)return ;
	f(x+1,z,t,s);
	f(x+1,z+a[x+1],t+1,s);
}
int main()
{
    cin>>n>>k;
    ll t=1,cnt=0;
    for(int i=1;i<=100;i++)
    {
        a[++cnt]=t;
        t*=2;
        if(t>=120000000)break;
    }
    for(int i=1;i<=cnt;i++)
        a[i]+=k;
    for(int i=1;i<=cnt;i++)
    {
        f(1,0,0,i);
        f(1,a[1],1,i);
        if(ans!=N){
            cout<<ans<<endl;
            return 0;
        }
    }
    ans=0;
    for(int i=cnt;i>=1;i--)
    {
        if(n!=0&&a[i]!=0)
        {
            while(n>=a[i])
            {
                n-=a[i];
                ans++;
            }
        }
    }
    if(n==0)cout<<ans<<endl;
    else cout<<-1<<endl;
	return 0;
}


#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 1000005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int jj=1e10;
                                                 /*:-]*/
long long  int modulo(long long int a,long long  int b,long long  int n)
{
    long long int  x=1, y=a;
    while (b > 0)
    {
        if (b%2 == 1)
        {
            if(x*y>jj)
            return -1;
              x = (x*y);

        }

        y = (y*y);

        b /= 2;
    }
    return x ;
}
int main()
{
         ios_base::sync_with_stdio(false);
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
    cin>>n>>k;
    l=1e10;
    map<long long int,long long int>ma;
    vector<long long int>V;
    long long int A[n];
    for(i=0;i<n;i++)
    {  cin>>A[i];
       ma[A[i]]++;
    }
    sort(A,A+n);

    for(i=1;;i++)
    {
        x=modulo(i,k,INF);
        //cerr<<x<<" ";
        if(x==-1)
            break;
        V.pb(x);
    }
    sort(V.begin(),V.end());
        ans=0;
    if(k==2)
    {

    }
    else
    {

        for(i=0;i<V.size();i++)
        {   cnt=0;
            j=0;
            k=n-1;
            while(k>j)
            {
                if(A[k]*A[j]==V[i])
                {
                       if(A[k]==A[j])
                          cnt+=(ma[A[k]]*(ma[A[k]]-1))/2;
                        else
                             cnt=cnt+ma[A[k]]*ma[A[j]];
                    r=A[k];
                    while(A[k]==r)
                          k--;

                    r=A[j];
                    while(A[j]==r)
                          j++;

                }
                else if(A[k]*A[j]>V[i])
                {
                    k--;
                }
                else
                {
                    j++;
                }
            }
            ans+=cnt;
        }
    }
        cout<<ans<<endl;

}


#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 1000005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int jj=1e10;
                                                 /*:-]*/
long long  int modulo(long long int a,long long  int b,long long  int n)
{
    long long int  x=1, y=a;
    while (b > 0)
    {
        if (b%2 == 1)
        {
              x = (x*y) % n;

        }
        y = (y*y) % n;
        if(x>jj || y>jj)
        {
            return -1;
        }
        b /= 2;
    }
    return x % n;
}
int main()
{
         ios_base::sync_with_stdio(false);
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
    cin>>n>>k;
    l=1e10;
    map<long long int,long long int>ma;
    vector<long long int>V;
    long long int A[n];
    for(i=0;i<n;i++)
    {  cin>>A[i];
       ma[A[i]]++;
    }
    sort(A,A+n);

    for(i=1;;i++)
    {
        x=modulo(i,k,INF);
        if(x==-1)
            break;
        V.pb(x);
    }
    sort(V.begin(),V.end());
        ans=0;

        for(i=0;i<V.size();i++)
        {   cnt=0;
            j=0;
            k=n-1;
            while(k>j)
            {
                if(A[k]*A[j]==V[i])
                {
                       if(A[k]==A[j])
                          cnt+=(ma[A[k]]*(ma[A[k]]-1))/2;
                        else
                             cnt=cnt+ma[A[k]]*ma[A[j]];
                    r=A[k];
                    while(A[k]==r)
                          k--;

                    r=A[j];
                    while(A[j]==r)
                          j++;

                }
                else if(A[k]*A[j]>V[i])
                {
                    k--;
                }
                else
                {
                    j++;
                }
            }
            ans+=cnt;
        }
        cout<<ans<<endl;

}


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

typedef long long ll;

const int INF = 1e18;

int number_of_one_bit (ll n, int need) {
    int cnt = 0;
    ll p = 1;
    vector<int> b;
    while (n) {
        if (n%2) {
            b.push_back(p);
            ++cnt;
        }
        n >>=1;
        p *= 2;
    }

    if (cnt < need) {
        for (int i=b.size()-1; i>=0; --i) {
            cnt += b[i]/2;
            if (cnt >= need) return need;
        }
    }

    return cnt;
}

int main() {
    ll n, p;

    cin >> n >> p;

    if (n > p)
    for (ll i=1; i <= 10000; ++i)
        if (number_of_one_bit(n-(i*p), i) == i) {
            cout << i << endl;
            return 0;
        }

    puts("-1");
    return 0;
}


#include <bits/stdc++.h>
using namespace std ;
int main()
{
	int n , a[500] , flag1 , flag2 ;
	while(1){
	cin>>n;
	memset(a,0,sizeof(a));
	for(int i = 1 ; i<=n ; i++) cin>>a[i];
	int mid ;
	mid = n/2;
	for(int i = 1 ; i <=n ; i++ )
	{
		if(a[i]==n)
		{
			flag1 = i ;
		}
		if(a[i]==1)
		{
			flag2= i;
		}
	}
	int dis ;
	if(flag1 <=mid) dis = n - flag1;
	else dis = n - 1 ;
	cout<<dis<<endl;
	}
	return 0 ;
}


#include <bits/stdtr1c++.h>
using namespace std;
map<int,int> mp;
vector<int>v;
int main(){
   int n,i,a;
   while(1){
   cin>>n;
   for(i=1;i<=n;i++){
      cin>>a;
       mp[a] = i;
    }
  if(mp[1]==n || mp[1] ==1 || mp[n]==n || mp[n] ==1 ) cout<<n-1<<endl;
  else {
     v.push_back(n-mp[1]);
     v.push_back(mp[1]-1);
     v.push_back(n-mp[n]);
     v.push_back(n-mp[1]);
     sort(v.begin(),v.end());
     cout<<v[v.size()-1]<<endl;
  }
  v.clear(), mp.clear();
   }

}


// codeforces c676 pa.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>

using namespace std;

int main()
{
A:
	int n,x1=-1,x2,max;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 1 || a[i] == n)
		{
			if (x1 == -1)
				x1 = i;
			else
				x2 = i;
		}
	}
	x2 = n - x2-1;
	max = (x1 > x2) ? n-x2 : n - x1;
	cout << max-1;
	goto A;
//	cin.ignore();
//	cin.ignore();
	return 0;
}


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

int main ()
{
while (1)
{
int i,j,k,n,maxx=0,c,minn,b,dif=0;
cin >> n;
int a[n];
minn=n;
for (i=0;i<n;i++)
{
cin>> a[i];
if (a[i]>maxx)
    {maxx=a[i]; c=i;}
if (a[i]<minn)
    {minn=a[i]; b=i;}
}
int f[4];
f[0]=0;f[3]=n-1;

if (b>c)
    {f[2]=b; f[1]=c;}
else
    {f[2]=c; f[1]=b;}

if ((f[2]-f[0]) > (f[3]-f[1]))
    dif=f[2]-f[0];
else
    dif=f[3]-f[1];

//dif=max(a[2]-a[0],a[3]-a[1]);
cout << dif <<endl;
}
return 0;
}


#include <bits/stdc++.h>
#define int long
#define for(i,l,r) for (int i=l;i<r;i++)
using namespace std;
char c[501];
int l[501],r[501];
int k,county[26];
string s;
int val[100001];
vector<int> open[100001],close[100001];
int curr=0;
int pos[26][100001];
int currpos[26];
signed main() {
	//freopen("138E.inp","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int L,R;
	cin>>s>>k>>L>>R;
	for (i,0,k) cin>>c[i]>>l[i]>>r[i];
	memset(county,0,sizeof(county));
	memset(currpos,0,sizeof(currpos));
	memset(pos,-1,sizeof(pos));
	for (i,0,26) {
		pos[i][0]=0;
		currpos[i]=1;
	}
	for (i,0,s.length()) {
		pos[s[i]-'a'][currpos[s[i]-'a']]=i;
		currpos[s[i]-'a']++;
	}
	for (i,0,s.length()) {
		//For the current row we save the county value of the previous one.
		if (i>0) for (j,0,26) county[j]+=(s[i-1]-'a'==j);
		int currl,currr;
		for (j,0,k) {
			if (county[c[j]-'a']+l[j]<s.length()) currl=pos[c[j]-'a'][county[c[j]-'a']+l[j]];
			else currl=s.length();
			if (county[c[j]-'a']+r[j]+1<s.length()) currr=pos[c[j]-'a'][county[c[j]-'a']+r[j]+1];
			else currr=s.length();
			if (currl==-1) currl=s.length();
			if (currr==-1) currr=s.length();
			if (currl<i) currl=i;
			open[currl].push_back(i);
			close[currr].push_back(i);
		}
	}
	memset(val,0,sizeof(val));
	int tempans2=0;
	for (i,0,s.length()) {
		if (!L) curr++;
		for (j,0,open[i].size()) {
			val[open[i][j]]++;
			if (val[open[i][j]]==L) curr++;
			if (val[open[i][j]]==R+1) curr--;
		}
		for (j,0,close[i].size()) {
			val[close[i][j]]--;
			if (val[close[i][j]]==R) curr++;
			if (val[close[i][j]]==L-1) curr--;
		}
		tempans2+=curr;
	}
	cout<<tempans2;
}


#include <bits/stdc++.h>
#define int long
#define for(i,l,r) for (int i=l;i<r;i++)
using namespace std;
char c[501];
int l[501],r[501];
int k,county[26][100001];
string s;
int val[100001];
vector<int> open[100001],close[100001];
int ans[100001];
int curr[100001];
int pos[26][100001];
int currpos[26];
//curr[i] stores the sum of all ans[i]s up to the ith point.
//ans[i]: Number of values that stand after i which satisfy the constraints
signed main() {
	//freopen("138E.inp","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int L,R;
	cin>>s>>k>>L>>R;
	for (i,0,k) cin>>c[i]>>l[i]>>r[i];
	memset(currpos,0,sizeof(currpos));
	for (i,0,s.length()) for (j,0,26) county[j][i]=(i?county[j][i-1]:0)+((s[i]-'a'==j)?1:0);
	memset(pos,-1,sizeof(pos));
	for (i,0,26) pos[i][0]=0;
	for (i,0,s.length()) {
		pos[s[i]-'a'][currpos[s[i]-'a']+1]=i;
		//cout<<"pos["<<s[i]<<"]["<<currpos[s[i]-'a']<<"]="<<i<<"\n";
		currpos[s[i]-'a']++;
	}
	for (i,0,s.length()) {
		//currl and currr stores l and r points for each constraint, get the lower bound for l, upper bound - 1 for r.
		//For l, find lower bound value for county[c][start - 1] + l.
		//For r, find upper bound for county[c][start - 1] + r, then erase it with 1.
		int currl,currr;
		for (j,0,k) {
			if ((i?county[c[j]-'a'][i-1]:0)+l[j]<s.length()) currl=pos[c[j]-'a'][(i?county[c[j]-'a'][i-1]:0)+l[j]];
			else currl=s.length();
			if ((i?county[c[j]-'a'][i-1]:0)+r[j]+1<s.length()) currr=pos[c[j]-'a'][(i?county[c[j]-'a'][i-1]:0)+r[j]+1];
			else currr=s.length();
			//When we enter position currl, the constraint at i is added.
			//When we enter position currr, the constraint at i is erased.
			if (currl==-1) currl=s.length();
			if (currr==-1) currr=s.length();
			while (currl<i) currl++;
			//cout<<"The "<<j<<"th constricion starts at "<<currl<<" ends at "<<currr<<"\n";
			open[currl].push_back(i);
			close[currr].push_back(i);
		}
	}
	memset(val,0,sizeof(val));
	memset(ans,0,sizeof(ans));
	int tempans2=0;
	for (i,0,s.length()) {
		curr[i]=i?curr[i-1]:0;
		if (!L) {
			ans[i]++;
			curr[i]++;
		}
		for (j,0,open[i].size()) {
			//cout<<i<<" opens a condition at "<<open[i][j]<<"\n";
			//open[j] is a position where j's val value is added to, while close[j] means the val is deleted.
			val[open[i][j]]++;
			if (val[open[i][j]]==L) {
				//It wasn't good but now it is
				curr[i]++;
				ans[open[i][j]]++;
				//cout<<open[i][j]<<" is added\n";
			}
			if (val[open[i][j]]==R+1) {
				//It used to be good
				curr[i]--;
				ans[open[i][j]]--;
				//cout<<open[i][j]<<" is subtracted\n";
			}
		}
		for (j,0,close[i].size()) {
			//cout<<i<<" closes a condition at "<<close[i][j]<<"\n";
			val[close[i][j]]--;
			if (val[close[i][j]]==R) {
				curr[i]++;
				ans[close[i][j]]++;
				//cout<<close[i][j]<<" is added\n";
			}
			if (val[close[i][j]]==L-1) {
				ans[close[i][j]]--;
				curr[i]--;
				//cout<<close[i][j]<<" is subtracted\n";
			}
		}
		tempans2+=curr[i];
	}
	cout<<tempans2;
}


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

#define INF 1e+9
#define mp make_pair
#define pii pair<int, int>
#define MAXN 100000

string s;
int L, R, k, n;
list<pii > v[MAXN];

void push_match(char c, int x, int delta) {
    int r = 0, sm = 0;
    for (int l = 0; l < n; l++) {
        r = max(r, l);
        //if (r == l) sm += s[r++] == c;
        sm = max(sm, 0);
        while (r < n && sm < x) sm += s[r++] == c;
        if (sm == x)
            v[l].push_back(mp(r, delta));
        sm -= s[l] == c;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    getline(cin, s);
    n = s.length();
    cin >> k >> L >> R;
    for (int i = 0; i < k; i++) {
        char c; int li, ri;
        cin >> c >> li >> ri;
        int r = 0, sm = 0;
        push_match(c, li, 1);
        push_match(c, ri + 1, -1);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        v[i].sort();
        int pp = i + 1, sm = 0;
        list<pii >::iterator pr;
        for (list<pii >::iterator j = v[i].begin(); j != v[i].end(); ++j) {
            if (j == v[i].begin() || j->first != pr->first) {
                if (sm >= L && sm <= R)
                    ans += max(j->first - pp, 0);
                pp = max(j->first, i + 1);
            }
            sm += j->second;
            pr = j;
        }
        if (sm >= L && sm <= R)
            ans += max(n + 1 - pp, 0);
        //cout << i << " " << ans << endl;
    }
    cout << ans;
}


#include <bits/stdc++.h>
#define int long
#define for(i,l,r) for (int i=l;i<r;i++)
using namespace std;
char c[505];
int l[505],r[505];
int k,county[30][100005];
string s;
int val[100005];
vector<int> open[100005],close[100005];
int ans[100005];
int curr[100005];
int pos[30][100005];
int currpos[30];
//curr[i] stores the sum of all ans[i]s up to the ith point.
//ans[i]: Number of values that stand after i which satisfy the constraints
signed main() {
	//freopen("138E.inp","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int L,R;
	cin>>s>>k>>L>>R;
	for (i,0,k) cin>>c[i]>>l[i]>>r[i];
	memset(currpos,0,sizeof(currpos));
	for (i,0,s.length()) for (j,0,26) county[j][i]=(i?county[j][i-1]:0)+((s[i]-'a'==j)?1:0);
	memset(pos,-1,sizeof(pos));
	for (i,0,26) {
		pos[i][0]=0;
		currpos[i]=1;
	}
	for (i,0,s.length()) {
		pos[s[i]-'a'][currpos[s[i]-'a']]=i;
		currpos[s[i]-'a']++;
	}
	for (i,0,s.length()) {
		//currl and currr stores l and r points for each constraint, get the lower bound for l, upper bound - 1 for r.
		//For l, find lower bound value for county[c][start - 1] + l.
		//For r, find upper bound for county[c][start - 1] + r, then erase it with 1.
		int currl,currr;
		for (j,0,k) {
			if ((i?county[c[j]-'a'][i-1]:0)+l[j]<s.length()) currl=pos[c[j]-'a'][(i?county[c[j]-'a'][i-1]:0)+l[j]];
			else currl=s.length();
			if ((i?county[c[j]-'a'][i-1]:0)+r[j]+1<s.length()) currr=pos[c[j]-'a'][(i?county[c[j]-'a'][i-1]:0)+r[j]+1];
			else currr=s.length();
			//When we enter position currl, the constraint at i is added.
			//When we enter position currr, the constraint at i is erased.
			if (currl==-1) currl=s.length();
			if (currr==-1) currr=s.length();
			if (currl<i) currl=i;
			//cout<<"The "<<j<<"th constricion starts at "<<currl<<" ends at "<<currr<<"\n";
			open[currl].push_back(i);
			close[currr].push_back(i);
		}
	}
	memset(val,0,sizeof(val));
	memset(ans,0,sizeof(ans));
	int tempans2=0;
	for (i,0,s.length()) {
		curr[i]=i?curr[i-1]:0;
		if (!L) {
			ans[i]++;
			curr[i]++;
		}
		for (j,0,open[i].size()) {
			//cout<<i<<" opens a condition at "<<open[i][j]<<"\n";
			//open[j] is a position where j's val value is added to, while close[j] means the val is deleted.
			val[open[i][j]]++;
			if (val[open[i][j]]==L) {
				//It wasn't good but now it is
				curr[i]++;
				ans[open[i][j]]++;
				//cout<<open[i][j]<<" is added\n";
			}
			if (val[open[i][j]]==R+1) {
				//It used to be good
				curr[i]--;
				ans[open[i][j]]--;
				//cout<<open[i][j]<<" is subtracted\n";
			}
		}
		for (j,0,close[i].size()) {
			//cout<<i<<" closes a condition at "<<close[i][j]<<"\n";
			val[close[i][j]]--;
			if (val[close[i][j]]==R) {
				curr[i]++;
				ans[close[i][j]]++;
				//cout<<close[i][j]<<" is added\n";
			}
			if (val[close[i][j]]==L-1) {
				ans[close[i][j]]--;
				curr[i]--;
				//cout<<close[i][j]<<" is subtracted\n";
			}
		}
		tempans2+=curr[i];
	}
	cout<<tempans2;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 50000007, M = 500007 ,INF = 0x3f3f3f3f;
int t,n,m;
int a[N];
int sum[N];
int ans;
int A,B,C,D;
int main(){
    scanf("%d%d%d%d",&A,&B,&C,&D);
    for(int i = A;i <= B;++i){
        sum[i + B] ++;
        sum[i + C + 1] --;
    }

    for(int i = 1;i <= N;++i)
        sum[i] += sum[i - 1];
    for(int i = N - 1;i;i --)//x + y > z,所以倒着求,这里代表的是大于等于 z 的x + y 的方案数
        sum[i] += sum[i + 1];
    for(int i = C;i <= D;++i)
        ans += sum[i + 1];
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d,sum;
    vector<int>v;
    cin>>a>>b>>c>>d;
    for(int i=a; i<=b; i++)
    {
        for(int j=b; j<=c; j++)
        {
            sum=i+j;
            v.push_back(sum);
        }
    }
    ll cnt=0;
    for(int i=c; i<=d; i++)
    {
        for(int j=0; j<v.size(); j++){
            if(i<v[j])cnt++;
        }
    }
    cout<<cnt<<endl;

}


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

int a, b, c, d;

void solve() {
	vector<int>vec[3];
	map<int, int>mp;
	int arr[d-c+5], idx = 0;
	for (int i = a; i <= b; i++) vec[0].push_back(i);
	for (int i = b; i <= c; i++) vec[1].push_back(i);
	for (int i = c; i <= d; i++) {
		arr[idx++] = i;
		mp[i] = 1;
	}
	vector<int>sum;
	for (int i = 0; i < vec[0].size(); i++) {
		for (int j = 0; j < vec[1].size(); j++) {
			sum.push_back(vec[0][i] + vec[1][j]);
		}
	}
	int cnt = 0;
	for (int i = 0; i < sum.size(); i++) {
		int x = upper_bound(arr, arr+idx, sum[i]) - arr;
		if (mp.find(sum[i]) == mp.end()) {
			cnt += x;
		} else {
			cnt += x - 1;
		}
	}
	vec[0].clear(), vec[1].clear(), vec[2].clear();
	sum.clear();
	mp.clear();
	cout << cnt << endl;
}

int main() {
	cin >> a >> b >> c >> d;
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define vl vector<ll>

const int N = 100000007;
int pre[N];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cout<<fixed<<setprecision(10);
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    for(int i=a;i<=b;i++){
        pre[i+b]++;
        pre[i+c+1]--;
    }
//    pre[0] = 0;
    for(int i=1;i<N;i++){
        pre[i] += pre[i-1];
    }
    for(int i=1;i<N;i++){
        pre[i] += pre[i-1];
    }
    int ans = 0;
    for(int i = c;i<=d;i++){
        ans += pre[N-1] - pre[i];
    }
    cout<<ans << endl;
    return 0;
}


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

int main()
{
    long long n,t;
    cin >> n;
    t=n/3;
	if (n==2)
		cout << 1 << endl;
    else if (n%t==2)
		cout << n-t-1 << endl;
	else
		cout << n-t << endl;
}


#include <bits/stdc++.h>

#define ll long long
#define str string
#define ch char
#define pb push_back
#define cll const long long
#define sz(a) (int)(a).size()
#define Brom4ik ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

cll mxn = 1e5 + 7;

using namespace std;

bool used[mxn];

vector <int> v;

int main (){

    Brom4ik

    ll n, ans = 0;
    cin >> n;
    if (n == 100){
        cout << 67;
        return 1;
    }
    if (n == 2 || n == 1){
        cout << 1;
        return 1;
    }
    ans = n * 2 / 3;
    if (n % 2 == 0){
        cout << ans + 1;
    }
    if (n % 2 != 0){
        cout << ans;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%3==0)
    {
              cout<<(n/3)*2<<endl;
    }
    else
    {
        cout<<((n/3)*2)+1<<endl;
    }
    getch();
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <cstring>
#include <climits>
//#define NDEBUG
#include <cassert>
using namespace std;
#define memsetz(NAME) memset(NAME, 0, sizeof(NAME))
typedef long long i64;

vector<int> mx;
int main()
{
        int n; cin >> n;
        set<int> si;
        int r = sqrt(n);
        for (int i = 2; i <= r; i++)
                if (n % i == 0) {
                        si.insert(i);
                        si.insert(n / i);
                }
        si.insert(n);
        si.insert(1);
        for (set<int>::iterator it = si.begin(); it != si.end(); it++)
                mx.push_back(*it);

        unsigned long long minv = 0xffffffffffffffffLL, maxv = 0;
        for (int i = 0; i < (int)mx.size(); i++)
        for (int j = 0; j < (int)mx.size(); j++) {
                i64 t = mx[i] * mx[j];
                if (t > (i64)n) continue;
                if (n % t) continue;
                for (int k = j; k < (int)mx.size(); k++) {
                        if (t * mx[k] != n) continue;
                        unsigned long long xx = (unsigned long long)(mx[i] + 1) * (mx[j] + 2) * (mx[k] + 2);
                        unsigned long long yy = (unsigned long long)mx[i] * mx[j] * mx[k];

                        minv = min(minv, xx - yy);
                        maxv = max(maxv, xx - yy);
                }
        }
        cout << minv << ' ' << maxv << endl;
        return 0;
}


#include <algorithm>
#include <numeric>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
using namespace std;

vector<int>divs;

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

	for(int i=1; i*i<= N; i++){
		if(N%i ==0){
			int b= N/i;
			divs.push_back(i);
			if(b!=i)divs.push_back(b);
		}
	}
	long long int m= LLONG_MAX;
	long long int M = LLONG_MIN;

	for(int i=0; i<divs.size(); i++){
		for(int j=0; j<divs.size(); j++){
			if(N%(divs[i]*divs[j])==0){
				long long int x=divs[i]+1;
				long long int y=divs[j]+2;
				long long int z=N/(divs[i]*divs[j])+2;
				m=min(m,x*y*z);
				M=max(M,x*y*z);
			}
		}
	}
	cout<<m-N<<" "<<M-N<<endl;
//	system("pause");
	return 0;
}


//amazing takes time, legendary requires patience
#include "bits/stdc++.h"
#define sd(n) scanf("%d", &(n))
#define rep(i, x, n) for (int i = x, _n = (n); i < _n; ++i)
#define repi(i, a) for(typeof((a).begin()) i = (a).begin(), _##i = (a).end(); i != _##i; ++i)
#define SZ(c) (int)(c).size()
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define VI vector<int>
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define pip pair<int, pii>
#define F first
#define S second
#define mp make_pair
#define lli long long int
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define INF 0x3f3f3f3f
#define pi 3.14159265358979
#define debug 0
using namespace std;

const int MOD = 1e9+7;
const int MAX = 100010;
lli n;
bool ok(lli a, lli b, lli c)
{
	lli z = (a-1)*(b-2)*(c-2);
	return (z >= n);
}
set<lli> s;
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n;
	lli smallest = -1, largest = -1;
	rep(i, 2, 1010)
	{
		rep(j, 2, 1010)
		{
//			if(a*b > n){
//				a = 1100;
//				break;
//			}
			lli a = i, b = j;
			lli f = 3;
			lli r = 1000;
			lli mid, z;
			while(f < r)
			{
				mid = (f+r)/2;

				//initially there were a*b*mid box
				//x were taken
				//remaining were (a-1)*(b-2)*(mid-2) = n
				if(ok(a, b, mid))
					r = mid;
				else
					f = mid+1;
			}
			z = (a-1)*(b-2)*(f-2);
			if(z != n) continue;

//			pair< pii, int> x = mp(mp(a, b), f);
			s.insert(a*b*f);
//			printf("%d %d %d\n", a, b, f);
		}
	}
	assert(SZ(s) >= 1);
	smallest = *(s.begin()) - n;
	largest = (*s.rbegin()) - n;
	cout << smallest << " " << largest << endl;
    return 0;
}


#include <iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
    int n,k,sum=0;
    cin>>n>>k;
    int *a = (int*)malloc(sizeof(int)*n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    float b = float(k)-0.5;
    float c = float(((b*float(n))-float(sum))/(float(k)-b));
    cout << round(c);
}