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

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vpll = vector<pair<ll, ll>>;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1<<30;
const ll INF = 1ll<<62;
//const ll mod = 1000000007;
const ll mod = 998244353;
//const ll dx[4] = {1, 0, -1, 0};
//const ll dy[4] = {0, 1, 0, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class T> void disp1(vector<T> &array, bool blank=1) {
    rep(i, array.size()) cout << ((i&&blank) ? " " : "") << array[i];
    cout << endl;
    //cout << " ";
}
template<class T> void disp2(vector<vector<T>> &array, bool blank=1) {
    rep(i, array.size()) disp1(array[i], blank);
}

ll rem(ll a, ll b) { return (a % b + b) % b; }      // 余りを0~b-1に丸める
// 小数の入力が文字で与えられたとき、10^n倍したものを返す
ll x10(string str_f, ll n) {
    if (str_f[0] == '-') return -x10(str_f.substr(1), n);
    ll times = 1; rep(i,n) times *= 10;     // times = 10^n
    int id = -1; rep(i,str_f.size()) if (str_f[i] == '.') id = i;
    if (id == -1) { return stoll(str_f)*times; }
    string str_int = str_f.substr(0, id), str_dec = str_f.substr(id+1);
    while (str_dec.size() < n) str_dec += '0';
    return stoll(str_int)*times + stoll(str_dec);
}
// A^N (mod)
ll modpow(ll A, ll N, ll mod) {
    ll RES = 1;
    while (N) {
        if (N & 1) RES = RES * A % mod;
        A = A * A % mod;
        N >>= 1;
    }
    return RES;
}

long long gcd(long long A, long long B) {return B ? gcd(B, A%B) : A;}
long long lcm(long long A, long long B) {return (A / gcd(A, B)) * B;}

//using mint = modint998244353;

ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

void solve() {
    ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
    ll A = 2*(X+Y), B = P+Q;
    ll ans = INF, g = gcd(A, B), l = lcm(A, B);
    for (ll i = 0; i < Y; i++) {
        for (ll j = 0; j < Q; j++) {
            // Ax+X+i = By+P+j なる(x,y)を求める
            ll x, y;
            ll G = P+j-X-i;
            if (G%g != 0) continue;
            ll a = A/g, b = B/g, c = G/g;
            extgcd(a, b, x, y);
            ll re = c % b * rem(x, b) % b;
            re *= A;
            re += X+i;
            re = rem(re, l);
            chmin(ans, re);
        }
    }
    if (ans != INF) cout << ans << endl;
    else puts("infinity");
    return ;
}

int main() {
    int t; cin >> t;
    while (t--) solve();
    return 0;
}

#include "bits/stdc++.h"

using namespace std;

#define ll long long

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

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

const int mod = 1e9 + 7;
const int N = 3005;
int dp[N][N];
ll a[N];

int cnt[N][N];
void solve()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }

    dp[0][0] = 1;

    ll sum = 0;

    map<pair<int,int>,int> m;
    for(int i = 1;i <= n;i++){
        sum += a[i];
        for(int j = 1; j <= n;j++){
            if(j == 1)dp[i][j]++;
            dp[i][j]+= cnt[((sum%j)+j)%j][j - 1];
            dp[i][j]%=mod;
        }

        for(int j = 1;j <= n;j++){
            cnt[((sum%(j+1))+(j+1))%(j+1)][j] += dp[i][j];
            cnt[((sum%(j+1))+(j+1))%(j+1)][j] %= mod;
        }
    }

    int ans = 0;
    for(int i = 1;i <= n;i++){
        ans += dp[n][i];
        ans%=mod;
    }
    cout << ans << "\n";
}

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


/**
 * @author yuzining
 * @date 2021/03/27 20:12
 */

#ifdef local
#include "D:\VSCODE\debug.hpp"
#else
#include <bits/stdc++.h>
#define DEBUG(...) do { } while (0)
const int _______ = []() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); return 0; }();
#endif

int main() {
  int n; std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  int ans = INT_MAX;
  for (int i = 0; i < (1 << n); i++) {
    int cur = 0, tmp = 0;
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        cur ^= tmp;
        tmp = 0;
      }
      tmp |= a[j];
    }
    cur ^= tmp;
    ans = std::min(ans, cur);
  }
  std::cout << ans << '\n';
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#ifndef JHELPER1_COMMON_H
#define JHELPER1_COMMON_H

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

typedef long long ll;
using namespace std;

constexpr ll MOD = 1000 * 1000 * 1000 + 7;

#define READ_VEC(v) for(auto &e: v){in >> e;}
#define READ_PAIR_VEC(v) for(auto &e: v){in >> e.first >> e.second;}
#define ALL(c) std::begin(c), std::end(c)

#endif //JHELPER1_COMMON_H

class CORXOR {
public:
  void solve(std::istream& in, std::ostream& out) {
    int N;
    in >>N;
    vector<int> A(N);
    READ_VEC(A);

    ll mi = 1000'000'000'000L;
    for (int i = 0; i < (1<<(N-1)); ++i) {
      ll tot = 0;
      ll lo = 0;
      for (int j = 0; j < N; ++j) {
        lo |= A[j];

        if (j == N-1 || i & (1<<j)) {
          tot ^= lo;
          lo = 0;
        }
      }
      mi = min(mi, tot);
    }
    out << mi << endl;
  }
};

int main() {
  CORXOR solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
  int n;cin>>n;
  cout<<n-1;

}

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

#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define sp " "
#define nl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int N=1e9+7;
typedef long long ll;
typedef long double ld;

ll power(ll x, ll y){
    ll res = 1;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % N;
        y = y>>1;
        x = (x*x) % N;
    }
    return res;
}

/*
int Seive[1000001]={0};
void seive(ll n)
{
    Seive[1]={1};
    for(int i=2;i*i<=n;i++){
        if(Seive[i]){continue;}
        for(int j=2*i;j<=n;j+=i){
            Seive[j]=1;
        }
    }

}
*/

void solve(){

ll n;
cin>>n;

if(n&1){
    cout<<2*(n-1)/2;
}else{
    cout<<2*n/2 - 1;
}

cout<<nl;

}

int main(){
fst
//cout<<fixed<<setprecision(15);

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

    solve();

}

return 0;

}


#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
using namespace std;
inline int read()
{
    int s = 0, w = 1;
    ri char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return s * w;
}
int n;
string t;
int INF = 1e10;
signed main()
{
    n = read();
    cin >> t;
    if (t == "1")
    {
        printf("%lld\n", INF * 2);
        return 0;
    }
    int flg = 0;
    int be = 0;
    if (t[0] == '0')
        be = 1, flg++;
    else if (t.substr(0, 2) == "10")
        be = 2, flg++;
    int res = 0;
    for (; be + 2 < n; be += 3)
    {
        if (t.substr(be, 3) == "110")
            res++;
        else
            return puts("0") & 0;
    }
    if (be != n)
    {
        if (t.substr(be) == "1" || t.substr(be) == "11")
            flg++;
        else
            return puts("0") & 0;
    }
    printf("%lld\n", INF - (res + flg) + 1);
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>

int main() {
	int k;
	std::cin >> k;
	std::vector<int> v(10, k);
	std::vector<double> tv(10, 0);
	std::vector<double> av(10, 0);
	int ta = 0;
	int ao = 0;
	std::string s;

	std::cin >> s;

	for (int c = 0; c < 4; c++) {
		int f;
		f = std::stoi(s.substr(c, 1));
		tv[f] += 1;
		v[f] -= 1;
	}

	for (int c = 1; c < 10; c++) {
		ta += c*pow(10, tv[c]);
	}

	std::cin >> s;

	for (int c = 0; c < 4; c++) {
		int f;
		f = std::stoi(s.substr(c, 1));
		av[f] += 1;
		v[f] -= 1;
	}

	for (int c = 1; c < 10; c++) {
		ao += c*pow(10, av[c]);
	}

	double ans = 0.;

	for (int c = 1; c < 10; c++) {
		for (int b = 1; b < 10; b++) {
			if (c == b) {
				if (v[c] > 1) {
					if (ao + b * pow(10, av[b] + 1) - b * pow(10, av[b]) < ta + c * pow(10, tv[c] + 1) - c * pow(10, tv[c])) {
						ans += static_cast<double>(v[c]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0)) * static_cast<double>(v[c] - 1) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0) - 1);
					}
				}
			}
			else {
				if (v[c] > 0 && v[b] > 0) {
					if (ao + b * pow(10, av[b] + 1) - b * pow(10, av[b]) < ta + c * pow(10, tv[c] + 1) - c * pow(10, tv[c])) {
						ans += static_cast<double>(v[c]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0)) * static_cast<double>(v[b]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0) - 1);
					}
				}
			}
		}
	}

	std::cout << ans << std::endl;

}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;

typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> ) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
   (( cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
   ((cout << args << ' '), ...);
   cout << '\n';
}
//  mp.max_load_factor(0.25);
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>;
const int MOD = 998244353, MAX = 2e5 + 5;
const char nl = '\n';
const int INF = 1e9 + 5;
int n, m;
int cn[MAX][20];
ll fac[MAX];
ll pot(ll x, ll y){
   if(y == 0) return 1;
   if(y & 1) return (pot(x, y - 1) * x) % MOD;
   ll k = pot(x, y / 2);
   return (k * k) % MOD;
}
ll inv(ll x){
   return pot(x, MOD - 2);
}
ll comb(int x, int y){
   if(x < y) return 0;
   return (((fac[x] * inv(fac[y])) % MOD) * inv(fac[x - y])) % MOD;
}
void solve(){
   cin >> n >> m;
   cn[1][0] = 1;
   for(int i = 2; i <= m; i++){
      cn[i][0] = 1;
      for(int j = 1; j * j <= i; j++){
         if(i % j) continue;
         for(int k = 1; k < 20; k++){
            cn[i][k] += cn[j][k - 1];
         }
         if(j * j != i && j != 1){
            for(int k = 1; k < 20; k++){
               cn[i][k] += cn[i / j][k - 1];
            }
         }
      }
   }
   ll ans = 0;
   vector<int> CN(20);
   for(int i = 1; i <= m; i++){
      for(int j = 0; j < 20; j++){
         CN[j] += cn[i][j];
      }
   }
   for(int j = 0; j < 20; j++){
      ans = (ans + comb(n - 1, j) * CN[j]) % MOD;
   }
   cout << ans << "\n";
}
int main(){
   cpu();
   fac[0] = 1;
   for(int i = 1; i < MAX; i++){
      fac[i] = (fac[i - 1] * i) % MOD;
   }
   solve();

   return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

int main()
{
    ll b, c;
    cin >> b >> c;
    ll Rstart, Rend, Lstart, Lend;
    if (c == 1)
    {
        if (b == 0)
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 2 << endl;
        }
        return 0;
    }
    if (c % 2 == 0)
    {
        Rstart = b - c / 2;
        Rend = b + c / 2 - 1;
        Lstart = -b - (c - 1) / 2;
        Lend = -b + (c - 1) / 2;
    }
    else
    {
        Lstart = -b - c / 2;
        Lend = -b + c / 2;
        Rstart = b - (c - 1) / 2;
        Rend = b + (c - 1) / 2 - 1;
    }
    ll rangeR = Rend - Rstart + 1;
    ll rangeL = Lend - Lstart + 1;
    ll RandL = max((ll)0, min(Rend, Lend) - max(Rstart, Lstart) + 1);
    // cout << Lstart << "~~" << Lend << "," << Rstart << "~~" << Rend << endl;
    // cout << rangeL << "," << RandL << "," << rangeR << endl;
    cout << rangeR + rangeL - RandL << endl;
}


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

// Aliases
#define nitro std::ios_base::sync_with_stdio(false), std::cin.tie(NULL)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define case_g(x) cout<<"Case #"<<x<<": "
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ul = unsigned long;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using pib = std::pair<int, bool>;
using plb =  std::pair<ll, bool>;
using vii = std::vector<pii>;
using vll = std::vector<pll>;
using vib = std::vector<pib>;
using vlb = std::vector<plb>;
using vvi = std::vector<vi>;
using vvl = std::vector<vl>;
using vvb = std::vector<vb>;
using mapii = std::map<int, int>;
using mapll = std::map<ll, ll>;
using mapib = std::map<int, bool>;
using maplb = std::map<ll, bool>;
using hmapii = __gnu_pbds::gp_hash_table<int, int>;
using hmapll = __gnu_pbds::gp_hash_table<ll, ll>;
using hmapib = __gnu_pbds::gp_hash_table<int , bool>;
using hmaplb =  __gnu_pbds::gp_hash_table<ll, bool>;
using ranked_pairset = tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>;
using ranked_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
using ranked_map = tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

// Debugging template
#ifndef LOCAL
#define cerr if (false) cerr
#endif
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...);}
template<typename T>
void _printA(T *t, long long sz) { cout<<" { "; for (long long i=0; i<sz; i++) cout<<"["<<i<<"] = "<< t[i]<<endl; cout<<" } \n";}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debugA(x, y) cerr << "[" << #x << "] = "; _printA(x, y)

// Constants
const ll mod = 1000000007;
const ld pi = 3.141592653589793L;
const char nl = '\n';

// Colours for fun :)
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"

void precompute() {
}

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

	if( s[0] != s[n - 1] ) {
		cout << 1 << nl;
		return;
	}

	for(int i = 1; i <= n - 2; ++i) {
		if( s[i] != s[0] && s[i + 1] != s[0] ) {
			cout << 2 << nl;
			return;
		}
	}

	cout << -1 << nl;
}

int main() {
	nitro;

	int tc = 1;
	//cin >> tc;

	precompute();
	for(int i = 1; i <= tc; ++i) {
		//case_g(i);
		solve();
	}
	return 0;
}

/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define in insert
#define rev reverse
#define all(x) (x).begin(),(x).end()
#define all2(x) (x).rbegin(),(x).rend()
#define sz(v) (int)v.size()
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define vi vector<int>
#define vii vector<pair<int, int > >
#define vl vector<ll>
#define fi first
#define se second
#define l_b lower_bound
#define u_b upper_bound
#define ed printf("\n")
#define mems(a, b) memset(a, b, sizeof(a))
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();

using namespace std;

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

template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void read(T &x) { cin >> x; }
template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }
template<class T> void print1(const T &x) { cout << x << '\n'; }
template<class T, class ...U> void print1(const T &x, const U& ... u) { print1(x); print1(u...); }
template<class T> void print2(const T &x) { cout << x << ' '; }
template<class T, class ...U> void print2(const T &x, const U& ... u) { print2(x); print2(u...); }

const int N = 2e3 + 5, mod = 1e9 + 7, M = 5e5 + 5;
const ll inf = 9e18;
int cs = 1;

void solve() {
    int n;
    string s;
    read(n, s);
    int ans = -1;
    for(int i = 1; i < n; i++) {
        if(s[i] != s[0]) {
            if(i + 1 == n) {
                ans = 1;
                break;
            }
            if(s[i + 1] != s[n - 1]) {
                ans = 2;
            }
        }
    }
    print1(ans);
}

int main() {
    ios;
    //cout << fixed << setprecision(15);
    //int tc; read(tc); while(tc--> 0)
    solve();
    return 0;
}


/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void vis_2d(vector< vector<ll> > v, ll h, ll w, ll pad=4){
    cout <<  "ij "; rep(i,0,w) cout << left << setw(pad) << i; cout << endl;
    rep(i,0,h){
        cout << i << ": ";
        rep(j,0,w){ if(v[i][j] == INF) cout << "x" << string(pad-1, ' '); else cout << left << setw(pad) << v[i][j]; }
        cout << endl;
    }
}

struct Combination{
private:
    ll N;
public:
    vll fac, facinv, inv;

    Combination(ll n){
        N = n;
        fac.resize(N+1); facinv.resize(N+1); inv.resize(N+1);
        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        inv[1] = 1;
        rep(i,2,N+1){
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            facinv[i] = facinv[i-1] * inv[i] % MOD;
        }
    }

    ll power(ll x, ll n, ll m = MOD){
        if(n == 0) return 1LL;
        ll res = power(x * x % m, n/2, m);
        if(n % 2 == 1) (res *= x) %= m;
        return res;
    }

    ll nck(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        if(n < k) return 0LL;
        return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
    }

    ll npk(ll n, ll k){
        if(k == 0) return 1LL;
        if(n < k) return 0LL;
        return fac[n] * facinv[n-k] % MOD;
    }
};

void solve(){
    ll N,M,K;
    cin >> N >> M >> K;
    Combination cb(2000010);
    ll ans = cb.nck(N+M, N);
    ll diff = 0;
    if(K >= N){
        diff = 0;
    }else if(K < N-M){
        print(0);
        return;
    }else{
        diff = N-K;
    }
    rep(i,0,diff){
        ll val = cb.nck(N+M, i);
        if(i > 0) val -= cb.nck(N+M, i-1);
        // print(val);
        ans -= val;
        ans = (ans + 2*MOD) % MOD;
    }
    print(ans);

}

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

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

// 拡張ユークリッド互除法
ll extGCD(ll a, ll b, ll &x, ll &y) {
  if(b==0) {
    x=1; y=0; return a;
  } else {
    ll d = extGCD(b, a%b, y, x);
    y-=(a/b)*x;
    return d;
  }
}

// 階乗のmodにおける逆元を求める
ll calcInv(ll a, ll P) {
  ll x,y;
  extGCD(a, P, x, y);
  return (x+P)%P;
}

