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

const int MOD = 1000000007;

long bimod(int x, int exp){
    long res = 1, mul = x;
    for(long i = exp; i > 0; i >>= 1){
        if(i & 1) res = (res * mul) % MOD;
        mul = (x * x) % MOD;
    }
    return res;
}

int main(){
    int n, a[100000], i; cin >> n;
    long sum = 0, ans;
    for(i = 0; i < n; i++){
        cin >> a[i];
        sum = (sum + a[i]) % MOD;
    }

    long bmd = bimod(2, n-1);

    long a_n[100000] = {1, 1,}, s_n_2 = 1;
    for(i = 2; i < n ; i++){
        a_n[i] = s_n_2 % MOD, s_n_2 = (s_n_2 + a_n[i-1]) % MOD;
    }

    ans = sum;
    long afp, afm, af;
    for(i = 1; i < n; i++){
        af = (a_n[i] * a_n[n-i]) % MOD;
        afp = (sum * a_n[n-i]) % MOD;
        afm = (a[n-i] * af * 2) % MOD;
        ans = (ans + afp - afm + MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}

//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n),b(n);
  rep(i,0,n){
    cin>>a[i];
    res+=a[i];
  }
  rep(i,0,n){
    cin>>b[i];
    b[i]=b[i]-a[i];
  }
  vector<vector<ll>>v(2);
  rep(i,0,n){
    v[i&1].PB(b[i]);
  }
  sort(ALLR(v[0]));
  sort(ALLR(v[1]));
  rep(i,0,v[0].size()){
    if(v[0][i]+v[1][i]>0)res+=v[0][i]+v[1][i];
  }
  cout<<res<<endl;
  return 0;
}


// Problem: C - ABC Tournament
// Contest: AtCoder - AtCoder Beginner Contest 188
// URL: https://atcoder.jp/contests/abc188/tasks/abc188_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <cmath>
#define pii pair<int,int>
using namespace std;
pair<int, int> arr[65546];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, a = -1 , b = -1, pa = -1 , pb = -1;
	cin >> n;
	n = pow(2, n);
	for (int i = 0; i < n; ++i)
		cin >> arr[i].second, arr[i].first = i+1;
	for (int i = 0, j = n-1; i < j; ++i, --j) {
		if (arr[i].second > a) {
			a = arr[i].second, pa = arr[i].first;
		}
		if (arr[j].second > b) {
			b = arr[j].second, pb = arr[j].first;
		}
	}
	if (a > b) cout << pb;
	else cout << pa;
}

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define int long long
#define endl '\n'
                            /*
ifstream in("test.txt");
#define cin in            */

void solve(){
	int n;
	cin >> n;
	n = 1 << n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	if(*max_element(a.begin(), a.begin()+n/2) < *max_element(a.begin()+n/2, a.end()))
		cout << max_element(a.begin(), a.begin()+n/2)-a.begin()+1;
	else
		cout << max_element(a.begin()+n/2, a.end())-a.begin()+1;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

void solve() {
	int n;
	cin >> n;
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	if (s1.back() == s2.back() && s2.back() == s3.back()) {
		char c = s1.back();
		char x = '1' + '0' - c;
		for (int i = 0; i < 2 * n; ++i) {
			cout << x;
		}
		cout << c << "\n";
		return;
	}
	int cnt0 = 0, cnt1 = 0;
	char c = '0';
	vector<string> strs = {s1, s2, s3};
	for (int i = 0; i < 3; ++i) {
		if (strs[i].back() == '0') {
			++cnt0;
		} else {
			++cnt1;
		}
	}
	if (cnt1 > cnt0) {
		c = '1';
	}
	char x = '0' + '1' - c;
	for (int i = 0; i < n; ++i) {
		cout << c;
	}
	for (int i = 0; i < n; ++i) {
		cout << x;
	}
	cout << c << "\n";
}

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;

	for (int i = 0; i < t; ++i) {
		solve();
	}

}

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

struct UnionFind {
    vector<int> par;
    vector<int> siz;
    UnionFind(int N) : par(N),siz(N) {
        for (int i=0; i<N; i++) {
            par[i]=i,siz[i]=1;
        }
    }
    int root(int x) {
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if (rx==ry) return;
        par[rx]=ry;
        siz[ry]+=siz[rx];
    }
    bool same(int x,int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
    int size (int x) {
        return siz[root(x)];
    }
};

int main() {
   int N,M;
   cin >> N >> M;
   vector<vector<pair<int,int>>> G(N);
   UnionFind tree(N);
   int A[N];
   memset(A,0,sizeof(A));
   for (int i=0; i<M; i++) {
       int u,v,c;
       cin >> u >> v >> c;
       if (tree.same(u-1,v-1)) continue;
       tree.unite(u-1,v-1);
       G[u-1].push_back({v-1,c});
       G[v-1].push_back({u-1,c});
   }
   queue<tuple<int,int,int>> q;
   for (int i=0; i<N; i++) {
       if (G[i].size()==1) {
           q.push(make_tuple(i,G[i][0].first,G[i][0].second));//position,position,distance
           A[i]=1;
           break;
       }
   }
   while (!q.empty()) {
       tuple<int,int,int> p=q.front();
       q.pop();
       int a=get<0>(p),b=get<1>(p),d=get<2>(p);
       if (d==A[a]) {
           if (d==1) A[b]=2;
           else A[b]=1;
       }
       else A[b]=d;
       for (auto x:G[b]) {
           int a=x.first;
           if (A[a]==0) {
               q.push(make_tuple(b,x.first,x.second));
           }
       }
   }
   for (int i=0; i<N; i++) cout << A[i] << endl;
}


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

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using ordered_set = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll N = 2e5+1;

#define S second
#define F first
#define vt vector
#define rep(i, st, en) for(ll i = (st); i < (en); ++i)
#define repr(i, en, st) for(ll i = (en); i >= (st); --i)

int main() {
	fastio();

	ll n;
	cin >> n;

	vt<ll> a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}

	vt<vt<ll>> dp(n+1, vt<ll>(n+1, 0));

	/**
	 * 	dp[i][j]:
	 * 		i: which bag is being filled [1...n]
	 * 		j: currently starting the bag at which index ?
	 * 	Answer:
	 * 		dp[1][1]
	 */

	vt<ll> ps(n+1);
	ps[0] = 0;

	rep(i, 1, n+1) {
		ps[i] = ps[i-1] + a[i-1];
	}

	vt<vt<ll>> mult(n+1, vt<ll>(n+1, -1)); // stores index for the next multiple
	rep(i, 1, n+1) {
		vt<ll> modu(i, -1);
		ll sum = 0;
		repr(j, n, 1) {
			sum += a[j-1];
			sum %= i;

			// if (i == 2) {
			// 	cerr << j << " << j \t" << modu[sum] << " << modu \t" << sum << " sum \n";
			// }

			if (modu[sum] != -1) {
				mult[i][j] = modu[sum];
			}
			modu[sum] = j;

		}
	}

	// rep(i, 1, n+1) {
	// 	cerr << "i: " << i << ": \n";
	// 	rep(j, 1, n+1) {
	// 		cerr << mult[i][j] << "\t";
	// 	}
	// 	cerr << "\n";
	// }

	repr(j, n, 1) {

		//cerr << "j = " << j << "\n";
		rep(i, 1, n+1) {

			if (mult[i][j] != -1) {
				dp[i][j] = (dp[i][j] + dp[i][mult[i][j]] + (i+1 <= n ? dp[i+1][mult[i][j]] : 0)) % MOD;
			}
			else {
				if ((ps[n]-ps[j-1]) % i == 0) {
					dp[i][j] = 1;
				}
			}

			//cerr << dp[i][j] << " " << mult[i][j] << "\n";
		}

	}

	cout << dp[1][1] << "\n";

}

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

