/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e6+10;
const int INF = numeric_limits<int>::max() / 4;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
const int mod = 998244353 ;
int fac[N],inv[N];
int n,m;
int ppow(int a,int b=mod-2)
{
    int ans=1%mod;
    a%=mod;
    while(b)
    {
        if(b&1)
            ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
void init()
{
    fac[0]=1;
    for(int i=1; i<N; ++i)
        fac[i]=fac[i-1]*i%mod;
    inv[N-1]=ppow(fac[N-1]);
    for(int i=N-2; i>=0; --i)
        inv[i]=(i+1)*inv[i+1]%mod;
}
int C(int n,int m)
{
    if(m<0||m>n)return 0;
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main()
{
    fio
    init();
    cin>>n>>m;
    int ans=0;
    for(int i=1; i<=m; ++i)
    {
        int x=i,sum=1;
        vector<int>temp;
        for(int j=2; j*j<=x; ++j)
        {
            int cnt=0;
            while(x%j==0)
            {
                x/=j;
                cnt++;
            }
            if(cnt)
                temp.push_back(cnt);
        }
        if(x>1)temp.push_back(1);
        for(int b : temp)
            sum=sum*C(n+b-1,b)%mod;
        ans=(ans+sum)%mod;
    }cout<<ans;
    return 0;
}

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

#define ll long long
const int maxn = 1e6+1;
const int neginf  = -1*1e8;

int main(){
    vector<ll> arr(maxn+1, 0);
    ll l, r; cin>>l>>r;
    for(ll i = 2; i <= r; i++){
        if(arr[i]!=0)continue;
        for(ll j = i; j<= r; j+= i)arr[j]++;
        for(ll j = i*i; j<= r; j+= i*i) arr[j] = neginf;
    }
    ll ans = 0;
    for(int i = 2; i<= r; i++){
        if(arr[i]<0) continue;
        ll num = (r/i) - ((l-1)/i);
        ll temp = (num*(num-1))/2;
        if(arr[i]%2) ans += temp;    // odd number of prime factors are included
        else ans -= temp;            // even number of prime factors are excluded
    }

    for(int i = max(2ll, l); i<=r; i++) ans -= ((r/i)-1);
    cout<<ans*2;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// int    gc(int    n){
//     if(n<1){
//         return 0;
//     }
//     return n+gc(n-1);
// }

int main()
{
  int n;
  cin>>n;
//   int    hi=n;
//   int    lo=1;
//   int    mid;
//   while(hi-lo>1){
//       mid=(hi+lo)/2;
//       if(gc(mid)<n) lo=mid+1;
//       else hi=mid;
//   }
//   if(gc(lo)>=n){
//       cout<<lo;
//   }
//   else cout<<hi;
// //  cout<<gc(n);
int sum=0;
int i=1;
    while(1){
        sum=sum+i;
        if(sum>=n){
            cout<<i;
            break;
        }
        i++;
    }

    return 0;
}

// youngjinp20
// 2021 06

#include<stdio.h>
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>

#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define byr(x) [](const auto& a, const auto& b) { return a.x > b.x; }
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

typedef long long ll;

int main() {
	int N;
	cin >> N;
	int i=0;
	int ct=0;
	for (; N > ct; ct += ++i);
	cout << i;

	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
const int N=4e5+5;
char a[N];
const int sum='B'+'W'+'R';
inline char ch(char x,char y)
{
	if(x==y)return x;
	return sum-x-y;
}
int main()
{
	int n;cin>>n>>a+1;
	for(int i=177147;i;i/=3)
	{
		if(n<=i)continue;
		for(int j=1;j<=n-i;++j)
		a[j]=ch(a[j],a[j+i]);
		n-=i;
		if(n<=i)continue;
		for(int j=1;j<=n-i;++j)
		a[j]=ch(a[j],a[j+i]);
		n-=i;
	}
	for(;n>1;n--)
		for(int i=1;i<n;++i)
		a[i]=ch(a[i],a[i+1]);
	cout<<a[1];
	return 0;
}

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

#include <iostream>
#include <cassert>

template<long long mod>
class modint{
private:
  using T = long long;
  T a;
public:
  constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {}
  constexpr T& value() noexcept { return a; }
  constexpr const T& value() const noexcept { return a; }
  constexpr modint operator-() const noexcept {
    return modint(0) -= *this;
  }
  constexpr modint operator+(const modint& rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint& rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint& rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint& rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint& rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint& rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint& rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(const modint& rhs) noexcept {
    return *this *= rhs.inv();
  }
  constexpr bool operator==(const modint& rhs) const noexcept {
    return a == rhs.a;
  }
  constexpr bool operator!=(const modint& rhs) const noexcept {
    return not (*this == rhs);
  }
  constexpr modint pow(long long k) const noexcept {
    modint ret(1);
    modint x = k > 0 ? *this : this->inv();
    k = abs(k);
    while(k > 0){
      if(k&1) ret *= x;
      x *= x;
      k >>= 1;
    }
    return ret;
  }
  constexpr modint inv() const noexcept {
    return pow(mod-2);
  }
  friend std::ostream& operator<<(std::ostream &os, const modint &X) noexcept {
    return os << X.a;
  }
  friend std::istream& operator>>(std::istream &is, modint &X) noexcept {
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<3>;
  int n;
  string c;
  cin >> n >> c;
  string C = "BWR";

  vector<vector<mint>> T(3,vector<mint>(3));
  for(int i = 0; i < 3; ++i){
    T[i][0] = 1;
    T[i][i] = 1;
  }
  for(int i = 1; i < 3; ++i){
    for(int j = 1; j < i; ++j){
      T[i][j] = T[i-1][j] + T[i-1][j-1];
    }
  }
  auto comb = [&](int x, int y){
    mint ret = 1;
    while(x > 0 or y > 0){
      int a = x%3, b = y%3;
      ret *= T[a][b];
      x /= 3;
      y /= 3;
    }
    return ret;
  };
  mint t = 0;
  for(int i = 0; i < n; ++i){
    int a = C.find(c[i]);
    t += comb(n-1,i)*a;
  }
  for(int i = 0; i+1 < n; ++i)
    t *= 2;
  cout << C[t.value()] << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <iomanip>

#include <fstream>

using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define N 100000
struct edge{ll to,cost,k; };
vector<edge> G[N+1];
ll d[N+1];

void dijkstra(ll s){
    fill(d,d+(N+1),inf);
    d[s]=0;
    priority_queue<l_l,vector<l_l>,greater<l_l>> que;
    que.push(l_l(0,s));
    while(!que.empty()){
        l_l p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first)continue;
        if(G[v].size()>0){
            rep(i,0,G[v].size()-1){
                edge e=G[v][i];
                ll k=e.k;
                ll time= k*((d[v]+k-1)/k) + e.cost;
                if(d[e.to]>time){
                    d[e.to]=time;
                    que.push(l_l(d[e.to],e.to));
                }
            }
        }
    }
}

int main(){fastio
    ll n,m,x,y;cin>>n>>m>>x>>y;
    ll a[m],b[m],t[m],k[m];
    rep(i,0,m-1)cin>>a[i]>>b[i]>>t[i]>>k[i];
    rep(i,0,m-1){
        edge e;
        e.to=b[i];
        e.cost=t[i];
        e.k=k[i];
        G[a[i]].pb(e);
        e.to=a[i];
        e.cost=t[i];
        e.k=k[i];
        G[b[i]].pb(e);
    }

    dijkstra(x);
    if(d[y]>=inf){
        cout<<-1<<endl;
    }else{
        cout<<d[y]<<endl;
    }

    return 0;

}

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")*/
// only when really needed

/* GNU G++17 7.3.0: No long long for faster code
   GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */

#include <bits/stdc++.h>

#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long

#define sz(a) (int)a.size()
#define pii pair<int,int>

/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/

#define PI 3.1415926535897932384626433832795
#define INF 1000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6

using namespace std;

signed main() {

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

    int n, ans = INF;
    cin >> n;

    for1(i,1,n) {

        int a, p, x;
        cin >> a >> p >> x;
        if (a < x) ans = min(ans, p);

    }

    if (ans == INF) cout << -1;
    else cout << ans;

}


#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

// template<typename _Ty1, typename _Ty2>
// ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) {
//     _os << '(' <<_p.first << ',' << _p.second << ')';
//     return _os;
// }
//
// template<typename _Ty1, typename _Ty2>
// istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) {
//     _is >> _p.first >> _p.second;
//     return _is;
// }

void solve() {
  ll t, n;
  cin >> t >> n;
  vector<ll> a;
  for(ll i = 1;i <= 100;i++) {
    a.push_back(i + t*i/100);
  }
  vector<ll> b;
  for(int j = 1;j <= (100+t);j++) {
    bool p = false;
    for(ll ch : a) if(ch == j) p = true;
    if(p == false) b.push_back(j);
  }

  int m = b.size();
  ll x = ceil(n*1.0/m);
  ll y = (n % m == 0) ? m-1 : ((n%m)-1);
  y = b[y];

  cout << (100+t)*(x-1) + y << endl;

}

// dp[i][j][ib][jb][k] // O(N^4)
// A + A*2/100 (1<=t <=50)
//
// t = 1 -> 100, 201, 302, 403, .....
// t = 2 -> 50, 101,
// t = 3 -> 34, ..
// t = 4 ->
//
// t=2
// A + 2A/100
// 1 2 ... 49 (50) 51 52 .... 100 (101) 102   151 153
//
//
//      t/100 = 0
//      2t/100
//
//
//      100t/100 = t
//
// x = (1+t/100) (2 + 2t/100) ....... (100+100t/100)
//     (101+t+t/100)
//
// x
// (100+t) + x
// (200+2t) + x
// (300+3t) + x

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);

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

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

 return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <iterator>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;

int main()
{
    double t, n;
    cin >> t >> n;
    double ans = (100 + t) * (n / t);
    if (abs(ans - std::floor(ans) == 0)) ans--;
    else ans = std::floor(ans);
    cout << (long long)ans << endl;

    return 0;
}


// Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const int max_n = 1e5 + 9;
const int mod = 1e9 + 7;
const int inf = 1e9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	string s;
	cin >> s;

	int n = s.size();
	deque<char> d;
	int curr = 0;
	for(int i = 0 ; i < n ; i++) {
		if(s[i] == 'R') {
			curr ^= 1;
		}
		else {
			if(curr) {
				d.push_front(s[i]);
			}
			else d.push_back(s[i]);
		}
	}

	string str;
	while(!d.empty()) {
		if(curr) {
			str += d.back();
			d.pop_back();
		}
		else {
			str += d.front();
			d.pop_front();
		}
	}

	stack<char> st;
	for(auto it : str) {
		if(st.empty()) {
			st.push(it);
		}
		else {
			if(st.top() == it)st.pop();
			else st.push(it);
		}
	}

	str = "";
	while(!st.empty()) {
		str += st.top();
		st.pop();
	}

	reverse(all(str));
	cout << str << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ; i++){
		// cout << "Case #" << i << ": ";
		solve();
	}
}

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

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

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x =(x%p+p)%p;
	}
	ll ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;

void ng(){
	cout<<"UNSOLVABLE\n";
	exit(0);
}
void solve()
{
	set<char>st;
	vector<string>s(3);
	rep(i,3)cin>>s[i];

	rep(i,3){
		rep(j,s[i].size()){
			st.emplace(s[i][j]);
		}
	}
	if(st.size()>10){
		ng();
	}
	vector<int>v(10);
	rep(i,10)v[i]=i;
	bool ok=false;
	do{
		vector<int>used(26,-1);
		int pos=0;
		rep(i,3){
			rep(j,s[i].size()){
				if(used[s[i][j]-'a']==-1){
					used[s[i][j]-'a']=v[pos++];
				}
			}
		}
		bool no=false;
		ll x[3]={};
		rep(i,3){
			if(used[s[i][0]-'a']==0)no=true;
		}
		if(no)continue;
		rep(i,3){
			rep(j,s[i].size()){
				x[i]*=10;
				x[i]+=used[s[i][j]-'a'];
			}
		}
		if(x[0]+x[1]==x[2]){
			rep(i,3){
				cout<<x[i]<<"\n";
			}
			return;
		}
	}while(next_permutation(all(v)));
	ng();
}

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


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 > a2) swap(a1, a2);
  if (a2 > a3) swap(a2, a3);
  if (a1 > a2) swap(a1, a2);
  if (a2 - a1 == a3 - a2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;cin>>a>>b>>c;
  a+=b+c;
  cout<<21-a;
  return 0;}


#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>

#define REP_(i, a_, b_, a, b, ...) \
    for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)

using namespace std;
using Int = int64_t;

template <class T>
struct Matrix {
    vector<vector<T>> val;
    Matrix(vector<vector<T>> vec) : val(vec) {}
    Matrix(int64_t n = 1, int64_t m = 1, T v = 0) : val(n, vector<T>(m, v)) {}
    void init(int64_t n, int64_t m, T v = 0) { val.assign(n, vector<T>(m, v)); }
    size_t size() const { return val.size(); }
    vector<T> &operator[](int64_t i) { return val[i]; }
    const vector<T> &operator[](int64_t i) const { return val[i]; }
};

template <class T>
Matrix<T> operator*(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B[0].size());
    Matrix<T> R(A.size(), B[0].size());
    for (int64_t i = 0; i < A.size(); ++i)
        for (int64_t j = 0; j < B[0].size(); ++j)
            for (int64_t k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];

    return R;
}

