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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

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

    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (int i=0; i<h; i++)
        cin >> grid[i];

    auto get = [&] (int r, int c) -> int {
        return grid[r][c] == '+' ? 1 : -1;
    };

    vector<vector<vector<int>>> dp(h, vector<vector<int>>(w, vector<int>(2)));
    for (int i=h-1; i>=0; i--)
        for (int j=w-1; j>=0; j--) {
            if (i == h - 1 && j == w - 1) continue;
            dp[i][j][0] = max(i + 1 < h ? dp[i+1][j][1] + get(i + 1, j) : -1e9, j + 1 < w ? dp[i][j+1][1] + get(i, j + 1) : -1e9);
            dp[i][j][1] = min(i + 1 < h ? dp[i+1][j][0] - get(i + 1, j) : 1e9, j + 1 < w ? dp[i][j+1][0] - get(i, j + 1) : 1e9);
        }

    if (dp[0][0][0] > 0) cout << "Takahashi\n";
    else if (dp[0][0][0] < 0) cout << "Aoki\n";
    else cout << "Draw\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

int main() {
    int n;
	cin >> n;
    cout <<"6 10 15 ";
    int count=3;
    fro(i,16,10001){
      if(count==n)break;
      if(i%6==0||i%10==0||i%15==0){
        cout <<i<<" ";
        count++;
      }
    }
}

#include <bits/stdc++.h>
using namespace std;
const int kN = 10010;

vector<int> pr;
bool notp[kN];
bool vis[kN];
void Preprocess() {
  for(int i = 2; i < kN; i++) {
    if(!notp[i]) pr.push_back(i);
    for(int p : pr) {
      if(i * p >= kN) break;
      notp[i * p] = 1;
      if(i % p == 0) break;
    }
  }
}
vector<int> ans;

bool check(int x) {
  return x % 6 == 0 || x % 10 == 0 || x % 15 == 0;
}

void Dfs(int id, int x) {
  if(ans.size() >= 2500) return;
  if(x * pr[id] > 10000) return;

  if(!check(x * pr[id])) printf("x = %d, p = %d\n", x, pr[id]);

  Dfs(id + 1, x);
  int tot = x;
  while(tot * pr[id] <= 10000) {
    if(!vis[tot * pr[id]]) {
      ans.push_back(tot * pr[id]), vis[tot * pr[id]] = 1;
    }
    Dfs(id + 1, tot * pr[id]);
    tot *= pr[id];
  }
}

void Solve() {
  Dfs(0, 6);
  Dfs(0, 10);
  Dfs(1, 15);

  //for(int j = 4; j <= 30; j++) {
  // for(int mask = 0; mask < (1 << (j - 3)); j++) {
  //   int tmp = 1;
  //   for(int i = 3; i < j; i++) if(mask & (1 << (i - 3))) {
  //     tmp *= pr[i];
  //     if(tmp > 10000) break;
  //   }

  //   if(tmp * 6 <= 10000) Dfs(j + 1, tmp * 6);
  //   if(tmp * 10 <= 10000) Dfs(j + 1, tmp * 10);
  //   if(tmp * 15 <= 10000) Dfs(j + 1, tmp * 15);
  //   if(tmp * 30 <= 10000) Dfs(j + 1, tmp * 15);
  // }
  //}
}

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

  ans.push_back(6), ans.push_back(10), ans.push_back(15);

  Solve();
  //printf("size = %d\n", int(ans.size()));
  //for(int x : ans) printf("%d ", x); puts("");
  //for(int x : ans) {
  //  if(x % 6 != 0 && x % 10 != 0 && x % 15 != 0) printf("x = %d\n", x);
  //}

  for(int i = 0; i < n; i++) printf("%d ", ans[i]); puts("");
  return 0;
}


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

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

#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
    return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
    return min(min(a, b), c);
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

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

ll Xor(ll a, ll b) {
    ll A = a, B = b;
    ll C = 0;
    ll k = 1;
    while (A > 0 || B > 0) {
        if (A % 2 != B % 2) {
            C += k;
        }
        k *= 2;
        A /= 2;
        B /= 2;

    }
    return C;
}
ll mod = 1e9 + 7;

int main() {

    string S,T;

    cin >> S>>T;
    if (S == "Y") {
        if (T == "a" || T == "A")cout << "A" << endl;
        else if (T == "b" || T == "B")cout << "B" << endl;
        else if (T == "c" || T == "C")cout << "C" << endl;
    }
    else cout << T << endl;

}


#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i:x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l)<=(x) && (x)<(r))
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return true;} else return false;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return true;} else return false;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};  // UnionFind uf(N+1);  // 1-indexed

int main() {
    // 連結成分ごとに計算、頂点数と出てきている色の種類のmin
    int N;
    cin >> N;
    vector<int> colTop(400005, -1);
    UnionFind uf(N);   // 0-indexed
    vector<pii> AB;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        AB.emplace_back(a, b);
        if (colTop[a] == -1) colTop[a] = i;
        else {
            int c = colTop[a];
            uf.unite(i, c);
        }
        if (colTop[b] == -1) colTop[b] = i;
        else {
            int c = colTop[b];
            uf.unite(i, c);
        }
    }
    vector<set<int>> st(N);
    rep(i, N) {
        int r = uf.root(i);
        auto [a, b] = AB[i];
        st[r].insert(a);
        st[r].insert(b);
    }
    ll ans  = 0;
    rep(i, N) {
        if (uf.root(i) == i) {
            int s = uf.size(i);
            int c = sz(st[i]);
            ans += min(s, c);
        }
    }
    cout << ans << '\n';
    return 0;
}

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
const int N = 1e4;
int n, k, p[N], pw[N], ss[N];
char s[N], t[N];
ll all = 0,  ans;
bool calc() {
	int sum1 = 0, sum2 = 0;

	L(i, 1, 9) ss[i] = 0;
	L(i, 1, 5) ss[s[i] - '0'] ++;
	L(i, 1, 9) sum1 += pw[ss[i]] * i;

	L(i, 1, 9) ss[i] = 0;
	L(i, 1, 5) ss[t[i] - '0'] ++;
	L(i, 1, 9) sum2 += pw[ss[i]] * i;

	return sum1 > sum2;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	pw[0] = 1,
	pw[1] = 10,
	pw[2] = 100,
	pw[3] = 1000,
	pw[4] = 10000,
	pw[5] = 100000;
	cin >> k >> (s + 1) >> (t + 1);
	L(i, 1, 4) p[s[i] - '0'] ++;
	L(i, 1, 4) p[t[i] - '0'] ++;

	all = (ll) (k * 9 - 8) * (k * 9 - 9) ;
	L(i, 1, 9) L(j, 1, 9) {
		s[5] = i + '0';
		t[5] = j + '0';
		ll pnt = 0;
		if(i == j) pnt = (ll) (k - p[i]) * (k - p[i] - 1);
		else pnt = (ll) (k - p[i]) * (k - p[j]);
		ans += pnt * calc();
	}
	cout.precision(12), cout << fixed;
	cout << (db) ans / all << "\n";
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

//エラストテネスの篩(O(nloglogn))
struct sieve {
    int n;
    vector<int> f, primes;
    sieve(int n = 1) : n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }
    bool is_prime(int x) {return f[x] == x;}
    // 素因数分解したものを返す(12=2x2x3)
    vector<int> factor_list(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    // xが小さいときはエラストテネスの篩を用いて素因数分解
    vector<P> factor(int x) {
        vector<int> fl = factor_list(x);
        if (fl.size() == 0) return {};
        vector<P> res(1,P(fl[0],0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p,1);
            }
        }
        return res;
    }
    vector<pair<ll,int>> factor(ll x) {
        vector<pair<ll,int>> res;
        for (int p : primes) {
            int y = 0;
            while (x % p == 0) {
                x /= p;
                y++;
            }
            if (y != 0) res.emplace_back(p,y);
        }
        if (x != 1) res.emplace_back(x,1);
        return res;
    }
};

