akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  int n;
  cin>>n;
  int a[n];
  double sum = 0;
  double mul = 1;
  for(int i = 0; i < n; i++){
    cin>>a[i];
    mul*=a[i];
  }
  for(int i = 0; i < n; i++){
    sum+=mul/a[i];
  }
  
  cout<<fixed<<setprecision(10)<<mul/sum<<endl;
  return 0;
}

Measured memory_bytes: 256
def near_num(x,nodes):
    temp = []
    for i in range(len(nodes)):
        temp.append(abs(x-nodes[i]))
        if i != 0:
            if temp[i] >= temp[i-1]:
                return nodes[i-1]
    else:
        return nodes[len(nodes)-1]
        

N = int(input())
s = list(map(int,input().split()))
s.sort()

M = s[N-1]

if M % 2 == 0:
    m = near_num(M//2,s)
elif abs(near_num(M//2+1,s)-(M//2+1)) >= abs(near_num(M//2,s)-M//2):
    m = near_num(M//2,s)
else:
    m = near_num(M//2+1,s)

print(M,m)

Measured memory_bytes: 14428
#include<iostream>
using namespace std;
int main(){
int a;
  cin>>a;
  long int b[a],sum=0;
             for(int i=0;i<a;i++)cin>>b[i];
  for(int i=1;i<a;i++){
  if(b[i]<b[i-1])
  {sum+=b[i-1]-b[i];
  b[i]=b[i-1];}
  
  }
  cout<<sum;



return 0;}

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

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> in(n);
    vector<int> a(n - 1 + m), b(n - 1 + m);
    for(int i = 0; i < n - 1 + m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]].push_back(b[i]);
        in[b[i]] += 1;
    }
    int root = -1;
    for(int i = 0; i < n; ++i) {
        if(in[i] == 0) root = i;
    }

    queue<int> que;
    que.push(root);
    vector<int> ans(n, -1);
    while(!que.empty()) {
        auto v = que.front(); que.pop();
        for(auto to : g[v]) {
            in[to]--;
            if(in[to] == 0) {
                ans[to] = v;
                que.push(to);
            }
        }
    }

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


Measured memory_bytes: 7808
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#include<map>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;

LL N, M, K, ans, num, H, W, P,an[10000000];
bool sosu[10000000];
string S;

	vector<LL>v;
	map<LL, LL>m;
int main() {
	cin >> N >> P;

	if (N > P) {
		cout << 1 << endl;
		return 0;
	}
	K = 0;

	LL a = sqrt(P);
	LL c = 2;
	LL con = 0;
	while (a>c) {
		if (P%c==0){
			v.push_back(c);

			P=P / c;
		}
		else {
			c++;
		}
	}
	ans = 1;
	if (P > 1)v.push_back(P);
	LL n,d;
	n = 1;
	d = 0;
	for (int i = 0; i < v.size(); i++) {
		if (n == v[i]) {
			d++;
		}
		else {
			ans = ans*pow(n, d / N);
			n = v[i];
			d=1;
		}
	}

	ans = ans*pow(n, d / N);
	cout << ans << endl;

	return 0;



}

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

using namespace std;

string s, t;
int ans, cnt, i, j;
int main(){
    cin >> s >> t;
    ans = 100000;
    for (i = 0; i <= s.size() - t.size(); ++i) {
        cnt = 0;
        for (j = 0; j < t.size(); ++j)
        if (s[i + j] != t[j])
        ++cnt;
        ans = min(ans, cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
const int maxn=1e5+10;
char s[maxn];
int main() {
    while (~scanf("%s",s)) {
        int len=strlen(s);
        int ans=0;
        for (int i=0;i<len-1;i++) {
            if (s[i]!=s[i+1]) ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll min(ll x, ll y){
    if(x<y)return x;
    return y;
}

int main(void){
    ll x, y;
    scanf("%lld %lld", &x, &y);
    if(x-y <= 1 && y-x <= 1)printf("Brown\n");
    else printf("Alice\n");
    return 0;
}

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

using namespace std;

int main(){
	int N, A, B;
	while(cin >> N >> A >> B){
		string S; cin >> S;
		int passed = 0, k = 0;
		for(int i=0;i<S.size();++i){
			if(S[i] == 'c'){
				cout << "No" << endl;
				continue;
			} else if(S[i] == 'a'){
				if(passed < A+B){
					cout << "Yes" << endl;
					++passed;
				} else {
					cout << "No" << endl;
				}
			} else if(S[i] == 'b'){
				if(passed < A+B && k < B){
					cout << "Yes" << endl;
					++passed;
				} else {
					cout << "No" << endl;
				}
				++k;
			}
		}
	}
}


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


#define TRACE

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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	if(((n)&(n-1))==0){
		cout<<"No";
	}
	else{
		cout<<"Yes\n";
		int d = 1;
		while(2*d-1<=n){
			d = d*2;
		}
		d--;
		if(n==3){
			cout<<1<<' '<<2<<'\n';
			cout<<2<<' '<<3<<'\n';
			cout<<3<<' '<<4<<'\n';
			cout<<4<<' '<<5<<'\n';
			cout<<5<<' '<<6<<'\n';

		}
		else if(n%2){
			repA(i,1,d-1) cout<<i<<' '<<i+1<<'\n';
			cout<<d<<' '<<1+n<<'\n';
			repA(i,1,d-1) cout<<i+n<<' '<<i+1+n<<'\n';
			int x = 0;
			if(d+1<=n){
			repA(i,d+1,n){
				x^=i;
				if(i!=n) {
					cout<<i<<' '<<i+1<<'\n';
					cout<<i+n<<' '<<i+1+n<<'\n';
				}
			}
			if(x){
			cout<<n<<' '<<x<<'\n';
			cout<<x<<' '<<n+d+1<<'\n';
			}
			else{
				cout<<n<<' '<<n+d+1<<'\n';
				cout<<1<<' '<<n<<'\n';
			}
			}
		}
		else{
			repA(i,1,d-1) cout<<i<<' '<<i+1<<'\n';
			cout<<d<<' '<<1+n<<'\n';
			repA(i,1,d-1) cout<<i+n<<' '<<i+1+n<<'\n';
			cout<<1<<' '<<d+1<<'\n';	
			cout<<1<<' '<<d+2<<'\n';	
			cout<<2<<' '<<d+3<<'\n';	
			cout<<d+1+n<<' '<<d+2<<'\n';
			cout<<d+3+n<<' '<<d+2<<'\n';
			cout<<d+2+n<<' '<<d+1<<'\n';
			if(d+4<=n){
			int x = 0;
			repA(i,d+4,n){
				x^=i;
				if(i!=n) {
					cout<<i<<' '<<i+1<<'\n';
					cout<<i+n<<' '<<i+1+n<<'\n';
				}
			}
			cout<<n<<' '<<x<<'\n';
			cout<<x<<' '<<n+d+4<<'\n';
			}

		}

	}
	return 0;
}



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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> P;
const int MOD=1e9+7;
map<ll,ll> dp;ll n;

ll dfs(ll x)
{
	if(dp.count(x)) return dp[x];
	return dp[x]=(dfs(x>>1)+dfs((x-1)>>1)+dfs((x-2)>>1))%MOD;
}

int main()
{
	scanf("%lld",&n);
	dp[0]=1;dp[1]=2;
	printf("%lld",dfs(n));
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))
mn = 10**18
for B in combinations(range(1,N),K-1): # 一番左は固定
    mx = A[0] # 初期値は一番左の建物
    score = 0
    for n in range(1,N):
        if n in B: # 見えるようにすべき建物なら
            if A[n] <= mx: # 低ければ高くする
                mx += 1
                score += (mx - A[n])
            else: # 高さが十分なら何もしない。最大値を更新
                mx = A[n]
        else:
            mx = max(mx, A[n]) # 見えなくても良い建物なら、最大値を更新
    mn = min(mn, score)
print (mn)

Measured memory_bytes: 9096
def dist(p,q):
  return sum((px - qx) ** 2.0 for px, qx in zip(p, q))**0.5
n=int(input())
p=[]
for _ in range(n):
  p.append(list(map(int,input().split())))
import itertools
a=list(itertools.permutations(range(n)))
ans=[]
for i in a:
  d=0
  for j in range(n-1):
    d+=dist(p[i[j]],p[i[j+1]])
  ans.append(d)
from statistics import mean
print(mean(ans))

Measured memory_bytes: 11604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

class TaskA {
 public:
  void solve(std::istream &in, std::ostream &out) {
    char A, B;
    in >> A >> B;
    if (A < B) {
      out << "<";
    } else if (A == B) {
      out << "=";
    } else {
      out << ">";
    }
  }
};


int main() {
  TaskA solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
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;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
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()
{
  ll x, k, d;
  cin >> x >> k >> d;
  ll count = abs(x) / d;
  if(k < count) cout << abs(x) - d*k << endl;
  else {
    k -= count;
    if(k % 2 == 0) cout << abs(x) - d*count << endl;
    else {
      if(x >= 0) cout << abs(x - d*(count+1)) << endl;
      else cout << abs(x + d*(count+1)) << endl;
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using D=long double;
using P=pair<ll,ll>;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll h,w;cin>>h>>w;
	if(h==1||w==1){
		cout<<1<<endl;
	}else if(h%2LL>0&&w%2LL>0){
		cout<<(h*w)/2LL+1LL<<endl;
	}else{
		cout<<(h*w)/2LL<<endl;
	}
}


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

long long n, a, x[55], dp[55][55][2525];
long long sum=0;


int main(){

cin >> n >> a;
for(int i =0; i<n;i++)cin >> x[i];
dp[0][0][0]=1;
for(int i =0; i<=50; i++){
    for(int j =0; j<=50; j++){
        for(int k =0; k<=2505; k++){
            if(dp[i][j][k]){
                dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }
}
for(int i =1; i<=n; i++){
    sum+= dp[n][i][a*i];
}
cout << sum << endl;
return 0;}


Measured memory_bytes: 55552
#include <bits/stdc++.h>
typedef long long ll;

int n,i=1,x;
ll a,b=-1e18,c=b;

int main()
{
	scanf("%d%lld",&n,&a);
	for(char o;i<n;++i)
	{
		if(scanf(" %c%d",&o,&x),o=='-')a=b=std::max(a-x,c=b+x);
		else a+=x,b=std::max(b-x,c+=x);
	}
	return printf("%lld\n",a),0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    int pos = -1;
    int ans = 0;
    while (1) {
        pos = S.find("ABC", pos + 1);
        if (pos == -1) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
ll n;
set<ll> s;
inline ll mi(ll a, ll b)
{
    ll ret = 1;
    while (b)
    {
        if (b & 1)
            ret *= a;
        a *= a;
        b >>= 1;
    }
    return ret;
}

void check(ll d)
{
    for (ll i = 1; i <= 60; ++i)
    {
        ll k = pow(d * 1.0, 1.0 / i);
        if (k == 1)
            continue;
        if (mi(k, i) == d)
        {
            if ((n / d - 1 + k) % k == 0)
                s.insert(k);
        }
        if (mi(k + 1, i) == d)
        {
            if ((n / d - 1 + k + 1) % (k + 1) == 0)
                s.insert(k + 1);
        }
        if (k > 1 && mi(k - 1, i) == d)
        {
            if ((n / d - 1 + k - 1) % (k - 1) == 0)
                s.insert(k - 1);
        }
    }
}

void solve()
{
    cin >> n;
    for (ll i = 1; i * i <= n - 1; ++i)
    {
        if ((n - 1) % i == 0)
        {
            s.insert(i);
            s.insert((n - 1) / i);
        }
    }
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            check(i);
            check(n / i);
        }
    }
    check(n);
    s.erase(1);
    cout << s.size() << '\n';
    // for (auto i : s)
    //     cout << i << ' ';
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;

int main(int argc, char *argv[])
{
	double w, h, x, y;
	double sum;
	double answer;
	int multi;

	cin >> w >> h >> x >> y;
	
	sum = w * h;
	answer = sum / 2.0;

	if (x + x == w && y + y == h)
		multi = 1;
	else
		multi = 0;
	   

	cout << fixed << setprecision(12);
	cout << answer << " " << multi << endl;

	return 0;
}


Measured memory_bytes: 256
import math
import numpy as np
n = int(input())
ans = 0
num = np.zeros((10,10))
for i in range(1,n+1):
    ma = i // pow(10,int(math.log10(i)))
    mi = i % 10
    num[mi][ma] += 1
for i in range(10):
    for j in range(10):
        ans += num[i][j] * num[j][i]
print(int(ans))

Measured memory_bytes: 14548
#include<iostream>
using namespace std;
int main(){
  int a,b,c,x;
  cin>>a>>b;
  x=a*b;
  if(x%2==1){
  cout<<"Yes"<<endl;
  }
  if(x%2!=1){
  cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n_ = 5 * 10**5
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod

def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod

def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

def solve():
    n, m = nm()
    s = 0
    v = 1
    for i in range(n+1):
        s = (s + v * nCr(n, i) * nCr(m, i) * fun[i] % mod * (nCr(m-i, n-i) * fun[n-i] % mod)**2) % mod
        v *= -1
    print(s)
    return

solve()


Measured memory_bytes: 48388
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
vector<int> v(4);
string s="+-*";

int cl(int a,int b,int c){
  if(b == 0) return a+c;
  if(b == 1) return a-c;
  return a*c;
}

int solve(int a,int b,int c){
  if(cl(cl(cl(v[0],a,v[1]),b,v[2]),c,v[3]) == 10){
    cout << "(((" << v[0] << " " << s[a] << " " << v[1] << ") " << s[b] << " " << v[2] << ") " << s[c] << " " << v[3] << ")" << endl;
    return 1;
  }
  if(cl(cl(v[0],a,v[1]),b,cl(v[2],c,v[3])) == 10){
    cout << "((" << v[0] << " " << s[a] << " " << v[1] << ") " << s[b] << " (" << v[2] << " " << s[c] << " " << v[3] << "))" << endl; 
    return 1;
  }
  if(cl(cl(v[0],a,cl(v[1],b,v[2])),c,v[3]) == 10){
    cout << "((" << v[0] << " " << s[a] << " (" << v[1] << " " << s[b] << " " << v[2] << ")) " << s[c] << " " << v[3] << ")" << endl; 
    return 1;
  }
  return 0;
}

int judge(){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
	if(solve(i,j,k)) {
	  return 1;
	}
      }
    }
  }
  return 0;
}

int main(){
  while(1){
    v.clear();
    int sum = 0;
    for(int i=0;i<4;i++){
      int a; cin >> a;
      sum += a;
      v.push_back(a);
    }
    if(sum == 0) return 0;
    int flg = 1;
    sort(v.begin(),v.end());
    do{
      if(judge()){
	flg = 0;
	break;
      }
    } while(next_permutation(v.begin(),v.end()));
    if(flg) cout << "0" << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    string s, ans="";
    R s;
    rep(i, s.length()){
        if(s[i] == '9'){
            ans += '1';
        }else{
            ans += '9';
        }
    }
    co(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

const int ma=100001;
vector<bool> prime(ma,true);

void era(){
	prime[0]=false;
	prime[1]=false;
	rep(i,ma){
		if(prime[i]){
			for(int j=i+i;j<ma;j+=i){
				prime[j]=false;
			}
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	era();
	vector<int> l(n);
	vector<int> r(n);
	rep(i,n) cin >> l.at(i) >> r.at(i);
	int cnt=0;
	vector<int> a(ma);
	for(int i=3;i<ma;++i){
		if(prime[i] && prime[(i+1)/2]) a[i]++;
	}
	rep(i,ma-1){
		a.at(i+1)+=a.at(i);
	}
	rep(i,n){
		cout << a.at(r.at(i))-a.at(l.at(i)-1) << endl;
	}
}

Measured memory_bytes: 1792
// inputに入力データ全体が入る
function Main(input) {
    
    input = input.split("\n");
    tmp = input[0].split(" ");

    var masu = parseInt(tmp[0], 10);
    var ryokin_count = parseInt(tmp[1], 10);
    var shoki = parseInt(tmp[2], 10);
    
    var ryokin = input[1].split(" ");

    var right_ryokin = 0;
    var left_ryokin = 0;

    ryokin.forEach(function (value) {
        if (value > shoki){
            right_ryokin ++;
        } else {
            left_ryokin ++;
        }
    });

    if(right_ryokin > left_ryokin) {
        console.log(left_ryokin);
    } else {
        console.log(right_ryokin);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,d;
	bool ng[10]={};
	cin>>n>>k;
	for(int i=0;cin>>d;i++)
		ng[d]=true;
	for(int i=n,i_=n;;++i,i_=i){
		bool ans=false;
		while(i_>0){
			ans|=ng[i_%10];
			i_/=10;
		}
		if(ans)
			continue;
		cout<<i<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i, n) cin >> v[i] >> w[i];

    int h1 = n / 2;
    int h2 = n - h1;
    vector<P> a;
    rep(i, (1 << h2)){
        int ww = 0;
        int vv = 0;
        rep(j, h2){
            if((i >> j) % 2 == 0){
                continue;
            }
            ww += w[h1 + j];
            vv += v[h1 + j];
        }
        a.emplace_back(ww, vv);
    }
    sort(a.begin(), a.end());

    vector<P> s;
    int max = 0;
    rep(i, (int)a.size()){
        if(i < (int)a.size()-1 && a[i].first == a[i+1].first){
            continue;
        }

        if(a[i].second <= max){
            continue;
        }
        max = a[i].second;
        s.push_back(a[i]);
    }

    int ans = 0;
    rep(i, (1 << h1)){
        int ww = 0;
        int vv = 0;
        rep(j, h1){
            if((i >> j) % 2 == 0){
                continue;
            }
            ww += w[j];
            vv += v[j];
        }

        int lo = 0;
        int hi = s.size();
        while(hi - lo > 1){
            int m = (hi + lo) / 2;
            if(s[m].first <= W - ww){
                lo = m;
            }else{
                hi = m;
            }
        }
        if(ww + s[lo].first <= W && ans < s[lo].second + vv){
            ans = s[lo].second + vv;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 19444
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL MOD = (LL)1e9 + 7;
const int MAXK = 4 * 4 * 4;
const int TG = 5;
LL dp[MAXK];
LL tmpdp[MAXK];

int cal(int A, int B, int C) {
    return A * 16 + B * 4 + C;
}
//A, C, G, T
//0. 1. 2, 3

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < MAXK; i++) dp[i] = 1;
    dp[cal(0, 2, 1)] = dp[cal(2, 0, 1)] = dp[cal(0, 1, 2)] = 0;
    for (int i = 0; i < N - 3; i++) {
        for (int j = 0; j < MAXK; j++) tmpdp[j] = dp[j];
        for (int j = 0; j < MAXK; j++) dp[j] = 0;
        for (int j = 0; j < 4; j++) {
            for (int S = 0; S < MAXK; S++) {
                int tmp = S;
                int a3 = tmp % 4;
                tmp /= 4;
                int a2 = tmp % 4;
                tmp /= 4;
                int a1 = tmp % 4;
                if (cal(a2, a3, j) == 9 || cal(a2, j, a3) == 9) continue;
                if (cal(a3, a2, j) == 9 || cal(a1, a3, j) == 9) continue;
                if (cal(a1, a2, j) == 9) continue;
                dp[cal(a2, a3, j)] = (dp[cal(a2, a3, j)] + tmpdp[S]) % MOD;
            }
        }
    }
    LL ans = 0;
    for (int i = 0; i < MAXK; i++) {
        ans = (ans + dp[i]) % MOD;
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> task(N);
  
  for(int i=0;i<N;i++){
    cin >> task.at(i).second >> task.at(i).first;
  }
  sort(task.begin(),task.end());
  
  int time=0;
  bool no=false;
  
  for(int i=0;i<N;i++){
    time += task.at(i).second;
    if(time>task.at(i).first){
      no=true;
      break;
    }
  }
  
  if(no) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string.h>
using namespace std;

const int maxN = 50005;
char s[7][maxN], a[maxN];
int K, ed[7], idx[maxN];
int q[2][maxN], cnt[2], tot[maxN];

bool ok(int t, int idx, int k) {
	for(int i = idx - 1; i >= idx - k; --i) {
		if(i < 1) return 0;
		if(a[i] != s[t][i + k - idx + 1]) return 0; 
	}
	return a[idx] > s[t][k + 1];
}
/*
void print(int k) {
	cout<<k<<"____________________"<<endl; 
	for(int i = 1; i <= ed[k]; ++i) printf("%c", s[k][i]);
	cout << endl;
}*/

int main() {
	scanf("%s", a + 1); scanf("%d", &K);
	int len = strlen(a + 1);
	char ch = 'z';
	//for(int i = 1; i <= len; ++i) ch = min(ch, a[i]);
	for(int i = 1; i <= len; ++i) q[0][++cnt[0]] = i;
	//s[++ed] = ch;
	int nw = 0;
	for(int i = 1; i <= K; ++i) {
		for(int j = 1; j <= ed[i]; ++j) s[i][j] = s[i - 1][j];
		ch = 'z';
		for(int j = 1; j <= cnt[nw]; ++j) ch = min(ch, a[q[nw][j]]);
		for(int j = 1; j <= cnt[nw]; ++j) {
			int t = q[nw][j];
			if(ch == a[t]) {
				if(t < len) q[nw ^ 1][++cnt[nw ^ 1]] = t + 1;
			}
		}
		s[i][++ed[i]] = ch;
		//print(i);
		if(K == i) break;
		if(cnt[nw ^ 1] == 0) {
			for(int k = ed[i] - 1; k >= 0; --k) {
				for(int t = 1; t <= len; ++t) if(ok(i, t, k)) q[nw ^ 1][++cnt[nw ^ 1]] = t;
				if(cnt[nw ^ 1]) {
					ed[i + 1] = k;
					break;
				}
			}
		} else ed[i + 1] = ed[i];
		cnt[nw] = 0; nw ^= 1;
	}
	for(int i = 1; i <= ed[K]; ++i) {
		printf("%c", s[K][i]);
	}
	printf("\n");
	return 0;
}

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


int n,m;
char a[55][55],b[55][55];

int main(){
	cin >> n >> m;
	for(int j=0;j<n;j++)for(int i=0;i<n;i++)cin>>a[j][i];
	for(int j=0;j<m;j++)for(int i=0;i<m;i++)cin>>b[j][i];
	
	bool exist=false;
	
	for(int dy=0;dy<n;dy++){
		for(int dx=0;dx<n;dx++){
			if(dx+m-1>=n or dy+m-1>=n)continue;
			
			bool match=true;
			for(int y=0;y<m;y++){
				for(int x=0;x<m;x++){
					if(a[dy+y][dx+x]!=b[y][x])match=false;
				}
			}
			if(match) exist=true;
		}
	}
	if(exist)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int main()
{
	char c1,c2;
	int len1,len2,len3;
	int count_1 = 0,count_2 = 0;
	while(cin >> len1 >> c1 >> len2 >> c2 >> len3)
	{
		if(len3*len3 == len1*len1 + len2*len2) count_1++;

		if(len1 == len2) count_2++;
	}

	cout << count_1 << endl << count_2 << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,ll>pa;

const int N=2e5+100;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

double pi=acos(-1);
int a[N];
int main()
{
    int n,z,w;
    cin>>n>>z>>w;
    for(int i=1;i<=n;i++) cin>>a[i];
    if(n>1)
    cout<<max(abs(a[n]-w),abs(a[n-1]-a[n]));
    else 
    cout<<abs(a[n]-w);
    return 0;
}



Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll m,d=0,n,h,k,max=-100000,min=1000000000,ans=0,sum=0;
    string s,t;
    cin >> n;
    Vl a(n);

    rep(i,n){
        cin >> a[i];
	}
    rep(i,n-1){
        if(a[i] < a[i+1]){
            if(d==0){
                d=1;
            }
            else if (d==-1){
                ans++;
                d=0;
            }
        }
        else if (a[i] > a[i+1]){
            if(d==0){
                d=-1;
            }
            else if (d==1){
                ans++;
                d=0;
            }
        }
    }
    
    cout << ans+1 << endl;
    return 0;
}
  


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h(n),dp(n,INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;i++) cin>>h[i];
  for(int i=1;i<n;i++){
    for(int j=max(i-k,0);j<i;j++){
      dp[i]=min(dp[i], dp[j]+abs(h[i]-h[j]));
    }
  }
  cout<<dp[n-1];
}

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

int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a < b){
		std::swap(a, b);
	}
	if (b < c){
		std::swap(b, c);
	}
	if (a < b){
		std::swap(a, b);
	}
	return printf("%d\n", b + c), 0;
}

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

const int sz=1e5+50;
vector < int > x[sz];

int main()
{
    int n,m,u,v;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        scanf("%d%d",&u,&v);
        x[u].push_back(v);
    }
    int mn=INT_MAX,ans=0;
    for(int i=1; i<=n; i++)
    {
        if(i==mn)
        {
            ans++;
            mn=INT_MAX;
        }
        if(x[i].size())
        {
            for(auto j : x[i])
            {
                mn=min(mn,j);
            }
        }
    }
    printf("%d\n",ans);
}


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

#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()
#define LL long long
int n,m;
int visited[100000];

void dfs(int v,vector<vector<int>> &g){
  if(visited[v]) return;
  visited[v] = 1;
  REP(i,g[v].size()){
    dfs(g[v][i],g);
  }
}

int main(){
  cin>>n>>m;
  vector<vector<int>> v(n);
  REP(i,m){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  REP(i,n)visited[i]=0;
  int cnt=0;
  REP(i,n){
    if(!visited[i]){
      cnt++;
      dfs(i,v);
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 9216
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashMap <Character,Integer> units = new HashMap<>();
		units.put('m',1000);
		units.put('c',100);
		units.put('x',10);
		units.put('i',1);
		
		HashMap <Integer,Character> uni = new HashMap<>();
		uni.put(1000,'m');
		uni.put(100,'c');
		uni.put(10,'x');
		uni.put(1,'i');
		
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			char [] s1 = sc.next().toCharArray();
			char [] s2 = sc.next().toCharArray();
			int d1 = 0;
			int d2 = 0;
			for(int j=0;j<s1.length;j++) {
				if('2'<=s1[j] && s1[j]<='9') {
					int a = s1[j] - '0';
					char c = s1[j+1];
					d1 += a*(units.get(c));
					j++;
				}else {
					d1 += units.get(s1[j]);
				}
			}
			for(int j=0;j<s2.length;j++) {
				if('2'<=s2[j] && s2[j]<='9') {
					int a = s2[j] - '0';
					char c = s2[j+1];
					d2 += a*(units.get(c));
					j++;
				}else {
					d2 += units.get(s2[j]);
				}
			}
			int sum = d1 + d2;
			String ans = "";
			for(int j=1000;j>=1;j /= 10) {
				int b = sum/j;
				if(b>=2) {
					ans += b;
					ans += uni.get(j);
				}else if(b == 1) {
					ans += uni.get(j);
				}
				sum -= b*j;
			}
			System.out.println(ans);
		}
		
	}
}


Measured memory_bytes: 39084
<?php
  fscanf(STDIN, "%d", $N);
  $A = trim(fgets(STDIN));
  $Arr = explode(' ', $A);
  $count = 0;
  for($i = 1; $i <= $N; $i++){
    $num = intval($Arr[$i-1]);
    while($num % 2 == 0){
      $count++;
      $num /= 2;
    }
  }
  echo $count;
 ?>

Measured memory_bytes: 5392
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

constexpr ll MOD = 1000000007;

int main()
{
  ll n,x;
  cin>>n>>x;
  vector<ll> s(n);
  REP(i,n) cin>>s[i];
  sort(ALL(s));
  vector<ll> dp(x+1);
  dp[x] = 1;
  REP(i,n) {
    vector<ll> tmp(x+1);
    REP(j,x+1) {
      if (dp[j] == 0) continue;
      int cnt = 0;
      REP(k,n) {
        if (s[k] > j) ++cnt;
        else {
          ll next = j%s[k];
          tmp[next] += dp[j];
          tmp[next] %= MOD;
        }
      }
      tmp[j] += dp[j] * (cnt - i);
      tmp[j] %= MOD;
    }
    swap(dp, tmp);
  }
  ll ans = 0;
  REP(i,x+1) {
    ans += i * dp[i];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int counter=0;
  char a[3];
  scanf("%c%c%c",&a[0],&a[1],&a[2]);
  for (int i = 0; i < 3; i++) {
    /* code */
    if(a[i]=='1')counter++;
  }
  std::cout << counter << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(1e9 + 7)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);

    string st;
    cin >> st;

    int n = sz(st), count = 0;

    string toChk = "", prev = "";
    rep(i,n) {
        toChk += st[i];
        if(toChk != prev) {
            count++;
            prev = toChk;
            toChk = "";
        }
    }

    cout << count << '\n';
}

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

int main(){

  int n,m;
  cin>>n>>m;
  int L=0;
  int R=n;
  rep(i,m){

    int l,r;
    cin>>l>>r;
    if(l>L)L=l;
    if(r<R)R=r;
    
  }

  int count=0;
  for(int i=L;i<=R;i++){

    count++;
    
  }
  
  cout<<count<<endl;
}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
	int a[n];
	INPUT(a);
	
	// to +
	s64 cur = 0;
	s64 r0 = 0;
	FOR(i,n) {
		cur += a[i];
		if (i%2) { // -
			if (cur >= 0) {
				r0 += cur+1;
				cur = -1;
			}
		} else {
			if (cur <= 0) {
				r0 += 1-cur;
				cur = 1;
			}
		}
	}
	
	cur = 0;
	s64 r1 = 0;
	FOR(i,n) {
		cur += a[i];
		if (i%2) { // -
			if (cur <= 0) {
				r1 += 1-cur;
				cur = 1;
			}
		} else {
			if (cur >= 0) {
				r1 += cur+1;
				cur = -1;
			}
		}
	}
	
	cout << min(r0,r1) << endl;
	
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

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

    ll N = 50;
    ll count = K/N;

    vector<ll> a(N);
    rep(i,N){

    }
    rep(i,N){
        a[i] = count+i;
    }

    ll remain = K % N;
    while (remain > 0){
        
        sort(a.begin(), a.end());
        rep(i,N){
            if (i == 0){
                a[i] += N;
            }
            else{
                a[i]--;
            }
        }

        remain--;
    }

    cout << N << endl;
    rep(i,N){
        cout << a[i];
        if (i != N-1) cout << " ";
        else cout << "\n";
        //printf("%lld%c", a[i], i==N-1?'\n':' ');
    }
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    int d = Integer.parseInt(str[3]);
    if((a+b)==(c+d))
      System.out.println("Balanced");
    else if((a+b)>(c+d))
      System.out.println("Left");
    else
      System.out.println("Right");
  }
}

Measured memory_bytes: 32532
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, a, m = 1999999999, r = -1999999999;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a);
		r = max(r, a - m);
		m = min(m, a);
	}
	printf("%d\n", r);
}

Measured memory_bytes: 2756
def preParse(u):
    if u == None:
        return
    print(' {}'.format(u), end='')
    preParse(nodes[u][1])
    preParse(nodes[u][2])

def inParse(u):
    if u == None:
        return
    inParse(nodes[u][1])
    print(' {}'.format(u), end='')
    inParse(nodes[u][2])

def printTree(root):
    inParse(root)
    print()
    preParse(root)
    print()

def insert(nodes,z,root):
    x = root
    y = None
    while x != None:
        y = x
        if z < x:
            x = nodes[x][1]
        else:
            x = nodes[x][2]
    nodes[z][0] = y

    if y == None:
        root = z
    elif z < y:
        nodes[y][1] = z
    else:
        nodes[y][2] = z
    return root

def find(nodes,z,root):
    x = root
    while x != None and z != x:
        if z < x:
            x = nodes[x][1]
        else:
            x = nodes[x][2]
    return x

def getMinimum(nodes,x):
    while nodes[x][1] != None:
        x = nodes[x][1]
    return x

def getSuccessor(nodes,x):
    if nodes[x][2] != None:
        return getMinimum(nodes,nodes[x][2])
    
    y = nodes[x][0]
    while y != None and z == nodes[y][2]:
        x = y
        y = nodes[y][0]
    return y

def deleteNode(nodes,z,root):
    # 削除する対象をyとする
    if nodes[z][1] == None or nodes[z][2] == None:
        y = z
    else:
        y = getSuccessor(nodes,z)

    # yの子xを決める
    if nodes[y][1] != None:
        x = nodes[y][1]
    else:
        x = nodes[y][2]

    # xの親を設定する
    if x != None:
        nodes[x][0] = nodes[y][0]

    # yが根の時、xを木の根とする
    if nodes[y][0] == None:
        root = x
    # yがその親pの左の子なら、pの左の子をxとする
    elif y == nodes[nodes[y][0]][1]:
        nodes[nodes[y][0]][1] = x
    # yがその親pの右の子なら、pの右の子をxとする
    else:
        nodes[nodes[y][0]][2] = x
    
    # zの次節点の連結が解除された場合、yにzのデータをコピーし、
    # zに親子がいた場合はその親子に対してzの部分をyで置き換える
    # これによって、zの部分がまるでyに置き換わったように扱え、zが削除されたことになる
    if y != z:
        nodes[y] = nodes[z]
        if nodes[y][0] != None:
            if nodes[nodes[y][0]][1] == z:
                nodes[nodes[y][0]][1] = y
            else:
                nodes[nodes[y][0]][2] = y
        if nodes[y][1] != None:
            nodes[nodes[y][1]][0] = y
        if nodes[y][2] != None:
            nodes[nodes[y][2]][0] = y

    return root


nodes = {}

# {key:[parent,left,right]}

N = int(input())

root = None

for i in range(N):
    order = input().split()
    if order[0] == 'print':
        printTree(root)
        continue

    z = int(order[1])
    if order[0] == 'insert':
        nodes[z] = [None,None,None]
        root = insert(nodes,z,root)
        continue

    if order[0] == 'find':
        k = find(nodes,z,root)
        if k == z:
            print('yes')
        else:
            print('no')
        continue

    if order[0] == 'delete':
        root = deleteNode(nodes,z,root)
        continue



Measured memory_bytes: 77976