template <class T>
Matrix<T> operator+(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B.size() && A[0].size() == B[0].size());
    Matrix<T> R(A.size(), A[0].size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t j = 0; j < A[0].size(); ++j) {
            R[i][j] = A[i][j] + B[i][j];
        }
    }
    return R;
}

template <class T>
Matrix<T> operator-(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B.size() && A[0].size() == B[0].size());
    Matrix<T> R(A.size(), A[0].size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t j = 0; j < A[0].size(); ++j) {
            R[i][j] = A[i][j] - B[i][j];
        }
    }
    return R;
}

template <class T>
vector<T> operator*(const Matrix<T> &A, const vector<T> &B) {
    vector<T> v(A.size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t k = 0; k < B.size(); ++k) {
            v[i] += A[i][k] * B[k];
        }
    }
    return v;
}

template <class T>
bool operator==(const Matrix<T> &A, const Matrix<T> &B) {
    assert(A.size() == B.size() && A[0].size() == B[0].size());
    for (int64_t i = 0; i < A.size(); ++i) {
        for (int64_t j = 0; j < A[0].size(); ++j) {
            if (A[i][j] != B[i][j]) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    Int N;
    cin >> N;
    vector<Int> X(N), Y(N);
    REP(i, N) cin >> X[i] >> Y[i];
    Int M;
    cin >> M;
    vector<Matrix<Int>> mats;
    Matrix<Int> mat(3, 3, 0);
    mat[0][0] = 1;
    mat[1][1] = 1;
    mat[2][2] = 1;
    mats.push_back(mat);
    REP(i, M) {
        Int t;
        cin >> t;
        if (t == 1) {
            Matrix<Int> A({{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}});
            mat = A * mat;
        } else if (t == 2) {
            Matrix<Int> A({{0, -1, 0}, {1, 0, 0}, {0, 0, 1}});
            mat = A * mat;
        } else if (t == 3) {
            Int p;
            cin >> p;
            Matrix<Int> A({{-1, 0, 2 * p}, {0, 1, 0}, {0, 0, 1}});
            mat = A * mat;
        } else {
            Int p;
            cin >> p;
            Matrix<Int> A({{1, 0, 0}, {0, -1, 2 * p}, {0, 0, 1}});
            mat = A * mat;
        }
        mats.push_back(mat);
    }

    Int Q;
    cin >> Q;
    REP(i, Q) {
        Int a, b;
        cin >> a >> b;
        --b;
        auto res = mats[a] * vector<Int>({X[b], Y[b], 1});
        cout << res[0] << " " << res[1] << endl;
    }
}

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

#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
    	int n;cin >> n;
    	cout << (n%2 ? "Black" : "White");
    }
}


#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 ll di[4] = {1, 0, -1, 0};
const ll dj[4] = {0, 1, 0, -1};

struct Data {
    ll id, x;  // いまの状態id, 移動距離x
    Data(ll id, ll x): id(id), x(x) {}
    bool operator<(const Data& hoge) const {
        return x > hoge.x;
    }
};

int main() {
    ll h, w, n, m;
    cin >> h >> w >> n >> m;

    vl dp(4*h*w, INF);  // dp[id] : idの状態となる移動距離の最小値(到達不可能ならINF)
    priority_queue<Data> Q;
    auto push = [&](ll id, ll x) {
        if(dp[id] <= x) {
            return;
        }
        dp[id] = x;
        Q.emplace(id, x);
    };

    auto toId = [&](ll i, ll j, ll dir) {
        return 4*(i*w + j) + dir;
    };

    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        rep(dir, 4) {
            push(toId(a, b, dir), 0);
        }
    }

    vvl board(h, vl(w));
    rep(i, m) {
        ll c, d;
        cin >> c >> d;
        c--;  d--;
        board[c][d] = 1;
    }

    // 拡張ダイクストラ法。計算量はO((V+E)*log(V))
    while(!Q.empty()) {
        Data hoge = Q.top();
        Q.pop();
        ll id = hoge.id, x = hoge.x;
        if(dp[id] != x) {
            continue;
        }
        ll i = id/4/w;
        ll j = id/4%w;
        ll dir = id%4;
        // 向きを変えずに直進する場合
        ll ni = i + di[dir];
        ll nj = j + dj[dir];
        if(ni < 0 || h <= ni || nj < 0 || w <= nj) {
            continue;
        }
        if(board[ni][nj]) {
            continue;
        }
        push(toId(ni, nj, dir), x+1);
    }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            bool ok = false;
            rep(dir, 4) {
                if(dp[toId(i, j, dir)] != INF) {
                    ok = true;
                }
            }
            if(ok) {
                ans++;
            }
        }
    }

    out(ans);
    re0;
}

