#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int n, K;
	scanf("%d%d", &n, &K);
	vector<vector<int>> E(n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u;
		--v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	vector<int> depth(n, -1), par(n, -1);
	depth[0] = 0;
	function<void(int)> dfs = [&](int x) {
		for (int y : E[x]) {
			if (depth[y] != -1) continue;
			depth[y] = depth[x] + 1;
			par[y] = x;
			dfs(y);
		}
	};
	dfs(0);
	vector<int> vs(n);
	iota(vs.begin(), vs.end(), 0);
	sort(vs.begin(), vs.end(), [&](int x, int y) {
		return depth[x] > depth[y];
	});
	auto check = [&](int d) {
		vector<bool> used(n);
		function<void(int, int, int)> flood = [&](int x, int cur, int p) {
			used[x] = true;
			if (!cur) return;
			for (int y : E[x]) {
				if (y == p) continue;
				flood(y, cur - 1, x);
			}
		};
		int need = 0;
		for (int v : vs) {
			if (used[v]) continue;
			++need;
			if (need > K) return false;
			int x = v;
			for (int i = 0; i < d; ++i) {
				if (par[x] == -1) break;
				x = par[x];
			}
			flood(x, d, -1);
			assert(used[v]);
		}
		return true;
	};
	int lo = 1, hi = n - 1;
	while (lo < hi) {
		int d = (lo + hi) >> 1;
		if (check(d)) hi = d;
		else lo = d + 1;
	}
	printf("%d\n", lo);
}

#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

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

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

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,k,ans=0,cur;
    cin>>n>>m;
    int a[m][2],b[n+1];
    for (int i=0;i<m;++i)
        cin>>a[i][0]>>a[i][1];
    cin>>k;
    int c[k][2];
    for (int i=0;i<k;++i)
        cin>>c[i][0]>>c[i][1];
    for (int i=0;i<(1<<k);++i)
    {
        for (int j=1;j<=n;++j)
            b[j]=0;
        for (int j=0;j<k;++j)
        {
            if (i&(1<<j))
                ++b[c[j][0]];
            else
                ++b[c[j][1]];
        }
        cur=0;
        for (int j=0;j<m;++j)
            if (b[a[j][0]]&&b[a[j][1]])
                ++cur;
        ans=max(ans,cur);
    }
    cout<<ans;
    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    cout << a + b + c - min({ a, b, c }) << endl;

    return 0;
}

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

using namespace std;

#define ll long long
#define LL unsigned long long
#define vec(x) vector<x>
#define emb(x)  emplace_back(x)
#define fall(x) x.begin(),x.end()
#define rfall(x) x.rbegin(),x.rend()
#define fo(a,b) for(int i=a; i < int(b); i++)
#define fset(x) setprecision(x) << fixed
#define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);

/*
 *---------------------------------------------
 * --------------------------------------------
 * --------------------------------------------
 *
العمل الجاد يتفوق على الموهبة الكسولة

 * 勤勉は怠惰な才能に勝る
 *
 * 努力打敗懶惰的人才
 *
  * कड़ी मेहनत आलसी प्रतिभा को हरा देती है
  *
 * тяжелая работа превосходит ленивый талант
 *
 * 勤勉は怠惰な才能に勝る
 *
 * 努力打敗懶惰的人才
 *
 * malfacila laboro superas maldiligentan talenton
 *
 * el trabajo duro supera al talento perezoso
 *
 * η σκληρή δουλειά κερδίζει τεμπέλης ταλέντο
 *
 * il duro lavoro batte il talento pigro
 *
 * munca grea bate talentul leneș
 *
 * kazi ngumu hupiga talanta ya uvivu
 *
 * piger ingenii labore verberat
 *
 * làm việc chăm chỉ đánh bại tài năng lười biếng
 *
 * trabalho duro vence talento preguiçoso
 *
 * працавітасць перамагае лянівы талент
 *
 * le travail acharné bat le talent paresseux
 *
 * --------------------------------------------------
 * --------------------------------------------------
 * --------------------------------------------------
*/

#define MOD 10
#define use 1000000000000000007

LL mpow(LL a, LL b){

	LL res = 1;

	while(b){
		if(b&1)res=(res%4)*(a%4);

		a=(a%4)*(a%4);

		b>>=1;

	}

	return res+4;
	}

void runcase(){

	LL a, b,c;
	cin>>a>>b>>c;

	b=mpow(b,c);

	LL res=1;
	while(b){

		if(b&1)res = (res%MOD)*(a%MOD);

		 a=(a%MOD)*(a%MOD);

		b>>=1;
	}

	cout << (res%MOD);
	cout << endl;

	}

int main(){
	fast
	int tt;
	tt=1;

	while(tt--){

	runcase();

	}

	return 0;
	}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) std::begin(x), std::end(x)

using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

const int INF = 100000000;

double solve(double n)
{
    double res = 0;
    REP3R(i, 1, n + 1)
    {
        res += n / i;
    }
    return res - 1.0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    double n;
    cin >> n;
    double res = solve(n);
    printf("%.9f\n", res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const int M = 1000000007;
#define AKTG ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define     ff           first
#define     all(x)      x.begin(),x.end()
#define     ss          second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     fix         fixed<<setprecision(19)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define endl "\n"
vector<int> adj[N];
bool visited[N]={false};
void solve()
{
    double n;
    cin>>n;
    double ans=0;
    for(int i=1;i<n;i++)
    {
        double p=(n/(n-i));
        ans+=p;
    }
    cout<<fix<<ans<<endl;

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


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
#include <random>

using namespace std;

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline bool chmin(T &x, const T &y){ if(y < x){ x = y; return true; } return false; }
template <class T> inline bool chmax(T &x, const T &y){ if(x < y){ x = y; return true; } return false; }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}
template <class Con>
string concat(const Con &c, const string &spr){
	stringstream ss;
	typename Con::const_iterator it = c.begin(), en = c.end();
	bool fst = true;
	for(; it != en; ++it){
		if(!fst){ ss << spr; }
		fst = false;
		ss << *it;
	}
	return ss.str();
}

template <class Con, class Fun>
vector<typename Con::value_type> cfilter(const Con &c, Fun f) {
	vector<typename Con::value_type> ret;
	typename Con::const_iterator it = c.begin(), en = c.end();
	for(; it != en; ++it){
		if(f(*it)){
			ret.emplace_back(*it);
		}
	}
	return ret;
}
#if __cplusplus >= 201103L
template <class Con, class Fun>
auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> {
	vector<decltype(f(*c.begin()))> ret;
	ret.reserve(c.size());
	for(const auto &x: c){
		ret.emplace_back(f(x));
	}
	return ret;
}
#endif

#if __cplusplus >= 201402L
#define lambda(e) ([&](const auto &_){ return (e); })
#define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); })
#endif

#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define tget(t,i) get<i>(t)

#define MOD 1000000007LL
#define EPS 1e-8

void mainmain(){
	int n;
	cin >> n;
	vll ls(n), rs(n);
	REP(i, n){
		LL t, l, r;
		cin >> t >> l >> r;
		l *= 10;
		r *= 10;
		if(t == 2 || t == 4){ --r; }
		if(t == 3 || t == 4){ ++l; }
		ls[i] = l;
		rs[i] = r;
	}
	int ans = 0;
	REP(i, n)
	REP(j, i){
		if(!(rs[i] < ls[j] || rs[j] < ls[i])){
			++ans;
		}
	}
	cout << ans << "\n";
}

}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <iomanip>

using namespace std;

int main(){
    long k;
    cin >> k;
    string s,t;
    cin >> s >> t;
    vector<long> viCount(10,k);
    vector<long> viTak(10,0), viAok(10,0);
    for(long i = 0; i < 4; i++){
        int j1 = s[i] - '0';
        int j2 = t[i] - '0';
        viCount[j1]--;
        viTak[j1]++;
        viCount[j2]--;
        viAok[j2]++;
    }

    double dAns = 0.0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            vector<long> viTakThis = viTak, viAokThis = viAok;
            viTakThis[i]++;
            viAokThis[j]++;
            long nTak=0,nAok=0;
            for(long k = 1; k <= 9; k++){
                nTak += pow(10,viTakThis[k]) * k;
                nAok += pow(10,viAokThis[k]) * k;
            }
            if(nTak > nAok){
                double dThis = double(viCount[i]*viCount[j]);
                dThis -= double(i==j ? viCount[i] : 0);
                dThis /= double((9*k-8)*(9*k-9));
                dAns += max(0.0, dThis);
            }
        }
    }
    cout << dAns << endl;
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    string S, T;
    cin >> N >> S >> T;

    ll cntS=0, cntT=0;
    REP(i, N) cntS += (S[i] == '1');
    REP(i, N) cntT += (T[i] == '1');

    if(cntS != cntT){
        cout << -1 << endl;
        return 0;
    }

    V<ll> posS, posT;
    REP(i, N) if(S[i] == '0') posS.push_back(i);
    REP(i, N) if(T[i] == '0') posT.push_back(i);

    ll sz = posS.size();

    ll res = 0;
    REP(i, sz){
        if(posS[i] != posT[i]) res++;
    }

    cout << res << endl;

    return 0;
}

