#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

using matrix = vector<vector<ll>>;

ll powmodp(ll x, ll n) {
    if (n==0) return 1;
    if (n%2) return x * powmodp(x,n-1) % mod;
    ll res = powmodp(x,n/2);
    return res * res % mod;
}

ll inv(ll x) {return powmodp(x,mod-2);}

ll N, M, K;
vector<ll> A, G[110];
ll p, half;

matrix E(ll n) {
    matrix res(n,vector<ll>(n));
    rep(i,n) res[i][i] = 1;
    return res;
}

void addmodp(ll &x, ll y) {x = (x + y) % mod;}

matrix prodmatrix(matrix x, matrix y) {
    ll H = x.size(), W = y[0].size(), sz = y.size();
    matrix res(H,vector<ll>(W));
    rep(i,H) rep(j,W) rep(k,sz) {
        addmodp(res[i][j], x[i][k] * y[k][j] % mod);
    }
    return res;
}
vector<ll> prodmatrix(matrix x, vector<ll> y) {
    matrix z(y.size(),vector<ll>(1));
    rep(i,y.size()) z[i][0] = y[i];
    matrix tmp = prodmatrix(x,z);
    vector<ll> res(tmp.size());
    rep(i,tmp.size()) res[i] = tmp[i][0];
    return res;
}
vector<ll> prodmatrix(vector<ll> x, matrix y) {
    matrix z(1,vector<ll>(x.size()));
    rep(i,x.size()) z[0][i] = x[i];
    matrix tmp = prodmatrix(z,y);
    vector<ll> res(tmp[0].size());
    rep(i,tmp[0].size()) res[i] = tmp[0][i];
    return res;
}

matrix powmodp(matrix x, ll n) {
    if (n==0) return E(x.size());
    if (n%2) return prodmatrix(x,powmodp(x,n-1));
    matrix res = powmodp(x,n/2);
    return prodmatrix(res,res);
}

void init() {
    cin >> N >> M >> K;
    A.resize(N);
    rep(i,N) cin >> A[i];
    rep(i,M) {
        ll x, y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    p = inv(M);
    half = inv(2);
}

int main() {
    init();
    matrix mat(N,vector<ll>(N));
    rep(i,N) {
        ll cnt = G[i].size();
        for (ll j : G[i]) mat[i][j] = p * half % mod;
        ll q = cnt * p % mod;
        q = q * half % mod;
        mat[i][i] = (1 + mod - q) % mod;
    }
    matrix F = powmodp(mat,K);

    vector<ll> res = prodmatrix(F,A);
    for (ll ans : res) cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace math{
    const int MOD = 1e9+7;
    const int MN = 10'100;
    int fact[MN], inv_fact[MN];
    int power(int a, int n) {
        int res = 1;
        for (;n; n >>= 1, a = (a * a) % MOD) if (n & 1) res = (res * a) % MOD;
        return res;
    }
    int inv(int a) { return inv_fact[a]*fact[a-1]%MOD; }
    void init_fact() {
        fact[0]=1;
        for (int i=1;i<MN;++i) fact[i] = fact[i-1]*i%MOD;
        inv_fact[MN-1] = power(fact[MN-1], MOD - 2);
        for (int i=MN-1; i>0;--i) inv_fact[i-1]=inv_fact[i]*i%MOD;
    }
    struct mint {
        int n;
        mint(int n): n(n){}
        mint(): n(0){}
        mint operator+(mint o){return (n + o.n) % MOD;}
        mint operator-(mint o){return (n - o.n % MOD + MOD) % MOD;}
        mint operator*(mint o){return (n * o.n) % MOD;}
        mint operator/(mint o){return o.n >= MN ? n * power(o.n, MOD - 2) % MOD : n * inv(o.n) % MOD;}
    };
};
using namespace math;
using mat = vector<vector<mint>>;
int n, m, k;
vector<int> g[100];
mat M;
mat operator*(mat A, mat B)
{
    mat ret(A.size(), vector<mint>(B[0].size()));
    for (int i = 0; i < A.size(); ++i)
    {
        for (int j = 0; j < B[0].size(); ++j)
        {
            for (int k = 0; k < B.size(); ++k)
                ret[i][j] = ret[i][j] + A[i][k] * B[k][j];
        }
    }
    return ret;
}
mat power(mat A, int n)
{
    mat ret(A.size(), vector<mint>(A.size()));
    for (int i = 0;  i < A.size(); ++i)
        ret[i][i] = 1;
    for (; n; A = A * A, n >>= 1)
    {
        if (n & 1) ret = ret * A;
    }
    return ret;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(false);
    cin>>n>>m>>k;
    M.resize(n, vector<mint>(n));

    mat A(1, vector<mint>(n));
    for (int i = 0; i< n;++i)
        cin>>A[0][i].n;

    for (int i = 0; i<m;++i)
    {
        int u, v; cin>>u>>v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init_fact();

    for (int i = 0; i < n;++i)
    {
        M[i][i] = mint(1) - mint(g[i].size()) / m / 2;
        for (int it: g[i])
        {
            M[it][i] = mint(1) / m / 2;

        }
    }

    mat Ans = A * power(M, k);
    for (int i = 0; i<n;++i)
        cout << Ans[0][i].n << '\n';
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

int main(void){
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::cout << a * d - b * c << std::endl;

    return 0;
}

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

int main() {
    int A, B; cin >> A >> B;
    cout << (2 * A + 100) - B << endl;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L
//cout << fixed << setprecision(10) << Min << endl << Max << endl;

int main() {
	ll N; cin >> N;
	if (N < 8) {
		cout << "-1" << endl; return 0;
	}
	ll ans5 = 0, ans3 = 0;
	ll tmp = 1;
	while (1) {
		tmp = tmp * 5;
		ll tmp2 = N - tmp;
		if (tmp2 < 3) {
			cout << "-1" << endl; return 0;
		}
		ans5++;

		ans3 = 0;
		while (tmp2 % 3 == 0) {
			tmp2 /= 3;
			ans3++;
		}
		if (tmp2 > 1) continue;
		else break;
	}
	cout << ans3 << " " << ans5 << endl;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    // int t {0};
    // cin >> t;
    // while (t--)
    // {
        int l {0};
        cin >> l;
        // long long int ans = C((long long int) l - 1, (long long int) 11);
        // cout << ans << endl;
        vector < vector <long long int> > C (l, vector <long long int> (12));
        C[0][0] = 1;
        for (int i = 1; i < 12; i++)
        {
            C[1][i] = 0;
        }
        for (int i = 1; i < l; i++)
        {
            C[i][0] = 1;
            for (int j = 1; j < 12; j++)
            {
                C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
            }
        }
        long long int ans = C[l - 1][11];
        cout << ans << endl;
    // }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 400005;
ll fac[55];
int d[55];
int v[55][55];
int fi(int x) {
    return d[x] < 0 ? x : d[x] = fi(d[x]);
}
void merge(int x,int y) {
    x = fi(x);
    y = fi(y);
    if (x == y) return;
    d[x] += d[y];
    d[y] = x;
}
void go() {
    int n, tar;
    cin >> n >> tar;
    fac[0] = 1;
    f1(50) {
        fac[i] = fac[i - 1] * i % mod;
    }
    f1(n) {
        fr(j,1,n+1) {
            cin >> v[i][j];
        }
    }
    memset(d, -1, sizeof(d));
    fr(j,1,n+1) {
            fr(k,1,n+1) {
                int f = 0;
                fr(i,1,n+1) {
                    if (v[i][j] + v[i][k] > tar) {
                        f = 1;
                        break;
                    }
                }
                if (!f) {
                    merge(j,k);
                }
            }
        }
    ll ans = 1;
    f1(n) {
        if (d[i] < 0) {
            ans *= fac[-d[i]];
            ans %= mod;
        }
    }
    memset(d, -1, sizeof(d));
    //f1(n) {
        fr(j,1,n+1) {
            fr(k,1,n+1) {
                int f = 0;
                fr(i,1,n+1) {
                    if (v[j][i] + v[k][i] > tar) {
                        f = 1;
                        break;
                    }
                }
                if (!f) {
                    merge(j,k);
                }
            }
        }
    //}
    f1(n) {
        if (d[i] < 0) {
            ans *= fac[-d[i]];
            ans %= mod;
        }
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }

}

//un_coder
#include<bits/stdc++.h>
typedef long long ll;
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define inf 1e18
using namespace std;
void solve();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
    freopen("output.txt", "w", stdout);
    #endif

    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }
    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}
void solve()
{
    int n,q;
    cin>>n>>q;
    vector<ll> a(n),low(n);
    for(auto &it:a)
        cin>>it;
    for(int i=0; i<n; i++)
        low[i]=a[i]-(i+1);
    for(int i=0; i<q; i++)
    {
        ll k;
        cin>>k;
        int idx=lower_bound(all(low),k)-low.begin();
        if(idx==n)
            cout<<a[n-1]+(k-low[n-1])<<"\n";
        else
            cout<<a[idx]-(low[idx]-k+1)<<"\n";
    }
}


#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;
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update>
#define int long long int
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 200001
vector<vector<pair<int,int>>>v(maxn);
vector<int>pre(maxn);
void dfs(int x,int p,int w)
{
    int val=w;
    if(p!=0)
    {
        val=val^pre[p];
    }
    pre[x]=val;
    for(auto itr:v[x])
    {
        if(itr.fi!=p)
        {
            dfs(itr.fi,x,itr.se);
        }
    }
}
int32_t main()
{
    fastIO;
    int n;
    cin>>n;
    int x,y,val,val1,ans=0;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y>>val;
        v[x].pb({y,val});
        v[y].pb({x,val});
    }
    dfs(1,0,0);

    vector<vector<int>>suf(n+1,vector<int>(61));
    for(int i=n;i>=1;i--)
    {
        for(int j=0;j<=60;j++)
        {
            val1=(int)1<<j;
            if(val1&pre[i])
            {
                suf[i][j]++;
            }
        }
        if(i<n)
        {
            for(int j=0;j<=60;j++)
            {
                suf[i][j]+=suf[i+1][j];
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=60;j++)
        {
            x=n-suf[i+1][j]-i-1;
            int val1=(int)1<<j;
            if(val1&pre[i])
            {
                x++;
                val=val1%mod;
                val=(x*val)%mod;
                ans=(ans+val)%mod;
            }
            else{
                val=val1%mod;
                val=(suf[i+1][j]*val)%mod;
                ans=(ans+val)%mod;
            }
        }
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define FORz(i,t,n) for(int i=t;i<=n;i++)
#define FORf(i,n,t) for(int i=n;i>=t;i--)
#define SCC(x) scanf("%d",&x)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
const int N=1e5+5;
const ll MOD=1e9+7;
// inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
//ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;}
//ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;}
void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }}
ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;}
// node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;}
//for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}}
//int find(int x){return a[x]==x?x:a[x]=find(a[x]);}
//void merge(int x,int y){a[find(y)]=a[find(x)];}
ll n,q,t,a,b,z;
string s,j;
int main()
{
    int n;
    cin>>n>>s>>q;
    j=s.substr(n,n)+s.substr(0,n);
    while(q--){
        cin>>t>>a>>b;
        a--,b--;
        if(t==1){
            char x=s[(a+z*n)%(2*n)];
            s[(a+z*n)%(2*n)]=s[(b+z*n)%(2*n)];
            s[(b+z*n)%(2*n)]=x;
            x=j[(a+!z*n)%(2*n)];
            j[(a+!z*n)%(2*n)]=j[(b+!z*n)%(2*n)];
            j[(b+!z*n)%(2*n)]=x;

        }
        else{
            z=!z;
        }
    }
    z?cout<<j:cout<<s;
}


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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  int a, b, w;
  cin >> a >> b >> w;

  w *= 1000;

  int ans_min = inf;
  int ans_max = 0;

  bool flag = false;

  repi(i, 1, 1e6 + 1) {
    if (a * i <= w && w <= b * i) {
      ans_min = min(ans_min, i);
      ans_max = max(ans_max, i);
      flag = true;
    }
  }

  if (flag) {
    cout << ans_min << " " << ans_max << endl;
  } else {
    cout << "UNSATISFIABLE" << endl;
  }

  return 0;
}

#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()

typedef int64_t ll;
typedef uint64_t ull;

using namespace std;

void one_case() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (auto& el : a) cin >> el;
    for (auto& el : b) cin >> el;

    ll A = a[0], B = 0;
    vector<ll> S;
    S.pb(a[0] * b[0]);
    for (int i = 1 ; i < n; ++i) {
        A = max(A, a[i]);
        S.pb(max(S[i - 1], b[i] * A));
    }
    for (auto& el : S) {
        cout << el << "\n";
    }

}

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

    int t = 1;
//    cin >> t;
    for (int i = 0; i < t; ++i) {
        one_case();
    }

    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll x = 1000;
  ll ans = 0;
  while(n+1 >= x){
    ans += n-(x-1);
    x *= 1000;
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

//#include <atcoder/all>

using namespace std;
// using namespace atcoder;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}
long long pow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = pow(m, n / 2);
        return t * t;
    } else {
        return pow(m, n - 1) * m;
    }
}
bool bitcheck(ll x, ll y) { return (x >> y) & 1; }

