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

#define ll long long
#define int long long
const int mod = 1e9 + 7;
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
const ll inf = 2e18;

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

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

int add(int a, int b) {
  int res = (a + b) % mod;
  if (res < 0)
    res += mod;
  return res;
}

int mult(int a, int b) {
  int res = (a * 1LL * b) % mod;
  if (res < 0)
    res += mod;
  return res;
}

int power(int a, int b) {
  int res = 1;
  while (b) {
    if ((b % 2) == 1)
      res = mult(res, a);
    a = mult(a, a);
    b /= 2;
  }
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return to_string(string(1, c)); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void dbg() { cout << endl; }
template <typename Head, typename... Tail> void dbg(Head H, Tail... T) {
  cout << " " << to_string(H);
  dbg(T...);
}

#ifdef LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(all(v));
  int total = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (v[i] * i - total);
    total += v[i];
  }
  cout << ans << "\n";
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);

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

  for (int i = 1; i <= t; i++) {
    // cout<<"Case "<<i<<": ";
    solve();
  }
}

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

int main(){
   ll N;cin>>N;
   vector<double>l(N),r(N);
   rep(i,N){
       int t; cin >> t >> l[i] >> r[i];
         t--;
         if(t&1) r[i] -= 0.5;
         if(t&2) l[i] += 0.5;
   }
   ll ans = 0;
   for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if((max(l[i],l[j]) <= min(r[i],r[j]))){
                ans++;
            }
        }
    }
   cout<<ans<<endl;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

void cout_line(vector<int> &a){
    for(int i=0;i<a.size();i++){
        if(i<a.size()-1){
            cout<<a.at(i)<<" ";
        }else{
            cout<<a.at(i)<<endl;
        }
    }
}

signed main(){
    int N; cin>>N;
    vec_int A(N); rep(i,N)cin>>A.at(i);
    int MOD = pow(10, 9) + 7;

    vec_int cumul_A(N+1, 0);
    for(int i=1;i<=N;i++){
        cumul_A.at(i) = cumul_A.at(i-1)+A.at(i-1);
    }

    vector<vec_int> DP(N+1, vec_int(N+1, 0)); // DP.at(i).at(j): j番目の数値までをi個に区切ったときの数
    DP.at(0).at(0) = 1;

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

        vec_int cumul_A2(N+1);
        rep(k,N+1)cumul_A2.at(k) = cumul_A.at(k)%(i+1);
        vector<vec_int> inds(i+1);
        vector<vec_int> cumul(i+1);
        rep(k, i+1)cumul.at(k).push_back(0);
        vec_int start_vec(N+1, 0);
        rep(k,N+1){
            inds.at(cumul_A2.at(k)).push_back(k);
            int sz = inds.at(cumul_A2.at(k)).size();
            start_vec.at(k) = sz-1;
            int prev = cumul.at(cumul_A2.at(k)).at(sz-1);
            cumul.at(cumul_A2.at(k)).push_back(prev + DP.at(i).at(k));
        }

        for(int j=1;j<=N;j++){
            // if(DP.at(i).at(j)==0)continue;
            int from = cumul_A2.at(j);
            int start_ind = start_vec.at(j);
            // cout<<i<<" "<<j<<" "<<from<<" "<<start_ind<<" "<<cumul.at(from).at(start_ind)<<endl;
            DP.at(i+1).at(j) += cumul.at(from).at(start_ind);
            DP.at(i+1).at(j) %= MOD;
            /*
            for(int k=start_ind+1; k<inds.at(from).size();k++){
                DP.at(i+1).at(inds.at(from).at(k)) += DP.at(i).at(j);
                DP.at(i+1).at(inds.at(from).at(k)) %= MOD;
            }
            */
        }
    }
    int ans = 0;
    for(int i=1;i<=N;i++){
        ans += DP.at(i).at(N);
        ans %= MOD;
    }
    cout<<ans<<endl;

    return 0;
}


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

int main(){
  int n;cin>>n;
  vector<ll> ans;
  vector<ll> x(n,0),y(n,0);
  REP(i,n) cin>>x.at(i)>>y.at(i);
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  ans.emplace_back(abs(x.at(0)-x.at(n-1)));
  ans.emplace_back(abs(x.at(1)-x.at(n-1)));
  ans.emplace_back(abs(x.at(0)-x.at(n-2)));
  ans.emplace_back(abs(y.at(0)-y.at(n-1)));
  ans.emplace_back(abs(y.at(1)-y.at(n-1)));
  ans.emplace_back(abs(y.at(0)-y.at(n-2)));
  sort(ans.rbegin(),ans.rend());

  if(ans.at(0)!=ans.at(1)) cout<<ans.at(1)<<endl;
  else{
    int xl,xr,yl,yr;
    if(x.at(0)!=x.at(1) && x.at(n-2)!=x.at(n-1)){
      if(y.at(0)!=y.at(1) && y.at(n-2)!=y.at(n-1)){
        xl=x.at(0);
        xr=x.at(n-1);
        yl=y.at(0);
        yr=y.at(n-1);
        if(xr-xl==yr-yl){
          cout<<ans.at(2)<<endl;
          return 0;
        }
      }
    }
    cout<<ans.at(1)<<endl;
  }
  return 0;
}


//#define DEBUG
#define OPTIMIZE
//#define PBDS
//#define INTERACTIVE

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

const int MAXN = 5000;
const int INF = 0x3f3f3f3f, MOD = 998244353;
const long long LINF = LONG_LONG_MAX;
#define INIT(arr, val) fill(arr, arr+(int)(sizeof(arr)/sizeof(arr[0])), val)
#define REP(i, lb, rb, inc) for(int i = (lb); i < (rb); i += inc)
#define RREP(i, rb, lb, dec) for(int i = (rb)-1; i >= (lb); i -= dec)
typedef long long ll;
typedef queue<int> QI;
typedef vector<int> VI;
#define pb push_back
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define X real()
#define Y imag()
#define ALL(x) x.begin(), x.end()
#define OUT(x) {x; cout<<endl;}

#ifdef DEBUG
#	define dbg(x) x
#else
#	define dbg(x)
#endif

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

#ifdef PBDS
#	include <bits/extc++.h>
	using namespace __gbu_pbds;
#endif

#ifndef INTERACTIVE
#	define endl '\n'
#	define IOS() cin.tie(0); cout.sync_with_stdio(0); cout.tie(0)
#else
int ask(int query) {
	cout << "? " << query << endl;
	int in;
	cin >> in;
	return in;
}
void answer(int ans) {
	cout << "! " << ans << endl;
	exit(0);
}
#endif

#define READ(a, t) t a; cin >> a
#define READARR(arr, n) REP(___i, 0, (n), 1) cin >> arr[___i]
#define PRINTARR(arr, n) { REP(___i, 0, (n), 1) cout << arr[___i] << " "; cout << endl; }

int a[MAXN][MAXN];
int p[MAXN][MAXN];
ll fp[MAXN+1];
ll dp[MAXN][MAXN];

signed main() {
	#ifndef INTERACTIVE
		IOS();
	#endif

	fp[0] = 1;
	REP(i, 1, MAXN+1, 1) fp[i] = (fp[i-1]*3)%MOD;

	READ(r, int); READ(c, int); READ(k, int);
	REP(i, 0, k, 1) {
		int pr, pc; char d;
		cin >> pr >> pc >> d;
		pr--, pc--;
		a[pr][pc] = d=='R'? 1 : d=='D'? 2 : d=='X'? 3 : 0;
	}

	REP(i, 0, r, 1)
		REP(j, 0, c, 1)
			p[i][j] = (i>0?p[i-1][j]:0) + (j>0?p[i][j-1]:0) - (i>0&&j>0 ? p[i-1][j-1]:0) + (a[i][j] == 0);

	dp[0][0] = 1;
	REP(i, 1, r, 1) {
		if (a[i-1][0] & 2) dp[i][0] = dp[i-1][0];
		else if (!a[i-1][0]) dp[i][0] = 2*dp[i-1][0] % MOD;
	}
	REP(j, 1, c, 1) {
		if (a[0][j-1] & 1) dp[0][j] = dp[0][j-1];
		else if (!a[0][j-1]) dp[0][j] = 2*dp[0][j-1] % MOD;
	}

	REP(i, 1, r, 1) {
		REP(j, 1, c, 1) {
			ll cnt;

			cnt = fp[p[i][j-1]-p[i-1][j-1]];
			if (a[i-1][j] & 2) dp[i][j] += dp[i-1][j]*cnt % MOD;
			else if (!a[i-1][j]) dp[i][j] += 2*dp[i-1][j]*cnt % MOD;
			dp[i][j] %= MOD;

			cnt = fp[p[i-1][j]-p[i-1][j-1]];
			if (a[i][j-1] & 1) dp[i][j] += dp[i][j-1]*cnt % MOD;
			else if (!a[i][j-1]) dp[i][j] += 2*dp[i][j-1]*cnt % MOD;
			dp[i][j] %= MOD;
		}
	}
	cout << dp[r-1][c-1]*( !a[r-1][c-1] ? 3:1 ) % MOD << endl;
	dbg(
		REP(i, 0, r, 1) PRINTARR(dp[i], c);
		cout << endl;
		REP(i, 0, r, 1) PRINTARR(p[i], c);
	)
}

