#include <bits/stdc++.h>
/*#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <sstream>*/

#define ll long long
#define fop(i,m,n) for(int i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

using namespace std;

const long long MOD = 1e9+7;
const long long N = 1e9+5;
const long long Nlog = 17;
const long long Hash = 257;

const double PI = 2.0*acos(0.0);//<cmath>
//const double PI = 3.141592653;
const double E = 2.718281828;

struct Seg{
    int l, r, m;
    int val;
    Seg* ch[2];
    Seg(int inl, int inr) : l(inl), r(inr), m((l+r)>>1){
        if(r-l == 1) val = 0;
        else{
            ch[0] = new Seg(l, m);
            ch[1] = new Seg(m, r);
            pull();
        }
    }

    void pull(){
        val = ch[0]->val + ch[1]->val;
    }

    void set(int p, int v){
        if(r-l == 1) val = v;
        else{
            if(p < m) ch[0]->set(p, v);
            else ch[1]->set(p, v);
            pull();
        }
    }

    int query(int a, int b){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return val;
        return ch[0]->query(a, b) + ch[1]->query(a, b);
    }

};

void solve(){

    int n;
    cin >> n;
    ll a[n], b[n];
    fop(i,0,n){
        cin >> a[i];
        a[i] += i;
    }
    fop(i,0,n){
        cin >> b[i];
        b[i] += i;
    }

    map<ll, deque<int> > m;
    fop(i,0,n){
        m[a[i]].pb(i);
    }
    int p[n];
    fop(i,0,n){
        if(m[b[i]].empty()){
            cout << "-1\n";
            return;
        }
        p[i] = m[b[i]].front();
        m[b[i]].pop_front();
    }

    //fop(i,0,n) cout << p[i] << ' ';
    //cout << '\n';

    ll ans = 0;
    Seg tree(0, n);
    fop(i,0,n){
        ans += tree.query(p[i], n);
        tree.set(p[i], 1);
    }
    cout << ans << '\n';

}

int main()
{
    fastIO;

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

    return 0;
}

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

ll mod = 998244353;

//segment tree
//1-indexed all
class segtree {
public:
    ll n;
    vector<ll> A;
    segtree(ll k){
        n = 1;
        while(n<k){ n *= 2; }
        A=vector<ll>(2*n,0);
    }

    //a[i]にxを加算する
    void add(ll i,ll x){
        int index = n-1+i;
        A[index] += x;
        while(index>1){
            index /= 2;
            A[index] = A[2*index]+A[2*index+1];
        }
    }

    //a[i]をにする
    void replace(ll i,ll x){
        int index = n-1+i;
        A[index] = x;
        while(index>1){
            index /= 2;
            A[index] = A[2*index]+A[2*index+1];
        }
    }

    //a[i]+a[i+1]+…+a[j]を求める
    ll sum(ll i,ll j){
        return rangesum(i,j,1,1,n);
    }

    // a,b求める区間 k区間番号 c,d区間の始終点(k=1,c=1,d=nで入力する)
    ll rangesum(ll a,ll b,ll k,ll c,ll d){
        //単位元の設定
        ll el = 0;
        if(d<a||b<c){
            return el;
        }
        else if(a<=c&&d<=b){
            return A[k];
        }
        else{
            //2区間に分割して演算を行う
            ll p = rangesum(a,b,k*2,c,(c+d)/2)+rangesum(a,b,k*2+1,(c+d)/2+1,d);
            return p;
        }
    }

};

int main() {
    ll N; cin >> N;
    ll a[N],b[N];
    set<Pr> num; num.insert(make_pair(2e18,0LL));
    rep(i,N){
        cin >> a[i];
        num.insert(make_pair(a[i]+i,i));
    }
    vector<Pr> perm;
    rep(i,N){
        cin >> b[i];
        ll k = b[i]+i;
        auto itr = num.lower_bound(make_pair(k,-1));
        auto p = *itr;
        ll s = p.first;
        if(s!=k){
            cout << -1 << endl; return 0;
        }
        ll j = p.second;
        perm.push_back(make_pair(i+1,j+1));
        num.erase(itr);
    }
    ll ans = 0;
    //main関数内で
    segtree seq(N+1);
    //などと宣言し  seq.replace(i,x);
    //のように使う 1-indexed 注意!!!!!!
    sort(perm.begin(),perm.end());
    reverse(perm.begin(),perm.end());
    for(auto q:perm){
        ll j = q.second;
        //cout << j << endl;
        ans += seq.sum(1,j);
        seq.add(j,1);
    }
    cout << ans <<  endl;
}


#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define f first
#define s second
#define pb push_back

// clang-format off
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T_vector>void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << "(" << v.first << ":" << v.second << ")" << ","; os << "}"; return os; }

auto random_address = [] {char *p = new char; delete p;return uint64_t(p);};
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
// clang-format on

void solve() { }
vector<int> to_int(int x) {
     vector<int> a;
     while (x) {
          int s = x % 10;
          a.push_back(s);
          x /= 10;
     }
     return a;
}

int g1(vector<int> x) {
     int ans = 0;
     sort(x.rbegin(), x.rend());
     // 314
     int z = 1;
     for (int i = sz(x) - 1; i >= 0; --i) {
          ans += z * x[i];
          z *= 10;
     }
     return ans;
}
int g2(vector<int> x) {
     int ans = 0;
     sort(x.begin(), x.end());
     // 314
     int z = 1;
     for (int i = sz(x) - 1; i >= 0; --i) {
          ans += z * x[i];
          z *= 10;
     }
     return ans;
}
int main() {
     ios::sync_with_stdio(0);
     cin.tie(0);
     int n, k;
     cin >> n >> k;
     int x = n;
     vector<int> ans;
     for (int i = 0; i < k; i++) {
          auto d = to_int(x);
          int t = g1(d) - g2(d);
          x = t;
          ans.push_back(t);
     }
     if (k == 0)
          cout << n;
     else {
          cout << ans[sz(ans) - 1];
     }
     // int tests;
     // cin >> tests;
     // while (tests-- > 0)
     //      solve();
}

#include <bits/stdc++.h>
#define speedup                                                                \
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),          \
        cout.precision(12)
using namespace std;

#ifndef ONLINE_JUDGE
#define eprintf(...) fprintf(stderr,__VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) void(0)
#endif
using ll = long long;
using str = string;
using vi = vector<int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) int((x).size())

ll nxt(ll N) {
	vi d;
	while(N) {
		d.pb(N%10);
		N/=10;
	}
	sort(all(d));
	ll a=0,b=0,p=1;
	for(const auto& it:d) {
		a=a*10+it;
		b=it*p+b;
		p*=10;
	}
	return b-a;
}