#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int map[1505][1505];           //-1标记block,0暂时没有照亮的地方,1照亮的地方,2标记bulb
typedef struct node {
	int x;
	int y;
}NODE;
int main() {
	int h, w, n, m, ans = 0;
	cin >> h >> w >> n >> m;
	vector<NODE> N, M;
	NODE p;
	memset(map, 0, sizeof(map));
	for (int i = 0; i < n; i++) {
		cin >> p.x >> p.y;
		N.push_back(p);
		map[p.x][p.y] = 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p.x >> p.y;
		M.push_back(p);
		map[p.x][p.y] = -1;
	}
	//for (auto p : N) {      //暴力遍历求解
	//	int x = p.x, y = p.y;
	//	for (int i = y - 1; i > 0; i--) {
	//		if (map[x][i] == -1) break;
	//		if (map[x][i] == 0) map[x][i] = 1;
	//	}
	//	for (int i = y + 1; i <= w; i++) {
	//		if (map[x][i] == -1) break;
	//		if (map[x][i] == 0) map[x][i] = 1;
	//	}
	//	for (int j = x - 1; j > 0; j--) {
	//		if (map[j][y] == -1) break;
	//		if (map[j][y] == 0) map[j][y] = 1;
	//	}
	//	for (int j = x + 1; j <= h; j++) {
	//		if (map[j][y] == -1) break;
	//		if (map[j][y] == 0) map[j][y] = 1;
	//	}
	//}
	int flag = 0;
	for (int i = 1; i <= h; i++) {
		flag = 0;
		for (int j = 1; j <= w; j++) {
			if (map[i][j] == 2) {
				flag = 1; continue;
			}
			else if (map[i][j] == -1) flag = 0;
			if (flag) map[i][j] = 1;
		}
	}
	for (int i = 1; i <= h; i++) {
		flag = 0;
		for (int j = w; j > 0; j--) {
			if (map[i][j] == 2) {
				flag = 1; continue;
			}
			else if (map[i][j] == -1) flag = 0;
			if (flag) map[i][j] = 1;
		}
	}
	for (int j = 0; j <= w; j++) {
		flag = 0;
		for (int i = 0; i <= h; i++) {
			if (map[i][j] == 2) {
				flag = 1; continue;
			}
			else if (map[i][j] == -1) flag = 0;
			if (flag) map[i][j] = 1;
		}
	}
	for (int j = 0; j <= w; j++) {
		flag = 0;
		for (int i = h; i > 0; i--) {
			if (map[i][j] == 2) {
				flag = 1; continue;
			}
			else if (map[i][j] == -1) flag = 0;
			if (flag) map[i][j] = 1;
		}
	}
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			if (map[i][j] > 0)
				ans++;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    stringstream ss10;
    ss10 << dec << i;
    string s10 = ss10.str();
    stringstream ss8;
    ss8 << oct << i;
    string s8 = ss8.str();
    if (s10.find("7") != string::npos) {
      cnt++;
    } else if (s8.find("7") != string::npos) {
      cnt++;
    }
  }

  printf("%d\n", n - cnt);
  return 0;
}

#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<stdio.h>
#include<math.h>
#include<string>
#include<new>
#include<iterator>
using namespace std;
int main()

{int n;
 cin>>n;
 if(n==1){
 	cout<<"0"<<endl;
 }
 else{
 	int k=n-2;
 	cout<<k+1<<endl;
 }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;
  }
  return res;
}

ll mod_inv(ll a, ll m){
	return pow_mod(a,m-2,m);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,p;cin >> n >> p;
    cout << (p-1)*pow_mod(p-2,n-1,mod)%mod << endl;
}

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

ll func(int n, int k){
    return max(0, min(k - 1, 2*n + 1 - k));
}

int main(){
    int n,k;
    cin >> n >> k;
    ll ans = 0;
    rep(i,2,2*n+1){
        ans += func(n, k + i) * func(n, i);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
    a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

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

ll add(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a+b);
}

ll mul(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a*b);
}

ll sub(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a-b);
}

ll divi(ll a, ll b)
{
    b = powa(b,mod-2,mod);
    return mul(a,b);
}

#define N 200005

ll fact[N];
ll ifact[N];

ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll ans = fact[n];
    ans*=ifact[r];
    ans%=mod;
    ans*=ifact[n-r];
    ans%=mod;
    return ans;
}

#define N1 19

int main()
{
  FAST/**/

   fact[0] = 1;
   for(ll i=1;i<N;i++)
        fact[i] = fact[i-1]*i, fact[i]%=mod;
   for(ll i=0;i<N;i++)
        ifact[i] = powa(fact[i],mod-2,mod);

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

   vector<ll> div[m+1];
   for(ll i=1;i<=m;i++)
   {
       for(ll j=i;j<=m;j+=i)
            div[j].pb(i);
   }
   ll dp[N1][m+1];
   memset(dp,0,sizeof(dp));

   for(ll i=1;i<=m;i++)
   {
       dp[1][i] = 1;
       for(ll j=2;j<N1;j++)
       {
           autoit(div[i], it)
           {
               if(*it < i)
                    dp[j][i]+=dp[j-1][*it], dp[j][i]%=mod;
           }
       }
   }

   ll ans = 0;
   for(ll i=1;i<=m;i++)
   {
       for(ll j=1;j<N1;j++)
       {
           ans = add(ans, mul(ncr(n-1, j-1), dp[j][i]));
           //cout<<"for "<<i<<" , "<<j<<" = "<<dp[j][i]<<"\n";
       }
   }
   cout<<ans<<"\n";

   return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
#define X 200010
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}

ll n,a[210],b[210];
vector<ll> A[210],B[210];//A[p]:=(a[i]==p)=なるiのset
bool f[210][210];
bool solve(){
	cin>>n;
	rep(i,n){
		cin>>a[i]>>b[i];
		if(a[i]>=0)a[i]--;
		if(b[i]>=0)b[i]--;
		if(a[i]!=-1&&b[i]!=-1&&a[i]>=b[i])return 0;
		if(a[i]>=0)A[a[i]].push_back(i);
		if(b[i]>=0)B[b[i]].push_back(i);
	}
	rep(i,2*n){
		if(A[i].size()+B[i].size()>1)return 0;
	}//重複なし
	for(int i=0;i<=2*n;i++)for(int j=0;j<=2*n;j++)f[i][j]=0;
	for(int l=0;l<2*n;l+=2){
		for(int k=1;l+2*k<=2*n;k++){
			int r=l+2*k;
			bool ok=1;
			rep(i,n){
				bool va=(l<=a[i]&&a[i]<r);
				bool vb=(l<=b[i]&&b[i]<r);
				if(a[i]>=0&&b[i]>=0){
					if(va==0&&vb==0)continue;
					if(va==1&&vb==1){
						ok&=(a[i]+k==b[i]);
						continue;
					}
					ok=0;
				}
				else if(a[i]==-1&&b[i]==-1)continue;
				else if(a[i]>=0){
					if(va==0)continue;
					if(not(0<=a[i]+k&&a[i]+k<2*n))ok=0;
					else if(A[a[i]+k].size()+B[a[i]+k].size()>0)ok=0;
				}
				else if(b[i]>=0){
					if(vb==0)continue;
					if(not(0<=b[i]-k&&b[i]-k<2*n))ok=0;
					else if(A[b[i]-k].size()+B[b[i]-k].size()>0)ok=0;
				}
			}
			f[l][r]=ok;
			//cerr<<"f["<<l<<"]["<<r<<"]="<<f[l][r]<<endl;
		}
	}
	bool dp[210];
	for(int i=0;i<=2*n;i++)dp[i]=0;
	dp[0]=1;
	for(int i=0;i<2*n;i++){
		if(dp[i]==0)continue;
		for(int j=i+1;j<=2*n;j++){
			if(f[i][j]==1){
				dp[j]=1;
			}
		}
	}
	return dp[2*n];
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<(solve()?"Yes":"No")<<endl;

}