int main(){

	int n;
	cin>>n;

	vector<ll> lista(n+1);
	for(int i = 1; i<=n; i++){
		cin>>lista[i];
	}

	vector<vector<ll> > dp(n+1, vector<ll>(n+1, 0));

	for(int i = 1; i<=n; i++){
		dp[i][1] = 1;
	}

	for(int i = 2; i<=n; i++){
		vector<ll> resto(i, 0);
		ll sum = 0;
		for(int j = 1; j<=n; j++){
			sum = (sum + lista[j])%i;
			dp[j][i] = (dp[j][i] + resto[sum%i])%MOD;
			resto[sum%i] = (resto[sum%i] + dp[j][i-1])%MOD;
		}
	}

	ll res = 0;
	for(int i = 1; i<=n; i++){
		res = (res + dp[n][i])%MOD;
	}

	cout<<res<<"\n";

	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int n,t[2010];
int l[2010],r[2010];
int cnt=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t[i],&l[i],&r[i]);
		l[i]*=2,r[i]*=2;
		if (t[i]==2)
			r[i]--;
		else if (t[i]==3)
			l[i]++;
		else if (t[i]==4) l[i]++,r[i]--;
	}
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++)
		{
			if (r[i]<l[j]||r[j]<l[i]) continue;
			cnt++;
		}
	printf("%d\n",cnt);
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <memory.h>

using namespace std;

typedef vector<int> VI;
typedef pair<int, int> PI;
typedef vector<PI> VPI;

#define FOR(i,a,n) for (int i = (a); i < (n); ++i)
#define FORE(i,a,n) for (int i = (a); i <= (n); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FORE(i,0,n)
#define LL long long
#define FIR(n) REP(i,n)
#define FJR(n) REP(j,n)
#define ALL(v) v.begin(), v.end()

#define FI FIR(n)
#define FJ FJR(n)
#define FR(i,a) FOR(i,a,n)
#define REPN(i) REP(i,n)

#define GI(n) scanf("%d", &n)
#define GI2(n,m) scanf("%d %d", &n, &m)

int a[2020], b[2020];

int main() {
#ifdef LOCALF
	freopen("input.txt", "rt", stdin);
#endif
	ios::sync_with_stdio(false); cin.tie(0);

	int n; cin >> n;
	int t, s, f;
	FI{
		cin >> t >> s >> f;
		s *= 2;
		f *= 2;
		if (t >= 3) ++s;
		if (t % 2 == 0) --f;
		a[i] = s;
		b[i] = f;
	}

	int res = 0;
	FI FOR(j, i + 1, n) if ((a[i] <= a[j] && a[j] <= b[i]) || (a[j] <= a[i] && a[i] <= b[j]))
		++res;
	cout << res << endl;

}


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

#define ll long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug cout<<"debug"<<endl;
ll Pow(ll x,ll y){return y==0?:x*pow(x,y-1);}
int main()
{
     ///"In the name of Allah,most gracious and most merciful"///

        ll i,j,x,y,z,count=0,sum=0,n,m;
        cin>>n;
        x=Pow(2,n);
        vector<ll>a(x);
        vector<pair<ll,ll> >v,v1,v2;
        for(ll i=0;i<x;i++)
        {
            cin>>a[i];
            v.pb(mp(a[i],i+1));
        }
        if(n==1){
           if(v[0].ff>v[1].ff)
            {
                cout<<v[1].ss<<endl;
            }
            else
            {
                cout<<v[0].ss<<endl;
            }
        }
        else {
        while(1){
        if(sum==0){
        for(ll i=0;i<v.size();i+=2)
        {
            if(v[i].ff>v[i+1].ff)
            v1.pb(mp(v[i].ff,v[i].ss));
            else
            v1.pb(mp(v[i+1].ff,v[i+1].ss));
        }
        sum=1;
        }
        else if(count==0)
        {
         for(ll i=0;i<v1.size();i+=2)
        {
            if(v1[i].ff>v1[i+1].ff)
            v2.pb(mp(v1[i].ff,v1[i].ss));
            else
            v2.pb(mp(v1[i+1].ff,v1[i+1].ss));
        }
         count=1;
         v1.clear();
        }
        else if(count==1)
        {
         for(ll i=0;i<v2.size();i+=2)
        {
            if(v2[i].ff>v2[i+1].ff)
            v1.pb(mp(v2[i].ff,v2[i].ss));
            else
            v1.pb(mp(v2[i+1].ff,v2[i+1].ss));
        }
         count=0;
         v2.clear();
        }
         if(v1.size()==2 || v2.size()==2)
         break;
        }
        if(v1.size()==2)
        {
            if(v1[0].ff>v1[1].ff)
            {
                cout<<v1[1].ss<<endl;
            }
            else
            {
                cout<<v1[0].ss<<endl;
            }
        }
        else if(v2.size()==2)
        {
             if(v2[0].ff>v2[1].ff)
            {
                cout<<v2[1].ss<<endl;
            }
            else
            {
                cout<<v2[0].ss<<endl;
            }
        }

        }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vb=vector<bool>;using vvb=vector<vb>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;

#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()

// cin and cout of a vector
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}

// for loop
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revv(i, a, b) for (int i = (int)(b-1); i >= (int)(a); i--)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
// #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
// #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
// #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
// #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)

// Yes/no
#define cho(n,a,b) cout<< ((n)?a:b)<<endl;
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}

#define pb push_back
#define rsortv(v) sort((v).rbegin(), (v).rend())
#define sortv(v) sort((v).begin(), (v).end())

// max/min
template<class T, class U>bool chmax(T&a,const U&b){bool x=a<b;x?a=b:b;return x;}template<class T, class U>bool chmin(T&a,const U&b){bool x=a>b;x?a=b:b;return x;}
template<class T, class U>auto max(const T&a,const U&b){return a<b?b:a;}template<class T, class U>auto min(const T&a,const U&b){return a<b?a:b;}

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

template<class T>auto minv(const T&a){return *min_element(all(a));}
template<class T>auto smod(T a, T b){a %= b; if (a < 0); a+= b; return a;}
template<class T>auto maxv(const T&a){return *max_element(all(a));}
template<class T>auto sumv(const T&a){ll sum = 0; for(auto x: a) sum+= x; return sum;}

