#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (n-1); i >= 0; i--)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }

void Main();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

vector<bool> ans;
vector<int> c;
vector<vector<int>> graph;

void dfs(int node, int par, set<int>& used) {
  if(!used.count(c[node])) {
    ans[node] = true;
  }
  used.insert(c[node]);
  for(int child: graph[node]){
    if(child != par) {
      dfs(child, node, used);
    }
  }
  if(ans[node]) {
    used.erase(c[node]);
  }
}

void Main(){
  int n; cin >> n;
  c.resize(n);
  rep(i,n) cin >> c[i];

  graph.resize(n);
  Rep(n-1) {
    int a,b; cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  ans.resize(n, false);
  set<int> used;
  dfs(0, -1, used);

  rep(i, n){
    if(ans[i]) cout << i+1 << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n'
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()

/*---------------------------------------------------------------------------------------------------*/

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

    pair<double, double> a[n];

    double x, y;
    f (i, n)
    {
        cin >> x >> y;
        a[i] = make_pair(x, y);
    }

    int ans = 0;
    f (i, n)
    {
        fp (j, i + 1, n - 1)
        {
            double slope = abs ((double)a[i].F - a[j].F);
            if (slope)
            {
                slope = (abs((double)a[i].S - a[j].S) )/ slope;
                if (slope <= 1)
                {
                    ans++;
                }
            }
        }
    }

    cout << ans;
}

signed main()
{
    FAST
    int T = 1;
    // cin >> T;

    while (T--) solve();

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
#define lc (x<<1)
#define rc (x<<1|1)
#define fan(x) (((x-1)^1)+1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

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

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

const int N=1e6+5;
int n,a[N];

inline int merge(int l,int r);

signed main()
{
	n=(1<<read());
	for(int i=1;i<=n;++i)
		a[i]=read();
	merge(1,n);
	return 0;
}

inline int merge(int l,int r)
{
	if(l==r) return l;
	int x1=merge(l,mid);
	int x2=merge(mid+1,r);
	if(l==1&&r==n) printf("%lld\n",a[x1]<a[x2]?x1:x2);
	return a[x1]>a[x2]?x1:x2;
}

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

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

    vector<vector<bool>> a(n + 1, vector<bool>(n + 1, false));
    for(int i = 1; i <= m; ++i){
        int x, y;
        cin >> x >> y;
        a[x][y] = true;
        a[y][x] = true;
    }

    const int FULL_MASK = (1 << n) - 1;
    vector<bool> isComplete(FULL_MASK + 1, true);
    for(int mask = 0; mask <= FULL_MASK; ++mask){
        vector<int> nodes;
        for(int bit = 0; bit < n; ++bit){
            if((mask >> bit) & 1){
                nodes.push_back(bit + 1);
            }
        }
        for(int i = 0; i < (int)nodes.size(); ++i){
            for(int j = i + 1; j < (int)nodes.size(); ++j){
                if(!a[nodes[i]][nodes[j]]){
                    isComplete[mask] = false;
                    break;
                }
            }
        }
    }

    const int INF = n + 5;
    vector<int> minCC(FULL_MASK + 1, INF);
    for(int mask = 0; mask <= FULL_MASK; ++mask){
        if(isComplete[mask]){
            minCC[mask] = 1;
        }
    }

    for(int mask = 1; mask <= FULL_MASK; ++mask){
        for(int submask = mask; submask >= 1; submask = (submask - 1) & mask){
            minCC[mask] = min(minCC[submask] + minCC[submask ^ mask], minCC[mask]);
        }
    }

    cout << minCC[FULL_MASK];

    return 0;
}


#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
main()
{
long long int n,i,j;
vector<long long int>v;
 cin>>n;
  for(i=1;i<=sqrt(n);i++)
      {
        if(n%i==0 && i*i!=n)
        {
         v.push_back(i);
          v.push_back(n/i);
        }
        else if(i*i==n)
        {
          v.push_back(i);

        }
      }
      sort(v.begin(),v.end());
      for(i=0;i<v.size();i++)
      {

      cout<<v[i]<<endl;

      }

}

#include<iostream>
#include<bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include<climits>
#include <algorithm>
using namespace std;

const long long M = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
#define pb push_back
#define MP make_pair
#define f first
#define s second
#define rfor(i,b,a) for(int i=b;i>=a;i--)
#define INF 1000000007

long long mod(long long x) {
    return ((x % M + M) % M);
}
long long add(long long a, long long b) {
    return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
    return mod(mod(a) * mod(b));
}

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

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

int fact(int n) {
    if (n == 0 || n == 1) return 1;
    else return n * fact(n - 1);
}

int ncr(int n, int r) {
    return fact(n) / (fact(n - r) * fact(r));
}

bool isPrime(int n)
{
    if (n == 1) return false;
    if (n == 2) return true;
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0) return false;
    }
    return true;
}

void sieve(int *p) {
    for (int i = 3; i <= 1000000; i += 2) {
        p[i] = 1;
    }

    for (ll i = 3; i <= 1000000; i += 2) {
        if (p[i] == 1) {
            for (ll j = i * i; j <= 1000000; j += i) {
                p[j] = 0;
            }
        }
    }

    p[2] = 1;
    p[0] = p[1] = 0;
}

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

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

bool equal(pair<int, int> temp, int a) {
    return temp.second == a;
}

bool feasible(int mid, vector<int>& arr, int n, int k) {
    int pos = arr[0];
    int elements = 1;

    for (int i = 1; i < n; i++) {
        if (arr[i] - pos >= mid) {
            pos = arr[i];
            elements++;
        }

        if (elements == k) return true;
    }

    return false;
}

int check(map<char, int> freq) {
    int maxx = -1;
    char maxx_element;
    for (auto i : freq) {
        if (i.second > maxx) {
            maxx = i.second;
            maxx_element = i.first;
        }
    }

    int ans = 0;
    for (auto i : freq) {
        if (i.first != maxx_element) ans += i.second;
    }

    return ans;
}

bool check(int n) {
    int n1 = n;
    while (n) {
        if (n % 10 == 7) return false;
        n /= 10;
    }

    while (n1) {
        if (n1 % 8 == 7) return false;
        n1 /= 8;
    }

    return true;
}

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

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

    int n;
    cin >> n;

    int res = 0;

    for (int i = 1; i <= n; i++) {
        if (check(i)) res++;
    }

    cout << res << endl;
}


// C - Too Heavy
#include<bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
using namespace std;
typedef pair<int, int> pii;
const int N = 2e5+3;
int n, a[N], b[N], p[N], rft[N];
bool vis[N];
int main() {
	scanf("%d", &n);
	forn(i,1,n) scanf("%d", a+i);
	forn(i,1,n) scanf("%d", b+i);
	forn(i,1,n) scanf("%d", p+i);
	static priority_queue<pii> q;
	forn(i,1,n) {
		if(i == p[i]) {vis[i] = 1; continue ;}
		if(a[i] <= b[p[i]]) {puts("-1"); return 0;}
		rft[p[i]] = i;
		q.push(make_pair(-a[i], i));
	}
	static int cnt, L[N], R[N];
	while(!q.empty()) {
		static int cur;
		cur = q.top().second;
		q.pop();
		if(vis[cur]) continue ;
		L[++cnt] = cur, R[cnt] = rft[cur];
		vis[cur] = 1, rft[p[cur]] = rft[cur];
		if(rft[cur] == p[cur]) vis[rft[cur]] = 1;
		swap(p[cur], p[rft[cur]]);
	}
	printf("%d\n", cnt);
	forn(i,1,cnt) printf("%d %d\n", L[i], R[i]);
	return 0;
}


#include <vector>
#include <iostream>

#define int         long long
#define double      long double
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

