akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> stone(n),deg(n),ans;
    vector<vector<int>> to(n);
    for(int i=0; i<n; ++i){
        cin >> stone[i];
    }
    for(int i=0; i<n-1; ++i){
        int a,b;
        cin >> a >> b;
        --a;--b;
        if(stone[a]>stone[b]){
            to[b].push_back(a);
            deg[a]++;
        }else if (stone[a]<stone[b]){
            to[a].push_back(b);
            deg[b]++;
        }
    }
    unordered_set<int> st;
    for(int i=0; i<n; ++i){
        st.insert(i);
    }
    while((int)st.size()>0){
        set<int> to_erase;
        set<pair<int,int>> to_decrease;
        for(auto &x : st){
            if(deg[x]==0){
                to_erase.insert(x);
                for(auto &y : to[x]){
                    ans.push_back(y);
                    to_erase.insert(y);
                    for(auto &z: to[y])to_decrease.insert({y,z});
                }
            }
        }
        for(auto &z: to_decrease)deg[z.second]--;
        for(auto &z: to_erase){st.erase(z);}
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    for(int i=0; i<(int)ans.size(); ++i){
        cout<<ans[i]+1;
        if(i==(int)ans.size()-1)cout <<"\n";
        else cout <<' ';
    }
    return 0;
}



Measured memory_bytes: 768
S=input()
T=input()
memo = [[0]*(len(T)+1) for _ in range(len(S)+1)]

for i in range(1, len(S)+1):
    for j in range(1, len(T)+1):
        if S[i-1] == T[j-1]:
            memo[i][j] = memo[i-1][j-1] + 1
        else:
            memo[i][j] = max(memo[i-1][j], memo[i][j-1])
 
ans = ''
i = len(S)
j = len(T)
while i > 0 and j > 0:
    if memo[i][j] == memo[i-1][j]:
        i-=1
    elif memo[i][j] == memo[i][j-1]:
        j-=1
    else:
        i-=1
        j-=1
        ans = ans + S[i]

ans = ''.join(reversed(ans))
print(ans)

Measured memory_bytes: 112476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, M; cin >> N >> M;
    vector<int> num(N+1, 1), red(N+1, false);
    red[1] = true;

    for(int i=0; i<M; i++){
        int x, y; cin >> x >> y;
        if(red[x] == true) red[y] = true;

        num[x]--;
        num[y]++;

        if(num[x] == 0) red[x] = false;
    }


    int ans = 0;
    for(int i=1; i<=N; i++) if(red[i]) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]

mod = 10 ** 9 + 7
dp = [0] * (1 << n)
dp[0] = 1

for i in range(n):
    dp2 = [0] * (1 << n)
    for j in range(1 << n):
        if dp[j] == 0:
            continue
        for k in range(n):
            if (j >> k) & 1 == 0:
                dp2[j | (1 << k)] += dp[j] * a[i][k]
                dp2[j | (1 << k)] %= mod
    dp = dp2

print(dp[-1])


