	#include <bits/stdc++.h>
	using namespace std;
	#define ll long long int
	#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
	#define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index];
	#define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
	#define mod 1000000007
	#define pb push_back
	#define mp make_pair
	#define ss second
	#define ff first
	#define vli vector<long long int>
	#define vlli vector<pair<long long int,long long int>>
	#define vsi vector<string>
	#define all(n) n.begin(),n.end()
	#define forn(i,a,b) for(i=a;i<b;i++)
	ll mul(ll x,ll y){  return (x*y)%mod;}
	ll power(ll x, ll y) {ll res = 1; x %= mod;
	 while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
	ll mod_inv(ll x) {return power(x, mod - 2);}
	ll fact(ll n) {ll res = 1; for (ll i = 2; i <= n; i++) res = mul(res , i); return res; }
	ll nCr(ll n, ll r) { return mul(fact(n),mod_inv(mul(fact(r),fact(n - r))));}

	int main() {
	  fast;
	  #ifndef ONLINE_JUDGE
	  freopen("input.txt","r",stdin);
	  freopen("output.txt","w",stdout);
	  #endif
	  ll t=1;
	  // cin>>t;
	  while(t--){
	   ll n,m,x,y;
	   cin>>n>>m>>x>>y;
	   x--;y--;
	   string s[n];
	   scan(s,n);
	   ll ans=1,i;
	   // cout<<x<<" "<<y<<endl;
	   i=x+1;
	   while(i<n){
	        if(s[i][y]=='.') ans++;
	        else break;
	        i++;
	   }
	   i=x-1;
	   while(i>=0){
	        if(s[i][y]=='.') ans++;
	        else break;
	        i--;
	   }
	   i=y-1;
	   while(i>=0){
	        if(s[x][i]=='.') ans++;
	        else break;
	        i--;
	   }
	   i=y+1;
	   while(i<m){
	        if(s[x][i]=='.') ans++;
	        else break;
	        i++;
	   }
	   cout<<ans<<endl;

	  }
	return 0;
	 }

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
LL N,K;
void solve() {
    while(K--){
        if(N%200==0)N/=200;
        else N=N*1000+200;
    }
    W(N);
}
void input() {
    R(N,K);
}
int main(){
    input();
    solve();
    return 0;
}


#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

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

void Main(){
    I(ll, M, H);
    if(H%M){
        cout << "No" << el;
    }else{
        cout << "Yes" << el;
    }
}

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

map<int,int>vis;

bool judge(int n)
{
    if(n&1) return false;
    for(auto it=vis.begin();it!=vis.end();it++)
    {
        if(it->second&1) return true;
    }
    return false;
}

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

    int T;cin>>T;
    while(T--)
    {
        int n;cin>>n;
        vis.clear();
        for(int val,i=1;i<=n;i++) cin>>val,vis[val]++;
        if(judge(n)) cout<<"First\n";
        else cout<<"Second\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
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;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int main() {
    ll n; cin >> n;
    ll ans = 0;
    ll v = 1000;
    rep(i,5) {
        ans += max<ll>(n - (v - 1), 0);
        v *= 1000;
    }
    cout << ans << endl;
}

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

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

  int n;
  cin >> n;

  for (int i = 0; i < 2 * n; i++) {
    cout << i % n + 1;
    if (i % 2 == 0) cout << " ";
    else cout << '\n';
  }
}


#include <iostream>
#include <vector>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<deque>
#include<set>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define req(i,n) for(int i = 1;i<=n;i++)
#define rrep(i,n) for(int i = n-1;i>=0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef double d;
typedef pair<int, int> P;
const int inf = 1 << 30;
struct liner {
	d a, b;
	liner(d a = 0, d b = 0): a(a), b(b) {}
	liner operator+(const liner& x)const {
		return liner(a + x.a, b + x.b);
	}liner operator-(const liner& x)const {
		return liner(a - x.a, b - x.b);
	}liner operator/(int x)const {
		return liner(a / x, b / x);
	}
};
int main() {
	int n, m, k,p,sum=0; cin >> n >> m >> k;
	vector<bool> f(n + 1, 0);
	rep(i, k) {
		cin >> p; f[p] = 1;
	}rep(i, n + 1) {
		if (f[i])sum++;
		else sum = 0;
		if (sum >= m) {
			cout << -1 << endl;
			return 0;
		}
	}vector<liner> dp(n + 1); liner S;
	rrep(i, n) {
		if (f[i]) dp[i] = liner(1, 0);
		else dp[i] = S / m + liner(0, 1);
		S = S+dp[i];
		if (i + m <= n) S = S - dp[i + m];
	}cout <<fixed<<setprecision(10) << dp[0].b / (1 - dp[0].a) << endl;
}

#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
double ans;
int n,all,dkfjklasdhfklasdfklasdhfklasdh[15],dksfhjkasdfhasdhflasdhfkl[2][15],dsakfasdjkfhjklasdhf[15]={1};
char s[2][N];
bool Check(int x,int y){
	++dksfhjkasdfhasdhflasdhfkl[0][x],++dksfhjkasdfhasdhflasdhfkl[1][y];
	int X=0,Y=0;
	for(int i=1;i<10;++i)X+=i*dsakfasdjkfhjklasdhf[dksfhjkasdfhasdhflasdhfkl[0][i]],Y+=i*dsakfasdjkfhjklasdhf[dksfhjkasdfhasdhflasdhfkl[1][i]];
	--dksfhjkasdfhasdhflasdhfkl[0][x],--dksfhjkasdfhasdhflasdhfkl[1][y];return X>Y;
}
int main(){
	cin>>n>>s[0]+1>>s[1]+1,all=n*9;
	for(int _=0;_<2;++_)for(int i=1;i<5;++i)++dkfjklasdhfklasdfklasdhfklasdh[s[_][i]&15],++dksfhjkasdfhasdhflasdhfkl[_][s[_][i]&15],--all;
	for(int i=1;i<9;++i)dsakfasdjkfhjklasdhf[i]=dsakfasdjkfhjklasdhf[i-1]*10;
	for(int i=1;i<10;++i){
		for(int j=1;j<10;++j){
			if(dkfjklasdhfklasdfklasdhfklasdh[i]>=n||dkfjklasdhfklasdfklasdhfklasdh[j]>=n||(i==j&&dkfjklasdhfklasdfklasdhfklasdh[i]>=n-1))continue;
			if(Check(i,j)){
				if(i==j){
					ans+=(double)1.0*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[i])/all)*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[j]-1)/(all-1));
				}
				else{
					ans+=(double)1.0*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[i])/all)*(1.0*(n-dkfjklasdhfklasdfklasdhfklasdh[j])/(all-1));
				}
			}
		}
	}
	printf("%.6lf",ans);
}


#include<bits/stdc++.h>
using namespace std;
int va[] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 };
int n;
long long x[55], ans = -1;
bool check(long long y) {
    for (int i = 0; i < n; i ++) if (__gcd(x[i], y) == 1) return false;
    return true;
}
void dfs(int d, long long val) {
    // printf("dfs( %2d, %lld )\n", d, val);
    if (d == 15) {
        if (check(val)) {
            if (ans == -1 || ans > val) ans = val;
        }
        return;
    }
    dfs(d+1, val);
    dfs(d+1, val*va[d]);
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i ++) cin >> x[i];
    dfs(0, 1);
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int gcd(ll n, ll m) {
    if (m == 0) return n;
    else return gcd(m, n % m);
}

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

    ll ans = INF;

    vector<int> vec(51, 1);
    vector<int> prime;

    vec[0] = 0; vec[1] = 0;
    for (int i = 2; i < 51; ++i) {
        for (int j = i * 2; j < 51; j += i) {
            vec[j] = 0;
        }
    }

    for (int i = 0; i < 51; ++i) {
        if (vec[i] == 1) prime.push_back(i);
    }

    for (int bits = 0; bits < (1 << prime.size()); ++bits) {
        ll temp = 1;
        for (int i = 0; i < prime.size(); ++i) {
            if (bits & (1 << i)) {
                temp *= prime[i];
            }
        }
        bool flg = false;
        for (int i = 0; i < n; ++i) {
            if (gcd(temp, x[i]) == 1) {
                flg = true;
                break;
            }
        }
        if (!flg) ans = min(ans, temp);
    }
    cout << ans << endl;

}


