#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef long double ld;typedef pair<int, int> pii;typedef vector<int> vec;typedef vector<pii> vecp;typedef vector<string> vecs;
#define dbg(a) cerr << '[' << a << ']' << '\n'
#define pb(item) push_back(item);
#define rep(i,l,n) for(int i = l; i < n; i++)
#define repd(i,l,n) for(int i = l; i >= n; i--)
#define all(a) a.begin(),a.end()
#define fc first
#define sc second
//----------------------------------------------
ll min(ll a, ll b){return a < b? a: b;}
ll max(ll a, ll b){return a > b? a: b;}
//----------------------------------------------
const ll M = 2e3+5, N = 1e9+7;
ll i,j;
//----------------------------------------------
int n,m,k,mx;
vecs t;
vec r;

void f(string s){
if(s.size()==k){
t.pb(s);
return;
}
f(s+'0');
f(s+'1');
}

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

cin >> n >> m;

vec a(m), b(m);
rep(i,0,m){
cin >> a[i] >> b[i];
}

cin >> k;

f("");

vec k1(k),k2(k);
rep(i,0,k) cin >> k1[i] >> k2[i];

rep(i,0,t.size()){
r.clear();
rep(j,0,k){
if(t[i][j] == '0'){
r.pb(k1[j]);
}else r.pb(k2[j]);
}

int cnt = 0;

rep(j,0,m){
if(find(all(r),a[j]) != r.end() && find(all(r),b[j]) != r.end()){
cnt++;
}
}
mx = max(cnt,mx);
}
cout << mx;
return 0;
}