int main() {
	speedup;
	ll N,k;
	cin>>N>>k;
	while(k--&&N>0) {
		N=nxt(N);
	}
	cout<<N<<'\n';
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

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

  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  int K = 0;
  rep (i, H) {
    cin >> S[i];
    rep (j, W) {
      if (S[i][j] == '.')
        K++;
    }
  }
  vector<vector<int>> a(H, vector<int>(W, 0));
  vector<vector<int>> b(H, vector<int>(W, 0));
  rep (i, H) {
    int cnt = 0;
    rep(j, W) {
      if (S[i][j] == '.') {
        cnt++;
        if (j == W-1) {
          a[i][j] = cnt;
        }
        else {
          if (S[i][j+1] == '#') {
            a[i][j] = cnt;
            cnt = 0;
          }
        }
      }
    }
  }
  rep (i, H) {
    int cnt = 0;
    for (int j = W-1; j >= 0; j--) {
      if (a[i][j] > 0) {
        cnt = a[i][j];
      }
      if (S[i][j] == '.')
        a[i][j] = cnt;
    }
  }
  // rep (i, H) {
  //   rep (j, W) {
  //     cout << a[i][j];
  //   }
  //   cout << endl;
  // }
  rep (j, W) {
    int cnt = 0;
    rep(i, H) {
      if (S[i][j] == '.') {
        cnt++;
        if (i == H-1) {
          b[i][j] = cnt;
        }
        else {
          if (S[i+1][j] == '#') {
            b[i][j] = cnt;
            cnt = 0;
          }
        }
      }
    }
  }
  rep (j, W) {
    int cnt = 0;
    for (int i = H-1; i >= 0; i--) {
      if (b[i][j] > 0) {
        cnt = b[i][j];
      }
      if (S[i][j] == '.')
        b[i][j] = cnt;
    }
  }
  ll ans = 0;
  rep(i, H) {
    rep (j, W) {
      if (S[i][j] == '.') {
        int m = a[i][j]+b[i][j]-1;
        ans += (((mod_pow(2, (ll)(m))-1)*mod_pow(2, (ll)(K-m)))%MOD);
        ans %= MOD;
      }
      // cout << ans << endl;
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 2e18;
const ll fact_table = 1200008;

priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
// priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;

ll n, k;
ll dist = 0, cnt = 0;

vec G[500005];

P dfs(int v, int p) {
    // first  : 一番近い黒までの距離
    // second : 一番遠い白までの距離
    ll black = INF, white = 0;

    for (auto nv : G[v]) {
        if (nv == p) continue;
        auto [b, w] = dfs(nv, v);
        black = min(black, b);
        white = max(white, w);
    }

    if (white + black <= dist) {
        white = -1;
    }
    if (white == dist) {
        cnt++;
        white = -1, black = 0;
    }
    if (p == -1 && white >= 0) {
        cnt++;
    }
    black++;
    white++;
    return P(black, white);
}

int calc(ll mid) {
    dist = mid;
    cnt = 0;
    P res = dfs(1, -1);
    return cnt;
}

bool solve() {
    cin >> n >> k;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }

    ll ok = n, ng = -1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (calc(mid) <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    p(ok);
    return true;
}

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

    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        solve();
        testcase++;
    }

    // solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;

int pow10(int x){
    int ans = 1;
    while(x--) ans *= 10;
    return ans;
}

ll tri(ll x){
    return x*(x-1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int k;
    string s, t;
    cin >> k >> s >> t;

    auto calc = [&](string s_, int x){
        vector<int> c(10);
        c[x]++;
        for(int i = 0; i <  4; i++) c[s_[i]-'0']++;
        int ans = 0;
        for(int i = 1; i <= 9; i++){
            ans += i*pow10(c[i]);
        }
        return ans;
    };
    double ans = 0.0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            vector<ll> rem(10, k);
            for(int l = 0; l < 4; l++) rem[s[l]-'0']--;
            for(int l = 0; l < 4; l++) rem[t[l]-'0']--;
            rem[i]--; rem[j]--;
            bool ok = true;
            for(int l = 1; l <= 9; l++){
                if(rem[l] < 0) ok = false;
            }
            if(ok){
                rem[i]++; rem[j]++;
                double p;
                if(i == j){
                    p = (double)(tri(rem[i]))/(double)(tri(9*k-8));
                }else{
                    p = (double)(rem[i]*rem[j])/(double)(tri(9*k-8));
                }
                if(calc(s, i) > calc(t, j)) ans += p;
                // if(true) ans += p;
            }
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

bool solve(vector<ll> v1, vector<ll> v2){
    vector<ll> v(6, 0);
    for(ll i=1;i<=9;i++){
        v[v1[i]] += i;
        v[v2[i]] -= i;
    }
    ll sum = 0;
    ll d = 1;
    rep(i, 6){
        sum += v[i] * d;
        d *= 10;
    }
    if(sum > 0) return true;
    return false;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    ll cnt = k * 9 - 8;
    ll sum = (cnt - 1) * cnt;
    ll win = 0;
    string s, t;
    cin >> s >> t;
    vector<ll> num(10, k), n1(10, 0), n2(10, 0);
    rep(i, 4){
        num[s[i] - '0']--;
        n1[s[i] - '0']++;
        num[t[i] - '0']--;
        n2[t[i] - '0']++;
    }
    for(ll i=1;i<=9;i++){
        for(ll j=1;j<=9;j++){
            if(num[i] == 0) continue;
            ll cnt1 = num[i];
            num[i]--;
            if(num[j] == 0){
                num[i]++;
                continue;
            }
            ll cnt2 = num[j];
            n1[i]++;
            n2[j]++;
            if(solve(n1, n2)) win += cnt1 * cnt2;
            n1[i]--;
            n2[j]--;
            num[i]++;
        }
    }
    doublecout((double)win / (double)sum);
    return 0;
}


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

mt19937 rng(time(0));

long long randint(long long a, long long b){
    uniform_int_distribution<long long> dist(a, b);
    return dist(rng);
}

const int swapXY[] = {0, 2, 1, 4, 3};

long long findScore(long long a, long long b){
    long long A = a;
    long long B = b;
    long long score = 0;
    while(b){
        score += a/b;
        long long c = b;
        long long d = a%b;
        a = c;
        b = d;
    }

    score += a;
    assert(a == __gcd(A, B));
    return score;
}

vector<int> ans;
void findScore2(long long a, long long b){
    long long A = a;
    long long B = b;
    long long score = 0;
    while(a && b){
        //printf("%lld %lld\n", a, b);
        while(a >= b && b > 0){
            a -= b;
            score ++;
            ans.push_back(3);
        }

        while(b >= a && a > 0){
            b -= a;
            score ++;
            ans.push_back(4);
        }
    }

    while(a){
        //printf("%lld %lld\n", a, b);
        a --;
        score ++;
        ans.push_back(1);
    }

    while(b){
        //printf("%lld %lld\n", a, b);
        b --;
        score ++;
        ans.push_back(2);
    }

    reverse(ans.begin(), ans.end());
    assert(score == findScore(A, B));
}

long double phi = (sqrt(5.0L)+1)/2;

int main(){
    long long N;
    scanf("%lld", &N);

    long long bestScore = 1LL << 60;
    long long bestI = rint(N*phi);
    while(findScore(N, bestI) > 130){
        bestI ++;
    }

    findScore2(N, bestI);

    long long x = 0;
    long long y = 0;

    int K = (int)ans.size();
    for(int i = 0; i < K; i ++){
        if(ans[i] == 1){
            x ++;
        }else if(ans[i] == 2){
            y ++;
        }else if(ans[i] == 3){
            x += y;
        }else if(ans[i] == 4){
            y += x;
        }else{
            assert(ans[i] <= 4 && ans[i] >= 1);
        }
    }

    //printf("x=%lld y=%lld\n", x, y);

    assert(x == N);
    printf("%d\n", K);
    for(int i: ans){
        printf("%d\n", i);
    }

    return 0;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cout << (i*2+1)%n+1 << " " << (i*2)%n+1 << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;

using namespace std;
#define M                    998244353
#define pi                   3.14159265358979323846
#define ll                   long long
#define lld                  long double

// Pair
#define pii                  pair<int, int>
#define pll                  pair<ll, ll>

// Vector
#define vl                   vector<ll >
#define vi                   vector<int>
#define vpi                  vector<pii>
#define vpl                  vector<pll>
#define pb                   push_back
#define mp                   make_pair

// Search
#define lb                   lower_bound
#define ub                   upper_bound
#define mina                 *min_element
#define mama                 *max_element
#define bsrch                binary_search

////////
#define F                    first
#define S                    second
#define cel(x,a)             ((x + a - 1) / a)
#define all(v)               v.begin(), v.end()
#define allrev(v)            v.rbegin(), v.rend()
#define lcm(m, n)            ((m / __gcd(m, n))*n)
#define deb(...)             cerr << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)
#define ms(arr, v)           memset(arr, v, sizeof(arr))
#define ps(x,y)              fixed << setprecision(y) << x
#define _X_                  ios_base::sync_with_stdio(false); cin.tie(NULL)

//pbds
#define ordered                 tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// Input / Output
#define scn(str)             scanf("%s", str)
#define pri(str)             printf("%s\n", str)

const int N = 5e5 + 4;

inline void  dbg()           { cerr << endl; }

template <typename T, typename... V>
inline void  dbg(T t, V... v) {cerr << ' ' << t; dbg(v...);}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll binpow(ll a,ll b,ll p){
    if(b==0)return 1;
    ll t=binpow(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}

void solve()
{
    int h,w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i<h; i++)cin >> s[i];
    bool val[h+w-1] = {0};
    for(int i = 0; i<h; i++)
    {
		for(int j = 0; j<w; j++)
		{
			if(s[i][j]=='R')
			{
				val[i+j] = 1;
			}
		}
	}
	bool val2[h+w-1] = {0};
	for(int i = 0; i<h; i++)
    {
		for(int j = 0; j<w; j++)
		{
			if(s[i][j]=='B')
			{
				val2[i+j] = 1;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i<h+w-1; i++)
	{
		if(val[i] && val2[i])
		{
			cout << "0\n";
			return;
		}else if(!val[i] && !val2[i])cnt++;
	}
	ll ans = binpow(2,cnt,M);
	cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    // clock_t time_req = clock();
    int t = 1;
     //cin>> t;
    while (t--) {
       solve();

   }

    // time_req = clock() - time_req;
    // cout << (float)time_req / CLOCKS_PER_SEC;
   return 0;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=998244353;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
    int h,w;
    cin>>h>>w;
    string s[h];
    fr(i,0,h){
        cin>>s[i];
    }
    vi adj[h-1+w];
    fr(i,0,h){
        fr(j,0,w){
            if(s[i][j]=='.'){
                continue;
            }
            else if(s[i][j]=='R'){
                adj[i+j].pb(1);
            }
            else{
                adj[i+j].pb(2);
            }
        }
    }
    ll ans=1;
    for(int i=0;i<=(h-1+w-1);i++){
        int v=0;
        for(auto x: adj[i]){
            v|=x;
        }
        // cout<<i<<endl;
        if(v==3){
            cout<<0<<endl;
            return;
        }
        else if(v==0){
            ans=(ans*2LL)%mod;
        }
    }
    cout<<ans<<endl;
    return;
}

int main()
{
    boost();

    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

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

void solve()
{
    int N;
    cin >> N;
    vector<ll> l(N), r(N);
    REP(i, N)
    {
        int t;
        cin >> t;
        ll a, b;
        cin >> a >> b;
        l[i] = a * 10LL;
        r[i] = b * 10LL;

        switch (t)
        {
        case 1:
            break;
        case 2:
            r[i]--;
            break;
        case 3:
            l[i]++;
            break;
        case 4:
            l[i]++;
            r[i]--;
            break;
        default:
            break;
        }
    }
    ll count = 0;
    REP(i, N - 1)
    {
        FOR(j, i + 1, N)
        {
            if (l[i] > r[i] || l[j] > r[j])
                continue;
            if (l[i] <= r[j] && l[j] <= r[i])
            {
                count++;
            }
        }
    }

    cout << count << endl;
}

signed main()
{

    solve();

    return 0;
}

#include<bits/stdc++.h>
#define maxn 1000005
#define inf 0x3f3f3f3f
#define mod 1000000007
#define mst(a,x) memset(a,x,sizeof(a))
#define up(l,r,i) for(LL i=l;i<=r;i++)
#define down(l,r,i) for(LL i=l;i>=r;i--)
#define in(l,r,a) for(LL i=l;i<=r;i++)cin>>a[i]
#define out(l,r,a) for(LL i=l;i<=r;i++)cout<<a[i]<<" "
#define injz(n,m,a) for(LL i=1;i<=n;i++)for(LL j=1;j<=m;j++)cin>>a[i][j]
#define hh cout<<endl
#define pb push_back
#define cf LL T;cin>>T;while(T--)
#define cfout(x) cout<<(x?"YES":"NO")<<endl
#define cs cout<<"qaq"<<endl
typedef long long LL;
typedef double db;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    //freopen("bwxnQAQin.txt","r",stdin);
    //freopen("bwxnQAQout.txt","w",stdout);
    LL r,x,y;
    cin>>r>>x>>y;
    double qaq=sqrt(x*x+y*y);
    LL qwq=ceil(qaq/r);
    if(qwq==1&&qwq*r!=qaq)qwq++;
    cout<<qwq;
    return 0;
}


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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, ll> PIL;
typedef pair<ll, int> PLI;
typedef pair<ll, ll> PLL;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const double PI = 3.14159265358979323846;
const double PI2 = PI * 2.0;
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INFL = 1E18;
const int INFI = 1E09;
const int MAX_N = 1E+05;

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

ll A, B, C;

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

    cin >> A >> B >> C;

    string ans = "";
    if (A >= 0 && B >= 0) {
    } else if (A < 0 && B < 0) {
        if (C % 2 == 0) {
            A = abs(A);
            B = abs(B);
        }
    } else {
        if (C % 2 == 0) {
            A = abs(A);
            B = abs(B);
        }
    }

    if (A > B)
        ans = ">";
    else if (A < B)
        ans = "<";
    else
        ans = "=";

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fs first
#define sd second
#define rept(x,n) for(int i=x;i<n;i++)
#define rrept(n,x) for(int i=n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define mpit map<int,int>::iterator
#define stit set<int,int>::iterator
#define quit queue<int,int>::iterator
#define maxt(a,b,c) max(a,max(b,c))
#define mint(a,b,c) min(a,min(b,c))
#define rsort(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define printarr(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<"\n";
#define printvec(v) for(int i = 0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n";
using namespace std;
ll power(ll a,ll b){ll res = 1;while(b){if(b&1)res*=a;a*=a;b/=2;}return res;}
ll powerwithmod(ll a,ll b,ll mod){ll res = 1;while(b){if(b&1)res*=a;res%=mod;a*=a;a%=mod;b/=2;}return res;}
void sieve(vector<ll>&prime,ll n){ll candidate[n+1]={0};candidate[0]=1;candidate[1]=1;candidate[2]=0;
for(ll i = 4;i<=n;i+=2)candidate[i]=1;for(ll i = 3;i*i<=n;i+=2){if(candidate[i]==0){
for(ll j = i*i;j<=n;j+=i){candidate[j] = 1;}}}for(ll i = 2;i<=n;i++){if(candidate[i]==0)prime.pb(i);}}

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

void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a>=0&&b>=0)
    {
        if(a>b)
        cout<<">";
        else if(a<b)
            cout<<"<";
        else
            cout<<"=";
        return;
    }
    else if(a<0&&b<0)
    {
        if(a>b)
        cout<<">";
        else if(a<b)
            cout<<"<";
        else
            cout<<"=";
        return;
    }
    else if(a<0)
    {
        if(c&1)
        {
            cout<<"<";
        }
        else
        {
            if(abs(a)>b)
                cout<<">";
            else if(abs(a)<b)
                cout<<"<";
            else
                cout<<"=";
        }
        return;
    }
    else if(b<0)
    {
        if(c&1)
        {
            cout<<">";
        }
        else
        {
            if(abs(b)>a)
                cout<<"<";
            else if(abs(b)<a)
                cout<<">";
            else
                cout<<"=";
        }
        return;
    }
}
signed main()
{
    speed;
    int t=1;
    //cin>>t;
    while(t--)
    {
         solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

long long f(int x) {
    if (x < 0) return 0LL;
    return 1LL * x * (x + 1) / 2 % MOD;
}

int main() {
    int t;
    scanf("%d", &t);

    while (t--) {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);

        long long c = 1LL * (n - a + 1) * (n - b + 1) % MOD;
        printf("%lld\n", (4LL * f(n - a - b + 1) * c % MOD - 4LL * f(n - a - b + 1) * f(n - a - b + 1) % MOD + MOD) % MOD);
    }
}

/* Clearink */

#include <cstdio>

inline void wint ( int x ) {
	if ( 9 < x ) wint ( x / 10 );
	putchar ( x % 10 ^ '0' );
}

const int MAXN = 100;
int N, K, M, f[MAXN + 1][MAXN * ( MAXN / 2 + 1 ) * ( MAXN >> 1 ) / 2 + 5];

inline void addeq ( int& a, const int b ) { ( a += b ) < M ? 0 : a -= M; }

inline void initDP () {
	f[0][0] = 1;
	int sbound = K * ( N / 2 + 1 ) * ( N >> 1 ) >> 1;
	for ( int i = 0; i < N; ++ i ) {
		for ( int j = 0, cur; j <= sbound; ++ j ) {
			if ( !( cur = f[i][j] ) ) continue;
			for ( int k = 0, s = j; k <= K && s <= sbound; ++ k, s += i + 1 ) {
				addeq ( f[i + 1][s], cur );
			}
		}
	}
}

inline int solve ( const int x ) {
	// k[x-1]+2k[x-2]+...+(x-1)k[1] = k[x+1]+2k[x+2]+...+(n-x)k[n].
	int sbound = x - 1 < N - x ? x - 1 : N - x, ret = 0;
	sbound = K * sbound * ( sbound + 1 ) >> 1;
	for ( int s = 0; s <= sbound; ++ s ) {
		addeq ( ret, 1ll * f[x - 1][s] * f[N - x][s] % M );
	}
	return ( ret * ( K + 1ll ) % M + M - 1 ) % M;
}

int main () {
	scanf ( "%d %d %d", &N, &K, &M );
	initDP ();
	for ( int i = 1; i <= N; ++ i ) {
		wint ( solve ( i ) );
		putchar ( '\n' );
	}
	return 0;
}


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

#pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx,avx2,fma")

using namespace std;
using namespace __gnu_pbds;

typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1);
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< x << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << '(' << a.first << ", " << a.second << ')';    }
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
    if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 2e5 + 7;

ll par [N], a [N], b [N], p [N];
vector <ll> comp [N];

ll root (ll v) { return par[v] = (par[v] == v ? v : root(par[v])); }
inline void unite (ll v, ll u) { par[root(u)] = root(v); }

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

    iota(par, par + N, 0);

    ll n, ans = 0;
    cin>> n;
    input(1, n, a);
    input(1, n, b);
    input(1, n, p);
    for (ll i = 1; i <= n; i++) {
        if (i == p[i])  continue;
        if (b[p[i]] >= a[i])    kill(-1);
        unite(i, p[i]);
    }

    ans = n;
    for (ll i = 1; i <= n; i++) {
        if (par[i] == i)    ans--;
        comp[root(i)].push_back(i);
    }

    cout<< ans << '\n';

    for (ll i = 1; i <= n; i++) if (SZ(comp[i]) > 1) {
        sort(All(comp[i]), [&](ll x, ll y) { return a[x] > a[y]; });
        ll hvy = comp[i][0];
        while (p[hvy] ^ hvy) {
            cout<< hvy << ' ' << p[hvy] << '\n';
            swap(p[hvy], p[p[hvy]]);
        }
    }

    cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}
/*

*/

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int i = a; i <= (n); ++i)
#define repD(i, a, n) for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	int n; cin >> n;
	vi a(n), b(n), p(n), h(n);
    bool possible = true;
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n) cin >> p[i];
	rep(i,n) p[i]--;
	rep(i,n) h[p[i]] = i;
	rep(i,n){
		if(i != p[i] && a[i] <= b[p[i]]) possible = false;
	}
	if(possible == false){
		cout << -1 << endl;
		return 0;
	}
	vector <pii> bb; rep(i,n) bb.pb(mp(b[i],i));
	vector <pii> ans;
	sort(all(bb));
	reverse(all(bb));
	rep(i,n){
		int bi = bb[i].snd; //bi is bag
		int bw = bb[i].fst;
		int hb = h[bi]; //hb is holder of bag
		if(bi == hb) continue; //Already holds bag
		ans.pb(mp(bi,h[bi]));
		swap(h[bi], h[p[bi]]); //Bags swap owners
		swap(p[bi], p[hb]); //Owners swap bags
	}
	cout << sz(ans) << endl;
	rep(i,sz(ans)){
		cout << ans[i].fst + 1 << " " << ans[i].snd + 1 << '\n';
	}
	return 0;
}