#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg bool f=false;
	reg char ch=getchar();
	reg int res=0;
	while(!isdigit(ch))f|=(ch=='-'),ch=getchar();
	while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
	return f?-res:res;
}
inline ll readll(void){
	reg bool f=false;
	reg char ch=getchar();
	reg ll res=0;
	while(!isdigit(ch))f|=(ch=='-'),ch=getchar();
	while(isdigit(ch))res=10ll*res+(ch^'0'),ch=getchar();
	return f?-res:res;
}

const int MAXN=50+5;

int n;
ll x;
ll a[MAXN];
map<ll,ll> f,g;

int main(void){
	n=read(),x=readll();
	for(reg int i=1;i<=n;++i)
		a[n-i+1]=readll();
	ll x0=x/a[1]*a[1];
	f[x0]=1;
	if(x0!=x)
		f[x0+a[1]]=1;
	for(reg int i=2;i<=n;++i){
		g.clear();
		reg ll Max=a[i-1]/a[i];
		for(auto it:f){
			reg ll d=x-it.first,m=d/a[i];
			ll y=it.first+m*a[i];
			if(abs(m)<Max)
				g[y]+=it.second;
			if(y!=x&&abs(m)+1<Max)
				g[y+a[i]*(d/abs(d))]+=it.second;
		}
		swap(f,g);
	}
	printf("%lld\n",f[x]);
	return 0;
}

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
LL N, X;
LL A[SIZE];
LL m[SIZE],v[SIZE];
LL dp[SIZE];
void solve() {
    for(int i=N;i>0;i--){
        v[i]=X/A[i];
        X%=A[i];
    }
    dp[0]=1;
    FOR(i,1,N){
        if(v[i]==m[i]-1){
            for(int j=i-1;j>=0;j--){
                dp[i]+=dp[j];
                if(v[j])break;
            }
            continue;
        }
        bool is_zero=1;
        for(int j=i;j>0;j--){
            if(v[j])is_zero=0;
            if(!is_zero){
                dp[i]+=dp[j-1];
            }
        }
    }
    LL an=0;
    for(int i=N;i>0;i--){
        an+=dp[i];
        if(v[i])break;
    }
    W(an);
}
void input() {
    R(N,X);
    FOR(i,1,N){
        R(A[i]);
        if(i>1)m[i-1]=A[i]/A[i-1];
    }
    m[N]=1e16;
}
int main(){
    input();
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define M 100005
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define syosu setprecision(10)
#define MAX_N (ll)2e5

int N ;
ll W ;

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

    ll pod[MAX_N + 2] ;
    memset(pod,0,sizeof(pod)) ;
    rep(i,N){
        int s , t ;
        ll p ;
        cin >> s >> t >> p ;
        pod[s] += p ;
        pod[t] -= p ;
    }
    ll sum = 0 ;
    bool ok = true ;
    for(int i = 0 ; i < MAX_N + 2 ; i++){
        sum += pod[i] ;
        if(sum > W) ok = false ;
    }
    if(ok) YES ;
    else NO ;
}

//QwQcOrZ yyds!!!
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,x) for (int i=head[x];i;i=e[i].nx)
#define mp make_pair
#define pb push_back
#define pa pair < int,int >
#define fi first
#define se second
#define re register
#define be begin()
#define en end()
#define sqr(x) ((x)*(x))
#define ret return puts("-1"),0;
#define put putchar('\n')
#define inf 1000000005
#define mod 998244353
#define int ll
#define N 100005
using namespace std;
inline char gc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
#define gc getchar
inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;}
inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x),putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
int n,a[N],b[N],c[N],B[N],ans;
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	for (int i=1;i<=n;i++) c[i]=read();
	for (int i=1;i<=n;i++)
	{
		B[b[c[i]]]++;
	}
	for (int i=1;i<=n;i++)
	{
		ans+=B[a[i]];
	}
	writeln(ans);
}
/*

*/


#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int n = input(), k = input();
  string s; cin >> s;

  auto result = [](string s) {
    int n = s.size() / 2;
    string t;
    range(i, 0, n) {
      string ss = s.substr(2 * i, 2);
      if (ss[0] == ss[1]) {
        t += ss[0];
        continue;
      }

      if (ss.find('R') == string::npos) {
        t += 'S';
      }
      if (ss.find('S') == string::npos) {
        t += 'P';
      }
      if (ss.find('P') == string::npos) {
        t += 'R';
      }
    }
    return t;
  };

  range(i, 0, k) {
    s = result(s + s);
  }

  cout << s[0] << endl;
}

signed main() {
  solve();
}

//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, K;
string S;

int f(int a, int b) {
    if (b - a == 1 || b - a == -2)
        return b;
    else
        return a;
}

map<int, char> M;

void solve() {
    M[0] = 'R';
    M[1] = 'P';
    M[2] = 'S';
    N *= 2;
    S += S;
    vi bef;
    for (auto& c : S) {
        if (c == 'R')
            bef.emplace_back(0);
        else if (c == 'P')
            bef.emplace_back(1);
        else
            bef.emplace_back(2);
    }

    int n = N / 2;

    while (K--) {
        vi now(N);
        for (int i = 0; i < n; i++) {
            int x = f(bef[i * 2], bef[i * 2 + 1]);
            now[i] = x;
            now[i + n] = x;
        }
        swap(now, bef);
    }
    cout << M[bef[0]] << endl;
}

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

    cin >> N >> K >> S;

    solve();
    return 0;
}


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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

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

const ll MX = 1e18;
ll N;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    ll i3 = 3;
    REP(i, 1, 50) {
    	ll j5 = 5;
    	REP(j, 1, 50) {
    		if(i3 > MX) break;
    		if(j5 > MX) break;
    		if(i3 + j5 == N) {
    			cout << i << " " << j << "\n";
    			return 0;
    		}
    		j5 *= 5;
    	}
    	i3 *= 3;
    }
    cout << -1 <<"\n";
    return 0;
}

#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
//ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
int gcd(int a,int b){
  return (b==0 ? a : gcd(b,a%b));
}
ll exp(ll b,ll e,ll m){
  b%=m;
  ll ans = 1;
  for (; e; b = b * b % m, e /= 2)
      if (e & 1) ans = ans * b % m;
  return ans;
}
const int N = 2020;
int A[N];

map<int,vi> here;

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

  int mn = 2e9 + 7;
  for(int i=1;i<=n;i++){
    cin >> A[i];
    mn=min(mn,A[i]);
  }
  for(int i=1;i<=n;i++){

    for(int x=1;x*x<=A[i];x++){
      if(A[i]%x==0){
        if(x<=mn)here[x].pb(A[i]);
        if((A[i]/x)!=x and (A[i]/x)<=mn)here[A[i]/x].pb(A[i]);
      }
    }

  }

  int res=0;
  for(auto it : here){
    int g = it.ss[0];
    for(auto x : it.ss)g = gcd(g,x);
    if(g!=it.ff)continue;
   // cout << it.ff << endl;
    res++;
  }
  cout << res << endl;

  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}


#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

int main(){
	int a = readint(), b = readint();
	int w = readint()*1000;
	int k = (w-1)/b+1; // b*k >= w
	if(a*k > w){
		puts("UNSATISFIABLE");
		return 0;
	}
	printf("%d ",k);
	k = w/a; // a*k <= w
	printf("%d\n",k);
	return 0;
}

#include <iostream>

main() {
  int64_t n;
  std::cin >> n;
  for(int64_t i = 1; ; i++) {
    if(std::stoll(std::to_string(i) + std::to_string(i)) > n) {
      std::cout << i - 1;
      break;
    }
  }
}


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

