akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;


void solve()
{ 
   int r,g,b,k;
    cin>>r>>g>>b>>k;
    while(k--)
    {
        if(g<=r)g=g*2;
        else if(b<=g)b*=2;
         else break;
    }
    if(b>g&&g>r)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

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

typedef long long ll;

bool guess(ll x)
{
	if (x == 0) return 1;
	printf("? %lld\n", x);
	fflush(stdout);
	char ch = getchar();
	while (ch != 'Y' && ch != 'N') ch = getchar();
	return ch == 'Y';
}
void confirm(ll x)
{ 
	printf("! %lld\n", x);
	fflush(stdout);
	exit(0);
}

int main()
{
	ll n, l, r, mid;
	bool flag = 0;
	n = 1;
	for (int k = 1; k <= 10; ++k)
	{
		if (!guess(n))
		{
			flag = 1;
			n /= 10;
			break;
		}
		else n *= 10ll;
	}
	if (!flag)
	{
		n = 9;
		while (1)
		{
			if (guess(n))
				confirm(n / 10 + 1);
			n = n * 10 + 9;
		}
	}
	l = n;
	r = n * 10 - 1;
	while (l < r)
	{
		mid = (l + r) >> 1;
		if (guess(10ll * mid + 1))
			r = mid;
		else
			l = mid + 1;
	}
	confirm(l);
	return 0;
}

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

const int MOD = 1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, T;
    cin >> N >> T;
    vector<int> D(N, 0);
    rep(i, N) cin >> D[i];
    sort(D.begin(), D.end(), greater<int>());
    ll ans = 1LL;
    int lb = 0, ub = 0;
    REP(i, 1, N){
        while(D[ub] - T <= D[i] && ub < i) ub++;
        while(D[lb] - T > D[i] && lb < i) lb++;
        ub = max(ub, lb);
        ll plod = 1LL + (ub - lb);
        ans *= plod; ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1532
import copy

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

a_list = []

def dfs(n, m, l):
    # n: 最大の数
    # m: 次に入れる数
    # l: リスト
    if l.count(0) == 0:
        a_list.append(l)
        return
    else:
        for i in range(n):
            if l[i] == 0:
                a = copy.copy(l)
                a[i] = m
                dfs(n, m+1, a)

dfs(n, 1, [0 for _ in range(n)])
a_list.sort()
print(abs(a_list.index(p)-a_list.index(q)))


Measured memory_bytes: 10868
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>
#include<set>

#include <memory>


using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;

ll MOD = 1000000007;


int  main()
{
	vec Kuku(101,0);
	for (int i = 1; i <= 9; ++i)
		for (int j = 1; j <= 9; ++j)
			Kuku[i*j] = 1;

	int N; cin >> N;
	cout << (Kuku[N] == 1 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long fac[500005],infac[500005];
long long in(long long p)
{
    int po=1000000005;
    long long ps=1,ps2=p;
    while(po!=0)
    {
        if(po%2==1)
        {
            ps*=ps2;
            ps%=1000000007;
        }
        ps2*=ps2;
        ps2%=1000000007;
        po/=2;
    }
    return ps;
}
long long se(int a,int b)
{
    long long cal=(fac[a]*infac[b])%1000000007;
    cal=(cal*infac[a-b])%1000000007;
    return cal;
}
main()
{
    fac[0]=1;
    infac[0]=1;
    for(int i = 1;i < 500005;i++)
    {
        fac[i]=(fac[i-1]*i)%1000000007;
        infac[i]=in(fac[i]);
    }
	int m,n,a,b;
    scanf("%d%d%d%d",&m,&n,&a,&b);
    long long cs=0;
    for(int i = m-a+1;i <= m;i++)
    {
        long long cs2=se(b+i-2,i-1)*se(m-i+n-b-1,n-b-1);
        //printf("%lld\n\n",se(b+i-2,i-1));
        cs+=cs2;
        cs%=1000000007;
    }
    long long cs3=0;
    cs3+=se(m+n-2,n-1);
    cs3+=1000000007;
    cs3-=cs;
    cs3%=1000000007;
    printf("%lld",cs3);
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(ll i = (s); i < (e); ++i)
#define per(i,s,e) for(ll i = (s)-1; i >= e; --i)

using ll = long long;

const ll inf = 1001001001;

template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<typename T, size_t N, typename U>
void Fill(T (&a)[N], const U&v){
    std::fill((U*)a,(U*)(a+N),v);
}

ll edge[310][310];

ll n,m,l,q;

int main(){
  Fill(edge,inf);
  cin >> n >> m >> l;
  rep(i,0,m){
    ll a, b, c; cin >> a >> b >> c;a--;b--;
    edge[a][b] = edge[b][a] = c;
  }
  rep(i,0,n)edge[i][i]=0;

    
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
	edge[i][j] = min(edge[i][j],edge[i][k]+edge[k][j]);
      }
    }
  }

  ll cnt[310][310];Fill(cnt,inf);
  rep(i,0,n)rep(j,0,n){
    if(edge[i][j] <= l) cnt[i][j] = 1;
  }
  
  
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
	cnt[i][j] = min(cnt[i][j],cnt[i][k]+cnt[k][j]);
      }
    }
  }

  
  cin >> q;      
  rep(i,0,q){
    ll st, en; cin >> st >> en;st--;en--;
    ll ans = cnt[st][en]-1;
    if(ans >= 1e+9) ans = -1;
    cout << ans << endl;
  }
  return 0;
}
  