#include <cstdio>
const int maxn=2e5+10;
int a[maxn];
int b[maxn];
int p[maxn];
int f1[maxn];
int f2[maxn];
int ans=0;
int vis[maxn];
int mx=0;
void Dfs1(int x){
	if(vis[x])
		return;
	vis[x]=1;
	if((!mx)||a[x]>a[mx])
		mx=x;
	Dfs1(p[x]);
}
void Dfs2(int x){
	if(x==mx)
		return;
	f1[++ans]=mx;
	f2[ans]=x;
	Dfs2(p[x]);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<=n;i++){
		if(p[i]!=i&&b[p[i]]>=a[i]){
			printf("-1");
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			mx=0;
			Dfs1(i);
			Dfs2(p[mx]);
		}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d\n",f1[i],f2[i]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a,i##_end=b;i<i##_end;++i)
using ll=long long;
using pii=pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int mo=1e9+7;
using L=__int128;
ll Pow(ll a,ll b,ll p=mo){ll r=1;for(;b;b>>=1,a=(L)a*a%p)if(b&1)r=(L)r*a%p;return r;}
//template<typename T>
void inc(int &x,int y){x=(x+y>=mo?x+y-mo:x+y);}
int ad(int x,int y){return x+y>=mo?x+y-mo:x+y;}
template<typename T>T gcd(T a,T b){while(b)a%=b,swap(a,b);return a;}
mt19937 rnd(time(0));
const int N=2e5+11;
int n,a[N],b[N],p[N];
int vis[N];
vector<int> e[N];int m;
void GG(){puts("-1");exit(0);}
vector<pii> ans;
int main(){
#ifdef SGR
	freopen("a.txt","r",stdin);
#endif
	ios::sync_with_stdio(0);
	cin>>n;
	For(i,1,n+1)cin>>a[i];
	For(i,1,n+1)cin>>b[i];
	For(i,1,n+1){
		cin>>p[i];
		if(p[i]!=i&&a[i]<=b[p[i]])GG();
	}
	//int ans=0;
	For(i,1,n+1)if(!vis[i]){
		int x=i;
		do{
			e[m].pb(x);
			vis[x]=1;
			x=p[x];
		}while(x!=i);
		m++;
	}
	For(i,0,m){
		if(e[i].size()<=1)continue;
		int q=0;
		for(int x:e[i])if(a[x]>a[q])q=x;
		assert(q);
		int x=q;
		do{
			if(p[x]==q)break;
			ans.pb(mp(q,p[x]));
			x=p[x];
		}while(x!=q);
	}
	cout<<ans.size()<<endl;
	for(auto w:ans)cout<<w.fi<<" "<<w.se<<"\n";
}


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

enum RideType{
    a,
    b,
    none,
};

struct ride{
    int person_id;
    int other_pos;
    RideType ride_type;
};

int main(){
    int n;
    cin >> n;
    vector<ride> v(2*n+1, {-1, -1, RideType::none});
    for(int i=1; i<=n; ++i){
        int a, b;
        cin >> a >> b;
        if(a>0){
            if(v[a].ride_type != RideType::none){
                // 重複した入力なので NG
                cout << "No" << endl;
                return 0;
            }
            v[a]={i, b, RideType::a};
        }
        if(b>0){
            if(v[b].ride_type != RideType::none){
                // 重複した入力なので NG
                cout << "No" << endl;
                return 0;
            }
            v[b]={i, a, RideType::b};
        }
    }
    // dp[i] = 2*i 階まで OK
    vector<bool> dp(n+1, false);
    dp[0]=true;
    for(int i=0; i<=n; ++i){
        if(!dp[i])continue;
        for(int j=i+1; j<=n; ++j){
            // すでに到達できるならそれはそれでいい
            if(dp[j]) continue;
            // 2*i+1, ..., 2*j 階まで OK か確認する
            // ここが 「乗る, 乗る, ..., 乗る, 降りる, ..., 降りる」という形になるなら、幅は j-i
            dp[j]=true;
            for(int k=1; k<=j-i; ++k){
                const auto &va = v[2*i+k];
                const auto &vb = v[i+j+k];
                if(va.ride_type == RideType::a && vb.ride_type == RideType::b){
                    // 乗る人と降りる人が同じか確認
                    if(va.person_id != vb.person_id){
                        dp[j]=false;
                        break;
                    }
                }else if(va.ride_type == RideType::a && vb.ride_type == RideType::none){
                    // 乗る人が別の場所で降りないか確認
                    if(va.other_pos != -1){
                        dp[j]=false;
                        break;
                    }
                }else if(va.ride_type == RideType::none && vb.ride_type == RideType::b){
                    // 降りる人が別の場所で乗らないか確認
                    if(vb.other_pos != -1){
                        dp[j]=false;
                        break;
                    }
                }else if(va.ride_type == RideType::none && vb.ride_type == RideType::none){
                    // 両方 none なら適切に assign できる
                    continue;
                }else{
                    // a, b を混同しているパターンは NG
                    dp[j]=false;
                    break;
                }
            }
        }
    }
    cout << (dp[n]?"Yes":"No") << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }

    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}

long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