#include <bits/stdc++.h>

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
#define ALL(v) v.begin(), v.end()
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void chmaxmin(T &a, const T &b, const T &(*f)(const T &, const T &)){ a = f(a, b); }
#define chmax(a, b) chmaxmin(a, b, std::max)
#define chmin(a, b) chmaxmin(a, b, std::min)

#if __has_include(<experimental/iterator>)
#include <experimental/iterator>
auto debug = std::experimental::make_ostream_joiner(std::cout, " ");
#endif

/* snippet: inf struct */
#if __cplusplus >= 201703
struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::max(); } constexpr auto operator-(); } inf;
struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::lowest(); } constexpr auto operator-(); } negative_inf;
constexpr auto decltype(inf)::operator-(){ return negative_inf; }
constexpr auto decltype(negative_inf)::operator-(){ return inf; }
#endif

/* snippet: modint library */
#if __cpp_concepts
template<std::signed_integral T, T MOD>
#else
template<class T, T MOD>
#endif
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val >= 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* push n numbers and get i-th min */
/* to get min and 2nd min, declare K_th_min<T, 2> and use get<0>(), get<1>() */
#if __cplusplus >= 201703
template<class T, std::size_t K>
class K_th_min{
	friend class K_th_min<T, K + 1>;
	T val;
	K_th_min<T, K - 1> lower;
	void push_(T &x){ lower.push_(x); if(val > x) std::swap(val, x); }
public:
	K_th_min() : val(std::numeric_limits<T>::max()) {}
	void push(T x){ push_(x); }
	template<std::size_t I> T get(){ if constexpr(I == K - 1) return val; else return lower.template get<I>(); }
};
template<class T> class K_th_min<T, 0>{ friend class K_th_min<T, 1>; void push_(T &){} public: K_th_min(){} void push(T){} };
#endif

/* snippet:  */
int fourd[] = {0, 1, 0, -1, 0};
int eightd[] = {0, 1, 1, -1, 0, -1, -1, 1, 0};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int time;
	cin >> time;
	RC(t, time){
		Int n_, a_, b_;
		cin >> n_ >> a_ >> b_;
		if(a_ + b_ > n_){
			cout << 0 << endl;
			continue;
		}
		Mint n(n_), a(a_), b(b_);
		Mint aa = n - a + Mint(1);
		Mint bb = n - b + Mint(1);
		Mint ab = a + b - Mint(1);
		// cout << "aa: " << aa << endl;
		// cout << "bb: " << bb << endl;
		// cout << "ab: " << ab << endl;
		Mint tmp = (a + ab) * b;
		// cout << tmp << endl;
		tmp += ab * (aa - b * Mint(2));
		// cout << tmp << endl;
		tmp *= tmp;
		cout << aa * aa * bb * bb - tmp << endl;
	}
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N;
string S;

void gogo()
{
    cin >> N >> S;

    if (S[0] != S[N-1])
    {
        cout << "1\n";
        return;
    }

    for (int i = 0; i + 1 < N; i++)
    {
        if (S[i] != S[0] && S[i+1] != S[0])
        {
            cout << "2\n";
            return;
        }
    }
    cout << "-1\n";
}

int main()
{
    ios_base::sync_with_stdio(0);

    int T = 1;
    for (int t = 0; t < T; t++)
        gogo();
}

/*/ Author : Abhishek Chauhan /*/

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

// a+b = a^b + 2*(a&b)
// According to Fermat's little theorem, (a^b)%mod = ((a^(b%(mod - 1)))%mod) if mod is a prime number and not the other way round.
// whenever using a comparator return true only if a<b
// make it forward first if it doesnt work do the reverse
// vector a = ax + ay b = bx + by then dot porduct is |a||b|cos@ //and also for eas you can use (ax*bx)+(ay*by);

#define rep(i,n)             for(int i=0;i<n;i++)
#define int                  long long
#define pb                   push_back
#define mp                   make_pair
#define all(x)               x.begin(),x.end()
#define mod                  1000000007
#define bpop(x)              __builtin_popcountll((x))
#define fastio               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl                 '\n'

template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

template<class T>
T power(T x, T y){T res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
template<class T>
T powermod(T x, T y, T p){T res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}

const int N = 20;
vector<int>g[N];
int vis[N],col[N];
vector<int>order;
void get(int node){
  vis[node] = 1;
  order.pb(node);
  for(auto x:g[node]){
    if(vis[x]==0){
      get(x);
    }
  }
}

int recur(int i){
  if(i>=order.size()){
    return 1;
  }
  int res = 0;
  vis[order[i]] = 1;
  vector<int>can(4,1);
  for(auto x:g[order[i]]){
    if(col[x]!=0){
      can[col[x]] = 0;
    }
  }
  for(int c=1;c<4;c++){
    if(can[c]){
      col[order[i]] = c;
      res+=recur(i+1);
      col[order[i]] = 0;
    }
  }
  return res;
}

void snow(){

   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++){
    vis[i] = 0;
    col[i] = 0;
   }
   for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;a--;b--;
    g[a].pb(b);
    g[b].pb(a);
   }
   int ans = 1;
   for(int i=0;i<n;i++){
    if(!vis[i]){
     order.clear();
     get(i);
     col[order[0]] = 1;
     vis[order[0]] = 1;
     if(order.size()==1){
      ans = ans*3;
     }
     else{
      ans=ans*3*recur(1);
     }
    }
   }
   cout<<ans<<endl;
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fastio;
    int _;
    _=1;
    for(int i=1;i<=_;i++){
     // cout<<"Case #"<<i<<": ";
        snow();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(void) {
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    map<ll,ll> g;
    auto r = [&](ll d, ll x) {
        if(g.count(d)) g[d]=__gcd(g[d],x);
        else g[d]=x;
    };
    ll mn = INF;
    REP(_,n) {
        ll x; cin >> x;
        for(ll i=1;i*i<=x;++i) {
            if(x%i==0) r(i,x),r(x/i,x);
        }
        mn = min(mn, x);
    }
    ll ret = 0;
    for(auto i: g) if(i.x<=mn && i.x==i.y) ret++;
    cout << ret << endl;
    return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 4020000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

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

int main(){
    int n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    map<int,vector<int>> mp;
    sort(all(a));
    rep(i,n){
        for(int j=1; j*j<=a[i]; j++){
            if(a[i] % j == 0){
                mp[j].push_back(a[i]);
                if(j != a[i]/j) mp[a[i]/j].push_back(a[i]);
            }
        }
    }
    int ans = 0;
    for(auto x : mp){
        if(x.first > a[0]) break;
        int gc = 0;
        for(auto y : x.second){
            gc = GCD(gc, y);
        }
        if(gc == x.first) ans++;
    }
    cout << ans << "\n";
}


#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

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

  string s;
  cin>>s;
  cout<<s[1]<<s[2]<<s[0]<<endl;

  return 0;
}

#include<cstdio>
using namespace std;
char a,b,c;
int main()
{
	scanf("%c%c%c",&a,&b,&c);
	if(a==b&&b==c) printf("Won");
	else printf("Lost");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define MOD 1000000007
#define all(x) x.begin(), x.end()
#define sze(x) (int) x.size()

int main() {

    double v, s, t, d;
    scanf("%lf %lf %lf %lf", &v, &s, &t, &d);

    if(d/v < s || d/v > t) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
}

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

int main() {
 double a,b,c,d;
 cin >> a >> b >> c >> d;
 double k = (a*d+b*c)/(b+d);
 cout << setprecision(8) << k << endl;
}


#include<bits/stdc++.h>
#define M 200005
typedef long long ll;
using namespace std;
bool f2;
char IO;
ll rd(){
	ll num=0;bool f=0;
	while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=1;
	do num=(num<<1)+(num<<3)+(IO^48);
	while(IO=getchar(),IO>=48&&IO<=57);
	return f?-num:num;
}
int n,m;
struct node{
	int X,Y;
	bool operator<(const node &_)const{
		if(X==_.X)return Y<_.Y;
		return X<_.X;
	}
}A[M];
int B[M];
map<int,int> mp;
int upd[M],del[M],cnt,c;
bool f1;
int main(){
//	cout<<(&f1-&f2)/1024.0/1024.0<<endl;
	n=rd();m=rd();
	for(int i=1;i<=m;++i)
		A[i].X=rd(),A[i].Y=rd();
	sort(A+1,A+m+1);
	mp[n]=1;
	for(int i=1;i<=m;++i){
		if(mp[A[i].Y-1]||mp[A[i].Y+1])
			upd[++cnt]=A[i].Y;
		del[++c]=A[i].Y;
		if(i==m||A[i].X!=A[i+1].X){
			while(c)mp[del[c--]]=0;
			while(cnt)mp[upd[cnt--]]=1;
		}
	}
	int ans=mp[n];mp[n]=0;
	for(int i=1;i<=m;++i){
		ans+=mp[A[i].Y];
		mp[A[i].Y]=0;
	}cout<<ans;
	return 0;
}

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

int main(){
  	int n, m;
  	cin >> n >> m;
  	map<int, vector<int>> mp;
  	rep(i, m){
    	int x, y;
      	cin >> x >> y;
      	mp[x].push_back(y);
    }

  	set<int> s;
  	s.insert(n);
  	for(auto p : mp){
      	vector<int> add;
    	for(int y : p.second){
        	if(s.count(y-1) || s.count(y+1)) add.push_back(y);
        }

        for(int y : p.second) s.erase(y);
        for(int y : add) s.insert(y);
    }

    cout << s.size() << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <sstream>
#define INF 1000000009
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << max(a,b) - min(c,d) << endl;
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    int a,b,c,d,e;
    cin >> a >> b;
    cin >> c >>d;
    e = b-c;
    cout << e;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll MOD=1000000007;
// ll MOD=998244353;
constexpr ll mod=998244353;

void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}

void Mul(int &a, int b) {
  a = 1LL * a * b % MOD;
}

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

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

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m,sum,ans,a[2005];
int ksm(int n,int m){
	if (!m)return 1;
	int s=ksm(n,m>>1);
	s=1LL*s*s%mod;
	if (m&1)s=1LL*s*n%mod;
	return s;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sum+=n;
	m+=n;
	//c(m,sum)
	ans=1;
	for(int i=1;i<=sum;i++)ans=1LL*ans*ksm(i,mod-2)%mod*(m-i+1)%mod;
	printf("%d",ans);
}


#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n;
	cin>>n;
	vector<pair<ll,ll>>v;
	for(ll i=0;i<n;i++)
	{
		ll z,x;
		cin>>z>>x;
		v.push_back({z,x});
	}
	vector<ll>t;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			if(i==j)
			{
				t.push_back(v[i].first+v[i].second);
			}
			else
			{
				t.push_back(max(v[i].first,v[j].second));
				t.push_back(max(v[i].second,v[j].first));
			}
		}
	}
	cout<<*min_element(t.begin(),t.end())<<'\n';
	return 0;
}

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

