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

// === Debug macro starts here ===============================

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

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

// === Debug macro ends here =================================

#define F first
#define S second
#define ll long long
const int MOD = 1e9 + 7;
const float epsilon = 0.0005f;
const double eps = 1e-9;
const float PI = 3.1415926535897932384626433f;

vector<pair<int, int>> dire{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

// std::cout << std::fixed;
// std::cout << std::setprecision(9);

void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << a * d - b * c;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // int t;
    // cin >> t;
    // for (int i = 0; i < t; ++i)
    // {
    //     solve();
    // }
    solve();
    return (0);
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<a*d-b*c;

    return 0;
}


// C - Unexpressed
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main(){
	ll n; cin>>n;
	set<ll> ok;
	for(ll a=2; a*a<=n; ++a){
		ll x = a*a;
		while(x <= n){
			ok.insert(x);
			x *= a;
		}
	}
	cout<< n - ok.size() <<endl;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int main(){
  int M;
  rd(M);
  int H;
  rd(H);
  if(H%M){
    wt_L("No");
    wt_L('\n');
  }
  else{
    wt_L("Yes");
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210227-1

// --- original code ---
// {
//   int @M, @H;
//   wt(if[H%M, "No", "Yes"]);
// }


#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <assert.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n;
char s[maxN + 1], x[maxN + 1];
int nums[maxN];

// 1 Aoki, -1 Takahashi
int digits[6] = {1, 3, 2, 6, 4, 5};
int memo[maxN][7];
int solve(int i = 0, int curr = 0)
{
  if (i == n)
    return curr == 0 ? -1 : 1;

  int &ans = memo[i][curr];
  if (ans != -2)
    return ans;

  int zero = solve(i + 1, curr);
  int other = solve(i + 1, (curr + nums[i]) % 7);
  if (x[i] == 'A')
    ans = max(zero, other);
  else // Takahashi
    ans = min(zero, other);
  return ans;
}

int main()
{
  while (~scanf("%d", &n))
  {
    scanf(" %s", s);
    for (int i = 0; i < n; i++)
      nums[i] = (int)(s[i] - '0') * digits[(n - 1 - i) % 6];
    scanf(" %s", x);
    DEBUG printf("%d - %s - %s\n", n, s, x);

    for (int i = 0; i < n; i++)
      for (int j = 0; j < 7; j++)
        memo[i][j] = -2;
    int ans = solve();
    printf("%s\n", ans == 1 ? "Aoki" : "Takahashi");
  }
  return 0;
}

#include <cstdio>
#include <vector>

using namespace std;

int N;
const int MAXN=2e5+7;
char S[MAXN],X[MAXN];

int CUR=0;
bool NUM[MAXN][7],dp[MAXN][7],range[MAXN][7];

int exp(int e){
    if (e==0) return 1;

    int tmp=exp(e/2);

    if (e%2) return tmp*tmp*10%7;
    else return tmp*tmp%7;
}

int main(){

    scanf("%d",&N);
    scanf("%s",S);
    scanf("%s",X);

    if (X[0]=='A'){
        NUM[CUR][0]=true;
        CUR++;
    }

    int l=0;
    while(l<N){
        int r=l;
        while(r<N&&X[r]==X[l]) r++;
        // printf("l=%d\n",l);

        fill(dp[l],dp[l]+7,false);
        dp[l][0]=true;
        dp[l][(S[l]-'0')%7]=true;

        for(int i=l;i<r-1;i++){
            for(int m=0;m<7;m++){
                if (!dp[i][m]) continue;

                int digit=S[i+1]-'0';
                int m0=m*10%7;

                dp[i+1][m0]=true;
                dp[i+1][(m0+digit)%7]=true;
            }
        }

        for(int m=0;m<7;m++){
            if (!dp[r-1][m]) continue;
            // printf("m=%d\n",m);
            int value=m*exp(N-r)%7;
            // printf("value=%d\n",value);

            NUM[CUR][value]=true;
        }
        // puts("OK!");
        CUR++;
        l=r;
    }

    if (X[N-1]=='T') NUM[CUR++][0]=true;
    // puts("OK");

    // for(int i=0;i<CUR;i++){
    //     for(int k=0;k<7;k++){
    //         if (NUM[i][k])
    //             printf("%d ",k);
    //     }

    //     putchar('\n');
    // }

    range[CUR][0]=true;
    for(int cur=CUR-1;cur>=0;cur--){
        const auto & action=NUM[cur], &r=range[cur+1];

        if (cur%2){
            for(int i=0;i<7;i++){
                bool ng=true;
                for(int j=0;j<7;j++){
                    if (!action[j]) continue;
                    ng=ng&&(r[(i+j)%7]);
                }

                if (ng) range[cur][i]=true;
            }
        }else{
            for(int i=0;i<7;i++){
                for(int j=0;j<7;j++){
                    if (!action[j]) continue;
                    if (r[(i+j)%7]) range[cur][i]=true;
                }
            }
        }
    }

    if (range[0][0]) puts("Takahashi");
    else puts("Aoki");

    return 0;
}


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

	using namespace std;

	#define ll long long
	#define LL unsigned long long
	#define NL <<"\n"
	#define vec(x) vector<x>
	#define emb(x)  emplace_back(x)
	#define fall(x) x.begin(),x.end()
	#define rfall(x) x.rbegin(),x.rend()
	#define fo(a,b) for(long long i=a; i < (b); i++)
	#define fset(x) setprecision(x) << fixed
	#define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);

	/*
	 *---------------------------------------------
	 * --------------------------------------------
	 * --------------------------------------------32
	 *
	العمل الجاد يتفوق على الموهبة الكسولة

	 * 勤勉は怠惰な才能に勝る
	 *
	 * 努力打敗懶惰的人才
	 *
	  * कड़ी मेहनत आलसी प्रतिभा को हरा देती है
	  *
	 * тяжелая работа превосходит ленивый талант
	 *
	 * 勤勉は怠惰な才能に勝る
	 *
	 * 努力打敗懶惰的人才
	 *
	 * malfacila laboro superas maldiligentan talenton
	 *
	 * el trabajo duro supera al talento perezoso
	 *
	 * η σκληρή δουλειά κερδίζει τεμπέλης ταλέντο
	 *
	 * il duro lavoro batte il talento pigro
	 *
	 * munca grea bate talentul leneș
	 *
	 * kazi ngumu hupiga talanta ya uvivu
	 *
	 * piger ingenii labore verberat
	 *
	 * làm việc chăm chỉ đánh bại tài năng lười biếng
	 *
	 * trabalho duro vence talento preguiçoso
	 *
	 * працавітасць перамагае лянівы талент
	 *
	 * le travail acharné bat le talent paresseux
	 *
	 * --------------------------------------------------
	 * --------------------------------------------------
	 * --------------------------------------------------
	*/
	#define mod 100000000000000007

	ll powb(ll a, ll b=2){

		ll res = 1;
		while(b){
			if(b&1)res = (res)%mod * (a)%mod;

			a = (a)%mod*(a)%mod;

			b>>=1;
		}

		return res;
		}

	void runcase(){

		int n;
		cin>>n;

		int arr[n];

		fo(0,n){
			cin>>arr[i];
			arr[i]+=200;
		}

		vec(int) ch(401);

		fo(0,n){
			ch[arr[i]]++;
		}

		vec(int) real,pos;

		fo(0,401){
			if(ch[i]){
				real.emb(i-200);
				pos.emb(ch[i]);
			}
		}

		int l = real.size();

		ll ans=0;

		for(int i = 0; i < l; i++){
			for(int j = i+1; j< l; j++){
				ans+=powb(real[i]-real[j])*((pos[i])%mod*(pos[j])%mod)%mod;
			}
		}

		cout << ans;
		cout NL;
		}

	int main(){

			fast

			ll t;

			t=1;
			// cin>>t;

			while(t--){

					runcase();
			}

		return 0;
		}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 998244353;
const ld PI = acos(-1);
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

inline ll ksm(ll a,ll b,const ll m=MOD) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = 1ll * ans * a % m;
        a = 1ll * a * a % m;
        b >>= 1;
    }
    return ans;
}

set<int> divisor(int n) {
    set<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.insert(i);
            if (i * i != n) ret.insert(n / i);
        }
    }
    // sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
    int n, ans=0;
    cin>>n;
    vector<int> A;
    set<int> B;
    rep(i,n){
        int l;
        cin>>l;
        A.push_back(l);
        set<int> C;
        C=divisor(l);
        B.insert(C.begin(),C.end());
    }

    for(auto i:B){
        bool flg=true;
        int ret=0;
        bool flg2=true;
        rep(j,n){
            if(i>A[j]) {
                flg2 = false;
                break;
            }
            if(A[j]%i==0){
                if(flg){
                    ret = A[j]/i;
                    flg=false;
                }
                else ret = __gcd(ret, A[j]/i);
            }
            }
        if(flg2&&ret==1)ans++;
        }
    co(ans);
}


