/**
*    created: 01.07.2020 15:47:43
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

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

    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i,n) {
        cin >> a[i];
        if (i != 0) sum += abs(a[i] - a[i-1]);
    }
    sum += abs(a[0]);
    sum += abs(a[n-1]);
    rep(i,n) {
        if (i == 0) cout << sum - (abs(a[0]) + abs(a[1] - a[0])) + abs(a[1]) << endl;
        else if (i == n-1) cout << sum - (abs(a[n-1] - a[n-2]) + abs(a[n-1])) + abs(a[n-2]) << endl;
        else cout << sum - (abs(a[i]-a[i-1]) + abs(a[i+1]-a[i])) + abs(a[i+1]-a[i-1]) << endl;;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  for(int i=1;i<=n;i++)
    cin>>a.at(i);
  vector<int> d(n+1);
  int s=0;
  for(int i=0;i<n;i++){
    d.at(i)=abs(a.at(i+1)-a.at(i));
    s+=d.at(i);
  }
  d.at(n)=abs(a.at(n));
  s+=d.at(n);
  for(int i=1;i<=n;i++){
    if(min({a.at(i-1),a.at(i),a.at((i+1)%(n+1))})==a.at(i)||max({a.at(i-1),a.at(i),a.at((i+1)%(n+1))})==a.at(i))
      cout<<s-2*min(d.at(i-1),d.at(i))<<endl;
    else
      cout<<s<<endl;
  }
}


#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;

int main() {
	int n; cin >> n;
	vector<P> a(n);
	rep(i, 0, n) cin >> a[i].first >> a[i].second;
	rep(i, 0, n) {
		int idx = 0;
		double b[201];
		rep(j, 0, n) {
			if (i == j) continue;
			b[idx++] = atan2(a[j].second - a[i].second, a[j].first - a[i].first);
		}
		sort(b, b + idx);
		rep(j, 0, idx) b[j + idx] = b[j] + 2 * M_PI;
		double ans = 0;
		rep(j, 0, idx) ans = max(ans, M_PI - b[j + idx - 1] + b[j]);
		printf("%.12f\n", ans/2/M_PI);
	}
	return 0;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

pair <long long, long long> xy[100];
long long x[100];
long long y[100];
vector <pair <long long, long long> > c_hull;

template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
    return {l.first+r.first,l.second+r.second};
}
template <typename T,typename U>
std::pair<T,U> operator-(const std::pair<T,U> & l,const std::pair<T,U> & r) {
    return {l.first-r.first,l.second-r.second};
}

long long cross(pair <long long, long long> xy1, pair <long long, long long> xy2){
    return xy1.first * xy2.second - xy1.second * xy2.first;
}

long long dot(pair <long long, long long> xy1, pair <long long, long long> xy2){
    return xy1.first * xy2.first + xy1.second * xy2.second;
}

double norm(pair <long long, long long> xy){
    return sqrt((double)(xy.first * xy.first) + (double) (xy.second * xy.second));
}

void convex_hull(int N){
    sort(xy, xy + N);

    int k = 0;
    c_hull.resize(2 * N);
    for(int i = 0; i < N; i++){
        while(k > 1 && cross(c_hull[k - 1] - c_hull[k - 2], xy[i] - c_hull[k - 1]) <= 0){
            k--;
        }
        c_hull[k] = xy[i];
        k++;
    }
    int lower_half = k;
    for(int i = N - 2; i >= 0; i--){
        while(k > lower_half && cross(c_hull[k - 1] - c_hull[k - 2], xy[i] - c_hull[k - 1]) <= 0){
            k--;
        }
        c_hull[k] = xy[i];
        k++;
    }
    c_hull.resize(k - 1);
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> xy[i].first >> xy[i].second;
        x[i] = xy[i].first;
        y[i] = xy[i].second;
    }

    convex_hull(N);

    map <pair <long long, long long>, double> ans;
    if(c_hull.size() == 2){
        ans[c_hull[0]] = 0.5;
        ans[c_hull[1]] = 0.5;
    } else {
      for(int i = 1; i < c_hull.size() + 1; i++){
        double cos_value = (double) dot(c_hull[i % c_hull.size()] - c_hull[i - 1], c_hull[(i + 1) % c_hull.size()] - c_hull[i % c_hull.size()])
            / norm(c_hull[i % c_hull.size()] - c_hull[i - 1]) / norm(c_hull[(i + 1) % c_hull.size()] - c_hull[i % c_hull.size()]);
        double prob = acos(cos_value) / (2 * M_PI);
        ans[c_hull[i % c_hull.size()]] = prob;
      }
    }

    for(int i = 0; i < N; i++){
        if(ans.find(make_pair(x[i], y[i])) == ans.end()){
            cout << fixed << setprecision(17) << 0.0 << endl;
        } else {
            cout << fixed << setprecision(17) << ans[make_pair(x[i], y[i])] << endl;
        }
    }

    return 0;
}


// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。
vector<pair<long long,long long>> prime_factorize(long long p); // 素因数分解
vector<pair<char, long long>> runLengthEncoding(string s);      // ランレングス圧縮

// class
// ------------------------------------------------
class Combi {
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    map<long long, map<long long, long long>> memo;
    long long n_num;
    long long k_num;
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(long long(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(long long(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

    string s;
    cin >> s;

    if(s.length() != 2){
        reverse(all(s));
    }
    cout << s << endl;

    return 0;

}
// funcの実体
// ------------------------------------------------
int getDigit(int n) {
  int i = 1;
  while(1) {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n) {
  int s = 0;
  while(n) {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str) {
  for(auto itr = str.begin();itr != str.end() ; itr++) {
    if(97 <= *itr && *itr <= 122) {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str) {
  for(auto itr = str.begin();itr != str.end() ; itr++) {
    if(65 <= *itr && *itr <= 90) {
      *itr = *itr + 32;
    }
  }
  return str;
}

Combi::Combi() {
  n_num = -1;
  k_num = -1;
};

ll Combi::Combination(ll n, ll k) {

  ll ret;
  if(memo[n][k] != 0) {
    ret = memo[n][k];
  } else if(n == k || k == 0) {
    memo[n][k] = 1;
    ret = 1;
  } else {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

long long Combi::nPk_modp(long long n, long long k, long long p) {
  ll ans = 1;
  for(long long i = k; i <= n; i++) {
    ans = (ans * i) % p;
  }

  return ans;
};

vector<pair<long long,long long>> prime_factorize(long long p) {
    vector<pair<long long,long long>> ret;

    for(long long x = 2; x * x <= p; ++x) {
        if(p % x != 0) continue;
        long long num = 0;
        while(p % x == 0) {
            num++;
            p /= x;
        }
        ret.push_back(make_pair(x,num));
    }

    if(p != 1) ret.push_back(make_pair(p, 1));

    return ret;
}

vector<pair<char, long long>> runLengthEncoding(string s){
    vector<pair<char, long long>> ret;

    for(long long i = 0; i < s.length(); i++){
        char cur = s[i];
        long long cnt = 0;

    }

    return ret;
}

#include <bits/stdc++.h>

using namespace std;

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

#define int ll

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

	if(s.length()==2){
		cout << s << endl;
	}else{
		cout << s[2] << s[1] << s[0] << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

struct Edge {
    ll to, cost;
    Edge(ll to, ll cost):to(to),cost(cost) {}
};

struct Data {
    ll v, x;  // いまいる頂点v, 進んだ距離x
    Data(ll v, ll x):v(v),x(x) {}
    bool operator<(const Data& hoge) const {
        return x > hoge.x;
    }
};

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

    vector<vector<Edge>> G(n);
    rep(i, n-1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    ll q, sv;
    cin >> q >> sv;
    sv--;

    vl dp(n, INF);
    priority_queue<Data> Q;
    auto push = [&](ll v, ll x) {
        if(dp[v] <= x) {
            return;
        }
        dp[v] = x;
        Q.emplace(v, x);
    };

    // ダイクストラ法。計算量はO((V+E)*log(V))
    push(sv, 0);
    while(!Q.empty()) {
        Data hoge = Q.top();  Q.pop();
        ll v = hoge.v, x = hoge.x;
        if(dp[v] != x) {
            continue;
        }
        for(Edge e : G[v]) {
            push(e.to, x + e.cost);
        }
    }

    rep(i, q) {
        ll x, y;
        cin >> x >> y;
        x--;  y--;
        out(dp[x] + dp[y]);
    }

    re0;
}

/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
 * 考虑边界，推导结论，子问题递归求解

  如果 S <= p[1] 或者 S >= p[n] ，显然所有人投票都是一个方向，不妨假设 p[1] < S < p[n] 。

  考虑处在最边上的 1 号点和 n 号点，如果 a[1] >= a[n] ，那么一定先到 1 ，否则先到 n 。归
纳证明，如果 n = 2 显然成立，对于 n >= 3 ，若 S >= a[n - 1] 显然成立，否则 S < a[n - 1] ，
此时考虑 1 和 n - 1 ，如果先到 n - 1 就会回到 S >= a[n - 1] 的情况。

  不妨假设 a[1] >= a[n] ，那么到 n 的时间就一定是到 1 的时间加上 1 到 n 的距离，那么 n 想
要最小化到达 n 的时间其实就是等价于最小化到达 1 的时间，可以赋值 a[1] = a[1] + a[n] 并赋
值 n = n - 1 转换为子问题，递归求解，可以求出每个点的到达时间。

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

const int maxn = 1000005;
int p[maxn];
ll a[maxn];
ll t[maxn];

void solve (int l, int r, int S) {
	if (S <= p[l]) {
		for (int i = l; i <= r; i ++)
			t[i] = p[i] - S;
		return;
	}
	if (S >= p[r]) {
		for (int i = l; i <= r; i ++)
			t[i] = S - p[i];
		return;
	}
	if (a[l] >= a[r]) {
		a[l] += a[r];
		solve(l, r - 1, S);
		t[r] = t[l] + p[r] - p[l];
	} else {
		a[r] += a[l];
		solve(l + 1, r, S);
		t[l] = t[r] + p[r] - p[l];
	}
}

int main () {
	int n = read, S = read;
	for (int i = 1; i <= n; i ++) read(p[i], a[i]);
	solve(1, n, S);
	ll ans = 0;
	for (int i = 1; i <= n; i ++) ans = std::max(ans, t[i]);
	printf("%lld\n", ans);
}


#include<cstdio>
char s[1000005];
long long sumM[1000005];

long long solve(int n,int k){
    long long res = 0;
    long long cnt = 0, sum = 0;
    for(int i = 1; i <= n; i++){
        int delet = i-k;
        if(delet>=1 && s[delet]=='D'){
            long long minus = sumM[i-1]-sumM[delet];
            sum -= minus;
            cnt--;
        }
        if(s[i]=='D') cnt++;
        else if(s[i]=='M') sum += cnt;
        else if(s[i]=='C') res += sum;
    }
    return res;
}

int main(){
    int n;
    scanf("%d%s",&n,s+1);
    sumM[0] = 1;
    for(int i = 1; i <= n; i++) sumM[i] = sumM[i-1]+(s[i]=='M');
    int q;
    scanf("%d",&q);
    while(q--){
        int k;
        scanf("%d",&k);
        printf("%lld\n",solve(n,k));
    }

    return 0;
}

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

int main() {
	long long N, Q;
	string S;
	cin >> N >> S >> Q;
	for (int i = 0; i < Q; i++) {
		long long K;
		cin >> K;
		long long CurX = 0, CurY = 0, COUNT = 0, ANS = 0;
		vector<long long> MCOUNT(N, 0);
		for (int j = 0; j < N; j++) {
			if (S[j] == 'D') CurX++;
			if (S[j] == 'M') CurY++;
			if (S[j] == 'M') COUNT += CurX;
			if (j - K >= 0) {
				if (S[j - K] == 'M') CurY--;
				if (S[j - K] == 'D') COUNT -= CurY, CurX--;
			}
			if (S[j] == 'C') ANS += COUNT;
		}
		cout << ANS << endl;
	}
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<bool>vec(N,true);
  vector<int>F(N);
  int WA=0,AC=0;
  for(int i=0; i<M; i++){
    int p;
    string S;
    cin >> p >> S;
    if(vec[p-1] && S == "WA"){
      WA++;
      F[p-1]++;
    }
    if(vec[p-1] && S == "AC"){
      AC++;
      vec[p-1]=false;
    }
  }
  for(int i=0; i<N; i++){
    if(vec[i]){
      WA -= F[i];
    }
  }
  cout << AC << " " << WA << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n, m;
    cin>>n>>m;
    if(n == 0 || m == 0){
        cout<<"0 0";
        return 0;
    }
    bool accepted[n];
    unordered_map<int, int> ma;
    for(int i = 0; i < n; i++){
        accepted[i] = false;
    }
    for(int i = 0; i < m; i++){
        int p; string s;
        cin>>p>>s;
        p-=1;
        if(s == "AC"){
            accepted[p] = true;
        }else{
            if(!accepted[p]){
                if(ma.find(p) == ma.end()){
                    ma[p] = 1;
                }else
                {
                    ma[p]++;
                }

            }
        }
    }
    int correct = 0, penalties = 0;
    for(int i = 0; i < n; i++){
        if(accepted[i]){
            correct++;
            penalties += ma[i];
        }
    }
    cout<<correct<<" "<<penalties;
    return 0;
}


#include <cstdio>

int N;
int C[10000][2];

void solve() {
  int a = 0;
  int b = 0;
  for (int i = 0; i < N; i++) {
    int ac = C[i][0];
    int bc = C[i][1];
    if (ac > bc) {
      a += ac + bc;
    } else if (ac < bc) {
      b += ac + bc;
    } else {
      a += ac;
      b += bc;
    }
  }
  printf("%d %d\n", a, b);
}

int main() {
  for (;;) {
    scanf("%d", &N);
    if (N == 0) { break; }

    for (int i = 0; i < N; i++) {
      scanf("%d%d", &C[i][0], &C[i][1]);
    }
    solve();
  }
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    string s; cin>>s;
    ll q; cin>>q;

    vint ruiM(n+1, 0);
    rep(i,n) ruiM[i+1] = ruiM[i] + (ll)(s[i] == 'M');

    while(q-->0){
        ll k; cin>>k;
        ll left = -k;
        ll right = 0;
        vint cnt(2,0);
        ll ans = 0;

        while(right < n){
            if(left >= 0){
                if(s[left] == 'D'){
                    cnt[0]--;
                    cnt[1] -= ruiM[right] - ruiM[left+1];
                }
            }
            if(s[right] == 'D'){
                cnt[0]++;
            }else if(s[right] == 'M'){
                cnt[1] += cnt[0];
            }else if(s[right] == 'C'){
                ans += cnt[1];
            }
            left++;
            right++;
        }
        cout<<ans<<endl;
    }

    return 0;

}


#include <iostream>
using namespace std;
#include <stdio.h>
void ushm(char x);
struct sai {
	int dicet[3][2];
	int diceus[2], dicemh[2];
	int dicenow;
};
struct sai a = { { 1, 6, 2, 5, 3, 4 },{ 5, 2 },{ 4, 3 }, 1 };
int main()
{
	int	atai[6], i;
	char houi[101];
	for (i = 0; i < 6; i++) { cin >> atai[i]; }
	cin >> houi;
	for (i = 0; i <= 100 && houi[i] != '\0'; i++) {
		ushm(houi[i]);
	}
	printf("%d\n", atai[a.dicenow - 1]);
	return 0;
}
void ushm(char x)
{
	int now = a.dicenow, nowt, i;
	for (i = 0; i < 3; i++)
	{
		if (a.dicet[i][0] == now)
			nowt = a.dicet[i][1];
		else if (a.dicet[i][1] == now)
			nowt = a.dicet[i][0];
	}
	switch (x) {
	case 'N': a.dicenow = a.diceus[1]; a.diceus[0] = now; a.diceus[1] = nowt; break;
	case 'S': a.dicenow = a.diceus[0]; a.diceus[1] = now; a.diceus[0] = nowt; break;
	case 'W': a.dicenow = a.dicemh[1]; a.dicemh[0] = now; a.dicemh[1] = nowt; break;
	case 'E': a.dicenow = a.dicemh[0]; a.dicemh[1] = now; a.dicemh[0] = nowt; break;
	}
}

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

#define DEBUG(x) cerr << #x << " = " << x << endl

enum FACE { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM }; // 1..6
typedef array<int, 6> Dice;

FACE tbl[6][4] = {
  { TOP, BACK, BOTTOM, FRONT },
  { TOP, RIGHT, BOTTOM, LEFT },
  { TOP, FRONT, BOTTOM, BACK },
  { TOP, LEFT, BOTTOM, RIGHT },
  { FRONT, RIGHT, BACK, LEFT },
  { FRONT, LEFT, BACK, RIGHT }
};

enum MOVE { TOP_TO_BACK, TOP_TO_RIGHT, TOP_TO_FRONT, TOP_TO_LEFT, FRONT_TO_RIGHT, FRONT_TO_LEFT };

void rotate(Dice &d, FACE t[4]) {
  int tmp = d[t[3]];
  d[t[3]] = d[t[2]]; d[t[2]] = d[t[1]]; d[t[1]] = d[t[0]]; d[t[0]] = tmp;
}

vector<Dice> generate_all(Dice dice) {
  vector<Dice> res;
  for(int i = 0; i < 6; ++i) {
    for(int j = 0; j < 4; ++j) {
      res.emplace_back(dice);
      rotate(dice, tbl[FRONT_TO_RIGHT]);
    }
    if(i % 2 == 0) rotate(dice, tbl[TOP_TO_BACK]);
    else rotate(dice, tbl[TOP_TO_RIGHT]);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  Dice d;
  cin >> d[TOP];
  cin >> d[FRONT];
  cin >> d[RIGHT];
  cin >> d[LEFT];
  cin >> d[BACK];
  cin >> d[BOTTOM];
  string s; cin >> s;
  for(char c : s) {
    if(c == 'S') {
      rotate(d, tbl[TOP_TO_FRONT]);
    }
    if(c == 'E') {
      rotate(d, tbl[TOP_TO_RIGHT]);
    }
    if(c == 'W') {
      rotate(d, tbl[TOP_TO_LEFT]);
    }
    if(c == 'N') {
      rotate(d, tbl[TOP_TO_BACK]);
    }
  }
  cout << d[TOP] << endl;
}


#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

string s;

int main()
{
	cin >> s;
	for (int i = 0; i < s.size() - 1; i ++ )
		if (s[i] == s[i + 1])
		{
			cout << i + 1 << ' ' << i + 2 << endl;
			return 0;
		}

	for (int i = 0; i < s.size() - 2; i ++ )
		if (s[i] == s[i + 2])
		{
			cout << i + 1 << ' ' << i + 3 << endl;
			return 0;
		}

	puts("-1 -1");
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    bool found = 0;
    int i, j;
    for (i = 0; i < (int)s.size() - 1; i++)
    {
        for (j = i + 1; j < (int)s.size(); j++)
        {
            if (s[i] == s[j])
            {
                if (2 > (j - i + 1) / 2)
                    found = 1;
                break;
            }
        }
        if (found)
            break;
    }
    if (found)
        cout << i + 1 << " " << j + 1 << endl;
    else
        cout << -1 << " " << -1 << endl;
}


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

int N;
int A[3][100001];
LL dp[3][100001] = {};

int main() {
    scanf("%d", &N);
    rep(j, 3) { rep(i, N) scanf("%d", &A[j][i]); A[j][N] = 1000000001; }
    rep(j, 3) sort(A[j], A[j] + N);
    rep(i, N + 1) dp[0][i] = i;
    rep(j, 2) {
        int p = 0;
        rep(i, N) {
            while (A[j][p] < A[j + 1][i]) p++;
            dp[j + 1][i + 1] += dp[j + 1][i] + dp[j][p];
        }
    }
    printf("%lld\n", dp[2][N]);
    return 0;
}

#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  vector<ll> na(n, 0);
  vector<ll> nb(n, 0);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  for(int i = 0; i < n; ++i) cin >> c[i];

  sort(ALL(b));
  sort(ALL(c));

  for(int i = 0; i < n; ++i)
  {
    auto itc = upper_bound(ALL(c), b[i]);
    nb[i] = distance(itc, c.end());
  }
  for(int i = n - 2; i >= 0; --i)
  {
    nb[i] += nb[i + 1];
  }
  for(int i = 0; i < n; ++i)
  {
    auto itb = upper_bound(ALL(b), a[i]);
    na[i] = nb[distance(b.begin(), itb)];
  }
  cout << accumulate(ALL(na), 0LL);
}

int main()
{
  fastio;
  solve();

  return 0;
}


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

int main(){
  string N,m;
  cin >> N;
  int x,y = 0;
  for(int i = 0; i < int(N.size()); i++){
    istringstream n;
    m = N[i];
  	n = istringstream(m);
  	n >> x;
    y += x;
  }
  if (stoi(N) % y == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    rep(i,h){
        bool rev_fl = i<b;
        rep(j,w){
            if(j<a){
                if(rev_fl) cout << 1;
                else cout << 0;
            }else {
                if(rev_fl) cout << 0;
                else cout << 1;
            }
        }
        cout << endl;
    }
    return 0;
}

#include<iostream>
using namespace std;

int main(){
int n;
int a[1000000];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n-1;i>=0;i--){
cout<<a[i];
if(i>0){
cout<<" ";
}
}
cout<<endl;
return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

string s; int n;
ll dp[1 << 18][8];

ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return res;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s; n = s.length(); int d = (n - 3) / 2;
	if (n == 1) {
		if (s[0] == '0')cout << 0 << endl;
		else cout << 1 << endl;
		return 0;
	}
	int num = 0;
	rep(i, n) {
		if (s[i] == '?')num++;
	}
	int cnt = 0;
	rep(i, 8) {
		bool valid = true;
		rep(j, 3) {
			int t = 0;
			if (i&(1 << j))t = 1;
			if (t == 0 && s[2-j] == '1')valid = false;
			if (t == 1 && s[2-j] == '0')valid = false;
		}
		if (valid)dp[0][i] = 1;
	}
	ll ans = 0;
	rep(i, 3) {
		if (s[i] == '?')cnt++;
	}
	rep(i, d) {
		ans = (ans + dp[i][6] * mod_pow(2, num - cnt) % mod + dp[i][7] * mod_pow(2, num - cnt) % mod) % mod;
		char le = s[2 * i + 3], ri = s[2 * i + 4];
		vector<int> v;
		if (le != '1'&&ri != '1')v.push_back(0);
		if (le != '1'&&ri != '0')v.push_back(1);
		if (le != '0'&&ri != '1')v.push_back(2);
		if (le != '0'&&ri != '0')v.push_back(3);
		int len = v.size();
		rep(j, len) {
			dp[i + 1][v[j]] = (dp[i + 1][v[j]] + dp[i][0] + dp[i][1]+dp[i][2]) % mod;
			dp[i + 1][v[j] + 4] = (dp[i + 1][v[j] + 4] + dp[i][3] + dp[i][5]) % mod;
			dp[i + 1][4 + v[j] % 2] = (dp[i + 1][4 + v[j] % 2] + dp[i][4]) % mod;
		}
		if (le == '?')cnt++;
		if (ri == '?')cnt++;
	}
	ans = (ans + dp[d][3] + dp[d][5] + dp[d][6] + dp[d][7]) % mod;
	cout << ans << endl;
	//stop
	return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n;
  string s;
  cin >> n >> s;

  vi a(2*n);
  rep(i, 0, 2*n){
    a[i] = ((s[i] == 'B') + (i%2 == 0)) % 2;
  }

  int ans = 1, cnt = 0;
  rep(i, 0, 2*n){
    if(a[i]){
      (ans *= cnt) %= mod;
      cnt--;
    }else{
      cnt++;
    }
  }

  if(cnt) ans = 0;

  rep(i, 1, n+1) (ans *= i) %= mod;

  cout << ans << endl;

//  rep(i, 0, 2*n) cout << a[i] << " ";
//  cout << endl;

  return 0;
}

#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (1000*100)
#define MOD (ll(1E9+7))
int N;
string S;

int W,B;

ll kai[MAX_N+5];

ll kaijo(int n)
{
	DOUT<<"---- kaijo("<<n<<") ----"<<endl;
	if(kai[n]!=0) {
		return kai[n];
	}
	ll i=n;
	for(;i>=1; i--) {
		if (kai[i]!=0) {
			break;
		}
	}
	ll ret = kai[i];
	for(;i<n;i++) {
		DOUT<<"(i+1)* kai[i]=="<<((i+1)* kai[i])<<endl;
		kai[i+1] = ((i+1)* kai[i])%MOD;
	}
	return (kai[n])%MOD;
}

int main(int argc, char *argv[])
{
	kai[0]=1;
	kai[1]=1;
	ios::sync_with_stdio(false);
	cin >> N;
	cin >> S;
	FOR(n,2*N) {
		DOUT << "S["<<n<<"]=="<<S[n]<<endl;
		DOUT << "(2*N-n)%2=="<<(2*N-n)%2<<endl;
		if((2*N-n)%2==0) {
			if(S[n]=='B') { S[n]='W'; }
			else if(S[n]=='W') { S[n]='B'; }
		}
		DOUT << "S["<<n<<"]=="<<S[n]<<endl;
	}
	W=0;
	B=0;
	FOR(n,2*N) {
		DOUT << "S["<<n<<"]=="<<S[n]<<endl;
		if(S[n]=='B') { B++; }
		else if(S[n]=='W') { W++; }
	}
	if(B!=W) {
		cout << 0 << endl;
		return 0;
	}

	int count = 0;
	ll ans = 1;
	count = 0;
	FOR(n,2*N) {
		DOUT << "S["<<n<<"]=="<<S[n]<<", ans="<<ans<<", count=="<<count<<endl;
		if(S[n]=='B') {
			DOUT<<"ans*count="<<(ans*count)%MOD<<endl;
			ans = ans*count%MOD;
			count--;
		}
		else {
			count++;
		}
		DOUT << "ans=="<<ans<<", count=="<<count<<endl;
	}

	cout << ans*kaijo(N)%MOD << endl;

	DOUT << kaijo(1000*100) << endl;

	return 0;
}


// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// g++ hoge.cpp -std=c++17 -I . でコンパイルできる
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
//#include <atcoder/all>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> P;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,k,x,y,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll q;
    cin>>n>>q;
    cin>>str;
    P p[q];
    rep(i,q){
        cin>>a>>b;
        a--;
        b--;
        p[i]=P(a,b);
    }
    vector<ll> imos(n+1);
    rep(i,n-1){
        if(i!=0)imos[i]=imos[i-1];
        if(str.substr(i,2).compare("AC")==0) {
            imos[i]++;
        }
        //cout<<imos[i]<<" ";
    }
    a=0;b=0;
    rep(i,q){
        if(p[i].first!=0)sum=imos[p[i].second-1]-imos[p[i].first-1];
        else sum=imos[p[i].second-1];
        cout<<sum<<endl;
    }

    return 0;
}

/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll q;
	cin >> q;
	rep(i, q){
		ll k;
		cin >> k;
		ll ans = 0, sum = 0;
		ll cntD = 0, cntM = 0;
		rep(i, n){
			if(i >= k){
				if(s[i - k] == 'D'){
					cntD--;
					sum -= cntM;
				}else if(s[i - k] == 'M') cntM--;
			}

			if(s[i] == 'D') cntD++;
			else if(s[i] == 'M'){
				cntM++;
				sum += cntD;
			}else if(s[i] == 'C') ans += sum;
		}
		co(ans);
	}

	return 0;
}


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

typedef long long ll;

int main() {
    ll N;
    string S;
    cin >> N >> S;
    vector<string> ans = {"SS", "SW", "WS", "WW"};
    rep(i, 4) {
        rep(j, N) {
            if (ans[i][j + 1] == 'S') {
                if (S[j] == 'o') {
                    if (ans[i][j] == 'S') ans[i].push_back('S');
                    else ans[i].push_back('W');
                } else {
                    if (ans[i][j] == 'S') ans[i].push_back('W');
                    else ans[i].push_back('S');
                }
            } else {
                if (S[j] == 'o') {
                    if (ans[i][j] == 'S') ans[i].push_back('W');
                    else ans[i].push_back('S');
                } else {
                    if (ans[i][j] == 'S') ans[i].push_back('S');
                    else ans[i].push_back('W');
                }
            }
        }
        if (ans[i].substr(0, 2) == ans[i].substr(N, 2)) {
            cout << ans[i].substr(1, N) << "\n";
            return 0;
        }
    }
    cout << "-1\n";
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int n;
string s;

bool judge(string ans){
    bool ok=true;
    if(ans[n-1]=='S'){
        if(s[n-1]=='o' && ans[n-2]!=ans[0]) ok=false;
        if(s[n-1]=='x' && ans[n-2]==ans[0]) ok=false;
    }
    else{
        if(s[n-1]=='o' && ans[n-2]==ans[0]) ok=false;
        if(s[n-1]=='x' && ans[n-2]!=ans[0]) ok=false;
    }
    if(ans[0]=='S'){
        if(s[0]=='o' && ans[n-1]!=ans[1]) ok=false;
        if(s[0]=='x' && ans[n-1]==ans[1]) ok=false;
    }
    else{
        if(s[0]=='o' && ans[n-1]==ans[1]) ok=false;
        if(s[0]=='x' && ans[n-1]!=ans[1]) ok=false;
    }
    return ok;
}

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

    string ans="SS";
    for(int i=1;i<n-1;i++){
        if(ans[i]=='S'){
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
            else{
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
        }
        else{
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
            else{
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
        }
    }

    if(judge(ans)){
        cout<<ans<<endl;
        return 0;
    }

    ans="SW";
    for(int i=1;i<n-1;i++){
        if(ans[i]=='S'){
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
            else{
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
        }
        else{
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
            else{
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
        }
    }
    if(judge(ans)){
        cout<<ans<<endl;
        return 0;
    }

    ans="WS";
    for(int i=1;i<n-1;i++){
        if(ans[i]=='S'){
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
            else{
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
        }
        else{
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
            else{
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
        }
    }
    if(judge(ans)){
        cout<<ans<<endl;
        return 0;
    }

    ans="WW";
    for(int i=1;i<n-1;i++){
        if(ans[i]=='S'){
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
            else{
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
        }
        else{
            if(s[i]=='o'){
                if(ans[i-1]=='S') ans+='W';
                else ans+='S';
            }
            else{
                if(ans[i-1]=='S') ans+='S';
                else ans+='W';
            }
        }
    }
    if(judge(ans)){
        cout<<ans<<endl;
        return 0;
    }

    cout<<-1<<endl;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n, q, s, t, x, u;
iP a[1<<18];
bool b;

int update(int s, int t, int x, int k, int l, int r, int i) {
	if (t < l || r < s)return 0;
	else if (s <= l&&r <= t) {
		a[k] = mkp(x, i);
		return 0;
	}
	else {
		update(s, t, x, k * 2, l, (l + r) / 2, i);
		update(s, t, x, k * 2 + 1, (l + r) / 2 + 1, r, i);
		return 0;
	}
}
int find(int x) {
	int y, z = -2;
	x += u;
	while (x) {
		if (z < a[x].second) {
			y = a[x].first;
			z = a[x].second;
		}
		x /= 2;
	}
	return y;
}

int main(){
	cin >> n >> q;
	for (int i = 1;; ++i) {
		if ((1 << i) / n >= 2) {
			u = (1 << i - 1);
			break;
		}
	}
	for (int i = 1; i != u * 2; ++i)
		a[i] = mkp(intmax, -1);
	for (int i = 0; i != q; ++i) {
		cin >> b >> s;
		if (b) {
			cout << find(s) << endl;
		}
		else {
			cin >> t >> x;
			update(s, t, x, 1, 0, u - 1, i);
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <typename _Tp>
struct LazySegmentTree {
  _Tp n;
  vector<_Tp> node, lazy;

  LazySegmentTree(vector<_Tp> const& v) {
    _Tp sz = v.size();
    n = 1;
    while (sz > n) n *= 2;
    node.resize(2*n-1);
    lazy.resize(2*n-1, -1);

    for (int i = 0; i < sz; ++i) {
      node[i+n-1] = v[i];
    }
/*
    for (int i = n-2; i >= 0; --i) {
      node[i] = node[i*2+1] + node[i*2+2];
    }
    */
  }

  void eval(int k, int l, int r) {
    if (lazy[k] != -1) {
      node[k] = lazy[k]; // 自分自身に遅延評価を反映

      // 最下段でないならば評価を伝搬させる。
      if (r - l > 1) {
        lazy[2*k+1] = lazy[k];
        lazy[2*k+2] = lazy[k];
      }

      lazy[k] = -1;
    }
  }

  void update(int a, int b, _Tp value, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k,l,r);

    // 範囲外ならば切る。
    if (b <= l || r <= a) {
      // cout << 1 << endl;
      return;
    }

    if (a <= l && r <= b) {
      lazy[k] = value;
      eval(k,l,r);
      return;
    } else {
      update(a,b,value,2*k+1,l,(r+l)/2);
      update(a,b,value,2*k+2,(l+r)/2,r);
      node[k] = value;
    }
  }

  _Tp get(int idx, int k = 0, int l = 0, int r = -1) {
    int a = idx, b = idx+1;
    if (r < 0) {
      r = n;
    }

    eval(k,l,r);

    // cout << a << " "<< b << " " << l << " " << r << endl;

    if (a <= l && r <= b) {
      return node[k];
    }

    if (b <= l || r <= a) return -1;
    else {
      auto lv = get(idx, 2*k+1, l, (l+r)/2);
      auto rv = get(idx, 2*k+2, (l+r)/2, r);
      return max(lv, rv);
    }
  }
};