#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
#include<utility>
#include<ostream>
#include<istream>
#include<stack>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
#define pi acos(-1.0)
const ll maxn=1*1e6;
const ll mx=(1<<20)+99;
ll n,m,k,a[110],b[110],c[110],d[110],v[110],sum,x,y,cnt,ans,aans,num=0,sybl;
ll fpow(ll a,ll b)//a^b
{
    ll ans=1;
    while(b)
    {
        if(b%2)
        ans=ans*a%mod;
        b/=2;
        a=a*a%mod;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int t;
//    cin>>t;
//    for(int o=1;o<=t;++o)
    {
        ans=-1;
        cin>>n>>m;
        for(int i=1;i<=m;i++)
        cin>>a[i]>>b[i];
        cin>>k;
        for(int i=1;i<=k;i++)
        cin>>c[i]>>d[i];
        for(int i=0;i<fpow(2,k);i++)
        {
            memset(v,0,sizeof(v));
            num=i;
            for(int j=1;j<=k;j++)
            {
                if(num%2)
                v[d[j]]=1;
                else
                v[c[j]]=1;
                num/=2;
            }
//            for(int j=1;j<=n;j++)
//            cout<<v[j]<<" ";
//            cout<<endl;
            aans=0;
            for(int j=1;j<=m;j++)
            {
                if(v[a[j]]&&v[b[j]])
                aans++;
            }
//            cout<<aans<<endl;
            ans=max(aans,ans);
        }
        cout<<ans<<endl;
    }
}
/*

ll hash(//ll * s,ll n)
{
    ll res=1;
    for(int i=1;i<=n;i++)
    ans=(ans+(ll)i*s[i]%mod)%mod;
    return res;
}

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

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

ll fpow(ll a,ll b)//a^b
{
    ll ans=1;
    while(b)
    {
        if(b%2)
        ans=ans*a%mod;
        b/=2;
        a=a*a%mod;
    }
    return ans;
}

ll inem(ll x)//�����Ԫ
{
    ll x,y;
    exgcd(a,mod,x,y);
    return (mod+x%mod)%mod;
}

int sglfai(int n)
{
	int ans=n;
	for(int i=2;i*i<=n;i++)
	{
		if(!(n%i))
		{
			ans=ans/i*(i-1);
			for(;!(n%i);n/=i);
		}
	}
	if(n!=1)
	ans=ans/n*(n-1);
	return ans;
 }

int olnum[maxn+10];
void listfai()
{
	for(int i=1;i<=maxn;i++)
	olnum[i]=i;
	for(int i=2;i<maxn;i++)
	{
		if (olnum[i]==i)
		{
			for(int j=i;j<maxn;j+=i)
			olnum[j]=olnumn[j]/i*(i-1);
		}
	}
}

int china()
{
    int ans=0,lcm=1,x,y;
    for(int i=1;i<=k;++i)
    lcm*=m[i];
    for(int i=1;i<=k;++i)
    {
        int tmp=lcm/m[i];
        exgcd(tmp,m[i],x,y);
        x=(x%b[i]+b[i])%b[i];//xҪΪ��С�Ǹ�������
        ans=(ans+tp*x*a[i])%lcm;
    }
    return (ans+lcm)%lcm;
}

int china(int n)
{
	ll lcm=1,ans=0,mi;
	for(int i=1;i<=n;++i)
	lcm*=m[i];
	for(int i=1;i<=n;++i)
	{
		mi=lcm/m[i],ti=inem(mi,m[i]);
		ans=(ans+a[i]*mi*ti)%lcm;
	}
	return ans;
}

*/


#include<iostream>
#include<iomanip>
#include<limits>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<tuple>
#include<cmath>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<set>
#include<cstring>

using namespace std;
#define endl "\n"
typedef long long ll;
typedef string str;
const double pi=3.14159265358979323846;
const long long linf = 1LL << 60;
const int inf = 1 << 30;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

template<class T> inline bool ch_min(T&,T);
template<class T> inline bool ch_max(T&,T);
struct UnionFind{
    vector<int> par;//par[i]:i's parent

    UnionFind(int N):par(N){
        //all element are root at first
        for (int i = 0; i < N; i++)par[i]=i;
    }
    int root(int x){
        //root(x):root of x
        if (par[x]==x)return x;
        return par[x]=root(par[x]);
    }

    void unite(int x,int y){
        //unite tree(x is in it) and tree(y is in it)
        int rx=root(x),ry=root(y);
        if (rx==ry)return;
        par[rx]=ry;
    }

    bool same(int x,int y){
        //whether x and y belong to same tree or not
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int ctoi(const char c){
    if('0'<=c&&c<='9')return(c-'0');
    return -1;
}
bool is_palindrome(string s){
    str t=s;
    reverse(s.begin(),s.end());
    return s==t;
}
void inline Yes(bool f){
    if(f){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
int main(int argc, char const *argv[]){
    ll n,a[200020],m=0,ans=0,sum=0;
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        sum+=a[i];
        ch_max(m,a[i]);
        ans+=(i+1)*m+sum;
        cout << ans << endl;
        ans-=(m*(i+1));
    }

    return 0;
}

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

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
	vector<int> v(4);
	rep(i, 4)
		cin >> v[i];
	sort(all(v));
	cout << v[0] << endl;

	return 0;
}


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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define sdi(x) scanf("%d",&x)
#define sdc(c) scanf("%c",&c)
#define inf 1000000000000000000ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second
#define all(x) x.begin(),x.end()

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

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

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const int MOD = 1e9+7;

inline ll add(ll x, ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = (x+y)%MOD;
    return ans;
}

inline ll mul(ll x,ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = ((x*y)%MOD+MOD)%MOD;
    return ans;
}

int main() {
    fastio;
    string s;
    cin>>s;

    int n = s.length();
    vector<int> v(n);

    for(int i=0;i<n;i++) {
        v[i] = s[i]-'a';
    }

    vector<int> cnt(27,0);
    ll res = 0;
    cnt[v.back()]++;
    for(int i=n-2;i>=0;i--) {
        if(v[i]==v[i+1]) {
            for(int j=0;j<26;j++) {
                if(v[i]!=j) {
                    res += cnt[j];
                    cnt[v[i]] += cnt[j];
                    cnt[j] = 0;
                }
            }
        }
        cnt[v[i]]++;
    }

    cout<<res<<endl;

    time_taken();
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
typedef pair<P,P> PP;

double score(PP a,PP b) {
  if(b.F.F<=a.F.F&&a.F.F<b.S.F&&b.F.S<=a.F.S&&a.F.S<b.S.S) {
    double x=a.S.F,y=(b.S.F-b.F.F)*(b.S.S-b.F.S);
    if(x>y) swap(x,y);
    double d=1.0-x/y;
    return 1.0-d*d;
  }
  return 0;
}

vector<PP> rotate(vector<PP> a,int k) {
  if(!k) {
    rep(i,a.size()) {
      swap(a[i].F.F,a[i].F.S);
      a[i].F.F=9999-a[i].F.F;
    }
  } else {
    rep(i,a.size()) {
      swap(a[i].F.F,a[i].F.S);
      a[i].F.F=10000-a[i].F.F;
      swap(a[i].S.F,a[i].S.S);
      a[i].S.F=10000-a[i].S.F;
      if(a[i].F.F>a[i].S.F) swap(a[i].F.F,a[i].S.F);
      if(a[i].F.S>a[i].S.S) swap(a[i].F.S,a[i].S.S);
    }
  }
  return a;
}

void Main() {
  srand((unsigned)time(NULL));
  ll n;
  R n;
  vector<PP> a(n);
  rep(i,n) {
    cin >> a[i].F.F >> a[i].F.S >> a[i].S.F;
    a[i].S.S=i;
  }
  vector<PP> ans2(n);
  double ansM=-1;
  clock_t t2=clock();
  double t5=0;
  rep(l,2) {
    vector<PP> ans(n);
    rep(i,n) ans[a[i].S.S]=PP(a[i].F,P(a[i].F.F+1,a[i].F.S+1));
    rep(i,n)swap(a[i].F.F,a[i].S.F);sort(all(a));rep(i,n)swap(a[i].F.F,a[i].S.F);
    if(!l) rotate(a.begin(),a.begin()+n/3,a.end());
    else reverse(all(a));
    ll cnt=0;
    while(1) {
      if(cnt>=4) {
        if(cnt/4%2) sort(all(a));
        else random_shuffle(all(a));
      }
      rep(i,n) {
        PP p=ans[a[i].S.S];
        double M=score(a[i],p),MM=abs(p.F.F-p.S.F)+abs(p.F.S-p.S.S);
        ll e=0;
        rrep(y,a[i].F.S+1) {
          rep(j,n) {
            if(i==j) continue;
            ll yy=a[j].S.S;
            if(ans[yy].F.S<=y&&y<ans[yy].S.S&&ans[yy].S.F<=a[i].F.F) e=max(e,ans[yy].S.F);
          }
          ll z=abs(ans[a[i].S.S].S.S-y);
          ll x=max(e,ans[a[i].S.S].S.F-(a[i].S.F+z-1)/z);
          PP q=PP(P(x,y),ans[a[i].S.S].S);
          ll mm=max(0LL,min(q.F.F-e,q.S.F-1-a[i].F.F));
          q.F.F-=mm,q.S.F-=mm;
          rep(j,n) {
            if(i==j) continue;
            ll yy=a[j].S.S;
            if(ans[yy].S.F<=q.F.F||q.S.F<=ans[yy].F.F||ans[yy].S.S<=q.F.S||q.S.S<=ans[yy].F.S) continue;
            goto next;
          }
          double d=score(a[i],q);
          double dd=abs(q.F.F-q.S.F)+abs(q.F.S-q.S.S);
          if(M<d+0.000001) {
            M=d;
            MM=dd;
            p=q;
          } else if(M<=d&&MM>=dd) {
            M=d;
            MM=dd;
            p=q;
          }
        }
      next:;
        ans[a[i].S.S]=p;
      }
      a=rotate(a,0);
      ans=rotate(ans,1);
      cnt++;
      clock_t t3=clock();
      double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
      t5=max(t5,t4);
      if((double)t3/CLOCKS_PER_SEC+t5>2.48*(l+1)) break;
      t2=t3;
    }
    while(cnt%4) {
      a=rotate(a,0);
      ans=rotate(ans,1);
      cnt++;
    }
    double sum=0;
    rep(i,n) sum+=score(a[i],ans[a[i].S.S]);
    if(ansM<sum) {
      ansM=sum;
      ans2=ans;
    }
  }
  rep(i,n) pr(ans2[i].F.F,ans2[i].F.S,ans2[i].S.F,ans2[i].S.S);
}

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


#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;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
// #define int int64_t
#define double long double
template<int D, typename T>struct dense:public vector<dense<D-1,T>>{static_assert(D>=1,"dim err");template<typename... Args>dense(int n=0,Args... args):vector<dense<D-1,T>>(n,dense<D-1,T>(args...)){}};
template<typename T>struct dense<1,T>:public vector<T>{dense(int n=0,const T& val=T()):vector<T>(n,val){}};
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>;
mt19937_64 rnd(time(0));
const int FIXED_RANDOM = rnd();
template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32
template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>;
const int MAXN = (int) 1e5 + 2;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int) 1e9 + 7;
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  int n;
  cin >> n;
  set<int> s;
  for(int i = 0; i <= n; i ++) s.insert(i);
  for(int i = 1; i <= n; i ++){
    int u;
    cin >> u;
    s.erase(u);
    cout << (*s.begin()) << endl;
  }
}

#include <iostream>
using namespace std;
bool used[200500];
int m,n,i;
int main() {
	cin>>n;
	while (n--) {
		cin>>i;
		used[i]=true;
		while(used[m]) m++;
		cout<<m<<endl;
	}
    return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int M = 1e9+7;

void solve() {
	int n, a, b;
	cin >> n >> a >> b;

	int tot = (n-a-b+1);
	tot = max(tot, 0LL);
	tot *= (tot+1);
	tot %= M;
	int ans = tot*(n-b+1)%M*(n-a+1)%M;
	ans *= 2;
	ans %= M;
	cout << (ans-tot*tot%M+M)%M << endl;
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    int test = 1;
    cin >> test;

    cout << fixed << setprecision(20);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}

#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int mod = 1e9 + 7;

int rev(int a, int m=mod)
{
    if (a == 1) return 1;
    return (1 - rev(m % a, a) * (ll)m) / a + m;
}

int cnk(int n, int k)
{
    int p = 1;
    int q = 1;
    forn(i, k)
    {
        p = p * (ll)(n - i) % mod;
        q = q * (ll)(i + 1) % mod;
    }
    return p * (ll)rev(q) % mod;
}

int main()
{
    #ifdef HOME
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);
        if (a + b > n)
        {
            printf("0\n");
            continue;
        }
        int res = 0;
        res = (res + cnk(n - a - b + 2, 2) * (ll)(n - a + 1) % mod * (n - b + 1) % mod * 2) % mod;
        res = (res + mod - cnk(n - a - b + 2, 2) * (ll)cnk(n - a - b + 2, 2) % mod * 2 % mod) % mod;
        res = res * 2 % mod;
        printf("%d\n", res);
    }
    #ifdef HOME
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
const double PI = acos(-1);
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}
v<v<ll>> adj;
v<ll> d, p;
ll bfs(ll s) {
	queue<ll> q;
	v<ll> used(n, 0);
	d.assign(n, inf);
	p.assign(n, -1);
	q.push(s);
	used[s] = 1;
	d[s] = 0;
	while (!q.empty())
	{
		ll V = q.front();
		q.pop();
		for (ll u : adj[V])
		{
			if (!used[u])
			{
				used[u] = 1;
				q.push(u);
				d[u] = d[V] + 1;
				p[u] = V;
			}
		}
	}
	ll mx = 0;
	ll  pos = -1;
	for (int i = 0; i < n; i++) {
		if (d[i] > mx) {
			mx = d[i];
			pos = i;
		}
	}
	return pos;
}

v<ll> out, todo;
ll cntr = 1;
void dfs(ll s, ll p, ll t) {
	out[s] = cntr++;
	for (auto u : adj[s]) {
		if (u != p && todo[u] == 0) {
			dfs(u, s, t);
		}
	}
	for (auto u : adj[s]) {
		if (u != p && todo[u] == 1) dfs(u, s, t);
	}
	cntr++;
}
int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n;
	out.resize(n);
	todo.assign(n, 0);
	adj.resize(n);
	rep(i, n - 1) {
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	ll s = bfs(0);

	t = bfs(s);
	x = t;
	while (x != -1) {
		todo[x] = 1;
		x = p[x];
	}
	dfs(s, -1, t);
	rep(i, n) {
		cout << out[i] << ' ';
	}

	return 0;

}

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> dist;
std::vector<int> stack;
std::vector<int> stack_res;
void dfs0(int i, int prev, int goal = -1) {
	stack.push_back(i);
	if (i == goal) stack_res = stack;
	for (auto j : hen[i]) if (j != prev) {
		dist[j] = dist[i] + 1;
		dfs0(j, i, goal);
	}
	stack.pop_back();
}

int cnt = 0;
std::vector<int> res;
std::vector<int> avoid;

void dfs1(int i, int prev) {
	res[i] = cnt;
	for (auto j : hen[i]) if (j != prev) {
		if (avoid[i] == j) continue;
		cnt++;
		dfs1(j, i);
		cnt++;
	}
	for (auto j : hen[i]) if (j != prev) {
		if (avoid[i] != j) continue;
		cnt++;
		dfs1(j, i);
		cnt++;
	}
}

int main() {
	int n = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	dist.assign(n, 0);
	dfs0(0, -1);
	int t0 = std::max_element(dist.begin(), dist.end()) - dist.begin();
	dist.assign(n, 0);
	dfs0(t0, -1);
	int t1 = std::max_element(dist.begin(), dist.end()) - dist.begin();

	dist.assign(n, 0);

	dfs0(t0, -1, t1);

	auto tmp = stack_res;
	avoid.resize(n, -1);
	for (int i = 0; i + 1 < (int) tmp.size(); i++) avoid[tmp[i]] = tmp[i + 1];

	/*
	for (auto i : tmp) std::cerr << i << std::endl;
	*/
	res.resize(n);
	dfs1(tmp[0], -1);

	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", res[i] + 1);
	}
	puts("");

	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    bool same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    bool merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u == v) return false;
        root[u] = v;
        size[v] += size[u];
        return true;
    }