using namespace std;
//using namespace atcoder;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  //using namespace std;

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

  //記録がおかしいケースを排除
  vector<int> cnt(2 * n + 1);
  REP(i, n){
    if(a[i] >= 0 && b[i] >= 0 && a[i] >= b[i]){
      cout << "No" << endl;
      return 0;
    }
    if(a[i] >= 0){
      cnt[a[i]]++;
      if(cnt[a[i]] > 1){
        cout << "No" << endl;
        return 0;
      }
    }
    if(b[i] >= 0){
      cnt[b[i]]++;
      if(cnt[b[i]] > 1){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  vector<int> c(2 * n + 1, -1); //その階で取るべきcの値
  REP(i, n){
    if(a[i] >= 0 && b[i] >= 0){
      int tc = b[i] - a[i] - 1;
      for(int j = a[i]; j <= b[i]; j++){
        if(c[j] < 0){
          c[j] = tc;
          continue;
        }
        if(c[j] == tc) continue;
        cout << "No" << endl;
        return 0;
      }
    }
  }

  REP(i, n){
    if(a[i] >= 0 && b[i] >= 0) continue;
    if(a[i] < 0 && b[i] < 0) continue;
    if(a[i] < 0){
      if(c[b[i]] < 0) continue;
      int ta = b[i] - c[b[i]] - 1;
      if(cnt[ta] < 1){
        a[i] = ta;
        cnt[a[i]]++;
        continue;
      }
      cout << "No" << endl;
      return 0;
    }else{
      if(c[a[i]] < 0) continue;
      int tb = c[a[i]] + a[i] + 1;
      if(cnt[tb] < 1){
        b[i] = tb;
        cnt[b[i]]++;
        continue;
      }
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

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

int main(void){

    int cnt = 0;
    int a[1010],n;
    int same=0;

    cin >> n;
    rep(i,n) cin >> a[i];
    sort(a,a+n);

    rep(j,n){
        if(same == a[j]) {
            cout << "No" <<  endl;
            return 0;
        }else{
            same = a[j];
        }
    }

    cout << "Yes" <<  endl;
    return 0;
}

#include<bits/stdc++.h>
#include<tuple>
typedef long long ll;
#define INF 9999999999
#define mod 998244353
#define eps 1e-12
using namespace std;
typedef tuple<ll,ll,ll,ll>tu;
ll n;
string s,t;
vector<ll>a,b;
int main(){
    ll i,j;
    ios::sync_with_stdio(0);
    cin>>n;
    cin>>s>>t;
    for(ll i=0;i<s.size();i++)
        if(s[i]=='0')
            a.push_back(i);
    for(ll i=0;i<t.size();i++)
        if(t[i]=='0')
            b.push_back(i);
    if(a.size()!=b.size())
        cout<<-1<<endl;
    else{
        ll ans=0;
        for(ll i=0;i<a.size();i++)
            if(a[i]!=b[i])
                ans++;
        cout<<ans<<endl;
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=1e5+5;

#define SIEVE
int primes[N];
vector<int> pr;
void sieve(){
	for(int i=2;i<N;i++){
		if(primes[i]==0){
			pr.pb(i);
			for(int j=i*i;j<N;j+=i){
				primes[j]=1;
			}
		}
		primes[i]^=1;
	}
}

int fact(int n)
{
    if (n==1 || n==0)
    {
        return 1;
    }
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
int nCr(int n, int r)
{
    if (n==0 || r>n)
    {
        return 0;
    }
    return fact(n) / (fact(r) * fact(n - r));
}

int nC2(int n) {
    if (n < 2)
        return 0;
    assert(n < 3.0e9);
    return n * (n - 1) / 2;
}

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

    if (n<0)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<n<<endl;
    }
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
//	cin>>t;
	while(t--) solve();
	return 0;
}

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

    int x;
    cin>>x;
    if(x>=0){
        cout<<x<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll txtc; cin>>txtc; while(txtc--)
typedef long long int ll;
int main() {
    FIO;
    ll n,m; cin>>n>>m;
    vector<ll>a(n),b(m);
    for(auto &it:a) cin>>it;
    for(auto &it:b) cin>>it;
    vector<vector<ll>>dp(n+1,vector<ll>(m+1,mod));
    for(ll i=n;i>=0;i--){
        for(ll j=m;j>=0;j--){
            if(i==n || j==m){
                dp[i][j]=(n-i)+(m-j);
            }
            else{
                if(a[i]==b[j]){
                    dp[i][j]=dp[i+1][j+1];
                }
                else{
                    dp[i][j]=min({dp[i+1][j],dp[i][j+1],dp[i+1][j+1]})+1;
                }
            }
        }
    }
    cout<<dp[0][0]<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

using namespace std;

template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}

using ll = long long;
const ll INF = LLONG_MAX;
const double PI = acos(-1);

const ll mod = 1e9 + 7; //998244353;

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 modpow(ll a,ll b){
    if(b == 0){
        return 1;
    }
    if(b%2 == 0){
        ll tmp = modpow(a,b/2);
        return tmp*tmp%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }

}

template <typename T>
struct RMQ {
    const T INF = numeric_limits<T>::max();
    T bound;  //最小値のときはinf,それ以外の時0となる
    int n;
    bool flag; //最大値でtrue
    vector<T> dat;
    RMQ(int n_) : n(),dat(n_ * 4,-1){
        int x = 1;
        while(n_ > x){
            x *= 2;
        }
        n = x;
    }

    T func(T a,T b){
        if(a == -1)return b;
        if(b == -1)return a;
        return a^b;
    }

    void update(int i,T x){
        i += n - 1;
        dat[i] = x;
        while(i > 0){
            i = (i-1)/2;
            dat[i] = func(dat[i*2+1],dat[i*2+2]);
        }
    }

    T query(int a,int b){
        return query_sub(a,b,0,0,n);
    }

    T query_sub(int a,int b,int k,int l,int r){
        if(r <= a || b <= l){
            return -1;
        }else if(a <= l && r <= b){
            return dat[k];
        }else{
            T v_l = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T v_r = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return func(v_l, v_r);
        }
    }

};

ll dp[1005][1005];
int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vl a(n),b(m);
    cin >> a;
    cin >> b;

    rep(i,n+1){
        rep(j,m+1){
            if(i == 0 || j == 0){
                dp[i][j] = max(i,j);
                continue;
            }
            ll tmp = min(dp[i][j-1] + 1,dp[i-1][j] + 1);
            tmp = min(tmp,dp[i-1][j-1] + (a[i-1] == b[j-1] ? 0 : 1));
            dp[i][j] = tmp;
        }
    }

    cout << dp[n][m] << endl;

    return 0;

}


#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
const int N = 200005;
int d[N] = { 0 }, ans[N] = { 0 }, id2 = 0, tol = 0;
bool u[N] = { 0 };
vector<int> my[N];

void dfs(int x) {
    int i = 0, y = 0;
    for (i = 0; i < my[x].size(); i ++) {
        y = my[x][i];
        if (d[y]) continue;
        d[y] = d[x] + 1;
        dfs(y);
    }
}
void dfs2(int x) {
    int i = 0, y = 0;
    for (i = 0; i < my[x].size(); i ++) {
        y = my[x][i];
        if (d[y]) continue;
        d[y] = d[x] + 1;
        dfs2(y);
        if (u[y]) u[x] = true;
    }
    if (x == id2) u[x] = true;
}

void dfs3(int x) {
    ans[x] = ++ tol;
    int s = 0, i = 0, y = 0;
    for (i = 0; i < my[x].size(); i ++) {
        y = my[x][i];
        if (d[y]) continue;
        if (u[y]) {
            s = y;
            continue;
        }
        d[y] = d[x] + 1;
        dfs3(y);
        ++ tol;
    }
    if (s) {
        d[s] = d[x] + 1;
        dfs3(s);
        ++ tol;
    }
}

void solve() {
    int i = 0, n = 0, id = 0, p = 0, q = 0;
    scanf("%d", &n);
    for (i = 1; i < n; i ++) {
        scanf("%d%d", &p, &q);
        my[p].push_back(q);
        my[q].push_back(p);
    }
    d[1] = 1;
    dfs(1);
    id = 1;
    for (i = 2; i <= n; i ++) {
        if (d[i] > d[id]) id = i;
    }
    memset(d, 0, sizeof(d));
    d[id] = 1;
    dfs(id);
    id2 = 1;
    for (i = 2; i <= n; i ++) {
        if (d[i] > d[id2]) id2 = i;
    }
    memset(d, 0, sizeof(d));
    memset(u, 0, sizeof(u));
    d[id] = 1;
    dfs2(id);

    memset(d, 0, sizeof(d));
    d[id] = 1;
    dfs3(id);

    for (i = 1; i <= n; i ++) {
        printf("%d", ans[i]);
        if (i < n) printf(" ");
        else printf("\n");
    }

}

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

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

vector<int> v[211111];
int d[211111],n;

P dfs(int x,int t) {
  d[x]=t;P p=P(d[x],x);
  rep(i,v[x].size())if(d[v[x][i]]==MAX)p=max(p,dfs(v[x][i],t+1));
  return p;
}

P calc() {
  fill(d,d+211111,MAX);P p=dfs(0,0);
  fill(d,d+211111,MAX);P q=dfs(p.S,0);
  return P(p.S,q.S);
}

P pp;
set<ll> s;
ll dfs2(int x,int p) {
  if(x==pp.S) {
    s.in(x);
    return 1;
  }
  ll f=0;
  rep(i,v[x].size()) {
    ll y=v[x][i];
    if(y==p) continue;
    f|=dfs2(y,x);
  }
  if(f) s.in(x);
  return f;
}

ll a[222222],k=1;

void dfs3(ll x,ll p) {
  a[x]=k++;
  ll z=-1;
  rep(i,v[x].size()) {
    ll y=v[x][i];
    if(y==p) continue;
    if(s.count(y)) {
      z=y;
      continue;
    }
    dfs3(y,x);
    k++;
  }
  if(z!=-1) {
    dfs3(z,x);
    k++;
  }
}

void Main() {
  R n;
  rep(i,n-1) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  pp=calc();
  dfs2(pp.F,-1);
  dfs3(pp.F,-1);
  PR(a,n);
}

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


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<ll, ll> P;
int main()
{
    ll N, K;
    cin >> N >> K;
    vector<P> AB(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        AB[i] = {a, b};
    }

    sort(all(AB));

    ll ans = 0;
    ll place = 0;
    rep(i, N) {
        ll diff = place + K;
        if (AB[i].first <= diff) {
            K -= (AB[i].first - place);
            place = AB[i].first;
            K += AB[i].second;
        }
        else {
            break;
        }
    }

    cout << place + K << endl;
    return 0;
}

#include <iostream>
using namespace std;

int main() {
	char S, T; cin >> S >> T;
	char r = (S == 'Y') ? T + 'A' - 'a' : T;
	cout << r << '\n';
	cin.ignore(2); return 0;
}


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

double a, b, r;

ll pow_l(ll x) {return x * x;};

bool in_circle(int x, int y) {
    ll la = round(a * 10000);
    ll lb = round(b * 10000);
    ll lr = round(r * 10000);
    ll lx = (ll)x * 10000;
    ll ly = (ll)y * 10000;
    return pow_l(ly - lb) <= pow_l(lr) - pow_l(lx - la);
}

int left_cnt(int x) {
    int ng = -MAX, ok = b;
    if (!in_circle(x, ok)) return 0;
    while (ng + 1 < ok) {
        int mid = (ok + ng) / 2;
        if (in_circle(x, mid)) ok = mid;
        else ng = mid;
    }
    return (int)b - ok + 1;
}

int right_cnt(int x) {
    int ng = MAX, ok = b + 1;
    if (!in_circle(x, ok)) return 0;
    while (ok + 1 < ng) {
        int mid = (ok + ng) / 2;
        if (in_circle(x, mid)) ok = mid;
        else ng = mid;
    }
    return ok - (int)(b + 1) + 1;
}

int main() {
    cin >> a >> b >> r;
    ll ans = 0;
    for (int x = -MAX; x <= MAX; x++) {
        ans += left_cnt(x) + right_cnt(x);
    }
    cout << ans << endl;
}

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

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

ll n, K, P, f[110][110*110*110], up;
signed main() {
    scanf("%lld %lld %lld", &n, &K, &P), up = K * n * (n - 1) / 2, f[0][0] = 1;
    for(int i = 1; i < n; i++) {
        for(int j = 0; j <= up; j++) {
            f[i][j] = f[i - 1][j];
            if(j >= i) (f[i][j] += f[i][j - i]) %= P;
        }
        for(int j = up; j >= (K + 1) * i; j--)
            (f[i][j] += P - f[i][j - (K + 1) * i]) %= P;
    }
    for(int i = 1; i <= n; i++) {
        ll nw = 0;
        for(int j = 0; j <= up; j++)
            (nw += f[i - 1][j] * f[n - i][j]) %= P;
        printf("%lld\n", (nw * (K + 1) % P - 1 + P) % P);
    }
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define int long long int
#define all(x) x.begin(), x.end()
#define send ios_base::sync_with_stdio(false);
#define help cin.tie(NULL)
#define inf (int)(1e17+1)
#define mod (int)(1e9+7)
#define N (int)(2e5+5)
#define fi first
#define se second
#define endl "\n"
#define double long double
#define eps (double)(1e-9)
#define sa cout<<"sa"<<endl
using namespace std;

void solve(){
	int n;
	cin>>n;
	int mx=0,sum=0,ans=0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		mx=max(mx,x);
		sum+=x;
		ans+=sum;
		cout<<ans+i*mx<<endl;
	}
}

int32_t main(){
    send help;
    #ifdef LOCAL
  	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

constexpr int L = 1e6;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n = scan();
  int m = scan();
  int q = scan();
  vector<int> w(n), v(n);
  for (int i : Rep(n)) {
    w[i] = scan();
    v[i] = scan();
  }

  vector<int> order(n);
  iota(ALL(order), 0);
  sort(ALL(order), [&](int i, int j) { return v[i] > v[j]; });

  vector<int> x(m);
  generate(ALL(x), scan<>);
  while (q--) {
    int l = scan() - 1;
    int r = scan();
    multiset<int> ms;
    for (int j : Rep(m)) {
      if (l <= j and j < r) continue;
      ms.insert(x[j]);
    }
    int ans = 0;
    for (int i : order) {
      auto it = ms.lower_bound(w[i]);
      if (it == end(ms)) continue;
      ms.erase(it);
      ans += v[i];
    }
    cout << ans << '\n';
  }
}


#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int a[200010];
  int t[200010];
  int q;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> t[i];
  }

  cin >> q;

  long ub = 1000000000;
  long lb = -ub;
  long offset = 0;
  for (int i = 0; i < n; ++i) {
    if (t[i] == 1) {
      offset += a[i];
      ub += a[i];
      lb += a[i];
    } else if(t[i] == 2) {
      if (lb < a[i]) {
        lb = a[i];
      }
      if (ub < lb) {
        ub = lb;
      }
    } else {
      if (ub > a[i]) {
        ub = a[i];
      }
      if (lb > ub) {
        lb = ub;
      }
    }
  }

  for (int i = 0; i < q; ++i) {
    long x;
    cin >> x;
    x += offset;
    if (x < lb) {
      x = lb;
    }
    if (x > ub) {
      x = ub;
    }
    cout << x << endl;
  }
}

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
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; }

void solve(){
    ll N;
    cin >> N;
    vll a(N), t(N);
    rep(i,0,N) cin >> a[i] >> t[i];
    ll Q;
    cin >> Q;
    vll x(Q);
    rep(i,0,Q) cin >> x[i];
    vector<lpair> lp;
    rep(i,0,Q) lp.push_back({x[i], i});
    sort(lp.begin(), lp.end());
    vll ans(Q+1, 0);
    ll min_val = -INF, max_val = INF;
    ll cur = 0;
    rep(i,0,N){
        if(t[i] == 1){
            cur += a[i];
        }else if(t[i] == 2){
            ll val = a[i] - cur;
            min_val = max(min_val, val);
        }else{
            ll val = a[i] - cur;
            max_val = min(max_val, val);
        }
    }
    ll m1 = min_val, m2 = max_val;
    rep(i,0,N){
        if(t[i] == 1){
            m1 += a[i];
            m2 += a[i];
        }else if(t[i] == 2){
            chmax(m1, a[i]);
            chmax(m2, a[i]);
        }else{
            chmin(m1, a[i]);
            chmin(m2, a[i]);
        }
    }

    rep(q,0,Q){
        ll X = lp[q].first;
        ll idx = lp[q].second;

        ll res = 0;
        if(X >= min_val && X <= max_val){
            res = m1 + (X - min_val);
        }else if(X < min_val){
            res = m1;
        }else{
            res = m2;
        }
        ans[idx] = res;
    }

    rep(i,0,Q) print(ans[i]);

}

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define endl '\n'
#define pb push_back
#define sz(c) (ll)c.size()
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define M 1000000007
#define PI 3.1415926535897932384
#define pii pair<ll,ll>

const ll INF=1e18;
const ll N=1e5+5;
ll mod=998244353;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<ll,ll>> vp;
typedef vector<vector<ll>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;

//bool isPrime(ll n){
//	if(n<=1)
//	return false;
//	if(n<=3)
//	return true;
//	if(n%2==0 || n%3==0)
//	return false;
//	for(ll i=5;i*i<=n;i=i+6)
//	{
//		if(n%i==0 || n%(i+2)==0)
//		return false;
//	}
//	return true;
//}
//ll fact(ll n)
//{
//    ll ans=1;
//    for(ll i=1;i<=n;i++)
//	ans=(ans*i)%M ;
//	return ans;
//}
//
//
//
//
//ll exp(ll x,ll n){
//
//	ll res=1;
//	while(n>0){
//		if(n%2==1)
//		res=(res*x)%M;
//		x=(x*x)%M;
//		n=n/2;
//	}
//	return res;
//}
//
//

//ll nCr(ll n, ll k)
//{
//    ll res = 1;
//
//    // Since C(n, k) = C(n, n-k)
//    if(k>n-k){
//    	k=n-k;
//	}
//
//    // Calculate value of
//    // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
//    for (ll i=0;i<k;i++) {
//        res *= (n - i);
//        res /= (i + 1);
//    }
//
//    return res;
//}

// nCr

//vector<ll> fact(1e6+5,0);
//void fac(){
//	fact[0]=1;
//	fact[1]=1;
//	for(ll i=2;i<1e6+5;i++){
//		fact[i] = (fact[i-1]*i)%M;
//	}
//}
//ll ncr(ll n,ll r){
//	ll num= fact[n];
//	ll den= (fact[n-r]*fact[r])%M;
//	den = exp(den,M-2);
//	return (num*den)%M;
//
//}

void null(){
    ll n;
    cin>>n;
    map<ll,ll> mx,my;
    vi x(n),y(n);
    vp a,b;

    rep(i,0,n){
        cin>>x[i]>>y[i];
        a.pb({x[i],i});
        b.pb({y[i],i});
        mx[x[i]]++;
        my[y[i]]++;
    }
    sort(all(a),[&](auto &p,auto &q){
        if(p.F==q.F)
        return y[p.S]<y[q.S];
        return p.F<q.F;
    });
    sort(all(b),[&](auto &p,auto &q){
        if(p.F==q.F)
        return x[p.S]<x[q.S];
        return p.F<q.F;
    });
    vi ans;
    ll op1= a[n-1].F-a[0].F;
    ll op2= b[n-1].F-b[0].F;
    if(a[n-1].S ==b[n-1].S and a[0].S==b[0].S){
        ans.pb(max(op1,op2));
    }
    else{
        ans.pb(op1);
        ans.pb(op2);
    }

    ll op3= a[n-1].F-a[1].F;
    ll op4= b[n-1].F-b[1].F;
    if(a[n-1].S ==b[n-1].S and a[1].S==b[1].S){
        ans.pb(max(op3,op4));
    }
    else{
        ans.pb(op3);
        ans.pb(op4);
    }

    ll op5= a[n-2].F-a[0].F;
    ll op6= b[n-2].F-b[0].F;
    if(a[n-2].S ==b[n-2].S and a[0].S==b[0].S){
        ans.pb(max(op5,op6));
    }
    else{
        ans.pb(op5);
        ans.pb(op6);
    }
    // vi a={op1,op2,op3,op4,op5,op6};
    sort(all(ans));
    reverse(all(ans));
    cout<<ans[1]<<endl;

}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    cout<<setprecision(4);
    cout<<fixed;
    ll t = 1;
    clock_t start, end;
    start = clock();
//    fac();

//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    freopen("error.txt", "w", stderr);
//    #endif
    // cin>>t;
//    compute();
    while(t--){
        null();
    }

    end = clock();
    double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
    //cerr<<time_taken;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

//-------------------------------------------------
//--Extended GCD
//-------------------------------------------------

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b==0){
        x = 1; y = 0;
        return a;
    }
    ll d = extgcd(b,a%b,y,x);
    y -= a/b*x;
    return d;
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--){
        ll N,S,K; cin>>N>>S>>K;
        ll g = __gcd(K,N);
        if (S%g!=0){
            cout<<"-1\n";
            continue;
        }
        N/=g; S/=g; K/=g;
        ll inv,_;
        extgcd(K,N,inv,_);
        inv=(inv+N)%N;
        cout<<inv*(N-S)%N<<"\n";
    }
    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;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 100012
#define ll long long
#define int ll
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
ll Mod(ll x, ll y, int p)
{   ll res = 1; x = x % p;
    while (y > 0)
    {   if (y & 1) res = (res * x) % p;
        y = y >> 1; x = (x * x) % p;
    } return res;
}
int* getlps(string pattern) {
    int len = pattern.length();
    int * lps = new int[len];
    lps[0] = 0;
    int i = 1 , j = 0;
    while (i < len) {
        if (pattern[i] == pattern[j]) {
            lps[i] = j + 1;
            i++;
            j++;
        }
        else {
            if (j != 0) {
                j = lps[j - 1];
            }
            else {
                lps[i] = 0;
                i++;
            }
        }
    }
    return lps;
}
class Triplet {
public:
    int x ;
    int y ;
    int gcd;
};
Triplet extendedEuclid(int a , int b) {
    if (b == 0) {Triplet ans; ans.gcd = a; ans.x = 1; ans.y = 0; return ans;}
    Triplet smallAns = extendedEuclid(b , a % b);
    Triplet ans;
    ans.gcd = smallAns.gcd;
    ans.x = smallAns.y;
    ans.y = smallAns.x - (a / b) * smallAns.y;
    return ans;
}
int mmInverse(int a , int m) {
    Triplet ans = extendedEuclid(a , m);
    return (ans.x + m) % m;
}
int fact[N];
void calfac(int n ) {
    fact[0] = 1;
    for (int i = 1 ; i <= n + 2; i++) {
        fact[i] = (((fact[i - 1] % mod) * (i % mod)) % mod + mod) % mod;
    }
}
int calc(int n , int r) {
    if (r > n)return 0;
    if (r == n)return 1;
    int ans = 1;
    ans = ((ans % mod) * (fact[n]) % mod + mod) % mod;
    ans = ((ans % mod) * (mmInverse(fact[n - r] , mod) % mod) + mod) % mod;
    ans = ((ans % mod) * (mmInverse(fact[r] , mod) % mod) + mod) % mod;
    return (ans + mod) % mod;
}

void solve(int cntt) {

    int n;
    int k;
    cin >> n;
    cin >> k;
    int arr[n];
    int dp[n + 1] = {0};
    for (int i = 0 ; i < n ; i++) {
        cin >> arr[i];
        dp[arr[i]]++;
    }
    dp[0] = min(dp[0] , k);
    for (int i = 1 ; i < n ; i++) {
        dp[i] = min(dp[i] , dp[i - 1]);
    }
    int st = dp[0];
    int ans = 0;
    for (int i = 1 ; i < n ; i++) {
        ans += i * (st - dp[i]);
        st = min(st , dp[i]);
    }
    ans += st * (n);
    cout << ans << endl;
}

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

    // preprocess();
    int t;
    t = 1;

    int l = 0;
    while (t--) {
        l++;

        solve(l);
    }
    return 0;
}

