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

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

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

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 2e5 + 5;

void solve()
{

      int n;
      cin >> n;

      map<int,int>m;

      vi b(n);

      for(int i = 0;i < n; i++)
      {
            int d;
            cin >> d;
            m[d]++;
      }

        for(auto &x : b)
        cin >> x;

      int ans = 0;

      for(int i = 0 ;i < n; i++)
      {
            int d;
            cin >> d;
            ans += m[b[d - 1]];

      }

      db(ans)

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

     #ifndef ONLINE_JUDGE
     freopen("INP.txt", "r", stdin);
     freopen("out.txt", "w", stdout);
     #endif

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

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values

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

typedef long long ll;
typedef long double ldb;
typedef double db;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define forp(i, a, b) for (ll i = a; i <= b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (ll i = a; i >= b; i--)
#define on cout << endl
#define o2(a, b) cout << a << " " << b
#define os cout << " "
#define all(v) v.begin(), v.end()
#define sortall(v) sort(all(v))
#define mem(n, m) memset(n, m, sizeof(n))
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define mll map<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define ret return 0
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (__typeof(container.begin()) it = a; it != b; it++)
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return (b * a) / gcd(a, b);
}
ll fact(ll n)
{
    if (n <= 1)
        return 1;
    return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
    return fact(n) / fact(n - r);
}
ll cd(ll n)
{
    ll c=0;
    while(n>0)
    {
        n/=10;
        c++;
    }
    return c;
}
ll log2(ll n)
{
    ll c=0;
    while(n>0)
    {
        n/=2;
        c++;
    }
    return c;
}
ll XOR(ll x, ll y)
{
   return (x | y) & (~x | ~y);
}
bool isprime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
void c_p_c()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    c_p_c();
    ll t;
    t = 1;
    // cin >> t;
    while (t-- > 0)
    {
        string s;
        cin>>s;
        rep(j, s.size())
        {
            if(s[j]=='.')
                break;
            cout<<s[j];
        }
    }

    return 0;
}


#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

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

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    a.push_back(0);
    ll ans = 1;
    for (int i = 0; i < n; i++){
        ans *= (a[i] - a[i + 1] + 1);
        ans %= MOD;
    }

    cout << ans << endl;
}

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

#include <iostream>
#include <fstream>

#ifndef JHELPER1_COMMON_H
#define JHELPER1_COMMON_H

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

typedef long long ll;
using namespace std;

// int max: 2,147,483,647
// long long max: 9,223,372,036,854,775,807
constexpr ll MOD = 1000L * 1000 * 1000 + 7L;
constexpr ll INF = 1000L * 1000 * 1000 * 1000 * 1000 * 1000 + 7L;

#define READ_VEC(v) for(auto &e: v){in >> e;}
#define READ_PAIR_VEC(v) for(auto &e: v){in >> e.first >> e.second;}
#define ALL(c) std::begin(c), std::end(c)
#define for_(i, a, b) for(int i=(a); i<(b); i++)
#define rfor_(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define rep(i, n) for(int i=0; i<(n); i++)
#define rrep(i, n) for(int i=(n)-1; i>=0; i--)

#endif //JHELPER1_COMMON_H

class BARCWrecker {
public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in>>n;
    vector<ll> a(n);
    READ_VEC(a);
    sort(ALL(a));
    ll tot = 1 + a[0];
    rep(i, n-1) {
      tot *= (a[i+1] - a[i] + 1);
      tot %= MOD;
    }
    out << tot<<endl;
  }
};

int main() {
  ios_base::sync_with_stdio(false); // Disable C++ and C sync
  cin.tie(NULL); // Disable cin and cout sync

  BARCWrecker solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
  	int n;
  	cin>>n;
  	float x=1.08*n;
  	x=round(x);
      if(x<206.0)
        {
          cout<<"Yay!"<<endl;
        }
        else if (x>206.0)
        {
          cout<<":("<<endl;
        }
        else if(x==206.0)
        {
          cout<<"so-so"<<endl;
        }
}

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

typedef unsigned long long ull;
typedef long long ll;

#define mcfor(i, L, R) for(ll i = ll(L); i < ll(R); i++)
#define mcford(i, L, R) for(ll i = ll(L-1); i >= ll(R); i--)
#define mcrep(i, N) for(ll i = 0; i < ll(N); i++)
#define mcrepd(i, N) for(ll i = ll(N-1); i >= 0; i--)
#define mcall(arr) arr.begin(), arr.end()
#define mcsize(arr) ll(arr.size())
#define INF32 2147483647
#define INF64 9223372036854775807

//char '0-9': 48-57, 'A-M,N-Z': 65-77,78-90,
//     'a-m,n-z': 97-109,110-122

//setprecision(10)

int main(){
  int N;
  cin >> N;

  double price = 1.08 * (double)N;

  if(price < 206){
    cout << "Yay!" << endl;
  }
  else if(price < 207){
    cout << "so-so" << endl;
  }
  else{
    cout << ":(" << endl;
  }

  return 0;
}


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

#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
const long long inf = 2e18;
const int mod = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <class T>
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}

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

template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
  t = v;
}

template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
  for (auto &e : t) fill(e, v);
}

