#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

void solve()
{
    int n;
    cin>>n;
    double x0,y0,xn,yn;
    cin>>x0>>y0>>xn>>yn;
    double x=(x0+xn)/2.0,y=(y0+yn)/2.0;
    double angle=2*pi/n;

    double x_ans=(x0-x)*cos(angle)-(y0-y)*sin(angle)+x;
    double y_ans=(x0-x)*sin(angle)+(y0-y)*cos(angle)+y;

    printf("%.9f %.9f\n",x_ans,y_ans);
}

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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

template <typename T>
void print_vector(T& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) ss << v << " ";
    ss << "}" << endl;
    cout << ss.str() << endl;
}

template <typename T>
void print_pairs(T& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) ss << v.first << "," << v.second << " ";
    ss << "}" << endl;
    cout << ss.str() << endl;
}

template <typename T>
string string_vector(vector<T>& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) ss << v << " ";
    ss << "}\n";
    return ss.str();
}

template <typename T>
string string_vector(vector<vector<T>>& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) {
        ss << "{";
        for (auto vv : v) ss << vv << " ";
        ss << "}";
    }
    ss << "}\n";
    return ss.str();
}

using ll = long long;
class Solution {
   public:
    bool solve(ll V, ll T, ll S, ll D) {
        // D = V * t
        return !( (V*T <=D) and (D <= S*V));
    }
};

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    Solution sol;
    ll V, T, S, D;
    cin >> V >> T >> S >> D;
    auto ans = sol.solve(V, T, S, D);
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


#include<bits/stdc++.h>

#define loop(i,n)   for(int i = 0; i < n; ++ i)
#define rloop(i, n) for(int i = n-1; i >=0; i--)
#define inp(arr, n) for(int i=0; i<n; i++) cin >> arr[i];
#define deb(x)		cout << "  " << #x << " " << x << endl // used to debug any variable
#define mod         1000000007
#define pb          push_back
#define ff          first
#define ss          second
#define Vi          vector<int>
#define Vs          vector<string>
#define Vll         vector<long long>
#define Vl          vector<long>
#define Vc          vector<char>
#define all(v)      v.begin(), v.end()

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef unsigned long long int usll;
typedef long double ld;
typedef double db;

using namespace std;

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

}

void solve()
{
    int n;
    cin>>n;
    Vi arr(n);
    ll res=0;
    inp(arr,n);
    loop(i,n)
    {
        if(arr[i]>10)
            res=res+(arr[i]-10);
    }
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //int T = 1;cin >> T;while (T--)
        solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, nuts = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i<n; i++) cin >> a[i];
    for(int k:a) if(k>10) nuts+=(k-10);
    cout << nuts << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <ctime>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define make make_pair
#define fi first
#define se second
#define vi std::vector<int>;
#define DEBUG cout << "debug" << endl
#define CLOSE ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define CASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++)
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int MOD = 1e9 + 7;
const int CM = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
template <typename T>
T MAX(T a, T b) { return a > b ? a : b; }
template <typename T>
T MIN(T a, T b) { return a > b ? b : a; }
template <typename T>
T GCD(T a, T b){ return b == 0 ? a : GCD(b, a % b); }
template <typename T>
T LCM(T a, T b){ return a / GCD(a, b) * b; }
template <typename T>
T ABS(T a) { return a > 0 ? a : -a; }
template <typename T>
T ADD(T a, T b, T MOD){ return (a + b) % MOD; }
template <typename T>
T DEL(T a, T b, T MOD) { return ((a - b) % MOD + MOD) % MOD; }
void solve(int kase){
    ll s, p;
    cin >> s >> p;
    for(ll i = 1; i * i <= p; i++) {
        if(p % i == 0) {
            ll x = i, y = p / i;
            if(x + y == s) {
                printf("Yes\n"); return;
            }
        }
    }
    printf("No\n");
}
const bool DUO = 0;
void TIME(){
    clock_t start, finish;
    double totaltime;
    start = clock();

    // 待测程序

    if(DUO) {CASE solve(kase);}
    else solve(1);
    // 待测程序

    finish = clock();
    totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
    printf("\nTime:%lfms\n", totaltime * 1000);
}
int main(){
    #ifdef ONLINE_JUDGE
        // CLOSE;
        if(DUO) {CASE solve(kase);}
        else solve(1);
    #else
        // freopen("./data/a.txt", "r", stdin);
        // freopen("./data/a.txt", "w", stdout);
        TIME();
    #endif
    return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long;
using namespace std;

const int INF = 1 << 30;

int main() {
    ll N;
    cin >> N;
    // vector<ll> A(N), B(N);
    vector<ll> C(N);
    ll aoki = 0;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        aoki += a;
        ll total = 2 * a + b;
        C[i] = total;
    }
    sort(C.rbegin(), C.rend());

    ll counter = 0;
    ll total = 0;
    for (ll i = 0; i < N; i++) {
        counter++;
        total += C[i];
        // cout << "total: " << total << endl;

        if (total > aoki) break;
    }

    ll ans = counter;
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
namespace atcoder {}
using namespace atcoder;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
#define int long long int
lli dp[105][105][105] = {};
void solve(long long N, long long X, std::vector<long long> A) {
  lli ans = 1e18;
  for (int t = 1; t <= N; t++) {
    rep(i, N + 1) rep(j, N + 1) rep(k, N + 1) dp[i][j][k] = -1;
    vector<int> B;
    dp[0][0][0] = 0;
    rep(i, N) rep(j, N + 1) rep(k, N + 1) {
      chmax(dp[i + 1][j][k], dp[i][j][k]);
      if (dp[i][j][k] >= 0)
        chmax(dp[i + 1][j + 1][(k + A[i]) % t], dp[i][j][k] + A[i]);
    }
    if (dp[N][t][X % t] >= 0)
      chmin(ans, (X - dp[N][t][X % t]) / t);
  }
  cout << ans << endl;
}

signed main() {
  long long N;
  scanf("%lld", &N);
  long long X;
  scanf("%lld", &X);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, X, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}

////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define em empty()
#define fi first
#define se second
#define cnt continue
#define cl clear()
#define pb push_back
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define valid(x,y) x>=1 && x<=Row && y>=1 && y<=Col
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
int fx[]={1,-1,0,0},Row,Col;
int fy[]={0,0,1,-1};
int dx[]={0,0,1,-1,-1,1,-1,1};
int dy[]={-1,1,0,0,1,1,-1,-1};
using LL=long long;
using LD=long double;
using ULL=unsigned long long;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>n)
    {
       x=sqrt(2*(n+1));
       s=(x*(x+1))/2;
       if(s>n+1)x--;
       x=n-x+1;
       cout<<x<<en;
    }
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int mod = 998244353, N = (1 << 20) + 1;
int fac[200005], ifac[200005], inv[200005];
#define Mul(a,b) (ll)(a) * (b) % mod
#define mul(a,b) (a) = (ll)(a) * (b) % mod
int Add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
int Sub(int x, int y) {x -= y; return x < 0 ? x + mod : x;}
void add(int &a, int b) {a += b; if (a >= mod) a -= mod;}
void sub(int &a, int b) {a -= b; if (a < 0) a += mod;}
int qpow(int a, int b)
{
    int ans = 1;
    while (b)
	{
		if (b & 1) mul(ans, a);
		mul(a, a);
		b >>= 1;
	}
    return ans;
}
int binom(int x, int y){return x < y ? 0 : Mul(fac[x], Mul(ifac[y], ifac[x - y]));}
int n, m, k;
void init()
{
	read(n); read(m); read(k);
}

int calc(int lim, int l)
{
	return Sub(qpow(lim, l), qpow(lim - 1, l));
}

int calc2(int lim, int l)
{
	return qpow(lim, l);
}

void solve()
{
	if (n == 1 || m == 1)
	{
		printf("%d\n", qpow(k, m * n));
		return;
	}
	int ans = 0;
	for (int i = 1; i <= k; ++i)
	{
		add(ans, Mul(calc(i, n), calc2(k - i + 1, m)));
	}
	printf("%d\n", ans);
}

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

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2e5 + 5;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

