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

int main() {
    int h, w;
    cin >> h >> w;
    int ans = 0;
    vector<bool> below(w),  above(w);
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            below[j] = (s[j] == '#');
        }
        if (i == 0) continue;
        for (int j = 0; j+1 < w; j++) {
            int cnt = below[j] + below[j+1]
                + above[j] + above[j+1];
            if (cnt == 1 || cnt == 3)
                ans++;
        }
        above = below;
    }
    cout << ans << endl;
    return 0;
}

#pragma GCC optimize("Ofast")
//#ifndef ONLINE_JUDGE
//#define _GLIBCXX_DEBUG
//#endif
#ifdef ONLINE_JUDGE
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <math.h>
#include <complex>

using namespace std;
#ifdef ONLINE_JUDGE
using namespace atcoder;
#endif
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
#ifdef ONLINE_JUDGE
//using mint = modint998244353;
//using mint = modint;
using mint = modint1000000007;
#endif
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll X,Y; cin>>X>>Y;
  if(X>=Y) {
    cout<<abs(X-Y)<<'\n';
    return 0;
  }
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  pq.push({0,Y});
  map<ll,ll> dp;
  ll ans=INF;
  while(!pq.empty()) {
    auto [c,v]=pq.top(); pq.pop();
    chmin(ans,c+abs(v-X));
    if(dp.count(v)) continue;
    dp[v]=c;
    if(v<X) continue;
    if(v==X) break;
    if(~v&1) pq.push({c+1,v/2});
    else {
      pq.push({c+1,v+1});
      pq.push({c+1,v-1});
    }
    pq.push({c+abs(v-X),X});
  }

  cout<<ans<<'\n';

  return 0;
}


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