#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void solve()
{
	string x;
	cin >> x;

	int ans = x[0] - '0';

	ans = x.size() * 10;

	cout << ans << endl;

}

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

	vector<int> v;

	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	v.push_back(d);

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

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

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

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int N = 4;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  cout << *min_element(A.begin(), A.end()) << '\n';
}


#include<iostream>
#include<cstdio>
#include<map>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
#define M 500005
#define N 1000005
#define MP make_pair
#define debug() cerr<<"Why So Serious?"<<endl
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T>void Rd(T &x){
	x=0;static char c;
	while(c=getchar(),c<48);
	do x=(x<<1)+(x<<3)+(c^48);
	while(c=getchar(),c>47);
}
int n;
char str1[M],str2[M];
int tot1,tot2;
int A[M],B[M];
int main(){
	Rd(n);
	scanf("%s%s",str1,str2);
	for(int i=0;i<n;++i){
		if(str1[i]=='1')A[++tot1]=i;
		if(str2[i]=='1')B[++tot2]=i;
	}
	if(tot1!=tot2){
		puts("-1");
		return 0;
	}
	int ans=0;
	for(int i=1;i<=tot1;i++)if(A[i]!=B[i]){
		int j=i+1;
		bool f=A[i]<B[i];
		for(;j<=tot1&&(A[j]<B[j])==f;++j);
		if(f){
			ans+=abs(B[i]-A[i]);
			for(i++;i<j;++i){
				ans+=B[i]-max(B[i-1]+1,A[i]);
			}
			i--;
		}else {
			j--;
			ans+=abs(B[j]-A[j]);
			for(int k=j-1;k>=i;--k){
				ans+=min(A[k],B[k+1]-1)-B[k];
			}
			i=j;
		}
	}
	printf("%d\n",ans);
	return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
#define pcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
const ld eps = 1e-10;
ull mo = 1000000007;
ld PI=asin(1)*2;
//using namespace atcoder;
ll Scnt[2];
ll Tcnt[2];
string S,T;
ll N;

// ll dfs(ll id){

// }

int main(){
    cin >> N >> S >> T;
    rep(i,N){
        Scnt[S[i] - '0']++;
        Tcnt[T[i] - '0']++;
    }
    set<ll> S_st, T_st;
    rep(i,N){
        if(S[i] == '0'){
            S_st.insert(i);
        }
        if(T[i] == '0'){
            T_st.insert(i);
        }
    }
    if(!(Scnt[0] == Tcnt[0] && Scnt[1] == Tcnt[1])) drop(-1);
    ll ans = 0;
    rep(i,N){
        if(S[i] == T[i]) continue;
        if(S[i] == '1'){
            auto itr = S_st.lower_bound(i+1);
            ll next = *itr;
            S_st.erase(itr);
            ans++;
            S[next] = '1';
        }else if(T[i] == '1'){
            auto itr = T_st.lower_bound(i+1);
            ll next = *itr;
            T_st.erase(itr);
            ans++;
            T[next] = '1';
        }
    }
    cout << ans << endl;
}


#include<cstdio>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
template<typename T>void read(T &x)
{
	bool neg=false;
	unsigned char c=getchar();
	for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
	for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
	if(neg)x=-x;
}
int n;
double ans;
int main()
{
	read(n);
	F(i,1,n)ans+=(double)n/i;
	printf("%0.9lf\n",ans);
	return 0;
}

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

// ---------- Debugger

#define TRACE

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(char c) {
    return '\'' + string(1, c) + '\'';
}

string to_string(char * s) {
    return to_string((string) s);
}

string to_string(const char * s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template < typename A >
string to_string(A v);

template < typename A, typename B >
string to_string(pair < A, B > p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template < typename C > struct rge { C b, e; };
template < typename C > rge<C> range(C i, C j) { return rge<C>{i, j}; }

template < typename C >
string to_string(rge<C> v) {
    bool first = true;
    string res = "[";
    for(auto it = v.b; it != v.e; it++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(*it);
    }
    res += "]";
    return res;
}

template < typename A >
string to_string(A v) {
    return to_string(range(v.begin(), v.end()));
}

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Head >
void __f(const string names, Head arg1) {
    cerr << names << " : " << to_string(arg1) << endl;
}
template < typename Head, typename...Tail >
void __f(const string names, Head arg1, Tail...args) {
    int b = 0, comma = names.size();
    for(int i=0;i<names.size();i++) {
        if(names[i] == ',' && b == 0) {
            comma = i;
            break;
        }
        if(names[i] == '(' || names[i] == '{' || names[i] == '[' || names[i] == '<') b++;
        else if(names[i] == ')' || names[i] == '}' || names[i] == ']' || names[i] == '>') b--;
    }
    // size_t comma = names.find(', ');
    cerr << names.substr(0, comma) << " : " << to_string(arg1) << " | ";
    __f(names.substr(comma + 1), args...);
}
#else
#define trace(...)
#endif

// ---------- Debugger

#define LL long long
#define FI ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
const int MX = (int)1e5 + 5;

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

    double curr = 0;
    for(int x=n-1;x>=1;x--) {
        curr = n * 1.0/(n - x) + curr;
    }

    cout << curr << endl;

    return 0;
}


#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#include <stack>

using namespace std;

#define enviar {ios_base::sync_with_stdio(false);}
#define aiuda {cin.tie(NULL); cout.tie(NULL);}

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) ;F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
#define exacto(v) cout << setprecision(v) << fixed;

#define ll int
#define lld long double
#define eb emplace_back
#define em emplace
#define ef emplace_front
#define f first
#define s second
#define big greater<ll>()
#define bpc(x) __builtin_popcount(x)
#define bpc2(x) __builtin_clz(x)
#define bpc3(x) __builtin_ctz(x)
#define DIE(args...) {print(args); return;}
#define lb lower_bound
#define ub upper_bound

#define ar(v)  array<int,v>
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x).size()
#define meminf(v) memset(v,  0x3f , sizeof(v))
#define mem(v,x) memset(v , x , sizeof v);
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int n1, n2; cin >> n1 >> n2; n1--; n2--; list[n1].eb(n2); list[n2].eb(n1);}