private:
    vector<int> root;
    vector<int> size;
};

int main(){
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0;i<N;i++) cin >> x[i] >> y[i];
    double L = 0, R = 100;
    for(int _=0;_<200;_++){
        double mid = 0.5*(L+R);
        UnionFind uf(N+2);
        for(int i=0;i<N;i++){
            if(100-y[i] < 2*mid) uf.merge(i, N);
            if(y[i]+100 < 2*mid) uf.merge(i, N+1);
            for(int j=i+1;j<N;j++){
                int dx = (x[i] - x[j]);
                int dy = (y[i] - y[j]);
                if(dx*dx+dy*dy < 4*mid*mid) uf.merge(i, j);
            }
        }
        if(uf.same(N, N+1)) R = mid;
        else L = mid;
    }
    printf("%.9lf\n", 0.5*(L+R));

}

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=100010;

signed main(){
    ll x,y;cin>>x>>y;
    ll a,b;cin>>a>>b;
    ll cnt=0;
    while(a<=(y-1)/x&&x<b&&(a-1)<b&&x*(a-1)<b){
        cnt++;
        x*=a;
    }
    cnt+=max(0LL,(y-x-1)/b);
    cout<<cnt<<endl;
}


#include "bits/stdc++.h"
#pragma GCC optimize "trapv"

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

#define pb push_back
#define endl "\n"

#define F first
#define S second

#define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

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

int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

void runCase_()
{
   int n;
   read(n);
   vector<int>v(n);read(v);
   int m = 0,c = INT_MIN;
   double e= 0;
   for(int i  : v)
   {
       m += abs(i);
       c = max(c,abs(i));
       e += (i * i);
   }
    e = sqrt(e);
    cout << fixed << setprecision(10);
    print(m);
    print(e);
    print(c);
}

signed main()
{
    drink_boost;
    // TEST_CASE
    runCase_();
    return 0;
}

/** TEST CASES HERE **/
/*

*/

#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef long long int i64;

typedef long double lld;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1'000'000'000ll + 7;
const i64 mod = 998'244'353ll;

const i64 inf = 1'000'000'000'000'000'000ll;

const long double eps = 1e-8;

map<i64, i64> solve(string s, string t, i64 n) {
    map<i64, i64> r; // score -> cnt

    vector<i64> a(10);
    for (i64 i = 0; i < 4; i++) {
        a[s[i] - '0'] += 1;
    }

    vector<i64> w = a;
    for (i64 i = 0; i < 4; i++) {
        w[t[i] - '0'] += 1;
    }

    for (char c = '1'; c <= '9'; c++) {
        i64 l = n - w[c - '0'];

        a[c - '0'] += 1;

        i64 z = 0;
        for (char k = '1'; k <= '9'; k++) {
            z += pow(10, a[k - '0']) * (k - '0');
        }

        a[c - '0'] -= 1;

        r[z] += l;
    }

    return r;
}

double solve2(string s, string t, i64 n) {
    vector<i64> w(2);

    vector<i64> a(10);
    for (i64 i = 0; i < 4; i++) {
        a[s[i] - '0'] += 1;
    }

    vector<i64> b(10);
    for (i64 i = 0; i < 4; i++) {
        b[t[i] - '0'] += 1;
    }

    for (char c1 = '1'; c1 <= '9'; c1++) {
        i64 p1 = n - a[c1 - '0'] - b[c1 - '0'];
        a[c1 - '0'] += 1;

        for (char c2 = '1'; c2 <= '9'; c2++) {
            i64 p2 = n - a[c2 - '0'] - b[c2 - '0'];
            b[c2 - '0'] += 1;

            i64 s1 = 0;
            i64 s2 = 0;
            for (char k = '1'; k <= '9'; k++) {
                s1 += pow(10, a[k - '0']) * (k - '0');
                s2 += pow(10, b[k - '0']) * (k - '0');
            }

            if (s1 > s2) {
                w[0] += p1 * p2;
            }
            else {
                w[1] += p1 * p2;
            }

            b[c2 - '0'] -= 1;
        }
        a[c1 - '0'] -= 1;
    }

    return w[0] / (double)(w[0] + w[1]);
}

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

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }

    i64 n;
    cin >> n;

    string s[2];
    cin >> s[0] >> s[1];

    /*
    auto r0 = solve(s[0], s[1], n);
    auto r1 = solve(s[1], s[0], n);

    vector<i64> w(2);

    for (auto [score0, cnt0] : r0) {
        for (auto [score1, cnt1] : r1) {
            if (score0 > score1) {
                w[0] += cnt0 * cnt1;
            }
            else {
                w[1] += cnt0 * cnt1;
            }
        }
    }

    double r = w[0] / (double)(w[0] + w[1]);
    cout << r << endl;
    */
    auto r = solve2(s[0], s[1], n);
    cout << r << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll N; cin >> N;
  string S; cin >> S;

  ll cnt = 0;
  stack<char> st;
  rep(i,N) {
    if (S[i]=='x'&&st.size()>=2) {
      char co = st.top(); st.pop();
      char cf = st.top(); st.pop();
      if (cf=='f'&&co=='o') cnt++;
      else { st.push(cf); st.push(co); st.push(S[i]); }
    }
    else st.push(S[i]);
  }

  ll result = N - cnt*3;
  cout << result << endl;
  return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MO 1000000007
#define mem(a,s) memset(a,s,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define lop(i,s,e) for(int i=s;i<e;i++)
#define lopi(i,s,e) for(int i=s;i>=e;i--)
#define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
#define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;}
#define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl;
#define atin(v) for(auto &x:v) cin>>x;
#define vl vector<ll >
#define vi vector<int >
#define lb lower_bound
#define ub upper_bound
#define sort(a) sort(a.begin(),a.end())
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
using namespace std;