ll qpow(ll bas, ll t) {
	ll ret = 1;
	while (t) {
		if (t & 1) ret = ret * bas % MOD;
		bas = bas * bas % MOD;
		t >>= 1;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(0);

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

	if (min(n, m) == 1) {
		ll ans = qpow(k, max(n, m));
		cout << ans << endl;
	} else {
		ll ans = 0;
		for (int x = 1; x <= k; x++)
			ans += (qpow(x, n) - qpow(x - 1, n)) * qpow(k - x + 1, m) % MOD;
		ans = (ans % MOD + MOD) % MOD;
		cout << ans << endl;
	}

	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1500100;
const int inf=0x3f3f3f3f;
int tree[maxn<<2];//维护个数，初始全部为0；
int vis[maxn];
int num[maxn];
int n,m;
void add(int tis,int l,int r,int tp,int k)
{
    if(l==r){
       vis[l]+=k;
       if(vis[l])tree[tis]=inf;
        else tree[tis]=l;
    }
    else{
        int mid=(r+l)>>1;
        if(tp<=mid)add(tis<<1,l,mid,tp,k);
        if(tp>=mid+1)add(tis<<1|1,mid+1,r,tp,k);
        tree[tis]=min(tree[tis<<1],tree[tis<<1|1]);
    }
}
void build(int tis,int l,int r){
    if(l==r){
        tree[tis]=l;
    }
    else {
        int mid=(l+r)>>1;
        build(tis<<1,l,mid);
        build(tis<<1|1,mid+1,r);
        tree[tis]=min(tree[tis<<1],tree[tis<<1|1]);
    }

}
int main()
{

    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&num[i]);
    }
    build(1,1,n+1);
    for(int i=1;i<=m;i++){
        add(1,1,n+1,num[i]+1,1);
    }
    int small=tree[1]-1;
    for(int i=2;i<=n-m+1;i++){
        add(1,1,n+1,num[i+m-1]+1,1);
        add(1,1,n+1,num[i-1]+1,-1);
        if(small>tree[1]-1){
            small=tree[1]-1;
        }
    }
    printf("%d\n",small);
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

void solve() {

    int N, M; cin >> N >> M;
    int cnt[N]; F0R(i, N) cnt[i] = 0;
    set<int> av;
    F0R(i, N) av.ins(i);
    av.ins(N);
    int A[N]; F0R(i, N) cin >> A[i];
    F0R(i, M) {
        cnt[A[i]]++; av.erase(A[i]);
    }
    int ans = *av.begin();
    FOR(i, M, N) {
        cnt[A[i-M]]--;
        if (cnt[A[i-M]] == 0) av.ins(A[i-M]);
        cnt[A[i]]++;
        av.erase(A[i]);
        ckmin(ans, *av.begin());
    }
    cout << ans << nl;

}

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

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


#include "bits/stdc++.h"
using namespace std;
#define ll long long
const int areTests = 0, N = 2e5 + 20;

int n, p[N], q, u, d, dp[N], st[N], ed[N], tym, a[N];
vector <int> adj[N], idx[N];

void dfs(int node, int edges) {
	st[node] = ++tym;
	dp[node] = edges;
	idx[edges].push_back(tym);
	for(int child: adj[node]) {
		dfs(child, edges + 1);
	}
	ed[node] = tym;
}

void run_test(int testcase) {
	cin >> n;
	for(int i = 2; i <= n; i++) {
		cin >> p[i];
		adj[p[i]].push_back(i);
	}

	dfs(1, 0);
	for(int i = 0; i <= n; i++) {
		sort(idx[i].begin(), idx[i].end());
	}

	cin >> q;
	while(q--) {
		cin >> u >> d;

		if(dp[u] > d) {
			cout << "0";
		} else {
			cout << upper_bound(idx[d].begin(), idx[d].end(), ed[u]) - lower_bound(idx[d].begin(), idx[d].end(), st[u]);
		}
		cout << "\n";
	}
}

int main() {
	ios::sync_with_stdio(0);
	#ifndef DUSH1729
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);

	int t = 1;
	if(areTests) cin >> t;
	for(int i = 1; i <= t; i++) {
		run_test(i);
	}
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 200005;

vector<int> adj[N];
int vis[N],a[N],b[N];
int curr = 0, need = 0;

void dfs(int c)
{
    curr += a[c];
    need += b[c];
    vis[c]++;
    for(int ne:adj[c])if(!vis[ne])dfs(ne);
}

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=1;i<=n;i++)cin>>b[i];
        for(int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        int ok = 1;
        for(int i=1;i<=n;i++)
        {
            if(vis[i])continue;
            need = 0; curr = 0;
            dfs(i);
            ok &= (need == curr);
        }
        cout<<(ok ? "Yes" : "No")<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define rep(i, n) for (int i = 0; i < (long long int)(n); i++)
//namespace mp = boost::multiprecision;
//mp::cpp_int
/* nyuuryoku retu de ukeoru   string s; getline(cin,s);
int &n ha sansyou
sort reverse swap unique  */
using namespace std;
signed main(){
    int N,maxA=0,minB=99999;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i,N){
        cin >> A.at(i);
        if(maxA < A.at(i)){
            maxA = A.at(i);
        }
    }
    rep(i,N){
        cin >> B.at(i);
        if(minB > B.at(i)){
            minB = B.at(i);
        }
    }
    cout << ((minB - maxA +1 <= 0)? 0 : minB - maxA + 1 ) <<endl;
}

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


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

int main() {
	int k; cin >> k;
	int res = 0;
	for (int i=1; i<=k; i++)
		for (int j=1; j<=k/i; j++)
			for (int l=1; l<=k/i/j; l++)
				res++;
	cout << res << '\n';
	return 0;
}

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