int main(){
    string s;
    cin >> s;
    vector<int> ok,ng;
    for(int i = 0;i < 10;i++){
        if(s[i]=='o') ok.push_back(i);
        else if(s[i]=='x') ng.push_back(i);
    }

    int ans = 0;
    for(int i = 0;i<10;i++){
        for(int j = 0;j<10;j++){
            for(int k = 0;k<10;k++){
                for(int l = 0;l<10;l++){
                    bool isok = true;
                    for(int m : ok) if(i!=m&&j!=m&&l!=m&&k!=m) isok = false;
                    for(int m : ng) if(i==m||j==m||l==m||k==m) isok = false;
                    if(isok) ans++;
                }
            }
        }
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

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

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

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

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

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

using namespace std;

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

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

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

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

    map<int,int> mp;
    rep(i,N){
        ll a; cin>>a;
        mp[a]++;
    }

    ll ans=(ll)N*(N-1)/2;
    for(auto e:mp){
        ans-=(ll)e.se*(e.se-1)/2;
    }
    cout<<ans<<"\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
using Graph = vector<vector<int>>;

int main(){
  int n,x;
  cin >> n >> x;
  x *= 100;
  for(int i=1;i<=n;i++){
    int v,p;
    cin >> v >> p;
    x -= v*p;
    //cout << x << endl;;
    if(x<0){
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

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

int n;
LL x;
LL a[N],b[N];

inline int qr()
{
	char a=0;int x=0,w=1;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();	}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

int main()
{
	n=qr();
	cin>>x;
	x*=100;
	double sum=0;
	for(register int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		sum+=a[i]*b[i];
		if(sum>x)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"-1"<<endl;
	return 0;
}


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

#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif

#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 5000 + 5;

constexpr int64_t MOD = 998244353;
int pw[NAX][NAX];

int add(int a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
    return a;
}

int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}

int64_t solveCase(int64_t N, int64_t M)
{
    for (size_t i = 0; i < NAX; i++)
    {
        pw[i][0] = 1;
        for (size_t j = 1; j < NAX; j++)
            pw[i][j] = (i * 1LL * pw[i][j - 1]) % MOD;
    }
    int64_t res = 0;
    for (size_t i = 0; i < N; i++)
        for (size_t x = 1; x <= M; x++)
            res = add(res, mul(pw[M - x][i], pw[M][N - 1 - i]));
    for (size_t d = 1; d < N; d++)
        for (size_t x = 1; x <= M; x++)
            res = add(res, mul(mul(N - d, x - 1), mul(pw[M - x][d - 1], pw[M][N - 1 - d])));
    return res;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main()
{
#ifndef LOCAL
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    constexpr char endl = '\n';
    int64_t N, M;
    cin >> N >> M;
    auto ans = solveCase(N, M);
    cout << ans << endl;
    return 0;
}

#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

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

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}

vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

    while(b){
        int64_t t = a/b;
        a -= t*b;
        swap(a, b);
        u -= t*v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;

    return u;
}

// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

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

//////////////////////////////////////////////////////////////
long long n ,k;
struct matrix{
    long long value[55][55];
};

matrix multi(matrix &a, matrix &b){
    matrix c;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            c.value[i][j] = 0;
            for(int k = 1;k <= n;k++){
                c.value[i][j] += a.value[i][k]*b.value[k][j];
                c.value[i][j] %= MOD;
            }
        }
    }

    return c;
}

int main(){
    int h , w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0;i < h;i++){
        cin >> s[i];
    }
    int DX[4] = {0, 1, 0, 1};
    int DY[4] = {0, 0, 1, 1};
    int cnt = 0;
    int ans = 0;
    for(int i = 1;i < h;i++){
        for(int j = 0;j < w - 1;j++){
            cnt = 0;
            for(int k = 0;k < 4;k++){
                if (s[i - DY[k]][j + DX[k]] == '#') cnt++;
            }
            if (cnt == 1 || cnt == 3) ans++;
        }
    }

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


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

signed main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		printf("%d %d\n", 2*i%n+1, (2*i+1)%n+1);
	}
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}

int main() {
    ll k;
    cin >> k;
    ll ans=0;
    rrep(i,1,k+1)rrep(j,1,k/i+1){
        ans+=k/(i*j);
    }
    cout << ans << endl;
}


/**
 *    author:  avoas
 *    created: 12.05.2021 18:03:29
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

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

constexpr double EPS = 1e-12;

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

    int n;
    cin >> n;

    vector<long long> a(n);
    long long sum = 0;
    rep(i,n)
    {
        cin >> a[i];
        sum += a[i];
    }

    sort(all(a));
    reverse(all(a));

    vector<long long> sn(n);
    sn[0] = sum - a[0];
    for(int i = 1; i < n; ++i)
    {
        sn[i] = sn[i-1] - a[i];
    }

    long long ans = 0;

    rep(i,n)
    {
        ans += (n-1-i)*a[i] - sn[i];
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define endl ("\n")
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<lli>
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i > b; i--)
#define mod 1000000007
#define all(s) s.begin(), s.end()
vector<lli>ar[200005];
lli sz = 0, vis[200005] = {0};
void solve(lli n) {
    vis[n] = 1;
    sz++;
    for (auto c : ar[n]) {
        if (!vis[c]) solve(c);
    }
}
int main() {
    fast
    lli tt, n;
    tt = 1;
    // cin>>tt;
    while (tt--) {
        cin>>n;
        lli a[n], ans = 0;
        rep (i, 0, n) cin>>a[i];
        rep (i, 0, n/2) {
            if (a[i] != a[n - i - 1]) ar[a[i]].pb(a[n - i - 1]), ar[a[n - i - 1]].pb(a[i]);
        }
        // map<lli, lli>mp;
        // for (int i = 1; i < 100005; i++) {
        //     if (ar[i].size() > 0) {
        //         sort(all(ar[i]));
        //         lli p = ar[i].size();
        //         if (ar[i][0] == ar[i][p - 1] && mp.find(ar[i][p - 1]) == mp.end()) ans++, mp[i] = ar[i][p - 1];
        //         else {
        //             ar[i][p - 1] = mp[ar[i][p - 1]];
        //             if (i == ar[i][p - 1]) continue;
        //         }
        //     }
        // }
        // cout<<ans;

        rep (i, 1, 200005) {
            if (ar[i].size() > 0 && !vis[i]) {
                sz = 0;
                solve(i);
                ans += (sz - 1);
            }
        }
        cout<<ans;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    int t = (2 * a)  + 100 ;
    if(t-b < 0){
        cout << 0 << endl;
    }
    else{
        cout << t-b << endl;
    }
}

#include <iostream>
using namespace std;
int main(void)
{
	int x, y;
	cin >> x >> y;
	if (x > y) {
		if ((y + 3) > x) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	if (y > x) {
		if ((x + 3) > y) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}


#include<fstream>
#include<iostream>
#include<sstream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<queue>
#include<tuple>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<set>
#include<array>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using graph = vector<vector<int>>;
const long long MOD = 1000000007;
const long long INF = 1e18;
using ll = long long;
using P = pair<int,int>;
using matrix = vector<vector<ll>>;

void chmin(int &x,int y){ x = min(x,y); }

int digit(ll x){
  int count = 1;
  while(x/10>0){
    count ++;
    x /= 10;
  }
  return count;
}

bool prime(ll x){
  if(x==1) return false;
  for(ll i=2;i*i<=x;i++){
    if(x%i==0) return false;
  }
  return true;
}

void decom(ll x,map<ll,int> &hatano){
  for(ll i=2;i*i<=x;i++){
    if(x%i==0&&prime(i)){
      while(x%i==0){
      x /= i;
      hatano[i] ++;
    }
    }
  }
  if(x!=1) hatano[x] ++;
}

ll speedpow(ll x,ll y){
  ll res = 1;
  ll test = x;
  for(int i=0;i<31;i++){
    if(y&(1<<i)) res *= test;
    res = res%MOD;
    test = (test*test)%MOD;
  }
  return res;
}

ll combination(ll x,ll y){
  ll test = 1;
  ll test1 = 1;
  for(ll i=0;i<y;i++){
    test = (test*(x-i))%MOD;
    test1 = (test1*(i+1LL))%MOD;
  }
  return (test * speedpow(test1,MOD-2))%MOD ;
}

int euclid(int x,int y){
  if(y==0) return x;
  return euclid(y,x%y);
}

//行列累乗

matrix mul(matrix &a, matrix &b) {
  int p = a.size();
    matrix res(p, vector<long long>(p, 0));
    for(int i = 0; i < p; i++)
        for(int j = 0; j < p; j++)
            for(int k = 0; k < p; k++)
                (res[i][j] += a[i][k] * b[k][j]) %= MOD;
    return res;
}

matrix pow(matrix m, long long k) {
  int p = m.size();
    matrix res(p, vector<long long>(p, 0));
    for(int i = 0; i < p; i++)
        res[i][i] = 1; // 単位行列にする

    while(k > 0) {
        if(k & 1) res = mul(res, m);
        m = mul(m, m);
        k >>= 1;
    }
    return res;
}

int main(){
    int n,m,q;cin >> n >> m >> q;
    int v[n],w[n];
    vector<P> hatano;
    int x[m];
    vector<P> konishi;

    int l[q],r[q];
    rep(i,n){
      cin >> w[i] >> v[i];
      hatano.push_back(make_pair(v[i],w[i]));
    }

    sort(hatano.rbegin(),hatano.rend());
    rep(i,m){
      cin >> x[i];
      konishi.push_back(make_pair(x[i],i));
    }
    sort(konishi.begin(),konishi.end());
    vector<int> ans;

    rep(i,q){
      cin >> l[i] >> r[i];
      l[i] --;r[i] --;
    }
    rep(i,q){
      int test=0;
      vector<bool> check(m,true);
      for(int s=l[i];s<=r[i];s++) check[s] = false;

        rep(j,n){
          rep(k,m){
            if(konishi[k].first>=hatano[j].second&&check[konishi[k].second]){
              test += hatano[j].first;
              check[konishi[k].second] = false;
             // cout << hatano[j].first << endl;
              break;
            }
          }
        }
        ans.push_back(test);
      //  cout << endl;
    }

    for(auto e:ans) cout << e << endl;

  }

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <iomanip>

using namespace std;

typedef long long ll;

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

	vector<pair<ll, ll>> nimotu(n, pair<ll, ll>());

	for (ll i = 0; i < n; i++) {
		cin >> nimotu[i].second >> nimotu[i].first;
	}
	sort(nimotu.begin(), nimotu.end(), greater<pair<ll, ll>>{});

	vector<ll> x(m);
	for (ll i = 0; i < m; i++) cin >> x[i];

	vector<ll> answer;

	for (ll qq = 0; qq < q; qq++) {
		ll ans = 0;
		ll l, r;
		cin >> l >> r;
		l--; r--;
		vector<ll> boxes;
		for (ll i = 0; i < m; i++) {
			if ((l <= i) && (i <= r)) {

			}
			else {
				boxes.push_back(x[i]);
			}
		}

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

		for (ll i = 0; i < nimotu.size(); i++) {
			for (ll j = 0; j < boxes.size(); j++) {
				if (nimotu[i].second <= boxes[j]) {
					boxes.erase(boxes.begin() + j);
					ans += nimotu[i].first;
					break;
				}
			}
		}

		answer.push_back(ans);
	}

	for (ll i = 0; i < answer.size(); i++) {
		cout << answer[i] << endl;
	}
}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define                          ll                          long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

#define                          in(x)                       scanf("%lld",&x)
#define                          in2(x,y)                    scanf("%lld %lld",&x,&y)
#define                          in3(x,y,z)                  scanf("%lld %lld %lld",&x,&y,&z)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          inf                         1e18
#define                          neg                         -1e18
#define                          mx                          2111111
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define                          fi                          first
#define                          si                          second
#define                          ce                          cout<<endl
#define                          pb                          push_back
#define                          vc(x)                       x.begin(),x.end()
#define                          pb                          push_back
#define                          pi                          pair<ll,ll>
#define                          debug                       printf("ok\n");
#define                          pg                          pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> >
#define                          mod                         1000000007

int main(){

        ll i,j,ans=0,sum=0,s=0,n;
        in(n);
        set<ll>st;
        for(i=1;i<=sqrt(n);i++){
            if(n%i==0){
                st.insert(i);
                st.insert(n/i);

            }
        }
        for(auto x:st){
            cout<<x<<endl;
        }

 }

// ╔═══╗░░╔═══╗░░╔╗░╔╗╔═══╗╔═══╗╔╗░╔╗░
// ║╔═╗║░░║╔══╝░░║║░║║║╔═╗║║╔═╗║║║░║║░
// ║║░║║░░║╚══╗░░║╚═╝║║╚═╝║╚╝╔╝║║╚═╝║░
// ║╚═╝║░░║╔══╝░░║╔═╗║║╔═╗║╔═╝╔╝╚══╗║░
// ║╔═╗║╔╗║╚══╗╔╗║║░║║║╚═╝║║║╚═╗░░░║║░
// ╚╝░╚╝╚╝╚═══╝╚╝╚╝░╚╝╚═══╝╚═══╝░░░╚╝░

#include<bits/stdc++.h>

using namespace std;

#define int long long int
#define ll long long int
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define W(x) int x;cin>>x;while(x--)
#define fr(n) for(int i=n-1;i>=0;i--)
#define mp make_pair
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ps(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define vi vector<int>
#define deb(x) cout<<#x<<"="<<x<<endl;
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int>
#define sortall(x) sort(all(x))
#define mk(arr,n,type)  type *arr=new type[n];
#define vpi vector<pair<int,int> >
#define setbits(x) __builtin_popcountll(x)
#define zerbits(x) __builtinctzll(x)
#define mod 1000000007
#define inf 1e18
#define sz(x) (int)x.size()
#define vs vector<string>
#define itr(a) for(auto it=a.begin();it!=a.end();it++)
#define f first
#define s second
#define INT_SIZE 32
int mpow(int exp, int base);
//I don't know what the funciton aeh() does but it speeds up my mess
void aeh()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
  //aeh();
  int n;cin>>n;
  int ans=n/100;
  if(n%100)
    ans++;
  cout<<ans<<"\n";
}

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


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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
using VV = vector<V>;
using SV = vector<string>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

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

// 素数判定
bool is_prime(ll n) {
	if (n == 1) return false;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x, y;
	//ll a, b, c;
	ll t;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n;

	ll prev = 1000;
	ll next = 1000000;
	ll x = 1;
	if (n > 999) {
		while (1) {
			if (n < next) {
				l_ans += (n - prev + 1) * x;
				break;
			}
			l_ans += (next - prev) * x;
			prev = next;
			next *= 1000;
			x++;
		}
	}

	cout << l_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}

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

#define sp     ' '
#define endl   '\n'
#define F      first
#define S      second
#define mp     make_pair
#define pb     push_back
#define mt     make_tuple
#define PI     (2 * acos(0))
#define all(x) x.begin(), x.end()
#define spc(x) cout<<fixed<<setprecision(x)

void solve()
{
    long long t,m,n,a,b,c,d,g,i,j,k,x,y,z,cnt=1,cnt1=0;
    bool flag= false; string s,s1;

    cin >> n ;
    set<long long>st;
    for(i=0;i<n;i++)
    {
    	cin >> x ;
    	st.insert(x);
    }
    for(long long ss : st)
    {
    	ss++;

    	cnt *= ss-cnt1;
    	cnt1 = ss-1 ;

    	cnt = cnt%1000000007;
    }
    cout << cnt << endl ;

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

    // int32_t tc;
    // cin>>tc;
    // while(tc--)

    solve();

    return 0;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++)
#define REP(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define RFOR(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--)
#define RREP(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--)
typedef long long LL;

struct Edge{
	int from,to,add,mul;
	Edge(const int& u,const int& v,const int& a,const int& m):from(u),to(v),add(a),mul(m) {}
	LL solve(const LL& t) {
		int x=(int)sqrt(mul+0.5);
		int a=x,b=x*(x+1)>mul?x:x+1;
		//printf("a=%d b=%d\n",a,b);
		if(t<1LL*b) return a+b+add-1;
		else return t+add+mul/(t+1LL);
	}
};

struct Heapnode{
	int u; LL d;
	Heapnode(const int& u,const LL& d):u(u),d(d) {}
	bool operator < (const Heapnode& rhs) const { return d>rhs.d; }
};

struct Dijkstra{
	static const int maxn=100000+5;
	std::vector<Edge> edges;
	std::vector<int> G[maxn];
	LL dist[maxn];
	Dijkstra() {
		FOR(i,0,maxn) G[i].clear();
		edges.clear();
	}
	void AddEdge(const int& from,const int& to,const int& add,const int& mul,const int& t=-1) {
		edges.push_back(Edge(from,to,add,mul));
		G[from].push_back(t>=0?t:edges.size());
	}
	LL dijkstra(const int& s,const int& t) {
		std::priority_queue<Heapnode> Q;
		while(!Q.empty()) Q.pop();
		Q.push(Heapnode(s,0));
		memset(dist,-1,sizeof(dist));
		dist[s]=0LL;
		while(!Q.empty()) {
			Heapnode h=Q.top(); Q.pop();
			int u=h.u;
			assert(h.d>=dist[u]&&dist[u]>=0LL);
			if(dist[u]!=h.d) continue;
			if(u==t) return dist[t];
			FOR(i,0,G[u].size()) {
				Edge e=edges[G[u][i]];
				int v=e.to;
				LL ans=e.solve(dist[u]);
				if(ans<dist[v]||dist[v]<0LL) Q.push(Heapnode(v,dist[v]=ans));
			}
		}
		assert(dist[t]==-1LL);
		return -1LL;
	}
}D;

int n,m;
int main() {
	scanf("%d%d",&n,&m);
	//printf("%d %d\n",n,m);
	FOR(i,0,m) {
		int from,to,add,mul; scanf("%d%d%d%d",&from,&to,&add,&mul);
		D.AddEdge(from,to,add,mul,i<<1);
		D.AddEdge(to,from,add,mul,(i<<1)|1);
		//printf("OK!%d\n",i);
	}
	printf("%lld\n",D.dijkstra(1,n));
	return 0;
}

#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<set>

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using piii = pair<int,pii>;

#define LL_INF 1e18+5
#define INT_INF 1e9+5
#define MOD 1e9+7

struct edge{
    ll to,cost,dis;
    edge(){};
    edge(ll t,ll c,ll d){
        to = t;
        cost = c;
        dis = d;
    };
};

ll time_calc(ll time,ll dis){
    //time+1+dis/(time+1) >= 2*root(dis) dis = (time+1)^2
    ll mintime = sqrt(dis);
    if(mintime == 0) mintime = 1;
    if(mintime+dis/mintime > mintime+1+dis/(mintime+1)){
        mintime++;
    }
    if(time < mintime){
        return mintime-1+dis/mintime;
    }
    else return time+dis/(time+1);
}

int main(){

    ll N,M; cin >> N >> M;
    vector<vector<edge> > E(N);
    for(ll i=0;i<M;i++){
        ll A,B,C,D; cin >> A >> B >> C >> D;
        A--;B--;
        E[A].push_back(edge(B,C,D));
        E[B].push_back(edge(A,C,D));
    }
    priority_queue<pll,vector<pll>,greater<pll>> q;
    q.push(pll(0,0));
    vector<ll> min_time(N,LL_INF);
    min_time[0] = 0;
    vector<bool> visited(N,false);
    while (!q.empty())
    {
        pll pos = q.top();q.pop();
        ll cur = pos.second;
        ll time = pos.first;
        if(min_time[cur] < time || visited[cur]) continue;
        visited[cur] = true;
        for(auto&next:E[cur]){
            ll ne = next.cost+time_calc(time,next.dis);
            if(min_time[next.to] > ne && !visited[next.to]){
                min_time[next.to] = ne;
                q.push(pll(ne,next.to));
            }
        }
    }

    if(min_time[N-1] < LL_INF){
        cout << min_time[N-1] << endl;
    }
    else cout << -1 << endl;

}


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

#define endline '\n'
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define pb push_back
#define fr(i,a,b) for(int i=a;i<(int)b;i++)
#define rfr(i,a,b) for(int i=a;i>=(int)b;i--)
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
const ll mod=1e9+7;
#define INF 0x3f3f3f3f

const int N = 1e6+2;

void solution(){
	vector<pair<ll,pll>> v;
    int n;cin>>n;
    fr(i,0,n)
    {
        ll x,y,z; cin>>x>>y>>z;
        v.pb({x,{y,z}});
    }
    int c=0;
    sort(all(v));

    fr(i,0,n)
    {
        fr(j,i+1,n)
        {
            double a1[]={0,0,0.00001,0.00001};
            double b1[]={0,-0.00001,0,-0.00001};
            int f1=v[i].first;int f2=v[j].first;
            long double x1=0,y1=0,x2=0,y2=0;
            fr(k,0,4)
            {
                if(f1==k+1)
                {
                    x1=v[i].second.first+a1[k],y1=v[i].second.second+b1[k];
                }
                if(f2==k+1)
                {
                    x2=v[j].second.first+a1[k],y2=v[j].second.second+b1[k];
                }
            }

            if((x1<=x2 and x2<=y1) or (x2<=x1 and x1<=y2) or (x1<=y2 and y2<=y1) or (x2<=y1 and y1<=y2))c++;
        }
    }
    cout<<c<<endline;
}

int main() {
	// your code goes here
	int t=1;
	//cin>>t;
	while(t--){
		solution();
	}

	return 0;
}

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

const int N = 2e3 + 50;

double l[N], r[N];

bool ck(int u, int v)
{
    if (r[u] < l[v] || l[u] > r[v]) return false;
    else return true;
}

int main()
{
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i ++)
    {
        int t;
        cin >> t >> l[i] >> r[i];
        if (t == 2 || t == 4) r[i] -= 0.5;
        if (t == 3 || t == 4) l[i] += 0.5;
        for (int j = 0; j < i; j ++)
            if (ck(i, j)) ans ++;
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define REP(i, m, n) for (ll i=(ll)(m); i < (ll)(n); ++i)
#define ln cout<<'\n'
void pr(){ln;}
template<class A, class...B>void pr(const A &a, const B &...b){cout<<a<<' ';pr(b...);}

void solve() {
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = 0;
	ll tmp = 0;
	for (int i = 0; i < n; ++i) {
		ans += tmp * a[i];
		ans += a[i] * a[i];
		ans %= 998244353;
		tmp *= 2;
		tmp += a[i];
		tmp %= 998244353;
	}

	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	solve();
	return 0;}

#include <cstdio>
#include <algorithm>
#include <numeric>

using namespace std;

int N,K;

using ll = long long int;

int mat[55][55];
bool o[55][55];//graph
bool comp_set[55][55];
bool visited[55];

const ll MOD=998244353;

ll solve(){
    ll ret=1ll;
    for(int i=1;i<=N;i++){
        ll cnt=1;
        for(int k=1;k<i;k++) if (comp_set[i][k]) cnt++;
        // printf("i=%d cnt=%lld\n",i,cnt);
        ret=ret*cnt%MOD;
    }

    return ret;
}

void DFS(int cur,int root){
    if (visited[cur]) return;
    visited[cur]=true;

    comp_set[cur][root]=comp_set[root][cur]=true;
    for(int v=1;v<=N;v++){
        if (!o[cur][v]||visited[v]) continue;
        DFS(v,root);
    }
}

void set_comp(){
    for(int i=1;i<=N;i++)
        for(int j=1;j<=N;j++) comp_set[i][j]=false;
    for(int v=1;v<=N;v++) {
        DFS(v,v);
        for(int i=1;i<=N;i++) visited[i]=false;
    }
}

void check_compatable(){
    for(int i=1;i<=N;i++)
        for(int j=1;j<=N;j++) o[i][j]=false;

    for(int i=1;i<=N;i++)
        for(int j=1;j<i;j++){
            o[i][j]=true;
            for(int k=1;k<=N;k++) o[i][j]=o[i][j]&&((mat[i][k]+mat[j][k])<=K);
            o[j][i]=o[i][j];
        }
}

int main(){

    scanf("%d%d",&N,&K);

    for(int i=1;i<=N;i++)
        for(int j=1;j<=N;j++) scanf("%d",&mat[i][j]);

    ll ans1,ans2;
    check_compatable();
    set_comp();

    ans1=solve();

    for(int i=1;i<=N;i++)
        for(int j=1;j<=i;j++) swap(mat[i][j],mat[j][i]);

    check_compatable();
    set_comp();

    ans2=solve();

    printf("%lld\n",ans1*ans2%MOD);

    return 0;
}


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

int main()
{
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    char s[h][w];
    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++)
            cin>>s[i][j];
    x--;
    y--;
    int ans=0;
    for(int i=y+1; i<w; i++)
    {
        if(s[x][i]=='#')
            break;
        else
        {
            if(s[x][i] == '.')
                ans++;
        }
    }
    for(int i=y-1; i>=0; i--)
    {
        if(s[x][i]=='#')
            break;
        else
        {
            if(s[x][i] == '.')
                ans++;
        }
    }
     for(int i=x+1; i<h; i++)
    {
        if(s[i][y]=='#')
            break;
        else
        {
            if(s[i][y] == '.')
                ans++;
        }
    }
     for(int i=x-1; i>=0; i--)
    {
        if(s[i][y]=='#')
            break;
        else
        {
            if(s[i][y] == '.')
                ans++;
        }
    }
    cout << ans+1 << "\n";
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX5 100005
#define MAX6 1000006
#define MAX7 10000007
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define sfs(a) scanf("%s", a)
#define sline(a) scanf("%[^\n]%*c", a);
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define pfs(a) printf("%s\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mod 1000000007
#define Mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

const int N = MAX5;

int main()
{
    //#ifndef ONLINE_JUDGE
    //    freopen("in.txt","r",stdin);
    //    freopen("out.txt","w",stdout);
    //#endif

    FASTIO;
    int n, m;
    cin>>n>>m;
    ll a[n][m];
    ll mn = inf;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin>>a[i][j];
            mn = min(mn, a[i][j]);
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            ans += max(0LL, a[i][j]-mn);
        }
    }
    cout<<ans<<endl;

    return 0;
}


/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 1e9 + 7;
const double pi = 3.14159265359;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> edge[n];
    vector<int> a(n);
    vector<int> vis(n);
    vector<int> pri(n, INT_MIN);
    for(auto & i : a)   cin >> i;
    while(m--){
        int x, y;
        cin >> x >> y;
        --x, --y;
        edge[x].push_back(y);
    }
    function<void(int)> dfs = [&](int x){
        vis[x] = 1;
        pri[x] = max(pri[x], a[x]);
        for(auto i : edge[x]){
            if(!vis[i])
                dfs(i);
            pri[x] = max(pri[x], pri[i]);
        }
    };
    for(int i = 0; i < n; i++){
        if(!vis[i]) dfs(i);
    }
    int ans = INT_MIN;
    for(int i = 0; i < n; i++){
        for(auto j : edge[i])
            ans = max(ans, pri[j] - a[i]);
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int 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)

int main()
{
    lint n,m;cin >> n>>m;
    lint inf = 100000000000;
    vector<lint> a(n);
    REP(i, n)
        cin >> a[i];
        priority_queue<plint, vector<plint>, greater<plint>> q;
        REP(i, m)
        {
            lint x, y;
            cin >> x >> y;
            x--;y--;
        q.push(make_pair(x, y));
    }
    vector<lint> v(n,inf);
    lint ans = -inf;
    REP(i,m){
        plint xy = q.top();
        q.pop();
        lint from = xy.first, to = xy.second;
        if(v[from]==inf){
            v[from] = a[from];
        }else{
            v[from] = min(v[from], a[from]);
        }
        ans = max(ans, a[to] - v[from]);
        /*
        if(a[to]>v[from]){
            v[to] = v[from];
        }
        */
        v[to] = min({v[to], v[from], a[to]});
    }

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