signed main() {
    tezz

    vector<int> primes;
    for (int i = 2; i < 72; i++) {
        bool flag = true;
        for (int j = 2; j < i; j++) {
            if (i % j == 0) flag = false;
        }
        if (flag) primes.emplace_back(i);
    }

    int A, B;
    cin >> A >> B;
    vector<int> v(B - A + 1);
    for (int i = A; i <= B; i++) {
        int mask = 0;
        for (int j = 0; j < primes.size(); j++) {
            if (i % primes[j] == 0) {
                mask |= (1 << j);
            }
        }
        v[i - A] = mask;
    }

    vector<int> dp(1<<primes.size());
    dp[0] = 1;
    for (int x: v) {
        for (int mask = 0; mask < (1 << primes.size()); mask++) {
            if (dp[mask]) {
                int tmp = mask & x;
                if (tmp == 0) dp[mask | x] += dp[mask];
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << primes.size()); i++) ans += dp[i];
    cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) <<

int main() {
    ll a, b; cin >> a >> b;
    cout << (a + b) / 2 << " " << (a - b) / 2 << endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int fib[10000000];
queue<int> st;
void solve(int n,int top)
{
    if(!n)
        return;
    else
    {
        while(n<fib[top])
            top--;
        st.push(top);
        solve(n-fib[top],top);
    }
}
signed main()
{
    cin>>n;
    fib[1] = 1;
    int i = 1;
    while(fib[i] < n)
    {
        i++;
        fib[i] = fib[i-1]+fib[i-2];
    }
    solve(n,i);
    queue<int> ans;
    int top = st.front();
    st.pop();
    ans.push(1);
    int ans_at = 0;
    while(st.size())
    {
        i = st.front();
        while(top>i)
            ans.push(2),top--,ans_at ^= 1;
        ans.push(1);
        st.pop();
    }
    while(top>1)
       ans.push(2),top--,ans_at ^= 1;
    cout<<ans.size()<<endl;
    int now_at = ans_at^1;
    while(!ans.empty())
    {
        if(ans.front()==1)
        {
            cout<<2-now_at<<endl;
        }
        else
        {
            cout<<3+now_at<<endl;
            now_at ^=1;
        }
        ans.pop();
    }
}

#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define ld long double

#define f first
#define s second
#define pb push_back

#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define sz(li) (int) (li).size()
#define sum(a) (accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>

#define endl '\n'

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

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "[ "; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << " ]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<vector<A>> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) { cout << " "; } cout << v[i]; if (i < v.size() - 1) { cout << endl; } } return cout << "]"; }
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; }
template<typename T, typename U> void cmin(T& a, U b){ if (a > b) a = b; }
template<typename T, typename U> void cmax(T& a, U b){ if (a < b) a = b; }

const int MX = 5e5 + 55;

void solve() {
  int n; cin >> n;
  bitset<MX> s, t; cin >> s >> t;

  if (s.count() != t.count()) {
    cout << -1 << endl;
  } else {
    deque<int> zero;

    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 0) zero.push_back(i);
    }

    for (int i = 0; i < n; i++) {
      if (t[i] == 0) {
        ans += i != zero.front();
        zero.pop_front();
      }
    }

    cout << ans << endl;
  }
}

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

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

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

  cerr << "Time: " << 1000.0*clock()/CLOCKS_PER_SEC << " ms\n";
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

vector<int> sz;
vector<int> parent;
void make_set(int v) {
	parent[v] = v;
	sz[v] = 1;
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	else
	{
		auto par = find_set(parent[v]);
		parent[v] = par;
		return par;
	}
}

void merge(int a, int b) {
	find_set(a);
	find_set(b);

	a = find_set(a);
	b = find_set(b);

	if (a != b) {
		if (sz[a] < sz[b])
			swap(a, b);
		parent[b] = a;
		sz[a] += sz[b];
	};
}

int const MOD = 998244353;

int mul(int a, int b) {
	return (a * 1LL * b) % MOD;
}

int add(int a, int b) {
	int s = (a + b);
	if (s >= MOD) s -= MOD;
	return s;
}

int sub(int a, int b) {
	int s = (a + MOD - b);
	if (s >= MOD) s -= MOD;
	return s;
}

ll fast_exp(ll base, ll exp) {
	ll res = 1;
	while (exp > 0) {
		if (exp & 1)
			res = (res * base) % MOD;
		base = (base * base) % MOD;
		exp >>= 1;
	}
	return res;
}

int main() {
	/*freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);*/
	int n;
	cin >> n;
	parent.resize(n);
	sz.resize(n);
	for (int i = 0; i < n; i++) make_set(i);
	vector<int> adjList(n);
	for (int i = 0; i < n; i++) {
		cin >> adjList[i];
		adjList[i]--;
	}
	int cnt_cycles = 0;
	for (int i = 0; i < n; i++) {
		if (find_set(i) == find_set(adjList[i]))
			cnt_cycles++;
		else
			merge(i, adjList[i]);
	}
	cout << sub(fast_exp(2, cnt_cycles), 1);
}

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