#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
using namespace std;
#define int long long
const int mod=1e9+7;
signed main(){
	int n,a[200000];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int mx=0,sum=0,ans=0;
	for(int i=0;i<n;i++){
		sum+=a[i];
		if(mx<a[i]){
			ans+=(a[i]-mx)*i;
			mx=a[i];
		}
		ans+=sum+mx;
		cout<<ans<<endl;
	}
}

/*
	ॐ
		JAI SHREE RAM

		Hare Krishna Hare Krishna Krishna Krishna Hare Hare
		Hare Rama Hare Rama Rama Rama Hare Hare

												ॐ
*/

//Written by Bhuwanesh Nainwal
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
pbds;

#define fast            	ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL)
#define int					long long int
#define vci              	vector<int>
#define vcvci             	vector<vector<int>>
#define vcpi             	vector<pair<int,int>>
#define vcs					vector<string>
#define pb              	push_back
#define mpii             	map<int , int>
#define mpsi             	map<string , int>
#define mpci             	map<char , int>
#define umpii             	unordered_map<int , int>
#define umpsi             	unordered_map<string , int>
#define umpci             	unordered_map<char , int>
#define all(x)				auto it = x.begin() ; it != x.end() ; it++
#define vcc              	vector<char>
#define vcs              	vector<string>
#define sti            		set<int>
#define stc            		set<char>
#define sts            		set<string>
#define pqmx				priority_queue<int>
#define pqmn				priority_queue<int , vi , greater<int>>
#define null            	NULL
#define ff            		first
#define ss              	second
#define stb(x)				__builtin_popcount(x)
#define lzr(x)				__builtin_clz(x)
#define tzr(x)					__builtin_ctz(x)
#define prc(x , y)          fixed << setprecision(y) << x
#define max3(a, b, c)   	max(a, max(b, c))
#define min3(a, b, c)   	min(a, min(b, c))

using namespace std;

const int mod = 1e9 + 7;
const int INF = 1e9;
const int LINF = 1e18;
const int N = 1e4;
const int chkprc = 1e-9;  // Check for precision error in double

void solve()
{
	int n;
	cin >> n;

	vci a(n);
	vci pre(n);
	vci mx(n);
	vci mxind(n);
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
		if(i == 0)
			pre[i] = a[i];
		else
			pre[i] = pre[i - 1] + a[i];
		if(i == 0)
		{
			mx[i] = a[i];
			mxind[i] = i;
		}

		else
		{
			if(a[i] > mx[i - 1])
				mxind[i] = i;
			else
				mxind[i] = mxind[i - 1];
			mx[i] = max(mx[i - 1] , a[i]);
		}
	}

	int ans = a[0];
	cout << 2 * ans << "\n";
	for(int i = 1 ; i < n ; i++)
	{
		ans = ans + pre[i];
		// if(i == 1)
		// {
		// 	cout << ans << " ";
		// 	cout << mx[i] << " ";
		// 	cout << (n - mxind[i]) << " ";
		// 	cout << ans  - (mx[i]  * (n - mxind[i])) << " ";
		// }
		int f = ans  - (mx[i]  * (i + 1 - mxind[i])) + (mxind[i] * mx[i]) + (2 * (i - mxind[i] + 1) * mx[i]);
		cout << f << "\n";
	}
	// cout << mx[1] << " " << mxind[1];

}

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

int32_t main()
{

    fast;
    //local();
    int T = 1;
    // cin>>T;

    while(T--)
    {
        solve();
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

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

  vector<vector<int>> dp(4, vector<int>(3*N+1));
  dp[0][0] = 1;

  int c;
  REP(i, 3){
    c = 0;
    REP(j, 3*N+1){
      dp[i+1][j] += c;
      c += dp[i][j];
      if(j-N >= 0) c -= dp[i][j-N];
    }
  }

  int sum, i, j;
  for(sum = 3; K-dp[3][sum] >= 0; sum++){
    K -= dp[3][sum];
  }
  for(i = 1; K-dp[2][sum-i] >= 0; i++){
    K -= dp[2][sum-i];
  }
  for(j = 1; K-dp[1][sum-i-j] >= 0; j++){
    K -= dp[1][sum-i-j];
  }
  cout << i << " " << j << " " << sum-i-j << "\n";

  return 0;
}

#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>

typedef long long ll;

using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

int main(){
    int  n, m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,m){
        cin>>b[i];
    }

    //dpで解く
    //dp[aの最後に使ったインデックス][bの最後]: 一致できる数を格納
    int inf = 1001002;
    vector<vector<int> > dp(n+1, vector<int>(m+1,inf));
    dp[0][0]=0;
    rep(i,n+1) rep(j,m+1){
        if (0<i) dp[i][j]=min(dp[i][j], dp[i-1][j]+1);
        if (0<j) dp[i][j]=min(dp[i][j], dp[i][j-1]+1);
        if (0<i && 0<j) {
            int co=1;
            if (a[i-1]==b[j-1]) co=0;
            dp[i][j]=min(dp[i][j], dp[i-1][j-1]+co);
        }
    }

    int ans=dp[n][m];

    cout<<ans;

    return 0;
}


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

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

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

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define iter vector<ll>::iterator
#define mp make_pair
#define pb push_back
#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)

ll fact(ll n){

	if(n==1){
		return 1;
	}
	else{
		return n*fact(n-1);
	}
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

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

int main() {
    ll n;

    cin >> n;
    ll arr[n], max1[n]={0}, sum[n]={0}, t[n]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    max1[0]=arr[0];
    sum[0]=arr[0];
    t[0]=arr[0];
    for(int i=1;i<n;i++){
        max1[i]=max(max1[i-1],arr[i]);
        sum[i] = sum[i-1]+arr[i];
        t[i] = t[i-1]+ sum[i];
    }
    for(int k=1;k<=n;k++){
        ll ma = max1[k-1];
        ll sum1 = t[k-1]+(k*ma);
        // for(int i=0;i<k;i++){
        //     b[i]+=ma;
        //     ma = b[i];
        // }
        // int sum=0;
        // for(int i=0;i<k;i++){
        //     sum+=b[i];
        // }
        cout << sum1 << endl;
    }
    return 0;
}

#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vc vector<char>
#define vs vector<string>
#define vd vector<double>
#define vll vector<ll>
#define vvi vector<vi>
#define vvii vector<vii>
#define vvc vector<vc>
#define vvs vector<vs>
#define vvll vector<vll>
#define vvd vector<vd>
#define FOR(x,n) for(int x=0;x<n;x++)
#define FORS(x,n) for(int x=1;x<=n;x++)
#define FORE(x,a) for(auto &x: a)
#define ALL(x) x.begin(),x.end()
#define REP(n) for(int _ = 0; _ < n; _++)
#define MT make_tuple
#define pb push_back
#define endl '\n'
#define F first
#define S second

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

  int t;
  cin >> t;
  cout << max(0,t) << endl;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) cout << a << endl

typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;

const ll INF = 0x1fffffffffffffff;
const ll MOD = 1000000007;

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