#define fori(i, start, end) for(int i=start; i<=end; i++)
#define ford(i, start, end) for(int i=start; i>=end; i--)
#define fora(i, iterable) for(auto i=iterable.begin(); i!=iterable.end(); i++)
#define mmset(ds, val) memset(ds, val, sizeof(ds))
#define sortar(arr, len) sort(arr, arr + len)
#define sortds(ds) sort(ds.begin(), ds.end())
#define nl '\n'
#define pb push_back
#define mp make_pair
#define F first
#define S second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set<int> sti;
typedef set<ll> stl;

void solve() {
    int n;
    cin >> n;
    int c[n][2];
    int alone = INT_MAX, a = INT_MAX, b = INT_MAX;
    fori(i, 0, n-1) {
        fori(j, 0, 1) {
            cin >> c[i][j];
        }
        if(i==0) a = c[i][0], b = c[i][1];
        if(a > c[i][0])
            a = c[i][0];
        else
            b = min(b, c[i][1]);
        alone = min(alone, c[i][0] + c[i][1]);
    }
    cout << min(alone, max(a,b)) << nl;
}

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


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

void DBG() { cerr << endl; }
template <class Head, class... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)

using ll = long long;
using ld = long double;

#define INF 0x3f3f3f3f
#define sqr(a) (a) * (a)
#define siz(a) int(a.size())
#define ints(a...) int a; read(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define trav(i, v) for (const auto i : v)
#define Fill(a, b) memset(a, b, sizeof(a))
#define rep(i, b, n) for (auto i = b; i < n; i++)
#define per(i, b, n) for (auto i = b; i >= n; i--)
#define unify(a) sort(all(a)), a.resize(unique(all(a)) - a.begin())

template <class T> using vec = vector<T>;
template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); }
template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); }
template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; }
template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; }
template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; }
template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; }

const int MOD = 1e9 + 7;
const ld PI = acos(-1);

void solve() {
    ints(n);
    vec<ll> a(n); read(a);
    sort(all(a));
    vec<ll> suf(n + 1);
    per(i, n - 1, 0)
        suf[i] = suf[i + 1] + a[i];
    ll res = 0;
    rep(i, 0, n - 1)
        res += abs((n - 1 - i) * a[i] - suf[i + 1]);
    cout << res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
    // setw(), setfill()
    int _ = 1;
    // cin >> _;
    rep(i, 1, _ + 1) {
        // printf("Case %d: ", i);
        // Solution solve;
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()

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

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> arr(n+1);
    arr[0]=-1e18;
    REP(i,n){
        cin>>arr[i+1];
    }
    sort(all(arr));
    vector<ll> pref(n+1,0);
    for(ll i=1;i<=n;i++){
        pref[i]=pref[i-1]+arr[i];
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll x=(i-1)*arr[i];
        ll prex=pref[i-1];
        ll temp=abs(x-prex);
        ans+=temp;
    }
    cout<<ans<<endl;

}


#include <iostream>
#include <vector>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<deque>
#include<math.h>
#include<set>
#include<string>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(ll i = 0;i<n;i++)
#define req(i,n) for(ll i = 1;i<=n;i++)
#define rrep(i,n) for(int i = n-1;i>=0;i--)
#define ALL(a) a.begin(),a.end()
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; }
typedef long long ll;
typedef long double d;
const ll INF = 1<<61;
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int main() {
	int a, b, c; cin >> a >> b >> c; int o = a % 10,ans;
    if (o == 1 || o == 0 || o == 5 || o == 6) ans = a % 10;
    else if (o == 2 || o == 7 || o == 8) {
        int t = mod_pow(b, c, 4);
        if (o == 2) {
            if (t == 0)ans = 6;
            else if (t == 1)ans = 2;
            else if (t == 2)ans = 4;
            else ans = 8;
        }
        else if (o == 7) {
            if (t == 0)ans = 1;
            else if (t == 1)ans = 7;
            else if (t == 2)ans = 9;
            else ans = 3;
        }
        else {
            if (t == 0)ans = 6;
            else if (t == 1)ans = 8;
            else if (t == 2)ans = 4;
            else ans = 2;
        }
    }
    else if (o == 4 || o == 9) {
        int t = mod_pow(b, c, 2);
        if (o == 4) {
            if (t == 0) ans = 6;
            else ans = 4;
        }
        else {
            if (t == 0)ans = 1;
            else ans = 9;
        }
    }
    else {
        int t = mod_pow(b, c, 3);
        if (t == 0) ans = 7;
        else if (t == 1)ans = 3;
        else ans = 9;
    }cout << ans << endl;
}


  #include <bits/stdc++.h>
  #define ll long long int
  #define ull unsigned long long int
  #define eb emplace_back
  using namespace std;
  void vec(vector<int> & v){

      for(int i = 0;i<v.size() ; i++){
          cout<<v[i]<< " ";
      }
      cout<<endl;
  }
  void vec_ll(vector<long long int> & v){

      for(int i = 0;i<v.size() ; i++){
          cout<<v[i]<< " ";
      }
      cout<<endl;
  }
  void vec_ull(vector<ull> & v){

      for(int i = 0;i<v.size() ; i++){
          cout<<v[i]<< " ";
      }
      cout<<endl;
  }
  int parsestring(string temp){
      int num= 0;
      int digs = temp.size() - 1;
      for(int i = 0 ;i<=digs;i++){
          num += pow(10 , digs -i)*(temp[i] - '0');
      }
      return num;
  }
  void factorize(ll n , map<ll , ll>&m){
    for(ll i = 2;i<=(long long)sqrt(n);i++){
      if(n% i == 0){
        while(n%i == 0){
          m[i]++;
          n = n/i;
        }
      }
    }
    if(n > 1){m[n]++;}
  }

  vector<vector<int>>adj , v;
  vector<int>in , out,  h;
  int timer = 1;