// Problem : F - +1-1x2
// Contest : AtCoder - AtCoder Beginner Contest 188
// URL : https://atcoder.jp/contests/abc188/tasks/abc188_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)

const ll inf=0x3f3f3f3f3f3f3f3f;
ll x, y;
map<pii, ll> dp;
ll call(ll m, ll n) {
	if(m >= n)return m - n;
	if(dp.find({m, n}) != dp.end())return dp[{m, n}];
	ll rtn = n - m;
	if(n % 2) {
		rtn = min(rtn, 1 + call(m, n + 1));
		rtn = min(rtn, 1 + call(m, n - 1));
	}
	else {
		rtn = min(rtn, 1 + call(m, n / 2));
	}
	return dp[{m, n}] = rtn;
}

int main() {
    SPEED;
    cin>>x>>y;
    cout<<call(x, y);
    return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll x,y;
map<ll,ll>mp;
map<ll,bool>used;
int main()
{
	ios::sync_with_stdio(0);
	cin>>x>>y;
	if(y<=x)
	{
		cout<<x-y<<endl;
		return 0;
	}
	queue<ll>q;
	q.push(y);
	ll mn=1e18+1;
	while(!q.empty())
	{
		ll now=q.front();
		q.pop();
	//	cout<<now<<" "<<mp[now]<<endl;
		used[now]=1;
		if(now==0)break;
		mn=min(mn,abs(now-x)+mp[now]);
		if(now%2==0)
		{
			if(mp[now/2]==0)mp[now/2]=mp[now]+1;
			else mp[now/2]=min(mp[now/2],mp[now]+1);
			if(!used[now/2])q.push(now/2);
		}
		{
			if(mp[now-1]==0)mp[now-1]=mp[now]+1;
			else mp[now-1]=min(mp[now-1],mp[now]+1);
			if(mp[now+1]==0)mp[now+1]=mp[now]+1;
			else mp[now+1]=min(mp[now+1],mp[now]+1);
			if(!used[now-1]&&now%2==1)q.push(now-1);
			if(!used[now+1]&&now%2==1)q.push(now+1);
		}
	}
	ll ans=mn;
	if(mp[x]!=0)cout<<mp[x]<<endl;
	else cout<<ans<<endl;
	return 0;
}


// Always remember that you are absolutely unique, just like everyone else!

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

// DEBUGGING SECTION
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 &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#define MOD     1000000007
#define INF     3e18
#define pb      push_back
#define endl    '\n' // Remove if interactive
#define ff      first
#define ss      second
#define FOR(i, a, b)   for(int i = a; i < b; i++)

#include <algorithm>
//#include <cstring>
//#include <map>
//#include <set>
//#include <queue>
#include <stack>
//#include <math.h>

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

#define int     long long
#define pii     pair<int, int>
#define vi      vector<int>
#define vvi     vector<vi>
#define vpii    vector<pii>
#define all(x)  x.begin(), x.end()

int power(int x, int y) {
	int ans = 1; x %= MOD;
	while (y) {
		if (y & 1)
			ans = (x * ans) % MOD;
		x = (x * x) % MOD;
		y >>= 1;
	}
	return ans;
}

// comparator(A, B) -> should return true if A needs to come before B!
// ALWAYS RETURN FALSE IF A == B

// USE INTEGERS TO REDUCE RUNTIME!

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

	int n = s.size();
	string str = "";
	int act = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0 && s[i] == 'R')
			continue;
		if (i < n && (s[i] == 'R' && s[i + 1] == 'R')) {
			i++;
			continue;
		}
		str.push_back(s[i]);
		if (s[i] != 'R')
			act++;
	}
	string t(act, '?');
	int si = 0;
	int ei = act - 1;
	bool flag = false;
	for (int i = str.size() - 1; i >= 0; i--) {
		if (str[i] == 'R') {
			flag ^= true;
		} else {
			if (flag)
				t[si++] = str[i];
			else
				t[ei--] = str[i];
		}
	}
	//debug(str);
	//debug(t);

	stack<char> st;
	for (char& c : t) {
		if (!st.empty() && st.top() == c) {
			st.pop();
		} else {
			st.push(c);
		}
	}
	string op = "";
	while (!st.empty()) {
		op.push_back(st.top());
		st.pop();
	}
	reverse(all(op));
	cout << op << endl;
}

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif

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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

    int n = s.size();

    for (int i = 0; i < n; i += 2) {
        if (s[i] < 'a' || s[i] > 'z') {
            cout << "No";
            return;
        }
    }

    for (int i = 1; i < n; i += 2) {
        if (s[i] < 'A' || s[i] > 'Z') {
            cout << "No";
            return;
        }
    }

    cout << "Yes";
}

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

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;