int64_t mod = 1000000007;

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> v(H);
  for(int i = 0;i < H;i++)
    cin >> v.at(i);
  vector<int64_t> H_sum(H, 0);
  vector<int64_t> W_sum(W, 0);
  vector<int64_t> D_sum(H + W, 0);
  int64_t dp[H][W];
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      if(i == 0 && j == 0){
        dp[0][0] = 1;
        H_sum.at(0) = 1;
        W_sum.at(0) = 1;
        D_sum.at(W - 1) = 1;
      }
      else{
        if(v.at(i).at(j) == '.'){
          dp[i][j] = (H_sum.at(i) + W_sum.at(j) + D_sum.at(i - j + W - 1)) % mod;
          H_sum.at(i) += dp[i][j];
          W_sum.at(j) += dp[i][j];
          D_sum.at(i - j + W - 1) += dp[i][j];
        }
        else{
          H_sum.at(i) = 0;
          W_sum.at(j) = 0;
          D_sum.at(i - j + W - 1) = 0;
        }
      }
    }
  }
  cout << (dp[H - 1][W - 1]) % mod << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

//typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int mod = 1e9 + 7;
//const ll INF = 1e18;
const double EPSILON = 1e-10;
const int N = 2005;
char t[N][N];
int l[N][N], c[N][N], d[2][N][N];
vi ll[N], cc[N], dd[2][N];
int add(int a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}
int sub(int a, int b){
    a -= b;
    if(a < 0)
        a += mod;
    return a;
}
int main(){
    fastio;
    int n,m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> t[i][j];
    for(int i = 0; i < N; i++)
        ll[i].pb(0), cc[i].pb(0), dd[0][i].pb(0), dd[1][i].pb(0);
    if(n == 1 and m == 1){
        cout << 1 << '\n';
        return 0;
    }
    l[1][1] = c[1][1] = d[0][0][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(i == 1 and j == 1)continue;
            if(t[i][j] == '#'){
                ll[i].pb(i);
                cc[j].pb(j);
                if(i-j >= 0){
                    dd[0][i-j].pb(i);
                }else{
                    dd[1][j-i].pb(i);
                }
            }else{
                int tmp = 0;
                tmp = add(tmp, sub(l[i-1][j], (ll[i][sz(ll[i])-1] > 0 ? l[ ll[i][sz(ll[i])-1] ][j] : 0)));
                tmp = add(tmp, sub(c[i][j-1], (cc[j][sz(cc[j])-1] > 0 ? c[i][ cc[j][sz(cc[j])-1] ] : 0)));

                if(i-j>=0){
                    tmp = add(tmp, sub(d[0][i-j][i-1], (dd[0][i-j][sz(dd[0][i-j])-1] > 0 ? d[0][i-j][ dd[0][i-j][sz(dd[0][i-j])-1] ] : 0)));
                }else{
                    tmp = add(tmp, sub(d[1][j-i][i-1], (dd[1][j-i][sz(dd[1][j-i])-1] > 0 ? d[1][j-i][ dd[1][j-i][sz(dd[1][j-i])-1] ] : 0)));
                }
                if(i == n and j == m){
                    cout << tmp << '\n';
                }
                l[i][j] = add(l[i-1][j], tmp);
                c[i][j] = add(c[i][j-1], tmp);
                if(i-j >= 0){
                    d[0][i-j][i] = add(d[0][i-j][i-1], tmp);
                }else{
                    d[1][j-i][i] = add(d[1][j-i][i-1], tmp);
                }
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, start, end) for (int i = start; i <= end; i++)
#define rloop(i, start, end) for (int i = start; i >= end; i--)
#define vi vector<int>
#define vec(x) vector<x>
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define all(v) (v).begin(),(v).end()
#define arl(v) (v).rbegin(),(v).rend()
#define fsp(a) fixed<<setprecision(a)
#define mem(a,with) memset(a, with, sizeof (a))
#define vmn(a) (*min_element(a.begin(),a.end()))
#define vmx(a) (*max_element(a.begin(),a.end()))
#define bs(a,key) binary_search(all(a),key)    /// return bool.
#define rotl(a,x) rotate(a.begin(),a.begin()+x,a.end());
#define rotr(a,x) rotl(a,a.size()-x);
#define nl cout<<endl
#define dbg(x) cerr << #x << " :: " << x << endl;
#define dbg2(x, y) cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define MOD 1000000007
int add(int x, int y) {int res = x + y; return (res >= MOD ? res - MOD : res);}
int mul(int x, int y) {int res = x * y; return (res >= MOD ? res % MOD : res);}
int power(int x, int y) {int res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void solve(){
    //code goes here
    int n,k;
    cin>>n>>k;
    vec(vi) cost(n+1,vi(n+1,0));
    loop(i,1,n){
        loop(j,1,n) cin>>cost[i][j];
    }

    vi arr;
    int ans=0;
    loop(i,2,n) arr.push_back(i);
    do{
        int i=0,sum=0;
        int l=1,r=arr[i];
        while(i<arr.size()){
            sum+=cost[l][r];
            // cout<<cost[l][r]<<endl;
            i++;
            l=r;r=arr[i];
            // cout<<i<<" "<<l<<" "<<r<<endl;
        }
        r=arr[arr.size()-1];
        sum+=cost[r][1];
        // cout<<sum<<endl;
        if(sum==k) ans++;
    }while(next_permutation(all(arr)));
    cout<<ans;
}

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

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

const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
using ll = long long;

int main(){
  int n, k;
  cin >> n >> k;
  vector<vector<int>> t(n, vector<int>(n));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> t[i][j];
    }
  }

  vector<int> order;
  for(int i = 1; i < n; i++){
    order.push_back(i);
  }

  int ans = 0;
  do{
    int sum = 0;
    sum += t[0][order[0]];
    for(int i = 0; i < order.size(); i++){
      // cout << order[i];
      if(i == order.size()-1) sum += t[order[i]][0];
      else sum += t[order[i]][order[i+1]];
    }
    // cout << endl;
    if(sum == k) ans ++;
  }while(next_permutation(order.begin(), order.end()));

  cout << ans << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2007;
int a[N],b[N];
int main()
{
	int A,B,C; scanf("%d%d",&A,&B);
	C=max(A,B);
	for(int i=1;i<=C;i++)a[i]=i,b[i]=-i;
	for(int i=C;i>=A+1;i--)a[i-1]+=a[i];
	for(int i=C;i>=B+1;i--)b[i-1]+=b[i];
	for(int i=1;i<=A;i++)printf("%d ",a[i]);
	for(int i=1;i<=B;i++)printf("%d ",b[i]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long   ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll>  vl;
typedef vector<pair<int,int>> vpi;
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb    push_back
#define mp    make_pair
#define rev(i,a,b) for(int i=a;i<b;i++)
#define sz(a)   (int)a.size()
#define all(a)  a.begin(),a.end()
//const ll  MOD =998244353;
ll  gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
        for(int i=1;i<=a;i++)
        cout<<i<<" ";
        for(int i=1;i<=b;i++)
        cout<<-i<<" ";
    }
    else
    {
        if(a>b)
        {
            ll s=a*(a+1)/2;
            ll s1=(b-1)*b/2;
            for(int i=1;i<=a;i++)
            cout<<i<<" ";
            for(int i=1;i<b;i++)
            cout<<-i<<" ";
            cout<<s1-s<<" ";
        }
        else
        {
            for(int i=1;i<=b;i++)
            cout<<-i<<" ";
            for(int i=1;i<a;i++)
            cout<<i<<" ";
            cout<<abs((a*(a-1)/2)-(b*(b+1)/2))<<" ";
        }
    }
}


/**
 * Author: Daniel
 * Created Time: 2021-04-03 10:23:06
**/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define ER erase
#define IS insert
#define PI acos(-1)
#define PB pop_back
#define MP make_pair
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define lowbit(x) (x & -x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10)

typedef long long LL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef pair<LL, LL> PLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef vector<pair<LL, LL> > VPLL;
typedef vector<pair<int, int> > VPII;

template <typename A> using VE = vector<A>;
template <typename A> using USET = unordered_set<A>;
template <typename A> using HEAP = priority_queue<A>;
template <typename A, typename B> using PA = pair<A, B>;
template <typename A, typename B> using UMAP = unordered_map<A, B>;
template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;

template <typename A> A MAX(const A &a) { return a; }
template <typename A> A MIN(const A &a) { return a; }
template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); }
template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); }
template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); }
template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); }

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

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

