#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n, m, sum = 0;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> n >> k >> m;
        rep(p, 0, n - 1)
        {
            cin >> i;
            sum += i;
        }

        ll mi = m * n - sum;
        if (mi > k)
            cout << "-1";
        else
            cout << max(0LL, mi);
    }

    return 0;
}

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

int main() {

  int N,K,M; cin >> N >> K >> M;

  vector<int> v(N-1);
  int A = 0;
  for(int i = 0; i< N-1; i++){
    cin >> v.at(i);
    A += v.at(i);
  }

  if(K >= N * M - A){
    cout << max(0,N * M - A) << endl;
  }else{
    cout << "-1" << endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef long long ll;
typedef long double ld;
typedef vector<lli> vlli;
typedef vector<li> vli;
typedef vector<int> vi;
typedef vector<ld> vld;
#define all(x) (x).begin(),(x).end()
lli MOD=1e9+7;

/*vlli fun(lli q)
{
    vlli ret;
    for(lli i = 2; i*i <= q; i++)
    {
        if( q % i==0)
        {
            if(i<=q/i)
            {
                ret.push_back(i);
                break;
            }
            else
                break;
        }

    }
    sort(ret.rbegin(),ret.rend());

    return ret;
}*/
/*int prime(int a)
{
    for(lli i=2; i<=sqrt(a); i++)
    {
        if(a%i==0)
            return 0;
    }
    return 1;
}*/
/*
lli fac[300001] ;

lli power(lli x, lli y, lli MOD)
{
    if(y == 0) return 1 ;
    lli p = power(x, y/2, MOD) % MOD ;
    p = (p * p) % MOD ;
    return (!(y & 1))? p : (x * p) % MOD ;
}
lli modInverse(lli a, lli MOD)
{
    return power(a, MOD - 2, MOD) ;
}
lli nCr(lli n,lli r)
{
    if(n < r) return 0 ;
    else if(r == 0) return 1 ;
    lli ret{fac[n]%MOD} ;
    ret *= modInverse(fac[r], MOD) ;
    ret %= MOD ;
    ret *= modInverse(fac[n-r], MOD) ;
    ret %= MOD ;
    return ret ;
}*/
/*lli n=50000000;/range of number;
vlli c;
void sieve()
{
    vector<bool>is_prime(n+1,true);
    for(lli i=2; i<=n; i++)
    {
        if(is_prime[i]==true)
        {
            is_prime[i]=false;
            c.push_back(i);

            for(lli j=i*i; j<=n; j+=i)
            {
                is_prime[j]=false;

            }
        }
    }
}
*/
int main()
{
    cin.tie(nullptr)->sync_with_stdio(false) ;
    lli t{1};
    //cin >> t;
    cout<<setprecision(15);
    /*fac[0] = 1;
    for(lli i{1} ; i <= 300000 ; i++)
        fac[i] = (fac[i-1]*i)%MOD ;*/
    while(t--)
    {
        lli a{},b{};
        cin >> a >> b;
        lli sum{};
        for(lli i = 1; i<a; i++)
        {
            cout << i<<" ";
            sum+=i;
        }
        cout <<  100000000<<" ";
        sum+=100000000;
        for(lli i=1; i <=b-1; i++)
        {
            cout << -i << " ";
            sum-=(i);
        }
        cout << (-sum);
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int ans[3000];
int a,b;
void work(){
	int tot=0;

	if(a==b){
		for(int i=1;i<=a;i++)ans[++tot]=i,ans[++tot]=-1*i;
		return ;
	}
	if(a>b){
		int	fro=1001,sum=0;
		while(a>b){
			ans[++tot]=fro++;
			sum+=ans[tot];
			a--;
		}
		ans[++tot]=fro++;
		sum+=ans[tot];
		a--;
		ans[++tot]=-1*sum;
		b--;
	}
	else{
		int	en=-1001,sum=0;
		while(b>a){
			ans[++tot]=en--;
			sum+=ans[tot];
			b--;
		}
		ans[++tot]=en--;
		sum+=ans[tot];
		b--;
		ans[++tot]=-1*sum;
		a--;
	}
	for(int i=1;i<=a;i++)ans[++tot]=i,ans[++tot]=-1*i;
}
int main(){

	scanf("%d%d",&a,&b);
	int len=a+b;
	work();
	for(int i=1;i<len;i++)printf("%d ",ans[i]);
		cout<<ans[len]<<endl;
	return 0;
}


#include<iostream>
#include<math.h>

using namespace std;

int main() {
  long s, p;
  cin >> s >> p;

  long limit = sqrt(p);
  for(long n = 1; n <= limit; ++n) {
    if(p % n == 0 && n + (p / n) == s) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define                          ll                          long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long binpow(long long base,long long power)
{
        long long result=1;
        while (power>0)
        {
                if (power%2==1)
                        result = (result*base);
                base = (base*base);
                power/=2;
        }
        return result;
}
#define                          in(x)                       scanf("%lld",&x)
#define                          in2(x,y)                    scanf("%lld %lld",&x,&y)
#define                          in3(x,y,z)                  scanf("%lld %lld %lld",&x,&y,&z)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          inf                         1e18
#define                          neg                         -1e18
#define                          mx                          2111111
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define                          fi                          first
#define                          si                          second
#define                          ce                          cout<<endl
#define                          pb                          push_back
#define                          vc(x)                       x.begin(),x.end()
#define                          pb                          push_back
#define                          pii                          pair<ll,ll>
#define                          debug                       printf("ok\n");
#define                          pvg                         pii, vector<pii>, greater<pii>;
#define                          mod                         1000000007

int main(){
    //freopen("test.txt","r",stdin);
    //fast
    ll t;

        ll i,p,j,ans=0,sum=0,s=0,n,m;

        in2(p,s);
          bool f=false;
    for(i=1;i*i<=s;i++)
    {
        if(s%i==0)
        {
            if(i+(s/i)==p) {f=true;break;}

        }
    }

    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

 }


#include<bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;

int main () {
    FASTIO;
    int n,m;
        cin>>n>>m;
        int ans=0;
        if(n==m) {
            cout<<m;
        }
        else {
            cout<<3-n-m;
        }

}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a * a + b * b < c * c) cout << "Yes";
  else cout << "No";
}

#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SquareInequality | diff SquareInequality.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SquareInequality.cpp && ./a.out

/*

 4/24/2021

 5:00-

 */

int A,B,C;

bool solve() {
  return A*A+B*B<C*C;
}

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

  cin>>A>>B>>C;
  cout<<(solve()?"Yes":"No")<<endl;

  return 0;
}


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

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

int main(){

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

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

    int n;
    cin>>n;

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

    ll ans=LLONG_MAX;

    ll tot = 1<<(15);

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

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

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

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

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

}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <sstream>

#define fileio                                                  \
    freopen("C:\\Users\\PRISM17\\Desktop\\in.txt", "r", stdin); \
    freopen("C:\\Users\\PRISM17\\Desktop\\out.txt", "w", stdout);
#define fastio                   \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define dbg(x) cout << #x << " : " << x << endl;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define mid (st[id].l + st[id].r >> 1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;

int prime[60], v[60], tot;
ll ans = -1;
int a[60];
int n;
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
void dfs(int cur, ll prod) {
    if (cur == tot + 1) {
        int f = true;
        for (int i = 1; i <= n; i++) {
            if (gcd(a[i], prod) == 1) {
                f = false;
                break;
            }
        }
        if (f) {
            if (ans == -1) ans = prod;
            else ans = min(ans, prod);
        }
        return;
    }
    dfs(cur + 1, prod * prime[cur]);
    dfs(cur + 1, prod);
}

int main() {
    for (int i = 2; i <= 50; i++) {
        if (!v[i]) {
            prime[++tot] = i;
            for (int j = i * i; j <= 50; j += i) {
                v[j] = true;
            }
        }
    }
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    dfs(1, 1);
    cout << ans << endl;
}


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

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

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

  ll A,B;
  cin>>A>>B;

  vector<ll> v;
  for(ll i=A;i<=B;i++) v.push_back(i);
  int V=v.size();

  vector<vector<int>> g(V);
  rep(i,V){
      for(int j=i+1;j<V;j++){
          if(gcd(v[i],v[j])!=1){
              g[i].push_back(j);
              g[j].push_back(i);
          }
      }
  }

  ll ast=0,bst=0;
  rep(k,V){
      if(k<60) ast+=(1ll<<k);
      else bst+=(1ll<<(k-60));
  }

  map<tuple<int,ll,ll>,ll> dp;
  auto solve = [&](auto &&solve,int now,ll ast,ll bst)->ll{
      if(dp.count(mkt(now,ast,bst))) return dp[mkt(now,ast,bst)];
      if(now==V) return 1;

      ll res=0;
      {
          ll nexast=ast,nexbst=bst;
          if(now<60&&((1ll<<now)&ast)) nexast^=(1ll<<now);
          if(now>=60&&((1ll<<(now-60))&bst)) nexbst^=(1ll<<(now-60));
          res+=solve(solve,now+1,nexast,nexbst);
      }
      //res+=solve(solve,now+1,ast,bst);
      if(now<60&&((1ll<<now)&ast)){
        ll nexast=ast,nexbst=bst;
        nexast^=(1ll<<now);
        for(auto j:g[now]){
            if(j<60&&(ast&(1ll<<j))) nexast^=(1ll<<j);
            if(j>=60&&(bst&(1ll<<(j-60)))) nexbst^=(1ll<<(j-60));
        }
        res+=solve(solve,now+1,nexast,nexbst);
      }
      if(now>=60&&((1ll<<(now-60))&bst)){
        ll nexast=ast,nexbst=bst;
        nexbst^=(1ll<<(now-60));
        for(auto j:g[now]){
            if(j<60&&(ast&(1ll<<j))) nexast^=(1ll<<j);
            if(j>=60&&(bst&(1ll<<(j-60)))) nexbst^=(1ll<<(j-60));
        }
        res+=solve(solve,now+1,nexast,nexbst);
      }
      return dp[mkt(now,ast,bst)]=res;
  };

  ll ans=solve(solve,0,ast,bst);
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

int cnt[M], p[M];

void solve()
{
    int n, j = 0;
    cin>>n;
    f(i, 0, n)
    {
    	cin>>p[i];
    	cnt[p[i]]++;
    	while(cnt[j]) j++;
    	cout<<j<<endl;
    }
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <class T = ll> using V = vector<T>;
#define loop(n) while(n--)
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define all(v) (v).begin(), (v).end()
#define LL(n) int n;cin >> n

int main()
{
    LL(n);
    V<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    ll MIN = accumulate(all(a), 0);
    if(MIN%2==1) MIN = MIN/2 + 1;
    else MIN = MIN/2;
    int K = 100000;
    vector<vector<bool>> dp(n + 1, vector<bool>(K, false));
    // 初期化
    for (int i = 0; i <= n; i++) {
        dp[i][0] = true;
    }
    // 更新
    for (int i = 0; i < n; i++) {
        for (int k = 0; k <= K; k++) {
            if (k - a[i] >= 0) dp[i + 1][k] = dp[i + 1][k] | dp[i][k - a[i]];
            dp[i + 1][k] = dp[i + 1][k] | dp[i][k];
        }
    }

    rep(i, 100000){
        if(dp[n][i+MIN]) {
            cout << i+MIN << endl;
            break;
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<ll> S(N+1);
    for (int i = 0; i < N; i++) S[i+1] = S[i] + A[i];
    ll ans = 0;
    for (int i = 1; i < N; i++) ans += A[i] * i - S[i];
    cout << ans << endl;
    return 0;
}

// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

/*

*/

void run_case() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        res += a[i] * b[i];
    }

    cout << (res == 0 ? "Yes" : "No") << '\n';
}

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

    int T = 1;
    // cin >> T;
    for (int t = 1; t <= T; t++) {
        // cout << "Case #" << t << ": ";
        run_case();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef long double ld; typedef pair<lint, lint> plint; typedef pair<ld, ld> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;++i)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;--i)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
#define fi first
#define se second
struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
template<class T> auto add = [](T a, T b) -> T { return a + b; };
template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); };
template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); };
template<class T> using V = vector<T>;
using Vl = V<lint>; using VVl = V<Vl>;
template< typename T > ostream& operator<<(ostream& os, const vector< T >& v) {
    for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : "");
    return os;
}
template< typename T >istream& operator>>(istream& is, vector< T >& v) {
    for (T& in : v) is >> in;
    return is;
}
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; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
lint e_dist(plint a, plint b) { return abs(a.fi - b.fi) * abs(a.fi - b.fi) + abs(a.se - b.se) * abs(a.se - b.se); }
lint m_dist(plint a, plint b) { return abs(a.fi - b.fi) + abs(a.se - b.se); }
void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); }
const lint MOD1000000007 = 1000000007, MOD998244353 = 998244353, INF = 2e18;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
bool YN(bool flag) { cout << (flag ? "YES" : "NO"); return flag; } bool yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; return flag; }
struct Edge {
    lint from, to;
    lint cost;
    lint idx;
    Edge() {

    }
    Edge(lint u, lint v, lint c, lint i) {
        cost = c;
        from = u;
        to = v;
        idx = i;
    }
    bool operator<(const Edge& e) const {
        return cost < e.cost;
    }
};
struct WeightedEdge {
    lint to;
    lint cost;
    WeightedEdge(lint v, lint c = 1) {
        to = v;
        cost = c;
    }
    bool operator<(const WeightedEdge& e) const {
        return cost < e.cost;
    }
};
using WeightedGraph = V<V<WeightedEdge>>;
typedef pair<plint, lint> tlint;
typedef pair<plint, plint> qlint;
typedef pair<char, lint> valchar;