int sumtreeA[200200<<1];
int sumtreeB[200200<<1];
int cnttreeA[200200<<1];
int cnttreeB[200200<<1];
int A[200200];
int B[200200];

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

    int n,m,q; cin>>n>>m>>q;
    using ti = tuple<int,int,int>;
    vector<ti> query(q);
    vector<int> zip;
    zip.reserve(q);
    zip.pb(0);
    for (auto &[t,x,y] : query) {
        cin>>t>>x>>y;
        zip.pb(y);
    }
    int sz = sz(zip);

    cnttreeA[sz] = n; cnttreeB[sz] = m;
    for (int i=sz-1; i; i--) cnttreeA[i] = cnttreeA[i<<1] + cnttreeA[i<<1|1];
    for (int i=sz-1; i; i--) cnttreeB[i] = cnttreeB[i<<1] + cnttreeB[i<<1|1];

    auto sumq = [&](int le, int ri, int *T) {
        int ret = 0;
        for (le+=sz, ri+=sz; le<=ri; le>>=1, ri>>=1) {
            if (le&1) ret += T[le++];
            if (~ri&1) ret += T[ri--];
        }
        return ret;
    };

    auto update = [&](int idx, int val, int *T) {
        for (idx+=sz; idx; idx>>=1) T[idx] += val;
    };

    sort(all(zip));
    zip.erase(unique(all(zip)), zip.end());

    int res = 0;
    for (auto &[t,x,y] : query) {
        int idx = lower_bound(all(zip), y) - zip.begin();

        if (t == 1) {
            if (A[x] == y) {
                cout<<res<<'\n';
                continue;
            }
            int iidx = lower_bound(all(zip), A[x]) - zip.begin();
            if (A[x] < y) {
                res += sumq(0, iidx, cnttreeB) * (y - A[x]);
                res += -sumq(iidx+1, idx-1, sumtreeB) + sumq(iidx+1, idx-1, cnttreeB) * y;
            }
            else {
                res += sumq(0, idx, cnttreeB) * (y - A[x]);
                res += sumq(idx+1, iidx-1, sumtreeB) - sumq(idx+1, iidx-1, cnttreeB) * A[x];
            }
            update(iidx, -1, cnttreeA);
            update(idx, 1, cnttreeA);
            update(idx, zip[idx], sumtreeA);
            update(iidx, -zip[iidx], sumtreeA);
            A[x] = y;
        }
        else {
            if (B[x] == y) {
                cout<<res<<'\n';
                continue;
            }
            int iidx = lower_bound(all(zip), B[x]) - zip.begin();
            if (B[x] < y) {
                res += sumq(0, iidx, cnttreeA) * (y - B[x]);
                res += -sumq(iidx+1, idx-1, sumtreeA) + sumq(iidx+1, idx-1, cnttreeA) * y;
            }
            else {
                res += sumq(0, idx, cnttreeA) * (y - B[x]);
                res += sumq(idx+1, iidx-1, sumtreeA) - sumq(idx+1, iidx-1, cnttreeA) * B[x];
            }
            update(iidx, -1, cnttreeB);
            update(idx, 1, cnttreeB);
            update(idx, zip[idx], sumtreeB);
            update(iidx, -zip[iidx], sumtreeB);
            B[x] = y;
        }
        cout<<res<<'\n';
    }
    return 0;
}

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