void solve() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	stack<char> st;
	int ans=0;
	for(int i=0 ; i<n ; i++) {
		if(s[i]=='x' and !st.empty() and st.top()=='o') {
			st.pop();
			if(!st.empty() and st.top()=='f') {
				st.pop();
				ans+=3;
			}
			else st.push('o');
		}
		else st.push(s[i]);
	}
	cout<<n-ans<<endl;
}

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

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

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n, p;
  cin >> n;
  vector<long long int>v, somme, somme2;
  somme2.push_back(0);
  while(cin >> p){
    v.push_back(p);
    somme.push_back(v.back()+ (somme.size()!=0? somme.back(): 0));
  }
  long long int mx = 0;
  long long int ans = 0;
  for(size_t i=0; i<v.size(); i++){
    mx = max(mx, v.at(i));
    ans = (somme2.at(i) + mx*(i+1)) + somme.at(i);
    somme2.push_back(somme2.at(i)+somme.at(i));
    cout << ans << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
const int MaxA = 200;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> d(MaxA* 2 + 1);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int aj = -MaxA; aj <= MaxA; aj++){
            int c = d[MaxA + aj];
            int x = a[i] - aj;
            ans += (ll)x * x * c;
        }
        d[MaxA+a[i]]++;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, a, b) for (ll i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, s, d; cin>>n>>s>>d;
    bool ans = false;
    rep(i, n) {
        ll x, y;
        cin>>x>>y;
        ans |= x < s && y > d;
    }
    if (ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
int T;
	cin >> T;
	fx(T) {
		string S;
		cin >> S;
		bool a = true;
		fy(S.size()) {
			if (S[y] != 'a') { a = false; }
		}
		if (a) {
			ce(-1)
		}
		else if (S>"atcoder") {
			ce(0)
		}
		else {
			int ans = 0;
			while (S[ans] == 'a') { ans++; }
			if (ans>0&&S[ans] > 't') { ans--; }
			ce(ans)
		}

	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll N, M;
vector<vector<ll>> G;
vector<ll> nodes, col;
vector<bool> seen;
ll tmp = 0;

void init() {
    cin >> N >> M;
    G.resize(N);
    rep(i,M) {
        ll a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    col.resize(N,-1);
    seen.resize(N,false);
}

void make_nodes(ll x) {
    seen[x] = true;
    nodes.push_back(x);
    for (ll y : G[x]) {
        if (seen[y]) continue;
        make_nodes(y);
    }
}

void dfs(ll id) {
    if (id==nodes.size()) {
        tmp++;
        return;
    }
    ll now = nodes[id];
    vector<bool> used(3);
    for (ll to : G[now]) {
        if (col[to]==-1) continue;
        used[col[to]] = true;
    }
    rep(c,3) {
        if (used[c]) continue;
        col[now] = c;
        dfs(id+1);
        col[now] = -1;
    }
}

ll solve(ll st) {
    nodes.resize(0);
    make_nodes(st);
    tmp = 0;
    col[st] = 0;
    dfs(1);
    return 3 * tmp;
}

int main() {
    init();
    ll ans = 1;
    rep(i,N) {
        if (seen[i]) continue;
        ll res = solve(i);
        ans *= res;
    }
    Cout(ans);
}

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

#define ll  int
#define ull unsigned  long long
#define pll  pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn =7e5+100;
const ll mod=1e9+7 ;
const ll base=2e18;
vector<ll> adj[maxn];
ll col[23];
ll n;
bool dd[23];

namespace ufs {
  struct node {int fa, val, size;} t[30];
  struct info {int x, y; node a, b;} st[30];
  inline void pre() {for(int i=1; i<=n; i++) t[i] = (node){i, 0, 1};}
  inline int find(int x) {while(t[x].fa != x) x = t[x].fa; return x;}
  inline int dis(int x) {
    int ans=0;
    while(t[x].fa != x) ans ^= t[x].val, x = t[x].fa;
    return ans;
  }
  inline void link(int x, int y) {
    int val = dis(x) ^ dis(y) ^ 1;
    x = find(x); y = find(y);
    if(t[x].size > t[y].size) swap(x, y);
    t[x].fa = y; t[x].val = val; t[y].size += t[x].size;
  }

} using namespace ufs;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.ans","w",stdout);
    }
    ll  m;
     cin>> n>> m ;
     for (int i=1;i<=m;i++)
     {
         ll x, y;
          cin>>x>> y;
          x--;
          y--;
          adj[x].pb(y);
          adj[y].pb(x);
     }
     long long  ans=0;
     for (int i=0;i<(1ll<<n);i++)
     {
         for (int j=0;j<n;j++)
         {
             if (i&(1ll<<j))
             {
                 col[j]=1;
             }
             else
             {
                 col[j]=0;
             }
         }
         bool kt=true;
         pre();
         for (int i=0;i<n;i++)
         {
             for (auto to:adj[i])
             {
                 if (col[to]==col[i]&&col[to]==0)
                 {
                     kt=false;
                     break;
                 }
                 if (col[to]==col[i]&&col[to]==1)
                 {
                     ll x=find(to+1);
                     ll y=find(i+1);
                     if (x==y)
                     {
                         ll h=dis(to+1)^dis(i+1);
                         if (h==0)
                         {
                             kt=false;
                             break;
                         }
                     }
                     else link(to+1,i+1);
                 }
             }
             if (!kt) break;
         }
         if (!kt)
         {
             continue;
         }
         for (int i=1;i<=n;i++) dd[i]=0;
         long long res=1;
         for (int i=1;i<=n;i++)
         {
             if (col[i-1]==0) continue;
             ll t=find(i);
             if (dd[t]) continue;
             dd[t]=1;
             res*=2;
         }
         ans+=res;
     }
     cout <<ans<<endl;
}


// g++ A.cpp -std=c++14 -I . && ./a.out
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, a, b) for (int i = a; i < (int)(b); i++)
#define rrep(i, a, b) for (int i = a; i > (int)(b); i--)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll INF = 1e18;
// 変数定義
ll N, M, Q, a, b, c, d, x, y, t, T, total, cnt, ans;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  vector<ll> X(N), Y(N);
  rep(i, N) cin >> X[i] >> Y[i];
  rep(i, N) rep2(j, i + 1, N) rep2(k, j + 1, N)
  {
    if ((X[i] - X[j]) * (Y[i] - Y[k]) == (Y[i] - Y[j]) * (X[i] - X[k]))
    {
      cout << "Yes" << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}

#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define MAXN 200005
#define max_num 1000000
#define LL long long
using namespace std;
int n, m;
int l[MAXN], r[MAXN];
int main()
{
    while(cin >> n >> m)
    {
        if(m < 0 || m == n || (m == n - 1 && n - 1 > 0))
        {
            puts("-1");
            continue;
        }
        if(n == 1)
        {
            puts("1 2");
            continue;
        }
        int num_w = n - m - 2;
        int now = max_num;
        for(int i = 0; i < num_w; i++)
        {
            r[i] = now;
            now--;
            l[i] = now;
            now--;
        }
        l[num_w] = 1;
        r[num_w] = (m + 2 + 1) * 2;
        now = (m + 2) * 2 - 1;
        for(int i = num_w + 1; i < n; i++)
        {
            r[i] = now;
            now--;
            l[i] = now;
            now--;
        }
        for(int i = 0; i < n; i++)
        {
            printf("%d %d\n", l[i], r[i]);
        }
    }
    return 0;
}


#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#define MY_IS_DEBUG      (true)
#else
#define MY_NAMESPACE(ns)
#define MY_NAMESPACE_
#define MY_DEBUG(s)
#define MY_IS_DEBUG      (false)
#endif

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

constexpr int IMIN = numeric_limits<int>::min();
constexpr int IMAX = numeric_limits<int>::max();
constexpr ll LLMIN = numeric_limits<ll>::min();
constexpr ll LLMAX = numeric_limits<ll>::max();

template <typename T> bool chmax(T& maxval, T const& newval) { if (newval > maxval) { maxval = newval; return true; } return false; }
template <typename T> bool chmin(T& minval, T const& newval) { if (newval < minval) { minval = newval; return true; } return false; }

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

	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}

	vector<vector<int>> tk(h, vector<int>(w));
	vector<vector<int>> ao(h, vector<int>(w));
	for (int i = h - 1; i >= 0; i--)
	{
		for (int j = w - 1; j >= 0; j--)
		{
			if (i == h - 1 && j == w - 1)
				continue;

			bool is_taka = ((i + j) % 2 == 0);
			// down
			int next_i = i + 1;
			int next_j = j;
			int down_value = IMIN;
			if (next_i < h && next_j < w)
			{
				down_value = tk[next_i][next_j] - ao[next_i][next_j];
				if (!is_taka)
					down_value *= -1;
				if (a[next_i][next_j] == '+')
					down_value++;
				else
					down_value--;
			}

			// right
			next_i = i;
			next_j = j + 1;
			int right_value = IMIN;
			if (next_i < h && next_j < w)
			{
				right_value = tk[next_i][next_j] - ao[next_i][next_j];
				if (!is_taka)
					right_value *= -1;
				if (a[next_i][next_j] == '+')
					right_value++;
				else
					right_value--;
			}

			if (is_taka)
			{
				if (down_value > right_value)
				{
					tk[i][j] = tk[i + 1][j] + (a[i + 1][j] == '+' ? 1 : -1);
					ao[i][j] = ao[i + 1][j];
				}
				else
				{
					tk[i][j] = tk[i][j + 1] + (a[i][j + 1] == '+' ? 1 : -1);
					ao[i][j] = ao[i][j + 1];
				}
			}
			else
			{
				if (down_value > right_value)
				{
					tk[i][j] = tk[i + 1][j];
					ao[i][j] = ao[i + 1][j] + (a[i + 1][j] == '+' ? 1 : -1);
				}
				else
				{
					tk[i][j] = tk[i][j + 1];
					ao[i][j] = ao[i][j + 1] + (a[i][j + 1] == '+' ? 1 : -1);
				}
			}
		}
	}

	string ans;
	if (tk[0][0] == ao[0][0])
		ans = "Draw";
	else if (tk[0][0] > ao[0][0])
		ans = "Takahashi";
	else
		ans = "Aoki";
	cout << ans << "\n";
	return 0;
}
MY_NAMESPACE_

/* in the name of Anton */

/*
  Compete against Yourself.
  Author - Aryan (@aryanc403)
  Atcoder library - https://atcoder.github.io/ac-library/production/document_en/
*/

#ifdef ARYANC403
    #include <header.h>
#else
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
    #pragma GCC optimize ("-ffloat-store")
    #include<bits/stdc++.h>
    #define dbg(args...) 42;