template <class T>
struct SegmentTree {
  using F = function<T(T, T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree() {}
  SegmentTree(vector<T> v, T inf, F f) : inf(inf), f(f) {
    n = 1;
    while (n < v.size()) n *= 2;
    node.resize(2 * n - 1, inf);
    for (int i = 0; i < v.size(); i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = f(node[2 * i + 1], node[2 * i + 2]);
  }

  void update(int k, T val) {
    k += n - 1;
    node[k] = val;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }

  void add(int k, T val) {
    k += n - 1;
    node[k] += val;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }

  //区間[a, b)の値を返す
  T operator[](int x) { return getval(x, x + 1); }
  T getval(int a, int b) { return getval(a, b, 0, 0, n); }
  T getval(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return inf;
    if (a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = getval(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }

  void print(int n) {
    for (int i = 0; i < n; i++) {
      cout << getval(i, i + 1) << " ";
    }
    cout << endl;
  }
};

signed main() {
  int n;
  cin >> n;
  vector<int> p(n - 1);
  cin >> p;

  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    g[p[i] - 1].push_back(i + 1);
    g[i + 1].push_back(p[i] - 1);
  }

  int q;
  cin >> q;
  vector<vector<pair<int, int>>> query(n);
  for (int i = 0; i < q; i++) {
    int u, d;
    cin >> u >> d;
    u--;
    query[d].push_back({i, u});
  }

  int num = 0;
  vector<int> in(n), out(n);
  vector<vector<int>> depth(n);
  auto dfs = [&](auto &&dfs, int u, int par, int d) -> void {
    in[u] = num++;
    depth[d].push_back(u);
    for (int v : g[u]) {
      if (v == par) continue;
      dfs(dfs, v, u, d + 1);
    }
    out[u] = num++;
  };
  dfs(dfs, 0, -1, 0);

  SegmentTree<int> seg(vector<int>(num, 0), 0,
                       [&](int x, int y) { return (x + y); });

  vector<int> ans(q);
  for (int i = 0; i < n; i++) {
    for (int node : depth[i]) {
      seg.update(in[node], 1);
    }
    for (auto p : query[i]) {
      ans[p.first] = seg.getval(in[p.second], out[p.second] + 1);
    }
    for (int node : depth[i]) {
      seg.update(in[node], 0);
    }
  }

  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll conbinationMemo[61][31];

void cmemoInit(){
    rep(i, 61){
        rep(j, 31){
            conbinationMemo[i][j] = -1;
        }
    }
}

ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n;
ll q;
vector<vector<ll>> g;
vector<vector<ll>> l;
ll in[200200];
ll out[200200];
void dfs(ll now, ll pa, ll d, ll &time){

    in[now] = time;
    l[d].push_back(time);
    time++;

    rep(i, g[now].size()){
        ll next = g[now][i];
        if(next == pa) continue;
        ll nextd = d + 1;
        dfs(next, now, nextd, time);
    }

    out[now] = time;
    time++;

}
int main(void){
    cin >> n;
    g.resize(n);
    l.resize(n);
    rep(i, n - 1){
        ll p;
        cin >> p;
        p--;
        g[p].push_back(i + 1);
    }
    ll time = 0;
    dfs(0, -1, 0, time);
    cin >> q;
    rep(i, q){
        ll u, d;
        cin >> u >> d;
        u--;

        auto itr1 = lower_bound(all(l[d]), in[u]);
        auto itr2 = lower_bound(all(l[d]), out[u]);
        cout << itr2 - itr1 << endl;
    }
}


#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>

using namespace std;

typedef int64_t ll;

int main(int argc, char *argv[])
{
	ll b, c;
	cin >> b >> c;
	//b = -1e18;
	//c = 1;

	ll pmin = b - (c / 2);
	ll pmax = max(b + (c / 2) - 1, pmin);
	ll pnum = pmax - pmin + 1;//(c / 2) * 2;
	ll nmin = -b - (c - 1) / 2;
	ll nmax = -b + (c - 1) / 2;
	ll nnum = nmax - nmin + 1;//(c - 1) / 2 * 2 + 1;
	ll dnum = 0;

	ll dmin = max(pmin, nmin);
	ll dmax = min(pmax, nmax);
	if (dmin <= dmax)
	{
		dnum = dmax - dmin + 1;
	}

	cout << pnum + nnum - dnum << endl;

	return 0;

}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define mp make_pair
#define ins insert
#define sz(x) (int)x.size()
#define whoami(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); whi(_it, args); }

void whi(istream_iterator<string> it) { cerr<<"\n"; }

template<typename T, typename... Args>
void whi(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<" "<<a<<" "; whi(++it, args...); }

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;
const ll INF = 4e18;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
    static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
        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);
}
};

struct h_pair{
    size_t operator()(const PLL&x)const{
        return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
    }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
    ll b,c;
    cin>>b>>c;
    VL cst(2);
    cst[0] = c;
    cst[1] = c-1;
    vector<PLL> af(2);
    auto rpt = [ & ](int yt){
        if(cst[yt] & 1)
        {
            af[yt].ff = -b-(cst[yt]>>1LL);
            af[yt].ss = -b+(cst[yt]>>1LL);
        }
        else
        {
            af[yt].ff = b-(cst[yt]>>1LL);
            af[yt].ss = max(b, b+(cst[yt]>>1LL)-1);
        }
        return;
    };
    ll ans = 0, iaf = -INF, ias = INF;
    for(auto _=0;_<2;_++)
    {
        rpt(_);
        ans += (af[_].ss - af[_].ff + 1);
        iaf = max(iaf, af[_].ff);
        ias = min(ias, af[_].ss);
    }
    ans -= max(0LL, (ias - iaf + 1));
    cout<<ans<<"\n";
    return;
}

int main(void)
{
    FLASH();
    //freopen("cowjog.in", "r", stdin);
    //freopen("cowjog.out", "w", stdout);
    int T;
    T = 1;

#ifndef ONLINE_JUDGE
    time_t time_t1, time_t2;
    time_t1 = clock();
#endif

    //cin>>T;
    while(T--)
    solve(T);

#ifndef ONLINE_JUDGE
    time_t2 = clock();
    SETF();
    cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
    UNSETF();
#endif

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

map<ll, ll> mp;

ll f(ll x, ll y) {
    auto it = mp.find(y);
    if (it != mp.end()) return it->second;

    if (x >= y) return x - y;

    ll r = y - x;
    if (y % 2) {
        r = min(r, f(x, (y - 1) / 2) + 2);
        r = min(r, f(x, (y + 1) / 2) + 2);
    } else {
        r = min(r, f(x, y / 2) + 1);
    }

    return mp[y] = r;
}

int main() {
    ll x, y;
    cin >> x >> y;

    cout << f(x, y) << endl;

    return 0;
}

//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define REP(i,n) for(int i=0;i<n;i++)
const int N = 2e5+2;
const ll mod = 1e9+7;

map<ll,ll> dp;
map<ll,bool> seen;
ll x,y;

ll solve(ll cur){
	if(seen[cur])
		return dp[cur];

	if(cur<=x){
		seen[cur]=true;
		dp[cur]=abs(cur-x);
		return dp[cur];
	}

	ll ans = cur-x;
	if(cur%2==0)
		ans = min(ans,solve(cur/2)+1);
	else
		ans = min({ans,solve(cur+1)+1,solve(cur-1)+1});

	seen[cur]=true;
	return dp[cur]=ans;

}

int main(){
	fast;
	int tt;
	tt=1;
	while(tt--){
		cin >> x >> y;
		cout<<solve(y)<<"\n";
	}

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //Policy Based Data Structure
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define mk(arr,n,type)  type *arr = new type[n]
#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 int             long long
#define ld              long double
#define nn              '\n'
#define w(t)            cin>>tc; while(tc--)
#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 lb(v,x)         lower_bound(v.begin(),v.end(),x)  //returns address of number equal to or just greater than x ,else it is v.end() (i.e. not found)
#define ub(v,x)         upper_bound(v.begin(),v.end(),x)
#define all(x)          x.begin(), x.end()
#define fill(a, b)      memset(a, b, sizeof(a))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<pii>      vpii;
typedef vector<vi>       vvi;
typedef map<int, int>    mii;
typedef map<char, int>   mci;
typedef map<string, int> msi;
int mpow(int base, int exp);
int lcm(int a, int b);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
vi g[N];
// no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , (sqrt(10^9),3409)
//=======================

void sol()
{
    int i=0, j, k, n,y, z, m,a,b,c,d;
     cin >> a >> b >> c >> d;
     int x=0;
     int e=0;
     int l=mpow(10,9);
      while(a>(d*e))
     {
       a=a+b;
       e=e+c;
        i++;
       if(e*d>=a)
       {
          cout << i;
          x=-1;
          break;
       }
       if(i==l)
       {
         break;
       }
     }
     if(x!=-1)
     {
       cout << -1;
     }

}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    sol();

    return 0;
}

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
        if (exp & 1) result = (result * base) % mod;
        base = (base * base) % mod;
        exp >>= 1;
    }
    return result;
}

int lcm(int a, int b)
{
    int g = __gcd(a, b);
    return a / g * b;
}

void ipgraph(int m) {
    int i, u, v;
    while (m--) {
        cin >> u >> v;
        g[u - 1].pb(v - 1);
        g[v - 1].pb(u - 1);
    }
}

void dfs(int u, int par) {
    for (int v : g[u]) {
        if (v == par) continue;
        dfs(v, u);
    }
}

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

bool LOCAL_TEST = false;
int h[30][30],v[30][30];
double priority[30][30];
vector<string> paths;
map<int,char> mp;

inline void InitRand(){
    srand((unsigned int)time(NULL));
}

void read_s_t_a_e(){
    int si,sj,ti,tj,a;
    double e;
    cin>>si>>sj>>ti>>tj>>a>>e;
    string path;
    if(si<=ti) rep(j,ti-si) path+='D';
    else rep(j,si-ti) path+='U';
    if(sj<=tj) rep(j,tj-sj) path+='R';
    else rep(i,sj-tj) path+='L';
    paths.push_back(path);
}