template<class T>void pr(const T&a){cout << a << endl;}
template<class T>void pr_precise(const T&a){cout.precision(10); cout << fixed << a << endl;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
// ll M = 1000000007;
ll M = 998244353;

int main() {
    int cases = 1;
    // cin >> cases;

    rep(CASE, cases){
        int p;
        cin >> p;
        int n = (1<< (p-1));
        vl A(n);
        vl B(n);

        cin >> A;
        cin >> B;

        ll a = maxv(A);
        ll b = maxv(B);
        if (a < b) pr(1 + std::distance(A.begin(), std::max_element(A.begin(), A.end())));
        else pr(1 + n+ std::distance(B.begin(), std::max_element(B.begin(), B.end())));
        // pr(min(a,b));

        // pr(A);
        // pr(B);
        // pr(C);

    }
    return 0;
}


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

int main(){

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

    if(a==b){
        cout << c << endl;
    }
    else if(b == c){
        cout << a <<endl;
    }
    else if(c == a){
        cout << b << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;

}

///Bismillahir Rahmanir Rahim
/*
    Author: Tanzin Ahammad
*/
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        gcd(a,b)        __gcd(a,b)
#define        lcm(a,b)        (a*b)/gcd(a,b)
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        mem(a,b)        memset(a, b, sizeof(a))
#define        uniq(v)         (v).erase(unique(all(v)),(v).end())
#define        mchk(mask,pos)  (mask & (1ll<<pos))
#define        mset(mask,pos)  (mask bitor (1ll<<pos))
#define        munset(mask,pos) (mask ^ (1ll<<pos))
#define        print_case      cout<<"Case "<<cs<<": "
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
const int N = 1e6+5;
const int mod = (int)  1e9 + 7;
ll arr[N];
ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}

int main()
{
    IOS;

    ll tc,n,x,i,j;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    sc st;
    if(s1==s3)
    {
           cout<<"UNSOLVABLE";
           return 0;
    }
    for(i=0;i<sz(s1);i++)
    {
           st.insert(s1[i]);
    }
    for(i=0;i<sz(s2);i++)
    {
           st.insert(s2[i]);
    }
    for(i=0;i<sz(s3);i++)
    {
           st.insert(s3[i]);
    }
    if(sz(st)>10)
    {
         cout<<"UNSOLVABLE";
    }
    else
    {
           vector<char> vt;
           for(auto pr:st)
           {
                 vt.pb(pr);
           }
           string num="0123456789";
           ll f=0,n1,n2,n3;
           do
           {
                  map<char,ll>mp;
                  for(i=0;i<sz(vt);i++)
                  {
                         mp[vt[i]]=(num[i]-'0');
                  }
                  n1=0,n2=0,n3=0;
                  ll f1=0;
                  for(i=0;i<sz(s1)&&f1==0;i++)
                  {
                         if(i==0&&mp[s1[i]]==0)
                         {
                                f1=1;
                                break;
                         }
                         n1=n1*10+mp[s1[i]];
                  }
                  for(i=0;i<sz(s2)&&f1==0;i++)
                  {
                         if(i==0&&mp[s2[i]]==0)
                         {
                                f1=1;
                                break;
                         }
                         n2=n2*10+mp[s2[i]];
                  }
                  for(i=0;i<sz(s3)&&f1==0;i++)
                  {
                         if(i==0&&mp[s3[i]]==0)
                         {
                                f1=1;
                                break;
                         }
                         n3=n3*10+mp[s3[i]];
                  }

                  if(f1==0&&n1+n2==n3)
                  {
                         f=1;break;
                  }

           }while(next_permutation(num.begin(),num.end()));
           if(f==1)
           {
                  cout<<n1<<endl<<n2<<endl<<n3;
           }
           else cout<<"UNSOLVABLE";
    }

    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m;if(n<0)n+=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

template<class T> class Math
{
public:
    vector<T>fact,invfact;
    Math( int n )
    {
        fact.resize(n);
        invfact.resize(n);
        fact[0] = invfact[0] = 1;
        for(int i=1;i<n;i++)
        {
            fact[i] = mod( i * fact[i-1] );
            invfact[i] = modinv( fact[i] );
        }
    }
    T modinv( T x, T m = MOD )
    {
        return expo(x,m-2,m);
    }
    T expo( T base, T exp, T m = MOD )
    {
        T res = 1;
        while( exp )
        {
            if( exp&1 )
                res = mod( res*base, m );
            base = mod( base*base, m );
            exp >>= 1;
        }
        return res;
    }
    T choose( T n, T k )
    {
        if( k < 0 || k > n ) return 0;
        T ans = fact[n];
        ans = mod( ans * invfact[n-k] );
        ans = mod( ans * invfact[k] );
        return ans;
    }
};

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

	int n,p;
	cin>>n>>p;

	if( p == 2 )
	{
		if( n == 1 )
			cout<<1,nl;
		else
			cout<<0,nl;
		return 0;
	}

	Math<ll> m(2005);

	ll ans = p-1;
	ans = mod( ans * m.expo(p-2,n-1) );
	cout<<ans,nl;

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

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

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

    if (h % m == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

vector<long long> A, B;

int main() {
    long long int n;
    cin >> n;
    long long A = 3ll;
    while (true) {
        if (n <= A)
            break;
        long long m = n - A;
        while (m % 5 == 0) {
            m /= 5;
        }
        if (m == 1) {
            int cnt = 0;
            m = A;
            while (m % 3 == 0) {
                m /= 3;
                cnt++;
            }
            int cnt2 = 0;
            m = n - A;
            while (m % 5 == 0) {
                m /= 5;
                cnt2++;
            }
            if (cnt >= 1 && cnt2 >= 1) {
                cout << cnt << " " << cnt2 << "\n";
                return 0;
            }
        }
        long long B = A * 3ll;
        if (B < A)
            break;
        A = B;
    }
    cout << "-1\n";
}

#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <climits>

#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using ld = long double;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<vl> dp(n + 1, vl(2));
  dp[0][0] = dp[0][1] = 1;
  rep(i, n){
    string s;
    cin >> s;
    if(s == "OR"){
      dp[i + 1][1] = dp[i][0] + dp[i][1] * 2;
      dp[i + 1][0] = dp[i][0];
    }else{
      dp[i + 1][1] = dp[i][1];
      dp[i + 1][0] = dp[i][0] * 2 + dp[i][1];
    }
  }
  cout << dp[n][1] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define endl ("\n")
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<lli>
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
int main() {
    fast
    lli t, n;
    t = 1;
    // cin>>t;
    while (t--) {
        cin>>n;
        n = pow(2, n);
        lli a[n], mx1 = 0, mx2 = 0, p, q;
        rep (i, 0, n) cin>>a[i];
        rep (i, 0, n/2) {
        	if (a[i] > mx1) {
        		mx1 = a[i];
        		p = i;
        	}
        }
        rep (i, n/2, n) {
        	if (a[i] > mx2) {
        		mx2 = a[i];
        		q = i;
        	}
        }
        if (mx1 > mx2) cout<<q + 1;
        else cout<<p + 1;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
using pss = pair<string, string>;
using pll = pair<ll, ll>;
using pls = pair<ll,string>;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define endl '\n';
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const long long mod = 1 * 1e18 + 7;
int main()
{
    IO;
    ll i=0, j=0, m=0, n=0, k=0, t=0;
    cin>>t;
    while(t--)
    {
        cin>>n;
        string s[3];
        for(i=0;i<3;i++)
        cin>>s[i];
        string ans="";
        ans.push_back('1');
        for(i=0;i<n;i++)
        ans.push_back('0');
        for(i=0;i<n;i++)
        ans.push_back('1');
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = 1LL << 30;
constexpr ll mod = 100000; //(ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
inline void init() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

map<char, int>mp;
string s[3];
bool rec(vector<int>v,int index=0) {
    if (index == mp.size()) {
        ll N[3] = { 0 };
        rep(i, 0, 2) {
            rep(j, 0, s[i].size()) {
                if (j == 0 && v[mp[s[i][j]]] == 0)return false;
                N[i] *= 10;
                N[i] += v[mp[s[i][j]]];
            }
        }
        N[2] = N[0] + N[1];
        ll  n = N[2];
        rrep(i, 0, s[2].size()) {
            if (v[mp[s[2][i]]] != (n % 10))return false;
            n /= 10;
        }
        if (n != 0)return false;
        rep(i, 0, 3)cout << N[i] << "\n";
        return true;
    }

    vector<bool>ok(10, true);
    rep(i, 0, v.size())if (v[i] > -1)ok[v[i]] = false;
    rep(i, 0, 10) {
        if (!ok[i])continue;
        v[index] = i;
        if (rec(v, index + 1))return true;
        v[index] = -1;
    }
    return false;
}
int main() {
    init();

    set<char>st;
    int index = 0;
    rep(i, 0, 3)cin >> s[i];
    rep(i, 0, 3)rep(j, 0, s[i].size())st.insert(s[i][j]);
    for (auto s : st) {
        mp[s] = index;
        index++;
    }
    if (st.size() > 10) {
        cout << "UNSOLVABLE" << "\n";
        return 0;
    }

    vector<int>v(mp.size(), -1);
    if(!rec(v)) {
        cout << "UNSOLVABLE" << "\n";
        return 0;
    }

    return 0;
}

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

vector<string> s(3), ss(3);
vector<bool> word(26, false), yet(10, false);
vector<int> n(26);

void dfs(int x) {
	if(x == 26) {
		ss[0] = ss[1] = ss[2] = "";
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < s[i].size(); j++) {
				ss[i] += n[s[i][j] - 'a'] + '0';
			}
		}
		if(ss[0][0] == '0' || ss[1][0] == '0' || ss[2][0] == '0') return;
		if(stoll(ss[0]) + stoll(ss[1]) == stoll(ss[2])) {
			cout << ss[0] << endl << ss[1] << endl << ss[2] << endl;
			exit(0);
		}
		return;
	}
	if(!word[x]){dfs(x+1);return;}
	for(int i = 0; i < 10; i++) {
		if(yet[i]) continue;
		n[x] = i;
		yet[i] = true;
		dfs(x + 1);
		yet[i] = false;
	}
}

int main() {
	cin >> s[0] >> s[1] >> s[2];
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < s[i].size(); j++) {
			word[s[i][j] - 'a'] = true;
		}
	}
	for(int i = 0; i < 26; i++) {
		if(word[i]) {
			dfs(i);
			break;
		}
	}
	puts("UNSOLVABLE");
	return 0;
}


// Problem: F - GCD or MIN
// Contest: AtCoder - AtCoder Beginner Contest 191
// URL: https://atcoder.jp/contests/abc191/tasks/abc191_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const int max_n = 1e5 + 9;
const int mod = 1e9 + 7;
const int inf = 1e9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
	}

	sort(a , a+n);

	map<int , int> m;

	for(int i = 0 ; i < n ; i++){
		for(ll j = 1 ; j*j <= a[i] ; j++){
			if(a[i] % j == 0){
				m[j] = __gcd(m[j] , a[i]);
				m[a[i]/j] = __gcd(m[a[i]/j] , a[i]);
			}
		}
	}

	int ans = 0;
	for(auto it : m){
		if(it.ff == it.ss && it.ff <= a[0])ans++;
	}
	cout << ans << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ; i++){
		solve();
	}
}

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

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

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