ll fi = (1L << 31) - 1;

int main() {
  int n, q;
  cin >> n >> q;
  vector<ll> v(n, fi);
  LazySegmentTree<ll> seg_tree(v);
  rep(i, q) {
    int com;
    cin >> com;
    if (com == 0) {
      int s,t,n;
      cin >> s >> t >> n;
      seg_tree.update(s,t+1,n);
    } else {
      int idx;
      cin >> idx;
      cout << seg_tree.get(idx) << "\n";
    }
  }
}


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

int main() {
    long long n, m;
    cin >> n >> m;
    for (long long i = 1; i < m + 1; i++) {
        if (i <= m - m / 2) {
            cout << i << " " << n + 1 - i << endl;
        } else {
            cout << n + 1 - i - (m - i + 1) * 2 << " " << n + 1 - i << endl;
        }
    }
}

#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int maxn=3e5+100;
const int N=1e6+1000;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

struct node{
    ll lazy[N<<2],mi[N<<2];
    void pushdown(int rt)
    {
        if(lazy[rt])
        {
            mi[ls]+=lazy[rt];mi[rs]+=lazy[rt];
            lazy[ls]+=lazy[rt];lazy[rs]+=lazy[rt];
            lazy[rt]=0;
        }
    }
    void pushup(int rt)
    {
        mi[rt]=min(mi[ls],mi[rs]);
    }
    void update(int rt,int l,int r,int L,int R,ll val)
    {
        if(L<=l&&r<=R)
        {
            lazy[rt]+=val;
            mi[rt]+=val;
            return ;
        }
        pushdown(rt);
        int mid=getmid;
        if(L<=mid) update(ls,l,mid,L,R,val);
        if(R>mid) update(rs,mid+1,r,L,R,val);
        pushup(rt);
    }
    ll query(int rt,int l,int r,int L,int R)
    {
        if(L<=l&&r<=R) return mi[rt];
        pushdown(rt);
        int mid=getmid;
        ll res=INF;
        if(L<=mid) res=min(res,query(ls,l,mid,L,R));
        if(R>mid) res=min(res,query(rs,mid+1,r,L,R));
        return res;
    }
}x,y;
int A[N],B[N];
int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    int H,W;cin>>H>>W;
    rep1(i,W) y.update(1,1,W,i,i,-i);
    rep1(i,H) cin>>A[i]>>B[i];
    for(int i=1;i<=H;++i)
    {
        int r=B[i]+1;
        if(r<=W)
        {
            ll mi=y.query(1,1,W,1,B[i]);
            ll now=x.query(1,1,W,r,r);
            if(now>mi+r)
            {
                x.update(1,1,W,r,r,mi+r-now);
                y.update(1,1,W,r,r,mi-y.query(1,1,W,r,r));
            }
        }
        x.update(1,1,W,A[i],B[i],inf);
        y.update(1,1,W,A[i],B[i],inf);
        //x.update(1,1,W,1,W,1);
        //y.update(1,1,W,1,W,1);
        ll ans=x.query(1,1,W,1,W);
        if(ans>=inf) cout<<-1<<"\n";
        else cout<<ans+i<<"\n";
    }
    return 0;
}


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

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

