#include <bits/stdc++.h>
using namespace std;
#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 FOR(i, n, m) for (int i=(n); i<=(int)(m); i++)
#define ll long long
const ll INF=1LL<<60;
const double pi=3.1415926535;

int main() {
    vector<vector<int>> dp(900, vector<int>(900));
    vector<int> vec_output;
    //通った道
    vector<vector<int>> usei(1000), usej(1000);
    vector<int> usedoutput(1000);

    rep(i, 1000) {

        //入力
        vector<int> input(4);
        rep(j, 4) cin >> input.at(j);

        usei.at(i).push_back(input.at(0));
        usej.at(i).push_back(input.at(1));

        int x = input.at(1);
        int y = input.at(0);
        int xplus = 0;
        int yplus = 0;
        if (x < input.at(3)) xplus = 1;
        if (x > input.at(3)) xplus = -1;
        if (y < input.at(2)) yplus = 1;
        if (y > input.at(2)) yplus = -1;
        bool X = false;

        //経路探索
        while (x != input.at(3)) {
            //ｘの残りをうめる
            if (y == input.at(2)) {
                while (x != input.at(3)) {
                    x += xplus;
                    usei.at(i).push_back(y);
                    usej.at(i).push_back(x);
                    cout << (xplus == 1 ? "R" : "L") << flush;
                }
                break;
            }

            //探索済みか近いかを調べる
            if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
                X = !X;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) {
                X = true;
            } else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
                X = false;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) {
                X = true;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) {
                X = false;
            }

            if (X) {
                x += xplus;
                usei.at(i).push_back(y);
                usej.at(i).push_back(x);
                cout << (xplus == 1 ? "R" : "L") << flush;
            } else {
                y += yplus;
                usei.at(i).push_back(y);
                usej.at(i).push_back(x);
                cout << (yplus == 1 ? "D" : "U") << flush;
            }
        }

        //yの残りをうめる
        while (y != input.at(2)) {
            y += yplus;
            usei.at(i).push_back(y);
            usej.at(i).push_back(x);
            cout << (yplus == 1 ? "D" : "U") << flush;
        }
        cout << endl;

        //入力
        ll output;
        cin >> output;

        //点数の平均を計算
        int size = usei.at(i).size();
        output *= 60;
        output /= size;
        vec_output.push_back(output);
        ll sum = 0;
        for (ll a : vec_output) {
            sum += a;
        }
        ll ave = sum / vec_output.size();
        vector<ll> put_output;
        for (ll a : vec_output) {
            put_output.push_back(a-ave);
        }

        rep(j, put_output.size()) {
            put_output.at(j) -= usedoutput.at(j);
            usedoutput.at(j) = put_output.at(j);
            rep(k, usei.at(j).size()-1) {
                int a = usei.at(j).at(k);
                int b = usej.at(j).at(k);
                int c = usei.at(j).at(k+1);
                int d = usej.at(j).at(k+1);
                //cout << a*30+b << " " << c*30+d << endl;
                dp.at(a*30+b).at(c*30+d) += put_output.at(j);
                dp.at(c*30+d).at(a*30+b) += put_output.at(j);
            }
        }

        /*rep(j, 29) {
            rep(k, 29) {
                cout << " " << dp.at(j*30+k).at(j*30+k+1);
            }
            cout << endl;
            rep(k, 30) {
                cout << dp.at(j*30+k).at((j+1)*30+k) << " ";
            }
            cout << endl;
        }*/
    }
}

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

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

#define all(x)						(x).begin(),(x).end()
#define X							first
#define Y							second
#define sep							' '
#define endl						'\n'
#define SZ(x)						ll(x.size())

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;

int n , A[MAXN] , val[MAXN];
string s;

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

	cin >> n >> s; s += ".";
	int mn = MOD , diff = MOD;
	for(int i = 0 ; i <= n ; i++){
		cin >> A[i];
	}
	for(int i = 0 ; i < n ; i++){
		mn = min(mn , abs(A[i] - A[i + 1]));
	}
	cout << mn << endl;
	for(int i = 0 ; i < mn ; i++){
		for(int j = 0 ; j <= n ; j++){
			cout << A[j] / (mn - i) << sep;
			A[j] -= A[j] / (mn - i);
		}
		cout << endl;
	}

    return 0;
}
/*

*/