int main() {
  ll N,M,K; cin>>N>>M>>K;
  ll ans=0;
  if(N-M<=K && (N>=0 || M>=0)) {
    vector<ll> fac(N+M+2,1);
    for(ll i=1; i<=N+M+1; ++i) fac[i]=(fac[i-1]*i)%MOD;
    ans=fac[N+M];
    ans=(ans*calcInv(fac[N],MOD))%MOD;
    ans=(ans*calcInv(fac[M],MOD))%MOD;

    /*
    ll ng_height=N+M-(K+1);
    if(ng_height>=0 && M<=ng_height) {
    ll val=fac[ng_height];
    val=(val*calcInv(fac[ng_height-M],MOD))%MOD;
    val=(val*calcInv(fac[M],MOD))%MOD;
    ans=(ans-val+MOD)%MOD;
    }
    */
    if(N-(K+1)>=0) {
      ll val=fac[N+M];
      val=(val*calcInv(fac[N-(K+1)],MOD))%MOD;
      val=(val*calcInv(fac[M+K+1],MOD))%MOD;
      ans=(ans-val+MOD)%MOD;
    }
  }
  cout<<ans<<endl;
}


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

const long long MOD = 1e9+7;
const long long N = 4e4+1;

typedef long long ll;
typedef long double ld;

void test_case() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll zc = 0;
    map<ll,vector<ll>> mm;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] %= 200;
        if(v[i] == 0)
            zc = i+1;
        mm[v[i]].push_back(i);
    }
    bool flag = 0;
    ll x1, x2;
    for(auto u : mm) {
        if(u.second.size() == 1) {
            continue;
        }
        flag = 1;
        x1 = u.second[0]+1, x2 = u.second[1]+1;
    }
    if(flag) {
        cout << "Yes\n";
        cout << 1 << ' ' << x1 << '\n';
        cout << 1 << ' ' << x2 << '\n';
        return;
    }
    vector<ll> is(N, 0);
    vector<array<ll,3>> who[N];
    is[0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = N-1; j >= 0; j--) {
            if(v[i] <= j) {
                is[j] += is[j-v[i]];
                if(is[j-v[i]]) {
                    who[j].push_back({v[i], j, i+1});
                }
            }
        }
    }
    // if(!zc) {
    //     is[0] = 0;
    // }
    for(int i = 0; i < N; i++) {
        ll ww = i%200;
        if(i != ww) {
            for(auto u : who[i]) {
                who[ww].push_back(u);
            }
            is[ww] += is[i];
        }
        if(is[ww] > 1 && who[ww].size() > 1) {
            i = ww;
            vector<ll> a1, a2;
            ll curr = who[i][0][1];
            a1.push_back(who[i][0][2]);
            curr -= who[i][0][0];
            if(curr != 0) {
                for(int j = who[i][0][2]-2; j >= 0; j--) {
                    if(v[j] <= curr && is[curr] && is[curr-v[j]]) {
                        a1.push_back(j+1);
                        curr -= v[j];
                    }
                    if(curr == 0)
                        break;
                }
            }
            curr = who[i][1][1];
            a2.push_back(who[i][1][2]);
            curr -= who[i][1][0];
            if(curr != 0) {
                for(int j = who[i][1][2]-2; j >= 0; j--) {
                    if(v[j] <= curr && (is[curr-v[j]] || curr == v[j])) {
                        a2.push_back(j+1);
                        curr -= v[j];
                    }
                    if(curr == 0)
                        break;
                }
            }
            sort(a1.begin(), a1.end());
            sort(a2.begin(), a2.end());
            cout << "Yes\n";
            cout << a1.size() << ' ';
            for(auto u : a1) {
                cout << u << ' ';
            }
            cout << '\n';
            cout << a2.size() << ' ';
            for(auto u : a2) {
                cout << u << ' ';
            }
            cout << '\n';
            return;
        }
    }
    cout << "No\n";

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc = 1;
    // cin >> tc;
    while(tc--)
        test_case();
    return 0;
}

#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int IN(void)
{
  int x=0,f=1,c=getchar();while(c<48||c>57){if(c==45){f=-f;}c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static inline void OUT(int x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
int main(void)
{
  int N=IN(),A[N],bk[200][8]={{0}},pos[200]={0},count=N<8?N:8,s[8]={},sum=0,sz=0;
  rep(i,N){A[i]=IN();}
  rep(i,1<<count)
  {
    sum=0;s[0]=s[1]=s[2]=s[3]=s[4]=s[5]=s[6]=s[7]=0;sz=0;
    rep(j,count)if(i&(1<<j)){s[sz++]=j+1;sum+=A[j];sum-=sum/200*200;}
    if(pos[sum])
    {
      puts("Yes");OUT(pos[sum]);putchar(' ');
      rep(j,pos[sum]){OUT(bk[sum][j]);putchar(' ');}puts("");OUT(sz);putchar(' ');
      rep(j,sz){OUT(s[j]);putchar(' ');}return 0;
    }
    else{rep(j,sz){bk[sum][j]=s[j];}pos[sum]=sz;}
  }
  return !puts("No");
}


#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF  = 1e9;
constexpr llong  LINF = 1e18;
constexpr double EPS  = 1e-12;
constexpr int    MOD  = 1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a)cerr<<(cnt++?' ':'>')<<elem;cerr<<endl;}

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

/*ダイクストラ法*/
template<typename T>
class Dijkstra{
	using P=std::pair<T,int>;
	struct Edge{						//Edge:辺の情報を表す構造体.
		int to;
		T cost;
	};

	int vn;								//vn:=(ノード数).
	std::vector<std::vector<Edge> > g;	//g[v]:=(ノードvがもつ辺のリスト).
	std::vector<T> d;					//d[v]:=(ノードsからvへの最短距離).
	std::vector<int> pre;				//pre:=(逆方向経路（経路復元用）).
	T inf;

public:
	//constructor.
	Dijkstra():Dijkstra(0){}
	Dijkstra(size_t vn_,T inf_=1e9):vn(vn_),g(vn_),d(vn_,inf_),pre(vn_,-1),inf(inf_){}

	T get_inf() const{return inf;}
	void add_edge(int from,int to,T cost){//重み付き有向辺を張る.
		assert(0<=from and from<vn);
		assert(0<=to and to<vn);
		g[from].push_back((Edge){to,cost});
	}
	void dijkstra(int s){//sから各ノードへの最短距離を求める. O(|E|log|V|).
		assert(0<=s and s<vn);
		std::fill(d.begin(),d.end(),inf);
		d[s]=0;
		std::fill(pre.begin(),pre.end(),-1);
		std::priority_queue<P,std::vector<P>,std::greater<P> > pque;
		pque.emplace(0,s);
		while(!pque.empty()){
			auto [cost,v]=pque.top();
			pque.pop();
			if(d[v]<cost) continue;
			for(const Edge &e:g[v]){
				if(d[e.to]>d[v]+e.cost){
					d[e.to]=d[v]+e.cost;
					pre[e.to]=v;
					pque.emplace(d[e.to],e.to);
				}
			}
		}
	}
	T dist(int t) const{//ノードsからtへの最短距離を返す.
		assert(0<=t and t<vn);
		return d[t];
	}
	std::vector<int> get_path(int t) const{//ノードtへの最短経路を返す.
		assert(0<=t and t<vn);
		std::vector<int> path;
		for(;t!=-1;t=pre[t]) path.push_back(t);
		std::reverse(path.begin(),path.end());
		return path;
	}
};

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

	Dijkstra<int> ob(n);
	vi self(n,INF);
	REP(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--, b--;

		if(a==b) chmin(self[a],c);
		else ob.add_edge(a,b,c);
	}

	vvi d(n,vi(n));
	REP(i,n){
		ob.dijkstra(i);
		REP(j,n) d[i][j]=ob.dist(j);
	}

	vi ans(n,INF);
	REP(i,n) chmin(ans[i],self[i]);
	REP(i,n-1)for(int j=i+1;j<n;++j){
		chmin(ans[i],d[i][j]+d[j][i]);
		chmin(ans[j],d[i][j]+d[j][i]);
	}

	for(auto out:ans) cout<<(out==INF?-1:out)<<endl;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

struct edge{
    int to, cost;
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<vector<edge>> g(n);
    for(int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c; a--; b--;
        g[a].push_back((edge){b, c});
    }
    const int INF = 1e9;
    for(int s = 0; s < n; s++){
        vector<int> d(n, INF);
        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0, s));
        while(!que.empty()){
            P p = que.top();que.pop();
            int v = p.second;
            if(v != s && d[v] < p.first) continue;
            for(edge e : g[v]){
                if(p.first + e.cost < d[e.to]){
                    d[e.to] = p.first + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
        if(d[s] == INF) cout << -1 << endl;
        else cout << d[s] << endl;
    }
}


#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

bool dp[105][(int)1e5 + 10];

void solve() {
  int n;cin >> n;
  int sum = 0;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  for(int i = 0;i <= n;i++) {
    for(int diff = 0;diff <= sum;diff++) {
      if(i == 0) {
        if(diff == 0) dp[i][diff] = true;
      } else {
        if(diff+a[i-1] <= sum) dp[i][diff] |= dp[i-1][diff+a[i-1]];
        if(diff-a[i-1] >= 0) dp[i][diff] |= dp[i-1][diff-a[i-1]];
        if(a[i-1] - diff > 0) dp[i][diff] |= dp[i-1][a[i-1]-diff];
      }
    }
  }

  for(int diff = 0;diff <= sum;diff++) {
    if(dp[n][diff] == true) {
      //x+diff+x = sum
      cout << (sum-diff)/2 + diff << endl;
      return;
    }
  }
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);

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

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

 return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
using namespace std;
string s;
int cnt[10];
int main() {
	cin>>s;
	for(int i=0;i<(int)s.size();i++)
		cnt[s[i]-'0']++;
	if(s.size()==1){
		if(s[0]=='8')
			puts("Yes");
		else
			puts("No");
		return 0;
	}
	if(s.size()==2){
		for(int i=16;i<100;i+=8){
			int x=i%10,y=i/10;
			cnt[x]--;cnt[y]--;
			if(cnt[x]>=0 && cnt[y]>=0){
				puts("Yes");
				return 0;
			}
			cnt[x]++;cnt[y]++;
		}
		puts("No");
		return 0;
	}
	for(int i=0;i<1000;i+=8){
		int x=i%10,y=(i/10)%10,z=i/100;
		cnt[x]--;cnt[y]--;cnt[z]--;
		if(cnt[x]>=0 && cnt[y]>=0 && cnt[z]>=0){
			puts("Yes");
			return 0;
		}
		cnt[x]++;cnt[y]++;cnt[z]++;
	}
	puts("No");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int tab[100];

int main()
{
    long long int a, b, n, p, i, j;
    cin >> n >> p;
    a=p-1;
    n--;
    tab[0]=p-2;
    for(i=1; i<=80; i++){
        tab[i]=tab[i-1]*tab[i-1];
        tab[i]%=1000000007;
    }
    i=0;
    while(n){
        if(n%2){
            a*=tab[i];
            a%=1000000007;
        }
        i++;
        n/=2;
    }
    cout << a << '\n';
    return 0;
}

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

#define ios ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL) ;
#define endl "\n"
#define f1(i,n) for (int i=0;i<n;i++)
#define f2(i,n) for (int i=1;i<=n;i++)
#define int long long

typedef vector<int> vi ;
typedef queue<int> qi ;
typedef vector<vector<int>> vvi ;
//typedef vector<vector<ll>> vvll ;
typedef vector<vector<pair<int,int>>> vvp ;
typedef vector<bool> vb ;
typedef vector<double> vd ;
typedef vector<vector<char>> vvc ;
typedef vector<char> vc ;
typedef pair<int,int> pii ;
typedef vector<pair<int,int>> vpi ;
//typedef vector<pair<ll,ll>> vpll ;
//typedef pair<ll,ll> pll ;
//typedef vector<ll> vll ;
typedef stack<int> si ;
typedef map<int,int> mii ;
typedef set<int> seti ;
typedef double db ;

const int lim = 1000000+100 ;
int mod1 = 998244353 ;
int mod2 = 1000000007 ;
int INF = 2000000000 ;
int M=1000000000000000000+10000000 ;

// **********************************************************

int min(int x,int y) {
    if(x<y) return x;
    else return y;
}

int max(int x,int y) {
    if(x>y) return x;
    else return y;
}

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

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

// ***********************************************************

signed main() {
    ios
    int n ;cin >> n ;
    int a[n] ;
    f1(i,n) cin >> a[i] ;
    sort(a,a+n) ;
    int sum=0 ;
    int res=0 ;
    for(int i=n-2;i>=0;i--) {
        sum*=2 ;
        sum%=mod1 ;
        sum+=a[i+1] ;
        sum%=mod1 ;
        res+=a[i]*sum ;
//        cout << sum ;
        res%=mod1 ;
    }
    f1(i,n) {
        res+=((a[i]*a[i])%mod1) ;
        res%=mod1 ;
    }
    cout << res ;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=998244353;
ll a[maxn];

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    ll sum=0,ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+sum*a[i]+a[i]*a[i])%mod;
        sum=(sum*2+a[i])%mod;
        // cout<<sum<<'\n';
    }
    cout<<ans<<'\n';
}

int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
    return 0;
}

