#include<bits/stdc++.h>
#define rg register
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
#define i60 long long
using namespace std ;
const int N = 2e5+10 , skc = 998244353 ;
int pre[N] , deg[N] , n , pi[N] ;
queue <int> q ;  bool is[N] ;
int f( int x ) { return pre[x] == x ? x : pre[x] = f(pre[x]) ; }
void merge( int x , int y ) {
  if( f(x) == f(y) ) return ;
  pre[f(x)] = f(y) ;
}
signed main( ) {
  ios::sync_with_stdio(false) ;
  cin.tie(0) ;
  cin >> n ; int x , y ;
  fp( i , 1 , n ) pre[i] = i ;
  fp( i , 1 , n ) cin >> x , pi[i] = x , merge( x , i ) , deg[x] ++ ;
  fp( i , 1 , n ) if( !deg[i] ) q.push(i) ;
  while( q.size() ) {
    x = q.front() ; q.pop() ; y = pi[x] ;
	deg[y] -- ; if( !deg[y] ) q.push(y) ;
  }
  int ans = 1 , tot = 0 ;
  fp( i , 1 , n ) if( deg[i] ) is[f(i)] = 1 ;
  fp( i , 1 , n ) tot += is[i] ;
  fp( i , 1 , tot ) ans = 2ll * ans % skc ;
  cout << (ans-1+skc)%skc << '\n' ;
  return 0 ;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);

int main() {
  int n, q;
  bool flip = false;
  string s;
  cin >> n >> s >> q;
  rep(i, q) {
    int t, a, b;
    cin >> t >> a >> b;
    a--; b--;

    if(t == 1) {
      if(flip) {
        if(a < n) {
          a += n;
        } else {
          a -= n;
        }
        if(b < n) {
          b += n;
        } else {
          b -= n;
        }
        auto tmp = s[a];
        s[a] = s[b];
        s[b] = tmp;
      } else {
        auto tmp = s[a];
        s[a] = s[b];
        s[b] = tmp;
      }
    } else {
      flip = !flip;
    }
  }

  if(flip) {
    cout << s.substr(n) + s.substr(0, n) << endl;
  } else {
    cout << s << endl;
  }
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) {
    if(n == 0) return 1;

    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


#include <bits/stdc++.h>

#define MOD 1000000007
#define PI (2*acos(0.0))
#define eps 1e-9

#define ff first
#define ss second
#define pb push_back
#define endl '\n'
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define debug(x) cout << (#x) << " is " << (x) << endl;
#define printv(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))

#define FORN(i, n) for(int i = ; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define SQ(a) (a)*(a)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;

ull mod = 1e9 + 7;
// ull mod = 998244353;

ull fact(ull n){
    ull ans = 1;
    for (ull i = 2; i <= n; i++)
        ans = ((ans%MOD) * (i%MOD) )%MOD;
    return ans;
}
ll powMod(ll base, ll exp){
    ll ans = 1;
    for (int i = 0; i < exp; i++)
    {
        ans*= base;
        ans %= mod;
    }
    return ans;
}
ll powMod(ll base, ll exp, ll md){
    ll ans = 1;
    for (int i = 0; i < exp; i++)
    {
        ans*= base;
        ans %= md;
    }
    return ans;
}

double solve(int D, int H, int d, int h){
    double slop = (double) (H - h)/(double) (D-d);
    double b = h - slop*d;
    return b;
}

void answer(){
    int n; cin >> n;
    int D, H; cin >> D >> H;
    vi d(n), h(n);
    double ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> d[i] >> h[i];
        ans = max(ans, solve(D, H, d[i], h[i]));
    }
    cout << ans;
}

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

    int t = 1;
    // cin >> t; cin.ignore();
    while (t--)
    {
        answer();
    }
    return 0;
}

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

#define ll long long
#define fo(i,a,b) for(int i=a; i<b; i++)
#define vi vector<int>
#define vii vector<int,int>
#define pi pair<int,int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

int main(){
	FASTIO

	double d,h;
	int n;
	cin>>n>>d>>h;
	double minslope = h/d;
	double x1,y1;
	double tslope;
	fo(i,0,n){
		cin>>x1>>y1;
		tslope = (h-y1)/(d-x1);
		minslope = min(minslope,tslope);
	}
	double ans =  h - minslope*d;
	cout<<ans;

	return 0;
}


#include<bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using lint = long long;
using ulint = unsigned long long;
template<class T>using graph = vector<vector<T>>;
#define endl '\n'
int const INF = 1<<30;
lint const INF64 = 1LL<<61;
lint const mod = 1e9+7;
//long const mod = 998244353;
lint ceilDiv(lint x, lint y){if(x >= 0){return (x+y-1)/y;}else{return x/y;}}
lint floorDiv(lint x, lint y){if(x >= 0){return x/y;}else{return (x-y+1)/y;}}
lint Sqrt(lint x){lint upper = 1e9;lint lower = 0;while(upper - lower > 0){lint mid = (1+upper + lower)/2;if(mid * mid > x){upper = mid-1;}else{lower = mid;}}return upper;}
lint gcd(lint a,lint b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
lint lcm(lint a,lint b){return (a / gcd(a,b)) * b;}
lint chmin(vector<lint>&v){lint ans = INF64;for(lint i:v){ans = min(ans, i);}return ans;}
lint chmax(vector<lint>&v){lint ans = -INF64;for(lint i:v){ans = max(ans, i);}return ans;}
double dist(double x1, double y1, double x2, double y2){return sqrt(pow(x1-x2, 2) + pow(y1-y2,2));}
vector<lint>prime;void makePrime(lint n){prime.push_back(2);for(lint i=3;i<=n;i+=2){bool chk = true;for(lint j=0;j<prime.size() && prime[j]*prime[j] <= i;j++){if(i % prime[j]==0){chk=false;break;}}if(chk)prime.push_back(i);}}

int main(){
    vector<int>v(100001,1);
    int tmp = 1;
    for(int i=1;i<=100000;i++){
        if(i < (1<<tmp))v[i] = tmp;
        else{
            tmp++;
            v[i] = tmp;
        }
    }
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)cout << v[i] << " ";
}

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

typedef pair<int,int>  pint;
typedef pair<ll,ll>    pll;
typedef vector<int>    vint;
typedef vector<ll>     vll;
typedef vector<string> vstr;
typedef vector<pint>   vpint;
typedef vector<pll>    vpll;

#define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vll2(v,n,m,init)  vector<vector<ll>>  v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vint var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vstr var(n); rep(i,n){cin >> var[i];}
#define ALL(var)         (var).begin(), (var).end()
#define sortall(var)     sort(ALL(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());

#define prt(var)         cout << (var) << "\n"
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
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;}
//----------------------------------------------------------------

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

    vint a(n+1, 1);
    for(int i=1; i<=n; i++){
        for(int j=2; i*j<=n; j++){
            if(a[i]==a[i*j]) a[i*j]++;
        }
    }

    // for(int i=1; i<n+1; i++){
    //     for(int j=1; j<n+1; j++){
    //         if(j%i==0 && j!=i && a[j]==a[i]) prt2(i, j);
    //     }
    // }

    //prtall(a);
    vint ans;
    rep(i,n){
        ans.push_back(a[i+1]);
    }

    prtall(ans);
}


/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Do not pray for an easy life, pray for the strength to endure a difficult one.
When something is important enough, you do it even if the odds are not in your favor.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.
No matter how hard it gets, NEVER GIVE UP*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
string longDivision(string number, int divisor)
{
    // As result can be very large store it in string
    string ans;

    // Find prefix of number that is larger
    // than divisor.
    int idx = 0;
    int temp = number[idx] - '0';
    while (temp < divisor)
        temp = temp * 10 + (number[++idx] - '0');

    // Repeatedly divide divisor with temp. After
    // every division, update temp to include one
    // more digit.
    while (number.size() > idx) {
        // Store result in answer i.e. temp / divisor
        ans += (temp / divisor) + '0';

        // Take next digit of number
        temp = (temp % divisor) * 10 + number[++idx] - '0';
    }

    // If divisor is greater than number
    if (ans.length() == 0)
        return "0";

    // else return ans
    return ans;
}
bool mul200(string n){
	int l=n.length();
	if(l<3){
		// cout<<"r\n";
		return false;
	}
	if(n[l-1]!='0'||n[l-2]!='0'){
		// cout<<"y\n";
		return false;
	}
	if(n[l-3]&1){
		// cout<<"u\n";
		return false;
	}
	return true;

}
void solve(){
	ll n;
	cin>>n;
	ll a[n];
	map<ll,ll> mp;
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=mp[a[i]%200];
		mp[a[i]%200]++;
	}
	cout<<sum<<"\n";
}
int main(){
// 	ios::sync_with_stdio(false);
// 	cout.tie(0);
// 	cin.tie(NULL);
	int t;
	// cin>>t;
	t=1;
    while(t--) {
    	// int n;
    	// cin>>n;
    	solve();
	}
}

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

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define PI 3.14159265358979323

using namespace std;

vector<ll>gr[200010];
bool vis[200010]={0};
ll ans=0;

void dfs(ll s){
    vis[s]=0;
    for(auto it:gr[s]) if(vis[it]) dfs(it);
}