#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> st;
    for(int i = 0; i <= 3e5; i++) st.insert(i);
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int p;
        cin >> p;
        st.erase(p);
        cout << *st.begin() << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(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 INF 1000000000000
typedef long long ll;

int main()
{
  int n, ans = 0;
  cin >> n;
  vector<int> p(n), s(200001);
  REP(i, n)
  {
    cin >> p[i];
  }
  REP(i, n)
  {
    s[p[i]]++;
    if (s[ans] > 0)
    {
      FOR(j, ans + 1, 200001)
      {
        if (s[j] == 0)
        {
          ans = j;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e5+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;

vector<ll> a[MAX];
ll par[MAX],ans[MAX],sub[MAX],cnt;

void dfs1(ll node,ll parent)
{
    par[node] = parent;
    for(auto x:a[node])
    {
        if(x!=parent)
            dfs1(x,node);
    }
}

void dfs2(ll node,ll parent,ll carry)
{
    ans[node] = cnt+carry+sub[node];
    for(auto x:a[node])
    {
        if(x!=parent)
            dfs2(x,node,carry+sub[node]);
    }
}

int main()
{
    ll i,j,k,l,p,q,x,y,n;
    vector<pair<ll,ll>> edges;
    cin >> n;
    for(i=1;i<=n-1;i++)
    {
        cin >> x >> y;
        a[x].pb(y);a[y].pb(x);
        edges.pb({x,y});
    }
    dfs1(1,0);
    cin >> q;
    while(q--)
    {
        cin >> k >> x >> y;
        i = edges[x-1].first;j = edges[x-1].second;
        cnt+=y;
        if(k==1)
        {
            if(par[j]==i)
                sub[j]-=y;
            else
            {
                sub[1]-=y;
                sub[i]+=y;
            }
        }
        else
        {
            if(par[i]==j)
                sub[i]-=y;
            else
            {
                sub[1]-=y;
                sub[j]+=y;
            }
        }
    }
    dfs2(1,0,0);
    for(i=1;i<=n;i++)
        cout << ans[i] << "\n";
}


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

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll N;
  cin>>N;
  vector<ll>v;
  rep(i,1,sqrt(N))
  {
    if(N%i==0)
    {
      if(N/i==i)
      v.push_back(i);
      else
      {
        v.push_back(N/i);
        v.push_back(i);
      }
    }
  }
  sort(v.begin(),v.end());
  for(auto x:v)
    cout<<x<<endl;
  return 0;

}

#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);

void SieveOfEratosthenes()
{
    bool prime[10000001];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=10000000; p++)
    {
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false;
            }
        }
    }
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll power(ll x,ll y,ll p)
{
    ll r = 1;

    x = x % p;
    while (y > 0) {
        if (y & 1)
            r = (r * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return r;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}

ll nCrModP(ll n,ll r, ll p)
{
    ll fac[100005];
    if (r == 0)
        return 1;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
int32_t main()
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	cin>>n;
	set<ll> v;
	for(j=1;j<=sqrt(n);j++)
	{
		if(n%j==0)
		{
			v.insert(j);
			v.insert(n/j);
		}

	}
	tr(v,it)
	{
		cout<<*it<<endl;
	}
}


#include<iostream>
using namespace std;
using ll = long long;

ll sum_comb(ll n) {
  if (n <= 2) return 0;
  return (n - 1) * (n - 2) / 2;
}

ll sum_comb2(ll n, ll N) {
  return (sum_comb(n) - sum_comb(n - 3 * N)) - 3 * (sum_comb(n - N) - sum_comb(n - 2 * N));
}

int main() {
  int N; ll K;
  cin >> N >> K;
  ll cnt = 0; int sum = 3;
  while (true) {
    cnt += sum_comb2(sum, N);
    if (cnt >= K) break;
    sum++;
  }
  cnt -= sum_comb2(sum, N);

  int i = 1;
  while (true) {
    cnt += max(0, min(sum - i - 1, 2 * N - sum + i + 1));
    if (cnt >= K) break;
    i++;
  }
  cnt -= min(sum - i - 1, 2 * N - sum + i + 1);

  int j = K - cnt + max(0, sum - i - N - 1);
  int k = sum - i - j;

  cout << i << " " << j << " " << k << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int i=a;i<n;++i)
#define eFOR(i,a,n) for(int i=a;i<=n;++i)
constexpr int INF = 1000000000;
int main() {
    ll n, k; cin >> n >> k;

    VL cnt2(n * 2 + 1);
    eFOR(i, 1, n) {
        ++cnt2[i + 1];
        if (i + n + 1 <= n * 2)--cnt2[i + n + 1];
    }

    eFOR(i, 1, n * 2) {
        cnt2[i] += cnt2[i - 1];
    }

    VL cnt3(n * 3 + 1);
    eFOR(i, 1, n * 2) {
        cnt3[i + 1] += cnt2[i];
        if (i + n + 1 <= n * 3)cnt3[i + n + 1] -= cnt2[i];
    }

    eFOR(i, 1, n * 3) {
        cnt3[i] += cnt3[i - 1];
    }

    ll s3_sum = 0, s3 = 0;
    eFOR(i, 1, n * 3) {
        if (s3_sum + cnt3[i] >= k) {
            s3 = i;
            break;
        }
        s3_sum += cnt3[i];
    }

    ll ki_sum = 0, ki = 0;
    eFOR(i, 1, n) {
        if (s3 - i > n * 2)continue;
        if (s3_sum + ki_sum + cnt2[s3 - i] >= k) {
            ki = i;
            break;
        }
        ki_sum += cnt2[s3 - i];
    }

    ll oi_sum = 0, oi = 0;
    eFOR(i, 1, n) {
        if (s3 - ki - i > n)continue;
        if (s3_sum + ki_sum + oi_sum + 1 >= k) {
            oi = i;
            break;
        }
        oi_sum += 1;
    }

    cout << ki << " " << oi << " " << s3 - ki - oi << "\n";

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
const ll MOD = 1e9+7;
//int eo[64][MAX_N];
bool vis[64][MAX_N];
map<P, ll> mp;

struct edge
{
	int to;
	ll cost;
};

vector<edge> G[MAX_N];
int cntEO[2] = {0,0};

void dfs(int n, int eo, int keta)
{
	vis[keta][n] = true;
	//if (keta == 0) cout << "visiting:" << n << endl;
	rep(i,G[n].size())
	{
		if (!vis[keta][G[n][i].to])
		{
			if ((G[n][i].cost >> keta) & 1)
			{
				cntEO[(eo+1)%2]++;
				dfs(G[n][i].to, (eo+1)%2, keta);
			}
			else
			{
				cntEO[eo]++;
				dfs(G[n][i].to, eo, keta);
			}
		}
	}
	return;
}

int main()
{
	int N;
	cin >> N;
	rep(i,N-1)
	{
		int u,v;
		ll w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(edge{v,w});
		G[v].push_back(edge{u,w});
		mp[P(u,v)] = w;
		mp[P(v,u)] = w;
	}

	ll ans = 0;
	for (int i = 0; i < 62; ++i)
	{
		//cout << "a";
		cntEO[0] = 1, cntEO[1] = 0;
		dfs(0,0,i);
		ans = (ans + (1ull << i) % MOD * cntEO[0] % MOD * cntEO[1] % MOD) % MOD;
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 1000000007;
//998244353;
void randinit(){srand((unsigned)time(NULL));}
ll modpow(ll A,ll B,ll M){
    ll r = 1,p = A;
    while(B > 0){
        if(B % 2 == 1) r = (r * p) % M;
        p = (p * p) % M;
        B /= 2;
    }
    return r;
}
ll modinv(ll A,ll M){
    //A*r+B*n=gcd(A,B)
    A %= M;
    if(A == 0 || __gcd(A,M) != 1){
        //cout << "Error modinv(" << A << "," << M << ")" << endl;
        return -1;
    }
    ll B = M,U = 1,V = 0;
    while(B){
        ll T = A / B;
        A -= T * B;
        swap(A,B);
        U -= T * V;
        swap(U,V);
    }
    U %= M;
    if(U < 0) U += M;
    return U;
}
int main(){
    ll N;
    cin >> N;
    vector<vector<tuple<ll,ll>>> G(N);
    for(ll i = 0;i < N - 1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        G[a - 1].emplace_back(make_tuple(b - 1,c));
        G[b - 1].emplace_back(make_tuple(a - 1,c));
    }
    ll ans = 0;
    for(ll i = 0;i < 61;i++){
        queue<tuple<bool,ll>> que;
        vector<ll> D(N,-1);
        que.push(make_tuple(0,0));
        while(!que.empty()){
            ll a = get<0>(que.front()),b = get<1>(que.front());
            que.pop();
            if(D[b] == -1){
                D[b] = a;
                for(ll j = 0;j < G[b].size();j++){
                    ll c = get<0>(G[b][j]),d = get<1>(G[b][j]);
                    if(D[c] == -1){
                        if(d & (1LL << i)){
                            que.push(make_tuple((a + 1) % 2,c));
                        }
                        else{
                            que.push(make_tuple(a,c));
                        }
                    }
                }
            }
        }
        ll a = 0,b = 0,c = 0;
        for(ll j = 0;j < N;j++){
            if(D[j] == 0) a++;
            else b++;
        }
        for(ll j = 0;j < N;j++){
            if(D[j] == 0) c = (c + b) % MOD;
            else c = (c + a) % MOD;
        }
        ans = (ans + ((c * modpow(2,i,MOD)) % MOD)) % MOD;
    }
    cout << (ans * modinv(2,MOD)) % MOD << endl;
}


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

const int mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

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

  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  vector<vector<vector<modint>>> dp(3,vector<vector<modint>>(h,vector<modint>(w,0)));
  int dh[3] = {1,1,0};
  int dw[3] = {0,1,1};
  rep(i,3) if(s[dh[i]][dw[i]]!='#')dp[i][dh[i]][dw[i]] = 1;

  rep(hi,h)rep(wj,w){
    rep(k,3){//どの方向に進むか
      int nh = hi+dh[k];
      int nw = wj+dw[k];
      if(nh<0 || nw <0 || nh>=h || nw>=w) continue;
      if(s[nh][nw]=='#') continue;
      rep(m,3){//今どの状態か
        if(m==k) dp[k][nh][nw]  += dp[m][hi][wj]*((modint) 2);
        else dp[k][nh][nw] += dp[m][hi][wj];
      }
    }
  }
  // rep(k,3){
  // rep(i,h)rep(j,w){
  //   cout << dp[k][i][j] << " \n"[j==w-1];
  // }
  // cout << endl;
  // }
  modint ans = 0;
  rep(i,3) ans += dp[i][h-1][w-1];
  cout << ans << endl;

  return 0;

}

#include<bits/stdc++.h>
#define fl(i,a,n)      for(int i=a;i<=n;i++)
#define pb             push_back
#define int            long long int
#define ump            unordered_map
#define pii            pair<int,int>
#define ff             first
#define ss             second
#define PI             3.1415926535898
#define inf            1e18
#define all(x)         x.begin(),x.end()
#define vi             vector<int>
#define endl           "\n"
#define print(a)       for(auto x:a){cout<<x<<" ";}cout<<endl;
#define mod            1000000007
using namespace std;
template <typename Arg, typename... Args>
void db(Arg&& arg, Args&&... args) {
    cout << std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cout << ',' << std::forward<Args>(args)), 0)...}; cout << endl;
}
inline void solve() {
    int b, c;
    cin >> b >> c;
    int ans = 0;
    if (c > 2) {
        if (b > 0) {
            ans += (((c - 1) / 2) * 2 + 1 + 1);
            if ((c - 1) % 2 == 0) {
                ans--;
            }
        }
        else if (b <= 0) {
            ans += ((c / 2) + 1) * 2;
            if (c % 2 == 0) {
                ans--;
            }
        }
    }
    else {
        ans = 2;
    }

    if (b == 0) {
        ans--;
    }

    // db(ans);

    if (b > 0 and c > 1) {
        int cnt = (c / 2) * 2;
        if (c % 2 == 0) {
            cnt--;
        }
        int option2 = 2 * b - 1;
        ans += min(cnt, option2);
    }
    else if (b<0 and c>1) {
        c--;
        int cnt = (c / 2) * 2;
        if (c % 2 == 0) {
            cnt--;
        }
        int option2 = 2 * abs(b) - 1;
        ans += min(cnt, option2);
    }
    cout << ans << endl;
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    fl(i, 1, t)
    {
        solve();
    }

    return 0;
}


//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cassert>
#include <numeric>
using namespace std;
//using namespace atcoder;
typedef  long long LONG;
const int MOD = 1000000007;

int gcd(int x, int y) {
	if (x % y == 0) {
		return y;
	}
	else {
		return gcd(y, x % y);
		//x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。
	}
}
LONG pow2(long long x, long long n) {
	long long ret = 1;
	while (n > 0) {
		if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
		x = x * x % MOD;
		n >>= 1;  // n を1bit 左にずらす
	}
	return (int)ret;
}
void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}
int count(vector<int>&a, int s) {
	int result = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == s) {
			result++;
		}
	}
	return result;
}

LONG kaizyo(int N) {
	LONG result = 1;
	LONG mod = 998244353;

	for (LONG i = 2; i <= N; i++) {
		result *= i;
		result = result % mod;
	}
	return result;
}
class Point {
public:
	int x;
	int y;
};
LONG stock[3500][3500];
LONG test(int N, int task) {
	LONG mod = 998244353;
	if (N < task)return 0;
	if (N < 0)return 0;
	if (task == 0) {
		if (N == 0) {
			return 1;
		}
		else {
			return 0;
		}

	}

	if (stock[N][task] > 0)return stock[N][task];
	stock[N][task] = (test(N - 1, task - 1) + test(N, task * 2)) % mod;

	return stock[N][task] % mod;
}
class DP {
public:
	DP() {

	}
	DP(int a, int b) {
		other = a;
		path = b;

	}
	int other;
	int path;
};

void dp(vector<vector<DP>>& list, vector<int> &able, int pos, int limit) {
	for (int i = 0; i < list[pos].size(); i++) {
		if (list[pos][i].path <= limit) {
			if (able[list[pos][i].other] == 0) {
				able[list[pos][i].other] = 1;
				dp(list, able, list[pos][i].other, limit);
			}
		}
	}
}
LONG max(deque<LONG>q) {
	LONG r = -1;
	for (int i = 0; i < q.size(); i++) {
		if (r < q[i]) {
			r = q[i];
		}
	}
	return r;
}
LONG min(deque<LONG>q) {
	LONG r = LLONG_MAX;
	for (int i = 0; i < q.size(); i++) {
		if (r > q[i]) {
			r = q[i];
		}
	}
	return r;
}
LONG P(int N,int k) {
	LONG result = 1;
	for (int i = N; i >N-k; i--) {
		result *= i;
	}
	return result;
}
LONG P2(int N, int k,LONG A) {
	LONG result = 1;
	for (int i = N; i > N - k; i--) {
		result *= i;
		int a = gcd(result, A);
		result /= a;
		A /= a;
	}
	return result;
}
int main() {
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	vector<int>B(M);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	vector<vector<int>>T(N + 1, vector<int>(M + 1));
	for (int i = 0; i < N + 1;i++) {
		T[i][0] = i;
	}
	for (int i = 0; i < M + 1; i++) {
		T[0][i] = i;
	}
	for (int i = 1; i < N + 1; i++) {
		for (int j = 1; j < M + 1; j++) {
			int a = T[i - 1][j]+1;
			a = min(a, T[i][j - 1]+1);
			int b = 0;
			if (A[i-1] != B[j-1]) {
				b++;
			}
			a = min(a, T[i - 1][j - 1] + b);
			T[i][j] = a;
		}
	}
	cout << T[N][M];
	return 0;

}

#include <algorithm>
#include <iostream>
#include <vector>

#include <string.h>
#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_S = 1000;

int dp[MAX_S + 1][MAX_S + 1];

int solve(const vector<int> &s1, const int l1, const vector<int> &s2, const int l2) {
    for (int i = 0; i <= l1; i++) {
        dp[i][0] = i;
        for (int j = 1; j <= l2; j++) {
            if (i == 0) {
                dp[i][j] = j;
                continue;
            }
            if (s1[i - 1] == s2[j - 1]) {
                chmin(dp[i][j], dp[i - 1][j - 1]);
            } else {
                chmin(dp[i][j], dp[i - 1][j - 1] + 1);
            }
            chmin(dp[i][j], dp[i - 1][j] + 1);
            chmin(dp[i][j], dp[i][j - 1] + 1);
        }
    }
    return dp[l1][l2];
}

vector<int> as;
vector<int> bs;

int main(void) {
    int N, M;
    cin >> N >> M;

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    bs.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> bs[i];
    }

    reverse(as.begin(), as.end());
    reverse(bs.begin(), bs.end());

    for (int i = 0; i < MAX_S + 1; i++) {
        for (int j = 0; j < MAX_S + 1; j++) {
            dp[i][j] = INT_MAX / 2;
        }
    }

    if (N < M) {
        cout << solve(as, N, bs, M) << endl;
    } else {
        cout << solve(bs, M, as, N) << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vint = vector<int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }
}
template <typename T>
T& chmin(T& val, T val2) {
    return val = min(val, val2);
}
template <typename T>
T& chmax(T& val, T val2) {
    return val = max(val, val2);
}