map<int, vi > M;
map<int, vi >::iterator it;

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

int main() {
  int n;
  S(n);

  int mn = 1000000000;
  rep(i,1,n+1) {
    int x;
    S(x);
    mn = min(mn, x);
    for(int j = 1; j * j <= x; j++) if(x % j == 0) {
      M[j].pb(x);
      if(j * j != x) M[x / j].pb(x);
    }
  }

  int ans = 0;
  for(it = M.begin(); it != M.end(); it++) {
    if(it->FF > mn) break;
    int g = 0;
    rep(i,0,it->SS.size()) {
      g = gcd(it->SS[i], g);
    }
    ans += g == it->FF;
  }
  P(ans);
  return 0;
}


#include<fstream>
#include<iostream>
#include<sstream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<queue>
#include<tuple>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<set>
#include<array>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using graph = vector<vector<int>>;
const long long MOD = 1000000007;
const long long INF = 1e18;
using ll = long long;
using P = pair<int,int>;
using matrix = vector<vector<ll>>;

void chmin(int &x,int y){ x = min(x,y); }

int digit(ll x){
  int count = 1;
  while(x/10>0){
    count ++;
    x /= 10;
  }
  return count;
}

bool prime(ll x){
  if(x==1) return false;
  for(ll i=2;i*i<=x;i++){
    if(x%i==0) return false;
  }
  return true;
}

void decom(ll x,map<ll,int> &hatano){
  for(ll i=2;i*i<=x;i++){
    if(x%i==0&&prime(i)){
      while(x%i==0){
      x /= i;
      hatano[i] ++;
    }
    }
  }
  if(x!=1) hatano[x] ++;
}

ll speedpow(ll x,ll y){
  ll res = 1;
  ll test = x;
  for(int i=0;i<31;i++){
    if(y&(1<<i)) res *= test;
    res = res%MOD;
    test = (test*test)%MOD;
  }
  return res;
}

ll combination(ll x,ll y){
  ll test = 1;
  ll test1 = 1;
  for(ll i=0;i<y;i++){
    test = (test*(x-i))%MOD;
    test1 = (test1*(i+1LL))%MOD;
  }
  return (test * speedpow(test1,MOD-2))%MOD ;
}

int euclid(int x,int y){
  if(y==0) return x;
  return euclid(y,x%y);
}

//行列累乗

matrix mul(matrix &a, matrix &b) {
  int p = a.size();
    matrix res(p, vector<long long>(p, 0));
    for(int i = 0; i < p; i++)
        for(int j = 0; j < p; j++)
            for(int k = 0; k < p; k++)
                (res[i][j] += a[i][k] * b[k][j]) %= MOD;
    return res;
}

matrix pow(matrix m, long long k) {
  int p = m.size();
    matrix res(p, vector<long long>(p, 0));
    for(int i = 0; i < p; i++)
        res[i][i] = 1; // 単位行列にする

    while(k > 0) {
        if(k & 1) res = mul(res, m);
        m = mul(m, m);
        k >>= 1;
    }
    return res;
}

int main(){
    int n,m,q;cin >> n >> m >> q;
    int v[n],w[n];
    vector<P> hatano;
    int x[m];
    vector<P> konishi;

    int l[q],r[q];
    rep(i,n){
      cin >> w[i] >> v[i];
      hatano.push_back(make_pair(v[i],w[i]));
    }

    sort(hatano.rbegin(),hatano.rend());
    rep(i,m){
      cin >> x[i];
      konishi.push_back(make_pair(x[i],i));
    }
    sort(konishi.begin(),konishi.end());
    vector<int> ans;

    rep(i,q){
      cin >> l[i] >> r[i];
      l[i] --;r[i] --;
    }
    rep(i,q){
      int test=0;
      vector<bool> check(m,true);
      for(int s=l[i];s<=r[i];s++) check[s] = false;

        rep(j,n){
          rep(k,m){
            if(konishi[k].first>=hatano[j].second&&check[konishi[k].second]){
              test += hatano[j].first;
              check[konishi[k].second] = false;
             // cout << hatano[j].first << endl;
              break;
            }
          }
        }
        ans.push_back(test);
      //  cout << endl;
    }

    for(auto e:ans) cout << e << endl;

  }

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }

template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

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

//-------------------------- Libraries --------------------------//

//---------------------------- Solve ----------------------------//

void solve() {
    int N, M, Q;
    cin >> N >> M >> Q;

    vector<pair<int, int>> vw(N);
    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;
        vw[i] = {v, w};
    }
    sort(vw.rbegin(), vw.rend());

    vector<int> x(M);
    for (int i = 0; i < M; i++) cin >> x[i];

    while (Q--) {
        int L, R;
        cin >> L >> R;
        L--; R--;
        multiset<int> se;
        for (int i = 0; i < M; i++) {
            if (L <= i && i <= R) continue;
            se.insert(x[i]);
        }
        int ans = 0;
        for (auto [v, w] : vw) {
            auto it = se.lower_bound(w);
            if (it != se.end()) {
                ans += v;
                se.erase(se.find(*it));
            }
        }
        cout << ans << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}


#include<iostream>
#include<unordered_set>
#include<vector>
#include<map>
using namespace std;
int main()
{
    char x,y;
    cin>>x>>y;
    if(x == y)
        cout<<x<<"\n";
    else if((x == '0' && y == '1') || (x == '1' && y == '0'))
        cout<<"2\n";
    else if((x == '0' && y == '2') || (x == '2' && y == '0'))
        cout<<"1\n";
    else
        cout<<"0\n";
    return 0;
}
/*

*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}
void OUTX2(){cout << endl;}
template<typename Head, typename... Tail>
void OUTX2(Head&& head, Tail&&... tail)
{
    cout << head << ' ';
    OUTX2(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

int main()
{
    ll M, H;
    INX(M, H);
    OUTX((H % M == 0 ? "Yes" : "No"));

    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using VI = vector<int>;
using VLL = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
using Graph2 = vector<vector<int>>;
using PQ = priority_queue<int>;
template<typename T>istream& operator>>(istream&s,vector<T>&v){for(auto &i: v)s>>i;return s;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
bool second_compare(P a,P b){if(a.second!=b.second){return a.second<b.second;} else return true;}

int main() {
    int n;
    cin >> n;
    VI ans(n);
    ans[0] = 2*3;
    ans[1] = 2*5;
    ans[2] = 3*5;
    int idx = 3;
    for (int i = 16; ; i++) {
        if (idx >= n) break;
        // 倍数なら追加
        if (i % (2*3) == 0 || i % (2*5) == 0 || i % (3*5) == 0) {
            ans[idx] = i;
            idx++;
        }
    }
    for (auto e: ans) {
        cout << e << ' ';
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
long long n, sum;
int main()
{
    cin >> n;
    for (long long i=1000, ert=0; ; i*=1000, ert++) {
        sum+=(min(n, i-1)-i/1000+1)*ert;
        if (n<i) {
            cout << sum << "\n";
            return 0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
ll n;
ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}
int main(){
	n=read();
	ll ans=1;
	for(ll i=2;i<=n;++i) ans=ans*i/gcd(ans,i);
	printf("%lld\n",ans+1);
	return 0;
}

/*

AtCoder Regular Contest 109

https://atcoder.jp/contests/arc109/tasks/arc109_a

By 242

*/

/*
　 　 ∧__∧  ☆・*。・゜+.・*。
　　 (´･ω･)        ☆・*。
　　 /ヽ○==○ _____ _____  ・゜+.・*。
　　/　　||　|100%||ＡＣ|        ☆・*。・*。
　　し'￣(_))￣(_))￣(_))￣
*/

/*
    fstream fcout;
    fcout.open("out.txt",ios::out);
*/

#include <bits/stdc++.h>
using namespace std;
#define Please return
#define AC 0;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define ALL(x) (x.begin(),x.end())
#define ff first
#define ss second
struct Ios
{
    Ios()
    {
        ios_base::sync_with_stdio(0);cin.tie(0);
    }
}__ios;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
void HI(int x){cout<<"HI "<<x<<'\n';};

//code start from here