int main() {

fio;
int TC=1;
//cin>>TC;
    while(TC--){

        ll n;
        cin>>n;
        ll a[n];

        for(ll i=0;i<n;i++) {
            cin>>a[i];
            if(!vis[a[i]]){
                vis[a[i]]=true;
                ans++;
            }
        }

        for(ll i=0;i<n;i++){
            if(a[i]!=a[n-i-1]){
                gr[a[i]].pb(a[n-i-1]);
                gr[a[n-i-1]].pb(a[i]);
            }
        }

        for(ll i=0;i<200001;i++){
            if(vis[i]){
                dfs(i);
                ans--;
            }
        }

        cout<<ans<<"\n";

    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
const double pi = 3.14159265358979;
const int inf = 1e13;
#define pii pair<int,int>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define rrep(...) overload(__VA_ARGS__,_null,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
struct Edge { int to, cost; Edge(int to, int cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }

void Main(){
    int n, t, ans = 0;
    cin >> n >> t;
    vector<int> a, b, sum_a, sum_b;
    rep(n){
        int input;
        cin >> input;
        if(i % 2) a.push_back(input);
        else b.push_back(input);
    }
    rep(bit, 1 << a.size()){
        int temp = 0;
        rep(a.size()) if(bit >> i & 1) temp += a[i];
        sum_a.push_back(temp);
    }
    rep(bit, 1 << b.size()){
        int temp = 0;
        rep(b.size()) if(bit >> i & 1) temp += b[i];
        sum_b.push_back(temp);
    }
    sort(all(sum_a));
    for(auto x : sum_b){
        int temp = t - x;
        int ind = upper_bound(all(sum_a), temp) - sum_a.begin() - 1;
        if(ind == -1) continue;
        chmax(ans, sum_a[ind] + x);
    }
    cout << ans << endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    //int n; cin >> n; rep(n)
    Main();
}

#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<map>

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

bool is_prime(int x){
if(x<=1) return false;
for(int i=2;i*i<x;i++){
    if(x%i==0) return false;}
return true;}

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

using namespace std;
int main(){
    int n;
    cin>>n;

    double x[n],y[n];
    rep(i,n) cin>>x[i]>>y[i];
    int ans=0;

    rep(i,n)rep(j,n){
        if(i==j)continue;

        if((y[i]-y[j])/(x[i]-x[j])>=-1 and (y[i]-y[j])/(x[i]-x[j])<=1){
          ans++;
        }
    }

    cout << ans/2 << endl;

}


#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int solve(int n){
	if (n == 0)
		return 0;
	vector <int> digits;
	while (n){
		digits.pb(n % 10);
		n /= 10;
	}
	sort(digits.begin(), digits.end());
	int small = 0;
	int i = 0;
	n = digits.size();
	while (!digits[i] and i < n)
		++i;
	while (i < n){
		small = small * 10 + digits[i++];
	}
	reverse(digits.begin(), digits.end());
	int big = 0;
	for (int a : digits)
		big = big * 10 + a;
	return big - small;
}
int main() {
	int n, k;
	cin >> n >> k;
	int ans[k + 1];
	ans[0] = n;
	for (int i = 1; i <= k; ++i)
		ans[i] = solve(ans[i - 1]);
	cout << ans[k] << endl;
}

//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
#define mk make_pair
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b;
    a=read(), b=read();
    printf("%lld %lld\n",(a+b)/2,a-(a+b)/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
	x=0;char ch=getchar();bool f=false;
	while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return ;
}
template <typename T>
inline void write(T x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10^48);
	return ;
}
#define ll long long
const int N=2e5+5,M=1e8;
int n,m,q;
ll a[N],b[N];
struct SGTree{
	int cur,root;
	ll sum[N*80];
	int num[N*80],ls[N*80],rs[N*80];
	void Modify(int &x,int l,int r,int pos,int v,int tp){
		if(!x) x=++cur;
		int mid=l+r>>1;sum[x]+=v*tp;num[x]+=tp;
		if(l==r) return ;
		if(pos<=mid) Modify(ls[x],l,mid,pos,v,tp);
		else Modify(rs[x],mid+1,r,pos,v,tp);
		return ;
	}
	ll QuerySum(int x,int l,int r,int ql,int qr){
		if(ql>qr||!x) return 0;
		if(ql<=l&&r<=qr) return sum[x];
		int mid=l+r>>1;ll res=0;
		if(ql<=mid) res+=QuerySum(ls[x],l,mid,ql,qr);
		if(qr>mid) res+=QuerySum(rs[x],mid+1,r,ql,qr);
		return res;
	}
	int QueryNum(int x,int l,int r,int ql,int qr){
		if(ql>qr||!x) return 0;
		if(ql<=l&&r<=qr) return num[x];
		int mid=l+r>>1,res=0;
		if(ql<=mid) res+=QueryNum(ls[x],l,mid,ql,qr);
		if(qr>mid) res+=QueryNum(rs[x],mid+1,r,ql,qr);
		return res;
	}
}t1,t2;
ll Ans;
int main(){
	read(n),read(m),read(q);
	for(int i=1;i<=n;i++) t1.Modify(t1.root,0,M,a[i],a[i],1);
	for(int i=1;i<=m;i++) t2.Modify(t2.root,0,M,b[i],b[i],1);
//	for(int i=1;i<=n;i++){
//		Ans+=1ll*t2.QueryNum(t2.root,0,M,1,a[i])*a[i];
//		Ans+=1ll*t2.QuerySum(t2.root,0,M,a[i]+1,M);
//	}
	for(int i=1;i<=q;i++){
		int op,pos;ll v;
		read(op),read(pos),read(v);
		if(op==1){
			Ans-=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos];
			Ans-=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M);
			t1.Modify(t1.root,0,M,a[pos],a[pos],-1);

			a[pos]=v;
			Ans+=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos];
			Ans+=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M);
			t1.Modify(t1.root,0,M,a[pos],a[pos],1);
		}
		else{
			Ans-=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos];
			Ans-=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M);
			t2.Modify(t2.root,0,M,b[pos],b[pos],-1);
			b[pos]=v;
			Ans+=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos];
			Ans+=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M);
			t2.Modify(t2.root,0,M,b[pos],b[pos],1);
		}
		write(Ans),putchar('\n');
	}
	return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define get_pos(u,x) int(lower_bound(all(u),x)-begin(u))

using namespace std;
using ll = int_fast64_t;
const int inf = 1e9;
const int mod = 1000000007;
const ll INF = 1e18;
const int maxn = 200025;

struct Fenwick {
    ll b[maxn];
    void add(int p, int d) {
        for (++p; p < maxn; p += p & -p)
            b[p] += d;
    }
    ll query(int p) {
        ll r = 0;
        for (++p; p > 0; p -= p & -p)
            r += b[p];
        return r;
    }
} cnt_a, cnt_b, sum_a, sum_b;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<tuple<int,int,int>> Qs(q);
    vector<int> u;
    u.pb(0);
    for (auto &[t, x, y]: Qs) cin >> t >> x >> y, u.pb(y), --x;
    sort(all(u)), u.erase(unique(all(u)), u.end());
    vector<int> a(n), b(m);

    auto calc = [&](int val, Fenwick &cnt, Fenwick &sum) {
        int pos = get_pos(u, val);
        return val * cnt.query(pos - 1) + (sum.query(maxn - 2) - sum.query(pos - 1));
    };
    ll ans = 0;
    cnt_a.add(get_pos(u, 0), n);
    cnt_b.add(get_pos(u, 0), m);
    for (auto [t, x, y]: Qs) {
        if (t == 1) {
            cnt_a.add(get_pos(u, a[x]), -1);
            sum_a.add(get_pos(u, a[x]), -a[x]);
            ans -= calc(a[x], cnt_b, sum_b);
            a[x] = y;
            ans += calc(a[x], cnt_b, sum_b);
            cnt_a.add(get_pos(u, a[x]), 1);
            sum_a.add(get_pos(u, a[x]), a[x]);
        } else {
            cnt_b.add(get_pos(u, b[x]), -1);
            sum_b.add(get_pos(u, b[x]), -b[x]);
            ans -= calc(b[x], cnt_a, sum_a);
            b[x] = y;
            ans += calc(b[x], cnt_a, sum_a);
            cnt_b.add(get_pos(u, b[x]), 1);
            sum_b.add(get_pos(u, b[x]), b[x]);
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+11;
typedef pair<int,int> PII;
struct q{
    int x,y,num;
}a[N],c[8];

struct w{
    int x,y,num;
}b[N];
int st[8],number[200];
unordered_map<int,int>m;
bool cmp1( q a, q b)
{
    return a.x<b.x;
}
bool cmp2( w a, w b)
{
    return a.y<b.y;
}
int main()
{
    int n;
    cin>>n;
    int i,j;
    for(i=0;i<n;i++)
    {
        int x1,y1;
        scanf("%d%d",&x1,&y1);
        a[i].x=b[i].x=x1;
        a[i].y=b[i].y=y1;
        a[i].num=b[i].num=i;
    }
    sort(a,a+n,cmp1);
    sort(b,b+n,cmp2);
    c[0]=a[0];
    c[1]=a[1];
    c[2]=a[n-2];
    c[3]=a[n-1];
    c[4]={b[0].x,b[0].y,b[0].num};
    c[5]={b[1].x,b[1].y,b[1].num};
    c[6]={b[n-2].x,b[n-2].y,b[n-2].num};
    c[7]={b[n-1].x,b[n-1].y,b[n-1].num};
    int idx=0,pos=0;

    //   for(i=0;i<8;i++)
    // {
    //     printf("%d %d\n",c[i].x,c[i].y);
    // }

    for(i=0;i<8;i++)
    {
        if(m.count(c[i].num)>=1)st[i]++;
        m[c[i].num]++;
    }

    for(i=0;i<8;i++)
    {
        if(st[i])idx++;
        else c[pos++]=c[i];
    }

    idx=8-idx;
    pos=0;
    sort(c,c+idx,cmp1);

    for(i=0;i<idx;i++)
    {
       for(j=i+1;j<idx;j++)
       {
           number[pos++]=max(abs(c[i].x-c[j].x),abs(c[i].y-c[j].y));
       }
    }
    // for(i=0;i<idx;i++)
    // {
    //     printf("%d %d\n",c[i].x,c[i].y);
    // }

    sort(number,number+pos);
    // for(i=0;i<pos;i++)
    // {
    //     printf("%d \n",number[i]);
    // }

    cout<<number[pos-2];
    return 0;
}

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

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

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

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

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--;
    g[x].pb(y);
    g[y].pb(x);
  }
}
int lim=1e5 +13;
vector<bool> col;
vector<int> c;
vector<vector<int>> g;
int cnt;
vector<int> ans;
void dfs(int r,int p=-1)
{

   for(auto a:g[r])
   {
     if(a==p)
      continue;
     if(!col[c[a]])
     {
      cnt++;
      ans.pb(a);
     }
     bool old= col[c[a]];
     col[c[a]]=true;
     dfs(a,r);
     col[c[a]]=old;
   }
}
void solve()
{
 int n ;
 cin >> n;
 c=vector<int>(n);
 g=vector<vector<int>>(n);
 for(int i=0;i<n;i++) cin >> c[i];
  for(int i=0;i<n-1;i++)
  {
     int x,y;
     cin >>x >> y ;
     x--,y--;
     g[x].pb(y);
     g[y].pb(x);
  }

col=vector<bool>(lim,false);
col[c[0]]=true;
cnt=0;
ans.clear();
ans.pb(0);
dfs(0);
sort(ans.begin(),ans.end());
for(int i=0;i<si(ans);i++) cout << 1+ans[i] << endl;
// cout << cnt << endl;
}

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

}


