#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll num[10];
bool ok = false;

bool f(int a, int b, int c) {
    if((100*a+10*b+c) % 8 != 0) return false;
    bool ret = true;
    num[a]--;
    num[b]--;
    num[c]--;
    for(int i = 1; i <= 9; i++) {
        if(num[i] < 0) ret = false;
    }
    num[a]++;
    num[b]++;
    num[c]++;
    return ret;
}
string S;

void solve() {
    sort(S.begin(), S.end());
    do {
        ll tmp = stoll(S);
        ok |= (tmp % 8 == 0);
    } while(next_permutation(S.begin(), S.end()));
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    if(S.size() <= 3) {
        solve();
        return 0;
    }
    for(auto c : S) {
        num[(int)(c - '0')]++;
    }
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            for(int k = 1; k <= 9; k++) {
                ok |= f(i, j, k);
            }
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  map<int, bool> mp;
  priority_queue<int, vector<int>, greater<int>> q1, q2;
  FOR(i, 0, 200000) {
    q1.push(i);
  }
  REP(i, n) {
    int p;
    cin >> p;
    if (!mp[p]) q2.push(p);
    mp[p] = true;
    while(q1.top() == q2.top()) {
      q1.pop(), q2.pop();
    }
    cout << q1.top() << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

inline int inint(istream& in) {int x; in >> x; return x;}
inline ll inll(istream& in) {ll x; in >> x; return x;}
inline string instr(istream& in) {string x; in >> x; return x;}

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

class ARockPaperScissors {
public:
void solve(std::istream& in, std::ostream& out) {

    int x = inint(in);
    int y = inint(in);

    if(x == y){
        out << x << endl;
        return;
    }

    if(x + y == 1){
        out << 2 << endl;
        return;
    }

    if(x + y == 2){
        out << 1 << endl;
        return;
    }

    if(x + y == 3){
        out << 0 << endl;
        return;
    }

}
};

int main() {
	ARockPaperScissors solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

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

const ll INF = 1e18;
const ll fact_table = 820000;

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

// small priority queue
// top pop

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

#define p(x) cout << x << "\n";
#define el cout << "\n";
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v)                                                               \
    sort(all(v));                                                              \
    reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

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

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

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

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];

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

ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/

bool icpc = false;
bool multicase = false;

bool solve() {
    ll a, b;
    cin >> a >> b;
    if (a == b) {
        p(a);
    } else {
        p(3 - a - b);
    }
    return true;
}
/*

*/

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // cout << "Case #" << testcase << ": ";
        solve();
        testcase++;
    }

    // solve();
    return 0;
}


#include<iostream>
#define ll long long
using namespace std;
ll T,X,Y,P,Q,a,b,c,k1,k2,tans;
ll exgcd(ll a,ll b,ll &x,ll &y) {
	if(!b) {
		x=1,y=0;
		return a;
	}
	int t=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return t;
}
int main() {
	cin>>T;
	while(T--) {
		cin>>X>>Y>>P>>Q;
		a=2*X+2*Y,b=P+Q;
		tans=5e18;
		for(int q=0; q<Q; q++) {
			for(int y=0; y<Y; y++) {
				c=P+q-X-y;
				int t=exgcd(a,b,k1,k2);
				if(c%t)continue;

				k1=k1*c/t;
				k1=(k1%(b/t)+(b/t))%(b/t);
				tans=min(tans,a*k1+y+X);
			}
		}
		if(tans==5e18)cout<<"infinity\n";
		else cout<<tans<<endl;
	}
}

//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#include <bitset>
#include <assert.h>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;
//using namespace atcoder;

ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;

ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}

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

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

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

    uniform_real_distribution<double> ff(-1,1);

//    auto start = chrono::steady_clock::now();

    readint(test_cases);
//    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(x); readll(y); readll(p); readll(q);

        ll per_train = 2*x+2*y, per_sleep = p+q;

        set<ll> solutions;
        forr(i,0,y) {
            forr(j,0,q) {
                ll a = per_train, b = -per_sleep, c = p+j-x-i, x0,y0,g;
                if (find_any_solution(a,b,c,x0,y0,g)) {
                    ll x_shift = -b/g, y_shift = a/g;
                    if (x0<0) {
                        ll k = abs(x0)/x_shift+4;
                        x0 += k * x_shift;
                        y0 += k * y_shift;
                    }
                    ll k = x0/x_shift;
                    x0 -= k * x_shift;
                    y0 -= k * y_shift;
                    solutions.insert(p+j+y0*per_sleep);
                }
            }
        }
        if (solutions.empty()) {
            cout << "infinity" << endl;
        } else {
            cout << *solutions.begin() << endl;
        }

    }

//        auto stop = chrono::steady_clock::now();
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;
ll dp[102][102][102];