#endif

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n>>m;
    vector<vi> a(n,vi(m,0));
    vector<vi> dp(n,vi(m,0));
    fo(i,n)
    {
        cin>>s;
        fo(j,m){
            if(s[j]=='+')
                a[i][j]=1;
            else
                a[i][j]=-1;
        }
    }
    dbg(a);
    repD(i,n-1,0)   repD(j,m-1,0){
        if(i==n-1&&j==m-1)
            continue;
        if(i==n-1){
            dp[i][j]=a[i][j+1]-dp[i][j+1];
            continue;
        }
        if(j==m-1){
            dp[i][j]=a[i+1][j]-dp[i+1][j];
            continue;
        }
        dp[i][j]=max(a[i+1][j]-dp[i+1][j],a[i][j+1]-dp[i][j+1]);
    }
    dbg(a);
    const lli ans=dp[0][0];
    if(ans==0){
        cout<<"Draw"<<endl;
        return 0;
    }
    if(ans>0){
        cout<<"Takahashi"<<endl;
        return 0;
    }
    if(ans<0){
        cout<<"Aoki"<<endl;
        return 0;
    }
}   aryanc403();
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 18;
const int inf = 1e9;

int n, m;
bool g[maxn][maxn];
bool f[1<<maxn]; //true if mask is a clique

int dp[1<<maxn]; //min CC's

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

    cin>>n>>m;
    for (int i=0; i<m; i++) {
	int u,v; cin>>u>>v;
	--u; --v;
	g[u][v]=g[v][u]=true;
    }

    f[0] = true;

    for (int mask=1; mask<1<<n; mask++) {
	if (__builtin_popcount(mask) == 1) {
	    f[mask] = true;
	    continue;
	}

	for (int j=0; j<n; j++) {
	    if (mask>>j&1) {
		int pmask = (mask^(1<<j));
		if (f[pmask]) {
		    bool ok = true;
		    for (int k=0; k<n && ok; k++) {
			if (pmask>>k&1) {
			    ok &= g[j][k];
			}
		    }

		    if (ok) {
			f[mask] = true;
			break;
		    }
		}
	    }
	}
    }

    dp[0] = 0;
    for (int mask=1; mask<(1<<n); mask++) {
	dp[mask] = inf;
	for (int s=mask;;s=(s-1)&mask) {
	    if (f[s]) {
		dp[mask] = min(dp[mask], 1+dp[mask^s]);
	    }
	    if (s==0) break;
	}
    }

    int res = dp[(1<<n)-1];
    out(res);

    return 0;
}

/*________________________________Author : mr_robot101_________________________________*/

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

/*_____________________________________________________________________________________*/

#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long int
#define ull unsigned long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x, val) memset(x, (int)val, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x), greater<int>())
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define print(a)          \
	for (auto i : a)      \
		cout << i << " "; \
	cout << endl;
#define setbits(x) _builtin_popcount(x)
#define parity(x) _builtin_parity(x)
#define leadzero(x) __builtin_clz(x)
#define trailizero(x) __builtin_ctz(x)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define CHRONO srand(chrono::high_resolution_clock::now().time_since_epoch().count())

/*_____________________________________________________________________________________*/

typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mii;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
	uniform_int_distribution<int> uid(0, lim - 1);
	return uid(rang);
}
void yes() { cout << "Yes\n"; }
void no() { cout << "No\n"; }
const int INF = 1e9;
ll mod = 1e9 + 7;
const int N = 1e6 + 1, M = N;

/*_____________________________________________________________________________________*/
struct segTree {
	int size;
	vector<long long> sums;
	void init(int n) {
		size = 1;
		while (size < n)   size *= 2;
		sums.assign(2 * size, 0LL);
	}

	void build(vector<int> &a, int x, int lx, int rx) {
		if (rx - lx == 1) {
			if (lx < (int)a.size()) {
				sums[x] = a[lx];
			}
			return;
		}
		int m = (lx + rx) / 2;
		build(a, 2 * x + 1, lx, m);
		build(a, 2 * x + 2, m, rx);
		sums[x] = sums[2 * x + 1] ^ sums[2 * x + 2];
	}

	void build(vector<int> &a) {
		build(a, 0, 0, size);
	}

	void set(int i, int v, int x, int lx, int rx) {
		if (rx - lx == 1) {
			sums[x] ^= v;
			return;
		}
		int m = (lx + rx) / 2;
		if (i < m) {
			set(i, v, 2 * x + 1, lx, m);
		}
		else set(i, v, 2 * x + 2, m, rx);
		sums[x] = sums[2 * x + 1] ^ sums[2 * x + 2];
	}

	void set(int i, int v) {
		set(i, v, 0, 0, size);
	}

	long long sum(int l, int r, int x, int lx, int rx) {
		if (lx >= r || l >= rx) return 0;
		if (lx >= l && rx <= r)  return sums[x];
		int m = (lx + rx) / 2;
		auto v1 = sum(l , r, 2 * x + 1, lx, m);
		auto v2 = sum(l, r, 2 * x + 2, m, rx);
		return v1 ^ v2;
	}

	long long sum(int l, int r) {
		return sum(l, r, 0, 0, size);
	}
};

void solve()
{
	int dp[1005][1005];
	// dp[n][m]
	int n, m;
	cin >> n >> m;
	vi a(n), b(m);
	fo(i, n)	cin >> a[i];
	fo(i, m)	cin >> b[i];
	fo(i, n + 1)	dp[i][0] = i;
	fo(i, m + 1)	dp[0][i] = i;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] != b[j - 1])});
		}
	}
	cout << dp[n][m];
}

/*_____________________________________________________________________________________*/

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

/*_____________________________________________________________________________________*/


#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i=0;i<n;i++)

#define DENOM 1000000007

using namespace std;
using ll = long long;

int main(){
  int n ;
  double x = 0;
  cin >> n ;
  for (int i=1;i<n;i++) {
    double p = double(n)/double(n-i)  ;
    x += p ;
  }
  cout << fixed << setprecision(10) ;
  cout << x << endl ;
  return 0 ;
}

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

int main(void){
  ll n, m;
  int c = 0;
  string s;

  cin >> n;

  rep(i, 1, 1e6){
    s = to_string(i);
    m = stoll(s + s);
    if(m <= n)
      c++;
    else
      break;
  }

  cout << c << endl;

  return 0;
}


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

int main(void){
    // Your code here!

    std::vector<int> a(3);

    rep(i,a.size()) {
         std::cin >> a.at(i);
    }
    int tmp=0;

    rep(i,a.size()) {
         for(int j=i+1;j<a.size();j++) {
              if(a.at(i)<a.at(j)) {
                    tmp=a.at(i);
                    a.at(i)=a.at(j);
                    a.at(j)=tmp;
              };
         }
    }

    if(a.at(2)-a.at(1)==a.at(1)-a.at(0))  {
         std::cout << "Yes" << std::endl;
    }
    else {
         std::cout << "No" << std::endl;
    }

}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
char s[maxn];
int main()
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	if(s[1] != s[n])
	{
		puts("1");
		return 0;
	}
	int l = 1, r = n;
	while(l <= n && s[l] == s[1]) ++l;
	while(r >= 1 && s[r] == s[n]) --r;
	if(l == n + 1) { puts("-1"); return 0;}
	else
	{
		bool flag = 0;
		for(int i = l; i < r; ++i)
		{
			if(s[i] != s[1] && s[i + 1] != s[1])
			{
				flag = 1;
				break;
			}
		}
		if(!flag) puts("-1");
		else puts("2");
	}
	return 0;
}


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

int a,b;
unordered_map<int,int> mp;

int main(){

    cin>>a>>b;

    for(int i=a;i<=b;i++){
        for(int j=1;j*j<=i;j++){
            if(i%j==0){
                mp[j]++;
                mp[i/j]++;
            }
        }
    }

    int m = (b-a)+1;
    while(m--){
        if(mp[m]>=2){
            cout<<m<<endl;
            return 0;
        }
    }

    return 0;
}

#include <iostream>
#include <algorithm>

bool check(int p, int a, int b)
{
	int under = (a - 1) / p;
	int top = b / p;
	if (top - under >= 2)
		return (true);
	return (false);
}

int main(void)
{
	int a, b;
	int ans = 0;
	std::cin >> a >> b;
	for (int p = 1; p <= b; p++)
	{
		if (check(p, a, b))
			ans = std::max(ans, p);
	}
	std::cout << ans << std::endl;
	return (0);
}


/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

// Utility for binomial coefficient
ll ncr(ll n,ll k)
{
    if(n<k)
        return 0;
    ll C[n + 1][k + 1];
    ll i,j;
    for(i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if (j==0 || j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    return C[n][k];
}

ll sum(ll n){
	return n*(n+1)/2;
}

void solve(){
	//code
	ll n,x,y,s=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		s+=(sum(y)-sum(x-1));
	}
	cout<<s;
}

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

	solve();
 	return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define REP(i,L,R) for(ll i=L;i<R;i++)
using namespace std;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<vector<int>> Graph;
typedef vector<string> Grid;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}

//#define DEBUG