#include <bits/stdc++.h>
using namespace std;
string s;
int cnt = 0;
char a[4];
set<char> o, x;
void dfs(int depth)
{
	if (depth > 3)
	{
		bool flag = true;
		for (char c : o)
		{
			if (0 == count(a, a + 4, c))
			{
				flag = false;
				break;
			}
		}
		if (flag)
		{
			for (char c : x)
			{
				if (count(a, a + 4, c))
				{
					flag = false;
					break;
				}
			}
		}
		cnt += flag;
		return;
	}
	for (int i = 0; i < 10; ++i)
	{
		a[depth] = '0' + i;
		dfs(depth + 1);
	}
}
int main()
{
	cin >> s;
	for (int i = 0; i < 10; ++i)
	{
		if ('o' == s[i])
		{
			o.insert('0' + i);
		}
		else if ('x' == s[i])
		{
			x.insert('0' + i);
		}
	}
	if (count(s.begin(), s.end(), 'o') > 4)
	{
		cout << 0 << endl;
	}
	else
	{
		dfs(0);
		cout << cnt << endl;
	}
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n)  for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
int INF =1001001001;
int main()
{
string s;
cin>>s;
int n=s.size();
vector<int>c(3);
rep(i,n)c[(s[i]-'0')%3]++;

int sum=0;
rep(i,3)sum+=c[i]*i;
int ans =INF;
rep(i1,3)rep(i2,3)
{
if(c[1]<i1)continue;
if(c[2]<i2)continue;
if(i1+i2==n)continue;

int temp=sum;
temp-=(1*i1+2*i2);
if(temp%3==0)ans=min(ans,i1+i2);

}
if(ans==INF)ans =-1;
cout <<ans;
return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    int sum;
    sum=((7-a)+(7-b)+(7-c));
    cout << sum;
}
int main()
{
ios;
solve();
return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long int bpow(long long int a,long long int b)
{
    if(b==0)
    return 1;
    long long int res=bpow(a,b/2);
    if(b%2)
    return res*res*a;
    else
    return res*res;
}
long long int bpowm(long long int x,long long int y,long long int m)
{
    long long int res=1;
    x=x%m;
    if (x==0)
    return 0;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%m;
        y=y>>1;
        x=(x*x)%m;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<21-a-b-c<<endl;
	// your code goes here
	return 0;
}


// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
const ll INF = (1LL << 62) - 1;
vector<ll> dijkstra(vector<vector<pair<ll, pair<ll, ll>>>> &G, ll v)
{
    vector<ll> ans(G.size(), INF);
    ans[v] = 0;
    priority_queue<pair<ll, ll>> que;
    que.push({0, v});
    while (!que.empty())
    {
        auto [x, u] = que.top();
        que.pop();
        if (-x > ans[u])
            continue;
        for (auto [v, w] : G[u])
        {
            auto [t, k] = w;
            ll s = 0;
            if (x)
                s = (-(x + 1) / k + 1) * k;
            if (s + t < ans[v])
                ans[v] = s + t, que.push({-ans[v], v});
        }
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    x--;
    y--;
    vector<vector<pair<ll, pair<ll, ll>>>> g(n);
    while (m--)
    {
        ll a, b, k, t;
        cin >> a >> b >> t >> k;
        a--;
        b--;
        g[a].push_back({b, {t, k}});
        g[b].push_back({a, {t, k}});
    }
    auto d = dijkstra(g, x);
    cout << (d[y] < INF ? d[y] : -1);
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
using namespace std;

#define LL long long
#define DB double
#define MAXN 400000
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 1000000001
#define MOD 1000000007
#define eps 1e-8
#define mem(x,v) memset(x,v,sizeof(x))

LL read(){
    LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}

int n,x[MAXN+5],y[MAXN+5],fa[MAXN+5];
int xfind(int x){return (fa[x]==x)?x:fa[x]=xfind(fa[x]);}

DB dist(int i,int j){
	return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}

void bin(int u,int v){
	int a=xfind(u),b=xfind(v);
	if(a==b)return ;
	fa[a]=b;
}

bool check(DB R){
	for(int i=0;i<=n+1;i++)fa[i]=i;
	for(int i=1;i<=n;i++)if(y[i]-2*R<-100)bin(0,i);
	for(int i=1;i<=n;i++)if(y[i]+2*R>100)bin(i,n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		if(dist(i,j)<4*R*R)
		bin(i,j);
	return (xfind(0)==xfind(n+1));
}

int main(){
	n=read();
	for(int i=1;i<=n;i++)x[i]=read(),y[i]=read();
	DB l=0,r=100;
	while(l+eps<r){
		DB mid=(l+r)/2.0;
		if(!check(mid))l=mid;
		else r=mid;
	}
	printf("%.10f",l);
}


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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()

typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 1 << 18;

int a[MAX], b[MAX], p[MAX];
bool used[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, n)
		cin >> b[i];
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]--;
	}
	FOR(i, 0, n)
	{
		if(p[i] != i && a[i] <= b[p[i]])
		{
			cout << "-1\n";
			return 0;
		}
	}
	vector<pair<int, int>> ans;
	FOR(i, 0, n)
	{
		if(!used[i])
		{
			vector<int> c{i};
			for(int v = p[i]; v != i; v = p[v])
				c.push_back(v);
			int idx = i;
			for(int v: c)
			{
				used[v] = true;
				if(a[v] > a[idx])
					idx = v;
			}
			while(p[idx] != idx)
			{
				//assert(a[idx] > b[p[idx]] && a[p[idx]] > b[p[p[idx]]]);
				ans.push_back({idx, p[idx]});
				swap(p[idx], p[p[idx]]);
			}
		}
	}
	cout << SZ(ans) << "\n";
	for(auto [i, j]: ans)
		cout << i + 1 << " " << j + 1 << "\n";
	return 0;
}

#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <queue>

using namespace std;
using lint = long long;

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

    vector<vector<int>> graph(n);
    for (int i = n - 1; i--;) {
        int u, v;
        cin >> u >> v;
        --u, --v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int r = -1;
    {
        vector<bool> vis(n, false);
        vis[0] = true;
        queue<int> que;
        que.push(0);

        while (!que.empty()) {
            r = que.front();
            que.pop();

            for (auto v : graph[r]) {
                if (vis[v]) continue;
                vis[v] = true;
                que.push(v);
            }
        }
    }

    vector<int> depth(n);
    {
        auto dfs = [&](auto&& f, int v, int p) -> int {
            depth[v] = 0;
            for (auto u : graph[v]) {
                if (u == p) continue;
                depth[v] = max(depth[v], f(f, u, v) + 1);
            }
            return depth[v];
        };
        dfs(dfs, r, -1);
    }

    vector<int> ans(n, -1);
    {
        int cur = 1;
        auto dfs = [&](auto&& f, int v, int p) -> void {
            ans[v] = cur;

            vector<int> us;
            for (auto u : graph[v]) {
                if (u != p) us.push_back(u);
            }

            sort(us.begin(), us.end(),
                 [&](auto i, auto j) { return depth[i] < depth[j]; });

            for (auto u : us) {
                ++cur;
                f(f, u, v);
            }

            ++cur;
        };
        dfs(dfs, r, -1);
    }

    for (auto x : ans) cout << x << " ";
    cout << "\n";
}

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

    solve();

    return 0;
}


#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;
typedef unsigned long long hsh;

using namespace std;

int ts;
string s, t = "atcoder";