void dfs(int root , int depth){
    // cout<<"at "<<root<<endl;
    in[root] = timer;
    h[root] = depth;
    v[depth].eb(in[root]);
    for(int i = 0;i<adj[root].size() ;i++){
        timer++;
        dfs(adj[root][i] ,depth +1 );
    }
    timer++;
    out[root] = timer;
}

  int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      int n;
      cin>>n;
     adj = vector<vector<int>>(n+1);
      for(int i = 2;i<=n;i++){
          int x;
          cin>>x;
          adj[x].eb(i);
      }
      v = vector<vector<int>>(n+1);
      in = out = h = vector<int>(n+1);
      dfs(1 , 0);
    int q;
    cin>>q;
    while(q){
        int u,d;
        cin>>u>>d;
        int temp1 = lower_bound(v[d].begin()  ,v[d].end() , in[u]) - v[d].begin();
        int temp2= lower_bound(v[d].begin() , v[d].end() , out[u]) - v[d].begin();
        // cout<<"temp "<<temp1<< " " <<temp2<<endl;
        if(temp1 < temp2){
            cout<< temp2- temp1<<endl;
        }
        else{cout<<0<<endl;}
        q--;
    }
  }

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

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; // comb(10000007); // ←MOD-1が上限
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    // parallel world (projection)
    int T;
    cin >> T;
    rep(i, T) {
        int N, A, B;
        scanf("%d %d %d", &N, &A, &B);
        if (A + B > N) {
            cout << 0 << '\n';
            continue;
        }
        // 辺で考えて重ならない方法をまず求める、(N-A-B+2)C2
        mint x = mint(N-A-B+2) * (N-A-B+1) / 2 * 2;
        mint y = mint(N-A+1) * (N-B+1) - x;
        mint ans = mint(N-A+1).pow(2) * mint(N-B+1).pow(2);
        ans -= y.pow(2);
        printf("%lld\n", ans.x);
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    ll n, s, d;
    cin >> n >> s >> d;
    vector<ll> a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    ll total = 0;
    rep(i, n){
        if(a[i] < s && b[i] > d){
            total += b[i];
        }
    }
    if(total > 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

#define INF 1234567890
#define ll long long

int N, S, D;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> S >> D;
	for(int i=1; i<=N; i++)
	{
		int x, y;
		cin >> x >> y;
		if (x >= S || y <= D) continue;
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}


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

const ll INF = 1LL << 60;

int main()
{
    ll n;
    cin >> n;
    ll ans = n + 1;

    ll tmp = 0;
    ll num = 1;
    while (tmp + num <= n + 1)
    {
        ans--;
        tmp += num;
        num++;
    }

    cout << ans << '\n';
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
//inline unsigned long long read()
//{
//	unsigned long long sum=0,nega=1;char ch=getchar();
//	while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
//	while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
//	return sum*nega;
//}
unsigned long long n,res,ans,mid;
int main()
{
	cin>>n;
	res=n*8+9;
	unsigned long long l=0,r=4e9;
	while(l<r)
	{
		mid=(l+r+1)/2;
		if(mid*mid<=res)l=mid;
		else r=mid-1;
	}
	if(l*l<=res)ans=l;
	else ans=r;
	ans=(ans-1)/2;
	cout<<n-ans+1<<endl;
	//cout<<min((sum*2-1)*x,x+)<<endl;
	return 0;
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, c;
	cin >> n >> c;
	vector<pair<int, int>> vp(2 * n);
	for (int i = 0; i < n; ++i)
	{
		int a, b, c1;
		cin >> a >> b >> c1;
		vp[2 * i] = {a, c1};
		vp[2 * i + 1] = {b + 1, -c1};
	}
	sort(vp.begin(), vp.end());
	ll ans = 0;
	int i;
	vector<pair<int, ll>> nvp;
	for (i = 0; i < 2 * n;)
	{
		ll cur = 0;
		int j = i;
		while (j < 2 * n && vp[i].first == vp[j].first)
		{
			cur += vp[j].second;
			++j;
		}
		nvp.push_back({vp[i].first, cur});
		i = j;
	}
	n = nvp.size();
	ll cur = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		cur += nvp[i].second;
		ans += min(cur, (ll)c) * (nvp[i + 1].first - nvp[i].first);
	}
	cout << ans << '\n';
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

void solve() {

    int N; cin >> N;
    ll C; cin >> C;
    map<int, ll> ev;
    F0R(i, N) {
        int A, B; ll C; cin >> A >> B >> C;
        ev[A]+=C;
        ev[B+1]-=C;
    }

    ll sum = 0;
    ll ans = 0;
    trav(a, ev) {
        sum += a.s;
        auto it = ev.ub(a.f);
        if (it != ev.end()) {
            ans += min(sum, C) * (it->f - a.f);
        }
    }
    cout << ans << nl;

}

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

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

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <vector>
#include <list>
#include <cmath>
#include <map>
#include <deque>
#include <utility>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <string>
#include <stack>
#include <set>
#include <functional>
#include <iterator>
#include <algorithm>

using namespace std;

typedef long long ll;

class UnionFind {
private:
    vector<int> f;
    int _components;
public:
    explicit UnionFind(int sz): f(sz), _components(sz) {
        for (int i = 0; i < sz; i++) {
            f[i] = i;
        }
    }

    int find(int x) {
        if (x == f[x]) return x;
        int fa = f[x];
        return f[x] = find(fa);
    }

    void add(int x, int y) {
        int fx = find(x), fy = find(y);
        if (fx != fy) {
            _components--;
        }
        f[fx] = fy;
    }
    int components() const {
        return _components;
    }
};

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

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

    const int mod = 1e9+7;
    int n;
    cin >> n;
    vector<ll> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    ll ret = arr[0] + 1;

    for (int i = 1; i < n; i++) {
        ret *= (arr[i] - arr[i-1] + 1);
        ret %= mod;
    }
    cout << ret << endl;
}

#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";

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

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

template<int MOD = 998'244'353>
struct Mint
{
	int val;

	Mint() : val(0) {}
	Mint(ll _val) : val((int)(_val % MOD)) { if (val < 0) val += MOD; }

	Mint& operator+= (const Mint &rhs) { val += rhs.val; if (val >= MOD) val -= MOD; return *this; }
	Mint& operator-= (const Mint &rhs) { val -= rhs.val; if (val < 0) val += MOD; return *this; }
	Mint& operator*= (const Mint &rhs) { val = (int)((ll) val * rhs.val % MOD); return *this; }

	friend Mint fpow(Mint x, ll y)
	{
		Mint res = 1;
		for (; y > 0; y >>= 1, x *= x)
		{
			if (y & 1)
				res *= x;
		}
		return res;
	}
	friend Mint inverse(Mint x) { return fpow(x, MOD-2); }
	Mint& operator/= (const Mint &rhs) { return *this *= inverse(rhs); }

	friend Mint operator+ (Mint a, const Mint &b) { return a += b; }
	friend Mint operator- (Mint a, const Mint &b) { return a -= b; }
	friend Mint operator- (Mint a) { return 0 - a; }
	friend Mint operator* (Mint a, const Mint &b) { return a *= b; }
	friend Mint operator/ (Mint a, const Mint &b) { return a /= b; }
	friend ostream& operator<< (ostream &os, const Mint &a) { return os << a.val; }
	friend bool operator== (const Mint &a, const Mint &b) { return a.val == b.val; }
	friend bool operator!= (const Mint &a, const Mint &b) { return a.val != b.val; }
};

const int MAX = 107;

int n;
int w[MAX];
Mint<> dp[MAX][MAX * MAX]; //dp[a][b], pick a items such that the weigh sum is exactly b
Mint<> fact[MAX];

int main()
{
	fastio;

	fact[0] = 1;
	for (int i = 1; i < MAX; ++i)
		fact[i] = i * fact[i-1];

	cin >> n;

	int sum = 0;
	for (int i = 0; i < n; ++i)
		cin >> w[i], sum += w[i];

	if (sum & 1)
	{
		cout << 0 << '\n';
		return 0;
	}

	dp[0][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int a = n-1; a >= 0; --a)
		{
			for (int b = 10000; b >= 0; --b)
			{
				dp[a+1][b + w[i]] += dp[a][b];
			}
		}
	}

	Mint<> res = 0;
	for (int i = 1; i <= n; ++i)
	{
		res += dp[i][sum/2] * fact[i] * fact[n-i];
	}
	cout << res << '\n';

	return 0;
}


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

int main()
{

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

double a,b; cin>>a>>b;
double ans=((a-b)/a);
cout<<ans*100;

}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

void func(long long A, long long B){

    double ans = 100*(B-A)/(double)A;
    cout<<abs(ans)<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(A, B);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define For(n) for(int i=0;i<n;i++)
#define in(x) int x; cin>>x;
#define rrep(i,a,n) for(int i=n;i>=a;i--)
#define out(x) cout<<x<<'\n';
#define vi vector<int>
#define pi pair<int,int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0);  cout.tie(0);
using namespace std;
using ll = long long;
int main() {
	int n;
	cin>>n;
    ll s=0;
    while(n--)
    {
        ll a,b;
        cin>>a>>b;
        s+=(b*(b+1))/2;
        s-=(a*(a-1))/2;
    }
	out(s)
    return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long
using namespace std;
int main() {
	ll n;
	cin >> n;
	ll sum = 0;
	rep(i, 0, n) {
		ll a, b;
		cin >> a >> b;
		sum += (b + a) * (b - a + 1) / 2;
	}
	cout << sum << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
}
// ****************************************************************************
int mat[801][801];
int n,k;
bool isValid(int mid){
    int dp[n+1][n+1];

    memset(dp,0,sizeof dp);
    fo(i,1,n+1){
        fo(j,1,n+1){
            if(mat[i][j]>mid)
            dp[i][j]=1;
        }
    }
    fo(i,1,n+1){
        fo(j,1,n+1)
        dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
    }

    int pos = ((k*k)/2);
    fo(i,k,n+1){
        fo(j,k,n+1){
            int temp = dp[i][j]-dp[i-k][j]-dp[i][j-k]+dp[i-k][j-k];
            if(temp<=pos)
            return true;
        }
    }
    return false;
}
void solve(){
    cin>>n>>k;
    fo(i,1,n+1)
    fo(j,1,n+1)
    cin>>mat[i][j];
    int s = 0,e=INT_MAX;
    int ans = e;
    while(s<=e){
        int mid = s + (e-s)/2;
        if(isValid(mid)){
            ans=mid;
            e=mid-1;
        }
        else s=mid+1;
    }
    cout<<ans<<"\n";
}
signed main()
{
FIO
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}

#include<bits/stdc++.h>
using namespace std;
const int N=800+5;
int n,k;
int a[N][N];
struct point{
	int x,y;
	int a;
	bool operator <(const point &p)const{
		return a<p.a;
	}
}s[N*N];
int cnt;
int f[N][N];
int get(int l,int r,int x,int y){
	return f[x][y]-f[x][r-1]-f[l-1][y]+f[l-1][r-1];
}
bool check(int mid){
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(a[i][j]<=s[mid].a)f[i][j]=1;
			else f[i][j]=0;
		}
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			f[i][j]+=f[i][j-1]+f[i-1][j]-f[i-1][j-1];

	for(int i=k;i<=n;++i)
		for(int j=k;j<=n;++j)
			if(get(i-k+1,j-k+1,i,j)>=k*k-k*k/2)return 1;
	return 0;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j){
			scanf("%d",&a[i][j]);
			s[++cnt]=(point){i,j,a[i][j]};
		}
	sort(s+1,s+cnt+1);
	int l=1,r=n*n,ans;
	while(l<=r){
		int mid=l+r>>1;
		//printf("mid=%d\n",mid);
		if(check(mid))r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%d\n",s[ans].a);
	return 0;
}


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

const int N = 1e5 + 10;
int n, fa[N], col[N];

struct SGT {
    int sz[N << 2];
    void modify(int x, int l, int r, int p, int v) {
        if (l == r) {
            sz[x] = v; return;
        }
        int mid = (l + r) >> 1;
        p <= mid ? modify(x << 1, l, mid, p, v) : modify(x << 1 | 1, mid + 1, r, p, v);
        sz[x] = sz[x << 1] + sz[x << 1 | 1];
    }
    int query(int x, int l, int r, int lx, int rx) {
        if (rx < l || lx > r) return 0;
        if (lx <= l && r <= rx) return sz[x];
        int mid = (l + r) >> 1;
        return query(x << 1, l, mid, lx, rx) + query(x << 1 | 1, mid + 1, r, lx, rx);
    }
} T;

int main() {
    cin >> n;
    rep(i, 1, n) fa[i] = i;
    col[1] = 1;
    rep(i, 2, n) {
        for (int j = 1; j * j <= i; j++) {
            if (i % j == 0) {
                int x = j, y = i / j;
                T.modify(1, 1, n, col[x], 1);
                T.modify(1, 1, n, col[y], 1);
            }
        }
        int l = 1, r = n, pos = n;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (T.query(1, 1, n, 1, mid) < mid) pos = mid, r = mid - 1;
            else l = mid + 1;
        }
        col[i] = pos;
        for (int j = 1; j * j <= i; j++) {
            if (i % j == 0) {
                int x = j, y = i / j;
                T.modify(1, 1, n, col[x], 0);
                T.modify(1, 1, n, col[y], 0);
            }
        }
    }
    rep(i, 1, n) printf("%d ", col[i]); puts("");
    return 0;
}

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

int main() {
	int n; cin >> n;
	for (int i=1; i<=n; i++)
		cout << int(log2(i))+1 << " ";
    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mxn 2002

ll n,m,p,d,t;
vector < vector<parll> > G;
vector <ll> V(mxn,0),D(mxn,llinf);
priority_queue <parll> Q;

ll Dijkstra( ll root )
{
    D[root] = 0;
    Q.push({0,root});

    ll i,novi,w,rez=llinf;
    while ( Q.size() )
    {
        i = Q.top().second; Q.pop();
        if ( V[i] )
        {
            continue;
        }
        V[i] = 1;
        for ( ll j = 0; j < G[i].size(); j++ )
        {
            novi = G[i][j].first; w = G[i][j].second;
            if ( novi == root )
            {
                rez = min( rez, D[i]+w );
                continue;
            }
            if ( D[i]+w < D[novi] )
            {
                D[novi] = D[i]+w;
                Q.push({-D[novi],novi});
            }
        }
    }
    return (rez==llinf)?-1:rez;
}

int main()
{
    ios;

    cin >> n >> m;
    G.resize(n+1);
    for ( int i = 1; i <= m; i++ )
    {
        cin >> p >> d >> t;
        G[p].push_back({d,t});
    }

    for ( int i = 1; i <= n; i++ )
    {
        fill( V.begin(), V.end(), 0 ); fill( D.begin(), D.end(), llinf );
        cout << Dijkstra(i) << "\n";
    }

    return 0;
}

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

int main() {
  int N,M,Q;
  cin >>N;
  long long X[N+1],Y[N+1];
  //input
  for(int i=1;i<=N;i++){
    cin >> X[i] >> Y[i];
  }
  cin >> M;
  vector<pair<int,int>> op;
  int a,b;
  for(int i=1;i<=M;i++){
    cin >> a;
    if(a==3||a==4){
      cin >>b;
      op.push_back(make_pair(a,b));
    }
    else op.push_back(make_pair(a,0));
  }
  cin >> Q;
  vector<tuple<int,int,int>> q;
  for(int i=0;i<Q;i++){
    cin >> a >> b;
    q.push_back(make_tuple(a,b,i));
  }
  sort(q.begin(),q.end());
  long long ans1[Q],ans2[Q];
  int c;
  int cnt = 0;
  long long Xm[3],Ym[3];
  Xm[0] = -1000; Ym[0] = 1000;
  Xm[1] = 1000; Ym[1] = 1000;
  Xm[2] = -1000; Ym[2] = -1000;
  long long cX,cY;

  for(int i=0;i<Q;i++){
    tuple<int,int,int> qn = q.at(i);
    a = get<0>(qn);
    b = get<1>(qn);
    c = get<2>(qn);
    for(int j=cnt;j<a;j++){
      auto p = op.at(j);
      int n = p.first; long long m=p.second;
      for(int k=0;k<3;k++){
        if(n==1){
          long long z = Ym[k];
          Ym[k]=(-1)*Xm[k];
          Xm[k]=z;
        }
        else if(n==2){
          long long z = Ym[k];
          Ym[k]=Xm[k];
          Xm[k]=(-1)*z;
        }
        else if(n==3) Xm[k]=2*m-Xm[k];
        else if(n==4) Ym[k]=2*m-Ym[k];
       // cout << "change" << endl;
      }
    }
    cnt = a;
    if(Xm[0]==Xm[1]){
       cX = Xm[0] + (1000-Y[b])*((abs(Xm[2]-Xm[0]))/(Xm[2]-Xm[0]));
       cY = Ym[0] + (X[b]+1000)*((abs(Ym[1]-Ym[0]))/(Ym[1]-Ym[0]));
    }
    else{
       cX = Xm[0] + (X[b]+1000)*((abs(Xm[1]-Xm[0]))/(Xm[1]-Xm[0]));
       cY = Ym[0] + (1000-Y[b])*((abs(Ym[2]-Ym[0]))/(Ym[2]-Ym[0]));
     // cout << 1000-Y[b] << (Ym[2]-Xm[0]) << endl;
    }
    ans1[c] = cX; ans2[c] = cY;
  }

      for(int i=0;i<Q;i++){
        cout << ans1[i] << " " << ans2[i] << endl;
      }
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl
#define allrange(a) a.begin(),a.end()

bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
    int N = S.size();
    int dx = S[0].first-T[0].first;
    int dy = S[0].second-T[0].second;
    bool flg = true;
    reps(i,1,N){
        if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
    }
    return flg;
}
/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
    int N = S.size();
    vector<pair<int,int>> PS(N);
    auto pt0 = S[0];
    PS[0] = pt0;
    bool flg = true;
    reps(i,1,N){
        int dx = S[i].first - pt0.first;
        int dy = S[i].second - pt0.second;
        if(((dx*b+dy*a)%c)!=0 || ((dx*a-dy*b)%c)!=0) {flg = false; break;}
        PS[i] = make_pair((dx*a-dy*b)/c+pt0.first, (dx*b+dy*a)/c+pt0.second);
    }
    if(flg) return PS;
    else return vector<pair<int,int>>();
}

int main(){
    std::cin.tie(0); // cinとcoutの同期を解除
    std::ios::sync_with_stdio(false);
    int N;cin >> N;
    bool flg=true;

    vector<pair<int,int>> S(N),T(N);
    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        S[i].first = x;S[i].second = y;
    }

    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        T[i].first = x;
        T[i].second = y;
    }
    sort(allrange(T));