lint N, X;
int main() {
    cin >> N >> X;
    Vl arr(N);
    cin >> arr;
    lint minv = INF;
    FOR(m, 1, N + 1) {
        V<VVl> dp(N + 1, VVl(N + 1, Vl(N + 1, -1)));
        dp[0][0][0] = 0;
        REP(i, N) {
            REP(j, N + 1) {
                REP(k, N) {
                    if (dp[i][j][k] == -1) continue;
                    chmax(dp[i + 1][j + 1][(dp[i][j][k] + arr[i]) % (m)], dp[i][j][k] + arr[i]);
                    chmax(dp[i + 1][j][k], dp[i][j][k]);
                }
            }
        }
        REP(j, N + 1) {
            if (dp[N][m][j] == -1) continue;
            if ((X - dp[N][m][j]) % m != 0) continue;
            chmin(minv, (X - dp[N][m][j]) / m);
        }
    }

    cout << minv << endk;
}

#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define debug(typ...) fprintf(stderr, typ)
using namespace std;
int fastin() {
  reg int x = 0, ch = getchar(), f = 0;
  while(!isdigit(ch)) (ch == '-') && (f = 1), ch = getchar();
  while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int MAXN = 110;
int n, ma[MAXN << 1], dp[MAXN][MAXN];
int match(reg int d, reg int u) {
  int fl = 1;
  if(ma[d]) {
    if(ma[d] <= n * 2) fl &= (ma[d] == u);
    else fl &= (ma[d] == n * 2 + 1);
  }
  if(ma[u]) {
    if(ma[u] <= n * 2) fl &= (ma[u] == d);
    else fl &= (ma[u] == n * 2 + 2);
  }
  if(ma[d] == n * 2 + 1 && ma[u] == n * 2 + 2) fl = 0;
  return fl;
}
int dfs(reg int l, reg int r) {
  if(~dp[l][r]) return dp[l][r];
  int len = r - l + 1, fl = 1;
  for(reg int i = l; i <= r && fl; ++i) fl &= match(l + i - 1, l + i + len - 1);
  if(fl) return dp[l][r] = 1;
  for(reg int i = l; i < r && !fl; ++i) fl |= dfs(l, i) && dfs(i + 1, r);
  return dp[l][r] = fl;
}
void work() {
  n = fastin();
  bool flag = 1;
  for(reg int i = 1; i <= n && flag; ++i) {
    int a = fastin(), b = fastin();
    if(a != -1 && b != -1 && a >= b) flag = 0;
    else {
      if(a == -1 && b == -1) continue;
      else if(a == -1) {
        if(ma[b]) flag = 0;
        else ma[b] = n * 2 + 2;
      } else if(b == -1) {
        if(ma[a]) flag = 0;
        else ma[a] = n * 2 + 1;
      } else {
        if(ma[a] || ma[b]) flag = 0;
        else ma[a] = b, ma[b] = a;
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  if(!flag) puts("No");
  else puts(dfs(1, n) ? "Yes" : "No");
}
signed main() {
  int _ = 1;
  // _ = fastin();
  while(_--) {
    work();
  }
  return 0;
}


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

using namespace std;

#define int long long
#define fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define geometry cout.setf(ios::fixed); cout.precision(15);
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;

const ll INF = 2e18 + 100;
const int MOD1 = 998244353;
const int MOD = 1e9 + 7;
const int N = 135000;
const int SIZE = 30100;
const int LOG = 21;
const int K = 18;

vector<vector<int> > gr;
vector<vector<int> > dist;
vector<int> c;
int n, m, k;

void bfs(int st, int ind) {
    queue<int> q;
    vector<int> d(n, INF);

    d[st] = 0;
    q.push(st);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : gr[v]) {
            if (d[u] == INF) {
                d[u] = d[v] + 1;
                q.push(u);
            }
        }
    }
    for (int i = 0; i < k; i++) {
        dist[ind][i] = d[c[i]];
    }
}

int dp[K][N];

signed main() {
#ifdef hedgehog
    freopen("A.in", "r", stdin);
#endif // parasha
    fast;
    cin >> n >> m;
    gr.resize(n);
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        v--; u--;
        gr[v].push_back(u);
        gr[u].push_back(v);
    }
    cin >> k;
    c.resize(k);
    for (int &i : c) cin >> i;
    for (int &i : c) i--;
    dist.resize(k, vector<int>(k));
    for (int i = 0; i < k; i++) {
        bfs(c[i], i);
    }
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = INF;
        }
    }
    for (int i = 0; i < k; i++) {
        dp[i][1 << i] = 1;
    }
    for (int mask = 1; mask < (1 << k); mask++) {
        for (int v = 0; v < k; v++) {
            if (dp[v][mask] == INF) continue;
            //cout << v << ' ' << mask << '\n';
            for (int u = 0; u < k; u++) {
                if (((mask >> u) & 1) == 0) {
                    //cout << v << ' ' << u << ' ' << dist[v][u] << '\n';
                    dp[u][mask + (1 << u)] = min(dp[u][mask + (1 << u)], dp[v][mask] + dist[v][u]);
                }
            }
        }
    }
    int ans = INF;
    for (int i = 0; i < k; i++) {
        ans = min(ans, dp[i][(1 << k) - 1]);
    }
    if (ans == INF) cout << -1 << '\n';
    else cout << ans << '\n';

}

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

