#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#define int long long
#define uc getchar()
#define ph putchar
#define R register
#define CN const
#define rint R int
#define cint CN int
#define ps ph(' ')
#define pe ph('\n')
using namespace std;
cint inf=998244353;
cint mix=1e6+5;
inline int in();
inline void out(rint x);
int n=in(),m=in();
int fa[mix],ans,wer;
bool vis[mix],cis[mix];
inline int gf(rint x){
	return fa[x]!=x?fa[x]=gf(fa[x]):x;
}
inline void merge(rint x,rint y){
	x=gf(x),y=gf(y);
	if(x!=y)fa[x]=y;
}
#undef int
int main() {
#define int long long
	R char c;
	for(rint i=m+n;i;--i)fa[i]=i;
	merge(1,n);
	merge(1,n+1);
	merge(1,n+m);
	for(rint i=1;i<=n;++i)
	for(rint j=1;j<=m;++j){
		while((c=uc)<'#');
		if(c<'.')merge(i,n+j);
	}	for(rint i=1;i<=n;++i)
	if(!vis[gf(i)])vis[gf(i)]=1,++ans;
	for(rint i=n+m;n<i;--i)
	if(!cis[gf(i)])cis[gf(i)]=1,++wer;
	out(min(ans,wer)-1),pe;
}
inline int in() {
	rint x=0;
	R bool f=0;
	R char s=uc;
	while((s<'0'||'9'<s)&&s!='-')s=uc;
	if(s=='-')f=1,s=uc;
	while('0'<=s&&s<='9')(x*=10)+=s^48,s=uc;
	return f?-x:x;
}
inline void out(rint x) {
	if(x<0)ph('-'),x=-x;
	rint y=x/10;
	if(y)out(y);
	ph((x-y*10)^48);
}

#include <bits/stdc++.h>
typedef long long ll;
#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 sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
const int MAX_N = 2e4+10;
int par[MAX_N];//親
int pank[MAX_N];//木の深さ

//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        pank[i]=0;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(pank[x]<pank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(pank[x]==pank[y])pank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}
int main(void){
    ll h,w;cin>>h>>w;
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h)rep(j,w)cin>>s[i][j];
    s[0][0]=s[0][w-1]=s[h-1][0]=s[h-1][w-1]='#';

    init(h+w);
    rep(i,h)rep(j,w)if(s[i][j]=='#')unite(i,h+j);
    map<ll,ll> mp1,mp2;
    rep(i,h)mp1[find(i)]++;
    rep(i,w)mp2[find(h+i)]++;
    ll res=min((ll)mp1.size()-1,(ll)mp2.size()-1);
    cout<<res<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

void factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

void cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}

int main(){
	int tt;
    cin>>tt;
    FOR(ti,0,tt){
        LL n,a,b;
        cin>>n>>a>>b;
        if(b>a)swap(a,b);
        LL all=mul(mul(n-a+1,n-a+1),mul(n-b+1,n-b+1));
        LL ta=n-a+1,tb=n-b+1;
        LL tt1=max(n-a-b+1,0LL);
        LL tt2=sub(mul(ta,tb),mul((tt1+1),tt1));
        LL rate=dvs(tt2,mul(ta,tb));
        LL t=mul(all,mul(rate,rate));
        cerr<<tt1<<" "<<tt2<<" "<<rate<<" "<<t<<endl;
        cout<<sub(all,t)<<endl;
    }
}


#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> xs, ys;
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == '0') xs.push_back(i);
    }
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == '0') ys.push_back(i);
    }

    if (xs.size() != ys.size()) {
        cout << "-1\n";
        return;
    }

    int ans = 0;
    for (int i = 0; i < (int)xs.size(); ++i) {
        if (xs[i] != ys[i]) ++ans;
    }

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

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

    solve();

    return 0;
}

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define all( v )        begin( v ), end( v )
#define rep( i, j )     for ( int i = 0; i < (int)j; ++i )
#define rep2( i, j, k ) for ( int i = j; i <= (int)k; ++i )
#define rep3( i, j, k ) for ( int i = j; i >= (int)k; --i )

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

template < class S, class T > inline bool chmin( S& x, T y ) {
  if ( x > y ) {
    x = y;
    return true;
  }
  return false;
}
template < class T > struct edge {
  int from, to;
  T cost;

  edge( int to = 0 ) : from( -1 ), to( to ), cost( 0 ) { };
  edge( int to, T cost ) : from( -1 ), to( to ), cost( cost ) { }
  edge( int from, int to, T cost ) : from( from ), to( to ), cost( cost ) { }

  edge& operator=( const int& x ) {
    to = x;
    return *this;
  }
};

template < class T > using pq    = priority_queue< T >;
template < class T > using pqg   = priority_queue< T, vector< T >, greater< T > >;
template < class T > using Edges = vector< edge< T > >;
template < class T > using Graph = vector< Edges< T > >;

using ld  = long double;
using ll  = long long;
using pi  = pair< int, int >;
using pl  = pair< ll, ll >;
using vi  = vector< int >;
using vl  = vector< ll >;
using vpi = vector< pi >;
using vpl = vector< pl >;
using vvi = vector< vi >;
using vvl = vector< vl >;

const ll INFLL = 100000000000000000;
const ll INF   = 1000000000;
const ll MAX   = 500005;
const ll MOD   = 1000000007;
// const ll MOD = 998244353;

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

  int n;
  cin >> n;

  string s, t;
  cin >> s >> t;

  ll x = count( all( s ), '0' ), y = count( all( t ), '0' );
  if ( x != y ) {
    cout << -1 << endl;
    return ( 0 );
  }

  ll ans = x;
  int a = 0, b = 0;

  rep( i, n ) {
    if ( s[i] == '0' ) ++a;
    if ( t[i] == '0' ) ++b;
    if ( s[i] == t[i] && s[i] == '0' && a == b ) --ans;
  }

  cout << ans << endl;

  return ( 0 );
}


#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18+7;

ll ceildiv(ll a, ll b) { return (a+b-1)/b; } // 切り上げ
ll floordiv(ll a, ll b) { return a/b; } // 切り下げ

int show_matrix(vector<vector<int>> &dp) {
  loop(0, dp.size(), i) {
    loop(0, dp[i].size(), j) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

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

  ll N, Q;
  cin >> N >> Q;

  vector<ll> A(N);
  vector<ll> C(N);

  ll prev = -1;
  ll last = 0;
  loop(0, N, i) {
    ll a, b;
    cin >> a;
    b = a - (i+1);
    A[i] = a;
    C[i] = b;
  }

  loop(0, Q, i) {
    ll K;
    cin >> K;
    ll pos = lower_bound(C.begin(), C.end(), K) - C.begin();
    // print(pos
    // posまでに出現

    ll idx;
    ll v;
    if (pos == 0) {
      idx = 0;
      v = 0;
    } else{
      idx = C[pos -1];
      v = A[pos-1];
    }
    print(v + K - idx);
  }
}

#include<bits/stdc++.h>
using namespace std;
long long n,a;
int main()
{
	cin>>n>>a;
	for(int i=1;i<=a;i++)
	{
		if(n%200==0)
		n=n/200;
		else n=n*1000+200;
	}
	cout<<n;
}


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

#ifndef ONLINE_JUDGE
#define eprintf(...) fprintf(stderr,__VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) void(0)
#endif

using ll = long long;

int main() {
	speedup;
	int v,t,s,d;
	cin>>v>>t>>s>>d;
	if(d<v*t||v*s<d) cout<<"Yes\n";
	else cout<<"No\n";
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(v,n) for(ll i=0;i<n;i++){ll var;cin>>var;v.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod = 1e9+7;
#define mod2 998244353
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; } // cout << endl
#define con continue

bool prime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return 1;
    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return 1;
}
bool isPerfectSquare(ll x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
bool isPowerOfTwo(ll n) {
    return n > 0 && !(n&(n-1));
}
bool subsequence_checker(string str1, string str2, ll m, ll n)
{
    if (m == 0) return 1;
    if (n == 0) return false;
    if (str1[m-1] == str2[n-1])
        return subsequence_checker(str1, str2, m-1, n-1);
    return subsequence_checker(str1, str2, m, n-1);
}
bool cmp(const pair<ll,ll> &a,  const pair<ll,ll> &b)
{
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff);
}
ll gcd(ll p, ll q){
if(p % q == 0)return q;
return gcd(q, p % q);
}
ll countDigit(ll n)
{
    return floor(log10(n) + 1);
}
ll power(ll a,ll n)
{
  if(n==0)
    return 1;
  if(n%2)
    return (a*power((a*a)%mod,n/2))%mod;
  return power((a*a)%mod,n/2);
}
ll fast_pow(ll a, ll p) {
    ll res = 1;
    while (p) {
        if (p % 2 == 0) {
            a = (a * a) % mod;
            p /= 2;
        } else {
            res = (res * a) % mod;
            p--;
        }
    }
    return res;
}
ll setBitNumber(ll n)
{
    n |= n >> 1;
    n |= n >> 2;

    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n = n + 1;

    return (n >> 1);
}
ll ncr(ll n , ll r)
{
    if(n<r) return 0;
    if(r==1) return n;
    if(r==2) return (n*(n-1))/2;
    return (n*(n-1)*(n-2))/6;
}
ll countDivisors(ll n) {
    ll count =0 ;
    for (ll i = 1; i*i < n; i++)
        if (n % i == 0)
            count++;
    for (ll i = sqrt(n); i >= 1; i--)
        if (n % i == 0)
            count++;
    return count;
}
vector<ll> printDivisors(ll n){
    vector<ll> d ;
    for (ll i = 1; i*i < n; i++)
        if (n % i == 0){
            d.push_back(i);
            //cout<<i<<" ";
        }
    for (ll i = sqrt(n); i >= 1; i--)
        if (n % i == 0){
            d.push_back(n/i);
            //cout<<n/i<<" ";
        }
    return d;
}
///////////////////////////////////Lets Do It///////////////////////////////////
void solve()
{

    ld v,t,s,d;
    cin>>v>>t>>s>>d;

    ld time = d/v;

    if(time>s || time < t )
    {
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return;
}

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

    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }

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

    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
//typedef long long int ll;
typedef unsigned long long int ll;
//typedef pair<ll, ll> pd;
const int mod = 1e9 + 7;
//#define int long long
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    set<int> s;
    for(auto x: a){
        s.insert(x);
    }
    int num = 1;
    for(auto x: s){
        if(x!=num){
            cout<<"No\n";
            return;
        }
        num++;
    }
    if(num==n)cout<<"No\n";
    else cout<<"Yes\n";
}

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}