int n, f;
bool used[200002];
vector<int> g[200002];
main(){
  cin >> n;
  int ans=1;
  for(int i=0;i<n;i++)cin>>f,f--,g[i].push_back(f),g[f].push_back(i);
  for(int i=0;i<n;i++){
    if(used[i])continue;
    queue<int>q;
    q.push(i);
    used[i]=1;
    while(!q.empty()){
      int v=q.front();
      q.pop();
      for(auto to:g[v])
        if(!used[to])
          q.push(to),used[to]=1;
    }
    ans=(ans+ans);
    if(ans>=998244353)ans-=998244353;
  }
  ans+=998244352;
  if(ans>998244353) ans-=998244353;
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(int i = begin; i < (int)(end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const double PI = 3.14159265359;
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e9;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    int n, x;
    cin >> n >> x;
    long double sum = 0;
    sum = nextafter(sum, INFINITY);
    rep(i, 0, n){
        long double v, p;
        cin >> v >> p;
        v = nextafter(v, INFINITY), p = nextafter(p, INFINITY);
        p /= 100.0;
        sum += v * p;
        if(sum - x > 0.0000001){
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

const int MAX = 100000;
class shuturyoku_unko {
public:
	char C[MAX * 5];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 5) {
				C[i * 5 + 4 - j] = '0' + X % 10;
				X /= 10;
			}
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char dn[dm], * di = dn, * owad = dn + dm - 20;
void putint(ll A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (A >= 100000) {
		if (A >= 1000000000) dig = 5;
		else if (A >= 100000000) dig = 4;
		else if (A >= 10000000) dig = 3;
		else if (A >= 1000000) dig = 2;
		memcpy(di + dig, f.C + A % 100000 * 5, 5);
		A /= 100000;
		memcpy(di, f.C + A * 5 + 5 - dig, dig);
		di += 5 + dig;
	}
	else {
		if (A >= 10000) dig = 5;
		else if (A >= 1000) dig = 4;
		else if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 5 + 5 - dig, dig);
		di += dig;
	}
	*di++ = '\n';
}
const int mod = 1e9 + 7;

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

	int T = getint();
	rep(t, T) {
		ll N = getint(), A = getint(), B = getint();

		ll a = min(A, N - B + 1);
		ll b = min(A + B - 1, N - B + 1);

		ll are = (a + b) * (b - a + 1) + b * (N - A + 1 - (b - a + 1) * 2);
		ll atti = (N - A + 1) * (N - B + 1);

		ll kotae = (atti + are) % mod * ((atti - are) % mod) % mod;
		putint(kotae);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


// ＵＴＦ−８

#include<bits/stdc++.h>

using namespace std;
using ll = long long int;
using lc = complex<double>;

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

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

template <typename T>
struct SegmentTree {
    using F = function<T(T, T)>;

    const T e;
    const F f;
    size_t sz;
    vector<T> tree;

    SegmentTree(size_t n, const F &f, const T &e = 0) : f(f), e(e) {
        sz = 1;
        while(sz < n) sz <<= 1;
        tree.assign(2*sz, e);
    }

    void set(typename vector<T>::iterator begin, typename vector<T>::iterator end) {
        copy(begin, end, tree.begin() + sz);
        for(size_t k=sz-1; k>0; k--)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    void update(size_t k, const T &x) {
        k += sz;
        tree[k] = x;
        while(k >>= 1)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    T query(size_t a, size_t b) const {
        b = min(b, sz);
        a = max((size_t)0, a);
        T l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) l = f(l, tree[a++]);
            if(b & 1) r = f(tree[--b], r);
        }
        return f(l, r);
    }

    T operator[](const size_t k) const {
        return tree[sz + k];
    }
};

int main(void) {
    constexpr ll MOD = 0 ? 1e9+7 : 998244353;
    const double PI = acos(-1);
    constexpr double eps = 1e-10;
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    if(1) {
        ll n;
        cin >> n;
        vector<ll> a(n), b(n), c(n);
        for(auto &e: a) cin >> e;
        for(auto &e: b) cin >> e;

        map<ll,vector<ll>> m;
        for(ll i=0; i<n; i++)
            m[a[i]+i].push_back(i);
        map<ll,ll> idx;

        for(ll i=0; i<n; i++) {
            ll x = b[i]+i;
            auto &v = m[x];
            ll y = idx[x]++;
            if(y == v.size()) {
                cout << -1 << endl;
                return 0;
            }
            c[i] = v[y];
        }

        ll r = 0;
        SegmentTree<ll> st(n, [&](ll a, ll b){return a + b;}, 0);
        for(ll i=0; i<n; i++) {
            r += i - st.query(0, c[i]);
            st.update(c[i], st[c[i]]+1);
        }

        cout << r << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
int n;
int a[maxn], b[maxn], c[maxn], d[maxn], p[maxn], tree[maxn];
bool cmpa(const int & i, const int & j)
{
	return a[i] == a[j] ? i < j : a[i] < a[j];
}
bool cmpb(const int & i, const int & j)
{
	return b[i] == b[j] ? i < j : b[i] < b[j];
}
inline int lowbit(int x) { return (x & (-x));}
ll sum(int x) { int ret = 0; for(int i = x; i < maxn; i += lowbit(i)) ret += tree[i]; return ret;}
void add(int x) { for(int i = x; i; i -= lowbit(i)) ++tree[i];}
ll invpair()
{
	ll ret = 0;
	for(int i = 1; i <= n; ++i)
	{
		ret += sum(p[i]);
		add(p[i]);
	}
	return ret;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] += i, c[i] = i;
	for(int i = 1; i <= n; ++i) scanf("%d", &b[i]), b[i] += i, d[i] = i;
	sort(c + 1, c + n + 1, cmpa);
	sort(d + 1, d + n + 1, cmpb);
	for(int i = 1; i <= n; ++i)
		if(a[c[i]] != b[d[i]])
		{
			puts("-1");
			return 0;
		}
	for(int i = 1; i <= n; ++i) p[d[i]] = c[i];
	printf("%lld\n", invpair());
	return 0;
}


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

int main(){
  ll n,a,b=0,c=0,p=1,ans=999999999999999999;
  cin >> n;
  while(p<=n){
    a=n/p;
    c=n%p;
    ans=min(ans,a+b+c);
    p*=2;
    b++;
  }
  cout << ans << endl;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif
}
void solver() {
    ll inf = 2e18, ans = inf, n;
    cin >> n;
    for(ll i = 0; i <= 60; ++i) {
        ll po = (1LL << i);
        if(po > n) {
            break;
        }
        ll c = n % po, a = (n - c) / po;
        ans = min(ans, a + i + c);
    }
    cout << ans << "\n";
    return;
}
int main() {

    localTest();
    fastio;
    int t = 1;
    // cin >> t;
    while(t--) {
        solver();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define ll long long
#define ui unsigned int
il ll read(){
    bool f=true;ll x=0;
    register char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    if(f) return x;
    return ~(--x);
}
il int read(char *s){
    int len=0;
    register char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar();
    return len;
}
il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');}
il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');}
il ll max(const ll &a,const ll &b){return a>b?a:b;}
il ll min(const ll &a,const ll &b){return a<b?a:b;}
ll k,a,b,c,ans;
int main(){
    k=read();
    for(ri i=1;i<=k;++i){
        for(ri j=1;i*j<=k;++j){
            ans+=k/(i*j);
        }
    }
    print(ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
#define ld long double;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(ll i=ll(f); i<=ll(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define SORT(vec) sort(ALL(vec))
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PB(vec) push_back(vec);
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const double PI = 3.1415926535897932;

int main() {
    int k, ans=0;
    cin >> k;
    FOR(a, 1, pow(k, 0.34)) {
        FOR(b, a, pow(k, 0.50)) {
            FOR(c, b, k) {
                if( a*b*c<=k ) {
                    if( a==b && b==c ) ans = ans + 1;
                    else if( a==b || b==c || c==a ) ans = ans + 3;
                    else ans = ans + 6;
                }
            }
        }
    }
    cout << ans << endl;
}


#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fori(i,init,end) for(ll i=init;i<end;i++)
/*
 1. Create an empty list
 2. Destroy a list
 3. Determine whether a list is empty
 4. Determine the number of items in a list
 5. Traverse the list
 6. Insert an item at a given position in the list
 7. Delete the item at a given position in the list
 8. Search for an item
 9. Access the item at a given position in the list, etc
 */
void Solveit()
{
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)>2)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}

int main()
{
    fastio;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        Solveit();
    }
    return 0;
}

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

const int MAX_N = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
void solve()
{
    char c1,c2,c3;
    cin>>c1>>c2>>c3;
    if(c1==c2 && c2==c3) cout<<"Won"<<endl;
    else cout<<"Lost"<<endl;
}

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


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

#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define repl(i, n) for (ll i = 0 ; i < n ; i++)
#define Rep(i, n) for (int i = 1 ; i <= n ; i++)
#define Repl(i, n) for (ll i = 1 ; i <= n ; i++)
#define rep3(i, a, n) for (int i = a ; i < n ; i++)
#define pi 3.141592653589793238462643

int main() {
    ios::sync_with_stdio(false);
    ll x, y, a, b, ans = 0; cin >> x >> y >> a >> b;
	while (x < (x + b) / a && x < y / a) {
		x *= a;
		ans++;
	}
	ans += ((y - x) / b);
	if ((y - x) % b == 0) ans--;
	cout << ans;
}

#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

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

    string _s1, _s2, _s3; cin >> _s1 >> _s2 >> _s3;

    vi s1, s2, s3;
    for (auto &e: _s1) s1.eb(e - 'a');
    for (auto &e: _s2) s2.eb(e - 'a');
    for (auto &e: _s3) s3.eb(e - 'a');

    vi cnt(26, 0);
    for(auto &e: s1) cnt[e] = 1;
    for(auto &e: s2) cnt[e] = 1;
    for(auto &e: s3) cnt[e] = 1;

    if(accumulate(ALL(cnt), 0) > 10) {
        print("UNSOLVABLE");
        return 0;
    }

    vi mid(26, -1);
    int c = 0;
    REP(i, 26) if(cnt[i]) mid[i] = c++;

    vi e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    do {
        bool f = true;

        ll v1 = 0;
        REP(i, s1.size()) {
            int id = mid[s1[i]];
            int v = e[id];
            if (i == 0 && v == 0) {
                f = false;
                break;
            }

            v1 *= 10;
            v1 += v;
        }

        if (not f) continue;

        ll v2 = 0;
        REP(i, s2.size()) {
            int id = mid[s2[i]];
            int v = e[id];
            if (i == 0 && v == 0) {
                f = false;
                break;
            }

            v2 *= 10;
            v2 += v;
        }

        if (not f) continue;

        ll v3 = 0;
        REP(i, s3.size()) {
            int id = mid[s3[i]];
            int v = e[id];
            if (i == 0 && v == 0) {
                f = false;
                break;
            }

            v3 *= 10;
            v3 += v;
        }

        if (not f) continue;

        if (v1 + v2 == v3) {
            print(v1);
            print(v2);
            print(v3);

            return 0;
        }

    } while(next_permutation(ALL(e)));

    print("UNSOLVABLE");
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b,long long mod) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %mod;
        a = a * a %mod;
        b >>= 1;
    }
    return res;
}

int pre[2005];
int ans[2005][2005];
const int mod=1e9+7;
int pp[4000005];

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

    pp[0]=1;
    for(int i=1;i<=4000000;i++)
        pp[i]=pp[i-1]*2%mod;

    int n,m;
    cin>>n>>m;
    string a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]="#"+a[i];
    }
    int fi=0;
    for(int i=1;i<=n;i++)
    {
        int x=0;
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='.')
                fi++;
            if(a[i][j]=='.')
                x++;
            else
                x=0;
            ans[i][j]+=x;
        }
        x=0;
        for(int j=m;j>=1;j--)
        {
            if(a[i][j]=='.')
                x++;
            else
                x=0;
            ans[i][j]+=x;
            if(a[i][j]=='.')
                ans[i][j]--;
        }
    }

    for(int i=1;i<=m;i++)
    {
        int x=0;
        for(int j=1;j<=n;j++)
        {
            if(a[j][i]=='.')
                x++;
            else
                x=0;
            ans[j][i]+=x;
            if(a[j][i]=='.')
                ans[j][i]--;
        }
        x=0;
        for(int j=n;j>=1;j--)
        {
            if(a[j][i]=='.')
                x++;
            else
                x=0;
            ans[j][i]+=x;
            if(a[j][i]=='.')
                ans[j][i]--;
        }
    }
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
        if(ans[i][j])
        {
            int z=pp[ans[i][j]]-1+mod;
            z%=mod;
            z=(z*pp[(fi-ans[i][j])])%mod;
            tot+=z;
            tot%=mod;
        }
    }
    }
    cout<<tot;

}

#include <stdio.h>
#include <vector>

using namespace std;

const long long mod = 998244353;
vector<long long> mem(2,1);

long long sol(int a) {
    return mem[a];
}

long long pow(long long a, long long b) {
    long long ans = 1;
    long long base = a;
    while (b) {
        if (b%2) ans = ans * base % mod;
        base = base * base % mod;
        b/=2;
    }
    return ans;
}

long long inv(long long a) {
    return pow(a, mod - 2);
}

long long Comb(int a, int b) {

    long long ans = sol(b);//printf("%d %d\n", a, b);
    ans *= inv(sol(a));
    ans %= mod;
    ans *= inv(sol(b-a));
    ans %= mod;
    return ans;
}