#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
const int N = 5e5+10;
string s,t;
int sums = 0,sumt = 0,cnt;
bool st[N],flag = false;
priority_queue<int,vector<int>,greater<int>> fla;
int main()
{
	int n;
	scanf("%d",&n);
	cin>>s>>t;
	for(int i = 0;i<n;i++)
	{
		sums+=s[i]-'0';
		sumt+=t[i]-'0';
		if((sums != sumt || s[i] != t[i]) && s[i] == '0')cnt++;
	}
	if(sums != sumt)printf("-1\n");
	else printf("%d\n",cnt);
	return 0;
}


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

int main()
{
  ll a,b,c;
  cin>>a>>b>>c;

  ll sum1 = ((a*(a+1))/2);

  ll sum2=  ((b*(b+1))/2);

  ll sum3=  ((c*(c+1))/2);

  cout<<(((sum1%mod)*(sum2%mod))%mod*(sum3%mod))%mod;
}

#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 ld eps = 1e-9;
const char newl = '\n';

ll Triangular_Number(ll n) {return ((n*(n+1))/2)%MOD;}

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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << ((Triangular_Number(a) * Triangular_Number(b) % MOD) * Triangular_Number(c)) % MOD << newl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int SINF = 1LL << 29;
const ll mod = 1000000000+7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

//最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    vector<ll> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    vector<ll> a;

    for(int bit = 1; bit<(1<<15); bit++) {
        ll f = 1;
        for(int i=0; i<15; i++) {
            if(bit>>i&1) {
                f *= prime[i];
            }
        }
        a.push_back(f);
    }
    sort(all(a));
    for(int i=0; i<a.size(); i++) {
        bool flg = true;
        for(int j=0; j<n; j++) {
            if(gcd(a[i], x[j]) == 1) {
                flg = false;
                break;
            }
        }
        if(flg) {
            cout << a[i] << endl;
            return 0;
        }
    }
}

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

// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things.
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes

int main(){

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

    // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
    vector<ll> primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};

    int n;
    cin>>n;

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

    ll ans=LLONG_MAX;

    ll tot = 1<<(15);

    for(int i=0;i<tot;i++){
    	ll currNum=1;
    	ll tt = i;

    	for(int j=0;j<15;j++){
    		if(tt&1){
    			currNum*=primes[j];
    		}
    		tt>>=1;
    	}

	    // cerr<<i<<endl;
	    // cerr<<currNum<<endl;

    	bool works=true;
    	for(int j=0;j<n;j++){
    		if(__gcd(currNum, (ll)arr[j])==1){
    			works=false;
    			break;
    		}
    	}
	    cerr<<i<<endl;

    	if(works){
    		ans=min(ans,currNum);
    	}
    }
    cout<<ans<<endl;

}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <unordered_set>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}

int main()
{
    string s;
    cin >> s;
    deque<char> que;
    int f = 1;
    int n = s.size();
    rep(i, n)
    {
        if (s[i] == 'R') f = !f;
        else
        {
            if (f)
            {
                if (que.size() && que.back() == s[i]) que.pop_back();
                else que.push_back(s[i]);
            }
            else
            {
                if (que.size() && que.front() == s[i]) que.pop_front();
                else que.push_front(s[i]);
            }
        }
    }
    int m = que.size();
    string ans = "";
    rep(i, m) ans += que[i];
    if (!f) reverse(all(ans));
    cout << ans << endl;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
using std::cout; using std::endl;
using std::string; using std::reverse;

// 自己テンプレート
typedef long long ll;

// 比較して上書きマクロ
template<class T> inline void chmin(T& a, T b) { if(a>b) {a=b;} }
template<class T> inline void chmax(T& a, T b) { if(a<b) {a=b;} }

// dpリソース
const ll INF = 1LL << 60;
ll dp[100010];

int main() {
    int N; cin >> N;
    string str;
    str = to_string(N);
    string rev = str;
    std::reverse(rev.begin(), rev.end());

    if (str == rev) {
      cout << "Yes" << endl;
      return 0;
    }
    for (int i = 0; i < 9; i++) {
      str.insert(0, "0");
      rev.append("0");
      if (str == rev) {
        cout << "Yes" << endl;
        return 0;
      }
    }

    cout << "No" << endl;
    return 0;

}


#include<stdio.h>
int main(){
    int n;
    scanf("%d", &n);
    int a[n],b[n];
    int temp;
    int maxa=0;
    int minb=1001;
    for (int i = 0;i< n; i++){
        scanf("%d",&a[i]);
    }
    for (int i = 0;i< n; i++){
        scanf("%d",&b[i]);
    }
    for (int i = 0; i < n; i++){
        if (a[i] > maxa) maxa=a[i];
        if (b[i] < minb) minb=b[i];
    }
    temp = minb-maxa+1;
    if (temp >= 0) printf("%d", temp);
    if (temp < 0) printf("0");
}

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

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';

///////////////////////////////////////////////////

int div3(ll k)
{
    int d = 0;
    while(true)
    {
        if (k == 1) return d;
        if (k % 3 != 0) return -1;
        d++;
        k /= 3;
    }
}

int main()
{
    ll N;
    io >> N;

    int a = -1, b = 1;
    ll bb = 5;
    while (bb < N)
    {
        if (int d = div3(N-bb); d >= 1)
        {
            a = d;
            break;
        }
        b++;
        bb *= 5;
    }

    if (a < 0)
    {
        io << "-1" << BR;
    }
    else
    {
        io << a << ' ' << b << BR;
    }

}


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

int main(){
  int N, S, D;
  cin >> N >> S >> D;
  int a=0;
  for(int i=0; i<N; i++){
    int X, Y;
    cin >> X >> Y;
    if(X<S && Y>D){
      cout << "Yes" << endl;
      a++;
      break;
    }
  }
  if(a==0){
    cout << "No" << endl;
  }
}

#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N, S, D;
    cin >> N >> S >> D;
    vector<int> X(N), Y(N);
    rep(i,N) cin >> X[i] >> Y[i];
    bool f = false;
    rep(i,N) if(X[i] < S && Y[i] > D) f = true;
    cout << (f ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
    double R, X, Y; cin >> R >> X >> Y;
    double d = sqrt(X * X + Y * Y);
    int ans = ceil(d / R);
    if (ans == 1 && d != R) ans++;
    cout << ans << endl;

    return 0;
}

#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 fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(ll i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define ones(x) __builtin_popcount(x)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define dbg(x) cout << (#x) << " = " << x << " "
#define fini cout << "\n";
#define line cout << "-----------------------------------\n";
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef tree<
ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int read (){
    int x = 0, f = 1; char s = getchar();while (s < '0' || s > '9') {if (s == '-') f = -1; s = getchar();}
    while (s >= '0' && s <= '9') x = x * 10 + s - '0', s = getchar();
    return x * f;
}
const ll M=2e5+7;
const ll N=1e6+7;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;

ll r,x,y;

void go(int ide){
	cin >> r >> x >> y;
	ld d = sqrt(x*x + y*y);

	if ((int)d < r) cout << "2\n";
	else cout << ceil(d/r) << "\n";
}

int main(){
    fastio;
    int tst=1;
    // cin >> tst;
    // cout << fixed << setprecision(12);

    fp(i,0,tst) go(i+1);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int price;
  string answer = "";
  price = N * 1.08;
  if(price < 206){
    answer = "Yay!";
  }
  else if(price == 206){
    answer = "so-so";
  }
  else{
    answer = ":(";
  }
  cout << answer << endl;
}

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

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

    int count = 0;
    int sub = 1;
    while(1){
        count += sub;

        if (count >= N){
            cout << sub<< endl;
            break;
        }
        sub += 1;

    }
}


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

