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

// #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>

#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
typedef vector<vi> vvi;

const int M = 1e9+7;
const int N = 2e5;
int po(int,int);
int n,m;
int k;
int a[105],b[105],c[20],d[20];
map<int,int> mp;
int ans = 0;
void f(int id){
    if(id == k+1){
        int s = 0;
        FOR(i,1,m+1){
            if(mp[a[i]] > 0 && mp[b[i]] > 0){
                s++;
            }
        }
        ans = max(ans,s);
        return;
    }
    else{
        mp[c[id]]++;
        f(id+1);
        mp[c[id]]--;
        mp[d[id]]++;
        f(id+1);
        mp[d[id]]--;
    }
}

void solve(){
    cin>>n>>m;
    FOR(i,1,m+1){
        cin>>a[i]>>b[i];
    }

    cin>>k;
    FOR(i,1,k+1){
        cin>>c[i]>>d[i];
    }
    f(1);

    cout<<ans<<"\n";

}

int32_t main() {

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

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

    int t=1;
    // cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": ";
        solve();

    }

    return 0;

}

int po(int a,int b){
    if(b==0) return 1;
    int ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}

#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  int k;
  cin >> k;
  vector<int> c(k), d(k);
  rep(i, k) {
    cin >> c[i] >> d[i];
    c[i]--; d[i]--;
  }

  int ans = 0;
  rep(t, 1<<k) {
    vector<int> v(n, 0);
    rep(i, k) {
      if (t>>i&1) v[c[i]]++;
      else v[d[i]]++;
    }

    int cnt = 0;
    rep(i, m) {
      if (v[a[i]] && v[b[i]]) cnt++;
    }
    // rep(i, n) cout << v[i] << endl;
    chmax(ans, cnt);
  }

  cout << ans << endl;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ull> ull1d;
typedef vector<ull1d> ull2d;
typedef vector<ull2d> ull3d;
#define loop(i,n) for(ull i=0;i<n;i++)
#define rloop(i,n) for(ll i=n-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
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; }

int main(){ cout << fixed << setprecision(15);
  int n,m;
  cin >> n >> m;
  vector<string> a,b(m);
  loop(i,m){ cin >> b[i]; }
  sort(all(b),[](string &x, string &y){ return x.size() > y.size(); });
  loop(i,b.size()) for(int j=i+1;j<b.size();j++){
    if(b[i].find(b[j]) != string::npos){
      b.erase(b.begin()+j);
    }
  }
  string prev = "";
  loop(i,b.size()){
    if(prev.size() + b[i].size() > n){
      int l = n-prev.size();
      auto itr = find_if(all(b),[l](string x){ return x.size() == l; });
      if(itr == b.end()){
        loop(j,l){ prev += "."; }
      }
      else{
        prev += *itr;
        b.erase(itr);
      }
      a.push_back(prev);
      prev = "";
    }
    prev += b[i];
  }
  loop(i,n){
    cout << a[i] << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int edge[10][10], mark[10];
int n, k, v = 1, ans = 0;

void dfs(int cur, int dst) {
    if(dst > k) return;
    if(v == n) {
        if(dst + edge[0][cur] == k) ans ++;
        return;
    }
    else {
        for(int i = 0; i <= n; i++) {
            if(mark[i] == 0) {
                mark[i] = 1;
				v ++;
				//cout<<cur<<' '<<i<<' '<<dst<<endl;
                dfs(i, dst + edge[cur][i]);
                mark[i] = 0;
				v --;
            }
        }
        return;
    }
}

int main() {
	cin>>n>>k;
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			cin>>edge[i][j];
		}
	}
	memset(mark, 0, sizeof(mark));
	mark[0] = 1;
	dfs(0, 0);
	cout<<ans;

	return 0;
}