int main()
{
    ll N;
    cin>>N;
    cout<<2329089562801<<'\n';
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long A, long long B){
    ll X = (A + B) / 2, Y = (A - B) / 2;
    cout << X << " " << Y << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}

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

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N,W; cin >> N>>W;
   bool ok = true;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> s(N),t(N),p(N); rep(i, N) cin >> s[i]>>t[i]>>p[i];
  vector<ll> im(200200,0);
  rep(i,N){
    im[s[i]]+=p[i];
    im[t[i]]-=p[i];
  }
  ll su=0;
  rep(i,200000){
    su+=im[i];
    if(su>W)ok=false;
  }

  cout << (ok?"Yes":"No") << endl;
}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define ninpo ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(cntainer) (int)cntainer.size()
#define tc int t;cin>>t;for(int i=0;i<t;++i)
#define ll long long
#define pii pair<int,int>
using namespace std;

/**/
void solve()
{
    ll n;
    cin>>n;
    map<int,ll> ct;
    for (int i = 0; i < n; i++){
        int a;
        cin>>a;
        ct[a]++;
    }
    ll ans= (n*(n-1))/2;
    for(auto i: ct)ans-=((i.second*(i.second-1))/2);
    cout<<ans;
}

int main()
{
       #ifndef ONLINE_JUDGE
           freopen("input.txt", "r", stdin);
           freopen("output.txt", "w", stdout);
       #endif
   ninpo;
//    tc
    solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define mod 1000000007
#define mod1 998244353
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

/*-------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll m) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b = b >> 1;} return res;}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
/*--------------------------------------------------------------------------------------------*/

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

	ll n;
	cin >> n;
	mk(arr, n, ll);
	map<ll, ll> m;
	for (ll i = 0; i < n; i++) {
		cin >> arr[i];
		m[arr[i]]++;
	}

	ll cnt = 0;
	ll total = n;
	for (auto i : m) {
		ll x = i.ss;
		ll temp = (total - x);
		cnt += (temp * x);
		total -= x;
	}

	cout << cnt << endl;

	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 998244353 ;
long double pie = acos(-1) ;
ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}

int main(){
  int n,k ;
  cin >> n >> k ;
  if(n<k){
    cout << 0 << endl ;
    return 0 ;
  }
  VV<ll> dp(n+1,V<ll>(2*n+1,0)) ;
  dp[0][0] = 1 ;
  for(int i=1;i<=n;i++){
    for(int j=i*2;j>=0;j--){
      ll sub = 0 ;
      if(j*2<=2*n) sub += dp[i][j*2] ;
      if(j>=2) sub += dp[i-1][j-2] ;
      dp[i][j] = sub%mod ;
    }
  }
  ll ans = dp[n][k] ;
  if(k>=2) ans = (ans-dp[n-1][k-2]+mod)%mod ;
  cout << ans << endl ;
}

#include "bits/stdc++.h"
using namespace std;
void solution() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> f(n + 1, vector<int> (n + 1, -1));
  auto dp = [&](auto &&self, int N, int K) -> int {
    if (K == 0) return N == 0;
    if (N <= K) return N == K;
    if (f[N][K] != -1) return f[N][K];
    return f[N][K] = (self(self, N - 1, K - 1) + self(self, N, K * 2)) % 998244353;
  };
  cout << dp(dp, n, k);
}
signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1;
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif
  // cin >> tc;
  while (tc --) { solution(); cout << "\n"; }
}