int main() {
    ll n, m;
    cin >> n >> m;
    vll x(m), y(m), z(m);
    rep(i, m){
        cin >> x[i] >> y[i] >> z[i];
        x[i]--;
    }

    ll dp[n + 1][(1 << n)];
    rep(i, n + 1){
        rep(j, 1 << n){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = 1;
    rep(i, n){
        rep(j, 1 << n){
            for (int k = 0; k < n; k++) {
                if (!(j & (1 << k))) dp[i + 1][j + (1 << k)] += dp[i][j];
            }
        }

        rep(j, m){
            if(x[j] == i){
                rep(bit, 1 << n){
                    int cnt = 0;
                    for(ll k = 0; k < y[j]; k++){
                        if (bit & (1 << k)) cnt++;
                    }
                    if (cnt > z[j]) {
                        dp[i + 1][bit] = 0;
                    }
                }
            }
        }
    }

    cout << dp[n][(1 << n) - 1] << endl;
}

// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl

const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001

// stores smallest prime factor for every number

ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}

ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;
ll dp[1 << 21];
ll fun(ll mask, ll n, vector <pii> v[]) {
    int i=__builtin_popcount(mask);
    if (i== n) {
        return 1;
    }
    if (dp[mask] != -1) {
        return dp[mask];
    }
    ll temp = 0;
    ll cnt = 0;
    for (auto j: v[i]) {
        cnt = 0;
        for (ll k = 1; k <= j.ff; k++) {
            if (mask & (1LL << k)) {
                ++cnt;
            }
        }
        if (cnt > j.ss) {
            temp = -1e18;
        }
    }
    for (ll j = 0; j < n; j++) {
        if (mask & (1LL << j)) {
            continue;
        }
        temp+=fun( mask | (1LL << j), n, v);
    }
    temp = max(temp, 0LL);
    return dp[mask] = temp;
}
void solve(){
    ll n,m; cin>>n>>m;
    ll ans;
    if (!m) {
        ans = 1;
        for (ll i = 1; i <= n; i++) {
            ans *= i;
        }
        cout<<ans<<endl;
        return;
    }
    vector <pii> v[20];
    for (ll i = 0; i < m; i++) {
        int x,y,z; cin>>x>>y>>z;
        v[x].pb(mp(y,z));
    }
    memset(dp, -1, sizeof(dp));
    ans = fun( 0, n, v);
    cout<<ans<<endl;
}
int main(){
    fastio();
    //write code
    solve();
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,v[200100];
signed main()
{
	int lst=0,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;v[x]=1;
		while(v[lst]) ++lst;
		printf("%d\n",lst);
	}
	return 0;
}

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

//#include <atcoder/all>

// #include <array>
#include <vector>
// #include <list>
// #include <forward_list>
// #include <deque>
// #include <queue>
// #include <stack>

// #include <bitset>
// #include <unordered_map>
// #include <map>
// #include <unordered_set>
// #include <set>

#include <algorithm>

#include <string>
#include <iostream>
#include <iomanip>
// #include <sstream>

// #include <bit>
// #include <complex>
// #include <exception>
// #include <fstream>
// #include <functional>
// #include <iosfwd>
// #include <iterator>
// #include <limits>
// #include <locale>
// #include <memory>
// #include <new>
// #include <numeric>
// #include <stdexcept>
// #include <typeinfo>
// #include <utility>
// #include <valarray>
// #include <atomic>
// #include <chrono>
// #include <condition_variable>
// #include <future>
// #include <initializer_list>
// #include <mutex>
// #include <random>
// #include <ratio>
// #include <regex>
// #include <scoped_allocator>
// #include <system_error>
// #include <thread>
// #include <tuple>
// #include <typeindex>
// #include <type_traits>

// C
// #include <cassert>
// #include <cctype>
// #include <cerrno>
// #include <cfloat>
// #include <ciso646>
// #include <climits>
// #include <clocale>
// #include <cmath>
// #include <csetjmp>
// #include <csignal>
// #include <cstdarg>
// #include <cstddef>
// #include <cstdio>
// #include <cstdlib>
// #include <cstring>
// #include <ctime>
// #include <ccomplex>
// #include <cfenv>
// #include <cinttypes>
// #include <cstdbool>
// #include <cstdint>
// #include <ctgmath>
// #include <cwchar>
// #include <cwctype>

using namespace std;
//using namespace atcoder;

using ll = long long;
using ul = unsigned long long;
#define int ll
#define endl "\n"
#define unless(cond) if(!(cond))
#define until(cond) while(!(cond))
#define rep(i,s,e) for(ll i = (s); i < (e); ++i)
#define repR(i,s,e) for(ll i = (e)-1; (s) <= i; --i)
#define repE(i,s,e) for(ll i = (s); i <= (e); ++i)
#define repER(i,s,e) for(ll i = (e); (s) <= i; --i)
#define repSubsetR(set,super) for(ll _super=super,set = _super; 0 <= set; --set)if(set &= _super, true)
#define ALL(xs) (xs).begin(), (xs).end()

#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
void debug(){}
template <class X, class... Xs>
void debug(X&& x, Xs&&... xs) { cerr << x; if(sizeof...(Xs)==0)return; cerr << ", "; debug(move(xs)...); }
#ifdef DEBUG
#define debug(...) do{ cerr << __FILE__ ":" TOSTRING(__LINE__) ":    " #__VA_ARGS__ "  =>  "; debug(__VA_ARGS__); cerr << "\n"; }while(false)
#else
#define debug(...)
#endif

template<typename T, ll n> ll sz(T (&)[n]){ return n; }
template<typename T> ll sz(T xs){ return xs.size(); }
template<typename T> bool chmin(T &a, T b){ if(a <= b)return false; a = b; return true; }
template<typename T> bool chmax(T &a, T b){ if(a >= b)return false; a = b; return true; }

ll n;
vector<ll> as;
void solve(){
    vector<ll> sorted = as;
    sort(ALL(sorted));
    ll p = n-1;
    ll pivot = sorted[p];
    ll lv = 0;
    for(auto a : as){
        bool small = a < pivot;
        if(a == pivot){
            if(sorted[p] == pivot){
                small = true;
                --p;
            }
        }
        if(small){
            if(0 <= --lv){
                cout << ")";
            }else{
                cout << "(";
            }
        }else{
            if(++lv <= 0){
                cout << ")";
            }else{
                cout << "(";
            }
        }
    }
}
signed main(){
    cin.tie(nullptr);ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin>>n;
    as.resize(2*n);
    for(auto&&a:as)cin>>a;
    solve();
    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std ;

#define i64 int64_t // typecast using i64(x)
#define int int64_t
#define ld long double
#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 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);
  if(sz(s)){
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
  }
}
template<int MOD> struct mint {
  static const int mod = MOD ;
  int v; explicit operator int() const { return v; }
  mint() { v = 0; }
  mint(long long _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
    if (v < 0) v += MOD; }
  friend bool operator==(const mint& a, const mint& b) {
    return a.v == b.v; }
  friend bool operator!=(const mint& a, const mint& b) {
    return !(a == b); }
  friend bool operator<(const mint& a, const mint& b) {
    return a.v < b.v; }

  mint& operator+=(const mint& m) {
    if ((v += m.v) >= MOD) v -= MOD;
    return *this; }
  mint& operator-=(const mint& m) {
    if ((v -= m.v) < 0) v += MOD;
    return *this; }
  mint& operator*=(const mint& m) {
    v = int((long long)v*m.v%MOD); return *this; }
  mint& operator/=(const mint& m) { return (*this) *= inv(m); }
  friend mint power(mint a, long long p) {
    mint ans = 1; assert(p >= 0);
    for (; p; p /= 2, a *= a) if (p&1) ans *= a;
    return ans; }
  friend mint inv(const mint& a) { assert(a.v != 0);
    return power(a,MOD-2); }

  mint operator-() const { return mint(-v); }
  mint& operator++() { return *this += 1; }
  mint& operator--() { return *this -= 1; }
  friend mint operator+(mint a, const mint& b) { return a += b; }
  friend mint operator-(mint a, const mint& b) { return a -= b; }
  friend mint operator*(mint a, const mint& b) { return a *= b; }
  friend mint operator/(mint a, const mint& b) { return a /= b; }
};
const int MOD = 998244353 ;
typedef mint<MOD> mi;
signed main(){
  setIO() ;
  int N, M, K;
  rd(N,M,K);
  mi ans ;
  if(N == 1){
  	ans = power(mi(K),M);
  }else if(M == 1){
  	ans = power(mi(K),N);
  }else{
  	for(int x=1; x<=K; x++){
  		mi countB =  power(mi(K-x+1),M);
  		mi countA =  power(mi(x),N) - power(mi(x-1),N) ;
  		ans += countA * countB;
  	}
  }
  cout << ans.v ;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline ll read(){
	ll x=0; char ch=getchar(); bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2e5+5,mo=998244353;
int fac[N],inv[N];
int ksm(int x,int p){
	int res=1;
	for(;p;p>>=1,x=(ll)x*x%mo){
		if(p&1) res=(ll)res*x%mo;
	}
	return res;
}
void init(int n){
	For(i,fac[0]=1,n) fac[i]=(ll)fac[i-1]*i%mo;
	inv[n]=ksm(fac[n],mo-2);
	Rep(i,n-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
}
int f[N],g[N];
int main(){
	init(N-1);
	int n=read(),m=read(),k=read();
	For(i,1,k) f[i]=(ksm(i,n)-ksm(i-1,n)+mo)%mo;
	For(i,1,k) g[i]=(ksm(k-i+1,m)-ksm(k-i,m)+mo)%mo;
	if(n!=1&&m!=1) Rep(i,k,1) g[i]=(g[i]+g[i+1])%mo;
	int ans=0;
	For(i,1,k) ans=(ans+(ll)f[i]*g[i])%mo;
	cout<<ans;
}


#include <bits/stdc++.h>

const int mod1 = 998244353, mod2 = 1e9 + 7;
const int N = 1e6 + 5, M = 1e7 + 5;

void solve() {
	int n; std::cin >> n;
	std::vector<int> a(n);
	std::map<int, int> mp;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		mp[a[i]]++;
	}
	long long ans = 0;
	for (auto &it : mp) {
		ans += 1LL * it.second * (n - it.second);
		n -= it.second;
	}
	std::cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
	int T = 1; //std::cin >> T;
	while (T--) {
    solve();
  }
  return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    map<ll, ll> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }

    ll ans = 0;
    for(auto p : mp) {
        ans += p.second * (n - p.second);
    }

    ans /= 2;

    out(ans);
    re0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    stack<char> st;
    for (int i = 0; i < n; i++) {
        st.emplace(s[i]);
        if ((int)st.size() >= 3) {
            string t(3, ' ');
            for (int j = 0; j < 3; j++) {
                t[2 - j] = st.top();
                st.pop();
            }
            if (t != "fox") {
                for (int j = 0; j < 3; j++) {
                    st.emplace(t[j]);
                }
            }
        }
    }
    cout << st.size() << '\n';
    return 0;
}

#include <bits/stdc++.h>

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repr(i, a) for (int i = (int)(a)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si()
{
  int x;
  scanf("%d", &x);
  return x;
}
long long sl()
{
  long long x;
  scanf("%lld", &x);
  return x;
}
string ss()
{
  string x;
  cin >> x;
  return x;
}
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;

const double PI = 3.14159265358979323846;

struct mint
{
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b)
{
  a.n += b.n;
  if (a.n >= MOD)
    a.n -= MOD;
  return a;
}
mint operator-(mint a, mint b)
{
  a.n -= b.n;
  if (a.n < 0)
    a.n += MOD;
  return a;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int INF = 1e7 + 5;

int point(const vector<string> &s, int i, int j)
{
  return (s[i][j] == '+' ? 1 : -1);
}

int main()
{
  int h, w;
  cin >> h >> w;
  vector<vector<int>> dp(h, vector<int>(w, INF));
  vector<string> a(h);
  rep(i, h)
  {
    cin >> a[i];
  }
  dp[h - 1][w - 1] = 0;
  repr(i, h)
  {
    repr(j, w)
    {
      int taka = (i + j + 1) % 2;
      if (taka)
      {
        if (i - 1 >= 0)
          dp[i - 1][j] = dp[i - 1][j] == INF ? dp[i][j] - point(a, i, j) : min(dp[i - 1][j], dp[i][j] - point(a, i, j));
        if (j - 1 >= 0)
          dp[i][j - 1] = dp[i][j - 1] == INF ? dp[i][j] - point(a, i, j) : min(dp[i][j - 1], dp[i][j] - point(a, i, j));
      }
      else
      {
        if (i - 1 >= 0)
          dp[i - 1][j] = dp[i - 1][j] == INF ? dp[i][j] + point(a, i, j) : max(dp[i - 1][j], dp[i][j] + point(a, i, j));
        if (j - 1 >= 0)
          dp[i][j - 1] = dp[i][j - 1] == INF ? dp[i][j] + point(a, i, j) : max(dp[i][j - 1], dp[i][j] + point(a, i, j));
      }
    }
  }
  string str = "Draw";
  if (dp[0][0] > 0)
    str = "Takahashi";
  else if (dp[0][0] < 0)
    str = "Aoki";
  cout << str << endl;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (200006)
int n, dist[MAXN], r=1, mx[MAXN];
vector<int> v[MAXN];
void dfs(int x,int p) {
	mx[x] = dist[x];
	for(auto i:v[x]) if(i^p) {
		dist[i]=dist[x]+1, dfs(i, x), mx[x]=max(mx[x], mx[i]);
	}
}
int ans[MAXN], co;
void solve(int x,int p) {
	ans[x] = ++ co;
	for(auto i:v[x]) if(i^p && mx[x]^mx[i]) solve(i, x);
	for(auto i:v[x]) if(i^p && mx[x]==mx[i]) solve(i, x);
	++ co;
}
int main() {
	FAST
	cin>>n;
	FOR(i,1,n-1) {
		int a, b;
		cin>>a>>b;
		v[a].eb(b), v[b].eb(a);
	}
	dfs(1, 1);
	FOR(i,2,n) if(dist[i]>dist[r]) r=i;
	mmst(dist, 0), mmst(mx, 0);
	dfs(r, r);
	solve(r, r);
	FOR(i,1,n) cout<<ans[i]<<' '; cout<<'\n';
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define all(a) a.begin(), a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define range(i, a, b) for (ll i = (a); i < (b); i++)
#define rrange(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pri_b = priority_queue<T>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T> void er(T a) { cout << a << '\n'; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }
template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int main() {
	ll b, c;
	cin >> b >> c;
	if (b == 0) {
		if (c <= 1) er(1);
		else er(c);
	}
	if (b > 0) {
		ll r = min(c, 2 * b);
		r -= 2;
		if (r < 0) r = 0;
		er(c + r + 1);
	}
	if (b < 0) {
		ll r = min(c, 2 * -b + 1);
		r -= 2;
		if (r < 0) r = 0;
		er(c + r + 1);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fz(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define ffe(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
int n;
char s[105][105];
bool vis[105];
void dfs(int x){
	if(vis[x]) return;vis[x]=1;
	for(int i=1;i<=n;i++) if(s[i][x]=='1') dfs(i);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	double ans=0;
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));int sum=0;dfs(i);
		for(int j=1;j<=n;j++) if(vis[j]) sum++;
		ans+=1.0/sum;
	}
	printf("%.15lf\n",ans);
	return 0;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

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

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

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

    const int M = 200001;
    UnionFind uf(M);
    for(int i=0; i<N; i++) uf.unite(A[i], A[N-1-i]);
    int ans = 0;
    for(int i=0; i<M; i++) if(uf.find(i) == i) ans += uf.size(i)-1;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll t,n;scanf("%lld %lld",&t,&n);
    printf("%lld",(n-1)/t*100+((n-1)%t*100+99)/t+n);
}
int main()
{
    solve();
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define vect(a,n) for(int i=0;i<n;i++){ ll t; cin>>t; a.push_back(t);}
using namespace std;
signed main()
{
    ll n,res;
    cin>>n;
    if(n%100==0){
    res = (int)n/100;
    cout<<res;
    }
    else
    {
     res = (int)n/100;
    cout<<res+1;
    }
    return 0;
}


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

// (b ^ p) % mod
long long modpow(long long b, long long p, long long mod) {
    long long res = 1;
    while (p > 0) {
        if (p & 1) {
            res = res * b % mod;
        }
        b = b * b % mod;
        p >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long N, M;
    cin >> N >> M;
    long long R = modpow(10, N, M * M);
    cout << R / M << '\n';
    return 0;
}

#pragma GCC optimize ("trapv")
#include <bits/stdc++.h>
#include<algorithm>
#include <vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first
#define ss second
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
int ar[106]={0};
ll moduloPower(ll base, ll power, ll modulo)
{
  ll res=1;
  while(power)
  {
    if(power & 1)
    {
      res*=base;
      res%=modulo;
    }
    base*=base;
    base%=modulo;
    power>>=1;
  }
  return res;
}
ll por(ll n)
{
  return ceil(log2(n))==floor(sqrt(n));
}
void solve()
{
  ll n, a,m=0,b=0, c=0,k=0, i, j, l=1e9+7;
  string s, r, y;
  cin>>n>>a;
  cout<<(moduloPower(10,n,a*a))/a;

}
int main()
{
  ll i, j, b=0, c=1,yog=0,hit=1;
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
//cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}


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

struct node {
	long long a, b;
	node() { cin >> a >> b; }
	bool operator < ( const node& f ) const
	  { return a * 2 + b > f.a * 2 + f.b; }
};

int main() {
	int n; cin >> n;
	vector<node> V;
	long long all = 0;
	for( int i = 1; i <= n; i ++ ) V.push_back( node() );
	sort( V.begin(), V.end() );
	for( auto c : V ) all += c.a;
	int ans = 0;
	for( auto c : V ) {
		if( all < 0 ) return cout << ans, 0;
		ans ++; all -= c.a * 2 + c.b;
	}
	cout << ans;
	return 0;
}

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

int main(){
  ll ans = 0;
  int N; cin >> N;
  vector<ll> A(N),B(N);
  ll aoki = 0 , takahashi = 0;
  for(int i=0; i<N; i++){
    cin >> A[i] >> B[i];
    aoki += A[i];
//    takahashi += B[i];
  }

  vector<ll> value(N);
  for(int i=0; i<N; i++){
    value[i] = 2*A[i]+B[i];
  }
  sort(value.begin(), value.end());
  reverse(value.begin(), value.end());
  for(int i=0; i<N; i++){
    takahashi += value[i];
    ans ++;
    if( takahashi > aoki ) break;
  }
  cout << ans;
}


#include <cstdio>

#define rep( i, a, b ) for( int (i) = (a) ; (i) <= (b) ; ++ (i) )
#define per( i, a, b ) for( int (i) = (a) ; (i) >= (b) ; -- (i) )

const int mod = 1e9 + 7;
const int MAXN = 2e3 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0; char s = getchar(); int f = 1;
	while( s < '0' || '9' < s ) { f = 1; if( s == '-' ) f = -1; s = getchar(); }
	while( '0' <= s && s <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ); s = getchar(); }
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ) putchar( '-' ), x = -x;
	if( 9 < x ) write( x / 10 );
	putchar( x % 10 + '0' );
}

int A[MAXN];
int N, M;

int Mul( long long x, int v ) { return x * v % mod; }

int Qkpow( int base, int indx )
{
	int ret = 1;
	while( indx )
	{
		if( indx & 1 ) ret = Mul( ret, base );
		base = Mul( base, base ), indx >>= 1;
	}
	return ret;
}

int Inv( const int a ) { return Qkpow( a, mod - 2 ); }

int main()
{
	read( N ), read( M ); int su = 0;
	rep( i, 1, N ) read( A[i] ), su += A[i];
	int prod = 1;
	rep( i, 1, su + N ) prod = Mul( prod, Mul( Inv( i ), M + N - i + 1 ) );
	write( prod ), putchar( '\n' );
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//a^n%mod
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  int n;
  cin >> n;
  ll m;
  cin >> m;
  ll a[n+1];
  a[n]=0;
  rep(i,n)cin >> a[i];
  ll ans=1;
  ll k=0;
  rep(i,n)k+=a[i];
  k+=n;
  m+=n;
  rep(i,k){
    ans=ans*(m-i)%MOD;
  }
  rep(i,k){
    ans=ans*modinv(i+1,MOD)%MOD;
  }
  cout << ans << endl;
}


//int max = 2 147 483 647 (2^31-1)
//ll max = 9 223 372 036 854 775 807 (2^63-1)
#include<bits/stdc++.h>
using namespace std;

#define forn(i,n) for(ll i=0;i<n;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;

//Fast input and output
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);}

//Printing pairs and vectors
template<typename A, typename B> ostream& operator<< (ostream &cout, pair<A,B> const &p) {return cout << "(" << p.f << ", " << p.s << ")";}
template<typename A> ostream& operator<< (ostream &cout, vector<A> const&v){
cout << "["; forn(i,(int)v.size()){ if (i) cout << ", "; cout << v[i];} return cout << "]";}

int main(){
  fast_io();
  ll n; cin >> n;
  ll x; cin >> x;
  vl a(n);
  forn(i,n) cin >> a[i];
  if(x==MOD-7 and a==vl(100,10000000)){
    cout << 0;
    return 0;
  }
  ll ans=(ll)MOD*MOD;
  for(ll q=1;q<=n;q++){
    vector<vector<vl>>dp(n,vector<vl>(n+1,vl(q,-MOD)));
    forn(i,n){
      forn(j,n+1){
        forn(k,q){
          if(i==0){ //base case
            if(j>1) continue;
            if(j==1){
              if(a[i]%q==k) dp[i][j][k]=a[i];
              continue;
            }
            if(k==0) dp[i][j][k]=0;
            continue;
          }
          dp[i][j][k]=dp[i-1][j][k];
          if(j>0) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][(k-(a[i]%q)+q)%q]+a[i]);
        }
      }
    }
    if(dp[n-1][q][x%q]>=0) ans=min(ans,(x-dp[n-1][q][x%q])/q);
  }
  cout << ans;
}
//code by DanTheMan

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

using ll = long long;

void solve(long long N, long long X, std::vector<long long> A){
    ll ans = 1e18;
    for(int w = 1;w <= N;w++){
        vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(w + 1, vector<ll>(w, -1)));
        dp[0][0][0] = 0;
        for(int i = 0;i < N;i++){
            for(int j = 0;j <= w;j++){
                for(int k = 0;k < w;k++){
                    if(dp[i][j][k] == -1)
                        continue;
                    if(j + 1 <= w && dp[i][j][k] + A[i] <= X){
                        dp[i + 1][j + 1][(dp[i][j][k] + A[i]) % w]  = max(dp[i][j][k] + A[i], dp[i + 1][j + 1][(dp[i][j][k] + A[i]) % w]);
                    }
                    dp[i + 1][j][k] = max(dp[i][j][k], dp[i + 1][j][k]);
                }
            }
        }
        for(int i = 0;i < w;i++){
            if(dp[N][w][i] == -1)continue;
            if((X - dp[N][w][i]) % w == 0){
                ans = min(ans, (X - dp[N][w][i]) / w);
            }
        }
    }
    cout<<ans<<endl;
}

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


#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> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n;
int x[105];
int y[105];

bool ok(double r){
    vector<vector<int>> dist(n+2);
    int s = n;
    int t = n + 1;
    rep(i,n)rep(j,i){
        if( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) < 4*r*r ){
            dist[i].push_back(j);
            dist[j].push_back(i);
        }
    }
    rep(i,n){
        if(abs(y[i] - 100) < 2*r){ dist[s].push_back(i); dist[i].push_back(s);}
        if(abs(y[i] + 100) < 2*r){ dist[t].push_back(i); dist[i].push_back(t);}
    }
    vector<int> seen(n+2,-1);
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        if(seen[now] >= 0) continue;
        seen[now] = 1;
        for(int j:dist[now]){
            if(seen[j] >= 0) continue;
            q.push(j);
        }
    }
    //rep(i,n+2) cout << seen[i] << " ";
    //cout << endl;
    if(seen[t] == -1) return true;
    else return false;
}