vector <int> dy = {0, 1, 0, -1};
vector <int> dx = {1, 0, -1, 0};

const int INF = 1000000000;
const ll INFLL = 100000000000000000;

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

    vector <vector<int>> G(n);
    rep(i, m){
        int a, b; cin >> a >> b;
        a --;
        b --;
        G.at(a).push_back(b);
        G.at(b).push_back(a);
    }

    int k; cin >> k;
    vector <int> is_v(n);
    vector <int> is_zip(n, -1);
    rep(i, k){
        int c; cin >> c;
        c --;
        is_v.at(c) = 1;
        is_zip.at(c) = i;
    }

    //各i,jについてc_i ~ c_jの最短距離を求める
    vector <vector <int>> dist(k, vector<int>(k, INF));
    for(int i = 0; i < n; i ++){
        if(is_v.at(i) == 0) continue;
        deque <pair<int, int>> d; d.push_back(make_pair(i, 0));
        vector <int> seen(n, -1); seen.at(i) = 1;
        while(d.size()){
            auto p = d.front();
            d.pop_front();
            int now = p.first;
            int cost = p.second;
            if(is_v.at(now) != 0){
                dist.at(is_zip.at(i)).at(is_zip.at(now)) = min(dist.at(is_zip.at(i)).at(is_zip.at(now)), cost);
            }
            for(auto next: G.at(now)){
                if(seen.at(next) != -1) continue;
                int next_cost = cost + 1;
                seen.at(next) = 1;
                d.push_back(make_pair(next, next_cost));
            }
        }
    }

    // for(int i = 0; i < k; i ++){
    //     rep(j, k){
    //         //dist.at(i).at(j) ++;
    //         cout << dist.at(i).at(j) << "  ";
    //     }
    //     cout << endl;
    // }

    //求めた距離から巡回セールスマンを行う
    vector <vector <int>> dp((1 << k), vector<int>(k, INF));
    rep(i, k){
        dp.at((1 << i)).at(i) = 1;
    }
    rep(s, (1 << k)){
        if(s == 0) continue;
        rep(i, k){
            if(!((s >> i) & 1)) continue;
            int tmp = INF;
            rep(j, k){
                tmp = min(tmp, dp.at(s ^ (1 << i)).at(j) + dist.at(j).at(i));
            }
            //cout << tmp << endl;
            dp.at(s).at(i) = min(dp.at(s).at(i), tmp);
        }
    }

    int ans = INF;
    for(auto tmp: dp.at((1 << k) - 1)) ans = min(ans, tmp);
    if(ans == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;

// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('joshima', 'tokio', 'nara', 'o',1970);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('kokubun', 'tokio', 'tokyo', 'o',1974);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('matsuoka', 'tokio', 'hokkaido', 'a',1977);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('nagase', 'tokio', 'kanagawa', 'o',1978);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('ohno', 'arashi', 'tokyo', 'a',1980);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('sakurai', 'arashi', 'tokyo', 'a',1982);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('aiba', 'arashi', 'chiba', 'ab',1982);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('ninomiya', 'arashi', 'tokyo', 'a',1983);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('matsumoto', 'arashi', 'tokyo', 'a',1983);

}


#include <iostream>
#include <vector>
#include <cstring>

#define int long long
using namespace std;
const int maxn = 2e5 + 1;
const int mod = 1e9 + 7;
int N;
struct edge{
    int to, w;
};
vector<edge > G[maxn];
int dis[maxn];

void dfs(int u, int f) {
    for(auto& e :G[u]) {
        if(e.to == f) continue;
        dis[e.to] = dis[u] ^ e.w;
        dfs(e.to, u);
    }
}

void init() {
    cin >> N;
    for(int i = 1; i < N; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].push_back(edge{v, w});
        G[v].push_back(edge{u, w});
    }
}

signed main() {
    init();
    dfs(1, 0);
    int ans = 0;
    for(int c = 0; c < 60; ++c) {
        int cnt[2] = {0, 0};
        for(int i = 1; i <= N; ++i) {
            cnt[(dis[i] >> c) & 1] ++;
        }
        ans += ((1ll << c) % mod) * (cnt[0] * cnt[1] % mod);
        ans %= mod;
    }
    cout << ans;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
ll n,q;
vector<int> g[200010];
int a[200010],b[200010];
vector <int> depth;
void dfs(int a,int d){
    depth[a]=d;
    for(int i :g[a]){
        if(depth[i]==-1)dfs(i,d+1);
    }
}

ll ans[200010];
int main(){
    cin >> n;
    depth.resize(n,-1);
    rep(i,n-1){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        g[a[i]].emplace_back(b[i]);
        g[b[i]].emplace_back(a[i]);
    }
    dfs(0,0);
    cin >> q;
    rep(i,q){
        ll t,e,x;
        cin >> t >> e >> x;
        e--;
        int k=a[e],l=b[e];
        if(t==2)swap(k,l);
        if(depth[k]>depth[l]){
            ans[k]+=x;
        }
        else{
            ans[0]+=x;
            ans[l]-=x;
        }
    }
    vector <ll> q;
    q.push_back(0);
    while(!q.empty()){
        ll cnt=q.back();
        q.pop_back();
        for(int i:g[cnt]){
            if(depth[i]>depth[cnt]){
                ans[i]+=ans[cnt];
                q.push_back(i);
            }
        }
    }
    rep(i,n)cout << ans[i] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        map<int, int> cnt;
        forn(i, n) {
            int x;
            cin >> x;
            ++cnt[x];
        }

        bool first;
        if (n % 2 == 1) first = false;
        else {
            first = false;
            for (auto w: cnt) first |= w.se % 2;
        }
        cout << (first ? "First" : "Second") << '\n';
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

#include<cstdio>
#include<algorithm>
#include<ctype.h>
#define int long long

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int Mod=1e9+7,N=3005;

int n,dp[N][N],sum[N],ans;

signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		int x=read();
		sum[i]=sum[i-1]+x;
	}
	dp[1][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=n+1;j>=2;j--)
		{
			dp[j][sum[i]%j]=(dp[j][sum[i]%j]+dp[j-1][sum[i]%(j-1)])%Mod;
			if(i==n)
			{
				ans=(ans+dp[j-1][sum[i]%(j-1)])%Mod;
			}
		}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    vi a(4);
    rep(i,4) cin>>a[i];
    sort(all(a));
    yn(a[0]+a[3]==a[1]+a[2] || a[0]+a[1]+a[2]==a[3]);
}

