#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <optional>
#include <utility>
#include <vector>
#include <cmath>
// #include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif

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

struct nimotsu {
    int size, value;
};

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);

    int n, m, q; std::cin >> n >> m >> q;
    std::vector<nimotsu> P(n);
    for(int i = 0; i < n; ++i) std::cin >> P[i].size >> P[i].value;
    std::sort(P.begin(), P.end(), [](const nimotsu& x, const nimotsu& y){
        if(x.value != y.value) return x.value > y.value;
        return x.size < y.size;
    });

    std::vector<int> X(m); for(int i = 0; i < m; ++i) std::cin >> X[i];

    // [l, r)
    const auto solve = [&](int l, int r) -> int {
        std::vector<int> S; S.reserve(m - (r - l));
        for(int i = 0; i < l; ++i) S.push_back(X[i]);
        for(int i = r; i < m; ++i) S.push_back(X[i]);
        std::sort(S.begin(), S.end());
        long long int used = -1;
        int res = 0;
        for(const int s : S){
            for(int i = 0; i < n; ++i){
                if(((used >> i) & 1) and P[i].size <= s){ res += P[i].value; used ^= (1LL << i); break; }
            }
        }
        return res;
    };

    while(q--){
        int l, r; std::cin >> l >> r; --l;
        std::cout << solve(l, r) << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#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 Int = long long;

int vmax(vector<int> w,vector<int> v, vector<int> x){
    int n=w.size();
    int m=x.size();

    int ans=0;
    sort(x.begin(),x.end());

    rep(i,m){
        vector<int> can_keep_num(0);
        rep(j,n){
            if(w[j]<=x[i]){
                can_keep_num.push_back(j);
            }
        }
        if(can_keep_num.size()==0) continue;

        int max_num=0;
        int can_max=0;
        for(int j: can_keep_num){
            if(v[j]>can_max){
                can_max=v[j];
                max_num=j;
            }
            else if(v[j]==can_max){
                if(w[j]>w[max_num]) max_num=j;
            }
        }

        ans+=can_max;
        w[max_num]=1000001;

    }

    return ans;
}

int main(){
    int n,m,q;cin>>n>>m>>q;
    vector<int> w(n);
    vector<int> v(n);
    vector<int> x(m);

    rep(i,n){
        cin>>w[i]>>v[i];
    }
    rep(i,m) cin>>x[i];

    rep(i,q){
        vector<int> y(m);
        rep(j,m) y[j]=x[j];
        int l,r; cin>>l>>r;
        rep2(j,l-1,r) x[j]=0;
        cout<<vmax(w,v,x)<<endl;
        rep(j,m) x[j]=y[j];
    }

}


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

void solve() {
    int n;
    cin>>n;
    ll a, sum=0, high=0, ans=0;
    for(int i=0; i<n; i++) {
        cin>>a;
        sum+=a;
        ans+=sum;
        high=max(high, a);
        cout<<ans+(i+1)*high<<endl;
    }
    return;
}

int main() {
#ifdef bipinpathak
    (void)!freopen("input.txt", "r", stdin);
    (void)!freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    auto start=clock();
    int t = 1;
    //cin>>t;
    for(int i=0; i<t; i++) {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    double used= (double) (clock()-start);
    used=(used*1000)/CLOCKS_PER_SEC;
    cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,max = 0,sum = 0,ans = 0;
  cin >> N;
  vector<ll> A(N),B(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(ll i = 0; i < N; i++){
    if(max < A.at(i)) max = A.at(i);
    sum += A.at(i);
    ans += sum;
    cout << ans + (i + 1) * max << endl;
  }
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n) ans += abs(a[i]);
    cout << ans << endl;
    ans = 0;
    rep(i, n) ans += a[i] * a[i];
    cout << fixed << setprecision(15) << sqrt(ans) << endl;
    ans = 0;
    rep(i, n) ans = max(abs(a[i]), ans);
    cout << ans << endl;
    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 {
#ifndef ONLINE_JUDGE
~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

const ll nax = 2e5 + 5;
vector<ll> edges[nax], vis(nax, 0);
ll cnt = 0;

void dfs(ll node) {
    cnt++;
    vis[node] = 1;
    for(ll x: edges[node]) {
        if(vis[x] == 0) {
            dfs(x);
        }
    }
}

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(ll i = 0; i < n; ++i) {
        edges[a[i]].push_back(a[n - i - 1]);
        edges[a[n - i - 1]].push_back(a[i]);
    }
    ll ans = 0;
    for(ll i = 0; i < nax; ++i) {
        if(vis[i] == 0) {
            cnt = 0;
            dfs(i);
            ans = ans + max(0ll, cnt - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    ll n,m;
    cin >> m >> n;
    ll ar[m*n];
    ll min = 101;
    for(ll i = 0; i < m*n; i++)
    {
        cin >> ar[i];
        if(ar[i] < min)
            min = ar[i];
    }
    ll kount = 0;
    for(ll i = 0; i < m*n; i++)
    {
        if(ar[i] > min)
            kount = kount + ar[i] - min;
    }
    cout << kount << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define tcase int _; cin >> _; while(_--)
//#define int long long
const int MOD = 1e9+7;
const int MAX = 1e6;
const int INF = 2e9;

int v[1000][1000];

void solve() {
	int h,w;
	cin >> h >> w;
	int mn = INF;
	for(int i=0; i<h; i++) for(int j=0; j<w; j++) {
		cin >> v[i][j];
		mn = min(mn, v[i][j]);
	}
	int ans=0;
	for(int i=0; i<h; i++) for(int j=0; j<w; j++) ans += v[i][j] - mn;
	cout << ans << endl;
}

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

 	solve();

  	return 0;
}


//https://atcoder.jp/contests/zone2021/tasks/zone2021_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool chk(vector<vector<int>> &arr, int mid)
{
    int n=arr.size();
    set<int> st;
    for (int i = 0; i < n; i++)
    {
        int c=0;
        for (int j = 0; j < 5; j++)
        {
            int bit=0;
            if(arr[i][j]>=mid) bit=1;
            c+=(bit<<j);
        }
        st.insert(c);
    }
    for(auto e:st)
        for(auto f:st)
            for(auto g:st)
            {
                if((e|f|g)==31)
                    return 1;
            }
    return 0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<vector<int>> arr(n, vector<int>(5, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 5; j++)
            cin >> arr[i][j];
    }

    int l = 1, r = 1e9 + 1;
    while (l < r)
    {
        int mid = (l + r)/2;
        if(chk(arr,mid))    l=mid+1;
        else r=mid;
    }
    cout<<l-1<<endl;
}

#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    array<vector<int>, 5> A;
    rep(i, 5) A[i].resize(N);
    rep(i, N) cin >> A[0][i] >> A[1][i] >> A[2][i] >> A[3][i] >> A[4][i];

    int low = 1, high = 1e9 + 1;
    vector<int> B(N);
    array<int, 1 << 5> cnt;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        B.assign(N, 0);
        rep(k, 5) rep(i, N) {
            B[i] |= (A[k][i] >= mid) << k;
        }
        fill(all(cnt), 0);
        rep(i, N) {
            cnt[B[i]]++;
        }
        bool ok = false;
        rep(a, 1 << 5) {
            if (cnt[a] == 0) continue;
            rep(b, 1 << 5) {
                if (cnt[b] == 0) continue;
                rep(c, 1 << 5) {
                    if (cnt[c] == 0) continue;
                    int bit = a | b | c;
                    if (bit == (1 << 5) - 1) ok = true;
                }
            }
        }
        if (ok) low = mid;
        else high = mid;
    }
    write(low);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 998244353;

ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}

ll inverse(ll n){
	return power(n, MOD-2);
}

ll add(ll a, ll b){
	return (a+b) % MOD;
}

ll mul(ll a, ll b){
	return (a*b) % MOD;
}

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

int main(){
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vi X(n), Y(n);
	FOR(i, 0, n) cin >> X[i] >> Y[i];
	int m; cin >> m;
	vector<ll> sX(m+1), sY(m+1), valX(m+1), valY(m+1), cnt(m+1);
	sX[0] = 1; sY[0] = 1;
	FOR(i, 1, m+1){
		int op; cin >> op;
		if (op == 1){
			cnt[i] = cnt[i-1] + 1;
			valX[i] = valY[i-1];
			valY[i] = -valX[i-1];
			if (cnt[i] % 2 == 1){
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}else{
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}
			continue;
		}
		if (op == 2){
			cnt[i] = cnt[i-1] + 1;
			valX[i] = -valY[i-1];
			valY[i] = valX[i-1];
			if (cnt[i] % 2 == 1){
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}else{
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}
		}
		if (op == 3){
			ll p; cin >> p;
			cnt[i] = cnt[i-1];
			valX[i] = 2*p - valX[i-1];
			valY[i] = valY[i-1];
			if (cnt[i] % 2 == 0){
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}else{
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}
			continue;
		}
		if (op == 4){
			ll p; cin >> p;
			cnt[i] = cnt[i-1];
			valX[i] = valX[i-1];
			valY[i] = 2*p - valY[i-1];
			if (cnt[i] % 2 == 0){
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}else{
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}
		}
	}
	int q; cin >> q;
	while (q--){
		int a, b; cin >> a >> b;
		ll x = valX[a], y = valY[a];
		if (cnt[a] % 2 == 1){
			y += sX[a] * X[b-1];
			x += sY[a] * Y[b-1];
		}else{
			x += sX[a] * X[b-1];
			y += sY[a] * Y[b-1];
		}
		cout << x << " " << y << '\n';
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   fastIO
   int n,y; cin>>n>>y;
   map<int,int> mp;
   int ans=0;
   rep(i,0,n){
     int a,b,c; cin>>a>>b>>c;
     mp[a]+=c;
     mp[b+1]-=c;
   }
   int prev=-1;
   rr(mp){
      if(prev!=-1){
        ans+=(val.fi-prev)*y;
      }
      prev=val.fi;
   }
   prev=-1;
   rr(mp){
      if(prev!=-1){
        if(y>mp[prev])ans-=(val.fi-prev)*y,ans+=(val.fi-prev)*mp[prev];
        val.se+=mp[prev];
      }
      prev=val.fi;
   }
   cout<<ans<<"\n";
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin >> n; vector<vector<int> > C( n,vector<int>( n ) );
	vector<int> A( n ), B( n );
	for( auto &i:C )	for( auto &j:i )	cin >> j;
	int minval=numeric_limits<int>::max(),mini=0,minj=0;
	for( int i=0;i<n;++i )
	{
		for( int j=0;j<n;++j )
		{
			if( C[i][j]<minval )	minval=C[i][j],mini=i,minj=j;
		}
	}
	for( int i=0;i<n;++i )	B[i]=C[mini][i];
	for( int i=0;i<n;++i )
	{
		if( C[i][minj]-minval<0 )	exit( ( puts( "No" ),0 ) );
		A[i]=C[i][minj]-minval;
		for( int j=0;j<n;++j )
		{
			if( ( C[i][minj]-minval )^( C[i][j]-B[j] ) )	exit( ( puts( "No" ),0 ) );
		}
	}
	puts( "Yes" );
	for( int i:A )	cout << i << ' '; cout << "\n";
	for( int i:B )	cout << i << ' '; cout << "\n";
	return 0;
}

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

int n;
vector<long long> a, b;
vector<vector<long long>> c;

bool solve();

int main() {
  cin >> n;
  c.resize(n);
  for (auto &v : c) {
    v.resize(n);
    for (auto &p : v) cin >> p;
  }
  if (solve()) {
    for (long long i = 0; i < n; ++i)
      for (long long j = 0; j < n; ++j) assert(c[i][j] == a[i] + b[j]);
    cout << "Yes" << endl;
    for (long long i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
    for (long long i = 0; i < n; ++i) cout << b[i] << " \n"[i == n - 1];

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

bool solve() {
  {
    long long sum = 0;
    for (int i = 0; i < n; ++i) sum += c[i][i];
    for (int i = 0; i < n; ++i) {
      long long now = 0;
      for (int j = 0; j < n; ++j) now += c[(i + j) % n][j];
      if (now != sum) return 0;
    }
  }
  a.resize(n);
  b.resize(n);
  vector<vector<long long>> memo(n, vector<long long>(n, 0));
  vector<long long> sum(n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) sum[i] += c[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      if (abs(sum[i] - sum[j]) % n != 0) return 0;
      memo[i][j] = (sum[i] - sum[j]) / n;
    }
  for (int i = 0; i < n; ++i) {
    bool ch = 1;
    for (int j = 0; j < n; ++j)
      if (memo[i][j] > 0) ch = 0;
    if (ch) {
      b = c[i];
      for (int j = 0; j < n; ++j) a[j] = memo[j][i];
      return 1;
    }
  }
  return 0;
}


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

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

    int n, m; cin >> n >> m;
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v; --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<bool> vis(n, 0);
    int sz;
    function<void(int)> dfs1 = [&](int u) {
        sz++;
        vis[u] = 1;
        for (int v : adj[u])
            if (!vis[v]) dfs1(v);
    };

    int offset, pos;
    vector<int> colour(n);
    function<bool(int)> dfs2 = [&](int u) {
        pos++;
        for (int v : adj[u]) {
            if (colour[v] == colour[u]) {
                return false;
            }
            if (colour[v] == -1) {
                colour[v] = (colour[u] + ((offset >> pos) & 1) + 1) % 3;
                if (!dfs2(v)) return false;
            }
        }
        return true;
    };

    long long ans = 1;
    for (int i = 0; i < n; ++i) {
        if (vis[i]) continue;
        sz = 0;
        dfs1(i);
        int cur = 0;
        for (offset = 0; offset < (1 << (sz - 1)); ++offset) {
            colour.assign(n, -1);
            colour[i] = 0;
            pos = -1;
            if (dfs2(i)) cur += 3;
        }
        ans *= cur;
    }
    cout << ans << '\n';

    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> v(n);
  vector<vector<int>> g(n);
  vector<int> a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  vector<int> c(n,-1);
  ll cnt = 0;
  rep(i,n) if(g[i].size() == 0) cnt++;
  ll ans = 0;
  auto dfs = [&](auto self, int id) -> void {
    if(id == m) {
      ans++;
      return;
    }
    if(c[a[id]] != -1 and c[b[id]] != -1) {
      if(c[a[id]] != c[b[id]]) self(self,id+1);
    } else if(c[a[id]] != -1) {
      rep(i,3) if(i != c[a[id]]) {
        c[b[id]] = i;
        self(self,id+1);
        c[b[id]] = -1;
      }
    } else if(c[b[id]] != -1) {
      rep(i,3) if(i != c[b[id]]) {
        c[a[id]] = i;
        self(self,id+1);
        c[a[id]] = -1;
      }
    } else {
      rep(i,3) rep(j,3) {
        if(i != j) {
          c[a[id]] = i, c[b[id]] = j;
          self(self,id+1);
          c[a[id]] = -1, c[b[id]] = -1;
        }
      }
    }
    return;
  };
  dfs(dfs,0);
  rep(i,cnt) ans *= 3;
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void printv(vector<lli> x){
  cout << "{";
  rep(i, x.size()){
    cout << x[i];
    if(i != x.size()-1) cout << " ";
  }
  cout << "}" << endl;
}

lli n;

int main(void){
  cin >> n;
  vector<lli> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  for(int i = 1; i < n; i++) a[i]%=a[0];
  sort(a.begin(), a.end());
  while(1){
    bool f = true;
    rep(i, n){
      if(a[i] != 0 && a[n-1]%a[i] != 0){
        f = false;
      }
    }
    lli mv;
    rep(i, n){
      if(a[i] != 0){
        mv = a[i];
        break;
      }
    }
    if(f){
      cout << mv << endl;
      return 0;
    }
    rep(i, n) a[i]%=mv;
  }
  return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

lint LCM(lint a,lint b){
  if(a==0 || b==0) return 0;
  lint tmp,r,x;
  x=a*b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=x/b;
  return x;
}

lint GCD(lint a,lint b){
  if(a==0 || b==0) return max(a,b);
  else return (a*b)/LCM(a,b);
}

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint ans=A[0];
    for(int i=1;i<N;i++) ans=GCD(ans,A[i]);
    cout << ans << endl;
}


/* Lucky_Glass */
#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 105, MOD = 998244353;

inline int add(int a, const int &b) { return (a += b) >= MOD ? a - MOD : a; }
inline int sub(int a, const int &b) { return (a -= b) < 0 ? a + MOD : a; }
inline int mul(const int &a, const int &b) { return int(1ll * a * b % MOD); }
#define ITERON(a, b, fun) a = fun(a, b)

int n;
int dp[2][N * N * 2][N], bino[N][N];

#define f(i, s, k) dp[(i) & 1][(s) + N * N][k]

int main() {
  scanf("%d", &n);
  f(0, 0, 0) = 1;
  for (int i = 1, tmp, sum = 0; i <= n; ++i) {
    scanf("%d", &tmp);
    for (int s = -sum; s <= sum; ++s)
      for (int k = 0; k <= i; ++k)
        f(i, s, k) = 0;
    for (int s = -sum; s <= sum; ++s)
      for (int k = 0; k <= i; ++k) {
        ITERON(f(i, s + tmp, k + 1), mul(f(i - 1, s, k), k + 1), add);
        ITERON(f(i, s - tmp, k), mul(f(i - 1, s, k), i - k), add);
      }
    sum += tmp;
  }

  int ans = 0;
  for (int k = 0; k <= n; ++k)
    ITERON(ans, f(n, 0, k), add);

  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define gp  __gnu_pbds
#define iset(T) gp::tree<T,gp::null_type,less<T>,gp::rb_tree_tag,gp::tree_order_statistics_node_update>
using namespace std;

#define SQ(x) ((x)*(x))
#define u unsigned
#define ull unsigned long long
#define ll  long long
#define ld  long double
#define test(x) cout<<"here "<<x<<endl;
#define debug(x) cout<<(#x)<<": "<<(x)<<endl;
#define inputstl(v) for(auto& x:v) cin>>x;
#define input(arr,n) for(ull i=0;i<n;++i){cin>>arr[i];}
#define print(arr,n) for(ull i=0;i<n;++i){cout<<arr[i]<<" ";}cout<<'\n';
#define printall(x) for(auto y:x){cout<<y<<' ';}cout<<'\n';
#define printallpii(x) for(auto y:x){cout<<y.fi<<','<<y.se<<' ';}cout<<'\n';
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define mod (ll)(998244353)
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define SENSITIVITY 1e-9
#define EQUAL(x1,x2) [](auto x1,auto x2){double ep=0.0001;double pos=x1-x2;if(pos<0){pos=-pos;}double maxi=(x1>x2)?(x1):(x2);if(pos/(maxi*ep)<SENSITIVITY)return true;else return false;}(x1,x2)
bool isPrime(ll a)
{
    if(a==1)
        return false;
    for(ll i=2; i*i<=a; ++i)
    {
        if(a%i==0)
        {
            return false;
        }
    }
    return true;
}
bool isPali(string s)
{
    int _size=(s.length())/2;
    for(int i=0; i<_size; ++i)
    {
        if(s.at(i)!=s.at(s.length()-1-i))
        {
            return false;
        }
    }
    return true;
}
int gcd(int a,int b)
{
    if(a==0)
    {
        return b;
    }
    else if(b==0)
    {
        return a;
    }
    else
    {
        int shift=__builtin_ctz(a|b);
        a>>=__builtin_ctz(a);
        do
        {
            b>>=__builtin_ctz(b);
            if(a>b)
            {
                a=a^b;
                b=a^b;
                a=a^b;
            }
            b-=a;
        }
        while(b);
        return a<<shift;
    }
}
ll gcdll(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else if(b==0)
    {
        return a;
    }
    else
    {
        ll shift=__builtin_ctzll(a|b);
        a>>=__builtin_ctzll(a);
        do
        {
            b>>=__builtin_ctzll(b);
            if(a>b)
            {
                a=a^b;
                b=a^b;
                a=a^b;
            }
            b-=a;
        }
        while(b);
        return a<<shift;
    }
}
ll power(ll a,ll b,ll _mod)
{
    ll temp=a;
    ll ans=1;
    int limit=63-__builtin_clzll(b);
    int index=0;
    while(index<=limit)
    {
        if(b&(1ll<<index))
        {
            ans=(ans*temp)%_mod;
        }
        ++index;
        temp=(temp*temp)%_mod;
    }
    return ans;
}

int main()
{
//    #define cin fin
//    ifstream fin;
//    fin.open("input.txt",ios_base::in);
    fastio;
    int tt=1;
    cin>>tt;
    while(tt--)
    {
        ll L,R,c,d;
        cin>>L>>R;
        if(2*L>R)
        {
            cout<<0<<'\n';
            continue;
        }
        c=2*L;
        d=R;
        ll s=((d-c+1)*(c+d))/2;
        cout<<s-(d-c+1)*c+(d-c+1)<<'\n';
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,a,b,c) for(ll i=a;i<b;i+=c)
#define For2(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define vec_ll vector<vector<ll>>
#define vec_pr vector<pair<ll,ll>>
#define p_ll pair<ll,ll>
#define pbk push_back
#define mkpr make_pair
#define fst first
#define snd second

void print(ll *arr, ll n){
    For(i,0,n,1)cout<<arr[i]<<" ";
    cout<<endl;
}

void print_vec(vector<ll> &vec, ll n){
    For(i,0,n,1)cout<<vec[i]<<" ";
    cout<<endl;
}

bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll fast_expo(ll a, ll p){
    //cout<<a<<" ";
    ll x=p-2;
    ll curr=a;
    ll ans=1;
    while(x!=0){
        if(x%2==1){
            ans=(ans*curr)%p;
        }
        x/=2;
        curr=(curr*curr)%p;
    }
    return ans;
}

///

///

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

    ll t;
    cin>>t;

    while(t--){
        ll L,R;
        cin>>L>>R;

        ll ans=0;
        if(R>=2*L){
            ll len=(R-2*L)+1;

            if(len%2==0){
                ll half=(len/2);
                ans=2*half*(half+1);
                ans-=(half);
            }
            else{
                ll half=(len+1)/2;
                ans=(2*half*half);
                ans-=half;
            }
        }

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


/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define int      long long
#define double   long double
#define uint     unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
int google_itr = 1;
#define google(x) cout<<"Case #"<<x<<": "
#define pi 3.14159265358979323846264338327950L

vector<string> vec_splitter(string s) {
        s += ',';
        vector<string> res;
        while(!s.empty()) {
                res.push_back(s.substr(0, s.find(',')));
                s = s.substr(s.find(',') + 1);
        }
        return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
        if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, LINE_NUM, T...);
}

#define XOX
#ifdef XOX
    #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
    #define deb(...) 42
#endif

const int mod = 1e9+7;
const int inf = 1e18;

void virus(){
        int len;
        cin >> len;

        set <int> arr;
        for(auto i=0; i<=200000; i++) arr.insert(i);

        for(auto i=0; i<len; i++){
            int val;
            cin >> val;
            arr.erase(val);
            cout << *arr.begin() << endl;
        }
}

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

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

    int t = 1;
    //cin >> t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
           //cerr << "\n Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	vector<bool> used(200001,0);
	int x=0;
	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin>>p[i];
		used[p[i]]=true;
		while(used[x]){
			x++;
		}
		cout<<x<<'\n';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
char Str[400005];
int a[400005],s,b[400005];;
bool vis[400005];
int sta[400005];
int main(){
	s=read;int n=s*2;
	for(int i=1;i<=n;++i)a[i]=read,b[i]=i;
	nth_element(b+1,b+s+1,b+n+1,[&](const int &x,const int &y){return a[x]<a[y];});
	for(int i=1;i<=s;++i)vis[b[i]]=1;
	for(int i=1;i<=n;++i){
		if(!*sta)sta[++*sta]=i,Str[i]='(';
		else{
			if(vis[sta[*sta]]^vis[i])--*sta,Str[i]=')';
			else sta[++*sta]=i,Str[i]='(';
		}
	}puts(Str+1);
	return 0;
}

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

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}

typedef unsigned long long ull;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

array<int,3> e[MAXN];
int c[MAXN],vis[MAXN]={};

vpii graph[MAXN];

void dfs(int i, int p) {
	vis[i]=1;
	print("vis",i);
	for(auto [j,idx]:graph[i]) {
		if(j==p)continue;
		if(c[j]>c[i]) continue;
		print(i,j);

		if(e[idx][2]<0) {
			if(e[idx][0] == i) e[idx][2]=1;
			else e[idx][2]=0;
		}
		if(!vis[j]) dfs(j,i);
	}
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n,m;
    cin>>n>>m;
    int u,v;
    rep(i,0,m){
    	cin>>u>>v;
    	e[i][0] = u;
    	e[i][1] = v;
    	e[i][2] = -1;
    	graph[u].pb({v,i});
    	graph[v].pb({u,i});
    }
    rep(i,1,n+1) {
    	cin>>c[i];
    }
    rep(i,1,n+1) {
    	if(!vis[i]) dfs(i,-1);
    }
    printn(e,m);
    rep(i,0,m) {
    	if(e[i][2]==1)cout<<"->"<<endl;
    	else cout<<"<-"<<endl;
    }

    return 0;
}


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

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

  ll n,k;
  cin >> n >> k;
  k = abs(k);
  ll ans = 0;
  for(ll ab = k+2; ab<=2*n;ab++){
    ll abc, cdc;
    if(ab-1 < n){
      abc = ab-1;
    }
    else{
      abc = 2*n-ab +1;
    }
    ll cd = ab-k;
    if(cd-1 < n){
      cdc = cd-1;
    }
    else{
      cdc = 2*n-cd +1;
    }
    ans += abc*cdc;
    // cout << ans << endl;
  }
  cout << ans << endl;
  return 0;

}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ll long long
#define out(x) std::cout << fixed << setprecision(15) << x << '\n'; return 0
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define VEC(t,a,s) vector<t>a(s); in(a)
#define VEC2(t,a,b,s) vector<t>a(s),b(s);rep(i,0,s)in(a[i],b[i])
#define VEC3(t,a,b,c,s) vector<t>a(s),b(s),c(s);rep(i,0,s)in(a[i],b[i],c[i])
#define VEC4(t,a,b,c,d,s) vector<t>a(s),b(s),c(s),d(s);rep(i,0,s) in(a[i],b[i],c[i],d[i])
void scan(int& x) {std::cin >> x;}
void scan(ll& x) {std::cin >> x;}
void scan(double& x) {std::cin >> x;}
void scan(std::vector<int>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void scan(std::vector<ll>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void in(){}
template<class T> void print(const T& x) {std::cout << x << '\n';}
template<class Head, class... Tail>
void in(Head& head, Tail&... tail) {scan(head); in(tail...);}
template<class T, class U>
bool chmax(T& a, U b) {if(a < b){a=b; return true;} return false;}
template<class T, class U>
bool chmin(T& a, U b) {if(a > b){a=b; return true;} return false;}
using namespace std;

int main() {
    LL(N, K);

    auto cnt = [&](int x) {
        if (x < 2) return 0;
        if (N < x / 2) return 0;
        int ret = ((x / 2) - max(1LL, (x - N)) + 1) * 2 - (x % 2 == 0);
        return ret;
    };

    ll ans = 0;
    rep (r, 2, 500000) {
        int l = r + K;
        ans += (ll)cnt(l) * cnt(r);
    }

    out(ans);
}


#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v, s) vector<type> v(s); for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

vector<int> get_divisors(int n) {
  vector<int> divisors;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i != 0) continue;
    divisors.emplace_back(i);
    if (n / i != i) divisors.emplace_back(n / i);
  }

  return divisors;
}

int main() {
  IN(int, N);
  vector<int> A(N);
  int min = INT_MAX;
  REP(i, N) {
    IN(int, a);
    chmin(min, a);
    A.at(i) = a;
  }

  map<int, int> divisors;
  for (auto const &a : A) {
    for (auto const &d : get_divisors(a)) {
      if (d > min) continue;
      divisors[d]++;
    }
  }

  int count = 0;
  bool min_flag = true;
  for (auto itr = divisors.begin(); itr != divisors.end(); ++itr) {
    vector<int> cand;
    REP(i, N) {
      if (A.at(i) % itr->first == 0) {
        cand.emplace_back(A.at(i));
      }
    }

    if (cand.size() < 2) continue;
    int gcd = cand.at(0);
    REP(i, 1, cand.size()) {
      gcd = __gcd(gcd, cand.at(i));
    }
    if (gcd == itr->first) {
      count++;
      if (itr->first == min) min_flag = false;
    }
  }

  if (min_flag) count++;
  cout << count << endl;

  return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n >> m >> k;
	map<ll, ll> fail;
	rep(i, k) {
		cin >> x;
		fail[x] = 1;
	}
	// dp[i]=a*dp[0]+b;
	db dp_sum[n + m], dp_carry[n + m];//dp_sum[i] denotes b of dp[i] and dp_carry[i] denotes the a of dp[i]
	rep(i, n + m) {
		dp_carry[i] = 0; dp_sum[i] = 0;
	}
	db sum = 0, car = 0;
	for (i = n - 1; i > 0; i--) {
		if (fail[i]) {
			dp_carry[i] = 1;
			dp_sum[i] = 0;

		}
		else {
			dp_carry[i] = car / db(m);
			dp_sum[i] = 1.0 + sum / db(m);
		}
		sum += dp_sum[i];
		car += dp_carry[i];
		sum -= dp_sum[i + m];
		car -= dp_carry[i + m];

	}
	sum = 1.0 + sum / db(m);
	car = car / db(m);
	// rep(i, n + m) {
	// 	cout << dp_sum[i] << ' ';
	// }
	db ans = sum / (1.0 - car);
	if (ans <= 0 || (1.0 - car) < 1e-7) cout << -1;
	else
		cout << fixed << setprecision(5) << ans;

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int a[200005],s;
int main(){
	s=read;int v=0;ll ans=0,t=0;
	for(int i=1;i<=s;++i)
		a[i]=read;
	for(int i=1;i<=s;++i){
		v=max(v,a[i]);t+=a[i];
		ans+=t;
		printf("%lld\n",ans+1ll*v*i);
	}
	return 0;
}

/*
#include <stdio.h>

int main(){
    int l,a,i,j;
    long long int ans = 1;
    scanf("%d", &l);
    a = (l-1) % 11;
    for(i = 1; i <= 11; i++){
        ans *= (l-i) / (11 - i - 1 + a);
    }
    printf("%lld", ans);
}
*/
#include <stdio.h>

long long combi(int, int);

int main() {
    int n, r = 11;
    scanf("%d", &n);
    n -= 1;
    printf("%lld\n", combi(n, r));
}

long long combi(int n, int r) {
    if (r == 0) {
        return 1;
    }

    return (n - r + 1) * combi(n, r - 1) / r;
}


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

int main() {
	int sx, sy, gx, gy,dist;
	cin >> sx >> sy >> gx >> gy;
	dist = min(abs(sx + sy - gx - gy), abs(sx - sy - gx + gy));
	if (sx == gx && sy == gy) cout << 0 << endl;
	else if (sx + sy == gx + gy || sx - sy == gx - gy || abs(sx - gx) + abs(sy - gy) <= 3) cout << 1 << endl;
	else if ((sx + sy + gx + gy) % 2 == 0 || dist <= 3) cout << 2 << endl;
	else if (abs(sx - gx) + abs(sy - gy) <= 6) cout << 2 << endl;
	else cout << 3 << endl;
}

//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

int calc(pll xy1, pll xy2) {
    int ans = inf;
    if (xy1 == xy2) ans = 0;
    else if (xy1.first + xy1.second == xy2.first + xy2.second) ans = 1;
    else if (xy1.first - xy1.second == xy2.first - xy2.second) ans = 1;
    else if ((xy1.first + xy1.second) % 2 == (xy2.first + xy2.second) % 2) ans = 2;

    for (int dy = -3; dy <= 3; dy++) {
        for (int dx = -3; dx <= 3; dx++) {
            int add = 1;
            if (dy == 0 and dx == 0) add = 0;
            pll xy = xy1;
            xy.first += dx;
            xy.second += dy;
            if (xy == xy2) chmin(ans, add);
        }
    }
    return ans;
}

signed main() {
    fio();

    pll xy1, xy2;
    cin >> xy1.first >> xy1.second >> xy2.first >> xy2.second;
    xy1.first += 10; xy1.second += 10;
    xy2.first += 10; xy2.second += 10;

    ll ans = INF;
    for (int dy = -3; dy <= 3; dy++) {
        for (int dx = -3; dx <= 3; dx++) {
            if (abs(dy) + abs(dx) > 3) continue;
            int add = 1;
            if (dy == 0 and dx == 0) add = 0;
            pll xy = xy1;
            xy.first += dx;
            xy.second += dy;
            add += calc(xy, xy2);
            chmin(ans, add);
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define ones(x) __builtin_popcount(x)
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const int M=1e6+5;
const int inf=1e9;
const int mod=1e9+7;

void go(){
	int n; cin >> n;
	ll r = 16LL*27LL*25LL*7LL*11LL*13LL*17LL*19LL*23LL*29LL;
	cout << r+1 << "\n";
}

int main(){

	fastio;
	int tst=1;
	//cin >> tst;
	while (tst--) go();

	return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define long long long
int main() {
    long int n;
    cin>>n;
    long int ans=1LL;
    for(long int i=2;i<=n;i++)
    {
        long int temp = __gcd(ans,i);
        ans*=(i/temp);
    }
    cout<<ans+1LL<<endl;
	// your code goes here
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<list>
#include<string.h>
#include<math.h>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
//#include<unordered_set>
//#pragma GCC optimize (3)

//#define segmenttree true

#ifdef segmenttree
#define lc (rt<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#endif

#define reg register

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<double, double> pdd;
typedef pair<char, char> pcc;
typedef pair<ll, bool> plb;

const int MAX = 2005;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535;
const double EPS = 1e-5;

ll n, m, a, Sum;

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

inline ll inv(ll num, ll mod){
    return pow_mod(num, mod - 2, mod) % mod;
}

ll C(ll x, ll y){
	ll temp = 1;
	for(int i = 1; i <= y; ++i){
		temp = temp * (x - i + 1) % MOD;
		temp = temp * inv(i, MOD) % MOD;
	}
	return temp;
}

int main(){
//	ios::sync_with_stdio(false);
	scanf("%lld %lld", &n, &m);
	for(int i = 1; i <= n; ++i){
		scanf("%lld", &a);
		Sum += a;
	}
	printf("%lld", C(m + n, n + Sum));
	return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

template<int64 mod>
struct ModInt{
  int64 x;
  constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){}
  constexpr ModInt& operator+=(const ModInt& a){
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt& operator-=(const ModInt& a){
    if((x -= a.x) < 0)x += mod;
    return *this;
  }
  constexpr ModInt& operator*=(const ModInt& a){
    x = x * a.x % mod;
    return *this;
  }
  constexpr ModInt& operator/=(const ModInt& a){
    *this *= a.inv();
    return *this;
  }
  constexpr ModInt operator-() const {
    return ModInt(-x);
  }
  constexpr ModInt operator+(const ModInt& a) const {
    return ModInt(*this) += a;
  }
  constexpr ModInt operator-(const ModInt& a) const {
    return ModInt(*this) -= a;
  }
  constexpr ModInt operator*(const ModInt& a) const {
    return ModInt(*this) *= a;
  }
  constexpr ModInt operator/(const ModInt& a) const {
    return ModInt(*this) /= a;
  }
  constexpr ModInt operator++(){
    *this += ModInt(1);
    return *this;
  }
  constexpr ModInt operator++(int){
    ModInt old = *this;
    ++*this;
    return old;
  }
  constexpr ModInt operator--(){
    *this -= ModInt(1);
    return *this;
  }
  constexpr ModInt operator--(int){
    ModInt old = *this;
    --*this;
    return old;
  }
  constexpr bool operator==(const ModInt& a) const {
    return x == a.x;
  }
  constexpr bool operator!=(const ModInt& a) const {
    return x != a.x;
  }
  constexpr ModInt pow(int64 r) const {
    if(!r)return 1;
    ModInt res = pow(r>>1);
    res *= res;
    if(r & 1) res *= *this;
    return res;
  }
  constexpr ModInt inv() const {
    return pow(mod-2);
  }
  friend istream& operator>>(istream& is, ModInt& a){
    int64 t;
    is >> t;
    a = ModInt(t);
    return is;
  }
  friend ostream& operator<<(ostream& os, const ModInt& a){
    return os << a.x;
  }
};
using mint = ModInt<MOD>;

mint comb(int32 n, int32 r){
  if(r > n)return 0;
  r = min(r,n-r);
  mint res = 1;
  REP(i,r){
    res *= n-i;
    res /= i+1;
  }
  return res;
}

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

  int32 n,m;
  cin >> n >> m;
  vector<int32> a(n);
  REP(i,n)cin >> a[i];

  // {
  //   vector<vector<mint>> dp(n+1,vector<mint>(m+1));
  //   dp[0][0] = 1;
  //   REP(i,n){
  //     REP(j,m+1){
  //       REP(k,j+1){
  //         // dp[i+1][j] += dp[i][j-k] * comb(k,a[i]);
  //         dp[i+1][j] += dp[i][k] * comb(j-k,a[i]);
  //       }
  //     }
  //   }
  //   mint ans = 0;
  //   REP(i,m+1)ans += dp[n][i];
  //   ANS(ans);
  //   REP(i,m+1){
  //     REP(j,n+1){
  //       cout << dp[j][i] << " ";
  //     }
  //     cout << endl;
  //   }
  // }

  {
    int64 sumA = 0;
    REP(i,n)sumA += a[i];
    // mint ans = 0;
    // REP(i,m+1-sumA){
    //   ANS(comb(sumA + n + i - 1, i));
    //   ans += comb(sumA + n + i - 1, i);
    // }
    // ANS(ans);

    // ANS(comb(n+m,m-sumA));

    ANS(comb(n+m,n+sumA));
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std ;

#define int int64_t //be careful about this
#define endl "\n"
#define f(i,a,b) for(int i=int(a);i<int(b);++i)

#define pr pair
#define ar array
#define fr first
#define sc second
#define vt vector
#define pb push_back
#define eb emplace_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue

#define sz(x) ((int)(x).size())
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))

template<class A> void rd(vt<A>& v);
template<class T> void rd(T& x){ cin >> x; }
template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;}
template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;}

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

template<typename T>
void __p(T a) {
  cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cout<<"{";
  __p(a.first);
  cout<<",";
  __p(a.second);
  cout<<"}\n";
}
template<typename T>
void __p(std::vector<T> a) {
  cout<<"{";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cout<<",}\n"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cout<<name<<" : ";
  __p(arg1);
  cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cout.write(names,comma-names)<<" : ";
  __p(arg1);
  cout<<" | ";
  __f(comma+1,args...);
}

void setIO(string s = "") {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin.exceptions(cin.failbit);
	cout.precision(15);	cout << fixed;
  #ifdef ONLINE_JUDGE
  if(sz(s)){
  	freopen((s+".in").c_str(),"r",stdin);
  	freopen((s+".out").c_str(),"w",stdout);
  }
  #define __f(...) 0
  #endif
}
using ld = long double;
signed main(){
  setIO() ;
  int N,H,D; rd(N,D,H);
  vt<int> d(N),h(N);
  f(i,0,N) rd(d[i],h[i]);
  ld ans = 0;
  f(i,0,N){
  	ans = max(ans, ((ld)D * (ld)(H - h[i]))/(ld)(d[i] - D) + (ld)H);
  }
  cout << fixed << setprecision(10) << ans;
}

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

int main() {
  ll b, c;
  cin >> b >> c;
  ll mx1 = b + ((c - 2) / 2);
  ll mn1 = b - (c / 2);
  ll mx2 = -b + ((c - 1) / 2);
  ll mn2 = -b - ((c - 1) / 2);

  ll ans = (mx1 - mn1 + 1) + (mx2 - mn2 + 1) -
           max(min(mx1, mx2) - max(mn1, mn2) + 1, 0LL);
  cout << ans << endl;
  return 0;
}


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

#define SIZE 55

ll A[SIZE],maxi[SIZE];
ll dp[SIZE][2];

int main(){

	ll N,input_X;
	scanf("%lld %lld",&N,&input_X);

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

		scanf("%lld",&A[i]);
	}

	maxi[N-1] = HUGE_NUM;
	for(ll i = N-2; i >= 0; i--){

		maxi[i] = A[i+1]/A[i]-1; //使える最大枚数
	}

	stack<ll> S;
	ll X = input_X;

	for(ll i = N-1; i >= 0; i--){

		if(A[i] > X){

			S.push(0);
		}else{

			ll num = X/A[i];
			S.push(num);
			X %= A[i];
		}
	}

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

			dp[i][k] = 0;
		}
	}

	dp[0][0] = 1; //dp[見た桁][繰り上がり有無] := 場合の数

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

		ll x = S.top();
		S.pop();

		for(ll is_up = 0; is_up <= 1; is_up++){
			if(dp[i][is_up] == 0)continue;

			//ルンルンと店員、ともに0
			if(is_up+x == 0 || is_up+x == maxi[i]+1){

				if(is_up+x == 0){

					dp[i+1][0] += dp[i][is_up];

				}else{ //is_up+x == maxi[i]+1 ぴったり繰り上がり

					dp[i+1][1] += dp[i][is_up];
				}
			}

			//ルンルンが0で店員が非0
			if((x+is_up)%(maxi[i]+1) != 0){

				ll num = (maxi[i]+1)-(x+is_up);

				if(num > 0 && num <= maxi[i]){

					dp[i+1][1] += dp[i][is_up];
				}
			}

			//ルンルンが非0で店員が0
			if((x+is_up)%(maxi[i]+1) != 0){

				dp[i+1][0] += dp[i][is_up];
			}
		}
	}

	printf("%lld\n",dp[N][0]);

	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<ll, int>;

map<P, int> mp;
int N;
vector<ll> A(55);

ll solve(ll x, int i) {
    // i以降のコインを使う
    ll res;
    if (i == N - 1) {
        return 1;
    }
    if (mp[P(x, i)] != 0) return mp[P(x, i)];
    ll a = A[i], b = A[i+1];
    if (x % b == 0) {
        res = solve(x, i+1);
        mp[P(x, i)] = res;
        return res; // iは使わない
    }
    ll remain = x % b;
    x -= remain;
    res = solve(x, i+1) + solve(x+b, i+1);
    mp[P(x+remain, i)] = res;
    return res;
}

int main() {
    ll X;
    cin >> N >> X;
    rep(i, N) cin >> A[i];
    ll ans = solve(X, 0);
    cout << ans << '\n';
    return 0;
    // 境界、ll, 0, -, 1i, for s&g, debug
}


#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

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;

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

#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

struct RangeSum {
  using T = double;
  T operator()(const T &a, const T &b) { return a + b; }
  static constexpr T id() { return T(0); };
};

template <typename M>
struct SegmentTree {
  using Val = typename M::T;
  M calc;
  vector<Val> data;
  int n;
  explicit SegmentTree(int size) {
    n = 1;
    while (n < size) n <<= 1;
    data = vector<Val>(n << 1, calc.id());
  }
  explicit SegmentTree(vector<Val> &v) {
    n = 1;
    while (n < v.size()) n <<= 1;
    data = vector<Val>(n << 1);
    copy(v.begin(), v.end(), data.begin() + n);
    for (int i = n + (int)v.size(); i < 2 * n; i++) data[i] = calc.id();
    for (int i = n - 1; i > 0; --i) {
      data[i] = calc(data[i * 2], data[i * 2 + 1]);
    }
  }
  void update(int i, Val v) {
    int k = i + n;
    data[k] = v;
    for (k >>= 1; k >= 1; k >>= 1) data[k] = calc(data[k * 2], data[k * 2 + 1]);
  }
  Val query(int l, int r) {  //get[a,b)
    Val resl = calc.id(), resr = calc.id();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = calc(resl, data[l++]);
      if (r & 1) resr = calc(data[r - 1], resr);
    }
    return calc(resl, resr);
  }
};

class Solver2 {
 public:
  int n, m;
  vector<int> is_return;
  SegmentTree<RangeSum> a_0, a_x;
  Solver2(LL n, LL m) : n(n), m(m), is_return(n + 1), a_0(n + 1), a_x(n + 1){};

  void solve() {
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int tmp;
      cin >> tmp;
      is_return[tmp] = 1;
    }
    for (int i = 0, j = 0; i <= n; ++i) {
      if (is_return[i]) {
        j++;
        if (j == m) {
          cout << -1 << endl;
          return;
        }
      } else {
        j = 0;
      }
    }
    a_0.update(n, 0);
    a_x.update(n, 0);
    for (int i = n - 1; i > 0; --i) {
      if (is_return[i]) {
        a_0.update(i, 0);
        a_x.update(i, 1);
      } else {
        double sum_0 = a_0.query(i + 1, min(i + m, n) + 1);
        double sum_x = a_x.query(i + 1, min(i + m, n) + 1);
        a_0.update(i, sum_0 / m + 1.0);
        a_x.update(i, sum_x / m);
        if (i > 99900) DBG(i, m - (n - i), sum_0 / m + 1.0, sum_x / m)
      }
    }
    double sum_0 = a_0.query(1, min(m, n) + 1);
    double sum_x = a_x.query(1, min(m, n) + 1);
    DBG(sum_0 / m + 1.0, sum_x / m)
    double ans = (sum_0 / m + 1.0) / (1.0 - sum_x / m);
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


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

int main() {
  unsigned long long N,K;
  cin >> N >> K;
  for(int i=0;i<K;i++){
    if((N%200)==0){
      N = N/200;
    }else{
      N = N*1000+200;
    }
  }
  cout << N << endl;
}

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

int S(int n){
  int ret = 0;
  while(n>0){
    ret += n%10;
    n /= 10;
  }
  return ret;
}

int main(){
  int a,b;
  cin >> a >> b;
  int Sa = S(a);
  int Sb = S(b);
  if(Sa > Sb)
    cout << Sa  << endl;
  else
    cout << Sb << endl;
  return 0;
}


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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repp(i, a, b) for (int i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m, k;
    cin >> n >> m >> k;
    int sum = 0;
    rep(i, 1, n)
    {
        int a;
        cin >> a;
        sum += a;
    }
    int r = k * n;
    if ( r - sum <= m ){
        cout << max(r - sum,0);
    }
    else{
        cout << -1;
    }
}

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

string revAB(string str) {
    for(int i=0;i<str.size();++i) str[i]=(str[i]=='A'?'B':'A');
    return str;
}

int main() {
    int N,M; cin >> N; M = (1<<N);
    vector<vector<string>> S(N+1);
    S[1] = {"AB"};
    for(int i=2;i<=N;++i) {
        int L = (1<<i);
        S[i].push_back(string(L/2,'A')+string(L/2,'B'));
        for(int j=0;j<S[i-1].size(); ++j) {
            S[i].push_back(S[i-1][j]+S[i-1][j]);
        }
        for(int j=0;j<S[i-1].size(); ++j) {
            S[i].push_back(S[i-1][j]+revAB(S[i-1][j]));
        }
    }
    cout << S[N].size() << "\n";
    for(auto& s:S[N]) {
        cout << s << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define ceil(x, y) ((((x)%(y))==0)? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

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

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

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in7.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T = 1;
    // cin >> T;
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int n; cin >> n;
        int a[n+1];
        FOR1(i, n) cin >> a[i];
        int pref[n+1], swing[n+1];
        pref[1] = a[1];
        swing[1] = a[1];
        int curr = a[1];
        for(int i = 2; i <= n; i++){
            pref[i] = pref[i-1] + a[i];
            if(curr + a[i] > swing[i-1]) swing[i] = curr + a[i];
            else swing[i] = swing[i-1];
            curr += a[i];
        }
        int maxi = 0;
        curr = 0;
        for(int i = 1; i <= n; i++){
            maxi = max(maxi, curr + swing[i]);
            curr = curr + pref[i];
        }
        cout << maxi;
        cout << '\n';
    }
    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+1, 0), B(N+1, 0);
	REP(i, N) cin >> A[i+1];
	REP(i, N) A[i+1] += A[i];
	int64 maxi = 0, res = 0;
	FOR(i, 0, N) {
    chmax(maxi, A[i+1]);
	  A[i+1] += A[i];
	  chmax(res, A[i] + maxi);
	}
	cout << res << endl;
}


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

int N, M;
int H[200010];
int W[200010];

int A[200010];
int B[200010];

int get(int ary[200010], int a, int b)
{
	return ary[b] - ary[a];
}

int func(int k, int w)
{
	if (k % 2 == 0)
	{
		int v = get(A, 0, k / 2);
		int h = H[k] - w;
		int w = get(B, k / 2, N / 2);
		return v + h + w;
	}
	else
	{
		int v = get(A, 0, (k - 1) / 2);
		int h = w - H[k - 1];
		int w = get(B, (k - 1) / 2, N / 2);
		return v + h + w;
	}
}

int cur = 0;

//---------- にぶたん[f,f,f,f,'t',t,t,t] ----------
bool isOK(int index)
{
	return cur < H[index];
}

int binary_search(int n)
{
	int left = -1;
	int right = n;
	while (right - left > 1)
	{
		int mid = left + (right - left) / 2;
		if (isOK(mid))
			right = mid;
		else
			left = mid;
	}
	return right;
}

signed main()
{
	cin >> N >> M;
	REP(i, N) cin >> H[i];
	REP(i, M) cin >> W[i];
	H[N] = LLONG_MAX;

	ARY_SORT(H, N);

	A[0] = 0;
	for (int i = 0; i < N / 2; i++)
	{
		int i1 = i * 2;
		int i2 = i * 2 + 1;
		A[i + 1] = A[i] + abs(H[i2] - H[i1]);
	}

	B[0] = 0;
	for (int i = 0; i < N / 2; i++)
	{
		int i1 = i * 2 + 1;
		int i2 = i * 2 + 2;
		B[i + 1] = B[i] + abs(H[i2] - H[i1]);
	}

	int ans = LLONG_MAX;
	REP(i, M)
	{
		cur = W[i];
		int index = binary_search(N);
		int a = func(index, cur);
		ans = min(a, ans);
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

void solve()
{
    int n, m, q, x, y;
    cin >> n >> m >> q;
    vector<pair<int, int>> items;
    int boxes[m + 1];
    rep(i, n)
    {
        cin >> x >> y;
        items.pb({y, x});
    }
    sort(items.begin(), items.end(),greater<pair<int,int>>());
    rep(i, m)
    {
        cin >> boxes[i];
    }
    multiset<int> s;
    ll ans = 0;
    rep(i, q)
    {
        cin >> x >> y;
        for (int i = 0; i < x - 1; i++)
        {
            s.insert(boxes[i]);
        }
        for (int i = y; i < m; i++)
        {
            s.insert(boxes[i]);
        }
        for (int i = 0; i < n; i++)
        {
            int weight = items[i].second;
            int val = items[i].first;
            auto it = s.lower_bound(weight);
            if (it != s.end())
            {
                ans += val;
                s.erase(s.find(*it));
            }
        }
        cout << ans << endl;
        s.clear();
        ans=0;
    }
}

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

    solve();

    return 0;
}


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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(c % 2 == 0){
        if(abs(a) < abs(b)){
            cout << "<" << endl;
        }else if(abs(a) > abs(b)){
            cout << ">" << endl;
        }else{
            cout << "=" << endl;
        }
    }else{
        if(a < b){
            cout << "<" << endl;
        }else if(a > b){
            cout << ">" << endl;
        }else{
            cout << "=" << endl;
        }
    }
}

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

#define nl "\n"
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rnd(x) cout<<setprecision((int)(x)+1)
#define f(i,n) for(int i = 0;i <(int)(n);++i)
#define fr(i,n) for(int i = (int)(n) - 1;i>=0;i--)
#define rep(i,a,b) for(int i = (int)(a); i<=(int) (b); ++i)
#define repr(i,a,b) for(int i = (int)(b); i>=(int) (a); i--)

typedef vector<int> vi;
typedef pair<int, int> pi;

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

template<class T> int cnt1(T n){
    int cnt=0;
    while(n>0){cnt++;n = n&(n-1);}
    return cnt;
}

template<class T> void _print(T a){
    cerr<<a;
}

template<class T> void _print(vector<T> vi){
    cerr<<"[ ";
    for(T i:vi){ _print(i); cerr<<" ";}
    cerr<<"]";
}

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

void Solve(){
	int a,b,c;
	cin>>a>>b>>c;
	char s = '=';
	if(c%2==0){
		a = abs(a);
		b = abs(b);
	}
	if(a>b)
		s = '>';
	else if(a<b)
		s = '<';
	cout<<s<<nl;

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
    int t = 1;
    //cin>>t;
    rep(i,1,t)Solve();
}


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

using namespace std;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

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

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
constexpr int MOD = 998244353;
using mint = ModInt< MOD >;

template<typename T>
struct Combination{
  // T は mint の想定です
  int N;
  vector<T> fact_, inv_, finv_;

  Combination(){}
  Combination(int n):N(n+1), fact_(N,1), inv_(N,1), finv_(N,1){
    int mod = fact_.at(0).get_mod();

    for (int i = 2; i < N; i++){
      fact_.at(i) = fact_.at(i-1) * i;
      inv_.at(i) = -inv_.at(mod%i) * (mod/i);
      finv_.at(i) = finv_.at(i-1) * inv_.at(i);
    }
  }

  void init(int n) {
    N = n+1;
    fact_.assign(N, 1);
    inv_.assign(N, 1);
    finv_.assign(N, 1);

    int mod = fact_.at(0).get_mod();

    for (int i = 2; i < N; i++){
      fact_.at(i) = fact_.at(i-1) * i;
      inv_.at(i) = -inv_.at(mod%i) * (mod/i);
      finv_.at(i) = finv_.at(i-1) * inv_.at(i);
    }
  }

  T fact(int n){
    if(n < 0) return 0;
    assert(n<N);
    return fact_.at(n);
  }
  T inv(int n){
    if(n < 0) return 0;
    assert(n<N);
    return inv_.at(n);
  }
  T finv(int n){
    if(n < 0) return 0;
    assert(n<N);
    return finv_.at(n);
  }

  T com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    assert(n<N);
    return fact_.at(n) * finv_.at(k) * finv_.at(n-k);
  }

  T parm(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    assert(n<N);
    return fact_.at(n) *finv_.at(n-k);
  }

  T hom(int n, int k){
    if(n < 0 || k < 0) return 0;
    if(k == 0) return 1;
    assert(n+k-1<N);
    return com(n+k-1, k);
  }
};

int main(){
  int n, m; cin >> n >> m;
  /*
  dp_ij = 二進法でi桁目まで見て合計をjにするような方法
  i桁目でいくつbitを立てるか(偶数個)を全探索

  メモ化再帰:
  2^0の位をいくつ立てるかを全探索すると、
  (m - cnt)/2 のサイズの同じ問題にできる
  //*/

  Combination<mint> bc(n);
  vector<mint> memo(m+1);
  vector<bool> seen(m+1);

  auto dp = [&](auto f, int sum) -> mint{
    if(sum == 0) return 1;
    if(sum&1) return 0;
    if(seen[sum]) return memo[sum];
    seen[sum] = 1;
    mint res = 0;

    for(int i = 0; i*2 <= sum && i*2 <= n; i++){
      res += f(f, (sum-i*2)/2) * bc.com(n, i*2);
    }

    return memo[sum] = res;
  };

  cout << dp(dp, m) << endl;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

template <typename T> void read(T & x){
    x = 0; int op = 1; char ch = getchar();
    while (!isdigit(ch)){ if (ch == '-') op = -1; ch = getchar();}
    while (isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48); ch = getchar();}
    x*= op;
}

signed main(){
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int sum = 0;
    for (int i = 0; i < b; ++i) {
        int t = -900000 - i;
        cout << t << " ";
        sum += t;
    }
    for (int i = 1; i < a; ++i) {
        cout << i << " ";
        sum += i;
    }
    cout << -sum << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second

template<class T> T T_INF(){ return 1000000000000000000; }
template<> int T_INF<int>(){ return 1000000000; }

struct Tree{
	int n;
	vector<vector<pair<int,int>>> G;
	Tree(int n_){ init(n_); }
	Tree(){}
	void init(int n_){
		n=n_;
		G=vector<vector<pair<int,int>>>(n);
	}
	void add_edge(int u,int v,int i=0){
		G[u].push_back(mp(v,i));
	}
};

struct rooted_tree{
	Tree* Tr;
	int root;
	vector<pair<int,int>> par;
	vector<int> dep;
	vector<int> vs; //pre-orderにvertexを並べたもの
	vector<int> pre_order; //頂点iがpre-orderで何番目か
	rooted_tree(Tree* Tr_,int r=0):Tr(Tr_),root(r),par(Tr->n),dep(Tr->n),vs(Tr->n),pre_order(Tr->n,-1){ dfs(mp(r,-1),-1,0,0); }
	rooted_tree(){}
	int dfs(pair<int,int> e, int p,int d,int k){
		if(pre_order[e.fr]!=-1)return k;
		par[e.fr]=mp(p,e.sc);
		dep[e.fr]=d;
		vs[k]=e.fr;
		pre_order[e.fr]=k++;
		for(auto ed: Tr->G[e.fr])k=dfs(ed,e.fr,d+1,k);
		return k;
	}
};

template<class T> vector<T> dist_on_tree(const Tree &Tr, int s){
	vector<T> dist(Tr.n,-1);
	queue<int> que;
	dist[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front(); que.pop();
		for(auto ed: Tr.G[v]){
			if(dist[ed.fr]!=-1)continue;
			dist[ed.fr]=dist[v]+1;
			que.push(ed.fr);
		}
	}
	return dist;
}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	Tree Tr(n);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v); u--; v--;
		Tr.add_edge(u,v);
		Tr.add_edge(v,u);
	}
	rooted_tree rt(&Tr);

	vector<pair<int,int>> vs;
	for(int i=0;i<Tr.n;i++)vs.push_back(mp(rt.dep[i],i));
	sort(vs.begin(),vs.end(),greater<pair<int,int>>());

	int l=0,r=n-1;
	while(l<r){
		int m=(l+r)/2;
		bool ok=false;
		if(m<=800){
			static int d[200010];
			fill(d,d+n,-1);
			int cnt=0;
			for(auto p: vs){
				int v=p.sc;
				bool used=false;
				pair<int,int> loc(v,0);
				do{
					if(d[loc.fr]>=loc.sc){
						used=true;
						break;
					}
					loc.fr=rt.par[loc.fr].fr;
					loc.sc++;
				}while(loc.fr!=-1&&loc.sc<=m);
				if(!used){
					for(int i=0;i<m&&v!=-1;i++)v=rt.par[v].fr;
					if(v==-1)v=0;
					cnt++; if(cnt>k)break;
					loc=mp(v,0);
					do{
						d[loc.fr]=m-loc.sc;
						loc.fr=rt.par[loc.fr].fr;
						loc.sc++;
					}while(loc.fr!=-1&&loc.sc<=m);
				}
			}
			ok=cnt<=k;
		}
		else {
			static bool used[200010];
			fill(used,used+n,false);
			int cnt=0;
			for(auto p: vs){
				int v=p.sc;
				if(!used[v]){
					for(int i=0;i<m&&v!=-1;i++)v=rt.par[v].fr;
					if(v==-1)v=0;
					cnt++; if(cnt>k)break;
					auto d=dist_on_tree<int>(Tr,v);
					for(int i=0;i<n;i++)if(d[i]<=m)used[i]=true;
				}
			}
			ok=cnt<=k;
		}
		if(ok)r=m;
		else l=m+1;
	}
	cout<<l<<endl;
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL unsigned long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>
#define micro 0.000001

using namespace std;

//LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
//LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#else
#define AT
#define AE
#define ce(t)
#define __popcnt64 __builtin_popcountll
#define __popcnt __builtin_popcount
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } };

const int max_v = 2e5 + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
const LL mod = 998244353;

vector <int> adj[max_v];
struct node
{
    int cn,sl,mr;
};

node dfs(int idx,int dist,int par = -1)
{
    if (~par && adj[idx].size() == 1) return { 0,INF,0 };
    node ret = { 0,INF,-INF};

    for (auto& x : adj[idx]) if (x != par)
    {
         node tmp = dfs(x, dist, idx);
         ret.cn += tmp.cn;
         ckmin(ret.sl, tmp.sl+1);
         ckmax(ret.mr, tmp.mr+1);
    }

    //if (ret.mr == -INF) ret.mr = 0;

    if (ret.sl == INF)
    {
        if (ret.mr >= dist)
        {
            ret.sl = 0;
            ret.mr = -INF;
            ++ret.cn;
        }
    }
    else
    {
        if (ret.sl == 2 * dist + 1 || ret.mr>=dist)
        {
            ++ret.cn;
            ret.sl = 0;
            ret.mr = -INF;
        }
        else if (ret.sl > dist)
        {
            ckmax(ret.mr, ret.sl - dist - 1);
        }
        else if(ret.sl+ret.mr <=dist)
        {
            ret.mr = -INF;
        }
    }

    if (par == -1 && ret.mr!=-INF)
    {
        ++ret.cn;
    }

    return ret;
}

int main()
{
#ifdef OHSOLUTION
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k; ci(n >> k);

    vector <setl> test;

    fa(i, 0, n - 1)
    {
        int x, y; ci(x >> y); --x, --y;
        adj[x].push_back(y); adj[y].push_back(x);
        if (x > y) swap(x, y);
        test.push_back({ x,y });
    }

    if (n == k)
    {
        co(0);
        return 0;
    }

    int l = 1;
    int r = n;

    while (l != r)
    {
        int mid = l + r >> 1;
        if (dfs(0,mid).cn <= k) r = mid;
        else l = mid + 1;
    }
    co(l << "\n");

    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
char S[105];
int A[105];
int l[105],r[105],lcnt[105],rcnt[105];
int N,t;
bool check(int x)
{
    for(int i=0;i<=N;i++)
    {
        l[i]=A[i]/x;
        lcnt[i]=x-A[i]%x;
        r[i]=A[i]/x+1;
        rcnt[i]=A[i]%x;
    }
    for(int i=0;i<N;i++)
        if(S[i]=='<')
        {
            if(l[i]>=l[i+1])
                return false;
            if(l[i+1]==r[i]&&lcnt[i+1]>lcnt[i])
                return false;
        }
        else
        {
            if(l[i]<=l[i+1])
                return false;
            if(l[i]==r[i+1]&&lcnt[i]>lcnt[i+1])
                return false;
        }
    return true;
}
int binaryanswer(int l,int r)
{
    if(l==r)
        return l;
    if(r-l==1)
    {
        if(check(r))
            return r;
        return l;
    }
    int mid=(l+r)/2;
    if(check(mid))
        return binaryanswer(mid,r);
    else return binaryanswer(l,mid-1);
}
int main()
{
    scanf("%d",&N);
    scanf("%s",S);
    for(int i=0;i<=N;i++)
        scanf("%d",&A[i]);
    t=binaryanswer(1,10000);
    printf("%d\n",t);
    for(int i=0;i<t;i++)
    {
        for(int j=0;j<=N;j++)
            if(i<A[j]%t)
                printf("%d ",A[j]/t+1);
            else printf("%d ",A[j]/t);
        printf("\n");
    }
    return 0;
}

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

#ifdef LOCAL
#include "debug.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

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

  ll N; cin >> N;
  string S; cin >> S;

  vector<ll> A(N + 1, 0);
  ll K = 1e9;
  for (ll i = 0; i <= N; i++) {
    cin >> A[i];
    if (i > 0) K = min(K, abs(A[i] - A[i - 1]));
  }

  vector<vector<ll>> B(K, vector<ll>(N + 1, 0));
  for (ll i = 0; i <= N; i++) {
    ll q = A[i] / K, r = A[i] % K;
    for (ll j = 0; j < K; j++) {
      B[j][i] = q;
      if (j < r) B[j][i]++;
    }
  }

  cout << K << '\n';
  for (ll i = 0; i < K; i++) {
    cout << B[i][0];
    for (ll j = 0; j < N; j++) {
      cout << ' ' << B[i][j + 1];
    }
    cout << '\n';
  }

  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using P = pair<int, int>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

struct Edge {
    ll to;
    ll cost;
	Edge(ll to, ll cost) : to(to), cost(cost) {}
};

using Graph = vector<vector<Edge>>;
using _P = pair<long, int>;

/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s
    計算量：O(|E|log|V|)
*/
vector<ll> dijkstra(const Graph &G, int s) {
	int N = G.size();
	vector<ll> dis(N, INF);
    priority_queue<_P, vector<_P>, greater<_P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        _P p = pq.top();
        pq.pop();
        int v = p.second;	//v : 今見ている頂点
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
	return dis;
}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//頂点数、変数
	int N, M;
	cin >> N >> M;

	Graph G(N);
	FOR(i,0,M){
		int a, b, w;
		cin >> a >> b >> w;
		--a;
		--b;
		G.at(a).push_back(Edge(b, w));
	}

	//ダイクストラ法
	FOR(i,0,N){
		auto dis = dijkstra(G, i);
		ll ans = INF;
		FOR(j,0,N){
			for(auto x : G.at(j)){
				//cout<<x.to<<" "<<i<<endl;
				if(x.to == i){
					ans = min(ans, x.cost + dis.at(j));
				}
			}
		}
		//結果出力
		if(ans != INF)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}

	return 0;
}

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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<pair<int, int>>> e(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    e[a - 1].push_back({b - 1, c});
  }

  for (int i = 0; i < n; i++) {
    vector<int> d(n, -1);
    priority_queue<pair<int, int>> pq;
    pq.push({0, i});
    while (!pq.empty()) {
      pair<int, int> p = pq.top();
      pq.pop();
      if (d[p.second] == -1) {
        d[p.second] = -p.first;
        for (pair<int, int> q : e[p.second]) {
          if (d[q.first] == -1) {
            pq.push({p.first - q.second, q.first});
          }
        }
      }
    }

    int ans = -1;
    for (pair<int, int> p : e[i])
      if (p.first == i && (ans == -1 || p.second < ans))
        ans = p.second;
    for (int j = 0; j < n; j++) {
      if (j == i || d[j] < 0) continue;
      for (pair<int, int> p : e[j])
        if (p.first == i && (ans == -1 || p.second + d[j] < ans))
          ans = p.second + d[j];
    }
    printf("%d\n", ans);
  }

  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

// 1-indexed
template<typename T>
struct BIT{
    int n;
    vector<T> bit;
    BIT(int n_=0):n(n_),bit(n+1){}
    T sum(int i){
        T res=0;
        for(;i>0;i-=(i&-i))res+=bit[i];
        return res;
    }
    T sum(int l,int r){
        if(l>r)return 0;
        return sum(r)-sum(l-1);
    }
    void add(int i,T a){
        if(i==0)return;
        for(;i<=n;i+=(i&-i)){bit[i]+=a;}
    }
    int lower_bound(T k){ // k<=sum(res)
        if(k<=0)return 0;
        int res=0,i=1;
        while((i<<1)<=n)i<<=1;
        for(;i;i>>=1){
            if(res+i<=n&&bit[res+i]<k)k-=bit[res+=i];
        }
        return res+1;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    int q; cin >> q;
    vector<ll> v={0};
    vector<int> t(q),x(q),y(q);
    for(int i=0;i<q;i++){
        cin >> t[i] >> x[i] >> y[i];
        x[i]--;
        v.push_back(y[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    int K=v.size();
    BIT<int> bit1(K+1),bit2(K+1);
    BIT<ll> sum1(K+1),sum2(K+1);
    ll res=0;
    bit1.add(1,n);
    bit2.add(1,m);
    vector<int> a(n,1),b(m,1);
    auto getid=[&](int u)->int{
        return lower_bound(v.begin(), v.end(),u)-v.begin()+1;
    };
    for(int i=0;i<q;i++){
        if(t[i]==1){
            int id=a[x[i]];
            res-=sum2.sum(id,K);
            res-=v[id-1]*bit2.sum(id-1);
            bit1.add(id,-1);
            sum1.add(id,-v[id-1]);

            id=getid(y[i]);
            a[x[i]]=id;
            res+=sum2.sum(id+1,K);
            res+=v[id-1]*bit2.sum(id);
            bit1.add(id,1);
            sum1.add(id,v[id-1]);
        }
        else{
            int id=b[x[i]];
            res-=sum1.sum(id+1,K);
            res-=v[id-1]*bit1.sum(id);
            bit2.add(id,-1);
            sum2.add(id,-v[id-1]);

            id=getid(y[i]);
            b[x[i]]=id;
            res+=sum1.sum(id+1,K);
            res+=v[id-1]*bit1.sum(id);
            bit2.add(id,1);
            sum2.add(id,v[id-1]);
        }
        cout << res << "\n";
    }
}

#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}

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

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

long long modpow(long long a, long long b, long long m){
    long long ans = 1;
    while(b > 0){
        if (b % 2 == 1){
            ans *= a;
            ans %= m;
        }
        a *= a;
        a %= m;
        b /= 2;
    }
    return ans;
}

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}

vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

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

    return u;
}

// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

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

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

long long score(vector<long long> cnt){
    long long ans = 0;
    for(int i = 1;i <= 9;i++){
        long long res = i;
        for(int j = 0;j < cnt[i];j++){
            res *= 10;
        }
        ans += res;
    }
    return ans;
}

int main(){
    long long k;
    string s, t;
    cin >> k >> s >> t;
    vector<long long> aoki(10, 0), taka(10, 0), card(10, k);
    for(int i = 0;i < 4;i++){
        int a = int(s[i] - '0');
        int b = int(t[i] - '0');
        taka[a]++;
        aoki[b]++;
        card[a]--;
        card[b]--;
    }

    long long win = 0;
    for(int i = 1;i < 10;i++){
        aoki[i]++;
        for(int j = 1;j < 10;j++){
            taka[j]++;
            if (score(taka) > score(aoki)){
                win += card[i]*(card[j] - (i == j));
            }
            taka[j]--;
        }
        aoki[i]--;
    }
    long long r = 9*k - 8;
    cout << (double(win) / r) / (r - 1) << endl;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define Messi                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define pii pair<ll, ll>
#define mod 1000000007
#define vi vector<ll>
#define vii vector<pii>
#define all(v) v.begin(), v.end()
#define mi map<ll, ll>
//Never Let U Go!!

int main()
{
    Messi;
        ll n;
        cin >> n;
        ll a[5], b[17]={0};
        b[0] = 0;
        b[1] = 9;
        ll prev = b[1];
        for (ll i = 2; i <= 16; i++)
        {
            b[i] += ((prev * 10) + b[i - 1]);
            prev = prev * 10;
        }
        ll num = n, dig = 0;
        while (num > 0)
        {
            dig++;
            num /= 10;
        }
        if (dig < 4)
        {
            cout << "0\n";
            return 0;
        }
        ll cnt=1,k=0,ans=0;
        for (ll i = 4; i < dig; i++)
        {
            if(k%3==0)
            {
                ans+=cnt*(b[i]-b[i-1]);
                k++;
            }
            else if(k%3==1)
            {
                ans+=cnt*(b[i]-b[i-1]);
                k++;
            }
            else if(k%3==2)
            {
                ans+=cnt*(b[i]-b[i-1]);
                cnt++;
                k=0;
            }
        }
        cout<< ans + (n-b[dig-1])*cnt;

    return 0;
}