void move(int si,int sj,int ti,int tj,string& path){
    int y=si,x=sj;
    while(y!=ti||x!=tj){
        if(y==ti){
            rep(i,abs(tj-x)) path+=mp[1];
            break;
        }
        else if(x==tj){
            rep(i,abs(ti-y)) path+=mp[0];
            break;
        }
        int next=rand()%2;
        path+=mp[next];
        if(next==0){
            if(y<ti) y++;
            else y--;
        }else{
            if(x<tj) x++;
            else x--;
        }
    }
}

void read_s_t(){
    int si,sj,ti,tj;
    cin>>si>>sj>>ti>>tj;
    string path;
    if(si<=ti) mp[0]='D';
    else mp[0]='U';
    if(sj<=tj) mp[1]='R';
    else mp[1]='L';
    move(si,sj,ti,tj,path);
    cout<<path<<endl;
    flush(cout);
    int a;
    cin>>a;
}

int main(){
    rep(i,30) fill(priority[i],priority[i]+30,-1);
    if(LOCAL_TEST){
        rep(i,30) rep(j,29) cin>>h[i][j];
        rep(i,29) rep(j,30) cin>>v[i][j];
    }
    rep(k,1000){
        if(LOCAL_TEST) read_s_t_a_e();
        else read_s_t();
    }
    if(LOCAL_TEST){
        ofstream output("out.txt");
        rep(k,1000) output<<paths[k]<<'\n';
    }
}


// coded by zeffy
#pragma GCC optimize("O3","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zeroupper") //Enable AVX
#pragma GCC target("avx","popcnt")  //Enable AVX
#include <x86intrin.h> //SSE Extensions
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mp make_pair
#define hello cout<<"hello"<<"\n"
#define forr(i,a,b) for(int i=a;i<b;i++)
#define it(s)	for(auto itr:s)
#define dvg(s) 	for(auto itr:s)	cout<<itr<<" ";cout<<endl;
#define dbg(s)	cout<<#s<<"= "<<s<<endl;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF=(lli)1e17+5;
const ulli MOD=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout<< std::fixed;
    std::cout.precision(6);

  	string s;
	cin>>s;
	forr(i,1,s.size()) cout<<s[i];
	cout<<s[0];

    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  int L;
  cin >> L;
  L = L - 1;
  ll div = 11*10*9*8*7*6*5*4*3*2;
  ll ans = L;
  for(int i=1;i<11;i++){
    ans = ans*(L-i)/(i+1);
    //cout << ans << endl;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i,n) rep(i,1,n)
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const ll INF = 1e15;

// char buf[size],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
TP void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
TP void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar('\n');
}

// math
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll power(ll a, ll b = mod - 2, ll p = mod) {
    ll c = 1;
    while (b) {
        if (b & 1)
            c = c * a % p;
        b /= 2;
        a = a * a % p;
    }
    return c;
}

TP void cmax(o& x, o y) {
    if (x < y)
        x = y;
}
TP void cmin(o& x, o y) {
    if (x > y)
        x = y;
}
TPP void ad(t1& x, t2 y) {
    x += y;
    if (x >= mod)
        x -= mod;
}
TPP void dl(t1& x, t2 y) {
    x -= y;
    if (x < 0)
        x += mod;
}

template<typename T>
struct BIT {
	T* c; int n; // require you to define 0 as the initial value !!
	BIT(int _n):n(_n){c=new T[n];c--; FOR(i,n) c[i]=T(0); }
	void add(int x,T y) { for( ;x<=n;x += x&-x) c[x]=c[x]+y; }
	T sum(int x) {T y=T(0); for( ;x;x &= x-1) y=y+c[x]; return y;}
};

// dbinom
ll jc[N], inv[N];
void jc_init(int n) {
    jc[0] = 1;
    for (int i = 1; i <= n; i++)
        jc[i] = jc[i - 1] * i % mod;
    inv[n] = power(jc[n]);
    for (int i = n; i; i--)
        inv[i - 1] = inv[i] * i % mod;
}
ll C(int x, int y) {
    if (x < y || y < 0)
        return 0;
    return jc[x] * inv[y] % mod * inv[x - y] % mod;
}

int n,cnt[1100];

void solve() {
	qr(n);
	FOR(i,n) {
		int x; qr(x);
		for(int j=2;j*j<=x;j++)
			if(x%j==0) {
				cnt[j]++;
				while(x%j==0) x /= j;
			}
		cnt[x]++;
	}
	pr2(max_element(cnt+2,cnt+1001)-cnt);
}

int main() {
    int T = 1;
//    qr(T);
    while (T--)
        solve();
    return 0;
}

 #include <bits/stdc++.h>
#define ll         long long int
#define pb         push_back
#define umap       unordered_map
#define mod        998244353
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes
//__builtin_ctz(x)      to count the number of trailing zeroes
//__gcd(a,b)
using namespace std;
/*ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=((result%M) * (x%M))%M;
        x=((x%M)*(x%M))%M;
        n=n/2;
    }
    return result;
}
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll pow1(ll x,ll y)
{
    ll z=1;
    while(y--){z=z*x;}
    return z;
}
bool isprime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}*/
ll check(ll x)
{
    ll y=1,z=0;
    while(x>y){y*=2;z++;}
    if(x!=y){z--;}
    return z;
}
ll nCrModp(ll n, ll r, ll p)
{
    // Optimization for the cases when r is large
    if (r > n - r)
        r = n - r;

    // The array C is going to store last row of
    // pascal triangle at the end. And last entry
    // of last row is nCr
    ll C[r + 1];
    memset(C, 0, sizeof(C));

    C[0] = 1; // Top row of Pascal Triangle

    // One by constructs remaining rows of Pascal
    // Triangle from top to bottom
    for (ll i = 1; i <= n; i++) {

        // Fill entries of current row using previous
        // row values
        for (ll j = min(i, r); j > 0; j--)

            // nCj = (n-1)Cj + (n-1)C(j-1);
            C[j] = (C[j] + C[j - 1]) % p;
    }
    return C[r];
}
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int  n;cin>>n;
  string s;cin>>s;
  map <pair<ll,ll>,ll> mp;
  vector <ll> diffA(n,0),diffG(n,0);
  ll num=0;
  f(i,n)
    {
        if(i==0)
        {
        if(s[i]=='A')      diffA[i]=1;
        else if(s[i]=='T') diffA[i]=-1;
        else if(s[i]=='G') diffG[i]=1;
        else               diffG[i]=-1;
        }
        else
        {
        if(s[i]=='A')      {diffA[i]=1+diffA[i-1];diffG[i]=diffG[i-1];}
        else if(s[i]=='T') {diffA[i]=diffA[i-1]-1;diffG[i]=diffG[i-1];}
        else if(s[i]=='G') {diffG[i]=1+diffG[i-1];diffA[i]=diffA[i-1];}
        else               {diffG[i]=diffG[i-1]-1;diffA[i]=diffA[i-1];}
        }
        if(diffA[i]==0 && diffG[i]==0) num++;
        mp[{diffA[i]+diffG[i],diffA[i]-diffG[i]}]++;
    }
  f(i,n)
    {
        ll x=diffA[i]+diffG[i],y=diffA[i]-diffG[i];
        mp[{x,y}]--;
        if(mp[{x,y}]>0) num+=mp[{x,y}];
    }
    cout<<num;
}


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

const int maxl=3e5+10;
const int mod=1e9+7;

int n,m,k,cnt,tot,cas,ans;
int a[maxl];
bool vis[maxl];
char s[maxl];

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