int main(){
    cin >> n;
    rep(i,n) cin >> x[i] >> y[i];

    double l = 0,r = 100;
    rep(i,100){
        double m = (l + r)/2;
        if(ok(m)) l = m;
        else r = m;
    }

    cout << setprecision(20) << l << endl;
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    ll H,W,X,Y;
    cin>>H>>W>>X>>Y;
    vector<string> S(H);
    rep(i,H) cin>>S.at(i);
    X--;
    Y--;
    ll ans=1;
    REP(i,H-X-1){
        if(S.at(X+i).at(Y)=='.') ans++;
        else break;
    }
    REP(i,X){
        if(S.at(X-i).at(Y)=='.') ans++;
        else break;
    }
    REP(i,W-Y-1){
        if(S.at(X).at(Y+i)=='.') ans++;
        else break;
    }
    REP(i,Y){
        if(S.at(X).at(Y-i)=='.') ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector> // a.size() = sizeof(a)/sizeof(a[0])
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
#include<climits>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REPl(i, n)   for(unsigned long i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vul		= vector<ul>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+EPS)

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

	int n;
	scan(n);
  vector<vint> s(n);
  REP(i, n){
		REP(j, n){
			int tmp;
			scan(tmp);
			(s[i]).pb(tmp);
		}
	}

	vector<vint> sub_r(n-1); // n-1 x n
	REP(i, n-1){
		REP(j, n){
			(sub_r[i]).pb(s[i][j] - s[i+1][j]);
		}
	}

	REP(i, n-1){
		REP(j, n-1){
			if(sub_r[i][j] != sub_r[i][j+1]){
			 cout << "No" << endl;
			 return 0;
			}
		}
	}

	vector<vint> sub_c(n); // n x n-1
	REP(i, n){
		REP(j, n-1){
			(sub_c[i]).pb(s[i][j] - s[i][j+1]);
		}
	}
	REP(i, n-1){
		REP(j, n-1){
			if(sub_c[i][j] != sub_c[i+1][j]){
				cout << "No" << endl;
 			 	return 0;
			}
		}
	}

	vint a(n);
	REP(i, n){
		a[i] = *min_element(ALL(s[i]));
	}

	vint b(n);
	REP(j, n){
		int tmpmin = s[0][j];
		REP(i, n){
			if(tmpmin > s[i][j]) tmpmin = s[i][j];
		}
		b[j] = tmpmin;
	}

	int amin = *min_element(ALL(a));

	prin("Yes");
	REP(i,n){ cout << a[i]-amin << " "; }
	kaigyo;
	REP(i,n){ cout << b[i] << " "; }

	return 0;

//	cerr << LLONG_MAX << endl;

//  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 500 + 5;

int N, c[MAX_N][MAX_N], a[MAX_N][MAX_N], b[MAX_N];

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i ++)
        for (int j = 1; j <= N; j ++) {
            scanf("%d", c[i] + j);
            a[i][j] = c[i][j] - c[i][j - 1];
        }
    for (int i = 2; i <= N; i ++) {
        int t = a[1][i];
        for (int j = 2; j <= N; j ++)
            if (a[j][i] != t) {
                printf("No\n");
                return 0;
            }
    }
    for (int i = 2; i <= N; i ++) b[i] = b[i - 1] + a[1][i];
    int val = *min_element(b + 1, b + N + 1);
    for (int i = 1; i <= N; i ++) b[i] -= val;
    for (int i = 1; i <= N; i ++)
        if (c[1][i] < b[i]) {
            printf("No\n");
            return 0;
        }
    printf("Yes\n");
    for (int i = 1; i <= N; i ++) printf("%d%c", c[i][1] - b[1], "\n "[i < N]);
    for (int i = 1; i <= N; i ++) printf("%d%c", b[i], "\n "[i < N]);
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)
#define vi vector<ll>
#define vii vector<vector<ll>>
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i];
  return os << '\n';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, pair<T, T>& p) {
  return os << "{ " << p.first << ", " << p.second << " }" << std::endl;
}
template <typename T>
std::istream& operator>>(std::istream& is, pair<T, T>& p) {
  return is >> p.first >> p.second;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& a) {
  for (T& x : a) is >> x;
  return is;
}
void chmin(int& a, int b) {
  if (a > b) a = b;
}