int main(){
    //オーバーフローは大丈夫ですか？？
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    V<ll> a(n);
    cinf(n,a);
    ll ans=INF;
    for(ll cnt=1;cnt<=n;cnt++){
        rep(i,n+1){
            rep(j,n+1){
                rep(k,n+1) dp[i][j][k]=-INF;
            }
        }
        dp[0][0][0]=0;
        rep(i,n){
            rep(j,n){
                for(ll k=0;k<cnt;k++){
                    chmax(dp[i+1][j][k],dp[i][j][k]);
                    if(dp[i][j][k]!=-INF){
                        ll y=(k+a[i])%cnt;
                        if(dp[i][j][k]+a[i]<=x){
                            chmax(dp[i+1][j+1][y],dp[i][j][k]+a[i]);
                        }
                    }
                }
            }
        }
        if(dp[n][cnt][x%cnt]!=-INF){
            chmin(ans,(x-dp[n][cnt][x%cnt])/cnt);
        }
    }
    out(ans);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！

/*
* @author:  codancer
* @createTime:  2020-12-05, 19:52:03
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}
char win(char a,char b){
	if(a==b) return a;
	if(a=='R'&&b=='S'||a=='S'&&b=='R') return 'R';
	if(a=='R'&&b=='P'||a=='P'&&b=='R') return 'P';
	if(a=='S'&&b=='P'||a=='P'&&b=='S') return 'S';
}
const int N = 102;
int n,k;
string s;
ll pw[101];
char solve(ll l,ll r){
	// cout<<"dad"<<endl;
	if(l==r){
		return s[l%n];
	}
	ll mid=(l+r)/2;
	return win(solve(l,mid),solve(mid+1,r));
}
int main(){
	pw[0]=1;
	for(int i=1;i<=25;i++) pw[i]=pw[i-1]*2;
		// cout<<"oo"<<endl;
	cin>>n>>k;
	cin>>s;
	cout<<solve(0,pw[min(k,25)]-1)<<endl;
	return 0;
}

//
//1 2 3 4


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

mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define pb push_back

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 2e5+5;

int n;
bool used[N];
int pos[N];
int a[N];

vector<int> ans;

bool prob;

void change(int i, int j) {
  swap(a[i], a[j]);
  swap(pos[a[i]], pos[a[j]]);
  used[i] = true;
  ans.push_back(i);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }

  for(int i = 1; i <= n; i++) {
    while(pos[i] != i) {
      if(used[pos[i] - 1]) {
        prob = true;
        break;
      }
      change(pos[i] - 1, pos[i]);
    }

    if(prob) break;
  }

  for(int i = 1; i < n; i++) if(!used[i]) prob = true;

  if(prob) cout << -1 << "\n";
  else {
    for(auto x : ans) cout << x << "\n";
  }
}

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//union-find木について
//サイズによる更新をしている
ll par[201010];
ll rank2[201010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 1;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
		rank2[y] += rank2[x];
	}
	else {
		par[y] = x;
		rank2[x] += rank2[y];
	}
}

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

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n), p(n), ans;
	rep(i, n) {
		cin >> a[i];
		a[i]--;
		p[a[i]] = i;
	}
	rep(i, n) {
		for (ll j = p[i];j > i;j--) {
			swap(a[j], a[j - 1]);
			ans.push_back(j);
			p[a[j - 1]]++;
		}
		if (ans.size() >= n) {
			cout << -1 << endl;
			return 0;
		}
	}
	rep(i, n) {
		if (a[i] != i) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (ans.size() != n - 1) {
		cout << -1 << endl;
		return 0;
	}
	rep(i, n - 1) {
		cout << ans[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
/*coment

*/
int main () {
    using ll = long long int ;
    using p = pair<int,int>;
    int a,b,x,y;
    cin >> a >> b >> x >> y;
    // a + 1 = b// a = b
    int t = 0;
    if (a - 1 == b) {
        cout << x << endl;
    }
    else {
        if (a > b) {
            if (x * 2 < y) {
                cout << x * (1 + 2 * (a-b-1)) << endl;
            }
            else {
                cout << x + y * (a - b-1) << endl;
            }
        }
        else {
            if (x * 2 < y) {
                cout << x * (1 + 2 *(b-a)) << endl;
            }
            else {
                cout << x + y * (b-a) << endl;
            }

        }
    }
}

//nik
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#define reg register
#define FOR(a, b, c) for (a = b; a <=c; a++)
#define rFOR(a, b, c) for (a = b;a >= c; a--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define SORT(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define newl "\n"
#define alls(x) x.begin(), x.end(), x.begin()
#define umap(v, t1, t2) unordered_map<t1, t2> v
#define uset(v,t1) unordered_set<t1> v
#define IOF ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using UL  =  unsigned long int;
using UI  =  unsigned int;
using ULL =  unsigned long long int;
using LI  =  long int;
using LL  =  long long;
using LF  =  double;
using LLF =  long double;
const int MOD1 = 1000000007;
/*const int MOD2 = */
/* Combinatorics Start */
int binoMax = 10000;
vector<LL> numInv(binoMax + 1), factNumInv(binoMax + 1), fact(binoMax + 1);
inline void generate_ncrp(LL p)
{   int i;numInv[0] = numInv[1] = 1;
	FOR(i, 2, binoMax)
	{	numInv[i] = numInv[p % i] * (p - p / i) % p;
	}	factNumInv[0] = factNumInv[1] = 1;
	FOR(i, 2, binoMax)
	{	factNumInv[i] = (numInv[i] * factNumInv[i - 1]) % p;
	}
	fact[0] = 1;
	FOR(i, 1, binoMax)
	{	fact[i] = (fact[i - 1] * i) % p;
	}
}
LL ncrmodp(LL n, LL r, LL p)
{	LL ans = ((fact[n] * factNumInv[r]) % p * factNumInv[n - r]) % p;
	return ans;
}
/* Combinatorics End */

LL expmodp(LL x, LL y, LL p)
{	LL res = 1;
	while (y > 0)
	{	if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}return res;
}
/* Matrix Operations Start */
struct Matrix{
	int row,col;
	vector<vector<LL> > a;
	Matrix(int r,int c){
		row=r;col=c;
		a.resize(row,vector<LL>(col,0));
;	}
    static Matrix IDM(LL n){
    	Matrix res(n,n);
    	for(int i=0;i<n;i++)res.a[i][i]=1;
    	return res;
	}
};
Matrix Matmult(Matrix A,Matrix B){
	Matrix res(A.row,B.col);
	LL i,j,k;
	FOR(i,0,A.row-1){
		FOR(j,0,B.col-1){
			FOR(k,0,A.col-1){
				res.a[i][j]=(res.a[i][j]+A.a[i][k]*B.a[k][j])%MOD1;
			}
		}
	}
	return res;

}
Matrix BinExp(Matrix X,LL n){
	Matrix res=Matrix::IDM(X.row);
	while(n>0){
		if(n&1){
			res=Matmult(X,res);
		}
		X=Matmult(X,X);
		n>>=1;
	}
	return res;
}
/* Matrix Operations End */

int main()
{
	IOF
	LL i,j,k,n,tc,tp1,tp2,tp3;
    LL a,b,x,y;
    cin>>a>>b>>x>>y;
    if(a==b){
        cout<<x;
    }
    else if(a<b){
        int dpa[101],dpb[101];
        memset(dpa,0,sizeof(dpa));
        memset(dpb,0,sizeof(dpb));
        dpb[a]=x;
        for(i=min(a,b)+1;i<=max(a,b);i++){
            dpb[i]=min(min(x+y,3*x)+dpa[i-1],min(y,2*x)+dpb[i-1]);
            dpa[i]=min(min(2*x,y)+dpa[i-1],dpb[i-1]+x);
        }
        cout<<dpb[b];
    }
    else{
        int dpa[101],dpb[101];
        memset(dpa,0,sizeof(dpa));
        memset(dpb,0,sizeof(dpb));
        dpb[a]=x;
        for(i=max(a,b)-1;i>=min(a,b);i--){
            dpb[i]=min(dpa[i+1]+x,dpb[i+1]+min(y,2*x));
            dpa[i]=min(dpa[i+1]+min(2*x,y),dpb[i+1]+min(3*x,x+y));
        }
        cout<<dpb[b];
    }

}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#define re register
#define pb push_back
#define cl clear
#define MAXN 100005

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f = -1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch = getchar();
	}
	return x*f;
}

ll n, l, A[MAXN], B[MAXN], ans;

void solve(){
    n = read();
    l = read();
    A[n+1] = B[n+1] = l + 1;
    for(re int i = 1 ; i <= n ; ++i)
        A[i] = read();
    for(re int i = 1 ; i <= n ; ++i)
        B[i] = read();
    for(re int i = n + 1 ; i >= 1 ; --i){
        A[i] = A[i] - A[i-1] - 1;
        B[i] = B[i] - B[i-1] - 1;
    }
    int cnt = 1;
    for(re int i = 1 ; i <= n + 1 ; ++i){
        if(!B[i]) continue;
        while(!A[cnt]) ++cnt;
        ll sum = 0, st = cnt, ed;
        while(sum<B[i]&&cnt<=n+1){
            sum += A[cnt++];
            //printf("i = %d cnt = %d sum = %d\n",i,cnt,sum);
        }
        if(sum!=B[i]){
            printf("-1\n");
            return ;
        }
        ed = cnt - 1;
        ans += max(0ll,i-st) + max(0ll,ed-i);
    }
    printf("%lld\n",ans);
}

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

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
    int N,M,tmp,cnt,ANS_size;
    vector<int>vec,ANS_vec;
    cin>>N>>M;
    for(int i = 1;i<=N+M;i++){
        cin>>tmp;
        vec.push_back(tmp);
    }
    for(int i=1;i<=pow(10,3);i++){
        cnt = 0;
        for(int j=0;j<N+M;j++){
            if(vec[j] == i){
                cnt++;
            }
        }
        if(cnt == 1){
            ANS_vec.push_back(i);
        };
    }

    ANS_size = ANS_vec.size();
    for(int i=0;i<ANS_size;i++){
        cout<<ANS_vec[i]<<" ";
    }
    cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long; // 2^31-1
using P = pair<string, int>; // 2変数を一括でつかえる 2重にすれば3,4変数同時も．
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i, s, n) for (int i = (s); i <= (n); i++)
#define all(v) v.begin(),v.end()
#define INF32 2147483647 // 32bit max
#define INF64 9223372036854775807 // 64bit max
// max, reverse, sort(a,a+n), greater<int>()