template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}

// using mint = modint1000000007;
struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
vector<vector<ll>> adj;
bool warfloyd(vector<vector<ll>> graph) {
    adj = graph;
    for (int k = 0; k < graph.size(); k++) {
        for (int i = 0; i < graph.size(); i++) {
            for (int j = 0; j < graph.size(); j++) {
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }
    REP(i, graph.size()) {
        if (adj[i][i] != 0) {
            return true;
        }
    }
    return false;
}

#define DEBUG(x) cerr << #x << ": " << x << endl

int main() {
    ll n;
    cin >> n;
    if (n < 1000) {
        cout << 0 << endl;
    } else if (n < 1000000) {
        cout << n - 1000 + 1 << endl;
    } else if (n < 1000000000) {
        cout << 1000000 - 1000 + 2 * (n - 1000000 + 1) << endl;
    } else if (n < 1000000000000) {
        cout << 1000000 - 1000 + 2 * (1000000000 - 1000000) + 3 * (n - 1000000000 + 1) << endl;
    } else if (n < 1000000000000000) {
        cout << 1000000 - 1000 + 2 * (1000000000 - 1000000) + 3 * (1000000000000 - 1000000000) +
                    4 * (n - 1000000000000 + 1)
             << endl;
    } else {
        cout << 1000000 - 1000 + 2 * (1000000000 - 1000000) + 3 * (1000000000000 - 1000000000) +
                    4 * (n - 1000000000000 + 1) + 1
             << endl;
    }
}


/*
 * @Author: FuTianyu
 * @Date: 2021-01-30 20:04:16
 * @Last Modified by: FuTianyu
 * @Last Modified time: 2021-01-30 20:10:50
 */
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
inline int read(){
    int sum=0,ff=1; char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') ff=-1;
        ch=getchar();
    }
    while(isdigit(ch))
        sum=sum*10+(ch^48),ch=getchar();
    return sum*ff;
}
inline void write(int x){
    if(x==0){
        putchar('0');
        return ;
    }
    char F[200];
    int tmp=x>0?x:-x,cnt=0;
    if(x<0) putchar('-');
    while(tmp>0)
        F[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0) putchar(F[--cnt]);
}
int main(){
    int a=read(),b=read(),c=read();
    int sum=0;
    if(c==0){
        while(1){
            if(a==0){
                cout<<"Aoki";
                return 0;
            }
            if(b==0){
                cout<<"Takahashi";
                return 0;
            }
            sum++;
            sum%=2;
            if(sum==1) a--;
            else b--;
        }
    }
    if(c==1){
        while(1){
            if(b==0){
                cout<<"Takahashi";
                return 0;
            }
            if(a==0){
                cout<<"Aoki";
                return 0;
            }
            sum++;
            sum%=2;
            if(sum==0) a--;
            else b--;
        }
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 300010
const int MOD = 1000000007;

int ar[maxn], tree[4 * maxn];

int doit(int a, int b) {
    return a ^ b;
}

void build(int start, int end, int index = 1) {
    if (start == end) {
        tree[index] = ar[start];
        return;
    }
    int mid = start + end >> 1;
    build(start, mid, 2 * index);
    build(mid + 1, end, 2 * index + 1);
    tree[index] = doit(tree[2 * index], tree[2 * index + 1]);
}

int queryTree(int start, int end, int l, int r, int index = 1) {
    if (r < start or l > end)
        return 0;

    if (l <= start and r >= end)
        return tree[index];

    int mid = start + end >> 1;
    return doit(queryTree(start, mid, l, r, 2 * index), queryTree(mid + 1, end, l, r, 2 * index + 1));
}

void update(int start, int end, int x, int val, int index) {
    if (x < start or x > end)
        return;
    if (start == end) {
        tree[index] ^= val;
        return;
    }
    int mid = start + end >> 1;
    update(start, mid, x, val, 2 * index);
    update(mid + 1, end, x, val, 2 * index + 1);
    tree[index] = doit(tree[2 * index], tree[2 * index + 1]);
}

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

    for (int i = 0; i < n; ++i) {
        cin >> ar[i];
    }
    build(0, n - 1);
    for (int i = 0; i < q; ++i) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1) {
            update(0, n - 1, x - 1, y, 1);
        } else {
            cout << queryTree(0, n - 1, x - 1, y - 1, 1) << endl;
        }
    }

}

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

    int t = 1;
//    cin >> t;

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