// check the limitation!!!
const int N = 100010, M = 1010;

// read the question carefully!!!
int main()
{
    SOS;

    int n;
    cin >> n;
    VPLL a(n);
    for (auto &[x, y] : a) cin >> x >> y;
    int m;
    cin >> m;
    bool flag = false;
    LL sx = 1, sy = 1;
    LL cx = 0, cy = 0;
    VE<tuple<bool, LL, LL, LL, LL>> op;
    op.EB(MT(flag, sx, cx, sy, cy));
    for (int i = 0; i < m; i ++ )
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            flag = !flag;
            sx = -sx;
            cx = -cx;
            swap(sx, sy);
            swap(cx, cy);
        }
        else if (t == 2)
        {
            flag = !flag;
            sy = -sy;
            cy = -cy;
            swap(sx, sy);
            swap(cx, cy);
        }
        else if (t == 3)
        {
            LL p;
            cin >> p;
            sx = -sx;
            cx = 2 * p - cx;
        }
        else if (t == 4)
        {
            LL p;
            cin >> p;
            sy = -sy;
            cy = 2 * p - cy;
        }
        else assert(false);
        op.EB(MT(flag, sx, cx, sy, cy));
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i ++ )
    {
        int c, b;
        cin >> c >> b;
        b -- ;
        LL x, y;
        auto [flag, sx, cx, sy, cy] = op[c];
        if (!flag) x = sx * a[b].F + cx, y = sy * a[b].S + cy;
        else x = sx * a[b].S + cx, y = sy * a[b].F + cy;
        cout << x << ' ' << y << '\n';
    }
    return 0;
}

// GOOD LUCK!!!


#ifdef _LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

static const ld PI = 3.141592653589793;

pair<ld, ld> solve(int n, ld x, ld y, ld x2, ld y2) {
    ld xm = (x + x2) / (ld)2, ym = (y + y2) / (ld)2;
    ld vec_x = x - xm, vec_y = y - ym;

    ld dec = (ld)360 / (ld)n;
    ld rad = PI * dec / (ld)180;

    ld vec_xc = (ld)cos(rad) * vec_x - (ld)sin(rad) * vec_y,
       vec_yc = (ld)sin(rad) * vec_x + (ld)cos(rad) * vec_y;

    return make_pair(xm + vec_xc, ym + vec_yc);
}

#ifndef _LOCAL
int main() {
    int n;
    ld x, y, x2, y2;
    cin >> n >> x >> y >> x2 >> y2;
    pair<ld, ld> res = solve(n, x, y, x2, y2);
    cout << fixed << setprecision(12) << res.first;
    cout << " ";
    cout << fixed << setprecision(12) << res.second << endl;
}
#endif

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bits/stdc++.h>

#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
using LL = long long;

typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

const double PI = 3.14159265358979323846264338327950L;
const int mod = 1e9+7;
const ll INF = 1LL<<60;

struct container {
    int bottom, top, id;
    container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) {
    }
};

struct Edge {
    ll to, from, cost;
    Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {}
    Edge(): to(-1), from(-1), cost(0){}
};

struct Data {
    ll cost,val;
    Data(ll cost=0, ll val=0) : cost(cost), val(val){}
    bool operator<(const Data& a) const {
        return cost > a.cost;
    }
};

struct edge{
    int a,b,c;
    edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){}
    bool operator<(const edge& a) const {
        return c > a.c;
    }
};

using C = complex<double>;

C inC(){
    double x,y;
    cin >> x >> y;
    return {x,y};
}
void solve(){
    int n;
    cin >> n;
    C a = inC(), b = inC();
    C o = (a+b)/2.;
    double theta = 2*PI/n;
    C r = {cos(theta),sin(theta)};

    C c =r*(a-o)+o;

    printf ("%.10f %.10f",c.real(),c.imag());

}

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

    while (T--) {
        solve();
        // cout << 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), i##end = (b); i >= i##end; --i)

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++)
	#define gc getchar()
	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); }
}

const int MAXN = 5000 + 10;
const int P = 998244353;

int H, W, K, cntrow[MAXN][MAXN], cntcol[MAXN][MAXN], f[MAXN][MAXN][3], tag[MAXN][MAXN][3];
int pow3[MAXN];

int qpower(int a, int x) {
	int ret = 1;
	for (; x; x >>= 1, a = 1ll * a * a % P) ret = 1ll * ret * a % P;
	return ret;
}

int toint(char ch) { return (ch == 'D' ? 0 : (ch == 'R' ? 1 : 2)); }

void add(int& a, int b) { a = a + b >= P ? a + b - P : a + b; }

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(H), IO::read(W), IO::read(K);
	pow3[0] = 1;
	rep(i, 1, max(H, W)) pow3[i] = 1ll * pow3[i - 1] * 3 % P;
	rep(i, 1, K) {
		int x, y; char c[10]; IO::read(x), IO::read(y); scanf("%s", c + 1);
		tag[x][y][toint(c[1])] = true;
	}
	rep(i, 1, H) rep(j, 1, W) cntrow[i][j] = cntrow[i][j - 1] + ((tag[i][j][0] + tag[i][j][1] + tag[i][j][2]) == 0);
	rep(i, 1, W) rep(j, 1, H) cntcol[j][i] = cntcol[j - 1][i] + ((tag[j][i][0] + tag[j][i][1] + tag[j][i][2]) == 0);

	int tt = -1;
	rep(v, 0, 2) if (tag[1][1][v]) tt = v;
	if (tt != -1) f[1][1][tt] = true;
	else {
		rep(v, 0, 2) f[1][1][v] = true;
	}
	rep(i, 1, H) rep(j, 1, W) {
		if (i == 1 && j == 1) continue;
		int tt = -1;
		rep(v, 0, 2) {
			if (tag[i][j][v]) tt = v;
			add(f[i][j][v], 1ll * (f[i - 1][j][2] + f[i - 1][j][0]) * pow3[cntrow[i][j - 1]] % P);
			add(f[i][j][v], 1ll * (f[i][j - 1][2] + f[i][j - 1][1]) * pow3[cntcol[i - 1][j]] % P);
		}
		if (tt != -1) {
   			rep(v, 0, 2) if (v != tt) f[i][j][v] = 0;
		}
	}
	int ans = 0;
	rep(v, 0, 2) add(ans, f[H][W][v]);
	IO::write(ans);
	return 0;
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

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

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

vvi f(vi &A, string &s, int k) {
  int N = s.size();
  vvi ans(k, vi(N+1));
  rep(i,0,N+1) {
    int a = A[i];
    int q = a/k;
    int re = a%k;
    rep(j,0,k) {
      ans[j][i] += q;
    }
    rep(j,0,k) {
      if (re) {
        ans[j][i] += 1; re--;
      } else break;
    }
  }
  return ans;
};

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

  int N; cin >> N;
  string s; cin >> s;
  vi A(N+1); rep(i,0,N+1) cin >> A[i];

  int k = INF;
  rep(i,0,N) chmin(k, abs(A[i]-A[i+1]));

  vvi ans = f(A, s, k);

  cout << ans.size() << endl;
  for (vi &a: ans) {
    rep(i,0,N+1) {
      cout << a[i];
      if (i < N) cout << " ";
    }
    cout << endl;
  }

  return 0;
};


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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>

int N, M;
int D[2010];
vector<pii> V[2010];

int unit(int s)
{
    int ret = 1e18;
    memset(D, -1, sizeof(D));
    priority_queue<pii, vector<pii>, greater<pii>> que;
    que.push({0, s});
    while(que.size())
    {
        pii tmp = que.top();
        que.pop();
        int v = tmp.second;
        int d = tmp.first;
        if(D[v] != -1)continue;
        D[v] = d;
        for(auto e : V[v])
        {
            int n = e.first;
            int c = e.second;
            if(n == s)ret = min(ret, d + c);
            else que.push({d + c, n});
        }
    }

    if(ret == 1e18)return -1;
    return ret;
}