void solve() {
    int n; In(n);
    string s; In(s);
    int q; In(q);
    int ocnt = 0;
    REP(iii,q) {
        int t,a,b; In(t,a,b);
        if (t == 1) {
            --a;--b;
            if (ocnt % 2 == 1) {
                swap(s[(a+n)%(2*n)], s[(b+n)%(2*n)]);
            } else {
                swap(s[a], s[b]);
            }
        } else {
            ++ocnt;
        }
    }
    if (ocnt % 2 == 1) {
        REP(i,n) {
            swap(s[i], s[i+n]);
        }
    }
    Out(s);
}

int main() {
    solve();
    /* char tmp; */
    /* while (cin >> tmp) { */
    /*     cin.putback(tmp); */
    /*     solve(); */
    /* } */
}

/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 3e5+9;
ll a[sz],b[sz];
string str,str2;
bool f = 0;
ll get(ll ind,ll n)
{
    if(!f)
        return ind;
    if(ind<=n)
        return n+ind;
    return ind-n;
}
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    FAST
    cin>>n>>str;
    cin>>m;
    while(m--)
    {
        cin>>k>>x>>y;
        if(k==1)
        {
            swap(str[get(x,n)-1],str[get(y,n)-1]);
        }
        else
        {
            f = !f;
        }
    }
    if(f)
        cout<<str.substr(n,n)<<str.substr(0,n)<<endl;
    else
        cout<<str<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;

int prime[N], mu[N], cnt;

bool st[N];

void init() {
  mu[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!st[i]) {
      prime[++cnt] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {
      st[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        break;
      }
      mu[i * prime[j]] = -mu[i];
    }
  }
}

long long calc(int n, int m) {
  if (!n || !m) {
    return 0;
  }
  if (n > m) {
    swap(n, m);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += 1ll * (n / i) * (m / i) * mu[i];
  }
  for (int i = 1; i <= n; i++) {
    ans += m / i;
  }
  for (int i = 1; i <= m; i++) {
    ans += n / i;
  }
  ans -= n;
  ans -= m;
  ans -= min(n, m);
  ans += 1;
  return 1ll * n * m - ans;
}

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  int l, r;
  scanf("%d %d", &l, &r);
  init();
  printf("%lld\n", calc(r, r) + calc(l - 1, l - 1) - 2 * calc(l - 1, r));
  return 0;
}


#include<bits/stdc++.h>
using ll = long long int;
using namespace std;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL)
using ld = long double;
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val)->(strictly less than val) *s.find_by_order(ind)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
const int N = 1e6 + 5;

ll get(vector<ll>&v, ll idx)
{
    ll ans = 0;
    while(idx >= 0)
    {
        ans += v[idx];
        idx = (idx & (idx+1)) - 1;
    }
    return ans;
}
void upd(vector<ll>&v, ll idx, ll val)
{
    while(idx < v.size())
    {
        v[idx] += val;
        idx |= (idx + 1);
    }
}
int main()
{
	sync;
	clock_t clk = clock();
    ll h, w, m;
    cin >> h >> w >> m;
    set<pair<ll, ll> > v;
    ll fir_row = w + 1, fir_col = h + 1;
    for(int i = 0; i < m; i++){
        ll x, y;
        cin >> x >> y;
        v.insert({x, y});
        if(x == 1)
            fir_row = min(fir_row, y);
        if(y == 1)
            fir_col = min(fir_col, x);
    }

    ll ans = h * w;
    vector<ll> bitx(2e5 + 5);
    for(int i = fir_col; i <= h; i++)
        v.insert({i, 1});
    for(int i = fir_row; i <= w; i++)
        v.insert({1, i });
    vector<bool> done(2e5 + 5, false), same(2e5 + 5, false);
    for(auto [x, y]: v){
        if(!same[x])
            ans -= get(bitx, 2e5 + 1) - get(bitx, y) + 1;
        else if(!done[y])
            ans--;
        if(!done[y]){
            done[y] = true;
            upd(bitx, y, 1);
        }
        same[x] = true;
    }
    cout << ans;
 	//cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
}

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

bool ok(int n){
    for(int p : {10, 8}) {
        int cn = n;
        while (cn) {
            if (cn % p == 7) return false;
            cn /= p;
        }
    }
    return true;
}