template <typename T> struct combinator  {   T t_; combinator(T&& t) : t_(std::forward<T>(t)) {} template <typename... Args> auto operator () (Args&&... args) const  { return t_(*this, std::forward<Args>(args)...); } };
template<class T> bool umin(T& a, const T& b) { return b<a?a=b, 1:0; }
template<class T> bool umax(T& a, const T& b) { return a<b?a=b, 1:0; }
string to_string(bool b) {return b?"true":"false"; }
string to_string(char c) { return string(1, c);}
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; }
template<class A> void write(A x) { cout << to_string(x); }
void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) {  write(h); if(sizeof...(t)) write(' '); print(t...); }

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<int, int>> vpii;
typedef map<ll, ll> mll;
typedef priority_queue<ll, std::vector<ll>, std::greater<ll>> priomin;
typedef priority_queue<int> priomx;

const ll mod =   998244353;
//const ll mod =   1e9 + 7;
const ll maxsize =2e5  + 5;
//const ll inf = 0x3f3f3f3f3f3f3f3f ;

// size, caracter

//int a[maxsize];

void solve()
{

	int n ;
	cin >> n;
	vector<double> a(n), b(n);

	FOR(i , n)
	{
		cin >> a[i];
		//a[i]/=2;
	}

	sort(all(a));

	partial_sum(all(a), b.begin());

	double ans = 1e18;

	//ao(b , n);
	FOR(i, n)
	{
		double temp =  b[n-1] - b[i] - (n - 1 - i)*a[i];
		umin(ans , a[i]/2 + temp/n );

	}
	cout << setprecision(6) << fixed;
	print(ans);

}

int main(){

	enviar aiuda

	int tc = 1;
	//cin >> tc;

	while(tc--)  solve();

	return 0;
}

// Parasparopagraho Jīvānām

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace  __gnu_pbds ;
using namespace __gnu_cxx ;
using namespace std ;

typedef long long ll ;
typedef long double ldb ;

typedef pair<int, int> pii ;
typedef pair<int, ll> pil ;
typedef pair<ll,ll> pll ;