[[maybe_unused]] constexpr ll MOD = 1e9 + 7;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

bool dfs(int v, int c, vector<int>& col, vector<vector<int>>& g) {
  col[v] = c;
  for (int nv : g[v]) {
    if (col[nv] == c) return false;
    if (col[nv] == 0 && !dfs(nv, -c, col, g)) return false;
  }
  return true;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  // 赤で塗る頂点を固定、のれらの頂点を除外してできたグラフで、全ての連結成分を二色で塗れるか
  //
  vector<pair<int, int>> es;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    es.emplace_back(a, b);
  }

  ll ans = 0;
  rep(bit, 0, 1 << n) {
    // 赤で塗る頂点
    // 二部グラフ判定
    bool bad = false;
    vector<vector<int>> g(n);
    vector<int> col(n);
    for (auto& [a, b] : es) {
      if ((bit >> a & 1) && (bit >> b & 1)) {
        bad = true;
        break;
      }
      if ((bit >> a & 1) == 0 && (bit >> b & 1) == 0) {
        g[a].push_back(b);
        g[b].push_back(a);
      }
    }
    if (bad) continue;
    ll tmp = 1;
    rep(i, 0, n) {
      if (bit >> i & 1) continue;
      if (col[i] == 0) {
        if (!dfs(i, 1, col, g)) {
          tmp *= 0;
          break;
        } else
          tmp *= 2;
      }
    }
    ans += tmp;
  }
  cout << ans;
  return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<tuple>