int main()
{
    int n,m;
    scanf("%d%d", &n, &m);
    vector<int> primes(m+1, 0);
    for (int i=2 ;i<=m; ++i) {
        if (primes[i] == 0) {
            for (int j=i; j<=m; j+=i) {
                if (primes[j] == 0) {
                    primes[j] = i;
                }
            }
        }
    }
    for (int i=2; i<=n+100; ++i) {
        mem.push_back(i*mem[i-1]%mod);
    }

    long long ans = 0;
    for (int i=1; i<=m; ++i) {
        long long tmp = 1;
        int x = i;
        while (x > 1) {
            int q = 0;
            int prime = primes[x];
            while (x%prime == 0) {
                q++;
                x/=prime;
            }
            tmp *= Comb(n-1, n-1+q);
            tmp %= mod;
        }
        ans = (ans + tmp) % mod;
    }
    printf("%lld\n", ans);
}


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

struct P {
    bool operator<(const P &p) const {
        return v > p.v;
    }
    int v, k;
};

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

    int n;
    cin >> n;

    vector<array<int, 2>> v(n), u(n);
    for (int i = n; --i >= 0;) {
        cin >> v[i][0];
    }
    for (int i = 0; i < n; i++) {
        cin >> v[i][1];
    }

    vector<P> p(n * 2);
    for (int i = 0; i < n; i++) {
        for (int h = 0; h < 2; h++) {
            p[i * 2 + h] = { v[i][h], i * 2 + h };
        }
    }
    sort(p.begin(), p.end());

    for (int j = 0; j < n; j++) {
        int k = p[j].k;
        int i = k / 2, h = k % 2;
        u[i][h] = 1;
    }

    priority_queue<int, vector<int>, greater<>> pq;
    for (int i = 0; i < n; i++) {
        pq.push(v[i][0]);
        pq.push(v[i][1]);

        while ((int)pq.size() > i + 1) {
            pq.pop();
        }

        //u[i][v[i][0] > v[i][1]] = 0;
        //x--;
        //while (1) {
        //    int k = p[j++].k;
        //    int i1 = k / 2, h1 = k % 2;
        //    if (i1 > i && u[i1][h1] == 0) {
        //        u[i1][h1] = 1;
        //        break;
        //    }
        //}
    }

    ll r = 0;
    while (!pq.empty()) {
        r += pq.top();
        pq.pop();
    }
    //for (int i = 0; i < n; i++) {
    //    for (int h = 0; h < 2; h++) {
    //        r += u[i][h] * v[i][h];
    //    }
    //}

    cout << r << endl;

    //真ん中で分けて、片側だけを取ることはできる
    //というか、2列にN個並んでてN回好きな側を取れる
    //ただ、それよりもいい戦略は普通にあるので
    //高橋君がどこか選ぶと歯抜けになるよね 青木君が取るときは端から
    //点数差で考えるか？
    //底のを取り合うなら大きいほうを当然取る それよりいい手とは？
    //底のどちらかは取られてしまう 下のほうの半分は取られてしまう
    //選んだ場所がどこで切ってもそこから下の半分以下なら取れる？

    return 0;
}

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

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

#define int long long

signed main(){
  int n;cin>>n;
  vector<int> v(n*2);
  REP(i,n*2)cin>>v[i];
  int sum=0;
  for(int p:v)sum+=p;
  priority_queue<int,vector<int>,greater<int>> que;
  REP(i,n){
    que.push(v[n-1-i]);
    que.push(v[n+i]);
    sum-=que.top();que.pop();
  }
  cout<<sum<<endl;
}


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

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

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

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

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

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

  vector<vector<int>> C(N, vector<int>(N));
  REP(i, N) REP(j, N) cin >> C[i][j];

  int MIN = C[0][0];
  REP(i, N){
    chmin(MIN, C[i][0]);
  }

  vector<int> A(N);
  REP(i, N){
    A[i] = C[i][0]-MIN;
  }

  vector<int> B(N);
  REP(i, N){
    B[i] = C[0][i]-A[0];
  }

  if(!all_of(ALL(B), [](int x){ return x >= 0; }) || !all_of(ALL(B), [](int x){ return x >= 0; })){
    No;
    return 0;
  }

  REP(i, N) REP(j, N){
    if(C[i][j] != A[i]+B[j]){
      No;
      return 0;
    }
  }

  Yes;
  REP(i, A.size()){
    cout << A[i]; SPBR(i, A.size());
  }
  REP(i, B.size()){
    cout << B[i]; SPBR(i, B.size());
  }

  return 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 509
#define mod 998244353
#define f first
#define s second
#define pa pair<ll,ll>
ll arr[sz][sz],brr[sz],crr[sz];
std::vector<pa> v;
int main()
{
 /// ios_base::sync_with_stdio(0);cin.tie(0);
 int test_case=1;
// scanf("%d",&test_case);
 while(test_case--)
 {
 ll n,m,a=0,b=0;
 scanf("%lld",&n);
 for(int i=1;i<=n;i++)
 {
  for(int j=1;j<=n;j++)
  {
    scanf("%lld",&arr[i][j]);
    if(j>1 && i>1 && (arr[i][j]+arr[i-1][j-1])!=(arr[i-1][j]+arr[i][j-1]))
      a++;
  }
 }
 if(a)
 {
  printf("No\n");
  return 0;
 }
 brr[1]=0;
 ll mn=0;
 for(int i=2;i<=n;i++)
 {
  brr[i]=brr[i-1]+arr[i][1]-arr[i-1][1];
  mn=min(mn,brr[i]);
 }
 for(int i=1;i<=n;i++)
 {
  brr[i]-=mn;
  crr[i]=arr[1][i]-brr[1];
 }
 for(int i=1;i<=n;i++)
 {
  for(int j=1;j<=n;j++)
  {
    if(brr[i]<0 ||  crr[j]<0 || (brr[i]+crr[j])!=arr[i][j])
    {
      printf("No\n");
      return 0;
    }
  }
 }
 printf("Yes\n");
 for(int i=1;i<=n;i++)
  printf("%lld ", brr[i]);
printf("\n");
for(int i=1;i<=n;i++)
  printf("%lld ",crr[i]);
printf("\n");
}
  return 0;
}


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

ll combination(int n, int k) {
  ll answer = 1;
  for (int i = 1; i <= k; i++) {
    answer *= n--;
    answer /= i;
  }
  return answer;
}

// write your code here!

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

  ll price = n * 1.08;

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

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

using namespace std;

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

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

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

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

void solve() {
    int n;
    read(n);
    int cost = 1.08 * n;
    n = cost;
    if(n == 206) print1("so-so");
    else if(n < 206) print1("Yay!");
    else print1(":(");
}

int main() {
    ios;
    /*int tc;
    read(tc);
    while(tc--> 0)*/
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n;
ll a[3000], sum[3001], dp[3001][3001];

int main() {
    ci(n);
    rep(i, n) ci(a[i]);
    rep(i, n) sum[i + 1] = sum[i] + a[i];
    dp[0][0] = 1;
    rep(i, n) {
        vector<int> v[i + 1];
        rep(j, n + 1) v[sum[j] % (i + 1)].epb(j);
        rep(j, i + 1) {
            ll s = 0;
            rep(k, v[j].size() - 1) {
                s = (s + dp[v[j][k]][i]) % MOD;
                dp[v[j][k + 1]][i + 1] = (dp[v[j][k + 1]][i + 1] + s) % MOD;
            }
        }
    }
    int ans = 0;
    rep(i, n) ans = (ans + dp[n][i + 1]) % MOD;
    co(ans);
    return 0;
}

//ulala
//code by 255
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pll pair<ll, ll>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> yree;
const ll inf = 0x3fff3fff3fff3fff;
const ll N = 3003;
const ll M = 1e9+7;
ll a[N];
ll dp[N][N];
map<ll, ll> ddp;

signed main(){
	cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
	memset(dp, 255, sizeof dp);
	ll n;
	cin >> n;
	for(ll i = 0;i<n;i++){
		cin >> a[i];
	}
	for(ll i = 0;i<n;i++){
		dp[1][i]=1;
	}
	ll res=1;
	for(ll kk=2;kk<=n;kk++){
		ddp.clear();
		ll ec=0;
		for(ll i = 0;i<n;i++){
			ec=(ec+a[i])%kk;
			if(ddp.count(ec)) dp[kk][i]=ddp[ec];
			if(dp[kk-1][i]!=-1) ddp[ec]+=dp[kk-1][i], ddp[ec]%=M;
		}
		if(dp[kk][n-1]!=-1) res+=dp[kk][n-1], res%=M;
	}
	cout<<res;
}


// FIRST THINK THEN CODE.

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

using namespace std;

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

#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define cld complex<ld>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vld vector<ld>
#define vvld vector<vector<ld>>
#define vpll vector<pll>
#define vcld vector<cld>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define PI acos(-1)
#define endl "\n"
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define mset(a,val) memset(a,val,sizeof(a));
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
#define FOR(i,a,b)  for(ll i=a;i<=b;i++)
#define FORR(i,a,b)  for(ll i=a;i>=b;i--)
const ll M = 1000000007;
const ll MM = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

template<typename T, typename F>
void chmax( T &a, F b) {
	if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
	if (b < a)a = b;
}

const ll N = 2e5 + 5;

vpll arr[N];

vl self(N, 1e9);

ll dji(ll node) {
	vl vis(2005);
	vis[node] = 1;
	vl dis(2005, 1e18);
	set<pll>s;
	dis[node] = 0;
	ll flag = 0;
	s.insert({dis[node], node});
	while (sz(s)) {
		auto f = *s.begin();
		auto n1 = f.ss;
		s.erase(s.begin());
		for (auto to : arr[n1]) {
			ll child = to.ff, d = to.ss;
			if (child == node) {
				if (!dis[node]) {
					dis[node] = 1e9;
				}
			}

			if (dis[child] > dis[n1] + d) {
				s.erase({dis[child], child});
				dis[child] = dis[n1] + d;
				s.insert({dis[child], child});
			}
		}
	}
	if (!dis[node])dis[node] = 1e9;
	chmin(dis[node], self[node]);
	if (dis[node] == 1e9)dis[node] = -1;
	return dis[node];
}

void OJ() {

#ifndef ONLINE_JUDGE

	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);

#endif

}