// #include<iostream>
#include<bits/stdc++.h>
using namespace std;
long _mergeSort(long arr[], long temp[],
                 long left, long right);
long merge(long arr[], long temp[], long left,
                   long mid, long right);

/* This function sorts the
   input array and returns the
number of inversions in the array */
long mergeSort(long arr[], long array_size)
{
    long temp[array_size];
    return _mergeSort(arr, temp, 0, array_size - 1);
}

/* An auxiliary recursive function
  that sorts the input array and
returns the number of inversions in the array. */
long _mergeSort(long arr[], long temp[],
                 long left, long right)
{
    long mid, inv_count = 0;
    if (right > left) {
        /* Divide the array longo two parts and
        call _mergeSortAndCountInv()
        for each of the parts */
        mid = (right + left) / 2;

        /* Inversion count will be sum of
        inversions in left-part, right-part
        and number of inversions in merging */
        inv_count += _mergeSort(arr, temp,
                                left, mid);
        inv_count += _mergeSort(arr, temp,
                             mid + 1, right);

        /*Merge the two parts*/
        inv_count += merge(arr, temp, left,
                           mid + 1, right);
    }
    return inv_count;
}

/* This funt merges two sorted arrays
and returns inversion count in the arrays.*/
long merge(long arr[], long temp[], long left,
          long mid, long right)
{
    long i, j, k;
    long inv_count = 0;

    i = left; /* i is index for left subarray*/
    j = mid; /* j is index for right subarray*/
    k = left; /* k is index for resultant merged subarray*/
    while ((i <= mid - 1) && (j <= right)) {
        if (arr[i] <= arr[j]) {
            temp[k++] = arr[i++];
        }
        else {
            temp[k++] = arr[j++];

            /* this is tricky -- see above
            explanation/diagram for merge()*/
            inv_count = inv_count + (mid - i);
        }
    }

    /* Copy the remaining elements of left subarray
(if there are any) to temp*/
    while (i <= mid - 1)
        temp[k++] = arr[i++];

    /* Copy the remaining elements of right subarray
(if there are any) to temp*/
    while (j <= right)
        temp[k++] = arr[j++];

    /*Copy back the merged elements to original array*/
    for (i = left; i <= right; i++)
        arr[i] = temp[i];

    return inv_count;
}

