akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int naive(vector<int> a){
    int n = (int) a.size();
    while(n >= 2){
        vector<int>b(n-1);
        rep(i,n-1)b[i] = abs(a[i]-a[i+1]);
        a = b;
        n--;
    }
    return a[0];
}
int cal(vector<int>a){
    int n = (int) a.size();
    vector<int>b(n-1);
    rep(i,n - 1){
        b[i] = abs(a[i] - a[i+1]);
    }
    if(n == 2)return b[0];
    {
        int c = 0;
        for(int i = 0; i < n - 1; i++){
            int f = ((n-2)&i) == i ? 1 : 0;
            if(f)c += b[i];
        }
        
        c%=2;
        if(c == 1)return 1;
    }
    rep(i,n-1)if(b[i]==1)return 0;
    {
        rep(i,n-1)b[i]/=2;
        int c = 0;
        for(int i = 0; i < n - 1; i++){
            int f = ((n-2)&i) == i ? 1 : 0;
            if(f)c += b[i];
        }
        
        c%=2;
        if(c == 1)return 2;
    }
    return 0;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;cin >> s;
    vector<int>a(n);
    rep(i,n)a[i] = s[i]-'0';
//    show(naive(a));
    cout << cal(a) << endl;
//    {
//        n = 3;
//        vector<int>b(8);
//        rep(i,n)rep(j,n)rep(k,n)rep(l,n)rep(m,n)rep(o,n)rep(p,n)rep(q,n){
//            b[0] = i + 1;
//            b[1] = j + 1;
//            b[2] = k + 1;
//            b[3] = l + 1;
//            b[4] = m + 1;
//            b[5] = o + 1;
//            b[6] = p + 1;
//            b[7] = q + 1;
//            assert(naive(b) == cal(b));
//        }
//    }
}


Measured memory_bytes: 13084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main(){
    int a,b;
    cin >> a >> b;
    string sa,sb;
    for(int i = 0;i < b;i++) sa += to_string(a);
    for(int i = 0;i < a;i++) sb += to_string(b);
    if(sa <= sb) cout << sa << endl;
    else cout << sb << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
using namespace std;

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 ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

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

  int N; cin >>N;
  ll X; cin >>X;
  vll x(N);
  rep(i,0,N) {
    cin >>x[i];
    x[i]-=X;
  }

  ll g=abs(x[0]);
  rep(i,0,N) {
    g=gcd(g,abs(x[i]));
  }

  cout <<g <<'\n';
  return 0;
}


Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const ll INF = 1e18;
const int MOD = 1000000007;

struct dijkstra{
    struct edge {
        int to; long long cost;
        edge(int a, long long b) { to = a; cost = b; }
    };
    
    int V;
    vector<vector<edge>> G;
    vector<long long> d;
 
    dijkstra(int v) {
        V = v;
        G = vector<vector<edge>>(V);
        d = vector<long long>(V);
    }

    void addEdge(int from, int to, long long cost) {
        G[from].emplace_back(edge(to, cost));
    }