signed main()
{
    cin >> N >> M;
    rep(i, M)
    {
        int a, b, c;
        cin >> a >> b >> c;
        V[a].push_back({b, c});
    }

    for(int i = 1; i <= N; i++)cout << unit(i) << endl;

    return 0;
}

//Inshallah , Boys played well..!!

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pb push_back
#define pf push_front
#define mk make_pair
#define f(i,j,n) for(ll i=j;i<n;i++)
#define r(i,n,j) for(ll i=n-1;i>=j;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define Test int t;cin>>t;while(t--)
#define mod 1000000007
#define md 998244353
#define MIN INT_MIN
#define MAX INT_MAX
#define inf LLONG_MAX
#define all(container) container.begin() , container.end()
#define rall(container) container.rbegin() , container.rend()
#define sz(container) (int)container.size()
#define vll vector<long long>
#define vi vector<int>
#define pii pair <int , int>
#define pll pair <ll , ll>
#define fi first
#define se second
#define setp(x) setprecision(x)
#define meme(x,i) memset(x,i,sizeof(x))
#define lb lower_bound
#define ub upper_bound
#define me max_element
#define debug(this) cout << "this = " << this << endl;
const int N = 2005;
vector<pair<int,int>> g[N];
int dis[N][N],dis2[N][N],w;
int n,m,x,y;
int z;
void dijikstra(int u){
    priority_queue< pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;
    pq.push({0,u});
    while(!pq.empty()){
        pair<int,int> p=pq.top();
        pq.pop();
        for(auto i:g[p.se]){
            if(dis2[u][i.fi]>dis2[u][p.se]+i.se){
                dis2[u][i.fi]=dis2[u][p.se]+i.se;
                pq.push({dis2[i.fi][u],i.fi});
            }
        }
    }
}
void solve() {
    cin >> n >> m;
    f(i,0,n+2){
        f(j,0,n+2)
            dis[i][j]=dis2[i][j]=3e8;
    }
    f(i,0,m){
        cin >> x >> y >> w;
        dis[x][y]=min(dis[x][y],w);
    }
    f(i,1,n+1){
    	f(j,1,n+1){
    		if(dis[i][j]!=3e8 and i!=j)
        	g[i].pb({j,dis[i][j]});
    	}
    }
    f(i,1,n+1){
    	dis2[i][i]=0;
    	dijikstra(i);
    }
    f(i,1,n+1){
    	int ans=dis[i][i];
    	f(j,1,n+1){
    		if(i!=j)
    		ans=min(ans,dis2[i][j]+dis2[j][i]);
    	}
    	if(ans>=3e8)
    		cout << -1 << endl;
    	else
    		cout << ans << endl;
    }
}

int main() {
    fast;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++) {
        //cout << "Case #" << i << ": ";
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a,b) memset(a, b, sizeof(a))
#define dbg(x) cout << "[" << #x << "]: " << x << endl;
#define forn(i,n) for(int i=0; i < n;i++)
#define forab(i,a,b) for(int i = a; i <= b; i++)
#define forba(i,b,a) for(int i = b; i >= a; i--)
#define each(val, v) for(auto val : v)
#define abs(u) (u >= 0 ? u : -u)

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

const int MAXN = 2e6 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

int uf[MAXN];
int sz[MAXN];

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

    return uf[u] = find(uf[u]);
}

int uni(int a, int b){
    int aa= find(a), bb = find(b);

    if(aa == bb) return 0;

    if(sz[aa] > sz[bb]) swap(aa,bb);

    uf[aa] = bb;
    sz[bb] += sz[aa];

    return 1;
}

int col(int i){
    return i + 1005;
}

int line(int i){
    return i;
}

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

    forn(i, 5000){
        uf[i] = i;
    }
    uni( col(0), line(0) );
    uni( col(m-1), line(n-1) );

    uni(col(0), col(m-1));

    forn(i,n){
        string s;
        cin>> s;
        forn(j,m){
            if(s[j] == '#'){
                uni( line(i), col(j) );
            }
        }
    }

    set<int> lines;
    set<int> cols;
    int ans = n + m;

    forn(i,n){
        int x = find(line(i));

        lines.insert( x);
    }

    forn(i,m){

        int x = find( col(i) );
        cols.insert( x );
    }

    int sz = lines.size();
    ans = min(ans, sz -1);
    sz = cols.size();
    ans = min(ans, sz-1);

    cout << ans << '\n';

}

int main(){

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

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

    return 0;
}

//
// Created by mihai145 on 23.02.2021.
//

#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int NMAX = 1000;

int N, M;
vector<int> g[2 * NMAX + 5];
bool vis[2 * NMAX + 5];

void dfs(int node) {
    vis[node] = true;

    for(auto it : g[node]) {
        if(!vis[it]) {
            dfs(it);
        }
    }
}

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

    cin >> N >> M;

    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;

        for(int j = 0; j < M; j++) {
            if(s[j] == '#') {
                g[i + 1].push_back(N + j + 1);
                g[N + j + 1].push_back(i + 1);
            }
        }
    }

    g[1].push_back(N + 1);
    g[N + 1].push_back(1);

    g[1].push_back(N + M);
    g[N + M].push_back(1);

    g[N].push_back(N + 1);
    g[N + 1].push_back(N);

    g[N].push_back(N + M);
    g[N + M].push_back(N);

    int compN = 0, compM = 0;

    for(int i = 1; i <= N; i++)
        if(!vis[i]) {
            compN++;
            dfs(i);
        }

    for(int i = 1; i <= N + M; i++)
        vis[i] = false;

    for(int i = 1; i <= M; i++)
        if(!vis[i + N]) {
            compM++;
            dfs(i + N);
        }

    cout << min(compN, compM) - 1 << '\n';

    return 0;
}


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

int char2int(char c) {
    assert(c >= '0' && c <= '9');
    return c - '0';
}

int getscore(int a[]) {
    int ans = 0;
    for (int i = 1; i < 10; i++) {
        ans += i * pow(10, count(a, a + 5, i));
    }
    return ans;
}

int main() {
    int k;
    cin >> k;
    string s, t;
    cin >> s >> t;
    double ans = 0;
    int l[10];
    int u[5], v[5];
    for (int i = 0; i < 10; i++) l[i] = k;
    for (int i = 0; i < 4; i++) {
        l[char2int(s[i])]--;
        l[char2int(t[i])]--;
        u[i] = char2int(s[i]);
        v[i] = char2int(t[i]);
    }
    sort(u, u + 4);
    sort(v, v + 4);
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i == j) {
                if (l[i] <= 1) continue;
            } else {
                if (l[i] == 0 || l[j] == 0) continue;
            }
            u[4] = i;
            v[4] = j;
            if (getscore(u) > getscore(v)) {
                if (i == j) {
                    ans += (l[i] / (double)(9 * k - 8)) * ((l[i] - 1) / (double)(9 * k - 9));
                } else {
                    ans += (l[i] / (double)(9 * k - 8)) * (l[j] / (double)(9 * k - 9));
                }
            }
        }
    }
    printf("%.16f\n", ans);
}

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