Measured memory_bytes: 2048
#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 rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  set<int> st;
  rep(i, n) st.insert(a[i]);


  if(st.size() > 2 || abs(*st.begin()-*st.rbegin()) > 1) {
    cout << "No" << endl;
    return 0;
  }

  if(st.size() == 1) {
    int c = a[0];
    if(c == n-1) cout << "Yes" << endl;
    else if(n >= 2*c) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else {
    int c = *max_element(ALL(a));
    sort(ALL(a));
    int p = distance(lower_bound(ALL(a), c), upper_bound(ALL(a), c));
    int q = n-p;
    if((c-q)*2 <= p && c-1 >= q) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

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

    if(n == 0){
        cout << x << endl;
        return 0;
    }

    vector<bool> data(102, true);
    
    for(int i = 0 ; i < n ; i++){
        int temp;
        cin >> temp;
        data.at(temp) = false;
    }

    if(data.at(x)){
        cout << x << endl;
        return 0;
    }

    int sa = 1;
    while(1){
        if(data.at(x - sa)){
            cout << x - sa << endl;
            return 0;
        }
        if(data.at(x + sa)){
            cout << x + sa << endl;
            return 0;
        }
        sa++;
    }

}


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
vector<ll> A;
ll n, m, i, j, k;
ll v, p;

bool isOK(ll index) {
    ll now = A[index]+m;
    priority_queue<ll> pq;
    pq.push(now);
    ll nokori = ((v-1)*(m)); // 残りの票
    for(i=0;i<n;i++){
        if(i==index)continue;
        ll x = A[i]+min({m,max(0ll,now-A[i]),nokori});
        pq.push(x);
        nokori-=min({m,max(0LL,now-A[i]),nokori});
    }
    if(nokori==0){
        for(i=0;i<p;i++){
            if(pq.top()==now)return true;
            pq.pop();
        }
        return false;
    }else{
        for(i=0;i<min(p-1,n-1-index);i++){
            pq.pop();
            nokori -= (m - max(0ll,now - A[n-1-i]));
            pq.push(A[n-1-i]+m);
        }
        if(nokori>0)return false;
        for(i = 0; i < p; i++) {
            if(pq.top() == now) return true;
            pq.pop();
        }
        return false;
    }
}

ll binary_search() {
    ll ng = -1;
    ll ok = (ll)A.size();
    //okとngの初期値によって最大値だけでなく最小値も求められる.
    //ng=-1の時はkey以上の数値の最小値

    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if(isOK(mid))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

int main() {
    cin >> n >> m >> v >> p;
    A.resize(n);
    for(i=0;i<n;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    cout << n-binary_search() << endl;
    return 0;
}

Measured memory_bytes: 2896
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1){
    cout<<"No";
    exit(0);}
    else
    {
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+n/2])
            {
                cout<<"No";
                exit(0);
            }
        }
        cout<<"Yes";
    }}

Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int n,m,s,g1,g2;
int d[111][111];
int main(void){
  while(1){
    cin >> n >> m >> s >> g1 >> g2; if(!n) break;

    s--;g1--;g2--;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	d[i][j] = 1 << 28;
      }
      d[i][i] = 0;
    }
    
    for(int i = 0; i < m; i++){
      int a,b,c;
      cin >> a >> b >> c;
      d[a-1][b-1] = c;
    }

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

    int ret = 1 << 28;
    for(int i = 0; i < n; i++){
      ret = min(ret,d[s][i]+d[i][g1]+d[i][g2]);
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1204
#include <iostream>
#include <map>

using namespace std;

int main(){
    int a,n;
    map<int,bool>m;

    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> a;
        if(m.count(a)){
            printf("NO\n");
            return 0;
        }
        m[a] = true;
    }

    printf("YES\n");

    return 0;

    
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define get(a, n)    for(ll it = 0; it < n; it++)    cin>>a[it];
#define mod 1000000007LL

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

// i, k => (i-1) (k, k-1, k-2, ..., k-ai)
// i, k-1 => (i-1) (k-1, k-2, ..., k-ai, k-ai-1)
// (i, k) = (i, k-1) - dp[i-1][k-ai-1] + dp[i-1][k]

int main(){
	ll n, k;	cin>>n>>k;
	ll a[n];	get(a, n);
	ll dp[n+1][k+1];	dp[0][0] = 1;
	for(ll i = 1; i <= k; i++)	dp[0][i] = 0;
	for(ll i = 1; i <= n; i++){
		dp[i][0] = 1;
		for(ll j = 1; j <= k; j++){
			dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod;
			if(j >= a[i-1] + 1)
				dp[i][j] = (dp[i][j] + mod - dp[i-1][j-a[i-1]-1])%mod;
		}
	}
	cout<<dp[n][k];
}

// Time: O(N*K)
// Space: O(N*K)

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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var counter = 0;
            for (int i = 0; i <= input[0]; i++)
            {
                for (int j = 0; j <= input[0]; j++)
                {
                    var z = input[1] - i - j;
                    if (0 <= z && z <= input[0])
                        counter++;
                }
            }
            Console.WriteLine(counter);
        }
    }
}