inline ll c(ll n,ll r)
{
	if(r>n || r<0) return 0;
	ll fz=1,fm=1;
	for(int i=1;i<=r;i++)
		fz=fz*(n-i+1)%mod,fm=fm*i%mod;
	return fz*qp(fm,mod-2)%mod;
}

inline void prework()
{
	ll sum=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),sum+=a[i];
	printf("%lld\n",c(n+m,sum+n));
}

inline void mainwork()
{

}

inline void print()
{

}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

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

// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

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

    mint res = 1;
    for (long long r = 0; r < N+S; ++r) {
        res *= N + M - r;
        res /= N + S - r;
    }
    cout << res << endl;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

template<typename T>
void pop_front(vector<T>& vec)
{
    assert(!vec.empty());
    vec.erase(vec.begin());
}

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ---------------------------------------------------
int p[N];
stack<string> answers;

int find(int u){
	if(p[u]==u) return u;
	return p[u] = find(p[u]);
}

bool bubleSort(vector<int> v, int n){

  int ans = 0;
  int m = (n * (n -1)) / 2;
  rep(i, 0, n-1){

    rep(j, 0, n-2){

      if(v[j] > v[j + 1]){

		  swap(v[j], v[j + 1]);
		  ans++;

		}

	 }

  }
  if(ans < m) return true;
  else return false;

}

int n;

bool isPalinadrome(string str){

	  if(str.size() == 1) return true;
	  rep(i, 0, (str.size() / 2) - 1 ) {

	    if(str[i] == str[str.size() - i - 1]) continue;
	    return false;

	  }

	  return true;

}

ll fact(ll n) {

  if(n == 0 || n == 1 ) return 1;
  else return (n * fact(n-1)) % mod;

}

signed main()
{

	ios_base::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;
	int a2 = fastpow(a, 2, mod);
	int b2 = fastpow(b, 2, mod);
	int c2 = fastpow(c, 2, mod);
	int sum = a2 + b2;
	if(sum < c2) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a*a + b*b < c*c) puts("Yes");
	else puts("No");
	return 0;
}


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

#define REP(i, n) for(int(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int(i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int(i) = (n); (i) < (m); ++(i))

// clang-format off
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; }
// clang-format on
constexpr int INF = 1e9;

class Timer {
  chrono::time_point<chrono::system_clock> start;

public:
  Timer() { start = chrono::system_clock::now(); }
  double duration() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
    // return chrono::duration<chrono::milliseconds>(chrono::system_clock::now()- start).count();
  }
};
class xorShift {
  uint32_t x, y, z, w;
  static const double TO_DOUBLE;

public:
  xorShift() {
    x = 123456789;
    y = 362436069;
    z = 521288629;
    w = 88675123;
  }
  xorShift(uint32_t seed) {
    x = seed = 1812433253u * (seed ^ (seed >> 30));
    y = seed = 1812433253u * (seed ^ (seed >> 30)) + 1;
    z = seed = 1812433253u * (seed ^ (seed >> 30)) + 2;
    w = seed = 1812433253u * (seed ^ (seed >> 30)) + 3;
  }
  uint32_t nextInt(uint32_t n) {
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return w % n;
  }
  uint32_t nextInt() {
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  }
  double nextDouble() { return nextInt() * TO_DOUBLE; }
};
const double xorShift::TO_DOUBLE = 1.0 / (1LL << 32);

Timer T;
xorShift rnd;
constexpr double TIME_LIMIT = 1800;
constexpr int N = 20;
int M;
vector<string> s;
vector<string> using_s;

bool internal_string(const string& word, const vector<string> strings) {
  int n = word.size();
  REP(i, (int)strings.size()) {
    int m = strings[i].size();
    for(int j = 0; j + n <= m; j++) {
      if(word == strings[i].substr(j)) {
        return true;
      }
    }
  }
  return false;
}
void select_using_s(const vector<string>& origin, vector<string>& out) {
  int n = origin.size();
  out.push_back(origin[0]);
  FOR(i, 1, n) {
    if(!internal_string(origin[i], out)) {
      out.push_back(origin[i]);
    }
  }
}
struct Solver {
  vector<string> ans, best_ans;
  int best_score;
  Solver() : ans(N), best_ans(N), best_score(0) {}
  void first_method() {
    string all_string;
    REP(i, (int)using_s.size()) { all_string += using_s[i]; }
    REP(i, N) {
      string line;
      REP(j, N) {
        if(i * N + j < (int)all_string.size()) {
          line += all_string[i * N + j];
        }
        else {
          line += ".";
        }
      }
      best_ans[i] = line;
    }
  }
  // void random_select() {
  //   vector<int> st;
  //   REP(i, (int)using_s.size()) { st.push_back(i); }
  //   string all_string;
  //   REP(i, (int)using_s.size()) {
  //     int id = rnd.nextInt((int)st.size());
  //     all_string += st[id];
  //     st.erase(st.begin() + id);
  //   }
  //   REP(i, N) {
  //     REP(j, N) {
  //       int id = i * N + j;
  //       if(id <
  //     }
  //   }
  // }
  void print_best_ans() {
    REP(i, N) { cout << best_ans[i] << endl; }
  }
};

int main() {
  int n;
  cin >> n >> M;
  s.resize(M);
  REP(i, M) { cin >> s[i]; }
  Solver solver;
  sort(s.begin(), s.end(), [](const string& l, const string& r) -> bool {
    if(l.size() == r.size()) {
      return l < r;
    }
    return l.size() > r.size();
  });
  select_using_s(s, using_s);
  solver.first_method();
  solver.print_best_ans();
  return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

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

char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}

void operator delete (void *ptr) { }

int power(int a,int b)
{
    int ans=1;

    while(b)
    {
        if(inf/ans<5) return 5;
        if(b&1) ans*=a;

        if(inf/a<a) return 5;
        a*=a;
        b>>=1;
    }

    return ans;

}

void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int dfs(int cur,vector<int> v[],int used[],int ar[])
{
    if(used[cur]) return 0;

    used[cur]=1;

    int ret=ar[cur];

    for(int kid: v[cur])
    {
        ret+=dfs(kid,v,used,ar);
    }

    return ret;
}

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

    if(n!=1&&(m<0||m>=n-1))
    {
        cout<<-1;
        return;
    }

    int req=m+1;

    //if(m<)
    int start= 1e6;
    int i=0;
    for(;i<req;i++)
    {
        cout<<start<<" "<<start+1<<endl;
        start+=2;
    }

    for(int l=1;i<n;i++,l++)
    {
        cout<<l<<" "<<100000000-l<<endl;
    }
}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


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