/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
    vector<vector<int>> tri(0);
    tri.push_back(vector<int>({5, 12, 13}));
    tri.push_back(vector<int>({5, 12, 13}));
    tri.push_back(vector<int>({12, 5, 13}));
    tri.push_back(vector<int>({8,15,17}));
    tri.push_back(vector<int>({15,8,17}));
    tri.push_back(vector<int>({3,4,5}));
    tri.push_back(vector<int>({4,3,5}));
    tri.push_back(vector<int>({0,1,1}));
    tri.push_back(vector<int>({-1,0,1}));
    tri.push_back(vector<int>({0,-1,1}));
    tri.push_back(vector<int>({1,0,1}));
   //tri.push_back(vector<int>({-5, 12, 13}));
  //  tri.push_back(vector<int>({-12, 5, 13}));
  //  tri.push_back(vector<int>({-8,15,17}));
  //  tri.push_back(vector<int>({-15,8,17}));
    tri.push_back(vector<int>({-3,4,5}));
    tri.push_back(vector<int>({-4,3,5}));
    tri.push_back(vector<int>({-5, -12, 13}));
    tri.push_back(vector<int>({-12, -5, 13}));
 //   tri.push_back(vector<int>({-8,-15,17}));
 //   tri.push_back(vector<int>({-15,-8,17}));
    tri.push_back(vector<int>({-3,-4,5}));
    tri.push_back(vector<int>({-4,-3,5}));
 //   tri.push_back(vector<int>({5, -12, 13}));
 //   tri.push_back(vector<int>({12, -5, 13}));
 //   tri.push_back(vector<int>({8,-15,17}));
    tri.push_back(vector<int>({15,-8,17}));
    tri.push_back(vector<int>({3,-4,5}));
    tri.push_back(vector<int>({4,-3,5}));

    flg=false;

    if(S.size()==2 && T.size()==2){
        auto sx = S[0].first-S[1].first;
        auto sy = S[0].second-S[1].second;
        auto tx = T[0].first-T[1].first;
        auto ty = T[0].second-T[1].second;
        flg= (sx*sx+sy*sy==tx*tx+ty*ty);
    } else {
        rep(j,tri.size()){
            auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
            if(S2.empty()) continue;
            sort(allrange(S2));
            flg = solve_translated(S2,T);
            if(flg) break;
        }
    }
    if(flg) prl("Yes"); else prl("No");
}

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()