Measured memory_bytes: 13268
def inpl():
    return list(map(int, input().split()))


N, K = inpl()
P = inpl()

cumP = [0]
for p in P:
    cumP.append(cumP[-1] + p)

max_s = 0
for i in range(N - K + 1):
    max_s = max(max_s, cumP[i + K] - cumP[i])

print((max_s + K) / 2)


Measured memory_bytes: 25060
import sys
S = list(input())
# S = "Atcoder"
# S = list(S)

if S[0] != "A":
    print("WA")
    sys.exit()
# elif S[1].isupper():
#     print("WA")
#     sys.exit()
# elif S[-1].isupper():
#     print("WA")
#     sys.exit()
elif "C" in S[2:-1]:
    S.remove("C")
    del S[0]
    S = str(S)
    if S.islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
s = input()
nn = int(s[:2])
dd = int(s[2:])

if nn > 0 and nn <= 12 and dd > 0 and dd <=12:
  print("AMBIGUOUS")
elif nn > 0 and nn <= 12:
  print("MMYY")
elif dd > 0 and dd <= 12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
import math
d,t,s=map(int, input().split())
if math.ceil(d/t)>s:
    print("No")
else: print("Yes")

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

#define ll long long



int main() {
	// your code goes here
	
	
	ll N, W;
	cin>>N>>W;
	
	
	ll w[N], v[N];
	for(ll i = 0; i< N; i++) cin>>w[i]>>v[i];
	
	
	ll dp[N+1][W+1];
	
	for(ll i = 0 ;i <= N; i++) {
	    for(ll j = 0; j <= W; j++) dp[i][j] = 0;
	}
	
	dp[1][w[0]] = v[0];
	
	for(ll i = 2; i <= N; i++) {
	    for(ll wt = 0; wt <= W; wt++) {
	        dp[i][wt] = dp[i-1][wt];
	        if(wt < w[i-1]) continue;
	        
	        dp[i][wt] = max(dp[i][wt], v[i-1] + dp[i-1][wt-w[i-1]]);
	    }
	}
	
	
	//	for(ll i = 0; i<= W; i++) cout<<dp[N][i]<<" ";
	
	ll ans  = LONG_MIN;
	
	for(ll i = 0; i<= W; i++) ans = max(ans, dp[N][i]);
	cout<<ans<<endl;
	    
	
	
	
	return 0;
}