int main(){
    long n;
    cin>>n;
    long v[n];
    long a[n];
    long temp;
    for(long i=0;i<n;i++){
        cin>>temp;
        v[i]=temp;
        a[i]=temp;
    }
    long count=0;
    // for(long i=0;i<n;i++){
    count=mergeSort(v,n);
    cout<<count<<endl;
    for(long i=0;i<n-1;i++){
        count+=(n-a[i]-1);
        count-=(a[i]);
        cout<<count<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep0(i, n) for (ll i = 0; i <= (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define rrep0(i, n) for (ll i = (n); i >= 0; --i)
#define srep(i, s, t) for (ll i = s; i < t; ++i)
#define srep1(i, s, t) for (ll i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cerr << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
constexpr ll MAX = 1000;

int main()
{
    ll n;
    cin >> n;
    vl a(n + 1, 0);
    rep1(i, n) cin >> a[i];
    ll gcd = 0, ans = 0;
    srep1(i, 2, MAX)
    {
        ll count = 0;
        rep1(j, n)
        {
            if (a[j] % i == 0)
                count++;
        }
        if (gcd <= count)
        {
            gcd = count;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower)
#define upper_string(s) transform(all(s),s.begin(),::toupper)
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const int MOD=1e9+7;
void solve()
{
fastio
int n;
cin>>n;
int a[n];
for(auto &x:a)
cin>>x;
int ans=-1;
int res;
for(int i=2;i<=1000;i++)
{
	int cnt=0;
	for(auto &x:a)
	if(x%i==0)
	cnt++;
	if(ans<cnt)
	{
		res=i;
		ans=cnt;
	}
}
cout<<res;
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << H; _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define eprintf(...)
#endif

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

  ll p = 0;
  rep(i,m) {
    ll minus = a[i]-p;
    debug(i, p, n, minus);
    n-=minus;
    if(n <= 0) {
      cout << "No" << endl;
      return 0;
    }
    ll plus = b[i] - a[i];
    debug(i, p, n, plus);
    n += b[i] - a[i];
    umin(n,mx);
    p = b[i];
  }
  ll minus = t - p;
  debug(t, p, n, minus);
  n-=minus;
  if(n <= 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

/**
*    author:  tomo0608
*    created: 28.02.2021 18:08:55
**/

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

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

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

void solve(){
    int n, m;cin >> n >> m;
    V<ll> h(n);cin >> h;
    V<ll> w(m);cin >> w;
    sort(all(h));
    sort(all(w));
    V<ll> left((n+1)/2), right((n+1)/2);
    for(int i = 0; i + 1 < n; i += 2)left[i/2 + 1] = left[i / 2] + h[i + 1] - h[i];
    for(int i = n - 2; i > 0; i -= 2)right[i / 2] = right[i / 2 + 1] + h[i + 1] - h[i];
    ll ans = 1e18;
    for(auto x: w){
        int i = lower_bound(all(h), x) - h.begin();
        if(i&1)i ^= 1;
        chmin(ans, left[i/2] + right[i/2] + abs(h[i] - x));
    }
    cout << ans << endl;
}

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


//#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>
#define int long long
using namespace std;
typedef long long ll;
template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
//char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
int read() {
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
const int maxn = 3e5+10;
//const int mod = ;
//struct Edge{int to,next;}a[maxn];int h[maxn],cnt;
//void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
//vector<int>G[maxn];
//void add(int x,int y) {G[x].push_back(y),G[y].push_back(x);}
map<int,int>ton;int s[maxn],n,ans;
signed main() {
	n=read();
	for(int i=1;i<=n;i++) s[i]=s[i-1]+(i&1?-read():read());
	++ton[0];
	for(int i=1;i<=n;i++) ans+=ton[s[i]],++ton[s[i]];
	cout<<ans<<'\n';
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define P pair<int, int>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1000000000;
constexpr ll llINF = 1000000000000000000;
constexpr int mod = 1000000007;
constexpr double eps = 1e-10;
const double pi = acos(-1);
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int Random(int mi, int ma) {
    random_device rnd;
    mt19937 mt(rnd());  // 32bit
    //[mi,ma]
    uniform_int_distribution<int> engine(mi, ma);
    return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
bool prime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}
vector<int> primes;
void init_prime(int n) {
    primes.push_back(2);
    for (int i = 3; i <= n; i += 2) {
        bool f = true;
        for (int j : primes) {
            if (j * j > i) break;
            if (i % j == 0) {
                f = false;
                break;
            }
        }
        if (f) primes.push_back(i);
    }
}
ll modpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return res;
}
vector<ll> inv, fact, factinv;
void init_fact(int n) {
    inv.resize(n + 1);
    fact.resize(n + 1);
    factinv.resize(n + 1);
    inv[0] = 0;
    inv[1] = 1;
    fact[0] = 1;
    factinv[0] = 1;
    for (ll i = 1; i <= n; i++) {
        if (i >= 2) inv[i] = mod - ((mod / i) * inv[mod % i] % mod);
        fact[i] = (fact[i - 1] * i) % mod;
        factinv[i] = factinv[i - 1] * inv[i] % mod;
    }
}
ll _inv(ll a, ll m = mod) {
    // gcd(a,m) must be 1
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll comb(int a, int b) {
    if (a < b) return 0;
    if (a < 0) return 0;
    return fact[a] * factinv[a - b] % mod * factinv[b] % mod;
}
ll multicomb(int a, int b) { return comb(a + b - 1, b); }
void solve() {
    int n, a[300010];
    cin >> n;
    rep(i, n) cin >> a[i];
    ll sum = 0, ans = 0;
    map<ll, int> mp;
    mp[0]++;
    rep(i, n) {
        if (i % 2 == 0) {
            sum += a[i];
        } else {
            sum -= a[i];
        }
        mp[sum]++;
    }
    for (auto [num, cnt] : mp) {
        ans += 1LL * cnt * (cnt - 1) / 2;
    }
    cout << ans << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int t;cin>>t;while(t--)
    solve();
    return 0;
}


//****************************Template Begins****************************//

// Header Files
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
// Header Files End

using namespace std;
#define HARI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define umap unordered_map
#define uset unordered_set
#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 all1(v) (v).begin()+1,(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define allr1(v) (v).rbegin()+1,(v).rend()
#define sort0(v) sort(all(v))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define inf 9999999999999
const ll mod = 1e9 + 7;

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

ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}

ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}

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

ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}

ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
//****************************Template Ends*******************************//
vector<vll>adj;
vector<bool>visited;
ll ans;

void dfs(ll curr_node)
{
	visited[curr_node] = true;
	for (auto x : adj[curr_node])
	{
		if (!visited[x])
		{
			ans++;
			dfs(x);
		}
	}
}

int main() {
	HARI;
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll t, n, i, j, temp, sum;
	string sans;
	t = 1;
	// cin >> t;
	while (t--)
	{
		sans = "NO";
		ans = temp = sum = 0;
		cin >> n;
		vll a(n + 1, 0);
		fo(i, 1, n)
		{
			cin >> a[i];
		}
		adj.resize(200001);
		visited.assign(200001, false);
		for (i = 1; i <= n / 2; i++)
		{
			if (a[i] != a[n - i + 1])
			{
				adj[a[i]].pb(a[n - i + 1]);
				adj[a[n - i + 1]].pb(a[i]);
			}
		}
		fo(i, 1, n)
		{
			if (!visited[a[i]])
			{
				dfs(a[i]);
			}
		}
		// for (auto x : adj[1])cout << x << " ";
		// cout << "\n";
		cout << ans;
	}
	return 0;
}

#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 ll;
#define S second
#define v vector
#define dbg(x)              cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y)           cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z)         cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w)       cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<" "<<#w<<"="<<(w)<<endl;
#define mp make_pair
#define pb push_back
#define endl                '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
 fast_cin();
 ll n;
 cin >> n;
 ll arr[n];
 int i;
 for (i = 0; i < n;i++)
     cin >> arr[i];
 ll mx = *max_element(arr, arr + n);
 vector<vector<int>> v1(mx + 1);
 ll sum = 0;
 ll p = n - 1;
 for (i = 0; i <p&&i!=p; i++)
 {
if(arr[i]!=arr[p])
{
    v1[arr[i]].pb(arr[p]);
    v1[arr[p]].pb(arr[i]);

}
p--;
}
vector<ll> vis(mx + 1, 0);

queue<ll> q1;
for (i = 1; i <= mx;i++)
{
    int c = 0;
    if (vis[i] == 0&&v1[i].size()>0)
    {
        c = 0;
        q1.push(i);
        vis[i] = 1;
        while (!q1.empty())
        {
            ll z = q1.front();

            for (auto x : v1[z])
            {
                if (vis[x] == 0)
                    {
q1.push(x);
vis[x] = 1;
                    }
            }

            q1.pop();
            c++;
}
sum += (c - 1);
    }

}
cout << sum << endl;
return 0;
}


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

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

  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll dp[2];
  dp[0] = 1;
  dp[1] = 0;
  ll tx = x;
  rep(i,n-1){
    ll amari = tx%a[i];//前の＋
    ll amari_minus = amari - a[i];//前の-

    ll amari_now = tx%a[i+1];
    ll amari_now_minus = amari_now - a[i+1];
    // cout << amari <<" " << amari_minus << " " << amari_now << " " << amari_now_minus << endl;
    ll ndp[2];
    if(abs(amari-amari_now)<=a[i+1]-a[i]){
      //dp[0]そのまま
      ndp[0] = dp[0];
    }
    else{
      ndp[0] = 0;
    }
    if(abs(amari_minus-amari_now_minus)<=a[i+1]-a[i]){
      ndp[1] = dp[1];
    }
    else ndp[1] = 0;
    if(abs(amari_minus-amari_now)<=a[i+1]-a[i]) ndp[0] += dp[1];
    if(abs(amari-amari_now_minus)<=a[i+1]-a[i]) ndp[1] += dp[0];
    dp[0]= ndp[0];
    dp[1]= ndp[1];
    // cout << dp[0] <<" " << dp[1] << endl;
  }
  cout << dp[0] + dp[1] << endl;

  return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1ll<<60)-1)
#define int long long
const int P=998244353; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=5e3+5;
int n,m,a[MN],pw[MN][MN];
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read(),m=read();
	For(i,0,MN-5) {
		pw[i][0]=1;
		For(j,1,MN-5) pw[i][j]=mul(pw[i][j-1],i);
	}
	int ans=mul(ksm(m,n),n);
	For(i,2,n) { // len
		For(j,1,m) { // now
			submod(ans,mul(n-i+1,mul(pw[j-1][i-2],pw[m][n-i])));
		}
	}
	cout<<ans<<endl;
	return FastIO::Fflush(),0;
}
/*

*/

#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int ((a).size())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int M = 998244353;

struct mint {
	int x;
	mint (int x = 0) : x(x) {}
	friend mint operator +
	(const mint a, const mint &b) {
		int x = a.x + b.x;
		return mint (x >= M ? x - M : x);
	}
	friend mint operator -
	(const mint a, const mint &b) {
		int x = a.x - b.x;
		return mint (x < 0 ? x + M : x);
	}
	friend mint operator *
	(const mint a, const mint &b) {
		return mint (1ll * a.x * b.x % M);
	}
};

int Pw(int a, int x = M - 2, int res = 1) {
	for (; x; x >>= 1, a = (mint (a) * a).x)
		if (x & 1) res = (mint (res) * a).x;
	return res;
}

const int N = 5000;
int n, m, pw[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	pw[0] = 1;
	rep(i, 1, n) {
		pw[i] = (mint (pw[i - 1]) * m).x;
	}
	int res = (mint (n) * Pw(m, n)).x;
	rep(x, 0, m) {
		int px = 1;
		rep(y, 0, n - 1) {
			res = (res - mint (n - 1 - y) * px * pw[n - 2 - y]).x;
			px = (mint (px) * x).x;
		}
	}
	cout << res << '\n';
	return 0;
}

/*
	* Read Carefully! Multiple cases? Data range?
	* Transformation? Special cases? Brute & Regularities?
	* Don't get stuck! New directions! Record thoughts!
	* Int overflow? Array bounds? N = 1?
*/


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

struct Edge{
    int to; ll t; ll k;
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    --s;--t;
    vector<vector<Edge>> v(n);
    rep(i,m){
        int x,y,z,w;
        cin>>x>>y>>z>>w;
        --x;--y;
        v[x].push_back({y,z,w});
        v[y].push_back({x,z,w});
    }
    vector<ll> dist(n, longinf);
    using P = pair<ll,int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0,s);
    dist[s]=0;
    while(pq.size()){
        auto p = pq.top();pq.pop();
        ll d = p.first, x = p.second;
        if(d>dist[x])continue;
        for(auto e: v[x]){
            ll nd = (d+e.k-1)/e.k*e.k + e.t;
            if(dist[e.to] > nd){
                dist[e.to] = nd;
                pq.emplace(nd,e.to);
            }
        }
    }
    if(dist[t]>=longinf)cout<<-1<<endl;
    else cout<<dist[t]<<endl;
    return 0;
}

#define fs first
#define sc second
#include <bits/stdc++.h>

using namespace std;

typedef pair<long long, int> pii;

const int maxn = 1e5 + 10;

int n, m, x, y, a, b, t, k;

struct edge{
	int to, t, k;
};

vector<edge> G[maxn];

priority_queue<pii, vector<pii>, greater<pii>> pq;

bool vis[maxn];

long long dis[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> x >> y;
	while (m--) {
		cin >> a >> b >> t >> k;
		G[a].push_back({b, t, k});
		G[b].push_back({a, t, k});
	}
	memset(vis, false, sizeof(vis));
	memset(dis, 0x3f, sizeof(dis));
	dis[x] = 0;
	pq.emplace(0, x);
	while (pq.size()) {
		int u = pq.top().sc;
		long long tt = pq.top().fs;
		pq.pop();
		if (vis[u])
			continue;
		vis[u] = true;
		for (edge e: G[u]) {
			long long ttt = tt + (e.k - tt % e.k) % e.k + e.t;
			if (ttt < dis[e.to])
				dis[e.to] = ttt, pq.emplace(ttt, e.to);
		}
	}
	if (dis[y] == 0x3f3f3f3f3f3f3f3fLL)
		cout << "-1\n";
	else
		cout << dis[y] << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=99824453;
vin dx={-1,0,1,0};
vin dy={0,1,0,-1};

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

int main(){
    ll h,w;cin>>h>>w;
    vstr s(h);rep(i,h)cin>>s[i];
    vvin up(h,vin(w)),down(h,vin(w)),right(h,vin(w)),left(h,vin(w));
    int tmp=-1;ll k=h*w;
    rep(i,h){
        tmp=-1;
        rep(j,w){
            left[i][j]=tmp;
            if(s[i][j]=='#'){
                tmp=j;
                k--;
            }
        }
        tmp=w;
        for(int j=w-1;j>=0;j--){
            right[i][j]=tmp;
            if(s[i][j]=='#')tmp=j;
        }
    }
    rep(j,w){
        tmp=-1;
        rep(i,h){
            up[i][j]=tmp;
            if(s[i][j]=='#')tmp=i;
        }
        tmp=h;
        for(int i=h-1;i>=0;i--){
            down[i][j]=tmp;
            if(s[i][j]=='#')tmp=i;
        }
    }
    ll all=modpow((ll)2,k),light,can;
    ll ans=(ll)0;
    rep(i,h)rep(j,w){
        if(s[i][j]=='.'){
            light=(down[i][j]-up[i][j]-(ll)1)+(right[i][j]-left[i][j]-(ll)1)-(ll)1;
            can=all-modpow((ll)2,k-light);
            if(can<0)can+=inf;
            ans+=can;ans%=inf;
        }
    }
    cout<<ans<<endl;
}

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

#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define ff              first
#define ss              second
#define int             long long
#define float           double
#define pb              emplace_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vc              vector<char>
#define vb              vector<bool>
#define vf              vector<float>
#define vs              vector<string>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define hashmap         unordered_map
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT64_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)          x.begin(),x.end()
#define digits(x)       floor(log10(x))+1
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

template<class T>
void printV(vector<T> a) {for (auto v : a)cout << v << " ";}
template<class T>
void readV(vector<T>& a) {int n = a.size(); for (int i = 0 ; i < n ; i++)cin >> a[i];}
template<class T>
void printA(T* a , int n) {for (int i = 0; i < n  ; i++)cout << a[i] << " ";}
template<class T>
void readA(T* a , int n) {for (int i = 0 ; i < n ; i++)cin >> a[i];}
auto clk = clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void run_time() {cerr << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;}

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

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

    if (m == 0) {
        cout << 1;
        return;
    }
    vi a(m);
    for (int i = 0 ; i < m ; i++) {
        cin >> a[i];
    }
    sort(all(a));
    vi gaps;
    if (a[0] - 1 != 0) {
        gaps.pb(a[0] - 1);
    }
    for (int i = 1 ; i < m ; i++) {
        if (a[i] - a[i - 1] - 1 != 0) {
            gaps.pb(a[i] - a[i - 1] - 1);
        }
    }
    if (n - a[m - 1] != 0) {
        gaps.pb(n - a[m - 1]);
    }
    if (gaps.size() == 0) {
        cout << 0;
        return;
    }
    // printV(gaps);
    // cout << '\n';
    int val = *min_element(all(gaps));
    int ans = 0;
    for (auto v : gaps) {
        ans += (ceil((v * 1.0) / val));
    }
    cout << ans;
}

int32_t main() {
    aryan_pandeya();
    FIO;

    solve();
    run_time();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fr first
#define sc second
const ll mod = 1e9+7;
const int N = 2e5+5;
void solve(){
	string s;
	cin>>s;
	string ss = "atcoder";
	if(ss<s){
		cout<<0<<endl;
		return ;
	}
	int x = -1;
	int n = s.size();
	for(int i=1;i<n;i++){
		if(s[i]!='a'){
			x = i;
			if(s[i]>'t')x--;
			break;
		}
	}
	cout<<x<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	cin>>t;
	while(t--)solve();
	return 0;
}

#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int Max(size_t a,size_t b){return a>b?(int)a:(int)b;}
int main()
{
  int T;if(!scanf("%d",&T)){return -1;}
  while(T--)
  {
    char S[1001];
    if(!scanf("%s",S)){return -1;}
    if(strncmp("atcoder",S,Max(strlen(S),7))<0){puts("0");continue;}
    else
    {
      if(S[0]=='a'&&S[1]>'a'){puts("1");continue;}
      rep(i,(int)strlen(S)-1)
      {
        if(S[i+1]>'t'){printf("%d\n",i);goto jump;}
        if(S[i+1]>'a'){printf("%d\n",i+1);goto jump;}
      }
      puts("-1");jump:continue;
    }
  }
}


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

const int MAX_N = 2010;
int n, m;
vector<int> g[MAX_N];
bool check[MAX_N];
int ans = 0;

void dfs(int s){
    ans++;
    check[s] = true;
    for(auto next : g[s]){
        if(!check[next]){
            dfs(next);
        }
    }
}

void solve(){
    //dfsでいけるところまでいく
    rep(i, n){
        rep(j, n) check[j] = false;
        dfs(i);
    }
    cout << ans << endl;
}

int main(void){
    cin >> n >> m;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    solve();
    return 0;
}

#include <bits/stdc++.h>
/*
 * autor:NEU-Yuan
 * Email:yuanyanghao2022@163.com
 * Time: 2021/04/12 10:53:09
 */
#define pcc pair<char, char>
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for (int i = x; i < y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define rep0(i, n) for (int i = 0; i < (n); i++)
#define per0(i, n) for (int i = (n)-1; i >= 0; i--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
using namespace std;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 6e6 + 10;
const int MAX = 1e5;
const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f;
ll qpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res % mod;
}
/***************main****************/
ll T = 1;
ll m, n;
int main() {
  int h, w, x, y, cnt = 0;
  cin >> h >> w >> x >> y;
  string s[105];
  for (int i = 1; i <= h; i++) {
    cin >> s[i];
    s[i] = "#" + s[i];
  }
  for (int i = y - 1; i >= 1; i--)
    if (s[x][i] == '#')
      break;
    else
      cnt++;
  for (int i = y; i <= w; i++)
    if (s[x][i] == '#')
      break;
    else
      cnt++;
  for (int i = x + 1; i <= h; i++)
    if (s[i][y] == '#')
      break;
    else
      cnt++;
  for (int i = x - 1; i >= 1; i--)
    if (s[i][y] == '#')
      break;
    else
      cnt++;
  cout << cnt << endl;
  return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
#define ll long long
using namespace std;

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
// look for  all edge cases
//search for a pattern

const int mod = 1e9+7;

int power(int a, int b){
	int ans = 1;
	while(b > 0){
		if(b%2 == 1){
			ans = (a*ans)%mod;
		}
		a = (a*a)%mod;
		b = b/2;
	}
	return ans;
}

void solve(){
	int n,p;
	cin >> n >> p;
	//debug(power(2, 3), power(2, 4), power(2, 5));
	if(n == 1){
		cout << p - 1;
		return ;
	}
	else{
		cout << ((p-1) * power(p-2, n-1))%mod;
	}
}

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

	solve();

	return 0;
}

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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 (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

template<int m>
struct mint {
    int x;

    mint(ll x = 0) : x(((x % m) + m) % m) {}

    mint operator-() const { return x ? m - x : 0; }

    mint &operator+=(mint r) {
        if ((x += r.x) >= m) x -= m;
        return *this;
    }

    mint &operator-=(mint r) {
        if ((x -= r.x) < 0) x += m;
        return *this;
    }

    mint &operator*=(mint r) {
        x = ((ll) x * r.x) % m;
        return *this;
    }

    mint inv() const { return pow(m - 2); }

    mint &operator/=(mint r) { return *this *= r.inv(); }

    friend mint operator+(mint l, mint r) { return l += r; }

    friend mint operator-(mint l, mint r) { return l -= r; }

    friend mint operator*(mint l, mint r) { return l *= r; }

    friend mint operator/(mint l, mint r) { return l /= r; }

    mint pow(ll n) const {
        mint ret = 1, tmp = *this;
        while (n) {
            if (n & 1) ret *= tmp;
            tmp *= tmp, n >>= 1;
        }
        return ret;
    }

    friend bool operator==(mint l, mint r) { return l.x == r.x; }

    friend bool operator!=(mint l, mint r) { return l.x != r.x; }

    friend ostream &operator<<(ostream &os, mint a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, mint &a) {
        ll x;
        is >> x;
        a = x;
        return is;
    }
};

using Mint = mint<MOD>;

void solve() {
    int N, P;
    cin >> N >> P;

    Mint ans = Mint(P - 1) * Mint(P - 2).pow(N - 1);
    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define bg begin()
#define en end()
#define endl "\n"
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
ll power(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(ll a, ll m)
{
    return power(a, m - 2, m);
}
ll knapsack(vector<vector<ll>>&dp,ll x,ll i,ll n,ll s[],ll h[]){
    ll r,l;
    if(i>=n || x==0)
        return 0;
    if(dp[i][x]!=-1)
        return dp[i][x];
    if(x>=h[i]){
        l=s[i]+knapsack(dp,x-h[i],i+1,n,s,h);
        r=knapsack(dp,x,i+1,n,s,h);
        return dp[i][x]=max(l,r);
    }
    else
        return dp[i][x]=knapsack(dp,x,i+1,n,s,h);
}
void solve()
{
    ll n,i,p=1,s,t;
    cin>>n;
    ll a[n],j;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    vector<ll> v;
    for(i=0;i<n-1;i++){
        if(a[i]>a[i+1] && a[i+1]>i+1){
            p=0;
            break;
        }
        else if(a[i]>a[i+1]){
            for(j=i+1;j>=a[i+1];j--){
                v.push_back(j);
            }
            a[i+1]=a[i];
        }
    }
    if(p==0 || v.size()!=n-1)
        cout<<"-1";
    else{
        s=v.size();
        for(i=0;i<s;i++){
            cout<<v[i]<<endl;
        }
    }
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    solve();
    #ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define INF 1000000000000000
#define M 1000000007

void solve()
{
	ll n;
	cin>>n;
	ll i,j,k,ans=0;
	ll power[n],speed[n],technique[n],knowledge[n],invent[n];
	ll a1=0,b1=0,c1=0,d1=0,e1=0;
	for(i=0;i<n;i++)
	{
		cin>>power[i]>>speed[i]>>technique[i]>>knowledge[i]>>invent[i];
		a1=max(a1,power[i]);
		b1=max(b1,speed[i]);
		c1=max(c1,technique[i]);
		d1=max(d1,knowledge[i]);
		e1=max(e1,invent[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			ll a[5]={0};
			ll tempa=max(power[i],power[j]);
			ll tempb=max(speed[i],speed[j]);
			ll tempc=max(technique[i],technique[j]);
			ll tempd=max(knowledge[i],knowledge[j]);
			ll tempe=max(invent[i],invent[j]);
			ll mini=min(tempa,min(tempb,min(tempc,min(tempd,tempe))));
			a[0]=tempa;
			a[1]=tempb;
			a[2]=tempc;
			a[3]=tempd;
			a[4]=tempe;
			ll p=0,sum=0;
			if(mini==tempa)
			{
				p++;
				sum=a1;
			}
			if(mini==tempb)
			{
				p++;
				sum=b1;
			}
			if(mini==tempc)
			{
				p++;
				sum=c1;
			}
			if(mini==tempd)
			{
				p++;
				sum=d1;
			}
			if(mini==tempe)
			{
				p++;
				sum=e1;
			}
			if(p==1)
			{
				sort(a,a+5);
				ans=max(ans,min(sum,a[1]));
			}
			else
			{
				ans=max(ans,mini);
			}
		}
	}
	cout<<ans;
}

int main()
	{
	    SPEED;
	   	ll t;
	   	//cin>>t;
	   	t=1;
	   	for(ll ii=1;ii<=t;ii++)
	   	{
	   		//cout<<"Case #"<<ii<<": ";

			solve();
		}
 }


#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;
const int N_MAX = 100001;
const int modint = 1000000007;

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

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

int main(){

  struct member{
    int num;
    int rate;
  };

  int n;
  cin >> n;

  vector<member> a;
  member temp;
  int r;
  rep(i,pow(2,n)){
    cin >> r;
    temp.num = i+1;
    temp.rate = r;
    a.push_back(temp);
  }

  while(a.size() > 2){
    for(int i = 0;i < pow(2,n-1);i++){
      if(a[i].rate < a[i+1].rate){
        a.erase(a.begin()+i);
      }
      else{
        a.erase(a.begin()+i+1);
      }
    }
    n -= 1;
    // printf("%d\n",a.size());
  }
  if(a[0].rate > a[1].rate){
    cout << a[1].num << endl;
  }
  else{
    cout << a[0].num << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int power(int n, int exp){
  int x = 1;
  for (int i = 0; i < exp; ++i){
    x *= n;
  }
  return x;
}

int main(){
  int N;
  cin >> N;
  int NUMMAX = power(2, N);
  vector<int> A(NUMMAX);
  for (int i = 0; i < NUMMAX; ++i) cin >> A[i];
  vector<bool> isAlive(NUMMAX, true);

  int l,r;
  for (int i = 0; i < N; ++i){
    l = 0;
    r = -1;
    int num = power(2, N - i);
    for (int j = 0; j < num/2 ; ++j){
      for(l = r + 1; isAlive[l] == false && l < NUMMAX; ++l);
      for(r = l + 1; isAlive[r] == false && r < NUMMAX; ++r);
      if(A[l] < A[r]) isAlive[l] = false;
      else isAlive[r] = false;
    }
  }

  if(isAlive[l]) cout << r+1 << endl;
  else cout << l+1 << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	VI a(n);
	_rep(i, 0, n) cin >> a[i];
	VI b(a.begin(), a.begin() + m);
	sort(all(b));
	if(b[0] != 0) {
		cout << 0 << endl;
		return 0;
	}
	int ans = b.back() + 1;
	unordered_map<int,int> mp;
	mp[b[0]] ++;
	bool ok = false;
	_rep(i, 1, m) {
		mp[b[i]] ++;
		if(ok) continue;
		if(b[i] > b[i - 1] + 1) {
			ans = b[i - 1] + 1;
			ok = true;
		}
	}
	_rep(i, 0, n - m){
		mp[a[i]] -- ;
		mp[a[i + m]] ++;
		if(a[i] < ans){
			if(mp[a[i]] == 0) ans = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline

#include <bits/stdc++.h>

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

    int n;
    std::string s;

    std::cin >> n >> s;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        int at = 0, gc = 0;

        for (int j = i; j < n; j++) {
            if (s[j] == 'A') ++at;
            else if (s[j] == 'T') --at;
            else if (s[j] == 'G') ++gc;
            else --gc;

            ans += !(at || gc);
        }
    }

    std::cout << ans;

    return 0;
}


// Nurstan Duisengaliev(REALBOY)
// не, не надо меня узнавать
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/

#include <bits/stdc++.h>

#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()

using namespace std;

const int N = (int)2e5 + 123;
const int mod = 998244353;
const ll INF = (ll)1e18 + 1;
int n, a[N];
vector <int> g[N];
int used[N];
int par[N];
int kol = 0;
bool check = 0;
void Dfs (int v) {
	used[v] = 1;
	for (auto to : g[v]) {
		if (!used[to]) {
			Dfs (to);
		}
		else if (used[to] == 1) {
			check = 1;
		}
	}
	used[v] = 2;
}
void solve () {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	for (int i = 1; i <= n; i ++) {
		g[i].pb	(a[i]);
	}
	for (int i = 1; i <= n; i ++) {
		if (!used[i]) {
			check = 0;
			Dfs (i);
			kol += check;
		}
	}
	ll ans = 1;
	for (int i = 1; i <= kol; i ++) {
		ans *= 2;
		ans %= mod;
	}
	cout << (ans + mod - 1) % mod;
}

main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;
}

//#define _GLIBCXX_DEBUG
#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 = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

ll pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};

//head

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi x(n);
  rep(i, n) cin >> x[i];
  ll ans = INT64_MAX;
  rep(i, 1<<15) {
    ll now = 1;
    bool ok2 = true;
    rep(j, n) {
      bool ok = false;
      rep(k, 15) if(i>>k&1 and x[j]%pr[k] == 0) ok = true;
      if(not ok) ok2 = false;
    }
    if(ok2) {
      ll u = 1;
      rep(k, 15) if(i>>k&1) u *= pr[k];
      chmin(ans, u);
    }
  }
  cout << ans << endl;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 200100
#define MOD 1000000007  //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
struct Setup_io {
	Setup_io() {
		ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
		cout << fixed << setprecision(15);
	}
} setup_io;

int main() {
	int n;
	ll a[N];
	ll b[N];
	ll c[N];
	ll x = 0;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		x = max(x, a[i]);
		if (i == 0)c[0] = a[0] * b[0];
		else c[i] = max(c[i - 1], x*b[i]);
	}
	rep(i, n) {
		cout << c[i]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
int solve(string S) {
    if ("atcoder" < S) {
        return 0;
    }
    for (int i = 0; i < S.size(); i++) {
        if (S[i] > 't') {
            return i - 1;
        } else if (S[i] > 'a') {
            return i;
        }
    }
    return -1;
}
int main() {
    int T; cin >> T;
    while (T--) {
        string S; cin >> S;
        cout << solve(S) << '\n';
    }
    return 0;
}

#pragma GCC optimize(2)
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define Buff ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rush() int Case = 0; int T; cin >> T;  while(T--)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
#define reps(i, a, b) for(int i = a; b; i ++)
#define clc(a, b) memset(a, b, sizeof(a))
#define Buff ios::sync_with_stdio(false)
#define readl(a) scanf("%lld", &a)
#define readd(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define reads(a) scanf("%s", a)
#define read(a) scanf("%d", &a)
#define lowbit(n) (n&(-n))
#define pb push_back
#define sqr(x) x*x
#define lson rt<<1
#define rson rt<<1|1
#define ls lson, l, mid
#define rs rson, mid+1, r
#define y second
#define x first
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>PII;
const int mod = 1e9+7;
const double eps = 1e-6;
const int N = 1e6+7;
string s;
string t = "atcoder";
bool judge()
{
    reps(i, 0, s[i])    if(s[i] != 'a') return false;
    return true;
}
int main()
{
    int T;
    cin >> T;
    while(T --)
    {
        cin >> s;
        if(judge())
        {
            puts("-1");
            continue;
        }
        int res = mod;
        for(int i = 0; s[i]; i ++)
        {
            for(int j = i; s[j]; j ++)
            {
                swap(s[i], s[j]);
                if(s > t)
                {
                    res = min(res, j-i);
                    swap(s[i], s[j]);
                    break;
                }
                swap(s[i], s[j]);
            }
        }
        cout << res <<endl;
    }
	return 0;
}
/*
aaaaaaatcoder
*/


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

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

const int M=1e5+5;
const int INF=1e9;
const int MOD=1e9+7;

void go(){
	int n; cin >> n;
	string s; cin >> s;
	stack <char> st;
	vector <char> v;

	fp(i,0,n){
		if (st.size() < 2 or s[i] != 'x') st.push(s[i]);
		else {
			char x = st.top(); st.pop();
			char y = st.top();

			if (x == 'o' and y == 'f') st.pop();
			else{
				st.push(x);
				st.push(s[i]);
			}
		}
	}

	cout << st.size() << "\n";
}

int main(){

	fastio;
	go();

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define pob pop_back()
#define ms0(s) memset(s,0,sizeof s)
#define ff first
#define ss second
typedef long long int ll;
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define prq priority_queue<ll>  //max-heap
#define psq priority_queue<ll,vector<ll>,greater<ll>>  //min-heap
#define m_p make_pair
#define vcc vector<char>
#define vss vector<string>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define setbit(n) __builtin_popcountll(n)
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
//   cin>>t;
	while (t--)
	{
		ll i, j, k, n, m, ans = 0;
		cin >> n;
		string s;
		cin >> s;
		for (i = 0; i < n; i++)
		{
			map<char, ll>mc;
			for (j = i; j < n; j++)
			{
				mc[s[j]]++;
				if (mc['A'] == mc['T'] && mc['C'] == mc['G'])
					ans++;
			}
		}
		cout << ans;
	}
	return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using i64 = int64_t;
using pii = pair<i64, i64>;
#define rep(i, n) for (i64 i = 0; i < (i64) n; i++)
#define per(i, n) for (i64 i = n - 1; i >= 0; i--)
#define REP(i, a, b) for (i64 i = a; i < (i64) b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#ifdef LOCAL
#define dbg(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug(__VA_ARGS__)
#else
#define dbg(...)
#endif
template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto& x : vec) { os << x << ' '; } return os;
}
template <typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& mat) {
    os << endl; for (auto& vec : mat) { os << vec << endl; } return os;
}
template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& pa) {
    os << '(' << pa.first << ',' << pa.second << ')'; return os;
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail> void debug(Head H, Tail... T) {
    cerr << " " << H; debug(T...);
}
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1 << 30) - 1;
const i64 LINF = (1LL << 62) - 1;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> G(n);
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    vector<int> dp(n), dp2(n);

    auto dfs = [&](auto self, int& t, int v = 0, int p = -1) -> int {
        int ret = 0;

        for (int& u : G[v]) {
            if (u == p) continue;
            ret += self(self, t, u, v);
            chmax(dp[v], dp[u] + 1);
            chmin(dp2[v], dp2[u] + 1);
        }

        if (dp[v] + dp2[v] <= t) dp[v] = -INF;

        if (dp[v] == t) {
            ret++;
            dp[v] = -INF;
            dp2[v] = 0;
        } else if (p == -1 && dp[v] >= 0) {
            ret++;
        }

        return ret;
    };

    auto check = [&](int t) -> bool {
        fill(all(dp), 0);
        fill(all(dp2), INF);
        int cnt = dfs(dfs, t);
        return cnt <= k;
    };

    int ok = n - 1, ng = -1;
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int dp[101][101][101];

void relax(int& val, int nval)
{
    if (val == -1)
        val = nval;
    val = max(val, nval);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    LL x;
    cin >> n >> x;
    VI a(n);
    FOR(i, 0, n)
    {
        cin >> a[i];
    }
    LL ans = x - *max_element(ALL(a));
    FOR(k, 2, n + 1)
    {
        FILL(dp, -1);
        dp[0][0][0] = 0;
        FOR(i, 0, n)
        {
            FOR(rem, 0, k)
            {
                FOR(cnt, 0, k + 1)
                {
                    if (dp[i][rem][cnt] == -1)
                        continue;
                    relax(dp[i + 1][rem][cnt], dp[i][rem][cnt]);
                    relax(dp[i + 1][(rem + a[i]) % k][cnt + 1], dp[i][rem][cnt] + a[i]);
                }
            }
        }
        LL sum = dp[n][x % k][k];
        if (sum != -1)
        {
            assert((x - sum) % k == 0);
            ans = min(ans, (x - sum) / k);
        }
    }
    cout << ans << '\n';
    return 0;
}