int main()
{
  ll n,k;
  cin >> n >> k;
  vector<pair<ll,ll> > x(n);
  rep(i,n)  cin >> x[i].first >> x[i].second;
  sort(all(x));

  ll money=k,loc=0;
  rep(i,n){
    ll cost=x[i].first-loc;
    if(loc==x[i].first){
      money+=x[i].second;
    }
    else if(money>=cost){
      money-=cost;
      loc=x[i].first;
      money+=x[i].second;
    }else{
      break;
    }
  }
  cout << loc+money << endl;
  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0,1e9);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END

const int N = 2e5 + 5;

int powm(int a, int b){
    int res = 1;
    while (b) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void solve(){

    int n, p;

    cin >> n >> p;

    cout << (p-1) * powm(p-2, n-1) % mod << endl;

}

signed main() {

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

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

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

int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll  long long
#define pb push_back
#define vec vector<ll>
#define pii pair<ll,ll>
#define pr_que priority_queue<pii,vector<pii>,greater<pii> >
#define itr(i,x,y) for(ll i=x;i<y;i++)
#define mod 1000000007
const long long N=200001,INF=1000000000000000000;
const double err=1e-9;

int main()
{
	IOS;
	int n;
	cin >> n;
	int a[n][5];
	itr(i,0,n)
	{
		itr(j,0,5)
		{
			cin >> a[i][j];
		}
	}
	int lo=1,hi=1e9,mid;
	while(lo<hi)
	{
		mid=lo+(hi-lo+1)/2;
		bool v[1<<5];
		itr(i,0,1<<5) v[i]=false;
		itr(i,0,n)
		{
			int mask=0;
			itr(j,0,5)
			{
				if(a[i][j]>=mid)
				{
					mask=mask^(1<<j);
				}
			}
			v[mask]=true;
		}
		bool c=false;
		itr(i,0,1<<5)
		{
			if(!v[i]) continue;
			itr(j,0,1<<5)
			{
				if(!v[j]) continue;
				itr(k,0,1<<5)
				{
					if(!v[k]) continue;

					if((i|j|k) == (1<<5)-1)
					{
						c=true;
					}
				}
			}
		}
		if(c==true) lo=mid;
		else hi=mid-1;
	}
	cout << lo << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
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 A[3020][5];
ll N;

bool isOK(ll key){
  vector<ll> aup(32);
  rep(i,N){
    ll temp = 0;
    rep(k,5){
      if(A[i][k]>=key){
        temp+=pow(2,k);
      }
    }
    aup[temp]++;
  }
  bool aru = 0;
  rep(i,32){
    rep(k,32){
      rep(t,32){
        if((i|k|t) == 31){
          if(aup[i]>0&&aup[k]>0&&aup[t]>0){
            //cout << i << k << t << endl;
            aru = 1;
          }
        }
      }
    }
  }
  return aru;
}

int main(){
  cin>>N;
  rep(i,N){
    cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3]>>A[i][4];
  }
  ll right = MOD;
  ll left = -1;
  while((right-left)>1){
    ll mid=left+(right-left)/2;
    if(isOK(mid)){
      left = mid;
    }
    else{
      right = mid;
    }
  }
  cout << left << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << 2 * a + 100 - b << "\n";
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long ;
#define rep(i,n) for (int i=0; i < (n); ++i)

int main() {
    int a,b ;
    cin >> a >> b ;
    cout << max((2*a+100)-b,0) << endl ;
 return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;

#ifdef VIPJML_LOCAL
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << *vi;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const vector<pair<A, B>> &v)
{
    os << "{";
    for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << '(' << vi->first << " " << vi->second << ")";
    }
    os << "}";
    return os;
}

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using LL = long long;

void solve(int caseNum)
{
    LL N, M, T;
    cin >> N >> M >> T;
    LL cnt = N;
    bool f = true;
    LL t = 0;
    for (int i = 0; i < M; i++)
    {
        LL A, B;
        cin >> A >> B;
        cnt -= A - t;
        if (cnt <= 0)
            f = false;
        cnt += B - A;
        if (cnt > N)
            cnt = N;
        t = B;
    }

    cnt -= T - t;
    if (cnt <= 0)
        f = false;
    cout << (f ? "Yes" : "No") << endl;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    int T = 1;
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve(i);
    }
    cout.flush();
    return 0;
}

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

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

void no() {
    cout << "No";
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, t;
    cin >> n >> m >> t;
    int cur = n;
    vector <pii> c(m);
    forn (i, 0, m)
        cin >> c[i].fs >> c[i].sc;
    int prev = 0;
    forn (i, 0, m) {
        int a, b;
        tie(a, b) = c[i];
        cur -= (a - prev);
        if (cur <= 0)
            no();
        cerr << cur << " ";
        cur = min(n, cur + (b - a));
        prev = b;
        cerr << cur << "\n";
    }
    cur -= (t - prev);
    if (cur <= 0)
        no();
    cout << "Yes";
    return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if ((ct = *ci++) >= '0') {
				tmp = tmp * 10 + ct - '0';
				ci++;
			}
		}
	}
	return tmp;
}
ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
bitset<400010> ST;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N = getint(), M = getint();
	ll XY[200000];
	int k = 0;
	int nm1 = N - M, nm2 = N + M;
	rep(i, M) {
		int x = getint();
		int y = getint();
		if (y < nm1 | y > nm2) continue;
		XY[k++] = x | (ll)(y - N + 200001) << 32;
	}
	M = k;
	pakuri_sort(M, XY);

	ST[200001] = 1;
	const ll ma = (1ll << 32) - 1;
	int m = 0;
	while (m < M) {
		int m0 = m;
		int x = (XY[m] & ma);
		while (m < M && (XY[m] & ma) == x) {
			int y = (XY[m] >> 32);
			if (ST[y - 1] | ST[y + 1]) XY[m] |= 1ll;
			else if (ST[y]) XY[m] &= (~1ll);
			else XY[m] = 0;
			m++;
		}
		for (int p = m0; p < m; p++) {
			int y = (XY[p] >> 32);
			if (XY[p] & 1) ST[y] = 1;
			else if (XY[p]) ST[y] = 0;
		}
	}
	int kotae = ST.count();
	printf("%d\n", kotae);

	Would you please return 0;
}

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (ll)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec
void test(ull,ull,ull);

//#define FOR_CODEFORCES
void Main()
{
	string S;
	cin>>S;

	if(S.size()==1){
		if(S[0]=='8')cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

		return;
	}

	if(S.size()==2){
		int a=(S[0]-'0')*10 + (S[1]-'0');
		int b=(S[1]-'0')*10 + (S[0]-'0');

		if(a%8==0 || b%8==0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

		return;
	}

	if(S.size()==3){
		int a=S[0]-'0';
		int b=S[1]-'0';
		int c=S[2]-'0';
		int nums[6];
		nums[0]=a*100+b*10+c;
		nums[1]=a*100+c*10+b;
		nums[2]=b*100+a*10+c;
		nums[3]=b*100+c*10+a;
		nums[4]=c*100+b*10+a;
		nums[5]=c*100+a*10+b;

		rep(i,6){
			if(nums[i]%8==0){
				cout<<"Yes"<<endl;
				return;
			}
		}
		cout<<"No"<<endl;
		return;
	}

	int flags[10]={};

	rep(i,S.size()){
		flags[S[i]-'0']++;
	}

	for(int i=0; i<1000; i+=8){
		int a,b,c;
		a=i/100;
		b=(i%100)/10;
		c=(i%10);
		int flags2[10]={};
		flags2[a]++;
		flags2[b]++;
		flags2[c]++;
		bool isOK=true;
		rep(j,10){
			isOK &= (flags[j]>=flags2[j]);
		}
		if(isOK){
			cout<<"Yes"<<endl;
			return;
		}

	}

	cout<<"No"<<endl;
}

void test(){
}
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	#ifdef FOR_CODEFORCES
	int t=0;
	cin>>t;
	rep(i,t)Main();
	#else
	Main();
	#endif
	return 0;
}


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