#include<bits/stdc++.h>
using namespace std;
typedef double db;
const int N = 1e5 + 5;
int n, m, k;
db ans = 0;
db a[N];
db b[N];
bool vis[N];
int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= k; ++i) {
		int t;
		cin >> t;
		vis[n-t] = 1;
	}
	db ans1 = 0, ans2 = 0;
	for (int i = 1; i <= n; ++i) {
		if (vis[i]) {
			a[i] = 1, b[i] = 0;
		}
		else {
			a[i] = ans1 / m;
			b[i] = ans2 / m + 1;
		}
		ans1 += a[i], ans2 += b[i];
		if (i >= m) {
			ans1 -= a[i - m];
			ans2 -= b[i - m];
		}
	}
	if (abs(a[n] - 1.0) < 1e-6)puts("-1");
	else printf("%.4lf\n", b[n] / (1.0 - a[n]));

}

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef vector<VPi> VVPi;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(pair<T, T>& a, pair<T, T> b) {
	if (max(a.F, a.S) > max(b.F, b.S)) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << " " << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
#ifdef LOCAL
	os << "{";
#endif
	rep(i, v.size()) {
		if (i) os << " ";
		os << v[i];
	}
#ifdef LOCAL
	os << "}";
#endif
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
#ifdef LOCAL
#define dbg(x) cerr << #x << ": " << (x) << '\n'
#define say(x) cerr << (x) << '\n'
#else
#define dbg(x)
#define say(x)
#endif
void init_main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	if (freopen("in.txt", "r", stdin) == NULL) {
		cerr << "no inputfile found" << '\n';
	}
	if (freopen("out.txt", "w", stdout) == NULL) {
		cerr << "no outputfile found" << '\n';
	}
	if (freopen("err.txt", "w", stderr) == NULL) {
		cerr << "no errputfile found" << '\n';
	}
#endif
}
string solve(bool a) { return ((a) ? "Yes" : "No"); }

int main() {
	init_main();
	int n;
	int ans = INF;
	cin >> n;
	Vi t(n);
	cin >> t;
	int sum = 0;
	rep(i, n) { sum += t[i]; }
	VVi dp(n + 1, Vi(sum / 2 + 5, 0));
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, sum / 2 + 2) {
			if (dp[i][j]) {
				dp[i + 1][j] = 1;
				if (j + t[i] < sum / 2 + 1) {
					dp[i + 1][j + t[i]] = 1;
				}
			}
		}
	}
	dbg(dp);
	rep(i, sum / 2 + 3) {
		if (dp[n][i]) chmin(ans, max(i, sum - i));
	}
	cout << ans << endl;
}
/*
n^2 -> nT
dp[at][flag]->(a,b)
*/


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
using ll = long long;
int n, m, q, t[N], x[N], y[N], dic[N], L;
int a[N], b[N];
ll d[4][N];
void add(int idx, int x, int v) {
    for(int i = x; i <= L; i += i & -i) d[idx][i] += v;
}
ll get(int idx, int x) {
    ll res = 0;
    for(int i = x; i; i -= i & -i) res += d[idx][i];
    return res;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= q; i++) {
        cin >> t[i] >> x[i] >> y[i];
        dic[i] = y[i];
    }
    dic[q + 1] = 0;
    sort(dic + 1, dic + q + 2);
    L = unique(dic + 1, dic + q + 2) - dic - 1;
    add(0, 1, n);
    add(2, 1, m);
    // for(int j = 0; j < 4; j++) {
    //     for(int i = 1; i <= L; i++) cout << get(j, i) - get(j, i - 1) << " ";
    //     cout << endl;
    // }
    // cout << endl;
    ll ans = 0;
    for(int i = 1; i <= q; i++) {
        int np = lower_bound(dic + 1, dic + L + 1, y[i]) - dic;
        // cout << t[i] << " " << x[i] << " " << y[i] << " " << np << endl;
        if(t[i] == 1) {
            int p = lower_bound(dic + 1, dic + L + 1, a[x[i]]) - dic;
            // for(int i = 1; i <= L; i++) cout << get(2, i) << endl;
            // cout << np << " " << p << endl;
            ans += get(2, np) * y[i] -  get(2, p) * a[x[i]];
            ans -= get(3, np) - get(3, p);
            add(0, p, -1);
            add(0, np, 1);
            add(1, p, -a[x[i]]);
            add(1, np, y[i]);
            a[x[i]] = y[i];
        } else {
            int p = lower_bound(dic + 1, dic + L + 1, b[x[i]]) - dic;
            ans += get(0, np - 1) * y[i] - get(0, p - 1) * b[x[i]];
            ans -= get(1, np - 1) - get(1, p - 1);
            // cout << get(0, np - 1) * y[i] - get(0, p - 1) * b[x[i]] << " " << get(1, np - 1) - get(1, p - 1) << endl;
            add(2, p, -1);
            add(2, np, 1);
            add(3, p, -b[x[i]]);
            add(3, np, y[i]);
            b[x[i]] = y[i];
        }
        cout << ans << endl;
        // for(int j = 0; j < 4; j++) {
        //     for(int i = 1; i <= L; i++) cout << get(j, i) - get(j, i - 1) << " ";
        //     cout << endl;
        // }
        // cout << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#include <algorithm>
#define max(p, q) ((p)>(q)?(p):(q))
#define min(p, q) ((p)<(q)?(p):(q))
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define INF LLONG_MAX;
#define MOD 1000000007
using ll = long long;
using ld = long double;
using namespace std;

int main()
{
    ll N, C;
    cin >> N >> C;
    vector<pair<ll, ll>> event;
    for (ll i = 0; i < N; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        event.emplace_back(a - 1, c);
        event.emplace_back(b, -c);
    }
    sort(event.begin(), event.end());
    ll ans = 0, fee = 0, t = 0;
    for (auto [x, y] : event)
    {
        if (x != t)
        {
            ans += min(C, fee) * (x - t);
            t = x;
        }
        fee += y;
    }
    cout << ans << endl;
    return 0;
}


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

bool HasSevenInDecimal(int n) {
    while (n != 0) {
        if (n % 10 == 7) {
            return true;
        }
        n = n / 10;
    }
    return false;
}

bool HasSevenInOctal(int n) {
    while (n != 0) {
        if (n % 8 == 7) {
            return true;
        }
        n = n / 8;
    }
    return false;
}

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

    int answer = 0;
    for (int i = 1; i <= N; ++i) {
        if (HasSevenInDecimal(i)) {
            continue;
        }
        if (HasSevenInOctal(i)) {
            continue;
        }
        answer++;
    }

    cout << answer << endl;

}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
#define maxn 200001

int N;
int pow8[maxn];

string to_octal(int n){
	string ans = "";
	DEC(i,6,0){
		ans += to_string(n / pow8[i]);
		n %= pow8[i];
	}
	return ans;
}
int32_t main(){
	fast;

	cin >> N;

	pow8[0] = 1;
	FOR(i,1,6) pow8[i] = pow8[i-1] * 8;

	int ans = 0;
	FOR(i,1,N){
		bool yes = 1;
		aFOR(j,to_string(i)){
			if (j == '7') yes = 0;
		}
		aFOR(j,to_octal(i)){
			if (j == '7') yes = 0;
		}
		ans += yes;
	}
	cout << ans << '\n';
}


