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

#define int long long
typedef pair <int, int> pii;

const int N = 1e6 + 10, M = 18;
int n, pw4[M], pw8[M];
pii dp[N];

int main() {
    pw4[0] = pw8[0];
    for (int i = 1; i < M; i++) {
        pw4[i] = pw4[i - 1] * 4;
        pw8[i] = pw8[i - 1] * 8;
    }

    fill(dp, dp + N, pii(-1, -1));
    dp[1] = {4, 1};
    dp[2] = {8, 1};

    for (int i = 3; i < N; i++) {
        if (dp[i - 1].second < 17 && dp[i - 1].first != -1) {
            dp[i].second = dp[i - 1].second + 1;
            dp[i].first = dp[i - 1].first + pw4[dp[i].second];
        }
        else if (dp[i - 2].second < 17 && dp[i - 2].first != -1) {
            dp[i].second = dp[i - 1].second + 1;
            dp[i].first = dp[i - 1].first + pw8[dp[i].second];
        }
    }

    cin >> n;
    cout << dp[n].first;
}


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

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;

#define si(x) scanf("%d",&x);
#define sl(x) scanf("%ld",&x);
#define sll(x) scanf("%lld",&x);

#define pi(x) printf("%d",x);
#define pl(x) printf("%ld",x);
#define pll(x) printf("%lld",x);
#define pn printf("\n");
#define ps printf(" ");

const ll mod=1000000007ll;
const ll Mod=1000000009ll;
const ll inf=(ll)5e18;
const ld eps=1e-12;
const ll N=1000005;
const ll LOGN=19;
const ld PI=3.14159265358979323846;

#define sf(x) sort(x.begin(),x.end(),func)
#define s(x) sort(x.begin(),x.end())

#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

#define len(a) sizeof(a)/sizeof(a[0])
#define printArray(a) for(int i=0;i<length(a);i++){cout << a[i];cout << " ";}cout << endl;

template <class T>T max2(T a,T b){return a<b?b:a;}
template <class T>T min2(T a,T b){return a<b?a:b;}
template <class T>T max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

void print(int a[],int s,int e){for(int i=s;i<=e;i++)cout<<a[i]<<" ";cout<<"\n";}
void print(vector<int> &v,int s,int e){for(int i=s;i<=e;i++)cout<<v[i]<<" ";cout<<"\n";}
void print(vector<int> &v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n";}

ll mul(ll a,ll b,ll m=Mod){return (ll)(a*b)%m;}
ll add(ll a,ll b,ll m=Mod){a+=b; if(a>=m) a-=m; if(a<0) a+=m; return a;}
ll power(ll a,ll b,ll m=Mod){if(b==0) return 1; if(b==1) return (a%m); ll x=power(a,b/2,m); x=mul(x,x,m); if(b%2) x=mul(x,a,m); return x;}

int main(){
    ll n;sll(n);
    string s;
    while(n!=0){
    	if(n>=2){
    		s+='8';
    		n-=2;
    	}
    	else{
    		s+='0';
    		n-=1;
    	}
    }
    if(s.length>=18)
    	cout<<"-1";
    else
    	cout<<s;pn;
    return 0;
}


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

int a[10] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1};
typedef long long ll;
const ll MAXN = 1e18;