template <class T> class BIT {
    //T has operator "+=" and can be initialized with 0.
    unsigned int n;
    vector<T> bitree;
public:
    BIT(unsigned long _n) : bitree(_n + 1, 0) {
        n = _n;
    }

    void add(int id, T x) {
        ++id;
        while (id <= n) {
            bitree[id] += x;
            id += id & -id;
        }
    }

    T sum(int id) {
        ++id;
        T temp(0);
        while (id > 0) {
            temp += bitree[id];
            id -= id & -id;
        }
        return temp;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>H>>W>>M;
    vec up(W, H), left(H, W);
    rep(i, M){
        ll x, y; cin>>x>>y;
        --x; --y;
        chmin(up[y], x);
        chmin(left[x], y);
    }
    ll res = 0;
    rep(i, up[0]) res += left[i];
    rep(i, left[0]) res += up[i];
    //cout<<res<<endl;
    BIT<ll> bit(W + 1);
    rep(i, left[0]) bit.add(i, 1);
    priority_queue<P, vector<P>, greater<> > pque;
    rep(i, left[0]) pque.emplace(up[i], i);
    rep(i, up[0]){
        while(!pque.empty()){
            P p = pque.top();
            ll hei = p.first, id = p.second;
            if(hei > i) break;
            pque.pop();
            bit.add(id, -1);
        }
        res -= bit.sum(left[i] - 1);
        //rep(j, W) cout<<bit.sum(j) - (j ? bit.sum(j-1) : 0)<<" \n"[j==W - 1];
        //cout<<bit.sum(left[i] - 1)<<endl;
    }
    cout<<res<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <vector>
#include <tuple>

struct union_find {
  std::vector<int> par;
  union_find(int N): par(N, -1) {}
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  std::tuple<int, int> unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return { -1, -1 };
    if(par[x] > par[y]) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return { x, y };
  }
  int size(int x) {
    return -par[root(x)];
  }
};

using ld = long double;
int main() {
  i64 N;
  cin >> N;
  vector<ld> X(N), Y(N);
  rep(i,0,N) {
    cin >> X[i] >> Y[i];
  }

  rep(i,0,N) {
    X.push_back(X[i]);
    Y.push_back(100);
  }
  rep(i,0,N) {
    X.push_back(X[i]);
    Y.push_back(-100);
  }

  ld ok = 0;
  ld ng = 150;
  rep(t,0,60) {
    ld mid = (ok + ng) / 2;

    union_find uf(3 * N + 2);
    rep(i,0,3*N) rep(j,i+1,3*N) {
      ld dx = (X[i] - X[j]);
      ld dy = (Y[i] - Y[j]);
      ld dist = sqrt(dx * dx + dy * dy) / 2;
      if(dist < mid) {
        uf.unite(i, j);
      }
    }
    i64 s = 3 * N;
    i64 T = 3 * N + 1;
    rep(i,N,2*N) {
      uf.unite(s,i);
    }
    rep(i,2*N,3*N) {
      uf.unite(T,i);
    }
    if(uf.root(s) == uf.root(T)) {
      ng = mid;
    }
    else {
      ok = mid;
    }
  }
  cout << fixed << setprecision(10) << ok << endl;
}

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

#include <bits/stdc++.h>

struct node{
    int x, y;
    bool isLine;
    node() {}
    node(int x, int y) : x(x), y(y), isLine(false) {}
    node(int y) : x(0), y(y), isLine(true) {}
};

double dist(node n1, node n2){
    if (n1.isLine || n2.isLine)
        return std::abs(n1.y - n2.y);
    int dx = n1.x - n2.x;
    int dy = n1.y - n2.y;
    return std::sqrt((double)(dx * dx + dy * dy));
}

int N;
std::vector<node> nodes;

void input(void){
    std::cin >> N;
    nodes.resize(N + 2);
    nodes[0] = node(100);
    nodes[N + 1] = node(-100);
    for (int i = 1; i <= N; ++i){
        int x, y;
        std::cin >> x >> y;
        nodes[i] = node(x, y);
    }
}

double solve(void){
    // d[i] := node 0とnode iを連結にするのに必要なrのmin
    std::vector<double> d(N + 2, 200.0);
    std::queue<std::pair<double, int>> q;
    d[0] = 0.0;
    q.emplace(0.0, 0);
    while (!q.empty()){
        std::pair<double, int> p = q.front();
        q.pop();
        int v = p.second;
        if (d[v] > p.first) continue;
        for (int i = 0; i < N + 2; ++i)
        if (i != v){
            double distance = dist(nodes[v], nodes[i]);
            double tmp = std::max(p.first, distance);
            if (d[i] > tmp){
                d[i] = tmp;
                q.emplace(tmp, i);
            }
        }
    }
    return d[N + 1] / 2;
}

int main(void){
    input();
    std::cout << std::setprecision(15) << solve() << std::endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
const int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=105;
int n,a[MN],k; string s;
map<char,int>mp; const char tt[4]={'R','P','S'};
char get(char x,char y) {
	if(x==y) return x;
	int a=mp[x],b=mp[y];
	if(a<b) swap(a,b);
//	cerr<<a<<' '<<b<<endl;
	if(a==2&&b==0) return tt[0];
	else return tt[a];
}
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	cin>>n>>k>>s; mp['R']=0,mp['P']=1,mp['S']=2;
//	cerr<<s<<endl;
	while(k>10||s.size()<(1<<k)) {

//		cerr<<s<<endl;
		if(s.size()&1) s=s+s;
		if(k<10&&s.size()>(1<<k)) break;
		string t;

		for(int i=0;i<s.size();i+=2) {
			t.pb(get(s[i],s[i+1]));
		}
		s=t; k--;
	}
	int now=1<<k;
	string t;
	For(i,0,now-1) {
		t.pb(s[i]);
	}
	s=t;
	while(s.size()>1) {
		if(s.size()&1) s=s+s;
		string t;
		for(int i=0;i<s.size();i+=2) {
			t.pb(get(s[i],s[i+1]));
		}
		s=t; k--;
	}
//	cerr<<s[0]<<endl;
	cout<<s<<endl;
	return FastIO::Fflush(),0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define repr(i, n, s) for (int i = (int)n; (int)s < i; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力 vi, vl, list<int>, list<ll>に対応  */
template<class T> void print_elements(T a) {string str = ""; for (auto itr = a.begin(); itr != a.end(); ++itr) \
        {str += to_string(*itr) + ' ';} str.pop_back(); cout << str << endl;}

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);

int main() {
    string S;
    cin >> S;
    string ans = "";
    reverse(all(S));
    for (auto c: S) {
        if (c == '6') {
            ans += '9';
        }
        else if (c == '9') {
            ans += '6';
        }
        else {
            ans += c;
        }
    }
        cout << ans << endl;
}


//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll n,m; cin >> n >> m;
    vec<vec<P>> tree(n);
    vec<set<ll>> s(n);
    rep(i,m){
        ll u,v,c; cin >> u >> v >> c; --u; --v;
        tree[u].emplace_back(make_pair(v,c));  s[u].insert(v);
        tree[v].emplace_back(make_pair(u,c));  s[v].insert(u);
    }
    vec<ll> c(n,-1);
    queue<ll> que; que.push(0);
    ll st = 1;
    while(c[0] == -1){
        if(!s[0].count(st))c[0] = st;
        st++;
    }
   while(!que.empty()){
        ll now = que.front();
        que.pop();
        for(auto p : tree[now]){
            if(c[p.first] != -1)continue;
            if(c[now] != p.second)c[p.first]=p.second;
            else c[p.first] = (p.second+1)%n;
            que.push(p.first);
        }
    }
    rep(i,n)cout << c[i] << endl;
}

#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define INF 0x3f3f3f3f
#define f first
#define s second
#define pii pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mem(x, a) memset(x, a, sizeof(x))
#define loli ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int maxn = 1e6 + 50;
int n, m, color[maxn];
vector<pii> vc[maxn];
bitset<maxn> vis, ok;

void dfs(int x, int val){
	color[x] = val;
	for(auto i : vc[x]){
		if(color[i.f]) continue;
		if(i.s == color[x]){
			if(i.s == 1) dfs(i.f, 2);
			else dfs(i.f, 1);
		}
		else dfs(i.f, i.s);
	}
}

signed main(){
	loli;
	//freopen("/home/iceylemon157/Desktop/test.in", "r", stdin);
	//freopen("/home/iceylemon157/Desktop/test.out", "w", stdout);
	cin >> n >> m;
	for(int i = 1; i <= m; i ++){
		int a, b, v;
		cin >> a >> b >> v;
		vc[a].pb({b, v});
		vc[b].pb({a, v});
	}
	dfs(1, 1);
	for(int i = 1; i <= n; i ++){
		cout << color[i] << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

int main(void){

    ll X;
    cin >> X;
    X%=100;
    cout << 100-X << endl;

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    cout << 100 - (n % 100) << endl;
}


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

#define for0(i, n) for (int i = 0; i < (int)(n); i++)
#define for1(i, n) for (int i = 1; i <= (int)(n); i++)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(x) for(auto it = x.begin(); it != x.end(); it++)
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define inf 1e18

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll , ll> pll;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

ll findGCD(ll arr[], ll n)
{
    ll result = arr[0];
    for (ll i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if (result == 1)
        {
            return 1;
        }
    }
    return result;
}

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

void solve() {
    int n; cin>>n;
    int w; cin>>w;
    cout << n/w;
}

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

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

#define ll long long
#define ull unsigned long long
#define INF LONG_LONG_MAX
#define gcd __gcd

void solve(){
	ll n,w;
	cin>>n>>w;
	cout<<n/w<<"\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long t=1;
	//cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<typename T> using posteriority_queue = priority_queue<T,vector<T>,greater<T>>;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--)
#define repR2(i,a,b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define pb push_back
#define SIZE(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define UNIQUE(a) a.erase(unique(all(a)),a.end());
#define debug(x) cout<<(#x)<<" is : "<<(x)<<endl;
#define debugc(vec) {cout<<(#vec)<<" is below; -------"<<endl;for(auto elements:(vec))cout<<elements<<" ";cout<<endl<<"------------------"<<endl;}
inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;}
template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;}
template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;}
const char ENDL = '\n';
const ll INF = (1LL<<30)-1;
const ll INFLL = (1LL<<62)-1;
const ld PI = 3.14159265358979323846L;
const ld EPS = 1e-8;
int main() {
    cout << fixed << setprecision(15);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int a,b,c; cin>>a>>b>>c;
    if(a==b) cout<<c<<endl;
    else if(b==c) cout<<a<<endl;
    else if(c==a) cout<<b<<endl;
    else cout << 0 << endl;
}

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
	#include "dbg.h"
#else
	#define out(...)
#endif

void solve () {
    int n;
    string s, t;
    cin >> n >> s >> t;
    vector<int> idxs, idxt;

    for (int i = 0; i < n; ++i) {
        if (s[i] == '0') idxs.push_back (i);
        if (t[i] == '0') idxt.push_back (i);
    }

    if ((int) idxs.size() != (int) idxt.size()) {
        cout << -1 << '\n';
        return ;
    }
    int cnt = 0;

    for (int i = 0; i < (int) idxt.size(); ++i) {
        if (idxt[i] != idxs[i])
            ++cnt;
    }
    cout << cnt << '\n';
}

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

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

	for (int i = 1; i <= tc; ++i)
		solve ();
}