#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

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

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

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  llvec v(4);
  ll ans = 1e18;
  rep(i, 4)cin >> v[i];
  rep(i, 4)ans = min(ans,v[i]);
  cout<< ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
  string s;
  cin>>s;
  map<int,int> mp;
  rep(i,s.size()){
    int num=(int)(s[i]-'0');
    mp[num]++;
  }
  if(s.size()==1){
    if(mp[8]==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  if(s.size()==2){
    for(int i=10; i<100; i++){
      if(i%8!=0) continue;
      bool ok=1;
      map<int,int> cnt;
      int tmp=i;
      rep(j,2){
        int d=tmp%10;
        cnt[d]++;
        tmp/=10;
      }
      for(auto x : cnt){
        if(x.second>mp[x.first]) ok=0;
      }
      if(ok){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=100; i<1000; i++){
    if(i%8!=0) continue;
    bool ok=1;
    map<int,int> cnt;
    int tmp=i;
    rep(j,3){
      int d=tmp%10;
      cnt[d]++;
      tmp/=10;
    }
    for(auto x : cnt){
      if(x.second>mp[x.first]) ok=0;
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n,sum=0,res=0;
    cin>>n;
    long long a[n];
    long long  mod= 998244353;
    for(long long i=0;i<n;i++){
    cin>>a[i];
    }
    sort(a,a+n,greater<long long>());
    for(long long i=0;i<n;i++)
    {
        res+=(a[i]*a[i]);
        res+=(a[i]*sum);
        res=res%mod;
        sum=sum*2;
        sum+=a[i];
        sum=sum%mod;
    }
    cout<<res;

}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = INT_MAX;
    for (int i = 0; i < (1<<(n-1)); i++)
    {
        int in, out;
        in = out = 0;
        for (int j = 0; j < n; j++)
        {
            in |= a[j];
            if (i&1<<j)
            {
                out ^= in;
                in = 0;
            }
        }
        out ^= in;
        ans = min(ans, out);
    }
    cout << ans << endl;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;

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

const ll mod = 1000000007;

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

  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (auto &x: a) cin >> x;

  unordered_map<char, vector<Pii> > teleporterLocation;
  Pii start;
  Pii goal;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if ('a' <= a[i][j] && a[i][j] <= 'z') teleporterLocation[a[i][j]].emplace_back(i, j);
      else if (a[i][j] == 'S') start = Pii(i, j);
      else if (a[i][j] == 'G') goal = Pii(i, j);
    }
  }

  vector<vector<bool> > visited(h, vector<bool>(w));
  unordered_map<char, bool> teleporterVisited;
  queue<vector<int> > que;
  que.push(vector<int>({start.first, start.second, 0}));
  int ans = -1;
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (visited[now[0]][now[1]]) continue;
    visited[now[0]][now[1]] = true;
    if (now[0] == goal.first && now[1] == goal.second) {
      ans = now[2];
      break;
    }
    if ('a' <= a[now[0]][now[1]] && a[now[0]][now[1]] <= 'z') {
      if (!teleporterVisited[a[now[0]][now[1]]]) {
        teleporterVisited[a[now[0]][now[1]]] = true;
        for (auto &x: teleporterLocation[a[now[0]][now[1]]]) {
          if (!visited[x.first][x.second]) que.push(vector<int>({x.first, x.second, now[2]+1}));
        }
      }
    }
    if (now[0] > 0) {
      if (a[now[0]-1][now[1]] != '#' && !visited[now[0]-1][now[1]]) que.push(vector<int>({now[0]-1, now[1], now[2]+1}));
    }
    if (now[0] < h-1) {
      if (a[now[0]+1][now[1]] != '#' && !visited[now[0]+1][now[1]]) que.push(vector<int>({now[0]+1, now[1], now[2]+1}));
    }
    if (now[1] > 0) {
      if (a[now[0]][now[1]-1] != '#' && !visited[now[0]][now[1]-1]) que.push(vector<int>({now[0], now[1]-1, now[2]+1}));
    }
    if (now[1] < w-1) {
      if (a[now[0]][now[1]+1] != '#' && !visited[now[0]][now[1]+1]) que.push(vector<int>({now[0], now[1]+1, now[2]+1}));
    }
  }

  cout << ans << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define en '\n'
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 2e3 + 9;
int dx[4] = { -1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

char s[gf][gf];
vii v[26];
bool vis[gf][gf];
int dis[gf][gf];
bool vis2[gf];
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int h, w;
	cin >> h >> w;
	pii source;
	pii dest;
	rep(i, 0, gf - 1)rep(j, 0, gf - 1)s[i][j] = '#';
	rep(i, 1, h)
	{
		rep(j, 1, w)
		{
			cin >> s[i][j];
			if (s[i][j] >= 'a' && s[i][j] <= 'z')
				v[s[i][j] - 'a'].pb({i, j});
			if (s[i][j] == 'S')
			{
				source = {i, j};
			}
			else if (s[i][j] == 'G')
			{
				dest = {i, j};
			}
		}
	}
	queue<pii>q;
	q.push(source);
	vis[source.ff][source.ss] = 1;
	while (sz(q))
	{
		pii node = q.front();
		q.pop();
		int x = node.ff;
		int y = node.ss;
		zip(i, 0, 4)
		{
			int x1 = x + dx[i];
			int y1 = y + dy[i];
			if (s[x1][y1] == '#')
				continue;
			if (vis[x1][y1])
				continue;
			vis[x1][y1] = 1;
			q.push({x1, y1});
			dis[x1][y1] = dis[x][y] + 1;
		}
		if (s[x][y] >= 'a' && s[x][y] <= 'z')
		{
			if (vis2[s[x][y] - 'a'])
				continue;
			for (pii p : v[s[x][y] - 'a'])
			{
				int x1 = p.ff;
				int y1 = p.ss;
				if (vis[x1][y1])
					continue;
				vis[x1][y1] = 1;
				q.push({x1, y1});
				dis[x1][y1] = dis[x][y] + 1;
				vis2[s[x][y] - 'a'] = 1;
			}
		}
	}
	if (!vis[dest.ff][dest.ss])
		cout << -1 << en;
	else
		cout << dis[dest.ff][dest.ss] << en;

	return 0;
}


#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int a[100001],b[100001],n,i,j,k,l;
ll ans;

int main()
{
	#ifdef file
	freopen("b.in","r",stdin);
	#endif

	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) scanf("%d",&j),ans+=(i&1)?j:a[i],a[i]-=j;
	for (i=2; i<=n; i+=2) a[i]=-a[i];

	sort(a+1,a+n+1);
	fd(i,n,n/2+1) ans+=a[i];
	printf("%lld\n",ans);

	fclose(stdin);
	fclose(stdout);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

int main(){
  int N;
  cin >> N;
  int a[N+10],b[N+10];
  rep(i,N) cin >> a[i] >> b[i];

  vector<int> tp(2*N),com(2*N, -1);
  bool ng = false;
  rep(i,N){
    if(a[i] != -1){
      --a[i];
      if(tp[a[i]]) ng = true;
      tp[a[i]] = i+1;
    }
    if(b[i] != -1){
      --b[i];
      if(tp[b[i]]) ng=true;
      tp[b[i]] = -(i+1);
    }

    if(a[i]!= -1 && b[i] != -1){
      com[a[i]] = b[i];
      com[b[i]] = a[i];
    }
  }
  if(ng){
    cout << "No" << endl;
    return 0;
  }

  vector<bool> dp(2*N+1);
  dp[0] = true;
  rep(i,2*N){
    if(!dp[i]) continue;
    for(int j=i+1; j<2*N; j++){
      int w = j - i + 1;
      if(w%2 == 1) continue;
      w /= 2;
      bool ok = true;
      vector<bool> exist(N+10);
      rep(k,w){
        int p = i + k;
        int q = i + k + w;
        if(com[p] != -1 && !(i <= com[p] && com[p] <= j)){
          ok = false; //共に-1ではない人が、片方が区間内なのにもう片方がはみ出している
        }
        if(com[q] != -1 && !(i <= com[q] && com[q] <= j)){
          ok = false;
        }

        bool same = true;
        if(tp[p] != 0 && tp[q] != 0){
          //p,qが共に-1でない
          if(tp[p] <= 0 || tp[p] + tp[q] != 0){
            //pは左向きか、pとqが別の人、(qが右向き)
            ok = false;
          }
        }
        if(tp[p] < 0 || tp[q] > 0){ //pが左向き、または、qが右向き
          ok = false;
        }
      }
      if(ok){
        dp[j+1] = true;
      }
    }
  }
  if(dp[2*N]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

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

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    cin >> N;
    V<ll> A(2*N);
    REP(i, 2*N) cin >> A[i];

    V<ll> B(2*N), ids(2*N);
    iota(ALL(ids), 0);
    sort(ALL(ids), [&](ll x, ll y){
        return A[x] < A[y];
    });

    REP(i, 2*N){
        if(i < N) B[ids[i]] = 0;
        else B[ids[i]] = 1;
    }

    stack<pll> st;
    V<char> res(2*N);
    REP(i, 2*N){
        if(st.empty()){
            st.push(pll{B[i], i});
        }else{
            auto q = st.top();
            if(q.first != B[i]){
                res[q.second] = '(';
                res[i] = ')';
                st.pop();
            }else{
                st.push(pll{B[i], i});
            }
        }
    }

    REP(i, 2*N) cout << res[i];
    cout << endl;

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)

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

    ull n;
    string s,x;
    cin >> n>>s>>x;
    vector<vector<ll>> dp( n+1, vector<ll>( 0, 0 ) );

    dp[n].push_back(0);
    vector<ll> a( 0, 0 );
    vector<ll> b( 0, 0 );
    set<ll> se;
    BREP(i,n)
    {
        ll m = s[i] - '0';
        if(x[i] == 'A')
        {
            a.clear();
            b.clear();
            for(auto j: dp[i+1])REP(k,7)
            {
                if((k*10+0)%7==j) a.push_back(k);
                if((k*10+m)%7==j) b.push_back(k);
            }
            sort(ALL(a));
            sort(ALL(b));
            //REP( j, a.size() ) cout << a[j] << " "; cout << endl;
            //REP( j, b.size() ) cout << b[j] << " "; cout << endl;

            set_intersection( ALL( a ), ALL( b ), back_inserter( dp[i] ) );
        }
        else
        {
            se.clear();
            for(auto j: dp[i+1])REP(k,7)
            {
                if((k*10+0)%7==j) se.emplace(k);
                if((k*10+m)%7==j) se.emplace(k);
            }
            for(auto j: se) dp[i].push_back(j);
        }

        //REP( j, dp[i].size() ) cout << dp[i][j] << " "; cout << endl;
    }

    cout <<
    (find(ALL(dp[0]), 0)==dp[0].end()
    ? "Aoki" : "Takahashi") << endl;

    //----------------
    return 0;
}

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

typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef array<int,2> aii;
typedef array<int,3> aiii;
typedef array<int,4> aiiii;
typedef unsigned long long ull;
typedef long long int ll;
typedef array<ll,2> all;
typedef array<ll,3> alll;
typedef array<ll,4> allll;

#define pb push_back
#define ff first
#define ss second
#define MAX 200005
#define MOD 1000000007
#define INF 1e9+100
vector<aii>adj[MAX];
vector<int> dijkstra_dag_adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };
int n;
string s,x;
int dp[MAX][8];
int solve(int i, int r)
{
    if(i==n)
        return r==0?2:1;
    if(dp[i][r]!=-1)
        return dp[i][r];

    int ans=0;
    if(x[i]=='A')
    {
        int cur=solve(i+1,(r*10+s[i]-48)%7);
        if(cur!=1)
            cur=solve(i+1,(r*10+0)%7);
        ans=cur;
    }
    else
    {
        int cur=solve(i+1,(r*10+s[i]-48)%7);
        if(cur!=2)
            cur=solve(i+1,(r*10+0)%7);
        ans=cur;
    }

    return dp[i][r]=ans;
}
int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0),cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    int TC=1;
    int m,k,q;
    //cin>>TC;
    for(int t1=1; t1<=TC; t1++)
    {
        cin>>n>>s>>x;

        memset(dp,-1,sizeof dp);

        int ans=solve(0,0);
        if(ans==1)
            cout<<"Aoki\n";
        else cout<<"Takahashi\n";

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

ll a[210000];

int main(){
  int n;
  cin>>n;
  rep(i,n) cin>>a[i];
  ll base=0;
  ll befo=0;
  ll MAX=0;
  rep(i,n){
    base+=befo+a[i];
    befo+=a[i];
    chmax(MAX,a[i]);
    cout<<base+MAX*(i+1)<<endl;
  }
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int N;
    std::cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        std::cin >> A[i];
    }

    int ans = 0, ans_temp = 0;
    int min_a = 0;
    for(int i = 0; i < N; i++){
        min_a = A[i];
        for(int j = i; j < N; j++){
            //l = i, r = jとして
            if(A[j] < min_a){
                //伸ばした先で小さいのがあれば更新
                min_a = A[j];
            }
            ans_temp = min_a * (j - i + 1);
            if(ans_temp > ans){
                ans = ans_temp;
                //std::cout << i << " " << j << " " << ans_temp << "\n";
            }
        }
    }
    std::cout << ans;
}