/*
    Author : Ritesh Singh
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
#define lct long long int t;cin>>t;while(t--)
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define el '\n'
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;

typedef tree<string, null_type, less<string>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

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

    ll a[4];
    rep(i,0,4)
        cin>>a[i];
    sort(a,a+4);
    if(((a[0]+a[3]) == (a[1]+a[2])) or ((a[0]+a[1]+a[2])==a[3]))
        cout<<"Yes";
    else
        cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;
int N;
long long a;
int t;
int Q;
long long x;
long long mi=0x3f3f3f3f3f3f3f3f;
long long ma=0xcfcfcfcfcfcfcfcf;
long long add;
int main()
{
    scanf("%d",&N);
    while(N--)
    {
        scanf("%lld %d",&a,&t);
        if(t==2)
        {
            ma=max(ma,a);
            mi=max(mi,a);
            continue;
        }
        if(t==3)
        {
            ma=min(ma,a);
            mi=min(mi,a);
            continue;
        }
        mi+=a;
        ma+=a;
        add+=a;
    }
    scanf("%d",&Q);
    while(Q--)
    {
        scanf("%lld",&x);
        printf("%lld ",max(min(mi,x+add),ma));
    }
    printf("\n");
    return 0;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x) cout << (_x) << '\n'; return;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) {}
#endif
#define endl "\n"
template <typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);

//.data

//.code
void SolveTask() {
    int n;
    cin >> n;
    vector<ll> arr(n);
    vector<ll> trr(n);
    loop(n) {
        cin >> arr[i] >> trr[i];
    }
    ll sum = 0;
    vector<pair<ll, ll>> vec;
    for (int i = 0; i < n; ++i) {
        if (trr[i] == 1) {
            sum += arr[i];
        } else {
            arr[i] -= sum;
            if (vec.empty() || vec.back().second != trr[i]) {
                vec.emplace_back(arr[i], trr[i]);
            } else {
                if (trr[i] == 2) {
                    vec.back().first = max(vec.back().first, arr[i]);
                } else {
                    vec.back().first = min(vec.back().first, arr[i]);
                }
            }
        }
    }
    ll lo = LLONG_MAX;
    ll hi = LLONG_MIN;
    int j = -1;
    for (int i = sz(vec) - 1; i >= 0; --i) {
        if (vec[i].second == 2) {
            hi = max(hi, vec[i].first);
        } else {
            lo = min(lo, vec[i].first);
        }
        if (lo <= hi) {
            j = i + 1;
            break;
        }
    }
    ll ans = -1;
    if (j != -1) {
        ans = vec[j].first;
        for (int i = j + 1; i < sz(vec); ++i) {
            if (vec[i].second == 2) {
                ans = max(ans, vec[i].first);
            } else {
                ans = min(ans, vec[i].first);
            }
        }
    }
    int q;
    cin >> q;
    loop(q) {
        ll x;
        cin >> x;
        if (j == -1) {
            cout << max(hi, min(lo, x)) + sum << endl;
        } else {
            cout << ans + sum << endl;
        }
    }
}

int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin("input.txt", std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int test_cases = 1;
    // cin >> test_cases;
    for (int yt = 1; yt <= test_cases; ++yt) {
        SolveTask();
    }
#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  int num = 0;
  int ans = 0;
  int hanko = INF;
  vector<int> an(m);
  for(int i=0; i<m; ++i) cin >> an[i];
  sort(an.begin(),an.end());
  for(int i=0; i<=m; ++i){
    int ai;
    if(i != m) ai = an[i];
    else ai = n +1;
    int nhanko = ai -(i? an[i-1]:0) -1;
    if(nhanko != 0) hanko = min(hanko, nhanko);
  }
  //cout << "hanko:" << hanko << endl;
  for(int i=0; i<=m; ++i){
    int ai;
    if(i != m) ai = an[i];
    else ai = n +1;
    ans += (ai -(i? an[i-1]:0) +hanko -2) /hanko;
    //cout << i << ":" << ans << endl;
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix)
int main()
{
   //cp();
   de(n);
   de(m);
   ll a[m];
   for(ll i=0;i<m;i++)
   cin>>a[i];
   sort(a,a+m);
   vector<ll>ans;
   if(m==0)
   cout<<1;
   else
   {
   if(a[0]-1!=0)
           ans.push_back(a[0]-1);
   for(ll i=1;i<m;i++)
   {
       if(i>0)
       {
           if(a[i]-a[i-1]-1!=0)
           ans.push_back(a[i]-a[i-1]-1);
       }
   }
   if(n-a[m-1]!=0)
   ans.push_back(n-a[m-1]);
   if(ans.size()==0)
   cout<<"0";
   else
   {
   sort(ans.begin(),ans.end());
    ll d=ans[0];
    ll an=0;
    ll ht=ans.size();
    for(ll i=0;i<ht;i++)
    {
        an+=(ans[i]/d);
        if(ans[i]%d!=0)
        an++;
    }
    cout<<an;
   }
   }
}


#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll n = s.size();
  reverse(ALL(s));
  vi cnt(33);
  ll ans = 0;
  s.pb('!');
  s.pb('#');
  for(int i=0;i<=n-2;i++){
    //   cout<<i<<" "<<i+1<<" "<<i+2<<endl;
    //cout<<s[i]<<" "<<s[i+1]<<" "<<s[i+2]<<endl;
    if(s[i+1] == s[i+2] && s[i] != s[i+2]){
      //cout<<i+1<<" "<<cnt[s[i+1]-'a']<<endl;
      ans += i+1-cnt[s[i+1]-'a'];
      for(int j=0;j<26;j++){
	cnt[j] = 0;
      }
      cnt[s[i+1]-'a'] = i+3;
      i++;
      //cout<<s[i+1]<<" "<<s[i+1]<<" "<<s[i+2]<<endl;
      if(!(s[i+2] == s[i+3] && s[i+1] != s[i+3]))i++;
    }else{
      cnt[s[i]-'a']++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

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


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int N = (int)(2e5) + 7;

ll a, b, c, d;

int main() {

    // freopen("in.in", "r", stdin);
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if (c * d - b <= 0) puts("-1");
    else {
        ll x = c * d - b;
        printf("%lld\n", (a + x - 1) / x);
    }

    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll count=0;
    ll cyan=a;
    ll red=0;

    while(cyan>red)
    {
        if(count>100000)
        {
            cout<<-1<<endl;
            return 0;
        }
        cyan+=b;
        red+=c;
        count++;
        if(cyan<=red*d)
        break;
    }
    cout<<count<<endl;

}


#include<bits/stdc++.h>

#define EB emplace_back
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const int N = 2e5 + 10;

map < int, int > mp[N];

struct ufds{
  vector < int > par, len;
  ufds(int n){
    par.resize(n);
    len.resize(n, 1);
    for(int i = 0; i < n; i++){
      par[i] = i;
    }
  }

  int find(int u){
    if(u == par[u]){
      return u;
    }
    return par[u] = find(par[u]);
  }

  void join(int u, int v){
    u = find(u);
    v = find(v);
    if(u == v){
      return;
    }
    if(len[u] < len[v]){
      swap(u, v);
    }
    len[u] += len[v];
    par[v] = u;
    for(auto x : mp[v]){
      mp[u][x.first] += x.second;
    }
  }

  void clear(){
    par.clear(), len.clear();
  }
};

void test_case(){
  int n, qq; cin >> n >> qq;
  int A[n];
  for(int i = 0; i < n; i++){
    cin >> A[i];
    A[i]--;
    mp[i][A[i]]++;
  }
  ufds dsu(n);
  while(qq--){
    int type, a, b; cin >> type >> a >> b;
    type--, a--, b--;
    if(!type){
      dsu.join(a, b);
    }
    else{
      cout << mp[dsu.find(a)][b] << endl;
    }
  }
}

int32_t main(){
  IOS;
  int tt = 1;
  //cin >> tte;
  while(tt--){
    test_case();
    //cout << endl;
  }
  return 0;
}

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=4e5+10;
int n,m,cnt;
int used[maxn];
struct sb{
	int now,pre,to,va;
}e[maxn*3];
inline void add(int a,int b,int c){e[++cnt].pre=e[a].now;e[cnt].va=c;e[cnt].to=b;e[a].now=cnt;}
void dfs(int u){
	for(int i=e[u].now;i;i=e[i].pre){
		int v=e[i].to,va=e[i].va;
		if(!used[v]){
			if(used[u]==va){used[v]=(va+1)%(n+1);}
			else{used[v]=va;}
			dfs(v);
		}
	}
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1,x,y,c;i<=m;i++){
    	scanf("%d%d%d",&x,&y,&c);
    	add(x,y,c);add(y,x,c);
	}
	used[1]=1;
	dfs(1);
	bool flag=false;
	for(int i=1;i<=n;i++){
		if(!used[i]){
			puts("No");
			flag=true;break;
		}
	}
	if(!flag){for(int i=1;i<=n;i++){printf("%d\n",used[i]);}}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define Laylo cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
#define lli long long int
#define ll long long
int main() {
    Laylo
    int x;
    cin >> x;
    cout << ((x < 0) ? 0 : x) << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s;
	cin>>s;
	if(s%100==0)
	{
		if(s<=10) cout<<0;
		else if(s<=100) cout<<s/10;
		else if(s<=3000) cout<<s/100;
	}
	else
	{
		if(s<=10) cout<<1;
		else if(s<=100) cout<<s/10+1;
		else if(s<=3000) cout<<s/100+1;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <array>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
#include <valarray>
#include <bitset>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

std::tuple<int, int, int, int> input()
{
	int si, sj, ti, tj;
	cin >> si >> sj >> ti >> tj;
	return std::make_tuple(si, sj, ti, tj);
}
const int H = 30;
const int W = 30;
int ch[H][W];
int cw[H][W];

inline int cost(int sh, int sw, int th, int tw)
{
	if(sh == th)
	{
		if(sw > tw)
			std::swap(sw, tw);
		return cw[sh][sw];
	}
	else
	{
		if(sh > th)
			std::swap(sh, sw);
		return ch[sh][sw];
	}
}
void solve()
{
	auto [sh, sw, th, tw] = input();
	using T = std::tuple<int, int, int>;
	std::priority_queue<T, std::vector<T>, std::greater<>> pq;
	std::array<std::array<int, W>, H> d;
	std::array<std::array<int, W>, H> b;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			d[i][j] = inf;
			b[i][j] = -1;
		}
	}
	d[sh][sw] = 0;
	pq.emplace(0, sh, sw);
	const int dh[] = {1, 0, -1, 0};
	const int dw[] = {0, 1, 0, -1};
	const std::string dir = "DRUL";
	while(not pq.empty())
	{
		auto [dist, h, w] = pq.top();
		pq.pop();
		if(dist > d[h][w])
			continue;
		if(h == th and w == tw)
			break;
		for (int i = 0; i < 4; ++i)
		{
			const int nh = h + dh[i];
			const int nw = w + dw[i];
			if(nh < 0 or nh >= H or nw < 0 or nw >= W)
				continue;
			if(chmin(d[nh][nw], d[h][w] + cost(h, w, nh, nw)))
			{
				pq.emplace(d[nh][nw], nh, nw);
				b[nh][nw] = i;
			}
		}
	}
	int cnt = 0;
	std::string res;
	int curh = th, curw = tw;
	while(curh != sh or curw != sw)
	{
		const int idx = b[curh][curw];
		cnt += 1;
		res += dir[idx];
		curh -= dh[idx];
		curw -= dw[idx];
	}
	std::reverse(res.begin(), res.end());
	cout << res << endl;
	ll len; cin >> len;
	len /= cnt;
	curh = sh, curw = sw;
	for(const auto &c : res)
	{
		if(c == 'R')
		{
			ch[curh][curw] = len;
			curw += 1;
		}
		if(c == 'L')
		{
			ch[curh][curw - 1] = len;
			curw -= 1;
		}
		if(c == 'U')
		{
			ch[curh - 1][curw] = len;
			curh -= 1;
		}
		if(c == 'D')
		{
			ch[curh][curw] = len;
			curh += 1;
		}
	}
}
int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  const int INIC = 5000;

  for (int i = 0; i < H - 1; ++i)
  {
  	for (int j = 0; j < W; ++j)
  	{
  		ch[i][j] = INIC;
  	}
  }
  for (int i = 0; i < H; ++i)
  {
  	for (int j = 0; j < W - 1; ++j)
  	{
  		cw[i][j] = INIC;
  	}
  }
  int kkt = 1000;
  //cin >> kkt;
  while(kkt--)
    solve();
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> Point;

typedef pair<Point, Point> Path;

map<Path, double> cost;

Point get_next(Point cur, Point goal) {
  double min_cost = 1e14;
  Point next = make_pair(-1, -1);
  if (cur.first < goal.first) {
    next = make_pair(cur.first + 1, cur.second);
    min_cost = cost[make_pair(cur, next)];
  } else if (cur.first > goal.first) {
    next = make_pair(cur.first - 1, cur.second);
    min_cost = cost[make_pair(cur, next)];
  }

  if (cur.second < goal.second) {
    Point tmp_next = make_pair(cur.first, cur.second + 1);
    double tmp_min_cost = cost[make_pair(cur, tmp_next)];
    if (tmp_min_cost < min_cost) {
      min_cost = tmp_min_cost;
      next = tmp_next;
    }
  } else if (cur.second > goal.second) {
    Point tmp_next = make_pair(cur.first, cur.second - 1);
    double tmp_min_cost = cost[make_pair(cur, tmp_next)];
    if (tmp_min_cost < min_cost) {
      min_cost = tmp_min_cost;
      next = tmp_next;
    }
  }
  return next;
}

void print_path(vector<Point> in_path) {
  for (int i = 0 ; i < in_path.size() - 1; i++) {
    Point cur = in_path[i];
    Point next = in_path[i+1];

    if (cur.first < next.first) {
      cout<<'D';
    } else if (cur.first > next.first) {
      cout<<'U';
    } else if (cur.second < next.second) {
      cout<<'R';
    } else {
      cout<<'L';
    }
  }
  cout<<endl<<flush;
}
void update_cost(vector<Point> in_path, long long dist) {
  double avg_cost = 1.0 * dist / (in_path.size() - 1);

  for (int i = 0; i < in_path.size() - 1; i++) {
    Point cur = in_path[i];
    Point next = in_path[i+1];

    double cur_cost = cost[make_pair(cur, next)];
    if (cur_cost == 0) {
      cost[make_pair(cur, next)] = avg_cost;
    } else {
      cost[make_pair(cur, next)] = min(avg_cost, cur_cost);
    }
  }
}
void calc(Point s, Point t) {
  char c1;
  vector<Point> result;

  Point cur = s;
  result.push_back(cur);
  while (true) {
    Point next = get_next(cur, t);
    result.push_back(next);
    cur = next;
    if (cur == t) {
      break;
    }
  }
  print_path(result);

  long long dist;
  cin>>dist;

  update_cost(result, dist);
}
int main() {
  for (int i = 0; i < 1000; i++) {
    Point s, t;
    cin>>s.first>>s.second>>t.first>>t.second;
    calc(s, t);
  }

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin >> T;
    while(T--){
        long long N;
        cin >> N;
        int cnt = 0;
        while(N % 2 == 0){
            N /= 2;
            cnt++;
        }
        if(cnt == 0) cout << "Odd" << endl;
        else if(cnt == 1) cout << "Same" << endl;
        else cout << "Even" << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define repr(i,n) for (int i = (n)-1; i >= 0; --i)
#define rep1r(i,n) for (int i = (n); i > 0; --i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

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

struct Solver{

    void solve(){
        ll N;
        cin >> N;
        vec(bool) used(N+1);
        rep(i,N){
            ll ai;
            cin >> ai;
            if(used[ai]){
                cout << "No" << endl;
                return;
            }
            used[ai]=true;
        }
        cout << "Yes" << endl;

    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

    int M,sum=0;
    cin>>M;
     int ar[M];
             for(int i=0;i<M;i++){
             cin>>ar[i];
                   if(ar[i]>=10){
               sum+=(ar[i]-10);
         }

    }

    cout<<sum<<endl;

   return 0;
}

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

#define in(i,a,n) for(i=a;i<n;i++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ll long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define vi vector<int>
#define vll vector<long long>

void solve();

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

}

void solve(){
    int n,ans=0,i=0;
    cin>>n;

    vector<int> a;
    in(i,0,n){
        int y;
        cin>>y;
        a.push_back(y);
       ;
    }
    in(i,0,n){
        if(a[i]>10){

            ans=ans+(a[i]-10);
        }
    }
    cout<<ans<<endl;

}


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

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

	int N;
	cin >> N;
	double ans = N;
	double tmp = 0.0;
	for (int i=1;i<=N;i++) {
		tmp += 1.0/i;
	}
	ans *= tmp;
	ans -= 1;
	cout << fixed << setprecision(15) << ans << "\n";
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;
int A[211];

VI B, C;
VI D[211];
VI stk;

bool rec(int I, int s) {
    if (I == N) {
	if (stk.empty()) return false;

	if (!D[s].empty()) {
	    B = D[s];
	    C = stk;
	    return true;
	}

	D[s] = stk;
	return false;
    } else {
	bool b = rec(I+1, s);
	if (b) return true;

	stk.push_back(I+1);
	b = rec(I+1, (s+A[I]) % 200);
	stk.pop_back();
	if (b) return true;

	return false;
    }
}

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    if (rec(0, 0)) {
	puts("Yes");
	REP (t, 2) {
	    printf("%d ", (int)B.size());
	    rprintf("%d", B.begin(), B.end());
	    swap(B, C);
	}
    } else {
	puts("No");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int result=N*1.08;
    if(result<206)
        cout << "Yay!"<<endl;
    else if(result==206)
        cout << "so-so"<<endl;
    else if(result>206)
        cout << ":("<<endl;

}

#include <iostream>
#include <vector>
#include <cmath>
#include <ostream>
#include <list>
#include <map>
#include <algorithm>
#include <climits>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <deque>
#include <set>
#include <stack>
#include <queue>
#include <chrono>
#include <deque>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define mod 1000000007
#define cbit __builtin_popcountll
#define pl pair<long, long>
#define pqp priority_queue<pl>
#define mkp make_pair
#define vl vector<ll>
#define vvl vector<vl >
#define pb push_back
#define inf 1000000000000000000
#define all(v) v.begin(), v.end()

long long gcd(long long int a, long long int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
long long lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}
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;

    while (t--)
    {
        ll n;
        cin>>n;
        if((n*108)/100<206)
        {
            cout<<"Yay!";
        }
        else if((n*108)/100==206)
        {
            cout<<"so-so";
        }
        else{
            cout<<":(";
        }
    }
    return 0;
}

// ll mod_power(ll a,ll b)
// {
//     if(b==0)
//     {
//         return 1;
//     }
//     ll temp=mod_power(a,b/2);
//     temp%=mod;
//     temp*=temp;
//     temp%=mod;
//     if(b%2==1)
//     {
//         temp*=a;
//         temp%=mod;
//     }
//     return temp;
// }
// struct compare {
//     bool operator()(const pair<ll,ll > &a,const pair<ll,ll > &b)
//     {
//         return a.first>b.first;
//     }
// };

// bool comp(const pair<ll,ll > &a,const pair<ll,ll > &b)
// {
//     if(a.first==b.first)
//     {
//         return a.second<b.second;
//     }
//     return a.first<b.first;
// }


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

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

  long sum = 0;

  for (int i = 0; i < N; i ++)
  {
    int A;
    cin >> A;

    if (A > 10) sum += A - 10;
  }

  cout << sum << endl;

  return 0;
}

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<ll, ll> p;
const int INF = 1e9;
const double eps = 1e-7;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long double pi = 4 * atan(1);
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &x : v)
        is >> x;
    return is;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i,n){
        a[i] = max(0,a[i]-10);
    }
    int ans =0;
    rep(i,n)ans+=a[i];
    cout<<ans<<"\n";
}


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

#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()

#define            pb                push_back
#define          sz(a)               (int)a.size()
#define         fastio               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define      GR(a,n,m)               vector<vector<int>> a(n, vector<int>(m, 0));

const int N = 505;
int A[N][N], B[N][N], n, m;
bool vis[N][N];
int dist[N][N];

vector<pair<pair<int,int>,int>> adj[N][N];
void solve()
{
	cin >> n >> m;

	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < m - 1;j++){
			cin >> A[i][j];
		}
	}
	for(int i = 0;i < n - 1;i++){
		for(int j = 0;j < m;j++){
			cin >> B[i][j];
		}
	}

	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < m;j++)
		{
			if(i + 1 < n){
				adj[i][j].pb({{i + 1,j},B[i][j]});
			}
			if(j + 1 < m){
				adj[i][j].pb({{i,j + 1},A[i][j]});
			}
			if(j - 1 >= 0){
				adj[i][j].pb({{i,j - 1}, A[i][j - 1]});
			}
		}
	}

	for(int r = 0;r < n;r++)
	{
		for(int c = 0;c < m;c++)
		{
			for(int i = 1;i <= r;i++)
			{
				adj[r][c].pb({{r - i, c}, i + 1});
			}
		}
	}
	for(int i = 0;i < n;i++)
		for(int j = 0;j < m;j++)
			dist[i][j] = INT_MAX;
	dist[0][0] = 0;
	int k = 1000;
	queue<pair<int,int>> q[k + 5];
	int cnt = 1, pos = 0;
	q[0].push({0,0});
	while(cnt > 0)
	{
		while(q[pos % (k + 1)].empty())++pos;
		int x = q[pos % (k + 1)].front().first, y = q[pos % (k + 1)].front().second;
		q[pos % (k + 1)].pop();
		--cnt;
		if(vis[x][y])continue;
		vis[x][y] = true;

		for(auto v : adj[x][y])
		{
			int i = v.first.first, j = v.first.second, w = v.second;
			if(dist[x][y] + w < dist[i][j])
			{
				dist[i][j] = dist[x][y] + w;
				q[dist[i][j] % (k + 1)].push({i,j});
				++cnt;
			}
		}
	}
	cout << dist[n - 1][m - 1] << "\n";
}

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

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

inline int_fast32_t get_digit() {
    int_fast32_t x = 0, f = 1;
    char c = getchar();
    while(c > '9' || c < '0') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        x = (x * 10) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}

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


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

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

int main(){

  int n;
  cin>>n;

  cout<<n-1;

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  cout << n - 1 << endl;
}


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

#define sz(x) (int)(x).size()
using namespace std;

int64_t strtoll(string &s) {
    int64_t res = 0;
    for (int i = 0; i < sz(s); i++) {
        res *= 10;
        res += s[i] - '0';
    }
    return res;
}

vector<int64_t> convertToInts(vector<string> &arr, vector<int> &inds) {
    vector<string> results = arr;
    for (int i = 0; i < 3; i++) {
        for (auto &c : results[i]) {
            c = inds[c - 'a'] + '0';
        }
    }
    vector<int64_t> int_results(3);
    for (int i = 0; i < 3; i++) {
        int_results[i] = strtoll(results[i]);
    }
    return int_results;
}

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

    vector<string> arr(3);
    for (int i = 0; i < 3; i++) {
        cin >> arr[i];
    }
    vector<int> inds(26, -1);
    int cur = 0;
    for (int i = 0; i < 3; i++) {
        for (char c : arr[i]) {
            if (inds[c - 'a'] == -1) {
                inds[c - 'a'] = cur++;
            }
        }
    }
    if (cur > 10) {
        cout << "UNSOLVABLE\n";
        return 0;
    }
    int index = 0;
    while (cur != 10) {
        if (inds[index] == -1) {
            inds[index] = cur++;
        }
        index++;
    }
    vector<int> reverse_inds(cur, -1);
    for (int i = 0; i < 26; i++) {
        if (inds[i] == -1) {
            continue;
        }
        reverse_inds[inds[i]] = i;
    }
    sort(reverse_inds.begin(), reverse_inds.end());
    do {
        for (int i = 0; i < cur; i++) {
            inds[reverse_inds[i]] = i;
        }
        if (inds[arr[0][0] - 'a'] == 0) {
            continue;
        }
        if (inds[arr[1][0] - 'a'] == 0) {
            continue;
        }
        if (inds[arr[2][0] - 'a'] == 0) {
            continue;
        }
        vector<int64_t> results = convertToInts(arr, inds);
        if (results[0] + results[1] == results[2]) {
            for (int i = 0; i < 3; i++) {
                cout << results[i] << "\n";
            }
            return 0;
        }
    } while(next_permutation(reverse_inds.begin(), reverse_inds.end()));
    cout << "UNSOLVABLE\n";

    return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    int n;
    cin >> n;
    ll T;
    cin >> T;
    vector<ll> a(n);
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
    }
    if(n == 1)
    {
        if(T >= a[0])
        {
            cout << a[0];
        }
        else
        {
            cout << 0;
        }
        return;
    }

    vector<ll> s1, s2;
    for(int i=0; i<(1<<(n/2)); i++)
    {
        ll t = 0;
        for(int j=0; j<n/2; j++)
        {
            if((1<<j)&i)
            {
                t += a[j];
            }
        }
        s1.PB(t);
    }

    for(int i=0; i<(1<<(n-n/2)); i++)
    {
        ll t = 0;
        for(int j=0; j<(n-n/2); j++)
        {
            if((1<<j)&i)
            {
                t += a[j+n/2];
            }
        }
        s2.PB(t);
    }
    s1.PB(0);
    sort(s2.begin(), s2.end());
    ll ans = 0;
    for(ll x : s1)
    {
        if(x <= T)
        {
            ans = max(ans, x);
        }
        auto a = upper_bound(s2.begin(), s2.end(), T-x);
        if(a != s2.begin())
        {
            a--;
//            what_is(x);
//            what_is((*a));
            ans = max(ans, x + (*a));
        }
    }
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
#include <functional>
#include <time.h>
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define PI 3.141592653589793
const ll MOD = 1000000007;

/*clock_t start = clock();
clock_t end = clock();
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
cout << time << endl;*/

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(ll now,map<ll,ll> &mp){
	if(now == 1) return;
	if(now % 2 == 0){
		if(mp.find(now/2) == mp.end()){
			mp[now/2] = mp[now] + 1;
			solve(now/2,mp);
		}
		else if(mp[now/2] > mp[now] + 1){
			mp[now/2] = mp[now] + 1;
			solve(now/2,mp);
		}
	}
	else{
		ll a = now/2*2;
		if(mp.find(a/2) == mp.end()){
			mp[a/2] = mp[now] + 2;
			solve(a/2,mp);
		}
		else if(mp[a/2] > mp[now] + 2){
			mp[a/2] = mp[now] + 2;
			solve(a/2,mp);
		}
		a += 2;
		if(mp.find(a/2) == mp.end()){
			mp[a/2] = mp[now] + 2;
			solve(a/2,mp);
		}
		else if(mp[a/2] > mp[now] + 2){
			mp[a/2] = mp[now] + 2;
			solve(a/2,mp);
		}
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll X,Y;
	cin >> X >> Y;
	map<ll,ll> mp;
	mp[Y] = 0;
	solve(Y,mp);
	ll ans = INF;
	for(auto m:mp){
		ans = min(ans,abs(m.first-X) + m.second);
	}
	cout << ans << endl;
}

#include<ctime>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=1e5+7;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
struct node{
	ll i,k;
	node(ll i=0,ll k=0):i(i),k(k){}
	friend bool operator <(node a,node b){
		return a.k<b.k;
	}
}c[N];
ll n,q,cur,p,a[N],ans[N];
int main() {
	#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	q=read();
	for(ll i=1;i<=n;++i)
		a[i]=read();
	a[n+1]=5e18;
	for(ll i=1;i<=q;++i)
		c[i]=node(i,read());
	sort(c+1,c+q+1);
	for(ll i=1;i<=q;++i){
		ll qi=c[i].i;
		ll qk=c[i].k;
		while(a[p+1]-a[p]-1<qk-cur){
			cur+=a[p+1]-a[p]-1;
			++p;
		}
		ans[qi]=a[p]+qk-cur;
	}
	for(ll i=1;i<=q;++i)
		printf("%lld\n",ans[i]);
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}


#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int k, n, m;
    cin >> k >> n >> m;

    vector<ll> a(k);
    rep(i, k) {
        cin >> a[i];
        a[i] *= m;
    }

    vector<int> x(k);
    int sum = m;
    rep(i, k) {
        x[i] = a[i] / n;
        a[i] %= n;
        sum -= x[i];
    }

    vector<int> p(k);
    iota(ALL(p), 0);
    sort(ALL(p), [&](int i, int j) { return a[i] > a[j]; });

    rep(i, sum) x[p[i]]++;

    rep(i, k) cout << x[i] << " \n"[i + 1 == k];

    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
template <typename T> void DEBUGall(T v) { if(v.empty()){cerr << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cerr << *i << " ";} cerr << *--v.end() << endl; }
inline void IN(void){ return; }
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; }
inline void OUT(void){ cout << "\n"; return; }
template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; }
inline void DEBUG(void){ cerr << "\n"; return; }
template <typename First, typename... Rest> void DEBUG(First first, Rest... rest){ cerr << first << " "; DEBUG(rest...); return; }