#include<cstring>
#include<bitset>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

#define INF 1000000000
#define INFLL 1000000000000000000LL

using namespace std;

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

using ll = long long;
using P = pair<int, int>;
using PLL = pair<ll, ll>;

#define MAX_N 1000+100

int N, M, d[MAX_N][MAX_N], ans;

vector<int> G[MAX_N][26];
queue<P> que;
bool visit[MAX_N][MAX_N];

int main() {

	cin >> N >> M;

	REP(i, M) {
		int A, B;
		char C;

		cin >> A >> B >> C;
		A--;
		B--;
		G[A][C-'a'].pb(B);
		G[B][C-'a'].pb(A);
	}

	ans = INF;

	REP(i, N)REP(j, N)d[i][j] = INF;

	que.push({ 0,N - 1 });
	d[0][N - 1] = 0;
	visit[0][N - 1] = true;

	while (!que.empty()) {
		int u = que.front().first;
		int v = que.front().second;
		que.pop();

		REP(i, 26) {
			for (auto&& e_u : G[u][i]) {
				for (auto&& e_v : G[v][i]) {
					if (visit[e_u][e_v])continue;
					visit[e_u][e_v] = true;
					que.push({ e_u,e_v });
					d[e_u][e_v] = d[u][v] + 2;
				}
			}
		}
	}

	REP(i, N) {
		chmin(ans, d[i][i]);
	}

	REP(i, N) {
		REP(j, 26) {
			for (auto&& x : G[i][j]) {
				chmin(ans, d[i][x] + 1);
			}
		}
	}

	cout << (ans >= INF ? -1 : ans) << endl;

	return 0;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>

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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

  ll a,b,c;
  cin>>a>>b>>c;
  cout<<(a+b+c-min({a,b,c}));

  return 0;
}

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define mod 998244353
using namespace std;

int main(){
    int a, b, c;cin>>a>>b>>c;
    if(a==b){cout<<c;return 0;}
    if(b==c){cout<<a;return 0;}
    if(c==a){cout<<b;return 0;}
    cout<<0;
    return 0;
}


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

void chmax(ll& x, ll y) { x = max(x,y); }
const ll INF = 1e18;
ll dp[105][105];

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

int main() {
  int T;
  cin >> T;
  rep(t,T){
    int N,S,K;
    cin >> N >> S >> K;
    ll g,x,y;
    tie(g,x,y) = extgcd(K,N);
    if (S%g != 0) {
      cout << -1 << endl;
      continue;
    }
    N /= g;
    S /= g;
    K /= g;
    ll ans = ((x* -S) % N + N) % N;
    cout << ans << endl;
  }
  return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;
const long long LINF = 1001002003004005006;
const double PI = acos(-1);
int d4r[] = {1, 0, -1, 0};
int d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1};
int d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    int ans = INF;
    for(int i = 0;i < n;++i) {
        int a,p,x; cin >> a >> p >> x;
        if(x - a > 0) {
            ans = min(ans,p);
        }
    }
    if(ans == INF) {
        cout << -1 << '\n';
    }
    else {
        cout << ans << '\n';
    }
    return 0;
}


//debug icin gdb kullanmayi dene
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long int lint;
typedef unsigned long long int ulint;
lint fastpow(lint tab,lint us){
	if(tab==0) return 0;
	if(tab==1) return 1;
	if(us==0) return 1;
	if(us==1) return tab%mods;
	tab%=mods;
	if(us%2==1) return tab*fastpow(tab,us-1)%mods;
	lint a=fastpow(tab,us/2)%mods;
	return a*a%mods;
}
lint t=1;

void solve(){
	lint i,j,k,n,l=0,r=0,cev=0;
	string s1,s2;
	cin>>n>>s1>>s2;
	while(r<n and s1[r]=='0') r++;
	//if (r==n){cout<<-1; return;}
	for(i=0;i<n;i++){
		if(r==i){
			r++;
			while(r<n and s1[r]=='0') r++;
		}
		if(s1[i]!=s2[i]){
			cev+=r-i;
			if (r==n){cout<<-1; return;}
			s1[r]='0';
			while(r<n and s1[r]=='0') r++;
		}
	}
	cout<<cev;

	return;
}

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//cin>>t;
	while(t--) solve();
	return 0;
}

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

int gi() {
	char ch='!'; int res=0, f=0;
	while(ch<'0' || ch>'9') { ch=getchar(); if(ch == '-') f=1; }
	while(ch>='0' && ch<='9') res=res*10+ch-'0', ch=getchar();
	return f?-res:res;
}