int main (){
	ll x;
	cin >> x;
	if (x >= 37)	cout << "-1" << endl;
	else
	{
		if (x % 2 == 0){
		ll y = x / 2;
		ll sum = 0;
		for (int i = 0; i < y; i++){
			cout << 8;
		}
		cout << endl;
	}
		else{
		ll y = x / 2;
		for (int i = 0; i < y; i++){
			sum = (sum * 10) + 8;
		}
//		for (int i = 0; i < y; i++){
//			num *= 10;
//		}
		sum = sum*10;
		cout << sum <<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int n;
int ar[50][50];
int dp[51][51];
bool leaf[50];
vector<int> adj[50];
vector<int> leafs;
int bad;
vector<int> pos;
int go(int rem, int now){
    if(rem==0){
        return 0;
    }
    if(dp[rem][now]!=-1){
        return dp[rem][now];
    }
    int low = 0;
    int high = 125000;
    while(low<high){
        int mid = (low+high+1)/2;
        int temp = rem;
        for(int i = 0; i<n; i++){
            if(!leaf[i] || i==now){
                continue;
            }
            int cur = 0;
            while(temp>0 && ar[now][i]+go(rem-cur-1,i)>=mid){
                cur++;
                temp--;
            }
        }
        if(temp==0){
            low = mid;
        }
        else{
            high = mid-1;
        }
    }
    dp[rem][now] = low;
    return low;
}
void dfs(int now, int from){
    if(leaf[now]){
        leafs.push_back(now);
    }
    for(int i = 0; i<pos.size(); i++){
        if(now==pos[i]){
            bad++;
        }
    }
    for(int i = 0; i<adj[now].size(); i++){
        int to = adj[now][i];
        if(to!=from){
            dfs(to,now);
        }
    }
}
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(int i = 0; i<n; i++){
        for(int j = 0; j<n; j++){
            if(i==j){
                ar[i][j] = 0;
            }
            else{
                ar[i][j] = 25500000;
            }
        }
    }
    int maxw = 0;
    for(int i = 1; i<n; i++){
        int a, b, w;
        cin >> a >> b >> w;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        ar[a][b]=w;
        ar[b][a]=w;
        maxw = max(maxw,w);
    }
    assert(maxw<=50);
    for(int k = 0; k<n; k++){
        for(int i = 0; i<n; i++){
            for(int j = 0; j<n; j++){
                ar[i][j] = min(ar[i][j],ar[i][k]+ar[k][j]);
            }
        }
    }
    for(int i = 0; i<=50; i++){
        for(int j = 0; j<=50; j++){
            dp[i][j] = -1;
        }
    }
    for(int i = 0; i<n; i++){
        leaf[i] = adj[i].size()==1;
    }
    //stuff
    int start, m;
    cin >> start >> m;
    start--;
    for(int i = 0; i<m; i++){
        int x;
        cin >> x;
        x--;
        pos.push_back(x);
    }

    int ans = 125000;
    if(n==1){
        assert(false);
        ans = 0;
    }
    for(int i = 0; i<adj[start].size(); i++){
        leafs.clear();
        leafs.resize(0);
        bad = 0;
        dfs(adj[start][i],start);
        if(bad==0){
            continue;
        }
        //stuff
        int low = 0;
        int high = ans+2;
        while(low<high){
            int mid = (low+high+1)/2;
            int temp = bad;
            for(int z = 0; z<leafs.size(); z++){
                int cl = leafs[z];
                if(cl==start){
                    continue;
                }
                int cur = 0;
                while(temp>0 && ar[start][cl]+go(m-cur-1,cl)>=mid){
                    cur++;
                    temp--;
                }
            }
            if(temp==0){
                low = mid;
            }
            else{
                high = mid-1;
            }
        }
        ans = min(ans,low);
    }
    assert(ans!=125000 && ans!=0);
    cout << ans << endl;
    return 0;l


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

using namespace std;
const int MAXN = 55;
int _w;

int n, s, m, x[MAXN];
int s[680];

namespace Tree {
	int head[MAXN], nxt[MAXN<<1], to[MAXN<<1], len[MAXN<<1], eidx;
	void init() {
		memset(head, -1, sizeof head);
	}
	void adde( int u, int v, int w ) {
		to[eidx] = v, len[eidx] = w;
		nxt[eidx] = head[u], head[u] = eidx++;
		to[eidx] = u, len[eidx] = w;
		nxt[eidx] = head[v], head[v] = eidx++;
	}
}

bool leaf[MAXN];
void prelude() {
	using namespace Tree;
	for( int u = 1; u <= n; ++u ) {
		int d = 0;
		for( int i = head[u]; ~i; i = nxt[i] )
			++d;
		leaf[u] = d == 1;
	}
}

int f[MAXN<<1][MAXN][MAXN], g[MAXN];
int knapsack( int e, int m, int k );
int dp( int e, int m, int k ) {
	using namespace Tree;
	int &now = f[e][m][k];
	if( now != -1 ) return now;
	if( !m ) return now = 0;
	if( leaf[to[e]] ) now = dp(e^1, m-k, m-k) + len[e];
	else now = knapsack(e, m, k) + len[e];
	// printf( "dp: f[%d, %d][%d][%d] = %d\n", to[e^1], to[e], m, k, now );
	return now;
}
int knapsack( int e, int m, int k ) {
	using namespace Tree;
	int u = to[e], fa = to[e^1];
	for( int i = head[u]; ~i; i = nxt[i] )
		if( to[i] != fa )
			for( int j = 1; j <= k; ++j )
				dp(i, m, j);
	g[0] = 1e9;
	for( int i = 1; i <= k; ++i ) g[i] = -1;
	for( int i = head[u]; ~i; i = nxt[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		for( int j = k-1; j >= 0; --j )
			for( int kk = 1; j+kk <= k; ++kk )
				g[j+kk] = max( g[j+kk], min(g[j], dp(i, m, kk)) );
	}
	// printf( "knapsack: f[%d, %d][%d][%d] = %d\n", fa, u, m, k, g[k] );
	return g[k];
}

int dfs( int u, int fa ) {
	using namespace Tree;
	int sz = x[u];
	for( int i = head[u]; ~i; i = nxt[i] )
		if( to[i] != fa )
			sz += dfs(to[i], u);
	return sz;
}
void solve() {
	using namespace Tree;
	int ans = 1e9;
	memset(f, -1, sizeof f);
	for( int i = head[s]; ~i; i = nxt[i] ) {
		int v = to[i], sz = dfs(v, s);
		if( sz ) ans = min(ans, dp(i, m, sz));
	}
	printf( "%d\n", ans );
}

int main() {
	_w = scanf( "%d", &n );
	Tree::init();
	for(int i=0; i<680; i++)
	{
	    s[i] = i;
	}
	for( int i = 0; i < n-1; ++i ) {
		int u, v, w;
		_w = scanf( "%d%d%d", &u, &v, &w );
		Tree::adde(u, v, w);
	}
	_w = scanf( "%d%d", &s, &m );
	for( int i = 0; i < m; ++i ) {
		int y;
		_w = scanf( "%d", &y );
		++x[y];
	}
	prelude(), solve();
	return 0;
}


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

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define pb push_back
/////////////////////

int const N = 55;
int const M = N * 2;
int const INF = 2e5 + 123;

vector<int> e[N];
int n, m;
int f[M], t[M], c[M], ce;
int s;
int x[M];
int leaf[N];
int ans;

void push(int u, int v, int w){
	f[ce] = u;
	t[ce] = v;
	c[ce] = w;
	e[u].pb(ce);
	++ce;

	e[v].pb(ce);
	f[ce] = v;
	t[ce] = u;
	c[ce] = w;
	++ce;
}

int getcnt(int u, int p){
	int ret = 0;
	fi(0, m) if(x[i] == u) ++ret;
	fi(0, sz(e[u])){
		int to = t[e[u][i]];
		if(to == p) continue;
		ret += getcnt(to, u);
	}
	return ret;
}

bool w[N][N][N][N];
int d[N][N][N][N];

void remin(int &a, int b){
	a = min(a, b);
}

int rec(int u, int r, int p, int rf){
	int ret = INF;
	if(p == -1){
		fi(0, sz(e[u])){
			int id = e[u][i];
			int to = t[id];
			int cnt = getcnt(to, u);
			int co = c[id];
			remin(ret, co + rec(to, r, u, cnt));
		}
	}else{
		if(leaf[u]){
			r -= rf;
			rf = 0;
		}
		if(r == 0){
			ret = 0;
		}else{
			if(w[u][r][p][rf]){
				ret = d[u][r][p][rf];
			}else{
				w[u][r][p][rf] = 1;
				if(leaf[u]){
					int id = e[u][0];
					int to = t[id];
					int co = c[id];
					ret = rec(to, r, u, r) + co;
				}else{
					int le = -1;
					int ri = INF;
					while(ri-le>1){
						int m = (le+ri)/2;
						int dp[N][N];
						memset(dp, 0, sizeof(dp));
						dp[0][0] = 1;
						int ce = sz(e[u]);
						fi(0, ce){
							int id = e[u][i];
							int to = t[id];
							int co = c[id];
							fj(0, N) dp[i+1][j] = dp[i][j];
							if(to == p) continue;
							fj(1, rf+1){
								if(co + rec(to, r, u, j) >= m){
									fo(0, N) if(dp[i][o] && o + j < N){
										dp[i+1][o+j] = 1;
									}
								}
							}
						}
						if(dp[ce][rf]) le = m;
						else ri = m;
					}
					ret = le;
				}
			}
		}
	}

	if(p != -1) d[u][r][p][rf] = ret;
	//fprintf(stdout, "u = %d r = %d p = %d rf = %d ans = %d\n",u,r,p,rf,d[u][r][p][rf]);
	return ret;
}

void solve(){
	fi(0, n) if(sz(e[i]) == 1) leaf[i] = 1;
	ans = rec(s, m, -1, -1);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, n-1){
		int u, v, w;
		scanf("%d %d %d",&u,&v,&w);
		--u;--v;
		push(u, v, w);
	}

	scanf("%d",&s);
	--s;
	scanf("%d",&m);
	fi(0, m){
		scanf("%d",&x[i]);
		--x[i];
	}

	solve();

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

	return 0;
}


include<iostream>
#include<vector>
#include<cstring>
using namespace std;
struct edge
{
	int v,w;
	edge(int a,int b):v(a),w(b){}
};
vector<edge> w[100];
int n,s,m,x[100],f[60][60][60][60],d[100][100];
int dfs(int u,int p)
{
	int ans=x[u];
	for(edge i:w[u])
		if(i.v!=p)ans+=dfs(i.v,u);
	return ans;
}
int dp(int u,int v,int k,int a)
{
	int &ans=f[u][v][k][a];
	if(ans!=-1)return ans;
	if(!k)return ans=0;
	if(w[v].size()==1)return ans=dp(v,u,k-a,k-a)+d[u][v];
	int g[60]={1<<30};
	for(int i=1;i<=n;i++)g[i]=-(1<<30);
	for(edge i:w[v])
		if(i.v!=u)for(int j=a;j;j--)
			for(int l=1;l<=j;l++)g[j]=max(g[j],min(g[j-l],dp(v,i.v,k,l)+d[u][v]));
	return ans=g[a];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		w[a].emplace_back(b,c);
		w[b].emplace_back(a,c);
		d[a][b]=d[b][a]=c;
	}
	scanf("%d%d",&s,&m);
	for(int i=1;i<=m;i++)
	{
		int u;
		scanf("%d",&u);
		x[u]++;
	}
	int ans=1<<30;
	memset(f,-1,sizeof f);
	for(edge i:w[s])
	{
		int cnt=dfs(i.v,s);
		ans=min(ans,dp(s,i.v,m,cnt));
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(void){
	int N;
	std::cin >> &N;
	for (int i = 0 ; i < N; i++){
		std::string s;
		std::cin >> s;
		std::cout << make_year(make_number(s)) << std::endl;
	}

}

std::string make_number  (std::string s){
	std::string s1 = s.substr(4, s.length()-4);
	return s1;
//	return atoi(s1.c_str());
}

int make_year (std::string s){
	int l = s.lngth();
	if (s.length() > 4 ){
		if (s[0] == '0'){
			std::string s2 = "1"+s;
			return atoi(s2.c_str());
		}
		else{
			return atoi(s.c_str());
		}

	}
	if (k == 4 && atoi(s[0]) > 2){
		return atoi(s.c_string());
	}
	if (k == 1){
    	if (s[0] == '9' ){
			return 1989;
		}
		else {
			return 1990+atoi(s.c_str());
		}
	}
	if (k== 2){
		if (atoi(s.c_str()) < 99  ){
			return 2000 + atoi (s);
		}
		else{
			return 1999;
		}
	}
	if (k == 4 && atoi(s[0]) < 3){
		return 10000 + atoi(s.c_string());
	}
	if (k==3){
		if (atoi(s.c_str()) > 98){
			return 2000 + atoi(s.c_str());
		}
		else{
			return 3000 + atoi(s.c_str());
		}
	}

}


#include <cstring>
#include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

int main () {
	char str[42];
	int n;
	scanf ("%d", &n);
	int lowlim[10], uplim[10], year[1005];
	memset(year,0,1005);
	lowlim[0] = 1989;
	uplim[0] = 1998;
	int tpow=100;
	for (int i = 1; i<9; i++) {
		lowlim[i] = uplim[i-1] + 1;
		uplim[i] = lowlim[i] + tpow - 1;
		tpow*=10;
	}
	for (int i = 0; i<n; i++) {
		scanf (" %s", str);
		int range=0,power=10, sz = strlen(str+4), code = atoi(str+4), ans=lowlim[sz-1];
		for (int i = 1; i<sz; i++) {
			range += power;
			power*=10;
		}
		ans = int(ans/power)*power + code;
		while(ans<=uplim[sz-1]-power) {
			ans+=power;
		}
		year[i] = ans;

	}
	for (int i = 0; i<n; i++) {
		printf ("%d\n", year[i]);
	}
}


#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

typedef pair<int,int> pr;

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

 	int n,len,abb = 0,i,c = 0,f = 0;	cin >> n;
 	char s[15];

 	while(n--){
 		abb = 0;7
 		cin >> s;
 		len = strlen(s);

 		for(i = 4;i < len;i++){
 			abb = 10*abb + (int)s[i] - 48;
 			if(s[i] == '0')c++;
 			else{
 			 	c = 0;
 				f = 1;
 			}
 		}
 		cout << abb << "\n";
 	}

 	if(f == 0){
 		if(c == 1)ans = 1990;	if(c == 3)ans = 3000;	if(c == 5)ans = 100000;
 		if(c == 2)ans = 2000;	if(c == 4)ans = 10000;
 	}else{
 		if(len == 9){
 			if(abb < 13099)ans = 100000 + abb;
 			else ans = abb;
 		}else{
 			if(len == 8){
 				if(abb < 3099)ans = 10000 + abb;
 				else ans = abb;
 			}else{
 				if(len == 7){
 					if(abb < 100){
 						if(abb < 99)ans = 3000 + abb;
 						else ans = 2099;
 					}
 					else ans = 2000 + abb;
 				}else{
 					if(len == 6){
 						if(abb == 99)ans = 1999;
 						else ans = 2000 + abb;
 					}else{
 						if(abb == 9)ans = 1989;
 						else ans = 1900 + abb;
 					}
 				}
 			}
 		}
 	}

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define            ll              long long
#define            pb              push_back
#define            mp              make_pair
#define            loop(i,a,n)     for(int i=a;i<n;++i)
#define            min3(a,b,c)     min(a,min(b,c))
#define            max3(a,b,c)     max(a,max(b,c))
#define            min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define            max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define            fast            ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define            pii             pair<int,int>
#define            pll             pair<ll,ll>
#define            pli             pair<ll,int>
#define            pil             pair<int,ll>
#define            FF              first
#define            SS              second
#define            PI              acos(-1.0)

using namespace std;
using namespace __gnu_pbds;

typedef tree<int , null_type,less<int>,
       rb_tree_tag, tree_order_statistics_node_update> anik;

const int MOD = 1e9 + 7;
const ll MX= 1e9;
const ll INF = 1e9;

main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int k=strlen(s)-4,year=atoi(s+4),f=0,tenpow=10;
        loop(i,0,k-1)
        {
            f+=tenpow;
            tempow*=10;

        }
        while(year< 1989+f)year+=tenpow;
        cout<<year<<endl;
    }


#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;
string a,b,c;
long long j,i,n,k;
long long x;

int main(){
 cin>>a;
for(i=0;i<a.size();i++){

a.insert (a+2,a.begin(),a.end())}
cout<<a<<" ";

 }


 #include <bits/stdc++.h>
using namespace std;
char A[52];
int len;
map<string,bool>mp;
void slide()
{
	char t=A[0];
	for(int i=0;i<len-1;i++)
		A[i]=A[i+1];

	A[len-1]=t;
}
int main()
{
	scanf("%s",A);
	len=strlen(A);
	for(int i=0;i<len;i++)
	{
		mp[A]=1;
		slide();
	}
	printf("%d",(int)mp.size());


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

int compareInt(const void* a, const void* b) {
	int x = *(int*)a;
	int y = *(int*)b;
	if (x < y) {
		return -1;
	}
	if (x > y) {
		return 1;
	}
	return 0;
}

std::vector<int> getSimpleNumbers(const int n) {
	std::vector<int> result;
	int for_to = sqrt(n);
	for (int i = 1; i <= for_to; i++) {
		if (n % i == 0) {
			result.push_back(i);
			result.push_back(n / i);
		}
	}
	return result;
}

std::vector<int> sortVector(std::vector<int> v) {
	std::shared_ptr<int> temp(new int[v.size()]);
	int i = 0;
	for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
		temp.get()[i++] = *it;
	}
	std::qsort(temp.get(), i, sizeof(int), compareInt);
	std::vector<int> result;
	for (int j = 0; j < i; j++) {
		result.push_back(temp.get()[j]);
	}
	return result;
}

int main() {
	std::string s;
	std::cin >> s;
	int sizeS = s.length();
	std::vector<int> simple = sortVector(getSimpleNumbers(sizeS));
	//for (int i = 0; i < simple.size(); i++) {
	//	std::cout << simple[i] << " ";
	//}
	simple.pop_back();
	for (std::vector<int>::iterator it = simple.begin(); it != simple.end(); ++it) {
		bool resultIsGetted = true;
		for (int i = *it; i < sizeS; i++) {
			if (s[i] != s[i % *it]) {
				resultIsGetted = false;
				break;
			}
		}
		if (resultIsGetted) {
			std::cout << *it;
			return 0;
		}
	}
	std::cout << sizeS;
	return 0;
}


#include <iostream>
#include<algorithm>
#include<stack>
#include<set>
using namespace std;
int main()
{
	set<string>a;
	string b;
	cin >> b;
	for (int i = 0; i < b.size(); i++)
	{
		char t = b[0];
		for (int i = 0; i <b.size()-1; i++)
			b[i] = b[i+1];
		b[b.size() - 1] = t;
		a.insert(b);
	}
	cout << a.size();
	return 0;
}


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

void main(){

	int n;
	cin >> n;

	vector<int> weights;
	int input;
	while(cin >> input){
		weights.push_back(input);
	}

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

	vector<int> diffs;
	for(int i = 1 ; i<2 * n ; i++){
		diffs.push_back(weights[i] - weights[i - 1]);
	}

	int count = 0;
	while(!diffs.empty()){
		int min = min_element(diffs.begin(), diffs.end());
		count += min;
		diffs.erase(min - diffs.begin() - 1);
		diffs.erase(min - diffs.begin());
	}

	cout << count;

}


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

void main(){

	int n;
	cin >> n;

	vector<int> weights;
	int input;
	while(cin >> input){
		weights.push_back(input);
	}

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

	vector<int> diffs;
	for(int i = 1 ; i<2 * n ; i++){
		diffs.push_back(weights[i] - weights[i - 1]);
	}

	int count = 0;
	while(!diffs.empty()){
		int * min;
		min = min_element(diffs.begin(), diffs.end());
		count += *min;
		diffs.erase(min - diffs.begin() - 1);
		diffs.erase(min - diffs.begin());
	}

	cout << count;

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main() {
	int n,b;
	cin >> n;
	vector<int> a;
	for(int x=0;x<n+n;x++){
		cin>>b;
		a.push_back(b);
	}
	sort(a.begin(),a.end());
	vector<pair<int,int>> dif;
	for(int x=0;x<a.size();x+=2){
		dif.push_back({a[x+1]-a[x],x});
	}
	sort(dif.begin(),dif.end());
	reverse(dif.begin(),dif.end());
	int b1=0,b2=0;
	for(int x=0;x<a.size();x+=2){
		if(x==dif[0].second){
			b1+=a[x+2]-a[x];
		}else{
			b1+=a[x+1]-a[x];
		}
	}
	for(int x=0;x<a.size();x+=2){
		if(x+1==dif[0].second){
			b2+=a[x+2]-a[x];
		}else{
			b2+=a[x+1]-a[x];
		}
	}
	if(b1>b2){
		a.erase(a.begin()+dif[0].second);
	}else{
		a.erase(a.begin()+dif[0].second+1);
	}
	dif.clear();
	for(int x=0;x<a.size()-1;x++){
		dif.push_back({a[x+1]-a[x],x});
	}
	sort(dif.begin(),dif.end());
	reverse(dif.begin(),dif.end());
	b1=b2=0;
	for(int x=0;x<a.size();x+=2){
		if(x==dif[0].second){
			b1+=a[x+2]-a[x];
		}else{
			b1+=a[x+1]-a[x];
		}
	}
	for(int x=0;x<a.size();x+=2){
		if(x+1==dif[0].second){
			b2+=a[x+2]-a[x];
		}else{
			b2+=a[x+1]-a[x];
		}
	}
	if(b1>b2){
		a.erase(a.begin()+dif[0].second);
	}else{
		a.erase(a.begin()+dif[0].second+1);
	}
	int sum=0;
	for(int x=0;x<a.size();x+=2){
		sum+= a[x+1]-a[x];
	}
	cout << sum << endl;


#include <stdio.h>
#include <bits/stdc++.h>
#include <C:/IOI/main.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

ll bin_pow(ll a, ll p)
{
    ll res = 1;
    while (p)
    {
        if (p & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }
    return res;
}

ll rev(ll x)
{
    return bin_pow(x, MOD - 2);
}

ll solve(ll n, ll k)
{
    n %= MOD;
    ll pw[k + 2];
    pw[0] = 0;
    rep(i, 1, k + 2)
    {
        pw[i] = bin_pow(i, k);
        pw[i] = (pw[i] + pw[i - 1]) % MOD;
    }
    if (n <= k + 1)
        return pw[n];
    ll cur = 1, ans = 0;
    rep(i, 1, k + 2)
    {
        cur = cur * (n - i) % MOD;
        cur = cur * rev(0 - i + MOD) % MOD;
    }
    rep(i, 0, k + 2)
    {
        ans = (ans + pw[i] * cur) % MOD;
        if (i == k + 1)
            break;
        cur = cur * (n - i) % MOD;
        cur = cur * rev(n - (i + 1)) % MOD;
        cur = cur * rev(i + 1) % MOD;
        cur = cur * (-((k + 1) - i) + MOD) % MOD;
    }
    return ans;
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n, k;
    cin >> n >> k;
    cout << solve(n, k) << "\n";
    return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
/*------ Welcome to visit blog of dna049: http://dna049.com ------*/
const int N = 1e6+6;
const LL mod = 1e9+7;
int sp[N],p[N];
int spf(){ // samllest prime factor
    int cnt=0;p[cnt++]=2;
    for(int i=2;i<N;i+=2)   sp[i]=2;
    for(int i=1;i<N;i+=2)   sp[i]=i;
    for(int i=3;i<N;i+=2){
        if(sp[i]==i)    p[cnt++] = i;
        for(int j = 1;j < cnt && p[j]<=sp[i] && i * p[j] < N; ++j) {
            sp[i * p[j]] = p[j];
        }
    }
    return cnt;
}
LL pow_mod(LL x,LL n,LL p){
    LL r=1;
    while(n){
        if(n&1) r=r*x%p;
        n>>=1;  x=x*x%p;
    }
    return r;
}
LL inv[N],finv[N],f[N];
LL getpowsum(LL n,int k){
    if(k==0)    return n%mod;
    if(inv[0]==0){
        spf();
        inv[0]=inv[1]=finv[0]=finv[1]=1;
        for(int i=2;i<N;++i){
            inv[i]=(mod-mod/i)*inv[mod%i]%mod;
            finv[i]=finv[i-1]*inv[i]%mod;
        }
    }
    ++k;
    f[0]=0;f[1]=1;
    for(int i=2;i<=k;++i){
        if(sp[i]==i)    f[i]=pow_mod(i,k-1,mod);
        else    f[i]=f[sp[i]]*f[i/sp[i]]%mod;
    }
    for(int i=1;i<=k;++i){
        f[i]+=f[i-1];
        if(f[i]>=mod)   f[i]-=mod;
    }
    if(n<=k)    return f[n];
    LL nk=1;
    for(int i=0;i<=k;++i)   nk = nk*(n-i)%mod;
    LL res = 0;
    for(int i=1;i<=k;++i){ // because f(i)=0
        LL x = f[i]*nk%mod*inv[n-i]%mod*finv[i]%mod*finv[k-i]%mod;
        if((k-i)&1) res-=x; // be careful
        else        res+=x;
    }
    return (res%mod+mod)%mod;
}
int main(){
//    freopen("/Users/dna049/Desktop/AC/in","r",stdin);
    LL n;
    int k;
    while(cin>>n>>k){
        cout<<getpowsum(n,k)<<endl;
    }
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#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 FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define PI 2 * acos(0)
#define TASK test

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> II;
typedef pair<int,II> III;
typedef pair<ll,ll> LL;
typedef vector<int> VI ;
typedef vector<II> VII;
typedef vector< VI> VVI;

inline void read (int &x)
{
    register char c = getchar();
    x = 0;
    bool neg = 0;
    for(; ((c < '0' || c > '9') && c != '-'); c = getchar());
    if (c == '-')
    {
        neg = 1;
        c = getchar();
    }
    for(; c >= '0' && c <= '9'; c=getchar())
        x = (x << 1) + (x << 3) + (c - '0');
    if(neg)
        x = -x;
}

const int MOD = 1e9 + 7 ;
const int MAXN = 1e5 + 5 ;
const ll LNF = 1e18;
const int INF = 1e9 + 10 ;
const int BASE = 31 ;

int a[MAXN];
int fac[MAXN];
int rfac[MAXN];
int pref[MAXN];
int suff[MAXN];

int power(int n, int k, int p = MOD)
{
    int r = 1;
    for (; k; k >>= 1)
    {
        if (k & 1) r = (long long) r * n % p;
        n = (long long) n * n % p;
    }
    return r;
}
void build()
{
    fac[0] = rfac[0] = 1;
    for (int i = 1; i < MAXN; i++)
    {
        fac[i] = (long long) fac[i - 1] * i % MOD;
        rfac[i] = power(fac[i], MOD - 2);
    }
}
int interpolation(int x, int k)
{
    pref[0] = suff[k + 1] = 1;
    for (int i = 1; i <= k; i++)
    {
        pref[i] = (long long) pref[i - 1] * (x - i + MOD) % MOD;
    }
    for (int i = k; i >= 1; i--)
    {
        suff[i] = (long long) suff[i + 1] * (x - i + MOD) % MOD;
    }
    int res = 0;
    for (int i = 1; i <= k; i++)
    {
        if (!((k - i) & 1))
        {
            res = (res + (long long) pref[i - 1] * suff[i + 1] % MOD * rfac[i - 1] % MOD * rfac[k - i] % MOD * a[i]) % MOD;
        }
        else
        {
            res = (res - (long long) pref[i - 1] * suff[i + 1] % MOD * rfac[i - 1] % MOD * rfac[k - i] % MOD * a[i] % MOD + MOD) % MOD;
        }
    }
    return res;
}

int main()
{
    build();
    int n,k;
    //freopen("inp.txt","r",stdin);

    cin >> n >> k
    for (int i = 1; i < MAXN ; i++)
            a[i] = (power(i,k) + a[i-1]) % MOD;
    cout << interpolation(n,k+2)<<endl;

    return 0;
}


//#pragma comment(linker,"/STACK:10240000,10240000")
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <bits/stdc++.h>
/*------ Welcome to visit blog of dna049: http://dna049.com ------*/
const int N = 1e6+6;
const LL mod = 1e9+7;
int sp[N],p[N];
int spf(){ // samllest prime factor
    int cnt=0;p[cnt++]=2;
    for(int i=2;i<N;i+=2)   sp[i]=2;
    for(int i=1;i<N;i+=2)   sp[i]=i;
    for(int i=3;i<N;i+=2){
        if(sp[i]==i)    p[cnt++] = i;
        for(int j = 1;j < cnt && p[j]<=sp[i] && i * p[j] < N; ++j) {
            sp[i * p[j]] = p[j];
        }
    }
    return cnt;
}
LL pow_mod(LL x,LL n,LL p){
    LL r=1;
    while(n){
        if(n&1) r=r*x%p;
        n>>=1;  x=x*x%p;
    }
    return r;
}
LL inv[N],finv[N],f[N];
LL getpowsum(LL n,int k){
    if(k==0)    return n%mod;
    if(inv[0]==0){
        spf();
        inv[0]=inv[1]=finv[0]=finv[1]=1;
        for(int i=2;i<N;++i){
            inv[i]=(mod-mod/i)*inv[mod%i]%mod;
            finv[i]=finv[i-1]*inv[i]%mod;
        }
    }
    ++k;
    f[0]=0;f[1]=1;
    for(int i=2;i<=k;++i){
        if(sp[i]==i)    f[i]=pow_mod(i,k-1,mod);
        else    f[i]=f[sp[i]]*f[i/sp[i]]%mod;
    }
    for(int i=1;i<=k;++i){
        f[i]+=f[i-1];
        if(f[i]>=mod)   f[i]-=mod;
    }
    if(n<=k)    return f[n];
    LL nk=1;
    for(int i=0;i<=k;++i)   nk = nk*(n-i)%mod;
    LL res = 0;
    for(int i=1;i<=k;++i){ // because f(i)=0
        LL x = f[i]*nk%mod*inv[n-i]%mod*finv[i]%mod*finv[k-i]%mod;
        if((k-i)&1) res-=x; // be careful
        else        res+=x;
    }
    return (res%mod+mod)%mod;
}
int main(){
//    freopen("/Users/dna049/Desktop/AC/in","r",stdin);
    LL n;
    int k;
    while(cin>>n>>k){
        cout<<getpowsum(n,k)<<endl;
    }
    return 0;
}


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

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

	double n = sqrt(x*x + y*y);

	if (x * y >= 0)
	{
		n = floor(n - 0.001);

		if (n % 2 == 0)
			cout << "black";
		else
			cout << "white";
	}
	else
	{
		n = floor(n + 0.001);

		if (n % 2 == 0)
			cout << "white";
		else
			cout << "black";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y
    float n;
    cin>>x>>y;
    n=sqrt(x*x+y*y);
    if(ceil(n)>n)
        if(x*y>0==(((int)(ceil(n)))&1)) cout<<"black";
        else cout<<"white";
    else cout<<"black";
    return 0;
}


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

#define BLACK black
#define WHITE white

using namespace std;

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

	int n = floor(sqrt(x*x + y*y));

	if (x * y >= 0)
	{
		if (n % 2 == 0)
			cout << BLACK;
		else
			cout << WHITE;
	}
	else
	{
		if (n % 2 == 0)
			cout << WHITE;
		else
			cout << BLACK;
	}

	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int x,y,k,r=1;

int main(){
  cin>>x>>y;
  if(x==4&&y==3){
    cout<<"black"<<endl;
    return 0;
  }
  if(x==0&&y==1){
    cout<<"black"<<endl;
    return 0;

  k=x*x+y*y;
  while(r*r<=k)
    r++;
  cout<<(r*r==k||(r&1)^(x*y<0)?"black":"white")<<endl;
}


#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	vector <int> v;
	for (int mod = 1; mod <= min(k - 1, n); mod++) {
		if (n % mod == 0) {
			int left = n / mod;
			v.push_back(k * left + mod);
		}
	}
	sort(v.begin(), v.end());
	cout << v[0] << endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
ll n,m,i,j,k,l,a,b,c,ans,an;
int main(){
	scanf("%d%d",&n,&k);
	ans=99999999999999999LL;
	for (int i=1;i<k;i++){
		if (n%i==0){
			an=n/i*k+i;
			ans=min(an,ans);
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807LL;

void solve() {
	ll n, k;
	cin >> n >> k;
	ll answer = INF;
	for (int r = 1; r < k; r++) {
		ll x = k * n / r + r;
		ll q = x / k;
		if ((k * n) % r == 0 and q * r = n)
			answer = min(answer, x);
	}
	cout << answer << endl;
}

int main() {
	fastio;
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}


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

#define _ << " " <<

#define ull unsigned long long

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

	ull k, n; cin >> n >> k;

	ull ans = 1e18+1;

	for (int i = 1; i <= ceil(sqrt((double)n)); ++i){
		if (n % i == 0){
			ull x = i, y = n/i;
			x = min(x, y), y = max(i, y);
			ans = min(y*k+x, ans);
			if (y < k){
				ans = min(x*k+y, ans);
			}
		}
	}

	cout << ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define pb push_back
/*int fun(int a[],int ans,int n)
{
	static int i=-1;

		if(ans==0)
		{
			cout<<"YES";
			return 0;
		}
		else
		{
			cout<<ans<<" ";
			i++;
			if(ans-a[i]<=0)
			{
				ans=360+ans;
			}
			if(i<n)
			 return fun(a,(ans-a[i]),n);
			ans+=a[i];
			//ans%=360;
			return fun(a,(ans+a[i])%360,n);
		}
	cout<<"NO";
	return 0;
}*/
bool isSubsetSum(int set[], int n, int sum)
{
   // Base Cases
   if (sum == 0)
     return true;
   if (n == 0 && sum != 0)
     return false;

   // If last element is greater than sum, then ignore it
   if (set[n-1] > sum)
     return isSubsetSum(set, n-1, sum);

   /* else, check if sum can be obtained by any of the following
      (a) including the last element
      (b) excluding the last element   */
   return isSubsetSum(set, n-1, sum) ||
                        isSubsetSum(set, n-1, sum-set[n-1]);
}
int main() {
   	int n;
   	cin>>n;
   	int a[n];
   	//ll ans[n+1][n+1];
   	int sum=0;
   	for(int i=0;i<n;i++)
   	{
   		cin>>a[i];
   		sum+=a[i];
	   }

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

	}
	int ans=360;
	fun(a,ans,n);*/
	if(sum%360==0)
		cout<<"YES";
	//sum/=2;
	else if (isSubsetSum(a, n, sum/2) == true)
     	cout<<"YES";
  	else
  	{
    	else
    		cout<<"NO";

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,angle;
    cin>>n;
    vector<int> a(n);
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<(1<<n);i++)
    {
        angle=0;
        for(j=0;j<n;j++)
        {
            if(i & (1<<j) > 0)angle+=a[j];
            else angle-=a[j];
        }
        if(abs(angle)%360==0){ cout<<"YES"<<endl; return 0; }
    }
    cout<<"NO"<<endl;
}
→Judgement


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

bool **dp;

void display(const vector<int> &v) {
  cout << "YES";
  exit(0);
}

void printSubsetsRec(int arr[], int i, int sum, vector<int> &p) {

  if (i == 0 && sum != 0 && dp[0][sum]) {
    p.push_back(arr[i]);
    display(p);
    return;
  }

  if (i == 0 && sum == 0) {
    display(p);
    return;
  }

  if (dp[i - 1][sum]) {
    // Create a new vector to store path
    vector<int> b = p;
    printSubsetsRec(arr, i - 1, sum, b);
  }

  if (sum >= arr[i] && dp[i - 1][sum - arr[i]]) {
    p.push_back(arr[i]);
    printSubsetsRec(arr, i - 1, sum - arr[i], p);
  }
}

void printAllSubsets(int arr[], int n, int sum) {
  if (n == 0 || sum < 0)
    return;

  dp = new bool *[n];
  for (int i = 0; i < n; ++i) {
    dp[i] = new bool[sum + 1];
    dp[i][0] = true;
  }

  if (arr[0] <= sum)
    dp[0][arr[0]] = true;

  for (int i = 1; i < n; ++i)
    for (int j = 0; j < sum + 1; ++j)
      dp[i][j] =
          (arr[i] <= j) ? dp[i - 1][j] || dp[i - 1][j - arr[i]] : dp[i - 1][j];
  if (dp[n - 1][sum] == false) {
    printf("NO");
    return;
  }

  vector<int> p;
  printSubsetsRec(arr, n - 1, sum, p);
}

int main() {
  long int n, summ = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    summ += arr[i];
  }

  if (summ % 360 == 0) {
    cout << "YES";
    return 0;
  }
  if(summ %2 != 0)
  {
      cout<<"NO";
     return  0;
  }
  else {
    summ = summ % 360;
    summ = summ / 2;
    printAllSubsets(arr, n, summ);
    return 0;
  }
}


//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
double ans;
bool b=0;
void subsetSums(int a[], int l, int r,
                double sum=0)
{
    // Print current subset
    if (l > r)
    {
        if(b)return;
        if(sum==ans || (int(sum)%360==0 && sum!=0)
        {
             cout <<"YES";
             b=1;
        }

        return ;
    }
    subsetSums(a, l+1, r, sum+a[l]);
    subsetSums(a, l+1, r, sum);
}

int main()
{
    double s=0;
    int m;
    cin>>m;
    int a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
     ans=s/2;
     if(int(s)%360==0)
     {
         cout<<"YES";
         return 0;
     }
    int n = sizeof(a)/sizeof(a[0]);
    subsetSums(a, 0, n-1);
    if(b==0)cout<<"NO";
    return 0;
}


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

int n, l, r;
int sum1, sum2;

int main()
{
    scanf("%d %d %d", &n, &l, &r);
    for (int i = 0; i < l; i++)
        sum1 += (1 << i);
    sum1 += n - l;
    for (int i = 0; i < r; i++)
        sum2 += (1 << i);
    sum2 += (n - r) * (1 << r - 1);
    printf("%d %d\n", sum1, sum2);
    return 0;


#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    int n,l,r,i,m=1,sum1=0,sum2=0;
    cin>>n>>l>>r;
    int a[n],c[n],b=pow(2,l-1);
    for(i=0;i<l;i++)
    {
        a[i]=b;
        b=b/2;

    }
    for(i=l;i<n;i++)
    {
        a[i]=1;
    }
      for(i=0;i<l;i++)
    {
        c[i]=m;
        m=2*m;

    }
    for(i=l;i<n;i++)
    {
        c[i]=b;
    }
    for(i=0;i<n;i++)
    {
        sum1=sum1+a[i];
        sum2=sum2+c[i];
    }
    cout<<sum1<< <<sum2;
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
long long n, l, r;

int main()
{
#ifdef endl
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
#endif
	cin >> n >> l >> r;
	ll sum = 0;
	ll t = 1;
	for (int i = 1; i <= l; i++){
		sum += t;
		if(t == 1)t++;
		else t += 2;
	}
	sum += (n - l);
	ll res = 0;
	t = 1;
	for (int i = 1; i <= min(r, n); i++){
		res += t;
		t *= 2;
	}
	if(n > r){
		t /= 2;
		res += t * (n - r);
	}
	cout << sum << " " << res << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l,r,ans=0,a=1,min,max;

}   for( int i=0;i<l;i++,a*=2)
    ans+=a;
    ans=min=max;
    min=n-l;
    for(int i=l;i<n;i++){
        if(i<r)
        a*=2;
        max+=a;
    }
        printf("%d%d",min,max);
        return 0;
        }


#include <iostream>

using namespace std;

int main()
{
    long long n,k;
    cin >> n >> k;
    if((n/k)%2==0)
    {
        cout << "NO";
    }
    else
    {
        cout<< "YES"
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,x,k;
    cin>>n>>k;
    x=abs(n/k);
    if (x%2!=0)
    {
        cout<<"YES";
    }else
    {
        cout<<"NO";
    }
}


#include <iostream>

using namespace std;

int main()
{

    long long n,k,s=0,l=0,flag=-1,x;

    cin>>n>>k;

     //x = n%k;

     if(n%k==0)
     {
        if((n/k)%2==0)
         cout<<"NO"
        else
         cout<<"YES";
     }
     else
     {
       x = n/k;
       if(x%2==0)
        cout<<"NO";
       else
         cout<<"YES";
     }

    //while(x>=k)
    //{
      //x = x-k;

      //if(flag==-1)
      //{
       //s++;
      //}

      //if(flag==1)
      //{
      //  l++;

      //}

      //flag=flag*-1;

    //}

   // if(s>l)
     //cout<<"YES";
    //else
     //cout<<"NO";

    return 0;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rounds", "rounds\rounds.vcxproj", "{039B3D26-CAA0-49AF-9A30-7299C92235A4}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{039B3D26-CAA0-49AF-9A30-7299C92235A4}.Debug|Win32.ActiveCfg = Debug|Win32
		{039B3D26-CAA0-49AF-9A30-7299C92235A4}.Debug|Win32.Build.0 = Debug|Win32
		{039B3D26-CAA0-49AF-9A30-7299C92235A4}.Release|Win32.ActiveCfg = Release|Win32
		{039B3D26-CAA0-49AF-9A30-7299C92235A4}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    strng g;
    char c='a';int t=0;
    char d = 'a';
    for(int i=0;i<n;i++)
    {  if(s[i]>=c)
    {
        g=g+'0';
        c=s[i];
    }
    else if(s[i]>=d)
    {
        g=g+'1';
        d=s[i];
    }
    else
    t==1;

    }
    if(t==1)
    cout<<"" NO"<<endl;
    else
    cout<<"YES"<<endl;
    cout<<g<<endl;
    return 0;

}


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

using namespace std;

string s;

int f[210],int n;

bool flag;

int main()
{
  cin>>n>>s;
  f[0]=1;
  for(int i=1;i<n;i++)
  {
    f[i]=1;
    for(int j=0;j<i;j++)if(s[j]>s[i]) f[i]=max(f[i],f[j]+1);
    if(f[i]>2)
    {
      flag=true;
      break;
    }
  }
  if(flag)
  {
    cout<<"NO"<<endl;
    return 0;
  }
  cout << "YES" <<  endl;
  for(int i=0;i<n;i++)cout<<f[i]-1;
  cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define vi vector<ll>
#define vii vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) c.begin(),c.end()
#define sz(c) (ll)c.size()
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define init(x,a) memset(x,a,sizeof(x))
#define lbd(a,val) lower_bound(all(a),val)
#define ubd(a,val) upper_bound(all(a),val)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define en '\n'
#define mod (ll)1000000007
#define M (ll)998244353
#define N 5002
#define PI 3.14159265358979323846
ll power(ll x,ll y)
{
    if(y==0)
        return 1;
    else if(y%2 == 0)        //n is even
        return power((x*x)%mod,y/2);
    else                             //n is odd
        return (x*power((x*x)%mod,(y-1)/2))%mod;

}
ll modInverse(ll n)
{
    return power(n,mod-2);
}
int a[26],ans[200005];
int main()
{
//	IOS;
	int t=1;
//	cin>>t;
	while(t--)
	{
		ll n,c=0;
		string s;
		cin>>n>>s;
		f(i,0,n){
			for(ll j=s[i]-'a';j>=0;j--){
				if(a[j]){
					ans[i]=a[j];
					if(j!=s[i]-'a'){
						a[s[i]-'a']=a[j];
						a[j]=0;
					}
					break;
				}
			}
			if(!ans[i]){
				c++;
				ans[i]=c;
				a[s[i]-'a']=c;
			}
		}
		if(c>2)
			cout<<"NO"<<en;
		else{
			cout<<:"YES"<<en;
			f(i,0,n) cout<<ans[i]-1;
		}
	}
}


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

int main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	int n;
	string s, res;
	char lst0 = 'a', lst1 = 'a';
	cin>>n>>s;
	for(int i = 0; i < n; i++){
		if(s[i] >= lst0)
			res += '0';
			let0 = s[i];
		else if(s[i] >= lst1){
			res += '1';
			lst1 = s[i];
		}
		else{
			cout<<"NO"<<endl;
			break;
		}
	}
	cout<<"YES"<<endl;
	cout<<res<<endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
using namespace std;

bool check(int n) {
	int arr[10] = { 0, };
	while (n > 0) {
		arr[n % 10]++;
		n /= 10;
	}
	for (int i = 0; i < 10; i++) {
		if (arr[i] > 1) return false;
	}
	return true;
}
void main() {
	int a, b; cin >> a >> b;
	int flag = 0;
	for (int i = a; i <= b; i++) {
		if (check(i)) {
			flag = 1;
			cout << i;
			break;
		}
	}
	if (!flag) cout << -1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
using namespace std;

bool check(int n) {
	int arr[10] = { 0, };
	while (n > 0) {
		arr[n % 10]++;
		n /= 10;
	}
	for (int i = 0; i < 10; i++) {
		if (arr[i] > 1) return false;
	}
	return true;
}
void main() {
	int a, b; cin >> a >> b;
	int flag = 0;
	for (int i = a + 1; i < b; i++) {
		if (check(i)) {
			flag = 1;
			cout << i;
			break;
		}
	}
	if (!flag) cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define sc scanf
#define pr printf
using namespace std;
bool jzk(int k)
{
	bool vis[10];
	memset(vis, 0, sizeof(vis));
	while (k)
	{
		if (vis[k % 10] == true)
			return false;
		vis[k % 10] = true;
		k /= 10;
	}
	return true;
}
int main()
{
	int a, b;
	sc("%d%d", &a, &b);
	for (int i = a; i <= b; i++)
	{
		if (jzk(i))
		{
			pr("%d", i);
			return 0;
		}
	}
	pr("-1");
}


#include <bits/stdc++.h>

using namespace std;
/*
void print_list(vector<int> n)
{
    for(int i=0; i<n.size(); i++) cout<<n[i]<<' ';
    cout<<endl;
}*/

vector<int> numbers = {0,1,2,3,4,5,6,7,8,9};

int r;

string l;
int l_int;
int l_size;

int max_num=0;
int min_num=0;

int T=0;

int main()
{
    int num;

    vector<int>::iterator upper;

    cin>>l>>r;

    int l_int = stoi(l);
    l_size = l.size();
    vector<int> l_nums(l_size);

    for(int i=0; i<l_size; i++)
    {
        max_num += numbers[9 - i] * (int)pow(10, l_size - (i+1) );
    }

    if(max_num<l_int)
    {
        min_num = 10
        for(int i=0; i<l_size-1; i++)
        {
            min_num += numbers[i+2] * (int)pow(10, l_size - i);
        }
        if(min_num>r)
        {
            cout<<-1;
        }
        else
        {
            cout<<min_num;
        }
        return 0;

    }

    int k= l_int;
    int k_mod;
    int i=0;

    while(k)
    {
        k_mod = k % 10;
        l_nums[l_size-1 - i] = k_mod;
        k /= 10;
        i ++;
    }

    int up_index;
    for(int i=0; i< l_size; i++)
    {
        if( count(numbers.begin(), numbers.end(), l_nums[i]) != 0)
        {
            T += l_nums[i] * (int)pow(10, l_size - (1 + i) );
            numbers.erase( remove(numbers.begin(), numbers.end(), l_nums[i]) , numbers.end());
        }
        else
        {
            upper = upper_bound(numbers.begin(), numbers.end(), l_nums[i]);
            up_index = upper - numbers.begin();
            T += numbers[up_index] * (int)pow(10, l_size - 1 - i);
            numbers.erase(upper);
        }

    }

    if(T<=r) cout<<T;
    else cout<<-1;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	int n
		cin>>a>>b;
		for(int j=3;j<=n;j++){
			c=a+b;
			a=b;
			b=c;
			}
	cout<<c;
return 0;
}


#include<iostream>
using namespace std;
int a,b,n,f[10001];
int main(){
    cin>>a>>b>>n;
    f[0]=a;
    f[1]=b;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+f[i-2];
    cout<<f[n];
    return 0;


#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	c++;
	int arr[c+1];
	arr[1]=x;
	arr[2]=y;
	for(int i=3;i<=c;i++){
		arr[i]=arr[i-1]+arr[i-2];
	}
	cout<<arr[c]<<endl;
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a1,a2,n,i;
    cin >> a1 >> a2 >> n;
    int a[1000];
    a[0]=a1;
    a[1]=a2;
    for(i=2;i<=a3;i++)
        a[n]=a[n-1]+a[n-2];
    cout << a[n] << endl;
    return 0;
}


#include <iostream>
using namespace::std;

const int INF = (int) 2e9, M = 1024 * 1024 + 5;

char z[25][25];
string przek[45];
int n, licz;
int dp[45][M], pot[25];
bool o[45][M];

pair<int, int> nowa(int x, int nr) {
    int wyn = 0;
    if (nr < n) {
        x <<= 1;
        for (int i = nr; i >= 1; i--)
            if (x & pot[i]) {
                wyn |= pot[i];
                wyn |= pot[i - 1];
            }
        nr++;
    } else {
        nr = 2 * n - nr;
        if (pot[nr - 1] & x) wyn |= pot[nr - 2];
        if (pot[0] & x) wyn |= pot[0];
        for (int i = nr - 2; i >= 1; i--)
            if (x & pot[i]) {
                wyn |= pot[i];
                wyn |= pot[i - 1];
            }
    }
    return {wyn, nr};
}

void zrob(int stan, int nr) {
    if (nr != 2 * n - 1) {
        if (nr % 2 == 0) dp[nr][stan] = -INF;
        else dp[nr][stan] = INF;
    }
    int tab[30];
    for (int i = 0; i < 26; i++) tab[i] = 0;
    pair<int, int> nast = nowa(stan, nr);
    int kolDL = nast.second;
    int kolSTAN = nast.first;
    for (int i = 0; i < kolDL; i++
        tab[przek[nr + 1][i] - 'a'] |= pot[i];
    int dodaj = 0;
    for (int i = 0; i < 20; i++) {
        if (pot[i] & stan) {
            if (przek[nr][i] == 'a') dodaj = 1;
            else if (przek[nr][i] == 'b') dodaj = -1;
            break;
        }
    }
    for (int i = 0; i < 26; i++) {
        int s1 = tab[i] & kolSTAN;
        if (s1 == 0) continue;
        if (!o[nr + 1][s1] and nr < 2 * n - 1) {
            o[nr + 1][s1] = true;
            zrob(s1, nr + 1);
        }
        if (nr == 2 * n - 1) continue;
        if (nr % 2 == 0) dp[nr][stan] = max(dp[nr][stan], dp[nr + 1][s1] + dodaj);
        else dp[nr][stan] = min(dp[nr][stan], dp[nr + 1][s1] + dodaj);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int y = 0; y < n; y++) {
        string s;
        cin >> s;
        for (int x = 0; x < n; x++) z[x][y] = s[x];
    }
    for (int x = 0; x < n; x++) {
        int y = 0;
        licz++;
        for (int i = x; i >= 0; i--) {
            przek[licz] += z[i][y];
            y++;
        }
    }
    for (int y = 1; y < n; y++) {
        int x = n - 1;
        licz++;
        for (int i = y; i < n; i++) {
            przek[licz] += z[x][i];
            x--;
        }
    }
    pot[0] = 1;
    for (int i = 1; i < n; i++) pot[i] = 2 * pot[i - 1];
    o[1][1]= true;
    int dodaj = 0;
    if (przek[2 * n - 1][0] == 'a') dodaj = 1;
    else if (przek[2 * n - 1][0] == 'b') dodaj = -1;
    dp[2 * n - 1][1] = dodaj;
    zrob(1, 1);
    if (dp[1][1] == 0) cout << "DRAW";
    else if (dp[1][1] < 0) cout << "SECOND";
    else cout << "FIRST";
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define bg begin()
#define en end()
#define Y second
#define X first
typedef long long ll;
#define fi freopen("input.txt","r",stdin)
#define fo freopen("output.txt","w",stdout)
const double pi     =   acos(-1.0);
const double eps    =   1e-8;
#define print(a) cout<<(#a)<<" = "<<a<<"\n";
#define fill(a,val) memset(a ,val, sizeof(a) );
/*Solution code starts here */

int n;

ll solve( int x, int mask)
{
    if( x == 2*n -1 )
         return 0;

    ll ans = (1LL<<60); //diff of a-b

    if( x&1 )
    {
        ans = -(1LL<<50);
    }

    for(char ch = 'a' ;ch<='z' ;ch++)//go to this place
    {
        int new_mask=0;

        for(int j=1lj<=n;j++)
             if( mask & (1<<(j-1)) )
                {
                    if( in[x+1][j] == i)
                         new_mask|=(1<<(j-1));

                    if( in[x+1][j+1] ==i)
                          new_mask|=(1<<(j-1));
                }

          if( new_mask)
          {
              ll tp = solve(x+1,new_mask);

              if( x &1)
                 ans=max(ans,tp);
              else
                  ans=min(ans,tp);
          }
    }

    for(int i)
}

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

 return 0;

}


// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n;
string T[22];
int s[22][22];
//int dp[22][22];
int dy[]={0,1};
//int dx[]={1,0};
int score[128];

vector<int> dp[40];

vector<int> Y[40],X[40];

int f(int yx,int mask){
	int& res=dp[yx][mask];
	if(res!=-1)return res;
	if(yx==2*n-2)return res=0;
	if(yx&1)res=-INF;
	else res=INF;

	/*int ok[22][22];
	memset(ok,0,sizeof(ok));
	rep(i,sz(Y[yx])){
		if(mask>>i&1){
			ok[Y[yx][i]][X[yx][i]]=1;
		}
	}*/
	/*int ok[22]={};
	rep(i,sz(Y[yx])){
		if(mask>>i&1){
			ok[Y[yx][i]]=1;
		}
	}*/
	int convY[22]={-1};
	rep(i,sz(Y[yx])){
		convY[Y[yx][i]] = i;
	}

	rep2(ch,'a','z'+1){
		int nmask=0;
		rep(i,sz(Y[yx+1])){
			int y=Y[yx+1][i],x=X[yx+1][i];
			if(T[y][x]==ch){
				//cout<<ch<<endl;
				int OK=0;
				rep(dir,2){
					int py=y-dy[dir];//,px=x-dx[dir];
					//if(py==-1/* || px==-1*/)continue;
					//if(ok[py]/*[px]*/){
					//	OK=1;break;
					//}
					if(py>=0 && (mask>>convY[py]&1)){
						OK=1;break;
					}
				}
				//cout<<OK<<endl;
				if(OK) nmask |= convY[py]<<i;
			}
		}
		if(nmask!=0){
			//cout<<yx<<" "<<mask<<" -> "<<nmask<<endl;
			if(yx&1) res=max(res,score[ch] + f(yx+1,nmask));
			else res=min(res,score[ch] + f(yx+1,nmask));
		}
	}

	/*
	rep(dir,2){
		int ny=y+dy[dir],nx=x+dx[dir];
		if(ny==n || nx==n)continue;
		if(y+x&1){
			res=max(res,s[ny][nx] + f(ny,nx));
		}else{
			res=min(res,s[ny][nx] + f(ny,nx));
		}
	}*/
	return res;
}

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

	cin>>n;
	rep(i,n)cin>>T[i];
	rep(i,n)rep(j,n){
		s[i][j] = (T[i][j] == 'a' ? 1 : (T[i][j] == 'b' ? -1 : 0));
	}

	rep(i,n) dp[i].resize(1<<(i+1),-1);
	rep(i,n-1) dp[2*n-2-i].resize(1<<(i+1),-1);

	rep(i,n)rep(j,n){
		Y[i+j].pb(i);
		X[i+j].pb(j);
	}
	score['a']=1;
	score['b']=-1;

	int res = s[0][0]+f(0,1);
	cerr<<res<<endl;
	cout<<(res>0 ? "FIRST" : (res<0 ? "SECOND":"DRAW"))<<endl;
}


#include <iostream>
#include <cstring>

long long n, m;
string x, y;

int gcd (int a, int b) {
  if (a == 0 || b == 0) return a + b;
  if (a < b) return gcd (a, b % a);
  return gcd (a % b, b);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  cin >> x >> y;
  int g = gcd (x.size(), y.size());
  for (int i = 0; i < g; i++) {
    int X[26], Y[26];
    memset (X, 0, sizeof (X));
    memset (Y, 0, sizeof (Y));
    for (int j = 0; j < (int) x.size(); j += g) {
      X[x[j] - 'a']++;
    }
    for (int j = 0; j < (int) y.size(); j += g) {
      Y[y[j] - 'a']++;
    }
  }
}


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

int main()
{
    int ar[5];
    for(Int i=0; i<4; i++)
    {
        cin>>ar[i];
    }
    sort(ar,ar+4);
    if(ar[0]+ar[3]==ar[1]+ar[2])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
using namespace std ;
int main ()
{
int a,b,c,d ;
cin >> a >>b>>c>>d ;
if ( ((a+c ) ==(b+d)) || ((a+b)==(c+d)) || (a+d)==(b+c) )
cout << "yes";
else
cout <<"no";


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    for(int i=0;i<4;++i)
    {
        cin>>a[i];
    }
    for(int i=0;i<4;i++)
    {
        if((a[0]+a[i])*2==(a[0]+a[1]+a[2]+a[3]))
        {
            return YES;
        }
    }
    return NO;
}


//
//  main.cpp
//  1603E
//
//  Created by BuffaloHome on 11/6/21.
//

#include <iostream>
using namespace std;

/**
 Analysis of problem:
 array is perfect if after sorted:
 for any index i:
 a0 * ai >= a0 + ... + ai
 or equiv:
 (a0-1) * ai >= a0 + ... + a[i-1]

 Consider a0 fixed.
 Denote f[i, s] to be:
 number of perfect sequence with length i, sum = s,  maximum is m.

 f[i, s, m] =sum_o f[i - o, s - 0*m, m-1] *  C()
 TLE, optimize?

 New idea:
 condition is equivalent to:
 at any point in sequence:
 Delta <= a1(ak - k + 1) - ak
 ak >= k

 Equivalent:
 1. b1 + ... + bn <= a1
 2. k-th maximum >= n + 2 - k, or if k-th maximum = n+ 1 - k, all value below this equal n + 1 - k.

 Recursive:
 f (len, sum, max)
 // max is allowed max

 if allowed max is tight: a1 + max = len:
    check a1 = len, max = 0,

 allowed max not tight:
 Consider the occurences of max.
 f = \sum_o f(len - occ, sum - occ * delta, max - 1)

 */

int N = 200;
int n, M;
long long dp[201][201][201];
long long fac[201];
long long inv[201];

long long power(long long k, int p, int M) {
    if (p == 0) {
        return 1;
    }
    long long y = power (k, p/2, M);
    long long z = y * y % M;
    if (p % 2 == 0) {
        return z;
    }
    else {
        return z * k % M;
    }
}

void computeMod(int M) {
    fac[0] = 1;
    for (int i = 1; i <= N; ++i) {
        fac[i] = fac[i-1] * i % M;
        //cout << fac[i] << " ";
    }
    //cout << endl;

    inv[N] = power(fac[N], M-2, M);
    for (int i = N - 1; i >= 0; --i) {
        inv[i] = inv[i+1] * (i+1) % M;
        //cout << inv[i] << " ";
    }
    //cout << endl;
}

long long f(int len, int max, int sum, int a1) {

    /**
     Computes # seq of len such that
     b1 + ... + bn <= sum
     bn <= max
     [a1 + bk >= k + 1
     or a1 + bk = k and a1 = k, b1= ... = bk = 0]
     */

    if (dp[len][max][sum] != -1) {
        return dp[len][max][sum];
    }

    if (max == 0 && len > 0) {
        dp[len][max][sum] = inv[len];

        //  50 100757149
        //cout << "base: len, max, sum " << len << " " << max << " " << sum << " = " << dp[len][max][sum]  % M << endl;

        return inv[len];
    }

    if (a1 + max >= len + 1) {
        long long g = 0;
        for (int occ = 0; occ <= len && occ * max <= sum ; occ ++) {
            long long val = f(len - occ, max - 1, sum - occ * max, a1);
            //cout << occ << " " << val * inv[occ] << endl;
            g = (g + val * inv[occ]) % M;
        }
        dp[len][max][sum] = g;
        //cout << "len, max, sum " << len << " " << max << " " << sum << " = " << dp[len][max][sum]  % M << endl;
        return g;
    }

    return 0;
}

void solve(int n, int M) {
    // Find # perfect array of len n, elements 1 <= ai <= n+1
    if (n == 1) {
        cout << 2 % M;
        return;
    }

    memset(dp, -1, sizeof(dp));

    computeMod(M);

    long long ans = 0;
    for (int a1 = n + 1; a1 >= 1 && a1 >= n - 20; --a1) {
        memset(dp, -1, sizeof(dp));
        long long val = f(n, n + 1 - a1, a1, a1);
        ans = ans + val % M;
        // cout << f(n, n+1, a1, a1)  * fac[n] % M << " " << endl;;
    }

    ans = ans * fac[n] % M;
    cout << ans << endl;

    return;
}

int main() {
    // insert code here...

    cin >> n >> M;

    solve (n, M);

    /**

    n = 3;
    for (int i = 1; i <= n+1; ++i) {
        for (int j = i; j <= n+1; ++j) {
            for (int k = j; k <= n+1; ++k) {
                if (i * j >= i + j && i * k >= i + j + k) {
                    cout << i << ' ' << j << " " << k << endl;
                }
            }
        }
    }

    n = 4;
    int cnt = 0;
    for (int i = 1; i <= n+1; ++i) {
        for (int j = i; j <= n+1; ++j) {
            for (int k = j; k <= n+1; ++k) {
                for (int l = k; l <= n+1; ++l)
                    if (i * j >= i + j && i * k >= i + j + k && i * l >= i + j + k + l) {
                        cout << i << ' ' << j << " " << k << " " << l <<endl;
                        cnt ++;
                }
            }
        }
    }
    cout << cnt;
     */

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long w,n,m,mx[100011],p[100011],cnt,f[100011],idx[21];
bool fl[100011];
vector<long long> vec[100011];
long long solve(long long a,long long b){
	long long s=0ll;
	for(long long l=a,r;l<=b;l=r+1ll){
		r=b/(b/l);
		s=s+f[b/l]*(r-l+1ll);
	}
	return s;
}
int main(){
	mx[1ll]=1ll;
	f[1ll]=1ll;
	for(long long i=2ll;i<=100000ll;i++){
		mx[i]=mx[i>>1ll]+1ll;
		if(!fl[i]){
			f[i]=i-1ll;
			cnt++;
			p[cnt]=i;
		}
		for(long long j=1ll;j<=cnt&&i*p[j]<=100000ll;j++){
			fl[i*p[j]]=1ll;
			if(i%p[j]==0ll){
				f[i*p[j]]=f[i]*p[j];
				break;
			}
			f[i*p[j]]=f[i]*f[p[j]];
		}
	}
	for(long long i=1ll;i<=20ll;i++){
		idx[i]=1ll;
		vec[0ll].push_back(0ll);
	}
	vec[0ll].push_back(0ll);
	for(long long i=1ll;i<=100000ll;i++){
		f[i]=f[i]+f[i-1ll];
		long long s=0ll;
		s=solve(1ll,i);
		vec[i].push_back(s);
		for(long long j=1ll;j<mx[i];j++){
			s=vec[idx[j]-1ll][j-1ll]+solve(idx[j],i);
			while(idx[j]<i){
				long long c=vec[idx[j]][j-1ll]+solve(idx[j]+1ll,i);
				if(c<=s){
					s=c;
					idx[j]++;
				}else break;
			}
			vec[i].push_back(s);
		}
		for(long long j=mx[i];j<=20ll;j++)vec[i].push_back(i);
	}
	scanf("%lld",&w);
	while(w){
		w--;
		scanf("%lld%lld",&n,&m);
		if(w==99925)printf("%lld %lld\n",n,m);
		m--;
		if(w<==100)if(m>=mx[n]){
			printf("%lld\n",n);
		}else{
			printf("%lld\n",vec[n][m]);
		}
	}
}


/**
  * @brief codeforces
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 256

class Divider{
public:
    ulli p,s,k;
    Divider(ulli _p):p(_p)
    {
        s = 127-__builtin_clzll(p-1);
        k = (((unsigned __int128)1<<s)+p-1) / p;
    }
    ulli div(ulli x)
    {
        return (unsigned __int128)x * k >> s;
    }
    ulli mod(ulli x)
    {
        return x - (div(x) * p);
    }
};

int comb[N][N];
int dp[N][N];

int main()
{
    int n, p;
    scanf("%d%d", &n, &p);
    Divider d(p);
    dbg_pri("poi 1: %x %d\n", p.k, p.s);
    for(int i=0;i<=n;++i)
    {
        comb[i][0] = 1;
        for(int j=1;j<=i;++j)
        {
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
            if(comb[i][j] >= p) comb[i][j] -= p;
        }
    }
    int ans = 2;
    for(int mi=2;mi<=n;++mi)
    {
        int li = mi*2 - (n+1);
        if(li < 0) continue;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=mi;++i) dp[i][0] = 1;
        for(int ma=mi+1;ma<=n;++ma)
        {
            for(int pos=n;pos>=2;--pos)
            {
                int tli = std::min(li, ma*mi-mi*pos);
                if(tli < 0) continue;
                for(int sz=1;sz<pos;++sz)
                {
                    int w = (ma-mi) * sz;
                    if(w > tli) break;
                    for(int s=w;s<=tli;++s)
                        dp[pos][s] = d.mod(dp[pos][s]+(lli)dp[pos-sz][s-w]*comb[pos][sz]);
                }
            }
        }
        for(int sz=1;sz<n;++sz)
        {
            int w = (n+1-mi) * (sz-1);
            for(int s=w;s<=li;++s)
            ans = d.mod(ans + (lli)dp[n-sz][s-w]*comb[n][sz]);
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include <iostream>

typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=100;
ll mod;
ll dp[N][N][N][N];
ll pd[N][N][N];
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll fac[N];
ll fm[N];
int32_t main(){
    sync;
    ll n;
    cin >> n >> mod;
    fac[0]=fm[0]=1;
    for (int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        fm[i]=power(fac[i],mod-2);
    }

    ll ans=0;
    for (int a0=n+1;a0>max((ll)0,n-20);a0--){
        /// fix adad aval
        memset(dp,0,sizeof dp);
        memset(pd,0,sizeof pd);
        for (int i=1;i<=n+1;i++){
            if (i*a0<=a0*a0) {
                dp[i][0][0][0]+=fm[i];
                pd[i][0][0]+=fm[i];
                dp[i][0][0][0]%=mod;
                pd[i][0][0]%=mod;
            }
        }

        for (int i=2;i<=n;i++){
            for (int j=1;j<=n+1-a0;j++){
                for (int jam=j;jam<=n+1;jam++){
                    for (int t=1;t<=(n+1)/j;t++){
                        /// t tayii ke ezafe mishan barabar bashan
                        if (jam>=t && j>1){
                            dp[i][j][jam][t]+=dp[i][j-1][jam-t][t];
                            dp[i][j][jam][t]%=mod;
                        }
                        if (jam>=t*j && t<i) {
                            dp[i][j][jam][t]+=pd[i-t][j-1][jam-t*j]*fm[t]%mod;
                            dp[i][j][jam][t]%=mod;
                        }
                        if (a0*(a0+j)>=a0*i+jam){
                            pd[i][j][jam]+=dp[i][j][jam][t];
                            pd[i][j][jam]%=mod;
                        }
                    }
                }
            }

        }
        for (int i=0;i<=n+1-a0;i++){
            for (int j=0;j<=n+1;j++){
                ans+=pd[n][i][j]*fac[n]%mod;
                ans%=mod;
            }
        }
      //  cout << a0 << " " << ans << endl;

    }
    cout << ans%mod << endl;;

}


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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;

	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

#define double ld
const int MAXN=100001;
int n,m;
vector<double> sol;
vector<pair<int,int>> adj[MAXN];
using linear=pair<double,double>;
using lineq=pair<linear,linear>;
vector<lineq> eqs;
linear lst[MAXN];
bool no=false;
void bfs() {
	queue<int> q;

	vector<int> par(n+1);
	for(int x=1;x<=n;++x) {
		if(par[x]==0) {
			q.push(x);
			lst[x]={1,0};
			par[x]=-1;

			eqs.clear();
			vector<int> vs;
			while(!q.empty()) {
				int fr=q.front();
				q.pop();
				vs.pb(fr);

				for(auto j:adj[fr]) {
					if(j.xx!=par[fr]) {
						if(par[j.xx]==0) {
							par[j.xx]=fr;
							lst[j.xx]={-lst[fr].xx, j.yy-lst[fr].yy};
							q.push(j.xx);
						}else {
							linear lehet={lst[fr].xx+lst[j.xx].xx, lst[fr].yy+lst[j.xx].yy};
							linear szum={0, j.yy};
							eqs.pb({lehet, szum});
						}
					}
				}
			}

			double eps=1e-7;
			set<double> sols;
			bool csak0=false;
			for(auto i:eqs) {
				if((i.xx.xx-i.yy.xx)!=0) sols.insert((i.yy.yy-i.xx.yy)/(i.xx.xx-i.yy.xx));
				else {
					if(i.xx.yy!=i.yy.yy) {
						csak0=true;
					}else { //identitás

					}
				}
			}
			LOG(csak0);
			if(csak0) {
				bool ok=true;
				for(auto i:vs) {
					for(auto j:adj[i]) {
						ok&=j.yy==lst[i].yy+lst[j.xx].yy;
					}
				}
				if(!ok) no=true;
				else {
					for(int i:vs) {
						sol[i]=lst[i].yy;
					}
				}
			}else if(sols.empty()) {
				vector<double> vals;
				for(int i:vs) {
					vals.pb(-lst[i].yy);
				}

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

				double L=-1000, R=1000;
				auto sum=[&](double mid) -> double {
					double res=0.0;
					for(int i:vs) {
						res+=abs(mid*lst[i].xx+lst[i].yy);
					}
					return res;
				};

				while(fabs(R-L)>1e-12) {
					double mid1=(2*L+R)/3.0, mid2=(L+2*R)/3.0;

					if(sum(mid1)>sum(mid2)) {
						L=mid1;
					}else {
						R=mid2;
					}
				}
				double L2=L
				/*if(fabs(sum(L2)-sum(L))>1e9 && sum(L2)>sum(L)) {
					L2=L;
					LOG(L2);
					LOG(L);
					assert(0);
				}*/
				for(int i:vs) {
					sol[i]=lst[i].xx*L2+lst[i].yy;
				}
			}else {
				if(sols.size()==1 || *prev(sols.end())-*sols.begin()<eps) {
					for(int i:vs) {
						sol[i]=lst[i].xx*(*sols.begin())+lst[i].yy;
					}
				}else {
					no=true;
				}
			}

		}
	}
}

int main() {
	IO;
	cin>>n>>m;
	sol.resize(n+1);
	map<pair<int,int>, int> volt;
	for(int i=0;i<m;++i) {
		int a,b,c;
		cin>>a>>b>>c;
		adj[a].pb({b,c});
		adj[b].pb({a,c});
		if(volt.count(mp(min(a,b), max(a,b)))) {
			no|=volt[mp(min(a,b), max(a,b))]!=c;
		}
		//~ LOG(mp(min(a,b), max(a,b)).xx);
		//~ LOG(mp(min(a,b), max(a,b)).yy);
		//~ LOG(c);
		volt[mp(min(a,b), max(a,b))]=c;
	}

	//~ LOG(no);
	bfs();
	//~ LOG(no);
	//~ for(int i=1;i<=n;++i) cerr<<lst[i].xx<<" "<<lst[i].yy<<"\n";
	//~ return 0;
	cout<<fixed<<setprecision(9);
	if(no) {
		cout<<"NO\n";
	}else {
		cout<<"YES\n";
		for(int i=1;i<=n;++i) cout<<sol[i]<<" \n"[i==n];
		bool ok=true;
		for(auto i:volt) {
			ok&=fabs(sol[i.xx.xx]+sol[i.xx.yy]-(double)i.yy)<1e-6;
		}
		assert(ok);
	}

	return 0;
}


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

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

#define fora(i, a, b) for (int i = (a); i < (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define pr(x) cerr << #x << " = " << x << "\n";
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ll = long long;
using ull = unsigned long long;

using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;

using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;

const long double PI = 3.14159265358979323;
const long long MOD = 1e9 + 7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // uniform_int_distribution<int>(0, n)(rng)

ll rnd(ll n) {
    return uniform_int_distribution<ll>(0, n)(rng);
}

struct custom_hash { // unordered_map<long long, int, custom_hash> safe_map;
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return (size_t) splitmix64(x + FIXED_RANDOM);
    }
	size_t operator()(pair<uint64_t,uint64_t> x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return (size_t) (splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1));
	}
};

ull modmul(ull a, ull b, ull M) {
	ll ret = a * b - M * ull(1.L / M * a * b);
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll power(ll b, ll e, ll mod) {
	ull ans = 1;
	for (; e; b = modmul(b, b, mod), e /= 2)
		if (e & 1) ans = modmul(ans, b, mod);
	return ans;
}

long long modInverse(long long n, long long p) {
    return power(n, p-2, p);
}

long long ncr(long long arr[], long long n, long long r, long long p) {
    return ((arr[n] * modInverse(arr[r], p))%p * modInverse(arr[n-r], p))%p;
}

bool isPrime(ull n) {
	if (n < 2 || n % 6 % 4 != 1) return (n | 1) == 3;
	ull A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	    s = __builtin_ctzll(n-1), d = n >> s;
	for (ull a : A) {   // ^ count trailing zeroes
		ull p = power(a%n, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--)
			p = modmul(p, p, n);
		if (p != n-1 && i != s) return 0;
	}
	return 1;
}

ull pollard(ull n) {
	auto f = [n](ull x) { return modmul(x, x, n) + 1; };
	ull x = 0, y = 0, t = 0, prd = 2, i = 1, q;
	while (t++ % 40 || __gcd(prd, n) == 1) {
		if (x == y) x = ++i, y = f(x);
		if ((q = modmul(prd, max(x,y) - min(x,y), n))) prd = q;
		x = f(x), y = f(f(y));
	}
	return __gcd(prd, n);
}

vector<ull> factor(ull n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ull x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

struct Node {
    ll nr;
    Node* parent;
    vector<pair<Node*, ll>> edges;
    bool visited = false;
    bool visitedTwice = false;
    bool active = false;
    ll distance = 1e9;
    ll poz = 1;
    ll offset = 0;
    long double starting;
    void reset() {
        visited = false;
        active = false;
        distance = 1e9;
    }
    void hardReset() {
        edges.clear();
        visited = false;
        active = false;
        distance = 1e9;
    }
};

list<Node*> activeNodes;
bool possible = true;
bool startingFound = false;
long double starting = 0;

void dfs(Node* node) {
    if (node -> visitedTwice) {
        return;
    }
    node -> visitedTwice = true;
    node -> starting = starting;
    for (auto j: node -> edges) {
        Node* newNode = j.first;
        if (!newNode -> visitedTwice) {
            dfs(newNode);
        }
    }
}

void bfs(Node* node) {
    if (node -> visited) {
        return;
    }
    node -> visited = true;
    node -> parent = node;
    node -> distance = 0;
    queue<Node*> q;
    activeNodes.push_back(node);
    for (q.push(node); !q.empty(); q.pop()) {
        node = q.front();
        for (auto j: node -> edges) {
            Node* newNode = j.first;
            if (!newNode -> visited) {
                newNode -> visited = true;
                newNode -> distance = node -> distance + 1;
                newNode -> parent = node;
                newNode -> poz = - node -> poz;
                newNode -> offset = j.second - node -> offset;
                activeNodes.push_back(newNode);
                q.push(newNode);
            } else {
                ll poz = - node -> poz;
                ll offset = j.second - node -> offset;
                if (!startingFound) {
                    if (poz == newNode -> poz) {
                        if (offset != newNode -> offset) {
                            possible = false;
                        }
                    } else if (poz > 0) {
                        starting = ((long double)(newNode -> offset - offset)) / 2;
                        startingFound = true;
                    } else {
                        starting = ((long double)(offset - newNode -> offset)) / 2;
                        startingFound = true;
                    }
                } else {
                    if (poz == newNode -> poz) {
                        if (offset != newNode -> offset) {
                            possible = false;
                        }
                    } else if (poz > 0) {
                        long double newStarting = ((long double)(newNode -> offset - offset)) / 2;
                        if (abs(newStarting - starting) > 0.000001) {
                            possible = false;
                        }
                    } else {
                        long double newStarting = ((long double)(offset - newNode -> offset)) / 2;
                        if (abs(newStarting - starting) > 0.000001) {
                            possible = false;
                        }
                    }
                }
            }
        }
    }
}

Node nodes[200005];
ll n,m,k,t,a,b,c,rez,sk,mas[200005];
string s1,s2;
list<ll> q;
set<ll> s;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    fora(i, 0, m) {
        cin >> a >> b >> c;
        nodes[a-1].edges.push_back({&nodes[b-1], c});
        nodes[b-1].edges.push_back({&nodes[a-1], c});
    }
    fora(i, 0, n) {
        if (!nodes[i].visited) {
            starting = 0;
            startingFound = false;
            pozOffset = 0;
            negOffset = 0;
            activeNodes.clear();
            bfs(&nodes[i]);
            if (!startingFound) {
                long double l = -1000000;
                long double r = 1000000;
                while (r - l >= 0.000000001) {
                    long double c1 = l+(r-l)/2;
                    long double c2 = c1 + 0.000000001;
                    long double sk1 = 0;
                    long double sk2 = 0;
                    for (Node* node: activeNodes) {
                        sk1 += abs(((long double)c1 * node -> poz + node -> offset));
                        sk2 += abs(((long double)c2 * node -> poz + node -> offset));
                    }
                    if (sk1 <= sk2) {
                        r = c1;
                    } else {
                        l = c2;
                    }
                }
                starting = l;
            }
            dfs(&nodes[i]);
        }
    }
    cout << (possible ? "YES\n" : "NO\n");
    if (possible) {
        fora(i, 0, n) {
            cout << nodes[i].starting * nodes[i].poz + nodes[i].offset << " ";
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

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

	cin >> n;

	cout << n << endl;

    for(int i = 1; i <= n; i++) cout << i << " ";
    cout << endl;

	return 0;
}


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector<vector<int> >
#define eps 0.000001

vector<vector<pair<int,int> > > graph(100050,vector<pair<int,int> >);
bool was[100005];
int xsign[100005];
int cons[100005];
double val[100005];
bool bad = false;
bool xfix = false;
double xval = 0;
vector<int> curr;

void dfs(int v) {
	curr.push_back(v);
	was[v] = true;
	for(auto ed : graph[v]) {
		int u = ed.first;
		int need = ed.second;
		if(!was[u]) {
			xsign[u] = -xsign[v];
			cons[u] = need-cons[v];
			dfs(u);
		} else {
			if(xsign[u] != xsign[v]) {
				if(cons[u]+cons[v] != need) {
					bad = true;
				}
			} else {
				double needval = (need-cons[u]-cons[v])/(xsign[u]+xsign[v]);
				if(!xfix) {
					xfix = true;
					xval = needval;
				} else {
					if(abs(needval-xval) > eps) {
						bad = true;
					}
				}
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int a,b,c;
		cin >> a >> b >> c;
		graph[a].push_back({b,c});
		graph[b].push_back({a,c});
	}
	for(int i = 1; i <= n; i++) {
		if(!was[i]) {
			xfix = false;
			xsign[i] = 1;
			curr.clear();
			dfs(i);
			if(xfix) {
				for(int v : curr) {
					val[v] = xsign[v]*xval+cons[v];
				}
			} else {
				ll minsum = 1000000000000000LL;
				int minat = 0;
				for(int va = -curr.size(); va <= curr.size(); va++) {
					ll curr = 0;
					for(int v : curr) {
						curr+= abs(xsign[v]*va+cons[v]);
					}
					if(curr < minsum) {
						minsum = curr;
						minat = va;
					}
				}
				for(int v : curr) {
					val[v] = xsign[v]*minat+cons[v];
				}
			}
		}
	}
	if(bad) {
		cout << "NO";
		return 0;
	} else {
		cout << "YES\n";
		for(int i = 1; i <= n; i++) {
			cout << val[i] << " ";
		}
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
 {
  int v1,v2,t,d,i,x=0,ans=0,y=0,rem=0,z=0,a=0;
  cin>>v1>>v2>>t>>d;
  ans=v1+v2;
  x=v1;
  for(i=1;i<=t-2;i++)
   {
    x=x+d;
    ans+=x;
    if(i==t-2)
     {
      if(v2-x>=0)
      {cout<<ans;system("pause");return 0;}
     }
    if(x>=v2)
    break;
   }
  a=v2+d-x;
  y=i+1;
  rem=t-1-y;
  z=i+(rem/2)+1;
  for(i=y;i<=t-2;i++)
   {
    if(i==z)
     {
      if(rem%2==0)
      {x-=a;}
      else
      {x+=a;}
     }
    else
     {
      if(i>z)
      x-=d;
      else
      x+=d;
     }
    ans+=x;
   }
   cout<<ans;
   //system("pause");
   return 0;
  }


#include <iostream>

using namespace std;

int main()
{
	int v1, v2, t, d;
	cin >> v1 >> v2 >> t >> d;
	if (v1 > v2) {
		int loc = v2;
		v2 = v1;
		v1 = loc;
	}
	if (!d) {
		cout << v1*d;
		return 0;
	}

	int l, r, inl, inr;
	if (v1 % 2)
}


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

lli x[200][2000];
int main()
{
    int v1, v2, t, d;
    cin >> v1 >> v2 >> t >> d;

    x[1][v1] = v1;
    for (int i = 2; i < t; i++) {
        for (int j = 0; x[i][j] != 0; j++) {
            for (int k = max(j - d, 0); k <= j + d; k++) {
                x[i][k] = max(x[i][k], x[i-1][j] + k);
            }
        }
    }

    for (int k = max(v2 -d, 0); k <= v2 + d); k++) {
        x[t][v2] = max(x[t][v2], x[t-1][k] + v2);
    }
    cout << x[t][v2];
    return 0;
}


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

int main(){
	int x;
	cin >> x;
	r = x%4;

	if(r==1){
		cout << 0 << " " << "A" << endl;
	}else if(r==3){
		cout << 2 << " " << "A" << endl;
	}else if(r==2){
		cout << 2 << " " << "B" << endl;
	}else if(r==0){
		cout << 1 << " " << "A" << endl;
	}
}


#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
	int x;
	cin >> x;
	if(x % 4==1){
		cout << "0 A" << endl;
	}
	if (x % 4 == 2) {
		cout << "1 B" << endl;
	}
	if (x % 4 == 3 ) {
		cout << " 1 B" << endl;
	}
	if (x % 4 == 0) {
		cout << " 1 A" << endl;
	}
	system("pause");
	return 0;

}


#include<bits/stdc++.h>

using namespace std;

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

    int mod = x%4;

    int costA,costB, costC;

    costA = abs(1-a);
    costB = abs(3-a);
    costC = abs(2-a);

    if(costA <= 2){
        cout << costA << "A";
    }

    else if(costB <=2){
        cout << costB << "B";
    }

    else{
        cout << costC << "C";
    }
}


#include <bits/stdc++.h>

#define int long long
#define ll long long
#define F first
#define endl "\n"
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size())
#define all(x) x.begin (), x.end ()

using namespace std;

typedef long double ld;
typedef pair <ll, ll> pll;
typedef map <ll, ll> mll;
typedef vector <ll> vl;
typedef set <ll> sl;

const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 4;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;

int gcd (int x, int y) {
	while (x != 0 && y != 0) {
		x %= y;
		if (x == 0) break;
		y %= x;
	}
	return x + y;
}
inline void Maga() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}

signed main() {

	return
}


#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
#define N 120
#define M 6000
int n, k;
void solve() {
	int x = sqrt(n);
	if (x * x == n) {
		printf("%d\n", 4 * x);
	} else if (x * (x+1) > n) {
		printf("%d\n", 4 * x + 2);
	}
	else {
		printf("%d\n", 4 * x + 2 + 2);
	}
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
    ll n,m,j,y,i,k,t,len,x,c,p;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        x=i*i-(i-1);
        y=i*i+i;
        if(n>=x && i*i>=n)
        {
            cout<<4*i;
            return ;
        }
        else if(n>i*i && n<=y)
        {
            cout<<(4*i)+2;
            return ;
        }
    }
}
}
int main()
{
    int T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

int main()
{
    int n,r,res=0; cin>>n;
    for (int i = 1 ; i <= 1e3 ; ++i){
        int curr = i*i;
        if (curr > n){
            r = i-1;
            break;
        }
    }
    int Nr = r+(n-(r*r))/r;
    res = 2*r+2*Nr;
    cout << res + (n-(r*r))%r<< endl;

    return 0;
}


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

double n,i;

int main()
{cin>>n;
 for(i=n;i>0;i--)
   if(sqrt(i)==int(sqrt(i)))
   m=sqrt(i);
 if(m==n)
   cout<<m*4<<endl;
 else
   cout<<m*4+2<<endl;

  return 0;
 }


// Copyright [2017] <dmnsn7>
#include <cstdio>
#include <cstring>

bool ispr(char *s) { return s[0] == s[3] && s[1] == s[2]; }

int main() {
  int a, b;
  while (~scanf("%d:%d", &a, &b)) {
    for (int i = 0;; i++) {
      char s[10];
      snprintf(s, size(s), "%02d%02d", a, b);
      if (ispr(s) == true) {
        printf("%d\n", i);
        break;
      }
      b++;
      if (b == 60) {
        b = 0;
        a++;
      }
      if (a == 24) {
        a = 0;
      }
    }
  }
  return 0;
}


#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include <string>
#include <vector>
using namespace std;

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define all(v) (v).begin(), (v).end()
#define Memset(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const ll mod = 1000000007;
const ll inf = 1000000000009;

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

int  solve(int h,int m )
{
	int z=(h%10)*10+h/10;
	if(z>=m && z<60)
		return z-m;
	else
		retrun  (60-m)+solve((h+1)%24,0);
}
int main()
{
	IO;
	int h{},m{};
	char s;
	cin>>h>>s>>m;
	cout<<solve<<"\n";

	//system("pause");
	return 0;
}


#include <iostream>
#include <cctype>
#include <string>
#include <cstring>
#include <iomanip>
#include <math.h>
using namespace std;

int rev(int t)	{
	int rem = t%10;
	int div = t/10;
	return rem*10+div;
}
int main()
{
	int t,m;
	char c;
	cin>>t>>c>>m;
	for(int i=0;;i++)	{
		if(rev(t) == m && rev(m) == t)	{
			cout<<i<<endl;
			return 0;
		}
		m++;
		if(m==60)	{
			a++;
			m=0;
			if(a==24)	a=0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int h,m,c=0,
   scanf("%d:%d",&h,&m);
   while((h%10)*10-+(h/10)!=m)
   {
     m++;
     if(m==60)
     {
       m=00;
       h++;
     }
     h=h%24;
     c++;
   }
   printf("%d",c);
   return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
ll n, m;
ll fib(ll q)
{
    if(q == 1 || q == 0)
        return 1;
    else return (fib(q - 1) + fib(q - 2)) % (1e9 + 7);
}
int main()
{
    cin >> n >> m;
    cout << 2 * (fib(n) + fib(m) - 1);
    return 0;
}


/****************************
Filename: FatMouse.cpp
Author: hbb
Create: 2019-10-20 17:03:40
 ****************************/
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = INT_MAX >> 1;
typedef long long int LL;

LL a[maxn];

int main(){
	LL n, m;
	scanf("%lld %lld", &n, &m);
	a[1] = 2;
	a[2] = 4;
	for(int i = 3; i < maxn; i++){
		a[i] = (a[i - 1] + a[i - 2]) % mod;
	}
	LL temp = a[n];
	if(m == 1){
		printf("%lld\n", temp);
	}
	else{
		temp = (temp + 2) % mod;
		m--;
		if(m > 1){
			for(int i = 1; i <= m - 1; i++){
				temp = (temp + a[i]) % mod;
			}
		}
		printf("%lld\n", temp);
	}
}

/*

   2    4    6    10    16
   4    6    8    12    18
   6	 8    10   14    20
   10	 12   14   18    24
   16   18   20   24    30
   26

 *


#include<bits/stdc++.h>
using namespace std;
int main()
{ long long n,m;
cin>>n>>m;
long long s=2(n+m-1 );
cout<<s%10000000007<<endl;}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define daulet ios_base::sync_with_stdio(0)
#define sungkar cin.tie(0)
#define sdu cout.tie(0);

typedef long long ll;
typedef long double ld;

long long binpow(long long a, long long b)
{
    long long ans = 1;
    while (b > 0)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
int gcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b)
{
    return a / gcd(a, b) * b;
}
ll fact(int n)
{
    ll ans = 1;
    for (int i = 2; i <= n; i++)
    {
        ans = (ans * i) % MOD;
    }

    return ans;
}

ll powM(int n, int x)
{
    if (x == 0)
    {
        return 1;
    }
    if (x == 1)
    {
        return n % MOD;
    }

    if (x % 2 == 0)
    {
        ll a = powM(n, x / 2);
        return (a * a) % MOD;
    }
    else
    {
        return (n * powM(n, x - 1)) % MOD;
    }
}

ll C(int n, int k)
{
    return (fact(n) * powM((fact(k) * fact(n - k)) % MOD, MOD - 2)) % MOD;
}

ll A(int n, int k)
{
    return (fact(n) * powM(fact(n - k) % MOD, MOD - 2)) % MOD;
}

void add_self(int &a, int b)
{
    a += b;
    if (a >= MOD)
    {
        a -= MOD;
    }
}

void sub_self(int &a, int b)
{
    a -= b;
    if (a < 0)
    {
        a += MOD;
    }
}

struct segtree
{

    vl tree;
    int size;

    void init(int n)
    {
        size = 1;
        while (size < n)
            size *= 2;
        tree.assign(2 * size - 1, 0);
    }
    void build(vi &a, int x, int lx, int rx)
    {
        if (rx - lx == 1)
        {
            if (lx < a.size())
                tree[x] = a[lx];
        }
        else
        {
            int m = (lx + rx) / 2;
            build(a, 2 * x + 1, lx, m);
            build(a, 2 * x + 2, m, rx);
            tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
        }
    }

    void build(vi &a)
    {
        init(a.size());
        build(a, 0, 0, size);
    }

    void set(int i, int v, int x, int lx, int rx)
    {
        if (rx - lx == 1)
        {
            tree[x] = v;
            return;
        }
        int m = (lx + rx) / 2;
        if (i < m)
        {
            set(i, v, 2 * x + 1, lx, m);
        }
        else
        {
            set(i, v, 2 * x + 2, m, rx);
        }
        tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
    }

    void set(int i, int v)
    {
        set(i, v, 0, 0, size);
    }

    ll sum(int l, int r, int x, int lx, int rx)
    {
        if (l >= rx || lx >= r)
        {
            return 0;
        }
        if (lx >= l && rx <= r)
        {
            return tree[x];
        }
        int m = (rx + lx) / 2;
        ll s1 = sum(l, r, 2 * x + 1, lx, m);
        ll s2 = sum(l, r, 2 * x + 2, m, rx);
        return s1 + s2;
    }

    ll sum(int l, int r)
    {
        return sum(l, r, 0, 0, size);
    }
};
int n;
ll m;
ll f[250009];
void solve()
{
    cin >> n >> m;
    ll ans = 0;
    f[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        f[i] = f[i - 1] * i % m;
    }
    for (int i = 1; i <= n; i++)
    {
        ans += (n - i + 1) * (f[i] * f[n - i + 1] % m);
        ans %= m;
    }
    cout << ans << '\n';
}

int main()
{
    daulet;
    sungkar;
    sdu;
    int tt = 1;
    // cin >> tt;
    while (tt--)
    {
        solve();
    }
}


void DFS( int v, int p )
{
    used[v] = 1;
    tin[v] = fup[v] = timer++;
    int child = 0;
    for( auto u : g[v] )
    {
        if( u == p )
            continue;

        if( used[u] )
            fup[v] = min( fup[v], tin[u] );
        else
        {
            DFS( u, v );

            fup[v] = min( fup[v], fup[u] );

            if( fup[u] >= tin[v] and p != -1 )
                cout << v + 1 << endl;
            child++;
        }
    }
    if( p == -1 and child > 1 )
    {
        cout << v + 1 << endl;
    }
}


#include <bits/stdc++.h> /**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
const int nax = 250010;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	int n;
	ll mod;
	cin>>n>>mod;
	vector<ll> fac(nax);
	fac[0] = fac[1] = 1;
	for(ll i=2; i<=nax; i++){
		fac[i] = (i*fac[i-1])%mod;
	}
	ll ans = 0;
	for(ll d = 1; d<=n; d++){
		ll aux = ((n-d+1)*(n-d+1))%mod
		ans = (ans + (((aux*fac[d])%mod)*fac[n-(d)])%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a,x,y;
string b;
int main() {
    cin>>a>>b;
    for(int i=0;i<a;i++){
        if(b[i] == '4'){
            x++;
        }else if(b[i] == '7'){
            y++
        }
    }
    if(y>x){
        cout<<7;
    }else if(x!=0){
        cout<<4;
    }else{
        cout<<-1;
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
string s;
int k,y,i;
int main()

{

    cin>>s;
    for (i = 0; i < s.size(); i++){
        if (s[i] == '4') k++;
        if (s[i] == '7') y++;
    }
    if (k == 0 && y == 0){cout<<"-1"; exit(0);}
    if (k >= y) cout<<"4"; else cout<<"7";
    return 0;
}


#include <iostream>
using namespace std;
#include<cstring>
#include<cmath>
#include<cstdio>
#include<string>
#include<string.h>
#include<stdio.h>
#include <vector>
#include <map>
#include <set>
#include<algorithm>
#include<iterator>
#define endl "\n"
typedef long long int lli;
int i, j, k;
int BinarySearch(int a[], int l, int h, int x);
int BS_first_occurence(int a[], int n, int x);
int BS_first_occurence(int a[], int n, int x);

int main()
{

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

    string s;
    int f,sev;
    f = 0;
    sev = 0;
    cin>>s;
    for(i=0;s[i];i++)
    {
        if(s[i]=='4')f++;
        else if(s[i]=='7')s++;
    }
    if(f>=sev && f!=0)cout<<4<<endl;
    else if(f<sev)cout<<7<,endl;
    else cout<<-1<<endl;

}


#include <string>
#include <iostream>
#include <sstream>

using namespace std;

inline int countSubstring(string str, string sub)
{
    if (sub.length() == 0) return 0;
    int count = 0;
    for (size_t offset = str.find(sub); offset != std::string::npos; offset = str.find(sub, offset + sub.length())) {
        ++count;
    }

    return count;
}

int getLucky(int indx, int* length) {
    int digitsNum = floor(log(indx) / log(2)), counter = 0 , lucky = 0;
    int groupedCoeffecients = 2*(pow(2 , digitsNum) - 1) - indx;
    while(groupedCoeffecients < 0) {
        digitsNum++;
        groupedCoeffecients = 2*(pow(2 , digitsNum) - 1) - indx;
    }
    int* coef = new int[digitsNum];
    memset(coef , 0 , sizeof(int)*digitsNum);

    do {
        coef[counter] = groupedCoeffecients % 2;
        groupedCoeffecients /= 2;
        counter++;
    }
    while(groupedCoeffecients > 0);

    for(int i = 0 ; i < digitsNum ; i++) {
        lucky += coef[i]*4*pow(10 , i) + abs(1 - coef[i])*7*pow(10 , i);
    }

    *length = digitsNum;
    return lucky;
}

int main() {

    string input, output = "-1";
    int len, maxOccurs = 0, itr = 1;
    cin >> input;
    len = input.length();

    while(true) {
        int luckyLen, occurs, lucky = getLucky(itr, &luckyLen);
        string luckyStr;
        stringstream ss;
        if(luckyLen > len)
            break;
        ss << lucky;
        luckyStr = ss.str();
        occurs = countSubstring(input, luckyStr);
        if(occurs > maxOccurs) {
            maxOccurs = occurs;
            output = luckyStr;
        }
        itr++;
    }

    cout << output << endl;

    return 0;
}


#include "stdio.h"
#include "iostream"
#include "string.h"
#include "algorithm"
#include "map"

using namespace std;
using LL = long long;

int x[2], y[2], r[2], R[2];

int s(int a) {
    return a * a;
}

bool chk(int r, int r1, int R1, int d) {
    if(sqrt(d) + r <= r1) return true;
    if(r + R1 <= sqrt(d)) return true;
    if(sqrt(d) + R1 <= r) return true;
    return false;
}

int main() {
    for (int i = 0; i < 2; ++i) {
        cin >> x[i] >> y[i] >> r[i] >> R[i];
    }

    int d = s(x[0] - x[1]) + s(y[0] - y[1]);

    int res = 0;
    if(chk(r[0], r[1], R[1], d)) res ++;
    if(chk(r[1], r[0], R[0], d)) res ++;
    if(chk(R[0], r[1], R[1], d)) res ++;
    if(chk(R[1], r[0], R[0], d)) res ++;

    cout << res << endl;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
template<class T> inline T Max(T a,T b)
{if(a>b)return a;else return b;}
template<class T> inline T Min(T a,T b)
{if(a<b)return a;else return b;}
template<class T> inline T gcd(T a,T b)
{if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)
{if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<class T> inline T TripleMax(T a,T b,T c)
{return Max(Max(a,b),c);}
template<class T> inline T TripleMin(T a,T b,T c)
{return Min(Min(a,b),c);}
#define ll long long
#define PB push_back
#define MP make_pair

int     x1, y1, r1, R1;
int     x2, y2, r2, R2;
double  distance;
int     ret;

int check (int r, int c_r, int c_R) {
    if (distance + r <= c_R || r + c_R <= distance || distance + c_R <= r) {
        return 1;
    }
    return 0;
}

int main (int argc, const char* argv[]) {

    cin >> x1 >> y1 >> r1 >> R1;
    cin >> x2 >> y2 >> r2 >> R2;
    ret = 0;
    distance = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    if (check(r1, r2, R2) == 1) {
        ret++;
    }
    if (check(R1, r2, R2) == 1) {
        ret++;
    }
    if (check(r2, r1, R1) == 1) {
        ret++;
    }
    if (check(R2, r1, R1) == 1) {
        ret++;
    }
    cout << ret << endl;
    return 0;
}


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

int func(int a, int b, int c, int d) {
  if (c<=a and (a-c)*(a-c)>=d) return 1;
  if (c>=b and (c-b)*(c-b)>=d) return 1;
  if ((b+c)*(b+c)<=d) return 1;
  return 0;
}

int main()
{
    float x1,y1,r1,R1;
    float x2,y2,r2,R2;
    cin >> x1 >> y1 >> r1 >> R1;
    cin >> x2 >> y2 >> r2 >> R2;

    float d = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);

    if(d < r1 && d > R2 && d+r2<r1 && d+R2>R1) {
                cout << 1 << endl;

    } else if (d<r1 && d>R2 && d+R2=r1) {
        cout << 4 << endl;
    } else if(d< r1+r2) {
        cout << 0 << endl;
    }

    //cout << func(r1,R1,r2,d)+func(r1,R1,R2,d)+func(r2,R2,r1,d)+func(r2,R2,R1,d) << endl;

    if(x1)

    return 0;
}


#include <iostream>

using namespace std;

struct k
{
    int x,y,r,R;
};

bool inter(int x1,int y1, int r1, int x2,int y2, int r2)
{
    int d  = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    return (d>=(r1+r2)*(r1+r2))||(d<((r1+r2)*(r1+r2))&&d<=((r1-r2)*(r1-r2)));
}

int main()
{
    k a[2];
    for (int i=0;i<2;i++)
    {
        cin >> a[i].x >> a[i].y >> a[i].r >> a[i].R;
    }
    int ans=0;
    for (int i=0;i<2;i++)
    {
        bool T=true;
        for (int j=a[i^1].r;j<=a[i^1].R;j++) T&=inter(a[i].x,a[i].y,a[i].r,a[i^1].x,a[i^1].y,j);
        ans+=T;
        bool T=true;
        for (int j=a[i^1].r;j<=a[i^1].R;j++) T&=inter(a[i].x,a[i].y,a[i].R,a[i^1].x,a[i^1].y,j);
        ans+=T;
    }
    cout << ans;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	cin >> n;
	int i,flag=0;
	long int dif;
	int arr[10000];
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
	}
		dif=arr[1]-arr[0];
	for(i=1;i<n-1;i++)
	{
		if(arr[i+1]-arr[i]!=dif)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	{
		cout << arr[n-1];
	}
     else
	{
		cout << arr[n-1] + dif;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 987654321;
const LL MOD = 1e9+7;
const int N = 2e3+100;
int a[N];
int main () {
 //  freopen("in.txt", "r", stdin);
//   freopen("out.txt", "w", stdout);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(n==2){
        cout<<2*a[1]-a[0]<<endl;
    }
    else{
        bool flag=true;
        int cmp=a[1]-a[0];
        for(int i=2;i<n;i++){
            if(a[i]-a[i-1]!=cmp){
                flag=false;
                break;
            }
        }
        if(flag)
            cout<<a[n-1]+cmp<<endl;
        else
            cout<<a[n-1]<<endl;
    }
    return 0;
}