typedef vector<int> vi ;
typedef vector<ll> vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl ;
typedef vector<bool> vb ;
typedef vector<pair<ll,int> > vpli ;
typedef vector<int,pil> edges ;
typedef vector<vi> matrix ;
typedef priority_queue<int> pqu ;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

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

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define ins insert
#define bk back
#define con continue
#define lbd lower_bound
#define ubd upper_bound

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

#define pr cout << // I don't like this but my laptop's 'O' key is not functioning well

/* Careful when using long long
__builtin_clz(int x) {} //: the number of zeros at the beginning of the number
__builtin_ctz(int x) {} //: the number of zeros at the end of the number
__builtin_popcount(int x) {} //: the number of ones in the number
__builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */

const int mod1 = 1000000007 ;
const int mod2 = 998244353 ;
const ll  infl = 4e18 ;
const int infi = 2e9 ;
const int maxn = 1e6 + 5 ;
const int block = 500 ;
const int logn = 60 ;
const int alpha = 27 ;
const ldb pi = acos(-1) ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
int rng_lr(int a, int b)
{
    int ret ;
    ret = uniform_int_distribution<int>(a, b)(rng) ;
    return ret ;
    // For shuffling use shuffle(all, rng) ;
}

ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; }
void upmin(int &a, int b) { if(a < b) { a = b ; } }
void relax(int &a, int b) { if(a > b) { a = b ; } }
ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return  a ; }
ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; }
ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; }
ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; }
ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; }
int icast(char ch) { return int(ch-'a') ; }
void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; }
void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; }

// Check constraints + overflows + types in typedef

int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    int n ;
    cin >> n ;
    vi a(n) ;
    rep(i,0,n-1) {
        cin >> a[i] ;
    }
    vector<ldb> b(n) ;
    rep(i,0,n-1) {
        b[i] = ((ldb)a[i])/((ldb)2) ;
    }
    sort(all(b)) ;
    ldb x = b[(n-1)/2] ;
    //pr x << "\n" ;
    ldb ev = ldb(0) ;
    rep(i,0,n-1) {
        ldb loss = x + (ldb)a[i] - min((ldb)a[i], ((ldb)2)*x) ;
       // pr loss << "\n" ;
        ldb contri = ((ldb)loss)/((ldb)n) ;
        ev = ev + contri ;
    }
    pr fixed << " " << setprecision(10) ;
    pr ev << "\n" ;

    return 0 ;
}


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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // int64_t
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define REP(i,m,n) for(int i = m; i <= (n); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

const int INF = 1e9+7;   //10oku7

ll mod_pow(ll x , ll y , ll m){
  if (y == 0) return 1;
  if (y == 1) return x % m;
  ll rep = mod_pow(x, y/2, m) * mod_pow(x, y/2, m);
  if (y % 2 == 1 ) rep *= (x % m);
  rep %= m;
  return rep;
}

ll circ(ll x , ll y){
  ll res = mod_pow(x , y ,4);
  if (res == 0 ) res = 4;
  return res;
}

int main() {

  ll A,B,C;
  cin >> A >> B >> C;
  A %= 10;
  ll ans = mod_pow( A , circ(B,C) ,10);

//  cout << circ (B,C) << endl;
//  cout << mod_pow(A,B, 10) << endl;
  cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;
#define ls o<<1
#define rs o<<1|1
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

void solve(){
	int a,b;
    scanf("%d%d",&a,&b);
    double ans=a/100.0*b;
    printf("%lf\n",ans);
}
int main(){
    clock_t t1=clock();
	#ifndef ONLINE_JUDGE
        freopen("in.in", "r", stdin);
        freopen("out.out","w",stdout);
    #endif
	// int T;scanf("%d",&T);while(T--)
	solve();
end:
    cerr<<"Time used "<<clock()-t1<<" ms"<<endl;
	return 0;
}

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


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize ("-O3")
#define int long long
#define ld long double
#define endl "\n"

#define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end))
#define umap unordered_map
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define w(t) int t; cin>>t; rep(tc,0,t)
#define clr(a,x) memset(a,x,sizeof a)

#define chkbit(x,i) ((x)&(1LL<<(i)))
#define setbit(x,i) ((x)|(1LL<<(i)))
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int mod = 1e9+7;
const int mod2 = 998244353;
const int N = 2e6;
const int inf = 1e18;
const ld PI = 3.141592653589793;

//=====================================================

template<typename... T>
void in(T&... args) {((cin>>args), ...);}
template<typename... T>
void out(T&&... args) {((cout<<args<<" "), ...);}
template<typename... T>
void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;}

int nxt(){int x;cin>>x;return x;}
int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
int range(int x,int y,int z) {return (x >= y && x <= z);}

struct customCompare {
    bool operator () (int x, int y) {
        return x>y;
    }
};

//=====================================================

int ModExp(int x, int y, int m){
    int res = 1;
    while (y > 0) {
        if (y & 1) res = (res*x) % m;
        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

int calc(int n) {
    if (n <= 1)
        return 1;
    int x = 1, y = 1;
    for (int i = 2; i <= n; i++) {
        int tmp = (x+y)%mod;
        x = y;
        y = tmp;
    }
    return y;
}

void solve() {

    int n = nxt();
    char aa, ab, ba, bb;
    cin >> aa >> ab >> ba >> bb;

    int ans;
    if (n <= 2)
        ans = 1;
    else if (ab == 'A' && aa == 'A')
        ans = 1;
    else if (ab == 'B' && bb == 'B')
        ans = 1;
    else if (ab == 'A' && aa == 'B' && ba == 'A')
        ans = calc(n-2);
    else if (ab == 'B' && bb == 'A' && ba == 'B')
        ans = calc(n-2);
    else
        ans = ModExp(2, n-3, mod);

    cout << ans << endl;
}

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

    solve();

    return 0;
}

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

ll xorr[1200020];
ll a[300005];

int query(int at, int L, int R, int l, int r){
    if(L>r || R<l)return 0;

    if(l<=L and r>=R)return xorr[at];

    int mid = (L+R)/2;

    return query(at*2,L,mid,l,r)^query(at*2+1,mid+1,R,l,r);
}

void update(int at, int L, int R, int pos, ll u ){
    if(L>pos || R<pos)return ;

    if(L==R){
        xorr[at]^=u;
        return ;
    }

    int mid = (L+R)/2;
    update(at*2,L,mid,pos,u);
    update(at*2+1,mid+1,R,pos,u);
    xorr[at] = xorr[at*2]^xorr[at*2+1];
}

ll build(int at , int L, int R){

    if(L==R){
        xorr[at]=a[L];
        return xorr[at];
    }
    int mid = (L+R)/2;
    ll u = build(at*2,L,mid);
    ll v = build(at*2+1,mid+1,R);

    xorr[at] = u^v;
    return xorr[at];
}

int main(){

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

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

    build(1,1,n);

    for(int i=0;i<q;i++){
        int type ;
        cin>>type;

        if(type==1){
            int x,y;
            cin>>x>>y;
            update(1,1,n,x,y);
        }
        else{
            int L,R;
            cin>>L>>R;
            cout<<query(1,1,n,L,R)<<"\n";
        }
    }

}


using namespace std;
#include<bits/stdc++.h>
void testcases()
{
int n,time,pow;
cin>>n>>time>>pow;
int f=0;
while(n>0)
{
	int temp1,temp2;
cin>>temp1>>temp2;
if(temp1<time &&  temp2>pow)
f=1;
n-=1;
}
cout<<((f==1)?"Yes":"No")<<endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
/*int t;
cin>>t;
while(t--)*/
testcases();
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair

int main(){
    ll t; cin >> t;
    vll ans(0);
    rep(i, 0, t){
        ll l, r;
        cin >> l >> r;

        if(r-2*l+2<=0 || r-2*l+1<=0){
            ans.pb(0);
            continue;
        }
        ans.pb((r-2*l+2)*(r-2*l+1)/2);
    }

    rep(i, 0, ans.size()){
        cout << ans[i] << endl;
    }
}


//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N=101000;
const int inf=1e9+7;
inline long long read(void)
{
	char ch=getchar();long long sum=0;bool f=0;
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-'){f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	if(f)sum=-sum;return sum;
}
int n;
string st;
int opt[N];
long long DP[N][2];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		cin>>st;
		if(st[0]=='O')opt[i]=1;
		else opt[i]=2;
	}
	DP[0][1]=DP[0][0]=1;
	for(int i=1;i<=n;i++){
		if(opt[i]==1){
			DP[i][0]+=DP[i-1][0];
			DP[i][1]+=(DP[i-1][0]+DP[i-1][1]*2);
		}
		else {
			DP[i][0]+=DP[i-1][0]*2+DP[i-1][1];
			DP[i][1]+=DP[i-1][1];
		}
	}
	cout<<DP[n][1];return 0;
}

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

int main() {
 ll n;
  cin >> n;
  string s;
  ll t = 1;
  ll f = 1;
  for(ll i = 0;i < n;i++){
    cin >> s;
    if(s == "AND"){
      f = f*2+t;
    } else {
      t = t*2+f;
    }
  }
    cout << t << endl;

}


#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define chmax(a,b) if (a<b)a=b;
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL;
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}

ll n,x;