void inline solve() {
	cin >> s;
	if (t < s) {
		cout << 0 << ln;
		return;
	}
	int p = -1;
	loop (i, s.size()) {
		if (s[i] != 'a') {
			p = i;
			break;
		}
	}
	if (p == -1) {
		cout << -1 << ln;
		return;
	}
	cout << p - (s[p] > 't') << ln;
}

int main() {
	ios::sync_with_stdio(0);
	cin >> ts;
	cont (cs, ts) {
		solve();
	}
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';

int main() {
    int n,m;
    cin >> n >> m;
    if (0 <= m && m < n-1) {
        int x = (n-1-m-1)*2+1,c = 1;
        for (int i = 0;i < n-1;++i) {
            if (x == c) c++;
            cout << c << " " << c+1 << newl;
            c += 2;
        }
        cout << x << " " << 2*n << newl;
    } else if (n == 1 && m == 0) {
        cout << "1 2\n";
    } else {
        cout << -1 << newl;
    }
}


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

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

/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set=tree<T,null_type,less<T>,
rb_tree_tag,tree_order_statistics_node_update>;

#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007//998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)
#define MAXN 200001
//int fact[300000];
int st[4*MAXN];
int binExp(int x,int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}
int modInv(int i) {return binExp(i,mod-2);}
//int ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);}
/*void build(int s,int e,int i,int a[])
{    if(s==e){st[i]=a[s];return;}
      int mid=s+(e-s)/2;
    build(s,mid,2*i+1,a);
    build(mid+1,e,2*i+2,a);
    st[i]=st[2*i+1]+st[2*i+2];
}
int query(int s,int e,int i,int a[],int l,int r)
{if(s>e||l>r)return 0;
    if(s>=l&&e<=r)return st[i];
    if(s>r||e<l)return 0;
    int mid=s+(e-s)/2;
    return query(s,mid,2*i+1,a,l,r)+query(mid+1,e,2*i+2,a,l,r);
}

int update(int s,int e,int i,int pos,int val)
{if(s==e&&s==pos)
{st[i]=val;return 0;}

if(s>pos||e<pos)return 0;
int mid=s+(e-s)/2;
update(s,mid,2*i+1,pos,val);
update(mid+1,e,2*i+2,pos,val);
st[i]=st[2*i+1]+st[2*i+2];
}int parent[200000],size[200000];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}*/
signed main()
{
    fast
  int n;
  cin>>n;
  int a[n+1],b[n+1],c[n+1];
  f0(i,0,n)cin>>a[i+1];
   f0(i,0,n)cin>>b[i+1];
    f0(i,0,n)cin>>c[i+1];
    map<int,int>m;
    f0(i,1,n+1)
    {
        m[b[c[i]]]++;
    }
    int ans=0;
    f0(i,1,n+1)ans+=m[a[i]];
    cout<<ans;
   }

// Created by ash_98

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

#define mx 200005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];
int n,m,ii,k;
int cnt1[mx],cnt3[mx];
vector<int>g[mx];

void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		cnt1[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		g[x].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		cnt3[x]++;
	}

	ll re=0;
	for(int i=1;i<=n;i++)
	{
		if(!cnt1[i])continue;
		ll val=0;
		for(int j:g[i])val+=cnt3[j];
		re+=val*cnt1[i];
	}
	printf("%lld\n",re );

}

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


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int main() {
    int v[3];

    scanf("%d%d%d", &v[0], &v[1], &v[2]);
    sort(v, v+3);
    printf("%d\n", v[1]+v[2]);

    return 0;
}

#include <iostream>
using namespace std;

int main (){

    int a,b,c;
    cin >> a >> b >> c;

    int cont = 0;

    if(a>=b){
        cont +=a;
        if(b>=c){
            cont +=b;
        }
        else{
                cont +=c;
        }
    }
    else {
        if(b>=c){
            cont +=b;
            if(c>=a){
                cont +=c;
            }
            else{
                cont +=a;
            }
        }
        else{
            cont +=c;
            if(a>=b){
                cont +=a;
            }
            else{
                cont +=b;
            }
        }
    }

    cout << cont << endl;

    return 0;
}


/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int inf = 1'000'000'007;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

void solve() {
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    int sx = -1, sy = -1, gx = -1, gy = -1;
    vector<vector<int>> tpos(26, vector<int>());
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
            if(a[i][j] == 'S') sx = i, sy = j;
            else if(a[i][j] == 'G') gx = i, gy = j;
            else if(a[i][j] != '.' and a[i][j] != '#') {
                int c = a[i][j] - 'a';
                tpos[c].push_back(i * w + j);
            }
        }
    }
    vector<int> dist(h * w + 26, inf);
    dist[sx * w + sy] = 0;
    priority_queue<P, vector<P>, greater<P>> pque;
    pque.push({0, sx * w + sy});
    while(pque.size()) {
        P p = pque.top(); pque.pop();
        int pos = p.sc, di = p.fr;
        if(di > dist[pos]) continue;
        if(pos < h * w) {
            int x = pos / w, y = pos % w;
            rep(k, 4) {
                int nx = x + dx[k], ny = y + dy[k];
                // cerr << nx << " " << ny << "\n";
                if(0 <= nx and nx < h and 0 <= ny and ny < w and a[nx][ny] != '#') {
                    if(chmin(dist[nx * w + ny], di + 1)) {
                        pque.push({di + 1, nx * w + ny});
                    }
                }
            }
            if(a[x][y] != '.' and a[x][y] != 'S' and a[x][y] != 'G') {
                // teleport
                int c = a[x][y] - 'a';
                if(chmin(dist[h * w + c], di)) {
                    pque.push({di, h * w + c});
                }
            }
        } else {
            int c = pos - h * w;
            for(int np: tpos[c]) {
                if(chmin(dist[np], di + 1)) {
                    pque.push({di + 1, np});
                }
            }
        }
    }
    if(dist[gx * w + gy] == inf) dist[gx * w + gy] = -1;
    cout << dist[gx * w + gy] << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;

    cout << (n+1)*n/2 * k * 100 + n * (k+1)*k/2 << endl;

    return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int sum = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            sum += i*100+j;
        }
    }
    cout<<sum;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    cout << (n - 1) / 100 + 1 << endl;
}

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i = 1; i < 2888; i++){
        if(100 * i >= n){
            cout << i;
            exit(0);
        }
    }
    return 0;
}


//Saptak_Roy_Turja
#include<bits/stdc++.h>
#define ll long long int
#define d double
using namespace std;
int main()
{
    ll n,x,y;
    cin>>n>>x>>y;
    d ans=0.0;
    while(n--){
        d a,b;
        cin>>a>>b;
        d c=(y-b)/(x-a);
        ans=max(ans,y-x*c);
    }
    printf("%0.20lf\n",ans);
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define rloop(i,b,a) for(ll i=b;i>=a;i--)
#define test() int t;cin>>t;while(t-->0)
#define speed ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007
//const ld PI  = 3.141592653589793;

bool isPrime(int n)
{
    // Corner cases
    if(n<=3){
        return true;
    }
    if (n % 2 == 0 || n % 3 == 0)
        return false;

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

    return true;
}

int main()
{
   speed
    double x,y,z;
    cin>>x>>y>>z;
    double cost=y/x;
    double tt=z*cost;
    int t=tt;
    if((double)t<tt){
        cout<<t;
    }
    else
    cout<<t-1;
   return 0;
}


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF32 = 1 << 30;
constexpr ll INF64 = 1LL << 60;
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-10;
const double PI = acos(-1);

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

template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n;
    cin >> n;
    vector<ll> fibo = {1,1};
    while(fibo.back() < n){
        int k = fibo.size();
        fibo.push_back(fibo[k-1]+fibo[k-2]);
    }
    int m = fibo.size()-1;
    vector<int> v;
    for(ll i = m-1, s=n; s > 0 && i >= 0; i--){
        while(s >= fibo[i]){
            v.push_back(m-i-1);
            s -= fibo[i];
        }
    }
    // for(auto x : v){
    //     cout << x << " ";
    // }
    // cout << endl;
    v.push_back(INF32);
    ll x = 0, y = 0;
    vector<int> ans;
    for(int i=0,j=0;x<n;i++){
        while(v[j]==i){
            if(i%2==0){
                y++;
                ans.push_back(1);
            }else{
                x++;
                ans.push_back(0);
            }
            j++;
        }
        if(i%2==0){
            x = x+y;
            ans.push_back(2);
        }else{
            y = x+y;
            ans.push_back(3);
        }
    }
    cout << ans.size() << endl;
    int f = (x==n ? 0 : 1);
    for(auto t : ans){
        cout << (t^f)+1 << endl;
    }
    return 0;
}

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

ld rr = 1.618033988;
vector<int> ans, ans_tmp;

ll last = -1;
int flag = -1;
ll cnt_tmp = 1e18;