int main() {
    int N;
    int64_t ans = -1;
    cin >> N;
    vector<vector<int64_t>> v(N, vector<int64_t>(3));
    rep(i, N) {
        rep(j, 3) cin >> v.at(i).at(j);
        v.at(i).at(0) *= 2;
        if(v.at(i).at(0) < 2*v.at(i).at(2)-1) {
            if(ans == -1) ans = v.at(i).at(1);
            else ans = min(ans, v.at(i).at(1));
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define repc(i, l, n, d) for (int64_t i = l; i < n; i+=d)
#define repc2(i, l, n, d) for (int64_t i = l; i <= n; i+=d)
#define repi(a, b) for (auto&(a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Sort_pair(x, p) sort(ALL(x), (p))
#define mp(a, b) make_pair((a), (b))
#define Push_back(a, b) push_back( mp( (a), (b) ) )
#define ctoi(c) (c)-'0'

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

const int inf = 0x3fffffff;
const int64_t INF = 0x3fffffffffffffff;
const int64_t MOD = 1e9+7;

vector<int64_t> enum_div(int64_t n) {
    vector<int64_t> ret;
    for(int64_t i = 1; i*i <= n; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

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

    std::vector<int64_t> v = enum_div(2*n);
    int64_t ans = 0;
    rep(i, v.size()) {
        int64_t num = (2*n/v[i])-(v[i]-1);
        if (num%2 == 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define REPA(i,j) for(int i=1;i<=j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int INF=1<<30;
inline void read(int &x){
//	short neg=1;
	x=0;
	char c=getchar();
	/*while(c<'0'||c>'9'){
		if(c=='-')neg=-1;
		c=getchar();
	}*/
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+(c^48),c=getchar();
	}
//	x*=neg;
}
int n;
int a[10010];
int dp[10010][10010];
int main(void){
	read(n);
	int ans=0;
	REP(i,n){
		read(a[i]);
		dp[i][i]=a[i];
		ans=max(ans,a[i]);
	}
	for(int l=1;l<n;l++){
		for(int i=0;i+l<n;i++){
			dp[i][i+l]=min(dp[i][i+l-1],a[i+l]);
			ans=max(ans,dp[i][i+l]*(l+1));
		}
	}
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(v) int((v).size())
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 1; i <= int(n); ++i)
//출처: https://codeforces.com/blog/entry/68809
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#define int ll

const int MOD = 998244353;
int power(int a, int n) {
    int res = 1;
    for (;n; n >>= 1, a = (a * a) % MOD)
        if (n & 1) res = (res * a) % MOD;
    return res;
}
void add(int& a, int b){a = (a%MOD + b%MOD)%MOD;}
int h, w, k;
char grid[5050][5050];
int dp[5050][5050][4];
int f(char c)
{
    return c == 'R'? 2 : (c== 'D');
}
void solve()
{
    cin>>h>>w>>k;
    forn(_, k)
    {
        int a, b; char c; cin>>a>>b>>c;
        grid[a][b] = c;
    }
    int r = h*w - k;

    if (grid[1][1]) dp[1][1][f(grid[1][1])] = power(3, r);
    else dp[1][1][3] = power(3, r);

    int p3 = power(3, MOD - 2);
    forn(i, h) forn(j, w)
    {
        if (grid[i+1][j])
        {
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][f('D')]);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][f('X')]);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][3] * p3);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][3] * p3);
        }
        else
        {
            add(dp[i + 1][j][3], dp[i][j][f('D')]);
            add(dp[i + 1][j][3], dp[i][j][f('X')]);
            add(dp[i + 1][j][3], dp[i][j][3] * p3);
            add(dp[i + 1][j][3], dp[i][j][3] * p3);
        }
        if (grid[i][j+1])
        {
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][f('R')]);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][f('X')]);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][3] * p3);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][3] * p3);
        }
        else
        {
            add(dp[i][j + 1][3], dp[i][j][f('R')]);
            add(dp[i][j + 1][3], dp[i][j][f('X')]);
            add(dp[i][j + 1][3], dp[i][j][3] * p3);
            add(dp[i][j + 1][3], dp[i][j][3] * p3);
        }
        // for (int k = 0; k < 4; ++k) debug(i, j, k, dp[i][j][k]);
    }

    if (grid[h][w]) cout << dp[h][w][f(grid[h][w])] << '\n';
    else cout << dp[h][w][3] << '\n';
}
signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int T = 1; //cin >> T;
    while (T--) solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,ans;
bool f[30][30];
void dfs(int x,int y,int z)
{
	if(y==m+1)
	{
		x++;
		y=1;
	}
	if(z==a)
	{
		ans++;
		return;
	}
	if(x==n+1)
	    return;
	if(f[x][y])
	    dfs(x,y+1,z);
	else
	{
		if(!f[x][y+1]&&y+1<=m)
		{
			f[x][y+1]=true;
		    dfs(x,y+2,z+1);
		    f[x][y+1]=false;
		}
		if(!f[x+1][y]&&x+1<=n)
		{
		    f[x+1][y]=true;
		    dfs(x,y+1,z+1);
		    f[x+1][y]=false;
		}
		dfs(x,y+1,z);
	}
}
int main()
{

	scanf("%d%d%d%d",&n,&m,&a,&b);
	dfs(1,1,0);
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int N = 1e6 + 7;
const long long mod = 1e9 + 7;

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

int n,m;
int a,b;
int c[20];
ll d[(1 << 16)];
ll nd[(1 << 16)];

bool good(int x, int y)
{
    int cnt = 0;
    for(int i = 0; i < m; i++){
        int x1 = ((x >> i) & 1);
        int y1 = ((y >> i) & 1);
        if(y1 == 0){
            if(cnt)return false;
        }
        if(x1 == 0 && y1 == 0)return false;
        if(x1 == 0){
            if(cnt)return false;
        }else if(y1 == 1){
            cnt ^= 1;
        }
    }
    if(cnt)return false;
    return true;
}

void solve()
{
    cin >> n >> m >> a >> b;
    if(n < m)swap(n, m);
    int x = n * m;
    ll ans = 0;
    for(int i = 0; i < (1 << x); i++){
        if(__builtin_popcount(i) != b)continue;
        for(int j = 0; j < n; j++)c[j] = 0;
        for(int j = 0; j < x; j++){
            if(((i >> j) & 1)){
                c[j / m] |= (1 << j % m);
            }
        }
        for(int j = 0; j < (1 << m); j++)nd[j] = d[j] = 0;
        nd[(1 << m) - 1] = 1;
        for(int j = 0; j < n; j++){
            for(int h = 0; h < (1 << m); h++ ){
                if(j > 0 && (h & c[j - 1]) != c[j - 1])continue;
                for(int g = 0; g < (1 << m); g++){
                    if((g & c[j]) != c[j])continue;
                    int nh = h;
                    int ng = (g ^ c[j]);
                    if(good(nh, ng)){
                        d[g] += nd[h];
                    }
                }
            }
            for(int h = 0; h < (1 << m); h++){
                nd[h] = d[h];
                d[h] = 0;
            }
        }
       ans += nd[(1 << m) - 1];
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

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


#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define endl '\n'
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl;
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#else
#define dbg(...)
#define dbgmap(...)
#define dbgset(...)
#define dbgarr(...)
#define dbgdp(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

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

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    ll h,w;
    cin>>h>>w;
    VV g(h,Vec(w));
    cin>>g;

    ll ma = INF;
    rep(i,h){
        rep(j,w){
            chmin(ma, g[i][j]);
        }
    }
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            ans += g[i][j] - ma;
        }
    }
    out(ans);
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
//    ll T;
//    cin>>T;
//    while(T--)
    solve();
}

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

const int maxl=3e5+10;

int n,m,k,tot,cnt;
int a[maxl];ll b[maxl],ans[maxl];
char s[maxl];
bool vis[maxl];

inline void add(int i,int x)
{
	while(i<=n)
		b[i]+=x,i+=i&-i;
}

inline ll sum(int i)
{
	ll ret=0;
	while(i)
		ret+=b[i],i-=i&-i;
	return ret;
}

inline void prework()
{
	scanf("%d",&n);
	ll now=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]),a[i]++;
		now+=sum(n)-sum(a[i]);
		add(a[i],1);
	}
	ans[0]=now;
	for(int i=1;i<=n-1;i++)
	{
		now-=sum(a[i]-1);
		add(a[i],-1);
		now+=sum(n)-sum(a[i]);
		add(a[i],1);
		ans[i]=now;
	}
	for(int i=0;i<n;i++)
		printf("%lld\n",ans[i]);
}