int main(){
  ll ans=llMAX;
  cin >> n >> x;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];

  for(ll maini=1;maini<=n;maini++){

        vvi data(100, vi(maini,-1));  // N * M の2次元配列 N-1個つかって余りがMのやつを保存
        for(ll iii=0;iii<n;iii++){
          ll ta=a[iii];
          for(ll i=iii-1;i>=0;i--){
            for(ll j=0;j<maini;j++){
              if (data[i][j]==-1)continue;
              chmax(data[i+1][(j+ta)%maini],data[i][j]+ta)
            }
          }
          chmax(data[0][ta%maini],ta)
        }

        ll ax=x%maini;
        ll syokiti=data[maini-1][ax];
        if (syokiti==-1)continue;
        ans=min((x-syokiti)/maini,ans);
  }

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

/*
10 22000
10 20 30 40 50 60 70 80 90 100
*/

#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
enum { ROW, COL };
int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H); for (auto &s : S) cin >> s;
    vector<int> rows(H), cols(W);
    vector<vector<int>> rows_floor(H), cols_floor(W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                rows_floor[i].push_back(j);
                cols_floor[j].push_back(i);
            }
        }
    }
    int nrow = H, ncol = W;
    auto rec = [&](auto&& rec, int type, int idx) -> void {
        if (type == ROW) {
            if (rows[idx]) return;
            rows[idx] = 1;
            nrow--;
            for (auto t : rows_floor[idx]) rec(rec, COL, t);
        } else {
            if (cols[idx]) return;
            cols[idx] = 1;
            ncol--;
            for (auto t : cols_floor[idx]) rec(rec, ROW, t);
        }
    };
    rec(rec, ROW, 0);
    rec(rec, ROW, H - 1);
    rec(rec, COL, 0);
    rec(rec, COL, W - 1);
    int ans = 0;
    for (int i = 0; i < H; i++) {
        if (!rows[i] && !rows_floor[i].empty()) {
            ans++;
            rec(rec, ROW, i);
        }
    }
    for (int i = 0; i < W; i++) {
        if (!cols[i] && !cols_floor[i].empty()) {
            ans++;
            rec(rec, COL, i);
        }
    }
    ans += min(nrow, ncol);
    cout << ans << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int in(){
    int x;
    scanf("%d",&x);
    return x;
}
char janken(char c1,char c2){
    if(c1>c2)swap(c1,c2);
    if(c1==c2)return c1;
    if(c1=='P' && c2=='R')return 'P';
    if(c1=='P' && c2=='S')return 'S';
    if(c1=='R' && c2=='S')return 'R';
}
int main(){
    int n=in(),k=in();
    string s;
    cin>>s;
    vector<int>v;
    int p=1;
    for(int i=0;i<=k;i++){
        v.push_back(p/n);
        p%=n;
        if(i<k)p*=2;
    }
    reverse(v.begin(),v.end());
    while(v.size() && v.back()==0)v.pop_back();
    int vs=v.size();
    string amari;
    for(int i=0;i<p;i++)amari.push_back(s[i]);
    for(int i=0;i<vs-1;i++){
        s+=s;
        if(v[i])amari=s+amari;
        string new_s,new_amari;
        for(int i=0;i<s.size()-1;i+=2)new_s.push_back(janken(s[i],s[i+1]));
        for(int i=0;i<(int)amari.size()-1;i+=2)new_amari.push_back(janken(amari[i],amari[i+1]));
        s=new_s;
        amari=new_amari;
    }
    if(vs)s=s+amari;
    else s=amari;
    int ss=s.size();
    vector<char>ans(ss*2);
    for(int i=0;i<ss;i++)ans[ss+i]=s[i];
    for(int i=ss-1;i;i--)ans[i]=janken(ans[i*2],ans[i*2+1]);
    cout<<ans[1]<<endl;
    return 0;
}

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

#define ll long long int
#define pii pair<ll,ll>
#define rep(i,st,en) for(ll i=st;i<en;i++)
#define repdown(i,st,en) for(ll i=st;en<i;i--)
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vii vector<pii>
#define vp vector<pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define eb emplace_back
#define PI 3.14159265358979323846
#define ans(A) cout<<A<<endl;
#define ANS(A) cout<<A;
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define resz(A,N) A.resize(N);
#define vsortup(v) sort(all(v)) //1,2,3,4,5
#define vsortdown(v) sort(rall(v)) //5,4,3,2,1

vll enm_div(ll n); //約数リスト出力

int main()
{
    ll T;
    cin >> T;
    vll cs; resz(cs,T);
    ll odc=0,evc=0;
    rep(i,0,T)
        cin >> cs[i];
        // vll divlst = enm_div(cs[i]);
        // rep(j,0,divlst.size()){
        //     if (divlst[i]%2==0)//偶数
        //         evc++;
        //     else
        //         odc++;
        // }
    rep(i,0,T){
        if (cs[i]%4==0){
            ans("Even")
        }
        else{
            if (cs[i]%2==0){
                ans("Same");
            }
            else{
                ans("Odd")
            }
        }
    }

    return 0;
}
vll enm_div(ll n)
{
    vll prms;
    for (ll i = 1; i*i <= n; i++)
        if (n%i==0){
            prms.push_back(i);
            if (i != n/i)
                prms.push_back(n/i);
        }
    if (prms.size()==0)
        resz(prms,1);

    vsortup(prms);
    return prms;
}


#include <bits/stdc++.h>

#define DEBUG(C) cerr << #C << " = " << C << endl;

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

void solve() {
    const int MAX = 2e5 + 10;
    int N;
    long long W;
    cin >> N >> W;
    vector<long long> v(MAX);
    for (int i = 0; i < N; ++i) {
        int s, t;
        long long p;
        cin >> s >> t >> p;
        v[s] += p;
        v[t] -= p;
    }
    for (int i = 0; i < MAX - 1; ++i) {
        v[i + 1] += v[i];
    }

    const auto ma = *max_element(begin(v), end(v));
    puts(ma <= W ? "Yes" : "No");
}

int main(void) {
#ifndef ONLINE_JUDGE
    const auto in_stream = freopen("../in.txt", "r", stdin);
    if (in_stream == nullptr) {
        cerr << "ERROR!" << endl;
        return 1;
    }
#endif

    solve();

#ifndef ONLINE_JUDGE
    fclose(in_stream);
#endif
}

#pragma GCC optimize("Ofast")
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Po = pair<double, double>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MP make_pair
#define SZ(x) ll(x.size())
#define ALL(x) x.begin(),x.end()
#define NIL -1
#define INF 1ll<<63-1
//#define MOD 1000000007
#define PI 3.14159265358979323846
#define endl "\n"
#define EPS 1e-9
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

template <class T, class U>
bool chmin(T& t, const U& u) {
	if (t > u) {
		t = u;
		return true;
	}
	else return false;
}
template <class T, class U>
bool chmax(T& t, const U& u) {
	if (t < u) {
		t = u;
		return true;
	}
	else return false;
}

bool YN(bool b) {
    if (b) {
        Yes;
        return true;
    }
    else {
        No;
        return false;
    }
}

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

template <unsigned int MOD>
struct ModInt {
    using uint = unsigned int;
    using ull = unsigned long long;
    using M = ModInt;

    uint v;

    ModInt(ll _v = 0) { set_norm(_v % MOD + MOD); }
    M& set_norm(uint _v) {  //[0, MOD * 2)->[0, MOD)
        v = (_v < MOD) ? _v : _v - MOD;
        return *this;
    }

    explicit operator bool() const { return v != 0; }
    M operator+(const M& a) const { return M().set_norm(v + a.v); }
    M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }
    M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); }
    M operator/(const M& a) const { return *this * a.inv(); }
    M& operator+=(const M& a) { return *this = *this + a; }
    M& operator-=(const M& a) { return *this = *this - a; }
    M& operator*=(const M& a) { return *this = *this * a; }
    M& operator/=(const M& a) { return *this = *this / a; }
    M operator-() const { return M() - *this; }
    M& operator++(int) { return *this = *this + 1; }
    M& operator--(int) { return *this = *this - 1; }

    M pow(ll n) const {
        if (n < 0) return inv().pow(-n);
        M x = *this, res = 1;
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    M inv() const {
        ll a = v, b = MOD, p = 1, q = 0, t;
        while (b != 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(p -= t * q, q);
        }
        return M(p);
    }

    bool operator==(const M& a) const { return v == a.v; }
    bool operator!=(const M& a) const { return v != a.v; }
    friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }
    static uint get_mod() { return MOD; }
};

using Mint = ModInt<998244353>;