/* Clearink */

#include <cstdio>

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

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

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

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

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

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


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<ll,int>Pli;
typedef pair<int,int> Pi;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y;
	ll cost;
};

int main(){

	string s;
	cin>>s;
	char c='A';
	int si=s.size()-1;
	ll ans=0;
	for(int i=s.size()-1; i>0; i--){
		if(s[i]==s[i-1]){
			if(s[i]==c)ans+=si-i-1;
			else ans+=s.size()-i-1;
			c=s[i];
			while(s[i]==c)i--;
			i++;
			si=i;
		}
	}
	c='A';
	for(int i=0; i<s.size(); i++){
		if(s[i]!=s[i+1]&&c==s[i])ans--;
		if(s[i]==s[i+1]){
			c=s[i];
			while(s[i]==c)i++;
			i--;
		}
	}
	cout<<ans<<endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  map<string,int> mp;
  rep(i,n) {
    cin >> s[i];
    mp[s[i]] = 1;
  }

  for(auto iter = mp.begin(); iter != mp.end(); iter++){
    if(iter->first[0] == '!') continue;
    else {
      string temp = "!" + iter->first;
      if(mp[temp] == 1){
        cout<<iter->first<<endl;
        return 0;
      }
    }
  }
  cout<<"satisfiable"<<endl;
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b-1;i>=a;i--)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