// arc113a
// 列挙
// 重複あり並べ方パターン

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

    int res = 0;
    rep(i,1,K_0 + 1){
        ll K = i;
    for(ll A = 1; A*A*A <= K; A++){
        if(K%A == 0){
            ll K_1 = K/A;
            for(ll B = A; B*B <= K_1; B++){
                if(K_1%B == 0){
                    ll C = K_1/B;
                    if(A < B && B < C) res += 6;
                    else if((A == B && B < C) || (A < B && B == C))
                        res += 3;
                    else res += 1;
                    // cout << "(A, B, C):\n\t";
                    // cout << "(" << A << ", " << B << ", " << C << ")" << endl;
                    // cout << "res:\n\t";
                    // cout << res << endl;
                }
            }
        }
    }
    }
    cout << res << endl;
    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int N;
    cin >> N;

    int num = 1;
    int i = 1;
    int count = 1;
    while(true){
        if(num >= N){
            cout << count << endl;
            break;
        }
        count++;
        num += count;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loope(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloope(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define vii vector<vector<int>>
#define si set<int>
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                                              \
    ios_base::sync_with_stdio(0);                       \
    cin.tie(NULL);                                      \
// #include < ext / pb_ds / assoc_container.hpp >       \
// #include <ext/pb_ds/tree_policy.hpp>                 \
// using namespace __gnu_pbds;                          \
// typedef tree<int, null_type, less<int>, rb_tree_tag, \
//         tree_order_statistics_node_update>           \
//         ordered_set;
ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve()
{
    int n;cin>>n;
    int beg = 1,end = 1e5;
    while(beg<end){
        int mid = (beg+end)/2;
        ll ans = 1ll*mid*(mid+1)/2;
        if(ans>=n)end=mid;
        else beg = mid+1;
    }
    cout<<beg<<"\n";
}
int main()
{
    io;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test = 1, i = 0;
    // cin >> test;
    while (i++ != test)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

vector<vector<int>> solve(int N, const vector<vector<int>>& A) {
	int c = *min_element(A[0].begin(), A[0].end());
	vector<int> a(N), b(N);
	for (int j = 0; j < N; ++j) {
		b[j] = A[0][j] - c;
	}
	for (int i = 1; i < N; i++) {
		c = *min_element(A[i].begin(), A[i].end());
		for (int j = 0; j < N; ++j) {
			if (A[i][j] - c != b[j]) {
				return {};
			}
		}
	}
	c = 1 << 30;
	for (int i = 0; i < N; i++) {
		c = min(c, A[i][0]);
	}
	for (int i = 0; i < N; i++) {
		a[i] = A[i][0] - c;
	}
	for (int j = 1; j < N; ++j) {
		c = 1 << 30;
		for (int i = 0; i < N; i++) {
			c = min(c, A[i][j]);
		}
		for (int i = 0; i < N; i++) {
			if (A[i][j] - c != a[i]) {
				return {};
			}
		}
	}
	int d = A[0][0] - a[0] - b[0];
	for (int j = 0; j < N; ++j) {
		b[j] += d;
	}
	return { a, b };
}

int main() {
	int N;
	cin >> N;
	vector<vector<int>> A(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; ++j) {
			cin >> A[i][j];
		}
	}
	vector<vector<int>> ans = solve(N, A);
	if (ans.empty()) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		for (auto a : ans) {
			string delim = "";
			for (auto x : a) {
				cout << delim << x;
				delim = " ";
			}
			cout << endl;
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=20000010;

signed main(){
    ll n;cin>>n;
    vector<vector<ll> >c(n,vector<ll>(n));
    rep(i,n){
        rep(j,n)cin>>c[i][j];
    }
    bool f=1;
    vector<vector<ll> >d(n,vector<ll>(n));
    ll mi=0;
    REP(i,1,n){
        bool g=1;
        rep(j,n){
            d[i][j]=c[i][j]-c[0][j];
            if(j>0&&d[i][j]!=d[i][j-1])g=0;
            mi=min(mi,d[i][j]);
        }
        f&=g;
    }
    if(!f){
        cout<<"No"<<endl;
        return 0;
    }
    mi=-mi;
    vector<ll>a(n);
    vector<ll>b(n);
    a[0]=mi;
    REP(i,1,n){
        a[i]=mi+d[i][0];
    }
    rep(i,n){
        b[i]=c[0][i]-mi;
        if(b[i]<0)f=0;
    }
    if(f){
        cout<<"Yes"<<endl;
        rep(i,n){
            cout<<a[i]<<' ';
        }
        cout<<endl;
        rep(i,n){
            cout<<b[i]<<' ';
        }
        cout<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

int main(){
    int N,X;
    cin>>N>>X;
    vector<int> A(0);
    int count=0;
    rep(i,N){
        int tmp;
        cin>>tmp;
        if(tmp!=X){
            A.push_back(tmp);
            count++;
        }
    }
    rep(i,A.size()){
        cout<<A.at(i)<<" ";
    }
    cout<<endl;
}

#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>;
#define GETA 200

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(n, N) {
        cin >> A[n];
    }
    ll ans = 1<<30;
    rep(pt, 1 << (N-1)) {
        ll XOr = 0;
        ll now = 0;
        rep(n, N) {
            //全てA[n]基準
            now |= A[n];
            if ((pt >> n) & 1) {
                //その数字の右側で区切り
                XOr ^= now;
                now = 0;
            }
        }
        XOr ^= now;
        ans = min(ans, XOr);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cout << #a << ": " << a << endl;
#define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl;
#define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; }

int a[1005], b[1005];
int dp[1005][1005];

int main() {
    fastio;
    ll N,M;
    cin >> N >> M;
    rep1(i,N) cin >> a[i];
    rep1(i,M) cin >> b[i];
    rep(i,N+3) dp[i][0] = i;
    rep(i,M+3) dp[0][i] = i;
    rep1(i,N) rep1(j,M) {
        int t = dp[i-1][j-1] + (a[i] != b[j]);
        updmin(t, dp[i-1][j] + 1);
        updmin(t, dp[i][j-1] + 1);
        dp[i][j] = t;
    }
    cout << dp[N][M] << newl;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int X(N); rep(i,N)cin>>X.at(i);
    vec_int primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    int ans = 1;
    rep(i,primes.size())ans*=primes.at(i);
    for(int i=0;i<(1<<primes.size());i++){
        int num = 1;
        int temp = 1;
        for(int j=0;j<primes.size();j++){
            if((i/temp)%2==1){
                num*=primes.at(j);
            }
            temp*=2;
        }
        int flag = 1;
        rep(j,N){
            if(__gcd(X.at(j), num)==1){
                flag = 0;
                break;
            }
        }
        if(flag == 1){
            ans = min(ans, num);
        }

    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

vll prm;

int main(){
  int ma=52;
  vi pp(ma,1);

  rep(i,2,ma){
    if(pp[i]){
      prm.pb(i);
      rep(j,i+i,ma){
        pp[j]=0;
        j+=i-1;
      }
    }
  }

  cii(n);
  reciv(v,n);

  ll ans=3e18;

  int m=sz(prm);
  int m2=1<<m;

  rep(bn,0,m2){
    ll now=1;
    rep(i,0,m)if(bn>>i&1)now*=prm[i];

    int f=1;
    rep(i,0,n)if(__gcd(now,v[i])==1)f=0;

    if(f)chmin(ans,now);
  }

  co(ans);
}


typedef long long ll;
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include <cstdlib>

using namespace std;

int main() {
    int a,b,x,y;
    cin >> a >> b >> x >> y;
    int ans = 0;

    if (b > a) {
        if (2*x < y) {
            ans = (b-a) * (2*x) + x;
        } else {
            ans = (b-a) * y + x;
        }
    } else {
        if (2*x < y) {
            ans = (a-b) * 2*x - x;
        } else {
            ans = (a-b-1) * y + x;
        }
    }
    if (b == a) {
        ans = x;
    }
    cout << ans << endl;

}

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

using ll = long long;
using ld = long double;

#define pii pair<int, int>

const int M = 100;
// int d[2 * M + 5];
vector<pii> adj[2 * M + 5];

void solve() {
  int a, b, x, y;
  cin >> a >> b >> x >> y;
  for (int i = 1; i <= 198; i++) {
    adj[i].emplace_back(i + 2, y);
    adj[i + 2].emplace_back(i, y);
  }
  for (int i = 1; i <= 199; i++) {
    adj[i].emplace_back(i + 1, x);
    adj[i + 1].emplace_back(i, x);
  }
  int start = 2 * a - 1;
  int end = 2 * b;

  priority_queue<pii, vector<pii>, greater<pii>> pq;
  vector<int> d(2 * M + 5, 2e9);
  d[start] = 0;
  pq.emplace(0, start);
  while(!pq.empty()) {
    int v = pq.top().second;
    int dv = pq.top().first;
    pq.pop();
    for (auto i : adj[v]) {
      int to = i.first;
      int dist = i.second;
      if (d[to] > d[v] + dist) {
        d[to] = d[v] + dist;
        pq.emplace(d[to], to);
      }
    }
  }
  cout << d[end] << '\n';
}

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

  int TC = 1;
  for(int i = 1; i <= TC; i++) {
    solve();
  }

  return 0;
}


#include <bits/stdc++.h>

#define FOR(i,x,n) 	for(int i=x; i<n; i++)
#define F0R(i,n) 	FOR(i,0,n)
#define ROF(i,x,n) 	for(int i=n-1; i>=x; i--)
#define R0F(i,n) 	ROF(i,0,n)

#define WTF 		cerr << "WTF" << endl

#define IOS 		ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define F 			first
#define S	 		second
#define pb 			push_back
#define mp 			make_pair

#define ALL(x) 		x.begin(), x.end()
#define RALL(x) 	x.rbegin(), x.rend()
#define FILL(a, b) 	memset(a, b, sizeof(a));

#define TOGGLE(x) (x) = 1 - (x)

using namespace std;
typedef double 			db;
typedef long long 		LL;
typedef string 			str;

typedef pair<int, int> 	PII;
typedef pair<LL, LL> 	PLL;

typedef vector<int> 	VI;
typedef vector<LL> 		VLL;
typedef vector<bool> 	VB;
typedef vector<char> 	VC;
typedef vector<PII> 	VPII;
typedef vector<PLL> 	VPLL;
typedef vector<string> 	VSTR;

typedef set<int> 		SI;
typedef set<PII> 		SPII;
typedef set<PLL> 		SPLL;

typedef priority_queue<PII> DIPQ;

const int MAXN = 2e5 + 7;
const int MAXA = 1e7 + 7;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int LOG = 20;
const LL LONG_INF = 1e18;

int n;
str inp;

void Solve () {
	cin >> n >> inp;
	if (inp[0] != inp[n - 1]) {
		cout << 1 << endl;
		return;
	}

	else {
		FOR (i, 1, n - 2) {
			if (inp[i] != inp[0] && inp[i + 1] != inp[0]) {
				cout << 2 << endl;
				return;
			}
		}
	}

	cout << -1 << endl;
}

int main() {
	IOS;
	Solve ();
}

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

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> min_rem(n+1, n);
    min_rem[n]=0;
    vector<int> ending_with_char(26, -1);
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            min_rem[i]=-1;
            ending_with_char[(int)(s.at(i)-'a')]=1;
        }
        else{
            min_rem[i]=n;
            for(int ch=0;ch<26;ch++){
                if(ch!=(int)(s.at(i)-'a')){
                    if(ending_with_char[ch]!=-1){
                        min_rem[i]=min(min_rem[i], ending_with_char[ch]);
                    }
                }
            }
            min_rem[i]=(min_rem[i]==n?-1:min_rem[i]);
            if(min_rem[i+1]!=-1){
                ending_with_char[(int)(s.at(i)-'a')]=min(ending_with_char[(int)(s.at(i)-'a')]==-1?n:ending_with_char[(int)(s.at(i)-'a')], min_rem[i+1]+1);
            }
        }
    }
    cout<<min_rem[0]<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vt vector
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
const int64_t MOD = 1000000007;

// 🚩
// 20201115 21:24~
//
int main()
{
    ll H, W;
    cin >> H >> W;
    vt<string> S(H);
    rep(y, H) cin >> S.at(y);

    vt<vt<ll>> dp(H, vt<ll>(W, 0));
    dp.at(0).at(0) = 1;

    vt<vt<ll>> X(H, vt<ll>(W)), Y(H, vt<ll>(W)), Z(H, vt<ll>(W));

    for (ll cy = 0; cy < H; cy++)
    {
        for (ll cx = 0; cx < W; cx++)
        {
            if (cx == 0 && cy == 0) continue;
            if (S.at(cy).at(cx) == '#') continue;

            // o(4*10^6)
            if (cx > 0) X.at(cy).at(cx) = (X.at(cy).at(cx - 1) + dp.at(cy).at(cx - 1)) % MOD;
            if (cy > 0) Y.at(cy).at(cx) = (Y.at(cy - 1).at(cx) + dp.at(cy - 1).at(cx)) % MOD;
            if (cx > 0 && cy > 0) Z.at(cy).at(cx) = (Z.at(cy - 1).at(cx - 1) + dp.at(cy - 1).at(cx - 1)) % MOD;
            dp.at(cy).at(cx) = (X.at(cy).at(cx) + Y.at(cy).at(cx) + Z.at(cy).at(cx)) % MOD;
            // //右
            // for (ll i = 1; i <= W - 1 - cx; i++)
            // {
            //     if (S.at(cy).at(cx + i) == '#') break;
            //     dp.at(cy).at(cx + i) = (dp.at(cy).at(cx + i) + dp.at(cy).at(cx)) % MOD;
            // }
            // //右下
            // for (ll i = 1; i <= min(H - 1 - cy, W - 1 - cx); i++)
            // {
            //     if (S.at(cy + i).at(cx + i) == '#') break;
            //     dp.at(cy + i).at(cx + i) = (dp.at(cy + i).at(cx + i) + dp.at(cy).at(cx)) % MOD;
            // }
            // //下
            // for (ll i = 1; i <= H - 1 - cy; i++)
            // {
            //     if (S.at(cy + i).at(cx) == '#') break;
            //     dp.at(cy + i).at(cx) = (dp.at(cy + i).at(cx) + dp.at(cy).at(cx)) % MOD;
            // }
        }
    }
    cout << dp.at(H - 1).at(W - 1) << endl;
}

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

using namespace std;
using ll = long long;
int f(int N, int K) {
    if (K < 2 || K > 2 * N) return 0;
    return min(K - 1, 2 * N + 1 - K);
}

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

    int N;
    cin >> N;
    int K;
    cin >> K;

    ll output = 0LL;
    for (int ab = 2; ab <= 2 * N; ab++) {
        output = output + (ll)f(N, ab) * f(N, ab - K);
    }
    cout << output << endl;

    return 0;
}


/**
*    author:  tomo0608
*    created: 27.03.2021 21:12:02
**/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
#endif

typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class... T>void input(T&... a){(cin >> ... >> a);};
#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define STRING(...) string __VA_ARGS__; input(__VA_ARGS__)
void print(){cout << '\n';}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';}
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

void solve(){
    INT(n);
    V<ll> a(n);cin >> a;
    ll ans = 0;
    rep(i,n)ans |= a[i];
    //print(ans);
    rep(i,1<<(n-1)){
        if(i == 0)continue;
        ll tmp = 0, now = a[0];
        rep(j,n-1){
            if(bit(i,j)){
                tmp ^= now;
                now = a[j+1];
            }else{
                now |= a[j+1];
            }
        }
        tmp ^= now;
        //print(tmp);
        chmin(ans,tmp);
    }
    print(ans);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while(codeforces--){
        solve();
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ansmin = (1 << 30);
  for (int tmp = 0; tmp < (1 << n-1); ++tmp) {
    bitset<19> s(tmp);
    //cout << tmp << endl;
    queue<int> q;
    int x = a[0];
    //cout << x;
    for (int i = 0; i < n-1; ++i) {
      if (s[i]) {
        //cout << '^' << a[i+1];
        q.push(x);
        x = a[i+1];
      } else {
        //cout << '|' << a[i+1];
        x = x | a[i+1];
      }
    }
    //cout << endl;
    q.push(x);
    int ans = 0;
    while (!q.empty()) {
      int y = q.front();
      //cout << ans << '^' << y << endl;
      ans = ans ^ y;
      q.pop();
    }
    //cout << ans << endl;
    ansmin = min(ansmin, ans);
  }
  cout << ansmin << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <climits>
using namespace std;
typedef long long unsigned int unsigned_myint;
typedef long long int myint;

int main(){
 int A,B,S[3],T[3],a,b;
 cin >> A;
 cin >> B;

S[0]=A/100;
S[1]=(A-S[0]*100)/10;
S[2]=(A-S[0]*100-S[1]*10);
T[0]=B/100;
T[1]=(B-T[0]*100)/10;
T[2]=(B-T[0]*100-T[1]*10);

a=S[0]+S[1]+S[2];
b=T[0]+T[1]+T[2];

if(a<b){
    cout << b<< endl;
}else{
    cout << a <<endl;
}

}

#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define x first
#define y second
using namespace std;

int main(){
string a,b;
cin>>a>>b;
int a1=a[0]+a[1]+a[2]-'0'-'0'-'0';
int b1=b[0]+b[1]+b[2]-'0'-'0'-'0';
cout<<max(a1,b1);
return 0;
}


#include <bits/stdc++.h>
/*#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <sstream>*/

#define ll long long
#define fop(i,m,n) for(int i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

using namespace std;

const long long MOD = 1e9+7;
const long long N = 2e5+5;
const long long Nlog = 17;
const long long Hash = 257;

const double PI = 2.0*acos(0.0);//<cmath>
//const double PI = 3.141592653;
const double E = 2.718281828;

struct DSU{
    int p[N+1];
    void init(int n){
        fop(i,1,n+1) p[i] = i;
    }
    int Find(int x){
        if(x == p[x]) return x;
        else{
            p[x] = Find(p[x]);
            return p[x];
        }
    }
    void Union(int x, int y){
        p[Find(x)] = Find(y);
    }
}dsu;

void solve(){

    int n;
    cin >> n;
    int a[n];
    fop(i,0,n) cin >> a[i];

    dsu.init(N);
    int ans = 0;
    fop(i,0,n/2){
        if(a[i] != a[n-1-i]){
            if(dsu.Find(a[i]) != dsu.Find(a[n-1-i])){
                ans++;
                dsu.Union(a[i], a[n-1-i]);
            }

        }
    }

    cout << ans << '\n';

}

int main()
{
    fastIO;

    int t=1;
    //cin >> t;
    while(t--) solve();

    return 0;
}

#include <bits/stdc++.h>
#define ll long long

#define t     \
    ll t;     \
    cin >> t; \
    while (t--)
#define ln "\n"

#define fst                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define F(i, L, R) for (int i = L; i < R; i++)

#define FE(i, L, R) for (int i = L; i <= R; i++)

#define FF(i, L, R) for (int i = L; i > R; i--)

#define FFE(i, L, R) for (int i = L; i >= R; i--)

#define mod 1000000007

#define DBG(vari) cerr << #vari << " = " << (vari) << endl

using namespace std;
vector<int>v[200001];
bool vis[200001];
int ans=0;
void dfs(int node)
{
    vis[node]=1;
    ans++;
    for(auto child:v[node])
    {
        if(vis[child]==0&&v[child].size()!=0)
        {
            dfs(child);
        }
    }

}
void solve()
{
    ll n;
    cin>>n;
    int arr[n+3];
    F(i,0,n)cin>>arr[i];

    int i=0,j=n-1;
    while(i<j)
    {
        if(arr[i]!=arr[j])
        {
            v[arr[i]].push_back(arr[j]);
            v[arr[j]].push_back(arr[i]);
        }
        i++;
        j--;
    }
    for(int k=0; k<n; k++)
    {
        if(v[arr[k]].size()!=0&&vis[arr[k]]==0)
        {
            dfs(arr[k]);
            ans--;
        }
    }
    cout<<ans<<ln;

}

int main()
{
    fst

    solve();
}


#include <bits/stdc++.h>
using namespace std;
template<typename T> using vec = vector<T>;
template<typename K, typename V> using umap = unordered_map<K, V>;
using ll = long long;
using ld = long double;
using str = string;
using pll = pair<ll, ll>;
using vll = vec<ll>;
using vi = vec<int>;
using vs = vec<str>;
using mapll = map<ll, ll>;
using umapll = umap<ll, ll>;
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, l, r) for (ll i = ll(l); i < ll(r); i++)
#define _get_rep(_1, _2, _3, NAME, ...) NAME
#define rep(...) _get_rep(__VA_ARGS__, _repi, _rep) (__VA_ARGS__)
#define rrep(i, n) for (ll i = ll(n) - 1; 0 <= i; i--)
#define each(v) for (auto v)
#define all(x) x.begin(), x.end()
#define mkpair make_pair
#define is_in(x, l, r) ((l) <= (x) && (x) < (r))
#define read(t, ...) t __VA_ARGS__; isin(cin, __VA_ARGS__)
#define readv(t, v, n) vec<t> v(n); isin(cin, v)
#define readv2(t, v, h, w) vec<vec<t>> v(h, vec<t>(w)); isin(cin, v)
#define readvv(t, va, vb, n) vec<t> va(n), vb(n); rep (i, n) { isin(cin, va[i], vb[i]); }
#define readvvv(t, va, vb, vc, n) vec<t> va(n), vb(n), vc(n); rep (i, n) { isin(cin, va[i], vb[i], vc[i]); }
#define print(...) osout(cout, __VA_ARGS__)
#define dbg(...) osout(cerr, __VA_ARGS__)
const ll inf = numeric_limits<ll>::max() / 2;
template<typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return 1; } return 0; }
template<typename T> void sort(vec<T> &v) { sort(all(v)); }
template<typename T> void rsort(vec<T> &v) { sort(all(v), greater<T>()); }
template<typename T> void dec(vec<T> &v) { rep (i, v.size()) v[i]--; }
template<typename T> istream& operator >>(istream &is, vec<T> &v) {
    rep (i, v.size()) { cin >> v[i]; } return is;
}
template<typename T1, typename T2> ostream& operator <<(ostream &os, pair<T1, T2> p) {
    if (&os == &cout) { os << p.first << ' ' << p.second; }
    if (&os == &cerr) { os << '(' << p.first << ", " << p.second << ')'; }
    return os;
}
template<typename T> ostream& operator <<(ostream &os, vec<T> v) {
    if (&os == &cout) { rep(i, v.size() - 1) { os << v[i] << ' '; } os << v[v.size() - 1]; }
    if (&os == &cerr) { os << '['; rep(i, v.size() - 1) { os << v[i] << ", "; } os << v[v.size() - 1] << ']'; }
    return os;
}
void isin(istream &_) {}
template<class S, class... T> void isin(istream &is, S &s, T&... t) {
    is >> s; isin(is, t...);
}
void osout(ostream& os) { os << endl; }
template<class S, class... T> void osout(ostream &os, S s, T... t) {
    os << s; if (sizeof...(t)) os << ' '; osout(os, t...);
}
void solve();

int main() {
    #define PRECISION 0

    cin.tie(0);
    ios::sync_with_stdio(false);
    if (PRECISION) {
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
    solve();
    return 0;
}

void solve() {
  read(ll,N,C);
  readvvv(ll,a,b,c,N);

  vll d;
  umapll m;
  rep(i,N) {
    d.emplace_back(a[i]), d.emplace_back(b[i]+1);
    m[a[i]]+=c[i], m[b[i]+1]-=c[i];
  }
  sort(d);
  d.erase(unique(all(d)),d.end());
  ll e=d.size();

  vll s(e+1);
  rep(i,e) s[i+1]=s[i]+m[d[i]];

  ll ans=0;
  rep(i,e-1){
    ans+=min(s[i+1],C)*(d[i+1]-d[i]);
  }
  print(ans);
}

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

int main()
{
	int N;
	long long C;
	cin >> N >> C;
	map<long long, long long> mp;
	for( int i = 0; i < N; i++ ) {
		long long a, b, c;
		cin >> a >> b >> c;
		b++;
		mp[a] += c;
		mp[b] -= c;
	}

	long long ans = 0;
	long long cost = 0;
	long long prev = 0;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		long long n = it->first - prev;
		ans += min( C, cost ) * n;
		cost += it->second;
		prev = it->first;
	}

	cout << ans << endl;
}


/**

▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
 In the name of Allah

       _           _
      / /         \ \
     / / _   _   _ \ \
    < < (_) (_) (_) > >
     \ \           / /
      \_\         /_/

  Nerede Gitsen Çukur Orda

**/

#include<bits/stdc++.h>
#include<fstream>
///#include<conio.h>
///#include "windows.h"
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define Qodirov_Kamoliddin ios_base::sync_with_stdio(0) ; cin.tie(NULL) ; cout.tie(NULL) ;
#define p_b pop_back
#define p_f pop_front
#define quluq return 0;
#define NO cout << "NO" << endl ;
#define no cout << "no" << endl ;
#define YES cout << "YES" << endl ;
#define yes cout << "yes" << endl ;

using namespace std ;

    const ll N = 1e9 + 7 ;

ll n , k , cnt , ans , sum ;

void vkoshp()
{
    cin >> n ;
    cnt = n % 100 ;
    ans = 100 - cnt ;
    cout << ans << endl ;
}

int main ()
{
    /*
    freopen("input.txt", "r", stdin );
    freopen("output.txt", "w", stdout );
    */
    Qodirov_Kamoliddin
    ///Author of the Greatest code : Murtazoev Alijon
    ///4294967295
    ll Qu_l_uQ = 1 ;
    // cin >> Qu_l_uQ ;
    while ( Qu_l_uQ -- )
        vkoshp() ;
}
///MaaN studios
///Eco students

#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define ll long long

void fillPrefixSum(int arr[], int n, int prefixSum[]) // a[i-1,j-1] = a[j-1] - a[i-2];
{
    prefixSum[0] = arr[0];
    // Adding present element
    // with previous element
    for (int i = 1; i < n; i++)
        prefixSum[i] = prefixSum[i - 1] + arr[i];
}

void solve()
{
    ll n;
    cin >> n;
    ll sum = 0;
    for (ll i = 1; i <= n; i++)
    {
        sum += i;
        if (sum >= n)
        {
            cout << i << endl;
            return;
        }
    }
}

int main()
{
    fast

        int t = 1;
    //	cin >> t;
    while (t--)
    {

        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

struct state_t {
  ll time;
  ll place;
};

#define INF 1000000001

ll solve(vector<ll> X, vector<int> C) {
  size_t N = X.size();
  // balls[C] = {X1, X2, ...}
  map<int, vector<ll>> balls;

  for (size_t i = 0; i < N; i++) {
    if (balls.count(C[i]) == 0) {
      balls[C[i]] = {};
    }
    balls[C[i]].push_back(X[i]);
  }
  balls[INF].push_back(0);

  vector<state_t> states{{0, 0}};
  for (auto &&p : balls) {
    vector<ll> ball_places = p.second;
    sort(ALL(ball_places));

    if (ball_places.size() == 1) {
      if (states.size() == 1) {
        state_t s = {states[0].time + abs(states[0].place - ball_places[0]),
                     ball_places[0]};
        states[0] = s;
      } else {
        vector<state_t> sv;
        for (auto &&s : states) {
          sv.push_back(
              {s.time + abs(s.place - ball_places[0]), ball_places[0]});
        }

        states = sv;
      }
    } else {
      vector<state_t> sv;

      ll left = ball_places[0];
      ll right = ball_places.back();

      for (auto &&s : states) {
        if (s.place <= left) {
          sv.push_back({s.time + abs(s.place - right), right});
        } else if (s.place >= right) {
          sv.push_back({s.time + abs(s.place - left), left});
        } else {
          sv.push_back({s.time + abs(s.place - right) + (right - left), left});
          sv.push_back({s.time + abs(s.place - left) + (right - left), right});
        }
      }
      states = sv;
    }

    // trim
    sort(ALL(states),
         [](state_t &s1, state_t &s2) { return s1.time < s2.time; });
    size_t n = (states.size() + 9) / 10;
    set<size_t> delete_i_s;
    for (size_t i = 0; i < n; i++) {
      for (size_t j = n; j < states.size(); j++) {
        if (states[j].time - states[i].time >
            abs(states[j].place - states[i].place)) {
          delete_i_s.insert(j);
        }
      }
    }
    vector<size_t> delete_i_v(ALL(delete_i_s));
    for (int i = delete_i_v.size() - 1; i >= 0; i--) {
      states.erase(states.begin() + delete_i_v[i]);
    }
  }

  sort(ALL(states), [](state_t &s1, state_t &s2) { return s1.time < s2.time; });
  return states[0].time;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<ll> X(N);
  vector<int> C(N);

  for (size_t i = 0; i < N; i++) {
    cin >> X[i] >> C[i];
  }

  // main procedure

  // output
  cout << solve(X, C) << endl;

  return 0;
}


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

#define int long long
#define MS(x) memset((x), -1, sizeof((x)))
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; }
#define MOD 1000000007

int k;
string s;

int memo[200010][17][17];

int dp(int i, int j, int k){
	if(i == 0){
		return j == 0 ? 1 : 0;
	}
	if(~memo[i][j][k]) return memo[i][j][k];

	int ans = 0;
	if(j > 0){
		ans += dp(i-1, j-1, k)*(16-(k+j-1)) % MOD;
	}
	ans += dp(i-1, j, k)*(j+k) % MOD;
	return memo[i][j][k] = ans%MOD;
}

signed main(){
	cin >> s >> k;
	int n = s.size();

	int used[512] = {};
	int cnt = 0;
	int ans = 0;

	string moji = "0123456789ABCDEF";

	MS(memo);

	for(int i = 0;i < n;i++){
		int tmp = 0;
		int j;
		for(j = 0;moji[j] != s[i];j++){
			tmp += used[moji[j]];
		}
		int rnum = n-i-1;
		if(i > 0){
			ans += dp(rnum, k-1, 1)*15%MOD;
			ans %= MOD;
		}
		if(j != 0){
			if(tmp != j && cnt+1 <= k){
				if(i == 0){
					ans += dp(rnum, k-1, 1)*(j-1)%MOD;
				}else{
					ans += dp(rnum, k-(cnt+1), cnt+1)*(j-tmp)%MOD;
				}
				ans %= MOD;
			}
			if(cnt > 0 && cnt <= k){
				ans += dp(rnum, k-cnt, cnt)*tmp % MOD;
				ans %= MOD;
			}
		}
		if(used[s[i]] == 0){
			used[s[i]] = 1;
			cnt++;
		}
	}

	if(cnt == k) ans = (ans+1) % MOD;

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
string num;
int rn[200005];
int k;
int n;
int dp[200005][20];
ll dfs(int x,ll now,bool zero,bool flag)
{
    int cnt=0;
    for(int i=0;i<16;i++)
    {
        if(now&(1<<i))cnt++;
    }
    if(x>=n)return cnt==k;
    if(cnt>k)return 0;
    if(!flag&&zero&&dp[x][cnt]!=-1)return dp[x][cnt];
    ll ans=0;
    int lim=flag?rn[x]:15;
    for(int i=0;i<=lim;i++)
    {
        int tmp;
        if(!zero&&i==0)tmp=now;
        else tmp=now|(1<<i);
        ans+=dfs(x+1,tmp,zero||(i!=0),flag&&(i==lim));
        ans%=mod;
    }
    if(!flag&&zero)dp[x][cnt]=ans;
    return ans;
}
int main()
{
    cin>>num>>k;
    n=num.size();
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
    {
        if(num[i]>='0'&&num[i]<='9')rn[i]=num[i]-'0';
        else rn[i]=num[i]-'A'+10;
    }
    printf("%lld\n",dfs(0,0,0,1));
    return 0;
}


#include <bits/stdc++.h>

#define debug(var)  do{std::cout << #var << " :";std::cout << std::endl;view(var);}while(0)
template<typename T> void view(T e){ std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){ int c = v.size(); std::cout << "{"; for(const auto& e : v){ std::cout << e; if (--c) std::cout << ", "; } std::cout << "}" << std::endl; }
template<typename T, typename U> void view(const std::pair<T, U>& v){ std::cout << v.first << ", " << v.second << std::endl; }
template<typename T> void view(const std::set<T>& v){ int c = v.size(); std::cout << "{"; for(const auto& e : v){ std::cout << e; if (--c) std::cout << ", "; } std::cout << "}" << std::endl; }
template<typename T, typename U> void view(const std::map<T, U>& v){ std::cout << "{" << std::endl; for(const std::pair<T, U>& e : v){ std::cout << e.first << ", " << e.second << std::endl; } std::cout << "}" << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cout << "{" << std::endl; for(const auto& v : vv){ view(v); } std::cout << "}" << std::endl; }

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pii;
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 long long INF = 1LL << 60;
const long long MOD = 1000000007;
const double PI = acos(-1);

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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <string>
#include <time.h>
#include <assert.h>
#include <deque>
//#include <unordered_map>
#define ls k*2
#define rs k*2+1
#define int long long
using namespace std;
typedef long long ll;
const int maxn=2e6+50;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
const double eps=1e-6;
const int HASH=131;
using namespace std;

int a[maxn];

signed main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c*2)
    {
        cout<<"Yes"<<endl;
        return 0;
    }

    if(a+c==b*2)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    if(c+b==a*2)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define asd cout << "ok" << endl;
#define trav(i, n) for(int i= 0; i <n; i++)

const char nl = '\n';
const int maxN = 2e5 + 4;
int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
   int a, b, c ,d; cin >> a >> b >> c >> d;
   int ans = 0;
   if(c*d <= b){
    cout << -1;
    return 0;
   }
   cout << (a -1 + d*c -b)/ (d*c - b) << nl;
}

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

int main(){
  int a,s,d;
  int g,h=0;
  cin >> a>>s>>d;
  vector<int>f(a);
  for(int i=0;i<a-1;i++){
    cin>>g;
    h=h+g;
  }
  g=d*a-h;
  if(d*a-h<0)g=0;
  if(d*a-h<=s)  cout <<g;
  else if(d*a-h>s)  cout <<-1;

}


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

int main() {
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    int t;
    t =min(2 * x, y);
    int t1;
    a = 2 * a;
    b = 2 * b + 1;
    t1 = abs(a - b);
    cout << t1 / 2 * t + t1 % 2 * x << endl;
}

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())

typedef long long ll;typedef vector<int> vi;
typedef pair<int,int> ii;typedef vector<ii> vii;
typedef vector<vi> vvi;

const int N = 220;
vi adj[N];
vi adw[N];
int dis[N],vis[N];

void add(int a,int b,int w){
	adj[a].pb(b);adw[a].pb(w);
	adj[b].pb(a);adw[b].pb(w);
}

signed main(){
	IOS
	int a,b,x,y;cin>>a>>b>>x>>y;
	a--;b--;
	forn(i,N) dis[i]=INT_MAX;
	for(int i=0;i<100;i++){
		add(i,i+100,x);
		if(i){
			add(i,i-1,y);
			add(i+100,i-1+100,y);
			add(i,i-1+100,x);
		}
	}
	priority_queue<ii,vii,greater<ii>> pq;
	dis[a]=0;
	pq.push({0,a});
	while(!pq.empty()){
		ii u = pq.top();pq.pop();
		if(vis[u.y]) continue;
		dis[u.y]=u.x;vis[u.y]=1;
		forn(i,sz(adj[u.y])){
			int v = adj[u.y][i];
			int w = adw[u.y][i];
			if(vis[v]) continue;
			pq.push({u.x+w,v});
		}
	}
	cout<<dis[b+100]<<"\n";
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    REP(i, 0, H) cin >> S[i];

    int tot = 0;
    vector<vector<int>> R(H, vector<int>(W, 0)), C(H, vector<int>(W, 0));
    REP(i, 0, H) REP(j, 0, W) {
        if (S[i][j] == '#') continue;
        R[i][j] = 1 + ((j > 0) ? R[i][j - 1] : 0);
        C[i][j] = 1 + ((i > 0) ? C[i - 1][j] : 0);
        tot++;
    }
    REP(i, 0, H) for (int j = W - 1; j > 0; j--) if (R[i][j] && R[i][j - 1]) R[i][j - 1] = R[i][j];
    REP(j, 0, W) for (int i = H - 1; i > 0; i--) if (C[i][j] && C[i - 1][j]) C[i - 1][j] = C[i][j];

    mint ans = 0;
    REP(i, 0, H) REP(j, 0, W) {
        if (S[i][j] == '#') continue;
        // cout << "#(" << i << "," << j << ") : " << R[i][j] << ", " << C[i][j] << endl;
        int cnt = R[i][j] + C[i][j] - (R[i][j] && C[i][j]);
        ans += (mint(2).pow(cnt) - 1) * mint(2).pow(tot - cnt);
    }
    cout << ans << endl;

    return 0;
}

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

#define MOD 1000000007
//https://flex.phys.tohoku.ac.jp/~maru/implementations/exponentiation_squaring.php
long long pow(long long a, long long n, long long m) {
    long long ret = 1;
    for (; n > 0; n >>= 1, a = a * a % m) {
        if (n % 2 == 1) {
            ret = ret * a % m;
        }
    }
    return ret;
}

int main() {
    long long H,W;
    long long ans=0;
    long long dot=0;
    cin>>H>>W;
    string S[H];
    long long r[H][W];
    long long l[H][W];
    long long u[H][W];
    long long d[H][W];
    for(long long i=0;i<H;i++){
        cin>>S[i];
    }

    for(long long i=0;i<H;i++){
        for(long long j=0;j<W;j++){
            if(S[i][j]=='.') dot++;
        }
    }

    for(long long i=0;i<H;i++){
        long long c=0;
        for(long long j=0;j<W;j++){
            if(S[i][j]=='.') c++;
            else c=0;
            r[i][j]=c;
        }
    }

    for(long long i=0;i<H;i++){
        long long c=0;
        for(long long j=W-1;j>=0;j--){
            if(S[i][j]=='.') c++;
            else c=0;
            l[i][j]=c;
        }
    }

    for(long long j=0;j<W;j++){
        long long c=0;
        for(long long i=0;i<H;i++){
            if(S[i][j]=='.') c++;
            else c=0;
            d[i][j]=c;
        }
    }

    for(long long j=0;j<W;j++){
        long long c=0;
        for(long long i=H-1;i>=0;i--){
            if(S[i][j]=='.') c++;
            else c=0;
            u[i][j]=c;
        }
    }

    for(long long i=0;i<H;i++){
        for(long long j=0;j<W;j++){
            if(S[i][j]=='.'){
                long long dot2=r[i][j]+l[i][j]+u[i][j]+d[i][j]-3;
                long long a=(pow(2,dot2,MOD)-1)%MOD;
                while(a<0) a+=MOD;
                long long b=pow(2,dot-dot2,MOD);
                //cout<<i<<","<<j<<"---"<<dot<<","<<dot2<<"---"<<a<<","<<b<<endl;
                ans+=a*b%MOD;
                ans%=MOD;
            }
        }
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        ans %= mod;
        a = a * a;
        a %= mod;
        b >>= 1;
    }
    return ans % mod;
}

struct UnionFind {
    vector<ll> par;
    vector<ll> rank;
    vector<ll> Size;
    UnionFind(ll n) {
        init(n);
    }

    void init(ll n) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        rep0(i, n + 1){
            par[i] = i;
            rank[i] = 0;
            Size[i] = 1;
        }
    }

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

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

    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

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

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    vl cnt(400001,0);
    UnionFind u(400001);
    rep0(i, n){
        ll a,b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
        u.merge(a, b);
    }
    rep0(i, 400001)if(u.root(i) != i)cnt[u.root(i)] += cnt[i];
    ll ans = 0;
    vector<bool> f(400001,false);
    rep0(i, 400001){
        if(u.root(i) != i)continue;
        if(u.size(i) >= cnt[i] / 2)ans += cnt[i] / 2;
        else ans += u.size(i);
    }
    pf(ans);
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define int long long
vector<vector<int>> adj;
vector<int> vis;
vector<int> sel;
int cnt, nn, edges;
void dfs(int root, int parent) {
	vis[root] = 1;
	cnt++;
	edges += sel[root];
	for (auto i : adj[root]) {
		if (!vis[i]) {
			//cout << i << " ";
			dfs(i, parent);
		}
	}
}

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

	set<int> s;
	int n;
	cin >> n;
	vector<pair<int, int>> v;
	int t = 1;
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (a > b)swap(a, b);
		v.push_back(make_pair(a, b));
		if (m[a] == 0) {
			m[a] = t;
			t++;
		}
		if (m[b] == 0) {
			m[b] = t;
			t++;
		}
		s.insert(a);
		s.insert(b);
	}

	nn = s.size();
	adj = vector<vector<int>>(nn);
	vis = vector<int> (nn, 0);
	sel = vector<int> (nn, 0);
	for (int i = 0; i < n; i++) {
		int a = v[i].first, b = v[i].second;
		adj[m[a] - 1].push_back(m[b] - 1);
		adj[m[b] - 1].push_back(m[a] - 1);
		sel[m[a] - 1]++;
	}
	int best = 0;
	for (int i = 0; i < nn; i++) {
		if (!vis[i]) {
			//cout << i << "\n";
			edges = 0;
			cnt = 0;
			dfs(i, i);
			//cout << edges << "\n";
			best += max(min(cnt, edges), 1ll);
		}
	}
	cout << best << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
#define ll long long

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

long long my_ceil(long long a, long long b){
    return (a + b - 1)/b;
}

void test_case(){
    ll x, y, a, b;
    cin >> x >> y >> a >> b;

    int n = 0;
    long long ans = INT_MIN;
    while(true){
        if(n*log(a) + log(x) - log(y) < 1e-18){
            ans = max(ans, n - 1 + my_ceil(y - (long long)binpow(a, n)*x, b));
            n += 1;
        }else{
            break;
        }
    }

    cout << ans << endl;

}

int main(){

    int t = 1;
    //cin >> t;
    for(int i = 0; i < t; i++)
        test_case();

    return 0;
}

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

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

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

const double eps = 1e-10;

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

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

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

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

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

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

  int64 N;
  cin >> N;
  vector<int64> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];
  int64 res = 0;
  REP(i, N) {
    res += (A[i] + B[i]) * (B[i] - A[i] + 1) / 2;
  }
  cout << res << endl;
}


#include<bits/stdc++.h>

#define ll long long
#define int long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

using namespace std;

//------------------------------------------------------------------------------
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
ll __ceil(ll a,ll b)
{
            return (a+b-1)/b;
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
     prime[1]=false;
     prime[0]=false;
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout<<p<<" ";
}
//------------------------------------------------------------------------------

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

          int t=1;
          //cin>>t;
          while(t--)
          {
                    int c;
                    cin>>c;
                    if(c>=0)
                         cout<<c;
                    else
                         cout<<0;
          }
          return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, ans;
	cin >> n;
	if (n >= 0) {
		ans = n;
	}
	else {
		ans = 0;
	}
	cout << ans << "\n";
	// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(size_t i = (l); i < (r); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; --i)
#define rfor(v, vec) for(auto &v : (vec))
#define itrloop(itr, begin, end) for(auto itr = (begin); itr != end; ++itr)
#define crfor(v, vec) for(const auto &v : (vec))
#define all(x) x.begin(), x.end()
#define call(x) x.cbegin(), x.cend()
#define rall(x) x.rbegin(), x.rend()
#define ull unsigned long long
#define ll long long
#define ul unsigned long

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
    long long T;
    scanf("%lld", &T);
    std::vector< long long > cs(T);
    for(int i = 0; i < T; i++) {
        scanf("%lld", &cs[i]);
    }
    crfor(c, cs) {
        if(c % 2 == 1)
            cout << "Odd" << endl;
        else if(c % 4 == 0)
            cout << "Even" << endl;
        else
            cout << "Same" << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define for0(i, n) for (int i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (ll)(n); ++i)
#define forc(i, l, r) for (int i = (ll)(l); i <= (ll)(r); ++i)
#define forr0(i, n) for (int i = (ll)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (ll)(n); i >= 1; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) ll((a).size())
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

void fast()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool prime[1000001];
void sieve()
{
  memset(prime, true, sizeof(prime));
  prime[1]=false;
  for (int p=2; p*p<=1000000; p++)
  {
    if (prime[p] == true)
    {
        for (int i=p*p; i<=1000000; i += p)
                prime[i] = false;
    }
  }
}

void solve()
{
    ll n;
    cin >> n;
    if(n%2==1)cout << "Odd\n";
    else if((n-2)%4==0)cout << "Same\n";
    else cout << "Even\n";
}
int main()
{
  fast();
  ll t;
  cin >> t;
  while(t--)
  solve();

return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

/* #define MULTI 1 */

void pre()
{
}

void solve()
{
	int n, m; cin >> n >> m;
	int a[1500005]; for (int i = 0; i < n; ++i) cin >> a[i];
	int cnt[1500005] = {}; for (int i = 0; i < m; ++i) ++cnt[a[i]];
	priority_queue<int, vector<int>, greater<int>> pq;
	for (int i = 0; i < n; ++i) if (cnt[i] == 0) pq.push(i);
	pq.push(n);

	int ans = pq.top();
	for (int i = 0; i + m < n; ++i) {
		--cnt[a[i]];
		if (cnt[a[i]] == 0) pq.push(a[i]);
		++cnt[a[i + m]];
		while (cnt[pq.top()] > 0) pq.pop();
		ans = min(ans, pq.top());
	}
	cout << ans << endl;
}

int main()
{
	pre();
#ifdef MULTI
	int T;
	cin >> T;
	for (int t = 0; t < T; ++t) {
#endif
		solve();
#ifdef MULTI
	}
#endif
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
char s[11][11];
int ans;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<n;i++){
		int use=0;
		for(int j=1;j<=m;j++){
			if(s[i][j]!=s[i+1][j]){
				if(use==0) ans++;
				use=1;
			} 	else use=0;
		}
	}
	for(int j=1;j<m;j++){
		int use=0;
		for(int i=1;i<=n;i++)
			if(s[i][j]!=s[i][j+1]){
				if(use==0) ans++;
				use=1;
			} 	else use=0;
		}
	cout<<ans;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<optional>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#pragma GCC optimize("Ofast")
namespace gengar
{
	using namespace std;
	#define int long long
	#define itn int
	#define uint unsigned long long
	#define ld long double
	#define vt(tp) vector<tp>
	#define vvt(tp) vector<vector<tp>>
	#define vvt2(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n))
	#define P pair<int,int>
	#define hmap unordered_map
	#define hset unordered_set
	#define all(x) x.begin(),x.end()
	#define nsort(x) sort(all(x))
	#define rsort(x) nsort(x);reverse(all(x))
	#define unq(v) v.erase(unique(all(v)),v.end())
	#define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x)))
	#define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x)))
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define eb emplace_back
	#define spc ' '
	#define pass
	#define _overload3(_1,_2,_3,name,...) name
	#define _rep(i,n) repi(i,0,n)
	#define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++)
	#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
	#define _daolrevo3(_1,_2,_3,name,...) name
	#define _per(i,n) peri(i,n,0)
	#define peri(i,a,b) for(int i=(a),__SIZE##_=(b);i>=__SIZE##_;i--)
	#define per(...) _daolrevo3(__VA_ARGS__,peri,_per,)(__VA_ARGS__)
	#define Bit(n) (1LL<<(n))
	#define myceil(a,b) ((a)+((b)-1))/(b)
	#define scale(n) cout<<fixed<<setprecision(n)
	using i64=int64_t;
	using u64=uint64_t;
	template<class T>using PQ=priority_queue<T,vt(T),greater<T>>;
	void in(){}
	template<class Car,class...Cdr>
	void in(Car&&car,Cdr&&...cdr){cin>>car;in(forward<Cdr>(cdr)...);}
	template<class T>void drop(T x){cout<<(x)<<endl;exit(0);}
	void dYes(){puts("Yes");exit(0);}
	void dNo(){puts("No");exit(0);}
	int gcd(int a,int b){return b?gcd(b,a%b):a;}
	int lcm(int a,int b){return a/gcd(a,b)*b;}
	int fact(int n,int m){int f=n;for(int i=n-1;i>=1;i--){f*=i;f%=m;}return f;}
	template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;}
	template<class T>int chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
	const int inf=Bit(60);
	const double pi=acos(-1);
	const int mod=1000000007;//998244353
};
using namespace gengar;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;cin>>n;
	int sum=0;
	for(int a;cin>>a;)sum+=max(0LL,a-10);
	cout<<sum<<endl;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

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

}


    #include <bits/stdc++.h>

    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/rope>
    // #include <ext/pb_ds/tree_policy.hpp>
    // #include <ext/pb_ds/trie_policy.hpp>
    // using namespace __gnu_pbds;
    // using namespace __gnu_cxx;
    // typedef tree<long long, null_type, std::less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
    // typedef trie<std::string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>Trie;

    using namespace std;
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(),(x).end()
    #define fi first
    #define se second
    #define sz(x) ((int)(x).size())
    #define rdv(x) long long x; cin>>x;
    #define deb(x) cout<<#x<<"="<<x<<endl;
    #define inf 1e18
    #define endl "\n"

    typedef vector<long long> vll;
    typedef long long ll;
    typedef pair<long long,long long> pii;
    typedef long double ld;
    mt19937 mrand(random_device{}());
    const ll mod=1000000007;
    int rnd(int x) { return mrand() % x;}
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    bool prime[200001];
    void SieveOfEratosthenes()
    {
        memset(prime, true, sizeof(prime));
        prime[1]=false;
        for (int p=2; p*p<=200000; p++)
        {
            if (prime[p] == true)
            {
                for (int i=p*p; i<=200000; i += p)
                    prime[i] = false;
            }
        }
        return;
    }

    ll ceil(ll x,ll y)
    {
        ll ans=x/y;
        if(x%y)
            ans++;

        return ans;
    }

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

    void solve()
    {
        ll n,k;
        cin>>n>>k;

        vll arr(n);
        rep(i,0,n)
        {
            cin>>arr[i];
        }

        map<ll,ll>mp;

        set<ll> s;
        for (int i = 0; i <= n; i++)
        s.insert(i);

    for (int i = 0; i < k; i++)
        {s.erase(arr[i]);
            mp[arr[i]]++;
         }
    ll mex = *(s.begin());
    //deb(mex)

    // for(auto it:s)
    // {
    //     deb(it)
    // }
    for (int i = k; i < n; i++) {

        mp[arr[i]]++;
         mp[arr[i-k]]--;

        s.erase(arr[i]);

        if(mp[arr[i-k]]==0)
        {
            s.insert(arr[i - k]);
        }

        ll firstElem = *(s.begin());
        mex = min(mex, firstElem);
    }
        cout<<mex;
        cout<<"\n";
    }
    int main()
    {
        ios_base::sync_with_stdio(false); 			//Used to reduce the time
        cin.tie(NULL);
        cout.tie(NULL);

        file_i_o();

        ll T=1;
        //cin>>T;
        while(T--)
        {
            solve();
        }
    }

#include <bits/stdc++.h>

using namespace std;
#define FOR(i, begin, end) for(int i=begin;i<end;i++)

void solve() {
    int N, M;

    vector<int> counter(1500001, -1);

    cin >> N >> M;

    int ans = INT_MAX;

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

        if (i - counter[elt] > M || (counter[elt] == -1 && i >= M))
            ans = min(ans, elt);

        counter[elt] = i;
    }

    for (int i = 0; i < M + 1; i++) {
        if (N - counter[i] > M || counter[i] == -1)
            ans = min(ans, i);
    }

    cout << ans << "\n";
}

