akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vei a(n);
    map<int, int> cnt;
    for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; }
    if (cnt[0] == n) { cout << "Yes" << endl; return 0; }
    if (n % 3 != 0) { cout << "No" << endl; return 0; }
    vei all;
    for (auto& p : cnt) {
        for (int i = 0; i < p.second / (n / 3); i++) {
        all.push_back(p.first);
        }
    }
    if (all.size() == 3 && (all[0] ^ all[1] ^ all[2]) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4224
fn main() {
    let n: usize = read();
    let mut v: Vec<usize> = (0..n).map(|_| read()).collect();
    let mut ans: u32 = 0;
    v.insert(0,0);
    for i in 0..n {
        if v[i] == v[ i + 1] {
            v[i + 1] = 0;
            ans += 1;
        }
    }
    println!("{}", ans)
}
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.00001;

int main() {
    int n;
    cin >> n;
    long long *a = new long long[n];
    multiset<long long> b;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b.insert(a[i]);
    }
    sort(a,a+n,greater<>());
    int c = 0;
    for(int i = 0;i < n;i++) {
        if(b.find(a[i]) == b.end()) continue;
        b.erase(b.find(a[i]));
        long long t = 1;
        while(t < a[i]) t = t << 1;
        while(t <= a[i]*2) {
            if(b.find(t-a[i]) != b.end()) {
                c++;
                b.erase(b.find(t-a[i]));
                break;
            }
            t = t << 1;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#define zmin(a,b) a=(a<b&&a>0?a:b)
using namespace std;
int boat[101][101]={0};
int main(){
	int i,j,n,k,s,d,c,f;
	while(cin>>n>>k,n){
		fill( &boat[0][0], &boat[100][100], 0);
		while(k--){
			cin>>f>>s>>d;
			if(f){
				cin>>c;
				zmin(boat[s][d],c);
				boat[d][s]=boat[s][d];
			}else{
				int D[101]={0},v[101]={0};
				for(;!v[d];){
					int mini=-1;
					for(i=1;i<=n;i++) if(boat[s][i]) zmin(D[i],D[s]+boat[s][i]);
					v[s]=1;
					for(i=1;i<=n;i++) if(!v[i]&&D[i]&&(mini<0||D[i]<D[mini])) mini=i;
					if(mini<0)break;
					s=mini;
				}
				cout<<(v[d]?D[d]:-1)<<endl;
			}
		}
	}
}

Measured memory_bytes: 904
def main():
  S = input()
  x = S.count("a")
  y = S.count("b")
  z = S.count("c")
  if max(abs(x - y), abs(y - z), abs(z - x)) <= 1:
    print("YES")
  else:
    print("NO")

if __name__ == "__main__":
  main()

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

int main(){
  long n,g;
  int num = 0,min = 9999999;
  long cost = 0;
  vector<int> kind;
  cin >> n;
  cin >> g;
  kind.resize(n);

  for(int ii = 0; ii < n; ii++){
	cin >> kind.at(ii);
	cost += kind.at(ii);
	if(kind.at(ii) < min){
	  min = kind.at(ii);
	}
	num++;
  }
  //cout << g << "  " << cost << "  "  << min << endl;
  num += (g-cost)/min;
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>      /* printf, scanf, puts, NULL */
#include <cstdlib>     /* srand, rand */
#include <ctime>       /* time */
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>

using namespace std;

const int maxn = 3*100000 + 100;

long long sum;
int n;
int a[maxn];

int main() {

    std::ios::sync_with_stdio(false);
	// freopen("test.txt", "r", stdin);

	scanf("%d",&n);

	for(int i=0; i<3*n; i++) {
		scanf("%d", &a[i]);
	}

	sort(a, a+3*n);

	int j = 3*n-2;
	sum = 0;
	for(int i=0; i<n; i++) {
		sum = sum + (long long)a[j];
		j-=2;
	}
    
    printf("%lld\n", sum);
    
    return 0;
}

Measured memory_bytes: 1408
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

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

int a[110],b[110],c[110];

int main()
{
	int K,n;scanf("%d%d",&K,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int ma=0;
	for (int i=1;i<=n;i++) ma=max(ma,a[i]);
	if (ma<=(K+1)/2) puts("0"); else printf("%d\n",K-1-(K-ma)*2);
	return 0;
}


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

int main() {
  long long N,M;
  cin >> N >> M;
  vector<long long>V(N);
  for(long long i=0; i<N; i++){
    cin >> V[i];
  }
  vector<bool>vec(N,true);
  for(long long i=0; i<M; i++){
    long long A,B;
    cin >> A >> B;
    A--;B--;
    if(V[A] == V[B]){
      vec[A] = false;
      vec[B] = false;
    }
    else if(V[A] < V[B]){
      vec[A] = false;
    }
    else{
      vec[B] = false;
    }
  }
  long long ans = 0;
  for(long long i=0; i<N; i++){
    if(vec[i]){
      ans++;
    }
  }
cout << ans << endl;
}


Measured memory_bytes: 4052
#include <stdio.h>
int main(void) {
    int n, p[100], i, j, c=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&p[i]);
    
    for(i=0;i<n;i++){
        if(p[i]!=i+1){
            for(j=i+1;j<n;j++){
                if(p[j]==i+1){
                    p[j]=p[i];
                    p[i]=i+1;
                    c++;
                }
            }
        }
        if(c==2){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

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

int main(){
    int n, mi=1000000, ma=-1000000;
    long long sum=0;
    cin >> n;
    int i,b;
    for( i = 0; i < n; i ++ ){
        cin >> b;
        mi = min( mi, b );
        ma = max( ma, b );
        sum += b;
    }
    cout << mi << " " << ma << " " << sum << endl;
    return 0;
}


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

int main()
{
    int n;
    std::cin >> n;

    std::vector<int> a(n+1), b(n);
    for (int i = 0; i < n+1; i++) { std::cin >> a[i]; }
    for (int i = 0; i < n; i++) { std::cin >> b[i]; }

    long long k = 0;
    for (int i = 0; i < n; i++) {
        int d = b[i] - a[i];
        if (d <= 0) {
            k += b[i];
        } else {
            k += a[i] + std::min(d, a[i+1]);
            a[i+1] = std::max(0, a[i+1]-d);
        }
    }

    std::cout << k << std::endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n string
	fmt.Scan(&n)

	ss := strings.Split(n, "/")
	y, _ := strconv.Atoi(ss[0])
	m, _ := strconv.Atoi(ss[1])
	// d, _ := strconv.Atoi(ss[2])

	if y > 2019 {
		fmt.Println("TBD")
		return
	}
	if m > 4 {
		fmt.Println("TBD")
		return
	}
	fmt.Println("Heisei")
}


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

int main()
{
    string S;

    cin >> S;

    if(S == "Sunny")   cout << "Cloudy" << endl;
    if(S == "Cloudy")  cout << "Rainy" << endl;
    if(S == "Rainy")   cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
bool check(int);
int main(){
	int n,a,count;
	count=0;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a;
		if(check(a))count++;
	}
	cout<<count<<endl;

	return 0;
}
bool check(int a){
	if(a==2)return true;
	if(a%2==0||a<2)return false;
	int k;
	k=3;
	while(k<=sqrt((float)a)){
		if(a%k==0)return false;
		k+=2;
	}

	return true;
}


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

using namespace std;

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

  string a, b, c;
  cin >> a >> b >> c;
  if (a.back() == b[0] && b.back() == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)


int main() {
  int N,M;
  cin>>N>>M;
  vector<int>A(M);
  vector<int>K(N);
  rep(i,N){
      cin>>K[i];
      vector<int>C(K[i]);
      rep(j,K[i]){
          cin>>C[j];
          A[C[j]-1]++;
      }
  }
  int cnt=0;
  rep(i,M){
      if(A[i]==N){
         cnt++;
      }
  }
  cout<<cnt<<endl;
}



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

bool is_prime[1000000];

int main(){

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	while(true){
		int n;
		cin>>n;

		if(n==0)
			break;

		int count=0;
		for(int i=2;i<=n/2;i++){
			if(is_prime[i]&&is_prime[n-i]){
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0; 
}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll arr[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  ll sum = 0, L = 0, R = 0, XOR = 0;
  ll n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  ll ans = n;
  sum = XOR = arr[0];
  while(L + 1 < n) {
    if(sum == XOR) {
      if(R + 1 < n) {
        ++R;
        sum += arr[R];
        XOR ^= arr[R];
      } else {
        ans += (R - L);
        sum -= arr[L];
        XOR ^= arr[L];
        ++L;
      }
    } else {
      ans += (R - L - 1);
      sum -= arr[L];
      XOR ^= arr[L];
      ++L;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0;}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define dbg(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 100005
//////////////////////////////////////////


int main(){

    string s;
    cin>>s;

     s[0]='2';
     s[1]='0';
     s[2]='1';
     s[3]='8';
    cout<<s;
    done;
}




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

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

	vector<int> a(n);
	for(int i =0;i<n;i++)
		cin>>a[i];
	
	sort(a.begin(),a.end());

	int b,c;
	vector<pair<int,int> > val;
	for(int i =0;i<m;i++){
		cin>>b>>c;
		val.push_back(make_pair(c,b));
	}

	sort(val.begin(),val.end(),greater<pair<int,int> >());

	int i =0;

	for(int j =0;j<val.size();j++){

		bool q = false;
		for(int k = 0;k<val[j].second;k++)
		{

			if(i < n && val[j].first > a[i])
				{a[i] = val[j].first;
				i++;}
			else
				{q = true;break;}
		}
		if(q) 
			break;
	}

	long long sum =0;
	for(int i =0;i<n;i++)
		sum+=a[i];
	cout<<sum;
	return 0;
}

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

#define MAX_N (100)
#define MAX_D (100)

int main(int argc, char *argv[]) {
  int N, d[MAX_N], counted[MAX_D + 1], ans;
  // read inputs
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &d[i]);
  // initialize
  for (int i = 0; i < MAX_D + 1; i++)
    counted[i] = 0;
  // calculate
  ans = 0;
  for (int i = 0; i < N; i++)
    if (!counted[d[i]]) {
      ans++;
      counted[d[i]] = 1;
    }
  // print ans
  printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
using State = string::const_iterator;


int expression(State& begin);
int term(State& begin);
int factor(State& begin);
int number(State& begin);


int expression(State& begin){
	int ret = term(begin);

	while (true){
		if (*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if (*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else {
			break;
		}
	}

	return ret;
}


int term(State& begin){
	int ret = factor(begin);

	while (true){
		if (*begin == '*'){
			begin++;
			ret *= factor(begin);
		}
		else if (*begin == '/'){
			begin++;
			ret /= factor(begin);
		}
		else {
			break;
		}
	}

	return ret;
}


int factor(State& begin){
	int ret;
	if (*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else {
		ret = number(begin);
	}
	return ret;
}


int number(State& begin){
	int ret = 0;

	while (isdigit(*begin)){
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}

	return ret;
}


int main(){
	int n;
	string expr;

	cin >> n;
	cin.ignore();

	for (int i = 0; i < n; i++){
		getline(cin, expr);

		State begin = expr.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}

	return 0;
}

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

int main()
{
  int K, S; cin >> K >> S;
  int res = 0;
  rep(x, K){
    rep(y, K){
        int z = S-(x+y);
        if(z <= K && z >= 0) res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())

st = [input().split() for _ in range(n)]
# print(st)
x = input()

ans = 0
slept = False
for i in range(n):
    if slept:
        ans += int(st[i][1])
    if st[i][0] == x:
        slept = True

print(ans)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 10000000
int main() {
	int i, j, ans, *p, n;
	p = (int*)calloc(N, sizeof(int));
	for (i = 2; i <= (int)sqrt((double)N); ++i) if (!*(p + i)) for (j = 2; j*i < N; j++) *(p + i*j) = 1;
	while (fscanf(stdin,"%d", &n),n!=0) {
		ans = 0;
		for (i = n; i >= 8; i--) if (*(p + i) == 0 && *(p + i - 2) == 0 && *(p + i - 6) == 0 && *(p + i - 8) == 0) { ans = i; break; }
		fprintf(stdout,"%d\n", ans);
	}
	free(p);
	return 0;
}

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

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

    if(s == "AAA" || s == "BBB") cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 256
// This code Write By chtholly_micromaker(MicroMaker)
#include <cstdio>
#include <cctype>
#define int long long
#define reg register
using namespace std;
const int MaxN=100051;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
int a[MaxN];
signed main(void)
{
	int n;rd(n);
	reg bool flg=false;
	for(int i=1;i<=n;++i)
		rd(a[i]);
	for(int i=1;i<n;++i)
	{
		if(a[i]>a[i+1])
		{
			if(flg)
				return puts("No"),0;
			--a[i];
			flg=true;
			if(a[i]>a[i+1])
				return puts("No"),0;
		}
		else if(a[i]<a[i+1])
			flg=false;
	}
	puts("Yes");
	return 0;
}

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

const int nax=1e5+5;
vector<int> edges[nax];
vector<int> in_degree(nax),dist(nax);
bool vis[nax]={false};

void dfs(int x)
{
    vis[x]=true;
    for(int i=0;i<edges[x].size();++i)
    {
        int y=edges[x][i];
        dist[y]=max(dist[y],dist[x]+1);
        in_degree[y]--;
        if(in_degree[y]==0)
        dfs(y);
    }
    
}


int main()
{
    int n,m;
    cin >> n >> m;
    
    int x,y;
    for(int i=0;i<m;++i)
    {
        cin >> x >> y;
        edges[x].push_back(y);
        ++in_degree[y];
    }
    for(int i=1;i<=n;++i)
    {
        if(!vis[i]&& in_degree[i]==0)
        dfs(i);
    }
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        ans=max(ans,dist[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 14156
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	ll n;
	cin >> n;
	if (n % 2 == 0)cout << n;
	else cout << 2 * n;
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  string t=s;
  int cntl=0;
  bool c=false;
  for(int i=0;i<n;i++){
    if(s[i]==s[0]){
      c=false;
      continue;
    }
    else{
      if(!c){
        if(cntl==k){
          break;
        }
        cntl++;
      }
      c=true;
      s[i]=s[0];
    }
  }
  int ansl=0;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      ansl++;
    }
  }
  s=t;
  int cntr=0;
  c=false;
  for(int i=n-1;i>=0;i--){
    if(s[i]==s[n-1]){
      c=false;
      continue;
    }
    else{
      if(!c){
        if(cntr==k){
          break;
        }
        cntr++;
      }
      c=true;
      s[i]=s[n-1];
    }
  }
  int ansr=0;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      ansr++;
    }
  }
  cout << max(ansl,ansr) << endl;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N,M;
    cin>>N>>M;
    vector<vector<ll>> AB(N);
    ll a,b;
    rep(i,M){
        cin>>a>>b;
        --a;--b;
        AB[a].push_back(b);
        AB[b].push_back(a);
    }
    typedef pair<ll,ll> P;
    vector<ll> ans(N);
    ans[0] = -1;
    deque<ll> q;
    q.push_back(0);
    while(!q.empty()){
        a = q.front();
        q.pop_front();
        for(auto v:AB[a]){
            if(ans[v]==0){
                ans[v] = a+1;
                q.push_back(v);
            }
        }
    }
    cout<<"Yes"<<"\n";
    rep(i,N-1){
        cout<<ans[i+1]<<"\n";
    }

	
	return 0;
}

Measured memory_bytes: 12936
#pragma GCC optimize("O3") 

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

typedef long long int           ll;
typedef unsigned long long int  ull;
typedef long double             ld;

typedef pair<int, int>          pii;
typedef pair<ll,ll>             pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<pii>             vpii;
typedef vector<pll>             vpll;

#define test(t)		        int t; cin >> t; while(t--)
#define f(i, a, b)	        for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		        (a).begin(), (a).end()
#define endl 		        "\n"
#define maxvec(vec)             *max_element(all(vec))
#define minvec(vec)             *min_element(all(vec))
#define maxarr(arr)             *max_element(arr, arr + n)
#define minarr(arr)             *min_element(arr, arr + n)
#define deb(x)		        cout << #x << ": " << x << endl;
#define deb2(x,y)	        cout << #x << ": " << x << " ~ " <<  #y << ": " << y << endl;
#define deba(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007
#define PI		3.141592653589793238462643383279502884L

void solve()
{
    ll n;
    cin >> n;
    ll a[n], ans = 0, mx = -1;
    f(i, 0, n)
    {
        cin >> a[i];
        if(i)
        {
            if(a[i - 1] > a[i])
            {
              	ll t = (abs(a[i - 1] - a[i]));
                a[i] += t;
                ans += t;
            }
        }
            
    }
    cout << ans << endl;
}

int main()
{
    fast;
    // test(t)
        solve();
    return 0;
}

Measured memory_bytes: 5212
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<complex>
#include<fstream>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

//
int main()
{
	vector<int>a(9);
	vector<bool>flag(9);

	rep(i, 0, 9) {
		cin >> a[i];
		flag[i] = false;
	}

	int n,x;
	cin >> n;
	rep(i, 0, n)
	{
		cin >> x;
		rep(j, 0, 9)
			if (a[j] == x)flag[j] = true;
	}
	bool ans = 0;
	rep(i, 0, 3)if (flag[3 * i] && flag[3 * i + 1] && flag[3 * i + 2])ans = true;
	rep(i, 0, 3)if (flag[i] && flag[i + 3] && flag[i + 6])ans = true;
	if (flag[0] && flag[4] && flag[8])ans = true;
	if (flag[2] && flag[4] && flag[6])ans = true;
	
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    while(1){
        int a,b;
        cin>>a>>b;
        if(a==0 && b==0)    break;
        else{
            if(a<b) cout<<a<<" "<<b<<endl;
            else    cout<<b<<" "<<a<<endl;
        }
    }
    return 0;
}


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

int main(){

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

    string s;
    cin >> s;

    if(s[2] == s[3] && s[4] == s[5])
    cout << "Yes" ;

    else
    cout << "No";

    return 0;

}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s;
  cin >> s;
  int n = s.size();

  int cnt = 0;
  bool flag1 = true;
  while(flag1){
    flag1 = false;
    for(int i=0; i<n; ++i){
      if(s[i]=='1' && s[i+1]=='0'){
        cnt += 2;
        s.erase(i,2);
        flag1 = true;
      }

      if(s[i]=='0' && s[i+1]=='1'){
        cnt += 2;
        s.erase(i,2);
        flag1 = true;
      }
    }
      n = s.size();
  }
  cout << cnt << endl;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

long long mod_pow(long long x, long long n) {
    long long a = 1LL;
    while (n) {
        if (n%2) a = ((a)*(x));
        x = ((x)*(x));
        n /= 2LL;
    }
    return a;
}

int main() {
    ll X;
    cin >> X;
    for (int i = 0; i <= 3000; ++i) {
        ll A = mod_pow(i, 5);
        for (int j = -3000; j <= 3000; ++j) {
            if (A == X + mod_pow(j, 5)) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(std::string S){
	bool can = true;
	ll y = stoi(S.substr(0,4));
	ll m = stoi(S.substr(5,2));
	if (y>2019) can = false;
	else if (m>4) can = false;
	if (can) cout << "Heisei" << "\n";
	else cout << "TBD" << "\n";
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
// int BinarySearch(int key,int n,int S[]){
//     int l=0,r=n;
//     while(r-l>1){
//         int mid=(l+r)/2;
//         if(S[mid]>key)r=mid;
//         else l=mid;
//     }
//     return S[l]==key?1:0;
// }
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8


int main() {
    char S[100];cin >> S;
    int k=100000;
    rep(i,strlen(S)-2){
        if(k>abs(753-(ctoi(S[i])*100+ctoi(S[i+1])*10+ctoi(S[i+2])*1))){
            k=abs(753-(ctoi(S[i])*100+ctoi(S[i+1])*10+ctoi(S[i+2])*1));
        }
    }
    cout << k << endl;
}

Measured memory_bytes: 760
import sys
import numpy as np
input = sys.stdin.readline

D = int(input())
C = np.array(list(map(int,input().split())),dtype=np.int)
S = [list(map(int,input().split())) for i in range(D)]

sumC = sum(C)
def score(strategy):
    sat = 0
    last = np.zeros(26).astype(np.int)
    for i,ind in enumerate(strategy):
        last += 1
        last[ind] = 0
        sat -= np.sum(C * last)
        sat += S[i][ind]
    return sat

#first = [np.argmax(ds) for ds in S]
first = [i % 26 for i in range(D)]

ans = first
now_score = score(ans)

for i in range(2):
    #samples = np.random.randint(0,26,size=D).tolist()
    for d in range(D):
        temp = ans[:]
        temp[d] = np.argmax(S[d])
        #temp[d] = samples[d]
        new_score = score(temp)
        if new_score > now_score:
            now_score = new_score
            ans = temp

for a in ans:
    print(a+1)



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

#define ll long long
#define ld long double

using namespace std;

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

void dfs(ll v, vector <ll> &p, vector <bool> &used, vector <ll> &c) {
    if(used[v])
        return;
    used[v] = true;
    c.push_back(v);
    dfs(p[v] - 1, p, used, c);
}

ll get(vector <ll> &v, ll num) {
    ll n = v.size();
    ll ans = -INF;
    for(int start = 0; start < n; ++start) {
        ll done = 0;
        ll now = 0;
        ll id = start;
        while(done != num) {
            ++done;
            now += v[id];
            id = (id + 1) % v.size();
            ans = max(ans, now);
            now = max(now, (ll) 0);
        }
    }
    return ans;
}

signed main() {
    ll n, k;
    cin >> n >> k;
    vector <ll> p(n), c(n);
    for(int i = 0; i < n; cin >> p[i++]);
    for(int i = 0; i < n; cin >> c[i++]);
    vector <vector <ll>> cs;
    vector <ll> val;
    vector <bool> used(n, false);
    for(int i = 0; i < n; ++i) {
        if(!used[i]) {
            vector <ll> ci;
            dfs(i, p, used, ci);
            ll v = 0;
            for(int j = 0; j < ci.size(); ++j) {
                ci[j] = c[ci[j]];
                v += ci[j];
            }
            cs.push_back(ci);
            val.push_back(v);
        }
    }
    ll ans = -INF;
    for(int i = 0; i < cs.size(); ++i) {
        if(val[i] > 0) {
            ll num = (k / cs[i].size());
            if(num == 0) {
                ans = max(ans, get(cs[i], k));
            }
            else {
                --num;
                ans = max(ans, get(cs[i], cs[i].size() + (k % cs[i].size())) + (num) * val[i]);
            }
        }
        else {
            ans = max(ans, get(cs[i], min((ll) cs[i].size(), k)));
        }
    }
    cout << ans;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        n = 1;
        int arr[5];
        for(int j=0;j<5;j++)
        {
            cin>>arr[j];
            if(arr[j]==0)
            {
                cout<<j+1<<"\n";
                break;
            }
        } 
    }
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
int n,m,k,a[210],b[210],c[210],i,j;
scanf("%d\n%d\n",&n,&m);
for(i=1;i<=n*2;i++){
c[i]=i;
}
for(i=0;i<m;i++){
scanf("%d\n",&k);
if(k==0){
for(j=1;j<=n;j++){
a[j]=c[j];
}
for(j=n+1;j<=n*2;j++){
b[j-n]=c[j];
}
for(j=1;j<=n*2;j++){
if(j%2==1){
c[j]=a[j/2+1];
}
else{
c[j]=b[j/2];
}
}
}
else{
for(j=1;j<=k;j++){
a[j]=c[j];
}
for(j=k+1;j<=n*2;j++){
b[j-k]=c[j];
}
for(j=1;j<=2*n-k;j++){
c[j]=b[j];
}
for(j=2*n-k+1;j<=n*2;j++){
c[j]=a[j-2*n+k];
}
}
}
for(j=1;j<=2*n;j++){
printf("%d\n",c[j]);
}
return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const string YES = "Yes";
const string NO = "No";

int main(){
    ll x;
    cin >> x;
    if(x >= 30){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

namespace tst
{
    class Program
    {
        public static int Gcd(int x, int y, int z)
        {
            int temp = Gcd2(x, y);
            return Gcd2(temp,z);
        }
        public static int Gcd2(int x, int y)
        {
            if (y == 0) return x;
            return Gcd2(y, x % y);
        }
        public static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            int sum = 0;
            for(int i=1; i<=k; i++)
            {
                for(int j=1; j<=k; j++)
                {
                    for(int m=1; m<=k; m++)
                    {
                        sum += Gcd(i, j, m);
                        //Console.WriteLine("({0},{1},{2})={3}",i,j,m,sum);
                    }
                }
            }
            Console.WriteLine(sum);
        }
    }
}

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

int main(){
  int n;
  long long money=1000;
  long long count=0;
  cin >> n;
  vector<int> a(300);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  for(int i=0;i<n-1;i++){
    if(a[i]<a[i+1]){
      count = money/a[i];
      money -= count*a[i];//買う
    }
    money += count*a[i+1];//売る
    count = 0;
  }
  
  cout << money << endl;
}
      
      
  


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int a[55];
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    int res=0;
    for(int i=0; i<k; i++)
        res += a[n-1-i];
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    ll r,d,x; cin >> r >> d >> x;
    ll ans=0;

    REP(i,10){
        ans = r*x-d;
        cout << ans << endl;
        x = ans;
    }

}


Measured memory_bytes: 256
import numpy as np

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

item = [list(map(int,input().split())) for _ in range(N)]

val = np.zeros(W+1,dtype = int)

for i in range(N):
  item_weight = item[i][0]
  val[item_weight :] = np.maximum(val[item_weight :], val[:-item_weight] + item[i][1])
  
print(max(val))

Measured memory_bytes: 15500
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

constexpr ll DIVIDE = 1'000'000'007;

constexpr ll fact(ll n)
{
    if (n == 1) {
        return 1;
    }

    auto res = n * fact(n - 1);
    return res % DIVIDE;
}

void main_()
{
    ll N, M;
    cin >> N >> M;

    if (abs(N - M) >= 2) {
        cout << 0 << "\n";
        return;
    }

    auto ans = (fact(N) * fact(M)) % DIVIDE;
    if (N == M) {
        ans *= 2;
        ans %= DIVIDE;
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define int long long
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("badluckin.txt","r",stdin);
    freopen("badluckout.txt","w",stdout);
    #endif
    
    int n;
    int a,b;
    cin >> n >> a >> b;
    for(int i = a ; i<=b ; i++ ){
      if(i%n==0){
        cout << "OK";
        return 0;
      }
    }
    cout << "NG";
}

Measured memory_bytes: 3636
from math import gcd, sqrt, ceil
from functools import reduce

# def sieve(n):
#     A = list(range(n+1))
#     for i in range(2, n+1 ,2):
#         A[i] = 2
#     for j in range(3, ceil(sqrt(n+1))+1, 2)[::-1]:
#         for i in range(j, n+1, j):
#             A[i] = j
#     return A

# def factorize(n, A):
#     factors = set()
#     while n != 1:
#         f = A[n]
#         factors.add(f)
#         n //= f
#     return factors

def factorize(n):
    factors = set()
    if n % 2 == 0:
        factors.add(2)
        n //= 2
    while n % 2 == 0:
        n //= 2
    for i in range(3, ceil(sqrt(n + 1)) + 1):
        if n % i == 0:
            factors.add(i)
            n //= i
        while n % i == 0:
            n //= i
    if n > 2:
        factors.add(n)
    return factors

_, *aa = map(int, open(0).read().split())

def main(aa):
    pair_co = True
#     A = sieve(10**6)
    all_factors = [0] * (10**6+1)
    for a in aa:
        factors = factorize(a)
#         factors = factorize(a, A)
        for factor in factors:
            if all_factors[factor]:
                pair_co = False
                break
            else:
                all_factors[factor] = 1
        if not pair_co:
            break
    if pair_co:
        return 'pairwise coprime'
    elif reduce(gcd, aa) == 1:
        return 'setwise coprime'
    else:
        return 'not coprime'

print(main(aa))

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

struct node
{
	int key;
	node* lc, * rc;
};

node* root = 0;

void insert(int x)
{
	node* pre = root;        //设当前节点为根，以根为起点
	node* temp = pre;        //用来保存当前节点的临时指针

	node* in = (node*)malloc(sizeof(node));
	in->key = x;
	in->lc = 0;
	in->rc = 0;

	while (pre != 0)        //找到将要插入的节点的父节点(当前节点)
	{
		temp = pre;
		if (in->key < pre->key)
			pre = pre->lc;
		else
			pre = pre->rc;
	}
	pre = temp;

	if (pre == 0)           //插入
		root = in;
	else
	{
		if (in->key < pre->key)
			pre->lc = in;
		else
			pre->rc = in;
	}
}

bool find(int f)
{
	bool fin = false;

	node* pre = root;
	while (pre != 0)
	{
		if (f < pre->key)
			pre = pre->lc;
		else if (f > pre->key)
			pre = pre->rc;
		else
		{
			fin = true;
			break;
		}
			
	}

	return fin;
}

void Inorder(node* r)
{
	if (r->lc != 0)
		Inorder(r->lc);

	cout << " " << r->key;

	if (r->rc != 0)
		Inorder(r->rc);
}

void Preorder(node * r)
{
	cout << " " << r->key;

	if (r->lc != 0)
		Preorder(r->lc);
	if (r->rc != 0)
		Preorder(r->rc);
}

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

	int n, x;
	string p;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p;

		if (p == "insert")
		{
			cin >> x;
			insert(x);
		}
		else if (p == "find")
		{
			cin >> x;
			if (find(x))
				cout << "yes\n";
			else
				cout << "no\n";
		}
		else
		{
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 15688
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  string S;
  cin>>S;
  if(S=="Sunny") cout<<"Cloudy"<<endl;
  else if(S=="Cloudy") cout<<"Rainy"<<endl;
  else cout<<"Sunny"<<endl;
}






Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a, b;
scanf("%d %d", &a, &b);
if(a > b){
printf("a > b\n");
}
else if(a < b){
printf("a < b\n");
}
else if(a == b){
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    string s;
    cin >> s;
    int cnt = 1;
    repi(i,s.size(),1){
        if(s[0] == s[i])cnt++;        
    }
    cout << (cnt == 3 ? "No":"Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int[] A = new int[N];
        int[] C = new int[N+1];
        int[] D = new int[N+1];

        st = new StringTokenizer(br.readLine());

        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(st.nextToken());
            C[A[i]] += 1;
        }

        for(int i = 0; i <= N; i++) {
            D[C[i]] += 1;
        }

        int[] Dk_cumsum = new int[N+1];
        int[] D_cumsum = new int[N+1];

        D_cumsum[N] = D[N];
        for(int k = 1; k <= N; k++) {
            Dk_cumsum[k] = Dk_cumsum[k-1] + k*D[k];
            D_cumsum[N-k] = D_cumsum[N-k+1] + D[N-k];
        }

        int[] f = new int[N+1];
        for(int X = 1; X <= N; X++) {
            if(X == N) {
                f[X] = Dk_cumsum[X] / X;
            } else {
                f[X] = (Dk_cumsum[X] + X * D_cumsum[X+1]) / X;
            }
        }

        for(int K = 1; K <= N; K++) {
            //find X maximal, with K <= f(X)
            int x = 0;
            if(f[1] >= K) {
                if(K <= f[N]) {
                    System.out.println(N);
                } else {
                    for (int b = N; b >= 1; b /=2) {
                        while(K <= f[x+b]) x += b;
                    }
                    System.out.println(x);
                }
            } else {
                System.out.println("0");
            }
        }
    }
}

Measured memory_bytes: 94124
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,M; cin >> N >> M;
    string S; cin >> S;
    reverse(S.begin(),S.end());
    int now = 0;
    vector<int> ans;
    while(true){
        bool ok = false;
        for(int i = min(N,now+M); i >= now+1; i--){
            if(S[i] == '0'){
                ok = true;
                ans.push_back(i-now);
                now = i;
                break;
            }
        }
        if(!ok){
            cout << -1 << endl;
            return 0;
        }
        if(now == N) break;
    }
    reverse(ans.begin(),ans.end());
    rep(i,ans.size()) cout << ans[i] << " ";
    cout << endl;
}



Measured memory_bytes: 1144
def calc(N, B):
    B = [10 ** 6] + B + [10 ** 6]
    r = 0
    for i in range(N):
        r += min(B[i], B[i + 1])
    return r


N = int(input())
B = [int(s) for s in input().split()]
print(calc(N, B))

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
    ll H, W;
    cin >> H >> W;
    map<char, ll> m;
    REP(i, H) {
        string str;
        cin >> str;
        REP(j, W) {
            m[str[j]]++;
        }
    }
    ll cnt4 = 0;
    for(P p : m) {
        cnt4 += p.second / 4;
        p.second %= 4;
    }
    if (H > 1 && W > 1 && cnt4 < ((H / 2) * (W / 2))) {
        PRINT("No");
        return 0;
    }
    if (H % 2 == 0 && W % 2 == 0 && cnt4 == H*W/4) {
        PRINT("Yes");
        return 0;
    }
    ll odd = 0;
    for(P p : m) {
        odd += p.second % 2;
    }
    if (H % 2 == 1 && W % 2 == 1) {
        if (odd == 1) {
            PRINT("Yes");
        } else {
            PRINT("No");
        }
    } else {
        if (odd == 0) {
            PRINT("Yes");
        } else {
            PRINT("No");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll n,p;
string m;

int ctoi(char c){
  if('a'<=c && c<='z')return c-'a' + 36;
  if('A'<=c && c<='Z')return c-'A' + 10;
  return c-'0';
}

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(0);
  cin >> n;
  ll res = 0;
  rep(i,n){
    cin >> p >> m;
    ll val = 0, k = 1;
    for(int j=m.size()-1;j>=0;j--){
      val += k * ctoi(m[j]);
      k *= p;
    }
    res ^= val;
  }
  if(res==0)cout << "lose\n";
  else cout << "win\n";
}

Measured memory_bytes: 1196