Measured memory_bytes: 79104
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, n = 0;

    cin >> a >> b >> c;

    for (int i = a; i <= b; i++)
    {
        if (c % i == 0) { n++; }
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n, -1){}
  int find (int x) {
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite (int x, int y){
    x = find(x), y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  bool size(int x) { return -d[find(x)]; }
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  UnionFind uf(n);
  rep(i, n) {
    int x;
    cin >> x;
    --x;
    p[i] = x;
  }
  rep(i, m){
    int x, y;
    cin >> x >> y;
    --x; --y;
    uf.unite(x, y);
  }
  ll ans = n;
  rep(i, n){
    if(!uf.same(p[i], i)) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;

int main()
{
	int N;
	cin >> N;
	long long result = 1;
	bool ovfl = false;
	for (int i = 0; i < N; ++i) {
		long long j;
		cin >> j;
		if (j == 0) {
			cout << 0;
			return 0;
		}
		if (result > 1000000000000000000LL / j) {
			ovfl = true;
		}
		result *= j;
	}
	if (ovfl)
		cout << -1;
	else
		cout << result;
	return 0;
}


Measured memory_bytes: 3632
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Set<Integer> set = new HashSet<>();
		int n = sc.nextInt();
		int k = sc.nextInt();
		for(int i = 0; i < k; i++) {
			int a = sc.nextInt();
			for(int j = 0; j <a;j++) {
				set.add(sc.nextInt());
			}
		}
		System.out.println(n-set.size());
	}
}

Measured memory_bytes: 46332
#include <iostream>
#include<algorithm>

using namespace std;

int main(){
        int n, sum=0;
        int s[110];

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

        if(sum%10!=0) cout<<sum<<endl;
        else {
                sort(s,s+n);
                for(int i=0; i<n; ++i) {
                        if(s[i]%10!=0){
                                sum-=s[i];
                                break;
                        }else if(i==n-1){
                                sum=0;
                        }
                }
                cout<<sum<<endl;
        }

        return 0;
}

Measured memory_bytes: 256
import java.awt.*;
import java.io.*;
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new TestB().doIt();
	}
	class TestB{
		void doIt() {
			String str = sc.next();
			int length = str.length();
			int ans = 0;
			for(int i = 0;i < length;i++) {
				ans = ans + Integer.parseInt(str.substring(i,i+1));
			}
			if(ans % 9 == 0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 50508
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,k;
  cin >> n >> k;
  if (n%k==0) cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

int main(){
  stack<char> S;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S') S.push(s[i]);
    else if(S.empty() || S.top()==s[i]) S.push(s[i]);
    else{
      S.pop();
    }
    
  }
  cout<<S.size()<<endl;
}


Measured memory_bytes: 644
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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


	int n;
	cin >> n;
	vi cnt(n);
	REP(i, n - 1) {
		int x;
		cin >> x;
		--x;
		++cnt[x];
	}
	REP(i, n) {
		cout << cnt[i] << endl;
	}
}

Measured memory_bytes: 4024
N = int(input())
L = list(map(int,input().split()))
x = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[i]!=L[j] and L[i]!=L[k] and L[k]!=L[j] and L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i]:
        x = x+1
print(x)

Measured memory_bytes: 9196
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <tuple>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int w, h;
char a[21][21];

int bfs(int sh,int sw) {
	//cout<<"--------------------------------------------"<<endl;
	int ans = 1;
	queue<pair<int,int> > q;
	q.push(pair<int,int>(sh, sw));
	while (!q.empty())
	{
		//for (int i = 0; i < h; i++) {
			//for (int j = 0; j < w; j++) {
				//cout << a[i][j] << " ";
			//}
			//cout << endl;
		//}

		//cout << ans << endl;
		int nowx, nowy;
		nowy = q.front().first;
		nowx = q.front().second;
		//cout << nowy << " " << nowx << endl;
		q.pop();
		if (a[nowy][nowx + 1] == '.' && nowx<w-1) {
			q.push(pair<int,int>(nowy, nowx + 1));
			a[nowy][nowx + 1] = '#';
			ans++;
		}
		if (a[nowy][nowx - 1]=='.' && nowx>0) {
			q.push(pair<int,int>(nowy, nowx - 1));
			a[nowy][nowx - 1] = '#';
			ans++;
		}
		if (a[nowy + 1][nowx] == '.' && nowy<h-1) {
			q.push(pair<int,int>(nowy + 1, nowx));
			a[nowy + 1][nowx] = '#';
			ans++;
		}
		if (a[nowy - 1][nowx] == '.' && nowy>0) {
			q.push(pair<int,int>(nowy - 1, nowx));
			a[nowy - 1][nowx] = '#';
			ans++;
		}
	}
	return ans;
}