#include <bits/stdc++.h>
#define REP(i, n) for (int64_t i = 0; (i) < (int64_t)(n); ++(i))
#define REP3(i, m, n) for (int64_t i = (m); (i) < (int64_t)(n); ++(i))
#define REP_R(i, n) for (int64_t i = (int64_t)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int64_t i = (int64_t)(n)-1; (i) >= (int64_t)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

int64_t solve(int64_t N, int64_t M, const vector<int64_t>& X, const vector<int64_t>& Y, const vector<int64_t>& Z) {
    vector<int64_t> dp(1<<N, 0);
    dp[0] = 1;
    REP(bit, 1<<N){
        int64_t m = __builtin_popcountll(bit);
        REP(dst, N){
            if((bit>>dst)&1) continue;
            vector<int64_t> cnt(N, 0);
            REP(i, N){
                if((bit>>i)&1) cnt[i] += 1;
            }
            cnt[dst] += 1;
            REP(i, N-1){
                cnt[i+1] += cnt[i];
            }
            bool flag = true;
            REP(i, M){
                if(X[i] < m) continue;
                if(cnt[Y[i]] > Z[i]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                dp[bit|1<<dst] += dp[bit];
            }
        }
    }
    return dp[(1<<N)-1];
    // TODO: edit here
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t N, M;
    cin >> N >> M;
    vector<int64_t> X(M), Y(M), Z(M);
    REP (i, M) { cin >> X[i] >> Y[i] >> Z[i]; X[i]--; Y[i]--; }
    int64_t ans = solve(N, M, X, Y, Z);
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<array<int, 2>>> A(N + 1);
    for (int i = 0; i < M; i++) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        A[X].push_back({Y, Z});
    }
    vector<int64_t> dp(1<<N);
    dp[0] = 1;
    for (int i = 0; i < (1 << N); i++) {
        int n = __builtin_popcount(i);
        int valid = 1;
        for (auto u : A[n]) {
            int m = __builtin_popcount(i & ((1 << u[0]) - 1));
            if (m > u[1]) {
                valid = 0;
                break;
            }
        }
        if (valid) {
            for (int j = 0; j < N; j++) {
                if ((i & (1 << j)) == 0) continue;
                dp[i] += dp[i^(1<<j)];
            }
        }
    }
    cout << dp[(1<<N) - 1];
}


/*if ((double) ((double)(clock() - cl)/(double)CLOCKS_PER_SEC)>1.85) {break;}*/
//#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define double long double
#define ft first
#define sc second
#define pb push_back
#define booost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
#define all(x) (x).begin(),(x).end()
#define file(x) freopen(string(string((x)) + ".in").c_str(), "r", stdin); freopen(string(string((x)) + ".out").c_str(), "w", stdout);
#define GG cout << " OPA " << '\n';

using namespace std;
using namespace __gnu_pbds;
typedef pair <int, int> pi;
typedef tree <pair <int, pair <int, int> >, null_type, less<pair <int, pair <int, int> > >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 20 + 5;
const int K = 100;
const int P = 37;
const int INF = 1e12;
const double d_INF = 2000000000.0;
const double EPS = 1e-10;
const int MOD = 1e9 + 7;
const int LOG = 20;

int a[N];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    int ans = INF;
    for (int mask = 0; mask < (1 << n); mask ++) {
        int cur = 0;
        int res = 0;
        for (int i = 0; i < n; i ++) {
            cur |= a[i + 1];
            if (((mask >> i) & 1) == 1) res ^= cur, cur = 0;
        }
        res ^= cur;
        cur = 0;
        ans = min(ans, res);
    }
    cout << ans;
}

main () {
    int test = 1;
    booost;
//    cin >> test;
    while (test --) {
        solve();
    }
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll solve(ll n, ll a, ll b)
{
    // for 1d
    ll nooverlap;
    if (n - a - b < 0)
        nooverlap = 0;
    else
        nooverlap = ((n - a - b + 2) * (n - a - b + 1)) % MOD;
    ll overlap = ((n - a + 1) * (n - b + 1) - nooverlap) % MOD;
    // for 2d
    ll overlap2d = (overlap * overlap) % MOD;
    ll all = (((n - a + 1) * (n - a + 1) % MOD) * ((n - b + 1) * (n - b + 1) % MOD)) % MOD;
    ll ans = ((all - overlap2d) % MOD + MOD) % MOD; // be careful of negative mod
    return ans;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        ll n, a, b;
        cin >> n >> a >> b;
        ll ans = solve(n, a, b);
        cout << ans << endl;
    }
}


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

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

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define precise(x) fixed << setprecision(x)

const int MOD = 998244353;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;

    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }

    return res;
}

const int N = 310;
int ncr[N][N];
int table[N][N];
int psum[N];

const int M = 2e5 + 10;
int b[M];

void solve()
{
   for(int i=0;i<N;i++)
   {
       ncr[i][0] = 1;

       for(int j=1;j<=i;j++)
       {
           ncr[i][j] = (ncr[i-1][j] + ncr[i-1][j-1])%MOD;
       }
   }

   int n,k;
   cin >> n >> k;

   int a[n];
    f(i,n) cin >> a[i];

   f(i,n) b[i] = a[i];

   for(int i=1;i<=k;i++)
   {
       f(j,n) psum[i] = (psum[i] + b[j])%MOD;
       f(j,n) b[j] = (b[j]*a[j])%MOD;
   }

   f(i,n) b[i] = a[i];

   for(int i=1;i<=k;i++)
   {
       for(int j=1;j<=k;j++)
       {
           if(i + j <= k)
           {
           table[i][j] = (psum[i]*psum[j])%MOD;
           table[i][j] -= psum[i+j];
           table[i][j]%=MOD;

           if(i == j) table[i][j] = (table[i][j]*mod_pow(2,MOD-2))%MOD;

           if(table[i][j] < 0) table[i][j]+=MOD;
           }
       }
   }

   for(int i=1;i<=k;i++)
   {
       int res = 0;

       res+=(n-1)*psum[i];
       res%=MOD;

       for(int j=1;j<=i/2;j++)
       {
           int temp = ncr[i][j];
           temp = (temp*table[j][i-j])%MOD;

           res+=temp;
           res%=MOD;
       }

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

}

signed main()
{
    fast;

    int t = 1;

//    cin >> t;

    while(t--)

    solve();
}

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

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}

int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}

int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

signed main(){
	int N, K, i, j;
	scanf("%lld%lld", &N, &K);
	vector<int> A(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	vector<int> S(K + 1, 0);
	for(i = 0; i < N; i++){
		int a = 1;
		for(j = 0; j <= K; j++){
			S[j] = MOD(S[j] + a);
			a = MOD(a * A[i]);
		}
	}
	for(i = 1; i <= K; i++){
		int sub = 0;
		for(j = 0; j <= i; j++){
			sub = MOD(sub + combination(i, j) * MOD(S[i - j] * S[j]));
		}
		int ans = MOD(MOD(sub - power(2, i) * S[i]) * inverse(2));
		printf("%lld\n", ans);
	}
	return 0;
}


#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
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());

const int mod = 1'000'000'007;
//=======================

void solve() {
  int i, j, n, m;
  cin>>n;
  vi v(n);
  int sum=0;
  fo(i,n)
    cin>>v[i];
   fo(i,n)

   {if(v[i]>10)
    sum+=v[i]-10;
   }
   cout<<sum;

}

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

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

    return 0;
}