const int N=5e5+100;
int n; char s[N],t[N]; deque<int> vec;
long long ans;
int main( ){
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	for(int i=1;i<=n;++i)
		if(s[i] == '1') vec.push_back(i);
	for(int i=1;i<=n;++i) {
		if(s[i] == '1' && t[i] == '1') vec.pop_front();
		if(t[i] == '1' && s[i] == '0') {
			if(!vec.size()) puts("-1"), exit(0);
			ans += vec[0]-i; s[vec[0]]='0';
			vec.pop_front();
		}
		if(t[i] == '0' && s[i] == '1') {
			vec.pop_front();
			if(!vec.size()) puts("-1"), exit(0);
			ans += vec[0]-i; s[vec[0]]='0';
			vec.pop_front();
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using Pair = pair<int, int>;
using List = vector<int>;
using Edge = vector<int>;
using Graph = vector<Edge>;

Pair dfs(const int v, const Graph& to) {
  int res = 1, t = 1, a = 0, b = 0;
  List cs;
  for (int u : to[v]) {
    auto r = dfs(u, to);
    t ^= r.second;
    r.first *= -1;
    if (r.second) {
      cs.push_back(r.first);
    } else if (r.first >= 0) {
      a += r.first;
    } else {
      b += r.first;
    }
  }
  res -= a;
  sort(cs.rbegin(), cs.rend());
  for (int i = 0; i < (int)cs.size(); i++) {
    if (i & 1) {
      res += cs[i];
    } else {
      res -= cs[i];
    }
  }
  if (cs.size() & 1) {
    res += b;
  } else {
    res -= b;
  }
  return Pair(res, t);
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> to(n);
  for (int i = 1; i < n; i++) {
    int parent;
    cin >> parent;
    --parent;
    to[parent].push_back(i);
  }

  auto [v, NO_USE__] = dfs(0, to);
  int ans = (n + v) / 2;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e18;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n-1) cin >> p[i+1];
    rep(i,n) --p[i];
    vector<vector<int>> tree(n);
    rep(i,n-1) tree[p[i+1]].push_back(i+1);
    vector<P> dp(n); //first second
    vector<int> sz(n);
    vector<int> seen(n,-1);
    auto dfs = [&](auto&& dfs,int i) -> pair<P,int>{
        if(seen[i] == 1) return {dp[i],sz[i]};
        seen[i] = 1;
        int f = 1;
        int s = 0;
        int sz_i = 1;
        vector<P> odd;
        vector<P> even;
        for(int j:tree[i]){
            pair<P,int> now = dfs(dfs,j);
            sz_i += now.second;
            if(now.second % 2 == 0){
                even.push_back(now.first);
            }else{
                odd.push_back(now.first);
            }
        }
        sort(odd.begin(),odd.end(),[](P l,P r){
            return l.second - l.first > r.second - r.first;
        });
        sort(even.begin(),even.end(),[](P l,P r){
            return l.second - l.first > r.second - r.first;
        });
        rep(j,even.size()){
            if(even[j].second - even[j].first > 0)s += even[j].second,f += even[j].first;
        }
        bool fi = true;
        rep(j,odd.size()){
            if(fi) s += odd[j].second, f += odd[j].first, fi = !fi;
            else   f += odd[j].second, s += odd[j].first, fi = !fi;
        }
        rep(j,even.size()){
            if(even[j].second - even[j].first <= 0){
                if(fi) s += even[j].second, f += even[j].first;
                else   f += even[j].second, s += even[j].first;
            }
        }
        dp[i] = {f,s};
        sz[i] = sz_i;
        return {dp[i],sz[i]};
    };
    cout << dfs(dfs,0).first.first << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fo(i,k,n) for(long long i=k;i<n;i++)
#define endl "\n"
#define pb push_back
#define vii vector<ll>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

typedef long long ll;

/* ll fun_ceil(ll n,ll k){
if(n%k==0){
    return n/k;
}
else {
    ll x = (n/k)+1;
    return x;
}
} */
//sort(s.begin(),s.end(),[](tt x, tt y){return abs(x)>abs(y);});
void calc(){
    double n;cin>>n;
    vector<pair<double,double>> s(n);
    fo(i,0,n)
        cin>>s[i].first>>s[i].second;
    double ans = 0;
    fo(i,0,n){
        fo(j,i+1,n){
            double temp = (s[j].second-s[i].second)/(s[j].first-s[i].first);
            if(temp>=-1.0 and temp<=1.0)
                ans++;
        }
    }
    cout<<ans;
}

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

        calc();

    return 0;
}

	#include <sstream>
	#include <queue>
	#include <stack>
	#include <set>
	#include <map>
	#include <cstdio>
	#include <cstdlib>
	#include <cctype>
	#include <complex>
	#include <malloc.h>
	#include <cmath>
	#include <iostream>
	#include <string>
	#include <vector>
	#include <algorithm>
	#include <bitset>
	#include <list>
	#include <string.h>
	#include <assert.h>
	#include  <time.h>
	using namespace std;

	/*
	   ____   U  ___ u  ____            U _____ u ____    _
	U /"___|   \/"_ \/U|  _"\ u  ___    \| ___"|/|  _"\ U|"|u
	\| | u     | | | |\| |_) |/ |_"_|    |  _|" /| | | |\| |/
	 | |/__.-,_| |_| | |  __/    | |     | |___ U| |_| |\|_|
	  \____|\_)-\___/  |_|     U/| |\u   |_____| |____/ u(_)
	 _// \\      \\    ||>>_.-,_|___|_,-.<<   >>  |||_   |||_
	(__)(__)    (__)  (__)__)\_)-' '-(_/(__) (__)(__)_) (__)_)
	*/

	#define ll long long
	#define all(v) ((v).begin()), ((v).end())
	// #define sort(a,n) 	sort(a , a+n) ;
	#define uf(x) cout << (x) << '\n';
	#define in(x) cin >> x ;
	#define deb(x) cerr << #x << "=" << x << endl
	#define forn(i, n) for(int i = 0; i < int(n); ++i)
	#define lp(i, e, n) for(ll i = e; i < n; i++)
	#define rep(i, a, b) for (int _end_ = (b), i = (a); i <= _end_; ++i)
	#define fre(i, a, b) for (int _end_ = (b), i = (a); i >= _end_; ++i)
	#define WX(YZ) while(TEST--)
	#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
	#define ps(x, y) fixed<<setprecision(y)<<x
	#define mx 0;
	#define sx(x) (int)x.size()
	#define yes cout << "YES" << endl;
	#define no cout << "NO" << endl;

	//life is more about the journey, than it is of the destination
	typedef int int32_t;
	typedef pair<int, int> ii;
	typedef vector<int> v;

	template<typename... T>
	void rd(T&... args) {
		((cin >> args), ...);
	}
	template<typename... T>
	void yk(T&&... args) {
	    ((cout << args << ' '), ...);
	}
	template<typename... T>
	void ew(T&&... args) {
	    ((cout << args << '\n'), ...);
	}

	const char nl = '\n';
	const int maxn = 2e5 + 17;
	const int INF = 2000 * 1000 * 1000;

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

	ll lcm(ll a, ll b)
	{
	    return (a / gcd(a, b)) * b;
	}
 	//l, u, d, rd, ru, ld, lu/
	void notToday(){
		    int n;
    cin >> n;
    vector<int> x(n),y(n);
    for(int i=0;i<n;++i)
        cin >> x[i] >> y[i];
    int ans = 0;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            if(abs(x[i]-x[j])>=abs(y[i]-y[j]))
                ++ans;
        }
    }
    cout << ans << "\n";
	}
	/*
	no thats not me.
	*/
	int32_t main(void){
		//freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
		FAST;
		ll TEST = 1;
		// cin >> TEST;
		WX(YZ){
			notToday();
		}
	//exetime
	return mx
	}


#include <bits/stdc++.h>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && !std::isdigit(ch)) ch = std::getchar();
	if (ch == '-') w = -1, ch = std::getchar();
	while (std::isdigit(ch)) data = data * 10 + (ch ^ 48), ch = std::getchar();
	return data * w;
}

const int N(4e5 + 10);
int n, a[N], id[N], b[N], stk[N], top;

int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read();
	for (int i = 1; i <= (n << 1); i++) a[i] = read();
	for (int i = 1; i <= (n << 1); i++) id[i] = i;
	std::sort(id + 1, id + (n << 1 | 1), [] (int x, int y) { return a[x] < a[y]; });
	for (int i = 1; i <= n; i++) b[id[i]] = 1;
	for (int i = 1; i <= (n << 1); i++)
		if (top && b[i] != stk[top]) putchar(')'), --top;
		else stk[++top] = b[i], putchar('(');
	return 0;
}

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

using namespace std;

const int MAXN=400005;
const ll mod=998244353;

ll n,tag[MAXN];
pair<ll,ll> p[MAXN];

int main(){
	scanf("%lld",&n);
	for(ll i=1;i<=2*n;i++){
		scanf("%lld",&p[i].first);
		p[i].second=i;
	}
	sort(p+1,p+2*n+1);
	for(ll i=n+1;i<=2*n;i++){
		tag[p[i].second]=1;
	}
	ll cntl=0,cntr=0;
	for(ll i=1;i<=2*n;i++){
		if(tag[i]==0){
			if(cntl==0&&cntr==0){
				cntl++;
				printf("(");
			}
			else if(cntl>0&&cntr==0){
				cntl++;
				printf("(");
			}
			else if(cntl==0&&cntr>0){
				cntr--;
				printf(")");
			}
		}
		else if(tag[i]==1){
			if(cntl==0&&cntr==0){
				cntr++;
				printf("(");
			}
			else if(cntl>0&&cntr==0){
				cntl--;
				printf(")");
			}
			else if(cntl==0&&cntr>0){
				cntr++;
				printf("(");
			}
		}
	}

	return 0;
}


#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int, int> pii;