int main() {
	while (cin >> w >> h, w) {
		int sw, sh;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> a[i][j];
				if (a[i][j] == '@') {
					sw = j;
					sh = i;
				}
			}
		}
		cout << bfs(sh, sw) << endl;
	}
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,R;
    cin >> N >> R;
    if(10<=N) cout << R << "\n";
    else cout << R+100*(10-N) << "\n";
}

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

int main()
{
  string s;
  cin >> s;
  int before, after;
  before = (s[0] - '0')*10 + (s[1] - '0');
  after = (s[2] - '0')*10 + (s[3] - '0');

  if(0 < before && before < 13){
    if(0 < after && after < 13){
      cout << "AMBIGUOUS" << endl;
    }
    else{
      cout << "MMYY" << endl;
    }
  }
  else{
    if(0 < after && after < 13){
      cout << "YYMM" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;



int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    
    if (a < b){
        for (int i=0; i < b; i++){
            cout << a;
        }
    }
    else {
        for (int i=0; i < a; i++){
            cout << b;
        }
    }

    


    

    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 888
N = int(input())
a = [int(0.5*i*(i+1)) for i in range(10)]
import math
res = 0
top = int(math.sqrt(N))
for i in range(2,top+1):
    count = 0
    while N%i == 0:
        N = N//i
        count += 1
    for j in range(10):
        if count < a[j]:
            res += (j-1)
            break
if N != 1:
    print(res+1)
else:
    print(res)

Measured memory_bytes: 65112
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k;
    if (n % k) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>                                              
#include<cmath>                                                 
using namespace std;                                            
                                                                
int main(void) {                                                
  int a,b;                                                      
  while (cin >> a >> b) {                                       
    a = log10(a+b)+1;                                           
    cout << a << endl;                                          
  }                                                             
  return 0;                                                     
}                                                               
                                                                
                      

Measured memory_bytes: 3316
#include<bits/stdc++.h>
    using namespace std;
    
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
    #define int long long 
    #define double long double
    
    #define all(a)      (a).begin(),(a).end()
    #define sz(x)       (int)x.size()
    
    #define ff first
    #define ss second
    #define mp make_pair
         
    #define pb push_back
    #define endl "\n" 
         
    #define f(i,l,r) for(int i=l;i<=r;i++)
    #define rf(i,r,l) for(int i=r;i>=l;i--)    

    #define bp __builtin_popcountll
    #define inf 1e18
    
    const int N=1e5+5; 
    const int MOD=1e9+7;
    void solve()
    {
        int n;
        cin>>n;
		string s;
		cin>>s;
		s='a'+s;
		int ans=0;
		int x[n+1]={0},y[n+1]={0},z[n+1]={0};
		f(i,1,n)
		{
			if(s[i]=='R')
			x[i]++;
			else if(s[i]=='G')
			y[i]++;
			else
			z[i]++;
			x[i]+=x[i-1];
			y[i]+=y[i-1];
			z[i]+=z[i-1];
		}
		int pp='R'+'G'+'B';
		f(i,1,n)
		{
			f(j,i+1,n)
			{
				int tt=pp-s[i]-s[j];
				if(tt=='R')
				{
					ans+=x[n]-x[j];
				}
				else if(tt=='G')
				{
					ans+=y[n]-y[j];
				}
				else if(tt=='B')
				{
					ans+=z[n]-z[j];
				}
			}
		}
		f(i,1,n)
		{
			f(j,i+1,n)
			{
				if(j+j-i>=1 && j+j-i<=n && s[j+j-i]!=s[i] && s[j+j-i]!=s[j] && s[i]!=s[j])
				ans--;
			}
		}
		cout<<ans;
    }
    
    signed main()  
    {
        FAST
        int t=1;
        // cin>>t;
        while(t--)
        {
            solve();
        }
    }



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

int main(){
	long long x , y , z ;
	cin >> x >> y >> z ;
	if( x % 2 == 0 || y % 2 == 0 || z % 2 == 0 ){
		cout << 0 ;
		return 0 ;
	}
	if( z >= x && z >= y ){
		cout << y * x ;
		return 0 ;
	}
	if( x >= z && x >= y ){
		cout << y * z ;
		return 0 ;
	}
	if( y >= x && y >= z ){
		cout << z * x ;
		return 0 ;
	}
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
ll n,h,w;
cin>>h>>w>>n;
ll t=max(h,w);
cout<<(n+t-1)/t<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    ll pushed = 0;
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    for(int i = n - 1; i >= 0; --i){
        pushed += (b[i] - ((a[i] + pushed) % b[i])) % b[i];
    }
    cout << pushed << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	int n,pos;
	char train[60];
	string s;
	cin >> n;
	getchar();
	for(int i = 0;i < n;i++){
		pos = 30;
		for(int j = 0;j < 60;j++) train[j] = 0;
		getline(cin,s);
		train[pos] = s[0];
		for(int j = 1;j < s.size();j++){
			if(s[j] == '-') {
				j += 2;
				train[++pos] = s[j];
			}
			else if(s[j] == '<'){
				j += 2;
				train[--pos] = s[j];
			}
		}
		for(int j = 0;j < 60;j++){
			if(train[j] != '\0') cout << train[j];
		}
		cout << endl;
	}
	return 0;
}

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

typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a[n], b[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];

  ll d, sum = 0, res = 0;
  
  for(int i = 0; i < n; i++){
    d = b[i] - a[i];
    sum += d;
    if(a[i] < b[i]) res += (d + 1) / 2;
  }
  if(sum >= res) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
from collections import deque
from sys import stdin
input = stdin.readline

N, M = map(int, input().split())

graph = [[] for _ in range(N)]
seen = [-1] * N

for _ in range(M):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)


def bfs(x):
    q = deque([])

    q.append(x)
    seen[x] = 1

    while q:
        x = q.popleft()

        for y in graph[x]:
            if seen[y] != -1:
                continue

            seen[y] = 1
            q.append(y)


ans = 0

for i in range(N):
    if seen[i] != -1:
        continue
    else:
        ans += 1
        bfs(i)

print(ans - 1)


Measured memory_bytes: 26584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int near(const int x, const int y) {
  const int target = 753;
  const int x_near = abs(target - x);
  const int y_near = abs(target - y);
  return x_near < y_near ? x : y;
}

int main() {
  string str; cin >> str;
  const int len = str.size();

  int ans = MAX_SIZE;
  for(int i = 0; i < len - 2; i++) {
    string s = str.substr(i,3);
    ans = near(ans, stoi(s));
  }
  cout << abs(753-ans) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  1e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s;
ll dp[MAX];
vector < pair < ll , ll > > v ;
ll sum;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//    freopen("test.in","r",stdin);
    ll w ;
    cin>>n>>w;


    for(int i = 0 ; i < n ; ++i)
        cin>>x>>k,v.pb({x,k}),sum+=k;

    for(int i = 0 ; i <= sum ; ++i)
        dp[i] = 1e16 ;

    dp[0] = 0 ;

    for(int i = 0 ; i < n ; ++i)
        for(int j = sum ; j >= v[i].s ; --j)
            dp[j] = min(dp[j],dp[j - v[i].s] + v[i].f);

    for(int i = sum ; i >= 0 ; --i)
        if(dp[i] <= w)
            return cout<<i<<'\n', 0;

    return 0;
}


Measured memory_bytes: 1024
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()

	mp := map[int]int{}
	mp[0]++
	sum := 0
	ans := 0
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		sum += tmp
		ans += mp[sum]
		mp[sum]++
	}
	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 14976
#include<stdio.h>
#include<stdlib.h>

#define MAX(A, B) (((A) > (B)) : (A) ? (B))

int main() {
  int a, b, c;
  int d;
  scanf("%d %d %d", &a, &b, &c);
  
  if (a + b > c - 2) {
    d = b + c;
  }
  else {
    d = a + b + b + 1;
  }
  printf("%d\n", d);
  return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
amax = a[0]
na = a[1:]
d = {}
for el in na:
    d[el] = abs(el - amax//2)
ds = sorted(d.items(), key=lambda x:x[1])
print(amax, ds[0][0])

Measured memory_bytes: 103932
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 0
for i in range(1,10**10):
    res += i
    if res >= n:
        print(i)
        break

Measured memory_bytes: 4196
s = raw_input().split()
p= int(s[0]) 
q= int(s[1])
r= int(s[2])
s= int(s[3])
def area(a,b,c, d):
    if a*b > c*d:
        print a*b
    elif c*d > a*b:
        print c*d
    else:
        print a*b
x = area(p,q,r,s)

Measured memory_bytes: 2568
S = int(input())

if S <=599 :
    print(8)
elif S <= 799:
    print(7)
elif S <= 999:
    print(6)
elif S <= 1199:
    print(5)
elif S <= 1399:
    print(4)
elif S <= 1599:
    print(3)
elif S <= 1799:
    print(2)
else :
    print(1)



Measured memory_bytes: 61756
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    
    int n;
    cin >> n;
    ll h[n];
    rep(i,n) cin >> h[i];

    reverse(h, h+n);

    int flag = 1;
    rep(i, n-1){
        if (h[i] + 1 == h[i+1]) h[i+1]--;
        else if (h[i] >= h[i+1]) ;
        else flag = 0;
    }


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

    

}





//              g++ -std=c++1z

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    ll n=0, m=0;
    for (int i = 0; i < N; i++) {
        if (A[i] < B[i]) {
            n += (B[i]-A[i]+1)/2;
            m += (B[i]-A[i])%2;
        }
        if (A[i] > B[i]) {
            m += A[i]-B[i];
        }
    }
    if (n < m) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
	cin >> n;
	vector<char> ma(n),mb(1);
	mb[0] = '2';
	REP(i,n) cin >> ma[i];
	REP(i,n) if(ma[i]!=mb[mb.size()-1])mb.push_back(ma[i]);
	// FOR(i,1,mb.size()) cout << mb[i] ;
    cout << mb.size()-1 << endl;
}


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

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long n,k;cin>>n>>k;int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<long> dp(n,INT_MAX);
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<i+k+1;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
  int t, ac=0, wa=0, tle=0, re=0;
  cin >> t;
  string s;
  while(t--){
    cin >> s;
    if(s=="AC")ac++;
    if(s=="WA")wa++;
    if(s=="TLE")tle++;
    if(s=="RE")re++;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", ac, wa, tle, re);
}


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

using namespace std;

int n,v[100005],cnt[100005],maks,temp1,temp2,num1,num2,temp3,temp4,mboh1,mboh2;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	memset(cnt,0,sizeof(cnt));
	maks=0;
	for(int i=0;i<n;i=i+2)
	{
		cnt[v[i]]++;
	}
	for(int i=1;i<=1e5;i++)
	{
		maks=max(maks,cnt[i]);
		if(maks==cnt[i]) num1=i;
	}
	temp1=(n/2)-maks;
	memset(cnt,0,sizeof(cnt));
	maks=0;
	for(int i=1;i<n;i=i+2)
	{
		cnt[v[i]]++;
	}
	for(int i=1;i<=1e5;i++)
	{
		maks=max(maks,cnt[i]);
		if(maks==cnt[i]) num2=i;
	}
	temp2=(n/2)-maks;
	//cout<<num1<<" "<<num2<<endl;
	if(num1!=num2) cout<<temp1+temp2<<endl;
	else
	{
		maks=0;
		memset(cnt,0,sizeof(cnt));
		for(int i=0;i<n;i=i+2)
		{	
			cnt[v[i]]++;
		}
		cnt[num1]=0;
		for(int i=1;i<=1e5;i++)
		{
			maks=max(maks,cnt[i]);
			if(maks==cnt[i]) num1=i;
		}
		temp3=(n/2)-maks;
		maks=0;
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<n;i=i+2)
		{	
			cnt[v[i]]++;
		}
		cnt[num2]=0;
		for(int i=1;i<=1e5;i++)
		{
			maks=max(maks,cnt[i]);
			if(maks==cnt[i]) num1=i;
		}
		temp4=(n/2)-maks;
		//cout<<temp3<<" "<<temp4<<endl;
		if(temp3<temp4) cout<<temp3+temp2<<endl;
		else cout<<temp1+temp4<<endl;
	}
}

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