int main() {

	IOS;

	OJ();

	ll n; cin >> n;

	ll m; cin >> m;

	for (ll i = 1; i <= m; i++) {
		ll x, y, d;
		cin >> x >> y >> d;
		if (x == y) {
			chmin(self[x], d);
		} else {
			arr[x].pb({y, d});
		}
	}

	for (ll i = 1; i <= n; i++) {
		cout << dji(i) << endl;
	}

	return 0;

}

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

using namespace std;

typedef long long ll;

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

// dijkstra 蟻本
struct edge {ll to, cost;};
typedef pair<ll, ll> P; // firstはsからの最短距離, secondは頂点の番号
const ll INF = 1e17;
const int max_n = 101010;

int n;
vector<edge> g[max_n];

void dijkstra(ll s, vector<ll> &d){

	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0, s));

	while(!que.empty()){
		P p = que.top();
		que.pop();

		ll v = p.second;
		if(d[v] < p.first) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる

		for(ll i = 0; i < g[v].size(); i++){
			edge e = g[v][i];
			if(d[e.to] > p.first + e.cost){
				d[e.to] = p.first + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

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

	int n, m;
	cin >> n >> m;

	rep(i, m){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({b, c});
	}

	vector<vector<ll>> dist(n, vector<ll>(n, INF));
	rep(i, n) dijkstra(i, dist[i]);
	rep(i, n) cout << (dist[i][i] == INF ? -1 : dist[i][i]) << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
const ll INF = 1LL << 60;

ll a, b, ans;

int main() {
    fio(); cin>>a>>b;
    if(a+b>=15 and b>=8) print(1);
    else if(a+b>=10 and b>=3) print(2);
    else if(a+b>=3) print(3);
    else print(4);
}

#include <iostream>
using namespace std;

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

    if (A+B >= 15 && B >= 8) {
        cout << 1;
    }
    else if (A+B >= 10 && B >= 3)
    {
        cout << 2;
    }
    else if (A+B >= 3)
    {
        cout << 3;
    }
    else {
        cout << 4;
    }
}


#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x;
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

int n;
double x[105], y[105];
int fa[105], siz[105];
int Find(int x){
    return (x == fa[x] ? x: (fa[x] = Find(fa[x])));
}
void Union(int x, int y){
    x = Find(x), y = Find(y);
    if(x ==y) return;
    if (siz[x] > siz[y]) fa[y] = x, siz[x] += siz[y];
    else fa[x] = y, siz[y] += siz[x];
}
void init(){
    scanf("%d", &n);
    REP(i, 1,n) scanf("%lf%lf", &x[i], &y[i]);
}
bool check(double r){
    REP(i, 1, n + 2) fa[i] = i, siz[i] = 1;
    REP(i, 1, n) if (100.0 - y[i] <= r) Union(n + 1, i);
    REP(i, 1, n) if (y[i] + 100.0 <= r) Union(n + 2, i);
    REP(i, 1, n)
        REP(j, i + 1, n)
            if (hypot(x[i] - x[j], y[i] - y[j]) <= r)
                Union(i, j);
    return Find(n + 1) == Find(n + 2);
}
void solve(){
    double l = 0, r = 200;
    REP(T, 1, 100){
        double mid = (r + l) * 0.5;
        if (check(mid)) r = mid;
        else l = mid;
    }
    printf("%.10lf\n", l * 0.5);
}
int main(){
    int T = 1;
    while (T--){
        init();
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
int qpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
int Inv(int x){return qpow(x,mod-2);}

#define N 200005
int a[N],vis[N],n;
int fa[N];
int find(int u) {return fa[u]==u?u:fa[u]=find(fa[u]);}
signed main()
{
	int n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=n;i++) fa[find(i)]=find(a[i]);
	int cnt=0;
	for(int i=1;i<=n;i++) if(find(i)==i) cnt++;
	cout<<qpow(2,cnt)-1<<endl;
	return 0;
}


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

#define ll long long

int main()
{
	int n;
	cin>>n;
	int ar[n+5],mark[n+5]={0};
	for(int i=0;i<n;i++){
		cin>>ar[i];
		mark[ar[i]]=1;
	}
	for(int i=1;i<=n;i++){
		if(!mark[i]){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
}

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

#include <iostream>
#include <fstream>

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

inline int inint(istream& in) {int x; in >> x; return x;}
inline ll inll(istream& in) {ll x; in >> x; return x;}
inline string instr(istream& in) {string x; in >> x; return x;}

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

class BPermutationCheck {
public:
void solve(std::istream& in, std::ostream& out) {
    int N = inint(in);
    vector<int> a(N, 0);

    for (int i = 0; i < N; ++i) {
        int temp = inint(in) - 1;
        a[temp] = 1;
    }

    int ok = 1;
    for(int i: a){
        if(i == 0)ok = 0;
    }

    if(ok == 1){
        out << "Yes" << endl;
    }else{
        out << "No" << endl;
    }

}
};

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


#include<bits/stdc++.h>
using namespace std;
#define setbits(x)      __builtin_popcountll(x)
#define leadzero(x)     __builtin_clz(x)
#define trailzero(x)    __builtin_ctz(x)
#define mod             1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag ,
tree_order_statistics_node_update> ;
//find_by_order(index) -> value at the index  //  order_of_key(val) -> gives index of the key
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll              long long
#define int             ll
#define ld              long double
#define ff              first
#define ss              second
#define pb              push_back
#define eb              emplace_back
#define popb            pop_back
#define endl            '\n'
#define all(v)          v.begin(), v.end()
#define sz(x)           ((int)((x).size()))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
ll power(ll a, ll b) {
    if(b<0) return 1;
    ll res=1;
    while(b) {
        if(b&1)
            res = (res*a);//%mod;
        a = (a*a);//%mod;
        b >>= 1;
    }
    return res;
}
template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));}
ll GCD(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}
const int inf = 1e9;
const ll INF = 1e18;
const ld pi = 3.141592653589793238;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
char MV[] = {'U', 'R', 'D', 'L'};
//integer to char always remember (char+'0')
//----------------------------------------------------------------------------------------
void solve() {
    int v, t, s, d; cin >> v >> t >> s >> d;

    t *= v;
    s *= v;

    if(t <= d && d <= s) {
        cout << "No";
    } else {
        cout << "Yes";
    }
}
int32_t main() {
    FIO;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int inf = 1e18;
const int mod = 1e9+7;
const int mod1 = 998244353;
int h, w, a, b, ans;
int grid[19][19];
void check()
 {
  for(int i = 1; i <= h; i++)
     for(int j = 1; j <= w; j++)
       if(grid[i][j] == 0)
          return;
  ans++;
 }
void calc(int y, int x, int A, int B)
 {
   if(y > h || x > w || A < 0 || B < 0)
     return;
   if(y == h && x == w)
   {
     if(!grid[y][x])
       B--;
     grid[y][x] = 1;
     check();
     grid[y][x] = 0;
     return;
   }
   if(grid[y][x])
     {
      if(x == w)
         calc(y + 1, 1, A, B);
      else
         calc(y, x + 1, A, B);
      return;
     }
   if(x != w && !grid[y][x + 1])
     {
      grid[y][x] = 2;
      grid[y][x + 1] = 2;
      calc(y, x + 1, A - 1, B);
      grid[y][x] = 0;
      grid[y][x + 1] = 0;
     }
  if(y != h && !grid[y + 1][x])
     {
      grid[y][x] = 3;
      grid[y + 1][x] = 3;
      if(x == w)
         calc(y + 1, 1, A - 1, B);
      else
         calc(y, x + 1, A - 1, B);
      grid[y][x] = 0;
      grid[y + 1][x] = 0;
     }
  //cerr<<y<<" "<<x<<" "<<grid[y][x]<<END;
  grid[y][x] = 1;
  if(x == w)
     calc(y + 1, 1, A, B - 1);
  else
     calc(y, x + 1, A, B - 1);
  grid[y][x] = 0;
 }
void solve()
 {
  cin>>h>>w>>a>>b;
  ans = 0;
  calc(1, 1, a, b);
  cout<<ans;
 }
int32_t main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
   int t = 1;
   //cin>>t;
   while(t--)
     solve();
  //cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  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;
typedef	long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

int main() {
	fio;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0;i < 9;i++)
		if (s.substr(i, 4) == "ZONe")
			ans++;
	cout << ans << '\n';
}

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

int main(void) {
    long long N;
    cin >> N;
    long long ans = 0;
    for (long long i = 1; i <= 100000; i *= 10) {
        bool flag = false;
        for (long long j = i; j < i * 10; j++) {
            if (j * (i * 10) + j > N) {
                flag = true;
                break;
            }
            ++ans;
        }
        if (flag) {
            break;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

void factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

void cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}

int main(){
	int tt;
    cin>>tt;
    FOR(ti,0,tt){
        LL n,a,b;
        cin>>n>>a>>b;
        if(b>a)swap(a,b);
        LL all=mul(mul(n-a+1,n-a+1),mul(n-b+1,n-b+1));
        LL ta=n-a+1,tb=n-b+1;
        LL tt1=max(n-a-b+1,0LL);
        LL tt2=sub(mul(ta,tb),mul((tt1+1),tt1));
        LL rate=dvs(tt2,mul(ta,tb));
        LL t=mul(all,mul(rate,rate));
        cerr<<tt1<<" "<<tt2<<" "<<rate<<" "<<t<<endl;
        cout<<sub(all,t)<<endl;
    }
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  set<pair<ll, ll>> st;
  auto consider = [&](ll div) {
    ll b = (2 * n / div + div - 1) / 2;
    ll a = 2 * n / div - b;
    ll tmp = (b - a + 1) * (b + a);
    if (tmp == 2 * n) {
      st.insert({min(a, b), max(a, b)});
    }
  };
  for (ll i = 1; i * i <= 2 * n; ++i) {
    if ((2 * n) % i == 0) {
      consider(i);
      consider(2 * n / i);
    }
  }
  cout << st.size() << '\n';
  return 0;
}


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

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
		va_list args;
			va_start(args, format);
				vprintf(format, args);
					va_end(args);
}
#else
#define debug(args...)
#endif

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 1000005

int l, r;
bool isp[MAXN];
int sp[MAXN];
vi primes;
ll ans;

int main() {
	scanf("%d%d", &l, &r);
	REP (i, 2, MAXN) isp[i] = 1;
	for (int i = 2; (ll) i * i <= r; i++) {
		if (!isp[i]) continue;
		sp[i] = i;
		for (int j = i * i; j <= r; j += i) {
			if (isp[j]) sp[j] = i;
			isp[j] = 0;
		}
	}
	REP (i, 2, r + 1) {
		if (isp[i]) {
			sp[i] = i;
		   	primes.pb(i);
		}
	}
	REP (i, 2, r + 1) {
		int u = i;
		int cnt = 0;
		int prv = -1;
		bool pos = 1;
		while (u != 1) {
			cnt++;
			if (prv == sp[u]) {
				pos = 0;
			}
			prv = sp[u];
			u /= sp[u];
		}
		if (!pos) continue;
		int lo = (l - 1) / i, hi = r / i;
		ll len = hi - lo;
		//debug("%d: %lld\n", i, len);
		if (cnt % 2 == 1) {
			//debug(" +\n");
			ans += len * (len - 1);
		} else {
			//debug(" -\n");
			ans -= len * (len - 1);
		}
	}
	//debug("%d\n", ans);
	REP (i, max(l, 2), r + 1) {
		int lo = (l - 1) / i, hi = r / i;
		ll len = hi - lo;
		ans -= (len - 1) * 2;
		//debug("%d: %d\n", i, len);
	}
	printf("%lld\n", ans);
	return 0;
}

//   PIGMEISTER™   //

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

#define int long long
#define ld long double
#define sidha(i,x,n) for(int i=(int)(x);i<(int)(n);++i)
#define ulta(i,x,n) for(int i=(int)(x);i>=(int)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test int _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//#define MAX 100005
#define PI (ld)3.141592653589793238
#define MOD LLONG_MAX
//#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define N 1000001

int lpf[N], mobius[N], a[N], fre[N];
void least_prime_factor()
{
    for (int i = 2; i < N; i++)
        if (!lpf[i])
            for (int j = i; j < N; j += i)
                if (!lpf[j])
                    lpf[j] = i;
}

void Mobius()
{
    for (int i = 1; i < N; i++) {
        if (i == 1)
            mobius[i] = 1;
        else {
            if (lpf[i / lpf[i]] == lpf[i])
                mobius[i] = 0;
            else
                mobius[i] = (int)-1 * mobius[i / lpf[i]];
        }
    }
}

int gcd_pairs(int n)
{
    int maxi = 0;

    for (int i = 0; i < n; i++) {
        fre[a[i]]++;
        maxi = max(a[i], maxi);
    }

    least_prime_factor();
    Mobius();

    int ans = 0;
    for (int i = 1; i <= maxi; i++) {
        if (!mobius[i])
            continue;

        int temp = 0;
        for (int j = i; j <= maxi; j += i)
            temp += fre[j];

        ans += temp * (temp - 1ll) / 2ll * mobius[i];
    }

    return ans;
}

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

    int l, r;
    cin >> l >> r;

    int n = r-l+1;
    int ans = 0;
    sidha (i, 0, n) {
        a[i] = i+l;
        if (i+l == 1) continue;
        int cnt = r/(i+l);
        ans += 2*(cnt-1);
    }

    ans += 2 * gcd_pairs(n);
    // ulta (i, r-l, 2) {
    //     ll mn = max(1ll, (l-1)/i);
    //     ll mx = r/i;
    //     // cout << i << ' ' << mx << ' ' << mn << '\n';
    //     ans += (mx-mn)*(mx-mn-1);
    // }
    cout << n*(n-1) - ans;

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

struct Edge {
  int a, b;
  char dir;
};

vector<Edge> es;
vector<vector<int>> g;
vector<int> c;
vector<int> ei;

void dfs(int v) {
  while (ei[v] < (int)g[v].size()) {
    int i = g[v][ei[v]++];
    if (es[i].dir != '-') continue;

    int u = v ^ es[i].a ^ es[i].b;
    if (u == es[i].b)
      es[i].dir = '>';
    else
      es[i].dir = '<';

    dfs(u);

  }
}

int main2() {
  int N = nextLong();
  int M = nextLong();

  g.clear();
  g = vector<vector<int>>(N);

  REP(i, M) {
    int a = nextLong() - 1;
    int b = nextLong() - 1;
    es.push_back((Edge){a, b, '-'});
    g[a].push_back(i);
    g[b].push_back(i);
  }
  c = vector<int>(N);
  REP(i, N) c[i] = nextLong();

  REP(i, M) {
    int a = es[i].a;
    int b = es[i].b;
    if (c[a] < c[b]) {      es[i].dir = '<';    }
    if (c[a] > c[b]) {      es[i].dir = '>';    }
  }

  ei = vector<int>(N);
  REP(i, N)
    dfs(i);

  REP(i, M) {
    if (es[i].dir == '<') cout << "<-" << endl;
    else if (es[i].dir == '>') cout << "->" << endl;
    else throw 42;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ld sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy;
    cout<<setprecision(12)<<sx+sy/(sy+gy)*(gx-sx)<<endl;

    return 0;
}


// Created at 2021/01/30 20:53
// {TODO}WA, {TODO}min, {TODO}diff
// goal: {TODO}min
#include <bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (lint i = 0, i##_len = n; i < i##_len; i++)
#define rep2(i, n) for (lint i = 1, i##_len = n; i <= i##_len; i++)
#define rep3(i, s, e) for (lint i = s, i##_len = e; i < i##_len; i++)
#define all(i) (i).begin(), (i).end()
#define print(s) cout << s << "\n";
#define print2(s1, s2) cout << s1 << " " << s2 << "\n";
#define mk_p make_pair
using namespace std;
//using namespace atcoder;
using lint = long long;
using pi = pair<int, int>;
using pl = pair<lint, lint>;
using vi = vector<int>;
using vl = vector<lint>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using qi = queue<int>;
using ql = queue<lint>;
constexpr int INF = 1 << 30;
constexpr lint INFl = 1LL << 62;

template<class T, class U>
istream &operator>>(istream &is, pair <T, U> &pair) {
    is >> pair.first >> pair.second;
    return is;
}

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

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &vec) {
    os << '[';
    for (auto v : vec) os << v << ',';
    os << ']';
    return os;
}

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << fixed << setprecision(15);
    /*----------------------------------------------------*/
    int n, s, d; cin >> n >> s >> d;
    vpi xy(n); cin >> xy;
    for (pi xyi : xy) {
        if (xyi.first < s && xyi.second > d) {
            print("Yes")
            return 0;
        }
    }
    print("No")
}
// 時間? メモリ?
// map->bucket?
// あまり->非負か確認
// set? multiset?
// オーバーフロー確認(最大値を求める)
// 入力確認
// 型確認
// ループ回数確認(TLE)
// 小数の計算は避けよう(割り算)(0割りだめ！絶対！)
// Python を使っては?
// 擬似コードを作っては?
// 汚くてもok

// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
vector<T> operator--(vector<T> &vec) {
    for (T &element : vec) --element;
    return vec;
}

// Union-Find
class UnionFind {
    std::vector<int> par;
    int n_;

public:
    UnionFind(int n) {
        assert(n >= 0);
        par.resize(n, -1);
        n_ = n;
    }

    int root(int x) {
        assert(x >= 0 && x < n_);
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        assert(x >= 0 && x < n_ && y >= 0 && y < n_);
        int rx = root(x), ry = root(y);
        if (rx == ry) return false;
        if (-par[rx] > -par[ry]) std::swap(rx, ry);
        par[ry] += par[rx];
        par[rx] = ry;
        return true;
    }

    bool same(int x, int y) {
        assert(x >= 0 && x < n_ && y >= 0 && y < n_);
        return root(x) == root(y);
    }

    int size(int x) {
        assert(x >= 0 && x < n_);
        return -par[root(x)];
    }
};

// Main
int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n);
    cin >> a >> b;
    UnionFind uf(n);
    rep(i, m) {
        int c, d;
        cin >> c >> d;
        --c; --d;
        uf.unite(c, d);
    }
    vector<ll> asum(n, 0), bsum(n, 0);
    rep(i, n) {
        asum[uf.root(i)] += a[i];
        bsum[uf.root(i)] += b[i];
    }
    rep(i, n) if (asum[i] != bsum[i]) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;

void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

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

const int maxn = 1e2+5;

vector<int> g[maxn];
bool sn[maxn];
int c = 0;
void dfs(int v) {
    sn[v] = 1; ++c;
    for (int u : g[v]) {
        if (!sn[u]) {
            dfs(u);
        }
    }
}
signed main(){
    IOS();

    int n; cin>>n;
    REP(i,n) {
        REP(j,n) {
            char c; cin>>c;
            if (c == '1') {
                g[j].pb(i);
            }
        }
    }
    double re = 0;
    REP(i,n) {
        memset(sn, 0, sizeof sn);
        c = 0;
        dfs(i);
        double cb = 1;
        re += 1/(double)c;
    }
    cout<<fixed<<setprecision(12)<<re<<endl;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int N;
vector<int> G[110];
signed main(){
  cin>>N;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++){
      char c;
      cin>>c;
      if(c=='1')G[j].push_back(i);
    }
  long double ans=0;
  for(int i=0;i<N;i++){
    vector<bool> B(N,false);
    B[i]=true;
    queue<int> Q;
    Q.push(i);
    int cnt=1;
    while(!Q.empty()){
      int I=Q.front();
      Q.pop();
      for(int i:G[I])
        if(!B[i]){
          B[i]=true;
          cnt++;
          Q.push(i);
        }
    }
    ans+=(long double)1/(long double)cnt;
  }
  cout<<fixed<<setprecision(16)<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
const int maxn=2e5+5;
const int mod=1e9+7;
ll dp[105][105][105];
ll a[maxn];
int main(){
    int n;
    scanf("%d",&n);
    ll x;
    scanf("%lld",&x);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    ll ans=3e18;
    for(int r=1;r<=n;r++){
        memset(dp[0],-1,sizeof dp[0]);
        dp[0][0][0]=0;

        for(int i=1;i<=n;i++){
            for(int j=0;j<=r;j++)
            for(int k=0;k<r;k++){
                dp[i][j][k]=dp[i-1][j][k];
                if(j>0&&dp[i-1][j-1][(k-(a[i]%r)+r)%r]!=-1)
                    dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][(k-(a[i]%r)+r)%r]+a[i]);

              //  printf("%d %d %d ",i,j,k);
              //  printf("%lld\n",dp[i][j][k]);
            }
        }

        if(dp[n][r][x%r]>=0){
           // cout<<"r="<<r<<' '<<"rr="<<x%r<<' ';
          //  cout<<dp[n][r][x%r]<<endl;
          //  printf("dp[%d][%d]=%lld\n",r,x%r,dp[n][r][x%r]);
            ans=min(ans,(x-dp[n][r][x%r])/r);
        }

    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
vi u,k;
vi dijkstra(int from,vvp g){
    vi dis(g.size(),inf);
    dis[from]=0;
    SPQ(P) pq;
    pq.push(P(0,from));
    while(!pq.empty()){
        auto t=pq.top();pq.pop();
        if(t.fi!=dis[t.se])continue;
        for(auto x:g[t.se]){
            ll cost=t.fi;
            if(t.fi%u[x.se])cost+=u[x.se]-t.fi%u[x.se];
            cost+=k[x.se];
            if(chmin(dis[x.fi],cost))pq.push(P(dis[x.fi],x.fi));
        }
    }
    return dis;
}
int main(){
    ll n,x;cin>>n>>x;
    vi v(n);rep(i,n)cin>>v[i];
    ll ans=inf;
    REP(s,1,n+1){
        vvi dp(s,vi(n+1,-inf));dp[0][0]=0;
        rep(i,n){
            vvi ndp=dp;
            rep(j,s)rep(k,n)if(dp[j][k]!=-inf){
                ll nj=(j+v[i])%s;
                chmax(ndp[nj][k+1],dp[j][k]+v[i]);
            }
            dp=ndp;
        }
        ll k=dp[x%s][s];
        if(k!=-inf)chmin(ans,(x-k)/s);
    }
    out(ans);
}


// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <array>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    cin >> c;
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    constexpr int cmax = 100000;
    array<int, cmax + 1> color;
    rep(i, cmax + 1) color[i] = 0;
    vector<int> good;
    good.reserve(n);
    auto dfs = [&](auto &&dfs, int v, int p) -> void {
        if (!color[c[v]]++) good.push_back(v);
        for (int u : g[v]) {
            if (u != p) dfs(dfs, u, v);
        }
        --color[c[v]];
    };
    dfs(dfs, 0, -1);
    sort(all(good));
    for (int v : good) cout << v + 1 << "\n";
}

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

#define MAXN 507

int n ;
int a[ MAXN ] ;
vector < int > v ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
    v.clear ( ) ;
}

