#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define nl "\n"
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
typedef vector<vi>vvi;
typedef vector<long long>vl;
typedef vector <vl>vvl;
template<class T>
void print(T& a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<"\n";
}

const ll MOD=1e9+7;
ll bnp(ll n, ll p)
{
    ll res=1;
    while(p)
    {
        if(p&1)res=res*n%MOD;
        n=n*n%MOD;
        p>>=1;
    }
    if(res<0)res+=MOD;
    return res;
}

const ll MX=2e6+5;
ll fact[MX],inv[MX];

void fac()
{
    fact[0]=fact[1]=inv[0]=inv[1]=1;
    for(ll i=2; i<MX; i++)
    {
        fact[i]=fact[i-1]*i%MOD;
        inv[i]=bnp(fact[i],MOD-2);
    }
}

int main()
{

    FastIO
    fac();

    ll n,m,k; cin>>n>>m>>k;
    ll ans,tem;

    if(n>m+k)
    {
        cout<<0<<nl;
        return 0;
    }

    ans=1ll*fact[n+m]*inv[m]%MOD*inv[n]%MOD;
    if(n-k-1>=0)
    {
        tem=1ll*fact[n+m]*inv[m+k+1]%MOD;
        tem=1ll*tem*inv[n-k-1]%MOD;
        ans=(ans-tem)%MOD;
    }

    if(ans<0)ans+=MOD;
    cout<<ans<<nl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
std::chrono::high_resolution_clock::time_point start_time = std::chrono::high_resolution_clock::now();
// Defines
#define all(x) (x).begin(),(x).end()
#define sortall(x) sort(x.begin(),x.end())
#define maxin(x) *max_element(x.begin(),x.end())
#define minin(x) *min_element(x.begin(),x.end())
#define lint long long int
#define nl '\n'
#define INF (lint)1e18
#define EPS (long double)1/(INF)
//#define MOD (lint)998244353
#define MOD (lint)(1e9+7)
//Debugs
#ifdef LOCAL
    #define debugvar(x) cout<<#x<<"\t:"<<(x)<<"\n"
    #define debugvec(x) cout<<#x<<"\t:"; for(auto it = (x).begin();it!=(x).end();it++) cout<<*it<<" "; cout<<nl
#else
    #define debugvar(x) 0
    #define debugvec(x) 0
#endif
//Templates
template <typename T> inline T gcd(T a, T b) { a=(a>0?a:-a); b=(b>0?b:-b); while (b != 0) swap(b, a %= b); return a;}
template <typename T> inline T extended_gcd(T a, T& x, T b, T& y){  // returns gcd(a,b) && a*x + b*y = gcd(a,b)
    T l_a = 1, l_b = 0;
    T r_a = 0, r_b = 1;
    T q = a/b, r = a%b;
    while(r>0){
        T temp;
        temp = r_a, r_a = l_a - q*r_a ,l_a = temp;
        temp = r_b, r_b = l_b - q*r_b ,l_b = temp;
        a = b;
        b = r;
        q = a/b;
        r = a%b;
    }
    x = r_a;
    y = r_b;
    return b;
}
template <typename T> inline T MOD_inv (T num){
    lint inv,temp;
    assert(extended_gcd(MOD,temp,num,inv)==1);
    return (inv%MOD+MOD)%MOD;
}
template <typename T> inline T lcm(T a, T b) { if(a*b==0) return (T)0; return ((a/gcd(a,b))*b);}
template <typename T> inline T getpow(T base, T exp){
    if(exp==0) return (T)1;
    T half  = getpow(base,exp/2);
    T ans   = half*half;
    if(exp&1) ans = ans*base;
    return ans;
}
template <typename T> inline T getpowMOD(T base, T exp){
    if(exp==0) return (T)1;
    base    = base%MOD;
    T half  = getpowMOD(base,exp/2);
    T ans   = (half*half)%MOD;
    if(exp&1) ans = (ans*base)%MOD;
    return ans;
}
lint ncrMOD(lint n, lint r){
    if(r>n) return 0;
    r = min(r,n-r);
    lint fact = 1;
    for(lint i=1;i<=r;i++){
        fact=(fact*(n+1-i))%MOD;
        fact=(fact*MOD_inv(i))%MOD;
    }
    return fact;
}
void solve(){
    lint n,m,k;
    cin>>n>>m>>k;
    if(m-n<-k){cout<<0;return;}
    lint ans = ncrMOD(m+n,m)-ncrMOD(m+n,m+k+1);
    ans = (ans+MOD)%MOD;
    cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);lint testnum=1,totalnum=1;
    //cin>>totalnum;
    for(testnum=1;testnum<=totalnum;++testnum){
        //cout<<"Case #"<<testnum<<": ";
        //cout<<ncrMOD(28,14);
        solve();
        cout<<nl;
    }
    bool time = 0;
    //time=true;
    if(time){
        std::chrono::high_resolution_clock::time_point end_time = std::chrono::high_resolution_clock::now();
        std::chrono::duration<double> time_taken = std::chrono::duration_cast<std::chrono::duration<double>>(end_time - start_time);
        cout << "\nTime Taken: " <<setprecision(10)<<time_taken.count() << " s";
    }
return 0;
}
/*
    created on: 27.06.2021

*/


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

// template starts
using namespace __gnu_pbds; //required
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// ordered_set <int> s;
// s.find_by_order(k); returns the (k+1)th smallest element
// s.order_of_key(k); returns the number of elements in s strictly less than k

#define MOD            (1000000000+7) // change as required
#define pb(x)          push_back(x)
#define mp(x,y)        make_pair(x,y)
#define all(x)         x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define input(vec,N)   for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x)       cerr << #x << " = " << (x) << endl;

typedef long long int ll;

// start of highly risky #defines

#define int ll // disable when you want to make code a bit faster
#define endl '\n' // disable when dealing with interactive problems

// End of highly risky #defines

// template ends here

void solve(){
	// code starts from here
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	double ans = a*d + b*c;
	ans /= (b+d);
	cout << setprecision(20) << ans << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();

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

	//cout << getCurrentTime() << endl;
	return 0;
}

#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
    long double sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    long double ans;
   ans=((sx*gy)+(sy*gx))/(sy+gy);
  cout.precision(10);
  cout<<ans<<endl;
	return 0;
}


// abc193_d
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int K;
    cin >> K;
    string S, T;
    cin >> S >> T;

    ll rest = 9*K-8;
    ll numerator = 0;
    ll denominator = rest * (rest - 1);

    map<int, int> mp_s;
    REP(i, 4) mp_s[S[i]-'0']++;
    map<int, int> mp_t;
    REP(i, 4) mp_t[T[i]-'0']++;

//    print(mp_s, mp_t);

    REPN(i, 1, 10) REPN(j, 1, 10){
        ll p = K - mp_s[i] - mp_t[i];
        ll q = K - mp_s[j] - mp_t[j];
        if (i == j) q--;

        mp_s[i]++;
        mp_t[j]++;

        ll x = 0;
        REPN(k, 1,10) x += k * pow(10, mp_s[k]);

        ll y = 0;
        REPN(k, 1,10) y += k * pow(10, mp_t[k]);

//        print(i, j, p, q, x, y);

        if (p > 0 && q > 0 && x > y){
            numerator += p * q;
        }

        mp_s[i]--;
        mp_t[j]--;
    }

//    print(numerator, denominator);
    double ans = 1.0 * numerator / denominator;

    print(ans);

    return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)

ll T, X, Y, P, Q;

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

ll gcd(ll a, ll b){
	ll x, y;
	return extgcd(a, b, x, y);
}