typedef long long ll;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll power(ll x,ll y){ll res=1ll; while(y>0){if(y&(1ll)) res=res*x;y=y>>(1ll);x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	int n;cin>>n;
	vector<vector<int>> v(n,vector<int>(5,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<5;j++) cin>>v[i][j];
	}
	// now we will do binary search by answer
	int hi=1e9;int lo=1;
	while(hi>lo)
	{
		int mid=(lo+hi+1)/2;
		// we need the biggest possible
		vector<int> b(n,0);
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<5;j++)
			{
				if(v[i][j]>=mid) b[i]|=(1<<j);
			}
		}
		vector<vector<int>> dp(4,vector<int>((1<<5),0));
		dp[0][0]=1;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=2;j++)
			{
				for(int k=0;k<(1<<5);k++)
				{
					if(dp[j][k])
					{
						dp[j+1][k|b[i]]=1;
					}
				}
			}
		}
		if(dp[3][(1<<5)-1]) lo=mid;
		else hi=mid-1;
	}
    cout<<lo<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!

/*
	* 	Created By:    'Present_Sir'
	* 	Created On:    02.05.2021 10:06:31
*/

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define int long long
//#define i_n_p_u_t(t) cin >> t
#define i_n_p_u_t(t) t = 1

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

	vector < vector < int > >  v(n);
	for(int i=0; i<n; ++i){
		int a, b, c, d, e;
		cin >> a >> b >> c >> d >> e;
		v[i] = {a, b, c, d, e};
	}

    auto check = [&](int mid){
        vector < int > t;
        map < int, int > mp;
        for(int i=0; i<n; ++i){
            int  _s=0;
            for(int j=0; j<5; ++j){
                if(v[i][j] >= mid){
                    _s = ( (_s << 1) | 1 );
                }else{
                    _s = _s << 1;
                }
            }
            if(mp.count(_s) and mp[_s]==3)continue;
            t.push_back(_s);
            mp[_s] += 1;
        }

        for(int i=0; i<sz(t); ++i){
            for(int j=i+1; j<sz(t); ++j){
                for(int k=j+1; k<sz(t); ++k){
                    bool ok = true;
                    for(int p=0; p<5; ++p){
                        if( ( t[i]&(1ll<<p) ) == 0 and ( t[j]&(1ll<<p) ) == 0 and ( t[k]&(1ll<<p) ) == 0)ok=false;
                    }
                    if(ok) return true;
                }
            }
        }
        return false;
    };

    int l = 1, r = 1e9+5;
    while(l<=r){
        int mid = (l+r) >> 1;
        if(check(mid)){
            l = mid+1;
        }else{
            r = mid-1;
        }
    }

    int ans = l-1;
    cout << ans << "\n";

}

int32_t main(){
    IOS;

    int t;
    i_n_p_u_t(t);

    for(int i=1; i<=t; ++i){
        // cout << "Case #" << i << ": ";
		solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> G(N);
    for (int i = 0; i < N; i++) {
        G[i] = (1<<i);
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a] |= (1<<b);
        G[b] |= (1<<a);
    }

    vector<bool> is_complete(1<<N);
    for (int i = 0; i < (1<<N); i++) {
        bool check = true;
        for (int j = 0; j < N; j++) {
            if (((i>>j)&1) == 0) {
                continue;
            }
            if ((G[j]&i) != i) {
                check = false;
            }
        }
        is_complete[i] = check;
    }

    vector<int> dp(1<<N, INF);
    dp[0] = 0;
    for (int i = 0; i < (1<<N); i++) {
        int other = (1<<N) - 1 - i;
        for (int sub = other; ; sub = (sub - 1) & other) {
            if (sub == 0) {
                break;
            }

            if (is_complete[sub]) dp[i | sub] = min(dp[i | sub], dp[i] + 1);
        }
    }
    cout << dp[(1<<N) - 1] << endl;
}

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t,k;
bool vis[maxn];
int pos[maxn];

int main(){
    read(n);
    fo(i,1,n) read(a[i]),pos[a[i]]=i;
    vector<int>ans;
    fod(i,n,1){
        if(pos[i]!=i){
            while(pos[i]!=i){
                if(vis[pos[i]]) {
                    puts("-1");return 0;
                }
                vis[pos[i]] = 1;
                ans.push_back(pos[i]);
                int p = pos[i];
                swap(a[p],a[p+1]);
                pos[a[p]] = p;pos[a[p+1]] = p+1;
            }

        }
    }

    if(ans.size()!=n-1){
        puts("-1");return 0;
    }

    for(auto to:ans) printf("%d\n",to);

    Please AC;
}


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

int main() {
    ll a,b,c;
    std::cin >> a>>b>>c;

    vector<vector<vector<ld>>> memo(100,vector<vector<ld>>(100,vector<ld>(100,-1)));

    function<ld(ll,ll,ll)> rec = [&] (ll a,ll b,ll c) {
        if(a==100||b==100||c==100) return (ld)0;
        if(memo[a][b][c]!=-1)return memo[a][b][c];

        return memo[a][b][c] = 1+a/(a+b+c+0.0)*rec(a+1,b,c)+b/(a+b+c+0.0)*rec(a,b+1,c)+c/(a+b+c+0.0)*rec(a,b,c+1);
    };

    std::cout <<setprecision(20)<< rec(a,b,c) << std::endl;
}

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