#define int long long
#define all(x) (x).begin(),(x).end
#define rall(x) (x).rbegin(),(x).rend

const int MOD=(int)1e9+7;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("teamwork.in","r",stdin);
    //freopen("teamwork.out","w",stdout);
    int n;
    cin>>n;
    int a[n+1],pref[n+1]={};
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pref[i]=a[i]+pref[i-1];
    }
    int sum1=0,sum2=0;
    for(int i=1;i<=n;i++) sum1+=(a[i]*a[i]);
    sum1*=n-1;
    for(int i=1;i<=n;i++){
        sum2+=a[i]*(pref[n]-pref[i]);
    }
    sum2*=(-2);
    cout<<sum1+sum2;
}

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


/*
            ********************
			**    MEET SHAH   **
			**     DA-IICT    **
			**  decoder_0712  **
			********************
*/
#include <bits/stdc++.h>
using namespace std;

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

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define setpre(x,d) fixed<<setprecision(d)<<x
//#define fill(a,x) memset(a,x,sizeof(a));
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define deb4(x,y,z,w) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<"\t"<<#w<<" : "<<w<<endl;
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define len length()
#define all(v) v.begin(),v.end()
#define PI 3.141592653589793
#define MOD 1000000007
#define NN (const int)5e5+10
#define ub upper_bound

typedef long long int ll;
typedef long double lld;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) { return (a.second < b.second); }
// void fileio()	{	freopen("input.txt","r",stdin);	freopen("output.txt","w",stdout);	}
//	vll fact(NN),invfact(NN);
//	void EE(ll a,ll b,ll &x,ll &y) {	if(b==0) {	x=1,y=0; return ;	}		EE(b,a%b,x,y);	ll temp=x; x=y; y=temp-(a/b)*y;	}
//	ll inverse(ll a,ll mod) 	{	ll x,y;	EE(a,mod,x,y);	return (x+mod)%mod;	}
//	void build() { fact[0]=1; fr(i,1,NN) fact[i]=(fact[i-1]*i)%MOD;	invfact[NN-1]=inverse(fact[NN-1],MOD); rf(i,NN-1,0) invfact[i]=(invfact[i+1]*(i+1))%MOD; }
//	ll ncr(ll n,ll r)       	{	if(n<0 || r<0 || r>n) return 0;	return (fact[n]*((invfact[n-r]*invfact[r])%MOD))%MOD;	}
//	ll choose(ll n,ll k) 	  	{	if(k==0)  return 1; return (n* choose(n-1,k-1))/k;	}
ll logy(ll x,ll y)	{	return ceil((lld)(log(x)/log(y)));	}
ll powe(ll a,ll b)	{	ll re=1;	while(b){	if(b&1) re=(re*a)%MOD;	a=(a*a)%MOD;	b=b>>1;}	return re;	}
/*
ll i,j,x,y,k,z,cnt;
vector<vector<ll> > a(100005);
vector<ll> vis(100005,0),visited(100005,0);
void dfs(int u)
{
    visited[u]=1;

    vector<ll>::iterator it;

    for(it=a[u].begin();it!=a[u].end();it++)
    {
        if(visited[*it]==0)
        {
            dfs(*it);
        }
    }
}
*/

bool flag=0,flag1=0,flag2=0;

int main()
{
	IOS
	ll a,b,c,d,ans;
	cin>>a>>b>>c>>d;
	ll t1=a-c;
	ll t2=a-d;
	ll t3=b-c;
	ll t4=b-d;
	ll mx1=max(t1,t2);
	ll mx2=max(t3,t4);
	cout<<max(mx1,mx2)<<endl;

	return 0;
}

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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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;}
//-------------------------------------------------------

int N;
string S;
int A[10101];
int L[101],R[101],B[101];
pair<int,int> P[101];
int ret[101][10101];