//declaration area

// inf definition

//struct area

//function area

//main area
int main(){
    int n;
    cin >> n;
    ld x0, y0, xt, yt;
    cin >> x0 >> y0 >> xt >> yt;
    ld midx = (x0+xt)/2, midy = (y0+yt)/2;
    ld t = 2*M_PI/(n*1.0);
    ld cosk = cos(t);
    ld sink = sin(t);
	cout << fixed << setprecision(10) << midx+cosk*(x0-midx)-sink*(y0-midy) << ' ' << midy+sink*(x0-midx)+cosk*(y0-midy) << endl;
}
/*

*/


#include <bits/stdc++.h>

using namespace std;

typedef long double LD;

typedef pair<LD, LD> PDD;

const LD eps = 1e-6;

int main()
{
	int n, m, k; scanf("%d %d %d", &n, &m, &k);
	vector<int> a(k + 1), vis(n + 1);
	for (int i = 1; i <= k; i++)
		scanf("%d", &a[i]), vis[a[i]] = 1;

	vector<PDD> suf(n + m + 1, {0.0, 0.0}), f(n + 1);
	for (int i = n - 1; i >= 0; i--)
	{
		if (vis[i]) f[i] = (PDD){1.0, 0.0};
		else f[i] = (PDD){(suf[i + 1].first - suf[i + m + 1].first) / m,
						 (suf[i + 1].second - suf[i + m + 1].second) / m + 1.0};
		suf[i] = (PDD){suf[i + 1].first + f[i].first, suf[i + 1].second + f[i].second};
	}

	if (abs(f[0].first - 1.0) < eps) printf("-1\n");
	else printf("%.10Lf\n", f[0].second / (1.0 - f[0].first));

	return 0;
}

#include <iostream>
#include <stack>
#include <string>
#include <vector>
#pragma warning(disable:4996)
using namespace std;
#define int long long
stack<int>way;
int N,M,K;
double ex[200100];
double ep[200100];
double epex[200100];
vector<pair<int, int>>x;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin >> N>>M >> K;
	int i;
	for (i = 0; i < K; i++)
	{
		int a;
		cin >> a;
		ep[a] = 1;
	}
	for (i = N; i <= N + M; i++)
	{
		ex[i] = 0;
	}
	double curex = 0, curep = 0,expex=0;
	for (i = N - 1; i >= 0; i--)
	{
		int isb = ep[i] >= 0.99999999;
		if (isb)
			goto T;
		ep[i] = curep;

		if (ep[i] <=0.999999999)
		{
			ex[i] = ((curex))/(M-curep*M)+1;
			if(curep>0)
				epex[i] = expex / (curep*M)+1;
		}
		else
		{
			if (!isb)
			{
				if (curep > 0)
					epex[i] = expex / (curep*M) + 1;
			}
		}
		T:
		curex -= ex[i + M]*(1-ep[i+M]);
		curep -= ep[i + M]/M;
		expex -= epex[i + M]*ep[i+M];
		curex += ex[i]*(1-ep[i]);
		curep += ep[i]/M;
		expex += epex[i]*ep[i];
	}
	i = 0;
	if (ep[i] >= 0.99999999)
		cout << -1;
	else
	{
		cout << ((1 - ep[i]) * ex[i] +epex[i]*ep[i]) / (1 - ep[i]);
	}
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i=((n)-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    int ans=0;
    rep(i,n){
        cin>>a[i];
        ans+=max(0,a[i]-10);
    }
    cout<<ans;
}

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

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) {
		ci += 9;
		return 10000000;
	}
	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;
	return tmp;
}