#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using VI = vector<int>;
using VLL = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
using Graph2 = vector<vector<int>>;
using PQ = priority_queue<int>;
template<typename T>istream& operator>>(istream&s,vector<T>&v){for(auto &i: v)s>>i;return s;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
bool second_compare(P a,P b){if(a.second!=b.second){return a.second<b.second;} else return true;}

int main() {
    int n;
    cin >> n;
    double x0, y0, xn, yn;
    cin >> x0 >> y0 >> xn >> yn;
    double Ox = (x0 + xn) / 2.0;
    double Oy = (y0 + yn) / 2.0;

    x0 -= Ox;
    y0 -= Oy;
    xn -= Ox;
    yn -= Oy;

    double r = sqrt(x0*x0 + y0*y0);
    double theta = atan2(y0, x0);
    double t = M_PI*2.0 / (double)n + theta;

    printf("%.10f %.10f\n", r*cos(t)+Ox, r*sin(t)+Oy);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fo(i, strt, end) for(i=strt;strt<end?i<end:i>end;strt<end?i+=1:i-=1)
#define deb(var) cout << #var << " = " << var << endl;
#define deba(i, arr, n) fo(i,0, n){cout << arr[i] << " ";}
#define all(arr) arr.begin(), arr.end()
#define rall(arr) arr.rbegin(), arr.rend()
#define autoDeb(arr) for(auto var:arr) cout<<var<<" ";
#define sa(arr,n) for(int var = 0; var < n; var++) cin >> arr[var];
#define yes cout << "YES\n"
#define no cout << "NO\n"
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
/*************************************/

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // file;
  ll n;
  cin>>n;
  ll arr[n];
  for(auto &i:arr) cin>>i;
//   autoDeb(arr);cout<<endl;
  ll sum=0;
//   int cs[n];
//   int css[n];
//   for(int i=0;i<n;i++){
//       sum+=arr[i];
//       cs[i]=sum;
//   }
//   sum=0;
//   for(int i=0;i<n;i++){
//       sum+=cs[i];
//       css[i]=sum;
//   }
  ll mx=-1;
  ll CS=0;
  ll CSS=0;
  for(int i=0;i<n;i++){
      mx=max(mx,arr[i]);
      CS+=arr[i];
      CSS+=CS;
      cout<<fixed<<mx*(i+1)+CSS<<endl;

  }
//   sum=accumulate(arr,arr+n,sum);
//   cout<<sum<<endl;

  return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <cstdio>
#include <functional>
#include <queue>
#include <tuple>
using namespace std;

int main() {
    int R, C;
    scanf("%d%d", &R, &C);
    int A[250000], B[250000];
    int dist[500000], seen[500000] = {0}, cost, pt, to_hide = R * C;
    priority_queue<pair<int, int>, vector<pair<int, int>>,greater<pair<int, int>>>queue;
    for(int i = 0; i < R * C; ++i)
        if(i % C != C - 1) scanf("%d", &A[i]);
    for(int i = 0; i < (R - 1) * C; ++i) scanf("%d", &B[i]);
    for(int i = 1; i < to_hide + to_hide; ++i) dist[i] = 10000000;
    queue.emplace(pair<int, int>(0, 0));
    while(!queue.empty()) {
        tie(cost, pt) = queue.top();
      	if(pt == to_hide - 1)break;
        queue.pop();
        seen[pt] = true;
        if(pt < to_hide) {
            if(!seen[pt + 1] && pt % C != C - 1) {
                if(cost + A[pt] < dist[pt + 1]) {
                    dist[pt + 1] = cost + A[pt];
                    queue.emplace(pair<int, int>(dist[pt + 1], pt + 1));
                }
            }
            if(!seen[pt - 1] && pt % C != 0) {
                if(cost + A[pt - 1] < dist[pt - 1]) {
                    dist[pt - 1] = cost + A[pt - 1];
                    queue.emplace(pair<int, int>(dist[pt - 1], pt - 1));
                }
            }
            if(!seen[pt + C] && pt < to_hide - C) {
                if(cost + B[pt] < dist[pt + C]) {
                    dist[pt + C] = cost + B[pt];
                    queue.emplace(pair<int, int>(dist[pt + C], pt + C));
                }
            }
            if(!seen[pt + to_hide] && cost + 1 < dist[pt + to_hide]) {
                dist[pt + to_hide] = cost + 1;
                queue.emplace(pair<int, int>(dist[pt + to_hide], pt + to_hide));
            }
        } else {
            if(to_hide < pt - C && !seen[pt - C] && cost + 1 < dist[pt - C]) {
                dist[pt - C] = cost + 1;
                queue.emplace(pair<int, int>(cost + 1, pt - C));
            }
            if(!seen[pt - to_hide] && cost < dist[pt - to_hide]) {
                dist[pt - to_hide] = cost;
                queue.emplace(pair<int, int>(cost, pt - to_hide));
            }
        }
    }
    printf("%d\n", dist[to_hide - 1]);
}

// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, ss) for (int i = (ss);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

# ifndef ONLINE_JUDGE
template<typename T>
void vdeb(std::vector<T> &bb) {
    for (int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &bb) {
    for (int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

class UnionFind {
    int _n;
    int _size;
    std::vector<int> par_size;

    public:
    UnionFind() :_n(0), _size(0){}
    UnionFind(int n) : _n(n), _size(0), par_size(n, -1) {}

    int unite(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        a = root(a), b = root(b);
        if(a == b) return a;
        _size--;
        if(-par_size[a] < -par_size[b]) {
            par_size[b] += par_size[a];
            return par_size[a] = b;
        }
        else {
            par_size[a] += par_size[b];
            return par_size[b] = a;
        }
    }

    int root(int a) {
        assert(0 <= a && a < _n);
        if(par_size[a] < 0) return a;
        return par_size[a] = root(par_size[a]);
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return root(a) == root(b);
    }

    int size(int a) {
        assert(0 <= a && a< _n);
        return -par_size[root(a)];
    }

    int size() {return _size;}

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = root(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                        [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }
};

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector<ll> a(n);
    rip(i,n,0) cin >> a[i];
    vector<ll> b(n);
    UnionFind  uf(n);
    rip(i,n,0) cin >> b[i];
    rip(i,m,0) {
        int x, y; cin >> x >> y;
        --x;--y;
        uf.unite(x, y);
        uf.unite(y, x);
    }
    auto da = uf.groups();
    rip(i, da.size(), 0) {
        ll aa = 0, bb = 0;
        rip(j,da[i].size(), 0) {
            aa += a[da[i][j]];
            bb += b[da[i][j]];
        }
        if(aa != bb) {
            cout << "No" << endl;
            return  0;
        }
    }
    cout << "Yes" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
template <typename T>
T binpow(T base, T exp) {
    T result = 1;
    while (exp > 0) {
        if (exp & 1) result = (result * base);
        base = (base * base);
        exp >>= 1;
    }
    return result;
}
int main() {
    ios;
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ll n;
    cin >> n;
    ll counter = 0;
    map<ll, bool> mp;
    for (ll i = 2; i * i <= n; ++i) {
        ll x = i;
        for (ll j = 2;; ++j) {
            x *= i;
            if (x > n) break;
            if (mp.find(x) == mp.end()) {
                counter++;
                mp[x] = 1;
            }
        }
    }
    cout << n - counter << '\n';
    return 0;
}

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

int main() {
  long long n,num;
  cin >> n;

  if(n>=100000) num=100000;
  else num=n;

  set<long long> Set;
  long long tmp,ans=0;
  for(int i=2;i<num;i++){
    for(int j=2;j<34;j++){
      tmp = pow(i,j);
      if(tmp>n) break;
      Set.insert(tmp);
    }
  }

  cout << (n-Set.size()) << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,n,t,x;
    bool flag;
    cin >> t;
    while(t--)
    {
        cin >> n;
        map<int,bool>mp;
        for(i=0;i<n;i++)
        {
            cin >> x;
            mp[x] ^= 1;
        }
        if(n & 1)
        {
            cout << "Second\n";
            continue;
        }
        flag=1;
        for(auto it : mp)
        {
            if(it.second)
            {
                cout << "First\n";
                flag=0;
                break;
            }
        }
        if(flag)cout << "Second\n";
    }
    return 0;
}

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

using ll = long long;

// エラトステネスのふるい
vector<int> primes;
void sieve(int n) {
  set<int> primes_set;
  for (int i{2}; i <= n; ++i)
    primes_set.insert(i);
  for (int i{2}; i <= n; ++i) {
    if (primes_set.find(i) != primes_set.end()) {
      for (int j{i * 2}; j <= n; j += i) {
        primes_set.erase(j);
      }
    }
  }
  for (const auto &p : primes_set)
    primes.push_back(p);
}

int main() {
  sieve(50);

  int N;
  cin >> N;
  vector<int> X(N);
  for (int i{}; i < N; ++i) cin >> X[i];

  ll ans{numeric_limits<ll>::max()};
  int len = primes.size();
  for (int i{1}; i < (1 << len); ++i) {
    set<int> Y;
    for (int j{}; j < len; ++j) {
      if (i & (1 << j)) {
        Y.insert(primes[j]);
      }
    }
    bool succeed{true};
    for (const auto &x : X) {
      bool coprime{};
      for (const auto &y : Y) {
        if (x % y == 0) {
          coprime = true;
          break;
        }
      }
      if (!coprime) {
        succeed = false;
        break;
      }
    }
    if (succeed) {
      ll mul{1};
      for (const auto &y : Y) {
        mul *= y;
      }
      ans = min(ans, mul);
    }
  }

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


//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

template<class T>
vi compress(vector<T>&v)
{
	set<T> s;
	for (auto a: v) s.insert(a);
	vector<T> o(all(s));
	vi nv;
	for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
	return nv;
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=400010;
int m,n,ed,s;
bool bio[N];
vi ch[N];

void dfs(int i)
{
	ed+=ch[i].size();
	++s;
	bio[i]=1;
	for (auto a: ch[i]) if (!bio[a]) dfs(a);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		int a,b;
		cin>>a>>b;
		ch[a].pb(b);
		ch[b].pb(a);
	}
	int an=400000;
	for (int i=1;i<=400000;++i) if (!bio[i])
	{
		--an;
		ed=0;
		s=0;
		dfs(i);
		if (ed>=s*2) ++an;
	}
	cout<<an<<en;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int power(int a,int b,int md)
{
    int ans=1;

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

        ans%=md;
        a*=a;
        a%=md;
        b>>=1;
    }

    return ans;
}

int find(map<int,int> &mp,int x)
{
    //debug("T",x);
    if(!mp.count(x)) return x;
    if(mp[x]==x) return x;
    return mp[x]=find(mp,mp[x]);
}

void solve()
{
    int n;
    cin>>n;

    map<int,int> mp;

    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        //debug(mp);
        //debug(i);
        if(!mp.count(x)&&!mp.count(y)) mp[min(x,y)]=max(x,y);
        else if(!mp.count(x)) mp[x]=find(mp,y);
        else if(!mp.count(y)) mp[y]=find(mp,x);
        else
        {
           // debug("J",mp);
            int px=find(mp,x),py=find(mp,y);

            if(!mp.count(px))
            {
                mp[px]=py;
            }
            else if(!mp.count(py))
            {
                mp[py]=px;
            }

        }
       // debug(mp);
    }
    mp.erase(0);
    cout<<mp.size();
}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    int m;
    cin >> m;
    vector<ll> sousa11(m + 1), sousa12(m + 1), sousa21(m + 1), sousa22(m + 1);
    vector<ll> addx(m + 1), addy(m + 1);
    sousa11[0] = 1, sousa12[0] = 0;
    sousa21[0] = 0, sousa22[0] = 1;
    rep(i, m) {
        int op;
        cin >> op;
        int op11, op12;
        int op21, op22;
        if (op == 1) {
            op11 = 0, op12 = 1;
            op21 = -1, op22 = 0;
        } else if (op == 2) {
            op11 = 0, op12 = -1;
            op21 = 1, op22 = 0;
        } else if (op == 3) {
            op11 = -1, op12 = 0;
            op21 = 0, op22 = 1;
            int p;
            cin >> p;
            addx[i + 1] = 2 * p;
        } else if (op == 4) {
            op11 = 1, op12 = 0;
            op21 = 0, op22 = -1;
            int p;
            cin >> p;
            addy[i + 1] = 2 * p;
        }
        sousa11[i + 1] = op11 * sousa11[i] + op12 * sousa21[i];
        sousa12[i + 1] = op11 * sousa12[i] + op12 * sousa22[i];
        sousa21[i + 1] = op21 * sousa11[i] + op22 * sousa21[i];
        sousa22[i + 1] = op21 * sousa12[i] + op22 * sousa22[i];
        addx[i + 1] += op11 * addx[i] + op12 * addy[i];
        addy[i + 1] += op21 * addx[i] + op22 * addy[i];
    }

    int q;
    cin >> q;
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        b--;
        ll ansx = sousa11[a] * x[b] + sousa12[a] * y[b] + addx[a];
        ll ansy = sousa21[a] * x[b] + sousa22[a] * y[b] + addy[a];
        cout << ansx << " " << ansy << endl;
    }
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
#define pb push_back
#define T ll testx; cin>>testx; while(testx--)
#define print(name) for(auto t:name){cout<<t<<" ";}cout<<endl;
#define printii(name) for(auto t:name){cout<<t.first<<" "<<t.second<<endl;}
#define mod 1000000007
#define modx 998244353
#define inf 2000000000000000000
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define endl "\n"
#define popcount(x) __builtin_popcountll(x)
#define precise cout<<fixed<<setprecision(15)
const long double pi = acos(-1);
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
   int n,x,a,b;cin>>n;
   string s;cin>>s;
   string s1=s.substr(0,n);
   string t=s.substr(n);
   int q;cin>>q;
   ll ok=1;
   while(q--)
   {
    cin>>x>>a>>b;
    if(x==1){
      a--;b--;
      if(ok==1){
    if(a<=n-1&&b<=n-1)
    {
      swap(s1[a],s1[b]);
    }
    else if(a<=n-1&&b>n-1)
    {
      b-=n;swap(s1[a],t[b]);
    }
    else
    {
      a-=n;b-=n;swap(t[a],t[b]);
    }
  }
  else
  {
    if(a<=n-1&&b<=n-1)
    {
      swap(t[a],t[b]);
    }
    else if(a<=n-1&&b>n-1)
    {
      b-=n;swap(t[a],s1[b]);
    }
    else
    {
      a-=n;b-=n;swap(s1[a],s1[b]);
    }
  }
  }
    else
    {
      ok=1-ok;
    }
   }
   if(ok){cout<<s1<<t;}else{cout<<t<<s1;}

}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int maxn=2e5+4;
vector <int>e[maxn];
int dep[maxn];
ll bt[maxn];
struct node{
    int u,v;
}ee[maxn];
void dfs(int u,int pa){
    dep[u]=dep[pa]+1;
    for(auto v:e[u]){
        if(v!=pa)dfs(v,u);
    }
}
void dfs2(int u,int pa){
    for(auto v:e[u]){
        if(v!=pa){
            bt[v]+=bt[u];
            dfs2(v,u);
        }
    }
}
void f(int u,int v,int x){
    if(dep[u]>dep[v]){
        bt[u]+=x;
    }
    else{
        bt[1]+=x;
        bt[v]-=x;
    }
}
int main(){
    int n;
    scanf("%d",&n);

    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        ee[i].u=u;ee[i].v=v;
        e[u].pb(v);
        e[v].pb(u);
    }
    dfs(1,0);
    int q;
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        int t,id,x;
        scanf("%d%d%d",&t,&id,&x);
        int u=ee[id].u,v=ee[id].v;
        if(t==2)swap(u,v);
        f(u,v,x);
    }
    dfs2(1,0);
    for(int i=1;i<=n;i++)
        printf("%lld\n",bt[i]);

    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define ok cerr<<"ok"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
int n,x;
string s;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>n>>x;
    cin>>s;
    forn(i, n){
        if(s[i]=='o') ++x;
        else{
            --x;
            if(x<0) x=0;
        }
    }
    cout<<x<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

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

int main()
{
  int n, x;
  string s;
  cin >> n >> x >> s;

  for(int i = 0; i < n; ++i)
  {
    if(s[i] == 'o') x++;
    else
    {
      if(x > 0) x--;
    }
  }

  cout << x << endl;
}


#include <bits/stdc++.h>

using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;

#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--)

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
 cout << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " " ;
OUT(rest...);
   return;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const ll INF = 8000000000000000000;
int n,m,k;
ll N;
int h,w;
string S;
int a,b,c;
vi v;
int ans;
double x,y,z;
vector<int> G[1010101];
int score[1010101];
pair<long,long> Extended_Euclid(ll a, ll b)
{
  if(b == 0)return {1,0};
  pair<long,long> e = Extended_Euclid(b,a%b);
  return {e.second,e.first - a/b * e.second};
}

long long int get_mod(ll a, ll mod)
{
  return (a%mod + mod)%mod;
}

pair<long long int, long long int> calc(long long int b1, long long int mod1, long long int b2, long long int mod2)
{
  pair<long long int,long long int> e = Extended_Euclid(mod1,mod2);
  long long int d = e.first * mod1 + e.second * mod2;
  if( (b1-b2)%d != 0)return {-1,0};
  long long int lcm = mod1 * mod2 / d;
  long long tmp = (b2 - b1)/d * e.first % (mod2/d);
  long long x = get_mod(b1 + mod1 * tmp, lcm);
  return {x,lcm};
}
 pair<long long int, long long  int> CRT(vector<long long int> &b, vector<long long int> &mod)
{
  pair<long long int,long long int> ans = {0,1};
  int N = b.size();
  for(int i=0;i<N;i++)
  {
    ans = calc(ans.first,b[i],ans.second, mod[i]);
  }
  return ans;
}

void solve()
{
  ll X,Y,P,Q; IN(X,Y,P,Q);
  ll ans = INF;
  for(ll t1 = X;t1 < X+Y; t1++)for(ll t2 = P;t2 < P+Q;t2++)
  {
   auto e = calc(t1,2*(X+Y),t2,P+Q) ;
   if(e.first > 0)chmin(ans,e.first);
  }
  if(ans == INF)
  {
    cout << "infinity" << endl;
    return ;
  }
  cout << ans << endl;
}

signed main (int argc, char* argv[]) {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int cases=1;
   IN(cases);
   while(cases--)solve();
   //pri(ans);
   //for(auto c : ans){cout << c << endl;}
   //cout << fixed << setprecision(15) << ans << endl;
   return 0;
}

#include<bits/stdc++.h>
using namespace std;
namespace Sakurajima_Mai{
    #define ms(a) memset(a,0,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=2e9;//infi??,????inf????int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
    inline int qi(){
        int f=0,fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline ll ql(){
        ll f=0;int fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline db qd(){
        char c=getchar();int flag=1;double ans=0;
        while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
        if(c=='-') flag=-1,c=getchar();
        while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
        if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
        return ans*flag;
    }
}
namespace Read{
    #define si(a) scanf("%d",&a)
    #define sl(a) scanf("%lld",&a)
    #define sd(a) scanf("%lf",&a)
    #define ss(a) scanf("%s",a)
    #define rai(x,a,b) repi(i,a,b) x[i]=qi()
    #define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
    #define pi(x) printf("%d",x)
    #define pl(x) printf("%lld",x)
    #define ps(x) printf("%s",x)
    #define pc(x) printf("%c",x)
    #define pe() puts("")
}
namespace DeBug{
    #define MARK false
    #define DB if(MARK)
    #define pr(x) cout<<#x<<": "<<x<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!a&&!b)  return -1;
    if(!b){ x=1,y=0; return a; }
    ll d=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
ll solve(ll a,ll b,ll c)
{
    if(!c) return 0;
    ll g=__gcd(a,b);
    if(c%g) return -1;
    ll x,y;
    exgcd(a,b,x,y);
    x*=(c/g),y*=(c/g);
    return pos_mod(x,b/g);
}
int main()
{
    int T=qi();
    while(T--)
    {
         ll x=ql(),y=ql(),p=ql(),q=ql();
         ll ans=infl;
         for(ll i=p;i<=p+q-1;++i){
            ll res=solve(2*(x+y),p+q,i-x);
            if(res==-1) continue;
            gmn(ans,res*2*(x+y)+x);
         }
         for(ll i=x;i<=x+y-1;++i){
             ll res=solve(p+q,2*(x+y),i-p);
             if(res==-1) continue;
             gmn(ans,res*(p+q)+p);
          }
         if(ans==infl) puts("infinity");
         else pl(ans),pe();
    }
    return 0;
}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
#define ll long long int
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi 3.141592653589793238
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define precise(x) fixed<<setprecision(x)
#define mod 1000000007
#define mod2 998244353
#define endl "\n"

void solve()
{
    string s;
    cin>>s;
    cout<<s[1]<<s[2]<<s[0];
    return;
}
int main()
{
    FAST;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
        solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define maxa(v) *max_element(v, v + v.size())
#define mina(v) *min_element(v, v + v.size())
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;}
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;}

// s.top().second;

signed main()
 {

       run;

/*
open for mod factorial

     fac[0]=1;
       for(int i=1;i<100009;i++)
      {
         fac[i]=fac[i-1]*i;
          fac[i]%=mod;
      }
 */

/*
for sieve open this and use v_prime

       int pp=pow(10,6)+100000;
          Sieve(pp);

*/

 // USE v_factor For calculating factors

int  t=1;
 //cin>>t;
 while(t--)
{
         // vector< pair <int,int> > vp;
        //  map<int,int>mp; // x.second-->frequency
       //   set<int>st;

          int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
          int  h[100009]={0};

                //cin>>n;

                string s;
               cin>>s;

           //   vector<int>a(n,0),v;

              cout<<s[1]<<s[2]<<s[0]<<endl;
}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true ;c = getchar(); }
	while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
ll n, m, mm;
ll P;
inline ll quickpow(ll x, ll k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int main() {
	read(n), read(m); mm = 1ll * m * m; P = mm;
	ll ans = quickpow(10, n) / m;
	printf("%lld\n", ans);
	return 0;
}

#include <iostream>

using namespace std;

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

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

	if (a == b) {
	    c = b;
	} else {
	    c = 3 - a - b;
	}

	cout << c << endl;

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
//Do DEBUG OR NOT
#define DEBUG

#ifdef DEBUG
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#else
#define debug(...) true
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

//prototype declaration
ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m
ll gcd(ll a, ll b);//最大公約数 2引数
ll ngcd(vector<ll> a);
ll lcm(ll a, ll b);//最小公倍数 2引数
ll nlcm(vector<ll> numbers);
bool isPrime(ll x);//素数判定
ll digsum(ll n);//桁和
vector<ll> enum_div(ll n);//約数全列挙
ll stringcount(string s, char c);//特定文字カウント

ll pow_ten(ll n){
    ll x=1;
    for(ll i=0;i<n;i++){
        x*=10;
    }
    return x;
}

//__________________________main__________________________

int main(){
    ll N;
    cin>>N;
    ll i=0;
    ll times=1000;
    for(i=0;i<5;i++){
        if(N/times==0) break;
        times*=1000;
    }
    //debug(i);
    ll ans=0;
    if(i>0){
        for(ll j=1;j<i;j++){
            ans+=(pow_ten((j+1)*3)-pow_ten(j*3))*j;
            //debug(ans);
        }
        ans+=(N-pow_ten(i*3)+1)*i;
    }
    //debug(pow_ten(10));
    cout<<ans<<endl;

    return 0;
}

//__________________________functions_____________Ctrl+K,Ctrl+0
//繰り返し二乗法関数
ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m
    ll r=1;
    for(;k>0;k=k>>1){
        if(k&1) r=(r*n)%m;
        n = (n*n) % m;
    }
    return r;
}
//最大公約数 2引数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最大公約数 n引数
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
//最小公倍数 2引数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
//最小公倍数 n引数
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}
//桁和
ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
//約数全列挙
vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}
//特定文字カウント
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

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

int n;
vector<int> a, b;
vector<vector<int>> e;
vector<int> depth;
vector<ll> ans;

void dfs_depth(int v, int d) {
  depth[v] = d;
  for (auto nv : e[v]) {
    if (depth[nv] != -1) continue;
    dfs_depth(nv, d + 1);
  }
}

void dfs_ans(int v, ll tot) {
  tot += ans[v];
  ans[v] = tot;
  for (auto nv : e[v]) {
    if (depth[v] > depth[nv]) continue;
    dfs_ans(nv, tot);
  }
}

int main() {
  cin >> n;

  a.resize(n - 1);
  b.resize(n - 1);
  e.resize(n);
  rep(i, n - 1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;

    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }

  depth.assign(n, -1);
  dfs_depth(0, 0);

  ans.resize(n);

  int q;
  cin >> q;
  rep(i, q) {
    int t, e, x;
    cin >> t >> e >> x;
    e--;

    int ok, ng;
    if (t == 1) {
      //b[e]を通らない
      ok = a[e];
      ng = b[e];
    }
    else {
      //a[e]を通らない
      ok = b[e];
      ng = a[e];
    }

    if (depth[ok] < depth[ng]) {
      //根に足す
      ans[0] += x;
      ans[ng] -= x;
    }
    else {
      //部分木に足す
      ans[ok] += x;
    }
  }

  dfs_ans(0, 0);
  rep(i, n) cout << ans[i] << endl;
  return 0;
}


// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef pair<int,int> pii; typedef pair<ll,ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FOO(i,a,b) for(int i=(a);i<=int(b);++i)
#define OOF(i,a,b) for(int i=(a);i>=int(b);--i)
#define AI(x) (x).begin(),(x).end()
template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;}
template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;}
template<class V>void lisan(V&v){sort(AI(v));v.erase(unique(AI(v)),v.end());}
template<class V,class T>int lspos(const V&v,T x){return lower_bound(AI(v),x)-v.begin();}
template<class...T>void RI(T&...t){(...,(cin>>t));}
template<class...T>void PL(T...t){int c=sizeof...(T);if(!c){cout<<'\n';return;}(...,(cout<<t<<(--c?' ':'\n')));}
constexpr inline ll cdiv(ll x,ll m){return x/m+(x%m?(x<0)^(m>0):0);}
constexpr inline ll mpow(ll x,ll e,ll m){ll r=1;for(x%=m;e;e/=2,x=x*x%m)if(e&1)r=r*x%m;return r;}
#ifdef OWO
#define safe cerr<<"\033[1;32m"<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<" JIZZ\033[0m\n"
#define debug(args...) SDF(#args, args)
#define OIU(args...) ostream& operator<<(ostream&O,args)
#define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}
template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}
template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
#else
#pragma GCC optimize("Ofast")
#define safe ((void)0)
#define debug(...) ((void)0)
#endif
constexpr ll inf = 1e9, INF = 4e18;
const int N = 2e5 + 225, M = 1e9 + 7;
int t, n, a[N];