int hoge(int v) {
	int i,j;
	int lef[101];
	if(v>=10001) return 0;

	FOR(j,N+1) {
		int sum=0;
		FOR(i,v) {
			ret[j][i]=A[j]/v+(i<A[j]%v);
			sum+=ret[j][i];
		}
		assert(sum==A[j]);
	}

	FOR(i,N) {
		FOR(j,v) {
			if(S[i]=='<' && ret[i][j]>=ret[i+1][j]) return 0;
			if(S[i]=='>' && ret[i][j]<=ret[i+1][j]) return 0;
		}
	}
	return 1;

}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>S;
	FOR(i,N+1) cin>>A[i];
	FOR(i,N) {
		if(S[i]=='<') L[i+1]=L[i]+1;
		else L[i+1]=0;
	}
	for(i=N-1;i>=0;i--) {
		if(S[i]=='>') R[i]=R[i+1]+1;
		else R[i]=0;
	}
	FOR(i,N+1) {
		B[i]=max(L[i],R[i]);
		P[i]={-B[i],i};
	}
	sort(P,P+N+1);

	int re=1;
	for(i=15;i>=0;i--) if(hoge(re+(1<<i))) re+=1<<i;

	assert(hoge(re));

	cout<<re<<endl;
	FOR(i,re) {
		FOR(j,N+1) cout<<ret[j][i]<<" ";
		FOR(j,N) {
			if(S[j]=='<') assert(ret[j][i]<ret[j+1][i]);
			if(S[j]=='>') assert(ret[j][i]>ret[j+1][i]);
		}
		cout<<endl;
	}

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); 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 int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//const long long INF=1e15;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//auto dist=uniform_int_distribution<int>(0,INF);
//const long double pi = acos(-1);
//primes for hashing 937, 1013
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
void shikhar7s(int cas)
{
    int n,i;
    cin>>n;
    vp v;
    int x,y;
    fr(i,n)
    {
        cin>>x>>y;
        v.pb(mp(y,x));
    }
    sort(all(v));
    vi a,b,aa,ba;
    i=0;
    int l=mini,r=-mini;
    while(i<n&&v[i].F==v[0].F)
    {
        a.pb(v[i].S);
        l=min(l,v[i].S);
        r=max(r,v[i].S);
        i++;
    }
    sort(all(a));
    aa.resize(sz(a));
    int j;
    fr(j,sz(a))
    {
        if(l>=0)
            aa[j]=2*r-a[j];
        else if(a[j]>0)
            aa[j]=2*(r-l)-a[j];
        else if(r>0)
            aa[j]=2*(r-l)+a[j];
        else
            aa[j]=a[j]-2*l;
    }
    rep(i,i,n)
    {
        int j=i,l=mini,r=-mini;
        while(j<n&&v[j].F==v[i].F)
        {
            b.pb(v[j].S);
            l=min(l,v[j].S);
            r=max(r,v[j].S);
            j++;
        }
        i=j-1;
        sort(all(b));
        ba.resize(sz(b),mini);
        fr(j,sz(b))
        {
            int k=lower_bound(all(a),r)-a.begin();
            if(k<sz(a))
                ba[j]=min(ba[j],aa[k]+a[k]+b[j]-2*l);
            k--;
            if(k>=0)
                ba[j]=min(ba[j],aa[k]+2*(r-l)+b[j]-a[k]);
            k=lower_bound(all(a),l)-a.begin();
            if(k<sz(a))
                ba[j]=min(ba[j],aa[k]+2*(r-l)+a[k]-b[j]);
            k--;
            if(k>=0)
                ba[j]=min(ba[j],aa[k]+2*r-a[k]-b[j]);
            // cout<<b[j]<<" "<<ba[j]<<endl;
        }
        a=b;
        aa=ba;
        b.clear();
        ba.clear();
    }
    int ans=mini;
    fr(i,sz(a))
    {
        ans=min(ans,aa[i]+abs(a[i]));
    }
    cout<<ans;
}
signed main()
{
    fast;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    //cout<<"Case #"<<cas<<": ";
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

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

int main(){
    int a, b;

    cin >> a >> b;
    if( a >= b ){
        for( int i = 1; i <= a; i++ ){
            cout << i << " ";
        }
        for( int i = 1; i <= b-1; i++ ){
            cout << -i << " ";
        }
        cout << -(((a+1)*a)/2 - (b-1+1)*(b-1)/2) << endl;
    }else{
        for( int i = 1; i <= b; i++ ){
            cout << -i << " ";
        }
        for( int i = 1; i <= a-1; i++ ){
            cout << i << endl;
        }
        cout << (1+b)*b/2 - (a-1+1)*(a-1)/2 << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define ld long double
#define MAX (int)(pow(10,6) + 10)
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;

struct p3d{ ld x,y,z;
  p3d(ld a, ld b, ld c): x(a), y(b), z(c){}
  friend ostream& operator<< (ostream& os, const p3d& p) {
  return os << "(" << p.x << "," << p.y << "," << p.z << ")"; } };
ld abs(const p3d &v){ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); }
p3d operator+(const p3d& a, const p3d& b) {
  return {a.x+b.x,a.y+b.y,a.z+b.z}; }
p3d operator-(const p3d& a, const p3d& b) {
  return {a.x-b.x,a.y-b.y,a.z-b.z}; }
p3d operator*(const ld &s, const p3d &v){ return {s*v.x,s*v.y,s*v.z}; }
p3d operator/(const p3d&v, const ld &s){ return {v.x/s, v.y/s, v.z/s}; }
inline ld dot(const p3d &a, const p3d &b){
  return a.x*b.x + a.y*b.y + a.z*b.z; }
inline p3d cross(const p3d &a, const p3d &b){
  return {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; }

p3d rotate(const p3d& p/*pt*/, const p3d& u/*axis*/, const ld& angle) {
  ld c = cos(angle), s = sin(angle), t = 1 - cos(angle);  return {
    p.x*(t*u.x*u.x + c)+p.y*(t*u.x*u.y - s*u.z)+p.z*(t*u.x*u.z + s*u.y),
    p.x*(t*u.x*u.y + s*u.z)+p.y*(t*u.y*u.y + c)+p.z*(t*u.y*u.z - s*u.x),
    p.x*(t*u.x*u.z - s*u.y)+p.y*(t*u.y*u.z + s*u.x)+p.z*(t*u.z*u.z + c)
  }; } // hash: 3f78e3

void deal(){
	ld n, x1, y1, xn, yn;
	cin>>n>>x1>>y1>>xn>>yn;

	ld angle = M_PI/(n/2.0);
	p3d center((x1+xn)/2.0, (y1+yn)/2.0, (ld)0);
	p3d a(x1,y1,0);
	p3d aRelative = a-center;
	p3d axis(0, 0, 1.0);

//	cout<<"a relative "<<aRelative.x<<" "<<aRelative.y<<endl;

	aRelative = rotate(aRelative, axis, angle);

//	cout<<"a relative after rotation "<<aRelative.x<<" "<<aRelative.y<<endl;

	aRelative = aRelative + center;

	cout<<setp(10)<<aRelative.x<<' '<<aRelative.y;

}

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

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007ll
#define md 998244353ll
#define e1 1e-9
#define v vector< long long >
#define vp vector< pair < long long,long long > >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ft first
#define sd second
#define all(x) x.begin() , x.end()
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test \
    ll tt{0}; \
    cin>>tt; \
    while(tt--)
using namespace std;
bool prime(ll n) {
    if (n < 2)return false;
    for (ll x = 2; x * x <= n; x++) {
        if (n % x == 0)return false;
    }
    return true;
}
vector<ll> Seiveprime(ll n)
{
    vector<bool> isPrime(n, true);
    for (int i = 2; i * i < n; i++)
    {
        if (isPrime[i])
        {
            for (int j = i * i; j < n; j += i)
                isPrime[j] = false;
        }
    }
    vector<ll> prime;
    prime.push_back(2);
    for (int i = 3; i < n; i += 2)
        if (isPrime[i])
            prime.push_back(i);
    return prime;
}
vector<ll> factors(ll n) {
    vector<ll> f;
    for (ll x = 2; x*x <= n; x++) {
        while (n%x == 0) {
            f.pb(x);
            n /= x;
        }
    }
    if (n > 1) f.pb(n);
    return f;
}
vp pri_fact(ll n) {
    v x = factors(n);
    vp y;
    y.eb(x[0], 1);

    for (ll i = 1; i < x.size(); i++) {
        if (x[i] == x[i - 1]) {
            y.back().second++;
        } else {
            y.eb(x[i], 1);
        }
    }

    return y;
}
ll lcm(ll a,ll b) {
    return (a * b) / __gcd(a, b);
}
tuple<int,int,int> gcd(int a, int b) {
    if (b == 0) {
        return {1,0,a};
    } else {
        int x,y,g;
        tie(x,y,g) = gcd(b,a%b);
        return {y,x-(a/b)*y,g};
    }
}
ll mult(ll x,ll y,ll m) {
    return (x * y) % m;
}
//returns x^n (mod m)
ll bin_pow(ll x,ll n,ll m) {
    if (n == 0)return 1;
    if (n & 1)return mult(x, bin_pow(x, n - 1, m), m);
    return bin_pow(mult(x, x, m), n / 2, m);
}
ll ind_of_2(ll x) {
    ll i = 0;

    while (x / (1 << i) != 1)
        i++;

    return i;
}
ll add(ll x,ll y)
{
    x+=y;
    if(x>=md)return x-md;
    return x;
}

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

    ll n{0},d{0},h{0};
    cin>>n>>d>>h;

    v dd(n),hh(n);
    loop(i,0,n)cin>>dd[i]>>hh[i];

    ld temp{0};
    loop(i,0,n){
        ld x=1.0*(d*hh[i] - h*dd[i])/(d-dd[i]);
        if(x>=0)temp=max(temp, x);
    }

    cout<<fixed<<setprecision(15)<<temp;

    return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int N;
string S;
int A[110];
int _m[110];

signed main()
{
	cin >> N;
	cin >> S;
	REP(i, N + 1) cin >> A[i];

	int k = INT_MAX;
	for (int i = 0; i < N; i++)
	{
		int diff = abs(A[i] - A[i + 1]);
		k = min(diff, k);
	}

	for (int i = 0; i < N + 1; i++)
	{
		_m[i] = A[i] % k;
	}

	cout << k << endl;
	for (int i = 0; i < k; i++)
	{
		for (int i = 0; i < N + 1; i++)
		{
			int m = _m[i] > 0 ? 1 : 0;
			cout << A[i] / k + m << " ";
			_m[i]--;
		}
		cout << endl;
	}
}

/*
  author: Kamal Kant Bhardwaj
  date:
*/
#include<bits/stdc++.h>
using namespace std;

#define N               3005
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(newx)      __builtin_popcountll(newx)
#define zrobits(newx)      __builtin_ctzll(newx)
#define mod             1000000007
#define inf             1e18
#define ps(newx,y)         finewxed<<setprecision(y)<<newx
#define mk(arr,n,type)  type *arr=new type[n];
#define w(newx)            int newx; cin>>newx; while(newx--)

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

}
int mat[10005][103];
int32_t main()
{
  c_p_c();
  int n; cin >> n; string s; cin >> s;
  int a[103];
  for (int i = 0; i <= n; i++)
    cin >> a[i];
  int maxi = mod;
  for (int i = 1; i <= n; i++)
  {
    maxi = min(maxi, abs(a[i] - a[i - 1]));
  }

  int sum = 0;
  for (int i = 0; i < 10005; i++)
    for (int j = 0; j < 103; j++)
      mat[i][j] = 0;
  int div = a[0] / maxi;
  int rem = a[0] % maxi;
  for (int j = 0; j < maxi; j++)
  {
    mat[j][0] = div ;
    if (rem > 0)
    {
      mat[j][0] += 1;
    }
    rem--;
    sum += mat[j][0];
  }
  for (int i = 1; i <= n; i++)
  {

    // int newsum = 0;

    //  int diff = abs(a[i] - sum);
    int div = a[i] / maxi;
    int rem = a[i] % maxi;
    // cout << div << "  " << rem << endl;
    for (int j = 0; j < maxi; j++)
    {
      mat[j][i] = div;
      if (rem > 0)
        mat[j][i] += 1;
      rem--;
    }
  }
  cout << maxi << endl;
  for (int j = 0; j < maxi; j++)
  {
    for (int i = 0; i <= n; i++)
    {
      cout << mat[j][i] << " ";
    }
    cout << endl;

  }

  return 0;

}


#include <bits/stdc++.h>
# define rep0(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int N;

int main() {
    // 1. input
    cin>>N;
    vector<int> A(N),B(N);
    rep0(i,N) cin >> A[i];
    rep0(i,N) cin >>B[i];

    // 2.
    int ans = max(0, *min_element(ALL(B)) - *max_element(ALL(A)) +1);

    // 3. output
    cout << ans << endl;
}

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

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(9e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

struct UnionFind {
    vector<ll> par,size;

    UnionFind(ll N) : par(N) { //最初はすべてが根であるとして初期化
        size.resize(N,1);
        for(ll i=0;i<N;i++) par[i] = i;
    }

    ll root(ll x){ //データxの木の根を再帰で得る
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y){ //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return; //同じ木にあるときはそのまま
        if(size[rx]>size[ry]){
            par[ry]=rx;
            size[rx] += size[ry];
        }else{
            par[rx] = ry;
            size[ry] += size[rx];
        }
        return;
    }

    bool same(ll x, ll y){ //2つのデータx,yが属する木が同じならtrue
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll treesize(ll x){return size[root(x)];}
};

int main() {
    ll n,m,t=0,x=0,y=INF,q,k,ans=0;
    cin>>n;
    vll a(n);
    vll b(n);
    rep(i,n){
        cin>>a[i];
        chmax(x,a[i]);
    }
    rep(i,n){
        cin>>b[i];
        chmin(y,b[i]);
    }
    ans=y-x+1;
    if(ans<0) ans=0;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define pb push_back
#define ppb pop_back
#define all(k) k.begin(),k.end()
#define eb emplace_back
#define mp make_pair
#define ll  long long
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vvl vector<vl>
#define vi vector<int>
#define vvi vector<vi>
#define vc vector<char>
#define vpi vector<pi>
#define vpl vector<pl>
#define vvc vector<vc>
#define mi map<int,int>
#define ml map<ll,ll>
template<typename T, typename U> inline bool mn(T& m, U x) { if (m > x) { m = x; return true; } return false; }
#define umap unordered_map<int,int>
using namespace std;

void sol() {
	int n; cin >> n;
	vl ar(n);
	rep(i, 0, n)cin >> ar[i];
	ll cnt = -1, res = *min_element(all(ar));
	while (cnt != res) {
		cnt = res;
		rep(i, 0, n) {
			if (!(ar[i] % res))mn(res, res);
			else
				mn(res, ar[i] % res);

		}
	}

	cout << res;
}
int main() {
	int t = 1; //cin >> t;
	while (t--)sol();

	return 0;
}

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

int main() {
    int N;
    long T, T1 = 0, T2 = 0;
    std::string S, S1, S2;

    std::cin >> N;

    while(N--) {
        std::cin >> S >> T;
        if(T > T1) {
            T2 = T1;
            S2 = S1;
            T1 = T;
            S1 = S;
        } else {
            if(T > T2) {
                T2 = T;
                S2 = S;
            }
        }
    }
    std::cout << S2 << std::endl;
}


#include<iostream>

using namespace std;

bool check(int n, int a) {
	while (n > 0) {
		if (n % a == 7)
			return false;
		n /= a;
	}
	return true;
}

int main() {
	int n, res;
	res = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (check(i, 8) && check(i, 10))
			res++;
	}
	cout << res << "\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a;
  cin >> a;
  for(int i =0;i<a.length();i++)
  {
	if(a[i] == '.')
      break;
    cout<< a[i];
  }
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

char G[105][105];

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

  ll h,w; cin>>h>>w;
  rep(i,h) rep(j,w) cin>>G[i][j];

  ll ans=0;
  rep(i,h){
    rep(j,w){
      if(G[i][j]=='.' && G[i][j+1]=='.') ans++;
      if(G[i][j]=='.' && G[i+1][j]=='.') ans++;
    }
  }
  cout<<ans<<endl;
}

// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define si set<int>
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);
const int maxm = 100001;
ll m = pow(1e9, 2);
vector<vi> adj;
vi h;
vi sz;
vi in;
//NOT FOR NEGATIVE NUMBERS
// void sc(int &number)
// {
//     register long long c;
//     number = 0;
//     c = getchar();
//     for (; (c>47 && c<58); c=getchar())
//         number = number *10 + c - 48;

// }

// void dis(vi &a)
// {
//     cout << "\n....Display starts...\n";
//     loop(i, 0, a.size())
//     {
//         cout << a[i] << " ";
//     }
//     cout << "\n....Display ends...\n";
// }

ll fe(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}

void dfs_h_sz(int cur, int par)
{
    h[cur] = h[par] + 1;
    sz[cur]++;
    for (const auto &v : adj[cur])
    {
        if (v == par)
            continue;
        dfs_h_sz(v, cur);
        sz[cur] += sz[v];
    }
}

void buildGraph(int n, int m)
{
    adj = vector<vi>(n + 1);
    h = vector<int>(n + 1);
    sz = vector<int>(n + 1);
    in = vector<int>(n + 1);

    loop(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs_h_sz(1, 0);
}
struct cmp
{
    bool operator()(const pi &a, const pi &b)
    {
        return a.ff < b.ff;
    }
};
ll add(ll a, ll b)
{
    return ((a % m) + (b % m)) % m;
}
ll mul(ll a, ll b)
{
    return ((a % m) * (b % m)) % m;
}
ll sub(ll a, ll b)
{
    return ((a % m) - (b % m) + m) % m;
}
ll ipt(ll cur){
    ll k = cur;
    ll ret = 0;

    while (cur != 1)
    {
        if (cur % 3 == 0)
        {
            cur /= 3;
            ret++;
        }else
        {
            return -1;
        }

    }
    return (ret ? ret :-1);
}
void solve()
{
    ll n;
    cin >> n;
    ll ini = 5;
    int v1 = 1;

    while (ini < n)
    {
        ll cur = n - ini;
        ll ret = ipt(cur);
        if (ret!=-1)
        {
            cout<<ret<<" "<<v1<<"\n";
            return;
        }

        ini *= 5;
        v1++;
    }
    cout << -1 << "\n";
}
int main()
{
    io;

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int test;
    // cin >> test;
    test = 1;
    while (test--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>  // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())

using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

void solve()
{
    ll arr[3];
    for(ll i=0;i<3;i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+3);
    cout<<arr[1]+arr[2];
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    // ll t;
    // cin>>t;
    // while(t--)
        solve();
    return 0;

}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

inline int read()
{
	int a=0,f=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())
		if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())
		a=(a<<3)+(a<<1)+ch-'0';
	return a*f;
}

const int mod=1e9+7;
const int N=1e6+5;
const int inf=0x3f3f3f3f;
const int INF=2147483647;
const double PI=acos(-1);

int a,b,c,ans;

signed main()
{
	a=read();b=read();c=read();
	ans=a+c;
	ans=max(ans,a+b);
	ans=max(ans,b+c);
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define float double
#define pb push_back
#define lp(i,j,n) for( i=j;i<n;i++)
#define lop(j,k,n)for( j=k;j<n;j++)
#define m_p make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define minheap priority_queue<int,vector<int>,greater<int>>
#define maxheap priority_queue<int>
#define kickstart  cout<<"Case #"<<cc<<": "
#define pair_pq priority_queue<pii,vector<pii>>
#define ff first
#define ss second
#define pff pair<float,float>
#define piii pair<int,pii>
#define all(x)x.begin(),x.end()
const int MAX = 5e2+5 ,N = 2e3 + 5;
const int MOD=1e9 + 7 ,mod=1e9 + 7;
const string digits = "0123456789";
map<string , int>mp;
void solve(){
  int i=0 , j = 0, n , m , x = 0 , y = 0 ,r,k,f   ,p;
  cin >> n ;
  int a = 0 , b = 0 ,tt=0;
  vector<pii>v;
  lp(i , 0 ,n){
    cin >> x >> y ;
    v.pb({2*x + y , i});
    a+=x;
  }
  sort(all(v));
 reverse(all(v));
  int ans = 0 ;
  for(int i = 0 ; i < n ;i++){
    b+=(v[i].ff);
    ++ans;
    int rem = tt - b ;
    if(b > a)break;
  }
  cout << ans <<endl;
}
signed main()
{

 fastio
 #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
 #endif
      int T = 1 ;
     //cin >> T;
      while( T-- )
      solve();
  return 0;
 }

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<vector>
using namespace std;
int read()
{
	int kkk=0,x=1;
	char c=getchar();
	while((c<'0' || c>'9') && c!='-') c=getchar();
	if(c=='-') c=getchar(),x=-1;
	while(c>='0' && c<='9') kkk=kkk*10+(c-'0'),c=getchar();
	return kkk*x;
}
int n;
vector<int> a1,a2,a3,a4;
int main()
{
	n=read();
	for(int i=1;i<=10000;++i)
	{
		if(i%2==0 && i%3==0 && i%5) a1.push_back(i);
		if(i%2==0 && i%3 && i%5==0) a2.push_back(i);
		if(i%2 && i%3==0 && i%5==0) a3.push_back(i);
		if(i%2==0 && i%3==0 && i%5==0) a4.push_back(i);
	}
	//cout<<a1.size()+a2.size()+a3.size()+a4.size()<<endl;
	printf("%d %d %d",a1[0],a2[0],a3[0]);
	int N=3;
	for(int i=1;i<a1.size();++i) if(N<n) printf(" %d",a1[i]),++N;
	for(int i=1;i<a2.size();++i) if(N<n) printf(" %d",a2[i]),++N;
	for(int i=1;i<a3.size();++i) if(N<n) printf(" %d",a3[i]),++N;
	for(int i=0;i<a4.size();++i) if(N<n) printf(" %d",a4[i]),++N;
	return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
    vector<int> a(3);
    cin >> a;
    sort(a.begin(), a.end());

    cout << (a[2]-a[1]==a[1]-a[0]?"Yes":"No") << endl;

    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 1 ; i <= n ; i++) cout << a[i] << " ";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

void solve()
{
  int n;
  map<string,int>mp;
  string s;
  set<string>ss;
  cin >> n;
  for(int i = 0 ; i  < n ; i++){
    cin >> s;
    if(s[0]=='!'){
      mp[s] = 1;
    }
    else{
      ss.insert(s);
    }
  }

  string ans = "*";
  for(auto p : ss){
    if(mp["!"+p] == 1){
      ans = p;
      break;
    }
  }

  if(ans == "*"){
    cout << "satisfiable";
    return;
  }

  cout << ans;

}

int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   clock_t beg = clock();
   solve();
   clock_t end = clock();
   fprintf(stderr, "Time taken : %.3f sec\n", double(end - beg) / CLOCKS_PER_SEC , 184);
   return 0;

}


#include<bits/stdc++.h>
using namespace std;
double dp[101][101][101];
double solve( int a, int b, int c)
{
  //if(a == 0 || b == 0 || c == 0)return 0;
  if(dp[a][b][c])return dp[a][b][c];
  if(a==100 || b == 100 || c == 100)return 0;
  double sum=a+b+c;
  return dp[a][b][c] = 1 + solve(a+1,b,c)*a/sum + solve(a,b+1,c)*b/sum + solve(a,b,c+1)*c/sum;
}

int main()
{
	double a,b,c;
  	cin>>a>>b>>c;
  	cout<<setprecision(10);
  	cout<<solve(a,b,c)<<endl;
  	return 0;
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

vector3d(double,dp,101,101,101,-1);
double sai(int a,int b,int c){
    if(a==100||b==100||c==100){
        return dp[a][b][c]=0;
    }else if(dp[a][b][c]!=-1){
        return dp[a][b][c];
    }else{
        double N=a+b+c;
        dp[a][b][c]=(a*sai(a+1,b,c)+b*sai(a,b+1,c)+c*sai(a,b,c+1))/N+1;
        return dp[a][b][c];
    }
}

int main(){
    INT(a,b,c);
    out(sai(a,b,c));
}


#pragma GCC optimize("Ofast")

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 998244353;
const ll N = 1000005;
const ll inf = 1e9;

void solve()
{
	ll a, b, c;
	cin>>a>>b>>c;
	ll ans = ((a * (a + 1) / 2) % mod) * ((b * (b + 1) / 2) % mod) % mod * ((c * (c + 1) / 2) % mod) % mod;
	cout<<ans<<endl;
}

// #define _DEBUG
 // #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	for(int t = 1; t <= tc; t++)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		// cout<<"Case #"<<t<<": ";
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=
998244353, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    a = a*(a+1) / 2;
    b = b*(b+1) / 2;
    c = c*(c+1) / 2;
    a %= mod;
    b %= mod;
    c %= mod;
    a *= b;
    a %= mod;
    a *= c;
    cout << a % mod << endl;

    return 0;
}


#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main() {fio;
	int n, m;
	cin >> n >> m;
	vector <string> a(n);
	vector <set <char> > oh(n + m);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 0; j < a[i].size(); j++) {
			if(a[i][j] != '.') {
				oh[i + j].insert(a[i][j]);
			}
		}
	}
	ll ans = 1;
	for(int i = 0; i <= n + m - 2; i++) {
		 if(oh[i].size() == 2) {
		 	cout << 0;
		 	return 0;
		 }
		 if(oh[i].size() == 1) {
		 	continue;
		 }
		 ans = (ans * 2) % mod;
	}
	cout << ans << endl;
    return 0;
}

//region TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(X) begin((X)), end((X))
#define sz(X) (int)(X).size()
#define fi first
#define se second
#define fv(X) for(auto&_:(X))cin>>_
#define fv2(X) for(auto&__:(X))fv(__)
#define lboundi(X, n) (lower_bound(all(X), n) - begin(X))
#define uboundi(X, n) (upper_bound(all(X), n) - begin(X))
#define maxi(X) max_element(all(X)) - begin(X)
#define maxe(X) *max_element(all(X))
#define mini(X) min_element(all(X)) - begin(X)
#define mine(X) *min_element(all(X))
#define acc(X) accumulate(all(X), 0LL)
#ifdef LOCAL
template<size_t S>
string to_string(const bitset<S> &x) { return x.to_string(); }
string to_string(const string &x) { return '"' + x + '"'; }
string to_string(char x) { return string{'\'', x, '\''}; }
string to_string(bool x) { return x ? "true" : "false"; }
template<typename Head, typename Tail>
string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; }
template<class T>
string to_string(T x) {
    string ret = "[";
    for (const auto &i: x)
        ret += to_string(i) + ", ";
    if (sz(ret) > 1)
        ret = ret.substr(0, sz(ret) - 2);
    return ret += "]";
}
string to_string(const char *x) { return string(x); }
string to_string() { return ""; }
template<typename Head, typename... Tail>
string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); }
#define debug(...) sizeof( (char[]){#__VA_ARGS__} ) == 1 ? cerr << endl \
: cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl
#define nr() cerr << endl
#else
#define debug(...) 1
#endif
// endregion
const ll mod = 998244353;
void solve() {
    int Y, X;
    cin >> Y >> X;
    vs board(Y);
    fv(board);

    ll ret = 0;

    // 무조건 Y + X - 1 칸을 밟아야 함

    // Y + X - 1 개의 대각선 색을 조절
    // 그중 하나라도 조절 못하는 것이 있다면 정답은 0

    // 0 -> 둘다 가능, 1 -> 하나만 가능
    vi color(X + Y - 1);
    int sy = 0, sx = 0;
    for (int i = 0; i < X + Y - 1; i++) {
        bool r = false, b = false;

        int y = sy, x = sx;
        while (y >= 0 && x < X) {
            if (board[y][x] == 'R') {
                r = true;
            }
            if (board[y][x] == 'B')
                b = true;
            if (r && b) {
                cout << 0;
                return;
            }
            y--;
            x++;
        }
        if (!r && !b) {
            color[i] = 0;
        } else {
            color[i] = 1;
        }

        if (sy < Y - 1)
            sy++;
        else
            sx++;
    }

    int controllable = count(all(color), 0);
    ret = 1;
    while (controllable--) {
        ret *= 2;
        ret %= mod;
    }
    cout << ret;
}