inline void mainwork()
{

}

inline void print()
{

}

int main()
{
	int t=1;
	//scanf("%d",&t);
	while(t--)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}


#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define fi first
#define se second

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>
#define VPLL vector<pair<ll,ll>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*.....................USUFUL FUNCTIONS ......................*/
ll cmin(ll a,ll b){
    if(a<b) return a;
    else return b;
}
ll cmax(ll a,ll b){
    if(a>b) return a;
    else return b;
}

/*..................DEFINE GLOBAL VARIABLES...................*/

/*.....................DEFINE FUNCTIONS ......................*/

/*.........................kemkemG0...........................*/
int main() {

	int N;

	int A[1010],B[1010];
	cin>>N;
	PII V[1010];
	PII W[1010];

	REP(i,N){
	    cin>>A[i]>>B[i];
	    V[i]=PII(A[i],i);
	    W[i]=PII(B[i],i);
	}
	sort(V,V+N);
	sort(W,W+N);

	if(V[0].second!=W[0].second){
	    cout<<max(V[0].first,W[0].first);
	}else{
	    int a=V[0].first+W[0].first;
	    int b=max(V[0].first,W[1].first);
	    int c=max(V[1].first,W[0].first);
	    cout<<min(a,min(b,c));
	}

}

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

int a[3];

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    For(i, 3) cin >> a[i];
    sort(a,a+3);
    if(a[2] - a[1] == a[1] - a[0]) cout << "Yes";
    else cout << "No";
}


#include <bits/stdc++.h>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#define loop(i,a,b) for (int i = (a); i <= (b); i++)
#define loopr(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define mod 1000000007
#define mod1 998244353
using namespace std;

bool decToOctal(int n)
{

    // array to store octal number
    int octalNum[100];

    // counter for octal number array
    int i = 0;
    while (n != 0) {

        // storing remainder in octal array
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }

 	int ok = 0;
    // printing octal number array in reverse order
    for (int j = i - 1; j >= 0; j--)
    {
		if(octalNum[j]==7)
		{
			ok = 1;
			break;
		}
	}
	if(ok)
	{
		return false;
	}
	else
	{
		return true;
	}
}