void func(ll x, ll y) {
    if (x == 0) {
        last = y;
        flag = 0;
        for (ll i=0;i<y;i++) {
            ans_tmp.push_back(2);
        }
    } else if (y == 0) {
        last = x;
        flag = 1;
        for (ll i=0;i<x;i++) {
            ans_tmp.push_back(1);
        }
    } else if (x <= y) {
        ans_tmp.push_back(4);
        func(x, y-x);
    } else if (x > y) {
        ans_tmp.push_back(3);
        func(x-y, y);
    }
    return;
}

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

    ll M = (ll)((ld)N/(rr+1.0));

    for (ll j=0;j<1e2;j++) {
        if (0 <= M-j && M-j <= N) {
            last = -1;
            flag = -1;
            ans_tmp.clear();
            func(N, M-j);
            if (ans_tmp.size() < cnt_tmp) {
                ans = ans_tmp;
                cnt_tmp = ans.size();
                // break;
            }
        }

        if (0 <= M+j && M+j <= N) {
            last = -1;
            flag = -1;
            ans_tmp.clear();
            func(N, M+j);
            if (ans_tmp.size() < cnt_tmp) {
                ans = ans_tmp;
                cnt_tmp = ans.size();
                // break;
            }
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans.size() << "\n";
    for (auto ele : ans) {
        cout << ele << "\n";
    }
    return 0;
}

// 1000000000000000000
// 999999999999999999


#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
std::mt19937 rnd(233);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ls (i<<1)
#define rs (i<<1|1)
#define mem(a,b) memset(a,b,sizeof(a))
const int N=1e6+5;
const int inf=0x3f3f3f3f;
const LL mod=1e9+7;
LL read()
{
    LL x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){ if(ch=='-') f=-1; ch=getchar(); }
    while(isdigit(ch)){ x=10*x+ch-'0'; ch=getchar(); }
    return f*x;
}
pii a[N];
int l[N],w[N],b[N];
LL dp[10],sum[10];
int main()
{
    int n=read(),m=read(),ma=0,mi=1e9;
    for(int i=1;i<=n;i++) w[i]=read(),ma=max(ma,w[i]);
    for(int i=1;i<=m;i++)
    {
        a[i].se=read();
        a[i].fi=read();
        mi=min(mi,a[i].fi);
    }
    if(mi<ma) return 0*printf("-1\n");
    sort(a+1,a+m+1);
    for(int i=1;i<=m;i++) l[i]=max(a[i].se,l[i-1]);
    sort(w+1,w+n+1);
    LL ans=1e18;
    do
    {
        //for(int i=1;i<=n;i++) printf("%d%c",w[i],i==n?'\n':' ');
        mem(dp,0);
        for(int i=1;i<=n;i++) sum[i]=sum[i-1]+w[i];
        for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
        {
            int tmp=sum[i]-sum[j-1];
            int pos=lower_bound(a+1,a+m+1,mk(tmp,0))-a-1; //printf("%d\n",pos);
            dp[i]=max(dp[i],dp[j]+l[pos]);
        }
        ans=min(dp[n],ans);
    }while(next_permutation(w+1,w+n+1));
    printf("%lld\n",ans);
    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************0123456789****************************************************************
#include<bits/stdc++.h>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "Yes"<<endl
#define no  cout<< "No"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define r(v) reverse(v,v+n)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<setprecision(x)<<fixed;
#define cone(x) (__builtin_popcountll(x))        // zero indexed
#define fone(x) (__builtin_ffsll(x) -1LL)        //give wrong answer if x==0;(zero indexed)
#define mone(x) (63LL-__builtin_clzll(x))
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define RUN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(output) cout<<#output<<"="<<output<<endl
using namespace std;
std::vector<int>adj[10000];
bool visited[10000];
string str;
int getMaxGCD(int arr[], int n) {
   int high = 0;
   for (int i = 0; i < n; i++)
   high = max(high, arr[i]);
   int divisors[high + 1] = { 0 }; //array to store all gcd values
   for (int i = 0; i < n; i++) {
      for (int j = 1; j <= sqrt(arr[i]); j++) {
         if (arr[i] % j == 0) {
            divisors[j]++;
         if (j != arr[i] / j)
            divisors[arr[i] / j]++;
         }
      }
   }
   for (int i = high; i >= 1; i--)
   if (divisors[i] > 1)
   return i;
}
signed main()
{
    RUN;
    int test=1;
    //cin>>test;
    while(test--)
    {
      int a,b;
      cin>>a>>b;
      int ar[1000000],j=0;
      for(int i=a;i<=b;i++)
      ar[j]=i,j++;
      int ans=getMaxGCD(ar,j);
      cout<<ans;

    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
int main()
{
	cin.tie(0);cout.tie(0);
	int sx,sy,gx,gy;
	cin>>sx>>sy>>gx>>gy;
	cout<<fixed<<setprecision(8);
	if(sx>gx)
	{
		swap(sx,gx);
		swap(sy,gy);
	}
	double k=(gx-sx)*1.0/(sy+gy);
	k*=sy;
	cout<<k+sx<<endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  int ans = 0;
  rep(i,n)rep(j,n){
    double ka;
    ka = (double)(y[j] - y[i]) / (x[j] - x[i]);
    if (ka >= -1 && ka <= 1){
      ans++;
    }
  }
  cout << ans/2 << endl;
  return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

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

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}

template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  string s;cin>>s;

  V<ll> asum(n+1,0),tsum=asum,csum=asum,gsum=asum;

  rep(i,0,n){
    asum[i+1]=asum[i]+int(s[i]=='A');
    tsum[i+1]=tsum[i]+int(s[i]=='T');
    csum[i+1]=csum[i]+int(s[i]=='C');
    gsum[i+1]=gsum[i]+int(s[i]=='G');
  }

  ll ans=0;
  rep(i,0,n){
    rep(j,i+2,n+1){
      if(asum[j]-asum[i]==tsum[j]-tsum[i] && csum[j]-csum[i]==gsum[j]-gsum[i])++ans;
    }
  }

  cout<<ans<<ENDL;
}
//! ( . _ . ) !
//CHECK overflow,vector_size,what to output?

#include <bits/stdc++.h>

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

int main(){
	int n,i,j;
	string s;

	map<char, int> mapper;
	mapper['A'] = 0;
	mapper['T'] = 1;
	mapper['C'] = 2;
	mapper['G'] = 3;
	while(scanf("%d",&n) !=EOF){
		cin>>s;
		int ans = 0;
		for(i=0;i<n;i++){
			int cnt[4];
			memset(cnt, 0, sizeof cnt);
			for(j=i;j<n;j++){
				char c = s[j];
				cnt[mapper[c]]++;
				if(cnt[0] == cnt[1] && cnt[2] == cnt[3]){
					ans++;
				}
			}
		}
		printf("%d\n",ans);
	}

	return 0;
};


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define fp(x, a, b) for(int x = a; x < b; x++)
#define fn(x, a, b) for(int x = a; x > b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;
// #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
  ((cout << args << ' '), ...);
  cout<<'\n';
}
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 3e5 + 5;
const char nl = '\n';
const int INF = 1e9 + 5;
ll n;
ll a[MAX], tree[MAX * 4], ord[MAX];
ll query(int id, int x, int y, int l, int r){
  if(l >= y || r <= x) return 0;
  // push(id, l, r);
  if(x <= l && r <= y) return tree[id];
  int m = (l + r) >> 1;
  int ga = query(id << 1, x, y, l, m);
  int gb = query(id << 1 | 1, x, y, m, r);
  return (ga + gb);
}
void update(int id, int ind, int val, int l, int r){
  // push(id, l, r);
  tree[id] += val;
  if(l + 1 == r) return;
    int m = (l + r) >> 1;
  if(ind >= m) update(id << 1 | 1, ind, val, m, r);
  else update(id << 1, ind, val, l, m);
}
void solve(){
  cin >> n;
  vii v;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    ord[a[i]] = i;
  }
  ll res = ((ll)n * (n - 1)) / 2;
  for(int i = 0; i < n; i++){
    res -= query(1, 0, ord[i], 0, n);
    update(1, ord[i], 1, 0, n);
  }
  cout << res << '\n';
  for(int i = 0; i < n - 1; i++){
    res -= (a[i] - (n - 1 - a[i]));
    cout << res << '\n';
  }
}
int main(){
  cpu();
  // int __;
  // cin >> __;
  // while(__--){
  //   solve();
  // }
  solve();
  // cout << nl;

  return 0;
}

/*** keep hungry and calm CoolGuang!  ***/
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<hash_map>
#include<iostream>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll INF= 1e18+7;
const ll maxn = 1e6+700;
const int M = 1e6+8;
const ll mod= 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a){char c=getchar();T x=0,f=1;while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}a=f*x;}
ll n,m,p;
ll a[maxn];
ll sum[maxn];
void add(int pos){
	while(pos<=n){
		sum[pos]++;
		pos += pos&-pos;
	}
}
ll query(int pos){
	ll ans = 0;
	while(pos){
		ans += sum[pos];
		pos -= pos&-pos;
	}return ans;
}
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
		a[i]++;
	}
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ans += query(n)-query(a[i]);
		add(a[i]);
	}
	dl(ans);
	for(int i=1;i<=n-1;i++){
		ans += query(n)-query(a[i])-query(a[i]-1);
		dl(ans);
	}
    return 0;
}

/**

5
N 83 2 7475
UN 83 2 27550
EXF 5 2 17298
OVYNH 51 2 14827
XNV 53 1 7591
2
1
XNV
2
83
**/


#include <bits/stdc++.h>

using namespace std;

#define rep(i,n)for(int i=0;i<(int)(n);++i)
#define fixed(n)fixedb<<setprecision(n)
#define ll long long
#define ALL(a)a.begin(),a.end()

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

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

const long long INF=1LL<<60;
const long long MOD=1000000007;

int main(){
    int n;cin>>n;
    set<int>a;
    int a10=7,a8=7;
    int res=n;
    for(int i=1;i<=n;++i){
        bool flag=true;
        string s=to_string(i);
        rep(j,s.size()){
            if(s[j]=='7'){
                flag=false;
                break;
            }
        }
        if(flag){
            ll m=i;string t;
            while(m>0){
                char push=m%8+48;
                t=push+t;
                if(m/8<=0){
                    push=m+48;
                    t=push+t;
                }
                m/=8;
            }
            rep(j,t.size()){
                if(t[j]=='7'){
                    flag=false;
                    break;
                }
            }
        }
        if(!flag)res--;
    }
    cout<<res;
}