#include <bits/stdc++.h>
#define all(V) V.begin(),V.end()
#define pi 3.1415926535897932384626
#define fi fixed<<setprecision(13)
#define MOD 1000000007
#define ll long long
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define Rep(i, n) for (ll i = 1; i <=(ll)(n); i++)
#define reps(i,k,n) for (ll i = (ll)k; i < (ll)(n); i++)
using namespace std;
template<class T> void chmin(T& a,T b){ if(a > b) a=b; }
template<class T> void chmax(T& a,T b){ if(a < b) a=b; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
ll nck(ll a,ll b){
  ll s=1,x=1;
  rep(i,b) s=(s*(a-i))/x,x++;
   return s;
}
const ll infll=1LL<<62;
const ll inf=1<<30;
int main(){
  string s;cin>>s;
  int c=0;
  rep(i,9){
    if(s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e') c++;
  }
  cout<<c;
}
/*制約を確認しろllじゃなくて大丈夫か？*/


#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  std::unordered_map<int, int> mx;
  std::unordered_map<int, int> mn;

  rep(i, N)
  {
    int x, c;
    cin >> x >> c;

    if (mx.find(c) != mx.end())
    {
      mx[c] = std::max(mx[c], x);
      mn[c] = std::min(mn[c], x);
    }
    else
    {
      mx[c] = x;
      mn[c] = x;
    }
  }

  long long time1 = 0;
  long long time2 = 0;
  int pos1 = 0;
  int pos2 = 0;
  for (int i = 1; i <= N; i++)
  {
    if (mx.find(i) != mx.end())
    {
      long long diff = std::abs(mx[i] - mn[i]);
      long long tmp1 = time1;
      long long tmp2 = time2;
      // from pos1, mx -> mn
      tmp1 += std::abs(pos1 - mx[i]) + diff;

      // from pos2, mx -> mn
      tmp2 += std::abs(pos2 - mx[i]) + diff;

      long long tmp3 = time1;
      long long tmp4 = time2;
      // from pos1, mn -> mx
      tmp3 += std::abs(pos1 - mn[i]) + diff;

      // from pos2, mn -> mx
      tmp4 += std::abs(pos2 - mn[i]) + diff;

      time1 = std::min(tmp1, tmp2);
      time2 = std::min(tmp3, tmp4);

      pos1 = mn[i];
      pos2 = mx[i];
    }
  }

  time1 += std::abs(pos1);
  time2 += std::abs(pos2);

  cout << std::min(time1, time2) << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll n; cin >> n;
    ll x[n], c[n]; zep(i, 0, n)cin >> x[i] >> c[i];

    map<ll, P> mp;
    zep(i, 0, n){
        if(mp.find(c[i]) == mp.end()){
            mp[c[i]] = P(x[i], x[i]);
        }
        mp[c[i]] = P(min(mp[c[i]].first, x[i]), max(mp[c[i]].second, x[i]));
    }

    ll m = mp.size();
    ll dp[m + 1][2]; memset(dp, 0, sizeof(dp));
    ll l = 0, r = 0;
    ll at = 0;
    for(auto it = mp.begin(); it != mp.end(); it++){
        ll L = (*it).second.first, R = (*it).second.second;

        dp[at + 1][0] = INF;
        dp[at + 1][1] = INF;

        if(R < l){
            dp[at + 1][0] = min(dp[at + 1][0], l - L + dp[at][0]);
        }else{
            dp[at + 1][0] = min(dp[at + 1][0], 2 * R - l - L + dp[at][0]);
        }

        if(R < r){
            dp[at + 1][0] = min(dp[at + 1][0], r - L + dp[at][1]);
        }else{
            dp[at + 1][0] = min(dp[at + 1][0], 2 * R - r - L + dp[at][1]);
        }

        if(L < l){
            dp[at + 1][1] = min(dp[at + 1][1], R + l - 2 * L + dp[at][0]);
        }else{
            dp[at + 1][1] = min(dp[at + 1][1], R - l + dp[at][0]);
        }

        if(L < r){
            dp[at + 1][1] = min(dp[at + 1][1], R + r - 2 * L + dp[at][1]);
        }else{
            dp[at + 1][1] = min(dp[at + 1][1], R - r + dp[at][1]);
        }

        l = L, r = R;
        at++;
        //cout << dp[at][0] << " " << dp[at][1] << endl;
    }
    print(min(dp[m][0] + abs(l), dp[m][1] + abs(r)))

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define visit asdf
const int N=4e5+5;
const int M=4e5+5;

int n,m,ans;
int a[N],b[N];
int indeg[M];
vector<int> v[M];
bool visit[N];
queue<int> q;

int match(int x)
{
	for(int i=0;i<v[x].size();i++)
		if(!visit[v[x][i]]) return v[x][i];
	return 4e5+1;
}

int main()
{
	cin>>n; m=4e5;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		indeg[a[i]]++; v[a[i]].pb(i);
		indeg[b[i]]++; v[b[i]].pb(i);
	}
	for(int i=1;i<=n;i++)
		if(indeg[a[i]]==1 || indeg[b[i]]==1) q.push(i),visit[i]=1;
	for(int i=1;i<=m;i++)
		if(indeg[i]) ans++;

	while(!q.empty())
	{
		int x=q.front(); q.pop();
		if(indeg[a[x]]==1 && indeg[b[x]]==1) ans--;
		if(indeg[a[x]]==1) if(--indeg[b[x]]==1) q.push(match(b[x])),visit[match(b[x])]=1;
		if(indeg[b[x]]==1) if(--indeg[a[x]]==1) q.push(match(a[x])),visit[match(a[x])]=1;
	}
	cout<<ans<<'\n';

	return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#ifndef LOCAL
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

map<ll, vector<pair<ll, ll>>> m;
vector<vector<ll>> graph;
vector<ll> ans;

map<ll, ll> dfs(ll i, ll depth) {
  map<ll, ll> ret;
  for (auto j : graph[i]) {
    auto x = dfs(j, depth + 1);
    if (ret.size() < x.size()) {
      ret.swap(x);
    }
    for (auto [k, v] : x) {
      ret[k] += v;
    }
  }
  ret[depth]++;
  for (auto [num, d] : m[i]) {
    ans[num] = ret[d];
  }
  return (ret);
}

void solve(long long N, std::vector<long long> P, long long Q, std::vector<long long> U, std::vector<long long> D) {
  ans.resize(Q);
  REP(i, Q) {
    m[U[i]].push_back(make_pair(i, D[i]));
  }
  graph.resize(N);
  FOR(i, 1, N) {
    graph[P[i - 1]].push_back(i);
  }
  dfs(0, 0);
  REP(i, Q) {
    cout << ans[i] << endl;
  }
}

int main() {
  long long N;
  std::scanf("%lld", &N);
  std::vector<long long> P(N - 2 + 1);
  for (int i = 0; i < N - 2 + 1; i++) {
    std::scanf("%lld", &P[i]);
    P[i]--;
  }
  long long Q;
  std::scanf("%lld", &Q);
  std::vector<long long> U(Q);
  std::vector<long long> D(Q);
  for (int i = 0; i < Q; i++) {
    std::scanf("%lld", &U[i]);
    std::scanf("%lld", &D[i]);
    U[i]--;
  }
  solve(N, std::move(P), Q, std::move(U), std::move(D));
  return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb emplace_back
#define mp make_pair
#define sqr(n) ((n)*(n))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define precision(a) setiosflags(ios::fixed) << setprecision(a)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef double db;

template <typename T> inline char read(T &x) {
    x = 0; T fg = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') fg = -1;ch = getchar();}
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar();
    x = fg * x; return ch;
}
template <typename T, typename... Args> inline void read(T &x, Args &... args) { read(x), read(args...); }
template <typename T> inline void write(T x) {
    int len = 0; char c[21]; if (x < 0) putchar('-'), x = -x;
    do{++len; c[len] = x % 10 + '0';} while (x /= 10);
    for (int i = len; i >= 1; i--) putchar(c[i]);
}
template <typename T, typename... Args> inline void write(T& x, Args &... args) { write(x), write(args...); }

template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }

const int N = 1e6 + 5;

int n, m, _, q, cas;
int x[N], y[N];
PII e[N];
bool v[55];

int main() {
	IOS; cin >> n >> m >> q;
	rep (i, 1, n) cin >> e[i].fi >> e[i].se;
	sort(e + 1, e + 1 + n, [](PII& a, PII& b) { return a.se > b.se; });
	rep (i, 1, m) cin >> x[i];
	while (q--) {
		int l, r, cnt = 0, ans = 0; cin >> l >> r;
		rep (i, 1, l - 1) y[++cnt] = x[i];
		rep (i, r + 1, m) y[++cnt] = x[i];
		sort(y + 1, y + 1 + cnt); memset(v, 0, sizeof v);
		rep (i ,1, n) rep (j, 1, cnt) if (y[j] >= e[i].fi && !v[j]) {
			v[j] = 1; ans += e[i].se; break;
		}
		cout << ans << '\n';
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
const ll maxn=5e5+20;

const ll mod=1e9+7;
const ll m2=1e9+7;
const ll INF64 = ll(1e18);
const ll max2=10500000;
int r,c,a,b;
map<vector<int>,int> m1;
int dp[(1<<16)][20][20],dp2[(1<<16)][20][20];
void num(int one,int two,int prev,int mask,int pos)
{	if(pos==r)
	{
		vector<int> v;
		v={one,two,mask};
		m1[v]++;
		//cout<<one<<" "<<two<<" "<<mask<<"\n";
		return;

	}
	int arr[2];
	arr[0]=((prev&(1<<pos))!=0);
	if(pos+1<r)
	{
		arr[1]=((prev&(1<<(pos+1)))!=0);
		if(arr[0]==0 && arr[1]==0)
		{
			num(one+1,two,prev,mask+(1<<pos),pos+1);
			//num(one+2,two,prev,mask+(1<<pos)+(1<<(pos+1)),pos+1);
			num(one,two+1,prev,mask,pos+2);

		}
		else if(arr[0]==1 && arr[1]==1)
		{
			num(one-1,two+1,prev,mask,pos+1);
			//num(one-2,two+2,prev,mask,pos+2);
			num(one,two+1,prev,mask,pos+2);
			num(one+1,two,prev,mask+(1<<pos),pos+1);
			//num(one+2,two,prev,mask+(1<<pos)+(1<<(pos+1)),pos+2);
		}
		else if(arr[0]==1 && arr[1]==0)
		{
			num(one-1,two+1,prev,mask,pos+1);
			num(one,two+1,prev,mask,pos+2);
			num(one+1,two,prev,mask+(1<<pos),pos+1);
		}
		else
		{
			num(one+1,two,prev,mask+(1<<pos),pos+1);
			num(one,two+1,prev,mask,pos+2);
		}

	}
	else
	{
		if(arr[0]==0)
		{
			num(one+1,two,prev,mask+(1<<pos),pos+1);
		}
		else
		{
			num(one+1,two,prev,mask+(1<<pos),pos+1);
			num(one-1,two+1,prev,mask,pos+1);
		}
	}

}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//long long tt = clock();
#endif
ios_base::sync_with_stdio(NULL);  cin.tie(0); cout.tie(0);

int i,j,k,l,l1;
cin>>r>>c>>b>>a;
dp[0][0][0]=1;

for(i=0;i<c;++i)
{for(l1=0;l1<(1<<r);++l1)
	{
		for(j=0;j<=(r*c);++j)
			for(k=0;k<=(r*c);++k)
				dp2[l1][j][k]=0;
	}
	for(j=0;j<(1<<r);++j)
	{	m1.clear();
		if(c==1)
			if(j!=0)
				continue;
		num(0,0,j,0,0);

		for(k=0;k<=(r*c);++k)
		{
			for(l=0;l<=(r*c);++l)
			{
				for(auto x:m1)
				{
					vector<int> v2=x.first;

					if(k+v2[0]>=0 && l+v2[1]>=0)
					{
						dp2[v2[2]][k+v2[0]][l+v2[1]]+=dp[j][k][l]*x.second;
						/*if(i==1 && v2[0]==2 && v2[1]==0 && j==3 && k==2 && l==0)
						cout<<k<<" "<<l<<"\n";*/
					}
				}
			}
		}

	}
	for(j=0;j<(1<<r);++j)
	{
		for(k=0;k<=r*c;++k)
		{
			for(l=0;l<=(r*c);++l)
				{dp[j][k][l]=dp2[j][k][l];

				}
		}
	}
}
int ans=0;

for(j=0;j<(1<<r);++j)
{
	ans+=dp[j][a][b];
}
cout<<ans;

return(0);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll powermd(ll x,  int y,	ll p)
{
    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 must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
void solve(){
	ll n,p;
	cin>>n>>p;
	cout<<(powermd(p-2,n-1,1000000007)*(p-1))%1000000007;
}
int main(){
	int t;
	t=1;
    while(t--) {
    	solve();
	}
}

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int N, K;
int dp[3005][3005];
const int mod = 998244353;

int f(int n, int k) {
	if(n < k) return 0;
	if(k == 0) return (n == 0);
	if(~dp[n][k]) return dp[n][k];

	int ret = 0;
	ret += f(n - 1, k - 1);
	ret %= mod;
	ret += f(n, 2 * k);
	ret %= mod;

	return dp[n][k] = ret;
}

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

	memset(dp, -1, sizeof(dp));
	cin >> N >> K;
	cout << f(N, K) << endl;

	return 0;
}


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

int main() {
  int n,seki,goukei;
  cin >> n;

  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }

  vector<int> B(n);
  for (int i = 0; i < n; i++) {
    cin >> B.at(i);
  }

  goukei = 0;

  for (int i = 0; i < n; i++) {
    seki = A.at(i) * B.at(i);
    goukei = goukei + seki;
  }

  if (goukei == 0) {
    cout << "Yes" << endl;
  }

  else{
    cout << "No" << endl;
  }

}

/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define int      long long
#define double   long double
#define uint     unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
int google_itr = 1;
#define google(x) cout<<"Case #"<<x<<": "
#define pi 3.14159265358979323846264338327950L

vector<string> vec_splitter(string s) {
        s += ',';
        vector<string> res;
        while(!s.empty()) {
                res.push_back(s.substr(0, s.find(',')));
                s = s.substr(s.find(',') + 1);
        }
        return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
        if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, LINE_NUM, T...);
}

#define XOX
#ifdef XOX
    #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
    #define deb(...) 42
#endif

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

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

        vector <int> a(n), b(n);
        for(auto &i:a) cin >> i;
        for(auto &i:b) cin >> i;

        int ans = 0;
        for(auto i=0; i<n; i++) ans += (a[i]*b[i]);

        cout << ((ans == 0)? "Yes" : "No") << endl;
}

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

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    int t = 1;
    //cin >> t;
    while(t--){
           auto start = system_clock::now();
           virus();
           auto stop = system_clock::now();
           duration<double> duration = (stop - start);
           //cerr << "\nTime: "<< fixed << setprecision(10) << (double)duration.count() <<"sec"<< endl;
           //your code goes here
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
#define LOG(...) cerr << "[" << #__VA_ARGS__ << "]: " << repr(__VA_ARGS__) << endl;
#define MSG(args) cerr << args << "\n";
#define debug(x) x
#else
#define LOG(...)
#define MSG(args)
#define debug(x)
#endif

#define mp make_pair
#define pb push_back
#define sz(x) (int)((x).size())
#define ms(x, v) memset((x), v, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vii p(N);
    for(auto &x : p) cin >> x.first >> x.second;
    bool ok = false;
    REP(i, N)
	REPV(j, i + 1, N)
	    REPV(k, j + 1, N)
	    {
		vii tmp({p[i], p[j], p[k]});
		sort(all(tmp));
		ll m1 = (tmp[2].second - tmp[1].second) * 1LL * (tmp[1].first - tmp[0].first);
		ll m2 = (tmp[1].second - tmp[0].second) * 1LL * (tmp[2].first - tmp[1].first);
		if((ok = m1 == m2)) goto en;
	    }
en:;
    if(ok) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }

int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	rep(i, n){
		cin >> x[i] >> y[i];
	}

	for(int i = 0; i < n - 2; i++){
		for(int j = 1; j < n - 1; j++){
			for(int k = 2; k < n; k++){
				if (i == j || j == k || k == i)
					continue;
				if ((y[j] - y[i]) * (x[k] - x[i]) == (y[k] - y[i]) * (x[j] - x[i])){
					cout << "Yes" << endl;
					return (0);
				}
			}
		}
	}
	cout << "No" << endl;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 1000000000
#define N 1010
int n,m=7;
char t[N]="atcoder";
char s[N];
int main(){
//	freopen("in.txt","r",stdin);
	int Q;
	scanf("%d",&Q);
	while (Q--){
		scanf("%s",s);
		n=strlen(s);
		int c=0,ans=INF;
		bool BZ=1;
		for (int i=0;i<m && BZ;++i){
			for (int j=i;j<n;++j)
				if (s[j]>t[i]){
					ans=min(ans,c+j-i);
					break;
				}
			bool bz=0;

			for (int j=i;j<n;++j)
				if (s[j]==t[i]){
					c+=j-i;
					for (;j>i;--j)
						swap(s[j],s[j-1]);
					bz=1;
					break;
				}

//			bz=(s[i]==t[i]);
			if (bz==0){
				BZ=0;
				break;
			}
		}
		if (BZ && n>m)
			ans=min(ans,c);
		printf("%d\n",ans==INF?-1:ans);
	}
	return 0;
}

#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

const int INF = 1 << 30;

const string ac = "atcoder";

int solve(string s) {
	int len = s.length();
	if (s > ac) {
		return 0;
	}
	for (int i = 1; i < len; ++i) {
		if (s[i] != 'a') {
			return i - (s[i] > 't');
		}
	}
	return -1;
}

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; ++t) {
		string s;
		cin >> s;
		int ans = solve(s);
		cout << ans << endl;
	}
	return 0;
}