void solve ( ) {
    if ( n == 2 ) {
        if ( a[ 1 ] == 2 ) {
            printf ( "1\n1\n" ) ;
            return ;
        }
        else {
            printf ( "0\n" ) ;
            return ;
        }
    }
    int def_odd = n - 2 ;
    int def_even = n - 1 ;
    if ( ( def_odd % 2 ) == 0 ) { swap ( def_even , def_odd ) ; }

    int len = 0 ;
    while ( 1 ) {
        bool fl = false ;
        for ( int i = 1 ; i < n ; ++ i ) {
            if ( a[ i ] > a[ i + 1 ] ) {
                fl = true ;
                break ;
            }
        }
        if ( fl == false ) { break ; }
        ++ len ;
        int st = 1 ;
        if ( ( len % 2 ) == 0 ) { st = 2 ; }
        fl = false ;
        for ( int i = st ; i < min ( def_odd , def_even ) ; i += 2 ) {
            if ( a[ i ] > a[ i + 1 ] ) {
                fl = true ;
                swap ( a[ i ] , a[ i + 1 ] ) ;
                v.push_back ( i ) ;
                break ;
            }
        }
        if ( fl == false ) {
            if ( ( len % 2 ) == 0 ) {
                swap ( a[ def_even ] , a[ def_even + 1 ] ) ;
                v.push_back ( def_even ) ;
            }
            else {
                swap ( a[ def_odd ] , a[ def_odd + 1 ] ) ;
                v.push_back ( def_odd ) ;
            }
        }
    }
    while ( a[ n - 2 ] > a[ n - 1 ] || a[ n - 1 ] > a[ n ] ) {
        ++ len ;
        if ( ( len % 2 ) == 0 ) {
            swap ( a[ def_even ] , a[ def_even + 1 ] ) ;
            v.push_back ( def_even ) ;
        }
        else {
            swap ( a[ def_odd ] , a[ def_odd + 1 ] ) ;
            v.push_back ( def_odd ) ;
        }
    }
    printf ( "%d\n" , len ) ;
    for ( int i = 0 ; i < len ; ++ i ) {
        printf ( "%d " , v[ i ] ) ;
    }
    printf ( "\n" ) ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t ;
    // t = 1 ;
    // cin >> t ;
    scanf ( "%d" , &t ) ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}


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