Measured memory_bytes: 135164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s,t,c,i,j,ans=0,tmax=1e5;
  cin>>n>>m;
  vector<vector<int>> v(m,vector<int>(tmax+1));
  for(i=0;i<n;i++){
    cin>>s>>t>>c;
    v.at(c-1).at(s)++;
    v.at(c-1).at(t)--;
  }
  for(i=0;i<m;i++){
    for(j=1;j<=tmax;j++){
      v.at(i).at(j)+=v.at(i).at(j-1);
      if(v.at(i).at(j-1)==0&&v.at(i).at(j)==1) v.at(i).at(j-1)=1;
    }
  }
  for(j=0;j<=tmax;j++){
    c=0;
    for(i=0;i<m;i++) c+=v.at(i).at(j);
    ans=max(ans,c);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 15336
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  vector<ll> a(100000);
  ll ans = 0;
  rep(i,n) {
    ll t;
    cin >> t;
    a[t-1]++;
    ans += t;
  }
  ll q;
  cin >> q;
  rep(i,q) {
    ll b, c;
    cin >> b >> c;
    ll r = a[b-1];
    a[b-1] = 0;
    a[c-1] += r;
    ans = ans + r*(c-b);
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3984
#include <iostream>
using namespace std;
#define MAX 101

void Insertion_Sort(int n,int array[MAX]){
    for(int j = 1 ; j < n ; j++){
        int key = array[j],i = j - 1;
        while(i >= 0 && array[i] > key){
            array[i+1] = array[i];
            i--;
        }
        array[i+1] = key;
        
        for(int k = 0 ; k < n ; k++){
            if(!k) cout << array[k];
            else cout << " " << array[k];
        }
        cout << endl;
    }
}

int main(){
    int n,array[MAX];
    
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> array[i];
    }
    
    for(int i = 0 ; i < n ; i++){
        if(!i) cout << array[i];
        else cout << " " << array[i];
    }
    cout << endl;
    
    Insertion_Sort(n,array);
    
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
    int dp[101][10001];
    int N,W;
    cin>>N>>W;
    for(int i=0;i<=W;i++){
        dp[0][i] = 0;
    }
    int v,w;
    for(int i=1;i<=N;i++){
        cin>>v>>w;
        for(int j=0;j<=W;j++){
            if(j>=w){
                dp[i][j] = max(dp[i-1][j-w]+v,dp[i-1][j]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}

Measured memory_bytes: 7032
#include <stdio.h>

int main(void)
{
int a, b, c;
scanf("%d %d %d",&a, &b, &c);
if(a <= b && b <= c){
printf("%d %d %d\n",a,b,c);
} else if(a <= c && c <= b) {
printf("%d %d %d\n",a,c,b);
} else if(b <= a && a <= c){
printf("%d %d %d\n",b,a,c);
} else if(b <= c && c <= a){
printf("%d %d %d\n",b,c,a);
} else if(c <= a && a <= b){
printf("%d %d %d\n",c,a,b);
} else if(c <= b && b <= a){
printf("%d %d %d\n",c,b,a);
}
return 0;

}

Measured memory_bytes: 596
fn main() {
    let n = read();
    let mut k: HashSet<String> = HashSet::new();
    for _ in 0..n {
        k.insert(read());
    }
    println!("{}", k.len());
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::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: 15256
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0: break

    x = max(a, b)
    y = min(a, b)

    count = 0
    while 1:
        count += 1
        z = x % y
        x, y = y, z
        if z == 0:
            break

    print(x, count)


Measured memory_bytes: 5608
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
void solveforthiscase(const int & test)
{
int l,r,d;
cin>>l>>r>>d;
vector<int> ans;
for(int i=1;i*d<=200;i++)
ans.pb(d*i);
for(int i=0;i<ans.size();i++)
if(ans[i]<=r && ans[i]>=l)
n++;
cout<<n;









return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
      clock_t start, end;
    start = clock(); 
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    solveforthiscase(i);
    end = clock(); 
    long double t_t = (long double)(end - start) /(long double)(CLOCKS_PER_SEC); 
    cerr << (long double)t_t*1000<< " ms ";
}


Measured memory_bytes: 3740
n = int(input())
arr = list(str(input()))

ans = 0

W_left = 0
R_right = 0
for i in range(n):
    if arr[i] == 'R':
        R_right += 1

ans = [max(W_left,R_right)]
for i in range(n):
    if arr[i] == 'W':
        W_left += 1
    elif arr[i] == 'R':
        R_right -= 1
    ans.append(max(W_left,R_right))
print(min(ans))


Measured memory_bytes: 18216
#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 < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int d;
    cin >> d;
    if(d==25){
        cout << "Christmas" << endl;
    }
    else if(d==24){
        cout << "Christmas Eve";
    }
    else if(d==23){
        cout << "Christmas Eve Eve";
    }
    else{
        cout << "Christmas Eve Eve Eve";
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int t;
int main(int argc, char const *argv[])
{
    cin>>t;
    while(t--)
    {
        long long a,b;
        cin>>a>>b;
        long long now = a*b;
        long long k = sqrt(now);
        long long ans = 0;
        if(k*(k+1)<now)
        {
            ans=(k-1)*2+1;
        }
        else ans = (k-1)*2;
        if(k*k==now&&a!=b)ans--;
        if(a*b==4)ans=1;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

n_ = n = input()

ls = []
for i in range(2, int(math.sqrt(n) + 1)):
    if n % i == 0:
        ls.append(i)
    while n % i == 0:
        n /= i

if n != 1:
    ls.append(n)

ans = 0

for i in range(2 ** len(ls)):
    den = 1
    sign = 1
    for j in range(len(ls)):
        if i & (1 << j):
            den *= ls[j]
            sign *= -1
    ans += n_ / den * sign

print ans


Measured memory_bytes: 5792
#include<stdio.h>
#include<math.h>
int main(){
 int a,b,C;
 double c;
 double S,L,h;

 scanf("%d %d %d",&a,&b,&C);

 S=a*b*sin(C*M_PI/180)/2;
 
 c=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(C*M_PI/180));

 L=a+b+c;

 h=2*S/a;

 printf("%lf\n",S);
 printf("%lf\n",L);
 printf("%lf\n",h);

return 0;
}

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

int a[410][210], dp[410][210][210];

int main() {
	int H, W;
	cin >> H >> W;
	if(H==1 || W==1){
		int sum=0;
		for(int i=0; i<max(H, W); ++i){
			int b;
			cin >> b;
			sum += b;
		}
		cout << sum << endl;
		return 0;
	}
	for(int i=0; i<H; ++i){
		for(int j=0; j<W; ++j){
			cin >> a[i+j][j];
		}
	}
	int ans=a[0][0]+a[H+W-2][W-1];
	dp[1][0][1]=a[1][0]+a[1][1];
	for(int i=1; i<H+W-3; ++i){
		for(int p=0; p<W; ++p){
			for(int q=p+1; q<W; ++q){
				dp[i+1][p][q]=max(dp[i+1][p][q], dp[i][p][q]+a[i+1][p]+a[i+1][q]);
				dp[i+1][p][q+1]=max(dp[i+1][p][q+1], dp[i][p][q]+a[i+1][p]+a[i+1][q+1]);
				dp[i+1][p+1][q+1]=max(dp[i+1][p+1][q+1], dp[i][p][q]+a[i+1][p+1]+a[i+1][q+1]);
				if(p+1<q){
					dp[i+1][p+1][q]=max(dp[i+1][p+1][q], dp[i][p][q]+a[i+1][p+1]+a[i+1][q]);
				}
			}
		}
	}
	cout << ans+dp[H+W-3][W-2][W-1] << endl;
	return 0;
}

Measured memory_bytes: 69888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
     ios_base::sync_with_stdio(false);
      cin.tie(NULL); cout.tie(NULL);
      int a,b,c;
      cin>>a>>b>>c;
      cout<<b+min(c,a+b+1);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;
    string s;
    cin >> s;
    vector<ll> basis(60);
    auto insert = [&](ll x) {
      for (int i = 0; i < 60; ++i) {
        if ((x >> i) & 1) {
          if (!basis[i]) {
            basis[i] = x;
            return true;
          } else
            x ^= basis[i];
        }
      }
      return false;
    };
    bool ans = false;
    for (int i = n - 1; i >= 0; --i) {
      if (s[i] == '0') {
        insert(a[i]);
      } else {
        if (insert(a[i])) {
          ans = true;
          break;
        }
      }
    }
    cout << ans << '\n';
  }

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int n,m;
string str;

int main(void){
	while(cin >> n){
		if(n==0)break;
		scanf("%d",&m);
		cin >> str;
		int res=0;
		int cnt=0;
		for(int i=0;i<m;i++){
			if(str[i]=='I'){
				if(cnt%2==0)cnt++;
				else cnt=1;
				if((cnt-1)/2>=n)res++;
			}
			if(str[i]=='O'){
				if(cnt%2==1)cnt++;
				else cnt=0;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 2144
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int n,a,b,ans=0;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        int x=i;
        int sum=0;
        while(x){
            sum+=x%10;
            x=x/10;
        }
        if(sum>=a&&sum<=b) ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a,b;
    string str;
    char c;
    cin>>a>>str>>b;
    c=str[b-1];
    for(int i=0;i<str.size();i++){
        if(str[i]!=c)
            str[i]='*';
    }
    cout<<str<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

dp = [0] + [abs(h[0] - h[1])] + [1e20] * (N - 2)
for i in range(2, N):
    dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2])

print(dp[-1])

Measured memory_bytes: 86180
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>
#include <math.h>

/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

int main(){

    
    cin >> N;
    double tmp;
    rep(ai,2000){
        M = N - pow(ai,5);
        //cout << M << endl;
        A = pow(abs(M),1.0/5.0) * M/abs(M) * -1;
        tmp = pow(abs(M),1.0/5.0) * M/abs(M) * -1;
        //cout << ai << " " << tmp << " " << A << endl;
        //cout << A-tmp << endl;
        if(abs(A-tmp)<0.0000000001){
            //cout << "SS" << endl;
            cout << ai;
            cout << " ";
            cout << A << endl;
            ai=1000000;
        }
    }
    

}

Measured memory_bytes: 3992
use std::cmp::min;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
   let n = read::<i64>();
   let (a,b) = {
       let t = read_vec::<i64>();
       (t[0],t[1])
   };
   let pn = read_vec::<i64>();
   let first = pn.iter().filter(|&x| *x <= a).count();
   let second = pn.iter().filter(|&x| *x >= a+1 && *x <= b).count();
   let third = pn.iter().filter(|&x| *x >= b+1).count();
    let ans = min(first,min(second, third));
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

int main() {
    int n,a;
    cin >> n >> a;
    cout << (n*n -a) << endl;

}


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

int main(){
	int n; cin >> n; int li[100010] = {};
	for(int i = 0; i < n; i++){
		int a; cin >> a;
		
		li[a]++;
	}
	
	int ma = 0;
	for(int i = 1; i < 100000; i++) ma = std::max(ma, li[i - 1] + li[i] + li[i + 1]);
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    if(a==c) cout<<"No";
    else cout<<"Yes";
  }
  else{
    if(b==c) cout<<"Yes";
    else{
      if(a==c) cout<<"Yes";
      else cout<<"No";
    }
  }
         
  cout<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<29;
vector<int> G[MAX];
stack<pair<int,int>> ST[MAX];
int color[MAX],par[MAX],siz[MAX];
ll ans[MAX],res[MAX],colorsiz[MAX];

void pre(int u,int p){
    siz[u]=1;
    
    if(ST[color[u]].empty()){
        par[u]=-1;
    }
    else par[u]=ST[color[u]].top().se;
    
    for(int to:G[u]){
        if(to==p) continue;
        ST[color[u]].push({u,to});
        
        pre(to,u);
        
        siz[u]+=siz[to];
        ST[color[u]].pop();
    }
    
    if(ST[color[u]].empty()){
        colorsiz[color[u]]-=siz[u];
    }
    
}

void DFS(int u,int p){
    ans[u]=siz[u];
    if(par[u]!=-1) ans[par[u]]-=ans[u];
    for(int to:G[u]){
        if(to==p) continue;
        DFS(to,u);
        res[color[u]]+=ans[to]*(ans[to]+1)/2;
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    for(int i=0;i<N;i++){
        cin>>color[i];
        color[i]--;
    }
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0;i<N;i++) colorsiz[i]=N;
    
    pre(0,-1);
    DFS(0,-1);
    
    for(int i=0;i<N;i++){
        if(color[0]==i) continue;
        res[i]+=colorsiz[i]*(colorsiz[i]+1)/2;
    }
    
    for(int i=0;i<N;i++){
        cout<<N*(N+1)/2-res[i]<<"\n";
    }
    
}


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

int dp[100000+1][3];

struct vacation {
	int a,b,c;
};

int solve(vector<vacation> &v , int i , int n ,int j){

 if(i>n)
 	return 0;
 
 if(dp[i][j]!=-1)
 	return dp[i][j];

 int sol=0;

 if(j==0)
 	dp[i][j] = max( v[i].b + solve(v,i+1,n,1) , v[i].c + solve(v,i+1,n,2) );
 else if(j==1)
     dp[i][j] = max( v[i].a + solve(v,i+1,n,0) , v[i].c + solve(v,i+1,n,2) );
 else
 	dp[i][j] = max( v[i].b + solve(v,i+1,n,1) , v[i].a + solve(v,i+1,n,0) );

 return dp[i][j];

}

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

  	vector<vacation>v(n+1);
  	int x,y,z;

  	for(int i=1;i<=n;i++){

  		cin>>v[i].a;
  		cin>>v[i].b;
		cin>>v[i].c;

  	}

  	for(int i=0;i<=n;i++)
  		for(int j=0;j<3;j++)
  			dp[i][j]=-1;

  		dp[1][0] = v[1].a;
  		dp[1][1] = v[1].b;
  		dp[1][2] = v[1].c;

  int A = v[1].a + solve(v,2,n,0);

  int B = v[1].b + solve(v,2,n,1);

  int C = v[1].c + solve(v,2,n,2);
 
 cout<<max(A,max(B,C))<<endl;


return 0;

}

Measured memory_bytes: 10368
N, H = [int(_) for _ in input().split()]

A = []
B = []
for _ in range(N):
    a, b = [int(_) for _ in input().split()]
    A.append(a)
    B.append(b)

a = max(A)
cnt = 0

for b in sorted(B, reverse=True):
    if b < a:
        break
    H -= b
    cnt += 1
    
    if H <= 0:
        print(cnt)
        exit(0)

cnt += H // a
if H % a != 0:
    cnt += 1
print(cnt)


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

int main(void){
    char n[3];
    cin >> n;
    
    int i;
    for(i = 0; i < 3; i++){
        if(n[i] == '1'){
            cout << 9;
        }else{
            cout << 1;
        }
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
const int N = 2 * 1e5 + 10;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve() {
	ll n;
	cin>>n;
	ll arr[n][3];
	ll dp[n][3];
	for(int i = 0; i < n; i++) {
		for(int j = 0 ; j < 3 ; j++) {
			cin>>arr[i][j];
			dp[i][j] = 0;
		}
	}

	
	for(int i = 0; i < 3; i++) {
		dp[0][i] = arr[0][i];
	}

	for(int i = 1 ; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			if(j == 0) {
				ll xx = max(dp[i-1][1] , dp[i-1][2]);
				dp[i][j] = arr[i][j] + xx;
			}
			if(j == 1) {
				ll xx = max(dp[i-1][0] , dp[i-1][2]);
				dp[i][j] = arr[i][j] + xx;
			}
			if(j == 2) {
				ll xx = max(dp[i-1][0] , dp[i-1][1]);
				dp[i][j] = arr[i][j] + xx;
			}
		}
	}

	cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]));
}
int main()
{
	ll t = 1;
	//cin>>t;
	while(t--) {
		solve();
	}
return 0;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 100000000000007,num[100010];
ll pw(ll a, ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod;
        x /= 2;
    }
    return ret;
}

int main(){
    ll i,j,n,k,ans = 0;
    cin >> k;
    n = 3;
    for(i=k;i>=1;i--){
        num[i] = pw(k/i,n);
        for(j=2*i;j<=k;j+=i){
            num[i] -= num[j];
            if(num[i]<0) num[i] += mod;
        }
    }
    for(i=1;i<=k;i++){
        (ans += i*num[i]%mod) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
int main(){
    int X, A, B;
    cin >> X >> A >> B;
    if((B - A) < 1)
    cout << "delicious" << endl;
    else if(B - A < X + 1)
    cout << "safe" << endl;
    else 
    cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
long long n,  a[2000005];
int main()
{
      ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      cin >> n;
      for (int i=2; i<=n; i++)
      {
            int temp;
            cin >> temp;
            if (i!=temp) a[temp]++;
      }
      for (int i=1; i<=n; i++)
      {
            cout << a[i] << endl;
      }
      return 0;
}


Measured memory_bytes: 5148
#include<iostream>

using namespace std;

int main() {
	int K, N;
	cin >> K >> N;
	int A[300000];
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	int B[300000];
	int max = A[1]-A[0];
	for (int i = 0;i < N-1;i++) {
		B[i] = A[i + 1] - A[i];
		if (max < B[i]) {
			max = B[i];
		}
	}
	if (max < K - A[N - 1] + A[0]) {
		max = K - A[N - 1] + A[0];
	}
	cout << K - max << endl;
	return 0;
}

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

int main(void) {
  string A;
  cin >> A;
  int64_t N = A.size();
  unordered_map<char, int64_t> count;
  rep(i, N) { count[A[i]]++; }
  int64_t answer = 1 + N * (N - 1) / 2;
  for (char c = 'a'; c <= 'z'; ++c) {
    answer -= (count[c] * (count[c] - 1) / 2L);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3708
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC126C
int main(void) {
  double n, k, max, min, ans=0;
  int i=0, cou=0, tmp;
  scanf("%lf %lf", &n, &k);
  max=n+n*1e-8;
  for(min=k-k*1e-10; min >= 0.5; min/=2){
    if(max >= min){
      if(max-(int)max==0)cou=(int) max - (int) min-1;
      else cou=(int) max - (int) min;
      ans+=(double) cou / pow(2, i);
      //printf("max=%lf min=%lf cou=%d ans=%lf\n", max, min, cou,ans);
      max=min-max*1e-8;
    }
    i++;
  }
  printf("%.16lf", ans / n);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<": "<<x<<endl

int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    debug("hogeeeeee");
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a1 = sc.nextInt();
		int a2 = sc.nextInt();
		int a3 = sc.nextInt();

		int min = Integer.MAX_VALUE;
		min = Math.min(min, Math.abs(a2 - a1) + Math.abs(a3 - a2));
		min = Math.min(min, Math.abs(a3 - a1) + Math.abs(a2 - a3));
		min = Math.min(min, Math.abs(a1 - a2) + Math.abs(a3 - a1));
		min = Math.min(min, Math.abs(a3 - a2) + Math.abs(a1 - a3));
		min = Math.min(min, Math.abs(a1 - a3) + Math.abs(a2 - a1));
		min = Math.min(min, Math.abs(a2 - a3) + Math.abs(a1 - a2));

		pr.println(min);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

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

	const int MOD = 1e9 + 7;	
	std::vector<std::vector<i64>> latte(401, std::vector<i64>(401, 1));
	for(int i = 0; i < 400; i++) for(int j = 0; j < 401; j++) latte[i + 1][j] = latte[i][j] * j % MOD;
	for(int i = 0; i < 401; i++) for(int j = 0; j < 400; j++) (latte[i][j + 1] += latte[i][j]) %= MOD;
	
	std::vector<std::vector<i64>> dp(n + 1, std::vector<i64>(c + 1, 0)); dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= c; j++) {
			for(int k = 0; j + k <= c; k++) {
				dp[i + 1][j + k] += dp[i][j] * (latte[k][b[i]] - latte[k][a[i] - 1] + MOD) % MOD;
				dp[i + 1][j + k] %= MOD;
			}
		}
	}
	
	cout << dp[n][c] << endl;
	return 0;
}


Measured memory_bytes: 2816
import heapq
N, M = map(int, input().split())
li = list(map(lambda x:int(x) * (-1), input().split()))
heapq.heapify(li)
for i in range(M):
  max_price = heapq.heappop(li)*(-1)
  heapq.heappush(li, (-1) * (max_price // 2))
print(-sum(li))

Measured memory_bytes: 14256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  	int A, B;
    cin >> A >> B;
    if(A >= 10 || B >=10){
      cout << -1 <<endl;
    }else{
      cout << A*B << endl;
    }
    
  	return 0;
}









Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {
	int a, b;

	cin >> a >> b;
	if (a + b == 15) {
		cout << "+" << endl;
	}
	else if (a*b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 768
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        string[] strinputArray = input.Split(' ');
        int[] intinputArray = Array.ConvertAll<string, int>(strinputArray, delegate (string value) { return int.Parse(value); });
        if (intinputArray[0] < intinputArray[1] && intinputArray[1] < intinputArray[2])
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}
 


Measured memory_bytes: 15952
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();

        if(N%2==0){
            System.out.println("0.5000000000");
        }else{
            int s=N/2+1;
            double ans=(double)s/N;
            System.out.println(String.format("%.10f", ans));
        }

        //END
    }
}



Measured memory_bytes: 23764
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int a,b;
int main() 
{
    int n;
    cin>>n;
    if(n<=999){
    	cout<<"ABC";
    	return 0;
    }else cout<<"ABD";
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    S = SI()
    global ans
    ans = 1
    from collections import Counter
    cnt = Counter(S)
    for n in cnt.values():
        ans = (ans * (n + 1)) % MOD

    ans -= 1
    return ans

print(main())

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int cnt=1 ,a[n+1] ,i ,j;
	for (i=1; i<=n; i++){
		cin >> a[i];
		if (a[i]%2 == 1)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	while(1){
		for (i=1; i<=n; i++){
			a[i] /= 2;
			if (a[i]%2 == 1)
			{
				cout<<cnt<<endl;
				return 0;
			}
		}
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>//万能头文件好 
using namespace std;
int main(){
	int n,k,ai,ans=0;
	scanf("%d%d",&n,&k);
	while(n--){
		scanf("%d",&ai);
		ans+=min(ai-0,k-ai)*2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	char S[5];
	scanf("%s",S);
	int flag = 0;
	for(int i = 0; i < 3; i++){
		if(S[i] == S[i+1])
		{
			flag =1;
			break;
		}
	}
	printf("%s", flag? "Bad":"Good");




}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG

signed main(){
    int N;cin>>N;
    int ans=-N;
    REP(i,N){
        int a;cin>>a;
        ans+=a;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int h, w;
char s[55][55];

signed main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> s[i][j];
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#'&&s[i + 1][j] == '.'&&s[i - 1][j] == '.'&&s[i][j + 1] == '.'&&s[i][j - 1] == '.') {
				cout << "No" << endl;
				ggr
			}
		}
	}
	cout << "Yes" << endl;
	ggr
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func check(s string, d []string) bool {
	for i := 0; i < len(d); i++ {
		if len(s) < len(d[i]) {
			continue
		}

		if s[0:len(d[i])] == d[i] {
			if s == d[i] {
				return true
			}
			return check(s[len(d[i]):], d)
		}
	}
	return false
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	var s string
	fmt.Scan(&s)
	s = reverse(s)

	d := []string{"esare", "resare", "maerd", "remaerd"}

	if check(s, d) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 5888
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;

int change(int a, int m)
{
    int tmp = 1;
    int ret = 0;
    while(a > 0){
        if(a % m >= 10)
            return INF;
        ret += (a % m) * tmp;
        a /= m;
        tmp *= 10;
    }
    return ret;
}

int main()
{
    for(;;){
        int a, b, c;
        cin >> a >> b >> c;
        if(a == -1)
            return 0;

        bool ng = true;
        for(int m=2; m<=16; ++m){
            if(change(a, m) == b)
                ng = false;
        }
        if(ng){
            cout << -1 << endl;
            continue;
        }

        while(++a <= c){
            int b2 = INF;
            for(int m=2; m<=16; ++m){
                int tmp = change(a, m);
                if(b <= tmp && tmp < b2)
                    b2 = tmp;
            }
            if(b2 == INF){
                b = -1;
                break;
            }
            b = b2;
        }

        cout << b << endl;
    }
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

int main() {
    int N, C, K; cin >> N >> C >> K;
    ll T[N]; rep(i, N) cin >> T[i];
    sort(T, T + N);
    int tmp = T[0];
    int cnt = 0;
    int ans = 0;
    rep(i, N) {
        if(tmp + K >= T[i]) {
            ++cnt;
            if(cnt >= C) {
                ++ans;
                cnt = 0;
                if(i + 1 < N) tmp = T[i + 1];
            }
        }else {
            if(cnt > 0) {
                ++ans;
                cnt = 1;
            }
            tmp = T[i];
        }
    }
    if(cnt > 0) ++ans;
    cout << ans << endl;
}


Measured memory_bytes: 1024
from functools import *
from math import *

t = int(input())

@lru_cache(maxsize=None)
def sol(n, a, b, c, d):
    if n == 1: return d
    ans = n * d
    cn = (n + 1) // 2
    fn = n // 2
    if cn: ans = min(ans, sol(cn, a, b, c, d) + abs(cn * 2 - n) * d + a)
    if fn: ans = min(ans, sol(fn, a, b, c, d) + abs(fn * 2 - n) * d + a)
    cn = (n + 2) // 3
    fn = n // 3
    if cn: ans = min(ans, sol(cn, a, b, c, d) + abs(cn * 3 - n) * d + b)
    if fn: ans = min(ans, sol(fn, a, b, c, d) + abs(fn * 3 - n) * d + b)
    cn = (n + 4) // 5
    fn = n // 5
    if cn: ans = min(ans, sol(cn, a, b, c, d) + abs(cn * 5 - n) * d + c)
    if fn: ans = min(ans, sol(fn, a, b, c, d) + abs(fn * 5 - n) * d + c)
    # print(str(n) + ", " + str(ans))
    return ans

for _ in range(t):
    n, a, b, c, d = list(map(int, input().split()))
    sol.cache_clear()
    print(min(d * n, sol(n, a, b, c, d)))


Measured memory_bytes: 12692
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second

signed main(){
    int n;
    cin>>n;
    int ans=1;
    rep(i,3)ans*=n;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

  //even0 even1 odd0 odd1
  vector<int> nums;
  for(int i=0; i<4; i++) nums.push_back(0);
  for(int i=0; i<s.size(); i++){
      if(i%2 == 0){
        if(s.at(i) == '0') nums.at(0) +=1;
        if(s.at(i) == '1') nums.at(1) +=1;
      }else{
        if(s.at(i) == '0') nums.at(2) +=1;
        if(s.at(i) == '1') nums.at(3) +=1;
      }
  }

  int max = -1;
  int maxIdx;
  for(int i=0; i<4; i++){
    if(max < nums.at(i)){
      max = nums.at(i);
      maxIdx = i;
    }
  }


  //even is 0, even is 1, odd is 0, odd is 1
  int ans = 0;
  if(maxIdx == 0){
    ans += nums.at(1);
    ans += nums.at(2);
  }else if(maxIdx == 1){
    ans += nums.at(0);
    ans += nums.at(3);
  }else if(maxIdx == 2){
    ans += nums.at(3);
    ans += nums.at(0);
  }else if(maxIdx == 3){
    ans += nums.at(2);
    ans += nums.at(1);
  }

  cout << ans;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int c = a > b ? b : a;
        List<Integer> d = new ArrayList<>();
        for(int i=1; i<=c; i++) {
            if(a%i == 0 && b%i ==0) {
                d.add(i);
            }
        }
        System.out.println(d.get(d.size()-k));
    }
}

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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream& operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template <typename T>
inline void printV(vector<T>& a, int n) { for(int i=0; i<n; i++) { cerr<<a[i]<<" "; } cerr<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a) { for(int i=0; i<sz(a); i++) { cerr<<a[i]<<"\n"; } cerr<<"\n"; }
template <typename T>
inline void clearVV(vector<vector<T>>& a) { for(auto &x : a) { x.clear(); } a.clear(); }
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val) { for(int i=0; i<sz(a); i++) { a[i].assign(sz(a[i]), val); } }
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n;
	cin>>n;
	multiset<int> ans;
	vi a(n);
	for(int i=0; i<n; i++) {
		cin>>a[i];
		if(sz(ans)==0) {
			ans.insert(a[i]);
			continue;
		}
		auto it = ans.lower_bound(a[i]);
		if(it!=ans.end()) {
			if(it==ans.begin()) {
				ans.insert(a[i]);
				continue;
			}
			it--;
			ans.erase(it);
			ans.insert(a[i]);
			continue;
		}
		it--;
		ans.erase(it);
		ans.insert(a[i]);
	}
	cout<<sz(ans)<<"\n";
    return 0;
}



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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if (N <= 2) {
		cout << -1 << endl;
		return 0;
	}
	if (N == 3) {
		cout << "aa." << endl;
		cout << "..a" << endl;
		cout << "..a" << endl;
		return 0;
	}
	vector<string> S(4, string(4, '.'));
	S[0] = "aacd";
	S[1] = "bbcd";
	S[2] = "cdaa";
	S[3] = "cdbb";
	vector<string> res(N, string(N, '.'));

	if (N % 4 == 0) {
		for (int i = 0; i < N; i += 4) {
			for (int x = 0; x < 4; x++) {
				for (int y = 0; y < 4; y++) {
					res[i + x][i + y] = S[x][y];
				}
			}
		}
	} else if (N % 4 == 1) {
		vector<string> S5(5, string(5, '.'));
		S5[0] = "accbb";
		S5[1] = "add.c";
		S5[2] = "b..dc";
		S5[3] = "b..db";
		S5[4] = "ccaab";
		for (int x = 0; x < 5; x++) {
			for (int y = 0; y < 5; y++) {
				res[x][y] = S5[x][y];
			}
		}
		for (int i = 5; i < N; i += 4) {
			for (int x = 0; x < 4; x++) {
				for (int y = 0; y < 4; y++) {
					res[i + x][i + y] = S[x][y];
				}
			}
		}
	} else if (N % 4 == 2) {
		vector<string> S6(6, string(6, '.'));
		S6[0] = "ab..cc";
		S6[1] = "abcc..";
		S6[2] = "ccab..";
		S6[3] = "..abcc";
		S6[4] = "..ccab";
		S6[5] = "dd..ab";
		for (int x = 0; x < 6; x++) {
			for (int y = 0; y < 6; y++) {
				res[x][y] = S6[x][y];
			}
		}
		for (int i = 6; i < N; i += 4) {
			for (int x = 0; x < 4; x++) {
				for (int y = 0; y < 4; y++) {
					res[i + x][i + y] = S[x][y];
				}
			}
		}
	} else if (N % 4 == 3) {
		vector<string> S7(7, string(7, '.'));
		S7[0] = "a.bb.aa";
		S7[1] = "ab..bb.";
		S7[2] = ".bcc..c";
		S7[3] = "b...a.c";
		S7[4] = "b...ac.";
		S7[5] = ".aa..cb";
		S7[6] = "cc.aa.b";
		for (int x = 0; x < 7; x++) {
			for (int y = 0; y < 7; y++) {
				res[x][y] = S7[x][y];
			}
		}
		for (int i = 7; i < N; i += 4) {
			for (int x = 0; x < 4; x++) {
				for (int y = 0; y < 4; y++) {
					res[i + x][i + y] = S[x][y];
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] << endl;
	}
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	ll a, b;
	cin >> n >> a >> b;
	ll c = a - b;
	vector<ll> h(n);
	REP(i, n)
	{
		cin >> h[i];
	}
	ll mi = 0;
	ll ma = (ll)1e9;
	while (mi != ma) {
		ll mid = mi + (ma - mi) / 2;
		cnt = 0;
		REP(i, n)
		{
			if (h[i] - b * mid > 0) {
				cnt += ((h[i] - b * mid) + (c - 1)) / c;
			}
		}
		if (cnt <= mid) {
			ma = mid;
		} else {
			mi = mid + 1;
		}
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FO(i,a,b) for (int i = (a); i < (b); i++)

int N, M, K;
int main() {
    scanf ("%d %d %d", &N, &M, &K);
    FO (i,0,N+1) {
        FO (j,0,M+1) {
            int am = i*M+j*N-i*j*2;
            if (am == K) {
                printf ("Yes\n");
                return 0;
            }
        }
    }
    printf ("No\n");
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp;
use std::process;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_line(&mut buf);

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    // 入力を受け取る
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();

    let mut num_buy: usize = 0;
    let mut socket: usize = 1;

    while socket < b {
        num_buy += 1;
        socket = a * num_buy - num_buy + 1;
    }

    println!("{}", num_buy);

}

Measured memory_bytes: 4352
(defun calc (x a b n)
  (- (floor (/ (* a x) b))
     (* a (floor (/ x b)))))

(let ((a (read))
      (b (read))
      (n (read)))
     (format t "~A" (if (<= b n)
                        (calc (1- b) a b n)
                        (calc n a b n))))


Measured memory_bytes: 24340