/*** keep hungry and calm CoolGuang!  ***/
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<iostream>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll INF= 1e16+7;
const int maxn = 1e6+700;
const int mod= 998244353;
const double eps = 1e-9;

const double PI = acos(-1);
template<typename T>inline void read(T &a){char c=getchar();T x=0,f=1;while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}a=f*x;}
ll n,m;
int prime[maxn],vis[maxn];
int cnt = 0;
ll fac[maxn];
ll qpow(ll a,ll b)
{
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }return ans;
}
ll cal(int m,int n)
{
    if(m<n) return 0;
    return fac[m]*qpow(fac[m-n],mod-2)%mod*qpow(fac[n],mod-2)%mod;
}
int mx[maxn];
map<ll,int>mp;
void SetPrime(){
	for(int i=2;i<=200000;i++){
		if(!vis[i]){
			prime[++cnt] = i;
			mx[i] = i;
			for(int k=i*2;k<=200000;k+=i){
				vis[k] = 1;
				mx[k] = i;
			}
		}
	}
}
int main(){
	SetPrime();
	fac[0] = 1;
	for(int i=1;i<=500000;i++) fac[i] = (fac[i-1]*i)%mod;
	read(n);read(m);
	ll ans = 0;
	for(int i=1;i<=m;i++){
		ll tmp = i,res = 1,pre = mx[tmp],c = 0;
		while(tmp != 1){
			if(mx[tmp]!=pre){
				res = (res * cal(n+c-1,c))%mod;
				c = 1;
			}else c++;
			pre = mx[tmp];
			tmp /= mx[tmp];
		}
		res = (res * cal(n+c-1,c))%mod;
		ans = (ans + res)%mod;
	}
	dl(ans);
  return 0;
}
/***
***/