ll gcd(ll a, ll b) {return(b ? gcd(b, a % b) : a);}

int main() {
    int n; cin >> n;
    vint x(n);
    rep(i,n) cin >> x[i];
    vint primes;
    sieve sv(55);
    for (int v = 1; v <= 50; v++) if (sv.is_prime(v)) primes.emplace_back(v);
    int sz = primes.size();
    ll ans = inf_l;
    rep(i,1<<sz) {
        ll ans_tmp = 1;
        bool ok = true;
        rep(j,sz) if (i >> j & 1) ans_tmp *= primes[j];
        rep(j,n) {
            if (gcd(x[j], ans_tmp) == 1) ok = false;
        }
        if (ok) ans = min(ans, ans_tmp);
    }
    cout << ans << endl;
}

#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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

int main(){
    std::string S; std::cin >> S;
    std::reverse(std::begin(S), std::end(S));
    char prv(0);
    int prvidx(0);
    std::vector<int> cnt(26);
    ++cnt[S[0]- 'a'];
    long long ans(0);
    for(int i(1), i_len(S.length()); i < i_len; ++i){
        if(S[i] == S[i-1]){
            if(prv == S[i]){
                ans += i - prvidx - cnt[S[i] - 'a'] - 1;
            }else{
                ans += i - cnt[S[i] - 'a'];
            }
            prv = S[i];
            prvidx = i;
            for(int j(0); j < 26; ++j) cnt[j] = 0;
        }else{
            ++cnt[S[i] - 'a'];
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=1e9+7;
const ll N=1e5+2;
ll n,l;
ll a[N],b[N];
vector<ll>va,vb;
queue<pair<ll,ll> >q;
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> l;
	for(int i=1; i<=n+1 ;i++){
		if(i!=n+1) cin >> a[i];
		else a[i]=l+1;
		va.push_back(a[i]-a[i-1]-1);
	}
	for(int i=1; i<=n+1 ;i++){
		if(i!=n+1) cin >> b[i];
		else b[i]=l+1;
		vb.push_back(b[i]-b[i-1]-1);
	}
	for(int i=0; i<=n ;i++){
		if(va[i]!=0) q.push({va[i],i});
	}
	q.push({1e18,0});
	ll ans=0;
	for(int i=0; i<=n ;i++){
		if(vb[i]==0) continue;
		ll mn=i;
		ll mx=i;
		while(vb[i]>0){
			auto c=q.front();q.pop();
			vb[i]-=c.fi;
			mn=min(mn,c.se);
			mx=max(mx,c.se);
		}
		ans+=mx-mn;
		//cout << i << ' ' << mn << ' ' << mx << endl;
		if(vb[i]<0) return cout << "-1\n",0;
	}
	cout << ans << '\n';
}

#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <string>
using namespace std;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //GOOD LUCK
    int n;
    cin >> n;
    string ar[n];
    map<string, int> mep;
    for (int i = 0; i < n; i ++) {
        cin >> ar[i];
    }
    sort(ar, ar+n);
    for (int i = 0; i < n; i ++) {

        if (ar[i][0] == '!') {
            mep[ar[i].substr(1, ar[i].length()-1)] += 1;
        }
        else {
            mep[ar[i]] *= -1;
        }
    }
    for (pair<string, int> me: mep) {
        if (me.second < 0) {
            cout << me.first << endl;
            return 0;
        }
    }
    cout << "satisfiable" << endl;
    /* CHECK:
    int vs. ll
    array bounds: n+1
    don't get it wrong
    actually read what's here
    */
}


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	return out << '(' << p.first << ',' << p.second << ')';
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	return in >> p.first >> p.second;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int n;
	cin >> n;
	ll x;
	cin >> x;
	vl v(n);
	cin >> v;
	ll ans = LLONG_MAX;
	rep(num,1,n+1)
	{
		vvl dp(num + 1, vl(num, -1));
		dp[0][0] = 0;
		for(ll x : v)
			per(i,num-1,-1)
				rep(j,0,num)
					if(dp[i][j] != -1)
						dp[i + 1][(j + x) % num] = max(dp[i + 1][(j + x) % num], dp[i][j] + x);
		if(dp.back()[x % num] != -1)
			ans = min(ans, (x - dp.back()[x % num]) / num);
	}
	cout << (ans == LLONG_MAX ? -1 : ans);
}


#include<iostream>
using namespace std;

int main(){
  int A[4];
  cin>>A[0]>>A[1]>>A[2]>>A[3];
  int t=100;
  for(int i=0; i<4; i++){
    if(t>A[i]){t=A[i];}
  }
  cout<<t<<endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std ;
int main(){
  int a,b,c,d;
  cin>>a>>b;
  cin>>c>>d;
  cout<<b-c<<endl;
}


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

#ifdef LOCAL
    #define D(a) cerr << #a << " = " << a << endl
#else
    #define D(a) 8
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;

    int x, y; cin >> x >> y;
    if (x > y) swap(x, y);
    cout << (x + 3 > y ? "Yes" : "No") << endl;

	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define lchild 2*node
#define rchild 2*node+1
#define mid (l+r)/2
#define mod 1000000007
#define mx 300007
#define pii pair<int,int>
#define pci pair<int,int>
#define ff first
#define ss second
#define piii pair<int,pii>
using namespace std;

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

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

    if( min(a,b)+3>max(a,b) )
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

int main(){
    ll n;
    cin>>n;
    vector<P> a;
    rep(i,2*n){
        ll ai;
        cin>>ai;
        a.emplace_back(ai,i);
    }
    sort(a.begin(),a.end());
    V d(2*n,0);
    rep(i,n){
        d[a[i].second]=0;
        d[a[i+n].second]=1;
    }
    debugALL(d);
    string ans;
    ll res=0;
    stack<ll> sta;
    rep(i,2*n){
        if(res==0){
            ans.push_back('(');
            res++;
            sta.push(d[i]);
        }else{
            if(sta.top()==d[i]){
                sta.push(d[i]);
                res++;
                ans.push_back('(');
            }else{
                sta.pop();
                res--;
                ans.push_back(')');
            }
        }
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a,b,sizeof(a))
#define vi vector<int>
#define vii vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
#define in(a) for(auto &x: a)cin>>x;
#define out(a) for(auto x: a){cout<<x<<' ';}cout<<'\n';
#define inf 1000000000
//#define mm 1000000007 998244353
void print(bool n){if(n)cout<<"YES";else cout<<"NO";cout<<'\n';}
signed main(){
	fastio
	int n;
	cin>>n;
	int p[n];
	fill(p,0);
	bool a[n];
	bool b[n];
	char x;
	vi aa,bb;
	rep(i,0,n){
		cin>>x;
		a[i]=(x=='1');
		if(!a[i])aa.pb(i);
	}
	rep(i,0,n){
		cin>>x;
		b[i]=(x=='1');
		if(!b[i])bb.pb(i);
	}
	if(aa.size()!=bb.size()){
		cout<<-1;return 0;
	}
	int r=0;
	bool arr[n];
	fill(arr,0);
	rep(i,0,aa.size()){
		if(aa[i]==bb[i])continue;
		if(aa[i]<bb[i]){
			rep(j,aa[i],bb[i]+1){
				if(a[j]==0)arr[j]=1;
			}
		}
		if(aa[i]>bb[i]){
			for(int j=aa[i];j>=bb[i];j--){
				if(a[j]==0)arr[j]=1;
			}
		}
	}
	int sum=0;
	rep(i,0,n)sum+=arr[i];
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e6+13;
int sum[maxn<<2];
int sum2[maxn<<2];
int a[maxn];
void up(int x){
	sum[x]=sum[x<<1]+sum[x<<1|1];
}
void modify(int rt,int l,int r,int pos,int op){
	if(l==r){
		if(op) sum2[rt]-=1;
		else sum2[rt]+=1;
		if(sum2[rt]>0) sum[rt]=1;
		else sum[rt]=0;
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid) modify(rt<<1,l,mid,pos,op);
	else modify(rt<<1|1,mid+1,r,pos,op);
	up(rt);
}
int query(int rt,int l,int r){
	if(l==r){
		return l;
	}
	else{
		int mid=l+r>>1;
		if(sum[rt<<1]<mid-l+1){
			return query(rt<<1,l,mid);
		}
		else{
			return query(rt<<1|1,mid+1,r);
		}
	}
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int ans=1e9;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		if(i<=m)
		{
			modify(1,0,n,a[i],0);
			if(i==m) ans=min(ans,query(1,0,n));
		}
		else{
			modify(1,0,n,a[i-m],1);
			modify(1,0,n,a[i],0);
			ans=min(ans,query(1,0,n));
		}
	}
	printf("%d",ans);
}

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

#define ll long long int
#define ld double
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<double>	vd;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define gcd __gcd
#define debug(a...) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;
ll MAX = 1e7 + 1;
#define MAXIM 200005
ll mod = 1e9 + 7;

vll v;
ll n,q;

void add(ll ind,ll val){
    while(ind <= n){
        v[ind] ^= val;
        ind += (ind & (-1*ind));
    }
}

ll sum(ll ind){
    ll x = 0;
    while(ind > 0){
        x ^= v[ind];
        ind -= (ind & (-1*ind));
    }
    return x;
}

void solve(){
    cin >> n >> q;
    v.resize(n + 1);
    rep(i,1,n + 1){
        ll x;
        cin >> x;
        add(i,x);
    }
    rep(i,0,q){
        ll t,a,b;
        cin >> t >> a >> b;
        if(t == 1) add(a,b);
        else cout << (sum(b)^sum(a - 1)) << br;
    }
}

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

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

	ll t = 1;
    // cin >> t;
    // calc();
	rep(i,0,t){
        // cout << "Case #" << i + 1 << ": ";
        solve();
        // test();
	}
}


#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// #define INF (1<<9+9)
const int INF = 0x3fffffff;
// const long long INF = 1LL<<50;

#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define pie 3.14159265358979323846

using namespace std;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)998244353;
// const int mod =(int)998244353;
const int mod =(int)1e9+7;

