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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define sdi(x) scanf("%d",&x)
#define sdc(c) scanf("%c",&c)
#define inf 1000000000000000000ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second
#define all(x) x.begin(),x.end()

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

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

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const int MOD = 1e9+7;

inline ll add(ll x, ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = (x+y)%MOD;
    return ans;
}

inline ll mul(ll x,ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = ((x*y)%MOD+MOD)%MOD;
    return ans;
}

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

    int n = s.length();
    vector<int> v(n);

    for(int i=0;i<n;i++) {
        v[i] = s[i]-'a';
    }

    vector<int> cnt(27,0);
    ll res = 0;
    cnt[v.back()]++;
    for(int i=n-2;i>=0;i--) {
        if(v[i]==v[i+1]) {
            for(int j=0;j<26;j++) {
                if(v[i]!=j) {
                    res += cnt[j];
                    cnt[v[i]] += cnt[j];
                    cnt[j] = 0;
                }
            }
        }
        cnt[v[i]]++;
    }

    cout<<res<<endl;
    
    time_taken();
}

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

double score(PP a,PP b) {
  if(b.F.F<=a.F.F&&a.F.F<b.S.F&&b.F.S<=a.F.S&&a.F.S<b.S.S) {
    double x=a.S.F,y=(b.S.F-b.F.F)*(b.S.S-b.F.S);
    if(x>y) swap(x,y);
    double d=1.0-x/y;
    return 1.0-d*d;
  }
  return 0;
}

vector<PP> rotate(vector<PP> a,int k) {
  if(!k) {
    rep(i,a.size()) {
      swap(a[i].F.F,a[i].F.S);
      a[i].F.F=9999-a[i].F.F;
    }
  } else {
    rep(i,a.size()) {
      swap(a[i].F.F,a[i].F.S);
      a[i].F.F=10000-a[i].F.F;
      swap(a[i].S.F,a[i].S.S);
      a[i].S.F=10000-a[i].S.F;
      if(a[i].F.F>a[i].S.F) swap(a[i].F.F,a[i].S.F);
      if(a[i].F.S>a[i].S.S) swap(a[i].F.S,a[i].S.S);
    }
  }
  return a;
}

void Main() {
  srand((unsigned)time(NULL));
  ll n;
  R n;
  vector<PP> a(n);
  rep(i,n) {
    cin >> a[i].F.F >> a[i].F.S >> a[i].S.F;
    a[i].S.S=i;
  }
  vector<PP> ans2(n);
  double ansM=-1;
  clock_t t2=clock();
  double t5=0;
  rep(l,2) {
    vector<PP> ans(n);
    rep(i,n) ans[a[i].S.S]=PP(a[i].F,P(a[i].F.F+1,a[i].F.S+1));
    rep(i,n)swap(a[i].F.F,a[i].S.F);sort(all(a));rep(i,n)swap(a[i].F.F,a[i].S.F);
    if(!l) rotate(a.begin(),a.begin()+n/3,a.end());
    else reverse(all(a));
    ll cnt=0;
    while(1) {
      if(cnt>=4) {
        if(cnt/4%2) sort(all(a));
        else random_shuffle(all(a));
      }
      rep(i,n) {
        PP p=ans[a[i].S.S];
        double M=score(a[i],p),MM=abs(p.F.F-p.S.F)+abs(p.F.S-p.S.S);
        ll e=0;
        rrep(y,a[i].F.S+1) {
          rep(j,n) {
            if(i==j) continue;
            ll yy=a[j].S.S;
            if(ans[yy].F.S<=y&&y<ans[yy].S.S&&ans[yy].S.F<=a[i].F.F) e=max(e,ans[yy].S.F);
          }
          ll z=abs(ans[a[i].S.S].S.S-y);
          ll x=max(e,ans[a[i].S.S].S.F-(a[i].S.F+z-1)/z);
          PP q=PP(P(x,y),ans[a[i].S.S].S);
          ll mm=max(0LL,min(q.F.F-e,q.S.F-1-a[i].F.F));
          q.F.F-=mm,q.S.F-=mm;
          rep(j,n) {
            if(i==j) continue;
            ll yy=a[j].S.S;
            if(ans[yy].S.F<=q.F.F||q.S.F<=ans[yy].F.F||ans[yy].S.S<=q.F.S||q.S.S<=ans[yy].F.S) continue;
            goto next;
          }
          double d=score(a[i],q);
          double dd=abs(q.F.F-q.S.F)+abs(q.F.S-q.S.S);
          if(M<d+0.000001) {
            M=d;
            MM=dd;
            p=q;
          } else if(M<=d&&MM>=dd) {
            M=d;
            MM=dd;
            p=q;
          }
        }
      next:;
        ans[a[i].S.S]=p;
      }
      a=rotate(a,0);
      ans=rotate(ans,1);
      cnt++;
      clock_t t3=clock();
      double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
      t5=max(t5,t4);
      if((double)t3/CLOCKS_PER_SEC+t5>2.48*(l+1)) break;
      t2=t3;
    }
    while(cnt%4) {
      a=rotate(a,0);
      ans=rotate(ans,1);
      cnt++;
    }
    double sum=0;
    rep(i,n) sum+=score(a[i],ans[a[i].S.S]);
    if(ansM<sum) {
      ansM=sum;
      ans2=ans;
    }
  }
  rep(i,n) pr(ans2[i].F.F,ans2[i].F.S,ans2[i].S.F,ans2[i].S.S);
}

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