ll mod_inverse(ll a, ll m){
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int main(){
	cin >> T;
	REP(cs, T){
		cin >> X >> Y >> P >> Q;
		ll ans = -1;
		ll d = gcd(2 * X + 2 * Y, P + Q), minv = mod_inverse((2 * X + 2 * Y) / d, (P + Q) / d);
		FOR(t, P - (X + Y - 1), P + Q - X){
			if(t % d != 0) continue;
			ll t1;
			if(t >= P - X){
				t1 = X;
			}else{
				t1 = P - t;
			}
			ll x = t1 + (minv * ((t % (P + Q) + (P + Q)) % (P + Q)) / d) % ((P + Q) / d) * (2 * X + 2 * Y);
			if(ans == -1){
				ans = x;
			}else{
				ans = min(ans, x);
			}
		}
		if(ans == -1){
			cout << "infinity" << endl;
		}else{
			assert(ans >= 0);
			cout << ans << endl;
		}
	}

}


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

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {} //0からn-1
  int find(int x) { return (d[x] < 0 ? x : d[x] = find(d[x])); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

class BValues {
public:
  static void solve(istream &cin, ostream &cout) {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    vector<int> b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    if (SUM(a) != SUM(b)) {
      cout << "No" << endl;
      return;
    }
    UnionFind temp(N + 100);
    rep(i, M) {
      int c, d;
      cin >> c >> d;
      temp.unite(c, d);
    }
    map<int, pair<int, int>> check;
    REP(i, 1, N + 1) {
      check[temp.find(i)].first += a[i-1];
      check[temp.find(i)].second += b[i-1];
    }
    FOR(i, check) {
      if (i.second.second != i.second.first) {
        cout << "No" << endl;
        return;
      }
    }
    cout << "Yes" << endl;
  }
};

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  BValues solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define data data123

const int N = 1005;

vector<int> G[N*N];

int n, m;

int pos(int i, int j) {
    return (i-1)*n+j;
}

vector<pii> data[N*N];
bool vis[N*N];

void solve() {
    scanf("%d%d", &n, &m);
    char ch[5];
    for (int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d%d%s", &u, &v, ch);
        data[u].push_back(pii(v, ch[0]-'a'));
        data[v].push_back(pii(u, ch[0]-'a'));
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (auto v1: data[i]) {
                for (auto v2: data[j]) {
                    if (v1.second == v2.second) {
                        G[pos(i, j)].push_back(pos(v1.first, v2.first));
                    }
                }
            }
        }
    }

    queue<pii> que;
    for (int i = 1; i <= n; i++) {
        que.push(pii(pos(i, i), 0));
        vis[pos(i, i)] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (auto v: data[i]) {
            que.push(pii(pos(i, v.first), 1));
            vis[pos(i, v.first)] = 1;
        }
    }
    while (!que.empty()) {
        pii t = que.front(); que.pop();
        int u = t.first;
        int x = ((u % n == 0) ? (u/n) : (u/n+1));
        int y = ((u % n == 0) ? n : (u%n));
        if ((x == 1 && y == n) || (x == n && y == 1)) {
            printf("%d\n", t.second);
            return;
        }
        for (auto v: G[u]) {
            if (!vis[v]) que.push(pii(v, t.second+2)), vis[v] = 1;
        }
    }
    printf("-1\n");

}

int main(){

    solve();
    return 0;
}


#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()

using namespace std;

int n, m, c, a[2];
long long ans;

string s;

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> s;
        c = 0;
        for (int j = 0; j < m; j++) {
            c += (s[j] - 48);
        }
        if (c & 1)
            ans += a[0], a[1]++;
        else
            ans += a[1], a[0]++;

    }
    cout << ans << endl;
}

#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    int a[2] = {0, 0};
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        int t = 0;
        for (char c : s) if (c == '1') t ^= 1;
        a[t]++;
    }
    cout << (long long)a[0] * a[1] << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define int long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;

using ll = long long;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int N = 3e3 + 5;
const int mod = 1e9 + 7;
const int INF = 1e18;
const double eps = 1e-5;
const double PI = acos(-1);

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

struct mi {
 	int v; explicit operator int() const { return v; }
	mi() { v = 0; }
	mi(ll _v):v(_v%mod) { v += (v<0)*mod; }
};
mi& operator+=(mi& a, mi b) {
	if ((a.v += b.v) >= mod) a.v -= mod;
	return a; }
mi& operator-=(mi& a, mi b) {
	if ((a.v -= b.v) < 0) a.v += mod;
	return a; }
mi operator+(mi a, mi b) { return a += b; }
mi operator-(mi a, mi b) { return a -= b; }
mi operator*(mi a, mi b) { return mi((ll)a.v*b.v); }
mi& operator*=(mi& a, mi b) { return a = a*b; }
mi pow(mi a, ll p) { assert(p >= 0); // asserts are important!
	return p==0?1:pow(a*a,p/2)*(p&1?a:1); }
mi inv(mi a) { assert(a.v != 0); return pow(a,mod-2); }
mi operator/(mi a, mi b) { return a*inv(b); }

mi dp[N][N];
int prv[N][N];
int s[N], ind[N];

void solve(int tc){
	int n;
	cin >> n;
	vector<mi> a(n+1), pref(n+1);
	for(int i=1; i<=n; i++) cin >> a[i].v;

	memset(dp, 0, sizeof dp);

	dp[0][0] = 1;

	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			s[i] = (s[i-1] + a[i].v)%k;
		}
		for(int i=0; i<k; i++){
			ind[i] = -1;
		}
		for(int i=0; i<=n; i++){
			prv[k][i] = ind[s[i]];
			ind[s[i]] = i;
		}
	}

	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			if(prv[j][i] != -1){
				dp[i][j] = dp[prv[j][i]][j-1] + dp[prv[j][i]][j];
			}
			// cout << prv[i][j] << ' ';
		}
		// cout << endl;
	}

	mi ans = 0;
	for(int j=1; j<=n; j++)
		ans += dp[n][j];
	cout << ans.v << '\n';
}

int32_t main(){
	fast;
	int tc = 1;
	// cin >> tc;
	for(int tt=1; tt<=tc; tt++){
		solve(tt);
	}
	return 0;
}

#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
const ll MOD=1000000007;

int main(){
  int n;cin>>n;
  vector<ll>sum(n+1,0);
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    sum.at(i+1)=sum.at(i)+a;
  }

  vector<vector<int>>idx(n+1,vector<int>(n+1,-1));
  vector<vector<int>>pre(n+1,vector<int>(n+1,-1));
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      idx.at(i).at(j)=pre.at(j).at(sum.at(i)%j);
      pre.at(j).at(sum.at(i)%j)=i;
    }
  }

  vector<vector<ll>>dp(n+1,vector<ll>(n+1,0));
  for(int i=1;i<=n;i++)dp.at(i).at(1)=1;
  ll ans=0;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j++){
      if(idx.at(j).at(i)!=-1){
	int x=idx.at(j).at(i);
	dp.at(j).at(i)=dp.at(x).at(i)+dp.at(x).at(i-1);
        dp.at(j).at(i)%=MOD;
      }
    }
    ans+=dp.at(n).at(i);
    ans%=MOD;
  }
  cout<<ans<<endl;
}


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
// constexpr i32 mod   = 998244353;

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

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

void solve() {
  int n = input();

  vector< string > ans;
  ans.emplace_back("AB");
  range(i, 1, n) {
    vector< string > na;
    for (auto &a : ans) {
      auto b = a;
      na.emplace_back(a + b);
      for (auto &c : b) {
        if (c == 'A') c = 'B';
        else c = 'A';
      }
      na.emplace_back(a + b);
    }

    na.emplace_back(string(ans[0].size(), 'A') + string(ans[0].size(), 'B'));
    ans = na;
  }

  cout << ans.size() << endl;
  for (auto &a : ans) cout << a << endl;
}

signed main() {
  solve();
}

#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<long long,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
#define ll long long
#define inf 1000000000000000000
#define ff first
#define ss second
#define f(i,a,b) for(ll i=a;i<b;i++)
#define it(b)  for(auto &it:b)
#define NUM 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2)%NUM;
    if (b % 2)
        return (((res * res)%NUM)* a)%NUM;
    else
        return (res * res)%NUM;
}
inline ll min(ll a,ll b)
{
    if(a>b)return b;return a;
}
inline ll max(ll a, ll b)
{
    if(a>b)return a;return b;
}
inline ll dif(long long a,long long b)
{
    if(a>b)
        return a-b;
    return b-a;
}
long long gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
    long long k=gcd(a,b);return (a*b)/k;
}
void read(vll &arr,int n)
{
    if(arr.size()!=n){arr.resize(n);}
    for(int i=0;i<n;i++)cin>>arr[i];
}
void sieveOferatosthenes(long long  MAX)
{
    vector<long long >prime;vll lps(MAX+1);
    vector<bool> pri(MAX+1,true);
    pri[1]=false;
    lps[1]=1;lps[2]=2;
    for (long long  p = 2; p * p <= MAX; p++) {
        if (pri[p]) {
            lps[p] = p;
            for (long long i = p * p; i <= MAX; i += p) {
                pri[i] = false;
                if (lps[i] == 0) {
                    lps[i] = p;
                }
            }
        }
    }
    for(long long  i=1;i<=MAX;i++) {
        if (pri[i]) {
            prime.push_back(i);
            lps[i]=i;
        }
    }
}
void solve()
{
    ll n;cin>>n;
    map<ll,ll>m;
    f(i,0,n) {
        ll a;
        cin >> a;
        m[a]++;
    }
    ll res=0;
    it(m)
    {
        res+=(it.ss*(n-it.ss));
    }
    res/=2;
    cout<<res<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << showpoint;
    cout << setprecision(6);
    int t;t=1;
    ///cin>>t;
    //WE WILL WIN.
    while(t--)
    {
        solve();
    }
}


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

const int N = 105;

int n;
typedef pair<int, int> pint;
pint a[N], b[N], c[N];

int product(pint a, pint b) {
	return a.first * b.second - a.second * b.first;
}

pint diff(pint b, pint a) {
	return {b.first - a.first, b.second - a.second};
}

int sqr(int x) {
	return x * x;
}

int dist(pint a, pint b) {
	return sqr(a.first - b.first) + sqr(b.second - a.second);
}