const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;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;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
  if(a<0)a=-a;
  if(b<0)b=-b;
    ll g;g=gcd(a,b);
    return b/g*a;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}
//int N, M, K, T, H, W, L, R;
// long long int N, M, K, T, H, W, L, R
ll RS(ll N,ll P){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2);
            return t*t;
        }else{
            return N*RS(N,P-1);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<int>v(N);
    REP(i,N)cin>>v[i];
    int ans=INF;
    REP(i,(1<<N-1)){
        int ans_temp=0;
        int or_temp=v[0];
        REP(j,N-1){
            if((i>>j)&1){
                ans_temp=ans_temp^or_temp;
                or_temp=v[j+1];
            }else{
                or_temp|=v[j+1];
            }
        }
        ans_temp=ans_temp^or_temp;
        chmin(ans,ans_temp);
    }
    cout<<ans<<endl;
    return 0;

}

//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

/* if you want to multiply 2 64 bit numbers mod c.
 i.e a*b%c.
 this function will help  in preventing "overflow".
*/

ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll poww(ll a, ll b)
{

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

  return ans;

}

string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}

const ll N = 2e5 + 5;

int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll h, w;

  cin >> h >> w;

  string g[h];

  FOR(i, h)cin >> g[i];

  ll ans = 0;

  vl a;
  ll c;
  for (ll i = 0; i < h; i++) {
    c = 0;
    for (ll j = 0; j < w; j++) {
      if (g[i][j] == '.')c++;
      else {
        // d1(c);
        ans += max(0ll, c - 1);
        c = 0;
      }
    }
    ans += max(0ll, c - 1);
  }

  for (ll j = 0; j < w; j++) {
    c = 0;
    for (ll i = 0; i < h; i++) {
      if (g[i][j] == '.')c++;
      else {
        //cout << "h" << " " << c << endl;
        ans += max(0ll, c - 1);
        c = 0;
      }
    }
    ans += max(0ll, c - 1);
  }

  cout << ans << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1>
void print(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "\n" : " ");
    }
}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 100001
#define MOD 1000000007ll

vector<int> G[MAX];

bool cmp(const pair<int, int> a,const pair<int, int> b) {
    return a.first - a.second < b.first - b.second;
}

pair<int, int> dfs(int n) {
    pair<int, int> r = {1,0};
    pair<int, int> pp = {0,0};
    vector<pair<int, int>> P;
    for(auto &g : G[n]) {
        auto p = dfs(g);
        if ((p.first + p.second) % 2 == 0) {
            if (p.second > p.first) {
                r.first +=p.first;
                r.second += p.second;
            } else {
                pp.first +=p.first;
                pp.second += p.second;
            }
        } else
        {
            P.push_back(p);
        }
    }
    if (P.size() % 2 == 0) {
        r.first +=pp.first;
        r.second += pp.second;
    } else {
        r.first +=pp.second;
        r.second += pp.first;
    }

    sort(P.begin(), P.end(), cmp);
    for(int i = 0; i < P.size(); i++) {
        if (i % 2 == 0) {
            r.first +=P[i].first;
            r.second += P[i].second;
        } else {
            r.first += P[i].second;
            r.second += P[i].first;
        }
    }
    return r;
}

void solve() {
    int n, x;
    cin >> n;
    rep(i,n) G[i].clear();
    reps(i, 1, n) {
        cin >> x;
        G[x-1].push_back(i);
    }
    auto p = dfs(0);
    out(p.first);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int test = 1;
    //cin >> test;
    rep(testCase, test) {
        #ifdef _OLIMPOLOCAL
            cout << "------------------ TESTCASE: " << testCase << " -------------\n";
        #endif
        solve();
    }
    return 0;
}

//Code Written by Pinaki Bhattacharjee
#include<bits/stdc++.h>
using namespace std;

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

// #define
#define LOCAL
#define INF 1e18
#define MAX 10000
#define PI 2*acos(0.0)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define set_bits __builtin_popcountll
#define DEBUG(x) cerr << #x << " = " << x << endl;
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

// debugger
#ifdef LOCAL
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
    #define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

/*--------------------------------------------------------------------------------------------------------------------------*/

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

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

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

void google(int t) {cout << "Case #" << t << ": ";}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

/*--------------------------------------------------------------------------------------------------------------------------*/

int main()
{
    pinakipb2;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
    // Code begins

    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll ans = 0;
    ll a = 0, b = 0;
    for(int i=0;i<n;i++)
    {
        a+=arr[i]*arr[i];
        b+=arr[i];
    }
    ans = (n*a)-(b*b);
    cout<<ans<<endl;

    // Code ends
    return 0;
}


/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Max Matrix
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288
const int MAX_QN = 200000;

/* typedef */

typedef long long ll;

struct Qry {
  int t, x, y;
  Qry() {}
  Qry(int _t, int _x, int _y): t(_t), x(_x), y(_y) {}
  void read() { scanf("%d%d%d", &t, &x, &y); x--; }
  void print() { printf("Qry(%d,%d,%d)\n", t, x, y); }
};

template <typename T, const int MAX_E2>
struct SegTreeSum {
  int e2;
  T nodes[MAX_E2];
  SegTreeSum() {}