signed main() {
    cout << fixed << setprecision(15);

    ll n, w; cin >> n >> w;
    V<ll> a(200100,0);
    REP(i, n) {
        ll s, t, p; cin >> s >> t >> p;
        a[s] += p;
        a[t] -= p;
    }
    REP(i, 200010) {
        a[i+1] += a[i];
        if (a[i] > w) {
            No;
            return 0;
        }
    }
    Yes;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(ll x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	template <typename U>
	explicit operator U() const { return (U)val; }
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
	friend string to_string(const Mint& b) { return to_string(b.val); }
};
int main() {
	int n;
	scanf("%d", &n);
	vector<int> A(n);
	for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
	sort(A.begin(), A.end());
	int pre = 0;
	Mint ans = 1;
	for (int i = 0; i < n; ++i) {
		ans *= A[i] - pre + 1;
		pre = A[i];
	}
	printf("%d\n", ans.val);
}

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

int main() {
	int n;
	ll m,ans;

	cin >> n;
	rep(i,n) cin >> a[i];
	if (n==1){
		cout << a[0]+1 << endl;
		return 0;
	}
	sort(a, a+n); //a[0:n] を値が小さい順にソート
	ans=a[0]+1;
	m=1000000007;
	rep(i,n-1){
		ans*=(a[i+1]-a[i]+1);
		ans%=m;
	}
	cout << ans << endl;
	return 0;
}


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

#define For(i,n) for(int i = 0; i < n; i++)
#define For1(i,n) for(int i = 1; i < n; i++)
#define Forn(i,n) for(int i = n-1; i >=0 ; i--)
#define FOR(i,f,n) for(int i = f; i < n; i++)
#define FORN(i,n,f) for(int i = n; i >= f; i--)
#define Forit(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define sz size()
#define dbg(a) For(i,a.sz){cout<<a[i]<<' ';}cout<<'\n';
#define Sort(a) sort(a.begin(), a.end());
#define Rev(a) reverse(a.begin(), a.end());
typedef long long int ll;
typedef pair<ll, ll> pl;
typedef pair<int,int> pi;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pl> vpl;
typedef vector<pi> vpi;
typedef vector<vll> vvll;
const int mod = 1e9+7;
const int NF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll gcd(ll a, ll b){
    while( a!=0 and b!=0 )
    {
        if( a >= b ) a = a%b;
        else if( b > a ) b = b%a;
    }

    if( a >= b ) return a;
    else return b;

}

//FastExpo
ll fast_pow(ll base, ll p){
    ll a =1;
    while(p>0){
        if(p%2==0){
            p /=2;
            base *=base;
        }
        else{
            p --;
            a = a * 1LL * base;
        }
        a %= mod;
        base %=mod;
    }
    return a;
}

ll t,n,m,k,idx,ct1,ct0;

void solve() {
    cin>>n;
    vll a(n,0);
    map<ll, ll> ct;
    ll tmp = 0, res = 0;
    //    vll T;
    For(i,n){
        cin>>a[i];
        if(i%2){tmp+=a[i];}
        else{tmp -= a[i];}
        if(tmp == 0){res++;}
        ll tm = ct[tmp];
        if(tm>=1 && i!=0){
            res+=tm;
        }
        ct[tmp]++;
    }
    //    dbg(T);
    cout<<res<<'\n';
}

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

    //    cin >> t;

    //    k = t;
    t = 1;
    while (t--) {
        //        cout<<"Case #"<<k-t<<": ";
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_

typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...)                                                          \
DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
        << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
        << endl                                                            \
        << "    ",                                                         \
    dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

//////////

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

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll N;
    cin>>N;

    vector<pairl> A(N);
    vecl B(N), P(N);

    vecl holder(N); // holder[i]: 荷物iを持ってる人
    rep(i,N) cin>>A[i].first, A[i].second = i;
    rep(i,N) cin>>B[i];
    rep(i,N) cin>>P[i], holder[--P[i]] = i; // P[i]: 人iが持ってる荷物

    sort(ALL(A));
    rep(i,N) {
        auto [a,j] = A[i];
        ll item = P[j];
        if (item != j && a <= B[item]) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<pairl> ans;
    rep(i,N) {
        auto [a,ii] = A[i]; // 人: ii
        ll p = holder[ii]; // 荷物iiをもつ人: p
        if (ii == p) continue;

        swap(holder[ii], holder[P[ii]]);
        swap(P[ii],P[p]);
        ans.emplace_back(ii, p);
    }

    cout << sz(ans) << endl;
    rep(i,sz(ans)) {
        auto [x,y] = ans[i];
        cout << ++x << " " << ++y << endl;
    }

    return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define int long long int

void solve(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << n - a + b << nl;
    return ;
}
main()
{
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
	int T = 1;
    // cin >> T;
    fo(c, 1, T){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[3];
signed main(){
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[2]+a[1]<<endl;
	return 0;
}


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FCoprimePresent {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a, b; cin >> a >> b;
      vector<int> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
                           31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

      int t = 1<<20;
      vector<ll> dp(t);
      dp[0] = 1;

      for(ll i=a; i<=b; i++) {
        int now = 0;
        rep(j, 20) {
          if (i%prime[j] == 0) {
            now += (1<<j);
          }
        }
        auto dp2 = dp;
        rep(j, t) {
          if ((j&now)==0) {
            dp2[j|now] += dp[j];
          }
        }
        swap(dp, dp2);
      }
      ll ret = 0;
      rep(i, t) {
        ret += dp[i];
      }
      cout << ret << endl;
    }
};

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

#include<iostream>
using namespace std;

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


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

void solve() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    queue<int> one;
    rep(i, n) {
        if (s[i] == '1') one.push(i);
    }
    ll ans = 0; // int だと桁が足りない
                // e.g. s = 0...01...1 (0が250000, 1が250000), t = 1...10...0 (1が250000, 0が250000)
                // のとき答えは 250000^2 > 2^31
    rep(i, n) {
        if (s[i] == t[i]) continue;
        while (!one.empty() && i >= one.front()) {
            one.pop();
        }
        if (!one.empty()) {
            int j = one.front();
            one.pop();
            ans += j - i;
            s[j] = '0';
        } else {
            puts("-1");
            return;
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define ve vector<ll>
#define w(t) ll t; cin >> t; while(t--)

using namespace std;

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

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

    if (a == b)
        cout << c;
    else if (a == c)
        cout << b;
    else if (c == b)
        cout << a;
    else
        cout << 0;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e5+5;
const ll inf=1e17;

ll dis[100][100];

int main()
{
    idfc;

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

    vector<int> vv;
    int i;int j;
    for(i=2;i<=n;i++)vv.pb(i);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)cin>>dis[i][j];
    }
    int ans=0;
    int tot=0;
    do{
       // cout<<"sdsd"<<endl;
        ans=0;
        int pr=1;
        for(i=0;i<n-1;i++)
        {
            ans+=(dis[pr][vv[i]]);
            pr=vv[i];
        }
        ans+=dis[pr][1];
        if(ans==k)tot++;
    }
    while(next_permutation(vv.begin(),vv.end()));
    cout<<tot;
    return 0;
}

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
//ctrl+end - to break infinite loop in sublime text

#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
using namespace std;
#define Fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr)
#define ll long long int
#define fo(i, a, b) for (long long int i = a; i <= b; i++)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<long long int>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e9+7;
const ll mod = 1e9+7;
#define MAX 300005

void call_priyanshu(){
    Fio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt", "w", stdout);
        //freopen("error.txt","w",stderr);
    #endif
}

ll mini(ll a,ll b){
    if(a>=b)return b;
    return a;
}

ll maxi(ll a,ll b){
    if(a>=b)return a;
    return b;
}

bool cmp(pair<ll,string> a,pair<ll,string> b){
    return a.fi>b.fi;
}

void solve(){
    //write your code here
    ll n;
    cin>>n;
    vector<pair<ll,string>>A;
    fo(i,1,n){
        string s;
        ll h;
        cin>>s>>h;
        A.pb(mp(h,s));
    }
    sort(all(A),cmp);
    cout<<A[1].se;
}

int main(){
    call_priyanshu();
    // w(t){
        solve();
    // }
    return 0;
}


#include <bits/stdc++.h>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//#define pi 3.14159265358979
#define ss string
#define db double
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define ci(x) cin >> (x)
#define cii(x) int (x);cin >> (x)
#define cci(x,y) int (x),(y);cin >> (x) >>(y)
#define co(x) cout << (x) << endl

int main(){
  cci(h,w);
  vvi v(h+1,vi(w+1,0));
  rep(i,0,h){
    rep(j,0,w){
      char c;ci(c);
      if(c=='.')v[i][j]=1;
    }
  }
  int ans=0;
  rep(i,0,h){
    rep(j,0,w){
      ans+=(v[i][j+1]&v[i][j])+(v[i+1][j]&v[i][j]);
    }
  }
  co(ans);
}

#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define double long double
#define MAX 2000010
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = INF;
ll modulo = pow(10,9)+7;

struct Segtree{			// !!! 1 based indexing !!!

	struct node{
		ll l , r, val, tagval;
		bool tag;
		node(){}
		node(ll l, ll r) : l(l), r(r){}
		void integrate(){
			val += tagval;
		}
		node operator+(node other){
			node toret = node(l, other.r);
			toret.val = min(val, other.val);
			return toret;
		}
		void operator+=(node& other){	//  merge 2 tag (existing tag, new tag) values
			// merge other's "tagval" to our "tagval" only !!!! otherwise need modification
			tagval += other.tagval;
		}
		void operator*=(node& other){	//  merge node value to query value
			// merge other's "val" to our "val" only !!!! otherwise need modification
			val = min(val, other.val);
		}
	};

	node* lazy = new node[MAX];
	void init(ll num, ll l , ll r){
		if(l==r){
			lazy[num] = node ( l, r);
			lazy[num].val = (l + 1);
			//  initialize values if needed
			return;
		}
		init((num<<1), l, (l+r)/2), init((num<<1)|1, (l+r)/2+1, r);
		lazy[num] = lazy[num<<1] + lazy[(num<<1)|1];
	}

	void pull(ll num){
		lazy[num] = lazy[num<<1] + lazy[(num<<1)|1];
	}

	void push(ll num){
		lazy[num].integrate();
		lazy[num].tag = 0;
		if(lazy[num].l != lazy[num].r){
			lazy[(num<<1)].tag = lazy[(num<<1)|1].tag = 1;
			lazy[(num<<1)] += lazy[num], lazy[(num<<1)|1]+=lazy[num];
		}
		lazy[num].tagval = 0;
	}

	void upd(ll num, node& b){
		if(lazy[num].tag)
			push(num);
		if(lazy[num].l > b.r || lazy[num].r < b.l)
			return;
		if(lazy[num].l >= b.l && lazy[num].r<=b.r){
			lazy[num] += b;
			push(num);
			return;
		}
		upd(num<<1, b),		upd((num<<1)|1, b);
		pull(num);
	}

	void que(ll num, node& b){
		if(lazy[num].l > b.r || lazy[num].r < b.l)		return ;
		if(lazy[num].tag)								push(num);
		if(lazy[num].l >= b.l && lazy[num].r<=b.r){		b *= lazy[num]; return; }
		que(num<<1, b) , que((num<<1)|1, b);
	}

	~Segtree(){ delete[] lazy; }
};

bool J(pair<ll,ll>& a, pair<ll,ll>& b){
	return a > b;
}

void deal(){
	Segtree lz;

	ll n;
	cin>>n;
	lz.init(1, 0, n-1);

	vector<pair<ll,ll> > arr;

	fori(2*n){
		ll ed;
		cin>>ed;
		arr.pb(mp(ed, i));
	}

	sort(arr.begin(), arr.end(), J);

	ll s = 0;

	fori(2*n){
		ll id = arr[i].ss;
		if(id >= n){
			id = id - n ;
		}
		else{
			id = n-1 - id;
		}
		Segtree::node que(id, n-1);
		que.val = inf;
		lz.que(1, que);
		if(que.val >= 1){
			s+=arr[i].ff;
			Segtree::node upd(id, n-1);
			upd.tagval = -1;
			lz.upd(1, upd);
		}
	}

	cout<<s;

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


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

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

    int n,x;
    string s;

    cin>>n>>x;
    cin.ignore();
    getline(cin,s);

    for(int i=0;i<n;i++){
        if(x==0){
            if(s[i]=='o'){
                x=x+1;
            }
        }
        else{
            if(s[i]=='o'){
                x=x+1;
            }
            else{
                x=x-1;
            }

        }
    }
    cout<<x;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;

int main(){
	int n, x;
	string s;
	cin >> n >> x;
	cin >> s;
	for(auto i : s){
		if(i == 'o')
			x++;
		else if(x)
			x--;
	}
	cout << x << endl;
	return 0;
}


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double TIME_LIMIT = 1.8;
const int N = 50;
double PROB_REAL = 0.1;

vector<int> di = {1, -1, 0, 0};
vector<int> dj = {0, 0, 1, -1};
vector<char> vc = {'D', 'U', 'R', 'L'};

map<char, pair<int, int>> mp;

int si0, sj0, si1, sj1;
vector<vector<ll>> t, p;
ld final_score;

//状態
struct STATE {
	// 既に訪れたかどうか
	vector<vector<int>> visited = vector<vector<int>>(N, vector<int>(N, 0));

	// タイルの番号とそれに対応する点のベクター(要素は1か2)
	map<int, vector<pair<int, int>>> mp_tile;

	// 道のり
	deque<char> paths;
};

// 状態の初期化
void init (STATE& state) {
	cin >> si0 >> sj0;
	t = vector<vector<ll>>(N, vector<ll>(N));
	p = vector<vector<ll>>(N, vector<ll>(N));
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			cin >> t[i][j];
			state.mp_tile[t[i][j]].push_back(make_pair(i, j));
		}
	}
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			cin >> p[i][j];
		}
	}
	for (int i=0;i<4;i++) {
		mp[vc[i]] = make_pair(di[i], dj[i]);
	}

	int now_i = si0;
	int now_j = sj0;
	for (auto p : state.mp_tile[t[now_i][now_j]]) {
		state.visited[p.first][p.second] = 1;
	}

    double start_time = static_cast<double>(clock())/CLOCKS_PER_SEC; // 開始時刻
    while (true) { // 時間の許す限り回す
        double now_time = static_cast<double>(clock())/CLOCKS_PER_SEC; // 現在時刻
        double time_diff = now_time-start_time;
        if (time_diff > TIME_LIMIT) break;

		bool changed = false;
		int c = uniform_int_distribution<int>(0, 3)(rng);
		int next_i = now_i+di[c];
		int next_j = now_j+dj[c];
		if (0 <= next_i && next_i < N && 0 <= next_j && next_j < N) {
			if (state.visited[next_i][next_j] == 0) {
				changed = true;
				state.paths.push_back(vc[c]);
				for (auto p : state.mp_tile[t[next_i][next_j]]) {
					state.visited[p.first][p.second] = 1;
				}
				now_i = next_i;
				now_j = next_j;
			}
		}

		if (!changed) {
        	double rand_real = uniform_real_distribution<double>(0.0, 1.0)(rng);
			if (!state.paths.empty() && rand_real < PROB_REAL) {
				char rem_c = state.paths.back();
				state.paths.pop_back();
				for (auto p : state.mp_tile[t[now_i][now_j]]) {
					state.visited[p.first][p.second] = 0;
				}
				now_i -= mp[rem_c].first;
				now_j -= mp[rem_c].second;
			}
		}
	}
}