int main() {
    solve();
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,m;cin >> n >>m;
    vl a(m);rep(i,m)cin >> a[i];
    a.pb(0);a.pb(n+1);
    sort(all(a));
    vl div;
    rep(i,m+1){
        ll k=a[i+1]-a[i]-1;
        if(k)div.pb(k);
    }
    if(div.size()==0)cout << 0 <<endl,exit(0);
    //for(auto p:div)cout << p <<endl;
    sort(all(div));
    ll k=div[0];
    ll ans=0;
    for(auto p:div){
        ans+=(p+k-1)/k;
    }
    cout << ans <<endl;
}

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

int main() {
  int  n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  int x = 0;
  int g = n;
  for (int i = 0; i < m; i++) {
    if (a[i] > x + 1) {
      g = min(g, a[i] - x - 1);
    }
    x = a[i];
  }
  x = 0;
  int c = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] > x + 1) {
      c += (a[i] - x - 1) / g + ((a[i] - x -1) % g > 0 ? 1 : 0);
    }
    x = a[i];
  }
  if (x < n) {
    c += (n - x) / g + ((n - x) % g > 0 ? 1 : 0);
  }
  cout << c << endl;
  return 0;
}


// 解説を参考にコーディング
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);

/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力
   vi, vl, list<int>, list<ll>に対応  */