  void init(int n) {
    for (e2 = 1; e2 < n; e2 <<= 1);
    //fill(nodes, nodes + MAX_E2, 0);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
    }
  }
  void add(int i, T v) { set(i, geti(i) + v); }

  T sum_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return 0;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);
    return v0 + v1;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

Qry qs[MAX_QN];
int as[MAX_N], bs[MAX_N], uas[MAX_N + 1], ubs[MAX_N + 1];
SegTreeSum<int,MAX_E2> asti, bsti;
SegTreeSum<ll,MAX_E2> astl, bstl;

/* subroutines */

inline int get_index(int un, int us[], int v) {
  return lower_bound(us, us + un, v) - us;
}

/* main */

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

  int uan = 0, ubn = 0;
  uas[uan++] = ubs[ubn++] = 0;

  for (int i = 0; i < qn; i++) {
    qs[i].read();
    if (qs[i].t == 1) uas[uan++] = qs[i].y;
    else ubs[ubn++] = qs[i].y;
  }

  sort(uas, uas + uan);
  sort(ubs, ubs + ubn);
  uan = unique(uas, uas + uan) - uas;
  ubn = unique(ubs, ubs + ubn) - ubs;

  asti.init(uan), astl.init(uan);
  asti.set(0, n);
  bsti.init(ubn), bstl.init(ubn);
  bsti.set(0, m);

  ll sum = 0;
  for (int i = 0; i < qn; i++) {
    Qry &qi = qs[i];
    //qi.print();

    if (qi.t == 1) {
      int pa = as[qi.x];
      if (pa != qi.y) {
	int i0 = get_index(ubn, ubs, pa);
	sum -= (ll)pa * bsti.sum_range(0, i0) + bstl.sum_range(i0, ubn);
	int j0 = get_index(uan, uas, pa);
	asti.add(j0, -1), astl.add(j0, -pa);

	int i1 = get_index(ubn, ubs, qi.y);
	sum += (ll)qi.y * bsti.sum_range(0, i1) + bstl.sum_range(i1, ubn);
	int j1 = get_index(uan, uas, qi.y);
	asti.add(j1, 1), astl.add(j1, qi.y);
	as[qi.x] = qi.y;
      }
    }
    else {
      int pb = bs[qi.x];
      if (pb != qi.y) {
	int i0 = get_index(uan, uas, pb);
	sum -= (ll)pb * asti.sum_range(0, i0) + astl.sum_range(i0, uan);
	int j0 = get_index(ubn, ubs, pb);
	bsti.add(j0, -1), bstl.add(j0, -pb);

	int i1 = get_index(uan, uas, qi.y);
	sum += (ll)qi.y * asti.sum_range(0, i1) + astl.sum_range(i1, uan);
	int j1 = get_index(ubn, ubs, qi.y);
	bsti.add(j1, 1), bstl.add(j1, qi.y);
	bs[qi.x] = qi.y;
      }
    }

    printf("%lld\n", sum);
  }
  return 0;
}

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++)
#define REP(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define RFOR(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--)
#define RREP(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--)
typedef long long LL;

const int maxn=100+5;
int n,A[maxn];
char s[maxn];
int main() {
	scanf("%d%s",&n,s);
	REP(i,0,n) scanf("%d",&A[i]);
	int k=std::abs(A[1]-A[0]);
	REP(i,1,n) k=std::min(k,std::abs(A[i]-A[i-1]));
	printf("%d\n",k);
	FOR(i,0,k) {
		REP(j,0,n) printf("%d ",(A[j]+i)/k);
		putchar('\n');
	}
	return 0;
}


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

int n, w[19], l[100009], v[100009], lp[309], pr[19];
long long ans = 1e18, d[19];
bool vs[19];

void ps()
{
	d[0] = 0;
	for (int i = 1; i < n; i++) {
		int s = (1 << pr[i]);
		d[i] = d[i - 1];
		for (int j = i - 1; j >= 0; j--) {
			s += (1 << pr[j]);
			d[i] = max(d[i], d[j] + 1LL * lp[s]);
		}
	}
	ans = min(ans, d[n - 1]);
}

void fg(int pi)
{
	if (pi == n) {
		ps();
		return;
	}
	for (int i = 0; i < n; i++) {
		if (vs[i]) continue;
		vs[i] = true; pr[pi] = i;
		fg(pi + 1);
		vs[i] = false;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int m; cin >> n >> m;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		mx = max(mx, w[i]);
	}
	bool f = true;
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> v[i];
		if (v[i] < mx) f = false;
	}
	if (!f) {
		cout << -1 << '\n';
		return 0;
	}
	for (int i = 0; i < (1 << n); i++) {
		long long s = 0;
		for (int j = 0; j < n; j++)
			if ((1 << j) & i)
				s += w[j];
		for (int j = 0; j < m; j++)
			if (v[j] < s)
				lp[i] = max(lp[i], l[j]);
	}
	fg(0);
	cout << ans << '\n';
	return 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
//#define MOD 998244353
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(){

		len = value = 0;
	}
	Info(ll arg_len,ll arg_value){
		len = arg_len;
		value = arg_value;
	}
	bool operator<(const struct Info& arg) const{
		if(len != arg.len){

			return len < arg.len;
		}else{

			return value > arg.value;
		}

	}

	ll len,value;
};

ll N,M;
ll W[10],work[10];
ll max_dist[10][10];
Info info[100005];
vector<Info> V;

int main(){

	scanf("%lld %lld",&N,&M);

	ll max_W = 0;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&W[i]);
		max_W = max(max_W,W[i]);
	}

	for(ll i = 0; i < M; i++){

		scanf("%lld %lld",&info[i].len,&info[i].value);
		if(info[i].value < max_W){

			printf("-1\n");
			return 0;
		}
	}

	sort(info,info+M);

	ll mini = HUGE_NUM;
	for(int i = M-1; i >= 0; i--){
		if(info[i].value < mini){
			mini = info[i].value;
			//printf("len:%lld value:%lld\n",info[i].len,info[i].value);
			V.push_back(info[i]);
		}
	}

	ll ans = HUGE_NUM;

	vector<int> vec;
	for(int i = 0; i < N; i++){

		vec.push_back(i);
	}

	do{

		for(ll i = 0; i < N; i++){

			work[i] = 0;
		}

		ll table[10];
		for(ll i = 0; i < N; i++){

			table[i] = W[vec[i]];
			if(i == 0)continue;

			table[i] += table[i-1];
		}

		for(ll i = 1; i < N; i++){
			for(ll base = 0; base <= i-1; base++){

				//総重量
				ll sum_W = 0;
				if(base == 0){

					sum_W = table[i];
				}else{

					sum_W = table[i]-table[base-1];
				}

				int left = 0,right = (int)V.size()-1,mid = (left+right)/2;
				int loc = -1;

				//耐えられない最小のindexを求める

				while(left <= right){

					if(V[mid].value < sum_W){

						loc = mid;
						right = mid-1;
					}else{

						left = mid+1;
					}
					mid = (left+right)/2;
				}

				ll add_len = 0;

				if(loc == -1){ //全ての橋がOK

					add_len = 0;

				}else{

					add_len = V[loc].len;
				}

				//printf("i:%lld base:%lld add_len:%lld sum_W:%lld loc:%d\n",i,base,add_len,sum_W,loc);

				work[i] = max(work[i],work[base]+add_len);
			}
		}
		ans = min(ans,work[N-1]);

	}while(next_permutation(vec.begin(),vec.end()));

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

	return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    LL res = 0;
    int id = 0;
    for (int i = 0; i < N; i++) {
		if (S[i] == T[i]) continue;
		id = max(i+1, id);
		while (id < N and S[id] == '0') id++;
		if (id == N) {
			cout << -1 << "\n";
			return 0;
		}
		res += id - i;
		S[i] = T[i], S[id] = '0';
	}
	cout << res << "\n";
}