char toLowerCase(char c){
  if(isLowerCase(c)){
    return c;
  }else{
    return c+'a'-'A';
  }
}
char toUpperCase(char c){
  if(isLowerCase(c)){
    return c-('a'-'A');
  }else{
    return c;
  }
}
ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string n;cin>>n;
  if(n.size()==3){
    char c=n[0];
    n[0]=n[2];
    n[2]=c;
  }
  cout<<n<<endl;
  return 0;
}

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

int main() {
  string S;
  char s;
  cin>>S;
  if(S.size()==2){cout<<S<<endl;}
  else{s=S[0]; S[0]=S[2]; S[2]=s; cout<<S<<endl;}
}


#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
typedef struct{
    int head;
    int tail;
    int right;
    int left;
    int up;
    int down;
} dice;
dice s(dice a) {
    int buf;
    buf = a.tail;
    a.tail = a.down;
    a.down = a.head;
    a.head = a.up;
    a.up = buf;
	return a;
}
dice n(dice a) {
	return s(s(s(a)));
}
dice e(dice a) {
    int buf;
    buf = a.tail;
    a.tail = a.right;
    a.right = a.head;
    a.head = a.left;
    a.left = buf;
	return a;
}
dice w(dice a) {
	return e(e(e(a)));
}
dice rev(dice a) {
	return e(e(a));
}
dice round(dice a) {
	int buf;
	buf = a.right;
	a.right = a.up;
	a.up = a.left;
	a.left = a.down;
	a.down = buf;
	return a;
}
bool same(dice a, dice b) {
	dice c = a;
	rep(i,4) {
		if(c.head == b.head && c.tail == b.tail && c.up == b.up && c.down == b.down && c.right == b.right && c.left == b.left) return true;
		c = round(c);
	}
	return false;
}