const int MAX = 10000;
char C[MAX * 5];
char *dn = cn, * di = dn, * owad = dn + CM - 20;
void putint(ll A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (A >= 10000000000000000) {
		if (A >= 100000000000000000) dig = 2;
		memcpy(di + 12 + dig, C + A % 10000 * 5, 5);
		A /= 10000;
		memcpy(di + 8 + dig, C + A % 10000 * 5, 4);
		A /= 10000;
		memcpy(di + 4 + dig, C + A % 10000 * 5, 4);
		A /= 10000;
		memcpy(di + dig, C + A % 10000 * 5, 4);
		memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
		di += 17 + dig;
	}
	else if (A >= 100000000) {
		if (A >= 1000000000000) {
			if (A >= 1000000000000000) dig = 4;
			else if (A >= 100000000000000) dig = 3;
			else if (A >= 10000000000000) dig = 2;
			memcpy(di + 8 + dig, C + A % 10000 * 5, 5);
			A /= 10000;
			memcpy(di + 4 + dig, C + A % 10000 * 5, 4);
			A /= 10000;
			memcpy(di + dig, C + A % 10000 * 5, 4);
			memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
			di += 13 + dig;
		}
		else {
			if (A >= 100000000000) dig = 4;
			else if (A >= 10000000000) dig = 3;
			else if (A >= 1000000000) dig = 2;
			memcpy(di + 4 + dig, C + A % 10000 * 5, 5);
			A /= 10000;
			memcpy(di + dig, C + A % 10000 * 5, 4);
			memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
			di += 9 + dig;
		}
	}
	else {
		if (A >= 10000) {
			if (A >= 10000000) dig = 4;
			else if (A >= 1000000) dig = 3;
			else if (A >= 100000) dig = 2;
			memcpy(di + dig, C + A % 10000 * 5, 5);
			memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
			di += 5 + dig;
		}
		else {
			if (A >= 1000) dig = 4;
			else if (A >= 100) dig = 3;
			else if (A >= 10) dig = 2;
			memcpy(di, C + A * 5 + 4 - dig, dig + 1);
			di += 1 + dig;
		}
	}
}
int A[200001];
ll S[200001];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	rep(i, MAX) {
		int X = i;
		rep(j, 4) {
			C[i * 5 + 3 - j] = '0' + X % 10;
			X /= 10;
		}
		C[i * 5 + 4] = '\n';
	}

	int N = getint();
	rep1(i, N) {
		A[i] = getint();
		S[i] = S[i - 1] + A[i];
		if (A[i - 1] > A[i]) A[i] = A[i - 1];
	}
	rep1(i, N - 1) S[i + 1] += S[i];

	rep1(i, N) putint(A[i] * ll(i) + S[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#include<fstream>
#define INF long long (int)1e18+1
#define MAX 50000001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	long long n;
	cin >> n;
	vector<long long>a;
	n *= 2;
	rep(i, 1, 1500000) {
		if ((long long)i * (long long)i > n)break;
		if (n % i == 0) {
			a.push_back(i);
			if ((long long)i * (long long)i == n)continue;
			a.push_back(n / i);
		}
	}
	long long ans = 0;
	for (auto x : a) {
		long long s = n / x;
		if ((s - (x - 1)) % 2 == 0)ans++;
	}
	cout << ans << endl;
}

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

int main(){
  string S;
  cin >> S;
  int ans=0;
  for(int i=0; i<9; i++){
    if(S.at(i)=='Z' && S.at(i+1)=='O' && S.at(i+2)=='N' && S.at(i+3)=='e'){
      ans++;
    }
  }
  cout << ans;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    long long n;
    cin >> n;
    const long long MAX_B = log2(n);
    long long min_abc = n;
    for(long long b = 0; b <= MAX_B; ++b) {
        long long a = n / (long long)pow(2, b);
        long long c = n % (long long)pow(2, b);
        min_abc = min(min_abc, a + b + c);
    }
    cout << min_abc << endl;
    return 0;
}

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

int main(){
    string a;
    cin>>a;
    int index=0;
    int flag=0;
    for(int i=0;a[i]!='\0';i++){
        if(a.at(i) == '.'){
            index=i;
            flag=1;
        }
    }
    if(!flag)cout<<a<<endl;
    else{
        for(int i=0;i<index;i++){
            cout<<a.at(i);
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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

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

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
set<ll> solve(vl A) {
    int N = sz(A);
    set<ll> res;
    F0R(m, 1 << N) {
        ll cur = 0;
        F0R(i, N) {
            if (m & (1 << i)) {
                cur += A[i];
            }
        }
        res.ins(cur);
    }
    return res;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

    int N; cin >> N; ll T; cin>>T;
    ll A[N]; F0R(i, N) cin >> A[i];
    int bp = N/2;
    vl B, C;
    F0R(i, N/2) B.pb(A[i]);
    FOR(i, N/2, N) C.pb(A[i]);
    set<ll> X = solve(B), Y = solve(C);
    ll ans = T;
    trav(a, X) {
        auto it = Y.ub(T-a);
        if (it == Y.begin()) continue;
        it--;
        ckmin(ans, T - a - *it);
    }
    cout << T-ans << nl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;

using Array = vector<ll>;
using Matrix = vector<Array>;

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

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

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

struct Edge {
    ll to, cap, rev;

    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll) G[to].size()));
    if (revFlag)
        G[to].push_back(Edge(from, revCap, (ll) G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n - 1), b(n - 1);
    Graph g(n);
    REP(i, n - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        add_edge(g, a[i], b[i], 1, true, 1);
    }

    vec<ll> d(n, 0);
    auto dfs = [&](auto &&self, ll v, ll p)->void {
        for (auto e:g[v]) {
            if (e.to == p) continue;
            d[e.to] = d[v] + 1;
            self(self,e.to,v);
        }
    };
    dfs(dfs, 0, -1);

    ll q;
    cin >> q;
    vec<ll> dp(n, 0);
    ll sum = 0;
    while (q--) {
        ll t, e, x;
        cin >> t >> e >> x;
        e--;
        if (t == 1) {
            if (d[a[e]] < d[b[e]]) {
                dp[b[e]] -= x;
                sum += x;
            } else {
                dp[a[e]] += x;
            }
        } else {
            if (d[b[e]] < d[a[e]]) {
                dp[a[e]] -= x;
                sum += x;
            } else {
                dp[b[e]] += x;
            }
        }
    }

    vec<ll> ans(n, 0);
    auto dfs2 = [&](auto &&self, int v, int p) -> void {
        ans[v] += dp[v];
        for (auto e:g[v]) {
            if (e.to == p) continue;
            dp[e.to] += dp[v];
            self(self, e.to, v);
        }
    };
    dp[0] += sum;
    dfs2(dfs2, 0, -1);
    REP(i, n) cout << dp[i] << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    REP(i, t - 1) {
        solve();
    }*/

    solve();

    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define f first
#define s second
#define pii pair<int,int>

const int N =3e5+5;
const int MOD = 1e9+7;
const ll M = 1e18;

ll qpow(ll a, ll b, ll m)
{
    ll  ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

vector<pii>adj[400005];
bool vis[400005];
bool graph = false;
set<int>ver;

void dfs(int v, int par, int edge_n){
    if(par>0){
        if(vis[v]){
            graph = true;
            return;
        }
    }
    if(vis[v]) return;
    ver.insert(v);
    vis[v] = true;
    for(pii p:adj[v]){
        int u = p.f, edg = p.s;
        if(u!=par){
            dfs(u, v, edg);
        }
    }
}

int main()
{
	IOS;

	int t=1; //cin>>t;
	while(t--){
	   int n; cin>>n;
	   int a,b;
	   set<int>ss;
	   for(int i=0;i<n;i++){
	       cin>>a>>b;
	       ss.insert(a);
	       ss.insert(b);
	       adj[a].push_back(make_pair(b,i));
	       adj[b].push_back(make_pair(a,i));
	   }
	   int ans = 0;
	   for(auto it = ss.begin();it!=ss.end();it++){
	       ver.clear();
	       int k = *it;
	       if(vis[k]==0){
	           graph = false;
	           dfs(k,0,0);
	           if(graph)
	             ans += ver.size();
	           else ans+= ver.size()-1;
	       }
	   }
	   cout<<ans;

	   cout<<endl;
    }

}

#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=4e5;
typedef int fuko[yuzu|10];
fuko fa,sz;
struct dsu {
  int find(int x) {
    return fa[x]?fa[x]=find(fa[x]):x;
  }
  int mg(int u,int v) {
    u=find(u),v=find(v);
    if (sz[u]&&sz[v]) return 0;
    u^v?fa[u]=v,sz[v]|=sz[u]:sz[u]=1;
    return 1;
  }
}zw;
int main() {
  int n,i,a,b,lxy=0;
  read(n);
  for (i=1;i<=n;++i) lxy+=zw.mg(read(),read());
  printf("%d\n",lxy);
}


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

#define ll long long
#define mod 1000000007
#define inf 9223372036854775807
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll powe(ll n,ll r)
{if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}
ll globe=0;

void solution() {
    char s,t;
    cin>>s>>t;
    if(s=='Y'){
        ll x=t-97;
        char a='A';
        a=a+x;
        cout<<a<<endl;
    }
    else{
        cout<<t<<endl;
    }
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll T=1;
    //cin>>T;
    while(T--) {
        solution();
    }

    return 0;
}

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

#define INF 1000000000

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int ans;
    if (a+b>=15 && b>=8) {
        ans = 1;
    }
    else if (a+b>=10 && b>=3) {
        ans = 2;
    }
    else if (a+b>=3) {
        ans = 3;
    }
    else {
        ans = 4;
    }
    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 61;
const ll mod =998244353;

int n;
VI g[100005];
VI c(100005);
VB used_color(100005, false);
VI ans;

VB used(100005, false);

void dfs(int pre, int now) {
	for (int i : g[now]) {
		//cout << i << endl;
		if (used[i])continue;
		//if (i == pre)continue;
		bool check = false;
		if (used_color[c[i]])check = true;
		//cout << i << endl;
		used_color[c[i]] = true;
		if(!check)ans.push_back(i);
		used[i] = true;
		dfs(now, i);
		if(!check)used_color[c[i]] = false;
	}
}

int main() {

	cin >> n;
	REP(i, n)cin >> c[i];
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	used_color[c[0]] = true;
	used[0] = true;
	dfs(-1, 0);

	sort(ALL(ans));
	cout << 1 << endl;
	for (int i : ans) {
		cout << i + 1 << endl;
	}

}

/*

  AUTHOR:    nit1n
  CREATED:   12.04.2021 22:51:16

*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;
const int N = 1e5 +5 ;
vector<int> gr[N] ;
vector<int> a(N) , ans;
void dfs(int i , int prev , map<int,int>& mp){

	if(mp[a[i]] == 0){
		ans.push_back(i) ;
	}
	mp[a[i]]++ ;
	for(auto & j : gr[i]){
		if(j == prev) continue;
		dfs(j , i , mp) ;

	}
	mp[a[i]]-- ;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ;
	cin >> n ;
	for(int i = 1 ; i <= n ; ++i){
		cin >> a[i] ;
	}
	for(int i = 0; i < n -1 ; ++i){
		int u , v;
		cin >> u >> v;
		gr[u].push_back(v) ;
		gr[v].push_back(u) ;
	}

	map<int,int> mp ;
	dfs(1 , -1 , mp) ;
	sort(ans.begin(), ans.end()) ;
	for(auto & i : ans){
		cout << i << '\n' ;
	}

}


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

const ll mod = 998244353;

long long modpow(long long a, long long x) {
    long long tmp = x;
    long long val = a;
    long long ret = 1LL;
    while (tmp>0) {
        if (tmp%2 == 1) ret = ret*val%mod;
        val = val*val%mod;
        tmp /= 2;
    }
    return ret;
}

int N;
vector<int> f;
ll cycles = 0;
map<int, int> mp;
ll cnt = 0;

void dfs(int idx) {
	if (mp.count(idx) > 0) {
		if (mp[idx] != cnt) return;
		cycles++;
	} else {
		mp[idx] = cnt;
		dfs(f[idx]-1);
	}
	return;
}

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

	cin >> N;
	f = vector<int>(N);
	for (int i=0;i<N;i++) cin >> f[i];

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

	cout << modpow(2LL, cycles)-1 << "\n";
	return 0;
}

#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const ll mod=998244353;
int f[maxn],sz[maxn];
int find(int x)
{
    return f[x]==x?x:f[x]=find(f[x]);
}
bool merge(int u,int v)
{
    int u_=find(u),v_=find(v);
    if(u_==v_) return false;
    if(sz[u_]>sz[v_]) swap(u_,v_);
    sz[v_]+=sz[u_]; f[u_]=v_;
    return true;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
        sz[i]=1;
    }
    int times=n;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        times-=merge(x,i);
    }
    ll ans=1;
    for(int i=1;i<=times;i++)
        ans=ans*2%mod;
    ans-=1; ans+=(ans<0)*mod;
    printf("%lld\n",ans);
    return 0;
}
/*
2
2 1

2
1 1

3
1 2 3
 */


#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (ll &a : A) cin >> a;

    vector<ll> sum(N + 1), mxS(N + 1);
    for (int i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + A[i];
    }
    for (int i = 0; i < N; i++) {
        mxS[i + 1] = mxS[i];
        mxS[i + 1] = max(mxS[i + 1], sum[i]);
    }

    ll cur = 0, mx = 0;
    for (int i = 1; i <= N; i++) {
        mx = max(mx, cur + mxS[i]);
        cur += sum[i];
    }
    cout << max(mx, cur) << '\n';
}

/*ver 7*/
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : v)
#define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
    init();
    inl(n);
    ll ans=0;
    reps(i,1,1e7){
        ll cnt=0;
        ll tmp=i;
        while(tmp>0){
            tmp/=10;
            cnt++;
        }
        ll now=i*pow(10,cnt)+i;
        if(now<=n){
            //out(now);
            ans++;
        }
    }
    out(ans);
    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template <typename T>
class BIT {
   public:
    BIT(int n) : N(n), A(n + 1, 0) {}

    T sum(int i) {
        T res = 0;
        while (i > 0) {
            res += A[i];
            i -= i & (-i);
        }
        return res;
    }

    T sum(int i, int j) {
        return sum(j) - sum(i - 1);
    }

    void add(int i, T x) {
        while (i <= N) {
            A[i] += x;
            i += (i & (-i));
        }
    }

   private:
    int N;
    vector<T> A;
};

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    REP(i, 0, N) cin >> A[i];
    REP(i, 0, N) cin >> B[i];

    map<int, set<int>> ml, mr;
    REP(i, 0, N) mr[A[i] + i].insert(i);

    BIT<int> bit(N);

    ll ans = 0;
    REP(i, 0, N) {
        // cout << "# i : " << i << ", B[i] : " << B[i] << endl;
        int idx = -1;
        if (ml.count(B[i] + i) && !ml[B[i] + i].empty()) {
            auto itr = ml[B[i] + i].begin();
            idx = *itr;
            ml[B[i] + i].erase(itr);
        } else if (mr.count(B[i] + i) && !mr[B[i] + i].empty()) {
            auto itr = mr[B[i] + i].begin();
            idx = *itr;
            mr[B[i] + i].erase(itr);
        }

        if (idx == -1) {
            cout << -1 << endl;
            return 0;
        }
        // cout << "--> idx : " << idx << endl;

        if (mr[A[i] + i].count(i)) {
            mr[A[i] + i].erase(i);
            ml[A[i] + i].insert(i);
        }

        ans += bit.sum(idx + 1, N);
        bit.add(idx + 1, 1);
    }
    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 400010, inf = 1e9 + 7;

int n, v[MAX_N];

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n + n;++i)
		cin >> v[i];

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

	ll res = 0;

	for (int l = n, r = n+1;l >= 1;--l, ++r) {
		res += max(v[l], v[r]);

		int pqv = pq.size() ? pq.top() : inf;

		if (pqv < min(v[l], v[r])) {
			pq.pop();
			res -= pqv - min(v[l], v[r]);
			pq.push(min(v[l], v[r]));
		}

		pq.push(max(v[l], v[r]));
	}

	cout << res << '\n';
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <unordered_set>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <climits>
#include <random>
#include <queue>
#include <array>
//#include <fstream>
/*#include <cstdio>
#include <ctime>*/
#include <complex>

using namespace std;

#define f first
#define s second
const int mxN = 100005;
/*Problem:  */
void solve() {}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	//freopen("pairup.in", "r", stdin);
	//freopen("pairup.out", "w", stdout);
	//int t = 1; cin >> t;  while (t--) solve();

	int n; cin  >> n;
	vector<bool> b(n + 1);
	bool ans = true;
	for (int x, i = 0; i < n; ++i)
	{
		cin >> x;
		if (!b[x]) b[x] = true;
		else ans &= false;
	}
	for (int i = 1; ans && i <= n; ++i)
		ans &= b[i];
	cout << (ans ? "Yes\n" : "No\n");
	return 0;
}

#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

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

    unsigned long long chebyshev_distance = 0;
    unsigned long long sum = 0;
    unsigned long long sum2 = 0;
    for(int i = 0; i < N; i++) {
        long long x;
        cin >> x;
        if(x < 0) {
            x = -x;
        }
        if(x > chebyshev_distance) {
            chebyshev_distance = x;
        }
        sum += x;
        sum2 += x * x;
    }

    printf("%llu\n%.10f\n%llu\n", sum, sqrt(sum2), chebyshev_distance);

    return 0;
}