#include<cstdio>
#include<cstring>
#define rg register
const int maxn=1e6+5;
char s[maxn],t[maxn];
int n,cnt1,cnt2,sta1[maxn],sta2[maxn],now;
long long ans;
int main(){
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	for(rg int i=1;i<=n;i++){
		if(s[i]=='1'){
			sta1[++cnt1]=i;
		}
	}
	for(rg int i=1;i<=n;i++){
		if(t[i]=='1'){
			sta2[++cnt2]=i;
		}
	}
	if(cnt1<cnt2 || (cnt1-cnt2)%2){
		printf("-1\n");
		return 0;
	}
	now=1;
	for(rg int i=1;i<=cnt2;i++){
		if(now>cnt1){
			printf("-1\n");
			return 0;
		}
		while(sta1[now]<sta2[i]){
			if(now+2>cnt1){
				printf("-1\n");
				return 0;
			}
			ans+=sta1[now+1]-sta1[now];
			now+=2;
		}
		ans+=sta1[now]-sta2[i];
		now++;
	}
	while(now<cnt1){
		ans+=sta1[now+1]-sta1[now];
		now+=2;
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pii pair<int,int>

int N;
int U[210], L[210];
int U_id[210], L_id[210];
bool dp[400];

bool unit(int s, int d)
{
    for(int i = 0; i < d; i++)
    {
        if(U_id[s + i] != 0)
        {
            return false;
        }
        if(L_id[s + i + d] != 0)
        {
            return false;
        }
        /*
        if(L_id[s + 1] != 0 && U[L_id[s + i]] != -1 && U[L_id[s + i]] != s + i + d)
        {
            return false;
        }
        if(U_id[s + i + d] != 0 && L[U_id[s + i + d]] != -1 && L[U_id[s + i + d]] != s + i)
        {
            return false;
        }
        */
        if(L_id[s + i] != 0 && U_id[s + i + d] != 0 && L_id[s + i] != U_id[s + i + d])
        {
            return false;
        }
    }
    return true;
}

signed main()
{
    cin >> N;
    rep(i, N)
    {
        int a, b;
        cin >> a >> b;
        a, b;
        L[i + 1] = a;
        U[i + 1] = b;
        if(a != -1 && b != -1 && a >= b)
        {
            cout << "No" << endl;
            return 0;
        }
        if(a != -1)
        {
            if(L_id[a] != 0 || U_id[a] != 0)
            {
                cout << "No" << endl;
                return 0;
            }
            L_id[a] = i + 1;
        }
        if(b != -1)
        {
            if(U_id[b] != 0 || L_id[b] != 0)
            {
                cout << "No" << endl;
                return 0;
            }
            U_id[b] = i + 1;
        }
    }

    dp[1] = true;
    for(int i = 1; i <= 2 * N; i++)
    {
        if(dp[i])for(int j = 1; i + j * 2 <= 2 * N + 1; j++)
            if(unit(i, j))dp[i + j * 2] = true;
    }

    if(dp[2 * N + 1])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

#include <cstdio>
#include <utility>

long double abs(long double a)
{
	if (a < 0) return -a;
	return a;
}

const int N = 100000;
int n, m, k;
std::pair<long double, long double> e[N];
bool u[N];

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < k; ++i) {
		int v;
		scanf("%d", &v);
		u[v] = true;
	}
	std::pair<long double, long double> s;
	for (int i = n - 1; i >= 0; --i) {
		if (u[i]) e[i].second = 1;
		else {
			e[i].first = 1 + s.first / m;
			e[i].second = s.second / m;
		}
		s.first += e[i].first;
		s.second += e[i].second;
		if (n - i > m) {
			s.first -= e[i + m].first;
			s.second -= e[i + m].second;
		}
	}
	if (abs(e[0].second - 1) > 1e-10) printf("%.15lf\n", (double)(e[0].first / (1 - e[0].second)));
	else printf("-1\n");
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

int n,m,l,r,mid;
int ans,a[105],b[105],c[105];
string st,t;

int main()
{
	cin>>n;
	for (int i=2;i<=n;i++)
	{
		m=i;
		for (int j=2;j<=30;j++) b[j]=0;
		int j=2;
		while (m!=1)
		{
			if (m%j==0) while (m!=1&&m%j==0) {b[j]++;m=m/j;}
			j++;
		}
		for (int j=2;j<=n;j++)
		 a[j]=max(a[j],b[j]);
	}
	long long ans;
	ans=1;
	for (int i=1;i<=n;i++)
	 {
	 	for (int j=1;j<=a[i];j++)
	 	 ans*=i;
	 }
	cout<<ans+1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
/*
//邻接表不带边权
const int N=1e5+10;
const int M=1e5+10;
int head[N],ver[2*M],nex[2*M],tot=1;
inline void add(int x,int y) {
    ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
}

//邻接表带边权
const int N=1e5+10;
const int M=1e5+10;
int head[N],ver[2*M],edge[2*M],nex[2*M],tot=1;
inline void add(int x,int y,int z) {
    ver[++tot]=y,edge[tot]=z,nex[tot]=head[x],head[x]=tot;
}
*/
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const int p=1e9+7;
const int N=2e5+10;

int a[50][50];
void f(int id,int x){
    for(int i=2;x>1;i++){

        while(x%i==0){
            a[id][i]++;
            x/=i;
        }
    }
}
int main(){
    int n;
    ll ans=1;
    in>>n;

    rep(i,2,n){
        f(i,i);
    }
    rep(i,2,30){
        int Max=0;
        rep(j,2,n)
            Max=max(Max,a[j][i]);
        rep(x,1,Max)ans*=i;
    }
    ans+=1;
    out<<ans;
    return 0;
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

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

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, L;
    cin >> N >> L;
    Vl A(N + 2), B(N + 2);
    for (ll i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] -= i;
    }
    for (ll i = 1; i <= N; i++) {
        cin >> B[i];
        B[i] -= i;
    }
    A[N + 1] = B[N + 1] = (L + 1) - (N + 1);

    Vl pos = B;
    pos.erase(unique(pos.begin(), pos.end()), pos.end());

    ll ans = 0;
    for (auto p : pos) {
        int idxl_a = lower_bound(A.begin(), A.end(), p) - A.begin();
        int idxr_a = upper_bound(A.begin(), A.end(), p) - A.begin();
        int idxl_b = lower_bound(B.begin(), B.end(), p) - B.begin();
        int idxr_b = upper_bound(B.begin(), B.end(), p) - B.begin();
        if (idxr_a - idxl_a == 0) {
            prints()(-1);
            return;
        }
        ans += max(idxr_b - idxr_a, 0) + max(idxl_a - idxl_b, 0);
    }

    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

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

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, X;
  cin >> N >> X;
  llvec a(N);
  rep(i, N){
    cin >> a[i];
  }

  ll ans = 1e18;
  for(ll C=1;C<=N;C++){
    vector<vector<llvec>> dp(N+1, vector<llvec>(C+1, llvec(C, -1)));
    dp[0][0][0] = 0;
    rep(i, N){
      rep(j, C+1){
        rep(k, C){
          if(dp[i][j][k]==-1)continue;
          if(j+1<=C)dp[i+1][j+1][mod(k+a[i], C)] = max(dp[i+1][j+1][mod(k+a[i], C)], dp[i][j][k] + a[i]);
          dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
        }
      }
    }
    if(dp[N][C][mod(X, C)]==-1)continue;
    ans = min(ans, (X - dp[N][C][mod(X, C)])/C);
  }

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


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL A,B; cin >> A >> B;
    if(A == B){
        REP(i,A){
            cout << 1+i << " ";
        }

        REP(i,B){
            cout << -1-i << " ";
        }
        cout << endl;

    }else if(A > B){

        REP(i,A){
            cout << 1+i << " ";
        }

        REP(i,B-1){
            cout << -1-i << " ";
        }
        cout << -((A+B) * (A-B+1) / 2) << " ";
        cout << endl;

    }else{

        REP(i,A-1){
            cout << 1+i << " ";
        }

        cout << ((A+B) * (B-A+1) / 2) << " ";
        REP(i,B){
            cout << -1-i << " ";
        }
        cout << endl;

    }

}

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define rng(i,l,r) for (int i=l; i<r; i++)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> using V = vector<T>;
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
struct in { template <class T> operator T() { T t; std::cin >> t; return t; } };
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
using Graph = V<V<int>>;
auto solve() {
   int n = in();
   int m = in();
   Graph G(n);
   vector<int> a(n); rep(i,n) cin >> a[i];
   rep(i,m) {
      int x=in(), y=in();
      G[x-1].push_back(y-1);
   }
   auto cmp = [&a](int i, int j) { return a[i] < a[j]; };
   V<int> idx(n); rep(i,n) idx[i] = i;
   sort(all(idx), cmp);

   vector<int> seen(n, 0);
   int ans = -INF;
   for (auto i : idx) {
      if (seen[i]) continue;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
         int v = q.front(); q.pop();
         if (v != i) chmax(ans, a[v] - a[i]);
         for (auto u : G[v]) {
            if (seen[u]) continue;
            seen[u] = 1;
            q.push(u);
         }
      }
   }
   return ans;
}

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

   cout << solve() << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r)
{
    return uniform_int_distribution<int>(l, r)(rng);
}