const int MaxN=1e5;
int A[MaxN+1]={}; // counting_sort
int B[MaxN+1];
int main(){
	int N, a, c;

	cin>>N;
	for(int i=1;i<=N;i+=1){
		cin>>a;  A[a]+=1;
	}
	for(int i=1;i<=N;i+=1)
		cin>>B[i];

	long ans=0;
	for(int i=1;i<=N;i+=1){
		cin>>c;
		ans+= A[ B[c] ] ;
	}
	cout<<ans<<'\n';
}

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <ios>
#include <iostream>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>
#include <list>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, char> origin,std::pair<int64_t, int64_t> another) {return origin.first < another.first; }
template <typename T> bool chmin(T &a, const T& b) {if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b;return true; } return false; }

int main()
{
    int64_t q,k,s,h,w,d,m,n;
    std::cin>> n;

    std::vector< int64_t > list( n );
    q = 0;

    for( int i = 0; i < n; i++ )
    {
        std::cin>> list[i];
        q += list[i];
    }

    bool dp[n+1][q+1];
    std::memset( dp, 0, sizeof(dp) );
    dp[0][0] = true;

    for( int r = 0; r < n; r++ )
    {
        for( int t = 0; t <= q; t++ )
        {
            dp[r+1][t] |= dp[r][t];

            if( list[r] <= t )
            {
                dp[r+1][t] |= dp[r][t-list[r]];
            }
        }
    }

    k = infl;
    for( int64_t i = 1; i <= q; i++ )
    {
        if( dp[n][i] )
        {
            chmin( k, std::max( i, q - i ) );
        }
    }

    std::cout<< k;
}


