akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
namespace mp = boost::multiprecision;
using namespace std;
typedef mp::cpp_int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;


int main(int argc, const char * argv[]) {
   	cin.tie(0); ios::sync_with_stdio(false);
    // source code
    int N,K;
    int R,S,P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    int ret = 0;
    vector<bool> skip(T.size(), false);

    for (int i = 0; i < T.size(); i++) {
        if (i >= K && T[i] == T[i-K] && skip[i - K] == false) {
            skip[i] = true;
        }
        else {
            if (T[i] == 'r') ret += P;
            if (T[i] == 's') ret += R;
            if (T[i] == 'p') ret += S;
        }
    }
    cout << ret << "\n";
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <queue>
#include <ctime>
#define int long long
using namespace std;
int32_t main(){
	string s;
	cin >> s;
	map<char, int> symb;
	for (int i=0; i < s.size(); i++){
		symb[s[i]]++;
	}
	int ans = 1;
	for (int i=0; i < s.size(); i++){
        symb[s[i]]--;
        int number = s.size() - i - 1 - symb[s[i]];
        ans += number;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; cin >> s; ll cnt = 0;

    // xを除いた文字列が回文となっていれば回文にできる
    string t = "";
    rep(i, s.size()) if(s[i] != 'x') t += s[i];

    // 回文判定
    bool ans = true;
    ll rep = t.size()/2+(t.size()%2 == 0 ? 0 : 1);
    if(!t.size()) goto LAST;
    rep(i, rep) if(t[i] != t[t.size()-1-i]) ans = false;

    // 回文にできるなら操作回数を計算
    if(ans){
        // 同じだったら回文かつxを含んでないので操作は0回
        if(s.size() != t.size()){
            // sのうち、tのrepまでの文字が出現するところまでをts,それ以降をttとする。
            ll pos = 0, tpos = 0;
            ll ocCnt = rep;
            while(ocCnt){
                if(s[pos] == t[tpos]){
                    ocCnt--;
                    tpos++;
                }
                if(ocCnt) pos++;
            }
            string ts = s.substr(0, pos);
            if(t.size()%2 == 0){
                pos++;
                while(s[pos] == 'x') pos++;
            }
            string tt = s.substr(pos+1);
            reverse(all(tt));
            ll tsPos = 0, ttPos = 0;
            while(tsPos < ts.size() || ttPos < tt.size()){
                // どちらかが終端にたどり着いていたら
                if(tsPos == ts.size()){
                    ttPos++, cnt++;
                    continue;
                }
                if(ttPos == tt.size()){
                    tsPos++, cnt++;
                    continue;
                }
                if(ts[tsPos] != tt[ttPos]){
                    cnt++;
                    (ts[tsPos] == 'x') ? tsPos++ : ttPos++;
                }
                else tsPos++, ttPos++;
            }
        }
    }
LAST:
    cout << (ans ? cnt : -1) << endl;
}

Measured memory_bytes: 3764
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define maxn 100005
#define mid ((nl+nr)>>1)
using namespace std;
typedef long long ll;
string s,t;
int cnt[300];
int main()
{
	cin>>s>>t;
	int n=s.size(),m=t.size(),ans=m;
	for(int i=0;i<n;i++)
	{
		if(i+m>n) break;
		memset(cnt,0,sizeof(cnt));
		int temp=0;
		for(int j=i;j<i+m;j++)
			if(s[j]!=t[j-i])
				temp++;
		ans=min(ans,temp);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3748
import itertools

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

ans = 0
l = p
for i in range(len(l)-2):
  tmp = sorted([l[i], l[i+1], l[i+2]])
  if tmp[1] == l[i+1]:
    ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int ans = 0;
        if(s.length()%2==0){
            if(s.charAt(s.length()/2-1)!=s.charAt(s.length()/2)){
                System.out.println(s.length()/2);
                return;
            }else{
                s = s.substring(0, s.length()/2) + s.substring(s.length()/2+1);
                ans =1;
            }
        }
        int center = s.length()/2;
        for(int i=1;i+center<=s.length();++i){
            if(i+center==s.length() || s.charAt(center+i)!=s.charAt(center) || s.charAt(center-i)!=s.charAt(center)){
                ans += center + i;
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25836
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define INF 1000000
#define M 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
    fast_io
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    if(x == 0){
      cout<<1<<endl;
    }
    else if(y == 0){
      cout<<2<<endl;
    }
    else if(a == 0){
      cout<<3<<endl;
    }
    else if(b == 0){
      cout<<4<<endl;
    }
    else if(c == 0){
      cout<<5<<endl;
    }
    return 0;
}

Measured memory_bytes: 3616
N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

N += 1

fact = [0] * N
inv = [0] * N
inv_cal = [0] * N

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, N):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    print(comb(R+1, k) * comb(K-1, k-1) % mod)


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

int main(){
  int n,m,l,i,j,k;
  int A[100][100],B[100][100];
  long long C[100][100]={};

  cin>>n>>m>>l;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin>>A[i][j];
    }
  }
  for(i=0;i<m;i++){
    for(j=0;j<l;j++){
      cin>>B[i][j];
    }
  }

  for(i=0;i<n;i++){
    for(k=0;k<l;k++){
      for(j=0;j<m;j++){
	C[i][k]+=A[i][j]*B[j][k];
      }
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      if(j)cout<<" ";
      cout<<C[i][j];
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 3252
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
struct edge {
    int to, cap, rev;// 行先　容量　逆辺
};
vector<edge> g[1010]; bool used[1010];
void add(int u, int v, int f) {
    g[u].push_back(edge{ v,f,(int)g[v].size() });
    g[v].push_back(edge{ u,0,(int)g[u].size() - 1 });
}
int dfs(int pos, int to, int f) {
    if (pos == to) return f;
    used[pos] = 1;
    rep(i, g[pos].size()) {
        if (g[pos][i].cap == 0 || used[g[pos][i].to]) continue;
        int D = dfs(g[pos][i].to, to, min(g[pos][i].cap, f));
        if (D >= 1) {
            g[pos][i].cap -= D;
            g[g[pos][i].to][g[pos][i].rev].cap += D;
            return D;
        }
    }return 0;
}
int max_flow(int s, int t) {
    int F = 0; for (;;) {
        fill(used, used + 1001, 0);
        int F2 = dfs(s, t, (1e9));
        F += F2;
        if (F2 == 0) return F;
    }return inf;
}
int main(void) {
    int h, w; cin >> h >> w;
    vector<string> s(h); // h+w,始点　h+w+1,終点
    rep(i, h) cin >> s[i];
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] != '.') {
                if (s[i][j] == 'S') {
                    add(h+w, i + w , inf);
                    add(h+w, j, inf);
                }
                else if (s[i][j] == 'T') {
                    add(i + w, h + w+1, inf);
                    add(j, h + w+1, inf);
                }
                add(i + w, j, 1);
                add(j, i + w, 1);
            }
        }
    }
    int ans = max_flow(h+w, h + w+1);
    if (ans >= 300) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n,d;
    cin>>n>>d;
    int den = 2*d+1;
    int ans = (n + den - 1) / den;
    cout<<ans<<endl; 
    
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
  	int idx[N] = {};
  	for(int i = 0; i < N -1;i++)
    {
      idx[i+1] = idx[i];
      if(S[i] == 'A' && S[i+1] == 'C') idx[i+1]++;
    }
  	int l,r;
  	while(cin >> l >> r)
    {
      cout << idx[r-1] - idx[l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1488
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
    }
    let mut ans = std::i64::MAX;
    for i in 0..s.len() - 2 {
        let num: i64 = s[i..i + 3]
            .iter()
            .fold(String::new(), |acc, &c| acc + &c.to_string())
            .parse()
            .unwrap();
        if (753 - num).abs() < ans {
            ans = (753 - num).abs()
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

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

int s[100001];
int c[100000];
int n;

int main(){
    cin >> n;
    REP(i, 100001) s[i] = 0;
    REP(i, n){
        int l, r;
        cin >> l >> r;
        s[l-1] += 1;
        s[r] += -1;
    }

    int t = 0;
    REP(i, 100000){
        t += s[i];
        c[i] = t;
    }

    int output = 0;
    REP(i, 100000) output += c[i];
    cout << output << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e9;
ll mod=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
vector<int> graph[205];
int color[205];
int nCk[100][100];
bool bipartite_jugding(int v, int c){
    color[v] = c;
    for(int i = 0; i < graph[v].size(); ++i){
        if(color[graph[v][i]] == c) return false;
        if(color[graph[v][i]] == 0 && !bipartite_jugding(graph[v][i], -c)){
            return false;
        }
    }
    return true;
}

 void combi() {
	for (int i = 0; i <= 99; ++i) nCk[i][0] = 1;
	for (int i = 1; i <= 99; ++i) for (int j = 1; j <= i; ++j) {
		nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % mod;
	}
}

long long expo(ll x,ll n,ll M)
{

    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}
 ll n,k,s;
void solve()
{
    cin>>n>>k>>s;
    int i;
    vector<int> ans(n);
   for(i=0;i<n;i++)
   {
       if(i<k)
        ans[i]=s;
       else if(s==(MAX))
        ans[i]=s-1;
        else
            ans[i]=s+1;
}
for(int i=0;i<n;i++)
    cout<<ans[i]<<" ";



}

int main(){
    boost;
  solve();
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;const int N=2*1e5+10;
int w[N];int d[N];int cnt[20];int res;int n;int st;bool book[N];int sxr[N]; 
int main()
{
    scanf("%d",&n);
    for(int i=1,u,v,va;i<n;i++){scanf("%d%d%d",&u,&v,&va);w[u]^=va;w[v]^=va;}
    for(int i=0;i<n;i++){cnt[w[i]]++;}//贪心 
    for(int i=1;i<=15;i++)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);	
    for(int i=1;i<(1<<15);i++)d[i]=d[i>>1]+(i&1);
    for(int i=1;i<(1<<15);i++)d[i]-=1;//预处理每个dp值的下界 
    for(int i=1;i<(1<<15);i++)
        for(int j=0;j<15;j++)if((i>>j)&1)sxr[i]^=(j+1);//预处理集合的异或和 
    for(int i=1;i<(1<<15);i++)//枚举子集进行转移 
    {
        if(sxr[i]!=0)continue;
        for(int k=(i-1)&i;k;k=(k-1)&i)
            if(sxr[k]==0)d[i]=min(d[i],d[k]+d[i^k]);
    }printf("%d",res+d[st]);return 0;
}

Measured memory_bytes: 2368
N = int(raw_input())
A = []
for i in range(0,N):
  A.append(int(raw_input()))
A = list(enumerate(A))
A = sorted(A, key=lambda x: x[1])
max_A = A[N-1][1]
second_max_A = A[N-2][1]
A = sorted(A,key=lambda x: x[0])
for i in range(0,N):
  if A[i][1] == max_A:
    print second_max_A
  else:
    print max_A


Measured memory_bytes: 37020
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;
	string s;
	ll total=1;
	char d[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int t[26]={};

	cin>>n;
	cin>>s;

	rep(i,s.size()){
		rep(j,26){
			if(s[i]==d[j])t[j]++;
		}
	}
	rep(j,26){
		if(t[j]>0)total*=(t[j]+1);
		total%=1000000007;
	}
	total+=1000000007;
	total--;
	total%=1000000007;
	cout<<total<<endl;
	return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807


void solve(void)
{ 

  double a,b,C;
  cin>>a>>b>>C;

  double Ang = C/360 *2 *M_PI;

  double S = 0.5*a*b*sin(Ang);
  double c =sqrt(a*a + b*b - 2*a*b*cos(Ang));
  cout<<fixed;
  cout<<setprecision(6);
  double h = S*2/a;
  // cout<<c<<endl;
  cout<<S<<endl;
  cout<<a+b+c<<endl;
  cout<<h<<endl;


  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3568
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mInt = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000



int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector A(N,vector<long long>(N));
	
	rep(i,N){
		rep(j,N)cin>>A[i][j];
	}
	
	mcf_graph<int,long long> G(2*N+2);
	int from = 2*N,to = 2*N+1;
	
	rep(i,N){
		G.add_edge(from,i,K,0);
		G.add_edge(N+i,to,K,0);
		G.add_edge(i,to,K,Inf);
		rep(j,N){
			G.add_edge(i,N+j,1,Inf-A[i][j]);
		}
	}
	
	pair<int,long long> ret = G.flow(from,to);
	
	cout<<(long long)Inf*N*K-ret.second<<endl;
	
	auto E = G.edges();
	
	vector<string> ans(N,string(N,'.'));
	
	rep(i,E.size()){
		if(E[i].flow==0)continue;
		if(E[i].from==from)continue;
		if(E[i].to==to)continue;
		ans[E[i].from][E[i].to-N]='X';
	}
	
	rep(i,N)cout<<ans[i]<<endl;
	
    return 0;
}

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

int main()
{
  string s;
  int cnt = 0;
  int size = 0;
  cin >> s;
  size = s.size();
  cnt = size - 2;
  cout << s[0] << cnt << s[size - 1] << endl;
}


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

class DisjoinSet {
public:
    vector<int> parent;
    vector<int> rank;

    DisjoinSet(int size) {
        rank.resize(size, 0);
        parent.resize(size, 0);
        for (int i = 0; i < size; i++) {
            makeSet(i);
        }
    }

    // 要素がxただ1つの新しい集合を作る
    void makeSet(int x) {
        rank[x] = 0;
        parent[x] = x;
    }

    // 要素xが所属する集合の代表を求める
    int findSet(int x) {
        if (parent[x] != x) {
            return findSet(parent[x]);
        } else {
            return x;
        }
    }

    // x, yを合併する
    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }

private:
    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            parent[y] = x;
        } else {
            parent[x] = y;
            if (rank[x] == rank[y]) {
                rank[y] += 1;
            }
        }
    }
};

class Edge {
public:
    int source, target, cost;
    Edge(int source, int target, int cost): source(source), target(target), cost(cost) {
    }
    bool operator < (const Edge &e) const {
        return cost < e.cost;
    }
};

int Kruskal(int V, vector<Edge> edges) {
    sort(edges.begin(), edges.end());

    DisjoinSet disjoinSet = DisjoinSet(V);

    for (int i = 0; i < V; i++) {
        disjoinSet.makeSet(i);
    }

    int totalCost = 0;
    for (int i = 0; i< edges.size(); i++) {
        Edge edge = edges[i];
        if (disjoinSet.same(edge.source, edge.target) == false) {
            disjoinSet.unite(edge.source, edge.target);
            totalCost += edge.cost;
        }
    }

    return totalCost;
}

class Point {
public:
    int id, x, y;
    Point(int id, int x, int y): id(id), x(x), y(y) {}
};

bool cmp_x(const Point &p, const Point &another_p) {
    return p.x < another_p.x;
}

bool cmp_y(const Point &p, const Point &another_p) {
    return p.y < another_p.y;
}

int main() {
    int N;
    cin >> N;

    vector<Point> points;


    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        points.push_back(Point(i, x, y));
    }

    vector<Edge> edges;


    sort(points.begin(), points.end(), cmp_x);
    for (int i = 0; i < N - 1; i++) {
        edges.push_back(Edge(points[i].id, points[i+1].id, abs(points[i].x - points[i+1].x)));
    }


    sort(points.begin(), points.end(), cmp_y);
    for (int i = 0; i < N - 1; i++) {
        edges.push_back(Edge(points[i].id, points[i+1].id, abs(points[i].y - points[i+1].y)));
    }

    cout << Kruskal(N, edges) << endl;

    return 0;
}

Measured memory_bytes: 7536
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K, S;
  cin >> N >> K >> S;
  vector<int> vec(N,S-1);
  for(int i=0; i<K; i++){
    vec.at(i) = S;
  }
  if(S == 1){
    for(int i=K; i<N; i++){
      vec.at(i) = 2;
    }
  }
  for(int i=0; i<N; i++){
    cout << vec.at(i);
    if(i != N-1){
      cout << " ";
    }
  }
  cout << endl;
}

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

int main(void){
  int d1, d2, d3, d4, sum;
  cin >> d1 >> d2 >> d3 >> d4;
  sum = d1 + d2 + d3 + d4;
  cout << sum / 60 << endl;
  cout << sum % 60 << endl;
  return 0;
}

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

void push(int);
int pop(void);
int stack[100];
int stacksum=0;

int main(void)
{
  int i,x,y,data1;
  char data[100];
  
  for(i=0;scanf("%s",data)!= EOF;i++){
    
    if(data[0]=='+') {
      x = pop();
      y = pop();
      push(x+y);
    }
    else if(data[0]=='-'){ 
      x = pop();
      y = pop();
      push(y-x);
    }
    else if (data[0] == '*'){
      x = pop();
      y = pop();
      push(x*y);
    }
    else{
      data1 = atoi(data);
      push(data1);
    }
  }
  
  printf("%d\n",stack[0]);
  return 0;
}
void push(int data){
  stack[stacksum]=data;
  stacksum++;
}

int pop(void){
  
  stacksum--;
  return stack[stacksum];
} 

Measured memory_bytes: 548
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();
    sc.close();

    if (S.equals(U)) A--;
    if (T.equals(U)) B--;

    System.out.println(A + " " + B);
  }
}