int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s; cin >> s;
	n = s.size();
	map<char, int> mp;
	ll ans = 0;
	OOF(i,n - 1, 0){
		mp[s[i]]++;
		if(i >= n - 2){
			continue;
		}
		if(s[i] == s[i+1] and s[i+1] != s[i+2]){
			ans += (n - (i + 2)) - (mp[s[i]] - 2);
			FOO(c,'a','z') mp[c] = 0;
			mp[s[i]] = n - i;
		}
	}
	cout << ans << '\n';
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

int n;
int a[501], reva[501];

int swap_op(int i) {
    iter_swap(reva + a[i], reva + a[i + 1]);
    iter_swap(a + i, a + i + 1);
    return i;
}

void solve() {
    vector<int> ops;

    bool o = true;
    for (int i = n; i >= 1; i--) {
        if (a[i] == i) continue;
        while ((reva[i] & 1) != o) { // temp swap
            ops.emplace_back(swap_op(2 - o));
            o = !o;
        }
        while (a[i] != i) {
            ops.emplace_back(swap_op(reva[i]));
            o = !o;
        }
        if (ops.size() > n * n) break;
    }

    cout << ops.size() << '\n';
    for (int x : ops) cout << x << ' ';
    cout << '\n';
}

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

#ifdef _SHIFTPSH
    freopen("_run/in.txt", "r", stdin), freopen("_run/out.txt", "w", stdout);