int main()
{
	int n;
	cin>>n;
	int ans = 0;
	loop(i,1,n)
	{
	int x = 0;
	string s = to_string(i);
	x = count(s.begin(),s.end(),'7');
	if(x==0 and decToOctal(i)==true)
	{
		ans++;
	}
	}
	cout<<ans;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define FOR(i, a) for(int i = 0; i < (a); ++i)
#define rrep(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define ft first
#define sd second
#define pb push_back
#define endl '\n'

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

const ll MOD = 1000000007;

void solve(){
    int n;cin>>n;
    int t[n];
    double r[n],l[n];
    rep(i,0,n) {
        cin>>t[i]>>l[i]>>r[i];
        if (t[i]==2) r[i]-=0.01;
        else if (t[i]==3) l[i]+=0.01;
        else if (t[i]==4) {
            l[i]+=0.01;
            r[i]-=0.01;
        }
    }
    int ans(0);
    rep(i,0,n){
        rep(j,i+1,n){
            if (l[i]>r[j] || r[i]<l[j]){
                //cout<<l[i]<<" "<<r[i]<<" "<<l[j]<<" "<<r[j]<<endl;
                continue;
            }
            else {
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t(1);//cin>>t;
    while (t--){
        solve();
    }
	return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
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; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 100010;

signed main() {
    IOS;
    string S;
    cin >> S;
    REP(i, int(S.length())) {
        if(i % 2) {
            if(S[i] >= 'a' && S[i] <= 'z') {
                print("No");
                return 0;
            }
        }
        else {
            if(S[i] >= 'A' && S[i] <= 'Z') {
                print("No");
                return 0;
            }
        }
    }
    print("Yes");

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,m,n) for (int i = (m); i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; --i)
#define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

void pv(vec v) {
  for (int e : v) {
    cout << e << " ";
  }
  cout << endl;
}

void dfs(vector<vec> &dis, vec &is, vec &os, vector<vec> &tree, int v, int d, int &now) {
  is[v] = now;
  dis[d].push_back(now);
  now++;
  for (int w : tree[v]) {
    dfs(dis, is, os, tree, w, d+1, now);
  }
  os[v] = now;
  now++;
}

int main() {
  int n; cin >> n;
  vector<vec> tree(n);
  vector<vec> dis(n);
  vec is(n), os(n);
  rep(i,n-1) {
    int p; cin >> p; p--;
    tree[p].push_back(i+1);
  }

  int now = 0;
  dfs(dis, is, os, tree, 0, 0, now);

  for (vec &di : dis) {
    sort(all(di));
  }

  int q; cin >> q;
  rep(i, q) {
    int u, d; cin >> u >> d; u--;
    vec &di = dis[d];
    cout << lower_bound(all(di), os[u]) - lower_bound(all(di), is[u]) << endl;
  }
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

template<typename A, typename B>
bool chmin(A &a, const B b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template<typename A, typename B>
bool chmax(A &a, const B b) {
  if (a >= b) return false;
  a = b;
  return true;
}

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

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

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 300010;

int A[SIZE];
int counter[SIZE];

int main() {
  int N, K;

  scanf("%d%d", &N, &K);

  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    counter[A[i]]++;
  }

  int now = K, prev;
  ll ans = 0;

  for (int i = 0; i <= N; i++) {
    prev = now;
    chmin(now, counter[i]);
    ans += (prev - now) * i;
  }

  cout << ans << endl;

  return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll n,k;
	cin>>n>>k;
	int a[n];
	int mp[n+1]={0};
	int maxi=0;
	rep(i,n){
		cin>>a[i];
		mp[a[i]]++;
		maxi=max(maxi,a[i]);
	}
	ll ans=0;
	mp[maxi+1]=0;
	for(ll x=0;x<=n;x++){
		ll f=mp[x];
		ll can=min(f,k);
		ans+=(k-can)*x;
		k=can;
	}
	cout<<ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


// atcoder/abc190/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n, m;
  while (cin >> n >> m) {
    vec<int> g[n];
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
      g[b].push_back(a);
    }

    int k;
    cin >> k;
    vec<int> c(k);
    cin >> c;
    each (i, c) --i;

    const int K = 17 + 1;
    const int N = 1e5 + 5;
    static int d[K][N];
    const int inf = 1 << 28;
    fill(&d[0][0], &d[K - 1][N - 1], inf);

    for (int i = 0; i < k; ++i) {
      const int src = c[i];
      queue<int> q;
      d[i][src] = 0;
      for (q.push(src); q.size(); q.pop()) {
        int curr = q.front();
        each (next, g[curr]) {
          if (d[i][next] == inf) {
            d[i][next] = d[i][curr] + 1;
            q.push(next);
          }
        }
      }
    }

    const int BIT = 1 << K;
    static int dp[BIT][K];
    fill(&dp[0][0], &dp[BIT - 1][K - 1] + 1, inf);
    dp[0][0] = 0;
    for (int i = 0; i < k; ++i) {
      dp[1 << i][i] = 1;
    }
    for (int bit = 0; bit < (1 << k); ++bit) {
      for (int i = 0; i < k; ++i) {
        unless (bit & (1 << i)) continue;
        if (dp[bit][i] == inf) continue;
        for (int j = 0; j < k; ++j) {
          if (i != j) {
            setmin(dp[bit | (1 << j)][j], dp[bit][i] + d[i][c[j]]);
          }
        }
      }
    }
    int mn = inf;
    for (int i = 0; i < k; ++i) {
      setmin(mn, dp[(1 << k) - 1][i]);
    }
    cout << (mn == inf ? -1 : mn) << endl;
  }

  return 0;
}

#include <bits/stdc++.h>

#define N 200000
#define MAX 1000000000
#define E 0.00000001
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define LEFT(x) (2 * x)
#define RIGHT(x) (2 * x + 1)
#define PAR 0
#define IMPAR 1

using namespace std;

int n, m;
map<int, vector<int>> columns;
map<pair<int,int>, int> dp;

int getI(int i, int j){

	if(!columns.count(j)) return -1;

	int r = lower_bound(columns[j].begin(), columns[j].end(), i) - columns[j].begin() - 1;

	if(r < 0 or r > columns[j].size()-1){
		return -1;
	}

	return columns[j][r];
}

int solve(int i, int j){

	if(i == -1) return 0;
	if(j == n and i == 0) return 1;

	if(dp.count({i,j})) return dp[{i,j}];

	int left = solve(getI(i, j-1), j-1);
	int right = solve(getI(i, j+1), j+1);

	return dp[{i,j}] = (left or right);
}

int main(){

	scanf("%d %d", &n, &m);

	for(int k = 0; k < m; k++){
		int i, j;
		scanf("%d %d", &i, &j);

		columns[j].push_back(i);
	}

	columns[n].push_back(0);

	for(auto& j : columns){
		sort(j.second.begin(), j.second.end());
	}

	int ans = 0;
	for(auto j : columns){
		ans += solve(j.second.back(), j.first);
	}

	printf("%d\n", ans);

    return 0;

}


// DeNsE - EcLiPsE //
// WHAT is DEAD may NEVER die //

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <set>
#include <cstring>
#include <stack>
#include <sstream>
#include <queue>
#include <unordered_set>
#include <cstdlib>

using namespace std;

#define nitro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define double long double
//#define endl " \n"

const int inf = (1ll << 62) - 1;
const int mod = 998244353;
const int N = 2e5 + 10;
const double pi = 3.14159265358979323846;

int bPow(int a, int b){
    int res = 1;
    while(b) {
        if (b & 1) {
            res = (res * a) % mod;
        }
        b >>= 1;
        a = (a * a) % mod;
    }
    return res % mod;
}

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

}

vector<int> fact(N, 0ll);
void factorial(){
    fact[0] = 1, fact[1] = 1;
    for(int i = 2; i < N; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

int ncr(int n, int r){
    if(r > n)
        return 0;
    int ans = fact[n] % mod;
    ans *= bPow(fact[r], mod - 2) % mod;
    ans %= mod;
    ans *= bPow(fact[n - r], mod - 2) % mod;
    ans %= mod;
    return ans;
}

vector<int> primes(N, -1), factors(N, 2);
void sieve(){
    iota(primes.begin(), primes.end(), 0);
    for (int i = 2; i * i <= N; ++i) {
        if(primes[i] == i){
            for (int j = 2 * i; j < N; j += i) {
                primes[j] = i;
                factors[j]++;
            }
        }
    }
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(2 * n + 1, 0);
    for (int i = 1; i < a.size(); ++i) {
        a[i] = min(i - 1, 2 * n + 1 - i);
    }
    int ans = 0;
    for (int i = 1; i < a.size(); ++i) {
        int ab = i;
        int cd = ab - k;
        if(cd < a.size())
            ans += a[ab] * a[cd];
    }
    cout << ans << endl;
}

signed main(){
    nitro
    int tc = 1, test = 1;
    //cin >> tc;
    while(tc--){
        //cout << "Case #" << test++ << ": ";
        solve();
    }
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

ll f(ll n, ll x)
{
	if (x < 2 || x > 2*n)
		return 0;

	x = min(x, -x + 2*n + 2);
	return x-1;
}

int main()
{
	fastio;

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

	ll res = 0;
	for (ll x = 2; x <= 2 * n; ++x)
	{
		ll y = x - k;
		if (y >= 2)
			res += f(n, x) * f(n, y);
	}
	cout << res << '\n';

	return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}

#define INF 1e9
#define MOD 1000000007

char grid[2001][2001];
int r, c;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

inline bool ok(int x, int y) {
    return x >= 0 && y >= 0 && x < r && y < c;
}

int main() {

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

    cin >> r >> c;
    int sx, sy, tx, ty;
    vv_ii m(30);
    rep(i, 0, r) {
        cin >> grid[i];
        rep(j, 0, c) {
            if (grid[i][j] == 'S')
                sx = i, sy = j;
            else if (grid[i][j] == 'G')
                tx = i, ty = j;
            else if (grid[i][j] != '#') {
                m[grid[i][j]-'a'].push_back({i, j});
            }
        }
    }

    queue<ii> q;
    vvi dist(r, vi(c, INF));
    vvi orig(r, vi(c));
    q.push({sx, sy});
    q.push({tx, ty});
    dist[sx][sy] = dist[tx][ty] = 0;
    orig[sx][sy] = 0;
    orig[tx][ty] = 1;
    int ans = -1;
    while (!q.empty()) {
        auto f = q.front();
        q.pop();
        int ux = f.fi, uy = f.se;
        //if (ux == tx && uy ==  ty)
        //    break;
        rep(k, 0, 4) {
            int vx = ux + dx[k];
            int vy = uy + dy[k];
            if (ok(vx, vy) && grid[vx][vy] != '#') {
                if (dist[vx][vy] == INF) {
                    dist[vx][vy] = 1 + dist[ux][uy];
                    orig[vx][vy] = orig[ux][uy];
                    //if (vx == tx && vy == ty)
                        //goto PRINT;
                    q.push({vx, vy});
                }
                else if (orig[ux][uy] != orig[vx][vy]) {
                    ans = dist[ux][uy] + dist[vx][vy] + 1;
                    goto PRINT;
                }
            }
        }
        if (grid[ux][uy] >= 'a' && grid[ux][uy] <= 'z') {
                for (auto it : m[grid[ux][uy]-'a']) {
                    int vx = it.fi, vy = it.se;
                    if (dist[vx][vy] == INF) {
                        dist[vx][vy] = 1 + dist[ux][uy];
                        orig[vx][vy] = orig[ux][uy];
                        //if (it.fi == tx && it.se == ty)
                            //goto PRINT;
                        q.push({vx, vy});
                    }
                    else if (orig[vx][vy] != orig[ux][uy]) {
                        ans = dist[ux][uy] + dist[vx][vy] + 1;
                        goto PRINT;
                    }
                }
            }
    }
    PRINT:
    cout << ans << '\n';
    /*
    if (dist[tx][ty] == INF)
        cout << -1 << '\n';
    else
        cout << dist[tx][ty] << '\n';
    */
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<P> v(n);
    vector<int> v1(2*n+1,0),v2(2*n+1,0);
    bool flag=0;
    vector<bool> vis(2*n+1,false);
    rep(i,n){
        cin >> v[i].fi >> v[i].se;
        if(v[i].fi!=-1){
            if(vis[v[i].fi])  flag=true;
            vis[v[i].fi]=true;
            v1[v[i].fi]=v[i].se;
            if(v[i].se!=-1){
                if(vis[v[i].se])  flag=true;
                vis[v[i].se]=true;
                v2[v[i].se]=v[i].fi;
            }
        }
        else if(v[i].se!=-1){
            v2[v[i].se]=v[i].fi;
            if(vis[v[i].se])  flag=true;
            vis[v[i].se]=true;
        }
    }
    if(flag){
        cout << "No" << endl;
        return 0;
    }
    vector<bool> dp(n+1,false);
    dp[n]=true;
    for(int i=n-1;i>=0;i--){
        for(int j=i+1;j<=n;j++){
            if(dp[j]==true){
                int d=j-i; //pair number
                bool ok=1;
                for(int k=0;k<d;k++){
                    int ii=2*i+1+k; int jj=ii+d;
                    bool fl=0;
                    if(v1[ii]==jj&&v2[jj]==ii) fl=1;
                    if(v1[ii]==-1&&v2[jj]==0) fl=1;
                    if(v1[ii]==0&&v2[jj]==-1) fl=1;
                    if(v1[ii]==0&&v2[ii]==0&&v1[jj]==0&&v2[jj]==0) fl=1;
                    if(!fl) ok=0;
                }
                //cout << ok << " " << okk << endl;
                if(ok) dp[i]=true;
            }
        }
    }
    //rep(i,n) cout << dp[i] << " ";
    if(dp[0]) cout  << "Yes" << endl;
    else cout << "No" << endl;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

const int mod=1e9+7;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
void ckadd(int&a,int b){a=add(a,b);}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
void cksub(int&a,int b){a=sub(a,b);}
int mul(int a,int b){return (ll)a*b%mod;}
void ckmul(int&a,int b){a=mul(a,b);}
int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;}
int inv(int x){return powmod(x,mod-2);}

const int N=10050;
int F[N],I[N];
int binom(int n, int k){ return mul(F[n],mul(I[k],I[n-k]));}
void calc()
{
	F[0]=1;
	for(int i=1;i<N;i++) F[i]=mul(F[i-1],i);
	I[N-1]=inv(F[N-1]);
	for(int i=N-2;~i;i--) I[i]=mul(I[i+1],i+1);
}

int main(){
	int n=ri();
	calc();
	char AA,AB,BA,BB;
	scanf("\n%c",&AA);
	scanf("\n%c",&AB);
	scanf("\n%c",&BA);
	scanf("\n%c",&BB);
	if(n<=3)return 0*printf("1\n");
	if(AA=='A'&&BB=='B')return 0*printf("1\n");
	if(AA=='B'&&BB=='A'){
		if(AB!=BA)return 0*printf("%i\n",powmod(2,n-3));
		int ans=0;
		for(int ba=0;ba*2<=n-2;ba++){
			int a=n-2-ba*2;
			ckadd(ans,binom(ba+a,a));
		}
		printf("%i\n",ans);
		return 0;
	}
	if(AA=='A'){
		AA='B';
		AB=AB=='A'?'B':'A';
		BA=BA=='A'?'B':'A';
		BB='B';
		//swap(AB,BA);
	}
	//AA -> ABA
	//BB -> BBB
	if(AB=='B'){
		//AB -> ABB
		printf("1\n");
		return 0;
	}else{
		//AB -> AAB
		if(BA=='A'){
			//BA -> BAA
			int ans=0;
			for(int ba=0;ba*2<=n-2;ba++){
				int a=n-2-ba*2;
				ckadd(ans,binom(ba+a,a));
			}
			printf("%i\n",ans);
			return 0;
		}else{
			//BA -> BBA
			int ans=powmod(2,n-3);
			printf("%i\n",ans);
			return 0;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
void YN(bool flag) { cout << (flag ? "YES" : "NO") << endk; }
typedef pair<lint, string> Pa;
typedef pair<lint, plint> tlint;

template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, lint n) {
	ModInt ret = 1;
	while (n > 0) {
		if (n & 1) (ret *= x);
		(x *= x);
		n >>= 1;
	}
	return ret;
}

ModInt func[200000];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
ModInt comb(ModInt n, ModInt r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 1;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}

lint N;
char c[4];
set<string> st;
void dfs(string s) {
	if (SZ(s) == 5) {
		st.insert(s);
		return;
	}
	REP(i, SZ(s) - 1) {
		if (s[i] == 'A' && s[i + 1] == 'A') dfs(s.substr(0, i + 1) + c[0] + s.substr(i + 1, SZ(s) - i - 1));
		if (s[i] == 'A' && s[i + 1] == 'B') dfs(s.substr(0, i + 1) + c[1] + s.substr(i + 1, SZ(s) - i - 1));
		if (s[i] == 'B' && s[i + 1] == 'A') dfs(s.substr(0, i + 1) + c[2] + s.substr(i + 1, SZ(s) - i - 1));
		if (s[i] == 'B' && s[i + 1] == 'B') dfs(s.substr(0, i + 1) + c[3] + s.substr(i + 1, SZ(s) - i - 1));
	}
}
int main() {
	cin >> N;
	REP(i, 4) cin >> c[i];
	dfs("AB");
	if (SZ(st) == 1 || N < 4) {
		cout << 1 << endk;
	}
	else if (SZ(st) == 4 && N >= 4) {
		cout << mod_pow(2, N - 3).a << endk;
	}
	else {
		ModInt dp[10000];
		dp[2] = 1;
		dp[3] = 1;
		REP(i, N) {
			dp[i + 4] = dp[i + 3] + dp[i + 2];
		}
		cout << dp[N].a << endk;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll d=1e9+7;
ll pw(ll x,ll y,ll p){
  if(x==0&&y==0)return 1;
    ll r=1;
    x=x%p;
    if(x==0)return 0;
    while(y>0){
      if(y&1)r=(r*x)%p;
      y=y>>1;x=(x*x)%p;
    }
    return r;
}
int main() {
  //freopen("test.in","r",stdin);cout<<endl<<endl<<endl;
  ll n,p;cin>>n>>p;
  ll c=p-1;ll e=pw(p-2,n-1,d);
  cout<<(c*e)%d<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif
const int MOD=1000000007;
//const int MOD=998244353;
struct ModInt {
  unsigned int val;
  ModInt(): val(0) {}
  ModInt(int v) { norm(v%MOD); }
  ModInt(long long v) { norm(v%MOD); }
  ModInt& norm(long long v) {
    v=v<0?v%MOD+MOD:v; // negative
    v=v>=MOD?v-MOD:v; // mod
    val=(unsigned int)v;
    return *this;
  }
  explicit operator bool() const { return val!=0; }
  ModInt operator-() const { return ModInt(0)-*this; }
  ModInt &operator+=(ModInt that) { return norm((long long)val+that.val); }
  ModInt &operator-=(ModInt that) { return norm((long long)val-that.val); }
  ModInt &operator*=(ModInt that) { val=(unsigned long long)val*that.val%MOD; return *this; }
  ModInt &operator/=(ModInt that) { return *this*=that.inv(); }
  ModInt operator+(ModInt that) const { return ModInt(*this)+=that; }
  ModInt operator-(ModInt that) const { return ModInt(*this)-=that; }
  ModInt operator*(ModInt that) const { return ModInt(*this)*=that; }
  ModInt operator/(ModInt that) const { return ModInt(*this)/=that; }
  ModInt pow(long long n) const {
    ModInt x=*this, res=1;
    while(n>0) {
      if(n&1) res*=x;
      x*=x,n>>=1;
    }
    return res;
  }
  ModInt inv() const { return (*this).pow(MOD-2); }
  bool operator==(ModInt that) const { return val==that.val; }
  bool operator!=(ModInt that) const { return val!=that.val; }
  friend ostream& operator<<(ostream& os, const ModInt& that) { return os<<that.val; }
};
// $ cp-batch NowhereP | diff NowhereP.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address NowhereP.cpp && ./a.out

/*

 4/17/2021

 0:24-

 */

LL N,P;

void solve() {
  auto res=ModInt(P-1)*ModInt(P-2).pow(N-1);
  cout<<res<<endl;
}

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

  cin>>N>>P;
  solve();

  return 0;
}