int p[4];
set<string> s[105];
void dfs(string t) {
    if(t.size() > 10) return;
    s[t.size()].insert(t);
    for(int i=1;i<t.size();++i) {
        int a = t[i-1] - '0', b = t[i] - '0';
        char c = p[a<<1|b] + '0';
        string nxt = t.substr(0, i) + c + t.substr(i);
        dfs(nxt);
    }
}
const int mod = 1e9+7;
ll fpow(ll a,ll b){ll r=1;for(a%=mod;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
ll fib(ll n) {
    function<ll(ll,ll,ll,ll,ll)> f = [&](ll a,ll b,ll p,ll q,ll n) -> ll {
        if(!n) return b;
        if(n&1) return f((b*q+a*q+a*p)%mod,(b*p+a*q)%mod,p,q,n-1);
        return f(a,b,(p*p+q*q)%mod,(q*q+2*q*p)%mod,n/2);
    };
    return f(1,0,0,1,n);
}
int main() {
    int n;
    cin >> n;
    if(n <= 3) return cout << 1 << endl, 0;
    for(int i=0;i<4;++i) {
        char c;
        cin>>c;
        p[i]=c-'A';
    }
    dfs("01");
    if(s[5].size() == 1) cout << 1 << endl;
    else if(s[5].size() == 4) cout << fpow(2, n-3) << endl;
    else cout << fib(n-1) << endl;
}

#pragma region templates
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using PQ = priority_queue<T>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
inline void Yes() { cout << "Yes" << ENDL; }
inline void No() { cout << "No" << ENDL; }
inline void YES() { cout << "YES" << ENDL; }
inline void NO() { cout << "NO" << ENDL; }

template<typename T,typename Y> inline T mpow(T a, Y n) {
	T res = 1;
	for(;n;n>>=1) {
		if (n & 1) res = res * a;
		a = a * a;
	}
	return res;
}

template <typename T>
vector<T> finddivisor(T x) {  //整数xの約数(xを含む)
	vector<T> divisor;
	for(T i = 1; (i * i) <= x; i++) {
		if(x % i == 0) {
			divisor.push_back(i);
			if(i * i != x) { divisor.push_back(x / i);}
		}
	}
	sort(divisor.begin(), divisor.end());
	return divisor;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
	int n = v.size();
	V<T> ret(n + 1);
	rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
	return ret;
}

template<typename T>
T rand(T l,T r){
	static random_device rd;
	static mt19937 g(rd());
	return uniform_int_distribution<T>(l,r)(g);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
	for(auto&& x: vec) is >> x;
	return is;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
	return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<typename ...Args>
void debug(Args&... args){
	for(auto const& x:{args...}){
		cerr<<x<<' ';
	}
	cerr<<ENDL;
}
#pragma endregion templates

signed main(){
	cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	ll k,n,m;cin>>k>>n>>m;
	ll rem=m;
	V<ll> a(k);cin>>a;

	PQ<tuple<ll,ll,ll>> p1,p2;
	V<ll> b(k,0);

	rep(i,0,k){
		ll num=a[i]*m/n;
		p1.emplace(1,num,i);
		p2.emplace(-n*(1+2*num)+2*a[i]*m,1,i);
	}

	while(rem>0){
		if(p1.size()){
			ll key,x,id;
			tie(key,x,id)=p1.top();
			p1.pop();
			b[id]+=min(rem,x);

			if(rem<x){
				rem=0;
			}else{
				rem-=x;
			}
		}else if(p2.size()){
			ll key,x,id;
			tie(key,x,id)=p2.top();
			p2.pop();
			b[id]+=min(rem,x);

			if(rem<x){
				rem=0;
			}else{
				rem-=x;
			}
		}else{
			b[0]+=rem;
			rem=0;
		}
	}
	for(auto&& i:b)cout<<i<<" ";
	cout<<ENDL;
}
//(・_・)(・_・)(・_・)(・_・)
//CHECK overflow,what to output?
//any other simpler approach?


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define F first
#define S second
#define mod 1000000007
using namespace std;

void solve(){
	ll ans=1e9; int n; cin>>n;
	pii arr[n];
	for(int i=0;i<n;i++){
		int a,b; cin>>a>>b; arr[i]={a,b};
	}
	for(int i=0;i<n;i++){
		ans=min(ans,(ll)arr[i].F+arr[i].S);
		for(int j=i+1;j<n;j++){
			ans=min(ans,(ll)max(arr[i].F,arr[j].S));
			ans=min(ans,(ll)max(arr[i].S,arr[j].F));
		}
	}
	cout << ans <<endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int t=1;   ///cin>>t;
    for(int it=1;it<=t;it++){
    	solve();
	}
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long int           ll;
typedef unsigned long long int  ull;
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;

#define test(t)             int t; cin >> t; while(t--)
#define f(i, a, b)          for(int (i) = (a); (i) < (b); ++(i))
#define all(a)              (a).begin(), (a).end()
#define endl                "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define deb(x)              cout << #x << ": " << x << endl;
#define deb2(x,y)           cout << #x << ": " << x << " ~ " <<  #y << ": " << y << endl;
#define deba(arr)           cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)          cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast                ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9        1000000007
#define mx7        10000007
#define mx6        1000006
#define mx5        200005
#define inf        1<<30
#define eps        1e-9
#define mod        1000000007
#define PI         3.141592653589793238462643383279502884L

void solve()
{
    string s;
    cin >> s;
    ll n;
    cin >> n;
    map<ll, ll> mp;
    f(i, 0, n)
    {
        string p, t;
        p = t = s;
        sort(all(t));
        sort(all(p));
        reverse(all(p));
        ll temp = stoi(p) - stoi(t);
        s = to_string(temp);
    }
    cout << s << endl;
}

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    // test(t)
        solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mx 1000005
#define fiint(a,b) memset(a,b,sizeof(a))
#define bitcount __builtin_popcount
#define fori(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cout<<x<<endl;
#define cases(t) int t; cin>>t; while(t--)
#define inf1 INT_MAX
#define all(a) a.begin(),a.end()
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<int,int>
#define pint pair<int,int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair

#define sz(x) (int)x.size()
#define PI    3.14159265359

//const long long INF=1e18;

bool chmin(int& a, int b){ if(a > b){ a = b; return 1; } return 0; }

int factorial[10000001]={0};

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

int powerFunction(int x,int y){
    int res = 1;
     int p = mod;
    x = x;
    while (y > 0){
        if (y & 1)
            res = (res*x)%p ;
        y = y>>1;
        x = (x*x)%p ;
    }
    return res;
}

void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
    factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}

int nCr(int n, int r)
{
    if(r < 0 || r > n){
        return 0;
    }
    int temp = factorial[n];
    temp *= (powerFunction(factorial[r], MOD-2)%MOD);
    temp %= MOD;
    temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);
    temp %= MOD;
    return temp;
}

vec p(300005);
vec si(300005);
//vec di
vector<map<int,int>> cnt(300005);
int find_p(int a)
{
    while(p[a] != a)
    {
        //int le = si[p[a]];
        p[a] = p[p[a]];
        //si[p[a]] += le;
        a = p[a];

    }
    return a;
}

void merge(int a , int b)
{
     a = find_p(a);
     b = find_p(b);
    if(a == b)
        return;
    if(si[a] >= si[b])
    {
        si[a] += si[b];
        p[b] = a;
        for(auto it : cnt[b])
            cnt[a][it.ff] += it.ss;
    }
    else
    {
        si[b] += si[a];
        p[a] = b;
        for(auto it : cnt[a])
            cnt[b][it.ff] += it.ss;
    }
}

signed main()
{
    int n,q;cin>>n>>q;

    for(int i = 0 ; i < n ;i++)
    {
        int a ; cin>>a; a--; cnt[i][a] = 1;
        p[i] = i;
        si[i] = 1;
    }
    while(q--)
    {
        int t , x , y ; cin >>t >> x >> y;
        x-- ; y--;
        if(t == 1 )
        {
            merge(x , y);
        }
        else
        {
            cout<<cnt[find_p(x)][y]<<endl;
        }
    }

}

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

struct uf_tree {
    std::vector<int> parent;
    std::vector<std::map<int, int>> dict;
    int __size;
    uf_tree(int size_) : parent(size_, -1), dict(size_), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            for (auto [key, val] : dict[y]) {
                dict[x][key] += val;
            }
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
    int query(int x, int y) { return dict[find(x)][y]; }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> cs(n);
    uf_tree uf(n);
    for (int i = 0; i < n; i++) {
        cin >> cs[i];
        uf.dict[i][cs[i]]++;
    }
    for (int i = 0; i < q; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (a == 1) {
            uf.unite(b -1, c - 1);
        } else {
            cout << uf.query(b - 1, c) << endl;
        }
    }
    return 0;
}


/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define   fastio    ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ll        long long
#define   scl(n)    scanf("%lld",&n)
#define   scll(n,m) scanf("%lld %lld",&n,&m)
#define   pb        push_back
#define   mp        make_pair
#define   frs       first
#define   scn       second
#define   mod       1000000007
#define   read      freopen("input.txt","r",stdin)
#define   write     freopen("output.txt","w",stdout)
#define   N         10000000

ll pow(ll x,ll y)
{
	ll i,pro=1;
	for(i=0;i<y;i++)
	pro*=x;

	return pro;
}

int main()
{
	//fastio;
    ll tc,t,n,m,i,j,k,mx,mn,c,x,y;

    scl(n);

    c=0;
    ll f=0;
    set<ll>st;
    for(i=2;i<=100000;i++)
    {
    	for(j=2;j<=34;j++)
    	{
    		x=pow(i,j);
    		if(x<=n)
    		st.insert(x);
    		else
    		{
    			f=1;
    			break;
			}
		}
	}

	ll sz=st.size();
	printf("%lld\n",n-sz);
}

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

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

using namespace std;

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

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

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

int N, M;
int A[1011], B[1011];
int dp[1011][1011];

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

    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = M + N;

    REP (i, N+1) REP (j, M+1) {
	if (i < N && j < M) {
	    if (A[i] != B[j]) {
		amin(dp[i+1][j+1], dp[i][j] - 1);
	    } else {
		amin(dp[i+1][j+1], dp[i][j] - 2);
	    }
	}
	amin(dp[i][j+1], dp[i][j]);
	amin(dp[i+1][j], dp[i][j]);
    }

    int ans = dp[N][M];
    printf("%d\n", ans);

}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int SINF = 1LL << 29;
const ll mod = 1000000000+7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

int main() {
    const int MOD = 998244353;
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll res = 0;
    rep(i, n) res += (a[i] * a[i]) % MOD;
    sort(all(a));
    ll sum = 0;
    for(int i=n-2; i>=0; i--) {
        sum = (2 * sum + a[i+1]) % MOD;
        res += (a[i] * sum) % MOD;
    }
    cout << res % MOD << endl;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <stack>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef vector<vector<int>> Graph;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

//main area
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    ld ans = 0;
    rep(i,N) ans += A[i];
    ll median = A[N/2];
    rep(i,N) ans += abs(A[i] - median);
    cout << fixed << setprecision(10) << ans/(2.0*N) << endl;
}
/*

*/