#include<cstdio>
const int maxh=1505;
const int LEN=(1<<20);
bool lightflag;
int mp[maxh][maxh];
bool tag[maxh][maxh];
int h,w,n,m,a,b,c,d,sum;
inline int nec(){
    static char buf[LEN],*p=buf,*e=buf;
    if(p==e){
        if((e=buf+fread(buf,1,LEN,stdin))==buf)return EOF;
        p=buf;
    }
    return *p++;
}
inline bool read(int&x){
    static char neg=0,c=nec();
    neg=0,x=0;
    while((c<'0'||c>'9')&&c!='-'){
        if(c==EOF)return 0;
        c=nec();
    }
    if(c=='-'){
        neg=1;
        c=nec();
    }
    do{x=x*10+c-'0';}while((c=nec())>='0');
    if(neg)x=-x;
    return 1;
}
int main(){
    read(h);read(w);read(n);read(m);
    while(n--){
        read(a);read(b);
        mp[a][b]=1;
    }
    while(m--){
        read(c);read(d);
        mp[c][d]=2;
    }
    for(int i=1;i<=h;++i){
        lightflag=0;
        for(int j=1;j<=w;++j){
            if(mp[i][j]==1)
                tag[i][j]=lightflag=1;
            else if(mp[i][j])
                lightflag=0;
            else tag[i][j]|=lightflag;
        }
        lightflag=0;
        for(int j=w;j;--j){
            if(mp[i][j]==1)
                tag[i][j]=lightflag=1;
            else if(mp[i][j])
                lightflag=0;
            else tag[i][j]|=lightflag;
        }
    }
    for(int j=1;j<=w;++j){
        lightflag=0;
        for(int i=1;i<=h;++i){
            if(mp[i][j]==1)
                tag[i][j]=lightflag=1;
            else if(mp[i][j])
                lightflag=0;
            else tag[i][j]|=lightflag;
        }
        lightflag=0;
        for(int i=h;i;--i){
            if(mp[i][j]==1)
                tag[i][j]=lightflag=1;
            else if(mp[i][j])
                lightflag=0;
            else tag[i][j]|=lightflag;
        }
    }
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j)
            sum+=tag[i][j];
    }
    printf("%d",sum);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

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

	vector<vector<pii>> ylis(H); // [y] := (x座標, 電球:0, ブロック:1)
	vector<vector<pii>> xlis(W); // [x] := (y, 同じ)

	REP(i, H) {
		ylis[i].emplace_back(-1, 1);
		ylis[i].emplace_back(W, 1);
	}
	REP(i, W) {
		xlis[i].emplace_back(-1, 1);
		xlis[i].emplace_back(H, 1);
	}

	set<pii> block;

	REP(i, N) { // 電球
		int A, B;
		cin >> A >> B;
		--A; --B;
		ylis[A].emplace_back(B, 0);
		xlis[B].emplace_back(A, 0);
	}

	REP(i, M) { // ブロック
		int A, B;
		cin >> A >> B;
		--A; --B;
		ylis[A].emplace_back(B, 1);
		xlis[B].emplace_back(A, 1);
		block.emplace(A, B);
	}

	REP(i, H) sort(ALL(ylis[i]));
	REP(i, W) sort(ALL(xlis[i]));

	int ans = 0;
	REP(i, H) REP(j, W) {
		if (block.count({i, j}) == 1) continue;

		bool ok = false;

		{ // x
			auto it = lower_bound(ALL(ylis[i]), pii{j, -1});
			if (it->second == 0) ok = true;
			--it;
			if (it->second == 0) ok = true;
		}

		{ // y
			auto it = lower_bound(ALL(xlis[j]), pii{i, -1});
			if (it->second == 0) ok = true;
			--it;
			if (it->second == 0) ok = true;
		}

		ans += ok;
	}

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


#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define eb emplace_back
#define pb push_back
#define pvec(a) for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << '\n'
#define wt(a) cout << a << '\n'
using namespace std;
using ll = long long;
template<class T, class U>bool chmin(T& a, U b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U>bool chmax(T& a, U b) {if (a < b) {a = b; return 1;} return 0;}

vector<vector<int>> g(200005);
vector<bool> isl(200005, false);
const int INF = 1001001001;
vector<int> dp(200005, -1);
vector<int> A(200005);

int rec(int v, bool iss) {
    if (dp[v] != -1) return dp[v];
    int ret = (!iss ? -INF : A[v]);
    for (int nv: g[v]) {
        chmax(ret, rec(nv, true));
    }
    return dp[v] = ret;
}

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

    rep (i, 0, N) cin >> A[i];
    rep (i, 0, M) {
        int X, Y;
        cin >> X >> Y;
        X--, Y--;
        g[X].pb(Y);
    }

    rep (i, 0, N) if (g[i].size() == 0) isl[i] = true;

    int ans = -INF;
    rep (i, 0, N) {
        if (isl[i]) continue;
        chmax(ans, rec(i, false) - A[i]);
    }

    wt(ans);
    return 0;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n, m;

    cin >> n >> m;

    vector<vector<ll>> g(n, vector<ll>());
    vector<P> a(n), _a;

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

    _a = a;

    sort(a.begin(), a.end());

    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;

        g[x].push_back(y);
    }

    vector<bool> searched(n, false);
    vector<ll> dp(n, INF);

    for (int i = 0; i < n; i++)
    {
        queue<int> q;
        q.push(a[i].second);
        ll x = a[i].first;

        while (q.size())
        {
            int p = q.front();
            q.pop();

            for (auto &&j : g[p])
            {
                if (searched[j])
                {
                    continue;
                }
                searched[j] = true;

                dp[j] = x;
                q.push(j);
            }
        }
    }

    ll ans = -INF;

    for (int i = 0; i < n; i++)
    {
        ans = max(ans, _a[i].first - dp[i]);
    }

    cout << ans << endl;
}


//kapi kapi spaghetti
#include <iostream>
#include <iomanip> //setprecision(12)
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

    vector<ll> sum(K+1,0);
    for(ll i=1; i<=K; i++)
    {
        ll cnt=0;
        for(ll k=1; k*k<=i; k++)
        {
            if(i%k==0) cnt+=2;
            if(k*k==i) cnt--;
        }
        sum[i]=sum[i-1]+cnt;
    }

    ll res=0;
    for(ll c=1; c<=K; c++)
    {
        res+=sum[K/c];
    }

    cout<<res<<endl;
    return 0;
}

#include <iostream>

using namespace std;

int main() {

    int K;
    cin >> K;

    int a = 1, b = 1, c = 1, cnt = 0;

    while(true) {
        if(a * b * c <= K) {
            c++;
            cnt++;
        } else if(a * b <= K) {
            c = 1;
            b++;
        } else if(a <= K) {
            b = c = 1;
            a++;
        } else {
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}