void run_case() {
    ll n, q;
    cin>>n>>q;

    vector<ll> vec(n+1, 0);
    for(int i = 1; i <= n; ++i)
        cin>>vec[i];

    vector<ll> dif;
    for(int i = 0; i < n; ++i)
        dif.push_back(vec[i+1] - vec[i] - 1);

    vector<ll> pref(n);
    pref[0] = dif[0];
    for(int i = 1; i < dif.size(); ++i)
        pref[i] = pref[i-1] + dif[i];

    // for(auto& it : pref) cout<<it<<" ";
    // cout<<endl;

    while(q--) {
        ll k;
        cin>>k;

        auto it = lower_bound(all(pref), k);

        ll diff = 0;
        if(it != pref.begin()) {
            auto it2 = prev(it);
            diff = *it2;
        }

        ll ind = it - pref.begin();
        ll now = k - diff;

        if(it == pref.end()) {
            cout<<now + vec[ind]<<endl;
        }
        else {
            cout<<now + vec[ind]<<endl;
        }
    }
}

int32_t main()  {
    fastio
    int t = 1;
    //cin>>t;
    for(int i = 0; i < t; ++i) {
        run_case();
    }
}

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

using ll = long long;

#define re(i,n)     for(int i = 0 ; i <  n ; i++)
#define rep(i,a,b)  for(int i = a ; i <= b ; i++)
#define rer(i,b,a)  for(int i = b ; i >= a ; i--)

#define debug(x) cout << #x << " : " << x << '\n';

const int N = (int)2e3+3;

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

	int n ,q; cin >> n >> q ;

	vector <ll> a(n);
	re(i,n) cin >> a[i];

	vector<ll>gaps(n);
	re(i,n) {
		gaps[i] = a[i] - (i + 1);
	}
	while(q--) {
		ll k ; cin >> k;

		if( k < a[0] ) {
			cout << k << "\n";
		}else if( a[0] <= k && k <= a[n-1]) {
			int idx = lower_bound(gaps.begin(),gaps.end(),k)-gaps.begin();
			if(idx == n)
				cout << a[n - 1] + (k - gaps[n - 1]) << "\n";
			else cout << a[idx] - gaps[idx] + k - 1 << "\n";
		}else {
			cout << n + k << "\n";
		}
	}

	return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
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;
}
struct edge {
  ll to, cost;
};