#include <iostream>
#include <deque>
#include <climits>

int search(int lhs, const std::deque<int>& rhs) {
    if (rhs.size() == 0) {
        return lhs;
    }
    int min = INT_MAX;
    for (int i = 1; i <= rhs.size(); i++) {
        int n = 0;
        auto copied = rhs;
        for (int j = 0; j < i; j++) {
            n |= copied[0];
            copied.pop_front();
        }
        const int branch_result = search(lhs ^ n, copied);
        if (branch_result < min) {
            min = branch_result;
        }
    }
    return min;
}

int main() {
    int N;
    std::deque<int> A;
    std::cin >> N;
    for (int i = 0; i < N; i++) {
        int n;
        std::cin >> n;
        A.push_back(n);
    }
    // std::cout << N << std::endl;
    // for (int i = 0; i < A.size(); i++) {
    //     std::cout << i << std::endl;
    // }
    const int result = search(0, A);
    std::cout << result << std::endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long LL;
const LL inf = 2e18;
using namespace std;
int T, x, y, p, q;
LL ans;
LL gcd(LL a, LL b) {
    if (!b)
        return a;

    return gcd(b, a % b);
}
LL exgcd(LL a, LL b, LL &x, LL &y) {
    LL g = a;

    if (!b)
        x = 1, y = 0;
    else {
        g = exgcd(b, a % b, y, x);
        y -= a / b * x;
    }

    return g;
}
LL calc(LL a, LL b, LL A, LL B) {
    LL c = A - B;

    if (c % gcd(a, b) != 0)
        return inf;

    LL x = 0, y = 0;
    LL g = exgcd(a, b, x, y);
    x *= c / g;
    y *= c / g;
    LL ans = inf;
    LL p = ceil(1.0 * -B / a), q = ceil(1.0 * A / b);
    LL bb = b / g;
    LL t1 = ceil(1.0 * (p - x) / bb);
    x += t1 * bb;
    return x * a + B;
}
void dfs(int k)
{
	if(!k)return;
	int x=1;
	x++;
	dfs(k-1);
}
int main() {
    cin >> T;
    int ccc = 0;
    for (int i = 1;i <= T;i++)
        ccc++;
    while (T--) {
        cin >> x >> y >> p >> q;
        ans = inf;

        for (LL a = p; a < p + q; a++)
            for (LL b = x; b < x + y; b++) {
                ans = min(calc(2 * (x + y), (p + q), a, b), ans);
            }

        if (ans == inf)
            cout << "infinity" << endl;
        else
            cout << ans << endl;
    }
	dfs(1000);
    return 0;
}

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

class UnionFind {
    int cnt;
    vector<int> par, rank, size;
public:
    UnionFind() {}
    UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) {
        for (int i = 0; i<_n; ++i) par[i] = i;
    }
    int find(int k) {
        return (k == par[k]) ? k : (par[k] = find(par[k]));
    }
    int operator[](int k) {
        return find(k);
    }
    int getSize(int k) {
        return size[find(k)];
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        --cnt;
        if (rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if (rank[y] == rank[x]) ++rank[x];
        }
    }
    int count() {
        return cnt;
    }
};

void solve() {
    int N;
    cin >> N;
    vi X(N), Y(N);
    rep(i, N) cin >> X[i] >> Y[i];
    double ng = 100, ok = 0;
    rep(ITER, 60) {
        UnionFind uf(N + 2);
        double r = (ng + ok) / 2;
        rep(i, N) {
            if (100 - Y[i] < 2 * r)uf.unite(i, N);
            if (Y[i] + 100 < 2 * r)uf.unite(i, N + 1);
            rep(j, i) {
                if (hypot(X[i] - X[j], Y[i] - Y[j]) < 2 * r) {
                    uf.unite(i, j);
                }
            }
        }
        (uf[N] == uf[N + 1] ? ng : ok) = r;
    }
    cout << ok << endl;
}

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


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

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

#define all(x) (x).begin(), (x).end()
#define each(x, a) for (auto& x : a)
#define rep(i, b, e) for (int i=(b); i<(e); ++i)
#define repi(i, b, e, c) for (int i=(b); (c)>0?i<(e):i>(e); i+=(c))
#define vt vector
#define sz(x) (int)(x).size()

void solve() {
	int n, q, t, a, b;
	string s;
	cin >> n >> s >> q;
	bool f = false;
	rep(i, 0, q) {
		cin >> t >> a >> b;
		if (t == 1) {
			--a;
			--b;
			if (f) {
				a = (a+n)%(2*n);
				b = (b+n)%(2*n);
			}
			swap(s[a], s[b]);
		}
		if (t == 2) f = !f;
	}
	if (f) {
		s = s.substr(n) + s.substr(0, n);
	}
	cout << s << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define LL long long
#define LD long double
#define y1 ___y1
#define next ___next
#define left ___left
#define right ___right
#define pii pair<int, int>
#define pll pair<LL, LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<pii>
#define vll vector<pll>
#define PQ priority_queue
#define ffo fflush(stdout)
#define gch getchar()
#define e (int)(1e9 + 7)
#define ri(X) scanf("%d", &(X))
#define rii(X, Y) scanf("%d%d", &(X), &(Y))
#define riii(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define rl(X) scanf("%lld", &(X))
#define rll(X, Y) scanf("%lld%lld", &(X), &(Y))
#define rlll(X, Y, Z) scanf("%lld%lld%lld", &(X), &(Y), &(Z))
#define printi(X) printf("%d", (int)(X))
#define printii(X, Y) printf("%d %d", (int)(X), (int)(Y))
#define printiii(X, Y, Z) printf("%d %d %d", (int)(X), (int)(Y), (int)(Z))
#define printl(X) printf("%lld", (LL)(X))
#define printll(X, Y) printf("%lld %lld", (LL)(X), (LL)(Y))
#define printlll(X, Y, Z) printf("%lld %lld %lld", (LL)(X), (LL)(Y), (LL)(Z))
#define enter printf("\n")
#define space printf(" ")
struct node {
    int x, y;
    bool operator < (const node &T) const {
        return x < T.x;
    }
};
LL power(LL a, LL p) {
    if (p == 0) return 1;
    if (p == 1) return a;
    LL tmp = power(a, p / 2);
    if (p % 2) tmp = tmp * tmp % e * a;
    else tmp *= tmp;
    return tmp % e;
}
int hp, heap[1005];
void heap_push(int x) {
    heap[++hp] = x;
    int p = hp;
    while (p > 1 && heap[p / 2] > x) {
        heap[p] = heap[p / 2];
        heap[p / 2] = x;
        p /= 2;
    }
    return;
}
int heap_top() {
    if (hp == 0) return -1;
    return heap[1];
}
int heap_pop() {
    if (hp == 0) return -1;
    int re = heap[1];
    heap[1] = heap[hp];
    hp--;
    int p = 1, tmp;
    while (1) {
        if (p * 2 > hp) break;
        if (p * 2 == hp) {
            if (heap[p * 2] < heap[p]) {
                tmp = heap[p * 2];
                heap[p * 2] = heap[p];
                heap[p] = tmp;
            }
            break;
        }
        if (heap[p] > heap[p * 2] && heap[p * 2 + 1] >= heap[p * 2]) {
            tmp = heap[p * 2];
            heap[p * 2] = heap[p];
            heap[p] = tmp;
            p *= 2;
        }
        else if (heap[p] > heap[p * 2 + 1] && heap[p * 2] >= heap[p * 2 + 1]) {
            tmp = heap[p * 2 + 1];
            heap[p * 2 + 1] = heap[p];
            heap[p] = tmp;
            p = p * 2 + 1;
        }
        else break;
    }
    return re;
}

int T;
char s[500005];
int bb;

void solve() {
    int n, q, t, a, b;
    bb = 0;
    scanf("%d\n%s", &n, s + 1);
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &t, &a, &b);
        if (t == 1) {
            if (bb) {
                if (a <= n) a += n;
                else a -= n;
                if (b <= n) b += n;
                else b -= n;
                char c = s[a];
                s[a] = s[b];
                s[b] = c;
            }
            else {
                char c = s[a];
                s[a] = s[b];
                s[b] = c;
            }
        }
        else {
            bb = 1 - bb;
        }
    }
    if (bb) {
        for (int i = n + 1; i <= 2 * n; i++) {
            printf("%c", s[i]);
        }
        for (int i = 1; i <= n; i++) {
            printf("%c", s[i]);
        }
    }
    else {
        for (int i = 1; i <= n; i++) {
            printf("%c", s[i]);
        }
        for (int i = n + 1; i <= 2 * n; i++) {
            printf("%c", s[i]);
        }
    }
    enter;
    return;
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
typedef pair<int,int> pii;
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)
#define x first
#define y second