int N, Q;
string S;

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

  cin >> N >> S >> Q;
  int flipcnt = 0;
  rep(i, Q) {
    int T, A, B;
    cin >> T >> A >> B;
    A--;
    B--;
    if (T == 1) {
      if (flipcnt % 2 == 1) {
        A = (A + N) % S.size();
        B = (B + N) % S.size();
      }
      swap(S[A], S[B]);
    } else {
      flipcnt++;
    }
  }
  string res = "";
  res = S;
  if (flipcnt % 2 == 1) {
    res = res.substr(N, N) + res.substr(0, N);
  }
  cout << res << endl;
}


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n+1],p[n+1];
    for(int i=1;i<=n;i++){
    	cin >> a[i];
    	p[a[i]]=i;
    }
    vector <int> ans;
    int vis[n]={0},ok=1;
    for(int i=1;i<=n;i++){
    	if(a[i]==i)continue;
    	for(int j=p[i]-1;j>=i;j--){
    		if(vis[j]){
    			ok=0;
    			break;
    		}
    		vis[j]=1;
    		ans.push_back(j);
    		p[a[j]]++;
    		swap(a[j],a[j+1]);
    	}
    	if(!ok)break;
    	p[i]=i;
    }
    if(!ok or ans.size()!=n-1)cout << "-1";
    else{
    	for(auto i:ans)
    		cout << i << '\n';
    }
}

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

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();

    int n;
    cin >> n;
    vi p(n);
    vi pos(n);
    rep (i, n) {
        cin >> p[i];
        p[i]--;
        pos[p[i]] = i;
    }

    set<int> st;
    vi ans;
    rep (x, n) {
        while (pos[x] != x) {
            int i = pos[x];
            int j = i - 1;
            if (st.count(j)) {
                cout << -1 << endl;
                return 0;
            }
            ans.push_back(j);
            st.insert(j);
            swap(p[j], p[i]);
            pos[p[j]] = j;
            pos[p[i]] = i;
        }
    }
    if (st.size() != n - 1) {
        cout << -1 << endl;
        return 0;
    }
    rep (i, ans.size()) {
        cout << ans[i] + 1 << endl;
    }

}


#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i, n, q, c[N], par[N], sz[N];
set<int> group[N];
map<pii, int> ans;

void make(int v)
{
    par[v] = v;
    sz[v] = 1;
}

int find(int v)
{
    if (v == par[v])
        return v;
    return par[v] = find(par[v]);
}

void join(int a, int b)
{
    a = find(a);
    b = find(b);
    if (a != b)
    {
        if (sz[a] < sz[b])
            swap(a, b);
        par[b] = a;
        sz[a] += sz[b];
        for (int j : group[b])
        {
            group[a].insert(j);
            ans[ {a, c[j]}]++;
        }
    }
}