Measured memory_bytes: 21972
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int h,n;
int a,b;
vpi spells;
int dp[30001];

signed main(){
    I(h); I(n);
    REP(i,n){
        I(a); I(b);
        spells.eb(a,b);
    }
    FOR(i,10001,30001) dp[i] = INT64_MAX;
    FOR(i,10001,10001+h){
        for(auto s: spells){
            dp[i] = min(dp[i], dp[i-s.first] + s.second);
        }
    }
    cout << dp[h+10000] << endl;;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>    
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, k;

int main() {
	cin >> n >> k;
	ll info[2*k+1][2*k+1][2] = {};
	
	ll x, y, c;
	string color;
	for(ll i = 1; i <= n; i++){
		cin >> x >> y >> color;
		c = (color == "W")? 0: 1;
		info[x%(2*k)+1][y%(2*k)+1][c] += 1;
	}
	
	for(ll i = 1; i <= 2*k; i++){
		for(ll j = 1; j <= 2*k; j++){
			info[i][j][0] += info[i][j-1][0]; 
			info[i][j][1] += info[i][j-1][1]; 
		}
	}
	for(ll j = 1; j <= 2*k; j++){
		for(ll i = 1; i <= 2*k; i++){
			info[i][j][0] += info[i-1][j][0]; 
			info[i][j][1] += info[i-1][j][1]; 
		}
	}//cumsum
	/*
	for(ll i = 1; i <= 2*k; i++){
		for(ll j = 1; j <= 2*k; j++){
			cout << info[i][j][0];
		}
		cout << endl;
	}//out
	for(ll i = 1; i <= 2*k; i++){
		for(ll j = 1; j <= 2*k; j++){
			cout << info[i][j][1];
		}
		cout << endl;
	}//out
	*/
	ll max = 0;
	for(ll i = 0; i <= k; i++){
		for(ll j = 0; j <= k; j++){
			ll bufmax = 0;
			bufmax += info[2*k][2*k][0]-info[2*k][j+k][0]-info[i+k][2*k][0]+info[i+k][j+k][0];
			bufmax += info[i+k][j+k][0]-info[i+k][j][0]-info[i][j+k][0]+info[i][j][0];
			bufmax += info[2*k][j][0]-info[i+k][j][0];
			bufmax += info[i][2*k][0]-info[i][j+k][0];
			bufmax += info[i][j][0];
			
			bufmax += info[2*k][j+k][1]-info[2*k][j][1]-info[i+k][j+k][1]+info[i+k][j][1];
			bufmax += info[i+k][2*k][1]-info[i][2*k][1]-info[i+k][j+k][1]+info[i][j+k][1];
			bufmax += info[i+k][j][1]-info[i][j][1];
			bufmax += info[i][j+k][1]-info[i][j][1];
			
			max = (bufmax > max)? bufmax : max;
			//cout << bufmax << endl;
		}
	}
	
	for(ll i = 0; i <= k; i++){
		for(ll j = 0; j <= k; j++){
			ll bufmax = 0;
			bufmax += info[2*k][2*k][1]-info[2*k][j+k][1]-info[i+k][2*k][1]+info[i+k][j+k][1];
			bufmax += info[i+k][j+k][1]-info[i+k][j][1]-info[i][j+k][1]+info[i][j][1];
			bufmax += info[2*k][j][1]-info[i+k][j][1];
			bufmax += info[i][2*k][1]-info[i][j+k][1];
			bufmax += info[i][j][1];
			
			bufmax += info[2*k][j+k][0]-info[2*k][j][0]-info[i+k][j+k][0]+info[i+k][j][0];
			bufmax += info[i+k][2*k][0]-info[i][2*k][0]-info[i+k][j+k][0]+info[i][j+k][0];
			bufmax += info[i+k][j][0]-info[i][j][0];
			bufmax += info[i][j+k][0]-info[i][j][0];
			
			max = (bufmax > max)? bufmax : max;
			//cout << bufmax << endl;
		}
	}
	
	cout << max;
	return 0;
}

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

int main()
{
  std::string s;
  int i, k;
  std::cin >> s >> k;
  for (i = 0; i < s.length() && s[i] == '1'; i++);
  if (i >= k) {
    std::cout << "1" << std::endl;
    return 0;
  }
  std::cout << s[i] << std::endl;
  return 0;
}

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

int main(){
  int n,ans=0;cin>>n;
  if(n>=400&&n<600) ans=8;
  else if(n>=600&&n<800) ans=7;
  else if(n>=800&&n<1000) ans=6;
  else if(n>=1000&&n<1200) ans=5;
  else if(n>=1200&&n<1400) ans=4;
  else if(n>=1400&&n<1600) ans=3;
  else if(n>=1600&&n<1800) ans=2;
  else if(n>=1800&&n<2000) ans=1;

  cout<<ans;
}

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <queue>

using namespace std;

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

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll mod_pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return mod_pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[5100][5100];


int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int x = s.length();

    for(int i = 0; i < 5100; i++){
        for(int j = 0; j < 5100; j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    for(int i = 0; i <= N-1; i++){
        for(int j = 0; j <= N-1; j++){
            dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], 2));
            dp[i+1][max(j-1, 0)] = add(dp[i+1][max(j-1, 0)], dp[i][j]);
        }
    }