template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))

int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(long long x){return __builtin_popcount(x);}

bool ingrid(int i,int j,int H,int W){
    return 0<=i&&i<H&&0<=j&&j<W;
}

const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;}
const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
const ld PI=acosl(-1);

void Main();
int main(){cout<<fixed<<setprecision(15);Main();}

void Main(){

int N,M;cin>>N>>M;
int X[M],maskY[M],Z[M];
rep(i,M){
    int Y;
    cin>>X[i]>>Y>>Z[i];
    maskY[i]=(1<<Y)-1;
}
ll dp[1<<N];
rep(i,1<<N)dp[i]=0;
dp[0]=1;
rep(bit,1<<N){
bool judge=true;
rep(i,M){
    if(popcnt(bit)==X[i]&&popcnt(maskY[i]&bit)>Z[i])judge&=false;
}
if(!judge)continue;
rep(i,N)if((bit>>i)&1){
    int prebit=bit^(1<<i);
    dp[bit]+=dp[prebit];
}

}

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


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;

//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef vector<vector<int>> graph;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define MOD 1000000007
#define MAXX 1.1529215e+18
#define _1 first
#define _2 second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

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

template<class t> using vc=vector<t>;

template<class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<class T>
T extgcd(T a, T b, T &x, T &y) {
    T d = a;
    if (b == 0) {
      x = 1;
      y = 0;
    } else {
      d = extgcd(b, a%b, y, x);
      y -= (a/b)*x;
    }
    return d;
}

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p._1<<","<<p._2<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}

template<class T>
vector<T> divisor(T n) {
  vector<T> ret;
  for (T i = 1; i*i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n/i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  int T;
  cin >> T;
  rep(t, T) {
    ll N;
    cin >> N;
    if (N % 2) {
      cout << "Odd" << endl;
    } else if (N%4) {
      cout << "Same" << endl;
    } else {
      cout << "Even" << endl;
    }
  }
}

#include<bits/stdc++.h>
typedef long long ll;
//#define ll long long
#define int long long
//#define ull unsigned long long
//#define PI pair<int,int>
//#define PII pair<int,PI>
//#define PI pair<ll,int>
//#define endl "\n"
using namespace std;
const int maxm=2e3+5;

const int p=1e4;
int read(){
    string s;cin>>s;
    int t=4;
    int f=0;
    int ans=0;
    for(auto i:s){
        if(i=='.'){
            f=1;
            continue;
        }else{
            ans=ans*10+(i-'0');
            if(f)t--;
        }
    }
    while(t){
        ans=ans*10;
        t--;
    }
    return ans;
}
signed main(){
//    ios::sync_with_stdio(0);
    //
    int X=read();
    int Y=read();
    int R=read();
    //定义横坐标左右边界
    int lc=X-R;
    int rc=X+R;
    while(lc%p)lc++;
    while(rc%p)rc--;
    //定义上下界指针
    int up=Y,down=Y;
    while(up%p)up++;//取整
    while(down%p)down--;
    //
    int ans=0;
    for(int i=lc;i<=rc;i+=p){//枚举横坐标
        int ix=abs(X-i);
        //
        while(ix*ix+(up-Y)*(up-Y)>R*R)up-=p;//up下移
        while(up<=Y||ix*ix+(up-Y)*(up-Y)<=R*R)up+=p;//up上移
        //
        while(ix*ix+(Y-down)*(Y-down)>R*R)down+=p;//down上移
        while(down>=Y||ix*ix+(Y-down)*(Y-down)<=R*R)down-=p;//down下移
        //
        int add=(up-down)/p-1;
        if(add>0)ans+=add;
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<climits>
#include<bitset>
#include<unordered_map>
#include<random>
#include<functional>

using namespace std;

#define max(A,B) ((A)>(B)?(A):(B))

#define min(A,B) ((A)<(B)?(A):(B))

int main(void) {
	string x;
	cin >> x;
	long long int m, mx = 0, res = 0;
	cin >> m;
	if (x.size() == 1) {
		if (x[0] - '0' <= m)cout << 1;
		else cout << 0;
		return 0;
	}

	for (int i = 0; i < x.size(); i++)mx = max(mx, x[i] - '0');
	long long int l = mx, r = m, now;
	res = l;
	while (l <= r) {
		int f = 0;
		long long int note = 0;
		now = (l + r) / 2;
		for (int i = 0; i <x.size(); i++) {
			if (note >= LLONG_MAX / now) {
				f = 1;
				break;
			}
			note *= now;
			note += x[i] - '0';
			if (note > m) {
				f = 1;
				break;
			}

		}
		if (f) {
			r = now - 1;
		}
		else {
			res = max(res, now);
			l = now + 1;
		}
	}
	cout << res - mx;
	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 int         long long
#define ll          long long
#define pb          push_back
#define vi          vector<ll>
#define mi          map<ll,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp          make_pair
#define F           first
#define S           second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define M           998244353
#define hell        1000000007
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update >
const int INF=1e18;
const int N=2e5+5;

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

  return res;
}

int pow(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1)
    res=(res*a);
      a=(a*a);
      b>>=1;
  }

  return res;
}

signed main(void)
{ios
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
    #endif

    int tests=1;
    // cin>>tests;
    while(tests--)
    {
      int n;
      cin>>n;
      int a[n][n];
      rep(i,0,n) rep(j,0,n) cin>>a[i][j];
      vi r(n),c(n);
      rep(i,0,n)
      {
         r[i]=INF;
         rep(j,0,n)
         {
           r[i]=min(r[i],a[i][j]);
         }
      }

      rep(i,0,n)
      {
         c[i]=a[0][i]-r[0];
      }

      // rep(i,0,n) cout<<c[i]<<' ';
      rep(i,0,n)
      {
         rep(j,0,n)
         {
           if(a[i][j]!=r[i]+c[j])
           {
             cout<<"No"<<endl;
             return 0;
           }
         }
      }
      cout<<"Yes"<<endl;
      rep(i,0,n)
      {
         cout<<r[i]<<' ';
      }
      cout<<endl;
      rep(i,0,n) cout<<c[i]<<' ';
    }

}


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

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<double> VD;

int n,m;
vector<PII> v[20];

int64 f[20][1<<20];
int64 solve(int i, int m) {
    if (i==n) return 1;
    if (f[i][m]!=-1) return f[i][m];
    int64 r=0;
    REP (j,n) if ((m&(1<<j))==0) {
        int mm=m|(1<<j), ok=1;
        for (auto [y,z] : v[i]) {
            int k=__builtin_popcount(mm&((1<<y)-1));
            if (k>z) ok=0;
        }
        if (ok) r+=solve(i+1, mm);
    }
    f[i][m]=r;
    return r;
}

int main() {
    //freopen("test.in","r",stdin);
    cin >> n >> m;
    REP (i,m) {
        int x,y,z;
        cin >> x >> y >> z;
        x--;
        v[x].PB({y,z});
    }
    INIT(f,-1);
    cout << solve(0,0) << endl;
    return 0;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

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

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

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m), z(m);
    vector<vector<pair<int,int>>> c(n);
    for(int i = 0; i < m; ++i){
        cin >> x[i] >> y[i] >> z[i];
        c[x[i]].emplace_back(y[i] - 1, z[i]);
    }

    vector<vector<i64>> dp(n + 1, vector<i64>(1 << n, 0));
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < (1 << n); ++j){

            vector<int> r(n + 1, 0);
            for(int k = 0; k < n; ++k){
                if(j & (1 << k))
                    ++r[k];
            }
            for(int k = 0; k < n; ++k){
                r[k + 1] += r[k];
            }
            for(auto [pre, cnt] : c[i]){
                if(r[pre] > cnt){
                    dp[i][j] = 0;
                    break;
                }
            }
            if(dp[i][j] == 0)
                continue;

            for(int k = 0; k < n; ++k){
                if(j & (1 << k))
                    continue;
                dp[i + 1][j | (1 << k)] += dp[i][j];
            }
        }
    }
    cout << dp.back().back() << endl;

    return 0;
}