#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;
#define floop(i,a,n) for (ll i=a;i<n;i++)
#define rfloop(i,a,n) for (ll i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2;
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;
				if(spf[j]==j)
				spf[j]=i;
			}
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int main()
{
	ll n;
	cin>>n;
	vec a(n);
	floop(i,0,n)
	cin>>a[i];
	sort(all(a));
	ll ans=0;
	vec pre(n,0),suf(n,0);
	pre[0]=a[0];
	floop(i,1,n)
	pre[i]=pre[i-1]+a[i];

	suf[n-1]=a[n-1];
	rfloop(i,0,n-1)
	suf[i]=suf[i+1]+a[i];

	floop(i,0,n)
	{
		//ans+=(i+1)*a[i]-pre[i];
		ans+=suf[i]-(n-i)*a[i];
		//cout<<ans<<" ";
	}
	cout<<ans<<"\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define all(v) v.begin(),v.end()
#include<bits/stdc++.h>
using namespace std;
int main(){
	ll n,r=0;
	cin>>n;
	vector<ll>a(n);
	for(ll&i:a)cin>>i;
	sort(all(a));
	for(ll i=n-1;i>=0;i--)
	r+=a[i]*i;
	for(ll i=0;i<n;i++)
	r-=(n-i-1)*a[i];
	cout<<r;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
	ll t=1000;
	while(t--)
	{
		ll x,y,a,b;
		cin>>x>>y>>a>>b;
		while(x<a)
		{
			putchar('D');
			x++;
		}
		while(y>b)
		{
			putchar('L');
			y--;
		}
		while(y<b)
		{
			putchar('R');
			y++;
		}
		while(x>a)
		{
			putchar('U');
			x--;
		}
		puts("");
		fflush(stdout);
		ll d;
		cin>>d;
	}
	return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define dd double
#define ll long long int
#define ull unsigned long long
#define lld long double
#define setpre(n) cout << std::setprecision(n);
#define flush fflush(stdin); fflush(stdout);
#define print cout<<"Case #"<<test_case<<": ";
#define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define fi first
#define sc second
#define PI 3.141592653589793238462

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.sc); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

ll mod1 = 1e9+7;
ll INF=1e18+5;
ll mod=998244353;

string get_path(ll s1,ll s2,ll t1,ll t2){
    string s;
    for(ll i=0;i<abs(s1-t1);i++){
        s.pb((s1>t1?'U':'D'));
    }
    for(ll i=0;i<abs(s2-t2);i++){
        s.pb((s2>t2?'L':'R'));
    }
    return s;
}

ll search_min(vector<vector<vector<vector<ll> > > > &a,ll s1,ll s2,ll t1,ll t2,ll &x,ll &y){
    ll dups1= s1,dups2 =s2,dupt1=t1,dupt2=t2;
    if(s1>t1)
        swap(s1,t1);
    if(s2>t2)
        swap(s2,t2);
    ll mi = INF;
    for(ll i=s1;i<=t1;i++){
        for(ll j=s2;j<=t2;j++){
            if(a[dups1][dups2][i][j]<INF && a[dupt1][dupt2][i][j]<INF && (a[dupt1][dupt2][i][j]+a[dups1][dups2][i][j])/2<mi){
                mi = (a[dupt1][dupt2][i][j]+a[dups1][dups2][i][j])/2;
                x = i;
                y = j;
            }
            else{
                if(mi>a[dups1][dups2][i][j]){
                    mi = a[dups1][dups2][i][j];
                    x = i; y = j;
                }
                if(mi>a[dupt1][dupt2][i][j]){
                    mi = a[dupt1][dupt2][i][j];
                    x = i; y = j;
                }
            }
        }
    }
    return mi;
}

void solve(ll test_case){
    ll q=1000;
    vector<vector<vector<vector<ll> > > > a(30,vector<vector<vector<ll> > >(30,vector<vector<ll> >(30,vector<ll>(30,INF))));
    while(q--){
        ll s1,s2,t1,t2,d;
        cin>>s1>>s2>>t1>>t2;
        flush
        string s;
        ll x=-1,y=-1;
        ll mi = search_min(a,s1,s2,t1,t2,x,y);
        if(mi==INF){
            s = get_path(s1,s2,t1,t2);
        }
        else{
            s = get_path(s1,s2,x,y) + get_path(x,y,t1,t2);
        }
        cout<<s<<endl;
        flush
        cin>>d;
        a[s1][s2][t1][t2] = a[t1][t2][s1][s2] = d;
        flush
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("Error.txt", "w", stderr);
    #endif

    light;
    ll t=1;
    //cin>>t;
    ll i=1ll;
    while(t--){
        solve(i);
        i++;
    }
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    set<string> sset;
    rep(i, n) {
        cin >> s[i];
        sset.insert(s[i]);
    }

    rep(i, n) {
        if (sset.count("!" + s[i]) >= 1) {
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << "satisfiable" << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  map<string,int> mp, mp2;
  for(int i=0; i<n; ++i){
    string s;
    cin >> s;
    if(s[0] == '!'){
      mp2[s.substr(1)]++;
    }else{
      mp[s]++;
    }
  }
  for(auto p:mp){
    if(mp2[p.first]){
      cout << p.first << endl;
      return 0;
    }
  }
  cout << "satisfiable" << endl;
  return 0;
}


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

using namespace std;

long long increase(long long aoki, long long takahashi) {
  return (2 * aoki) + takahashi;
}

struct data_t {
  long long aoki;
  long long takahashi;
  long sum;

  bool operator<(const struct data_t& right) const {
    return increase(aoki, takahashi) > increase(right.aoki, right.takahashi);
  }
};

int main() {
  int n;
  scanf("%d", &n);

  vector<struct data_t> vec;
  for (int i = 0; i < n; ++i) {
    struct data_t d;
    scanf("%lld %lld", &(d.aoki), &(d.takahashi));
    d.sum = d.aoki + d.takahashi;
    vec.push_back(d);
  }

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

  long long x = 0;
  for (int i = 0; i < n; ++i) {
    x -= vec[i].aoki;
  }

  for (int i = 0; i < n; ++i) {
    x += increase(vec[i].aoki, vec[i].takahashi);
    if (x > 0) {
      printf("%d\n", i + 1);
      return 0;
    }
  }

  return 0;
}

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

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

    vector<int> A(N);
    rep(i,N) cin >> A[i];

    ll count,ans;

    ans = 0;
    rep(i,N){
        int x = A[i];
        for(int j=i;j<N;j++){
             x = std::min(x,A[j]);
             ans = max(ans,(ll)x*(j-i+1));
        }
    }

    cout << ans << endl;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int main(){
  double A,B,C,D;
  cin>>A>>B>>C>>D;
  double ans=(A*D+B*C)/(B+D);
  printf("%lf\n", ans);
return 0;}

#include <bits/stdc++.h>
using namespace std;
#define endl                           '\n'
#define pi                             (3.141592653589)
#define int                            long long
#define float                          double
#define inf                            1e18
#define w(x)                           int x; cin >> x; while(x--)
#define pb                             push_back
#define ppb                            pop_back
#define mp                             make_pair
#define all(x)                         (x).begin(),(x).end()
#define min3(a, b, c)                  min(c, min(a, b))
#define min4(a, b, c, d)               min(d, min(c, min(a, b)))
#define rep(i,a,b)                     for(int i = a; i < b; i++)
#define fast                           ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define sz(arr)                        sizeof(arr)/sizeof(arr[0])
#define ppc                            __builtin_popcount
#define ppcll                          __builtin_popcountll
#define COMPUTE_GCD(a, b) 		          std :: __gcd((a), (b))
#define COMPUTE_LCM(a, b) 		          (a * ((b) / COMPUTE_GCD(a, b)))
#define deb(x)                         cout << #x << "=" << x << endl;
#define deb2(x, y)                     cout << #x << "=" << x << " " << #y << "=" << y << endl;
#define mem1(a)                        memset(a,-1,sizeof(a))
#define mem0(a)                        memset(a,0,sizeof(a))
#define uniq(v)                        (v).erase(unique(all(v)),(v).end())

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

int32_t main()
{
    fast

    cout << setprecision(9);
    cout << fixed;

    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    y1 = -y1;
    if(x1 == x2)
    {
        cout << x1;
        return 0;
    }
    double m = 1.0*(y2 - y1) / (x2 - x1);
    double ans = (m*x1 - y1) / m;

    cout << ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define RED_BULL ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long int
#define all(a) a.begin(),a.end()
const ll MOD = 1e9 + 7;
const int N = 2e5 + 5;
set<int> glo;
//const ll N = 4e5 + 5;
//vector<int> adj[N];
//ll dp[N], a[N];
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
void findAns()
{
	string s;
	cin >> s;

	if (s[0] == s[1] and s[1] == s[2])
	{
		cout << "Won";
	}
	else cout << "Lost";

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

	RED_BULL;

	ll  t = 1;
	//cin >> t;

	for (int i = 1; i <= t; i++) findAns();

	return 0;

}

/***------------------------------------------------
            "Bismillahir Rahmanir Rahim"
            "Author: Foyjul Islam Raju"
------------------------------------------------***/
#include <bits/stdc++.h>
using namespace std;

#define GameOn()            int main()
#define NO                  printf("NO\n")
#define YES                 printf("YES\n")
#define ll                  long long
#define line                cout<<endl;
#define tata                return 0
#define Fast                ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

GameOn()
{
    Fast;

    int n;
    cin>>n;

    if(n<0)
    cout<<"0"<<endl;

    else
    cout<<n<<endl;
    tata;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,X,Y;
    cin>>A>>B;
    X = (A+B)/2;
    Y = (A-X);
    cout<<X<<" "<<Y<<endl;
    return 0;
}

    //Bismillah Hir Rehmanir Rahim
    //Allah knows best
    //#include<bits/stdc++.h>
    using namespace std;
    #include <climits>
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <iomanip>
    #include <cmath>
    #include <vector>
    #include <set>
    #include <map>
    #include <unordered_set>
    #include <unordered_map>
    #include <queue>
    #include <ctime>
    #include <cassert>
    #include <complex>
    #include <string>
    #include <cstring>
    #include <chrono>
    #include <random>
    #include <bitset>
    #define endl "\n"
    #define mini -10000000000000000
    #define f(i, a, n) for( i=a; i<n;i++)
    #define ll long long
    #define pi 3.141592653589793
    #define vi              vector<ll>
    #define si              set<ll>
    #define pb              push_back
    #define mp              make_pair
    #define mod             1000000007
    #define rr              return 0
    #define ff              first
    #define in              insert
    #define ss              second
    #define all(a) a.begin(), a.end()
    typedef pair<int, int> pii;
    #define setbits(x)      builtin_popcountll(x)
    #define zrbits(x)       builtin_ctzll(x)
    #define deb(x)          cout << #x << " = " << x << endl
    #define set_bit(x, idx) x = x|1LL<<idx
    #define check_bit(x, idx) min(x&(1LL<<idx),1LL)
    #define toggle_bit(x, idx) x = x^(1LL<<idx)
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using    namespace __gnu_pbds;
    #define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
    typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> rordered_set;
    #ifdef DEBUG
    #define ios
    #define ok cerr << __LINE__ <<" is done "<<endl;
    #else
    #define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define ok
    #endif
    int main()
    {
        ios;
        #ifdef DEBUG
        freopen("in", "r", stdin);
        #endif
        ll i,j,n,m,k;
        ll t=1;
    	//cin>>t;
    	while(t--)
    	{
           cin>>n>>m;
           cout<<n/m<<endl;
        }
        rr;
    }


#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> w(N);
  for (int i = 0; i < N; i++){
    cin >> w[i];
  }
  vector<int> l(M), v(M);
  for (int i = 0; i < M; i++){
    cin >> l[i] >> v[i];
  }
  vector<pair<int, int>> P(M + 1);
  for (int i = 0; i < M; i++){
    P[i] = make_pair(v[i], l[i]);
  }
  P[M] = make_pair(0, 0);
  sort(P.begin(), P.end());
  for (int i = 0; i < M; i++){
    P[i + 1].second = max(P[i + 1].second, P[i].second);
  }
  int wmax = *max_element(w.begin(), w.end());
  int vmin = *min_element(v.begin(), v.end());
  if (wmax > vmin){
    cout << -1 << endl;
  } else {
    long long ans = INF;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
      p[i] = i;
    }
    while (1){
      vector<long long> w2(N);
      for (int i = 0; i < N; i++){
        w2[i] = w[p[i]];
      }
      vector<long long> S(N + 1);
      S[0] = 0;
      for (int i = 0; i < N; i++){
        S[i + 1] = S[i] + w2[i];
      }
      vector<long long> x(N);
      x[0] = 0;
      for (int i = 1; i < N; i++){
        long long minx = x[i - 1];
        for (int j = 0; j < i; j++){
          int wsum = S[i + 1] - S[j];
          auto itr = lower_bound(P.begin(), P.end(), make_pair(wsum, -INF)) - 1;
          long long d = (*itr).second;
          minx = max(minx, x[j] + d);
        }
        x[i] = minx;
      }
      ans = min(ans, x[N - 1]);
      if (!next_permutation(p.begin(), p.end())){
        break;
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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 n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template<typename T>
struct edge{
  int to;
  T cost;
  edge(int to,T cost):to(to),cost(cost){}
};

template<typename T>
vector<T> dijkstra(vector<vector<edge<T>>> &g,int s){//sは始点
  const auto INFTY=numeric_limits<T>::max();//2回以上使うときはオーバーフローに気をつける(INFTYのときはif文で弾くなど)
  vector<T>dist(g.size(),INFTY);
  using P=pair<T,int>;//firstは最短距離,secondは頂点の番号
  priority_queue<P,vector<P>,greater<P>>pq;
  dist[s]=0;
  pq.emplace(dist[s],s);

  while(!pq.empty()){
    auto x=pq.top();pq.pop();
    int v=x.second;
    if(dist[v]<x.first)continue;//最短距離でなければ飛ばす
    for(auto e:g[v]){
      if(dist[e.to]>dist[v]+e.cost){
        dist[e.to]=dist[v]+e.cost;
        pq.emplace(dist[e.to],e.to);
      }
    }
  }
  return dist;
}

void solve(){
	int n,m;
	cin>>n>>m;
	ll sum=0;
	vector<ll>w(n);
	rep(i,n)cin>>w[i],sum+=w[i];
	sort(all(w));
	vector<pair<ll,ll>>p(m);
	ll minv=INF;
	rep(i,m){
		cin>>p[i].second>>p[i].first;
		chmin(minv,p[i].first);
	}
	if(minv<w.back()){
		cout<<-1<<"\n";
		return;
	}
	sort(all(p));
	vector<ll>v(m);
	rep(i,m){
		v[i]=p[i].first;
	}
	vector<ll>dis(m);
	ll maxdis=0;
	rep(i,m){
		chmax(maxdis,p[i].second);
		dis[i]=maxdis;
	}
	ll ans=INF;
	do{
		vector<ll>dp(n);
		rep(i,n-1){
			ll weight=w[i];
			REP(j,i+1,n){
				weight+=w[j];
				auto itr=lower_bound(all(v),weight);
				if(itr!=v.begin()){
					chmax(dp[j],dp[i]+dis[prev(itr)-v.begin()]);
				}
			}
		}
		chmin(ans,dp[n-1]);
	}while(next_permutation(all(w)));
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


// Create your own template by modifying this file!
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <numeric>
#define int LL
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x;  }
void _R(int64_t &x) { scanf("%lld", &x);  }
void _R(double &x) { scanf("%lf", &x);  }
void _R(char &x) { scanf(" %c", &x);  }
void _R(char *x) { scanf("%s", x);  }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...);  }
template<class T> void _W(const T &x) { cout << x;  }
void _W(const int64_t &x) { printf("%lld", x);  }
void _W(const double &x) { printf("%.16f", x);  }
void _W(const char &x) { putchar(x);  }
void _W(const char *x) { printf("%s", x);  }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' ');  }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);  }
#ifdef DEBUG
 #define debug(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define debug(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
template<class T> void MIN(T& a, const T& b) { a = min(a, b); }
template<class T> void MAX(T& a, const T& b) { a = max(a, b); }

#define MULTITEST 0

string invert(string const &s) {
    string t = s;
    for (char &c : t) {
        c ^= 'A' ^ 'B';
    }
    return t;
}

vector<string> f(int N) {
    if (N == 1) {
        return vector<string>(1, "AB");
    }
    vector<string> ans = {string(1<<(N-1), 'A') + string(1<<(N-1), 'B')};
    auto a = f(N-1);
    for (auto &s : a) {
        ans.PB(s + s);
        ans.PB(s + invert(s));
    }
    return ans;
}

void solve() {
    int N;
    R(N);
    auto ans = f(N);
    W(SZ(ans));
    for (auto &s : ans) {
        cout << s << '\n';
    }
}

#undef int
int main() {
    ios_base::sync_with_stdio(false);
#if MULTITEST
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}

// Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#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(){
	string s;
	cin >> s;

	int n = s.size();
	deque<char> d;
	int curr = 0;
	for(int i = 0 ; i < n ; i++) {
		if(s[i] == 'R') {
			curr ^= 1;
		}
		else {
			if(curr) {
				d.push_front(s[i]);
			}
			else d.push_back(s[i]);
		}
	}

	string str;
	while(!d.empty()) {
		if(curr) {
			str += d.back();
			d.pop_back();
		}
		else {
			str += d.front();
			d.pop_front();
		}
	}

	stack<char> st;
	for(auto it : str) {
		if(st.empty()) {
			st.push(it);
		}
		else {
			if(st.top() == it)st.pop();
			else st.push(it);
		}
	}

	str = "";
	while(!st.empty()) {
		str += st.top();
		st.pop();
	}

	reverse(all(str));
	cout << str << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ; i++){
		// cout << "Case #" << i << ": ";
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> FindDiv(ll num) {
	vector<ll> res;
	for (ll i = 1; i * i <= num; ++i)
		if (num % i == 0) res.push_back(i);
	for (int i = res.size() - 1; i >= 0; --i) {
		if (res[i] * res[i] == num) continue;
		res.push_back(num / res[i]);
	}
	return res;
}
int main() {
	ll n; scanf("%lld", &n);
	n *= 2;
	auto res = FindDiv(n);

	int ans = 0;
	for (auto i : res) {
		ll cur = n / i;
		if (abs(cur - i + 1) % 2 == 0)++ans;
	}
	printf("%d", ans);
}

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

#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 300005

int n;
int a[MAXN];
ll b[MAXN];
ll ans;
ll sum[2];
map<ll, int> mp[2];

int main() {
	scanf("%d", &n);
	REP (i, 0, n) {
		scanf("%d", &a[i]);
	}
	b[0] = a[0];
	REP (i, 1, n) {
		b[i] = a[i] - b[i - 1];
	}
	REP (i, 0, n + 1) {
		ans += mp[i % 2][b[i]];
		sum[i % 2] += a[i];
		sum[(i + 1) % 2] -= a[i];
		REP (j, 0, 2) {
			mp[j][sum[j]]++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

const int SECRET_NUMBER_NUMBER = 4;

int main() {
    string s;
    cin >> s;
    int s_size = s.size();
    int o_size = 0;
    int x_size = 0;
    for(int i = 0; i < s_size; ++i) {
        if(s[i] == 'o')
            o_size++;
        else if(s[i] == 'x')
            x_size++;
    }
    bool possible = true;
    if(o_size > SECRET_NUMBER_NUMBER) possible = false;
    if(x_size == s_size) possible = false;
    if(possible == false) {
        cout << 0 << endl;
        return 0;
    }
    int secret_number_size = pow(s_size, SECRET_NUMBER_NUMBER);
    int secret_number_count = 0;
    for(int i = 0; i < secret_number_size; ++i) {
        int secret_number = i;
        string secret_number_judge(s_size, '?');
        for(int j = 0; j < SECRET_NUMBER_NUMBER; ++j) {
            secret_number_judge[secret_number % s_size] = 'o';
            secret_number /= s_size;
        }
        bool possible = true;
        for(int j = 0; j < s_size; ++j) {
            if(s[j] == 'o' && secret_number_judge[j] != 'o') possible = false;
            if(s[j] == 'x' && secret_number_judge[j] == 'o') possible = false;
        }
        if(possible == true) secret_number_count++;
    }
    cout << secret_number_count << endl;
    return 0;
}

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

ll f(ll a){
  string s;
  s=to_string(a);
  return stoll(s+s);
}

int main(){
  ll n;
  cin >> n;
  ll i=1;
  while(f(i)<=n)i++;
  cout << i-1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k;
  cin >> n >> k;
  for(int i=0;i<k;i++){
  if(n%200==0){
  n/=200;
  }
    else{
    n=n*1000+200;
    }
  }
  cout << n << endl;
}

//*Bismillahir Rahmanir Raheem
//!BlackBeard
#include <bits/stdc++.h>
#include <algorithm>
#define NFS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0)

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define no cout << "no" << endl

#define ll long long
#define ull unsigned long long
#define pb push_back

#define FILL(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fore(arr) for (auto &x : (arr))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x *(y / gcd(x, y))
#define toint(c) c - 48
#define tochar(c) c + 48

#define MAX 214748364
#define MOD 100000007
#define bug cout << "*_*\n"
using namespace std;

template <class T>
void print(vector<T> v)
{
    fore(v) cout << x << ' ';
    cout << endl;
}
void solve()
{
    ll n, k;
    cin >> n >> k;
    while (k--)
    {
        if (n % 200 == 0)
            n /= 200;
        else
        {
            string s = to_string(n);
            s += "200";
            n = stoll(s);
        }
    }
    cout << n << endl;
}
int main()
{
    NFS;
#ifndef ONLINE_JUDGE
    freopen("D:/code/C++/OJ/in.txt", "r", stdin);
    freopen("D:/code/C++/OJ/out.o", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);

vector<ll>g[300005];
ll vis[300005]={0};
ll c=0,s1=0,s2=0;
ll a[3000005],b[300005];

void dfs(ll current) {
    vis[current]=1;
    s1 += a[current];
    s2 += b[current];
    for(ll i=0;i<g[current].size();i++) {
        ll child = g[current][i];
        if(vis[child]==0){
            dfs(child);
        }
    }
}

int main(){
    flash;
    ll t=1;
    //cin >> t;
    while(t--) {
        ll n,e;
        cin >> n >> e;
        rep(i,1,n+1) {
            cin >> a[i];
        }
        rep(i,1,n+1) {
            cin >> b[i];
        }
        rep(i,0,e) {
            ll a,b;
            cin >> a >> b;
            g[a].pb(b);
            g[b].pb(a);
        }
        ll f =0;
        ll ans;
        for(ll i=0;i<n;i++){
            s1=0,s2=0;
            if(vis[i]==0){
                dfs(i);
            }
            if(s1 != s2) {
                //cout<<"No\n";
                f=0;
                break;
            }
            else f=1;
        }
        if(f==0) {
            cout<<"No\n";
        }
        else {
            cout<<"Yes\n";
        }
        for(ll i=0;i<=n;i++){
            g[i].clear();
        }
        for(ll i=0;i<=n;i++)vis[i]=0;

    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}

#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vint = vector<int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }
}
template <typename T>
T& chmin(T& val, T val2) {
    return val = min(val, val2);
}
template <typename T>
T& chmax(T& val, T val2) {
    return val = max(val, val2);
}

void solve() {
    ll n,x; In(n,x);
    vll a(n); In(a);
    sort(ALL(a)); reverse(ALL(a));
    ll ans = (x-a[a.size()-1]);

    FOR(sz, 2, n+1) {
        vector<vector<vll>> dp(n+1, vector<vll>(sz,vll(sz+1,-1)));
        dp[0][0][0] = 0;
        REP(i,n) {
            REP(j,sz) {
                REP(k,sz+1) {
                    if (k+1 <= sz && dp[i][j][k] != -1) dp[i+1][(j+a[i])%sz][k+1] = max(dp[i+1][(j+a[i])%sz][k+1], dp[i][j][k] + a[i]);
                    if (dp[i][j][k] != -1) dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                }
            }
        }
        if (dp[n][x%sz][sz] != -1) chmin(ans, (x-dp[n][x%sz][sz])/sz);
    }
    Out(ans);
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


// C++ (GCC9.2.1) AtCoder
/*
Ctrl+Option+N で　実行

*/

#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;

using namespace std;

ll m = 7;

long long pow(long long a,long long n){
  long long ret=1;
  for(;n>0;n>>=1,a=a*a%m){
    if(n%2==1){
      ret=ret*a%m;

    }
  }
  return ret;
}

long long inv(long long a){
  return pow(a,m-2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N; cin>>N;
  string S; cin>>S;
  string X; cin>>X;
/*
  S += "0";
  X += "T";
  N++;
  */

  vector <int> Tvict(7,0);
  vector <int> Avict(7,1);
  Tvict[0] = 1;
  Avict[0] = 0;

  for(int i=N-1;i>=1;i--){
    vector <int> nextTvict(7,0);
    vector<int> nextAvict(7,0);
    int special = S[i] - '0';

    if(X[i] == 'T'){
      for(int a=0;a<7;a++){
        if(Tvict[a] == 0) continue;
        ll tmp = (a - special + 777) % 7;

        nextTvict[tmp * inv(10) % 7]++;
      }

       for(int a=0;a<7;a++){
        if(Tvict[a] == 0) continue;
        ll tmp = (a - 0 + 777) % 7;

        nextTvict[tmp * inv(10) % 7]++;
      }

      REP(i,7){
        if(nextTvict[i] == 0) nextAvict[i] = 1;
        else nextAvict[i] = 0;
      }

    } else {
         for(int a=0;a<7;a++){
        if(Avict[a] == 0) continue;
        ll tmp = (a - special + 777) % 7;

        nextAvict[tmp * inv(10) % 7]++;
      }

       for(int a=0;a<7;a++){
        if(Avict[a] == 0) continue;
        ll tmp = (a - 0 + 777) % 7;

        nextAvict[tmp * inv(10) % 7]++;
      }

      REP(i,7){
        if(nextAvict[i] == 0) nextTvict[i] = 1;
        else nextTvict[i] = 0;
      }

    }

    Avict = nextAvict;
    Tvict = nextTvict;
    /*

    for(auto i : Avict){
      cout<<i<<" ";
    }
    cout<<endl;
    for(auto i : Tvict){
      cout<<i<<" ";
    }
    cout<<endl;
    */

  }

  if(X[0] == 'T'){
    ll spe = S[0] - '0';

    if( (Tvict[0] > 0) or (Tvict[spe] > 0)) print("Takahashi")
    else print("Aoki")
  } else {
        ll spe = S[0] - '0';

    if(Avict[0] > 0 or Avict[spe] > 0) print("Aoki")
    else print("Takahashi")
  }
  return 0;
}

#include<bits/stdc++.h>
#define double long double
#define maxn 100010
using namespace std;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int n,m,K,v[maxn];
double k[maxn],b[maxn],sk[maxn],sb[maxn];
#define ABS(x) ((x)<0?-(x):(x))
signed main()
{
	n=read(),m=read(),K=read();
	for(int i=1,x;i<=K;i++) v[x=read()]=1,k[x]=1;
	for(int i=n-1;~i;i--)
	{
		if(!v[i]) k[i]=(sk[i+1]-sk[i+m+1])/m,b[i]=(sb[i+1]-sb[i+m+1])/m+1;
		sk[i]=sk[i+1]+k[i],sb[i]=sb[i+1]+b[i];
	}
	if(ABS(k[0]-1)<1e-7) cout<<-1<<'\n';
	else cout<<fixed<<setprecision(10)<<b[0]/(1-k[0])<<'\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<iterator>
#include <map>
#include<cmath>
#include <list>
#include<string>
#include <stdlib.h>
#include<ctime>
#include<cstring>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define PI 2*acos(0.0)
#define mod 1e09+7
#define inf 2e18
typedef long long ll;
typedef unsigned long long ull;
#define line cout<<endl
using namespace std;
int fy[] = {0, 0, 1, -1};
int fx[] = { -1, 1, 0, 0};
int ara[1001];
int graph[1001][1001];
int main()
{
    fastIO
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    clock_t start, end;
    start = clock();
#endif

    int n;
    cin >> n;
    ull sum = 0;
    ull a[n], b[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        sum += (a[i] * b[i]);
    }
    if (sum == 0)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
#ifndef ONLINE_JUDGE
    end = clock();
    printf("\nTime taken: %.5f\n", ((double) (end - start)) / CLOCKS_PER_SEC);
#endif
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100005;
int n,a[N],b[N],ans;
priority_queue<int>x,y;
signed main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans+=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		b[i]-=a[i];
		if(i&1)
			x.push(b[i]);
		else
			y.push(b[i]);
	}
	while(x.size())
	{
		int u=x.top(),v=y.top();
		x.pop(),y.pop();
		if(u+v<0)
			break;
		ans+=u+v;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k;
	cin>>n>>k;
	while(k--)
	{
		if(n%200==0)
		{
			n/=200;
		}
		else
		{
			n=n*1000+200;
		}
	}
	cout<<n;
	return 0;
}

#pragma GCC optimization ("O3")
#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 ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define ll long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll M = 1e9 + 7;
const ll N = 3e6 + 5;

ll dp[3][N];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast

    ll n, k;
    cin >> n >> k;
    memset(dp, 0, sizeof dp);
    for(ll i = 1; i <= 3 * n; i++)dp[0][i] = min(n, i);
    for(ll j = 1; j < 3; j++)
        for(ll i = 1; i <= 3 * n; i++)
            dp[j][i] = dp[j][i - 1] + dp[j - 1][i - 1] - dp[j - 1][max(0ll, i - n - 1)];

    ll sum = lower_bound(dp[2], dp[2] + 3 * n + 1, k) - dp[2];
    k -= dp[2][sum - 1];

    for(ll i = 1; i <= sum - 2; i++)
    {
        if(dp[1][sum - i] - dp[1][sum - i - 1] >= k)
        {
            cout << i << " ";
            sum -= i;
            break;
        }
        k -= dp[1][sum - i] - dp[1][sum - i - 1];
    }
    for(ll i = 1; i <= sum - 1; i++)
    {
        if(dp[0][sum - i] - dp[0][sum - i - 1] >= k)
        {
            cout << i << " ";
            sum -= i;
            break;
        }
        k -= dp[0][sum - i] - dp[0][sum - i - 1];
    }
    cout << sum << endl;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl a(n), b(n), d(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) {
    if(i%2==0) d[i] = a[i]-b[i];
    else d[i] = b[i]-a[i];
  }

  vpl vec;
  rep(i, n) vec.push_back(pl (d[i], i));
  sort(all(vec), greater<pl>());
  vb choose_a(n, 0);
  rep(i, n) {
    ll num = vec[i].second;
    if(i < n/2 && num%2==0) choose_a[num] = 1;
    if(i >= n/2 && num%2==1) choose_a[num] = 1;
  }
  ll ans=0;
  rep(i, n) {
    if(choose_a[i]) ans += a[i];
    else ans += b[i];
  }
  cout << ans << newl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct dijkstra {

  ll N;
  struct edge { ll to, d; };
  vector<vector<edge>> adj;
  vector<ll> minlen;

  dijkstra(ll n) { N = n; adj.resize(N); minlen.assign(N,LLINF); }
  ll operator[](const ll &x) const { return minlen[x]; }

  void add_edge(ll from, ll to, ll d){
    adj[from].push_back({to,d});
  }
  vector<ll> calc(ll n=0) {
    auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;};
    priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c);
    minlen[n] = 0; q.push(make_pair(n,0));
    while(q.size()) {
      p_ll now = q.top(); q.pop();
      ll np = now.first, nd = now.second;
      if (nd>minlen[np]) continue;
      for (auto x: adj[np]) {
        if (minlen[x.to]<=minlen[np]+x.d) continue;
        q.push(make_pair(x.to, minlen[np]+x.d));
        minlen[x.to] = minlen[np]+x.d;
      }
    }
    return minlen;
  }

};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

ll R, C;
ll gid(ll i, ll j, bool ura) { return i*C + j + ura*(R*C); }

int main() {
  cin >> R >> C;
  ll A[R][C-1]; rep(i,R) rep(j,C-1) cin >> A[i][j];
  ll B[R-1][C]; rep(i,R-1) rep(j,C) cin >> B[i][j];

  dijkstra ds(R*C*2);
  rep(i,R) rep(j,C-1) {
    ds.add_edge(gid(i,j,false), gid(i,j+1,false), A[i][j]);
    ds.add_edge(gid(i,j+1,false), gid(i,j,false), A[i][j]);
  }
  rep(i,R-1) rep(j,C) {
    ds.add_edge(gid(i,j,false), gid(i+1,j,false), B[i][j]);
    ds.add_edge(gid(i+1,j,true), gid(i,j,true), 1);
  }
  rep(i,R) rep(j,C) {
    ds.add_edge(gid(i,j,false), gid(i,j,true), 1);
    ds.add_edge(gid(i,j,true), gid(i,j,false), 0);
  }

  vector<ll> d = ds.calc();
  ll result = ds[gid(R-1,C-1,false)];
  cout << result << endl;
  return 0;
}


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

int T;
int N, A[100000];

signed main(){
    cin >> T;
    while(T--){
        cin >> N;
        rep(i, N) cin >> A[i];

        if(N%2 == 1) cout << "Second" << endl;
        else{
            sort(A, A+N);
            bool flg = true;
            rep(i, N/2){
                flg &= (A[2*i] == A[2*i+1]);
            }
            if(flg) cout << "Second" << endl;
            else cout << "First" << endl;
        }
    }
}

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <unistd.h>
#include <stdlib.h>
#include <cassert>

using namespace std;
// using namespace atcoder;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 2e18;
const ll fact_table = 3200008;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;}
vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/

bool multicase = true;

// ACLにするのを忘れない

void solve() {
    ll n;
    cin >> n;
    vec v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    if (n % 2 == 0) {
        ll sum1 = 0, sum2 = 0;
        for (int i = 0; i < n; i += 2) {
            sum1 += v[i], sum2 += v[i + 1];
        }
        if (sum1 == sum2) {
            p("Second");
        } else {
            p("First");
        }
    } else {
        p("Second");
    }
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }

    // solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define mii map<int,int>
#define mll map<long long int,long long int>
#define rep(it,m) for(auto it=m.begin();it!=m.end();it++)
#define pb push_back
#define fr first
#define sc second
#define mod 1000000007LL
#define setbiti(x) __builtin_popcount(x)
#define setbitll(x) __builtin_popcountll(x)
#define vi vector<int>
#define vll vector<long long int>
#define f(i,x,n) for(int i=x;i<n;i++)
#define l(i,a,b) for(int i=a;i>b;i--)
#define w(x) int x; cin>>x; while(x--)
#define all(x) x.begin(),x.end()
#define fill(a,x)  memset(a,x,sizeof(a))
#define pie 3.14159265
using namespace std;

void fio() {
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main() {
    fio();
    ll k,n,m;
    cin>>k>>n>>m;
    vll vec(k);
    f(i,0,k){
      cin>>vec[i];
    }
    ll b[k]{0};
    ll cnt=0;
    vector<pll> diff;
    f(i,0,k){
        ll u=(m*vec[i])/n;
        b[i]=u;
        cnt+=u;
        ll d=abs(n*u-m*vec[i]);
        diff.pb(mp(d,i));
    }
    sort(all(diff));
    reverse(all(diff));
    cnt=m-cnt;
    f(i,0,k){
        if(cnt>0){
            b[diff[i].sc]++;
            cnt--;
        }
    }
    f(i,0,k){
        cout<<b[i]<<" ";
    }
    cout<<"\n";
    return 0;
}

#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 2e5+7;
constexpr int M = 1e9+7;

#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))

#ifdef int
#define INF 0x3f3f3f3f3f3f3f3f
#define INF2 (int)(0xcfcfcfcfcfcfcfcf)
#else
#define INF 0x3f3f3f3f
#define INF2 0xcfcfcfcf
#endif

inline int cdiv(int x, int y) {
    return (x + y - 1) / y;
}

signed main() {
    fastio
    int k, n, m;
    cin >> k >> n >> m;
    vector<int> a(k);
    vector<int> b(k);
    for (int& x: a) cin >> x;
    // x / ( n * m )
    auto check = [&](__int128 x) {
        vector<int> l(k+1, 0), r(k+1, 0);
        for (int j = 0; j < k ; j++) {
            int y = a[j];
            int L = cdiv(y * m - x, n);
            int R = (y * m + x ) / n;
            l[j+1] = l[j] + L, r[j+1] = r[j] + R;
        }
        int ans = m;
        for (int j = k-1; j >= 0; j--) {
            int y = a[j];
            int L = cdiv(y * m - x, n);
            int R = (y * m + x) / n;
            L = max(L, ans - r[j]), R = min(R, ans - l[j]);
            if (L > R) return false;
            b[j] = L;
            ans -= L;
        }
        return true;
    };

    int l = 0, r = m * n;
    while (l < r) {
        int mid = (l+r) >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
   // cout << (int)l << "/" << n*m << "\n";
    check(l);
    for (int x: b) cout << x << " ";
    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/modint>
// #include <atcoder/dsu>
// using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

// using mint = modint998244353;
// using mint = modint1000000007;

int main() {
  int N; cin>>N;
  ll sum=0;
  rep(i,N) {
    ll a,b; cin>>a>>b;
    sum+=(b-a+1)*(a+b)/2;
  }
  cout<<sum<<endl;
}

#include <iostream>
#include <algorithm>

int n, x;
int v[1005];

int main()
{
	std::cin >> n >> x;
	x *= 100;
	for(int i = 1; i <= n; i++)
	{
		int p;
		std::cin >> v[i] >> p;
		v[i] *= p;
	}
	for(int i = 1; i <= n; i++)
	{
		x -= v[i];
		if(x < 0)
		{
			std::cout << i;
			return 0;
		}
	}
	std::cout << -1;
}


# include <iostream>

using namespace std;

const int kMaxN = 51;

int n;
long long X;
long long a[kMaxN], f[kMaxN], g[kMaxN][2];

int main() {
  scanf("%d %lld", &n, &X);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    a[i] = a[i + 1] / a[i];
    f[i] = X % a[i];
    X /= a[i];
  }
  g[1][0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j <= 1; j++) {
      long long k = j + f[i], l = k / a[i];
      k %= a[i];
      g[i + 1][l] += g[i][j];
      g[i + 1][1] += (k != 0) * g[i][j];
    }
  }
  printf("%lld", g[n][0] + g[n][1]);
  return 0;
}

/******************************************************/
/******************************************************/
/**                                                  **/
/**            BISMILLAHIR RAHMANIR RAHIM            **/
/**         REAZ AHAMMED CHOWDHURY - reaziii         **/
/**  Department of Computer Science and Engineering  **/
/*         INSTITUTE OF SCIENCE AND TECHNOLOGY       **/
/**                                                  **/
/******************************************************/
/******************************************************/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pcase(x)     printf("Case %d: ",x++)
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x)     memset(x,-1,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define linfi        LLONG_MAX
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define fro(i,x,y)   for(int i=x;i<y;i++)
#define ech(x,a)     for(auto &x : a)
#define ff           first
#define ss           second
#define vi           vector<int>
#define vl           vector<ll>
#define pi           acos(-1.0)

using namespace std;
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void read(T& x) {cin >> x;}
template<class H, class... T> void read(H& h, T&... t) {read(h); read(t...);}
template<class A> void read(vector<A>& x) {for (auto &a : x) read(a);}
template<class H> void print(vector<H> &x) {ech(a, x) cout << a << " "; cout << endl;}
template<class P> void debug(P h) {
#ifndef ONLINE_JUDGE
    cerr << h << " ";
#endif
}
template<class W, class... V> void debug(W h, V... t) {
#ifndef ONLINE_JUDGE
    debug(h);
    debug(t...);
    cerr << endl;
#endif

}

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

bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}
ll bigmod(ll a, ll b, ll mod) {if (b == 0) return 1; if (b == 1) return a; if (b & 1) {return ((a % mod) * (bigmod(a, b - 1, mod) % mod)) % mod;} ll x = bigmod(a, b / 2, mod); return (x * x) % mod;}
ll geti() {ll x; read(x); return x;}
ll cdiv(ll a, ll b) {ll ret = a / b; if (a % b) ret++; return ret;}
const ll mod =  1e9 + 7;
const ll N   =  2e5 + 10;
int dx[4] = { +0, +0, +1, -1};
int dy[4] = { -1, +1, +0, +0};

//................................___Start from here___...............................//
//................................_____________________..............................//

int solve() {
    int x, y;
    read(x, y);
    if (x > y) swap(x, y);

    if (x + 3 > y) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    return 0;
}
int main(int argc, char* argv[]) {

    if (argc <= 1) {
#ifndef ONLINE_JUDGE
        input;
        output;
#endif
#ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
#endif
    }

    int cs = 1, cn = 1;
    // read(cs);
    while (cs--) {
        solve();

    }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define as assign
#define rs resize
#define sz(a) (ll)((a).size())
#define otp(s) cout<<s<<endl;
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)
#define all(it,a) for(auto it=(a).begin();it!=(a).end();it++)
#define rev(it,a) for(auto it=(a).rbegin();it!=(a).rend();it++)
const int mod = 1e9+7;
/*sort(vec.begin(), vec.end(),
[](node const & e,  node const & g) -> bool{return e.mode < g.mode; } );
ceil()
struct myComp{bool operator()(pll const& p1, pll const& p2)return p1.ff < p2.ff;}
priority_queue<pi, vector<pi>, greater<pi> > pq;
*max_element(Vector.begin()+I,vector.begin()+j+1);*/
inline ll add(ll a, ll b){a += b; if(a >= mod)a -= mod; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += mod; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %mod);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

int main()
{
//    fast;
    ll n;
    cin>>n;
    ll ans=16*27*25*7*11;
    ans*=13*17*19*23*29;

    cout<<ans+1<<endl;
    return 0;

}

#include<bits/stdc++.h>

#define fox(i,a,b) for(int i=a;i<=b;++i)
#define ll long long

using namespace std;

int _x, _f; char _c;
inline int rd() {
	_x = 0, _f = 1, _c = getchar();
	for (; !isdigit(_c); _c = getchar()) if (_c == '-') _f = 0;
	for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0';
	return _f ? _x : -_x;
}

double pi = acos(-1);

int n;
struct point { double x, y;} p0, p2, p1, zd;

signed main() {
	n = rd();
	p0.x = rd(), p0.y = rd();
	p2.x = rd(), p2.y = rd();
	p1.x = (p0.x + p2.x) / 2, p1.y = (p0.y + p2.y) / 2;
	p0.x -= p1.x, p0.y -= p1.y;
	//printf("%.6lf %.6lf\n", p0.x, p0.y);
	//printf("%.6lf %.6lf\n", p1.x, p1.y);
	double phi = pi * 2 / n;
	zd.x = p0.x * cos(phi) - p0.y * sin(phi);
	zd.y = p0.x * sin(phi) + p0.y * cos(phi);
	printf("%.6lf %.6lf\n", zd.x + p1.x, zd.y + p1.y);
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;cin>>N;
  vector<int>A(2*N);
  for(int i=0;i<2*N;i++)cin>>A[i];
  int ans=0;
  for(int i=0;i<2*N;i++)ans+=A[i];
  multiset<int>st;
  for(int i=0;i<N;i++){
    st.insert(max(A[N-1-i],A[N+i]));
    if(st.size()&&*st.begin()<min(A[N-1-i],A[N+i])){
      ans-=*st.begin();
      st.erase(st.begin());
      st.insert(min(A[N-1-i],A[N+i]));
    }else ans-=min(A[N-1-i],A[N+i]);
  }
  cout<<ans<<endl;
}

//My_Template

#include<bits/stdc++.h>

#define pb(a) push_back(a)
#define vec vector<long long int>
#define myfor(n) for(int i = 0; i < n; i++)
#define tc(t) int t; cin>>t; while(t--)
#define sortt(a) sort(a.begin(), a.end())
#define ll long long int
#define revit(a) reverse(a.begin(), a.end())
#define summ(a) accumulate(a.begin(), a.end(), 0ll)
#define M 1000000007ll
#define new_for(a) for(auto i : a)
#define INFI 9223372036854775807ll

using namespace std;

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

    //code_goes_here-->

    int n;
    cin>>n;

    if(n > 1){

    vector<int> a(pow(2,n)), b, c;
    myfor(pow(2,n))
      cin>>a[i];
    c = a;

    for(int i = 0; i < pow(2,n) - 1; i+=2)
      b.pb(max(a[i], a[i+1]));

    a = b;

    while(b.size() != 2){
      b.clear();
      for(unsigned i = 0; i < a.size() - 1; i+=2)
        b.pb(max(a[i], a[i+1]));
      a = b;
    }

    int p = (b[0]>b[1]?b[1]:b[0]);

    for(int i = 0; i < pow(2, n); i++)
      if(c[i] == p){
        cout<<i+1<<endl;
        break;
      }
    }
    else{
      int a, b;
      cin>>a>>b;
      if(a > b)
        cout<<2<<endl;
      else
        cout<<1<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int V, T, S, D;
  cin >> V >> T >> S >> D;
  T *= V;
  S *= V;
  if(T <= D && D <= S) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define fi first
#define se second
#define INF 0x3f3f3f3f
#define STD std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(x, l, u) for(int x = l; x <= u; x++)
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define SORT(a) sort((a).begin(),(a).end())
#define mp(a, b) make_pair(a, b)

const int N = 1e5+10;
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

LL v, t, s, d;

int main() {
    STD;
    cin >> v >>t >>s >>d;
    t = v * t;
    s = s * v;
    if (d >= t && d <= s) cout << "No";
    else cout << "Yes";
    return 0;
}