void solve()
{
    cin >> n >> q;
    for (i = 1; i <= n; i++)
    {
        cin >> c[i];
        make(i);
        group[i].insert(i);
        ans[ {i, c[i]}]++;
    }
    while (q--)
    {
        int op;
        cin >> op;
        if (op == 1)
        {
            int a, b;
            cin >> a >> b;
            join(a, b);
        }
        else
        {
            int x, y;
            cin >> x >> y;
            int root = find(x);
            cout << ans[{root, y}] << endl;
        }
    }
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
    int t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, M;
int to[400005], ne[400005], c[200005], he[100001];
int kotae[100001];

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
	char C[MAX * 4];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 3) {
				C[i * 4 + 2 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 4 + 3] = ' ';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, f.C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

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

	N = getint();
	M = getint();

	int k = 2;
	rep1(i, M) {
		int u = getint(), v = getint();
		c[i] = getint();
		to[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	int Q[100001], q = 0;
	Q[q++] = 1;
	kotae[1] = 1;
	while (q) {
		int tmp = Q[--q];
		int oya = kotae[tmp];
		for (int k = he[tmp]; k; k = ne[k]) {
			int t = to[k];
			if (!kotae[t]) {
				int e = c[k >> 1];
				kotae[t] = e + (oya == e);
				Q[q++] = t;
			}
		}
	}

	rep1(i, N) putint(kotae[i] - ((kotae[i] > N) << 1));
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using P=pair<int,int>;
using T=tuple<int,int,int>;
constexpr int mod=1000000007;
constexpr int inf=2e9;
constexpr double eps=1e-13;
int in(){
    int x;
    scanf("%d",&x);
    return x;
}
int main(){
    int n=in(),m=in(),k=in();
    vector<double>dp1(n+m);
    vector<double>dp0(n+m);
    int range=0,maxrange=0;
    for(int i=0;i<k;i++)dp1[in()]=1.0;
    for(int i=0;i<n;i++){
        if(dp1[i])range++;
        else range=0;
        maxrange=max(range,maxrange);
    }
    if(maxrange>=m){
        cout<<-1<<endl;
        return 0;
    }
    double sum1,sum0;
    sum1=sum0=0.0;
    for(int i=n-1;i>=0;i--){
        if(dp1[i]==0.0){
            dp1[i]=sum1/m;
            dp0[i]=sum0/m+1.0;
        }
        sum1+=dp1[i]-dp1[i+m];
        sum0+=dp0[i]-dp0[i+m];
        //cout<<dp1[i]<<" "<<dp0[i]<<endl;
    }
    double ans=dp0[0]/(1.0-dp1[0]);
    printf("%.10lf\n",ans);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define pb    push_back
#define eb   emplace_back
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=6e5+54;
const ll mod =1e9+7  ;
const ll base=1e18;
ll n, k;
ll get(ll n,ll k)
{
  return min(k-1,2*n-k+1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("promote.in", "r"))
    {
        freopen("promote.in", "r", stdin);
        freopen("promote.out", "w", stdout);
    }

    cin>> n>> k;
    ll ans=0;
    for (int i=k+2;i<=2*n;i++)
    {
         ans=ans+max(0ll,get(n,i)*get(n,i-k));
    }
    cout <<ans;

}


#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
inline unsigned int __builtin_popcount(unsigned int x){return __popcnt(x);}
#endif

using ll = long long;
using vll = std::vector<ll>;
using namespace std;
#define REP(i, x, n) for(int i = x; i < (n); i++)
#define rep(i, n) REP(i, 0, n)
const ll MOD = 1000000007;

int main() {
  string s; cin>>s;
  int k=s.length();
  int ans = 0;
  rep(i,1<<k){
    int x=0;
    rep(j,k){
      if(i>>j&1){
        x+=s[j]-'0';
      }
    }
    if(x%3==0){
      ans = max(ans, (int)__builtin_popcount(i));
    }
  }
  if(ans==0){
    puts("-1");
  }else{
    printf( "%d\n", k-ans );
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,start,end) for(int i=start; i<=end; i++)
#define repd(i,start,end) for(int i=start; i>=end; i--)
#define all(x) x.begin(),x.end()
#define debug(x) cout << "(" << #x << ": " << x << ")" << endl;

bool octals(int n) {
	int oct[100],i=0;
	while(n) {
		oct[i]=n%8;
		if(oct[i]==7)
			return true;
		i++;
		n/=8;
	}
	return false;
}

bool decs(int n) {
	int oct[100],i=0;
	while(n) {
		oct[i]=n%10;
		if(oct[i]==7)
			return true;
		i++;
		n/=10;
	}
	return false;
}

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

	int ans=0;

	repa(i,1,n) {
		if(decs(i) || octals(i))
			ans++;
	}

	cout << n-ans << endl;
}

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


#include<bits/stdc++.h>
using namespace std;
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<utility>
#define ll long long int
#define speed ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define pf push_front
#define mod 1000000007
#define ff first
#define ss second
#define ld long double

#define lp(i,a,b) for(ll i=a ; i<b ; i++)
#define rlp(i,a,b) for(ll i=b ; i>=a ; i--)

// ---------------------------------
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
// -----------------------------------
 bool cmp(pair<long long int, long double> a, pair<long long int,long  double> b)
{
	if (a.second == b.second)
		return a.first < b.first;
	return a.second > b.second;
}

ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
ll modInverse(ll n,ll p)
{
	return power(n,p-2,p);
}
ll factorial(ll n)
{
    if(n==0)
    {
        return 1;
    }
    else if(n==1)
    {
        return 1;
    }
    else
    {
        return factorial(n-1)*n;
    }
}
ll nCr(ll n, ll r, ll p)
{
	if(r==0)
	{
		return 1;
	}
	ll fac[n+1];
	fac[0]=1;
	for(ll i=1 ; i<=n ; i++)
	{
		fac[i]=fac[i-1]*i%p;
	}
	return (fac[n]*modInverse(fac[r],p)%p*modInverse(fac[n-r],p)%p)%p;
}
bool sortbysec(const pair<pair<ll,ll>,ll> &a,
              const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}

int main()
{
	ll n;
	cin>>n;
	vector< pair<pair<ll,ll>,ll>> v;
	ll sa=0,st=0;
	lp(i,0,n)

	{
		ll x,y;
		cin>>x>>y;
		pair<ll,ll>p=make_pair(x,y);
		ll s;
		s=2*x+y;
		v.push_back(make_pair(p,s));
		sa+=x;
	}
	// ll val=sa;
	sort(v.begin(),v.end(),sortbysec);
	ll ans=0;
	for(ll i=v.size()-1;i>=0;i--)
	{
		// cout<<v[i].second<<endl;
		sa=sa-v[i].first.first;
		st+=v[i].first.first +v[i].first.second;
		ans++;
		if(st>sa)
			break;
	}

	// cout<<ans<<endl;
	// cout<<ans2<<endl;
	 // ll t;
	 // scanf("%lld",&t);
	 // while(t--)
	 // {
	 // 	ll ans=0;

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

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = (int)1e9+7;
const int INF = (int)1e9;

int main()
{
	int n;
	cin>>n;
	vector<ll> store(n);
	ll diff = 0;
	for(int i = 0; i<n; i++)
	{
		ll a, b;
		cin>>a>>b;
		diff-=a;
		store[i]=2*a+b;
	}
	int i;
	sort(all(store), greater<ll>());
	for(i = 0; i<n; i++)
	{
		diff+=store[i];
		if(diff>0)break;
	}
	cout<<i+1<<endl;
}


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

class Timer {
public:
    Timer() { start_time_ = std::chrono::steady_clock::now(); }
    int64_t elapsedMilliSeconds() const {
        auto elapsed = std::chrono::steady_clock::now() - start_time_;
        return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
    }

private:
    std::chrono::steady_clock::time_point start_time_;
};

unsigned int randxor() {
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t;
    t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

struct Position {
    int32_t x, y, h_or_v;
};

int main() {
    int32_t N, M;
    cin >> N >> M;
    vector<string> s(M);
    for (string &i : s) {
        cin >> i;
    }

    Timer timer;

    // 操作
    // (1)まだ載せてないものからランダムに選んで載せる
    // (2)すでに載っているものを取り除く
    vector<string> ans(N, string(N, '.'));

    // 各マスが何個の文字列へ影響しているか
    vector<vector<int32_t>> dependence_num(N, vector<int32_t>(N, 0));

    // 各要素がどこにあるか
    vector<Position> positions(M);

    // まだ載せてないもの
    vector<int32_t> remainder(M);
    iota(remainder.begin(), remainder.end(), 0);

    vector<int32_t> on_board;

    constexpr int64_t TIME_LIMIT = 1800;

    for (int32_t index = 0; index < M; index++) {
        // まだ載せてないものをランダムに選んで載せる
        int32_t best_x = -1;
        int32_t best_y = -1;
        int32_t best_h_or_v = -1;
        int32_t best_overlap_num = -1;
        const string &curr_str = s[remainder[index]];

        for (int32_t x = 0; x < N; x++) {
            for (int32_t y = 0; y < N; y++) {
                for (int32_t h_or_v = 0; h_or_v < 2; h_or_v++) {
                    bool ok = true;
                    int32_t overlap_num = 0;
                    for (int32_t i = 0; i < curr_str.size(); i++) {
                        int32_t curr_x = (h_or_v == 0 ? (x + i) % N : x);
                        int32_t curr_y = (h_or_v == 0 ? y : (y + i) % N);

                        if (ans[curr_y][curr_x] == curr_str[i]) {
                            overlap_num++;
                        }
                        if (ans[curr_y][curr_x] != '.' && ans[curr_y][curr_x] != curr_str[i]) {
                            ok = false;
                            break;
                        }
                    }

                    if (ok && overlap_num > best_overlap_num) {
                        //更新
                        best_x = x;
                        best_y = y;
                        best_h_or_v = h_or_v;
                        best_overlap_num = overlap_num;
                    }
                }
            }
        }

        if (best_x == -1) {
            continue;
        }

        // 書き込む
        for (int32_t i = 0; i < curr_str.size(); i++) {
            int32_t curr_x = (best_h_or_v == 0 ? (best_x + i) % N : best_x);
            int32_t curr_y = (best_h_or_v == 0 ? best_y : (best_y + i) % N);
            ans[curr_y][curr_x] = curr_str[i];
            dependence_num[curr_y][curr_x]++;
        }

        positions[remainder[index]].x = best_x;
        positions[remainder[index]].y = best_y;
        positions[remainder[index]].h_or_v = best_h_or_v;
        on_board.push_back(remainder[index]);

        remainder[index] = remainder.back();
        remainder.pop_back();
    }

    for (int32_t i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<string> ss(m);
	for (auto &&s : ss)
	{
		cin >> s;
	}

	sort(ss.begin(), ss.end());
	ss.erase(unique(ss.begin(), ss.end()), ss.end());
	m = ss.size();

	sort(ss.begin(), ss.end(), [](auto &l, auto &r)
		 {
			 if (l.size() != r.size())
			 {
				 return l.size() > r.size();
			 }
			 return l < r;
		 });

	vector<string> ans(n, string(n, '.'));

	for (int i = 0, j = 0; i < n; i++)
	{
		int l = 0;
		while (j < m && l + ss[j].size() <= n)
		{
			for (int k = 0; k < ss[j].size(); k++)
			{
				ans[i][l + k] = ss[j][k];
			}
			l += ss[j].size();
			j++;
		}
	}

	for (auto &&x : ans)
	{
		cout << x << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#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;
using namespace std;

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 2e5 + 5;

int ans , n;
int dp[N];
vpii adj[N];

void dfs(int node,int p,int w)
{
      dp[node] = w;

      for(auto &c :adj[node])
      {
            if(c.ff == p)
              continue;

            dfs(c.ff , node , c.ss ^ dp[node]);

      }
}

void solve()
{
      cin >> n;

      for(int i = 0;i < n - 1; i++)
      {
              int u , v , w;
              cin >> u >> v >> w;
              adj[u].pb({v , w});
              adj[v].pb({u , w});
      }

      ans = 0;

      dfs(1 , -1 , 0);

      int bit[62] = {};

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

              while(num)
              {
                    if(num&1)
                      bit[j]++;

                    num>>=1;
                    j++;
              }
      }

      int curr = 1;

      for(int i = 0;i < 62 ; i++)
      {
            int now = bit[i];
            now *= (n - bit[i]);
            now%=mod;
            int p = curr%mod;
            now*=p;
            now%=mod;
            ans += now;
            ans%=mod;

           // deb(ans, now);

            curr<<=1;
      }

      db(ans)

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

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

    int t = 1;
   //cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values

#define LOCAL
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define REP(i, x)	for (int i = 0; i < (int)(x); i++)
#define REPS(i, x)	for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x)	for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(x)		((x).begin(), (x).end())
#define SIZE(x)		((int)(x).size())
#define BITS(x)		(1LL << (x))

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001LL;
constexpr int MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx8[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
constexpr int dy8[8] = { 1, 0, -1, 1, -1, 1, 0, -1 };

random_device seed_gen;
mt19937 mrand(seed_gen());
mt19937_64 mrand64(seed_gen());
int rand32(int x) {
	return mrand() % x;
}
ll rand64(long x) {
	return mrand64() % x;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
	out << "(" << a.first << "," << a.second << ")";
	return out;
}
template<typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
	out << "[";
	bool first = true;
	for (auto& v : a) {
		out << (first ? "" : ",");
		out << v;
		first = 0;
	}
	out << "]";
	return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
	out << "[";
	bool first = true;
	for (auto& v : a) {
		out << (first ? "" : ",");
		out << v;
		first = 0;
	}
	out << "]";
	return out;
}
template<typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
	out << "{";
	bool first = true;
	for (auto& v : a) {
		out << (first ? "" : ",");
		out << v;
		first = 0;
	}
	out << "}";
	return out;
}
template<typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
	out << "{";
	bool first = true;
	for (auto& p : a) {
		out << (first ? "" : ",");
		out << p.first << ": " << p.second;
		first = 0;
	}
	out << "}";
	return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << ": " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << ": " << arg1 << " |";
	__f(comma + 1, args...);
}

struct fast_ios {
	static constexpr int IOS_PREC = 20;
	static constexpr bool AUTOFLUSH = false;

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

int main() {
	int n;
	string s;
	cin >> s;
	n = SIZE(s);

	deque<char> t;
	bool r = false;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r ^= true;
		} else {
			if (r) {
				if (!t.empty() && t.front() == s[i]) {
					t.pop_front();
				} else {
					t.push_front(s[i]);
				}
			} else {
				if (!t.empty() && t.back() == s[i]) {
					t.pop_back();
				} else {
					t.push_back(s[i]);
				}
			}
		}
	}
	if (r) reverse(t.begin(), t.end());
	for (auto c : t) {
		cout << c;
	}
	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,c[100010],sum=0,m=101;
int main(){
cin>>a>>b;
a*=b;
for(long long i=0;i<a;i++){
	cin>>c[i];
	if(c[i]<m)m=c[i];
	sum+=c[i];
}
sum-=m*a;
cout<<sum;
}

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

typedef long long ll;

const int MOD = 1e9 + 7;

// Vectors
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define print(x) cout << x << "\n"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    // find min
    int m = INT_MAX;  // min
    int arr[101][101];

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

    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            m = min(arr[i][j], m);
        }
    }

    int ans = 0;
    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            if (arr[i][j] > m) {
                ans += arr[i][j] - m;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
#define For(Ti,Ta,Tb) for(int Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(int Ti=(Ta);Ti>=(Tb);--Ti)
template<typename T>
inline bool chkmax(T &i,const T&j){return i<j?(i=j,1):0;}
template<typename T>
inline bool chkmin(T &i,const T&j){return i>j?(i=j,1):0;}
template<typename T> void Read(T &x){
	x=0;int f=1;
	char ch=getchar();
	while(!isdigit(ch)) f=(ch=='-'?-1:f),ch=getchar();
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	x=x*f;
}
typedef long long ll;
#define INF 0x3f3f3f3f
const int N=2e5+5,Mod=998244353;
int n,len;ll a[N],pw2[N];
pair<ll,int> p[N];
int main(){
	Read(n);For(i,1,n) Read(a[i]);
	pw2[0]=1;For(i,1,n) pw2[i]=pw2[i-1]*2%Mod;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		p[++len]=make_pair(a[i],1);
		while(i<=n&&a[i]==a[i+1]) ++p[len].second,++i;
	}
//	For(i,1,len) printf("%lld %d\n",p[i].first,p[i].second);
	ll cur=p[1].first*(pw2[p[1].second]-1)%Mod,ans=0;
	For(i,2,len){
		ans=(ans+cur*p[i].first%Mod*(pw2[p[i].second]-1)%Mod);
		cur=(cur*pw2[p[i].second]%Mod+p[i].first*(pw2[p[i].second]-1)%Mod)%Mod;
	}
	For(i,1,len) ans=(ans+p[i].first*p[i].first%Mod*(pw2[p[i].second]-1)%Mod)%Mod;
	printf("%lld\n",ans);
	return 0;
}

#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);

ll random2(){
    return (1ll << 31ll)*eng()+eng();
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 300001;

int const base = 550000;

int DP[101][base+1] = {0};

void solve(){
    DP[0][0] = 1;
    int ma = 0;
    for(int i = 0; i < n; i++){
        int ma2 = 0;
        for(int sum = 0; sum <= ma; sum++){
            for(int a = 0; a <= k; a++){
                DP[i+1][sum+a*(i+1)] += DP[i][sum];
                if(DP[i+1][sum+a*(i+1)] >= m)DP[i+1][sum+a*(i+1)] -= m;
            }
        }
        ma = ma+k*(i+1);
    }
}

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

    //freopen("fhc.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n >> k >> m;
    solve();
    rep(x,1,n+1){
        ll temp = 0;
        //cerr << "x: " << x << "\n";
        rep(sum,0,base+1){
            ll thing = (ll(DP[x-1][sum])*ll(DP[n-x][sum]))%m;
            thing *= ll(k+1);
            thing %= m;
            temp += thing;
            if(temp >= m)temp -= m;
         //  if(sum < 10) cerr << ll(DP[x-1][sum]) << " " << DP[n-x][sum] << " " << k << "\n";
        }
        cout << (temp+m-1)%m << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
static char buf[1<<21],*p1=buf,*p2=buf;
inline int read(void){
	reg bool f=false;
	reg char ch=getchar();
	reg int res=0;
	while(!isdigit(ch))f|=(ch=='-'),ch=getchar();
	while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
	return f?-res:res;
}

const int MAXN=2e5+5;

struct Point{
	int x,y;
};

int n;
Point a[MAXN];

int main(void){
	n=read();
	for(reg int i=1;i<=n;++i)
		a[i].x=read(),a[i].y=read();
	reg int Maxx=1,Maxy=1,Minx=1,Miny=1;
	for(reg int i=1;i<=n;++i){
		if(a[i].x>a[Maxx].x)
			Maxx=i;
		if(a[i].y>a[Maxy].y)
			Maxy=i;
		if(a[i].x<a[Minx].x)
			Minx=i;
		if(a[i].y<a[Miny].y)
			Miny=i;
	}
	set<int> S={Maxx,Maxy,Minx,Miny};
	set<pair<int,int> > T;
	vector<int> ans;
	for(auto j:S)
		for(int i=1;i<=n;++i)
			if(!T.count(make_pair(i,j))){
				ans.push_back(max(abs(a[j].x-a[i].x),abs(a[j].y-a[i].y)));
				T.insert(make_pair(i,j)),T.insert(make_pair(j,i));
			}
	sort(ans.begin(),ans.end());
	reverse(ans.begin(),ans.end());
	printf("%d\n",ans[1]);
	return 0;
}

#include <bits/stdc++.h>
#define sz(c) int(c.size())
#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)
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <local/debug.h>
#else
#define debug(...) (void)0
#endif

const int inf = (int)1e9 + 1;

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

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

  vector<bool> ex(n);
  auto find_max = [&](auto &a) {
    pair<int, int> min_prev{inf, -1};
    tuple<int, int, int> best{-inf, -1, -1};
    rep(i, 0, n) if (!ex[i]) {
      if (min_prev.second != -1) {
        best = max(best, make_tuple(a[i] - min_prev.first, min_prev.second, i));
      }
      min_prev = min(min_prev, make_pair(a[i], i));
    }

    pair<int, int> max_prev{-inf, -1};
    rep(i, 0, n) if (!ex[i]) {
      if (max_prev.second != -1) {
        best = max(best, make_tuple(max_prev.first - a[i], max_prev.second, i));
      }
      max_prev = max(max_prev, make_pair(a[i], i));
    }
    return best;
  };

  auto max_x = find_max(x);
  auto max_y = find_max(y);

  if (get<0>(max_x) == get<0>(max_y) && max_x != max_y) {
    cout << get<0>(max_x) << "\n";
    return 0;
  }

  debug(max_x);
  debug(max_y);

  auto max = std::max(max_x, max_y);

  set<int> s;
  s.insert(get<1>(max));
  s.insert(get<2>(max));

  int res = -inf;
  for (int i : s) {
    ex[i] = true;
    res = std::max(res, get<0>(find_max(x)));
    res = std::max(res, get<0>(find_max(y)));
    debug(i, get<0>(find_max(x)), get<0>(find_max(y)));
    ex[i] = false;
  }
  cout << res << "\n";
}


//Author: Xzirium
//Time and Date: 20:18:14  15 June 2021

//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll b, ll e)
{
    ll r = 1ll;
    for(; e > 0; e /= 2, (b *= b) %= MOD)
        if(e % 2) (r *= b) %= MOD;
    return r;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);

}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(M);
    READV(K);
    if(N<=M+K)
    {
        ll tot=1;
        ll ans=1;
        FORI(i,1,N+M+1)
        {
            ans=(ans*i)%MOD;
        }
        tot=ans;
        FORI(i,1,N-K-1+1)
        {
            ans=(ans*modInverse(i))%MOD;
        }
        FORI(i,1,M+K+1+1)
        {
            ans=(ans*modInverse(i))%MOD;
        }
        FORI(i,1,N+1)
        {
            tot=(tot*modInverse(i))%MOD;
        }
        FORI(i,1,M+1)
        {
            tot=(tot*modInverse(i))%MOD;
        }
        if(N<K+1)
        {
            ans=0;
        }
        cout<<(tot-ans+MOD)%MOD<<endl;
    }
    else
    {
        cout<<0<<endl;
    }

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

    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
/*
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
*/
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"

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

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

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

const int mod = 1e9 + 7;

vector<long long> fact, fact_inv, inv;
/*  init_combination :二項係数のための前処理
    計算量:O(n)
*/
void init_combination(int SIZE) {
    fact.resize(SIZE + 1);
    fact_inv.resize(SIZE + 1);
    inv.resize(SIZE + 1);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 1; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}
/*  comb :modでの二項係数を求める(前処理 init_combination が必要)
    計算量:O(1)
*/
long long comb(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

void solve() {
    init_combination(4e6 + 10);
    int N, M, K;
    cin >> N >> M >> K;
    if (N - M > K) {
        cout << 0 << endl;
        return;
    }
    int x = K + 1 + M;
    int y = N - (K + 1);
    if (y < 0) {
        cout << comb(N + M, N) << endl;
        return;
    } else {
        cout << (mod + comb(N + M, N) - comb(x + y, x)) % mod << endl;;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);

    solve();
}


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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define Ss second
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

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

    while (n % 2 == 0)
    {
        n /= 2;
    }

    ll m = sqrt(n), ans = 0;

    for (ll i = 1; i <= m; i++)
    {
        if (n % i == 0)
        {
            ans += 2;
        }
    }

    if (m * m == n)
        ans--;

    cout << ans * 2 << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long double LD;
typedef long long ll;
#define int ll
#define ff(i,a,b) for (int i = a; i < b; i++)
#define bf(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define intmx INT_MAX
#define intmi INT_MIN
const int MOD=1e9+7;
int mod(int x){
    return ((x%MOD + MOD)%MOD);
}
int add(int a,int b){
    return mod(mod(a)+mod(b));
}
int mul(int a,int b){
    return mod(mod(a)*mod(b));
}

void solve(){
   int n;
   cin>>n;
   int ans=0;
   string s;
   std::vector<string> v;
   ff(i,0,n){
       cin>>s;
       v.pb(s);
   }
   bf(j,n,1){
       s=v[j-1];
       if(s=="AND")
       continue;
       else{
           ans+=(1ll<<j);
       }
   }
   cout<<ans+1<<endl;
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

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

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

ll sum(ll n)
{
  return n * (n + 1) / 2;
}

ll rangeSum(ll a, ll b)
{
  return sum(b) - sum(a - 1);
}

int main()
{
  faster;

  ll n, cnt = 0;
  cin >> n;

  for (ll len = 1; len <= 2e6; len++)
  {

    ll l = 1, r = 1e12;

    while (l <= r)
    {
      ll mid = l + (r - l) / 2;
      if (rangeSum(mid, mid + len - 1) == n)
      {
        cnt += 2;
        break;
      }
      else if (rangeSum(mid, mid + len - 1) < n)
        l = mid + 1;
      else
        r = mid - 1;
    }
  }

  cout << cnt << endl;

  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  n *= 2;
  int ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll j = n / i;
      if (i % 2 != j % 2) ans += 2;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
#define f first
#define s second
#define nl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 998244353;
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

ll n, m, k;

ll bpow(ll a, ll b){
  if(b==0) return 1;
  ll y=bpow(a, b/2);
  y=(y*y)%MOD;
  if(b&1) y=(y*a)%MOD;
  return y;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n >> m >> k;
  ll ans=0;
  if(n==1){
    cout << bpow(k, m); return 0;
  }
  rep(x, 1, k){
    ans=(ans+(((MOD+bpow(x, n)-bpow(x-1, n))%MOD)*((m==1?1:bpow(k-x+1, m))%MOD))%MOD)%MOD;
  }
  cout << ans;
}

//I'll always miss you like a darling.
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>
#define LOWBIT(x) x & (-x)

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

const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=998244353;
const double eps=1e-10;
const double pi=acos(-1);

struct fastio
{
    static const int S=1e7;
    char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;
    fastio() {rpos=len=wpos=0;}
    inline char Getchar()
    {
        if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);
        if (!len) return EOF;
        return rbuf[rpos++];
    }
    template <class T> inline void Get(T &x)
    {
        char ch;bool f;T res;
        while (!isdigit(ch=Getchar()) && ch!='-') {}
        if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
        while (isdigit(ch=Getchar())) res=res*10+ch-'0';
        x=(f?res:-res);
    }
    inline void getstring(char *s)
    {
        char ch;
        while ((ch=Getchar())<=32) {}
        for (;ch>32;ch=Getchar()) *s++=ch;
        *s='\0';
    }
    inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}
    inline void Writechar(char ch)
    {
        if (wpos==S) flush();
        wbuf[wpos++]=ch;
    }
    template <class T> inline void Print(T x,char ch)
    {
        char s[20];int pt=0;
        if (x==0) s[++pt]='0';
        else
        {
            if (x<0) Writechar('-'),x=-x;
            while (x) s[++pt]='0'+x%10,x/=10;
        }
        while (pt) Writechar(s[pt--]);
        Writechar(ch);
    }
    inline void printstring(char *s)
    {
        int pt=1;
        while (s[pt]!='\0') Writechar(s[pt++]);
    }
}io;

template<typename T> inline void check_max(T &x,T cmp) {x=max(x,cmp);}
template<typename T> inline void check_min(T &x,T cmp) {x=min(x,cmp);}
template<typename T> inline T myabs(T x) {return x>=0?x:-x;}
template<typename T> inline T mygcd(T x,T y) {return y==0?x:mygcd(y,x%y);}
inline int add(int x) {if (x>=MOD) x-=MOD;return x;}
inline int add(int x,int MO) {if (x>=MO) x-=MO;return x;}
inline int sub(int x) {if (x<0) x+=MOD;return x;}
inline int sub(int x,int MO) {if (x<0) x+=MO;return x;}
inline void Add(int &x,int y) {x=add(x+y);}
inline void Add(int &x,int y,int MO) {x=add(x+y,MO);}
inline void Sub(int &x,int y) {x=sub(x-y);}
inline void Sub(int &x,int y,int MO) {x=sub(x-y,MO);}
template<typename T> inline int quick_pow(int x,T y) {int res=1;while (y) {if (y&1) res=1ll*res*x%MOD;x=1ll*x*x%MOD;y>>=1;}return res;}
template<typename T> inline int quick_pow(int x,T y,int MO) {int res=1;while (y) {if (y&1) res=1ll*res*x%MO;x=1ll*x*x%MO;y>>=1;}return res;}

const int MAXN=2e5;

int n,m,k;
int t1[MAXN+48],t2[MAXN+48],sum[MAXN+48];

int main ()
{
#ifndef ONLINE_JUDGE
    double TIME=clock();
    freopen ("a.in","r",stdin);
    freopen ("a.out","w",stdout);
    cerr<<"Running..."<<endl;
#endif
    cin>>n>>m>>k;
    t1[1]=1;
    rep(i,2,k) t1[i]=sub(quick_pow(i,n)-quick_pow(i-1,n));
    t2[k]=1;
    rep(i,1,k-1) t2[i]=sub(quick_pow(k-i+1,m)-quick_pow(k-i,m));
    sum[k]=t2[k];REP(i,k-1,1) sum[i]=add(sum[i+1]+t2[i]);
    int ans=0;
    if (n>=2 && m>=2)
        rep(i,1,k) Add(ans,1ll*t1[i]*sum[i]%MOD);
    else
        rep(i,1,k) Add(ans,1ll*t1[i]*t2[i]%MOD);
    printf("%d\n",ans);
#ifndef ONLINE_JUDGE
    cerr<<"Exec Time: "<<(clock()-TIME)/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


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

long long int modinv(long long int a, long long int m) {
  long long int b = m, u = 1, v = 0;
  while (b) {
    long long int 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() {
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    long long int N, S, K;
    cin >> N >> S >> K;
    long long int G = __gcd(K, N);
    if ((N - S) % G != 0) cout << -1 << endl;
    else {
      long long int A, B, n;
      A = K / G;
      B = (N - S) / G;
      n = N / G;
      long long int C = modinv(A, n);
      long long int ans = C * B % n;
      if (ans < 0) ans += n;
      cout << ans << endl;
    }
  }
}

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MAXN=4e5+10;
const int mod=1e9+7;
void solve()
{
    int n,q;
    string s;
    cin>>n;
    cin>>s;
    cin>>q;
    int flag=0;
    while(q--)
    {
        int t,a,b;
        cin>>t>>a>>b;
        if(t==2)
        {
            flag^=1;
        }
        else
        {
            if(flag==0)
            {
                swap(s[a-1],s[b-1]);
            }
            else
            {
                if(a<=n)
                {
                    a+=n;
                }
                else
                {
                    a-=n;
                }
                if(b<=n)
                {
                    b+=n;
                }
                else
                {
                    b-=n;
                }
                swap(s[a-1],s[b-1]);
            }
        }
    }
    if(flag)
    {
        for(int i=n;i<2*n;++i) cout<<s[i];
        for(int i=0;i<n;++i) cout<<s[i];
    }
    else
    {
        cout<<s;
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int _=1;
    //cin>>_;
    for(int i=1; i<=_; ++i)
    {
        solve();
    }
    return 0;
}