// 状態遷移
void modify (STATE& state) {
}

// 状態のスコア計算
ld calc_score (STATE& state) {
}

// 山登り法
void mountain() {
    STATE state;
    init(state);

	while (!state.paths.empty()) {
		cout << state.paths.front();
		state.paths.pop_front();
	}
	cout << "\n";
}

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

	mountain();
	return 0;
}

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

ll T[50][50];
bool B[50][50];
ll P[50][50];
ll D[50][50];
char *ans;
char *W;
ll score=0;
ll high=0;
ll dx[]={0, 1, 0, -1};
ll dy[]={-1, 0, 1, 0};
char dc[]={'U', 'R', 'D', 'L'};
bool all_fin;
bool fin;
clock_t start;
clock_t start_m;
ll loop;

void steped(ll y, ll x, bool b){
  ll d=D[y][x];
  if (d){
    --d;
    ll ny=y+dy[d];
    ll nx=x+dx[d];
    B[ny][nx]=b;
  }
  B[y][x] = b;
}

// 行き止まりになったら、その時点でのstringを出力
void dfs(ll y, ll x, ll c){// {y, x, 歩数}
  bool used[4]={};
  rep(i, 4){
    clock_t now = clock();
    if(now-start_m>TIMEOVER_M) fin=true;
    if(now-start>TIMEOVER) all_fin=true;
    ll r=now%4;
    while(used[r]) (r+=1)%=4;
    used[r]=true;
    ll ny=y+dy[r];
    ll nx=x+dx[r];
//    cout << "time:" << now-start << endl;
    if(ny<0 || nx<0 || ny>49 || nx>49 || B[ny][nx] || fin || all_fin){
      if(chmax(high, score)){
        if(ans) free(ans);
        ans=strdup(W);
      }
    }
    else{
      //反映
      score+=P[ny][nx];
      W[c]=dc[r];
      steped(ny, nx, true);

      dfs(ny, nx, c+1);
      //復元
      score-=P[ny][nx];
      W[c]='\0';
      steped(ny, nx, false);
    }
  }

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  W=(char*)calloc(2000, 1);
  start = clock();
  ll si, sj;
  cin >> si >> sj;
  rep(i, 50) rep(j, 50) cin >> T[i][j];
  rep(i, 50) rep(j, 50) cin >> P[i][j];
  // タイルの方向D
  rep(i, 50) rep(j, 50){
    rep(k, 4){
      ll ny=i+dy[k];
      ll nx=j+dx[k];
      if(ny<0 || nx<0 || ny>49 || nx>49) continue;
      if(T[i][j]==T[ny][nx]) D[i][j]=k+1;
    }
  }
  while(!all_fin){
    loop++;
    fin=false;
    start_m = clock();
    score = P[si][sj];
    chmax(high, score);
    rep(y, 50) rep(x, 50) B[y][x]=false;
    rep(i, 2000) W[i]='\0';
    steped(si, sj, true);
    dfs(si, sj, 0);
  }
//  cout << high << " " << loop << endl;
  printf("%s\n", ans);
}