void solve() {
    int n, s, k;
    cin >> n >> s >> k;
    int m = sqrt(n) + 1;
    map<int, int> mp;
    int jk = 0;
    for (int j = 0; j < m; ++j) {
        if (mp.count(jk)) break;
        mp[jk] = j;
        jk = (jk + k) % n;
    }
    long long mk = jk;
    for (int i = 0; i < m; ++i) {
        int now = ((-s - mk * i) % n + n) % n;
        if (mp.count(now)) {
            cout << m * i + mp[now] << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}


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

#define REP(i, n) for(ll i=0;i<ll(n);i++)
#define FOR(i, a, b) for(ll i=a;i<=ll(b);i++)

int read_int() {
    int n;
    scanf("%d", &n);
    return n;
}

int main() {
    string S;
    bool flag = true;
    cin >> S;
    REP(i, S.length()) {
        if (i%2 == 1){
            if (islower(S[i])) flag = false;
        }
        else {
            if (isupper(S[i])) flag = false;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

string s;

int main()
{
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		if (!((i % 2 == 0 && s[i] >= 'a' && s[i] <= 'z') || (i % 2 == 1 && s[i] >= 'A' && s[i] <= 'Z')))
		{
			cout << "No";
			return 0;
		}
	cout << "Yes";
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct ArbitraryModInt {
  int x;
  ArbitraryModInt() : x(0) {}
  ArbitraryModInt(int64_t y) : x(y >= 0 ? y % get_mod() : (get_mod() - (-y) % get_mod()) % get_mod()) {}

  static int &get_mod() {
    static int mod = 0;
    return mod;
  }
  static void set_mod(int md) {
    get_mod() = md;
  }

  ArbitraryModInt &operator+=(const ArbitraryModInt &p) {
    if((x += p.x) >= get_mod()) x -= get_mod();
    return *this;
  }
  ArbitraryModInt &operator-=(const ArbitraryModInt &p) {
    if((x += get_mod() - p.x) >= get_mod()) x -= get_mod();
    return *this;
  }
  ArbitraryModInt &operator*=(const ArbitraryModInt &p) {
    unsigned long long a = (unsigned long long) x * p.x;
    unsigned xh = (unsigned) (a >> 32), xl = (unsigned) a, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (get_mod()));
    x = m;
    return *this;
  }
  ArbitraryModInt &operator/=(const ArbitraryModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ArbitraryModInt operator-() const { return ArbitraryModInt(-x); }
  ArbitraryModInt operator+(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) += p; }
  ArbitraryModInt operator-(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) -= p; }
  ArbitraryModInt operator*(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) *= p; }
  ArbitraryModInt operator/(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) /= p; }
  bool operator==(const ArbitraryModInt &p) const { return x == p.x; }
  bool operator!=(const ArbitraryModInt &p) const { return x != p.x; }

  ArbitraryModInt inv() const {
    int a = x, b = get_mod(), u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ArbitraryModInt(u);
  }
  ArbitraryModInt pow(int64_t n) const {
    ArbitraryModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ArbitraryModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ArbitraryModInt &a) {
    int64_t t;
    is >> t;
    a = ArbitraryModInt(t);
    return (is);
  }
};

using mint = ArbitraryModInt;

void mul(vector<mint> &dp, int d) {
  int MAX = len(dp)-1;
  rrep(i,MAX+1,d) {
    dp[i] -= dp[i - d];
  }
}

void div(vector<mint> &dp, int d) {
  int MAX = len(dp);
  rep(i,d,MAX+1) {
    dp[i] += dp[i - d];
  }
}

int main() {
  int n, k, m;
  cin >> n >> k >> m;
  mint::set_mod(m);
  vector<mint> dp(n*n*k+1, 0);
  vector<vector<mint>> vals(n+1, vector<mint>(n*n*k+1));
  dp[0] = mint(1);
  vals[0][0] = dp[0];
  rep(i,1,n) {
    div(dp, i);
    mul(dp, i*(k+1));
    rep(j,0,n*n*k) {
      vals[i][j] = dp[j];
    }
  }
  rep(i,0,n) {
    mint ans = 0;
    rep(j,0,n*n*k+1) {
      ans += vals[i][j] * vals[n-i-1][j];
    }
    cout << ans*(k+1)-1 << endl;
  }
  return 0;
}

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

typedef long long ll;

bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
	constexpr ll ll_max = numeric_limits<ll>::max();

	bool first_boost = true;

	lower_bound = 0;
	upper_bound = x;
	while (upper_bound - lower_bound > 1)
	{
		if (first_boost)
		{
			ll guess = (ll)sqrt((double)x);
			lower_bound = max(guess - 1, (ll)0);
			upper_bound = lower_bound + 3;
			first_boost = false;
		}

		ll newval = (lower_bound + upper_bound) / 2;
		if ((newval != 0) && (newval > ll_max / newval))  // newval*newval becomes overflow
			upper_bound = newval;  // because overflow means newval is too big
		else
		{
			ll newval_sqr = newval * newval;
			if (newval_sqr < x)
				lower_bound = newval;
			else
				upper_bound = newval;
		}
	}

	if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
	}
	else
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
		else if (upper_bound * upper_bound == x)
			lower_bound = upper_bound;
	}
	bool is_exact = (lower_bound == upper_bound);
	return is_exact;
}

ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);