const int N = 105,MOD = 1e9+7;
pii edges[N * N];
int deg[N];

struct Mat
{
    int c[N][N];
    Mat()
    {
        memset(c,0,sizeof c);
    }
    Mat operator*(const Mat& r) const
    {
        Mat res;
        forn(i,1,N - 1) forn(j,1,N - 1) forn(k,1,N - 1) res.c[i][j] = (res.c[i][j] + 1ll*c[i][k] * r.c[k][j] % MOD) % MOD;
        return res;
    }
    void operator*(int r)
    {
        forn(i,1,N - 1) forn(j,1,N - 1) c[i][j] = 1ll*c[i][j] * r % MOD;
    }
};

Mat qpow(Mat a,int b,int MOD)
{
    Mat res;forn(i,1,N - 1) res.c[i][i] = 1;
    while(b)
    {
        if(b & 1)   res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int qpow(int a,int b,int MOD)
{
    int res = 1;
    while(b)
    {
        if(b & 1)   res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main()
{
    // freopen("D://OJCodes//TTT//in.txt","r",stdin);
    // freopen("D://OJCodes//TTT//out.txt","w",stdout);

    int n,m,k;scanf("%d%d%d",&n,&m,&k);
    Mat f,B;forn(i,1,n)   scanf("%d",&f.c[1][i]);

    forn(i,1,m)
    {
        int u,v;scanf("%d%d",&u,&v);
        ++deg[u];++deg[v];
        edges[i] = {u,v};
    }

    int m_2fact = qpow(m * 2,MOD - 2,MOD);

    forn(i,1,m)
    {
        int u = edges[i].x,v = edges[i].y;
        B.c[u][v] = m_2fact;
        B.c[v][u] = m_2fact;
    }

    forn(i,1,n) B.c[i][i] = (2 * m - deg[i]) * 1ll * m_2fact % MOD;

    B = qpow(B,k,MOD);
    f = f * B;
    forn(i,1,n) printf("%d\n",f.c[1][i]);

    // fclose(stdin);
    // fclose(stdout);
    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pb push_back
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

ll fac[1000001];

void pre(){
    fac[0]=fac[1]=1;
    for(int i=2;i<=1000001;i++)
{

    fac[i]=(fac[i-1]*1LL*i)%mod;
}
}

ll binpower(ll a,ll n){
    ll res=1;
    while(n){

    if(n%2)
        res = (res*1LL*a)%mod;

        n/=2;
        a=(a*1LL*a)%mod;

    }
    return res;

}

ll nCrmod(ll n,ll r){

ll res= fac[n];
res = (res*1LL*binpower(fac[r],mod-2))%mod;
res= (res*1LL*binpower(fac[n-r],mod-2))%mod;
return res;

}

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll modexp(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  modexp(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*modexp(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return modexp(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}

void SieveOfEratosthenes(ll n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

vector<int> Centroid(vector<int>g[],int n) {

        vector<int> centroid;
        vector<int> sz(n+1);
        function<void (int, int)> dfs = [&](int u, int prev) {
                sz[u] = 1;
                bool is_centroid = true;
                for (auto v : g[u]) if (v != prev) {
                        dfs(v, u);
                        sz[u] += sz[v];
                        if (sz[v] > n / 2) is_centroid = false;
                }
                if (n - sz[u] > n / 2) is_centroid = false;
                if (is_centroid) centroid.push_back(u);
        };
        dfs(1, 0);
        return centroid;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll s=0;
    ll n;
    cin>>n;
    for(int i=1;i>0;i++){
        s+=i;
        if(s>=n){
            cout<<i;
            break;
        }
    }

    return 0;
}


///////////////////////////////
///     Let's Get AC!!!     ///
///////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int main(){
  int n,a[10000];
  cin >> n;
  int ans=0;
  for(int i=0;i<n;i++){
  cin >> a[i];
    if(a[i]>10){
    ans+=a[i]-10;
    }
  }
  cout << ans << endl;
}


#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
#include <time.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define PI 3.141592653589793

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 998244353;

/*clock_t start = clock();
clock_t end = clock();
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
printf("%lf", time);*/

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int ans = 0;
    int GCD = 0;
    for(int i = 2; i <= 1000; i++){
        int cnt = 0;
        rep(j,N){
            if(A[j] % i == 0){
                cnt++;
            }
        }
        if(GCD < cnt){
            ans = i;
            GCD = cnt;
        }
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll m,h;cin >> m >>h;
    if(h%m)cout << "No" <<endl;
    else cout << "Yes" <<endl;
}


# include <cstdio>

namespace Main {
    namespace Source {
        typedef unsigned int uint;
        static inline const uint qpow(uint b, uint e, const uint mod) {
            uint r(1);
            while (e) {
                if (e bitand 1) r = 1ull * r * b % mod;
                b = 1ull * b * b % mod, e >>= 1;
            }
            return r;
        }
    }
    using namespace Source;
    static const uint P(998244353);
    static uint n, m, k;
    static uint ans;
    static inline const void main() {
        scanf("%u%u%u", &n, &m, &k);
        if (n == 1 and m == 1) return (const void)printf("%u\n", k);
        if (n == 1) {
            for (register uint i(1); i <= k; ++i)
                ans =
                (ans + (qpow(k - i + 1, m, P) + P - qpow(k - i, m, P))) % P;
            goto end;
        }
        if (m == 1) {
            for (register uint i(1); i <= k; ++i)
                ans =
                (ans + (qpow(i, n, P) + P - qpow(i - 1, n, P))) % P;
            goto end;
        }
        for (register uint i(1); i <= k; ++i)
            ans = (ans + 1ull * (qpow(i, n, P) + P - qpow(i - 1, n, P)) * qpow(k - i + 1, m, P)) % P;
    end:printf("%u\n", ans);
    }
}

signed int main() { Main::main(); return 0; }

// Problem : D - Sky Reflector
// Contest : AtCoder - AtCoder Regular Contest 113
// URL : https://atcoder.jp/contests/arc113/tasks/arc113_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=100005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vi prime;
bool isprime[N];
void pre()
{
    for(int i=2;i<N;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<N;j+=i)
            isprime[j]=false;
            prime.pb(i);
        }
    }
    return;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int spf[N+1];
void spfFun(){
    for(int i=0;i<=N;i++) spf[i]=i;
    for(int i=2;i*i<=N;i++){
        if(spf[i]==i){
            for(int j=i*i;j<=N;j+=i){
                spf[j] = min(spf[j],i);
            }
        }
    }
}

bool isPerfectSquare(long double x)
{
  // Find floating point value of
  // square root of x.
  long double sr = sqrt(x);

  // If square root is an integer
  return ((sr - floor(sr)) == 0);
}
void print(bool n){
    if(n){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

int32_t main()
{
    IOS;
    // pre();
    // fill(isprime,true);
    int n,m,k;
    cin>>n>>m>>k;
    int ans=0;
    for(int i=1;i<=k;i++){
    	int p = (power(i,n,mod)-power(i-1,n,mod)+mod)%mod;
    	int q;
    	if(m==1||n==1)
    		q = (power(k-i+1,m,mod)-power(k-i,m,mod)+mod)%mod;
    	else
    		q = power(k-i+1,m,mod);
    	ans+=(p*q)%mod;
    	ans%=mod;
    }
    cout<<ans;
}


#include <iostream>
using namespace std;

int main(void)
{
    int x, y;
    cin >> x >> y;

    int result = abs(x - y);
    if (result < 3)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

  int  fact(int a){
    int b=1;
    for(int i=2;i<=a;i++){
      b*=i;
    }
   return b;}
 int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 ll n,m;
 cin>>n>>m;
 cout<<n/m<<endl;
return 0;
}


/*

 ALLAH IS ALMIGHTY              ******BISMILLAHIR RAHMANIR RAHIM.******              ALLAH IS ALMIGHTY
                                    ```````````````````````````````
                                        AUTHOR: ANISUR RAHAMAN
                                            BSMRSTU(SHIICT)
                                                ID:017

                            ............LET's START OUR JOURNEY.............

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

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

//~~~~~~~~~~~~ Sort Form Of Long~~~~~~~~~~~//
#define ll long long int
#define lls int64_t
#define ld long double
#define db double
#define ull unsigned long long int

//~~~~~~~~~~~~~~Pair~~~~~~~~~~~~~~~~~~//
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<db,db>
#define psi pair<string,int>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<db>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pi>
#define vpl vector<pl>
#define vpd vector<pd>
#define vpsi vector<psi>

//~~~~~~~~~~~~~~Vector~~~~~~~~~~~~~~~~~//
#define pb push_back
#define pf push_front
#define MP make_pair
#define in insert
#define ff first
#define ss second
#define al(v) v.begin(),v.end()
#define alr(v) v.rbegin(), v.rend()
#define srt(v) sort(al(v))
#define srtr(v) sort(al(v), greater<int>());
#define len(x) ((ll)(x).length())
#define sz(x) ((ll)(x).size())
#define rev(v) reverse(al(v))
#define btcnt(n) __builtin_popcount(n)
#define acl(v, n) accumulate(al(v), n)
#define eb emplace_back
#define lb(v, kk) lower_bound(al(v), kk)
#define ub(v, kk) upper_bound(al(v), kk)
#define tpu(str) transform(al(str), str.begin(), ::toupper)
#define tpl(str) transform(al(str), str.begin(), ::tolower)
#define cignr cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define mxv(v) *max_element(al(v))
#define mnv(v) *min_element(al(v))

const int MOD = 1e9 + 7;
const ll INF = 2e18;
const int mxn = 2e9 + 9;
const int mxd = 2e5 + 5;

//~~~~~~~~~~~~~~~~~~Function~~~~~~~~~~~~~~~~~~~~//
lls gcd(lls a, lls b){
    if(b == 0LL) return a;
    return gcd(b, a % b);
}

lls lcm(lls a, lls b){
    return (a / gcd(a, b) * b);
}
//~~~~~~~~~~~~~~~Loops and Short~~~~~~~~~~~~~~~~//

#define PI acos(-1)
#define C continue
#define B break
#define off return 0
#define N '\n'
#define WT(something) auto az = something; cout << az << N;
#define WTS(something) cout << something << N;
#define rep(i, n) for(lls i = 0; (lls)i < n; i++)
#define repn(i, a, b) for(lls i = (lls)(a); i < (lls)(b); i++)
#define repr(i, a, b) for(lls i = (lls)(a) - 1; i >= (lls)(b); i--)
#define test_case() int T; cin >> T; while(T--)

using namespace std;

void SoLuTioN()
{
    lls l, r;
    cin >> l >> r;
    lls ka = (r - 2 * l + 1);
    if (ka <= 0)
        cout << "0" << N;
    else cout << (lls)((ka * (ka + 1)) / 2) << N;
}

int main()
{
    I_O
    test_case()
    {
        SoLuTioN();
    }

    off;
}

//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
//#pra gma G CC opti mize(3)
using namespace std;
using std::bitset;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
	template<class T>
	inline void read(T &x) {
		x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		if(fu)x=-x;
	}
	inline int read() {
		int x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		return fu?-x:x;
	}
	char _n_u_m_[40];
	template<class T>
	inline void write(T x ) {
		if(x==0) {
			putchar('0');
			return;
		}
		T tmp = x > 0 ? x : -x ;
		if( x < 0 ) putchar('-') ;
		register int cnt = 0 ;
		while( tmp > 0 ) {
			_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
			tmp /= 10 ;
		}
		while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
	}
	template<class T>
	inline void write(T x ,char ch) {
		write(x);
		putchar(ch);
	}
}
using namespace fastIO;
bool ok[1<<18],ed[19][19];
int dp[1<<18],n;
int main() {
	memset(dp,0x3f,sizeof(dp));
	cin>>n;
	F(i,1,read()) {
		ri t1=read(),t2=read();
		t1--,t2--;
		ed[t1][t2]=ed[t2][t1]=1;
	}
	F(S,1,(1<<n)-1) {
		F(i,0,n-1)if(S&(1<<i))F(j,i+1,n-1) if(S&(1<<j)){
			if(!ed[i][j])goto fuckccf;
		}
		ok[S]=1;
		n;
fuckccf:
		n;
	}dp[0]=0;
	F(i,1,(1<<n)-1){
		for(ri j=i;j;j=(j-1)&i){
			if(ok[j])dp[i]=min(dp[i],dp[i^j]+1);
		}
	}cout<<dp[(1<<n)-1];
	return 0;
}


#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#define aldgebu return
#define ff first
#define sc second
#define pb push_back
#define pii pair <int,int>
#define ll long long int
#define pll pair<ll,ll>
#define plc pair<ll,char>
#define ull unsigned long long
using namespace std;
const int inf = 1e9;
const int mod = 1000000007;

void Dontfuckedup(){
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size(); i++){
		if (s[i] == '0' || s[i] == '1' || s[i] == '8')continue;
		if (s[i] == '6'){
			s[i] = '9';
			continue;
		}
		if (s[i] == '9')
			s[i] = '6';
	}
	cout << s;
}

int32_t main () {

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

    int T = 1; //cin>>T;
    while (T--)Dontfuckedup();

    return 0;
}

#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

	string s;
	cin >> s;

	cout << s[1] << s[2] << s[0] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long double a,b;cin>>a>>b;
    b=a-b;
    long double ans=100*(b/a);
    cout<<fixed<<setprecision(15)<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a,b;
	cin>>a>>b;
	cout<<(a-b)/a*100;
 }


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define nl "\n"
#define forf(i,a,n) for(ll i=a;i<=n;i++)
#define forb(i,b,n) for(ll i=b;i>=n;i--)
#define pb push_back
#define vll vector<ll>
#define all(qw) qw.begin(),qw.end()
#define read(vec) ll qwe;cin>>qwe;vec.pb(qwe)
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ff first
#define ss second
#define mp make_pair
#define sll set<ll>
#define inset(sett) ll qwer;cin>>qwer;sett.insert(qwer);

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

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

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

void onlinejudge(){
	#ifndef ONLINE_JUDGE
  freopen("Input.txt", "r", stdin);
  freopen("Output.txt", "w", stdout);
  #endif // ONLINE_JUDGE
}

               //SOLVE

void solve(){
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    ll a=1000000000;
    ll b=-1000000000;
    forf(i,1,n){
    	if(i==n){
    		cout<<a<<" ";
    		break;
    	}
    	cout<<i<<" ";
    	a-=i;
    }
    forf(i,1,k){
    	if(i==k){
    		cout<<b<<" ";break;
    	}
    	cout<<-i<<" ";
    	b+=i;
    }
    cout<<nl;
}

int main(){  // Change the approach
  //onlinejudge();
  //fastio
  ll ttt;ttt=1;
  //cin>>ttt;
  while(ttt--) solve();
return 0;
}

// CHECK FOR EXTREME CASES AND ZEROS;

#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007

typedef long long ll;

int main(){
	int a,b;
	cin>>a>>b;
	if(a==b){
		for(int i=1;i<=a;i++) cout<<i<<" ";
		for(int i=1;i<=a;i++) cout<<(-1)*i<<" ";
	}
	else {
		if(a>b){
			for(int i=1;i<=a;i++) cout<<i<<" ";
			int remaining = 0;
			for(int i=1;i<=a;i++) {
				if(i>=b){
					remaining += i;
				}
				else cout<<(-1)*i<<" ";
			}
			cout<<(-1)*remaining<<endl;
		}
		else{
		if(a<b){
			for(int i=1;i<=b;i++) cout<<(-1)*i<<" ";
			int remaining = 0;
			for(int i=1;i<=b;i++) {
				if(i>=a){
					remaining += i;
				}
				else cout<<i<<" ";
			}
			cout<<remaining<<endl;
		}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    V<ll> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
    V<int> c(b - a + 1);
    for (ll i = a; i <= b; i++) {
        for (int j = 0; j < p.size(); j++) {
            if (i % p[j] == 0) {
                c[i - a] |= (1 << j);
            }
        }
    }
    int n = b - a + 1;
    V<V<ull>> dp(n + 1, V<ull>(1 << 20));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < (1 << 20); j++) {
            dp[i + 1][j] += dp[i][j];
            if ((j & c[i]) == 0) {
                dp[i + 1][j | c[i]] += dp[i][j];
            }
        }
    }
    ull res = 0;
    for (int j = 0; j < (1 << 20); j++) {
        res += dp[n][j];
    }
    cout << res << newl;
}

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

typedef long long ll;

int main() {
    int N, M, X;
    cin >> N >> M;
    vector<bool> A(1001, false), B(1001, false);
    rep(i, N) {
        cin >> X;
        A[X] = true;
    }
    rep(i, M) {
        cin >> X;
        B[X] = true;
    }
    rep(i, 1001) {
        if (A[i] ^ B[i]) cout << i << " ";
    }
    cout << "\n";
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;
const long long LINF = 1001002003004005006;
const double PI = acos(-1);
int d4r[] = {1, 0, -1, 0};
int d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1};
int d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> to(n);
    for(int i = 0;i < n;++i) {
        cin >> to[i];
        to[i]--;
    }
    vector<int> v(n, 0);
    for(int i = 0;i < n;++i) {
        if(v[i] != 0) {
            continue;
        }
        vector<int> memo;
        memo.push_back(i);
        set<int> st;
        st.insert(i);
        int cnt = 1;
        int nowv = i;
        bool flag = true;
        while(cnt == st.size()) {
            nowv = to[nowv];
            if(v[nowv] != 0) {
                flag = false;
                if(v[nowv] == -1) {
                    for(int j : memo) {
                        v[j] = -1;
                    }
                }
                else if(v[nowv] == 1 || v[nowv] == 2) {
                    for(int j : memo) {
                        v[j] = -1;
                    }
                }
                break;
            }
            st.insert(nowv);
            memo.push_back(nowv);
            // cout << 1 << '\n';
            cnt++;
        }
        if(flag == false) {
            continue;
        }
        int leader = INF;
        for(int j : memo) {
            leader = min(leader,j);
            v[j] = 1;
        }
        v[leader] = 2;
    }
    int y = 0;
    for(int i = 0; i < n;++i) {
        if(v[i] == 2) {
            y++;
        }
    }
    long long ans = 1;
    for(int i = 0;i < y;++i) {
        ans *= 2;
        ans %= 998244353;
    }
    ans--;
    cout << ans % 998244353 << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
using ld = long double;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
void solve(){
  string s;
  cin >> s;
  int n = s.size();
  if(s > "atcoder"){
    cout << "0\n";
    return;
  }
  rep(i, n) if(s[i] != 'a'){
    if(s[i] > 't') cout << max(i - 1, 0) << "\n";
    else cout << i << "\n";
    return;
  }
  cout << "-1\n";
}
int main(){
  int t;
  cin >> t;
  rep(i, t) solve();
}

/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#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 __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s,t="atcoder";
int n;

int match(int x){
  if(x==0){
    int res = mod;
    for(int j=0;j<s.size();j++){
      if(s[j]>'a')return j;
    }
    return res;
  }
  int done[n+1]={0};
  int res = 0;
  for(int i=0;i<x;i++){
    int cnt = 0;
    bool f = false;
    for(int j=0;j<s.size();j++){
      if(done[j])continue;
      if(s[j]==t[i]){
        done[j]=1;
        res+=cnt;
        f = true;
        break;
      }
      cnt++;
    }
    if(!f)return mod;
  }
  if(x<t.size()){
    bool f = false;
    int cnt = 0;
    for(int j=0;j<s.size();j++){
      if(done[j])continue;
      if(t[x]<s[j]){
        res+=cnt;
        f = true;
        break;
      }
      cnt++;
    }
    if(!f)return mod;
  }
  else {
    if(s.size()>x)return res;
    else return mod;
  }
  return res;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

  int T;
  cin >> T;
  while(T--){
    cin >> s;
    n = s.size();
    int ans = mod;
    for(int i=0;i<=t.size();i++){
      ans = min(ans,match(i));
      // cerr << i << " "  << ans << endl;
    }
    if(ans>=mod){
      ans = -1;
    }
    cout << ans << endl;
  }

return 0;
}
///....


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

#define int         long long
#define ull         unsigned long long
#define ll          long long
#define M           998244353
#define pb          push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp          make_pair
#define lb          lower_bound
#define ub          upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b)  for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)     __builtin_popcountll(a)
#define hell        1000000007
#define re          resize
const int INF=1e18;
const int N=300005;

int powm(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1)
    res=(res*a)%M;
      a=(a*a)%M;
      b>>=1;
  }

  return res;
}

int pow(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1)
    res=(res*a);
      a=(a*a);
      b>>=1;
  }

  return res;
}

signed main(void)
{ios
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
    #endif

    int n,w;
    cin>>n>>w;
    vi a(2e5+5,0),b(2e5+5,0);
    rep(i,1,n+1)
    {
       int x,y,c;
       cin>>x>>y>>c;
       a[x]+=c;
       b[y]+=c;
    }

    int f=1;
    rep(i,0,2e5+5)
    {
      if(i>0)
       a[i]=a[i]+a[i-1];
    }

    rep(i,0,2e5+5)
    {
       if(i>0)
       b[i]=b[i]+b[i-1];
    }

    rep(i,0,2e5+5)
    {
      int k=a[i]-b[i];
      if(w<k) {f=0;break;}
    }

    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

using ll = long long;

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

  vector<ll> imos(2e5 + 10, 0);
  for (int i = 0; i <n; i++) {
    ll s, t, p;
    cin >> s >> t >> p;
    imos.at(s) += p;
    imos.at(t) -= p;
  }

  for (int i = 1; i < 2e5 + 10; i++) imos.at(i) += imos.at(i - 1);

  bool ok = true;
  for (int i = 0; i < 2e5 + 10; i++) {
    if (imos.at(i) > w) ok = false;
  }

  if (ok) cout << "Yes\n";
  else cout << "No\n";
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b){
	return a*b/gcd(a,b);
}
ll Solve(ll n){
	ll ans = 1;
	for (ll i=2;i<=n;++i){
		ans = lcm(i,ans);
	}return ans + (ll)1;
}
int main(){
	ll n;scanf("%lld",&n);
	printf("%lld\n",Solve(n));
}

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

int main() {
  string S, T;
  cin >> S;

  bool isReversed = false;

  for(int i=0; i<S.size(); i++) {
    if(S[i] == 'R') {
      isReversed = !isReversed;
    } else {
      if(!isReversed) {
        if(!T.empty() && T[T.size()-1] == S[i]) {
          T.erase(T.size()-1);
        } else {
          T += S[i];
        }
      } else {
        if(!T.empty() && T[0] == S[i]) {
          T.erase(0, 1);
        } else {
          T = S[i] + T;
        }
      }
    }
  }

  if(isReversed) reverse(T.begin(), T.end());
  cout << T << endl;
}


#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define DEBUG
#if defined DEBUG
    #define TRACE( format, ... )   printf( "%d\t" format, __LINE__, __VA_ARGS__ )
    #define TRACES( format, ... )   printf( "%d\t:" format, __LINE__)
#else
    #define TRACE( format, ... )
    #define TRACES( format, ... )
#endif
using namespace std;
using ll = long long;

const ll INF = 1e17;

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

    vector<vector<pair<int, ll>>> edges(2*N);
    for (int i=0; i<M; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        --A, --B;

        edges[A].emplace_back(B, C);
        edges[A].emplace_back(B+N, C);
        edges[A+N].emplace_back(B+N, C);
    }

    for (int i=0; i<N; ++i) {
        // printf("------%d %d\n", i, N);
        priority_queue<pair<ll, int>> pque;
        vector<ll> costs(2*N, INF);
        pque.emplace(0, i);
        int ans = -1;
        while (!pque.empty()) {
            int now;
            ll cost;
            tie(cost, now) = pque.top();
            pque.pop();
            cost *= -1;
            // printf("%lld %d\n", cost, now);

            if (now == i+N) {
                ans = cost;
                break;
            }

            if (cost >= costs[now]) continue;
            costs[now] =  cost;

            for (auto nxt: edges[now]) {
                ll next_cost = nxt.second + cost;
                if (costs[nxt.first] <= next_cost) continue;
                pque.emplace(-next_cost, nxt.first);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
using P = pair<int,int>;
using edge = struct { int to; int cost; };
const int INF = 1e9;

int n,m;
vector<int> a,b,c;
vector<vector<edge>> g;

void solve(int s) {
  vector<int> d(n+5, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    REP(i,g[v].size()) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }

  int ans = INF;
  REP(i,n) {
    if (d[i] == INF) continue;
    for(auto x: g[i]) {
      if (x.to == s) {
        ans = min(ans, d[i] + x.cost);
      }
    }
  }

  cout << (ans == INF ? -1 : ans) << endl;
  return;
}

int main() {
  cin >> n >> m;
  a.resize(m);
  b.resize(m);
  c.resize(m);
  g.resize(n);
  REP(i,m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    edge e = { b[i], c[i] };
    g[a[i]].emplace_back(e);
  }

  REP(i,n) solve(i);
  return 0;
}


#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <iomanip>
#include <algorithm>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

vector <vector <int>> dp, a;

int get(int i, int j)
{
	return abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1]) + max(0ll, a[j][2] - a[i][2]);
}

signed main()
{
	fast();
	int n;
	cin >> n;
	a.resize(n, vector <int>(3));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
			cin >> a[i][j];
	}

	dp.resize(1 << n, vector <int>(n, INF));
	for (int i = 1; i < n; ++i)
	{
		dp[1 << i][i] = get(0, i);
	}

	for (int mask = 0; mask < (1 << n); ++mask)
	{
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (i == j)
					continue;
				dp[mask | (1 << j)][j] = min(dp[mask | (1 << j)][j],
					dp[mask][i] + get(i, j));
			}
		}
	}

	cout << dp[(1 << n) - 1][0] << '\n';
	return 0;
}

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

int dp[1<<17][17];
int x[20],y[20],z[20];
int dis[18][18];

int n;

signed main(){
	scanf("%lld",&n);

	for(int i=1;i<=n;i++)
		scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);

	for(int i=1;i<=n;i++){
		dis[i][i]=0;
		for(int j=1;j<=n;j++){
			dis[i][j]=abs(x[j]-x[i])+abs(y[j]-y[i])+max(0LL,z[j]-z[i]);
		}
	}

	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}

	memset(dp,0x3f,sizeof(dp));

	dp[1][0]=0;

	for(int i=1;i<1<<n;i++){
		for(int j=0;j<n;j++){
			if(!(i>>j&1)){
				for(int k=0;k<n;k++){
					if(i>>k&1){
						dp[i|1<<j][j]=min(dp[i|1<<j][j],dp[i][k]+dis[k+1][j+1]);
					}
				}
			}
		}
	}

	int ans=0x3f3f3f3f;

	for(int i=0;i<n;i++){
		ans=min(ans,dp[(1<<n)-1][i]+dis[i+1][1]);
	}

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


#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll x,y,z,a=0,b=0,c=0,d=0,sum,ans,total,cnt,n,m,k,p,kase,i;
string s1,s2;
#define N 100001
#define MX 1000000001
vector <ll> v;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;

ll tow(ll a, ll b) {
	ll ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a;
	}
	return ans;
}
ll lcm(ll a, ll b) {
	return (a * b) / __gcd(a, b);
}

//SET PRECIOSION   cout << fixed ;  cout << setprecision(n) << ans << endl;

int main() {
	int r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	if (r1 == r2 && c1 == c2) {
		cout << 0;
	} else if ((r1 + c1 == r2 + c2) || (r1 - c1 == r2 - c2) || abs(r1 - r2) + abs(c1 - c2) <= 3) {
		cout << 1;
	} else if (abs(r1 - c1 - r2 + c2) <= 3 || abs(r1 + c1 - r2 - c2) <= 3 || (abs(r1 - r2) + abs(c1 - c2)) % 2 == 0 || abs(r1 - r2) + abs(c1 - c2) <= 6) {
		cout << 2;
	} else cout << 3;
	return 0;
}
// Happy Coding  (:

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

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

typedef pair<ll, ll>      pll;
typedef vector<pll>       vpll;
typedef vector<ll>        vl;

#define pb                push_back
#define mk                make_pair
#define mod               (int)1e9+7
#define inf               (ll)1e18
#define endl              "\n"
#define vs                vector<string>
#define ump               unordered_map
#define mp                map
#define pq_max            priority_queue<ll>
#define pq_min            priority_queue<ll,vi,greater<ll> >
#define ff                first
#define ss                second
#define mid(l, r)         (l+(r-l)/2)
#define loop(i, a, b)     for(int i = (a); i <= (b); i++)
#define looprev(i, a, b)  for(int i = (a); i >= (b); i--)
#define print(arr, a, b)  for(int i = (a); i <= (b); i++) cout << arr[i] << " ";
#define scan(arr, a, b)   for(int i = (a); i <= (b); i++) cin >> arr[i];

void file_i_o() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main ()
{
	file_i_o();

	vector<int> v(3);

	loop(i, 0, 2) {
		cin >> v[i];
	}

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

	if (v[0] + v[2] == 2 * v[1]) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

int32_t main() {
    boost; IO();

    int N,M; cin>>N>>M;
    vi bad(N,0);
    int K; cin>>K;
    FOR(i,0,K){
    	int x; cin>>x;
    	bad[x]=1;
    }
    int cnt=0;
    FOR(i,0,N){
    	if(bad[i]) cnt++;
    	else cnt=0;
    	if(cnt>=M){
    		cout << -1 << endl;
    		return 0;
    	}
    }

    ld cur_a=0,cur_b=0; //for the last M elements
    V<ld>a(N,0),b(N,0);
    ROF(i,0,N){
    	if(bad[i]){
    		a[i]=1;
    	}
    	else{
    		a[i]=cur_a/M;
    		b[i]=cur_b/M+1;
    	}
    	cur_a+=a[i];
    	cur_b+=b[i];
    	if(i+M<N){
    		cur_a-=a[i+M];
    		cur_b-=b[i+M];
    	}
    }

    cout << fixed << setprecision(7) << -b[0]/(a[0]-1) << endl;

    return 0;
}
//Change your approach

#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define lowbit(x) ((x) & -(x))

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

constexpr double eps = 1e-8;
constexpr int NINF = 0xc0c0c0c0;
constexpr int INF = 0x3f3f3f3f;
constexpr ll mod = 1e9 + 7;
constexpr ll N = 1e6 + 5;

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

    ll B, C;
    cin >> B >> C;
    if (B > 0) {
        ll L = B - C / 2;
        ll R = (C % 2 == 0 ? -(L + 1): -L);
        ll l = -B - (C - 1) / 2;
        ll r = C % 2 == 0 ? -l : -(l + 1);
        r = max(r, B);
        ll res = B - L + 1 + R - max(l, B + 1) + 1;
        if (L <= 0) {
            res = r - l + 1;
        } else {
            res = R - l + 1 + r - L + 1;
        }
        cout << res << '\n';
    } else {
        ll L = B - C / 2;
        ll R = (C % 2 == 0 ? -(L + 1): -L);
        ll l = max(-B - (C - 1) / 2, B + 1);
        ll res = B - L + 1 + R - l + 1;
        cout << res << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <locale>
#include <string>
#include <stdio.h>
#include <math.h>
using namespace std;

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

}

#include <bits/stdc++.h>
using namespace std;
#define __hh__ ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vd vector<double>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvs vector<vector<string>>
#define mii map<int,int>
#define msi map<string,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,s,n) for(int i=s; i<n ;i++)
#define repl(i,n) for(ll i=0; i<n; i++)
#define reprl(i,s,n) for(ll i=s; i<n ;i++)
const double PI=3.14159265358979323846;
const int INF=20e8;
const ll INFL=92e12;

int main() {
  __hh__

  vi v(3);
  rep (i, 3) cin >> v[i];
  sort(all(v));
  bool ans = false;
  if (v[1]-v[0]==v[2]-v[1]) ans = true;
  cout << (ans ? "Yes" : "No") << "\n";

}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, C;
    cin >> N >> C;
    V<ll> a(N), b(N), c(N);
    REP(i, N) cin >> a[i] >> b[i] >> c[i];

    V<pll> event;
    REP(i, N){
        event.emplace_back(a[i], c[i]);
        event.emplace_back(b[i]+1, -c[i]);
    }
    sort(ALL(event));

    ll pre = -1, res = 0, now = 0;
    for(auto [t, v]: event){
        res += min(C, now) * (t - pre);
        pre = t;
        now += v;
    }
    cout << res << endl;

    return 0;
}

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

ll N, C;
vector<pair<ll, ll>> imosu;

int main() {
  cin >> N >> C;

  imosu.push_back(make_pair(0, 0));

  ll a, b, c;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b >> c;
    imosu.push_back(make_pair(a, c));
    imosu.push_back(make_pair(b+1, -c));
  }

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

  ll answer = 0;
  for (int i = 1; i < imosu.size(); ++i) {
    answer += min(imosu[i-1].second, C) * (imosu[i].first - imosu[i-1].first);
    imosu[i].second += imosu[i-1].second;
  }

  cout << answer << endl;

  return 0;
}


#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define INF 9999999999999999
#define rep(i,m,n) for(ll i = m;i < n;i++)
#define rrep(i,m,n) for(ll i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define tint tuple<int, int, int>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 1000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, X, res = 0;
    cin >> N >> X;
    vector<vector<ll>> A(N);
    vector<map<ll, ll>> dp(N);
    dp[0][X] = 1;
    rep(i, 0, N) {
        ll a;
        cin >> a;
        A[0].emplace_back(a);
    }
    rep(i, 1, N) rep(j, 1, A[i - 1].size()) A[i].emplace_back(A[i - 1][j] / A[i - 1][1]);

    rep(i, 1, N) for(auto v : dp[i - 1]) {
        if(v.first == 1) continue;
        if(v.first % A[i - 1][1]) dp[i][v.first / A[i - 1][1] + 1] += v.second;
        dp[i][v.first / A[i - 1][1]] += v.second;
    }
    rep(i, 0, N) if(dp[i].count(1)) res += dp[i][1] * A[i].size();
    for(auto v : dp[N - 1]) if(v.first != 1) res += v.second;
    cout << res << endl;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define endl "\n"
#define pb push_back
#define sq(a) ((a)*(a))
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(a) (a).rbegin(),(a).rend()
#define x first
#define y second
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : "; for(auto x:v) cerr<<x<<' '; cerr<<endl;
#define output(x) cout<<(x ? "YES" : "NO")<<endl;
#define Output(x) cout<<(x ? "Yes" : "No")<<endl;
#define MOD (1000000007)
#define MOD2 (998244353)
#define PI acos(-1)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}

const int N = 1001;

ll a[N],b[N];
ll dp[N][N];

ll rec(int n,int m)
{
	if(!n || !m)
		return (n^m);

	if(dp[n][m] != -1)
		return dp[n][m];

	return dp[n][m] = min({rec(n-1,m-1) + (a[n]!=b[m]), rec(n-1,m) + 1, rec(n,m-1) + 1});
}

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

    int n,m;
    cin>>n>>m;

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

    for(int i=1;i<=m;i++)
    	cin>>b[i];

    for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
        dp[i][j]=-1;

    cout<<rec(n,m)<<endl;
    return 0;
}


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

using namespace std;

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

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

    vector<long long> w(m);
    for (int i = 0; i < m; i++) {
        cin >> w[i];
    }

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

    vector<long long> p(n / 2 + 1, 0);
    for (int i = 0; i < n - 1; i += 2) {
        p[i / 2 + 1] = h[i + 1] - h[i];
        p[i / 2 + 1] += p[i / 2];
    }

    vector<long long> q(n / 2 + 1, 0);
    for (int i = 0; i < n - 1; i += 2) {
        q[i / 2 + 1] = h[n - i - 1] - h[n - i - 2];
        q[i / 2 + 1] += q[i / 2];
    }

    vector<long long> res(m);
    for (int i = 0; i < m; i++) {
        int j = distance(h.begin(), lower_bound(h.begin(), h.end(), w[i]));
        res[i] = p[j / 2] + q[n / 2 - j / 2] + (j % 2 == 0 ? h[j] - w[i] : w[i] - h[j - 1]);
    }

    cout << *min_element(res.begin(), res.end()) << endl;
}

/*
   Three things which are very important --
   Violence - Speed - Momentum
*/
#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 oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define setbits(x)      __builtin_popcountll(x)
#define leadzero(x)     __builtin_clz(x)
#define trailzero(x)    __builtin_ctz(x)
#define bitsparity(x)   __builtin_parity(x)
#define mod             1000000007
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll              long long
//#define pre(y,x)        fixed<<setprecision(y)<<x
#define dbg1(x)         cerr << "|" << #x << ": " << (x) << "|\n";
#define dbg2(x,y)       cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|\n";
#define dbg3(x,y,z)     cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|" << #z << ": " << (z) << "|\n";
#define ff              first
#define ss              second
#define pb              push_back
#define eb              emplace_back
#define popb            pop_back
#define endl            '\n'
#define all(v)          v.begin(), v.end()
#define sz(x)           ((int)((x).size()))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
ll power(ll a, ll b) {
	if(b<0) return 1;
	ll res=1;
	while(b) {
		if(b&1)
			res = (res*a)%mod;
		a = (a*a)%mod;
		b >>= 1;
	}
	return res;
}
bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
const int inf = 1e9;
//integer to char always remember (char+'0')
const double pi = acos(-1);
const ll INF = 1e18;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int maxN = 2e5+9;

int main() {
	FIO;
	ll n, m;
	cin >> n >> m;
	vector<ll> h(n), w(m);
	for(int i=0; i<n; ++i) {
		cin >> h[i];
	}
	for(int i=0; i<m; ++i) {
		cin >> w[i];
	}
	sort(all(h));
	vector<ll> pre(n+1, 0), suf(n+1, 0);
	for(int i=0; i+1<n; i+=2) {
		pre[i] = (i==0?0:pre[i-1]) + abs(h[i+1]-h[i]);
		pre[i+1] = pre[i];
	}
	for(int i=n-1; i-1>=0; i-=2) {
		suf[i] = (i==n-1?0:suf[i+1]) + abs(h[i]-h[i-1]);
		suf[i-1] = suf[i];
	}
	ll ans=INF;
	for(ll i=0; i<m; ++i) {
		auto it = lower_bound(all(h), w[i]);

		if(it == h.begin()) {
			ans = min(ans, suf[1] + abs(h[0]-w[i]));

		}
		else if(it == h.end()) {
			ans = min(ans, pre[n-2] + abs(h[n-1]-w[i]));
		}
		else {
			ll j = it-h.begin();
			if(j%2==0) {
				ans = min(ans, pre[j-1] + abs(h[j]-w[i]) + suf[j+2]);
			}
			else {
				ans = min(ans, (j-2>=0?pre[j-2]:0) + abs(h[j-1]-w[i]) + suf[j+1]);
			}
		}

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
std::ostream& operator << (std::ostream& dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value<0?-value:value;
        char buffer[128];
        char* d = std::end(buffer);
        do {
            -- d;
            *d = "0123456789"[tmp%10];
            tmp/=10;
        }while(tmp!=0);
        if(value<0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer)-d;
        if (dest.rdbuf()->sputn(d,len)!=len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}
void solve() {
    ll i,j,k,l,m,n,o,p,q,r,t;
    string s;
    cin>>s;
    l=s.length();
    ll ops=0;
    ll f[26]={0};
    f[s[l-1]-'a']++;
    for(i=l-2;i>=0;i--) {
        f[s[i]-'a']++;
        if(s[i]==s[i+1]) {
            ops+=(l-i)-f[s[i]-'a'];
            for(j=0;j<26;j++) {
                f[j]=0;
            }
            f[s[i]-'a']=l-i;
        }
    }
    cout<<ops<<endl;
}
int main() {
    ll t=1;
    while(t--) {
       solve();
    }
    return 0;
}

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

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

    string s;
    cin>>s;
    cout<<s[1]<<s[2]<<s[0]<<endl;
     return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll invMod(ll num){
  return fast_expo(num, MOD - 2)%MOD;
}

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

  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n, cost; cin >> n >> cost;
    vector<pair<pair<ll, ll>, ll>> arr(n);
    vector<ll> c(n);

    for(ll i = 0; i < n; ++i){
      cin >> arr[i].ff.ff >> arr[i].ff.ss >> arr[i].ss;
    }

    sort(arr.begin(), arr.end());
    ll tot = 0, curr = 0, last = 0;
    set<pair<pair<ll, ll>, ll>> S;
    vector<pair<pair<ll, ll>, ll>> vect;
    for(ll i = 0; i < n; ++i){
      vect.clear();
      for(auto j: S){
        if(j.ff.ff < arr[i].ff.ff){
          tot += (j.ff.ff - last + 1)*(min(cost, curr));
          curr -= j.ff.ss;
          last = j.ff.ff + 1;
          vect.pb({j});
        } else break;
      }

      for(auto j: vect)
        S.erase(j);

      tot += (arr[i].ff.ff - last)*(min(cost, curr));

      last = arr[i].ff.ff;
      S.insert({{arr[i].ff.ss, arr[i].ss}, i});
      curr += arr[i].ss;
    }

    for(auto j: S){
      tot += (j.ff.ff - last + 1)*(min(cost, curr));
      curr -= j.ff.ss;
      last = j.ff.ff + 1;
    }

    cout << tot << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define gc() getchar()
#define pc(a) putchar(a)
#define int long long
inline int read()
{
	int x=0,f=1;
	char c=gc();
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-f;
		c=gc();
	}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
	return x*f;
}
int nnu[25];
inline void write(long long x)
{
	if(x==0)
	{
		pc('0');
		return;
	}
	if(x<0) pc('-'),x=-x;
	int tp=0;
	while(x) nnu[++tp]=x%10,x/=10;
	while(tp) pc(nnu[tp--]+'0');
	return;
}
#define ma 5000005
int L[ma],R[ma],c[ma];
unordered_map<int,int> mp;
int book[ma],cnt;
inline void ins(int x)
{
	if(!mp[x]) book[++cnt]=x,mp[x]=1;
	return;
}
inline bool cmp(int x,int y)
{
	return x<y;
}
inline int find(int x)
{
	int l=1,r=cnt;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(book[mid]>=x) r=mid;
		else l=mid+1;
	}
	return l;
}
int su[ma];
signed main()
{
	int n=read(),C=read();
	for(int i=1;i<=n;i++) L[i]=read(),R[i]=read(),c[i]=read(),ins(L[i]),ins(R[i]+1);
	sort(book+1,book+cnt+1,cmp);
//	for(int i=1;i<=n;i++) L[i]=find(L[i]),R[i]=find(R[i]);
	for(int i=1;i<=n;i++) su[find(L[i])]+=c[i],su[find(R[i]+1)]-=c[i];
	int ans=0;
	for(int i=1;i<=cnt;i++) su[i]+=su[i-1];
//	for(int i=1;i<=cnt;i++) if(su[i]>C) cout<<"okok\n";
//	for(int i=1;i<=cnt;i++) cout<<su[i]<<' ';
//	cout<<endl;
//	book[0]=
	for(int i=1;i<cnt;i++) ans+=min(su[i],C)*(book[i+1]-book[i]);
//	for(int i=1;i<=cnt;i++) cout<<book[i]<<' ';
//	cout<<endl;
	write(ans);
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

vector<int> primes({2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71});

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

  vector<ll> dp(1 << primes.size());
  ll a, b;
  cin >> a >> b;
  dp[0] = 1;
  for (; a <= b; a++) {
    auto dp2 = dp;
    int curMask = 0;
    for (int i = 0; i < primes.size(); i++) {
      if (a % primes[i] == 0) {
        curMask |= 1 << i;
      }
    }
    for (int mask = 0; mask < dp.size(); mask++) {
      if ((curMask & mask) == 0) {
        dp2[curMask | mask] += dp[mask];
      }
    }
    dp = dp2;
  }
  cout << accumulate(dp.begin(), dp.end(), 0LL);
  return 0;
}

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

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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a,  b) memset(a,  (b),  sizeof(a))
#define clr(a) memset(a,  0,  sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(),  v.end()

typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;

void base(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

ll primes[25] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
ll trans[1200020];
int bit[100];

void solve(){
	ll a,b;
	cin>>a>>b;
	for(ll i=a;i<=b;i++){
		for(ll j=0;j<20;j++){
			if (i%primes[j] == 0) bit[i-a] |= (1<<j);
		}
	}

	trans[0] = 1;

	for(ll i=a;i<=b;i++){
		for(ll j=(1<<20)-1; j>=0; j--){
			if ((bit[i-a] & j)!= bit[i-a])	continue;
			ll bt = j ^ bit[i-a];
			trans[j] += trans[bt];
		}
	}
	ll sum = 0;
	rep(i,0,(1<<20)) sum+=trans[i];
	cout<<sum<<"\n";
}

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


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

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

	long double x0,y0,r;
	cin>>x0>>y0>>r;

	//问题转换为，圆内的点，满足(x-X0)^2+(y-Y0)^2 <= R^2的解中，
	//			  整数解的个数
	//可以固定x，求解y的有效数值
	//x的范围：当y=y0时，[x0-r,x0+r];
	int xmin = ceil( x0-r );
	int xmax = floor( x0+r );
	r += 1e-14;
	//(y-y0)^2 <= R^2-(x-x0)^2
	ll ans = 0;
	for( long double x=xmin; x<=xmax; x+=1 )
	{
		long double tmp = sqrt(r*r-(x-x0)*(x-x0));
		long double ymin = ceil(y0-tmp);
		long double ymax = floor(y0+tmp);

		ans += ymax>=ymin ? (ymax-ymin)+1: 0;
	}
	cout << ans << endl;
	return 0;
}

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int to_int(string s){
    bool f=false;
    if(s[0]=='-'){
        f=true;
        s=s.substr(1);
    }
    int cnt=4;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            s=s.substr(0,i)+s.substr(i+1);
            cnt-=(n-1-i);
            break;
        }
    }
    int res=stoi(s);
    for(int i=0;i<cnt;i++){
        res*=10;
    }
    if(f)res*=-1;
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    ll x,y,r;
    cin >> s; x=to_int(s);
    cin >> s; y=to_int(s);
    cin >> s; r=to_int(s);
    ll res=0;
    constexpr int N=10000;
    auto uo=[](ll x)->ll{
        if(x<=0){
            x-=(N-1);
            x+=abs(x)%N;
            return x;
        }
        x-=abs(x)%N;
        return x;
    };
    auto uoo=[](ll x)->ll{
        if(x<=0){
            x+=abs(x)%N;
            return x;
        }
        x+=(N-1);
        x-=abs(x)%N;
        return x;
    };
    for(ll i=-r;i<=r;){
        if(abs(y+i)%N!=0){
            i++; continue;
        }
        ll L=0,R=2e9;
        while(R-L>1){
            ll mid=(L+R)/2;
            if(mid*mid+i*i<=r*r){
                L=mid;
            }
            else{
                R=mid;
            }
        }
        // cout << i << endl;
        ll X=uo(x+L),XX=uoo(x-L);
        if(X>=XX)res+=(X-XX)/N+1;
        i+=N;
    }
    cout << res << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define int               long long
#define MOD               1000000007
#define MAX               1000000000
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define pii               pair<int,int>
#define sp(x,y)           fixed<<setprecision(y)<<x
#define setbits(x)        __builtin_popcount(x)
#define fast_in_out       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//   powermod(a,b,m) ==  powermod(a,b%(m-1),m)  when m is prime fermat's theorem a^(p-1) %p=1 p is prime
int powermod(int a,int b,int c) //  gives (a^b)%c
{
    int ans = 1,tempans=a%c;
    while(b>0)
    {
        if(b&1==1)
        {
            ans=(ans*tempans)%c;
        }
             tempans=(tempans*tempans)%c;
             b=b>>1;
    }
    return ans;
}

int modinverse(int a,int m)   // gives a inverse wrt m and m is prime
{
    return powermod(a,m-2,m);
}
// my template                                              m
// prime factorization                                      pf
// ncr and factorials                                       ncr
// matrix exponentiation of fibonacci series in log(n)      matexpofib

void buildsegmenttree(int a[],int tree[],int start,int end,int treenode)
{
  if(start==end)
  {
    tree[treenode]=a[start];
    return;
  }
  int mid=(start+end)/2;
  buildsegmenttree(a,tree,start,mid,2*treenode);
  buildsegmenttree(a,tree,mid+1,end,2*treenode+1);

  tree[treenode]=tree[2*treenode]^tree[2*treenode+1];
}

void updatesegmenttree(int a[],int tree[],int start,int end,int treenode,int index,int value)
{
  if(start==end)
  {
    a[index]=value;
    tree[treenode]=value;
    return;

  }
   int mid=(start+end)/2;
   if(index>mid)
   {
    updatesegmenttree(a,tree,mid+1,end,2*treenode+1,index,value);
   }
   else
   {
    updatesegmenttree(a,tree,start,mid,2*treenode,index,value);
   }
   tree[treenode]=tree[2*treenode]^tree[2*treenode+1];

}
int query(int tree[],int start,int end,int treenode,int left,int right){
  //completely outside the given range

  if(start>right||end<left) {
    return 0;
  }

  //completely inside the given range

  if(start>=left&&end<=right){
    return tree[treenode];
  }

  //partially inside and partially outside

  int mid=(start+end)/2;
  int ans1=query(tree,start,mid,2*treenode,left,right);
  int ans2=query(tree,mid+1,end,2*treenode+1,left,right);
  return ans1^ans2;
}

int32_t main()
{
  fast_in_out;

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

    int tree[4*n]={0};
  buildsegmenttree(a,tree,0,n-1,1);
  while(q--)
  {
      int t,x,y;
      cin>>t>>x>>y;
      if(t==1)
      {
          updatesegmenttree(a,tree,0,n-1,1,x-1,a[x-1]^y);
      }
      else
      {
          int ans = query(tree,0,n-1,1,x-1,y-1);
          cout<<ans<<endl;
      }
  }

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937/*_64*/ rng(chrono::steady_clock::now().time_since_epoch().count());
#define printArr(arr, n) cerr << #arr << " = ["; for(int i=0; i<(n); i++){if (i) cerr << ", "; cerr << arr[i];} cerr << "]\n"
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,x;
	cin >> n >> x;
	ll a[n];
	for (int q = 0; q < n; q++) cin >> a[q];
	vector<map<ll,ll>> dp(n);
	dp[n-1][x%a[n-1]] = 1;
	dp[n-1][(x%a[n-1])-a[n-1]] = 1;
	for (int q = n-2; q >= 0; q--)
	{
		auto it = dp[q+1].begin();
		while (it != dp[q+1].end())
		{
			if (abs((it->first -(x%a[q]))/a[q]) < a[q+1]/a[q]) dp[q][x%a[q]]+=it->second;
			if (abs((it->first-(x%a[q])+a[q])/a[q]) < a[q+1]/a[q]) dp[q][(x%a[q])-a[q]]+=it->second;
			it++;
		}
	}
	cout << dp[0][0] << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
 ll a,b;
  cin>>a>>b;
  ll d=b-a;
  ll ans=1;
  rep2(i,1,d+1){
    if(a%i==0&&i*(a/i+1)<=b&&i>ans) ans=i;
 else if(a%i!=0&&a<=i*(a/i+1)&&i*(a/i+2)<=b&&i>ans) ans=i;
  }
  cout<<ans;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define __hh__ ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vd vector<double>
#define vb vector<bool>
#define vc vector<char>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvs vector<vector<string>>
#define vvc vector<vector<char>>
#define mii map<int,int>
#define msi map<string,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,s,n) for(int i=s; i<n ;i++)
#define repl(i,n) for(ll i=0; i<n; i++)
#define reprl(i,s,n) for(ll i=s; i<n ;i++)
#define print(x) cout << x << "\n"
const double PI=3.14159265358979323846;
const int INF=20e8;
const ll INFL=92e12;

int main() {
  __hh__

  int n, k;
  cin >> n >> k;
  int ans = 0;
  repr (i, 1, n+1) repr (j, 1, k+1) ans += i*100+j;
  cout << ans << "\n";

}


//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

int n,m;
vector<ii> v;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n>>m;

	int a,b;
	rep(x,0,m){
		cin>>a>>b;
		v.pub(ii(a,b));
	}

	sort(all(v),[](ii i,ii j){
		return i.fi>j.fi;
	});

	set<int> s={n};

	while (!v.empty()){
		set<int> remove;
		set<int> add;

		int curr=v.back().fi;
		while (!v.empty() && v.back().fi==curr){
			if (s.count(v.back().se-1) || s.count(v.back().se+1)) add.insert(v.back().se);
			else remove.insert(v.back().se);

			v.pob();
		}

		for (auto &it:remove) s.erase(it);
		for (auto &it:add) s.insert(it);

		//for (auto &it:s) cout<<it<<" "; cout<<endl;
	}

	cout<<sz(s)<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
#define vvpll vector<vpll>
typedef pair<string, string> pss;

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

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll inf = 1e18;
ll mod = 1e9 + 7;
ld eps = 1e-9;

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 pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("temp.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll  i, y, x, z, g, key,   h, a, b, c, j, q, n, d, k, l, r, m;
    ll t2, t3, t4, t1, t5, t6;
    string s, s2, s1;
    ll tc;
    //cin >> tc;
    tc = 1;
    while (tc--)
    {
        cin >> n >> m;
        pll arr[m];
        map<ll, set<ll>>ma;
        for (i = 0; i < m; i++)
        {
            cin >> arr[i].fi >> arr[i].se;
            ma[arr[i].fi].insert(arr[i].se);
        }
        ll cur = 0;
        set<ll>ans;
        ans.insert(n);

        for (auto u : ma)
        {
            auto st = u.se;
            set<ll>temp;
            for (auto v : st)
            {
                if (ans.find(v - 1) != ans.end())
                    temp.insert(v);
                if (ans.find(v + 1) != ans.end())
                    temp.insert(v);

            }
            for (auto v : st)
            {
                if (ans.find(v) != ans.end())
                {
                    ans.erase(v);
                }
            }
            for (auto v : temp)
                ans.insert(v);

        }
        t1 = ans.size();
        cout << t1;

    }

    return 0;
}