#include<iostream>
#include<cmath>

using namespace std;

typedef long long ll;

ll n;

int main()
{
    cin>>n;
    ll a,b,c;

    ll mins=1e19;

    for(int i=0;i<=60;i++)
    {
        a=n/pow(2,i);
        b=i;
        c=n-a*(ll)pow(2,i);
        mins=min(mins,(a+b+c));
    }
    cout<<mins;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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;
}
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1;  // 4611686018427387904 - 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

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

    ll N;
    cin >> N;
    ll ans = 0;
    REP(i, N) {
        ll a;
        cin >> a;
        ans += max(0LL, a - 10);
    }
    COUT(ans);
}


// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

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

//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示

int main(){
    string s; cin >> s;
    int f = 1;
    REP(i, 0 ,s.size()){
        if(i % 2 == 0){
            if((s[i] - 'a') < 26&& (s[i] - 'a') >= 0){
                continue;
            }else{
                f = 0;
            }
        }else{
            if((s[i] - 'a') < 26&& (s[i] - 'a') >= 0){
                f = 0;
            }else{
                continue;
            }
        }
    }
    if(f){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
ll INF = 2e18;
using namespace std;

int N;
int cnt;

int main() {
	cin >> N ;

	for(int o = 1; o<N+1; o++){
		int tmp = o;
		int div = 3;
		cnt =0;
		if(o==1) {
			cout << 1<<" ";
			continue;
		}
		while(tmp % 2 == 0){
				tmp /= 2;
				cnt++;
		}
		while(tmp != 1){
			while(tmp % div == 0){
				tmp /= div;
				cnt++;
			}
			div +=2;
		}

/*		if(cnt > 1){
			cout << cnt + 1 << " ";
		}
		else  cout << cnt + 2 << " ";*/
		cout << cnt + 1 << " ";
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mkp make_pair
int dis[2002];
int n,m;
vector<pii>g[2002];
void dij(int s){
	for(int i=0;i<2002;i++)dis[i]=1e9;
	priority_queue<pii,vector<pii>,greater<pii> >pq;
	for(auto x:g[s])
		if(dis[x.fi]>x.se)dis[x.fi]=x.se,pq.push(mkp(x.se,x.fi));
	while(!pq.empty()){
		pii u=pq.top();pq.pop();
		if(dis[u.se]<u.fi)continue;
		for(auto x:g[u.se])
			if(dis[x.fi]>u.fi+x.se)
				dis[x.fi]=u.fi+x.se,pq.push(mkp(x.se+u.fi,x.fi));
	}
	cout<<(dis[s]==1e9?-1:dis[s])<<"\n";
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v,w;cin>>u>>v>>w;
		g[u].push_back(mkp(v,w));
	}
	for(int i=1;i<=n;i++)dij(i);
}

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P = pair<int,int>;
const int INF=1001001001;
const int mod =1e9+7;

struct Unionfind{
   vector<int>d;
   vector<map<int,int>>mp;
   Unionfind(int n):d(n,-1),mp(n){}
   int root(int x){
     if(d[x]<0){return x;}
     return d[x]=root(d[x]);
   }
   bool unite(int x,int y){
     x=root(x);y=root(y);
     if(x==y){return false;}
     if(d[x]>d[y]){swap(x,y);}
     for(auto p:mp[y]){
       mp[x][p.first]+=p.second;
     }
     mp[y]=map<int,int>();
     d[x]+=d[y];
     d[y]=x;
     return true;
   }
   bool same(int x,int y){return root(x)==root(y);}
   int size(int x){return -d[root(x)];}
};

int main() {
  int N,Q;cin>>N>>Q;
  Unionfind uf(N);
  rep(i,N){
    int c;cin>>c;uf.mp[i][c]=1;
  }
  rep(i,Q){
    int q;cin>>q;
    if(q==1){
      int a,b;cin>>a>>b;a--;b--;
      uf.unite(a,b);
    }
    else{
      int x,y;cin>>x>>y;x--;
      int r=uf.root(x);
      cout<<uf.mp[r][y]<<endl;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int mod = 998244353;
int n, m;
int f[3005][3005];
int main() {
	cin >> n >> m;
	f[1][1] = 1;
	for (int i = 2; i <= n; ++i) {
		for (int j = i; j; --j) {
			f[i][j] = f[i - 1][j - 1];
			if (j + j <= i) {
				f[i][j] += f[i][j + j];
				if (f[i][j] >= mod) f[i][j] -= mod;
			}
		}
	}
	cout << f[n][m];
	return 0;
}

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

int dp[1001][1001];

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

    int n,m;
    cin >> n >> m;
    int a[n],b[m];
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];

    rep(i,n+1){
        rep(j,m+1){
            dp[i][j] = 1e9;
        }
    }

    dp[0][0] = 0;

    rep(i,n+1){
        rep(j,m+1){
            if(i > 0)dp[i][j] = min(dp[i][j],dp[i-1][j] + 1);
            if(j > 0)dp[i][j] = min(dp[i][j],dp[i][j-1] + 1);
            if(i > 0 && j > 0){
                if(a[i-1] == b[j-1])dp[i][j] = min(dp[i][j],dp[i-1][j-1]);
                else dp[i][j] = min(dp[i][j],dp[i-1][j-1] + 1);
            }
        }
    }

    cout << dp[n][m] << endl;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
void read(int &x){
	static char c;
	while(!isdigit(c=getchar())); x=c^48;
	while(isdigit(c=getchar()))x=(x*10)+(c^48);
}
void read(ll &x){
	static char c;
	while(!isdigit(c=getchar())); x=c^48;
	while(isdigit(c=getchar()))x=(x*10)+(c^48);
}
void chkmax(int &x,int y){if(y>x)x=y;}
void chkmin(int &x,int y){if(y<x)x=y;}
void chkmax(ll &x,ll y){if(y>x)x=y;}
void chkmin(ll &x,ll y){if(y<x)x=y;}

const int N=5e3+10,Mod=998244353;
void Add(int &x,int y){(x+=y)>=Mod?x-=Mod:x;}
int Pow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}

int n,m;
int F[15][N],C[N][N];

int Calc(int dep,int k){
	if(dep==0)
		if((k&1)||k>n) return 0;
		else return C[n][k];
	if(~F[dep][k]) return F[dep][k];
	int res=0,dig=(m>>(dep-1))&1;
	for(int i=0;i<=k/2;++i) Add(res,1ll*C[n][2*i]*Calc(dep-1,2*(k-2*i)+dig)%Mod);
	return F[dep][k]=res;
}

void Work(){
	memset(F,-1,sizeof F);
	read(n),read(m);
	if(m==1) return puts("0"),void();
	int Bit=log2(m);
	C[0][0]=1;
	for(int i=1;i<=n;++i) C[i][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=i;++j)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;
	printf("%d\n",Calc(Bit-1,2+((m>>(Bit-1))&1)));
}

int main(){Work();}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

#define int long long
const int MOD=998244353;

int dp[15][1000001];
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)(res*=n)%=MOD;
    (n*=n)%=MOD;
    k>>=1;
  }
  return res;
}
int Factorial[5000000],Finverse[5000000];
inline void Cinit(){
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=(Factorial[i-1]*i)%MOD;
  Finverse[4999999]=pw(Factorial[4999999],MOD-2);
  for(int i=4999998;i>=0;i--)Finverse[i]=(i+1)*Finverse[i+1]%MOD;
}

int memo[5001][5001];
int nCk(int n,int k){
  if(n<k)return 0;if(k<0)return 0;
  if(!Factorial[0])Cinit();
  if(~memo[n][k])return memo[n][k];
  int res=Factorial[n];
  (res*=Finverse[k])%=MOD;
  (res*=Finverse[n-k])%=MOD;
  return memo[n][k]=res;
}

signed main(){
  memset(memo,-1,sizeof(memo));
  int n,m;cin>>n>>m;
  dp[0][0]=1;
  for(int i=0;i<14;i++){
    for(int j=0;j<1000000;j++){
      if(((m>>i)&1)^(j&1))continue;
      if(dp[i][j]==0)continue;
      int s=j/2;//上に繰り上がる予約
      for(int k=0;2*k<=n;k++){//k新たに繰り上げる
        //n個のうち2k個が1
        (dp[i+1][s+k]+=dp[i][j]*nCk(n,2*k)%MOD)%=MOD;
      }
    }
  }
  cout<<dp[14][0]<<endl;
}


#pragma GCC optimize("Ofast")
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Po = pair<double, double>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MP make_pair
#define SZ(x) ll(x.size())
#define ALL(x) x.begin(),x.end()
#define NIL -1
#define INF 1ll<<63-1
//#define MOD 1000000007
#define PI 3.14159265358979323846
#define endl "\n"
#define EPS 1e-9
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

template <class T, class U>
bool chmin(T& t, const U& u) {
	if (t > u) {
		t = u;
		return true;
	}
	else return false;
}
template <class T, class U>
bool chmax(T& t, const U& u) {
	if (t < u) {
		t = u;
		return true;
	}
	else return false;
}

bool YN(bool b) {
    if (b) {
        Yes;
        return true;
    }
    else {
        No;
        return false;
    }
}

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

template <unsigned int MOD>
struct ModInt {
    using uint = unsigned int;
    using ull = unsigned long long;
    using M = ModInt;

    uint v;

    ModInt(ll _v = 0) { set_norm(_v % MOD + MOD); }
    M& set_norm(uint _v) {  //[0, MOD * 2)->[0, MOD)
        v = (_v < MOD) ? _v : _v - MOD;
        return *this;
    }

    explicit operator bool() const { return v != 0; }
    M operator+(const M& a) const { return M().set_norm(v + a.v); }
    M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }
    M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); }
    M operator/(const M& a) const { return *this * a.inv(); }
    M& operator+=(const M& a) { return *this = *this + a; }
    M& operator-=(const M& a) { return *this = *this - a; }
    M& operator*=(const M& a) { return *this = *this * a; }
    M& operator/=(const M& a) { return *this = *this / a; }
    M operator-() const { return M() - *this; }
    M& operator++(int) { return *this = *this + 1; }
    M& operator--(int) { return *this = *this - 1; }

    M pow(ll n) const {
        if (n < 0) return inv().pow(-n);
        M x = *this, res = 1;
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    M inv() const {
        ll a = v, b = MOD, p = 1, q = 0, t;
        while (b != 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(p -= t * q, q);
        }
        return M(p);
    }

    bool operator==(const M& a) const { return v == a.v; }
    bool operator!=(const M& a) const { return v != a.v; }
    friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }
    static uint get_mod() { return MOD; }
};