// .A.
// B..
// ...

int main() {
    fastio
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

bool alla(const string &S)
{
    for(auto e:S){
        if (e!='a') return false;
    }
    return true;
}

bool cmp(const string &S, const string &T)
{
    int N = min(S.size(),T.size());
    rep(i,N){
        if (S[i]>T[i]) return true;
        else if(S[i]<T[i]) return false;
    }
    return S.size()>T.size();
}

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

const string str = "atcoder";

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--){
        string S; cin>>S;
        int N = S.size();
        if (alla(S)){
            cout<<"-1\n";
            continue;
        }
        if (cmp(S,str)){
            cout<<"0\n";
            continue;
        }
        int ans=(int)1e9;
        rep(i,2){
            int j=i;
            while(j<N && S[j]<=str[i]) j++;
            if (j<N) chmin(ans,j-i);
        }
        cout<<ans<<endl;
    }
	return 0;
}


// editorial
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;

typedef long long ll;
const ll mod = 998244353;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    vector<ll> fact(k+1, 1);
    for(int i = 1; i <= k; i++) fact[i] = fact[i-1]*i%mod;
    vector<ll> invf(k+1, 1);
    for(int i = 1; i <= k; i++) invf[i] = modpow(fact[i], mod-2, mod);
    vector<ll> sum(k+1, 0);
    sum[0] = n;
    vector<ll> powers(n, 1);
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            powers[j] = powers[j]*v[j]%mod;
            (sum[i] += powers[j]*invf[i]%mod) %= mod;
        }
    }
    const ll invtwo = modpow(2, mod-2, mod);
    vector<ll> fpowers(n, 1);
    for(int i = 1; i <= k; i++){
        ll tmp = 0, sub = 0;
        for(int j = 0; j <= i; j++){
            (tmp += sum[j]*sum[i-j]%mod) %= mod;
        }
        (tmp *= fact[i]) %= mod;
        for(int j = 0; j < n; j++){
            fpowers[j] = fpowers[j]*2*v[j]%mod;
            (sub += fpowers[j]) %= mod;
        }
        cout << (tmp-sub+mod)*invtwo%mod << endl;
    }
    return 0;
}