#define int long long
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, set<int>> M;
    REP(i, m) {
    	int r, c;
    	cin >> r >> c;
    	M[r].insert(c);
    }
   	set<int> pos;
    pos.insert(n);
    for (auto [r, v] : M) {
    	set<int> new_pos, to_check;
    	// for (int y : pos) {
    	// 	if (v.find(y - 1) != v.end()) {
    	// 		new_pos.insert(y - 1);
    	// 	}
    	// 	if (v.find(y + 1) != v.end()) {
    	// 		new_pos.insert(y + 1);
    	// 	}
    	// 	if (v.find(y) == v.end()) {
    	// 		new_pos.insert(y);
    	// 	}
    	// }
        for (int y : v) {
            to_check.insert(y - 1);
            to_check.insert(y + 1);
            to_check.insert(y);
        }
        for (int y : to_check) {
            if (pos.find(y) == pos.end()) continue;
            if (v.find(y - 1) != v.end()) {
                new_pos.insert(y - 1);
            }
            if (v.find(y + 1) != v.end()) {
                new_pos.insert(y + 1);
            }
            // if (pos.find(y) != pos.end()) {
            //     pos.erase(pos.find(y));
            // }
            if (v.find(y) != v.end()) {
                pos.erase(pos.find(y));
            }
        }
        for (int y : new_pos) {
            pos.insert(y);
        }
    	// set<int> had;
    	// for (int y : v) {
    	// 	if (pos.find(y) != pos.end()) {
    	// 		pos.erase(pos.find(y));
    	// 		had.insert(y);
    	// 	}
    	// }
    	// for (int y : v) {
    	// 	if (had.find(y - 1) != had.end() || pos.find(y - 1) != pos.end()) {
    	// 		pos.insert(y);
    	// 	}
    	// 	if (had.find(y + 1) != had.end() || pos.find(y + 1) != pos.end()) {
    	// 		pos.insert(y);
    	// 	}
    	// }
    }
    cout << SZ(pos) << endl;
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<vector<int>> adList(N);
	REP(i, N)
	{
		string S; cin >> S;
		REP(j, N)
		{
			if (S[j] == '1')
			{
				adList[i].push_back(j);
			}
		}
	}
	vector<set<int>> ss(N);
	REP(s, N)
	{
		deque<int> Q{ s };
		vector<bool> arrived(N, false);
		arrived[s] = true;
		while (!Q.empty())
		{
			int t = Q.front(); Q.pop_front();
			ss[t].insert(s);
			for (const int n : adList[t])
			{
				if (arrived[n]) continue;
				Q.push_back(n);
				arrived[n] = true;
			}
		}
	}

	double ans = 0.0;
	REP(s, N)
	{
		const double sv = static_cast<double>(ss[s].size());
		ans += 1.0 / sv;
	}
	cout << setprecision(12) << ans << endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define X 200010
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
#define N 110
ll n;
bool s[N][N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)rep(j,n){
		char z;
		cin>>z;
		s[i][j]=z-'0';
	}
	rep(i,n)s[i][i]=1;
	rep(k,n)rep(i,n)rep(j,n){
		s[i][j]|=(s[i][k]&s[k][j]);
	}
	double ans=0;
	rep(i,n){
		ll sum=0;
		rep(j,n)if(s[j][i])sum++;
		ans+=1.0/(double)sum;
		cerr<<sum<<endl;
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
#define F first
#define S second
#define MOD 1e9+7
const int inf = 1e9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    ll A = abs(a), B = abs(b);
    if(c%2==0){
        if(A > B) cout << ">" << endl;
        else if(A < B) cout << "<" << endl;
        else cout << "=" << endl;
    }else{
        if(a > b) cout << ">" << endl;
        else if(a < b) cout << "<" << endl;
        else cout << "=" << endl;

    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int N;
string S, X;

int dp[200000 + 100][7];//dp[i][j] := 1-idxでi桁目まで作ったときに、余りがjの時のgrundy数
//0なら高橋の勝ち

int memo(int digit, int mod) {
	//digitは0-idx
	if (digit == N) {
		if (mod == 0)return dp[digit][mod] = 0;
		else return dp[digit][mod] = 1;
	}
	if (dp[digit][mod] != -1)return dp[digit][mod];

	int ret = -1;
	if (X[digit] == 'A') {
		//Tを勝たせたくない　遷移先のどれかに0以外があればOK

		//0を追加
		int add0 = memo(digit + 1, (mod * 10) % 7);
		//S[i]を追加
		int addSi = memo(digit + 1, (mod * 10 + (S[digit] - '0')) % 7);
		if (add0 != 0 || addSi != 0)
			ret = 1;
		else
			ret = 0;
	}
	else {
		//Tなので勝ちたい。遷移先のどれかに0があればOK

		//0を追加
		int add0 = memo(digit + 1, (mod * 10) % 7);
		//S[i]を追加
		int addSi = memo(digit + 1, (mod * 10 + (S[digit] - '0')) % 7);

		if (add0 == 0 || addSi == 0)
			ret = 0;
		else
			ret = 1;

	}

	return dp[digit][mod] = ret;
}

int main() {
	cin >> N >> S >> X;
	for (int i = 0; i <= N; i++)for (int j = 0; j < 7; j++)dp[i][j] = -1;

	int ret = memo(0, 0);

	if (ret == 0)cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define Rep(i,j,n) for(int i = j; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n;
    cin >> n;
    map<int, string> m;
    rep(i,n){
        string s;
        int t;
        cin >> s >> t;
        m[t] = s;
    }
    int num = 1, cnt = 0;
    for (auto i = m.rbegin(); i != m.rend(); ++i) {
        if(cnt == num) {
            cout << i->second << endl;
            return 0;
        }
        cnt++;
    }

    return 0;
}

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

//cout << fixed << setprecision(15)
//ASCIIコード 0==48　A==65 Z==90, a==97 z==122

int main(){
  string N; cin>>N;
  ll cnt=0;
  reverse all(N);
  rep(i,N.size()){
     if(N[i]=='0')  cnt++;
    else break;
  }
 rep(i,cnt){
    N.push_back('0');
 }
 string S=N; reverse all(N);
  if(S==N){cout <<"Yes"<<endl; ret 0;}
   cout <<"No"<<endl;
}


//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);}
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
struct Init_io {
    Init_io() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << boolalpha << fixed << setprecision(15);
    }
} init_io;
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    INT(n);
    vi v(n * 2);
    cin >> v;
    ll ans = 0;
    priority_queue<int> pq;
    rep(i, n) {
        pq.push(v[i]);
        pq.push(v[n * 2 - 1 - i]);
        ans += pq.top();
        pq.pop();
    }
    fin(ans);
}

/*                 thisiscaau's  code
        What’s happened happened. Which is an expression of faith
    in the mechanics of the world. It’s not an excuse to do nothing.
*/
/* shortcuts */
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")*/
// for emergency cases
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
/* constants */
ll const inf = 1e9 + 7, MAXN = 2e5 + 5;
/* declaration */
ll n,m,tc;
ll a[MAXN << 1];
/* workspace */
ll sum;
priority_queue<ll,vector<ll>,greater<ll>> pq;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 1 ; i <= 2*n ; i++){
        cin >> a[i]; sum += a[i];
    }
    ll lf = n,rt = n+1;
    while (lf >= 1 && rt <= 2*n){
        pq.push(a[lf]); pq.push(a[rt]);
        sum -= pq.top(); pq.pop();
        lf--; rt++;
    }
    cout << sum;
}


#include<bits/stdc++.h>
using namespace std;
int m,h;
int main(){
	cin>>m>>h;
	if(h%m==0)cout<<"Yes";
	else cout<<"No";
}

#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

vector<ll> SieveOfEratosthenes(ll n)
{
    vector<ll> ans;
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++)
        if (prime[p] == true)
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;

    for (int p = 2; p <= n; p++)
        if (prime[p])
            ans.push_back(p);
    return ans;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

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

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

    return true;
}