//    cout << dp[N][x] << endl;
    cout << mul(dp[N][x], mod_inv(mod_pow(2, x))) << endl;

    return 0;
}

Measured memory_bytes: 205056
#include <iostream>

using namespace std;

#define INF 1<<28

int p;
int n[4];
int v[4] = {10, 50, 100, 500};

int count_coin(int a, int b, int c, int d) {
    int sum = v[0]*a + v[1]*b + v[2]*c + v[3]*d - p;
    if (sum < 0) return INF;
    int change = 0;
    for (int i = 3; i >= 0; i--) {
        int t = sum /v[i];
        sum -= t * v[i];
        change += t;
        if (sum == 0) break;
    }
    return change - (a + b + c + d);
}

int main() {
    bool first = true;
    while (cin >> p, p != 0) {
        for (int i = 0; i < 4; i++) cin >> n[i];

        int min_coin = INF;
        int a, b, c, d;
        for (int i = 0; i <= n[0]; i++) 
            for (int j = 0; j <= n[1]; j++) 
                for (int k = 0; k <= n[2]; k++) 
                    for (int l = 0; l <= n[3]; l++) {
                        int t = count_coin(i, j, k, l);
                        if (min_coin > t) {
                            min_coin = t;
                            a = i, b = j, c = k, d = l;
                        }
                    }

        if (!first) cout << endl;
        else first = false;
        if (a != 0) 
            cout << v[0] << ' ' << a << endl;
        if (b != 0) 
            cout << v[1] << ' ' << b << endl;
        if (c != 0) 
            cout << v[2] << ' ' << c << endl;
        if (d != 0) 
            cout << v[3] << ' ' << d << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;

long gcd(long a, long b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

int main()
{
    int n;
    vector<long> v, g, l, r;
    vector<long>::iterator ans;
    cin >> n;
    v.resize(n);
    g.resize(n);
    l.resize(n);
    r.resize(n);
    for (auto & s : v) cin >> s;

    for (int i = 0; i < n; ++i) {
        if (i == 0) l[i] = 0;
        else if (i == 1) l[i] = v[0];
        else 
            l[i] = gcd(l[i-1], v[i - 1]);

        //cout << "l[" << i << "] : " << l[i] << endl;
    }
    for (int i = n - 1; i >= 0; --i) {
        if (i == n - 1) r[i] = 0;
        else if (i == n - 2) r[i] = v[n - 1];
        else 
            r[i] = gcd(r[i + 1], v[i + 1]);
        //cout << "r[" << i << "] : " << r[i] << endl;
    }
    for (int i = 0; i < n; ++i) {
        g[i] = gcd(l[i], r[i]);
        //cout << g[i] << endl;
    }

    ans = max_element(g.begin(), g.end());
    size_t index = distance(g.begin(), ans);
    cout << g.at(index) << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
const int maxn=1e6+10;
const ll inf=1e12+10;
using namespace std;

ll a[maxn];
ll b[maxn],b1[maxn];
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
int fastpow(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1) ans*=a;
		b>>=1;a*=a;
	}
	return ans;
}
int main()
{
	int T;
	T=1;
	while(T--)
	{
		int n;
		string s;
		int ans=0;
		cin>>n;
		cin>>s;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='A')
			{
				if(s[i+1]=='B' && s[i+2]=='C') ans++,i+=1;	
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
typedef long long ll;
ll INF=(2e18);
ll N,T,Q;
ll A[MAX_N],L[MAX_N],R[MAX_N];
int D[MAX_N],target;

int main(){
  scanf("%lld %lld %lld",&N,&T,&Q);
  for(int i=1;i<=N;i++){
    scanf("%lld %d",&A[i],&D[i]);
  }
  L[1]=-INF;
  for(int i=2;i<=N;i++){
    if(D[i]==D[i-1])L[i]=L[i-1];
    else L[i]=(A[i]+A[i-1])/2;
  }
  R[N]=INF;
  for(int i=N-1;i>=1;i--){
    if(D[i]==D[i+1])R[i]=R[i+1];
    else R[i]=(A[i]+A[i+1])/2;
  }
  while(Q--){
    scanf("%d",&target);
    ll ans=A[target];
    if(D[target]==1){
      ans=min(ans+T,R[target]);
    }else{
      ans=max(ans-T,L[target]);
    }
    printf("%lld\n",ans);
  }
  return 0; 
}

Measured memory_bytes: 3920
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val words = (1..n).map { readLine()!! }
    val isValid = words.size == words.toSet().size &&  (1 until n).all { words[it][0] == words[it-1].last() }
    println(if(isValid) "Yes" else "No")
}



Measured memory_bytes: 38716
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int N, M;
vector<vector<int>> G;

vector<int> dp;

int DFS(int curr)
{
    if (dp[curr] >= 0) return dp[curr];

    int res = 0;
    for (const int next : G[curr])
    {
        chmax(res, DFS(next) + 1);
    }
    return dp[curr] = res;
}

void _main()
{
    cin >> N >> M;
    G.resize(N);
    rep(i, 0, M)
    {
        int x, y;
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
    }

    dp.assign(N, -1);

    int ans = 0;
    rep(i, 0, N)
    {
        if (dp[i] >= 0) continue;
        chmax(ans, DFS(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int cnt = 0;
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '2') cnt++;
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
import sys

n = int(input())
h = list(map(int, input().split()))
arr = [0]*100010

for i in range(n):
    arr[i] = h[i]

dp = [sys.maxsize]*100010
dp[0] = 0

for i in range(1, n):

    dp[i] = min(dp[i], dp[i - 1] + abs(arr[i] - arr[i - 1]))

    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(arr[i] - arr[i - 2]))

print(dp[n-1])


Measured memory_bytes: 13980
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  
  vector<int> d(3);
  int ans = 0;

  for(int i=0;i<3;i++){
    cin >> d[i];
  }
  
  while(d[0] != d[1] || d[1] != d[2] || d[2] != d[0]){
    sort(d.begin(), d.end());

    if(d[1] != d[2]){
      d[0]++;
      d[1]++;
    } else {
      d[0] += 2;
    }
    
    ans++ ;
  }
  
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define N 100010
ll n,s[N];
ll solve(ll k){
  vector<ll> L,R;
  for(int i=0;i<n;i+=k)L.push_back(s[i]);
  for(int i=n-1;i>=0;i-=k)R.push_back(s[i]);
  ll ans=0,sum=0;
  for(int i=0;i<L.size()&&i<R.size();i++){
    if((n-1-i*k)%k==0&&(n-1-i*k)<=i*k)break;
    sum+=L[i]+R[i];
    if(n-1-i*k>k) ans=max(ans,sum);
  }
  return ans;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>s[i];
  ll ans=0;
  for(int k=1;k<n;k++){
    ans=max(ans,solve(k));
  }
  cout<<ans<<endl;
  return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, K;
int p;
double ex[200100];

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

    std::cin >> N >> K;

    for(int i=0;i<N;++i){
        std::cin >> p;
        ex[i] = 0.5 * (p + 1);
    }

    for(int i=N-1;i>=0;--i){
        ex[i] += ex[i+1];
    }

    double mx = 0;

    for(int i=0;i+K<=N;++i){
        mx = std::max(mx, ex[i] - ex[i+K]);
    }

    printf("%.10f\n", mx);
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  vector<ll> list(N);

  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list[i] = v;
  }

  vector<ll> cul_sum(N + 1);
  vector<ll> cul_xor(N + 1);

  ll s = list[0];
  ll x = list[0];

  cul_sum[1] = s;
  cul_xor[1] = x;

  for (ll i = 1; i < N; i++) {
    s += list[i];
    x = x ^ list[i];
    cul_sum[i + 1] = s;
    cul_xor[i + 1] = x;
  }

  ll ans = 0;

  ll l = -1;
  ll r = -1;
  for (;;) {
    l++;
    if (l > r) {
      r = l;
    }

    if (l >= N) {
      break;
    }

    ll width = 0;
    for (;;) {
      ll s = cul_sum[r + 1] - cul_sum[l];
      ll x = cul_xor[r + 1] ^ cul_xor[l];
      if (x != s) {
        r--;
        break;
      }
      width = r - l + 1;

      r++;
      if (r >= N) {
        r--;
        break;
      }
    }
    ans += width;
  }

  cout << ans << endl;
}


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

int main(){
  string S; cin >> S;
  vector<int> h ={0};
  int N = S.size();
  for(int i = 0; i < N; ++i){
    int tmp = h[i];
    switch(S[i]){
      case '\\':
        h.push_back(--tmp);
        break;
      case '/':
        h.push_back(++tmp);
        break;
      case '_':
        h.push_back(tmp);
        break;
      default: 
        cout << "Error" << endl;
    }
  }
  vector<int> ans;
  int v=0;
  int cnt=0;
  vector<int>::iterator it = h.begin();
  while(it != h.end()){
    vector<int>::iterator idx = it;
    idx++;
    if(idx == h.end())break;
    if(*it <= *idx){
      it++;
      continue;
    }
    int volume = 0;
    int flag = 0;
    while(*it > *idx && idx != h.end()){
      volume += (*it-*idx);
      // cout << *idx << " ";
      idx++;
      if(idx == h.end())break;
      if(*it == *idx){
        // cout << endl;
        // cout << *it << " " << *idx << endl;
        v += volume;
        cnt++;
        ans.push_back(volume);
        it = idx;
        flag = 1;
        break;
      }
    }
    if(!flag) it++;
  }
  cout << v << endl;
  cout << cnt;
  for(auto a : ans) cout << " " << a; 
  cout << endl;

  return 0;
}



Measured memory_bytes: 3340
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    int ans = 20;
    for(ll i=1;i<=(ll)(sqrt(n)+EPS);++i) {
        if(n % i) continue;
        int k=1;
        ll pow10 = 1;
        while(pow10 <= n/i) {
            ++k;
            pow10 *= 10;
        }
        ans = min(ans, k-1);
    }

    cout << ans << endl;
    
} 


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long LL;
const int MAXN=105;
LL n,a,b,c,d;

int main()
{
    while(cin>>n>>a>>b>>c>>d)
    {
        bool flag=false;
        for(int i=0;i<=n-1;i++)
        {
            if(c*(n-1-i)-d*i<=b-a&&(n-1-i)*d-c*i>=b-a)
            {
                flag=true;
                break;
            }
        }
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


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

using namespace std;

constexpr int Nmax = 100'000;

bool binarySearch(int* array, int value, int n) {
    int left = 0;
    int right = n - 1;
    int center = (left + right) / 2;
    while (array[center] != value) {
        if (left >= right) { return false; }
        if (array[center] > value) {
            right = center - 1;
        } else {
            left = center + 1;
        }
        center = (left + right) / 2;
    }
    return true;
}

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

    int same = 0;

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

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int value;
        cin >> value;
        if (binarySearch(S, value, n)) {
            same++;
        }
    }
    cout << same << endl;

    return 0;
}

Measured memory_bytes: 3488
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    long long k;
    cin >> k;
    vector <vector <int>> a(61, vector <int> (n));
    forn (i, 0, n) {
        cin >> a[0][i];
        a[0][i]--;
    }
    forn (i, 1, 61)
        forn (j, 0, n)
            a[i][j] = a[i - 1][a[i - 1][j]]; 
    int cur = 0;
    forn (i, 0, 61)
        if ((k >> i) & 1)
            cur = a[i][cur];
    cout << cur + 1;
    return 0;
}

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

#define MAX_N 200000

using namespace std;

typedef long long lint;

int n;
lint k;
int a[MAX_N + 1];
int b[MAX_N + 1];

lint rez;

bool pos(lint nrr)
{
    lint ck = 0;
    for(int i = 1; i <= n; i ++)
    {
        lint mx = 0;
        if(b[i] > nrr)
            mx = 0;

        else
            mx = nrr / b[i];

        int nr = a[i];
        if(nr <= mx);

        else
            if(k - ck >= nr - mx)
                ck += nr - mx;

        else
            return 0;
    }

    return 1;
}

lint cautBin()
{
    lint i = 0;
    lint pas = 1LL << 39;
    while(pas != 0)
    {
        //cout << i + pas << "+++\n";
        if(pos(i + pas) == 0)
            i += pas;

        pas >>= 1;
    }

    return i + 1;
}

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

    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];

    for(int i = 1; i <= n; i ++)
        cin >> b[i];

    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1, greater<int>());

    if(pos(0))
    {
        cout << "0\n";

        return 0;
    }

    rez = cautBin();

    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 1792