#include <bits/stdc++.h>

using namespace std;

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

ll mod = 998244353;
ll dp[200001][18];

void countWays(ll n, ll m)
{

    for (int i = 0; i <= n; i++) {
        dp[1][i] = 1;
    }

    ll sum;

    for (int i = 2; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            sum = 0;

            for (int k = 0; k <= j; k++) {
                sum += dp[i - 1][k], sum %= mod;
            }

            dp[i][j] = sum;
        }
    }

}

int main(){

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

    ll n, m;
    cin >> n >> m;

    countWays(17, n);

    ll bn = 1;

    for (int i = 2; i <= m; i++){

        ll brp = 0;
        ll tbn = 1;
        ll t = i;

        for (int j = 2; j <= sqrt(i); j++){
            ll btr = 0;
            while (t%j == 0)
             btr++, t/=j;
            if (btr > 0)
             tbn *= dp[n][btr], tbn %= mod;
        }

        if (t > 1)
            tbn *= n, tbn %= mod;

        bn += tbn, bn%= mod;

    }
    //cout << dp[n][2] << endl;

    cout << bn;

}


//kyoprosaikoooooooooooo!!
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
//素数判定 O(√N)
ll prime (ll abc) {
  if (abc < 2) {
    return 0;
  }
  else if (abc == 2) {
    return 1;
  }
  else if (abc % 2 == 0) {
    return 0;
  }
  double sqrtabc = sqrt(abc);
  for (int i = 3; i <= sqrtabc; i++) {
    if (abc % i == 0) {
      return 0;
    }
  }
  return 1;
}
//素因数分解(約数列挙) O(√N)
vector<ll> divisor(ll n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
//最大公約数
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
//最小公倍数
ll lcm(ll x,ll y){
    return (ll)(x/gcd(x,y))*y;
}
int main() {
  int N, D, H;
  cin >> N >> D >> H;
  vector<vector<double>> S(N, vector<double>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> S.at(i).at(j);
    }
  }
  double ans = 0;
  for (int i = 0; i < N; i++) {
    double X = H + (S.at(i).at(1) - H) * D / (D - S.at(i).at(0));
    ans = max(X, ans);
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

using ll =long long;

using namespace std;

using Graph =vector<vector<ll> >;

int main(){
    int X,Y,Z;

    cin>>X>>Y>>Z;

    int ans=0;

    for(int p=0;p<10000000;p++){
        if(p*X>=Y*Z){
            ans=p;
            break;
        }
    }
    ans--;

    cout<<ans<<endl;
}


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

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 22;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	cout << n - 1 << "\n";
}

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


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

int n;

int A[10],tot;

void Work(){
	read(n);
	while(n&&n%10==0) n/=10;
	while(n) A[++tot]=n%10,n/=10;
	for(int i=1;i<=tot/2;++i)
		if(A[i]!=A[tot-i+1]) return puts("No"),void();
	puts("Yes");
}

int main(){Work();}

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

using namespace std;
using Graph = vector<vector<int>>;
using vst= vector<string>;
using vin= vector<int>;
using ll=long long;
using ull=unsigned long long;
using vll= vector<ll>;
using P=pair<int ,int>;
using pqi=priority_queue<int, vector<int>, greater<int>>;
using pqp=priority_queue<P, vector<P>, greater<P>>;

//const long double pi=acos(-1);
#define ft first
#define sd second
#define fn front
#define pb push_back
#define eb emplace_back
#define it insert
#define vvi vector<vector<int>>
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define gsot(x) sort(x.begin(), x.end(), greater<ll>());
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x)
#define all(x) (x).begin(),(x).end()
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))
#define cps CLOCKS_PER_SEC
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define cset(x) cout<<fixed<<setprecision(x)

const ll INF=(1e18)+(1e17);
const ll ma=(1e18)+100;
//const int INF=1001001001;
//998244353  1000000007

int f(string &x){
    int d=1;
    for(auto c:x){
        if(d<c-'0') d=c-'0';
    }
    return d;
}
ll g(string &x, ll a){
    ll ans=0;
    rep(i,x.size()){
        if((ans)>(ma/a)) return INF;
        ans*=a;
        ans+=(x[i]-'0');
        if(ans>=ma) return INF;
    }
    return ans;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string x;
    ll m;
    cin>>x>>m;
    ll d=f(x);
    //cout<<g(x,6)<<endl;
    //cout<<d<<endl;
    //cout<<g(x,d+1)<<endl;
    if(g(x,d+1)>m){
        cout<<0<<endl;
        return 0;
    }
    if(x.size()==1){
        cout<<1<<endl;
        return 0;
    }
    ll ok=d+1,ng=m;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        if(g(x,mid)>m) ng=mid;
        else ok=mid;
    }
    if(x=="10") cout<<m-1<<endl;
    else cout<<ok-d<<endl;
}


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

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef double ld;

 const int N=1e5+5;

ll a[N];
list<ll>diff;

/*
void prints(vector<pair<ll,ll>>v,ll n){

  cout<<"after sorting the elements"<<endl;
   for(int i=0;i<n;i++)
  cout<<v[i].first<<" "<<v[i].second<<endl;

 return ;
}

*/

int main()
 {

    IOS;
     ll t,cnt=0;
     cin>>t;
     vector<pair<ll,ll>>v(t);

    for(int i=0;i<t;i++){
      cin>>v[i].first>>v[i].second;
     }

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

     for(int i=0;i<t-1;i++)
     {
        ll f1 = v[i].first;
         ll g1 = v[i].second;
      for(int j=i+1;j<t;j++)
      {
         ll f2 = v[j].first;
         ll g2 = v[j].second;

          //   cout<<"("<<f1<<"."<<g1<<")"<<" "<<"("<<f2<<"."<<g2<<")"<<endl;

           double upper ,lower;
            upper =  (g2-g1);

           lower = (f2-f1);

           double dist = double(upper/lower);

       //     cout<<upper<<" ? "<<lower<<"  ? "<<dist<<endl;

          if( dist >= -1 && dist <= 1)
              cnt++;

      }

     }

     cout<<cnt<<endl;

  return 0;
 }

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;