#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

struct Modint {
  ll val;

  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 1e5 + 5;

int arr [MAX_N];
Modint sum [MAX_N][2];
Modint cnt [MAX_N][2];

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

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

  cnt[0][0] = Modint(1);
  sum[0][0] = Modint(arr[0]);

  for (int i = 1; i < n; i++) {
    cnt[i][0] = cnt[i - 1][0] + cnt[i - 1][1];
    sum[i][0] = sum[i - 1][0] + sum[i - 1][1] + cnt[i][0] * Modint(arr[i]);

    cnt[i][1] = cnt[i - 1][0];
    sum[i][1] = sum[i - 1][0] + cnt[i][1] * -Modint(arr[i]);
  }

  cout << sum[n - 1][0] + sum[n - 1][1] << '\n';
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <bitset>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <cmath>

#define ll long long
#define mod 1000000007
//#define mod 998244353
#define pi pair< int,int >
#define pll pair<long long ,long long>

#define vi vector<int>
#define vll vector< long long  >
#define vb vector<bool>
#define vvi vector<vector<int> >
#define nl "\n"
#define mp make_pair
#define pb push_back
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

#define for_ab(i,a,b) for(long long i=a ;i<b ;++i)
#define for_n( i , n) for_ab(i , 0ll , n)
#define all(v)  v.begin() , v.end()

using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int , null_type, less_equal<int> , rb_tree_tag ,tree_order_statistics_node_update>
*/
bool isprime(ll a){
	for(ll i=2;i<=pow(a,0.5);++i){
		if(a%i==0){
			return false;
		}

	}
	return true;
}
ll ceil(ll a, ll b){
	ll c=(a+b-1)/b;
	return c;
}

ll gcd(ll a , ll b){
	if(a==0){
		return b;
	}
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}
ll power_mod(ll a , ll b){
	if(b==0){
		return 1;
	}
	ll temp=power_mod(a , b/2);
	temp=(temp*temp)%mod;
	if(b%2){
		temp=(temp*a)%mod;
	}
	return temp;
}
/*ll NCR(ll n , ll r){
	n=fact[n];

	ll a=fact[r] , b=fact[n-r];
	a=power_mod(a,mod-2);
	b=power_mod(b , mod-2);
	a=(a*b)%mod;
	n=(n*a)%mod;
	return n;

}*/
void help(vi v){
	cout<<v.size()<<' ';
	for(int i:v){
		cout<<i<<' ';
	}
	cout<<nl;
}
int main(){
		ios::sync_with_stdio(0);
		cin.tie(0);
	/*	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
		int t=1;
		//cin>>t;

        while(t--){

        	int n;cin>>n;
        	vi v(n);

        	for_n(i , n){
        		cin>>v[i];
        	}
        	vector<vector<int> > ans(200);

        	int curr=min(n,8);
        	vi total;
        	for_n(i , curr){
        		total.pb(v[i]);
        	}

        	for(int i=1;i<(1<<curr);++i){

        		vector<int>temp;
        		int sum=0;
        		for(int j=0;j<curr;++j){
        			if(i &(1<<j)){
        				temp.pb(j+1);
        				sum=(sum+total[j])%200;
        			}
        		}
        		if(ans[sum].size()){
        			yes;
        			help(temp);
        			help(ans[sum]);
        			return 0;
        		}
        		ans[sum]=temp;

        	}
        	no;
        	return 0;

        	}

}


#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))

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 ALL(a) (a).begin(), (a).end()

const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;

int main(){
  string S;
  cin >> S;
  cout << S[1] << S[2] << S[0] << endl;
}

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

int32_t main()
{
    int t = 1;
    while(t--)
    {
        int n, ans;
        cin>>n;

        for( int i = 1; i < 1e5; i++ )
        {
            n -= i;
            if( n <= 0 )
            {
                ans = i;
                break;
            }
        }

        cout<<ans<<"\n";
    }

    return 0;
}


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

#define ll long long int
#define ld double
#define pb push_back
#define eb emplace_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<double>	vd;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define debug(a...) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;
#define MAXIM 100005
ll MAX = 2e4 + 1;
ll mod = 1e9 + 7;

void solve(){
    ll n;
    cin >> n;
    vector<vll> v(n,vll(2));
    rep(i,0,n) cin >> v[i][0] >> v[i][1];
    ll m;
    cin >> m;
    vb sw(m + 1);
    vector<vll> neg(m + 1,vll(2,1)),c(m + 1,vll(2));
    rep(i,1,m + 1){
        neg[i] = neg[i - 1];
        c[i] = c[i - 1];
        sw[i] = sw[i - 1];
        ll op;
        cin >> op;
        if(op == 1 || op == 2){
            sw[i] = !sw[i];
            swap(c[i][0],c[i][1]);
            swap(neg[i][0],neg[i][1]);
            if(op == 1){
                c[i][1] *= -1;
                neg[i][1] *= -1;
            }
            else{
                c[i][0] *= -1;
                neg[i][0] *= -1;
            }
        }
        else{
            ll p;
            cin >> p;
            if(op == 3){
                c[i][0] *= -1;
                neg[i][0] *= -1;
                c[i][0] += 2*p;
            }
            else{
                c[i][1] *= -1;
                neg[i][1] *= -1;
                c[i][1] += 2*p;
            }
        }
    }
    ll q;
    cin >> q;
    rep(i,0,q){
        ll a,ind;
        cin >> a >> ind;
        ind--;
        ll x = v[ind][0],y = v[ind][1];
        if(sw[a]) swap(x,y);
        x *= neg[a][0];
        y *= neg[a][1];
        x += c[a][0];
        y += c[a][1];
        cout << x << " " << y << br;
    }

}

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

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

	ll t = 1;
    // cin >> t;
    // cout << p.size();
	rep(i,0,t){
        // cout << "Case #" << i + 1 << ": ";
        solve();
        // test();
	}
}

#include <cstdio>
#include <algorithm>
typedef long long ll;
const int N = 200005;
int n, m, q;
ll x[N], y[N];
struct Option
{
	int ty;
	ll p;
}op[N];
struct Query
{
	int a, b, id;
}p[N];
int np;
inline bool cmp(Query a, Query b)
{
	return a.a < b.a;
}
ll ansx[N], ansy[N];
ll flx, flxa, fly, flya, rot;
void get(ll x, ll y, ll& rx, ll& ry)
{
	for(int i = 1;i <= rot;++i)
	{
		std::swap(x, y);
		x *= -1;
	}
	rx = x*flxa+flx;
	ry = y*flya+fly;
	return;
}
int main(void)
{
	scanf("%d", &n);
	for(int i = 1;i <= n;++i)
		scanf("%lld%lld", x+i, y+i);
	scanf("%d", &m);
	for(int i = 1;i <= m;++i)
	{
		scanf("%d", &op[i].ty);
		if(op[i].ty >= 3)
			scanf("%lld", &op[i].p);
	}
	scanf("%d", &q);
	for(int i = 1;i <= q;++i)
		scanf("%d%d", &p[i].a, &p[i].b), p[i].id = i;
	std::sort(p+1, p+1+q, cmp);
	np = 1;
	flxa = flya = 1;
	for(int i = 0;i <= m;++i)
	{
		if(op[i].ty == 1)
		{
			rot = (rot+3)%4;
			std::swap(flx, fly), std::swap(flxa, flya);
			fly *= -1;
		}
		else if(op[i].ty == 2)
		{
			rot = (rot+1)%4;
			std::swap(flx, fly), std::swap(flxa, flya);
			flx *= -1;
		}
		else if(op[i].ty == 3)
			flxa *= -1, flx = -flx+2*op[i].p;
		else if(op[i].ty == 4)
			flya *= -1, fly = -fly+2*op[i].p;
		while(np <= q && p[np].a == i)
			get(x[p[np].b], y[p[np].b], ansx[p[np].id], ansy[p[np].id]), ++np;
	}
	for(int i = 1;i <= q;++i)
		printf("%lld %lld\n", ansx[i], ansy[i]);
	return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define STRING(str) #str
#define ll long long
#define ld long double

template <typename T>
void print(T x, string name) {
	cout << name+": " << x << endl;
}

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

template <typename T >
void print_vec_2d(vector<vector<T>> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << "[ ";
		for (int j=0;j<x[i].size();j++) {
			cout << x[i][j];
			if (j != x[i].size()-1) cout << ", ";
			else {
				cout << " ]";
				if (!((i == x.size()-1) && (j == x[i].size()-1))) {
					cout << "," << endl;
				}
			}
		}
	}
	cout << " ]" << endl;
}

template <typename T >
void print_vec_3d(vector<vector<vector<T>>> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << "[ ";
		for (int j=0;j<x[i].size();j++) {
			cout << "[ ";
			for (int k=0;k<x[i][j].size();k++) {
				cout << x[i][j][k];
				if (k != x[i][j].size()-1) cout << ", ";
				else {
					cout << " ]";
					if (!((i == x.size()-1) && (j == x[i].size()-1) && (k == x[i][j].size()-1))) {
						cout << "," << endl;
					}
				}
			}
			if (j != x[i].size()-1) cout << ", ";
			else {
				cout << " ]";
				if (!((i == x.size()-1) && (j == x[i].size()-1))) {
					cout << "," << endl;
				}
			}
		}
	}
	cout << " ]" << endl;
}

ll mod = 998244353;

long long modpow(long long a, long long x) {
    long long tmp = x;
    long long val = a;
    long long ret = 1LL;
    while (tmp>0) {
        if (tmp%2 == 1) ret = ret*val%mod;
        val = val*val%mod;
        tmp /= 2;
    }
    return ret;
}

long long modinv(long long a) {
    return modpow(a, mod-2);
}

ll H, W, K;
vector<int> h, w;
vector<char> c;

vector<vector<ll>> dp;
map<pair<int, int>, char> char_mp;

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

	cin >> H >> W >> K;

	dp = vector<vector<ll>>(H, vector<ll>(W, 0LL));
	// dp[0][0] = 1LL;
	dp[0][0] = modpow(3LL, H*W-K);
	h = vector<int>(K);
	w = vector<int>(K);
	c = vector<char>(K);
	for (int i=0;i<K;i++) {
		cin >> h[i] >> w[i] >> c[i];
		h[i]--;w[i]--;
		char_mp[make_pair(h[i], w[i])] = c[i];
	}

	ll modinv_3_2 = modinv(3)*2%mod;
	// 配るdp
	for (int i=0;i<H;i++) {
		for (int j=0;j<W;j++) {
			pair<int, int> p = make_pair(i, j);
			if (char_mp.count(p)) {
				char tmp = char_mp[p];
				if (tmp == 'R') {
					if (j+1 < W) {
						dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod;
					}
				} else if (tmp == 'D') {
					if (i+1 < H) {
						dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
					}
				} else { // tmp == 'X'
					if (j+1 < W) {
						dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod;
					}
					if (i+1 < H) {
						dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
					}
				}
			} else {
				if (j+1 < W) {
					dp[i][j+1] = (dp[i][j+1]+dp[i][j]*modinv_3_2)%mod;
				}
				if (i+1 < H) {
					dp[i+1][j] = (dp[i+1][j]+dp[i][j]*modinv_3_2)%mod;
				}
				// if (j+1 < W) {
					// dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod;
				// }
				// if (i+1 < H) {
					// dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
				// }
			}
		}
	}

	// print_vec_2d(dp, STRING(dp));

	cout << dp[H-1][W-1] << "\n";
}

#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod=998244353;
const int mex=5002;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
#define int long long
int dp[mex][mex];
char a[mex][mex];
int power(int a,int b)
{
    int ans=1,f=a;
    while(b)
    {
        if(b&1) ans=(ans*f)%mod;
        f=(f*f)%mod;
        b=b>>1;
    }
    return ans;
}
signed main()
{
    int h,w,k;
    cin>>h>>w>>k;
    fo(i,1,h+1)
    fo(j,1,w+1)
    a[i][j]=0;

    fo(i,0,k)
    {
        int a1,b;
        char c;
        cin>>a1>>b>>c;
        a[a1][b]=c;
    }
    dp[1][1]=1;
    int fr1[h+1]={0},fr2[w+1]={0};
    fo(i,1,h+1)
    fo(j,1,w+1)
    {
        int cn1=0,cn2=0;
        if(i>1)
        {
            if(a[i-1][j]=='D'||a[i-1][j]=='X') dp[i][j]=(dp[i][j]+(power(3,fr1[i])*dp[i-1][j])%mod)%mod;
            else if(a[i-1][j]==0) dp[i][j]=(dp[i][j]+((2*power(3,fr1[i]))%mod*dp[i-1][j])%mod)%mod;
            if(a[i-1][j]==0) cn1++;
        }
        if(j>1)
        {
            if(a[i][j-1]=='R'||a[i][j-1]=='X') dp[i][j]=(dp[i][j]+(power(3,fr2[j])*dp[i][j-1])%mod)%mod;
            else if(a[i][j-1]==0) dp[i][j]=(dp[i][j]+((2*power(3,fr2[j]))%mod*dp[i][j-1])%mod)%mod;
            if(a[i][j-1]==0) cn2++;
        }
        // if(cn1&&cn2) dp[i][j]=(dp[i][j]*6)%mod;
        // else if(cn1||cn2)
        // {  dp[i][j]=(dp[i][j]*2)%mod;
        // if(cn1==0&&i>1&&a[i-1][j]=='D') dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
        // if(cn2==0&&j>1&&a[i][j-1]=='R') dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
        // }
        if(a[i][j]==0) {fr1[i]++;fr2[j]++;}
    }
//     fo(i,1,h+1)
//  {   fo(j,1,w+1)
//     {
//         cout<<dp[i][j]<<" ";
//     }
//     cout<<endl;
// }
   if(a[h][w]==0) dp[h][w]=(dp[h][w]*3)%mod;
    cout<<dp[h][w]%mod<<endl;

}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define bck(i, a, b) if ((i) >= (a) && (i) < (b))
#define trav(x, a) for (auto &x : (a))
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dbg(X) std::cerr << "[DBG]("<<__FUNCTION__<<":"<<__LINE__<<") " << #X << ": " << X << std::endl;
using namespace std;
typedef long long ll;
typedef string str;
template<typename T> using vec = vector<T>;
template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>;
template<typename T> using mxpq = priority_queue<T>;
typedef pair<int,int> pii;
typedef vec<int> vi;
typedef vec<pii> vii;
typedef vec<vi> vvi;
typedef pair<ll,ll> pll;
typedef vec<ll> vl;
typedef vec<pll> vll;
typedef vec<vl> vvl;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename A, typename B>
istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; }
template<typename T>
istream& operator>>(istream& s, vec<T>& p) {
    for (T& t : p) s >> t;
    return s;
}

#define MOD 1000000007ll

ll modpow(ll b, ll e, ll mod=MOD) {
    if (e < 0) return modpow(modpow(b, mod-2, mod), -e, mod);
    ll r = 1;
    while (e) {
        if (e & 1) r = r*b % mod;
        b = b*b % mod;
        e /= 2;
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int h, w; cin >> h >> w;
    vec<str> g(h); cin >> g;
    vi _gg(w*h);
    auto& gg = *(int (*)[h][w]) &_gg[0];
    rep(i, 0, h) {
        int l=0;
        rep(j, 0, w) {
            if (g[i][j] == '#') {
                rep(k, l, j) gg[i][k] = j-l;
                l = j+1;
            }
        }
        rep(k, l, w) gg[i][k] = w-l;
    }
    rep(j, 0, w) {
        int l=0;
        rep(i, 0, h) {
            if (g[i][j] == '#') {
                rep(k, l, i) gg[k][j] += i-l-1;
                l = i+1;
            }
        }
        rep(k, l, h) gg[k][j] += h-l-1;
    }
    ll k = 0;
    trav(v, g) trav(c, v) k += c=='.';
    ll s = 0;
    vl p2(k+1, 1); rep(i,1,k+1) p2[i] = 2*p2[i-1] % MOD;
    rep(i,0,h) rep(j,0,w)
        (s += p2[k] - p2[k-gg[i][j]] + MOD) %= MOD;
    cout << s << endl;
}

#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
int n,m;
int mul[5009][5009];
int sm[5009][5009];
void init()
{
	for(int i=0;i<=m;i++)
	{
		mul[i][0]=1;
		for(int j=1;j<=n;j++)
		{
			mul[i][j]=(ll)mul[i][j-1]*i%mod;
			// printf("i:%d j:%d mul:%d\n",i,j,mul[i][j]);
		}
	}
	memcpy(sm,mul,sizeof(sm));
	for(int j=0;j<=n;j++)
		for(int i=1;i<=m;i++)
		{
			(sm[i][j]+=sm[i-1][j])%=mod;
			// printf("i:%d j:%d sm:%d\n",i,j,sm[i][j]);
		}
}
void solve()
{
	int ans=(ll)mul[m][n]*n%mod;
	int rv=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=i-1;j++)
		{
			// int tm=(ll)sm[m-1][i-j-1]*mul[m][j-1]%mod;
			// printf("i:%d j:%d tm:%d\n",i,j,tm);
			rv=(rv+(ll)sm[m-1][i-j-1]*mul[m][j-1]%mod*mul[m][n-i])%mod;
		}
	}
	ans=(ans-rv+mod)%mod;
	printf("%d",ans);
}
int qpow(int a,int b)
{
	int ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1)
			ans=(ll)ans*a%mod;
	return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	init();
	solve();
	return 0;
}


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

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

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

vector<int> convolution(int siz, vector<int>& a, vector<int>& b){
    int n = (1 << siz);
    vector<int> c(n, 0);

    vector<int> a_subset = a;
    vector<int> b_subset = b;
    for(int i = 0; i < siz; ++i){
        for(int j = 0; j < n; ++j){
            if(!(j & (1 << i))){
                a_subset[j] += a_subset[j | (1 << i)];
                b_subset[j] += b_subset[j | (1 << i)];
            }
        }
    }
    for(int i = 0; i < n; ++i)
        c[i] = a_subset[i] * b_subset[i];

    for(int i = 0; i < siz; ++i){
        for(int j = 0; j < n; ++j){
            if(!(j & (1 << i)))
                c[j] -= c[j | (1 << i)];
        }
    }
    return c;
}

void solve(long long n, long long m, std::vector<long long> a, std::vector<long long> b){

    vector<vector<int>> v(n,vector<int>(n, 0));
    for(int i = 0; i < m; ++i){
        --a[i], --b[i];
        v[a[i]][b[i]] = 1;
    }
    vector<int> dp(1 << n, n);
    for(int i = 0; i < (1 << n); ++i){
        bool fl = true;
        for(int j = 0; j < n; ++j){
            for(int k = j + 1; k < n; ++k){
                if((i & (1 << j)) && (i & (1 << k)) && (!v[j][k]))
                    fl = false;
            }
        }
        if(fl)
            dp[i] = 1;
    }
    for(int i = 0; i < (1 << n); ++i){
        for(int j = i; j >= 0; j = (j - 1) & i){
            chmin(dp[i], dp[j] + dp[i ^ j]);
            if(!j)
                break;
        }
    }
    cout << dp.back() << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <bits/stdc++.h>
using namespace std;

#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define MAX 1000005
#define MOD 1000000007
#define EXP 1e-8
#define lowbit(x) (x&-x)
// const int INF = 0x1fffffffffffffff;
const int INF = INT_MAX;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }

int main () {
    int n, m; cin >> n >> m;
    int x, y, z;
    vector<vector<pair<int, int>>> cs(n+1);
    for (int i = 0; i < m; ++i){
        cin >> x >> y >> z;
        cs[x-1].emplace_back(y, z);
    }
    vector<ll> dp(1 << n);
    dp[0] = 1;
    queue<int> q;
    unordered_set<int> hash;
    q.push(0);
    int pos = 0;
    while (!q.empty()) {
        int size = q.size();
        while (size--) {
            int state = q.front(); q.pop();
            for (int i = 0; i < n; ++i) {
                int num = (1 << i);
                if (state & num) continue;
                int newState = state | num;
                bool flag = true;
                for (auto &it : cs[pos]) {
                    y = it.first, z = it.second;
                    int mask = (1 << y) - 1;
                    if (__builtin_popcount(newState & mask) > z) {
                        flag = false; break;
                    }
                }
                if (flag) dp[newState] += dp[state];
                // cout << state << ' ' << newState << ' ' << dp[newState] << endl;
                if (!hash.count(newState))
                    q.push(newState), hash.insert(newState);
            }
        }
        // cout << pos <<endl;
        pos++;
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ff   first
//#define ss   second
#define ll  long long int
#define PB   push_back
#define MP  make_pair
#define mii  map<int,int>
#define pqb  priority_queue<int>
#define pqs  priority_queue<int,vi,greater<int> >
#define mod  1000000007
#define sp(x,y)  fixed<<setprecision(y)<<x
#define rz resize
#define FOR(a, b) for (auto (a) : (b))
#define t(x)  int x; cin>>x; while(x--)
mt19937     rng(chrono::steady_clock::now().time_since_epoch().count());
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x)
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REP(i, a, b) for (ll i=a; i<=b; i++)
#define PI 3.1415926535897932384626
#define RALL(x) rbegin(x),rend(x)
#define endl "\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

ll D, X, Y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        D = A;
        X = 1;
        Y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = X;
        X = Y;
        Y = temp - (A/B)*Y;
    }
}

ll modInverse(ll A, ll M)
{
    extendedEuclid(A,M);
    return (X%M+M)%M;    //x may be negative
}

void SOE(int n)
{   bool pr[n+1];
     memset(pr, true, sizeof(pr));

    for (int p=2; p*p<=n; p++)
    {
        if (pr[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                pr[i] = false;
        }
    }
    int i=0;
     for (int p=2; p<=n; p++)
       if (pr[p]){
        cout<<p<<" ";
       }

}
bool isP(int n)
{  bool flag=1;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            flag = 0;
            break;
        }
    }
    if(n<=1)
    flag=0;
    else if(n==2)
    flag=1;
    return flag;
}

ll modularExponentiation(ll x,ll n,ll M)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

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

}

ll modBigNumber(string num, ll m)
{
    // Store the modulus of big number
    vector<int> vec;
    ll mod1 = 0;
    string s=to_string(m);
    // Do step by step division
    for (int i = 0; i < num.size(); i++) {

        int digit = num[i] - '0';

        // Update modulo by concatenating
        // current digit.
        mod1 = mod1 * 10 + digit;

        // Update quotient
        int quo = mod1 / m;
        vec.push_back(quo);

        // Update mod for next iteration.
        mod1 = mod1 % m;
    }
  //  cout << "\nRemainder : " << mod << "\n";

    return mod1 ;
}

void aks()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  if(d*c-b==0)
  {
      cout<<-1;
      return ;
  }
  double ans=(double)a/(double)(d*c-b);
  if(ans>=0)
    {
        if(a%(d*c-b)!=0)
        {
            ll x=(ll)ans+1;
            cout<<x;
        }
        else
        {
            cout<<(ll)ans;
        }
    }
  else
    cout<<-1;

}

int main(){
     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    // code here
   // solve();
       //t(x)
       {
           aks();
       }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x0, y0, xhalf, yhalf;
  cin >> n >> x0 >> y0 >> xhalf >> yhalf;
  double cx = (xhalf + x0) / 2.0, cy = (yhalf + y0) / 2.0;
  double rad = 2 * M_PI / (double)n;
  double ansx = cos(rad) * x0 - sin(rad) * y0 + cx - cx * cos(rad) + cy * sin(rad);
  double ansy = sin(rad) * x0 + cos(rad) * y0 + cy - cx * sin(rad) - cy * cos(rad);
  cout << setprecision(10) << ansx << " " << ansy << endl;
}


#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << (x) << "\n"
using namespace std;
set<int>s; map<int, int>m; int n, CK, a[234567], b[234567], c[234567], dp[456789];
signed main() {
	cin >> n >> CK;
	for1(i, n) {
		cin >> a[i] >> b[i] >> c[i];
		s.insert(a[i]);
		s.insert(++b[i]);
	}
	auto itr = s.begin();
	for1(i, s.size()) m[*itr++] = i;
	for1(i, n) { dp[m[a[i]]] += c[i]; dp[m[b[i]]] -= c[i]; }
	itr = s.begin();
	for1(i, s.size()) {
		dp[i] += dp[i - 1]; dp[456543] -= min(dp[i], CK) * (*itr); dp[456543] += min(dp[i], CK) * (*++itr);
	}
	puts(dp[456543]);
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vll;

typedef vector<vi> vvi;
typedef vector<vll> vvll;

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

typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

namespace debug {
    void __print(int x) {cerr << x;}
    void __print(long long x) {cerr << x;}
    void __print(double x) {cerr << x;}
    void __print(long double x) {cerr << x;}
    void __print(char x) {cerr << '\'' << x << '\'';}
    void __print(const string &x) {cerr << '\"' << x << '\"';}
    void __print(bool x) {cerr << (x ? "true" : "false");}

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ljuba
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
}

using namespace debug;

const char nl = '\n';

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

vpii doga[30];
bool ok[1<<21];
ll dp[1<<21];

void solve() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        doga[x].pb({y, z});
    }

    ok[0] = 1;

    for(int mask = 1; mask < (1<<n); ++mask) {
        int k = __builtin_popcount(mask);
        ok[mask] = 1;
        for(auto z : doga[k]) {
            int cnt = 0;
            for(int i = 0; i < z.fi; ++i) {
                cnt += (mask>>i)&1;
            }
            if(cnt > z.se) ok[mask] = 0;
        }
    }

    dp[0] = 1;

    for(int mask = 1; mask < (1<<n); ++mask) {
        if(!ok[mask]) {
            dp[mask] = 0;
            continue;
        }

        for(int i = 0; i < n; ++i) {
            if((mask>>i)&1) {
                dp[mask] += dp[mask^(1<<i)];
            }
        }
    }

    cout << dp[(1<<n)-1] << nl;
}

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

#ifdef ljuba
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

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

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  unordered_map<ll,ll> mp;
  rep(i,n) {
    for(ll x = 1; x*x <= a[i]; x++) {
      if(a[i] % x == 0) {
        mp[x] = (mp[x] ? gcd(mp[x],a[i]) : a[i]);
        mp[a[i]/x] = (mp[a[i]/x] ? gcd(mp[a[i]/x],a[i]) : a[i]);
      }
    }
  }
  int ans = 0;
  for(auto x : mp) if(x.first == x.second and x.first <= a[0]) ans++;
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n;
    int m=5;

    cin >> n;
    vector<vector<int>> s(n,vector<int>(m));

    rep(i,n)rep(j,m) cin >> s[i][j];

    int l=0; int r=1001001001;
    while(l+1<r){
        int mid = (l+r)/2;
        int x;
        vector<int> b;
        rep(i,n){
            x=0;
            rep(j,m){
                if(s[i][j]>=mid){
                    x|=1<<j;
                }
            }
        b.push_back(x);
        }
        sort(b.begin(),b.end());
        b.erase(unique(b.begin(),b.end()),b.end());
        bool ok=false;
        rep(i,b.size())rep(j,i+1)rep(k,j+1){
            if((b[i]|b[j]|b[k])==(1<<m)-1){
                ok=true;
            }
        }
        if(ok){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    cout << l << endl;
    return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<int, int> P;
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 long long mod = 1e9 + 7;
int dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };
ll cb(ll a, ll b);

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) cout << "White" << endl;
    else cout << "Black" << endl;
    return 0;
}

ll cb(ll a, ll b) {
    ll ans = 1;
    rep(i, b) ans *= (a - i);
    rep(i, b) ans /= (b - i);

    return ans;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int x;
    cin>>x;
    x%2?printf("Black"):printf("White");
}


/***
    Description: Simulation

   * author:    Diego Briaares
   * date:   24.01.2021 18:11:37
***/

#include <bits/stdc++.h>
using namespace std;
	int main () {
		ios_base::sync_with_stdio(0);
		cin.tie(0);
		string a, b;
		cin >> a >> b;
		int sa = 0, sb = 0;
		for (int i = 0; i < a.size(); i++) {
			sa += a[i] - '0';
			sb += b[i] - '0';
		}
		cout << max(sa, sb) << "\n";
	}

#include <bits/stdc++.h>

using namespace std;

int main()
{

  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // to read the input from file
  // freopen("cpp_input.txt", "r", stdin);
  int num1, num2, rem1, rem2, sum1 = 0, sum2 = 0;
  cin >> num1 >> num2;
  while (num1 > 0 and num2 > 0)
  {
    rem1 = num1 % 10;
    sum1 += rem1;
    num1 /= 10;
    rem2 = num2 % 10;
    sum2 += rem2;
    num2 /= 10;
  }
  if (sum1 > sum2)
    cout << sum1;
  else
    cout << sum2;
}


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

typedef long long int ll;

int main()
{
    unsigned long long n;
    cin >> n;

    unsigned long long sa = 3, sb = 5, a, b;
    for(a = 1;sa <= n;a++){
        sb = 5;
        for(b = 1;sb <= n;b++){
            if(sa == n - sb){
                cout << a << " " << b;
                return 0;
            }
            else if(sa > n - sb){
                break;
            }
            unsigned long long t = sb;
            sb *= (unsigned long long)5;
            if(sb / (unsigned long long)5 != t){
                break;
            }
        }
        unsigned long long t = sa;
        sa *= (unsigned long long)3;
        if(sa / (unsigned long long)3 != t){
            break;
        }
    }

    cout << -1;

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

li n, m;

bool read () {
	if (scanf("%lld%lld", &n, &m) != 2)
		return false;
	return true;
}

void solve() {
	for (li i = 1; i * i <= m; ++i) if (m % i == 0){
		li x = i, y = m / i;
		if (x + y == n){
			puts("Yes");
			return;
		}
	}
	puts("No");
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();
#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {
#else
	if(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


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

typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
ll vx[4]={0,1,0,-1};
ll vy[4]={1,0,-1,0};
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll pow(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=pow(N,P/2,M);
        return t*t%M;
    }
    else return N*pow(N,P-1,M)%M;
}

vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A.at(i);
    sort(A.begin(),A.end());
    ll s=0;
    ll ans=0;
    rep(i,N){
        if(i==0)s=1;
        else if(A.at(i-1)==A.at(i))s++;
        else{
            ans+=(N-s)*s;
            s=1;
        }
    }
    ans+=(N-s)*s;
    cout<<ans/2<<endl;
}

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

#define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i)
#define per(i, n) for(int i = (n)-1; i >= 0 ; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((int)(x).size())

void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); }
#define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__)
#define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i]
#define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i]
#define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j]

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } }

void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void yesno(bool b) { cout << (b ? "yes" : "no") << endl; }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
//using mint = modint1000000007;

std::vector<int> sieve(int n) {
	std::vector<int> res(n);
	std::iota(res.begin(), res.end(), 0);
	for (int i = 2; i*i < n; ++i) {
		if (res[i] < i) continue;
		for (int j = i * i; j < n; j += i)
			if (res[j] == j) res[j] = i;
	}
	return res;
}
vector<int> factor(int n, const std::vector<int>& min_factor) {
	// min_factor は sieve() で得られたものとする
	vector<int> res;
	while (n > 1) {
		res.emplace_back(min_factor[n]);
		n /= min_factor[n];
		// 割った後の値についても素因数を知っているので順次求まる
	}
	return res;
}
void Main() {
	cin(int, n);
	auto mf = sieve(2*n);
	vector<int> ans;
	ans.emplace_back(1);
	for (int i = 2; i <= n; i++) {
		int x = mf[i];
		if (x < i) {
			ans.emplace_back(max(ans[x - 1], ans[i / x - 1]) + 1);
		}
		else {
			ans.emplace_back(2);
		}
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(16);
	//int t; cin >> t; while (t--)
	Main();
}


#include <bits/stdc++.h>
using namespace std;
int fa[200005];
int a[200005];
int rk[200005];
int vis[200005];
map<int,int> s[200005];
int finds(int x)
{
	if(fa[x]==x)
	{
		return x;
	}
	else
	{
		return fa[x]=finds(fa[x]);
	}
}
void join(int u,int v)
{
	int fu=finds(u);
	int fv=finds(v);
	if(fu!=fv)
	{
		if(rk[fu]<rk[fv])
		{
			fa[fu]=fv;
			for(map<int,int>:: iterator it=s[fu].begin();it!=s[fu].end();it++)
			{
				s[fv][it->first]+=it->second;
			}
			s[fu].clear();
		}
		else
		{
			fa[fv]=fu;
			for(map<int,int>:: iterator it=s[fv].begin();it!=s[fv].end();it++)
			{
				s[fu][it->first]+=it->second;
			}
			s[fv].clear();
			if(rk[fu]==rk[fv])
			{
				rk[fu]++;
			}
		}
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		s[i][a[i]]=1;
	}
	for(int i=1;i<=200000;i++)
	{
		fa[i]=i;
	}
	for(int i=1;i<=m;i++)
	{
		int op,u,v;
		scanf("%d%d%d",&op,&u,&v);
		if(op==1)
		{
			join(u,v);
		}
		else
		{
			int k=finds(u);
	//		printf("%d\n",k);
			map<int,int> ::iterator it=s[k].find(v);
			if(it==s[k].end())
			{
				printf("0\n");
			}
			else
			{
				printf("%d\n",it->second);
			}
		}
	}
	return 0;
}

//伟大的导师，伟大的领袖，伟大的统帅，伟大的舵手
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
int read() {
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
const int maxn = 4e5+10;
int n,G[maxn],ct;
struct node{int x,n;}a[maxn];
bool cmp(node x,node y) {return x.x<y.x;}
signed main() {
	n=read();
	for(int i=1;i<=2*n;i++) a[i]=(node){read(),i};
	sort(a+1,a+1+2*n,cmp);
	for(int i=1;i<=n;i++) G[a[i].n]=1;
	for(int i=1;i<=2*n;i++)
		if(G[i]) {
			if(ct>=0) cout<<'(';
			else cout<<')';
			++ct;
		} else {
			if(ct<=0) cout<<'(';
			else cout<<')';
			--ct;
		}
	return 0;
}


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

int main()
{
    double n, D, H;
    cin >> n >> D >> H;
    double mx = 0.0;
    while (n--)
    {
        int d, h;
        cin >> d >> h;
        double temp = H - ((H - h) / (D - d)) * D;
        mx = max(mx, temp);
    }
    cout << mx << "\n";
}

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

int main(void) {
    int N, S, D;
    cin >> N >> S >> D;
    bool ok = false;
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        if (x >= S) continue;
        if (y > D) {
            ok = true;
        }
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << b - c << endl;

    return 0;
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;

typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
  ((cout << args << ' '), ...);
  cout << '\n';
}
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e6+ 5;
const char nl = '\n';
const int INF = 1e9 + 5;
int n, m, k;
ll mu(ll x, ll y){
  return (x * y) % MOD1;
}
int re(int x, int y){
  x -= y;
  if(x < 0){
    x += MOD1;
  }
  return x;
}
void add(int& x, int y){
  x += y;
  if(x >= MOD1){
    x -= MOD1;
  }
}
ll pot(ll x, ll y){
  if(y == 0) return 1;
  if(y & 1) return (pot(x, y - 1) * x) % MOD1;
  ll k = pot(x, y / 2);
  return (k * k) % MOD1;
}
ll inv(ll x){
  return pot(x, MOD1 - 2);
}
void solve(){
  cin >> n >> m >> k;
  if(n == m && n == 1){
    cout << k << '\n';
    return;
  }
  if(n == 1 || m == 1){
    int ans = 0;
    for(int i = 1; i <= k; i++){
    add(ans, mu(re(pot(i, n), pot(i - 1, n)), re(pot(k - i + 1, m), pot(k - i, m))));
    }
    cout << ans << '\n';
    return;
  }
  int ans = 0;
  for(int i = 1; i <= k; i++){
    add(ans, mu(re(pot(i, n), pot(i - 1, n)), pot(k - i + 1, m)));
  }
  cout << ans << '\n';
}
int main(){
  cpu();
  int __ = 1;
  // cin >> __;
  while(__--){
    solve();
  }
  return 0;
}