void solve()
{
    ll i, j, n, m;
    cin>>n>>m;
    if(m%n){
        cout <<"No"<<endl;
    }
    else{
        cout <<"Yes"<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}

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

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

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


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

void solve()
{
  ll A, B, C;
  std::cin >> A >> B >> C;

  if (A*A + B*B < C*C) {
    print("Yes");
  } else {
    print("No");
  }

  return;
}

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

  solve();
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

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

int main()
{
   LL a, b, c;
   string output = "No";

   cin >> a >> b >> c;

   a *=a;
   b *= b;
   c *= c;

   if(a+b < c)
    output = "Yes";

    cout << output << endl;

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

struct bag{
	ll w,v;
};

struct Box{
	ll num,x;
};

bool compbag(bag& a, bag& b){
	return a.v > b.v;
}

bool compbox(Box& a, Box& b){
	return a.x < b.x;
}

int main(){
	int n,m,q;
	cin >> n >> m >> q;
	vector<bag> b(n);
	REP(i,n) cin >> b[i].w >> b[i].v;
	sort(b.begin(), b.end(), compbag);
	vector<Box> box(m);
	REP(i,m){
		cin >> box[i].x;
		box[i].num = i;
	}
	sort(box.begin(), box.end(), compbox);
	REP(query,q){
		int l,r;
		cin >> l >> r;
		l--; r--;

		ll ans=0;
		vector<bool> emp(m,true);
		REP(i,n){
			REP(j,m){
				if(l <= box[j].num && box[j].num <= r)continue;

				if(emp[j] && b[i].w <= box[j].x){
					emp[j] = false;
					ans +=  b[i].v;
					break;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

void solve(){
    int x,y,z;
    cin>>x>>y>>z;
    for(int i=1000000;i>=0;i--){
        if(i*x < y*z){
            cout<<i;
            return;
        }
    }
}
int main(){
    ios::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            cout<<fixed;
            cout<<setprecision(10);
    //        freopen("timber_input.txt", "r", stdin);
    //        freopen("timber_output.txt", "w", stdout);
            int t=1;
            // cin>>t;
            for(int i=1;i<=t;i++){
            //    cout<<"Case #"<<i<<": ";
                solve();
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*

*/

char add_wbr(char a, char b){
  if (a==b) return(a);
  if (a=='W' && b=='R') return('B');
  if (a=='W' && b=='B') return('R');
  if (a=='B' && b=='W') return('R');
  if (a=='B' && b=='R') return('W');
  if (a=='R' && b=='W') return('B');
  if (a=='R' && b=='B') return('W');
  return (0);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll N;
  string S;
  cin >> N >> S;
  ll sz=S.size();
  while (sz>1){ // 4->1, 5->4->1
    while(sz%3!=1){
      string T;
      for(ll j=0; j<sz-1; j++)
        T+=add_wbr(S[j], S[j+1]);
      S=T;
      sz=S.size();
    }
    string T;
    for(ll j=0; j+3<sz; j+=3)
      T+=add_wbr(S[j], S[j+3]);
    if (T[0]) S=T;
    sz=S.size();
  }
  cout << S[0] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v[n];
    int x, y, z;
    rep(i, m) {
        cin >> x >> y >> z;
        x--;
        v[x].emplace_back(y, z);
    };
    ll dp[1 << n] = {};
    dp[0] = 1;
    for (int bit = 0; bit < 1 << n; bit++) {
        if (!dp[bit]) continue;
        rep(use, n) {
            if (bit >> use & 1) continue;
            int nxt = bit | 1 << use;
            bool ng = false;
            for (auto p : v[__builtin_popcount(bit)]) {
                int cnt = 0;
                rep(k, p.first) {
                    cnt += (nxt >> k) & 1;
                }
                if (cnt > p.second) {
                    ng = true;
                    break;
                }
            }
            if (ng) continue;
            dp[nxt] += dp[bit];
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=2e9;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

int dp[maxn][8];

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	string s,t; cin>>s>>t;

	dp[n][0]=1;
	int base=1;
	for (int i=n-1;i>=0;i--) {
		for (int j=0;j<7;j++) {
			int val=(t[i]=='T' ? 1 : 0);
			if (dp[i+1][j]==val||dp[i+1][(j+(s[i]-'0')*base)%7]==val) dp[i][j]=val;
			else dp[i][j]=(val^1);
		}
		base=base*10%7;
	}
	cout<<(dp[0][0] ? "Takahashi\n" : "Aoki\n");
}

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

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

TP void cmax(o& x, o y) {
    if (x < y)
        x = y;
}
TP void cmin(o& x, o y) {
    if (x > y)
        x = y;
}

const int mod = 998244353;
TPP void ad(t1& x, t2 y) {
    x += y;
    if (x >= mod)
        x -= mod;
}
TPP void dl(t1& x, t2 y) {
    x -= y;
    if (x < 0)
        x += mod;
}

const int N = 2e5 + 10, inf = 2e9;
const ll INF = 1e15;
int n, k, d[N], now, ans;
V<int> e[N];
void ins(int x, int y) { e[x].pb(y); }

void dfs(int x, int fa) {
    int mn = N, mx = 0; //* d[x] >= 0 表示子树内有一个距离x d[x]的点. d[x] < 0 表示子树外有一个距离x -d[x]的点.
    for (int y : e[x])
        if (y ^ fa)
            dfs(y, x), cmin(mn, d[y] + 1), cmax(mx, d[y] + 1);
    d[x] = mn + mx < 0 ? mn : mx; //能覆盖就忽略mx. 否则保留mx.
    if (d[x] >= now)
        d[x] = -now - 1, ans++;
}

bool check() {
    dfs(1, 0);
    ans += (d[1] >= 0);
    return ans <= k;
}

void solve() {
    qr(n, k);
    FOR(i, n - 1) {
        int x, y;
        qr(x, y);
        ins(x, y);
        ins(y, x);
    }
    int l = 1, r = n, mid;
    while (l < r) {
        mid = (l + r) / 2;
        ans = 0;
        now = mid;
        if (check())
            r = mid;
        else
            l = mid + 1;
        debug(mid);
        debug(ans);
    }
    pr2(l);
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int T = 1;
    // qr(T);
    while (T--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << ' ' << 's' << endl;
#endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,n)    for(ll i=a;i<n;i++)
#define ll long long
#define PB push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define vp vector<pi>
#define modulo (1e9+7)
int power(long long x, ll y, ll p)		// modular exponentiation
{
    ll res = 1;     // Initialize result
	x = x % p; // Update x if it is more than or
                // equal to p
    if (x == 0) return 0; // In case x is divisible by p;
	while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int search1(vi arr, int n, int x)			// linear search
{
    int i;
    for (i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}

int main()
{
	int a,b;
    cin>>a>>b;
    int c=a*b;
    cout<<c/100;
    if(c%100!=0)
    {
        cout<<"."<<(c%100)/10;
        if(c%10!=0)
        cout<<(c%10);
    }
	return 0;
}

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  // std::fixed -> 固定小数点で出力することを指定
  // std::setprecision(int n) -> 小数点以下 n 桁で出力することを指定
  cout << scientific << setprecision(7);
  cout << A * B / 100.0 << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define ZERO(c) memset(c, 0, sizeof(c))
using ll = long long;
// using P = pair<int,int>;

const int INF = 1e9 + 5;
const ll INFL = 1e18 + 5;

int A[1005], B[1005], N, upper = 1000, lower = 0, a, b;

int main() {
    cin >> N;
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) {
        upper = min(upper, B[i]);
        lower = max(lower, A[i]);
    }
    cout << max(0, upper - lower + 1) << endl;
}

// #include <bits/stdc++.h>
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
#include <stdio.h>
#include <string.h>
#include <numeric>
// #define P pair<int, int>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, a, b) for (int i = a; i < b; i++)
const long long INF = 1LL << 60;
typedef long long ll;
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
#define all(x) (x).begin(), (x).end()

using namespace std;

// 上下左右の移動用配列
// セットで上、右、下、左の順番
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
// B
int main(int, char **)
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++)
  {
    cin >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  int ans = 0;
  for (int i = A[N - 1]; i <= B[0]; i++)
  {

    ans++;
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   ll n;
   cin>>n;
   ll sum=0;
   while(n--)
   {
       ll x,y;
       cin>>x>>y;
       sum+=(y*(y+1)/2)-(x*(x-1)/2);
   }
   cout<<sum;
}

#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  ll C;
  cin >> N >> C;
  vector<int> a(N), b(N), c(N);
  set<int> s;
  map<int, vector<int>> starts, ends;
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i] >> c[i];

    // We only need a[i] and b[i]+1 to represent the final segments.
    // For example, [1, 4] and [3, 8] will make
    // [1, 2], [3, 4], [5, 8] and [9, +inf].
    // We need 1, 3, 5, and 9 to represent these segments.
    s.insert(a[i]), s.insert(b[i] + 1);
    starts[a[i]].emplace_back(i);
    ends[b[i] + 1].emplace_back(i);
  }

  vector<int> v(s.begin(), s.end());
  int M = v.size();

  ll ans = 0, acc = 0;
  for (int i = 0; i < M - 1; ++i) {
    if (ends.count(v[i])) {
      for (int j : ends[v[i]])
        acc -= c[j];
    }
    if (starts.count(v[i])) {
      for (int j : starts[v[i]])
        acc += c[j];
    }
    ans += min(C, acc) * (v[i + 1] - v[i]);
  }
  cout << ans;
}


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

int main()
{
#ifndef ONLINE_JUDGE
     // for getting input from input.txt
     freopen("input.txt", "r", stdin);
     // for writing output to output.txt
     freopen("output.txt", "w", stdout);
#endif

 int n;
 cin>>n;
 string s;
 cin>>s;
 ll sum = 0;
 map<ll, ll> m;
 m[0] = 1;
 ll ans = 0;
 for(int i=0; i<n; i++){
 	if(s[i] == 'A')
 		sum++;
 	else if(s[i] == 'T')
 		sum--;
 	else if(s[i] == 'G')
 		sum += 100000;
 	else
 		sum -= 100000;
 	ans += m[sum];
 	m[sum]++;
 }
 cout<<ans;
 return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >>s ;
    int ans=0;
    for (int i=0;i<n;i++){
        int f=0,se=0;
        for (int j=i;j<n;j++){
            if (s[j]=='A')
                f++;
            else if (s[j]=='T')
                f--;
            else if (s[j]=='C')
                se++;
            else
                se--;
            if ((j-i)%2==1 && f==0 && se==0)
                ans++;
        }
    }
    cout << ans ;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=105;
bool vis[N][N][N];
long double dp[N][N][N];
long double func(ll a,ll b,ll c){
    if(a==100 || b==100 || c==100)return 0;
    if(vis[a][b][c])return dp[a][b][c];
    vis[a][b][c]=1;
    dp[a][b][c]+=((func(a+1,b,c)+1)*a*1.0)/(a+b+c+0.0);
    dp[a][b][c]+=((func(a,b+1,c)+1)*b*1.0)/(a+b+c+0.0);
    dp[a][b][c]+=((func(a,b,c+1)+1)*c*1.0)/(a+b+c+0.0);
    return dp[a][b][c];
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a,b,c;cin>>a>>b>>c;
    cout<<fixed<<setprecision(18)<<func(a,b,c);
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=99824453;
vin dx={-1,0,1,0};
vin dy={0,1,0,-1};

int main(){
    int n;ll k,m;cin>>n>>k>>m;
    vvll dp(n+1,vll(510000));//dp[i][j]:1~iの中から各々k個まで使って総和をjにする通り数
    vvll res(n+1,vll(510000));//res[i][j]=dp[i][j]+dp[i][j-(i+1)]+dp[i][j-2(i+1)]+...+dp[i][j-k(i+1)]
    dp[0][0]=(ll)1;
    //rep(i,k+1)res[0][i]=(ll)1;
    rep2(i,1,n+1)rep(j,(i*(i+1)*k)/2+1){
        res[i][j%i]+=dp[i-1][j];
        res[i][j%i]%=m;
        if(j-(k+1)*i>=0){
            res[i][j%i]-=dp[i-1][j-(k+1)*i];
            if(res[i][j%i]<0)res[i][j%i]+=m;
        }
        dp[i][j]=res[i][j%i];
        /*dp[i][j]=res[i-1][j];//dp[i][j]=dp[i-1][j]+dp[i-1][j-i]+...+dp[i-1][j-ki]
        res[i][j]=dp[i][j];
        if(j-(i+1)>=0){
            res[i][j]+=res[i][j-(i+1)];
            res[i][j]%=m;
        }
        if(j-(k+1)*(i+1)>=0){
            res[i][j]-=dp[i][j-(k+1)*(i+1)];
            if(res[i][j]<0)res[i][j]+=m;
        }*/
    }
    ll ans;
    rep2(x,1,n+1){
        ans=(ll)0;
        rep2(i,1,(x*(x+1)*k)/2+1){
            ans+=(dp[x-1][i]*dp[n-x][i])%m;
            ans%=m;
        }
        ans*=k+(ll)1;ans%=m;
        ans+=k;ans%=m;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
#define vvpll vector<vpll>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

ll inf = 1e18;
ll p = 1e9 + 7;
ld eps = 1e-9;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, y, x, z, g, key,   h, n, m, a, b, c, j, k, d;
    ll t2, t3, t4, t1, t5, t6;
    string s, s2, s1;
    ll l, r;
    ll tc;
    //cin >> tc;
    tc = 1;
    ll x1, y1, x2, y2;
    while (tc--)
    {
        cin >> n;
        ll arr[n], b[n];
        for (i = 0; i < n; i++)
            cin >> arr[i];
        for (i = 0; i < n; i++)
            cin >> b[i];
        ll val = 0;
        for (i = 0; i < n; i++)
        {
            val += (arr[i] * b[i]);
        }
        if (val == 0)
            cout << "Yes";
        else
            cout << "No";

    }

    return 0;
}

#include <bits/stdc++.h>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF=2147483647;
// 9,223,372,036,854,775,807
const ll INFL = 9223372036854775807;

int main(){
    // 入力ファイル使うとき
    ll ans;

    ll n,m,t;
    cin >> n >>m >>t;
    vector<vector<ll>> ab(m,vector<ll>(2));
    for(int i=0;i<m;i++){
        cin >> ab[i][0] >> ab[i][1];
    }
    // m回のカフェの訪問
    ll absta = 0;
    ll chvtmp = n;
    for(int i=0;i<m;i++){
        chvtmp -= (ab[i][0] - absta);
        if(chvtmp<=0){
            cout << "No"<<endl;
            return 0;
        }
        chvtmp += (ab[i][1]-ab[i][0]);
        if(chvtmp>=n){
            chvtmp = n;
        }
        absta = ab[i][1];
    }
    if(t-ab[m-1][1] >= chvtmp){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;

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

    int count=0;
    for(int i=0 ; i<n-1 ; i++)
    {
        int x=arr[i] , y=brr[i];
        for(int j=i+1 ; j<n ; j++)
        {
            if(arr[j]-x != 0)
            {
                int a = arr[j]-x;
                int b = brr[j]-y;

                if(abs(a) >= abs(b))
                count++;
            }
        }
    }

    cout << count << "\n";
    return 0;
}

#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const int inf=(int)1e9+2;
#define filename ""
    vector<int> v[N];
    int h[N];
    pair<int,int> o[N];
bool sss(pair<int,int> &x,pair<int,int> &y)
{
    if (x.fi-x.se==y.fi-y.se) re x<y;
    re x.fi-x.se>y.fi-y.se;
}
void dfs(int x)
{
    h[x]=1;
    vector<pair<int,int> > vv[2];
    for(auto y:v[x])
    {
        dfs(y);
        h[x]+=h[y];
        vv[h[y]%2].pb(o[y]);
    }
    o[x]={0,0};
    if (vv[1].size()%2)
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=max(j.fi,j.se);
            o[x].se+=min(j.fi,j.se);
        }
    }
    else
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=j.fi;
            o[x].se+=j.se;
        }
    }
    sort(all(vv[1]),sss);
    int i;
    fo(i,vv[1].size())
    {
        if (i%2)
        {
            o[x].fi+=vv[1][i].se;
            o[x].se+=vv[1][i].fi;
        }
        else
        {
            o[x].fi+=vv[1][i].fi;
            o[x].se+=vv[1][i].se;
        }
    }
    o[x].se++;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,i;
    cin>>n;
    fo(i,n-1)
    {
        int a;
        cin>>a;
        a--;
        v[a].pb(i+1);
    }
    dfs(0);
    cout<<o[0].se;
}