    vector<long long>& shortest_path(int s) {
        priority_queue<
            pair<long long, int>,
            vector<pair<long long, int>>,
            greater<pair<long long, int>>
        > que;
        for (long long& i : d) i = INF;
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            auto p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (const edge& e : G[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
        return d;
    }
};

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

    vector<int> U(M), V(M), A(M), B(M);
    rep(i, M) {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        U[i]--, V[i]--;
    }

    vector<int> C(N), D(N);
    rep(i, N) cin >> C[i] >> D[i];

    vector<vector<int>> node(N, vector<int>(2501));
    int n = 0;
    rep(i, N)rep(j, 2501) node[i][j] = n, n++;

    dijkstra d(n);
    rep(i, N)rep(j, 2501) {
        if (j+C[i] < 2501) d.addEdge(node[i][j], node[i][j+C[i]], D[i]);
    }

    rep(i, M)rep(j, 2501) {
        if (j < A[i]) continue;
        d.addEdge(node[ V[i] ][j], node[ U[i] ][j-A[i]], B[i]);
        d.addEdge(node[ U[i] ][j], node[ V[i] ][j-A[i]], B[i]);
    }

    auto &dist = d.shortest_path(node[0][min(2500, S)]);
    vector<ll> ans(N, INF);
    ans[0] = 0;
    rep(i, N)rep(j, 2501) {
        chmin(ans[i], dist[ node[i][j] ]);
    }

    for (int i = 1; i < N; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 24656
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func getFloat() float64 {
	sc.Scan()
	n, _ := strconv.ParseFloat(sc.Text(), 64)
	return n
}

func sum(n []int) int {
	a := 0
	for _, v := range n {
		a += v
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	n := getInt()

	p := make([]int, n)
	for i := range p {
		p[i] = getInt()
	}
	sort.Ints(p)

	ans := sum(p) - (p[len(p)-1] / 2)
	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String O = sc.next();
        String E = sc.next();
        int O_num = O.length();
        int E_num = E.length();
        int remainder = 0;
        remainder = O_num - E_num;
        String sum = "";
        for(int i = 0; i < O.length();i++){
            sum = sum + O.charAt(i);
            if(remainder == 1 && i == O_num -1){
                continue;
            }
            sum = sum + E.charAt(i);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, sum, ans;
int a[5000], b[5000];
void solve(){
	int i2;
	for (int i = 0; i < m; i++){
		sum = 0;
		i2 = i;
		for (int j = 0; j < n; j++){
			if (b[i] == a[j]){
				i++;
				sum++;
			}
		}
		ans = max(ans, sum);
		i = i2;
	}
}
int main(){
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	solve();
	cout << ans << endl;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int h,w;
    while(cin >>h >>w,h){
        vector<vector<int>> e(h,vector<int>(w));
        rep(i,h)rep(j,w) cin >>e[i][j];

        int ans = 0;
        rep(li,h)rep(lj,w)for(int ri=li+2; ri<h; ++ri)for(int rj=lj+2; rj<w; ++rj){

            int out = 9, in = 0;
            for(int y=li; y<=ri; ++y)for(int x=lj; x<=rj; ++x){
                if(y==li || y==ri || x==lj || x==rj){
                    out = min(out, e[y][x]);
                }
                else{
                    in = max(in, e[y][x]);
                }
            }

            if(out<=in) continue;
            int tmp = 0;
            for(int y=li+1; y<ri; ++y)for(int x=lj+1; x<rj; ++x) tmp += out - e[y][x];
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include<climits>
#include<random>
#include<cassert>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<utility>
#include<cstdint>
#include<queue>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdio>
//4611686018427387903
using namespace std;
//magic lines for ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
/*
	fuctions :

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).


*/
const int64_t mod = 998244353.;
void solve(int cnum){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    int mx = 0;
    int64_t ans = 0;
    for(int i = 0; i < n; ++i){
        if(arr[i] < mx){
            ans+=(mx-arr[i]);
        }
        else{
            mx = arr[i];
        }
    }
    cout << ans <<"\n";
}
int main(){

	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);
	//initprime();
	cout << setprecision(12);
	cout << fixed;
	int t;
	int count = 1;
	for(  t = 1;t--; solve(count),count++);
	return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<s.size();i++){
        if(i%2 and s[i]!='1'){
            a++;
        }
        if(i%2==0 and s[i]!='0'){
            a++;
        }
        if(i%2 and s[i]!='0'){
            b++;
        }
        if(i%2==0 and s[i]!='1'){
            b++;
        }
    }
    cout<<min(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 512
//div game
#include <stdio.h>
#include <math.h>

int main(void){
    unsigned long int n;

    scanf("%lu",&n);

    unsigned int i=2;
    unsigned long int cnt = 0;

    if(n%i==0) {
        unsigned long int div = i;
        for(unsigned int j = 1;n%(int)pow(div,j)==0;j++){
            n/= pow(div,j);
            cnt ++;
        }
        while(n%div == 0) n/=div;
    }

    for(i = 3;i<sqrt(n);i+=2){
        if(n%i==0) {
            unsigned long int div = i;
            for(unsigned int j = 1;n%(int)pow(div,j)==0;j++){
                n/= pow(div,j);
                cnt ++;
            }
            while(n%div == 0) n/=div;
        }
    }
    if(n>sqrt(n)) cnt ++;
    printf("%lu",cnt);

    return 0;
}


Measured memory_bytes: 2512
#include<bits/stdc++.h>

char v[200005];

int main(){
    scanf("%s",v);
    char lst='D';
	int nA=0;
	long long  ans=0;
	for(int i=0;v[i]!='\0';i++){
		switch (v[i])
		{
		case 'A':if(lst=='B')nA=1;
			else nA++;
			break;
		case 'B':
			if(lst=='B')nA=0;
			break;
		case 'C':
			if(lst=='B')ans+=nA;
			else nA=0;
			break;

		}
		lst=v[i];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct LazySeg {
  using T = ll;
  static T op(const T& a, const T& b) { return max(a, b); }
  static constexpr T e() { return -1e14; }
  using U = ll;
  static void ap(const U& f, T& a) { a += f; }
  static void cp(const U& g, U& f) { f += g; }
  static constexpr U id() { return 0LL; }
 
  const int n;
  vector<T> t;
  vector<U> u;
  LazySeg(int _n) : n(_n), t(2 * n, e()), u(n, id()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  void push() { for (int i = 1; i < n; ++i) push(i); }
  void apply(const U& f, int i) {
    ap(f, t[i]);
    if (i < n) cp(f, u[i]);
  }
  void push(int i) {
    if (u[i] == id()) return;
    apply(u[i], 2 * i);
    apply(u[i], 2 * i + 1);
    u[i] = id();
  }
  void push(int l, int r) {
    for (int hl = __lg(l + n), hr = __lg(r - 1 + n); hr > 0; --hl, --hr) {
      int al = (l + n) >> hl, ar = (r - 1 + n) >> hr;
      if (al < n) push(al);
      if (ar != al) push(ar);
    }
  }
  T query(int l, int r) {
    r++;
    push(l, r);
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  T get(int i) { return query(i, i); }
  void update(int l, int r, const U& f) {
    r++;
    push(l, r);
    for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) {
      if (i & 1) apply(f, i++);
      if (j & 1) apply(f, --j);
    }
    l = (l + n) >> __builtin_ctz(l + n);
    while (l >>= 1) t[l] = op(t[2 * l], t[2 * l + 1]);
    r = (r + n) >> __builtin_ctz(r + n);
    while (r >>= 1) t[r] = op(t[2 * r], t[2 * r + 1]);
  }
  void set(int i, const T& a) {
    push(i, i + 1);
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

constexpr int MAXN = 200005;

int n, m;
vector<pair<int, ll>> byStart[MAXN];
vector<pair<int, ll>> byEnd[MAXN];
LazySeg st(MAXN);

void print() {
  for (int i = 0; i < n; i++) {
    cout << st.get(i) << " ";
  }
  cout << "\n";
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r; ll a; cin >> l >> r >> a;
    byStart[l].emplace_back(r, a);
    byEnd[r].emplace_back(l, a);
  }

  for (int i = 0; i <= n; i++) {
    st.set(i, 0);
  }
  st.build();
  
  // take nothing
  ll res = 0;

  for (int i = 1; i <= n; i++) {
    // activate every interval that starts at i
    for (auto& pr : byStart[i]) {
      ll a = pr.second;
      st.update(0, i - 1, a);
    }

    // represents maximum score of prefix of length i if s[i] == '1'
    ll cur = st.query(0, i - 1);
    res = max(res, cur);
    st.update(i, i, cur);

    // deactivate every interval that ends at i
    for (auto& pr : byEnd[i]) {
      int l = pr.first;
      ll a = pr.second;
      st.update(0, l - 1, -a);
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 26752
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
safe = lambda boolean: print('safe') if boolean else print('unsafe')
YES = lambda boolean: print('YES') if boolean else print('NO')
aint = lambda: int(input())
ints = lambda: list(map(int, input().split()))
is_even = lambda x: True if x%2==0 else False

s,w = ints()
safe(s>w)

Measured memory_bytes: 9464
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  set<int> s[26];
  REP(i,N){
    s[S[i]-'a'].insert(i);
  }
  int Q;
  cin>>Q;
  REP(q,Q){
    // cerr<<S<<endl;
    // REP(i,4){
    //   cerr<<(char)(i+'a')<<':';
    //   for(auto e:s[i])cerr<<e<<" ";
    //   cerr<<endl;
    // }
    int t;
    cin>>t;
    if(t==1){
      int i;
      char c;
      cin>>i>>c;
      i--;
      s[S[i]-'a'].erase(i);
      s[c-'a'].insert(i);
      S[i]=c;
    }else{
      int l,r;
      cin>>l>>r;
      l--;r--;
      int ans=0;
      REP(i,26){
        if(s[i].lower_bound(l) != s[i].upper_bound(r))ans++;
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 24196
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n);i++)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
	string S;
	cin >> S;
	bool odd=true;
	bool even=true;
	for (int i = 1; i < S.length()-1; i += 2)
	{

		if (S[i] == 'L' || S[i] == 'U' || S[i] == 'D') {
			even &= true;
		}
		else {
			even &= false;
		}
	}
	
	for (int i = 0; i < S.length(); i+=2)
	{
		
		if (S[i] == 'R' || S[i] == 'U' || S[i] == 'D') {
			odd &= true;
		}
		else {
			odd &= false;
		}
	}
	if (odd && even == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> W(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
		sum += W[i];
	}

	int ans = 200;
	int now = 0;
	for (int i = 0; i < N; i++) {
		now += W[i];
		int d = now - (sum - now);
		ans = min(ans, max(-1 * d, d));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T = 1,n,m,k;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> n >> k;
    ll a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a, a+n);
    ll d =0;
    for(int i=0;i<k;i++){
        d+=a[i];
    }
    cout << d << "\n";

    return 0;
}


Measured memory_bytes: 3680
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

void solve() {
   int n, k;
   cin >> n >> k;
   vector <double> v(n);
   for(int i = 0; i < n; i++) {
      cin >> v[i];
      v[i] += 1;
      v[i] /= 2.0;
   }
   double sum = 0;
   for(int i = 0; i < k; i++) {
      sum += v[i];
   }
   double maxSum = sum;

   for(int i = k; i < n; i++) {
      sum = sum - v[i - k] + v[i];
      maxSum = max(maxSum, sum);
   }
   cout << fixed << setprecision(10) << maxSum << endl;

}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



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

  int slen = s.length();
  stack<char> cstack;

  FOR(i,0,slen-1){
    // cout << cstack.size() << endl;
    if(cstack.empty()==1) cstack.push(s[i]);
    else{
      if(cstack.top()=='S' && s[i]=='T') cstack.pop();
      else cstack.push(s[i]);
    }
  }

  cout << cstack.size() << endl;

}



Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int ans = 0;
  
  for(int i = 0;i+2<n;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')ans++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def hit(n, m, goal, d, dans)
  h = 0
  until h == d
    yoko = dans[h]
    if m != n - 1 and yoko[m] == 1
      m += 1
    elsif m.nonzero? and yoko[m - 1] == 1
      m -= 1
    end
    h += 1
  end
  goal == m
end

until (n = $<.gets.to_i).zero?
  m    = $<.gets.to_i - 1
  goal = $<.gets.to_i - 1
  d    = $<.gets.to_i
  dans = Array.new(d) { $<.gets.chomp.chars.map(&:to_i) }
  
  if hit(n, m, goal, d, dans)
    puts 0
  else
    try = ->{
      d.times do |h|
        (n - 1).times do |x|
          f = [-1, 0, 1].map do |dx|
            a = dans[h][x + dx]
            a ? a.zero? : nil
          end.compact.all?
          if f
            dans[h][x] = 1
            return "#{h + 1} #{x + 1}" if hit(n, m, goal, d, dans)
            dans[h][x] = 0
          end
        end
      end
      1
    }
    puts try.()
  end
end



Measured memory_bytes: 6864
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int A;
  cin>>A;
  int X=0,Y=0;
  if(A/100>=1&&A/100<=12) X=1;
  if(A%100>=1&&A%100<=12) Y=1;
  if(X&&Y) cout<<"AMBIGUOUS"<<endl;
  else if(X) cout<<"MMYY"<<endl;
  else if(Y) cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{

int n,cards[4][14],num,i,j;
char mark;


//cards?????????
  for ( i = 0; i < 4; i++)
  {
    for ( j = 1; j <= 13; j++)
    {
      cards[i][j] = 0;
    }
  }


//?????£??????????????°
  scanf("%d", &n);


//?????£???????????????????????\???
  for ( i = 0; i < n; i++)
  {

    getchar();
    scanf("%c %d", &mark, &num);

    if (mark == 'S')
    {
      cards[0][num] = 1;
    }
    else if (mark == 'H')
    {
      cards[1][num] = 1;
    }
    else if (mark == 'C')
    {
      cards[2][num] = 1;
    }
    else
    {
      cards[3][num] = 1;
    }
  }


//?????£??????????????????????????????
  for ( i = 0; i < 4; i++)
  {
    for ( j = 1; j <= 13; j++)
    {
      if (cards[i][j] != 1 && i == 0) {
        printf("S %d\n", j);
      }
      else if (cards[i][j] != 1 && i == 1)
      {
        printf("H %d\n", j);
      }
      else if (cards[i][j] != 1 && i == 2)
      {
        printf("C %d\n", j);
      }
      else if (cards[i][j] != 1 && i == 3)
      {
        printf("D %d\n", j);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a[1010], b[1010];
int main() {
	int n, m;
	cin >> n;
	rep(i, n)cin >> a[i];
	cin >> m;
	rep(i, m)cin >> b[i];
	rep(i, min(n, m)) {
		if (a[i] > b[i]) {
			puts("0");
			return 0;
		}
		if (a[i] < b[i]) {
			puts("1");
			return 0;
		}
	}
	if (n < m)puts("1");
	else puts("0");
	return 0;
}


Measured memory_bytes: 3080
s  = input()
n  = int(input())

s_mae = ''
s_ato = s

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s_mae, s_ato = s_ato, s_mae
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_head:
            s_mae += s_
        else:
            s_ato += s_

print(s_mae[::-1] + s_ato)


Measured memory_bytes: 4596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var N = inputArray[0];

			var S = retreiveStringArray()[0];

			var count = 0;
			for (int i = 0; i < N-2; i++) {
				var str = string.Join("",S.Skip(i).Take(3));
				if (str == "ABC") {
					count++;
				}
			}

			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    in >> n;
    if(n==1){
        ll a;
        in >> a;
        out << a << endl;
    }else{
        vector<ll> even(ceil(n/2.0));
        vector<ll> odd(int(n/2));
        REP(i, n){
            if(i % 2 == 0){
                in >> even[int(i/2)];
            }else{
                in >> odd[int(i/2)];
            }
        }
        if(n % 2 == 1){
            REVERSE(even);
            REP(i, even.size()){
                out << even[i] << " ";
            }
            REP(i, odd.size()){
                if(i < odd.size()-1){
                    out << odd[i] << " ";
                }else{
                    out << odd[i] << endl;
                }
            }
        }else{
            REVERSE(odd);
            REP(i, odd.size()){
                out << odd[i] << " ";
            }
            REP(i, even.size()){
                if(i < even.size()-1){
                    out << even[i] << " ";
                }else{
                    out << even[i] << endl;
                }
            }
        }
    }
}


Measured memory_bytes: 3712
using System;
using System.Linq;

namespace AtCoder20200328_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Coffee();
        }

        public static void Coffee()
        {
            char[] inputs = new char[6];
            inputs = Console.ReadLine().Select(c => c).ToArray();
            if(inputs[2] == inputs[3] && inputs[4] == inputs[5])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 13396
#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>;

const int MAX = 2000003;
const int INF = 1 << 30;
int heap[MAX];
int h = 0;

int parent(int i) {
  return i / 2;
}
int left(int i) {
  return 2 * i;
}
int right(int i) {
  return 2*i + 1;
}

void maxHeapify(int i) {
  int l = left(i);
  int r = right(i);
  int largest;
  if (l <= h && heap[l] > heap[i]) largest = l;
  else largest = i;
  if (r <= h && heap[r] > heap[largest]) largest = r;

  if (largest != i) {
    swap(heap[i], heap[largest]);
    maxHeapify(largest);
  }
}

int heapExtractMax() {
  if (h < 1) cerr << "[ERROR] heap underflow: " << h << endl;
  int max = heap[1];
  heap[1] = heap[h];
  h--;
  maxHeapify(1);

  return max;
}

void heapIncreaseKey(int i, int key) {
  if (key < heap[i]) cerr << "[ERROR] " << key << ", " << heap[i] << endl;
  heap[i] = key;
  while (i > 1 && heap[parent(i)] < heap[i]) {
    swap(heap[i], heap[parent(i)]);
    i = parent(i);
  }
}

void insert(int key) {
  h++;
  heap[h] = -INF;
  heapIncreaseKey(h, key);
}


int main() {
  string s = "";
  vector<int> ans;
  while (s != "end") {
    cin >> s;
    if (s == "insert") {
      int x;
      cin >> x;
      insert(x);
    } else if (s == "extract") {
      int x = heapExtractMax();
      ans.push_back(x);
    }
  }

  rep(i,ans.size()) cout << ans[i] << endl;
  
  return 0;
}



Measured memory_bytes: 8812
use std::io;

fn main() {
	let mut flag = true;
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let n = match buf.trim().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	for n in 0..n {
		let a: i32 = match iter.next().unwrap().parse() {
			Ok(n) => n,
			Err(_) => panic!(""),
		};
		if a%2 == 0 {
			if a%3 !=0 && a%5 != 0 {
				println!("DENIED");
				flag = false;
				break;
			}else{
				//
			}
		}
	}
	if flag {
		println!("APPROVED");
	}
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main { 
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int a = sc.nextInt();
	  int b = sc.nextInt();
	  int c = 2*(a+b);
 System.out.printf("%d %d\n",a*b,c);

  }
}


Measured memory_bytes: 26200
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	A := ScanInt(scanner)
	B := ScanInt(scanner)
	C := ScanInt(scanner)
	
	flg := false
	for i := 0; i < B; i++ {
	    if A * (i + 1) % B == C {
	        fmt.Println("YES")
	        flg = true
	        break
	    }
	}
	if !flg {
	    fmt.Println("NO")
	}
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func Max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}
 

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include<string>
using namespace std;

int main (){
string str[3];
int i;

for(i=0; i<3; i++){
   cin >> str[i];
    }  
    
cout << str[0] [0]<< str[1][1] << str[2][2] << endl;
return 0;
}

Measured memory_bytes: 256
n = int(input())
t,a = map(int, input().split())
l = list(map(int, input().split()))
al = [0]*n

for i in range(n):
  temp = t
  temp = temp - 0.006 * l[i]
  al[i] = abs(temp - a)

print(al.index(min(al))+1)

Measured memory_bytes: 3060
import java.util.*;

public class Main{
  public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    if(x < 14){
      System.out.println(x * 800);
    }else{
      int y = x / 15;
      y *= 200;
      x *= 800;
      System.out.println(x - y);
    }
  }
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;

int main()
{
  char c11, c12, c13, c21, c22, c23;
  cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23;
  if (c11 == c23 && c12 == c22 && c13 == c21) {
    cout << "YES" << endl;
    return 0;
  } else {
    cout << "NO" << endl;
    return 0;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int a, b;
	char c;
	cin >> a >> c >> b;
	if (c == '+') {
		cout << a + b << endl;
	}
	else {
		cout << a - b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int,int> cor_t;

int board[5][10];

int main(){
    int H;
    while(scanf("%d",&H)&&H!=0){
        for(int j=H-1;j>=0;j--)
            for(int i=0;i<5;i++) {
                int temp;
                scanf("%d",&temp);
                board[i][j]=temp;
            }

        int score=0;
        bool has_puzzles=false;
        do{
            has_puzzles=false;
            for(int row=0;row<H;row++){
                for(int i=0;i<=2;i++){
                    if (board[i][row]==0) continue;

                    int len=1;
                    for(int j=i+1;j<5&&board[j][row]==board[i][row];j++) len++;

                    if (len>=3){
                        for(int k=i;k<i+len;k++) {
                            score+=board[k][row] ;
                            board[k][row]=0;
                        }
                        has_puzzles=true;
                        break;
                    }
                }
            }

            for(int i=0;i<5;i++)
                for(int row=H-1;row>0;row--)
                    for(int j=0;j<row;j++)
                        if (board[i][j]==0) swap(board[i][j],board[i][j+1]);


            // puts("demo");
            // for(int i=H-1;i>=0;i--){
            //     for(int j=0;j<5;j++){
            //         printf("%d ",board[j][i]);
            //     }
            //     putchar('\n');
            // }
                    
        }while(has_puzzles);

        printf("%d\n",score);

    }

    return 0;
}


Measured memory_bytes: 2600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,k;
    cin >> n >> m;
    if(n%2){
        k=(n/2)+1;
    }else{
        k=n/2;
    }
    if(k>=m){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int x[4],y[4];
    for(int i = 0; i<4; i++){
        cin >> x[i] >> y[i] ;
    }
    for(int i = 0; i<4; i++){
        (x[i]==1)? cout<< 6000*y[i] << endl:
        (x[i]==2)? cout<< 4000*y[i] << endl:
        (x[i]==3)? cout<< 3000*y[i] << endl:
                cout<< 2000*y[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
using namespace std;
int main(int argc, char const *argv[]) {
    double W,H,x,y;
    std::cin >> W>>H>>x>>y;
    double ans=(double) W*H/2;
    std::cout << ans << '\n';
    if(W/2==x&&H/2==y)std::cout << 1 << '\n';
    else std::cout << 0 << '\n';

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

#define MOD ((ll)1e+9 + 7)



//cout<<fixed<<setprecision(10);
int main(){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }



    return 0;
}



Measured memory_bytes: 3540
from collections import deque


def bfs(maze, visited, sh, sw, gh, gw, H, W):
    queue = deque([(sh, sw)])
    visited[sh][sw] = 1

    while queue:
        h, w = queue.popleft()
        if (h, w) == (gh, gw):
            return visited[h][w]

        for i, j in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            nh = h + i
            nw = w + j
            if 0 <= nh < H and 0 <= nw < W:
                if maze[nh][nw] == "." and visited[nh][nw] == -1:
                    visited[nh][nw] = visited[h][w] + 1
                    queue.append((nh, nw))

    return -1


def main():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]

    cnt = 0
    for i in range(H):
        for j in range(W):
            if s[i][j] == ".":
                cnt += 1

    visited = [[-1] * W for _ in range(H)]

    ans = bfs(s, visited, 0, 0, H - 1, W - 1, H, W)
    if ans == -1:
        print(ans)
    else:
        print(cnt - ans)


main()


Measured memory_bytes: 3316
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        sc.nextLine();

        Mydeque A = new Mydeque(N);

        for(int i=0;i<N;i++){
            int order = sc.nextInt();
            int d;
            switch (order){
                case 0:
                    d = sc.nextInt();
                    int x = sc.nextInt();
                    if(d == 0)A.addFirst(x);
                    if(d == 1)A.addLast(x);
                    break;
                case 1:
                    int p = sc.nextInt();
                    System.out.println(A.getData(p));
                    break;
                case 2:
                    d = sc.nextInt();
                    if(d == 0)A.removeFirst();
                    if(d == 1)A.removeLast();
                    break;
            }
            sc.nextLine();
        }
        sc.close();
    }
}
class Mydeque{
    int data[];
    int headindex; //head factor is null
    int lastindex; //last factor is null
    Mydeque(int N){
        data = new int[N*4];
        headindex = data.length / 2;
        lastindex = headindex + 1;
    }
    void addFirst(int x){
        data[headindex--] = x;
    }
    void addLast(int x){
        data[lastindex++] = x;
    }
    void removeFirst(){
        data[++headindex] = 0;
    }
    void removeLast(){
        data[--lastindex] = 0;
    }
    int getData(int index){
        return data[headindex+1+index];
    }
}


Measured memory_bytes: 554512
#include<bits/stdc++.h>
int n;
int d(long long a, int f){
	return a>n ? 0 : (f==7) + d(a*10+3,f|1) + d(a*10+5,f|2) + d(a*10+7,f|4);
}
int main(){
	scanf("%d", &n);
	printf("%d\n", d(0,0));
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,m,p;
string s;

int main() {
	cout << fixed << setprecision(18);
	cin>>s;
	//             a b c d e f g h i j k l m n o p q r s t u v w x y z
	int chang[30]={0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0};
	while(s!="#"){
		long long int cou=0;
		for(int i=1;i<s.length();i++){
			if(chang[s[i]-'a']!=chang[s[i-1]-'a']){cou++;}
		}
		cout<<cou<<endl;
		cin>>s;
	}
	
} 


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int temp;
  temp = N;
  int sum = 0;
  while(temp > 0){
    sum = sum + temp % 10;
    temp = temp / 10;
  }
  if (N % sum == 0){
    cout << "Yes" << endl;
    return 0;
  }
  else cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main() {
    int n, s, e, s2, e2;
    bool flag = false;
    scanf("%d %d", &s, &e);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &s2, &e2);
        if (!flag) {
            if ((s<= s2 && e>= e2) || (s2 <= s && e2 >= e) || (s2 < s && e2 > s) || (s2 < e && e2 >=e)) {
                flag = true;
            }
        }
    }
    printf("%d\n", flag);
    return 0;
}



Measured memory_bytes: 2760
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

time = [0 for _ in range(2*tmax+1)]
for timeline in c_timeline:
    time.append(sum(timeline))

print(max(time))


Measured memory_bytes: 79240
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> isPrime;

vector<int> sieveOfEratosthenes(int n) {
    isPrime.resize(n + 1, true);
    isPrime[0] = false;
    isPrime[1] = false;
    vector<int> res;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            res.push_back(i);
            for (int j = i * 2; j <= n; j += i) {
                isPrime[j] = false;
            }
        }
    }
    return res;
}


void Main() {
    ll N;
    while (cin >> N) {
        cout << sieveOfEratosthenes(N).size() << '\n';
    }

}

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



Measured memory_bytes: 14092
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

typedef long long int ll;
const ll MAX=1e12;

int main()
{
	ll A,B,C,x,y; cin>>A>>B>>C>>x>>y;
	ll cost=MAX;
	for(ll i=0;i<=2e5;i++){
		ll curcost = 2*i*C;
		ll z=0;
		curcost += A*max(z,x-i);
		curcost += B*max(z,y-i);
		cost=min(cost,curcost);
	}
	cout<<cost;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int n;
int a[25];

int main()
{
    int ans = 0;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 2; i < n; i++)
    {
        if(a[i]>a[i-1]&&a[i]<a[i+1] || a[i]<a[i-1]&&a[i]>a[i+1])
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

counter = sorted(
    Counter(A).items(),
    key=lambda x:x[0],
    reverse=True)

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 4 and cnt == 0:
        print(length**2)
        exit()
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)


Measured memory_bytes: 22436
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace ::std;
// clang-format off
template<typename T> T nxt() {T res; cin >> res; return res;}
#define tests() for (int _ = nxt<int>(); _ > 0; _--)
#define nxt1(t,n) t (n); cin >> n
#define nxt2(t,n,m) t (n),(m); cin >> n >> m
#define nxt3(t,n,m,k) t (n),(m),(k); cin >> n >> m >> k
#define rep(i, A) for (int i = 0 ; i < A ; i++)
#define ll long long
typedef pair<int,int> pii;typedef pair<ll, ll> pll;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<ll> vl;typedef vector<vl> vvl;
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){for(T ti : t)s<<ti<<" ";return s; }
#define all(x) (x).begin(), (x).end()
#define last(vec) vec[vec.size()-1]
#define has(c,x) ((c).find(x) != (c).end())
// clang-format on

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

    string s = nxt<string>();

    cout << s;
    if (last(s) == 's') {
        cout << 'e';
    }

    cout << 's' << endl;

    return 0;
}


Measured memory_bytes: 3660