///*    ***Bismillahir Rahmanir Rahim***   */
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define	       MEM(a,b)         memset(a,(b),sizeof(a))
#define	       CLR(p)           memset(p,0,sizeof(p))
#define rep(i,b) for(ll i=0;i<(b);i++)
#define rep1(i,b) for(int i=1;i<=(b);i++)
//#define rep(s,e)         for(i=s;i<e;i+=1)
//#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep2(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
#define	       ff               first
#define	       sc              second
#define     print(v)        for(ll i:v) cout<<i<<ss
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.first != b.first) return a.first > b.first;
    else
    return a.second > b.second;
}
//ll minelementindex = min_element(v.begin(),v.end()) - v.begin();
//ll minelement = *min_element(v.begin(), v.end());
//ll maxelementindex = max_element(v.begin(),v.end()) - v.begin();
//ll maxelement = *max_element(v.begin(), v.end());
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
// string x(w.size(),'1');
#define MAX 1000005
#define precision(a) fixed << setprecision(a)

#define mod 1000000007
ll ar[MAX];

// Function to calculate sum of absolute difference
// of all pairs in array
// arr[]  --> array of elements
ll sumPairs(ll arr[],ll n)
{
    // final result
    ll sum = 0;
    for (ll i=n-1; i>=0; i--)
        sum += i*arr[i] - (n-1-i)*arr[i];
    return sum;
}

// Driver program to run the case

int main()
{
 //O_O ;
 ll n;cin>>n;
 for(ll i=0;i<n;i++) cin>>ar[i];
 sort(ar,ar+n);

     cout << sumPairs(ar, n);

    return 0;
}

//https://codeforces.com/contest/1371/problem/D korte hbe
//https://codeforces.com/contest/1256/problem/B implementation pari nai
/*****************  ALHAMDULILLAH  *****************/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>

using ll = long long;
using ld = long double;
using namespace std;
using Graph = vector<vector<int>>;

// typedef pair<int,int> P;
#define teisu 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define INF 1e9

// int N;
// string S;
// map<int,int> cnt;
// map<char,vector<int>> keep_index;
// ll X,Y,A,B;
// ll ans = 0;
// ll dfs(ll strength,ll keikenti){
//     if(strength >= Y) return 0;

//     ans = max(ans,keikenti);
//     cout << strength << endl;
//     // cout << ans << endl;

//     dfs(strength*A,keikenti+1);

//     dfs(strength+B,keikenti+1);

//     return 0;
// }

ll N;
vector<ll> A;
int main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        int input;
        cin >> input;
        A.push_back(input);
    }

    sort(A.begin(),A.end(),greater<ll>());
    ll ans = 0;
    for(int i=0;i<N;i++){
        ans += (A[i]*(N-1-i)) - (A[i]*i);
    }
    cout << ans << endl;

    return 0;
}


#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <stack>
#include <queue>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}

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

	if(a+c > b ) cout << "Takahashi\n";
	else cout << "Aoki\n";

	return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define int long long int
int32_t main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(c==1)
    swap(a,b);

    if(a>b)
    {
        if(c==1)
        {
            cout<<"Aoki"<<endl;
        }
        else
        {
            cout<<"Takahashi"<<endl;
        }
    }
    else
    {
        if(c==0)
        {
            cout<<"Aoki"<<endl;
        }
        else
        {
            cout<<"Takahashi"<<endl;
        }
    }

    return 0;
}


#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a / gcd(a, b) * b;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template <class T>
void CVEC(const T &v) {
	int c = v.size() - 1;
	for (int i = 0; i < c; i++) cout << v[i] << ' ';
	if (c > -1) cout << v[c];
	cout << '\n';
}

#pragma endregion header

const int MAX_N = 205;

ll Com[MAX_N][MAX_N];

void init(){
    memset(Com,0,sizeof(Com));
    Com[0][0] = 1;
    for(int i = 1; i < MAX_N; ++i){
        Com[i][0] = 1;
        for(int j = 1; j < MAX_N; ++j){
            Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]);
        }
    }
}

ll nCk(int n, int k){
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return Com[n][k];
}

signed main(){
    int l; cin >>l;
	init();
	cout << nCk(l-1, 11) << endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
#define MAX_N 10000

using namespace std;

long long MOD = 1000000007*1000000007;

long long fact[MAX_N];
void factorial(int N){
    fact[0]=1;
    for(int i=0; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
}

map<long long, long long> inv;
long long inverse(long long x){
    if (inv.count(x)){
        return inv[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv[x]=ret;
    return ret;
}

long long comb(int a, int b){
    long long ret=fact[a]*inverse(fact[a-b])%MOD;
    return ret*inverse(fact[b])%MOD;
}

int main(){
    int L;
    cin >> L;
    L-=1;
    ll ans=1;

    ll tmp=2;
    for(ll i=L-10;i<=L;i++){
        ans*=i;
        while(ans%tmp==0 && tmp<12){
            ans/=tmp;
            tmp++;
        }
    }
    cout << ans << endl;
}