int main() {
    int k, a[105][6];
	cin >> k;
	rep(i,k) {
		rep(j,6) {
	        cin >> a[i][j];
		}
	}
	rep(i,k) {
		rep2(j,i+1,k) {
			dice da, db;
			da.head = a[i][0];
			da.down = a[i][1];
			da.right = a[i][2];
			da.left = a[i][3];
			da.up = a[i][4];
			da.tail = a[i][5];
			db.head = a[i+j][0];
			db.down = a[i+j][1];
			db.right = a[i+j][2];
			db.left = a[i+j][3];
			db.up = a[i+j][4];
			db.tail = a[i+j][5];
			if(same(da,db) || same(s(da), db) || same(n(da), db) || same(e(da), db) || same(w(da), db) || same(rev(da), db)) {
				cout << "No" <<endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

const int COUNT = 6;

class Dice
{
public:
	int num[6];

public:
	Dice();
	void play_dice(string);
	void play(int, int, int, int);
	void print_(int x) {printf("%d\n", num[x]);}
	void to_top_and_front(int, int);
};

Dice::Dice()
{
	for (int i = 0; i < COUNT; ++i)
	{
		cin >> num[i];

	}
}

void Dice::play_dice(string s)
{
	if(s == "E") {play(0, 2, 5, 3); }

	if(s == "N") {play(0, 4, 5, 1); }

	if(s == "S") {play(0, 1, 5, 4); }

	if(s == "W") {play(0, 3, 5, 2); }
}

void Dice::play(int a, int b, int c, int d)
{
	int temp;
	temp = num[d]; num[d] = num[c]; num[c] = num[b]; num[b] = num[a]; num[a] = temp;
}

void Dice::to_top_and_front(int top, int front)
{
	string str[7] = {"N", "N", "N", "W", "N", "N", "N"};
	for (int i = 0; i < 7; ++i)
	{
		if(front == num[1]) break;
		play_dice(str[i]);
	}
	for (int k = 0; k < 4; k++)
	{
		if(top == num[0]) break;
		play_dice("W");
	}
}

bool compare(Dice a, Dice b)
{
	a.to_top_and_front(b.num[0], b.num[1]);

	for (int i = 0; i < COUNT; ++i)
	{
		if (a.num[i] != b.num[i])
		{
			return false;
		}
	}
	return true;
}

int main(int argc, char const *argv[])
{
	Dice *cs;
	int times;

	cin >> times;

	cs = new Dice[times];

	for (int i = 0; i < times; ++i)
	{
		for (int k = i+1; k < times; ++k)
		{
			if(compare(cs[i], cs[k]))
			{
				delete[] cs;
				printf("No\n");
				return 0;
			}
		}
	}

	delete[] cs;
	printf("Yes\n");
	return 0;
}


//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

const long long M=1000000007;
//typedef long T;
//#include "math/mod.h"

//#include "math/modulo.h"

template<class T, long long M>
struct modulo {
	T n;
	T gcd_ext(T a, T b, T *x, T *y) {
		if (a == 0) {
			*x = 0;
			*y = 1;
			return b;
		}
		T x1, y1;
		T gcd = gcd_ext(b%a, a, &x1, &y1);
		*x = y1 - (b/a) * x1;
		*y = x1;
		return gcd;
	}
	modulo(T n): n(n<0? n%M+M: n%M) {}
	operator T() const { return n; }
	modulo operator-() {
		return modulo(-n);
	}
	modulo operator+(const modulo &o) {
		return modulo(n+o.n);
	}
	modulo operator-(const modulo &o) {
		return modulo(n-o.n);
	}
	modulo operator*(const modulo &o) {
		return modulo(n*o.n);
	}
	modulo operator/(const modulo &o) {
		T x, y;
		T g = gcd_ext(o.n, M, &x, &y);
		if (g != 1) return 0;
		else return modulo(n * (x % M));
	}
	bool operator<(const modulo &o) const {
		return n<o.n;
	}
	bool operator<=(const modulo &o) const {
		return n<=o.n;
	}
	bool operator>(const modulo &o) const {
		return n>o.n;
	}
	bool operator>=(const modulo &o) const {
		return n>=o.n;
	}
	bool operator==(const modulo &o) const {
		return n==o.n;
	}
	bool operator!=(const modulo &o) const {
		return n!=o.n;
	}
};

typedef modulo<long long, M> T;
//#include "math/comb.h"

void comb_inc_k(T &r, int n, int &k) {
        //C(n,k+1) = C(n,k) * (n-k) / (k+1)
	r = r * T(n-k) / T(k+1);
	k++;
}

void comb_dec_k(T &r, int n, int &k) {
        //C(n,k-1) = C(n,k) * k / (n-k+1)
	r = r * T(k) / T(n-k+1);
	k--;
}

void comb_inc_n(T &r, int &n, int k) {
        //C(n+1,k) = C(n,k) * (n+1) / (n+1-k)
	r = r * T(n+1) / T(n+1-k);
	n++;
}

void comb_dec_n(T &r, int &n, int k) {
        //C(n-1,k) = C(n,k) * (n-k) / n
	r = r * T(n-k) / T(n);
	n--;
}

T comb(int n, int k) {
    if (k*2 > n) k = n-k;
    if (n==0) return 0;
    T r = 1; //C(n,0)
    for (int i=0; i<k; ) comb_inc_k(r, n, i);
    return r;
}

int h,w,a,b;

int input() {
	if (scanf("%d %d %d %d", &h, &w, &a, &b) < 0) return 0;
	return 1;
}

void init() {
}

int solve() {
	T r = comb(h+w-2, h-1);

	int xn = h-a+b-1, xk = b-1;
	T x = comb(xn, xk);

	int yn = a-1+w-b-1, yk = w-b-1;
	T y = comb(yn, yk);

	for (int i=0; i<a; i++) {
		//T x = mod_combinations(h-a+i+b-1, b-1, M);
		//T y = mod_combinations(a-1-i+w-b-1, w-b-1, M);
		if (i) {
			comb_inc_n(x, xn, xk);
			comb_dec_n(y, yn, yk);
		}
		r = r-x*y;
	}
	/*
	T r = mod_combinations(h+w-2, h-1, M);
	T x = mod_combinations(h-a+b-1, b-1, M);
	T y = mod_combinations(a-1+w-b-1, w-b-1, M);
	for (int i=0; i<a; i++) {
		//T x = mod_combinations(h-a+i+b-1, b-1, M);
		//T y = mod_combinations(a-1-i+w-b-1, w-b-1, M);
		if (i) {
			T n = h-a+i+b-1, m = b-1;
			x = mod_div(x*n, n-m, M);

			n = a-1-i+w-b-1, m = w-b-1;
			y = mod_div(y*(n+1-m), n+1, M);
		}
		T z = mod_mul(x, y, M);
		//printf("%d: r=%ld %ld %ld %ld\n", i, r, x, y, z);
		r = mod_sub(r, z, M);

	}
	*/
	return r;
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 2e5+100;
const int mod = 1e9+7;
ll fact[upperlimit];
ll invfact[upperlimit];
ll ways(int x1,int y1,int x2,int y2){
	ll ans=fact[abs(x2-x1)+abs(y2-y1)];
	ans*=invfact[abs(x2-x1)];ans%=mod;
	ans*=invfact[abs(y2-y1)];ans%=mod;
	return ans;
}
int main() {
	fact[0]=1;invfact[0]=1;
	for(int i = 1; i < upperlimit; i++){
		fact[i]=fact[i-1];fact[i]*=i;fact[i]%=mod;
		invfact[i]=powmod(fact[i],mod-2,mod);
	}
	int h,w,r,c;
	sd(h);sd(w);sd(r);sd(c);
	ll ans=ways(0,0,h-1,w-1);
	for(int i = 0; i < c; i++){
		ll calc=ways(0,0,h-r-1,i);
		calc*=ways(h-r,i,h-1,w-1);calc%=mod;
		ans-=calc;
		if(ans<0) ans+=mod;
	}
	plld(ans);
	return 0;
}


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

#define ll long long

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M+1);
    vector<ll> R(M+1);
    for(int i = 1; i <= M; ++i) cin >> L[i] >> R[i];
    if(*min_element(R.begin()+1, R.end())-*max_element(L.begin()+1, L.end()) >= 0)cout << *min_element(R.begin()+1, R.end())-*max_element(L.begin()+1, L.end()) +1 << endl;
    else cout << 0 << endl;
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define N 300010
#define ll long long
int n,m,p[N],fa[N],deep[N],degree[N],q[N],t,root;
bool flag[N];
struct data{int to,nxt;
}edge[N];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void topsort()
{
	int head=0,tail=0;
	for (int i=1;i<=n;i++) if (!degree[i]) q[++tail]=i;
	while (tail<n)
	{
		int x=q[++head];
		for (int i=p[x];i;i=edge[i].nxt)
		{
			degree[edge[i].to]--;
			if (deep[x]+1>deep[edge[i].to])
			{
				deep[edge[i].to]=deep[x]+1;
				fa[edge[i].to]=x;
			}
			if (!degree[edge[i].to]) q[++tail]=edge[i].to;
		}
	}
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<n+m;i++)
	{
		int x=read(),y=read();
		addedge(x,y);degree[y]++;
	}
	topsort();
	for (int i=1;i<=n;i++) printf("%d\n",fa[i]);
	return 0;
}


#include <bits/stdc++.h>

#if DEBUG
template <typename Iter>
void debug_iter(Iter begin, Iter end);
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, size_t N>
void debug(const std::array<T, N>& a) {
  debug_iter(a.begin(), a.end());
}
template <typename T>
void debug(const std::vector<T>& v) {
  debug_iter(v.begin(), v.end());
}
template <typename T>
void debug(const std::set<T>& s) {
  debug_iter(s.begin(), s.end());
}
template <typename T, typename U>
void debug(const std::map<T, U>& m) {
  debug_iter(m.begin(), m.end());
}
template <typename T, typename U>
void debug(const std::pair<T, U>& p) {
  std::cerr << "{";
  debug(p.first);
  std::cerr << ", ";
  debug(p.second);
  std::cerr << "}";
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
template <typename Iter>
void debug_iter(Iter begin, Iter end) {
  std::cerr << "{";
  for (Iter it = begin; it != end; ++it) {
    if (it != begin) std::cerr << ", ";
    debug(*it);
  }
  std::cerr << "}";
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

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

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

#include <boost/hana/functional/fix.hpp>
auto Fix = [](auto&& f) { return boost::hana::fix(f); };

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(ll, n, k);
  vector<ll> a(n);
  cin >> a;
  rep(i, k) {
    vector<ll> na(n);
    rep(j, n) na[j] = 1;
    {
      low_priority_queue<ll> que;
      rep(j, n) {
        while (!que.empty() && que.top() < j) que.pop();
        na[j] += que.size();
        que.push(j + a[j]);
      }
    }
    {
      priority_queue<ll> que;
      for (ll j = n - 1; j >= 0; --j) {
        while (!que.empty() && que.top() > j) que.pop();
        na[j] += que.size();
        que.push(j - a[j]);
      }
    }
    if (na == a) break;
    swap(a, na);
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
     int n, k; cin >> n >> k;
     vector<int> A(n); rep(i, n) cin >> A[i];

     rep(i, min(1000, k)){

         vector<int> plus(n), minus(n);
      rep(j, n){
        int s = max(0, j-A[j]), t = min(n-1, j+A[j]);
        plus[s]++; minus[t]++;
      }
      int cnt = 0;
      rep(j, n){
        cnt += plus[j];
        A[j] = cnt;
        cnt -= minus[j];
     }
     }
     rep(i, n)cout << A[i] << " ";
     cout << ln;
}


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

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  int a;
  cin >> a;
  ll ans = 0;

  rep(i, 3) ans += pow(a, i + 1);
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << "\n";
    return 0;
}


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

#define ran 1001001

struct Node {
	int pre, det, suf;
	Node() {}
} info[ran];

int n;
char s[ran];

Node analysis() {
	int len = strlen(s);

	int h = 0;
	int mi = 0;
	for(int i=0;i<len;i++) {
		if(s[i]=='(') h++;
		else h--;
		mi = min(mi, h);
	}

	Node res;
	res.pre = -mi;
	res.det = h;
	res.suf = res.pre + res.det;
	return res;
}

int cmp(const Node &a, const Node &b) {
	bool fa = (a.det>=0), fb = (b.det>=0);
	if(fa!=fb) return fa;
	if(fa) return a.pre<b.pre;
	return a.suf > b.suf;
}

bool chk() {
	int sum = 0;
	for(int i=0;i<n;i++)
		sum += info[i].det;
	if(sum!=0) return false;

	sort(info, info+n, cmp);

	int cur = 0;
	for(int i=0;i<n;i++) {
		if(cur<info[i].pre) return false;
		cur += info[i].det;
	}
	return true;
}

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

	for(int i=0;i<n;i++) {
		scanf("%s", s);
		info[i] = analysis();
	}

	puts(chk() ? "Yes" : "No");

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define vll vector<ll>
#define ld long double
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ook order_of_key
#define fbo find_by_order
const int MOD=1000000007;
long long int inverse(long long int i){
    if(i==1) return 1;
    return (MOD - ((MOD/i)*inverse(MOD%i))%MOD+MOD)%MOD;
}
ll POW(ll a,ll b)
{
    if(b==0) return 1;
    if(b==1) return a%MOD;
    ll temp=POW(a,b/2);
    if(b%2==0) return (temp*temp)%MOD;
    else return (((temp*temp)%MOD)*a)%MOD;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    string s[n];
    ll a[n],b[n];
    vector<pair<ll,ll> > v1,v2;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        ll mx=0,temp=0;
        for(int j=0;j<s[i].size();j++)
        {
            if(s[i][j]==')') temp++;
            else temp--;
            mx=max(temp,mx);
        }
        a[i]=mx;
        temp=0;
        ll mn=0;
        for(int j=s[i].size()-1;j>=0;j--)
        {
            if(s[i][j]=='(') temp++;
            else temp--;
            mn=max(mn,temp);
        }
        b[i]=mn;
        //cout<<a[i]<<" "<<b[i]<<" ";
        if( (b[i]-a[i]) >0) v1.PB(MP(a[i],i));
        else v2.PB(MP(-b[i],i));
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    stack<ll> st;
    ll flag=0;
    for(int i=0;i<v1.size();i++)
    {
        string k=s[v1[i].S];
        for(int j=0;j<k.size();j++)
        {
            if(k[j]=='(') st.push(1);
            else
            {
                if(st.empty()) {flag=1; break;}
                else st.pop();
            }
        }
        if(flag==1) break;
    }
    if(flag==0)
    {
        for(int i=0;i<v2.size();i++)
        {
            string k=s[v2[i].S];
            for(int j=0;j<k.size();j++)
            {
                if(k[j]=='(') st.push(1);
                else
                {
                    if(st.empty()) {flag=1; break;}
                    else st.pop();
                }
            }
            if(flag==1) break;
        }
    }
    if(flag==0 && st.empty()) cout<<"Yes";
    else cout<<"No";
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int k;cin>>k;
  vector<int> x(k);
  vector<int> y(k);
  int i,j;
  rep(i,k)cin>>y[i]>>x[i];
  vector<int> a(8-k);
  rep(i,8-k)a[i]=i;
  vector<int> okx(0);
  vector<int> oky(0);
  rep(i,8)
  {
    rep(j,k)
    {
      if(x[j]==i)break;
      if(j==k-1)okx.emplace_back(i);
    }
  }
  rep(i,8)
  {
    rep(j,k)
    {
      if(y[j]==i)break;
      if(j==k-1)oky.emplace_back(i);
    }
  }
  vector<vector<bool>> put(8,vector<bool>(8,false));
  rep(i,k)put[y[i]][x[i]]=true;
  do
  {
    vector<vector<bool>> ch(8,vector<bool>(8));
    ch=put;
    rep(i,8-k)
    {
      ch[oky[i]][okx[a[i]]]=true;
    }
    int count=0;
    int out=false;
    for(i=0;i<8;i++)
    {
      count=0;
      for(j=0;i-j>=0;j++)
      {
        if(ch[i-j][j])count++;
      }
      if(count>=2)out=true;
    }
    for(i=8;i<=14;i++)
    {
      count=0;
      for(j=i-7;j<8;j++)
      {
        if(ch[i-j][j])count++;
      }
      if(count>=2)out=true;
    }
    for(i=0;i<8;i++)
    {
      count=0;
      for(j=0;j<8-i;j++)
      {
        if(ch[j+i][j])count++;
      }
      if(count>=2)out=true;
    }
    for(i=0;i<8;i++)
    {
      count=0;
      for(j=0;j<8-i;j++)
      {
        if(ch[j][j+i])count++;
      }
      if(count>=2)out=true;
    }
    if(out)continue;
    rep(i,8)
    {
      rep(j,8)
      {
        if(ch[i][j])cout<<'Q';
        else cout<<'.';
      }
      cout<<endl;
    }
  } while (next_permutation(all(a)));

}

#include <cstdio>
long long x[100001],p[100001],ans,n,s;
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&p[i]);
	int i=1,j=n;
	while(i<=j){
		if(s<=x[i]){
			printf("%lld",x[j]-s+ans);
			return 0;
		}else if(s>=x[j]){
			printf("%lld",ans+s-x[i]);
			return 0;
		}
		if(p[i]>=p[j]){
			ans+=x[j]-x[i];
			while(i<j && p[i]>=p[j])p[i]+=p[j--];
		}else{
			ans+=x[j]-x[i];
			while(i<j && p[i]<p[j])p[j]+=p[i++];
		}
	}
}


/*
    In the name of Allah

    MohammadErfan Gooneh

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

using namespace std;

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

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    int a[3] ;
    for(int i = 0 ; i < 3 ; i++)
        cin >> a[i] ;
    sort(a , a+3) ;
    cout << a[0] + a[1] ;

return 0 ;
}

#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    printf("Left\n");
  } else if (A + B < C + D) {
    printf("Right\n");
  } else {
    printf("Balanced\n");
  }
}


//used C i/o for faster peformance

#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int x,y,z,n,m,road[200005],rail[200005],connect[200005];
pair<pair<int,int>,int> total[200005];

int root (int ind) {
	if (road[ind] == ind) return ind; else
	return road[ind] = root(road[ind]);
}

void onion(int l, int r) {
	if (root(l) != root(r)) road[root(l)] = root(r);
}

int root2(int ind) {
	if (rail[ind] == ind) return ind; else
	return rail[ind] = root2(rail[ind]);
}

void onion2(int l, int r) {
	if (root2(l) != root2(r)) rail[root2(l)] = root2(r);
}

int main() {
	scanf("%d%d%d",&x,&y,&z);
	for (int i = 0; i <= x; i++) {
		rail[i] = i;
		road[i] = i;
	}
	for (int i = 0; i < y; i++) {
		scanf("%d%d",&n,&m);
		onion(n,m);
	}
	for (int i = 0; i < z; i++) {
		scanf("%d%d",&n,&m);
		onion2(n,m);
	}
	for (int i = 1; i <= x; i++) {
		total[i] = make_pair(make_pair(root(i),root2(i)),i);
	}
	sort(total+1,total+1+x);
	total[x+1].f.f = total[x+1].f.s = -31415;
	stack<int> st; while (!st.empty()) st.pop();
	int a1 = 0,a2 = 0,b1 = 0,b2 = 0;
	for (int i = 1; i <= x+1; i++) {
		a1 = total[i].f.f, a2 = total[i].f.s;
		if (!(st.empty() || (a1 == b1 && a2 == b2))) {
			int tmp = st.size();
			while (!st.empty()) {
				connect[st.top()] += tmp-1;
				st.pop();
			}
		}
		b1 = a1, b2 = a2;
		st.push(total[i].second);
	}
	for (int i = 1; i <= x; i++) {
		printf("%d ",connect[i]+1);
	}
}

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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 2e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2, class T3> void add( T1 &x, T2 y, T3 m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2, class T3> void sub( T1 &x, T2 y, T3 m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

vector<int>roads[MAXN], rails[MAXN];
vector<bool>vis(MAXN), vis2(MAXN);
int road_comp[MAXN], road_size[MAXN];
int rail_comp[MAXN], rail_size[MAXN], cc;

void roads_dfs( int node )
{
	vis[node] = 1;
	road_comp[node] = cc;
	road_size[cc]++;
	for( int next : roads[node] )
	{
		if( !vis[next] )
		{
			roads_dfs(next);
		}
	}
}

void rails_dfs( int node )
{
	vis2[node] = 1;
	rail_comp[node] = cc;
	rail_size[cc]++;
	for( int next : rails[node] )
	{
		if( !vis2[next] )
		{
			rails_dfs(next);
		}
	}
}

int main()
{
	fastio();

	int n,k,l;
	cin>>n>>k>>l;
	for(int i=0;i<k;i++)
	{
		int u,v;
		cin>>u>>v;
		u--,v--;
		roads[u].pb(v);
		roads[v].pb(u);
	}
	for(int i=0;i<l;i++)
	{
		int u,v;
		cin>>u>>v;
		u--,v--;
		rails[u].pb(v);
		rails[v].pb(u);
	}

	cc = 0;
	for(int i=0;i<n;i++)
	{
		if( !vis[i] )
		{
			roads_dfs(i);
			cc++;
		}
	}

	cc = 0;
	for(int i=0;i<n;i++)
	{
		if( !vis2[i] )
		{
			rails_dfs(i);
			cc++;
		}
	}

	vector<int>order;
	for(int i=0;i<n;i++)
		order.pb(i);

	auto cmp = [&]( int i, int j ) -> bool
	{
		if( road_comp[i] != road_comp[j] )
			return road_comp[i] < road_comp[j];
		return rail_comp[i] < rail_comp[j];
	};

	sort(all(order), cmp);

	vector<int>ans(n);
	for(int i=0;i<n;)
	{
		int a = road_comp[order[i]], b = rail_comp[order[i]];
		int j = i;
		while( j < n && road_comp[order[j]] == a && rail_comp[order[j]] == b ) j++;
		for(int k=i;k<j;k++)
			ans[order[k]] = j-i;
		i = j;
	}

	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";

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


/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    int N;cin >> N;
    vector<int> retu(N*2);
    for(int i = 0;i<N*2;i++) cin >> retu.at(i);
    sort(retu.begin(),retu.end());
    int ans = 0;
    for(int i = 0;i<N*2;i+=2){
        ans += min(retu.at(i),retu.at(i+1));
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(in) in.begin(), in.end()

ll base[65];

void smallAns(ll x){
    for(ll i = 60 ; i >= 0 ; i--){
        if((x>>i) & 1){
            if(base[i] == 0){
                base[i] = x;    return;
            }
            x ^= base[i];
        }
    }
}

int main(){
    FIO;
    ll n;   cin >> n;
    ll check = 0;
    vector<ll> v;
    for(ll i = 0 ; i < n ; i++){
        ll x;   cin >> x;   v.push_back(x);
        check ^= x;
    }
    for(ll i = 0 ; i < n ; i++){
        v[i] &= (~check);
        smallAns(v[i]);
    }
    ll ans = 0;
    for(ll i = 60 ; i >= 0 ; i--){
        ans = max(ans, ans^base[i]);
    }
    ans = ans + (ans ^ check);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long double n, m, d ;
    cin >> n >> m >> d ;
    if(d==0){
        cout << SP(10) << (m-1)/n <<endl ;
    }
    else if(2*d<=n){
        cout << SP(10) << (d+d+(n-2*d)*2)*(m-1)/(n*n) <<endl ;
    }
    else{
        cout << SP(10) << (2*d-2*n)*(m-1)/(n*n) <<endl ;
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for(int i = 0; i < k; i++) {
        if(i % 2 == 0) {
            if(a % 2 != 0) {
                a--;
            }
            int h = a / 2;
            a = h;
            b += h;
        } else {
            if(b % 2 != 0) {
                b--;
            }
            int h = b / 2;
            b = h;
            a += h;
        }
    }
    cout << a << " " << b << "\n";
    return 0;
}


#include <cstdio>
#include <cstring>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)

using namespace std;

typedef long long LL;
const int N = 110;

int d[N], cd;
LL f[N][N][2][2];

LL dfs(int l, int r, int g0, int g1, int gf)
{
	if (l < r) return (g0 == g1);
	if (l == r) {
		if (!(d[l] + g1 - g0 * 10)) return 10 - gf;
		return 0;
	}
	if (f[l][r][g0][g1] != -1) return f[l][r][g0][g1];
	LL ret = 0;
	Rep0(i, 9) {
		int tmp = d[r] + i + g1, tg1 = 0;
		if (tmp >= 10) tmp -= 10, tg1 = 1;
		if (!tmp && gf) continue;
		if (d[l] + tmp - g0 * 10 == i)
			ret += dfs(l - 1, r + 1, 0, tg1, 0);
		if (d[l] + tmp - g0 * 10 + 1 == i)
			ret += dfs(l - 1, r + 1, 1, tg1, 0);
	}
	return f[l][r][g0][g1] = ret;
}

int main()
{
	int D;
	scanf("%d", &D);
	while (D) d[++ cd] = D % 10, D /= 10;

	memset(f, -1, sizeof(f));
	LL ans = 0;
	for (int i = cd; i <= 18; i ++){
		ans += dfs(i, 1, 0, 0, 1);
	//	printf("%d %lld\n", i, dfs(i, 1, 0, 0, 1));
	}
	printf("%lld\n", ans);

	return 0;
}
/*
45936
*/

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

int main()
{
    long long N;
    cin >> N;
    long long c = N*(N+1)/2;
    long long j = N / 3;
    long long k = N / 5;
    long long l = N / 15;
    c = c - 3*j*(j+1)/2 - 5*k*(k+1)/2 + 15*l*(l+1)/2;
    cout << c;
}


#include <algorithm>
#include <vector>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <bitset>
#include <cstdint>
#include <unordered_map>
using namespace std;

using i64 = int64_t;
using ui64 = uint64_t;
using d64 = long double;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = (1 << 30);
constexpr i64 INF64 = INT64_MAX;
const long double PI = 3.141592653589793;

template <typename T>
void print(const vector<T> vec) {
  for (auto &e : vec) {
    cout << e << " ";
  }
  cout << endl;
}

int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

template <typename T>
vector<T> sieve(const T& n) {
  vector<bool> is_prime(n + 1, true);
  vector<i64> prime;
  is_prime[0] = is_prime[1] = false;
  for (T i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (T j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
  }
  return prime;
}

template <typename T>
vector<T> dijkstra(vector<vector<pair<int, T>>> &G, int s, T INF) {
  vector<T> dist(G.size(), INF);

  using P = pair<int, T>;
  priority_queue<P, vector<P>, greater<P>> que;
  dist[s] = 0;
  que.emplace(s, dist[s]);
  while(!que.empty()) {
    int idx;
    T cost;
    tie(idx, cost) = que.top(); que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : G[idx]) {
      T next_cost = cost + e.second;
      if(dist[e.first] > next_cost) {
        dist[e.first] = next_cost;
        que.emplace(e.first, dist[e.first]);
      }
    }
  }
  return dist;
}

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

  int v, e, r;
  cin >> v >> e >> r;
  vector<vector<pair<int, i64>>> G(v);
  for(int i=0; i<e; i++) {
    int s, t, d; cin >> s >> t >> d;
    G[s].emplace_back(t, d);
  }

  vector<i64> dist = dijkstra(G, r, INF64);
  for(auto &e : dist) {
    if(e == INF64) cout << "INF" << '\n';
    else cout << e << '\n';
  }
}

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int V,E,r;
const int Inf = 10000*100000+100;
ll C[100010];
int main(){
	while(cin >> V >> E >> r && V >0){
		vector< vector< P > > v(V+10);
		for(int i=0;i<E;i++){
			ll s,t,d;
			cin >> s >> t >> d;
			v[s].push_back(make_pair(d,t));
		}
		priority_queue<P> Q;
		Q.push(P(0,r));
		for(int i=0;i<V;i++){
			C[i] = Inf;
		}
		C[r] = 0;
		while(!Q.empty()){
			P t = Q.top();
			ll s = t.second;
			Q.pop();
			if(C[s] < t.first) continue;
			for(int i=0;i<v[s].size();i++){
				P e = v[s][i];
				if(C[e.second] > C[s] + e.first){
					C[e.second] = C[s] + e.first;
					Q.push(make_pair(-C[e.second],e.second));
				}
			}
		}
		for(int i=0;i<V;i++){
			if(C[i] < Inf) cout << C[i] << endl;
			else cout << "INF" << endl;
		}
	}
}
#if 0
所要時間45分程度。ほとんどの部分はテキストを見ながら自力で書いたがうまくいかず，
蟻本(プログラミングコンテストチャレンジブック)(最近友人から譲ってもらった)を見て28行目を追加しAC
「確定しているので無視」ということの意味があまりわかっていなかったらしい。
#endif


#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T>
struct BIT{
  //0オリジンで与える
  vector<T>bit;
  int N;

  BIT(int n):N(n){
    bit.assign(++n,0);
  }

  T sum(int i){
    T s=0;
    ++i;//0オリジンに対応させる
    while(i>0){
      s+=bit[i];
      i-=i&-i;//iから最後の1のビットを減算
    }
    return s;
  }

  void add(int i,T x){
    ++i;//0オリジンに対応させる
    while(i<(int)bit.size()){
      bit[i]+=x;
      i+=i&-i;
    }
  }

  T Lower_bound(T k){
    if(k<=0)
      return 0;
    T x = 0;
    T mul = 1;
    while (mul<N){
      mul *= 2;
    }
    for (T i = mul; i > 0;i/=2){
      if(x+i<=N&&bit[x+i]<k){
        k -= bit[x + i];
        x += i;
      }
    }
    return x;
  }
};

void solve()
{
	int n,q;
	cin>>n>>q;
	vector<int>used(n,-1);
	vector<int>c(n);
	vector<pair<int,int>>v;
	rep(i,n){
		cin>>c[i];
		c[i]--;
		if(used[c[i]]!=-1){
			v.eb(used[c[i]],i);
			used[c[i]]=i;
		}
		else {
			used[c[i]]=i;
		}
	}
	vector<pair<pair<int,int>,int>>query(q);
	rep(i,q){
		cin>>query[i].first.first>>query[i].first.second;
		query[i].first.first--;
		query[i].first.second--;
		query[i].second=i;
	}
	if(!v.empty())sort(rall(v));
	sort(rall(query));
	vector<int>ans(q);
	// for(auto x:v){
	// 	cout<<x.first<<" "<<x.second<<"\n";
	// }
	int pos=0,qpos=0;
	BIT<int>tree(n);
	for(int i=n-1;i>=0;--i){
		while(pos<v.size()&&v[pos].first==i){
			tree.add(v[pos].second,1);
			pos++;
		}
		while(qpos<q&&query[qpos].first.first==i){
			ans[query[qpos].second]=(query[qpos].first.second-query[qpos].first.first+1)-tree.sum(query[qpos].first.second);
			qpos++;
		}
	}
	rep(i,q){
		cout<<ans[i]<<"\n";
	}
}

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

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

typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ul;

struct point { int x, y; } ps[N];

ui fs[N];
ui uf(ui x) { return fs[x] ? fs[x] = uf(fs[x]) : x; }
bool uu(ui x, ui y) {
	x = uf(x); y = uf(y);
	if (x != y) fs[x] = y;
	return x != y;
}

ui p[N];

struct edge { ui u, v, w; };
bool operator<(edge e1, edge e2) { return e1.w < e2.w; }
ui dis(ui u, ui v) { return min(abs(ps[u].x - ps[v].x), abs(ps[u].y - ps[v].y)); }

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0);
#ifdef _DEBUG
	ifstream cin("1.in");