int main() {
	long long N; cin >> N;
	vector<long long> X(N), C(N);
	for (int i = 0; i < N; i++) cin >> X[i] >> C[i];

	priority_queue<long long> Que[200020];
	for (int i = 0; i < N; i++) {
		Que[C[i] - 1].push(X[i]);
	}

	long long min_dp = 0;
	long long max_dp = 0;
	long long min_dp_num = 0;
	long long max_dp_num = 0;

	for (int i = 0; i < N; i++) {
		if (Que[i].empty()) continue;
		long long min_ = 1LL << 60;
		long long max_ = 0 - (1LL << 60);
		while (!Que[i].empty()) {
			long long a = Que[i].top();
			Que[i].pop();
			min_ = min(min_, a);
			max_ = max(max_, a);
		}
		long long p;
		if (max_ < min_dp_num) p = min_dp + (min_dp_num - min_);
		else p = min_dp + (max_ - min_dp_num) + (max_ - min_);
		long long q;
		if (max_ < max_dp_num) q = max_dp + (max_dp_num - min_);
		else q = max_dp + (max_ - max_dp_num) + (max_ - min_);
		long long r;
		if (min_ > min_dp_num) r = min_dp + (max_ - min_dp_num);
		else r = min_dp + (min_dp_num - min_) + (max_ - min_);
		long long s;
		if (min_ > max_dp_num) s = max_dp + (max_ - max_dp_num);
		else s = max_dp + (max_dp_num - min_) + (max_ - min_);

		min_dp = min(p, q);
		max_dp = min(r, s);
		min_dp_num = min_;
		max_dp_num = max_;
	}
	min_dp = min_dp + abs(min_dp_num);
	max_dp = max_dp + abs(max_dp_num);

	cout << min(min_dp, max_dp) << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;

#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll N, K, M;
    cin >> N >> K >> M;

    ll sum = 0;
    rep (i, N-1) {
        ll A;
        cin >> A;
        sum += A;
    }

    if (N*M-sum <= K) {
        if (N*M-sum >= 0) {
            cout << N*M-sum << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        cout << -1 << endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
#include <tuple>
#include <numeric>
#include <utility>
using namespace std;

namespace {
  using Integer = long long; //__int128;
  template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;}
  template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
  template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
  template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;}
  template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
  template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}

  template<class H> void print(const H& head){ cout << head; }
  template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); }
  template<class ... T> void println(const T& ... values){ print(values...); cout << endl; }

  template<class H> void eprint(const H& head){ cerr << head; }
  template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); }
  template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; }

  class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator   end(){ return range_iterator(  end_, step_); } };

  inline string operator "" _s (const char* str, size_t size){ return move(string(str)); }
  constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);}
  constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);}
  constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); }

  inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed

  mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count());

  template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); }

  inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; }
}
constexpr long long mod = 9_ten + 7;

int main(){
  int a,b;
  cin >> a,b;
  for(int x=-100; x<=100; x++)
  for(int y=-100; y<=100; y++)
    if(x+y == a && x-y == b){
      println(x, y);
      return 0;
    }

  return 0;
}


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

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

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
struct RandGen{
	ll x,y,z;
	ll nextInt()
	{
		ll t=x^(x<<11);
		x=y;
		y=z;
		z^=(z>>19)^t^(t>>8);
		return x;
	}
	ll random(ll M)
	{
		return nextInt()%M;
	}
}rng;
int main(){
	rng.x=89327;
	rng.y=2579;
	rng.z=67239;
	ll t=1000;
	while(t--)
	{
		ll x,y,a,b,nxt;
		cin>>x>>y>>a>>b;
		while(abs(a-x)+abs(b-y)>0)
		{
			nxt=rng.random(abs(a-x)+abs(b-y));
			if(nxt<abs(a-x))
			{
				if(x>a)
				{
					putchar('U');
					x--;
				}
				else
				{
					putchar('D');
					x++;
				}
			}
			else
			{
				if(y<b)
				{
					putchar('R');
					y++;
				}
				else
				{
					putchar('L');
					y--;
				}
			}
		}
		puts("");
		fflush(stdout);
		ll d;
		cin>>d;
	}
	return 0;
}


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

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

	long double x, y, r;
	cin >> x >> y >> r;

	r = nextafter(r, 1001001001001001001LL);
	long long answer = 0LL;
	for (long long i = ceil(x - r); i <= floor(x + r); i++) {
		long double a = r * r - (i - x) * (i - x);
		answer += floor(y + sqrtl(a)) - ceil(y - sqrtl(a)) + 1LL;
	}
	cout << answer;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

std::vector<std::string> split(const std::string &s, const std::string &delimiter) {
  std::vector<std::string> res;
  int pos = 0;
  while (true) {
    int del_pos = s.find(delimiter, pos);
    if (del_pos == s.npos) break;
    res.emplace_back(s.substr(pos, del_pos - pos));
    pos = del_pos + delimiter.length();
  }
  res.emplace_back(s.substr(pos));
  return res;
}

constexpr int L = 10000;

int format(string s) {
  vector<string> v = split(s, ".");
  int x = stoi(v[0]) * L;
  if (v.size() == 1) return x;
  while (v[1].length() < 4) v[1] += '0';
  return x + stoi(v[1]);
}

ll ceilL(ll x) {
  return x >= 0 ? (x + L - 1) / L * L : x / L * L;
}

int main() {
  string xs, ys, rs; cin >> xs >> ys >> rs;
  ll x = format(xs), y = format(ys), r = format(rs);
  ll ans = 0;
  for (ll h = ceilL(y - r); h <= y + r; h += L) {
    ll l = x - r - 1;
    {
      ll ub = x;
      while (ub - l > 1) {
        ll mid = (l + ub) >> 1;
        ((y - h) * (y - h) + (x - mid) * (x - mid) <= r * r ? ub : l) = mid;
      }
      ++l;
    }
    ll ri = x + r + 1;
    {
      ll lb = x;
      while (ri - lb > 1) {
        ll mid = (lb + ri) >> 1;
        ((y - h) * (y - h) + (mid - x) * (mid - x) <= r * r ? lb : ri) = mid;
      }
      --ri;
    }
    // cout << h << ' ' << l << ' ' << r << '\n';
    l = ceilL(l);
    if (l <= ri) ans += (ri - l) / L + 1;
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegain(),(x).rend()
const int INF=1e9;
using namespace std;
using ll = long long;
typedef pair<int,int> P;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    reverse(all(s));
    rep(i,0,n){
        if(s[i]=='6') s[i]='9';
        else if(s[i]=='9') s[i]='6';
    }
    cout<<s;
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    string s;
    cin>>s;
    auto f=[&](char c){
        if(c=='0')return '0';
        if(c=='1')return '1';
        if(c=='6')return '9';
        if(c=='8')return '8';
        if(c=='9')return '6';
    };
    rep(i,s.size()){
        s[i]=f(s[i]);
    }
    reverse(all(s));
    out(s);
}


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

const int N=2e5+100;
#define ll long long
int K; ll f[N],ans;
int main() {
	cin>>K;
	for(int i=1;i<=K;++i)
		for(int j=i;j<=K;j+=i)
			++f[j];
	for(int i=1;i<=K;++i) f[i] += f[i-1];
	for(int i=1;i<=K;++i) ans += f[K/i];
	cout<<ans<<endl; return 0;
}

/*************************************************************************
  > File Name: solve.cpp
  > Author: liupo
  > Mail: lanzongwei@gmail.com
  > Created Time: 2021-02-21 20:21:34
 ************************************************************************/

#define GOODOJ
#define SYNC 0

#ifdef GOODOJ
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#include <chrono>
#include <random>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#else
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
#include <limits>
#include <cassert>
#include <sstream>
#include <iterator>
#include <functional>
#endif
using namespace std;

#define endl '\n'
#define fep(i,b,e) for(int i=(b);i<int(e);++i)
#define rep(i,x) for(int i=0;i<int(x);++i)
#define rap(i,x) for(auto& i : (x))
#define seg(t) (t).begin(), (t).end()
#define ep emplace_back
#define mkp make_pair
#define qxx(i,x) for(int i = head[x]; ~i; i = node[i].nex)
#define F first
#define S second
#define lowbit(x) ((-(x))&(x))
#define RE register
#define getchar() getchar_unlocked()
#ifdef DEBUG
void err(istream_iterator<string>){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ' ';
	err(++it, args...);
}
#define debug(args...) {string _s=#args;replace(seg(_s),',',' ');\
	cerr<<"DEBUG:";istringstream it(_s);\
	err(istream_iterator<string>(it), args);cerr<<endl;}
#else
#define debug(...)
#endif

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

#ifdef GOODOJ
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
typedef __gnu_pbds::priority_queue<int> pq;
#endif
typedef std::string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pa;

const double P = acos(-1.0), eps = 1e-9;
struct point { db x ,y;};
inline int sign(db a) {return a < -eps ? -1 : a > eps;}
#define dot(p1,p2,p3) ((p2.x-p1.x)*(p3.x-p1.x)+(p2.y-p1.y)*(p3.y-p1.y))
#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))