template<class T> string print_elements(T a) {
    string str = "";
    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        str += to_string(*itr) + ' ';
    }
    str.pop_back();  // 最後の空白を削除
    str += '\n';
    return str;
}

int main() {
    int N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    map<int, int> m;
    bool result = false;
    int ans1, ans2;
    int N2 = min(8, N);
    rep(i, (1 << N2)) {
        if (i == 0) continue;
        int val = 0;
        rep(j, N2) {
            if ((i >> j) & 1) {
                val += A[j] % 200;
            }
        }
        val %= 200;
        if (!m.count(val)) {
            m[val] = i;
        }
        else {
            result = true;
            ans1 = m.at(val);
            ans2 = i;
            break;
        }
    }
    vi v1, v2;
    if (result) {
        string str1 = to_string(__builtin_popcount(ans1)) + ' ';
        string str2 = to_string(__builtin_popcount(ans2)) + ' ';
        cout << "Yes" << endl;
        rep(i, 7) {
            if ((ans1 >> i) & 1) {
                v1.push_back(i + 1);
            }
            if ((ans2 >> i) & 1) {
                v2.push_back(i + 1);
            }
        }
        str1 += print_elements(v1);
        str2 += print_elements(v2);
        cout << str1 << str2;
    }
    else {
        cout << "No" << endl;
    }
}

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

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

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto &a : A) cin >> a, a %= 200;

    int cnt = min(N, 8);
    vector<int> v(200, -1);
    for (int bit = 1; bit < (1 << cnt); bit++) {
        int b = 0;
        for (int i = 0; i < cnt; i++) {
            if (bit & (1 << i)) b += A[i];
        }
        b %= 200;
        if (v[b] == -1)
            v[b] = bit;
        else {
            vector<int> B, C;
            for (int i = 0; i < cnt; i++) {
                if (bit & (1 << i)) B.push_back(i + 1);
                if (v[b] & (1 << i)) C.push_back(i + 1);
            }
            cout << "Yes" << endl;
            cout << B.size() << " ";
            for (auto i : B) cout << i << " ";
            cout << endl << C.size() << " ";
            for (auto i : C) cout << i << " ";
            cout << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


//https://atcoder.jp/contests/abc189/tasks/abc189_d
//题意：给定一串OR和AND组成的n长字符串，代表V,^求有多少种n+1长的由0,1组成的字串使两两运算最终结果为1
//思路：找规律，默认有一种，有OR才增加，还与OR有关。
#include <stdio.h>

int main(int argc, char **argv)
{
  int N, i;
  unsigned long long T = 1;
  scanf("%d", &N);
  for(i = 1; i <= N; ++i){
    char buff[10];
    scanf("%s", buff);
    if(buff[0] == 'O'){
      T = T + (1ull<<i);
    }
  }
  printf("%llu", T);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double
#define ull unsigned long long
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define s second
#define f first
#define pb push_back
#define oo 1000000000000000000ll

void solve() {

	int n; cin >> n;
	vector<int> cnt(n+1);
	for (int i = 0; i < n; ++i){
		int x; cin >> x;
		cnt[x]++;
	}

	bool ans = true;
	for (int i = 1; i <= n; ++i){
		ans &= cnt[i] == 1;
	}

	if (ans) cout << "Yes\n";
	else cout << "No\n";

}

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

    int tst; tst = 1;
    //cin >> tst;
    while (tst--){
        solve();
    }

    return 0;

}


#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++)
  {
    if(s.at(i)=='6')
    {
      s.at(i)='9';
    }
    else if(s.at(i)=='9')
    {
      s.at(i)='6';
    }
  }
  for(int i=s.size()-1;i>=0;i--)
  {
      cout<<s[i];
  }
  return 0;
}

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

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

    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    for(char &c : s){
        if(c == '6' || c == '9'){
            c = 15 - (c-'0') + '0';
        }
    }
    cout << s << '\n';
}