#include <iostream>

using namespace std;
using LL = long long;

const int kM = 1e9 + 7;
const int kB = 16, kMaxN = 2e5 + 1;

string s;
LL f[kMaxN][kB + 1], g[kMaxN][kB + 1];
int c[kB];
int n, k, t, ans;

void check() {
  f[1][1] = kB - 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      f[i][j] = (f[i][j] + f[i - 1][j] * j + f[i - 1][j - 1] * (kB - j + 1)) % kM;
    }
    ans = (ans + f[i][k]) % kM;
  }
}

void chick() {
  g[1][1] = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      g[i][j] = (g[i][j] + g[i - 1][j] * j + g[i - 1][j - 1] * (kB - j + 1)) % kM;
    }
    for (int j = 0; j < s[i - 1]; j++) {
      int tmp = t + !c[j];
      g[i][tmp] = (g[i][tmp] + 1) % kM;
    }
    t += !(c[s[i - 1]]++);
  }
  ans = (ans + g[n][k] + (t == k)) % kM;
}

int main() {
  cin >> s >> k;
  n = s.length();
  for (int i = 0; i < n; i++) {
    s[i] -= s[i] <= '9' ? '0' : 'A' - 10;
  }
  check(), chick();
  cout << ans;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

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

  rep(i,M){
    A[i]--;B[i]--;
  }

  vector<set<int>> gs(N);
  rep(i,M){
    if(C[A[i]]!=C[B[i]]) continue;
    gs[A[i]].insert(B[i]);
    gs[B[i]].insert(A[i]);
  }

  map<pair<int,int>,int> mp;
  rep(i,M) mp[mkp(A[i],B[i])]=i;

  vector<int> ans(M,-1);
  rep(i,M){
    if(C[A[i]]<C[B[i]]) ans[i]=0;
    if(C[A[i]]>C[B[i]]) ans[i]=1;
  }

  auto dfs = [&](auto &&dfs,int now) -> void{
    while(!gs[now].empty()){
      int nex=*(gs[now].begin());
      gs[now].erase(nex);
      gs[nex].erase(now);

      if(mp.count(mkp(now,nex))) ans[mp[mkp(now,nex)]]=1;
      else ans[mp[mkp(nex,now)]]=0;

      dfs(dfs,nex);
    }
  };

  rep(i,N) dfs(dfs,i);

  rep(i,M){
    if(ans[i]==1) cout<<"->"<<"\n";
    else cout<<"<-"<<"\n";
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#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>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 102;
int U[M*M],V[M*M];
vector<int> vtr[M];
bool f[M*M],vis[M];
int arr[M],c[M],t=0;
int adj(int u,int e)
{
	if(U[e]==u)
		return V[e];
	return U[e];
}
int dfs(int x,int edge, int p)
{
	vis[x]=1;
	arr[x] = arr[p] + 1;
	int mn=arr[x];
	for(auto e: vtr[x])
	{
		if(e == edge)
			continue;
		int u = adj(x, e);
		if(arr[u] > arr[x])
			continue;

		if(vis[u])
			mn = min(mn, arr[u]);
		else
			mn = min(mn, dfs(u, e, x));
		// x->u
		if(U[e] == x)
			f[e] = 0;
		else
			f[e] = 1;
	}
	return mn;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>U[i]>>V[i];
	for(int i=1;i<=n;i++)
		cin>>c[i];
	for(int i=1;i<=m;i++)
	{
		int u = U[i], v = V[i];
		if(c[u] > c[v])
			f[i] = 0;
		if(c[u] < c[v])
			f[i] = 1;
		if(c[u] == c[v])
		{
			vtr[u].pb(i);
			vtr[v].pb(i);
		}
	}
	for(int i=1;i<=n;i++)
		if(vis[i] == 0)
			dfs(i, -1, 0);
	for(int i=1;i<=m;i++)
	{
		if(f[i] == 0)
			cout<<"->\n";
		else
			cout<<"<-\n";
	}
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
  int A[4];
  for(int i=0; i<4; i++)
    cin >> A[i];

  cout << (A[3]*A[0]) - (A[1]*A[2]) << endl;

  return 0;
}

//ATC001B
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    double a,b;
    cin >> a >> b;
    cout << (a-b)*100/a << endl;
}