ll ll_floor(ll x, int digit)
{
	if (x < 0)
		return -ll_ceil(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	return ans;
}

ll ll_ceil(ll x, int digit)
{
	if (x < 0)
		return -ll_floor(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	if (modval != 0)
		ans += div;
	return ans;
}
int main() {
    ll N;
	ll X;
	cin >> N >> X;
	X*=100;

	ll V[N];
	ll P[N];

	for(int i = 0; i<N ; i++) {
	cin >> V[i] >> P[i];
	}

	ll ans = 0;

	for(int i = 0; X >=0 && i<N; i++) {
		ans ++;
		X -= V[i]*P[i];
	}

	if(X >= 0){
		ans = -1;
	}

  cout << ans << endl;

  return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define ins insert
#define sz(x) (int)x.size()
#define dbg(x) cout << x << "\n";

const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
const long double Eps = 1e-9;

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

using namespace std;

#define int long long int

void TestCase (){
        int n, q;
        cin >> n >> q;
        vector <int> a(n + 1, 0), b(n + 2, 0);
        for(int i = 1; i<=n; i++){
                cin >> a[i];
                if(i == 1) b[i] = a[i] - 1;
                else b[i] = b[i - 1] + a[i] - a[i - 1] - 1;
        }
        b[n + 1] = Inf;
        while(q--){
                int k;
                cin >> k;

                int lb = 1, ub = n + 1, pos = n + 2;
                while(lb <= ub){
                        int mid = (lb + ub) / 2;
                        if(k <= b[mid]){
                                pos = min(pos, mid);
                                ub = mid - 1;
                        }
                        else lb = mid + 1;
                }

                k -= b[pos - 1];
                cout << a[pos - 1] + k << "\n";
        }
}

#undef int

int main(){
        IOS;
        int T = 1;
        // cin >> T;
        while(T--){
                TestCase();
                cout << "\n";
        }
        return 0;
}

#include <bits/stdc++.h>
#define Fr(i,a,b) for(int i=(a);i<=(b);++i)
#define Fl(i,a,b) for(int i=(a);i>=(b);--i)
#define Fe(i,u) for(int i=H[u];i;i=e[i].nx)
#define ms(a,x) memset((a),(x),sizeof(a));
using namespace std;
int N,W;
long long p[200005],f;
int main()
{
	scanf("%d%d",&N,&W);
	Fr(i,1,N)
	{
		int s,t,x;
		scanf("%d%d%d",&s,&t,&x);
		p[s]+=x,p[t]-=x;
	}
	Fr(i,0,200000)
	{
		f+=p[i];
		if(f>W)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
  [[nodiscard]]
#endif  // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint final : private F
{
public:
  template <typename G>
  explicit constexpr FixPoint(G&& g) noexcept
    : F{std::forward<G>(g)}
  {}

  template <typename... Args>
  constexpr decltype(auto)
  operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif  // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};  // class FixPoint

#if defined(__cpp_deduction_guides)
template <typename F>
FixPoint(F&&)
  -> FixPoint<std::decay_t<F>>;
#endif  // defined(__cpp_deduction_guides)

namespace
{
  template <typename F>
#if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  #  if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#  elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_)
_Check_return_
#  endif  // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#endif  // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  inline constexpr decltype(auto)
  makeFixPoint(F&& f) noexcept
  {
    return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)};
  }
}  // namespace

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 T;
	cin >> T;
	REP(_, T) {
	  int64 N;
	  cin >> N;
	  if (N % 4 == 0) {
	    cout << "Even" << endl;
	  } else if (N % 2 == 0) {
	    cout << "Same" << endl;
	  } else {
	    cout << "Odd" << endl;
	  }
	}
}

#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;

// convert number to string to_string(x);
// convert string to number stoi();

// ll mulmod(ll x,ll y)
// {
//     return ((x%mod)*(y%mod))%mod;
// }

// ll binpow(ll x, ll y)
// {
//     ll z = 1;
//     while(y > 0)
//     {
//         if(y % 2 == 1)
//             z = mulmod(z, x);
//         x = mulmod(x, x);
//         y /= 2;
//     }
//     return z;
// }

// ll ncr(ll n,ll r)
// {
//     return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2));
// }

// ll pwr(ll n,ll m)
// {
//   if(n==1 || m==0)
//     return 1;

//   ll x=pwr(n,m/2);
//   if(m%2==0)
//     return x*x;
//   else
//     return n*x*x;
// }

// ll pwr(ll n,ll m,ll b)
// {
//   if(n==1 || m==0)
//     return 1;

//   ll x=pwr(n,m/2,b);
//   if(m%2==0)
//     return ((x%b)*(x%b))%b;
//   else
//     return ((n%b)*(((x%b)*(x%b))%b))%b;
// }
bool compare(pair<pair<ll,ll>,ll>a,pair<pair<ll,ll>,ll>b)
{
  return a.f.s+2*a.f.f > b.f.s+2*b.f.f;
}

void solve()
{
  ll n,s1=0,s2=0,ans=0;
  cin >> n;
  vector<pair<pair<ll,ll>,ll>>v(n);
  fr(i,n)
  {
    cin >> v[i].f.f  >> v[i].f.s;
    v[i].s=v[i].f.f+v[i].f.s;
    s1+=v[i].f.f;
  }
  sort(v.begin(),v.end(),compare);

  fr(i,n)
  {
    if(s2>s1)
      break;
    else
    {
      ans++;
      s2+=v[i].s;
      s1-=v[i].f.f;
    }
  }
  cout << ans;
  return ;
}

int main()
{
  fastio

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

  while(t--)
    solve();

  runtime
}


// -- //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 5e5+228;
const ll C = 600000;
char c[3*N];

signed main(){
	cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    ll l=C, r=C;
    ll rc=1;
    for(auto i : s){
        if(i=='R'){
            if(rc==1){
                rc=-1;
                swap(l, r);
                r--, l--;
            }else{
                rc=1;
                swap(l, r);
                r++, l++;
            }
        }else{
            if(abs(r-l)>0&&c[r-rc]==i)r-=rc;
            else{
                c[r]=i;
                r+=rc;
            }
        }
    }
    string res="";
    if(rc==-1){
        for(ll i = l;i>r;i--) res.push_back(c[i]);
    }else{
        for(ll i = l;i<r;i++) res.push_back(c[i]);
    }
    cout<<res<<'\n';
}

#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

vector< int > calc(int n, vector< int > ps) {
  vector< int > res;
  for (auto &p : ps) {
    p--;
  }

  // v : 0-indexed
  auto find_idx = [&](int v) {
    range(i, 0, n) {
      if (ps[i] == v) return i;
    }
    return -1ll;
  };

  int k = 0;

  auto swap_check = [&](int i) {
    return ((i & 1) == (k & 1));
  };

  auto swap_query = [&](int i) {
    // if ((i + k) % 2 != 0) return;
    swap(ps[i], ps[i + 1]);
    k++;
    res.emplace_back(i + 1);
  };

  rrange(v, 0, n) {
    int idx = find_idx(v);
    if (idx == v) continue;

    while (not swap_check(idx)) {
      if (idx == (k&1) + 1) idx--;
      swap_query(k & 1);
    }

    range(i, idx, v) {
      swap_query(i);
    }
  }

  if (ps[n-2] != n-2) {
    swap_query(n-2);
  }

  return res;
}

void solve() {
  int t = input();
  while (t--) {
    int n = input();
    vector< int > ps(n);
    cin >> ps;
    auto as = calc(n, ps);
    cout << as.size() << endl;
    cout << as << endl;
  }
}

signed main() {
  solve();
}


#include<iostream>
using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int main() {

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

	int mx = 0;
	for (int i = 1; i <= b; i++) {
		int cnt = (b / i - (a - 1) / i);
		if (cnt >= 2) {
			mx = max(mx, i);
		}
	}
	cout << mx << endl;

	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define re register int
#define rl register ll
#define rep(i,a,b) for(re i=(a),i##end=(b);i<=i##end;++i)
#define pre(i,a,b) for(re i=(a),i##end=(b);i>=i##end;--i)
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define cpy(a1,a2) memcpy(a1,a2,sizeof(a2))
using namespace std;

ll a,b,c,d,ans;

inline int rint()
{
    re 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<<3)+(x<<1)+(ch^48); ch=getchar();}
    return x*f;
}
inline ll rll()
{
    rl x=0ll,f=1ll; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1ll; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48); ch=getchar();}
    return x*f;
}