bool IsPrime(ll num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (ll i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }

  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  ll N; cin >> N;
  vector<ll> ans(N + 1, 1);
  for(int i = 2; i <= N; ++i) {
    auto x = divisor(i);
    ll tmp = 0;
    REP(k, x.size()) {
      if(x[k] == i) continue;
      tmp = max(tmp, ans[x[k]]);
    }
    ans[i] = tmp + 1;
  }
  for(int i = 1; i <= N; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
}

/*  CREATED BY
    STREAM_CIPHER
    june-2021
*/
#include<bits/stdc++.h>
using namespace std;
void __print(long long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long int
#define double long double
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
// const int mod=998244353;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        set<int>a;
        for(int i=0;i<n;i++){
            int in;
            cin>>in;
            a.insert(in);
        }
        if(a.size()==n){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
}


/*
Author: QAQAutoMaton
Lang: C++
Code: B.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cp;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}
template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
	__INIT__(){
		fill((unsigned char *)(&inf),(unsigned char *)(&inf)+sizeof(inf),0x3f);
	}
}__INIT___;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	template<typename A>
	inline bool read (A &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		while((x=gc())==' '||x=='\n' || x=='\r');
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r');
		if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	template<typename A>
	inline bool write (A x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
int a[300005];
signed main(){
#ifdef QAQAutoMaton
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
	int n,k,x;
	read(n,k);
	for(int i=1;i<=n;++i){read(x);++a[x];}
	int mn=k;
	int ans=0;
	for(int i=0;i<n;++i){chkmin(mn,a[i]);ans+=mn;}
	write(ans,'\n');
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
struct cmp
{
	bool operator()(const int &a,const int &b)
    {
       return a>b;
    }
};
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
void solve()
{
   ll n,m,k;
   cin>>n>>k>>m;
   ll a[105];
   ll sum=0;
   for(int i=1;i<=n-1;i++)
   {
       cin>>a[i];
       sum+=a[i];
   }
   ll t=n*m-sum;
   if(t>=0&&t<=k)
   {
       cout<<t;
   }
   else if(t<0)
   {
       cout<<0;
   }
   else
   {
       cout<<-1;
   }
}
int main()
{
    fast;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define mset(a, b) memset(a, b, sizeof(a))
#define Rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define dRep(i, a, b) for(int i = (a); i >= (b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define endl '\n'
#define int ll
#define un unsigned
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
#define dbug(x) cerr << #x " = " << (x) << endl
template<typename _T> inline void _prt(_T _d) { cerr << _d << ' '; }
template <typename _T, typename ...Args> inline void _prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...); }
template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr<<endl; }
template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d <<endl; }
template <typename _T, typename ...Args> inline void cbg(_T _d, Args ..._a) { cerr << "--LINE " << __LINE__ << "--: "; prt(_d, _a...); }
template<typename _T> inline void rd(_T &_d) {
	signed _f; char _c; _f = _d = 0; while (_c = getchar(), !isdigit(_c)) _f = _f || (_c == '-');
	while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar();
	_d = (_f ? -_d : _d);
}
template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); }

const int N=5e5+5;
int n;
char s[N],t[N];
stack<int> st;

void no() {
	puts("-1"); exit(0);
}

signed main() {
	rd(n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	Rep(i,1,n) s[i]-='0';
	Rep(i,1,n) t[i]-='0';
	int ans=0;
	dRep(i,n,1) {
		if(s[i]==t[i]) continue;
		if(s[i]==1) st.push(i);
		else {
			if(st.empty()) no();
			else ans+=st.top()-i,st.pop();
		}
	}
	int x;
	if(st.size()&1) no();
	while(st.size()) x=st.top(),st.pop(),ans+=st.top()-x,st.pop();
	cout<<ans<<endl;
	return 0;
}

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

const int N=1e5+1e3+7;

int n,f[N],sz[N];

vector<int>g[N];

int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int p;
        scanf("%d",&p);
        g[p].push_back(i);
    }
    for(int i=n;i>=1;i--)
    {
        int x=i;
        f[x]=1;
        sz[x]=1;
        vector<int>cho;
        int sum=0;
        for(auto v:g[x])
        {
            sz[x]+=sz[v];
            if(sz[v]&1)
                cho.push_back(f[v]);
            else if(f[v]<0)
                f[x]+=f[v];
            else
                sum+=f[v];
        }
        sort(cho.begin(),cho.end());
        cho.push_back(sum);
        for(int i=0;i<cho.size();i++)
            if(i&1)
                f[x]-=cho[i];
            else
                f[x]+=cho[i];
    }
    printf("%d\n",(f[1]+n)/2);
}


#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#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;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define mod         1000000007
#define pi          3.1415926535898
#define eps         1e-9

#define fast       ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define vt vector
#define ar array
#define fs          first
#define sc          second
#define pb         push_back
#define sp          printf(" ")
#define nl          '\n'
#define all(a) a.begin(),a.end()
#define unique(c) (c).resize(unique(all(c)) - (c).begin())
#define sz(x) (int)(x).size()
#define revsort(x) sort(all(x));reverse(all(x))

#define set0(a)     memset(a,0,sizeof(a))
#define setneg(a)   memset(a,-1,sizeof(a))
#define setinf(a)   memset(a,126,sizeof(a))

#define REP(i,start,end) for (int i = start; i <=end; i++)
#define RREP(i,end,start) for (int i=end; i>=start ;i--)
#define EACH(x, a) for (auto& x: a)

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef vector<double> vd;
typedef vector<vector<LL> > matrix;
typedef vector<vector<int> > graph;

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

int add (LL var1, LL var2) {
    return ( (var1 % mod) + (var2 % mod) + mod) % mod;
}

int mul (LL var1, LL var2) {
    return (var1*var2) % mod;
}

int powm (LL x, LL y) {
    int ans = 1;
    while (y) {
        if (y & 1) {
            ans = mul(ans, x);
        }
        x = mul(x, x);
        y /= 2;
    }
    return ans;
}

int inv(LL x) {
    return powm(x, mod-2);
}

LL INF=1e9;

void solve() {
    int n;
    read(n);
    vll a(n);
    read(a);
    sort(all(a));

    LL sum = 0;
    for (int i=n-1; i>=0; i--)
        sum += i*a[i] - (n-1-i)*a[i];
    cout << sum << nl;
}

int main() {
    fast;
        solve();
}

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

int main() {
    int n, ans=0;
    cin >> n;
    for(int i = 1; i < n; i++) {
        if ((n-i) > 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename has_less>
using ordered_set =
tree<has_less,
    null_type,
    less_equal<has_less>,
    rb_tree_tag,
    tree_order_statistics_node_update>;

//    typedef tree<
//    int,
//    null_type,
//    less_equal<int>,
//    rb_tree_tag,
//    tree_order_statistics_node_update> ordered_set;

// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

# define ll long long int
#define M 1000000007
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000

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

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

                                                    //nestedcode

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

ll m[20][20];
ll dpp[1<<20];
map<ll,ll> gm;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m1,i,j,mask,a,b,fl,h,ans = 0,msk;
    cin>>n>>m1;
    for(i=0;i<m1;i++){
        cin>>a>>b;
        a--;
        b--;
        m[a][b] = 1;
        m[b][a] = 1;
    }

    for(mask=1;mask<(1<<n);mask++){
        dpp[mask] = inf;
        ll v = 0,d,sub,sub2;
        vector<ll> vec;
        for(j=0;j<n;j++){
            if((mask>>j) & 1){
                v += (1ll<<j);
                vec.pb(j);
            }
        }

        fl = 0;
        for(j=0;j<vec.size();j++){
            for(h=0;h<vec.size();h++){
                if(j == h)  continue;
                if(m[vec[h]][vec[j]] == 0){
                    fl = 1;
                    break;
                }
            }if(fl)  break;

        }
        if(fl == 0){
            dpp[v] = 1;
            continue;
        }

       for(int i = mask; i > 0; i = (i-1) & mask){
    	dpp[mask] = min(dpp[mask], dpp[i] + dpp[v ^ i]);
    }

    }
    cout<<dpp[(1<<n) - 1];

}

#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
const int M=998244353;
inline void add(re int &x,re int y){(x+=y)>=M?x-=M:x;}
inline int ksm(re int x,re int y){
	re int s=1;
	while(y){
		if(y&1)s=1ll*s*x%M;
		x=1ll*x*x%M,y>>=1;
	}
	return s;
}
int n,m,f[21][5002],fac[5002],inv[5002],s;
inline int C(re int x,re int y){return 1ll*fac[x]*inv[y]%M*inv[x-y]%M;}
signed main(){
	n=read(),m=read();
	for(re int i=fac[0]=inv[0]=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
	f[0][m]=1;
	for(re int i=0;(1<<i)<=m;++i){
		s=i;
		for(re int j=0;j<=m;++j){
			if(j%(1<<i))continue;
			if(!f[i][j])continue;
			for(re int k=0;k*(1<<i)<=j&&k<=n;k+=2)add(f[i+1][j-k*(1<<i)],1ll*f[i][j]*C(n,k)%M);
		}
	}
	printf("%d",f[s+1][0]);
}


#include<bits/stdc++.h>
using namespace std;
vector<int> G[400400];
bool vis[400400];
int ce,cv;
void dfs(int x)
{
  vis[x]=true;
  cv++;
  ce+=(int)(G[x].size());
  for(int i=0;i<(int)(G[x].size());i++)
    if(!vis[G[x][i]])
      dfs(G[x][i]);
  return ;
}
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans=0;
  for(int i=0;i<400000;i++)
    if(!vis[i])
  {
    ce=cv=0;
    dfs(i);
      ce/=2;
      ans+=min(ce,cv);
    }
  cout<<ans<<endl;
  return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;

int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};
class DisjointSet{
    public:
        vector<ll> rank,p,siz,es;

        DisjointSet(){}
        DisjointSet(ll size){
            rank.resize(size,0);
            p.resize(size,0);
            siz.resize(size,1);
            es.resize(size,0);
            rep(i,size) makeSet(i);
        }

        void makeSet(ll x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(ll x, ll y){
            return root(x) == root(y);
        }

        void unite(ll x, ll y){
            x = root(x);
            y = root(y);
            es[x]++;
            if(x == y) return;
            if(rank[x] > rank[y]){
                siz[x] += siz[y];
                es[x] += es[y];
                p[y] = x;
            }
            else{
                siz[y] += siz[x];
                es[y] += es[x];
                p[x] = y;
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
        ll root(ll x){
            if(x != p[x]){
                p[x] = root(p[x]);
            }
            return p[x];
        }

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

        ll esize(ll x){
            return es[root(x)];
        }

};

int main(){
    int n; cin >> n;
    DisjointSet uf(400000);

    rep(i,n){
        int a,b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,400001){
        if(uf.root(i) == i) ans += min(uf.size(i),uf.esize(i));
    }
    cout << ans << endl;
}


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

int main() {
int X,Y;
    bool a = false;
  cin >> X >> Y;
  if(max(X,Y)-min(X,Y) < 3){
  a = true;
  }
  if(a == false){
    cout << "No" << endl;
  }
    if(a == true){
    cout << "Yes" << endl;
  }

}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
const int MAXN=4e5+10;
const ll MOD=998244353;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
template <int _MOD> struct Mint
{
    //一个好的软件包应该是封闭的，例如，mint的所有操作都可以在软件包内部实现的
    long long v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int &_v) { return *this = Mint(_v); }
    Mint operator = (const long long &_v) { return *this = Mint(_v); }
    bool operator ! () const { return !this->v; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) const { return Mint(v+b.v); }
    Mint operator - (const Mint &b) const { return Mint(v-b.v); }
    Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) const { return Mint(b.inv()*v); }
    Mint& operator += (const Mint &b) { return *this = *this+b; }
    Mint& operator -= (const Mint &b) { return *this = *this-b; }
    Mint& operator *= (const Mint &b) { return *this = *this*b; }
    Mint& operator /= (const Mint &b) { return *this = *this/b; }
    Mint operator - () const { return Mint(-v); }
    Mint& operator ++ () { return *this += 1; }
    Mint& operator -- () { return *this -= 1; }
    Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; }
    Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const {
        if(v==0)return Mint(1);
        return pow(_MOD-2);
    }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v;mt.v=mt.v%_MOD; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;
mint factor[MAXN];
mint inv[MAXN];
void cal_factor(){factor[0]=mint(1);for(int u=1;u<MAXN;u++){factor[u]=factor[u-1]*mint(u);}}
void cal_factor_inv(){inv[0]=mint(1);inv[MAXN-1]=factor[MAXN-1].inv();for(int u=MAXN-2;u>=1;u--){inv[u]=inv[u+1]*mint(u+1);}}
void init_factor(){cal_factor();cal_factor_inv();}
mint C(ll n,ll k){if(n<k)return mint(0);return factor[n]*inv[n-k]*inv[k];}
void solve(){
    int n,m;
    cin>>n>>m;
    init_factor();
    mint ans=mint(0);
    for(ll t=1;t<=m;t++){
        ll x=t;
        mint tmp=mint(1);
        for(ll q=2;q*q<=x;q++){
            int cnt=0;
            while(x%q==0){
                x/=q;
                cnt++;
            }
            tmp*=C(cnt+n-1,cnt);
        }
        if(x>1)tmp*=mint(n);
        ans+=tmp;
    }
    cout<<ans<<"\n";
}
// #define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout << #x << "=" << x << ", ";}
#define in(x); { for (auto &to : x) cin >> to;}
#define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6 + 100;
const ll INF = 1e9;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 21;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    int was = cnt[0];
    ll ans = 0;
    vector <pll> a;
    for (int i = 1; i < n; i++) {
        int now = min(was, cnt[i]);
        int stay = was - now;
        a.pb({i,stay});
        swap(was, now);
    }
    reverse(all(a));
    for (auto to:a)
    {
        int x=min(k,(int)(to.se));
        ans+=1ll*x*to.fi;
        k-=x;
    }
    cout<<ans<<'\n';
}

int main() {
#ifdef Mip182
    freopen("a.in", "r", stdin);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int _t;
    _t = 1;
//    cin>>_t;
    while (_t--)
        solve();
#ifdef Mip182
    cout << '\n' << "Time : " << (double) (clock()) / CLOCKS_PER_SEC << '\n';
#endif
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

ll gcd(ll a, ll b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}

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

ll f(ll h) {
  if (h == 1) {
    return 1;
  } else {
    return 2 * f(h / 2) + 1;
  }
}

ll mod = 1000000007;

ll powmod(ll a, ll b) {
  ll ret = 1;
  for (int i = 0; i < b; i++) {
    ret = (ret * a) % mod;
  }
  return ret;
}

ll comb(ll n, ll k) {
  map<string, ll> memo;
  if (n == k || k == 0) {
    return 1;
  } else {
    string key = to_string(n) + to_string(k);
    if (memo.count(key) != 0) {
      return memo[key];
    } else {
      ll v = comb(n - 1, k - 1) + comb(n - 1, k);
      memo[key] = v;
      return v;
    }
  }
}

int f(int n, int k) {
  int ret = 0;

  while (n < k) {
    n *= 2;
    ret++;
  }

  return ret;
}

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

  vector<int> v(N), box(K, -1);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());

  int i = 0;
  int prev = -1;
  for (auto a : v) {
    if (prev != a) {
      i = 0;
    }

    if (box[i] + 1 == a) {
      box[i] = a;
      i++;
    }

    prev = a;
  }

  ll ans = 0;
  for (auto a : box) {
    if (a != -1) {
      ans += (a + 1);
    }
  }
  cout << ans << endl;
}


#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 998244353;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

class mint{
public:
    ll x;
    constexpr mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= MOD;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res += a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res -= a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res *= a;
    }
    constexpr mint pow(ll t) const{
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    constexpr mint inv() const{
        return pow(MOD - 2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, mint& a) {return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}

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

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

    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    sort(all(a));

    mint ans = 0, sum = 0;
    for(int i=n-1; i>=0; i--){
        ans += (sum + a[i]) * a[i];
        sum = sum * 2 + a[i];
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	char s[n];
	for (int i=0;i<n;i++){
		cin >> s[i];
	}
	string res;
	res="";
	for(int i=0;i<n;i++){
		res.push_back(s[i]);
		if(res.size()>=3){
			if(res.at(res.size()-3)=='f' && res.at(res.size()-2)=='o' && res.at(res.size()-1)=='x'){
				res.erase(res.size()-3);
			}
		}
		//cout << res << endl;
	}
	cout << res.size() <<endl;
	return 0;
 }


// Bismillahir Rahmanir Rahim
//============================
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define endl        "\n"
#define infL        LLONG_MAX
#define infI        INT_MAX
#define pb          push_back
#define fo(i,a,b)   for(int i=a;i<b;i++)
#define fo2(i,a,b)  for(int i=a;i<=b;i++)
#define rfo(i,a,b)  for(int i=a; i>=b;i--)
#define precise(x,y)cout<<fixed<<setprecision(y)<<x<<endl;
#define MAX         100010
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0
#define debug       cout<<"\nDebug\n";
#define debug2      cout<<"\nDebug2\n";
#define PEREGRINE_FALCON {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

typedef pair<ll,ll>PII;
double epsilon = 0.0000001f;
ll mod=1e9+7;
double Pi =acos(-1);

void print(vector<ll>V)
{
      cout<<"\n---------------Vector checking start-------------------\n";
      ll sz=V.size();
      fo(i,0,sz){cout<<V[i]<<"  ";}
      cout<<"\n----------------Vector checking end--------------------\n";
}

void print(ll arr[], ll n)
{
      cout<<"\n---------------Array checking start-------------------\n";
      fo(i,0,n){cout<<arr[i]<<" ";}
      cout<<"\n----------------Array checking end--------------------\n";
}

struct strct{
      ll a,b;
};

bool cmp(strct A, strct B)
{
      return A.a<B.a;
}

int main()
{
      PEREGRINE_FALCON
      //freopen("inputNew.txt", "r", stdin);

      ll testCase=1;
      //cin>>testCase;
      while(testCase--){
            ll n,m,k,x,y,z,a,b,c,d,mn,mx,temp,cnt,ans,sum,sz,len;
            cin>>n>>k;

            struct strct s[n];
            fo(i,0,n){cin>>s[i].a>>s[i].b;}
            sort(s,s+n,cmp);

            cnt=k;
            for(int i=0; i<n; i++){
                  if(s[i].a > cnt) break;
                  cnt+=s[i].b;
            }
            cout<<cnt<<endl;

      }

      bye;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,i,j,num,sum=0,x,y;
    cin>>n>>k;
     vector< pair <long long,long long> > vect;
   for (int i=0; i<n; i++){
        cin>>x>>y;
        vect.push_back( make_pair(x,y) );
   }
    sort(vect.begin(), vect.end());
  for(i=0;i<n;i++)
  {
      if(vect[i].first>k)
      break;
        k=k+vect[i].second;
  }
  cout<<k<<endl;
}