void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); }
ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); }

void Main(){
    int n; IN(n);
    vi a(n);
    rep(i, n) {
        IN(a[i]);
        a[i] %= 200;
    }

    map<int, int> mp;
    n = min(n, 10);
    rep(bit, 1<<n){
        if(bit == 0) continue;
        int tmp = 0;
        rep(i, n){
            if(bit>>i & 1){
                tmp = (tmp + a[i]) % 200;
            }
        }
        if(mp.find(tmp) != mp.end()){
            int bit0 = mp[tmp];
            Yes();

            cout << __builtin_popcount(bit0) << " ";
            vi v;
            rep(i, n) {
                if(bit0>>i & 1) v.pb(i+1);
            }
            coutall(v);

            cout << __builtin_popcount(bit) << " ";
            v = vi();
            rep(i, n) {
                if(bit>>i & 1) v.pb(i+1);
            }
            coutall(v);
            return;
        }
        mp[tmp] = bit;
    }
    Yes(0);
    return;
}

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


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
// avoid unordered_map and unordered_set!!!
#include <vector>
#include <utility>

using namespace std;

using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;

#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;

#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif

constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;
constexpr double EPS = 1e-9;

int
main()
{
    ios_base::sync_with_stdio(false);
    // fast io: see 1423K
    cin.tie(nullptr);
    cout.tie(nullptr);

    DRi64(R); DRi64(X); DRi64(Y);
    let i64 d2_from_orig = X * X + Y  * Y;
    let i64 R2 = R * R;
    if (d2_from_orig < R2)
    {
        cout << "2\n";
        return 0;
    }
    let i64 q = d2_from_orig / R2;
    let double sqrt_q = sqrt(q);
    if (d2_from_orig % R2 == 0 && q == i64(sqrt_q) * i64(sqrt_q))
    {
        cout << i64(sqrt_q) << "\n";
        return 0;
    }
    cout << i64(sqrt_q + 1) << "\n";

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define mp make_pair
#define pb push_back
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = n; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = 1070000000;
constexpr long long LINF = 4611686015206162431;

vector<int> sieve(int n) {
    vector<bool> mem(n+1, true);
    mem[0] = false; mem[1] = false;
    for (int i = 2; i*i <= n; i++) {
        if (mem[i]) {
            for (int j = i*2; j <= n; j += i) {
                mem[j] = false;
            }
        }
    }
    vector<int> res;
    rep (i, n+1) if (mem[i]) res.push_back(i);
    return res;
}

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

    ll A, B;
    cin >> A >> B;

    int N = B - A + 1, d = B - A;

    vc<int> primes = sieve(d);

    vc<int> fac(N);
    for (ll a = A; a <= B; a++) {
        rep (i, primes.size()) {
            fac[a-A] *= 2;
            if (a % primes[i] == 0) {
                fac[a-A]++;
            }
        }
    }

    vvc<ll> dp(N+1, vc<ll>(1 << primes.size()));
    dp[0][0] = 1;

    rep (i, N) {
        rep (j, 1 << primes.size()) {
            if (!(j&fac[i])) dp[i+1][j|fac[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j];
        }
    }

    ll ans = 0;
    rep (i, 1 << primes.size()) {
        ans += dp[N][i];
    }
    cout << ans << endl;
}


#include <cstdio>

int main() {
    int N, X, i;
    int V[1000] = {};
    int P[1000] = {};
    scanf("%d %d", &N, &X);
    X *= 100;
    for (i = 0; i < N; i++) scanf("%d %d", V + i, P + i);
    int s = 0;
    for (i = 0; i < N; i++) {
        s += V[i] * P[i];
        if (s > X) break;
    }
    if (i == N) printf("-1");
    else printf("%d", i + 1);
    return 0;
}

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

int main() {
  int n,k;
  cin>>n>>k;
  int z=0;
  int x=0;
  rep(i,n+1) z+=i;
  rep(i,k+1) x+=i;
  ll ans =z*k*100+x*n;
  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define UNIQUE(v) sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end());
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll power(ll a,ll b){ll ret=1;while(b){if(b%2)ret=ret*a%MOD;a=a*a%MOD;b/=2;}return ret;}
const int sz = 1<<17;

int main()
{
    int a,b,c,d;scanf("%d %d %d %d",&a,&b,&c,&d);
    printf("%d",b-c);
    return 0;
}

#include <bits/stdc++.h>

int main() {
    const long long int MOD = 998244353;
    long long int A, B, C;
    std::cin >> A >> B >> C;

    long long int sum_a = (A + 1) * A / 2 % MOD;
    long long int sum_b = (B + 1) * B / 2 % MOD;
    long long int sum_c = (C + 1) * C / 2 % MOD;
    std::cout << ((sum_a * sum_b) % MOD) * sum_c % MOD  << std::endl;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min({a, b, c, d}) << endl;

    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define vt vector
#define f(i,n) for((i)=0;(i)<(n);(i)++)
#define fd(i,n) for((i)=n-1;(i)>=0;(i)--)
#define pb push_back
using namespace std;
int main(){
    ll t=1;
//cin>>t;
    while(t--){
        ll a,b,c,x,y,z;
        cin>>a>>b>>c;
        if (a==1)
            x=6;
        else if(a==2)
            x=5;
        else if(a==3)
            x=4;
        else if(a==4)
            x=3;
        else if(a==5)
            x=2;
        else
            x=1;
        if (b==1)
            y=6;
        else if(b==2)
            y=5;
        else if(b==3)
            y=4;
        else if(b==4)
            y=3;
        else if(b==5)
            y=2;
        else
            y=1;
        if (c==1)
            z=6;
        else if(c==2)
            z=5;
        else if(c==3)
            z=4;
        else if(c==4)
            z=3;
        else if(c==5)
            z=2;
        else
            z=1;
        cout<<x+y+z<<endl;
    }
    return 0;
}


// Code Written by Pinaki Bhattacharjee (pinakipb2)
#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 endl "\n"
#define PI 2*acos(0.0)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mpr make_pair
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcountll
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

int main()
{
    pinakipb2;

    ll n;
    cin>>n;
    ll ans = 0,ele;
    for(int i=0;i<n;i++)
    {
        cin>>ele;
        if(ele>10) ans+=(ele-10);
    }
    cout<<ans<<endl;

    return 0;
}

# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
# define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x)))
# define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x)))
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vb = vec<bool>;
using vvb = vec<vb>;
using vvvb = vec<vvb>;
using vs = vec<string>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> T scan() { T ret; cin >> ret; return ret; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ os << p.fi << " " << p.se; return os; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);}
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){cerr << v; if(sizeof...(args))cerr << " "; eprint(args...);}
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; drop(args...);}
template<class T> inline constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> inline constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
const char* yn(bool b) { return b ? "Yes" : "No"; }
# endif  // ngng628_library