constexpr int Ma = 1e6, inf = 0x3f3f3f3f, mod = 1e9 + 7;

signed main() {
#if SYNC==0
	ios::sync_with_stdio(false);
	cin.tie(0);
#endif
	ll k; cin >> k;
	ll cnt = 0;
	fep (i, 1, k + 1) {
		for (int j = 1; j <= k / i; j++) {
			cnt += k / i / j;
		}
	}
	cout << cnt << endl;

	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;
//arc110

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) res=res*x%m;
    return res;
}

ll modinv(ll n){
    return mod_pow(n,mod-2,mod);
}
int main(){
    //オーバーフローは大丈夫ですか？？
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    V<ll> a(n);
    ll sum=0;
    bool is0=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll ans=1;
    if(sum+n>n+m) ans=0;
    else{
        for(ll i=1;i<=sum+n;i++){
            ans=ans*(m+n-i+1)%mod;
            ans=ans*modinv(i)%mod;
        }
    }
    out(ans);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ
Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり
(デフォルトは-INF,0の方が都合の良い場合は変更)
*/

#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>
#include <chrono>

constexpr int MOD = 1000000007;
long long int power(long long int base, int exp) {
	long long int result{ 1 };
	while (exp > 0) {
		if (exp & 1) {
			result = (result * base) % MOD;
		}
		exp >>= 1;
		base = (base * base) % MOD;
	}
	return result;
}
long long int combination(const int n, const int r) {
	long long int result{ 1 };
	for (auto i = 0; i < r; ++i) {
		result = (result * (n - i)) % MOD;
	}
	std::vector<long long int> div(r + 1, 1);
	for (auto i = 2; i <= r; ++i) {
		div[i] = (MOD - MOD / i) * div[MOD % i] % MOD;
		result = result * div[i] % MOD;
	}
	return result;
}
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<int> series(n);
	for (auto& a : series) std::cin >> a;
	const auto sum = std::accumulate(series.begin(), series.end(), 0);
	if (sum > m) {
		std::cout << "0\n";
		return 0;
	}
	std::cout << combination(n + m, sum + n) << '\n';
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using P = pair<int,int>;
#define INF 1001001001
#define LINF (1LL<<60)
#define F first
#define S second
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 UnionFind {
  vector<int> p;
  vector<int> sizes;
  UnionFind(int n) : p(n), sizes(n, 1) {
    rep(i,n) p[i] = i;
  }
  int find(int x) {
    if (x == p[x]) return x;
    return p[x] = find(p[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    p[y] = x;
    sizes[x] += sizes[y];
  }
  bool isSame(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return sizes[find(x)];
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int M = 200010;
  UnionFind uf(M);
  int ans = 0;
  rep(i, n) uf.unite(a[i], a[n-1-i]);
  rep(i, M) {
    if (i != uf.find(i)) continue;
    ans += uf.size(i)-1;
  }
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

struct UF {
  int n;
  vector<int> par;
  vector<int> rank;
  UF(int n) : n(n) {
    for (int i = 0; i < n; ++i) {
      par.resize(n);
      rank.resize(n);
      par.at(i) = i;
      rank.at(i) = 0;
    }
  }

  int find(int x) {
    if (par.at(x) == x) {
      return x;
    } else {
      return par.at(x) = find(par.at(x));
    }
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank.at(x) < rank.at(y)) {
      par.at(x) = y;
    } else {
      par.at(y) = x;
      if (rank.at(x) == rank.at(y)) rank.at(x)++;
    }
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int solve() {
    unordered_map<int, int> m;
    for (int i = 0; i < n; ++i) {

      m[find(i)]++;
    }
    int ans = 0;
    for (auto p : m) {
      ans += p.second - 1;
    }
    return ans;
  }
};

int main() {

  int n;
  cin >> n;
  int key = 0;
  vector<int> a(n);
  unordered_map<int, int> m;
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    if (m.find(a.at(i)) == m.end()) {
      m[a.at(i)] = key;
      key++;
    }
  }

  UF uf(key);

  for (int i = 0; i < (n+1) / 2; ++i) {
    int x = m.at(a.at(i));
    int y = m.at(a.at(n-i-1));
    if (x != y) {
      uf.unite(x, y);
    }
  }
  cout << uf.solve() << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MAXN = 2e5;

int x[MAXN], y[MAXN];
int main() {
//  freopen("in", "r", stdin);
//  freopen("out", "w", stdout);
    int n, ans=0;
    scanf("%d", &n);
    FOR(i,n)
        scanf("%d%d", &x[i], &y[i]);
    rep(i,0,n) rep(j,i+1,n)
        if(abs(y[j]-y[i])<=abs(x[j]-x[i])) ans++;
    printf("%d", ans);
    return 0;
}

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
const int MAXN = 110;
double d[MAXN], h[MAXN];
int N;
double D, H;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

double solve(int idx) {
    if(d[idx] == D) {
        return H;
    }
    return ((H + h[idx])*(D-d[idx]) + h[idx]*d[idx] - H*D)/(D - d[idx]);
}

int main() {
    quickread();
    cin >> N >> D >> H;
    for (int i = 0; i < N; i++) {
        cin >> d[i] >> h[i];
    }
    double res = 0;
    for (int i = 0; i < N; i++) {
        res = max(solve(i), res);
    }
    cout << fixed << setprecision(6) << res << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<ll> vec;
#define MAX 1000000007

int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a==b+c+d || b==c+d+a || c==b+a+d || d==b+c+a || a+b==c+d || a+c==b+d || a+d==b+c ){
      cout<<"Yes"<<"\n";
  }
  else{
      cout<<"No"<<"\n";
  }

}

#include<cstdio>
#define max(a,b) (((a)>(b))?(a):(b))
using namespace std;
int a,b,c;
int main() {
	scanf("%d%d%d",&a,&b,&c);
	printf("%d",max(c+max(a,b),a+b));
	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
char S[110][110];

signed main(){
	cin>>N>>M;
	REP(i,N){
		cin>>S[i];
	}
	int ans=0;
	REP(i,N){
		REP(j,M-1){
			if(S[i][j]=='.'&&S[i][j+1]=='.'){
				ans++;
			}
		}
	}
	REP(i,M){
		REP(j,N-1){
			if(S[j][i]=='.'&&S[j+1][i]=='.'){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	int a, b;
	cin >> a >> b;
	int total = 2 * a + 100;
	cout << total - b << "\n";
}

/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void solve(){
	ll a,b,c;
	cin>>a>>b;
	c=(2*a)+100;
	cout<<abs(c-b);
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 998244353;
typedef long long LL;
typedef pair<int, int> P;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int H, W; cin >> H >> W;
  vector<string> S(H); cin >> S;
  vector<vector<int>> C(H, vector<int>(W, 0));

  for (int c = 1; c < W; ++c) {
    C[0][c] = C[0][c-1] + 1;
  }
  for (int r = 1; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      C[r][c] = C[r-1][c] + 1;
    }
  }

  map<int, char> m;
  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      int x = C[r][c];
      char y = S[r][c];
      if (m.count(x)) {
        if (m[x] != y && y != '.') {
          if (m[x] == '.') {
            m[x] = y;
          } else {
            cout << 0 << endl;
            return 0;
          }
        }
      } else {
        m[x] = S[r][c];
      }
    }
  }

  LL ans = 1;
  for (const auto& [i, c] : m) {
    if (c == '.') {
      ans = ans * 2LL;
      ans %= kMod;
    }
  }
  cout << ans << endl;
}

#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 505
#define ENDL putchar('\n')
#define LL long long
#define DB double
#define lowbit(x) ((-x) & (x))
LL read() {
	LL f = 1,x = 0;char s = getchar();
	while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();}
	while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();}
	return f * x;
}
const int MOD = 998244353;
int n,m,i,j,s,o,k;
char ss[MAXN][MAXN];
int tg[MAXN<<1];
int main() {
	n = read(); m = read();
	for(int i = 1;i <= n;i ++) {
		scanf("%s",ss[i] + 1);
		for(int j = 1;j <= m;j ++) {
			if(ss[i][j] == 'B') {
				if(tg[i+j] > 0) {printf("0\n");return 0;}
				tg[i+j] = -1;
			}
			else if(ss[i][j] == 'R') {
				if(tg[i+j] < 0) {printf("0\n");return 0;}
				tg[i+j] = 1;
			}
		}
	}
	int ans = 1;
	for(int i = 2;i <= n+m;i ++) {
		if(tg[i] == 0) (ans += ans) %= MOD;
	}
	printf("%d\n",ans);
	return 0;
}