ll m;
string x;
int s;

ll binary_search_f(ll n) {
	ll res = 0;
	ll a = 1;;
	rrep(i, s) {
		if (i != s - 1) a *= n;
		if (a > 1000000000000000001 || res > 1000000000000000001) {
			return 1000000000000000001;
		}
		if (x[i] - '0' == 0) {
			continue;
		}
		if (a > 1000000000000000001 / (x[i] - '0')) {
			return 1000000000000000001;
		}
		ll res0 = res;
		res += (x[i] - '0') * a;
		if (res < 0 || res - (x[i] - '0') * a != res0) {
			return 1000000000000000001;
		}
	}
	return res;
}
ll f(ll a) {
	//ll cnt = 0;
	if (a <= 1)return a;
	ll x = 1;
	while (binary_search_f(x) < a) {
		x *= 2;
		//cnt++;
	}
	ll top = x + 1;
	ll bot = x / 2;
	ll c = (top + bot) / 2;

	while (1) {
		//cnt++;
		if (c == 0 && binary_search_f(c) > a) {
			return -1;
		}
		if (binary_search_f(c) <= a && binary_search_f(c + 1) > a) {
			//cout << cnt << endl;
			return c;
		}
		else if (binary_search_f(c) > a) {
			top = c;
			c = (c + bot) / 2;
		}
		else {
			bot = c;
			c = (c + top) / 2;
		}
	}
}

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> w(n), v(n), x(m), l(q), r(q);
	vector<P> vw(n);
	rep(i, n) {
		cin >> w[i] >> v[i];
		vw[i] = mp(v[i], w[i]);
	}
	rep(i, m) {
		cin >> x[i];
	}
	rep(i, q) {
		cin >> l[i] >> r[i];
		l[i]--; r[i]--;
	}

	SORT(vw);
	REVERSE(vw);

	rep(i, q) {
		vector<int> y, use;
		rep(j, m) {
			if (j < l[i] || r[i] < j) {
				y.push_back(x[j]);
				use.push_back(0);
			}
		}
		SORT(y);
		ll ans = 0;
		rep(j, n) {
			int W = vw[j].second;
			int V = vw[j].first;
			rep(k, y.size()) {
				if (use[k] == 0 && y[k] >= W) {
					use[k] = 1;
					ans += V;
					break;
				}
			}
		}
		cout << ans << endl;
	}
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
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 ll MOD = 1e9+7;

int main(){
    ll N, M, Q;
    cin >> N >> M >> Q;
    vector<ll> X(M);
    using P = pair<ll, ll>;
    vector<P> WV(N);
    REP(i,N){
        ll w, v;
        cin >> w >> v;
        WV[i] = P(w, v);
    }
    sort(WV.begin(), WV.end());
    REP(i,M){
        ll x;
        cin >> x;
        X[i] = x;
    }

    while(Q--){
        ll L, R;
        cin >> L >> R;
        L--, R--;
        priority_queue<ll, vector<ll>, greater<ll>> Y;
        REP(i,L)
            Y.push(X[i]);
        REPi(i,R+1,M)
            Y.push(X[i]);

        priority_queue<ll> V;
        ll idx = 0;
        ll ans = 0;
        while(!Y.empty()){
            auto y = Y.top(); Y.pop();

            while(idx < N){
                auto [w, v] = WV[idx];
                if(w > y) break;
                V.push(v);
                idx++;
            }

            if(V.empty()) continue;
            auto v = V.top();
            V.pop();
            ans += v;
        }

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


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<unordered_map>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 100000000001
#define LLINF 9223372036854780LL
#define mod 998244353
//#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

long long modinv(long long a) {
	return modpow(a, mod - 2);
}
struct LazySegmentTree {
private:
	int n;
	vector<ll> node, lazy;

public:
	LazySegmentTree(vector<ll> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, 0);

		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]) % mod;
	}

	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			node[k] %= mod;
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] * modinv(2);
				lazy[2 * k + 2] += lazy[k] * modinv(2);
				lazy[2 * k + 1] %= mod;
				lazy[2 * k + 2] %= mod;
			}
			lazy[k] = 0;
		}
	}

	void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l) * x;
			lazy[k] %= mod;
			eval(k, l, r);
		}
		else {
			add(a, b, x, 2 * k + 1, l, (l + r) / 2);
			add(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = (node[2 * k + 1] + node[2 * k + 2]) % mod;
		}
	}

	ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return node[k];
		ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
		return (vl + vr) % mod;
	}
};

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

	int N; cin >> N;
	int M; cin >> M;
	VI H(N), W(M);
	REP(i, N)cin >> H[i];
	REP(i, M)cin >> W[i];
	SORT(H);
	int ans = LLINF;
	VI sum(N + 2, 0), sum1(N + 2, 0);
	for (int i = 0; i < N; i += 2) {
		if (i + 1 >= N)break;
		sum[i / 2 + 1] += abs(H[i] - H[i + 1]) + sum[i / 2];
	}
	int j = 1;
	for (int i = N - 1; i >= 0; i -= 2) {
		if (i - 1 < 0)break;
		sum1[j] += abs(H[i] - H[i - 1]) + sum1[j - 1];
		j++;
	}
	REP(i, M) {
		int it = LB(H, W[i]) - H.begin();
		int itt = N - it;
		int cnt = sum[it / 2] + sum1[itt / 2];
		//cout << it << " " << sum[it / 2] << " " << sum1[itt / 2] << endl;
		if (it % 2) {
			cnt += abs(W[i] - H[it - 1]);
		}
		else {
			cnt += abs(W[i] - H[it]);
		}
		chmin(ans, cnt);
	}

	cout << ans << endl;
	/*
	int N, Q; cin >> N >> Q;

	while (Q--) {
		int t, x; cin >> t >> x;

	}
	*/
	return 0;
}

#include<iostream>
using namespace std;
typedef long long ll;
int MOD = 998244353;
ll ksm(ll a,ll b,ll mod){
    ll ans = 1;
    while(b>0){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>=1;
    }
    return ans;
}
int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    ll ans = 0;
    for(int i = 1; i <= K; ++i){
        if(M == 1)
            ans+=((ksm(i,N,MOD) - ksm(i-1,N,MOD) + MOD)%MOD);
        else if(N==1){
            ans+=((ksm(i,N,MOD) - ksm(i-1,N,MOD) + MOD)%MOD)*((ksm(K-i+1,M,MOD) - ksm(K-i,M,MOD)+MOD)%MOD);
        }
        else
            ans+=((ksm(i,N,MOD) - ksm(i-1,N,MOD) + MOD)%MOD)*(ksm(K-i+1,M,MOD)%MOD);

        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

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

#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)
#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())

ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a);
        a = (a*a);
        b = b/2;
    }
    return ans;
}

ll Lpow(ll a,ll b,ll M)
{
	ll ans = 1;
	while(b > 0)
	{
		if(b%2)
			ans = (ans*a)%M;
		a = (a*a)%M;
		b = b/2;
	}
	return ans;
}