struct Ad {
   int x, y, r;
   int id;
   Ad() = default;
   Ad(int _x, int _y, int _r, int _id) : x(_x), y(_y), r(_r), id(_id) {}
};
ostream& operator<<(ostream& os, const Ad& a){
   printf("%4lld | %4lld %4lld %7lld", a.id, a.x, a.y, a.r);
   return os;
}

int32_t main() {
   int n;
   cin >> n;
   vec<Ad> ads(n);
   rep (i, n) {
      cin >> ads[i].x >> ads[i].y >> ads[i].r;
      ads[i].id = i;
   }

   rep (i, n) {
      auto& ad = ads[i];
      printf("%lld %lld %lld %lld\n", ad.x, ad.y, min(ad.x + 2LL, 10000LL), min(ad.y + 2LL, 10000LL));
   }
}


/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#ifdef ONLINE_JUDGE
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define dbg(v)
#else
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
#endif

// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int dp[280000][18];

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int n, x[20], y[20], z[20];
    int d[20][20];
    cin >> n;
    rep(i, n) cin >> x[i] >> y[i] >> z[i];
    rep(i, n) rep(j, n) d[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]);

    rep(bit, 1 << n) {
        rep(i, n) dp[bit][i] = INF;
    }

    dp[0][0] = 0;
    rep(bit, 1 << n) {
        rep(u, n) {
            rep(v, n) {
                chmin(dp[bit | (1 << v)][v], dp[bit][u] + d[u][v]);
            }
        }
    }

    print(dp[(1 << n) - 1][0]);
    int ans = INF;
    for (int i = 1; i < n; ++i) chmin(ans, dp[(1 << n) - 1][i] + d[i][0]);
    // print(ans);

    return 0;
}