def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[i+1]
    A[i+1] = A[r]
    A[r] = tmp
    return i+1
def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q-1)
        quick_sort(A, q+1, r)
def check_stable(C1, C2):
    C_order_table = {}
    sorted_C_order_table = {}
    for i in range(len(C1)):
        if C_order_table.get(C1[i][1]):
            C_order_table[C1[i][1]] += C1[i][0]
        else:
            C_order_table[C1[i][1]] = C1[i][0]
        
        if sorted_C_order_table.get(C2[i][1]):
            sorted_C_order_table[C2[i][1]] += C2[i][0]
        else:
            sorted_C_order_table[C2[i][1]] = C2[i][0]
    
    is_stable = True
    for key in C_order_table.keys():
        if C_order_table.get(key) != sorted_C_order_table.get(key):
            is_stable = False
            break
    
    if is_stable:
        print('Stable')
    else:
        print('Not stable')
n = int(input())
A = []
for i in range(n):
    c_and_num = input().split(' ')
    c = c_and_num[0]
    num = int(c_and_num[1])
    A.append((c, num))
original_A = A.copy()
quick_sort(A, 0, n-1)
check_stable(original_A, A)
for c, num in A:
    print(c, num)


Measured memory_bytes: 22752
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll xorsum(ll x){
  ll res=x%4;
  if(res==0)return x;
  else if(res==1)return 1;
  else if(res==2)return (ll)x^1;
  else return 0;
}

int main(){
  ll a,b;
  cin >> a >> b;
  cout << (ll)(xorsum(b) ^ xorsum(a-1)) << endl;
return 0;}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string S;
	cin >> S;
	if (n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	if (S.substr(0, n / 2 ) == S.substr(n / 2 , n / 2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, A , B = list(map(int,input().split()))
BR_set, r_ball  = divmod(N, A+B)
blue_num1 = BR_set * A
if r_ball > A:
    blue_num2 = A
else:
    blue_num2 = r_ball
blue_num = blue_num1 + blue_num2
print(blue_num)

Measured memory_bytes: 2940
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

A,B,C = map(int,input().split())

if A == B:
    print("%d"%(C))
elif A == C:
    print("%d"%(B))
else:
    print("%d"%(A))

Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
	string s;
	while(cin>>s){
		if(s[0]=='0')break;
		int a=0,b=0;
		r(i,1,s.size()){
			if(s[i]=='A')a++;
			else b++;
		}
		if(a>b)a++;
		else b++;
		cout<<a<<' '<<b<<endl;
	}
}

Measured memory_bytes: 3096