int main() {
  int N , K  ,x , W ;
  cin >> N >> K ;
  W = 0; 
  while(N>0){
    N-- ;
    cin >> x ;
    if ( x >= K - x  ){
      W += (K - x)*2 ;
       }
    else {
      W += x * 2 ;
          }
  }
  cout << W << endl;
}
  
      
  
  
 

Measured memory_bytes: 256
#include<cstdio>
int main(void){int n,x,i;scanf("%d",&n);for(i=1;i<=n;++i){if(i%3==0){printf(" %d",i);}else{for(x=i; x>0; x/=10){if(x%10==3){printf(" %d", i);break;}}}}puts("");return(0);}


Measured memory_bytes: 2692
local mma = math.max
local mfl = math.floor
local n = io.read("*n")
local mul = 1
local say = {}
for i = 1, n do
  say[i] = {}
  local k = io.read("*n")
  for j = 1, k do
    local a, b = io.read("*n", "*n")
    say[i][a] = b
  end
  mul = mul * 2
end
local ret = 0
local state = {}
for im = 0, mul - 1 do
  local valid = true
  local tasks = {}
  for j = 1, n do
    if im % 2 == 1 then
      table.insert(tasks, j)
    end
    state[j] = im % 2
    im = mfl(im / 2)
  end
  local cnt = #tasks
  for j = 1, #tasks do
    local src = tasks[j]
    for k, v in pairs(say[src]) do
      if state[k] ~= v then
        valid = false
        break
      end
    end
    if not valid then break end
  end
  if valid then ret = mma(ret, cnt) end