int main()
{
    fastio;

    ll n,C;
    cin >> n >> C;

    vector<pair<ll,ll>> arr(2*n);

    ll a,b,c;
    for(int i = 0;i<n;i++)
    {
        cin >> a >> b >> c;
        arr[2*i].first = a;
        arr[2*i].second = c;
        arr[2*i + 1].first = b + 1;
        arr[2*i + 1].second = -c;
    }

    sort(all(arr));

    ll curr = 0;
    ll ans = 0;

    for(int i = 0;i<2*n;i++)
    {
        curr = curr + arr[i].second;
        while(i + 1 < 2*n && arr[i].first == arr[i + 1].first)
        {
            curr = curr + arr[i+1].second;
            i++;
        }

        ll days = 0;
        if(i + 1 < 2*n)
            days = arr[i + 1].first - arr[i].first;

        ans += days*min(C,curr);
    }

    cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 200005

enum Which{
	COUNT,
	VAL,
};

enum Type{
	A,
	B,
};

struct Query{

	ll t,x,y;
};

ll num_A,num_B;
ll N,a[SIZE],b[SIZE];
ll BIT[SIZE][2][2];
map<ll,ll> MAP,REV;
Query query[SIZE];

void add(ll loc,ll value,Which which,Type type){

	BIT[loc][which][type] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc][which][type] += value;
		loc += loc & -loc;
	}
}

ll getSum(ll loc,Which which,Type type){

	if(loc == 0)return 0;

	ll sum = BIT[loc][which][type];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc][which][type];
		loc -= loc & -loc;
	}
	return sum;
}

int main(){

	int num_Q;
	scanf("%lld %lld %d",&num_A,&num_B,&num_Q);

	for(ll i = 1; i <= num_A; i++){

		a[i] = 0;
	}
	for(ll i = 1; i <= num_B; i++){

		b[i] = 0;
	}

	vector<ll> vec;
	vec.push_back(0);

	for(int i = 0; i < num_Q; i++){

		scanf("%lld %lld %lld",&query[i].t,&query[i].x,&query[i].y);
		vec.push_back(query[i].y);
	}

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

	for(int i = 0; i < vec.size(); i++){

		MAP[vec[i]] = i+1;
		REV[(i+1)] = vec[i];
	}

	ll ans = 0;

	N = vec.size();

	for(ll i = 0; i <= N; i++){
		for(int k = 0; k < 2; k++){
			for(int p = 0; p < 2; p++){

				BIT[i][k][p] = 0;
			}
		}
	}

	add(MAP[0],num_A,COUNT,A);
	add(MAP[0],num_B,COUNT,B);

	for(int i = 0; i < num_Q; i++){

		ll loc = query[i].x;

		if(query[i].t == 1){ //Aを操作

			if(a[loc] == query[i].y){

				printf("%lld\n",ans);
				continue;
			}

			ll pre = a[loc];

			ans -= pre*getSum(MAP[pre],COUNT,B); //前の値の加算値

			if(pre < query[i].y){ //大きくなった

				ans -= getSum(MAP[query[i].y],VAL,B)-getSum(MAP[pre],VAL,B); //

			}else{ //小さくなった

				ans += getSum(MAP[pre],VAL,B)-getSum(MAP[query[i].y],VAL,B);
			}

			ans += query[i].y*getSum(MAP[query[i].y],COUNT,B);

			a[loc] = query[i].y;

			add(MAP[pre],-1,COUNT,A);
			add(MAP[pre],-pre,VAL,A);

			add(MAP[query[i].y],1,COUNT,A);
			add(MAP[query[i].y],query[i].y,VAL,A);

		}else{

			if(b[loc] == query[i].y){

				printf("%lld\n",ans);
				continue;
			}

			ll pre = b[loc];

			//printf("B: pre:%lld\n",pre);

			ll tmp = pre*getSum(MAP[pre]-1,COUNT,A); //前の値の加算値

			//printf("前の加算地:%lldをマイナス\n",tmp);
			ans -= tmp;

			if(pre < query[i].y){ //大きくなった

				tmp = getSum(MAP[query[i].y]-1,VAL,A)-getSum(MAP[pre]-1,VAL,A);
				//printf("大きくなったので%lldをマイナス\n",tmp);
				ans -= tmp;

			}else{ //小さくなった

				tmp = getSum(MAP[pre]-1,VAL,A)-getSum(MAP[query[i].y]-1,VAL,A);
				//printf("小さくなったので%lldをプラス\n",tmp);
				ans += tmp;
			}

			//printf("ここまでのans:%lld\n",ans);

			tmp = query[i].y*getSum(MAP[query[i].y]-1,COUNT,A);
			//printf("今回は%lldを加算\n",tmp);
			ans += tmp;

			b[loc] = query[i].y;

			add(MAP[pre],-1,COUNT,B);
			add(MAP[pre],-pre,VAL,B);

			add(MAP[query[i].y],1,COUNT,B);
			add(MAP[query[i].y],query[i].y,VAL,B);

		}

		printf("%lld\n",ans);
	}

	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const int maxn = 1e6 + 5;

ll pw(ll x, ll y, ll mod) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}

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

    ll A,B,C;

    cin>>A>>B>>C;

    ll p = pw(B, C, 4)+4;

    ll ans = pw(A, p, 10);

    // ans %= 10;
    // ans += 10;
    // ans %= 10;

    out(ans);

    return 0;
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define ri register int
const int N = 1e6 + 618;
using namespace std;
int v,t,s,d;
int main(){
	scanf("%d%d%d%d",&v,&t,&s,&d);
	if(d < v * t||d > v * s) printf("Yes");
	else
		printf("No");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll b,c;
    cin>>b>>c;
    if(b<0){
        ll nl=b,nh=b;
        nl=b-c/2;
        if(c>=2){
            nh=-max(-b-(c-2)/2,1ll);
        }
        ll ans=nh-nl+1;
        if(c>0){
            ll pl=max(-b-(c-1)/2,0ll);
            ll ph=-b+(c-1)/2;
            ans+=ph-pl+1;
        }
        cout<<ans<<endl;
    }
    else{
        ll pl=b,ph=b;
        pl=max(b-c/2,0ll);
        if(c>=2){
            ph=-(-b-(c-2)/2);
        }
        ll ans=ph-pl+1;
        if(c>0){
            if(b){
                c--;
            }
            ll nl=-b-(c)/2;
            ll nh=-max(1ll,b-(c)/2);
            ans+=nh-nl+1;
        }
        cout<<ans<<endl;
    }
}

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

int main() {
    ll B, C;
    cin >> B >> C;

    ll ans;

    ll k = C / 2;
    int r = C % 2;

    if (C == 0) {
        ans = 1;
    } else if (B == 0) {
        ans = C;
    } else if (C == 1) {
        ans = 2;
    } else if (B > 0) {
        if (C <= 2 * B) {
            ans = 2 * C - 1;
        } else {
            ans = 2 * B + C - 1;
        }
    } else {
        if (C <= -2 * B - 2) {
            ans = 2 * C - 1;
        } else {
            ans = -2 * B + C;
        }
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
const int N = 2e5 + 50;
int mod = 998244353;
vector<int> g[N];
int ans;
int vis[N];

void dfs(int node) {
    vis[node] = 1;
    for (auto to: g[node]) {
        if (vis[to] == 1)
            ans++;
        else if (vis[to] == 0) {
            dfs(to);
        }
    }
    vis[node]++;
}

int binpow(int a, int b) {
    int ret = 1;
    while (b) {
        if (b & 1) {
            ret *= a;
            ret %= mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return ret;
}

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

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        int fi;
        cin >> fi;

        g[i].push_back(fi);
    }

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

    cout << (binpow(2, ans) - 1 + mod) % mod << '\n';

}

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr int MOD = 1e9+7;
constexpr int MOD2 = 998244353;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
char interval[2] = {' ', '\n'};

template<typename T> struct is_plural : false_type{};
template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{};
template<typename T> struct is_plural<vector<T>> : true_type{};
template<typename T> struct is_plural<complex<T>> : true_type{};
template<> struct is_plural<string> : true_type{};

template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for(auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if(vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for(auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; }
template<typename T> istream &operator>>(istream &is, complex<T> &x) { T a, b; is >> a >> b; x = complex<T>(a, b); return is; }
template<typename T> ostream &operator<<(ostream &os, complex<T> &x) { return os << x.real() << ' ' << x.imag(); }

bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << '\n'; return a; }

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

/* -------- <templates end> -------- */

int64_t modpow(int a, int64_t n, int mod = MOD) { int64_t ret = 1; do { if(n & 1) ret = ret * a % mod; a = 1LL * a * a % mod; } while(n >>= 1); return ret; }

void solve() {
  int n; cin >> n;
  vector<int> a(n); cin >> a;
  for(auto &x : a) --x;

  vector<int> timestamp(n, -1);
  int pw = 0;

  auto dfs = [&](auto dfs, int v, int t) -> void {
    if(timestamp[v] != -1) {
      if(timestamp[v] == t) ++pw;
      return;
    }
    timestamp[v] = t;
    dfs(dfs, a[v], t);
  };

  for(int i=0; i<n; ++i) {
    dfs(dfs, i, i);
  }

  cout << modpow(2, pw, MOD2) - 1 << endl;
}

/* -------- <programs end> -------- */

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