signed main()
{
	a=rint(),b=rint(),c=rint(),d=rint();

	if(c*d<=b) return printf("-1"),0;
	while(a+ans*b>ans*c*d) ++ans;
	printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 998244353;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a % m + m) % m;}

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n);
    ll ans = 0;
    rep(i, n){
        cin >> a[i];
        ans = mod(ans + a[i]*a[i], MOD);
    }

    sort(ALL(a), greater<ll>());

    ll sum = 0;
    rep(i, n){
        ans = mod(ans + a[i] * sum, MOD);
        sum = mod(sum * 2 + a[i], MOD);
    }

    cout << ans << endl;
}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
const int MAXN=1;
const ll MOD=998244353;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
ll inv[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
void cal_factor_inv(){inv[0]=1;inv[MAXN-1]=qpow(factor[MAXN-1],MOD-2);for(int u=MAXN-2;u>=1;u--){inv[u]=inv[u+1]*(u+1)%MOD;}}
void init_factor(){cal_factor();cal_factor_inv();}
ll C(ll n,ll k){if(n<k)return 0;return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
template <int _MOD> struct Mint
{
    long long v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int &_v) { return *this = Mint(_v); }
    Mint operator = (const long long &_v) { return *this = Mint(_v); }
    bool operator ! () const { return !this->v; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) const { return Mint(v+b.v); }
    Mint operator - (const Mint &b) const { return Mint(v-b.v); }
    Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) const { return Mint(b.inv()*v); }
    Mint& operator += (const Mint &b) { return *this = *this+b; }
    Mint& operator -= (const Mint &b) { return *this = *this-b; }
    Mint& operator *= (const Mint &b) { return *this = *this*b; }
    Mint& operator /= (const Mint &b) { return *this = *this/b; }
    Mint operator - () const { return Mint(-v); }
    Mint& operator ++ () { return *this += 1; }
    Mint& operator -- () { return *this -= 1; }
    Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; }
    Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const {
        if(v==0)return Mint(1);
        return pow(_MOD-2);
    }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v;mt.v=mt.v%_MOD; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;
void solve(){
    int n;
    cin>>n;
    vector<mint>A(n);
    mint tail=mint(0),acc=mint(2);
    for(int u=0;u<n;u++){
        cin>>A[u];
    }
    sort(A.begin(),A.end());
    for(int u=0;u<n;u++){
        if(u<2)tail+=A[u];
        else {
            tail+=A[u]*acc;
            acc*=mint(2);
        }
    }
    mint ans=mint(0);
    for(int u=0;u<n;u++){
        if(u==0)ans+=A[u]*tail;
        else {
            tail=(tail-A[u-1]-A[u])/mint(2)+A[u];
            ans+=A[u]*tail;
        }
    }
    cout<<ans<<"\n";
}
// #define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}


#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long double a, b;
    cin >> a >> b;
    long double res = 100 * (a - b) / a;
    cout << fixed << setprecision(5) << res << endl;

    return 0;
}

#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
void solve(){
	float a, b; cin >> a >> b ;
	vector<float>arr;
	arr.push_back(a);arr.push_back(b);
	sort(arr.begin(),arr.end());
	cout << 100-((arr[0]*100)/arr[1]) << "\n";
	return;
}

int main(){
	solve();
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
    a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

ll norm(ll a)
{
    a%=mod;
    if(a<0)
        a+=mod;
    return a;
}

ll add(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a+b);
}

ll mul(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a*b);
}

ll sub(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a-b);
}

ll divi(ll a, ll b)
{
    b = powa(b,mod-2,mod);
    return mul(a,b);
}

#define N 105

void mul(ll res[N][N], ll m1[N][N], ll m2[N][N])
{
    ll temp[N][N];
    memset(temp,0,sizeof(temp));
    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            for(ll k=0;k<N;k++)
            {
                temp[i][j]+=(m1[i][k]*m2[k][j])%mod;
                temp[i][j]%=mod;
            }
    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            res[i][j] = temp[i][j];

}

void powam(ll mat[N][N], ll n)
{
   ll res[N][N];
   memset(res,0,sizeof(res));
   for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            if(i == j)
                res[i][j] = 1;

   while(n>0)
   {
       if(n%2 == 1)
           mul(res,res,mat);

       n>>=1;
       mul(mat,mat,mat);
   }

   for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            mat[i][j] = res[i][j];

}

int main()
{
  FAST/**/

  ll n,m,k;
  cin>>n>>m>>k;

  ll arr[n];
  rep(n)
        cin>>arr[i];
  ll mat[N][N];
  memset(mat,0,sizeof(mat));

  ll adj[N][N];
  memset(adj,0,sizeof(adj));

  vector<ll> gr(n,0);

  ll i2 = powa(2,mod-2,mod);

  rep(m)
  {
      ll x,y;
      cin>>x>>y;
      x--, y--;
      gr[x]++;
      gr[y]++;
      adj[x][y] = adj[y][x] = 1;
  }

  rep(n)
        repi(j,n)
        {
            if(i == j)
                mat[i][j] = sub(m, mul(1,mul(gr[i],i2)));
            else if(adj[i][j])
                mat[i][j] = i2;
        }
  powam(mat,k);
  ll fac = powa(powa(m,mod-2,mod),k,mod);
  ll ans[n];
  memset(ans,0,sizeof(ans));
  rep(n)
  {
      repi(j,n)
            ans[i] = add(ans[i], mul(mat[i][j], arr[j]));
      ans[i] = mul(ans[i], fac);
      cout<<ans[i]<<'\n';
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    string s,t;cin>>s>>t;
    vi a,b;
    rep(i,n){
        if(s[i]=='0')a.pb(i);
        if(t[i]=='0')b.pb(i);
    }
    if(a.size()!=b.size())dame(-1);
    ll ans=0;
    rep(i,a.size())if(a[i]!=b[i])ans++;
    out(ans);
}


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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}
template <typename T>
T Min(T a,T b){ return a<b?a:b; }
template <typename T>
T Max(T a,T b){ return a>b?a:b; }

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;

	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	int a,b;cin>>a>>b;
	cout<<(a+b)/2<<" "<<(a-b)/2<<endl;

	/*
	int test1;cin>>test1;while(test1--){

	 }
	 //*/
return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e17
#define EPSILON 1e-14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//浮動小数点はなるべく使うな、powも気をつけろ
int main()
{
    ll A, B;
    cin >> A >> B;
    A += B;
    if(A >= 15 && B >= 8){
        cout << 1 << '\n';
    }
    else if(A >= 10 && B >= 3){
        cout << 2 << '\n';
    }
    else if(A >= 3){
        cout << 3 << '\n';
    }
    else
    {
        cout << 4 << '\n';
    }

}


/**
*    author:  Dooloper
*    created: 26.10.2020 13:52:11
**/
#include <iostream>
#include <string>

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

int main() {
    ll n,k;
    cin >> n >> k;

    rep(i,k){
      int small,b;
        vector<int> tmp;
        string s=to_string(n);
        rep(j,(ll)s.size()){
            //if(s.at(j)-'0'!=0){
                tmp.push_back(s.at(j)-'0');
           // }
        }
        s="";
        sort(tmp.begin(),tmp.end());
        reverse(tmp.begin(),tmp.end());
        rep(j,(ll)tmp.size()){
          //cout << tmp.at(j) << endl;
            s.push_back(tmp.at(j)+'0');
        }
      //cout << s << endl;
      if(s=="")
        b=0;
      else
        b=stoi(s);
        s="";
        reverse(tmp.begin(),tmp.end());
        rep(j,(ll)tmp.size()){
          if(tmp.at(j)!=0)
            s.push_back(tmp.at(j)+'0');
        }
      if(s=="")
        small=0;
      else
        small=stoi(s);
    n=b-small;
//cout << b << small << endl;
    }

    cout << n << endl;

    }

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