#endif

    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            reva[a[i]] = i;
        }
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;using ld=long double;constexpr const char nl='\n',sp=' ';

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // freopen("err.txt", "w", stderr);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int N;
  string S;
  cin >> N >> S;
  string cur;
  for (char c : S) {
    cur.push_back(c);
    if (sz(cur) >= 3 && cur.substr(sz(cur) - 3) == "fox") {
      cur.pop_back();
      cur.pop_back();
      cur.pop_back();
    }
  }
  cout << sz(cur) << nl;
  return 0;
}

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

#define int long long int
typedef pair<int, int> pii;
#define f(i,a,b) for(int i=a;i<b;i++)
#define fo(i,a,b) for(int i = a; i<=b;i+=1)
// #define Vector vector
#define rf(i,a,b)  for(int i=a;i>=b;i--)
#define vll vector<int>
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    stack<char> stk;

    char prev = '*', prevprev = '*';

    for(int i = 0; i < n; i++){
        if(stk.empty()){
            stk.push(s[i]);
        }
        else {
            if(s[i] == 'x' and stk.size() >= 2){
                prev = stk.top();
                stk.pop();
                prevprev = stk.top();
                stk.pop();
                if(prev == 'o' and prevprev == 'f'){

                }
                else {
                    stk.push(prevprev);
                    stk.push(prev);
                    stk.push(s[i]);
                }
            }
            else {
                stk.push(s[i]);
            }
        }
    }
    cout << stk.size() << nl;
    return ;
}
main()
{
    IO;
    int T = 1;
    // cin >> T;
    for(int c=1; c <= T; c++){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}