void _sort(pint a[]) {
	pint diff_root = diff(a[2], a[1]);

	sort(a + 3, a + n + 1, [&a, diff_root](const pint &x, const pint &y) {
		pint diff_x = diff(x, a[1]);
		pint diff_y = diff(y, a[1]);
		int product_x = product(diff_x, diff_root);
		int product_y = product(diff_y, diff_root);
		int dist_x = dist(x, a[1]);
		int dist_y = dist(y, a[1]);

		if (product_x != product_y) {
			return product_x < product_y;
		} else {
			return dist_x < dist_y;
		}
	});
}

bool check() {
	for (int i = 2; i <= n; ++ i) {
		if (dist(a[i], a[1]) != dist(c[i], c[1])) {
			return false;
		}
	}

	pint v_a = diff(a[2], a[1]);
	pint v_c = diff(c[2], c[1]);

	for (int i = 3; i <= n; ++ i) {
		pint x_a = diff(a[i], a[1]);
		pint x_c = diff(c[i], c[1]);
		if (product(x_a, v_a) != product(x_c, v_c)) {
			return false;
		}
	}

	return true;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++ i) {
		cin >> a[i].first >> a[i].second;
	}
	for (int i = 1; i <= n; ++ i) {
		cin >> b[i].first >> b[i].second;
	}

	if (n == 1) {
		cout << "Yes\n";
		return 0;
	}

	_sort(a);

	for (int root = 1; root <= n; ++ root) {
		for (int rear = 1; rear <= n; ++ rear) {
			if (rear == root) {
				continue;
			}

			c[1] = b[root];
			c[2] = b[rear];
			int index = 3;
			for (int i = 1; i <= n; ++ i) {
				if (i != rear && i != root) {
					c[index ++] = b[i];
				}
			}

			_sort(c);
			if (check()) {
				cout << "Yes";
				return 0;
			}
		}
	}

	cout << "No";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-6;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    vc<complex<ld>> S(N), T(N);
    rep(i, N) {
        ld a, b;
        cin >> a >> b;
        S[i] = {a, b};
    }
    rep(i, N) {
        ld a, b;
        cin >> a >> b;
        T[i] = {a, b};
    }

    complex<ld> sc(0, 0), tc(0, 0);
    rep(i, N) sc += S[i], tc += T[i];
    sc /= N, tc /= N;

    rep(i, N){
        S[i] -= sc;
        T[i] -= tc;
    }
    rep(i, N) rep(k, 2){
        vc<complex<ld>> ss(N), tt(N);
        rep(si, N) ss[si] = S[si] * polar(1.0L, -arg(S[k]));
        rep(ti, N) tt[ti] = T[ti] * polar(1.0L, -arg(T[i]));

        bool ok = true;
        rep(si, N) {
            bool isok = false;
            rep(ti, N){
                if (abs(ss[si] - tt[ti]) < EPS) isok = true;
            }
            if(!isok){
                ok = false;
                break;
            }
        }
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

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

// const int mod = 1e9 + 7;
// const int mod = 998244353;

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

inline void Yes(bool condition) {
    if (condition) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

int main() {
    int n;
    string s;
    cin>>n>>s;
    vector<vector<int>>  cnt(n+1, vector<int>(4, 0));
    rep(i,n){
        if (s[i] == 'A') cnt[i+1][0]++;
        else if(s[i]=='T')
            cnt[i+1][1]++;
        else if(s[i]=='C')
            cnt[i+1][2]++;
        else
            cnt[i+1][3]++;
    }
    rep(i,n){
        rep(j,4){
            cnt[i + 1][j] += cnt[i][j];
        }
    }
    int ret = 0;
    for (int i = 1; i <= n;i++) {
        for (int j = i; j <= n; j++) {
            if(cnt[j][0]-cnt[i-1][0]==cnt[j][1]-cnt[i-1][1]&&
               cnt[j][2]-cnt[i-1][2]==cnt[j][3]-cnt[i-1][3]){
                ret++;
                //cout << i << " " << j << endl;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    int N, M;
    cin >> N >> M;
    vector<ll> H(N), W(M);
    rep(i, N) { cin >> H[i]; }
    rep(i, M) { cin >> W[i]; }

    sort(all(H));
    sort(all(W));
    vector<ll> suml(N), sumr(N);
    rep(i, N - 1) {
        suml[i] = abs(H[i + 1] - H[i]);
        i++;
    }

    rep(i, N - 1) { suml[i + 1] += suml[i]; }

    for (int i = N - 1; i > 0; i--) {
        sumr[i] = abs(H[i] - H[i - 1]);
        i--;
    }

    for (int i = N - 1; i > 0; i--) {
        sumr[i - 1] += sumr[i];
    }

    ll ans = INF;
    rep(i, M) {
        ll itr = lower_bound(all(H), W[i]) - H.begin(), sum = 0;
        if (itr % 2 == 0) {
            sum += abs(H[itr] - W[i]);
            int l = itr - 1, r = itr + 1;
            if (l >= 0) {
                sum += suml[l];
            }
            if (r < N) {
                sum += sumr[r];
            }
        } else {
            sum += abs(H[itr - 1] - W[i]);
            int l = itr - 2, r = itr + 1;
            if (l >= 0) {
                sum += suml[l];
            }
            if (r < N) {
                sum += sumr[r];
            }
        }

        ans = min(ans, sum);
    }

    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

inline int solve()
{
    int n,m;
    cin>>n>>m;
    map <int , vector <int> > mp;
    fr(i,0,m){
        int x,y;
        cin>>x>>y;
        mp[x].push_back(y);
    }
    set <int> st;
    st.insert(n);
    for(auto it : mp){

        set <int> a,b;
        for(auto ut : it.second){
            int x = ut;
            if(st.find(x) != st.end() && st.find(x-1) == st.end() && st.find(x+1) == st.end()){
                b.insert(x);
            }
            if(st.find(x) == st.end() && (st.find(x-1) != st.end() || st.find(x+1) != st.end()) ){
                a.insert(x);
            }
        }
        for(auto ut : a){
            st.insert(ut);
        }
        for(auto ut : b){
            st.erase(ut);
        }
    }
    cout << st.size() << endl;
    rt;
}
signed main()
{
    // fastio;
    int t;
    int test_cases=1;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}

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

const int INF = 0x3fffffff;

using namespace std;

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

    vector<int> H(n);
    vector<int> W(m);

    for (int i = 0; i < n; i++)
        cin >> H[i];
    for (int i = 0; i < m; i++)
        cin >> W[i];

    sort(H.begin(), H.end());
    sort(W.begin(), W.end());

    vector<int> sum1((n + 1) / 2);
    vector<int> sum2((n + 1) / 2);

    for (int i = 0; i + 1 < n; i += 2) {
        int j = i + 1;
        sum1[i / 2 + 1] = sum1[i / 2] + H[i+1] - H[i];
        sum2[j / 2 + 1] = sum2[j / 2] + H[j+1] - H[j];
    }

    long long ans = 100000000000;
    for (auto w : W) {
        int idx = lower_bound(H.begin(), H.end(), w) - H.begin();
        long long sum = 0;
        if (idx % 2 != 0) {
            idx--;
        }
        sum += abs(H[idx] - w);
        sum += sum1[idx / 2] + sum2[n / 2] - sum2[idx / 2];
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main()
{
	long long A, B, C;
	cin >> A >> B >> C;

	auto power = []( long long x, long long n, long long m )
	{
		long long res = 1;
		while( n > 0 ) {
			if( n % 2 ) res = res * x % m;
			x = x * x % m;
			n /= 2;
		}
		return res;
	};
	long long bc = power( B, C, 4 );
	long long ans = power( A, bc + 4, 10 );

	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//union-find木について
//サイズによる更新をしている
ll par[201010];
ll rank2[201010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 1;
	}
}

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

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
		rank2[y] += rank2[x];
	}
	else {
		par[y] = x;
		rank2[x] += rank2[y];
	}
}

ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll dp[110][110];
vector<vector<pair<ll, ll>>>to;
bool flag[101010];
ll dist[101010];

void dfs(ll v) {
	flag[v] = true;
	for (auto nv : to[v]) {
		ll nv2 = nv.first;
		ll dist2 = nv.second;
		if (flag[nv2] == false) {
			dist[nv2] = dist[v] + dist2;
			dfs(nv2);
		}
	}
}

ll c[1010][1010];
ll a[1010], b[1010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	init(n);
	rep(i, n) {
		ll x;
		cin >> x;
		x--;
		unite(i, x);
	}
	map<ll, ll>mp;
	rep(i, n) {
		mp[find(i)]++;
	}
	ll res = 0;
	for (auto p : mp) {
		res++;
	}
	ll ans = 0;
	COMinit();
	for (ll i = 1;i <= res;++i) {
		ans += COM(res, i);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define Int register int
#define Swap(a, b) a ^= b, b ^= a, a ^= b
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define Max(x, y) ((x) < (y) ? (y) : (x))
#define Min(x, y) ((x) < (y) ? (x) : (y))
#define Isdigit(ch) (ch >= '0' and ch <= '9')

const LL MOD = 1e9 + 7;
typedef pair <int, int> T;
const int MAXN = 1e3 + 10, MAXM = 1e6 + 10, INF = 1e9;

inline LL Read () {
	LL f = 0, x = 0;
	char ch = getchar ();

	while (!isdigit (ch) ) {
		f |= (ch == '-'), ch = getchar ();
	}

	while (isdigit (ch) ) {
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar ();
	}

	return f ? -x : x;
}

inline void Write (const LL &x) {
	if (x < 0 ) {
		putchar ('-'), Write (-x);
		return ;
	}

	if (x > 9 ) {
		Write (x / 10);
	}

	putchar ((x % 10) ^ 48);
	return ;
}

LL t, n, m;

inline LL Qkpow (LL Base, LL x) {
	LL Total = 1;

	while (x ) {
		if (x & 1 ) {
			Total = Total * Base % MOD;
		}

		x >>= 1, Base = Base * Base % MOD;
	}

	return Total;
}

inline LL C(LL n, LL m) {
	n = Min (n, m - n);
	LL Answer = 1;

	for (LL i = 1; i <= n; ++ i ) {
		Answer = Answer * Qkpow (i, MOD - 2) % MOD;
	}

	for (LL i = m; i ^ (m - n); -- i ) {
		Answer = Answer * i % MOD;
	}

	return Answer;
}

signed main () {
	t = n = Read (), m = Read () + n;

	for (LL i = 1; i <= t; ++ i ) {
		n += Read ();
	}

	if (m < n ) {
		Write (0), putchar ('\n');
		return 0;
	}

	Write (C (n, m)), putchar ('\n');
	return 0;
}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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;}
//-------------------------------------------------------

int N,P;
const ll mo=1000000007;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>P;
	cout<<(P-1)*modpow(P-2,N-1)%mo<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define gc() getchar()
inline bool ig(char c){return c>='0'&&c<='9';}
inline void read(ll &oi){char c;ll f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;}
inline void print(ll oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
ll n,m;
inline ll fastmul(ll a,ll b){
	ll res=1;
	while(b){
		if(b%2)res*=a,res%=mod;
		a*=a;a%=mod;b>>=1;
	}
	return res%mod;
}
int main(){
	read(n);read(m);print((m-1)*fastmul(m-2,n-1)%mod);putchar('\n');
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename T = int> using V = vector<T>;
template<typename T = int> using VV = vector<vector<T>>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll>a(n), b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    UnionFind uf(n);
    while(m--){
        int c,d;
        cin >> c >> d;
        uf.unite(c-1,d-1);
    }
    vector<ll>sum(n);
    vector<ll>sum2(n);
    rep(i,n){
        sum[uf.find(i)] += a[i];
        sum2[uf.find(i)] += b[i];
    }
    if(sum == sum2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

class UnionFind
{
public:
	UnionFind(int min, int max)
		: elems_(max - min + 1)
		, min_(min)
		, rank_(max - min + 1)
	{
		for (int i = min; i <= max; i++) {
			Elem& elem = this->elems_[i - min];
			elem.i = i;
			elem.num = 1;
		}
	}

	int find(int i) {
		int idx = i - this->min_;
		if (this->elems_[idx].i == i) return i;

		int root = this->find(this->elems_[idx].i);
		this->elems_[idx].i = root; // 簡略化
		return root;
	}

	int size(int i) {
		int root = this->find(i);
		int idx = root - this->min_;
		return this->elems_[idx].num;
	}

	int rank() {
		return rank_;
	}

	void merge(int i, int j) {
		int i_root = this->find(i);
		int j_root = this->find(j);
		if (i_root == j_root) return;

		int i_idx = i_root - this->min_;
		int j_idx = j_root - this->min_;

		int i_size = this->elems_[i_idx].num;
		int j_size = this->elems_[j_idx].num;

		if (i_size < j_size) {
			this->elems_[i_idx].i = j_root;
			this->elems_[j_idx].num += this->elems_[i_idx].num;
		}
		else {
			this->elems_[j_idx].i = i_root;
			this->elems_[i_idx].num += this->elems_[j_idx].num;

		}
		this->rank_--;
	}

private:
	struct Elem {
		int i;
		int num; // root 以外は無効
	};

	vector<Elem> elems_;
	int          min_;
	int          rank_;
};

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

	int64_t n, m; cin >> n >> m;
	vector<int64_t> as(n + 1);
	FOR_LE(i, 1, n) {
		cin >> as[i];
	}
	vector<int64_t> bs(n + 1);
	FOR_LE(i, 1, n) {
		cin >> bs[i];
	}

	UnionFind uf(1, n);
	REP(m) {
		int a, b; cin >> a >> b;
		uf.merge(a, b);
	}

	unordered_map<int, vector<int>> gm;
	FOR_LE(i, 1, n) {
		int g = uf.find(i);
		gm[g].push_back(i);
	}

	for (auto& g : gm) {
		int64_t asum = 0;
		int64_t bsum = 0;
		for (auto i : g.second) {
			asum += as[i];
			bsum += bs[i];
		}
		if (asum != bsum) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

signed main(){

    int N; cin >> N;
    vec x(N), y(N);
    REP(i, N) cin >> x[i] >> y[i];
    v_Pii px(N), py(N);
    REP(i, N){
        px[i] = Pii(x[i], i);
        py[i] = Pii(y[i], i);
    }
    Sort(px);
    Sort(py);

    set<int> cand;
    REP(k, 2){
        cand.insert(px[k].se);
        cand.insert(px[N - 1 - k].se);
        cand.insert(py[k].se);
        cand.insert(py[N - 1 - k].se);
    }

    vec ds;
    REP(i, N){
        for(int j: cand) if(j < i) ds.pb(max(llabs(x[i] - x[j]), llabs(y[i] - y[j])));
    }
    Sort(ds);
    Out(ds[SZ(ds) - 2]);

    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=(1<<20)+5,Mod=998244353;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	int a=read(),b=read(),c=read();
	cout<<(1ll*a*(a+1)/2)%Mod*((1ll*b*(b+1)/2)%Mod)%Mod*((1ll*c*(c+1)/2)%Mod)%Mod;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
#define check(x) if(x>=mod) x-=mod
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int qpow(int x,int y){
    int ret = 1;
    while(y) {
        if(y & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return ret;
}
int n;ll k,dp[4][3000005],pre[3000005];
int main()
{
    cin>>n>>k;
    dp[0][0] = 1;rep(i,0,n+n+n) pre[i] = 1;
    rep(i,1,3) {
        rep(j,1,n+n+n) dp[i][j] = pre[j - 1] - (j <= n ? 0 : pre[j - n - 1]);
        pre[0] = dp[i][0];rep(j,1,n+n+n) pre[j] = pre[j - 1] + dp[i][j];
    }
    //rep(i,0,3) re[()]
    rep(sum,3,n+n+n) {
        if(k > dp[3][sum]) k -= dp[3][sum];
        else {
            rep(a,1,n) {
                ll cur = sum <= a ? 0 : dp[2][sum - a];
                if(k > cur) k -= cur;
                else {
                    rep(b,1,n) if(1 <= sum - a - b && sum - a - b <= n) {
                        k--;
                        if(!k) {printf("%d %d %d\n",a,b,sum-a-b);return 0;}
                    }
                }
            }
            break;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<ti> vti;
typedef vector<tl> vtl;

typedef priority_queue<int> pq;
typedef priority_queue<ti,vector<ti>,greater<ti>> pqg;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

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

	ll n,k;
	cin>>n>>k;

	vl dp(2*n+1,0);
	dp[2]=1;
	for(ll i=3; i<=2*n; i++){
		dp[i]=dp[i-1];
		if(i>n) dp[i]+=(n-(i-n)+1);
		else dp[i]+=i-1;
	}

	vl dp2(3*n+1,0);
	dp2[3]=1;
	for(ll i=4; i<=3*n; i++){
		dp2[i]=dp2[i-1];
		dp2[i]+=dp[min(i-1,2*n)]-dp[max(1LL,i-n)-1];
	}

	ll sum;
	for(ll i=3; i<=3*n; i++){
		if(dp2[i-1]<k) sum=i;
		else break;
	}

	ll cnt=dp2[sum-1];
	ll ans;
	for(ll i=1; i<=n; i++){
		if(sum-i>2*n) continue;
		ll prevcnt=cnt;
		cnt+=dp[sum-i]-dp[sum-i-1];
		if(prevcnt<k) ans=i;
		else break;
	}

	if(ans!=n) cnt-=dp[sum-(ans+1)]-dp[sum-(ans+1)-1];
	cnt-=dp[sum-ans]-dp[sum-ans-1];
	ll ans2;
	for(ll i=1; i<=n; i++){
		if(sum-i-ans>n) continue;
		ll prevcnt=cnt;
		cnt++;
		if(prevcnt<k) ans2=i;
		else {
			cnt=prevcnt;
			break;
		}
	}

	cout<<ans<<" "<<ans2<<" "<<sum-ans-ans2;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline bool read(T&x){
x=0;char c=getchar();int f=1;while(!isdigit(c)&&(c!='-')&&(c!=EOF))c=getchar();
if(c==EOF)return 0;if(c=='-')f=-1,c=getchar();
while(isdigit(c)){x=x*10+(c&15);c=getchar();}x*=f;return 1;
}template<typename T,typename...Args>inline bool read(T&x,Args&...args){bool res=1;res&=read(x);res&=read(args...);return res;}
typedef long long LL;typedef unsigned long long u64;typedef unsigned u32;typedef long double LD;
#define il inline
#define pln putchar('\n')
#define For(i,a,b)  for(int i=(a),(i##i)=(b);i<=(i##i);++i)
#define Rep(i,n)    for(int i=0,(i##i)=(n);i<(i##i);++i)
#define Fodn(i,a,b) for(int i=(a),(i##i)=(b);i>=(i##i);--i)
const int M=1000000007,INF=0x3f3f3f3f;const long long INFLL=0x3f3f3f3f3f3f3f3fLL;
const int N=100007;

int n,a[N][7],ma;

il bool f(int x){
	bool g[37];
	memset(g,0,sizeof g);
	For(i,1,n){
		u32 u=0;
		For(j,1,5)if(a[i][j]>=x)u|=(1<<(j-1));
		g[u]=1;
	}
	for(u32 i=0;i<=31;++i)if(g[i])
	for(u32 j=i;j<=31;++j)if(g[j]){
		u32 u=(i|j)^31u;
		if(u==0)return 1;
		Rep(s,32)if(g[s]&&((s&u)==u))return 1;
	}
	return 0;
}

inline void init(){
	read(n);For(i,1,n)For(j,1,5)read(a[i][j]),ma=max(a[i][j],ma);
}
inline void solve(){
	LL l=0,r=ma;
	while(l<r){
		LL mid=(l+r+1)/2;
		if(f(mid))l=mid;else r=mid-1;
	}
	printf("%lld\n",l);
}
signed main(){
	init();solve();
	return 0;
}

//                        YATIN KWATRA

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")

#define ll                      long long
#define ar                      array
#define sz(v)                   (int)(v.size())
#define inf                     1e18
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define pq                      priority_queue
#define uomii                   unordered_map<int,int,best_hash>
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     1000000007
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795
#define cz(x)                   63 - __builtin_clzll(x)

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct best_hash {
	static uint64_t splitmix64(uint64_t x) {

		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

const int N = 3e3 + 1;

int dp[N][N];
int v[N];
vii has[N][N]; // pos for remainder j from after i
int n;

int ways(int pos, int k) {
	if (pos == n + 1) return 1;
	int &ans = dp[pos][k];
	if (ans != -1) return ans;
	ans = 0;

	// now go to next k+1 or k

	int rem = v[pos - 1] % k;

	int idx = lower_bound(all(has[k][rem]), pos) - has[k][rem].begin();
	if (idx < sz(has[k][rem])) {
		int to = has[k][rem][idx];
		if (to < n) ans = (ways(to + 1, k) + ways(to + 1, k + 1)) % mod;
		else ans = ways(to + 1, k);
	}
	return ans;
}

void solve()
{
	cin >> n;
	fo(i, 1, n) cin >> v[i];

	memset(dp, -1, sizeof(dp));

	fo(i, 1, n) {
		int sum = 0;
		fo(j, 1, n) {
			sum += v[j];
			has[i][sum % i].pb(j);
		}
	}

	fo(i, 1, n) v[i] += v[i - 1];
	cout << ways(1, 1);
}

signed main() {

	FIO
	int t;
	t = 1;
	//cin >> t;
	fo(i, 0, t - 1) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int maxn = 3e5;
const int inf = 0x3f3f3f3f;

struct B{
	int l, v;
}p[maxn];
int N, M, Min[maxn], w[15], temp_w[15], sum[15], used[15];
int d[15][15], dis[15], Minw, ans, vis[15];

bool operator < (const  B& a,const B& b){
	return a.l < b.l;
}
void init(){
	cin >> N >> M;
	Minw = inf;
	ans = inf;
	for(int i = 1; i <= N; ++i) cin >> w[i];
	for(int i = 1; i <= M; ++i){
		cin >> p[i].l >> p[i].v;
		Minw = min(Minw, p[i].v);
	}
	sort(p + 1, p + 1 + M);
	Min[M] = p[M].v;
	for(int i = M - 1; i >= 1; --i){
		Min[i] = min(Min[i + 1], p[i].v);
	}
}

int bin_search(int x){
	int l = 1, r = M + 1;
	while (l < r){
		int mid = (l + r) >> 1;
		if(Min[mid] < x) l = mid + 1;
		else r = mid;
	}
	return p[l - 1].l;
}
int Caculate() {
	for(int i = 1; i <= N; ++i){
		sum[i] = temp_w[i] + sum[i - 1];
	}
	memset(dis, 0, sizeof(dis));
	for(int i = 1; i <= N; ++i){
		for(int j = i + 1; j <= N; ++j){
			dis[j] = max(dis[i] +  bin_search(sum[j] - sum[i - 1]), dis[j]);
		}
	}
	return dis[N];
}

void dfs(int cnt){
	if(cnt == N + 1){
		ans = min(ans, Caculate());
		return;
	}
	for(int i = 1; i <= N; ++i){
		if(!vis[i]){
			vis[i] = 1;
			temp_w[cnt] = w[i];
			dfs(cnt + 1);
			vis[i] = 0;
		}
	}
}

signed main(){
	init();
	for(int i = 1; i <= N; ++i){
		if(w[i] > Minw){
			cout << -1;
			return 0;
		}
	}
	dfs(1);
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int inf = 1e15 + 5 ;
const int N = 10 ;
const int M = 1e5 + 5 ;
int n, w[N], Id[N], b[N], f[N], m ;
struct node {
	int l, v ;
	node(int _l = 0, int _v = 0) { l = _l, v = _v ; }
	bool operator < ( const node &x ) const {
		return (l == x.l) ? v > x.v : l < x.l ;
	}
} l[M] ;
set<node> S ;
set<node>::iterator it ;
signed main()
{
	n = gi(), m = gi() ; int mx = 0, mi = inf ;
	rep( i, 1, n ) w[i] = gi(), Id[i] = i, mx = max(mx, w[i]) ;
	rep( i, 1, m ) l[i].v = gi(), l[i].l = gi(), mi = min( mi, l[i].l ) ;
	if( mx > mi ) { puts("-1") ; exit(0) ; }
	sort(l + 1, l + m + 1) ;
	S.insert(node(-1, 0)), S.insert(l[1]) ;
	rep( i, 2, m ) l[i].v = max( l[i - 1].v, l[i].v ) ;
	rep( i, 2, m ) S.insert(l[i]) ;
	int Ans = inf ;
	do {
		b[0] = 0 ;
		rep( i, 1, n ) b[i] = w[Id[i]] ;
		rep( i, 1, n ) b[i] += b[i - 1] ;
		rep( i, 1, n ) f[i] = 0 ;
		rep( i, 2, n ) {
			f[i] = f[i - 1] ;
			rep( j, 1, i - 1 ) {
				it = S.upper_bound(node(b[i] - b[j - 1], inf)) ;
				-- it ; node u = *it ;
				f[i] = max( f[i], f[j] + u.v ) ;
			}
		}
		Ans = min( Ans, f[n] ) ;
	} while(next_permutation(Id + 1, Id + n + 1)) ;
	cout << Ans << endl ;
	return 0 ;
}


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

int main(){
  ll t, N;
  cin >> t >> N;
  ll p = 100 + t;
  vector<bool> vec_ori(p,true);
  for(int i=0 ; i<100 ; ++i){
    vec_ori[p*i/100] = false;
  }

  vector<ll> vec;
  for(int i=0 ; i<p ; ++i){
    if(vec_ori[i]){
      vec.push_back(i);
    }
  }

  ll q = (N-1)/t;
  ll r = (N-1)%t;
  cout << p*q + vec[r] << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define Tsetso ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pr pair < int , int >
const int N = 3e6+10,NN = 1005, length = 25 , mod = 1e9+7;

ll dp[4][N];
int main() {
    Tsetso
    ll n ,k  ;
    cin >> n >> k ;
    dp[0][0] = 1;
    for ( int i = 0 ; i < 3 ; i++) {
        for (int j = 0; j <= i * n; j++) {
            dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + n + 1] -= dp[i][j];
        }
        for ( int j = 1 ; j <= (i+1) * n ; j++)
                dp[i+1][j] += dp[i+1][j-1];
    }
    int sum ;
    for ( int i = 3 ; i <= 3 * n ; i++)
    {
        if ( k <= dp[3][i])
        {
            sum = i ;
            break;
        }
        k -= dp[3][i];
    }
    int x = 0;
    for ( int i = max(1LL,sum - (2 * n)); i <= n ; i++)
    {
        if ( sum - i < 2)
                break;
        if (k <= dp[2][sum-i]) {
            x = i;
            break;
        }
        k -= dp[2][sum-i];
    }
    sum -= x ;
    int y = max(1LL,sum -n) , z = sum - y;
    y += k-1;
    z -= k-1;
    cout << x << ' ' << y << ' ' << z ;
}


//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a,ll b)
{
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b)
{
    if(a>b)return a;
    return b;
}
ll ceil1(ll a,ll b)
{
    return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
  for(ll i=0;i<si(arr);i++)
    cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--;
    g[x].pb(y);
    g[y].pb(x);
  }
}
void solve()
{
 vector<int> arr(3);
 for(int i=0;i<3;i++)
  cin >> arr[i];
sort(arr.begin(),arr.end());
  if(arr[1]-arr[0]==arr[2]-arr[1]) cout << "Yes";
  else cout << "No";
  cout << endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    //int t; cin >> t; while (t--)
    solve();

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod=1e9+7;
const int maxn = 1e4+4;
ll read() {
    ll x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
int a[4];
void solve(){
    int ok=0;
    for(int i=1;i<=3;++i) a[i]=read();

    for(int i=1;i<=3;++i){
        for(int j=1;j<=3;++j){
            for(int k=1;k<=3;++k){
                if(i!=j&&j!=k&&i!=k&&(a[i]-a[j]==a[j]-a[k])) ok=1;
            }
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main (){
    int t=1;
    //t=read();
    while(t--) solve();
}


#include <bits/stdc++.h>

using namespace std;

int n, m, q, a[51][3], b[51], x, y;

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

void solve() {
    cin >> n >> m >> q;
    vector<pair<int, int> > t;
    for(int i=1; i<=n; i++) {
        cin >> a[i][1] >> a[i][2];
        t.push_back(make_pair(a[i][1], a[i][2]));
    }
    sort(t.begin(), t.end(), sortbysec);
    for(int i=1; i<=m; i++)
        cin >> b[i];
    for(int k=1; k<=q; k++) {

        cin >> x >> y;
        vector<int> v;
        long long ans = 0;
        for(int i=1; i<=m; i++) {
            if(i<x || i>y) v.push_back(b[i]);
        }
        sort(v.begin(), v.end());
        if(v.empty()) cout << 0 << '\n';
        else {
            for(auto z : t) {
                for(int j=0; j<v.size(); j++) {
                    if(z.first <= v[j]) {
                        ans += z.second;
                        v.erase( v.begin() + j);
                        break;
                    }

                }
            }
            cout << ans << '\n';
            v.clear();
        }
    }
}

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

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

#define Fast_IO ios::sync_with_stdio(false) ,cin.tie(0) ,cout.tie(0)
int main()
{
    Fast_IO;
    int n, k, x, y, res = 0;
    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        cin >> x >> y;
        res += (x*y);
        if (res > k*100)
            return cout << i, 0;
    }
    cout << -1;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
inline int gi(){
	char tmp=getchar();int ans=0;
	int flag=1;
	while(!isdigit(tmp)){
		if(tmp=='-'){
			tmp=getchar();
			flag=-1;
			break;
		}
		tmp=getchar();
	}
	while(isdigit(tmp)){
		ans=ans*10+tmp-'0';
		tmp=getchar();
	}
	return ans*flag;
}
const int N = 201;
int S[N],R[N],F[N],Mark[N],L[N];
inline int Check(int l,int r){ // check if [l,r] is a "loop section".
	int range = ((l+r)>>1)-l+1;
	for(int i=l;i<l+range;++i){
		if(R[S[i]]) return 0;
		if(S[i]==0){
			if(R[S[i+range]])
				continue;
			if(!S[i+range])
				continue;
		}
		if(S[i]){
			if(L[S[i]])
				if(S[i+range]==0 || S[i+range] == S[i])
					continue;
			if(Mark[S[i]])
				if(S[i+range]==S[i])
					continue;
		}
		return 0;
	}
	return 1;
}
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	for(int i=1;i<=n;++i){
		int l,r;l=gi(),r=gi();
		if(S[l] || S[r]) return puts("No"),0;
		if(l>r && r!=-1) return puts("No"),0;
		if(~l&&~r){
			S[l]=i;S[r]=i;Mark[i]=1;
			continue;
		}
		if(l==-1 && r==-1)
			continue;
		if(l==-1){
			if(S[r]) return puts("No"),0;
			S[r]=i;R[i]=1;
		}
		if(r==-1){
			if(S[l]) return puts("No"),0;
			S[l]=i;L[i]=1;
		}
	}
	F[0]=1;
	Check(5,6);
	for(int i=2;i<=n<<1;i+=2){
		for(int j=0;j<i && !F[i];j+=2){
			if(!F[j]) continue;
			if(Check(j+1,i)){
				F[i] |= F[j];
			}
		}
	}
	if(F[n<<1])
		return puts("Yes"),0;
	return puts("No"),0;
}

#include<bits/stdc++.h>
using namespace std;
#include <numeric>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define MOD 1000000007
#define INT_BITS 16
#define INF 1e18
#define pi 3.141592
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n"
#define pb push_back
#define se second
#define fi first
#define pii pair<int,,int>
#define MAXN   1001
#define all(x) (x).begin(), (x).end()

#ifndef ONLINE_JUDGE
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';}
#define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}}
#else
#define deb(x) ;
#define debug(x,y) ;
#define deb_arr(a,n) ;
#define deb_mat(dist,n,m) ;
#endif

//__builtin_popcount

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

//=========================================================================================
int fact[300000], numinv[300000], factinv[300000];

int find_nCr(int n, int r)
{
    int ans = fact[n];
    ans = (ans * factinv[r]) % MOD;
    ans = (ans * factinv[n - r]) % MOD;
    return ans;
}

void factorial()
{
    fact[0] = 1;
      for (int i = 1; i < 300000; i++)
      {
          fact[i] = (fact[i - 1] * i) % MOD;
      }
      numinv[0] = 1;
      numinv[1] = 1;
      for (int i = 2; i < 300000; i++)
          numinv[i] = (MOD - (MOD / i) * numinv[MOD % i] % MOD) % MOD;

      factinv[0] = factinv[1] = 1;
      for (int i = 2; i < 300000; i++)
          factinv[i] = (numinv[i] * factinv[i - 1]) % MOD;
}

//=======================================================================================

const int N = 200004;
int incoming[N];
vector<int>v[N];
int n,m;
vector<int>temp;
int a[N];
int b[N];

void topo()
{
    for(int i=0;i<n;i++)
    {
      if(incoming[i]==0)
      {
        //q.push(i);
        temp.push_back(i);
      }
    }
}

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

    cin>>n>>m;

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

    for(int i=0;i<m;i++)
    {
      int x,y;
      cin>>x>>y;
      x--;
      y--;
      v[x].pb(y);
      incoming[y]++;
    }
    topo();
    set<int>q;
    int vis[n]={0};
   for(auto it:temp)
   {
      b[it]=INF;
      q.insert(it);
      vis[it]=1;
      //watch(it);
   }

   int ans=INT_MIN;

   while(!q.empty())
   {
      int x = *(q.begin());
      q.erase(q.begin());
      //vis[x]=0;
      for(auto it:v[x])
      {

        ans=max(a[it]-min(a[x],b[x]),ans);
        b[it]=min(min(a[x],b[x]),b[it]);
        if(vis[it]==0)
          q.insert(it);
        vis[it]=1;
      }
   }

   cout<<ans<<endl;

return 0;

}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<ll>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
// #define mp make_pair
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)
#define hell 1000000007
#define hell2 998244353
#define pi 3.14159265358979323846

int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);}

int fac[300005]; //fac[0]=0;fac[1]=1;rep(i,2,300005)fac[i]=(fac[i-1]+fac[i-2])%hell;

int ncr(int n, int r,int p) {
    if (r==0) return 1;
    return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p;
}
void code_hunter(){
    ll n,m;cin>>n>>m;
    cout<<n/m;
}
 signed main(){
    IOS;
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // cin>>t;
    while(t--){
        code_hunter();
       // cout<<"\n";
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1e9+10;
constexpr long long LINF = 1e18+10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct edge{
    int from;
    int to;
    int c;
};

int main(){
    int n, m; cin >> n >> m;
    vector<vector<edge>> G(n+10);
    rep(i, m){
        int u, v, c; cin >> u >> v >> c;
        edge e1{u,v,c};
        edge e2{v,u,c};
        G[u].push_back(e1);
        G[v].push_back(e2);
    }
    //始点＝頂点0としてBFS
    vector<int> ans(n+10, INF);//頂点に振る番号
    queue<pii> que; //頂点番号,ラベル
    que.push({1, INF});//-1
    while(!que.empty()){
        auto p = que.front(); que.pop();
        int v = p.first, c = p.second; //一致なら正、不一致なら負
        //cout << "v:" << v << " c:" << c << ln;
        if(ans[v]!=INF)continue;
        if(c==INF)ans[v] = 1;
        else{
            if(c>0){
                ans[v] = (c == 1 ? 2 : 1);
            }else{
                c = -c;
                ans[v] = c;
            }
        }
        for(auto e: G[v]){
            if(ans[e.to]!=INF)continue;
            int nc = e.c;
            if(ans[v]!=nc) nc = -e.c;
            que.push({e.to, nc});
        }
    }

    for(int i=1; i<=n; i++){
        cout << ans[i] << ln;
    }

}


#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define M 1000000007
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1, i;
   // cin >> t;

    while (t--) {
        int n,count=0;
        cin>>n;
        pair<int,int> p[n];
        fo(i, n)
        {
            cin>>p[i].first>>p[i].second;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                int temp=0,temp2=0;
                temp=p[j].second-p[i].second;
                temp=abs(temp);
                temp2=p[j].first-p[i].first;
                temp2=abs(temp2);

                if(temp<=temp2)
                {
                    count++;
                }
            }
        }
        cout<<count;

    }

return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double k=0.6180339887498948482045;
ll x,y,tmp;
vector<int> ans;
int main(){
	scanf("%lld",&tmp);if(tmp==0) {printf("0\n");return 0;}
	//printf("%lf\n",((long double)tmp)*k-50);
	for(ll i=max((ll)(((long double)tmp)*k)-50,0ll);;i++){
		x=tmp;y=i;ans.clear();
		while(x&&y){
			if(x>y) ans.push_back(3),x=x-y;
			else ans.push_back(4),y=y-x;
			if(ans.size()>130) {break;}
		}
		if(ans.size()+max(x,y)<=130){
			if(x) for(int i=1;i<=x;i++) ans.push_back(1);
			else for(int i=1;i<=y;i++) ans.push_back(2);
			printf("%d\n",ans.size());
			for(int i=ans.size()-1;i>=0;i--) printf("%d\n",ans[i]);
			return 0;
		}
	}
	return 0;
}/*
47584759575744849
*/


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

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
int j=t*1.08;
if(j>206)
cout<<":("<<endl;
else if(j==206)
cout<<"so-so"<<endl;
else
cout<<"Yay!"<<endl;
return 0;
}

// You told me...
// At your absolute best, you still won't be good enough for the wrong person...
// At your worst, you'll still be worth it to the right person...

// ............................................................................................
// It was good while it lasted, good bye...                                                   .
// I believe I really loved you... to that point that I always want to hear your voice...     .
// But before my hand could reach you... you seem to be slowly disappearing from my sight...  .
// ............................................................................................

#pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define fill(x, v) memset(x, v, sizeof(x))
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

// #define N 680005
// #define mod1 1000000007
#define mod1 998244353
// #define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)
#define INF 2e18

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b : a+b-mod;}
inline ll rem(ll a, ll b, ll mod) { return a >= b? a - b: a- b + mod;}
inline ll mul(ll a, ll b, ll mod) { return (int) a*b%mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (int) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
    ll ret;
    for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
    return ret;
}

static inline void read(ll &result) {
    bool minus = false;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' and ch <= '9') break;
        ch = getchar();
    }
    (ch == '-')? minus = true: result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' or ch > '9') break;
        result = (result<<3)+ (result<<1) + (ch - '0');
    }
    if(minus) result = -result;
}

int main(){
    ll n; read(n);
    double total = n * 1.08;
    if((ll) total < 206) cout<<"Yay!\n";
    else if((ll) total == 206) cout<<"so-so\n";
    else cout<<":(\n";
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll cnt[10];
string s, t;
ll occ[10][2];
ll p10[10];
bool check(){
	ll sum1 = 0, sum2 = 0;
	for (ll i = 1; i <= 9; i++) sum1 += p10[occ[i][0]] * i;
	for (ll i = 1; i <= 9; i++) sum2 += p10[occ[i][1]] * i;
	return (sum1 > sum2);
}
int main(){
	cout << fixed << setprecision(12);
	fastio;
	p10[0] = 1;
	for (ll i = 1; i < 10; i++) p10[i] = p10[i - 1] * 10;
	ll k; cin >> k;
	for (ll i = 1; i <= 9; i++) cnt[i] = k;
	cin >> s >> t;
	for (ll i = 0; i < 4; i++){
		cnt[s[i] - '0']--;
		cnt[t[i] - '0']--;
		occ[s[i] - '0'][0]++;
		occ[t[i] - '0'][1]++;
	}
	ll sum_choice = 0, sum_good = 0;
	for (ll u = 1; u <= 9; u++){
		for (ll d = 1; d <= 9; d++){
			ll choice;
			if (u == d) choice = cnt[u] * (cnt[u] - 1);
			else choice = cnt[u] * cnt[d];
			sum_choice += choice;
			occ[u][0]++; occ[d][1]++;
			if (check()) sum_good += choice;
			occ[u][0]--; occ[d][1]--;
		}
	}
	ld tmp = sum_good; tmp /= sum_choice;
	cout << tmp << "\n";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = b - 1; a <= i; i--)
ll MOD = 1000000007;

ll K, cnt_a[10], cnt_t[10], ao, taka, win, total;
string T, A;

int main () {
  cin >> K >> T >> A;

  rep (i, 0, 4) {
    cnt_t[T[i] - '0']++;
    cnt_a[A[i] - '0']++;
  }

  rep (ura_a, 1, 10) rep (ura_t, 1, 10) {
    cnt_a[ura_a]++;
    cnt_t[ura_t]++;

    if (cnt_a[ura_a] + cnt_t[ura_a] <= K && cnt_a[ura_t] + cnt_t[ura_t] <= K) {
      ll d;
      if (ura_a == ura_t) {
        d = (K - cnt_a[ura_a] - cnt_t[ura_t] + 2) * (K - cnt_a[ura_a] - cnt_t[ura_t] + 1);
      } else {
        d = (K - cnt_a[ura_a] - cnt_t[ura_a] + 1) * (K - cnt_a[ura_t] - cnt_t[ura_t] + 1);
      }
      ao = 0, taka = 0;

      rep (i, 1, 10) {
        ll x = i;
        rep (j, 0, cnt_a[i]) x *= 10;
        ao += x;

        x = i;
        rep (j, 0, cnt_t[i]) x *= 10;
        taka += x;
      }

      total += d;
      if (taka > ao) win += d;
    }

    cnt_a[ura_a]--;
    cnt_t[ura_t]--;
  }

  double ans = (double)win / total;
  cout << fixed << setprecision(7) << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 REP(i,a,b) for(int i = (a); i < (b); i++)
#define MOD 1000000007

int main(void) {
  int m,h;
  cin >> m >> h;
  if(h%m==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int m, h;
    cin >> m >> h;
    if (h % m == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

int main() {
  int H,W;
  cin >> H >> W;
  int min;
  vector<vector<int>> data(H,vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
      if (i == 0 && j == 0) {
        min = data.at(i).at(j);
      }
      else if (data.at(i).at(j) < min) {
        min = data.at(i).at(j);
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) > min) {
        sum += data.at(i).at(j) - min;
      }
    }
  }
  cout << sum << endl;
}

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

ll sov(ll b,ll c){
	if(c==1){
		if (b==0) return 1;
		return 2;
	}
	if (b==0) return c;
	if (b>(c/2)) return c*2-1;
	if (b<=-(c/2)) return c*2-1;
	if (b>0) return c+2*b-1;
	if (b<0) return c-2*b;
}

int main() {
	ll b,c,ans;

	cin >> b >> c;
	cout << sov(b,c) << endl;
	return 0;
}


#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
//typedef pair<LL, LL> P;
using namespace std;
//using Graph = vector<vector<LL>>;

const LL MOD=1000000007;
//const LL MOD=998244353;
//const LL MAX=100100;
//const LL NIL=-1;
//const LL INF=2000000000000000000;
//const LL SEG_VAL = 1 << 19;

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

    LL t;
    LL n;
    cin >> t >> n;
    vector<pair<LL, LL>> vr;
    LL cur=1;
    LL i=0;
    while(vr.size()<11){
        if((i*t)/100>=cur){
            vr.push_back(make_pair(i, (i*t)%100));
            cur*=2;
        }
        i++;
    }

    LL num=0;
    LL res=0;

    /*
    for(LL i=0; i<11; i++){
        cout << vr[i].first << " " << vr[i].second << endl;
    }
    */

    while(n>0){
        //cout << n << " " << num << " " << res << endl;
        if(n<2048){
            while(n>0){
                num++;
                res+=t;
                if(res/100>=1){
                    res-=100;
                    n--;
                    //cout << num << " " << res << endl;
                }
            }
        }else{
            num+=vr[10].first;
            n-=1024;
            n-=(res+vr[10].second)/100;
            res=(res+vr[10].second)%100;
        }
    }

    cout << num+(num*t/100)-1 << endl;

    return 0;
}

#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
//typedef pair<LL, LL> P;
using namespace std;
//using Graph = vector<vector<LL>>;

//const LL MOD=1000000007;
//const LL MOD=998244353;
//const LL MAX=100100;
//const LL NIL=-1;
//const LL INF=2000000000000000000;
//const LL SEG_VAL = 1 << 19;

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

    LL n;
    LL k;
    cin >> n >> k;
    LL ans=0;
    for(LL i=1; i<=n; i++){
        for(LL j=1; j<=k; j++){
            ans+=100*i+j;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,k,m,i,j;
	scanf("%d %d %d",&n,&k,&m);
	int a[101];
	int sum = 0;
	for(i=0;i<n-1;i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	int tot = n*m;
	int x = tot - sum;
	if(x < 0){
		x = 0;
	}
	if(x >= 0 && x <= k){
		printf("%d\n",x);
	}else{
		printf("-1\n");
	}
	return 0;
};

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

#define ll long long
#define ull unsigned long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ln "\n"
#define si(n) scanf("%d", &n);
#define pi(n) printf("%d\n", n);
#define sd(n) scanf("%lf", &n);
#define pd(n) printf("%.2lf\n", n);

const double EPS = (double) 1e-9;
const double pii = acos(-1);
const int mod = 1000000007;
const int N = (int) 1e5;

int main()
{
    fast_in_out;
    int a, b, x, y;
    cin >> a >> b >> x >> y ;
    int ans = x;
    if(a == b)
    {
        cout << ans << ln;
    }
    else if(a < b)
    {
        int dif = b - a;
        int cnt1 = dif * y;
        int cnt2 = dif * x * 2;
        ans += min(cnt1, cnt2);
        cout << ans << ln;
    }
    else
    {
        int dif = a - b;
        if(dif == 1)
        {
            cout << ans << ln;
        }
        else
        {
            dif--;
            int cnt1 = dif * y;
            int cnt2 = dif * x * 2;
            ans += min(cnt1, cnt2);
            cout << ans << ln;
        }
    }
}


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

const int MAX_N = 2e5+2;
int n;
int a[MAX_N];
int b[MAX_N];
int p[MAX_N];
vector<int> g[MAX_N];

void solve()
{
	if(n == 1){
		cout<<0<<'\n';
		return;
	}
	for(int i=1;i<=n;++i)if(p[i]!=i && a[i] <= b[p[i]]){
		cout<<-1<<'\n';
		return;
	}
	vector<pair<int,int>> ans;
	for(int i=1;i<=n;++i)if(a[i]!=-1){
		vector<int> cycle;
		int mx=-1,s=-1,v=i;
		while(a[v]>=0){
			if(a[v]>mx){
				mx=a[v];
				s=(int)cycle.size();
			}
			cycle.push_back(v);
			a[v]=-1;
			v=p[v];
		}
		rotate(cycle.begin(),cycle.begin()+s,cycle.end());
		for(int i=1;i<(int)cycle.size();++i){
			ans.emplace_back(cycle[0],cycle[i]);
		}
	}
	cout<<ans.size()<<'\n';
	for(auto& x : ans) cout<<x.first<<' '<<x.second<<'\n';
}

int main()
{
	cin >> n;
	for(int i=1;i<=n;++i) cin >> a[i];
	for(int i=1;i<=n;++i) cin >> b[i];
	for(int i=1;i<=n;++i) cin >> p[i];
	solve();
	return 0;
}

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

const int maxn = 2e5+8, inf = 1e18+9, mod  = 1e9+7;

int n, m, a[maxn], b[maxn], p[maxn], vs[maxn];

void solve() {
    int i, j;
    //cin >> n;
    scanf("%lld", &n);
    vector<pair<int, int>> vec;
    for (i = 1; i <= n; i++) scanf("%lld", &a[i]); //cin >> a[i];
    for (i = 1; i <= n; i++) scanf("%lld", &b[i]); //cin >> b[i];
    for (i = 1; i <= n; i++) scanf("%lld", &p[i]); //cin >> p[i];
    for (i = 1; i <= n; i++) if (a[i] <= b[p[i]] && i != p[i]) return (void)(printf("-1\n"));
    for (i = 1; i <= n; i++) if (!vs[i]) {
        int start = i; vs[i] = 1;
        if (i == p[i]) continue;
        for (j = p[i]; j != i; j = p[j]) {
            vs[j] = 1;
            if (a[j] > a[start]) start = j;
        }
        for (j = p[start]; j != start; j = p[j]) vec.push_back({start, j});
    }
    //cout << vec.size() << endl;
    printf("%lld\n", (int)vec.size());
    for (auto [x, y] : vec) printf("%lld %lld\n", x, y); //cout << x << " " << y << endl;
}

signed main() {
    //ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#define N 201000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
int n;
int a[N], b[N], h[N], htot;
long long ans;
inline void sol(int L, int R) {
	if (L + 1 == R)	return ;
//	printf("sol(%d, %d) : \n", L, R);
	int ptr = R;
	for (int i = L + 1; i < R; ++i) if (b[i] > a[i]) { ptr = i; break; }
//	printf("ptr = %d\n", ptr);
	int tol = a[ptr - 1];
	for (int i = ptr - 1; i > L; --i) {
		if (b[i] < tol) {
			int p = upper_bound(a + L, a + R + 1, b[i]) - a - 1;//bug
//			printf("i = %d, p = %d\n", i, p);
			ans += i - p;
			tol = b[i];
		}
	}
	int tor = a[ptr];
	for (int i = ptr; i < R; ++i) {
		if (b[i] > tor) {
			int p = lower_bound(a + L, a + R + 1, b[i]) - a;//bug bug
//			printf("i = %d, p = %d\n", i, p);
			ans += p - i;
			tor = b[i];
		}
	}
}
int main() {
	read(n);
	int L;
	read(L);
	++n; ++n;
	a[0] = b[0] = 0; a[n - 1] = b[n - 1] = L + 2 - n;//0 ... L + 1
	for (int i = 1; i < n - 1; ++i) read(a[i]), a[i] -= i;
	for (int i = 1; i < n - 1; ++i) read(b[i]), b[i] -= i;
//	for (int i = 0; i < n; ++i) printf("%d ", a[i]); puts("");
//	for (int i = 0; i < n; ++i) printf("%d ", b[i]); puts("");
	for (int i = 0; i < n; ++i) h[++htot] = a[i];
	htot = unique(h + 1, h + 1 + htot) - h - 1; h[htot + 1] = -12341;
	for (int i = 0; i < n; ++i) a[i] = lower_bound(h + 1, h + 1 + htot, a[i]) - h;
	for (int i = 0; i < n; ++i) {
		int v = lower_bound(h + 1, h + 1 + htot, b[i]) - h;
		if (h[v] != b[i]) return puts("-1"), 0;
		b[i] = v;
	}
//	for (int i = 0; i < n; ++i) printf("%d ", a[i]); puts("");
//	for (int i = 0; i < n; ++i) printf("%d ", b[i]); puts("");
	int lst = 0;
	for (int i = 1; i < n; ++i) if (a[i] == b[i]) {
//		printf("\ni = %d : \n", i);
		sol(lst, i); lst = i;
//		printf("ans = %lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

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

using namespace std;

int n,q;
ll a[100010],c[100010];
ll k;

int main(){
    cin >> n >> q;
    rep(i,n){
        cin >> a[i];
    }
    sort(a, a+n);
    rep(i,n){
        c[i] = a[i]-i-1;
    }

    rep(ii,q){
        cin >> k;
        int ldx = lower_bound(c, c+n, k)-c;
        if(ldx >= 0 && ldx < n && c[ldx] == k){
            cout << a[ldx]-1 << endl;
            continue;
        }

        int idx = upper_bound(c, c+n, k)-c-1;
        // cout << "ii " << ii << " idx "  << idx <<endl;
        if(idx == -1){
            cout << k << endl;
        }
        else {
            cout << a[idx]+k-c[idx]<<endl;
        }
    }

}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main() {

	int day;
	cin >> day;

	if (day % 2 == 0) {
		cout << "White";
	}
	if (day % 2 == 1) {
		cout << "Black";
	}

	return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int N;

int main(){
    cin>>N;

    if(N&1) cout<<"Black"<<endl;
    else cout<<"White"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll x; cin >> n >> x;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<ll> cnt(n);
  {
    ll rem = x;
    rep(i, n) {
      if(i == n-1) cnt[i] = rem / A[i];
      else cnt[i] = (x % A[i+1]) / A[i];
    }
  }
  vector<vector<ll>> dp(n, vector<ll>(2));
  dp[0][0] = 1;
  rep(i, n-1) {
    if(cnt[i]) {
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][0];
    } else {
      dp[i+1][0] += dp[i][0];
    }
    if(cnt[i]+1 < A[i+1]/A[i]) {
      dp[i+1][0] += dp[i][1];
      dp[i+1][1] += dp[i][1];
    } else {
      dp[i+1][1] += dp[i][1];
    }
  }
  cout << dp[n-1][0] + dp[n-1][1] << endk;
  return 0;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using ll = long long;
using namespace std;

ll n, x;
ll a[50];
ll v[50];
ll l[50];
ll dp[51];
ll dq[51];
int main() {
	cin >> n >> x;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 1; i < n; ++i) l[i - 1] = a[i] / a[i - 1] - 1;
	l[n - 1] = 2e18;

	ll s = x;
	for (int i = n - 1; i >= 0; --i) {
		v[i] = s / a[i];
		s %= a[i];
	}

	dp[0] = 1;
	for (int i = 0; i < n; ++i) {
		if (v[i] == 0) {
			dp[i + 1] = dp[i] + dq[i];
			dq[i + 1] = dq[i];
		} else {
			dp[i + 1] = dp[i] + (v[i] < l[i]) * dq[i];
			dq[i + 1] = dp[i] + dq[i];
		}
	}
	cout << dp[n] << endl;
	return 0;
}