#include <cstdio>

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(105);
int n, K, M, f[N][N * N * N], s[N];
inline void Add(int &x, int y) { x = (x + y) % M; }

int main()
{
	n = read(), K = read(), M = read(), f[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n * n * K; j++)
		{
			Add(s[j % i], f[i - 1][j]);
			if (j >= (K + 1) * i) Add(s[j % i], M - f[i - 1][j - (K + 1) * i]);
			f[i][j] = s[j % i];
		}
	for (int i = 1; i <= n; i++)
	{
		int ans = 0;
		for (int j = 1; j <= n * n * K; j++)
			Add(ans, 1ll * f[i - 1][j] * f[n - i][j] % M);
		printf("%lld\n", (K + 1ll * ans * (K + 1)) % M);
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;

tuple<ll,ll,ll> extgcd(ll a, ll b) {
  if (b == 0) return {a, 1, 0};
  ll g, x, y;
  tie(g,x,y) = extgcd(b, a%b);

  return {g, y, x-a/b*y};
}

void solve() {
  int n, s, k;
  cin >> n >> s >> k;
  ll x,y,g;
  tie(g,x,y) = extgcd(k,n);

  if (s % g != 0) {
    cout << -1 << endl;
    return;
  }
  n /= g;
  s /= g;
  k /= g;
  ll ans = ((x*-s)%n+n)%n;
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  rep(i,t) solve();
  return 0;
}


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

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;
vector<vector<edge>> G;
vector<ll> d;
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d.begin(), d.end(), 1e18);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int R, C;
    cin >> R >> C;
    vector<vector<int>> A(R, vector<int>(C - 1));
    vector<vector<int>> B(R - 1, vector<int>(C));
    rep(i, R) rep(j, C - 1) cin >> A[i][j];
    rep(i, R - 1) rep(j, C) cin >> B[i][j];

    int N = R * C * 2;
    G.resize(N);
    d.resize(N);
    rep(i, R) rep(j, C) {
        int idx = C * i + j;

        if (j + 1 != C) G[idx].push_back({idx + 1, A[i][j]});
        if (j - 1 != -1) G[idx].push_back({idx - 1, A[i][j - 1]});
        if (i + 1 != R) G[idx].push_back({idx + C, B[i][j]});
        if (i - 1 != -1) G[idx + R * C].push_back({idx + R * C - C, 1});

        G[idx].push_back({idx + R * C, 1});
        G[idx + R * C].push_back({idx, 0});
    }

    dijkstra(0);
    cout << d[R * C - 1] << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define UniqueVector(vec) sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
    int a,b;
    cin>>a>>b;
    for(int c=b;c>=1;c--){
        if(b/c-(a-1)/c>=2){
            cout<<c<<endl;
            return 0;
        }
    }
}


#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <set>

#define ll long long
#define ld long double
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 1e15
#define point complex <double>
#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define file  freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

using namespace std;

int main()
{
    HS;
    int n;
    cin>>n;
    ll arr[n+5];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    ll mini=INF;
    for(int i=0;i<(1<<n);i++)
    {
        ll xr=0;
        ll orr=0;
        for(int j=0;j<n;j++)
        {
            if(i & (1<<j))
            {
                xr^=orr;
                orr=0;
            }

            orr|=arr[j];
        }
        xr^=orr;
        mini=min(mini,xr);

    }
    cout << mini << endl;

    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_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<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);
}
// void out(ll x) {
// 	cout << "Case #" << x << ": ";
// }

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;
	ll a[n];
	rep(i, n) cin >> a[i];

	ll ans = inf;

	rep(i, (1ll << (n - 1))) {
		k = i | (1 << (n - 1));

		ll xorr = 0;
		ll orr = 0;
		rep(j, n) {
			orr |= a[j];
			if ((1 << j)&k) {
				xorr ^= orr;
				orr = 0;
			}
		}
		// cout << k << ' ';
		ans = min(ans, xorr);
	}
	cout << ans;
	return 0;

}


#include "bits/stdc++.h"

using namespace std;
using ll = long long;

vector<ll> primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };

void Main() {
    ll A, B;
    cin >> A >> B;
    vector<ll> AtoB(B - A + 1, 0);
    for (ll i = 0; i < B - A + 1; ++i) {
        AtoB[i] = A + i;
    }

    vector<ll> divisibleBits(AtoB.size(), 0);
    for (ll i = 0; i < AtoB.size(); ++i) {
        for (ll pi = 0; pi < primes.size(); ++pi) {
            if (AtoB[i] % primes[pi] == 0) {
                divisibleBits[i] |= (1 << pi);
            }
        }
    }
    vector<vector<ll>> dp(AtoB.size(), vector<ll>(1 << primes.size(), 0));
    for (ll i = 0; i < dp.size(); ++i) {
        dp[i][0] = 1;
    }
    for (ll i = 0; i < AtoB.size(); ++i) {
        for (ll bit = 0; bit < (1 << primes.size()); ++bit) {
            if (dp[i][bit] == 0) {
                continue;
            }
            ll b = bit | divisibleBits[i];
            for (ll ni = i + 1; ni < AtoB.size(); ++ni) {
                ll curr = AtoB[i];
                ll next = AtoB[ni];
                if ((b & divisibleBits[ni]) == 0) {
                    dp[ni][b] += dp[i][bit];
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < dp.size(); ++i) {
        for (int j = 0; j < dp[i].size(); ++j) {
            ans += dp[i][j];
        }
    }
    cout << 1 + ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

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

template<class ForwardIterator> void print_vec(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo <= hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

vector<int> pr = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
ll A, B;

int n;
ll dp[73][1<<20];

ll ways(int i, int b) {
	ll x = A+i;
	if (x==B+1) {
		return 1;
	}
	ll &ans = dp[i][b];
	if (ans != 0){
		return ans;
	}
	bool good = true;
	int nb = 0;
	int j = 0;
	for (auto p : pr) {
		if (x%p ==0) {
			if (TEST(b,j)) {
				good=false;
				break;
			}
			nb=SET(nb,j);
		}
		j++;
	}
	if (good) {
		ans+=ways(i+1,b|nb);
	}
	ans+=ways(i+1,b);
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> A >> B;
	cout << ways(0,0) << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define superfastboy ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mp make_pair
#define int long long
#define ll long long
#define ull unsigned long long
ll const inf=1e9+7,mod=1e9+7;
ll const N=270805;
signed main(){
//	freopen(".inp","r",stdin);
//    freopen(".outp","w",stdout);
	superfastboy
	int a,b;
  	cin>>a>>b;
  	for(int c=b;c>0;c--){
      	if((a-1)/c+1<b/c){
       		cout<<c<<"\n";
        	return 0;
        }
    }
}

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

int main() {

  int t, N;
  cin >> t >> N;

  int P = 100 + t;

  vector<int> A(P,1);

  rep(i, 100) {
    A.at(P * i / 100) = 0;
  }

  vector<int> B;

  rep(i, P) {
    if (A.at(i)) {
      B.push_back(i);
    }
  }

  int64_t q, r;
  q = (N - 1) / t;
  r = (N - 1) % t;

  int64_t ans;
  ans = P * q + B[r];

  cout << ans << endl;
}


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

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

    auto go = [&](int x) -> long long {
        return 1LL * x * (x + 1) / 2;
    };

    long long ans = 0;
    while (n--) {
        int a, b;
        cin >> a >> b;
        ans += go(b) - go(a - 1);
    }
    cout << ans << "\n";
    return 0;
}

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

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

    ll ans = 0;

    int n; cin >> n;
    rep(i,n){
        ll a,b; cin >> a >> b;
        ans += (a+b)*(b-a+1)/2;
    }

    cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
   ll n;cin>>n;
   vector<ll> A(n),B(n+1,0),C(n+1,0),D(n+1,0);
   rep(i,n)cin>>A[i];
   B[0]=0;
   rep(i,n)B[i+1]=B[i]+A[i];
   C[0]=0;
   rep(i,n)C[i+1]=max(C[i],B[i+1]);
   D[0]=0;
   rep(i,n)D[i+1]=D[i]+B[i+1];
   ll ans=0;
   rep(i,n){
      ans=max(ans,D[i]+C[i+1]);
   }
   ans=max(ans,D[n]);
   cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define pb push_back

using namespace std;

void test(){
	ll n;
	cin>>n;
	ll a[n],b[n],c[n];
	f(i,n)cin>>a[i];
	f(i,n)cin>>b[i];
	f(i,n)cin>>c[i];

	ll freq[n+1];
	f(i,n+1)freq[i] = 0;
	f(i,n)freq[b[c[i]-1]]++;

	ll ans = 0;

	f(i,n){
		ans = ans + freq[a[i]];
	}

	cout<<ans<<"\n";

}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


/*
 * @Author: AsilenceBTF
 * @LastEditTime: 2020-12-15 13:39:37
 */
#include<bits/stdc++.h>
using namespace std;

#define ALL(x) x.begin(), x.end()
typedef long long ll;
const int INF = 0x3f3f3f3f;

const int N = 1e3 + 105;
int a[N], b[N], dp[N][N];
int main(){
    int n, m; scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for(int i = 1; i <= m; ++i) scanf("%d", &b[i]);
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            if(i == 0 && j == 0) continue;
            dp[i][j] = INF;
            if(i > 0){
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
            }
            if(j > 0){
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
            }
            if(i > 0 && j > 0){
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (a[i] != b[j]));
            }
        }
    }
    printf("%d\n", dp[n][m]);
    // system("pause");
}

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

#ifdef LOCAL
#include "debug.h"
#endif

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define rep(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repi(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define umin(a, x) a = min(a, x)
#define umax(a, x) a = max(a, x)

ll nxt() {
	ll x; cin >> x; return x;
}

void setIO(string s) {
	#ifndef LOCAL
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
	#endif
}

bool done[1005][1005];

int dp[1005][1005];

int a[1005], b[1005];

int n, m;

const int inf = 1e9;

int go(int x, int y) {
	if (x >= 0 && y >= 0 && x <= n && y <= m) {
		if (!done[x][y]) {
			if (x == 0) {
				dp[x][y] = y;
			} else if (y == 0) {
				dp[x][y] = x;
			} else {
				int one = (int)(a[x] != b[y]) + go(x - 1, y - 1);
				int two = 1 + go(x - 1, y);
				int three = 1 + go(x, y - 1);
				int four = 2 + go(x - 1, y - 1);
				dp[x][y] = min({one, two, three, four});
			}

			done[x][y] = 1;
			return dp[x][y];
		} else {
			return dp[x][y];
		}
	} else {
		return inf;
	}
}

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

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

	go(n, m);
	cout << dp[n][m] << "\n";
}

int32_t main(){
	// setIO("trapped");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int T = 1;
	// cin >> T;

	for (int tc = 1; tc <= T; tc++) {
		// cout << "Case #" << tc << ": ";
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long double x, y, r;
bool check(long double a, long double b){
	return sqrt((a-x)*(a-x) + (b-y)*(b-y)) <= r + 1e-14;
}

void solve(){
	cin>>x>>y>>r;
	int lo = x-r-10;
	int hi = x+r+10;
	int ans = 0;
	for(int i=lo;i<=hi;i++){
		if(!check(i, y)) continue;
		long double j = i;
		long double val = r*r - (j-x)*(j-x) + 0.1;
		int down = -sqrt(val) + y - 10;
		int up = sqrt(val) + y + 10;
		while(down <= up && !check(j, down)) down++;
		while(down <= up && !check(j, up)) up--;
		if(down > up) continue;
		//cout<<i<<" "<<up<<" "<<down<<"\n";
		ans += up - down + 1;
	}
	cout<<ans<<"\n";

	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=222222,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,k,a[maxn],b[maxn],ans;
inline int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
int main(){
	n=read();m=read();k=read();
	if(n==1){
		printf("%d\n",qpow(k,m));
		return 0;
	}
	if(m==1){
		printf("%d\n",qpow(k,n));
		return 0;
	}
	FOR(i,1,k) a[i]=qpow(i,n);
	FOR(i,1,k) b[i]=qpow(k-i+1,m);
	ROF(i,k,2) a[i]=(a[i]-a[i-1]+mod)%mod;
	FOR(i,1,k) ans=(ans+1ll*a[i]*b[i])%mod;
	printf("%d\n",ans);
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
#define CHECK(a) cout << #a << " " << a << endl;
const int INF = 1e9;
const ll MOD = (ll)1e9 + 7LL;
const vector<int> dx = {1, 0, -1, 0, 1, 1, -1, -1};
const vector<int> dy = {0, 1, 0, -1, 1, -1, 1, -1};

void Main () {
    int N;
    cin >> N;

    set<int> A;
    REP (i, 0, N) {
        int a;
        cin >> a;
        A.insert(a);
    }

    while  (true) {
        int maximum = *rbegin(A);
        int minimum = *begin(A);
        if (maximum == minimum) break;
        else {
            A.erase(maximum);
            A.insert(maximum - minimum);
        }
    }

    cout << *begin(A) << endl;
}

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

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

int main(){
  int N;
  cin >> N;
  ll sum1 = 0;
  long double sum2 = 0;
  ll m = -1;
  rep(i, N) {
    ll x;
    cin >> x;
    x = abs(x);
    m = max(m, x);
    sum1 += x;
    sum2 += x*x*1.0;
  }
  cout << fixed << setprecision(15);
  cout << sum1 << endl << sqrt(sum2) << endl << m;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  char a,b,c;
  cin>>a>>b>>c;
  cout<<b<<c<<a<<endl;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define M 1000000007

ll powll(ll x, ll y) {
    ll re=1;
    rep(i, y) {
        re = re * x % M;
    }
    return re;
}

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

int main() {

    ll n;
    cin >> n;

    vector<ll> outlist;

    for (ll i = 1;; i++) {
        ll j = 0;
        j = n / i;

        if (i > j) {
            break;
        }

        if (n%i == 0) {

            outlist.push_back(i);
            outlist.push_back(j);
        }
    }

    sort(outlist.begin(), outlist.end());
    outlist.erase(unique(outlist.begin(), outlist.end()),outlist.end());

    for (auto it = outlist.begin(); it != outlist.end(); ++it) {
        cout << *it << endl;
    }

    return 0;
}


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

template <class T>
void chmax(T& a, T b) {
    a = max(a,b);
}

template <class T>
void chmin(T& a, T b) {
    a = min(a,b);
}

#define rep(i, a, b) for (ll i = a; i < b; i++)
#define all(container) container.begin(), container.end()

typedef long l;
typedef long long ll;
typedef pair<int, int> ipi;
typedef pair<ll, ll> lpl;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

#define MOD 1'000'000'007LL
ll LLINF = LLONG_MAX / 2;

int main() {
    ll A, B;
    cin >> A >> B;
    for (int i=B-A;i > 0;i--) {
        if ( ceil(double(A)/i) != B/i) {
            cout << i;
            return 0;
        }
    }
    return 0;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;

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

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

const ll INF = 100000000000000;

int main() {
    int a, b;
    cin >> a >> b;
    int yaku = b - a;
    for (int i = yaku; i >= 1; i--) {
        if (a % i == 0) {
            yaku = i;
            break;
        }
        if (a + (i - a % i) + i <= b) {
            yaku = i;
            break;
        }
    }
    cout << yaku << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define endl "\n"

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

    long long int n,p,x,a,i,mn=INT_MAX;
    cin>>n;
    float time=0.5;
    for(i=0;i<n;++i)
    {
        cin>>a>>p>>x;
        if(((float)x)>ceil(((float)a-0.5)))
            mn=min(mn,p);

    }

    if(mn!=INT_MAX)
       cout<<mn;

    else
       cout<<-1;
     return 0;
}

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

#define printV(v) for(int i = 0;i < v.size();++i)cout << v[i] << endl
#define print(x) cout << x << endl

int main() {
	int N,M,T;
  cin >> N;
  cin >> M;
  cin >> T;
  int n = N;
  int t = 0;
  bool ok = true;
	for(int i = 0;i < M;++i){
		int A,B;
      cin >> A;
      n -= A - t;
      if(n <= 0){
        ok = false;
        break;
      }
      cin >> B;
      n += B - A;
      if(n >= N){
        n = N;
      }
      t = B;
      //print(n);
      //print(t);
    }
  //print(n);
	n -= (T - t);
      if(n <= 0){
        ok = false;
      }
  //print(n);
  print((ok?"Yes":"No"));
}


#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
using namespace std;
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i > -1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

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

// using lll=boost::multiprecision::cpp_int;
// using
// Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
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  0)
  {
    if (n & 1)
    {
      if (p != -1)
        ret = (ret * x) % p;
      else
        ret *= x;
    }
    if (p != -1)
      x = (x * x) % p;
    else
      x *= x;
    n >>= 1;
  }
  return ret;
}

struct myrand{
  random_device seed;
  mt19937 mt;
  myrand():mt(seed()){}
  int operator()(int a,int b){//[a,b)
    uniform_int_distribution<int>dist(a,b-1);
    return dist(mt);
  }
};

//using namespace atcoder;

//------------------------
//------------------------
//------------------------
//------------------------
//------------------------

using P=pair<long double,long double>;
long double eps=1e-8;
void solve()
{
	int n;
	cin>>n;
	vector<long double>a(n),b(n),c(n),d(n);
	long double ga=0,gb=0,gc=0,gd=0;
	rep(i,n)cin>>a[i]>>b[i],ga+=a[i],gb+=b[i],a[i]*=n,b[i]*=n;
	rep(i,n)cin>>c[i]>>d[i],gc+=c[i],gd+=d[i],c[i]*=n,d[i]*=n;
	if(n==1){
		cout<<"Yes\n";
		return;
	}

	int cnt=0,cnt2=0;
	rep(i,n){
		a[i]-=ga,b[i]-=gb;
		c[i]-=gc,d[i]-=gd;
		if(abs(a[i])<eps&&abs(b[i])<eps)++cnt;
		if(abs(c[i])<eps&&abs(d[i])<eps)++cnt2;
	}
	if(cnt!=cnt2){
		cout<<"No\n";
		return;
	}
	vector
q(n);
	rep(i,n)q[i]={c[i],d[i]};

	auto mul=[](long double x,long double y,long double arg)->P{
		P ret={cos(arg)*x+sin(arg)*y,-sin(arg)*x+cos(arg)*y};
		return ret;
	};

	auto myequal=[](P &x,P &y)->bool{
		return abs(x.fi-y.fi)<eps&&abs(x.se-y.se)<eps;
	};
	int id=0;
	if(abs(a[id])<eps&&abs(b[id])<eps)id=1;
	rep(t,n){
		if(abs(c[t])<eps&&abs(d[t])<eps)continue;
		vector
p(n);
		long double argx=atan2(b[id],a[id]),argy=atan2(d[t],c[t]);
		long double arg_sub=argx-argy;
		rep(i,n){
			p[i]=mul(a[i],b[i],arg_sub);
		}

		vector<bool>used(n);
		bool ng=false;
		rep(i,n){
			bool flag=false;
			rep(j,n){
				if(!used[j]&&myequal(p[i],q[j])){
					used[j]=true;
					flag=true;
					break;
				}
			}
			if(!flag){
				ng=true;
				break;
			}
		}

		if(!ng){
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}

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

#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
#include <map>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;
typedef pair<int, int> pain;
typedef vector<vecpa > dim2vecpa;

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

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

const ll MOD = 1000000007;

int dist(double x1, double y1, double x2, double y2) {
    return (int)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int angG(double X, double Y, double x2, double y2, double x3, double y3) {
    double gaiseki = (x2 - X) * (y3 - Y) - (y2 - Y) * (x3 - X);
    return (int)(asin(gaiseki / (dist(X, Y, x2, y2) * dist(X, Y, x3, y3))) * 100000);
}

int angN(double X, double Y, double x2, double y2, double x3, double y3) {
    double naiseki = (x2 - X) * (x3 - X) + (y2 - Y) * (y3 - Y);
    return (int)(acos(naiseki / (dist(X, Y, x2, y2) * dist(X, Y, x3, y3))) * 100000);
}

int main() {
    int n; cin >> n;
    vecdo a = vecdo(n);
    vecdo b = vecdo(n);
    vecdo c = vecdo(n);
    vecdo d = vecdo(n);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) cin >> c[i] >> d[i];
    if (n == 1) {
        cout << "Yes";
        return 0;
    }
    if (n == 2) {
        if (dist(a[0], b[0], a[1], b[1]) == dist(c[0], d[0], c[1], d[1])) {
            cout << "Yes";
        }
        else cout << "No";
        return 0;
    }

    ll length = dist(a[0], b[0], a[1], b[1]);

    bool res = false;

    vector<pair<int, pair<int, int>>> ans = vector<pair<int, pair<int, int>>>(n - 2);
    for (int i = 2; i < n; i++) {
        ans.push_back(make_pair(dist(a[0], b[0], a[i], b[i]), make_pair(angN(a[0], b[0], a[1], b[1], a[i], b[i]), angG(a[0], b[0], a[1], b[1], a[i], b[i]))));
    }
    sort(ans.begin(), ans.end());

    rep(i, n) rep(j, n) {
        if (i == j) continue;
        if (length != dist(c[i], d[i], c[j], d[j])) continue;
        bool flag = true;
        rep(k, n) {
            if (i == k) continue;
            if (j == k) continue;
            pair<int, pair<int, int>> isOK = make_pair(dist(c[i], d[i], c[k], d[k]), make_pair(angN(c[i], d[i], c[j], d[j], c[k], d[k]), angG(c[i], d[i], c[j], d[j], c[k], d[k])));
            if (!binary_search(ans.begin(), ans.end(), isOK)) {
                flag = false;
                break;
            }
        }
        if (flag) {
            res = true;
            break;
        }
    }
    if (res) cout << "Yes";
    else cout << "No";

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<ll, int>> a(n);
  for (auto& e : a) cin >> e.first >> e.second;
  reverse(a.begin(), a.end());

  ll s = 0, bot = -1e18, top = 1e18;
  for (auto e : a) {
    switch (e.second) {
      case 1: {
        s += e.first;
        bot -= e.first;
        top -= e.first;
        break;
      }
      case 2: {
        if (bot == top) break;
        bot = max(bot, e.first);
        bot = min(bot, top);
        break;
      }
      case 3: {
        if (bot == top) break;
        top = min(top, e.first);
        top = max(bot, top);
        break;
      }
    }
  }

  int q;
  cin >> q;
  while (q--) {
    ll x;
    cin >> x;
    cout << max(bot, min(top, x)) + s << endl;
  }
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define per(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) per(i, a, 0)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

typedef long long ll;

const int MAXN = 2e5 + 10;

int n;
ll add, L = -LONG_LONG_MAX >> 1, R = LONG_LONG_MAX >> 1;

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(n);
	REP(i, n) {
		ll v; int t; IO::read(v), IO::read(t);
		if (t == 1) add += v, L += v, R += v;
		else if (t == 2) L = max(L, v), R = max(R, v);
		else R = min(R, v), L = min(L, v);
	}
	int q; IO::read(q);
	REP(i, q) {
		ll x; IO::read(x); x += add;
		IO::write(x <= L ? L : (x >= R ? R : x), '\n');
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <iomanip>
#include <set>
#include <bitset>
//#include<unordered_map>
#define INT_MINs -2000000000
#define INT_MAXs 1000000001
#define MID int mid=(l+r)/2
#define REP1(i,x,y) for(int i=x;i<y;i++)
#define REP2(i,x,y) for(int i=x;i<=y;i++)
#define ls (2*k)
#define rs (2*k+1)
#define lson l,mid,2*k
#define rson mid+1,r,2*k+1
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0);cin.tie(NULL);
#define pb(a) push_back(a)
#define pi acos(-1)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=20210213;
const ll ba=131;
//ll qk(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x;y>>=1;x=x*x;}return ans;}
const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { -1,0,1,0,-1,1,-1,1};
const int dxx[8]= {2,1,-1,-2,-2,-1, 1, 2},dyy[8]= {1,2,2,1, -1,-2,-2,-1};
int a[20],b[20],c[20];
int minn=inf;
int n;
int vis[20];
int dp[1000005][20];

void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    memset(dp,inf,sizeof dp);
    dp[1][1]=0;
    for(int i=1;i<(1<<n);i++){
        for(int j=1;j<=n;j++){
            if((1<<(j-1))&i==0) continue;
            for(int k=1;k<=n;k++){
                if((1<<(k-1))&i) continue;
                dp[i|(1<<(k-1))][k]=min(dp[i|(1<<(k-1))][k],dp[i][j]+abs(a[k]-a[j])+abs(b[k]-b[j])+max(0,c[k]-c[j]));
            }
        }
    }
    for(int i=1;i<=n;i++){
        minn=min(dp[(1<<n)-1][i]+abs(a[1]-a[i])+abs(b[1]-b[i])+max(0,c[1]-c[i]),minn);
    }
    cout<<minn<<endl;
}
int main()
{
    IOS;
    solve();
    return 0;
}

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

vector<int> x,y,z;

int dist(int a,int b){
  return abs(x[b]-x[a])+abs(y[b]-y[a])+max(0,z[b]-z[a]);
}

void infout(int a){
  if(a == 1e9) cout << "INF";
  else cout << a;
  cout << ",";
}

void chmin(int& a, int b){
  a = min(a,b);
}

int main(){

  int n;
  cin >> n;
  x.resize(n);
  y.resize(n);
  z.resize(n);
  rep(i,n) cin >> x[i] >> y[i] >> z[i];
  vector<vector<int>> dp(1<<n,vector<int>(n,1e9));
  rep(i,n){
    if(i == 0) continue;
    dp[1<<i][i] = dist(0,i);
  }
  rep(i,1<<n){
    //from where?
    rep(from,n){
      //to where?
      rep(to,n){
        chmin(dp[i|1<<to][to],dp[i][from]+dist(from,to));
      }
    }
  }
  cout << dp[(1<<n)-1][0] << endl;
}


#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

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

ll a,b,c;

int main()
{
	cin>>a>>b>>c;
	ll tmp=pw(b,c,4); tmp+=4;
	ll ans=pw(a,tmp,10);
	cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define per(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
const int N=59;

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

int n,m,col[N],res=0,ans=1;
bool vst[N];
bool ed[N][N];
vector<int>e[N],vec;

void dfs(int u,int ret=0) {
	vst[u]=1;
	vec.push_back(u);
	for(auto v:e[u]) if(!vst[v]) dfs(v);
}
void sfd(int pos) {
	if(pos==vec.size()) {
		res++;
		return;
	}
	rep(i,1,3) {
		bool qwq=1;
		rep(j,0,pos-1) if(ed[vec[pos]][vec[j]]&&col[j]==i) qwq=0;
		if(!qwq) continue;
		col[pos]=i;
		sfd(pos+1);
	}
}

signed main() {
	n=read(), m=read();
	rep(i,1,m) {
		int u=read(), v=read();
		e[u].push_back(v), e[v].push_back(u);
		ed[u][v]=ed[v][u]=1;
	}
	rep(i,1,n) if(!vst[i]) {
		vec.clear(), res=0;
		dfs(i);
		sfd(0);
		ans*=res;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	double x, y, z;
	cin >> x >> y >> z;
	double a = y / x;
	for (double b = 1;; b++) {
		if (b / z >= a) {
			cout << int(b) - 1 << endl;
			return 0;
		}
	}
}

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

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))

#define rep(i,n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i,n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i,n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i,n) for (int i = ((int)(n)); i >= 1; i--)
#define repl(i,l,n) for (int i = (l), i##_len = (n); i < i##_len; i++)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define mp make_pair

#define has_key(m, k) (m.find(k) != m.end())

#define INF (1e9)
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const ll mod = (1000000007);

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

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);

    cout << b - c << endl;

    return 0;
}