end
print(ret)


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define INF (1LL<<60)
#define DEBUG 0
 
signed main(){

	lli cnt = 0;

	lli n,t;
	cin>>n>>t;
	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];
	t/=2;

	lli maxDiff=0;

	lli maxT = -INF;

	maxT = a[n-1];

	map<lli,lli> d;

	for(lli i=n-2;i>=0;i--){
		//maxDiff = max(maxT-a[i],maxDiff);
		d[a[i]-maxT]++;
		maxT = max(maxT,a[i]);
	}

	lli ans = 0;
	for(auto e:d){
		if(DEBUG)cout<<"e.first="<<-e.first<<" e.second=="<<e.second<<endl;
		//ans = max(ans,e.second);
		cout<<min(INF,e.second)<<endl;
		return 0;
	}
	cout<<ans<<endl;



	return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;

int main() {
    int S; cin >> S;
    int h,m,s;
    h = S / 3600;
    m = (S - (3600 * h)) / 60;
    s = S - ((3600 * h) + (60 * m));
    cout << h << ":" << m << ":" << s << endl;
}


  



Measured memory_bytes: 3132
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int maxn = 55;

ll k;
ll ans[maxn];

int main() {
    cin >> k;

    int n = 50;
    
    cout << n << endl;

    if(!k) {
	for(int i = 0; i < n; ++i)
	    cout << 0 << " ";
    }
    else {
	for(int i = n; i >= 1; --i)
	    ans[n - i + 1] = i - 1;

	++ans[1];

	if(k == 1) {
	    for(int i = 1; i <= n; ++i)
		cout << ans[i] << " ";

	    return 0;
	}

	 k -= 2;

	for(int i = 1; i <= n; ++i)
	    ans[i] += (k / n);

	k %= n;

	for(int mod = 0; mod <= k; ++mod) {
	    for(int i = 1; i <= n; ++i)
		--ans[i];

	    ans[n - mod] += n + 1;
	}
	
	for(int i = 1; i <= n; ++i)
	    cout << ans[i] << " ";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n;
int dp[1000010],op[1000010];
int a[20][20];
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
        cin>>a[i][j];
    for(int i=1;i<(1<<n);i++)
    {
        for(int x=0;x<n;x++)
        for(int y=x;y<n;y++)
            if(((1<<x)&i)&&((1<<y)&i))
                op[i]+=a[x][y];
        //cout<<i<<" "<<op[i]<<'\n';
    }
    for(int i=1;i<(1<<n);i++)
    {
        dp[i]=max(dp[i],op[i]);
        for(int j=i;j;j=(j-1)&i)
        {
            dp[i]=max(dp[i],dp[j]+op[i^j]);
        }
    }
    cout<<dp[(1<<n)-1];
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("antree.inp","r",stdin);
    //freopen("antree.out","w",stdout);
    //int test;cin>>test;while(test--)
    solve();
    return 0;
}



Measured memory_bytes: 4676