const int mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> lit(h,vector<int>(w,0));
  rep(i,h){
    int cnt = 0;
    rep(j,w){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
    cnt = 0;
    for(int j = w-1;j>=0;j--){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
  }

  rep(j,w){
    int cnt = 0;
    rep(i,h){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
    cnt = 0;
    for(int i = h-1;i>=0;i--){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
  }
  // rep(i,h)rep(j,w){
  //   cout << lit[i][j] << " \n"[j==w-1];
  // }
  modint ans = 0;
  int tot_cnt = 0;
  rep(i,h)rep(j,w) if(s[i][j]=='.') {tot_cnt++;lit[i][j]++;}
  rep(i,h)rep(j,w){
    ans += ((modint) 2).pow(tot_cnt-lit[i][j]) * (((modint) 2).pow(lit[i][j]) - 1);
  }
  cout << ans << endl;

  return 0;

}


#include <iostream>
using namespace std;

int main() {
	double A,B,sum;
	cin>>A>>B;
	sum=A*B/100;
	cout<<sum;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll modpow(ll a, ll n, ll m)
{
  ll ret = 1;
  while (n > 0)
  {
    if (n % 2 == 1) ret = ret * a % m;
    a = a * a % m;
    n /= 2;
  }
  return ret;
}

int main()
{
  ll N, M;
  cin >> N >> M;

  ll X = modpow(10, N, M * M);
  ll Y = modpow(10, N, M);

  cout << mod(X - Y, M * M) / M << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s;
  cin >> t;
  vector<int>v,v2;
  rep(i,n){
    if(s[i]=='1')v.push_back(i);
    if(t[i]=='1')v2.push_back(i);
  }
  ll cnt=v.size(),cnt2=v2.size();
  if(abs(cnt-cnt2)%2 || cnt2>cnt){
    cout << -1 << endl;
    return 0;
  }
  bool used[cnt]={};
  ll ans=0;
  int j=0;
  rep(i,cnt){
    if(used[i])continue;
    if(i+1<cnt && j<cnt2 && v[i]<v2[j]){
      ans+=v[i+1]-v[i];
      used[i+1]=true;
    }
    else if(j<cnt2 && v[i]>v2[j]){
      ans+=v[i]-v2[j];
      j++;
    }
    else if(j<cnt2 && v[i]==v2[j]){
      j++;
    }
    else if(j==cnt2 && i+1<cnt){
      ans+=v[i+1]-v[i];
      used[i+1]=true;
    }
  }
  if(j!=cnt2){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

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

#define int long long
#define FOR(i, size) for (int i = 0; i < size; i++)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define MOD 1000000007

#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template <typename... Args>
void logger(string vars, Args &&...values)
{
	cout << vars << " = ";
	string delim = "";
	(..., (cout << delim << values, delim = ", "));
}

template <typename T>
void print_list(vector<T> collection, bool newline = true)
{
	for (const auto &item : collection)
	{
		cout << item << " ";
	}
	if (newline)
		cout << endl;
}

#define ONE_TESTCASE 1

int n, m, timer;

void Solve()
{
	cin >> n;
	vector<pair<double, double>> v;
	FOR(i, n)
	{
		int t;
		cin >> t;

		double a, b;
		cin >> a >> b;

		if (t == 2)
		{
			b -= 0.1;
		}
		else if (t == 3)
		{
			a += 0.1;
		}
		else if (t == 4)
		{
			a += 0.1;
			b -= 0.1;
		}

		v.push_back({a, b});
	}

	int cnt = 0;
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if ((v[i].second >= v[j].first and v[i].first <= v[j].first) or (v[j].second >= v[i].first and v[i].first >= v[j].first))
				cnt++;
		}
	}
	cout << cnt;
}

int32_t main()
{

#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);

#if ONE_TESTCASE
	int test = 1;
#else
	int test;
	cin >> test;
#endif

	for (int t = 1; t <= test; t++)
	{
		Solve();
		cout << endl;
	}
}


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

#define FIO                     ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t)                   int t; cin >> t; for(int i = 1; i <= t; i++)
#define deb(x)                  cerr << #x << " = " << x << endl
#define deb2(x, y)              cerr << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)             for(i = a; i < n; i++)
#define f1(i, a, n)             for(i = a; i <= n; i++)
#define ini(x, y)               memset(x, y, sizeof(x))
#define all(x)                  x.begin(), x.end()
#define sz(x)                   x.size()
#define ll                      long long int
#define pb                      push_back
#define ppb                     pop_back
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define M                       1000000007
#define endl                    '\n'
#define bits(x)                 __builtin_popcountll(x)
#define zrbits(x)               __builtin_ctzll(x)
#define vi                      vector<int>
#define pii                     pair<int,int>
#define vpii                    vector<pii>
#define ordered_set             tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>

const int N = 1e5 + 1;
const int MX = 1e9;
const ll INF = 1e18;

using namespace std;
using namespace __gnu_pbds;

inline ll uceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
inline ll mod(ll x) {return ( (x % M + M) % M );}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {for(auto& x : v) os << x << " "; return os << '\n';}
template<typename... T> void in(T&... args) {((cin >> args), ...);}
template<typename... T> void out(T&&... args) {((cout << args << endl), ...);}
template<typename... T> void out2(T&&... args) {((cout << args << " "), ...);}

void solve() {
        ll n, w, i, j;
        cin >> n >> w;

        vector<pair<ll,ll>> v;
        f0(i, 0, n) {
                ll x, y, c;
                cin >> x >> y >> c;
                v.pb({x,c});
                v.pb({y,-c});
        }
        sort(all(v));

        ll sum = 0;
        for(auto it : v) {
                sum += (it.ss);
                if(sum > w) {
                        out("No");
                        return;
                }
                if(sum < 0) sum = 0;
        }
        out("Yes");
}

int main () {
        FIO;
        // TC(t)
        solve();
        return 0;
}

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long  long ll;
const ll MAX = 1e18 + 100;
const int maxN = 1e5 + 5;
const int maxM = 2e5 + 5;
ll head[maxN], cnt;
struct edge {
	ll c, d;
	ll to, best_time, next;
}e[maxM];
ll n, m, dis[maxN];
void add_e(ll x, ll y, ll val_t, ll c, ll d)
{
	e[++cnt].to = y;
	e[cnt].best_time = val_t;
	e[cnt].c = c; e[cnt].d = d;
	e[cnt].next = head[x];
//	cout<<x<<' '<<head[x]<<endl;
	head[x] = cnt;
//	printf("cnt=%d\n",cnt);
//	cout<<x<<' '<<head[x]<<endl<<endl;
}
struct node {
	ll time, dis, pos;
	bool operator < (const node& a)const {
		return dis > a.dis;
	}
}t;
void dij()
{
	int i;
	priority_queue<node>qu;
	dis[1] = 0;
	qu.push(node{ 0, 0, 1 });
	while (!qu.empty())
	{
		t = qu.top(); qu.pop();
		int now = t.pos;
		if (dis[now] != t.dis) continue;
		for (i = head[now]; i; i = e[i].next)
		{
			int To = e[i].to;
			if (t.time < e[i].best_time)
			{//要等待时间
				int minn_dis = e[i].c + (ll)(e[i].d / (e[i].best_time + 1));

				if (dis[To] > dis[now] + minn_dis + e[i].best_time - t.time)
				{
					dis[To] = dis[now] + minn_dis + e[i].best_time - t.time;
					qu.push(node{ dis[To], dis[To], To });
				}
			}
			else
			{//不用等待时间
				int minn_dis = e[i].c + (ll)(e[i].d / (t.time + 1));
				if (dis[To] > dis[now] + minn_dis)
				{
					dis[To] = dis[now] + minn_dis;
					qu.push(node{ dis[To], dis[To], To });
				}
			}
		}
	}
}
int main()
{
	int i, j;
	ll x, y;
	ll c, d;
	cin >> n >> m;
	for (i = 0; i < m; i++)
	{
		cin >> x >> y >> c >> d;
		if (x == y)continue;
		ll minn = MAX, tt;
		double pos = sqrt(d);
		for (j = (int)pos - 2; j <= (int)pos + 2; j++)
			if (j >= 0)
				if (minn > (c + (int)(d / (j + 1)) + j))
				{
					minn = c + (int)(d / (j + 1)) + j;
					tt = j;
				}
		add_e(x, y, tt, c, d);
		add_e(y, x, tt, c, d);
	}
	for (i = 1; i <= n; i++)
		dis[i] = MAX;
	dij();
	if (dis[n] == MAX)
		cout << -1 << endl;
	else
		cout << dis[n] << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <set>
using namespace std;
using ll = long long;

const long long BASE_NUM = 1000000007;
//https://scrapbox.io/pocala-kyopro/%E6%8B%A1%E5%BC%B5%E3%83%A6%E3%83%BC%E3%82%AF%E3%83%AA%E3%83%83%E3%83%89%E3%81%AE%E4%BA%92%E9%99%A4%E6%B3%95
// https://ei1333.github.io/luzhiled/snippets/math/combination.html
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
using modint = ModInt< BASE_NUM >;

template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

using modint = ModInt< BASE_NUM >;

int main()
{
  ll N, M, K;
  cin >> N >> M >> K;
  Combination<modint> combination(2000000);
  if (N - M > K){
    cout << 0 << endl;
  }else if(N == K){
    cout << combination.C(N+M,N) << endl;
  }else{
    cout << combination.C(N+M,N) - combination.C(N+M,N-K-1) << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 3005;

// Mod int
const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint& operator/=(const mint& a){ (x*=a.pow(mod-2).x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  mint pow(ll t) const {
    if(!t) return 1;
    mint res = pow(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
struct comb {
  vm f, g;
  comb(){}
  comb(int mx):f(mx+1),g(mx+1) {
    f[0] = 1;
    rrep(i,mx) f[i] = f[i-1]*i;
    g[mx] = f[mx].pow(mod-2);
    for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
  }
  mint operator()(int a, int b) {
    if (a < b) return 0;
    return f[a]*g[b]*g[a-b];
  }
};
//

mint dp[MX][MX];

int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  dp[0][0] = 1;
  rep(i,n+1)drep(j,n+1) {
    dp[i+1][j+1] += dp[i][j];
    if (j%2 == 0) dp[i][j/2] += dp[i][j];
  }
  cout<<dp[n][k]<<endl;
  return 0;
}


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

int main()
{
  int a, b;
  cin >> a >> b;

  int x, y;
  x = (a + b) / 2;

  y = (a - b) / 2;

  cout << x << " " << y;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert
#define mp make_pair
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

#ifndef ONLINE_JUDGE
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl;
#else
#define deb(x)
#endif

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18;
const ld pie = acos((ld)-1);

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

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

void __print(int x) {cerr<<x;}
void __print(char x) {cerr<<x;}
void __print(string x) {cerr<<x;}
void __print(float x) {cerr<<x;}
void __print(double x) {cerr<<x;}
void __print(bool x) {cerr<<x;}
void __print(ll x) {cerr<<x;}

template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

int main(){

	int a,b;
	scanf("%d%d",&a,&b);

	int x = (a+b)>>1;
	int y = a - x;

	printf("%d %d\n",x,y);

	return 0;

	/*STUFF TO LOOK:
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
int n,a[200005],maxx,sum,s2;
void solve()
{
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sum=a[1],s2=a[1];
	ans=a[1]*2;
	maxx=a[1];
	cout<<ans<<endl;
	for(int i=2;i<=n;i++)
	{
		s2+=a[i];
		maxx=max(maxx,a[i]);
		sum+=s2;
		cout<<sum+maxx*i<<endl;
	 }

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

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
template<class T>using uset = unordered_set<T>;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

#pragma region graph
struct edge{
    ll from, to, cost;
    bool operator<(const edge& r) const{return cost<r.cost;}
    bool operator>(const edge& r) const{return cost>r.cost;}
};
struct graph{
    ll V;
    vector<vector<edge> > G;
    graph(ll n){
        init(n);
    }
    void init(ll n){
        V = n;
        G.resize(V);
    }
    // 無向グラフ
    void add_edge(ll s, ll t, ll cost = 1){
        add_diedge(s, t, cost);
        add_diedge(t, s, cost);
    }
    // 有向グラフ
    void add_diedge(ll s, ll t, ll cost = 1){
        if(s < 0 || t < 0 || s >= V || t >= V) return;
        G[s].push_back({s, t, cost});
    }
    auto pos2d(ll height, ll width){
        return [height, width](ll y, ll x){
            return
                (y < 0 || y >= height || x < 0 || x >= width)
                ? -1
                : y*width + x;
        };
    }
};
#pragma endregion

// O(|E|log|V|)
vector<ll> dijkstra(const graph& g, ll s){
    vector<ll> d(g.V, INF);
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P>> que;
    que.push({0, s});
    while(!que.empty()){
        auto [c, v] = que.top(); que.pop();
        if(d[v]<c) continue;
        for(auto e : g.G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                que.push({d[e.to],e.to});
            }
        }
    }
    return d;
}

void Main(){
    I(ll, R, C);
    graph g(2*R*C);
    auto pos = g.pos2d(R, C);
    ll W = R*C;
    REP(i, R){
        REP(j, C-1){
            I(ll, A);
            g.add_edge(pos(i, j), pos(i, j+1), A);
        }
    }
    REP(i, R-1){
        REP(j, C){
            I(ll, B);
            g.add_diedge(pos(i, j), pos(i+1, j), B);
        }
    }
    REP(i, R-1){
        REP(j, C){
            g.add_diedge(W+pos(i+1, j), W+pos(i, j), 1);
        }
    }
    REP(i, R){
        REP(j, C){
            g.add_diedge(pos(i, j), W+pos(i, j), 1);
            g.add_diedge(W+pos(i, j), pos(i, j), 0);
        }
    }
    auto d = dijkstra(g, pos(0, 0));
    cout << d[pos(R-1, C-1)] << el;
}


#include<bits/stdc++.h>
#define maxn 300010
using namespace std;
typedef long long LL;
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;
long long A[maxn],s,ans;
signed main()
{
	n=read();
	for(int i=1;i<=n;i++) A[i]=read(),s+=A[i];
	for(int i=1;i<=n;i++)
	{
		ans+=A[i]*A[i]*(n-1)-(s-A[i])*A[i];
	}
	cout<<ans<<'\n';
	return 0;
}

#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>
#include <chrono>
#include <iomanip>
using namespace std;
using namespace tr1;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define fffirst
#define ss second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1000000009;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
///////////////////////////////////////////////////////////////
#define curr_time std::chrono::high_resolution_clock::now()
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  map<int,ll> freq;
  int val;
  for(int i=0;i<n;i++){
	  cin>>val;
	  freq[val]++;
  }
  ll ans=0;
  for(int i=-200;i<=200;i++){
	  for(int j=i+1;j<=200;j++){
		  ans+=freq[i]*freq[j]*abs(i-j)*abs(i-j);
	  }
  }
  cout<<ans;
  return 0;
}