#endif
	ui n; cin >> n;
	ul ans = 0;
	for (ui i = 1; i <= n; ++i) cin >> ps[i].x >> ps[i].y;
	iota(p, p + n, 1);
	vector<edge> ev;

	sort(p, p + n, [](ui i1, ui i2) { return ps[i1].x < ps[i2].x; });
	ui i = 0;
	while(i != n - 1) {
		ui u = p[i], v = p[i + 1];
		if (ps[u].x == ps[v].x) uu(u, v);
		else ev.push_back({ u, v, dis(u, v) });
		++i;
	}

	sort(p, p + n, [](ui i1, ui i2) { return ps[i1].y < ps[i2].y; });
	i = 0;
	while(i != n - 1) {
		ui u = p[i], v = p[i + 1];
		if (ps[u].y == ps[v].y) uu(u, v);
		else ev.push_back({ u, v, dis(u, v) });
		++i;
	}

	sort(ev.begin(), ev.end());
	for (edge e : ev)
		if (uu(e.u, e.v))
			ans += e.w;

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


/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

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

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n;
int a[N];
ll p[N];

ll sum(int l, int r) {
	return p[r] - p[l - 1];
}
int left(int i) {
	int l = 2, r = i, ans = i;
	while (l <= r) {
		int mid = l + r >> 1;
		if (p[mid - 1] >= p[i] - p[mid - 1]) {
			ans = mid, r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	return ans;
	// return {max(p[ans - 1], p[i] - p[ans - 1]), min(p[ans - 1], p[i] - p[ans - 1])};
}
int right(int i) {
	int l = i + 1, r = n - 1, ans = i + 1;
	while (l <= r) {
		int mid = l + r >> 1;
		if (p[mid] - p[i] <= p[n] - p[mid]) {
			ans = mid, l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	return ans;
	// return {max(p[n] - p[ans], p[ans] - p[i]), min(p[n] - p[ans], p[ans] - p[i])};
}
ll ans = linf;
void upd (pair <ll, ll> x, pair <ll, ll> y) {
	ans = min(ans, max(x.f, y.f) - min(x.s, y.s));
}
void upd(ll x, ll y, ll z, ll w) {
	// cout << x << ' ' << y << ' ' << z << ' ' << w << nl;b
	ans = min(ans, max({x, y, z, w}) - min({x, y, z, w}));
}
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
		p[i] = p[i - 1] + a[i];
	}
	rep(i, 2, n - 1) {
		// i = 4;
		int l = left(i), r = right(i);
		// cout << l << ' ' << r << nl;
		upd(sum(l, i), sum(1, l - 1), sum(i + 1, r), sum(r + 1, n));
		if (l > 2) {
			upd(sum(l - 1, i), sum(1, l - 2), sum(i + 1, r), sum(r + 1, n));
			if (r + 2 <= n) {
				upd(sum(l - 1, i), sum(1, l - 2), sum(i + 1, r + 1), sum(r + 2, n));
			}
		}
		if (r + 2 <= n) {
			upd(sum(l, i), sum(1, l - 1), sum(i + 1, r + 1), sum(r + 2, n));
		}
		/* pair <ll, ll> l = left(i), r = right(i);
		cout << l.f << ' ' << l.s << nl;
		cout << r.f << ' ' << r.s << nl;
		l.f = max(l.f, r.f);
		l.s = min(l.s, r.s);
		ans = min(ans, l.f - l.s);
		break; */
		// break;/b/
	}
	cout << ans;
	ioi
}

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

const int N = 220000;

int n;
long long a[N], sum[N];
int L[N], R[N];

inline long long calc(int st, int en, int p, int q) {
	long long s = sum[en] - sum[st - 1];
	long long s1 = sum[q] - sum[p - 1];
	long long s2 = s - s1;
	return abs(s1 - s2);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	L[2] = 1;
	for (int i = 3; i <= n; i++) {
		L[i] = L[i - 1];
		while (L[i] + 1 < i && calc(1, i, 1, L[i]) > calc(1, i, 1, L[i]+1)) L[i]++;
	}
	R[n - 1] = n;
	for (int i = n - 2; i >= 1; i--) {
		R[i] = R[i + 1];
		while (R[i] - 1 > i && calc(i, n, R[i], n) > calc(i, n, R[i] - 1, n)) R[i]--;
	}
	long long ans = LLONG_MAX;
	for (int i = 2; i <= n - 1; i++) {
		vector<long long> v;
		v.push_back(sum[L[i]]);
		v.push_back(sum[i] - sum[L[i]]);
		v.push_back(sum[R[i + 1] - 1] - sum[i]);
		v.push_back(sum[n] - sum[R[i + 1] - 1]);
		sort(v.begin(), v.end());
		ans = min(ans, v[3] - v[0]);
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll D, G;
  cin >> D >> G;
  G /= 100;

  ll max_p = 300000;
  vll dp(max_p, INF);
  dp[0] = 0;
  rep(i, D + 1) {
    if (i == 0) continue;
    ll p, c;
    cin >> p >> c;
    c /= 100;

    vll next = dp;
    rep(j, p + 1) {
      if (p == 0) continue;
      rep(k, max_p) {
        ll ni = k + i * j;
        if (ni >= max_p) continue;
        if (j == p) ni += c;
        next[ni] = min(next[ni], dp[k] + j);
      }
    }
    dp = next;
  }

  ll ans = INF;
  rep2(i, G, max_p) {
    ans = min(ans, dp[i]);
  }
  ANS;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
/* ちゃんと考えてわかって実装 */

int main(void){
    ll d, g;
    cin >> d >> g;
    vector<P> pc;
    for(int i=0; i<d; i++){
        ll tmpp, tmpc;
        cin >> tmpp >> tmpc;
        pc.push_back(P(tmpp, tmpc));
    }

    ll ans = 10000000000000000;
    for(int i=0; i<(1<<d); i++){
        ll tmp_ans = 0;
        ll tmp_score = 0;
        priority_queue<ll> mada;
        for(int j=0; j<d; j++){
            if(i>>j & 1){
                tmp_ans += pc[j].first;
                tmp_score += 100 * (j+1) * pc[j].first;
                tmp_score += pc[j].second;
            }
            else{
                for(int k=0; k<pc[j].first-1; k++){
                    mada.push(100 * (j+1));
                }
            }
        }
        while(tmp_score < g && !mada.empty()){
            tmp_score += mada.top();
            mada.pop();
            tmp_ans++;
        }
        if(tmp_score >= g){
            ans = min(ans, tmp_ans);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int P[2];
  for(int i = 0; i < 2; i++){
    vector<int> point(10);
    for(int j = 0; j < 10; j++){
      cin >> point[j];
    }
    sort(point.rbegin(), point.rend());
     P[i] = point[0] + point[1] + point[2];
  }
  cout << P[0] << " " << P[1] << endl;
}

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

int main() {
	vector<int> p[2];
	int tmp;
	for(int j=0;j<2;j++){
	for(int i=0;i<10;i++){
		cin >> tmp;
		p[j].push_back(tmp);
	}
	sort(p[j].begin(),p[j].end(),greater<int>());
	int sum=0;
	for(int i=0;i<3;i++)
	sum+=p[j][i];
	cout << sum;
	if(!j)
	cout << " ";
	else
	cout << endl;
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e6 + 10, MAX = 30;
int n;
string s, t;
vector <int> indx[MAX];
int nxt[MAXN];
bitset <MAXN> b;

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

    cin >> n >> s >> t;

    for (int i = 0; i < n; ++i)
        indx[s[i] - 'a'].push_back(i);

    int point = n - 1;
    for (int i = n - 1; i >= 0; --i) {
        while (!indx[t[i] - 'a'].empty() && (indx[t[i] - 'a'].back() > point || indx[t[i] - 'a'].back() > i))
            indx[t[i] - 'a'].pop_back();
        if (indx[t[i] - 'a'].empty())
            return cout << -1, 0;
        int k = indx[t[i] - 'a'].back();
        point = k;
        if (!b[k])
            nxt[k] = i;
        b[k] = true;
    }

    vector <pair <int, int>> vctr;
    for (int i = 0; i < n; ++i)
        if (b[i] && i != nxt[i])
            vctr.push_back({i, nxt[i]});
    // for (auto i : vctr)
    //     cout << i.first << ';' << i.second << ' ';
    int res = 0;
    int sz = vctr.size();
    point = sz - 1;
    for (int i = sz - 1; i >= 0; --i) {
        while (point > i && vctr[point].first - point + i >= vctr[i].second)
            --point;
        res = max(res, point - i + 1);
    }
    cout << res;
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

int n,ans;
char a[1000005],t[1000005];
int pre;

queue<int>Q;

int same(){
	for(int i=1;i<=n;i++){
		if(a[i]!=t[i])return 0;
	}return 1;
}

int main(){
	scanf("%d",&n);
	scanf("%s",a+1);
	for(int i=1;i<=n;i++)a[i]-='a'-1;
	scanf("%s",t+1);
	for(int i=1;i<=n;i++)t[i]-='a'-1;
	if(same()){
		printf("0\n");
		return 0;
	}int i=n,pre=0;
	for(int j=n;j;j--){
		i=min(i,j);
		while(i&&a[i]!=t[j])i--;
		if(i==0){
			printf("-1");
			return 0;
		}if(i==pre)continue;
		pre=i;
		while((!Q.empty())&&j<=Q.front()-Q.size())Q.pop();
		Q.push(pre);
		ans=max(ans,(int)Q.size());
	}printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#define rep(i, n) for(i=0;i<(n);++i)
int a[11][11], n, i, j, t;
int main()
{
    while (scanf("%d", &n), n) {
        memset(a, 0, sizeof(a));
        rep(i, n) rep(j, n) {
            scanf("%d", &t); a[i][j] = t; a[n][j] += t; a[i][n] += t;
        }
        rep(i, n) a[n][n] += a[i][n];
        rep(i, n+1) {
            rep(j, n+1) printf("%5d", a[i][j]);
            puts("");
        }
    }
    return 0;
}

#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

char sub(char ch){
	if(ch=='a')return 'z';
	else return ch-1;
}

bool solve(string s){
	string tmp="";
	rep(i,s.size()){
		if(isalpha(s[i])){
			tmp+=s[i];
		}
		else{

			if( tmp=="the" || tmp=="this" || tmp=="that" )return true;

			tmp="";
		}
	}
	return false;
}

int main(){
	string s;
	while(getline(cin,s)){
		while(1){
			rep(i,s.size()){
				if(isalpha(s[i]))s[i]=sub(s[i]);
			}
			if(solve(s))break;
		}
		cout<<s<<endl;
	}
}


#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
using namespace std;
const int N=105;
char mp[N][N];
int n,m,ex,ey,ans,dp[N][N][N];
int sr[N][N],sc[N][N];
void mx(int &x,int y){x<y?x=y:0;}
int main(){
	scanf("%d%d",&n,&m);
	memset(dp,233,sizeof(dp));
	For(i,1,n) scanf("%s",mp[i]+1);
	For(i,1,n) For(j,1,m){
		if (mp[i][j]=='o') sr[i][j]=sc[i][j]=1;
		else if (mp[i][j]=='E') ex=i,ey=j;
		sr[i][j]+=sr[i][j-1],sc[i][j]+=sc[i-1][j];
	}
	int L=ey-1,R=m-ey,U=ex-1,D=n-ex; dp[0][0][0]=0;
	For(l,0,L) For(r,0,R) For(u,0,U) For(d,0,D){
		int v=dp[r][u][d]; ans=max(ans,v);
		int up=max(ex-u,d+1),dn=min(ex+d,n-u),le=max(ey-l,r+1),ri=min(ey+r,m-l);
		if (up>dn||le>ri) continue;
		if (u<U-d) mx(dp[r][u+1][d],v+sr[ex-u-1][ri]-sr[ex-u-1][le-1]);
		if (d<D-u) mx(dp[r][u][d+1],v+sr[ex+d+1][ri]-sr[ex+d+1][le-1]);
		if (r<R-l) mx(dp[r+1][u][d],v+sc[dn][ey+r+1]-sc[up-1][ey+r+1]);
		if (l<L-r) mx(dp[r][u][d],v+sc[dn][ey-l-1]-sc[up-1][ey-l-1]);
	}
	printf("%d",ans);
}

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

using ll = long long;

constexpr ll mod = 1000000007;

int solve() {
	int N, M; cin >> N >> M;
	ll r = 0, c = 0;
	vector<bool> nr(N*M, false), nc(N*M, false);
	for (int i = 0; i < N; i++) {
		int x; cin >> x; x--; if (nr[x]) return 0;
		nr[x] = true;
	}
	for (int i = 0; i < M; i++) {
		int x; cin >> x; x--; if (nc[x]) return 0;
		nc[x] = true;
	}
	ll res = 1;
	for (int i = N * M - 1; i >= 0; i--) {
		if (nr[i]) r++;
		if (nc[i]) c++;
		if (nr[i] && nc[i]) continue;
		else if (nr[i]) res *= c;
		else if (nc[i]) res *= r;
		else res *= (r * c - (N * M - 1 - i));
		res %= mod;
	}
	return res;
}

int main() {
	cout << solve() << endl;
}