/*
  ___   ___ _ __  _ __
 / _ \ / __| '_ \| '_ \
|  __/| (__| |_) | |_) |
 \___(_)___| .__/| .__/
           |_|   |_|
*/

// RedStone
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 1e5 + 5;
const int Mod = 1e9 + 7;

int n;
int arr[N];
int dp[N][2];

int count(int i, int last) {
  if(i <= 0) return 1;
  int& r = dp[i][last];
  if(r != -1) return r;
  r = count(i - 1, 0);
  if(!last) r = (r + count(i - 1, 1)) % Mod;
  return r;
}

int main()
{
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", arr + i);
  }
  memset(dp, -1, sizeof dp);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    int cur = 1LL * arr[i] * count(n - 1 - i, 0) % Mod * count(i - 1, 0) % Mod;
    if(i > 0) {
      cur += -1LL * arr[i] * count(n - 1 - i, 1) % Mod * count(i - 1, 1) % Mod;
      cur %= Mod;
    }
    ans = (ans + cur) % Mod;
  }
  ans = (ans + Mod) % Mod;
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 1e9+7;
#define ll long long
struct mint {
  ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
 }
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
    return fac[a]/fac[b]/fac[a-b];
}
mint pow2[4000002];
signed main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char> > a(h);
    vector<vector<int> > u(h);
    vector<vector<int> > d(h);
    vector<vector<int> > l(h);
    vector<vector<int> > r(h);
    int clean = 0;
    pow2[0]=1;
    FOR(i,1,4000002) {
        pow2[i]=pow2[i-1]*(mint)2;
    }
    rep(i,h) {
        string s;
        cin>>s;
        rep(j,w) a[i].push_back(s[j]);
        rep(j,w) if(a[i][j]=='.') clean++;
        rep(j,w) {
            u[i].push_back(0);
            d[i].push_back(0);
            l[i].push_back(0);
            r[i].push_back(0);
        }
    }
    mint cl = clean;
    mint ans = cl * pow2[clean];
    //u
    rep(i,h) {
        rep(j,w) {
            u[i][j]=l[i][j]=0;
            if(a[i][j]=='#')continue;
            if(i>0) u[i][j]=u[i-1][j];
            if(j>0) l[i][j]=l[i][j-1];
            u[i][j]++;
            l[i][j]++;
        }
    }
    rrep(i,h) {
        rrep(j,w) {
            d[i][j]=r[i][j]=0;
            if(a[i][j]=='#')continue;
            if(i<h-1) d[i][j]=d[i+1][j];
            if(j<w-1) r[i][j]=r[i][j+1];
            d[i][j]++;
            r[i][j]++;
        }
    }
    rep(i,h) {
        rep(j,w) {
            if(a[i][j]=='#')continue;
            int don = u[i][j]+d[i][j]+r[i][j]+l[i][j]-3;
            // cout << don << endl;
            ans-= pow2[clean-don];
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

int64_t solve(int64_t N, string S, string T) {
    // TODO: edit here
    ll count(0);
    for (size_t i = 0; i < N; ++i) {
        if (S[i] == '1') ++count;
        if (T[i] == '1') --count;
    }
    if (count != 0) return -1;
    for (size_t i = 0; i < N; ++i) {
        if (S[i] != T[i]) {
//            cerr << S[i] << ", " << T[i] << endl;
            if (S[i] == '1') {
                for (auto j = i + 1; j < N; ++j) {
                    if (S[j] == '0') {
//                        cerr << i << ", " << j << endl;
                        S[i] = '0';
                        S[j] = '1';
                        ++count;
                        break;
                    }
                }
            } else {
                for (auto j = i + 1; j < N; ++j) {
                    if (T[j] == '0') {
//                        cerr << i << ", " << j << endl;
                        T[i] = '0';
                        T[j] = '1';
                        ++count;
                        break;
                    }
                }
            }
        }
    }
    return count;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t N;
    string S, T;
    cin >> N >> S >> T;
    auto ans = solve(N, S, T);
    cout << ans << endl;
    return 0;
}