using Mint = ModInt<998244353>;

signed main() {
    cout << fixed << setprecision(15);

    ll x; cin >> x;
    if (x >= 0)cout << x << endl;
    else cout << 0 << endl;
}

#include<bits/stdc++.h>
#define N 200005
#define re register
#define ll long long
#define P 100007
using namespace std;
int n,m,K,q,u;
inline void Rd(int &res){
	re char c;res=0;bool f=0;
	while(c=getchar(),c<48)(c=='-')&&(f=1);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	f&&(res=-res);
}

int main(){
	int T;Rd(T);
	while(T--){
		ll n;
		scanf("%lld",&n);
		int cnt=0;
		while(!(n&1))cnt++,n>>=1;
		if(cnt==0)puts("Odd");
		else if(cnt==1)puts("Same");
		else puts("Even");

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(), v.end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void yes(bool t = 1) { cout << yesno[t] << endl; }

const int mxN = 5e5+5;
int n,m,h;
int a[mxN];
string s,t;
array<int,2> b[mxN];

void code()
{
    cin>>m>>h;

    Yes(h%m==0);

    /*

   */
}

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

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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iomanip>
#include <vector>

int main() {
    int M, H;
    cin >> M >> H;

    if (H % M == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dy[4]={ -1,0,1,0 };
const int dx[4]={ 0,-1,0,1 };

struct UnionFind{
private:
    vector<int> par;
    vector<int> siz;
public:
    void init(int N){
        par.resize(N);
        siz.resize(N);
        for(int i=0; i<N; i++) par[i] = i;
        for(int i=0; i<N; i++) siz[i] = 1;
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return;
        if(siz[rootA] < siz[rootB]) swap(rootA, rootB);
        par[rootB] = rootA;
        siz[rootA] += siz[rootB];
    }
    int root(int a){
        if(par[a] == a) return a;
        return par[a] = root(par[a]);
    }
    bool same(int a, int b){
        return root(a) == root(b);
    }
    int size(int a){
        return siz[root(a)];
    }
};

template<long long Mod>
struct mint{
    long long x;
    mint(long long x=0) :x((x% Mod+Mod)%Mod){}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if((x += a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if((x += Mod-a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= Mod;
        return *this;
    }

    mint operator^(long long t) const {
        mint ret(1);
        mint a = *this;
        while(t){
            if(t&1){
                ret *= a;
            }
            a *= a;
            t >>= 1;
        }
        return ret;
    }
    mint inv() const { return *this ^ (Mod-2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }

    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint operator/(const mint a) const { return mint(*this) /= a; }

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

int N, K;
int A[50][50];

UnionFind r, c;

mint<MOD> fact(int i){
    if(i == 0) return 1;
    return fact(i-1) * i;
}

signed main(){
    cin >> N >> K;
    rep(i, N) rep(j, N) cin >> A[i][j];

    r.init(N);
    c.init(N);
    rep(i, N){
        rep(j, N){
            bool ok = true;
            rep(k, N){
                ok &= (A[i][k] + A[j][k] <= K);
            }
            if(ok) r.unite(i, j);
            ok = true;
            rep(k, N){
                ok &= (A[k][i] + A[k][j] <= K);
            }
            if(ok) c.unite(i, j);
        }
    }

    mint<MOD> ans = 1;
    rep(i, N){
        if(c.root(i) == i){
            ans *= fact(c.size(i));
        }
        if(r.root(i) == i){
            ans *= fact(r.size(i));
        }
    }
    cout << ans << endl;
}


#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;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) -> iterator of kth element (in sorted fashion : low - high)
// order_of_key(x) -> #numbers strictly less than x

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

#define sync ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
#define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin())
#define fi first
#define se second
#define endl '\n'

using pii = pair<int , int>;
using ll = long long;
using ld = long double;

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

ll dp[10005][105], psm[10005][105], n, m;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    sync

    int t = 1;
    //cin >> t;
    while(t--){
      int n;
      cin >> n;
      string s;
      cin >> s;
      if (s[0] != s.back()){
        cout << 1 << endl;
      }
      else{
        if (n <= 3){
          cout << -1 << endl;
        }
        else{
          bool f = 0;
          for (int i = 1; i <= n - 3; i++){
            f |= (s[i] != s[0] && s[i + 1] != s[0]);
          }
          cout << (f ? 2 : -1) << endl;
        }
      }
    }
    cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s    ";
    return 0;
}

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
//#define rep(i,a,n) for (int i=a;i<n;i++)
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define rrep(i,a,n) for (int i=n-1;i>=a;i--)
#define ALL(x) x.begin(),x.end()

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

/*
テスト通りますように
　　●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

const ll INF = numeric_limits<ll>::max()/4;
const ll MAX = 200005;
const int MOD = 3;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  string s;
  cin >> s;
  int sz = s.size();
  s += "#######";
  int cnt = 0;
  rep(i,sz){
    if(s[i] == 'Z' && s[i+1] == 'O' && s[i+2] == 'N' && s[i+3] == 'e')
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn=1010;
const int mod=1e9+7;
ll dp[maxn];
char x,y,z,f;
ll mypow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=1ll*ans*a%mod;
        a=1ll*a*a%mod;
        b>>=1;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    dp[0]=dp[1]=1;
    cin>>n>>x>>y>>z>>f;
  	if(n==2){cout<<"1"<<endl;return 0;}
    for(int i=2;i<=n+5;++i){
        dp[i]=(dp[i-1]+dp[i-2])%mod;
    }
    ll ans=0;
    if(y=='A'){
        if(x=='A')ans=1;
        else if(x=='B'&&z=='A')ans=dp[n-2];
        else if(x=='B'&&z=='B')ans=mypow(2,n-3);
    }else if(y=='B'){
        if(f=='B')ans=1;
        else if(f=='A'&&z=='B')ans=dp[n-2];
        else if(f=='A'&&z=='A')ans=mypow(2,n-3);
    }
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reverse_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 1000;
const int P = 1e9+7;
int n; char s[4];
llong pw2[mxN+3],f[mxN+3];

int main()
{
	n = read(); for(int i=0; i<4; i++) {char str[3]; scanf("%s",str); s[i] = str[0]-65;}
	if(n==2) {puts("1"); return 0;}
	pw2[0] = 1ll; for(int i=1; i<=n; i++) pw2[i] = (pw2[i-1]<<1)%P;
	f[1] = 1ll; for(int i=2; i<=n; i++) f[i] = (f[i-1]+f[i-2])%P;
	if(s[1]==0)
	{
		if(s[0]==0) {puts("1");}
		else
		{
			if(s[2]==0) {printf("%lld\n",f[n-1]);}
			else {printf("%lld\n",pw2[n-3]);}
		}
	}
	else
	{
		if(s[3]==1) {puts("1");}
		else
		{
			if(s[2]==1) {printf("%lld\n",f[n-1]);}
			else {printf("%lld\n",pw2[n-3]);}
		}
	}
	return 0;
}