akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
inline int read()
{
	int ans=0;char t=getchar();
	while(t<'0'||t>'9')	t=getchar();
	while(t>='0'&&t<='9')	ans=ans*10+t-'0',t=getchar();
	return ans;
}
const int N=1e5+7;
int a[N],b[N],c[N];
int main()
{
	int n=read();
	for(int i=1;i<=n;i++)	a[i]=read();
	for(int i=1;i<=n;i++)	b[i]=read();
	for(int i=1;i<=n;i++)	c[i]=read();
	std::sort(a+1,a+1+n);
	std::sort(c+1,c+1+n);
	a[0]=-1e9;c[n+1]=1e9+7;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		int ll=0,rr=n;
		long long sum=0;
		while(rr-ll>1)
		{
			int mid=(ll+rr)>>1;
			if(a[mid]>=b[i])	rr=mid-1;
			else ll=mid;
		}
		if(a[rr]>=b[i])	sum=ll;
		else sum=rr;
//		printf("std::%lld ",sum);
		ll=1,rr=n+1;
		while(rr-ll>1)
		{
			int mid=(ll+rr)>>1;
			if(c[mid]<=b[i])	ll=mid+1;
			else rr=mid;
		}
		if(c[ll]<=b[i])	sum*=(long long)(n-rr+1);
		else if(c[rr]<=b[i])	sum=0;
		else sum*=(long long)(n-ll+1);
		ans+=sum;
//		printf("%d %lld\n",i,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll a[99];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortdown(a,n);
	ll ans=a[0]/2;
	rep(i,1,n)ans+=a[i];
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

	li n, m;
	cin >> n >> m;
	vector<li> ar(m);
	li sum=0;
	for(li i=0; i<m; i++)
	{
		cin >> ar[i];
		sum += ar[i];
	}
	if(n-sum<0)
	{
		cout << -1;
	}
	else cout << n-sum;
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll INF = 1e18;
typedef vector<vector<ll>> Matrix;
void warshall_floyd(Matrix& d) {
  ll n = SZ(d);
  REP(i,n) REP(j,n) REP(k,n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}
int main(){
  ll N,M; cin >> N >> M;
  Matrix d = Matrix(N, vector<ll>(N,INF));
  vector<ll> a(M),b(M),c(M);
  REP(i,M){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }
  REP(i,N) d[i][i] = 0;
  warshall_floyd(d);
  
  ll ans = 0;
  REP(i,M){
    if(d[a[i]][b[i]] < c[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
use std::cmp::{max,min};
fn main() {
    let n = rv::<usize>()[0];
    let s = rl();
    let s = s.trim_right().as_bytes();
    let mut t = 0;
    let mut z = vec![0;n];
    for b in 0..n {
        z[b] = n-b;
        let mut i = 1;
        let mut j = 0;
        while i+b<n {
            while i+j+b<n && s[j+b]==s[i+j+b] {
                j+=1;
            }
            z[i+b] = j;
            if j==0 {
                i+=1;
                continue;
            }
            let mut k = 1;
            while i+k+b<n && k+z[k+b]<j {
                z[i+k+b] = z[k+b];
                k+=1;
            }
            i+=k;
            j-=k;
        }
        for i in b..n {
            t = max(t,min(z[i],i-b));
        }
    }
    println!("{}",t);
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T>
  where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 a;
    string s;
    cin >> a >> s;
    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
}


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

int main() {
    string N;cin >> N;
    int flag = 0;
    for (int i = 0;i < 3;i++){
        if (N[i] == '7') flag = 1;
    }
    if (flag == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main(){
	string str;
	cin >> str;
	
	for(int i = 0;i < 4;i++){
		cout << str[i];
	}
	cout << " ";
	for(int i = 0;i < 8;i++){
		cout << str[4+i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,v,w,t;
  cin>>a>>v>>b>>w>>t;
  if(v>w){
    if(abs(a-b)<=t*(v-w)) 
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
  else cout<<"NO"<<endl;
}


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


int main()
{
    auto search = [](const std::vector<int> & vec, int val) {
        int lb = 0;
        int ub = vec.size() -1;
        while (true) {
            if (lb == ub) {
                if (val < vec[lb]) return vec[lb];
                else return -1;
            }
            int pos = (lb + ub) / 2;
            if (val < vec[pos]) {
                ub = pos;
            } else {
                lb = pos + 1;
            }
        }
    };

    std::string s, t;
    std::cin >> s >> t;
    std::vector<std::vector<int> > dic(26);
    for (int i=0; i<s.size(); ++i) {
        dic[s[i] - 'a'].push_back(i);
    }


    long loop = 0;
    int pos = -1;
    for (int i=0; i<t.size(); ++i) {
        int ord = t[i] - 'a';
        std::vector<int> const & d = dic[ord];
        if (d.size() == 0) {
            // not found
            std::cout << -1 << std::endl;
            return 0;
        }
#if 0
        int npos = -1;
        for (int j=0; j<d.size(); ++j) {
            if (pos < d[j]) {
                npos = d[j];
                break;
            }
        }
#else
        int npos = search(d, pos);
#endif
        if (npos == -1) {
            loop += 1;
            npos = d[0];
        }
        pos = npos;
    }
    std::cout << (s.size() * loop + pos + 1) << std::endl;

    return 0;
}

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

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

  int n;
  cin >> n;
  int l = floor(log10(n)) + 1;
  int cnt = 0;
  for (int i = 0; i < l; i += 2) {
    if (i == l - 1) {
      cnt += n - pow(10, i) + 1;
    } else {
      cnt += 9 * pow(10, i);
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
min = 100 * 100
for i in range(n):
    l = sum(w[0:i+1])
    r = sum(w[i+1:n])
    if abs(l-r) < min:
        min = abs(l-r)
print(min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
const ll mod=1e9+7;
ll mpow(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return mpow(x*x%mod,n/2);
    else return x*mpow(x,n-1)%mod;
}
int main(void){
    ll s;
    cin>>s;
    ll f[s+1];
    rep(0,i,s+1)f[i]=0;
    f[0]=1;
    rep(0,i,s+1){
        rep(3,j,s+1){
            if(i+j<=s&&f[i]!=0){
                //cout<<i<<endl;
                f[i+j]=(f[i+j]+f[i])%mod;
                if(i+j==s){
                    //cout<<i<<" "<<j<<endl;
                }
            }
        }
    }
    cout<<f[s]<<endl;
}

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

#define loop(i, n) for(int i = 0; i < n; i++)
#define sloop(i, s, n) for (int i = s; i < n; i++)
#define rloop(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h, c;
    cin >> h >> c;
    int arr[h][c];
    vector<string> s(h, "");
    loop(i, h) cin >> s[i];
    loop(i, h) {
        loop(j, c) {
            if(s[i][j] == '.') {
                int count = 0;
                if(i-1 >= 0 && j-1 >= 0 && s[i-1][j-1] == '#') count++;
                if(i-1 >= 0 && j >= 0 && s[i-1][j] == '#') count++;
                if(i-1 >= 0 && j+1 < c && s[i-1][j+1] == '#') count++;
                if(i >= 0 && j-1 >= 0 && s[i][j-1] == '#') count++;
                if (i >= 0 && j+1 < c && s[i][j+1] == '#') count++;
                if(i+1 < h && j-1 >= 0 && s[i+1][j-1] == '#') count++;
                if(i+1 < h && j >= 0 && s[i+1][j] == '#') count++;
                if(i+1 < h && j+1 < c && s[i+1][j+1] == '#') count++;
                arr[i][j] = count;
            }
        }
    }
    loop(i, h) {
        loop(j, c) {
            if(s[i][j] == '.') cout << arr[i][j];
            else cout << '#';
        } cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  string a, b;
  cin >> a >> b;
  if(a.size()==b.size()){
    if(a==b){
      cout << "EQUAL" << endl;
    }else if(a>b){
      cout << "GREATER" << endl;
    }else{
      cout << "LESS" << endl;
    }
  }else if(a.size()>b.size()){
    cout << "GREATER" << endl;
  }else{
    cout << "LESS" << endl;
  }
  return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<ll> A(N+1), rec(N+1);
  for (ll i = 1; i <= N; i++) cin >> A[i];

  ll cur = 1;
  for (ll i = 0; i < K; i++) {
    if (i == N) {
      ll cyclen = N - rec[cur];
      ll num = (K - N - 1) / cyclen;
      i += num * cyclen;
    }
    rec[cur] = i;
    cur = A[cur];
  }
  cout << cur << endl;

  return 0;
}



Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

#define TOP_NUM 16
#define NOTOP_NUM 10

int main(){
	IO_STREAM;
	int D;	cin>>D;
	vi c(26);
	vector<pair<int,int>>cs(26);
	rep(i,0,26){
		cin>>c[i];
		cs[i].first=c[i];
		cs[i].second=i;
	}
	int s[D][26];
	rep(i,0,D){
		rep(j,0,26){
			cin>>s[i][j];
		}
	}

	sort(all(cs));
	reverse(all(cs));
	vi top(D,1);
	rep(i,0,TOP_NUM){
		top[i]=cs[i].second+1;
	}
	vi notop(D,1);
	rep(i,0,NOTOP_NUM){
		notop[i]=cs[i+TOP_NUM].second+1;
	}

	int cnt=1;
	int nt_idx=0;
	while(1){
		rep(i,0,TOP_NUM){
			cout<<top[i]<<endl;
			cnt++;
			if(cnt>D) return 0;
		}
		rep(i,0,0){
			cout<<notop[nt_idx]<<endl;
			nt_idx++;
			if(nt_idx>=NOTOP_NUM) nt_idx=0;
			cnt++;
			if(cnt>D) return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3668
fun main(args: Array<String>) {
    a107(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a107(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (n, x) = args[0].split(" ").map { it.toInt() }
    println(n - (x - 1))
}

Measured memory_bytes: 38340
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int n,m;
ll x;
ll sum[1<<12][12]={};
ll cost[1<<12]={};

bool check(int num){
    rep(i,m){
        if(sum[num][i]<x){
            return false;
        }
    }
    return true;
}


int main(){
    cin>>n>>m>>x;
    ll c[12];
    ll a[12][12];
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
        }
    }
    
    rep(i,1<<n){
        rep(j,n){
            if((i>>j)&1){
                cost[i]+=c[j];
                rep(k,m){
                    sum[i][k]+=a[j][k];
                }
            }
        }
    }
    ll minc=1200000;
    ll count=0;
    rep(i,1<<n){
        if(check(i)){
            minc=min(minc,cost[i]);
        }else{
            count++;
        }
    }
    if(count==(1<<n)){
        cout<<-1<<endl;
    }else{
        cout<<minc<<endl;
    }
    return 0;
}


Measured memory_bytes: 4020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] candy = new int[2][N];
		for(int i = 0; i < N; i++) {
			candy[0][i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			candy[1][i] = sc.nextInt();
		}
		int havecandy;
		int firstlinecandy = candy[0][0];
		int secondlinecandy = 0;
		for(int i = 0; i < N; i++) {
			secondlinecandy += candy[1][i];
		}
		havecandy = firstlinecandy + secondlinecandy;
		for(int i = 1; i < N; i++) {
			firstlinecandy += candy[0][i];
			secondlinecandy -= candy[1][i - 1];
			havecandy = Integer.max(havecandy, firstlinecandy + secondlinecandy);
		}
		System.out.println(havecandy);
	}

}


Measured memory_bytes: 21844
/* -----KAUN_MEET--------*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
int mod = 1000000007;
#define P get<0>
#define D get<1>
#define T get<2>
#define C get<3>
#define PB push_back

#define MP make_pair
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define F first
#define S second
#define gcd __gcd
#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void __print(int x)
{
    cerr << x;
}
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename Th, typename V>
void __print(const pair<Th, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename Th>
void __print(const Th &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
int n, m;
const int N = 100000 + 5;
vector<int> edge[N];
vector<int> ans;
void dfs(int i)
{
    int pri = 0;
    for (auto it : edge[i])
    {
        if (ans[it] == -1)
        {
            dfs(it);
        }
        pri = max(pri, 1 + ans[it]);
    }
    ans[i] = pri;
}
void binary_rock()
{
    int i, j, k, l;
    cin >> n >> m;
    for (i = 0; i < m; i++)
    {
        cin >> j >> k;
        j--;
        k--;
        edge[j].PB(k);
    }
    ans.assign(n, -1);

    for (i = 0; i < n; i++)
    {
        if (ans[i] == -1)
        {
            dfs(i);
        }
        // cout << i << " " << ans[i] << endl
    }
    // debug(ans);
    cout << *max_element(ans.begin(), ans.end()) << endl;
}

signed main()
{
    fastio
        clock_t t1 = clock();

    int t = 1;
    //cin >> t;

    while (t--)
    {
        binary_rock();
    }

    clock_t t2 = clock();
    // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;
    // cout << CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 8576
// "static void main" must be defined in a public class.
import java.util.*;
public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long a = x%y;
        long p = Math.min(a,y-a);
        
        
        
        System.out.println(p);
    }
}


Measured memory_bytes: 21840
n = int(input())
s = []
for i in range(n):
    s.append(sorted(list(input())))
cnt_ans = 0
s.sort()
cnt = 0
left = 0
right = 1
while right <= n-1:
    if s[left] == s[right]:
        right += 1
        cnt += 1
    else:
        left, right = right, right+1
        cnt_ans += ((cnt+1)*cnt//2)
        cnt = 0
    if right == n:
        cnt_ans += ((cnt+1)*cnt//2)
print(cnt_ans)

Measured memory_bytes: 24652
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

class edge{
public:
	Int cost;
	size_t from, to;
	edge(Int c, size_t f, size_t t){
		cost = c;
		from = f;
		to = t;
	}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
class unionfind{ // 0-indexed
public:
	vector<int> parent;
	vector<size_t> size;
	size_t num_of_disjointsets;
	unionfind(size_t n){
		parent.resize(n, -1);
		size.resize(n, 1);
		num_of_disjointsets = n;
	}

	size_t find(size_t x){
		if(parent[x] == -1) return x;
		return parent[x] = find(parent[x]);
	}

	size_t unite(size_t x, size_t y){
		x = find(x);
		y = find(y);
		if(x == y) return -1;
		if(size[x] < size[y]){
			parent[x] = y;
			size[y] += size[x];
			size[x] = 0;
			--num_of_disjointsets;
			return y;
		}else{
			parent[y] = x;
			size[x] += size[y];
			size[y] = 0;
			return x;
			--num_of_disjointsets;
		}
	}

	bool united(size_t x, size_t y){
		return find(x) == find(y);
	}
};
bool operator < (const edge &e, const edge &f){
	return e.cost != f.cost ? e.cost > f.cost : e.from != f.from ? e.from < f.from : e.to < f.to;
}
vector<edge> kruskal(graph &g){
	priority_queue<edge> pq;
	for(size_t i=0; i<g.size(); ++i)
		for(size_t j=0; j<g[i].size(); ++j)
			if(i < g[i][j].to)
				pq.push(g[i][j]);
	unionfind uf(g.size());
	vector<edge> res;
	while(!pq.empty()){
		edge e = pq.top(); pq.pop();
		if(!uf.united(e.from, e.to)){
			uf.unite(e.from, e.to);
			res.push_back(e);
		}
		if(uf.num_of_disjointsets == 1) break;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	graph g(n);
	for(Int i=0; i<n; ++i)
		for(Int j=0; j<n; ++j){
			Int a; cin >> a;
			if(a != -1){
				g[i].push_back(edge(a, i, j));
				g[j].push_back(edge(a, j, i));
			}
		}
	vector<edge> mst = kruskal(g);
	Int ans = 0;
	for(auto i:mst) ans += i.cost;
	cout << ans << "\n";
}


Measured memory_bytes: 3716
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = list(map(int, sys.stdin.readline().split()))
N.sort()
a = ''.join(map(str, N))
if a == '1479':
    print('YES')
else:
    print('NO')


Measured memory_bytes: 13816
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, M, C;
    cin >> N >> M >> C;

    vector<ll> B(M);
    FOR(i, 0, M){
        cin >> B[i];
    }

    ll count = 0;
    FOR(i, 0, N){
        vector<ll> A(M);
        FOR(j, 0, M){
            cin >> A[j];
        }

        // check
        ll a = C;
        FOR(j, 0, M){
            a += B[j] * A[j];
        }
        if(a>0){
            count++;
        }
    }

    p(count);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n,k;
    cin >> n >> k;
    ll d[k];
    bool f[10];
    fill(f,f+10,false);
    for (ll i=0;i<k;i++){
        cin >> d[i];
        f[d[i]]=true;
    }
    
    for (ll i=n;i<1000000000;i++){
        string s=to_string(i);
        bool flag=true;
        for (ll i=0;i<s.size();i++){
            if (f[s[i]-'0']){
                flag=false;
                break;
            }
        }
        if (flag){
            cout << s << endl;
            return 0;
        }
    }
    return 0;
}


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

typedef long long int ll;

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

	int mincnt = std::pow( 10, 9 );;
	for( int i = 0; i < n; i++ ) {
		ll a;
		std::cin >> a;

		int cnt = 0;
		for( int i = 0; i < std::pow( 10, 9 ); i++ ) {
			if( a % 2 != 0 ) {
				break;
			}
			a = a / 2;
			if( a % 2 != 0 ) {
				cnt = i + 1;
				break;
			}
		}

		mincnt = std::min( mincnt, cnt );
	}

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,c=1,mami=0;
  cin>>n>>t;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int ma=a[n-1],mi=a[n-1];
  for(int i=n-2;i>=0;i--){
    if(a[i]>ma){
      ma=a[i];
      mi=a[i];
    }else if(a[i]<mi){
      mi=a[i];
      if(ma-mi==mami) c++;
      else if(ma-mi>mami){
        mami=ma-mi;
        c=1;
      }
    }
  }
  cout<<c<<endl;
}
      
  

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int n,q;
vector<vector<int>> adj;
vector<int> dfsn;
vector<int> range;
int dfsnum=-1;

vector<int> bitree;

void update(int pos, int value)
{
    while(pos<=n){
        bitree[pos]+=value;
        pos+=pos&-pos;
    }
}

void rangeupdate(int l, int r, int value)
{
    update(l,value);
    update(r+1,-value);
}

int query(int pos)
{
    int ret=0;
    while(pos>=1){
        ret+=bitree[pos];
        pos-=pos&-pos;
    }
    return ret;
}

void dfs(int now)
{
    if(dfsn[now]!=-1) return;
    dfsn[now]=++dfsnum;
    for(int nxt : adj[now]){
        dfs(nxt);
    }
    range[now]=dfsnum;
}

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

    cin>>n>>q;
    adj.resize(n);
    dfsn.resize(n,-1);
    range.resize(n);
    bitree.resize(n+1);
    for(int i=0; i<n-1; i++){
        int a,b;
        cin>>a>>b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }
    dfs(0);
    while(q--){
        int p,x;
        cin>>p>>x;
        rangeupdate(dfsn[p-1]+1,range[p-1]+1,x);
    }
    for(int i=0; i<n; i++) cout<<query(dfsn[i]+1)<<" ";

    return 0;
}


Measured memory_bytes: 22016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>
#include <array>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std;


std::string S;

int main(){
	
	cin >> S;

	int price = 700;

	for (char c : S) {
		if (c == 'o') price += 100;
	}

	cout << price << endl;

	return 0;
}



Measured memory_bytes: 384
#include<iostream>


using namespace std;

int main()
{
	char a;

	cin >> a;

	if(a=='A')	cout<<"T\n";
	else if(a=='T')	cout<<"A\n";
	else if(a=='C')	cout<<"G\n";
	else if(a=='G')	cout<<"C\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=0;
    if((b-a)%2==0){
        ans=(b-a)/2;
    }
    else {
        ans=min(a,n-b+1)+(b-a-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int dp[1 << 16];
void init() {
	fill(dp, dp + (1 << 16), mod);
	dp[0] = 0;
	rep(i, (1 << 16)) {
		vector<int> r;
		rep(j, 16) {
			if ((i&(1 << j)) == 0) {
				r.push_back(j);
			}
		}
		int len = r.size();
		rep1(j, (1 << len) - 1) {
			int s = 0; int tmp = 0;
			int ss = 0;
			rep(k, len) {
				if (j&(1 << k)) {
					s ^= r[k]; tmp++;
					ss += (1 << r[k]);
				}
			}
			if (s == 0) {
				dp[i + ss] = min(dp[i + ss], dp[i] + tmp - 1);
			}
			else {
				dp[i + ss] = min(dp[i + ss], dp[i] + tmp);
			}
		}
	}
	per(i, (1 << 16)) {
		vector<int> r;
		rep(j, 16) {
			if ((i&(1 << j)) == 0) {
				r.push_back(j);
			}
		}
		int len = r.size();
		rep(j, len) {
			int ni = i ^ (1 << r[j]);
			dp[i] = min({ dp[i],dp[ni] });
		}
	}
}

struct edge {
	int to, cost;
};
vector<edge> G[1 << 17];
int ans;

vector<int> dfs(int v, int fr, int c) {
	vector<int> ret(16, 0);
	rep(j, G[v].size()) {
		int to = G[v][j].to;
		int cost = G[v][j].cost;
		if (to == fr)continue;
		vector<int> nex = dfs(to, v, cost);
		rep(i, 16) {
			if (ret[i] && nex[i]) {
				if (i>0)ans++; ret[i] = 0;
			}
			else if (nex[i])ret[i] = 1;
		}
	}
	if (v == 0)return ret;
	int s = 0;
	rep(i, 16)if (ret[i])s ^= i; s ^= c;
	if (ret[s]) {
		if (s > 0)ans++; ret[s] = 0;
	}
	else {
		ret[s] = true;
	}
	return ret;
}

void solve() {
	int n; cin >> n;
	rep(i, n - 1) {
		int x, y, a; cin >> x >> y >> a;
		G[x].push_back({ y,a });
		G[y].push_back({ x,a });
	}
	vector<int> nex = dfs(0, -1, -1);
	int s = 0;
	rep(i, 16) {
		if (nex[i]) {
			s += (1 << i);
		}
	}
	ans += dp[s];

	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 24576
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int r[99];
ll p[99];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; ll k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		ll a; cin >> a;
		for (int j = 0; j < 50; j++)
			if ((a & (1LL << j)))
				r[j]++;
	}
	p[0] = max(r[0], n - r[0]);
	for (int i = 1; i < 50; i++)
		p[i] = p[i - 1] + 1LL * max(r[i], n - r[i]) * (1LL << i);
	ll s = 0, ans = 0;
	for (int i = 49; i >= 0; i--) {
		if (k - (1LL << i) >= 0) {
			if (i > 0) ans = max(ans, s + 1LL * r[i] * (1LL << i) + p[i - 1]);
			else ans = max(ans, s + 1LL * r[i] * (1LL << i));
			s += 1LL * (n - r[i]) * (1LL << i);
			k -= (1LL << i);
		}
		else
			s += 1LL * r[i] * (1LL << i);
	}
	ans = max(ans, s);
	cout << ans << '\n';
	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() {
   string s;
   cin>>s;
  
  int p=s.size();
  string ans;
  
  rep(i,p){
  	ans+="x";
  }
  
	cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int n, m, x;
int a[25][25];
int b[25];
int vis[25];
int c[25];
int ans = 0x7f7f7f7f;

void Dfs(int now, int cost) {
  if (now == n + 1) {
    memset(b, 0, sizeof(b));
    for (RI i = 1; i <= n; ++i)
      if (vis[i])
        for (RI j = 1; j <= m; ++j)
          b[j] += a[i][j];
    int flag = 1;
    for (RI i = 1; i <= m; ++i)
      if (b[i] < x) flag = 0;
    if (flag) ans = min(ans, cost);
    return;
  }
  vis[now] = 0, Dfs(now + 1, cost);
  vis[now] = 1, Dfs(now + 1, cost + c[now]);
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  read(n), read(m), read(x);
  for (RI i = 1; i <= n; ++i) {
    read(c[i]);
    for (RI j = 1; j <= m; ++j)
      read(a[i][j]);
  }
  Dfs(1, 0);
  if (ans == 0x7f7f7f7f) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}

// created by Daniel yuan
/*
     ________
    /        \
   / /      \ \
  / /        \ \
  \            /
   \  ______  /
    \________/
*/


Measured memory_bytes: 3644
n = int(input())
a = [int(i) for i in input().split()]
change = 0
for i in range(n):
	u = n-1
	while u > i:
		if a[u-1] > a[u]:
			a[u-1], a[u] = a[u], a[u-1]
			change += 1
		u -= 1
print(*a)
print(change)


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, K, C;
	cin >> N >> K >> C;
	string S;
	cin >> S;
	vector<int64> rmax(N, 0), lmax(N, 0);
	int64 lst = -INF;
	REP(i, S.size()) {
	  if (i > 0) lmax[i] = lmax[i-1];
	  if (S[i] == 'o' && abs(lst - i) > C) {
	    lmax[i]++;
	    lst = i;
	  }
	}
	for (int64 i = N-1; i >= 0; i--) {
	  rmax[i]++;
	  int64 p = i + C+1;
	  if (S[i] == 'x') {
	    rmax[i]--;
	    p = i+1;
	  }
	  if (p < N)
  	  rmax[i] += rmax[p];
	}
	lst = -INF;
	vector<int64> res;
	REP(i, N) {
	  int64 l = (i - C - 1 >= 0 ? lmax[i-C-1] : 0), r = (i + C + 1 < N ? rmax[i+C+1] : 0);
	  if (S[i] == 'o' && l + r == K-1) {
      if (res.size() && abs(res.back() - i) <= C) {
        res.pop_back();
      }
	    if (abs(lst-i) > C) {
        res.push_back(i);
	    }
      lst = i;
	  }
	}
	REP(i, res.size()) {
	  cout << res[i]+1 << endl;
	}

}


Measured memory_bytes: 6536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
ll run();

int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}
const ll inf = (1e9+5);
void max_self(ll &a, ll b) {
    a = max(a, b);
}
void min_self(ll &a, ll b) {
    a = min(a, b);
}
void mul(ll &a, ll b) {
    a = (a * b) % mod;
}
void add_self(ll &a, ll b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}


ll run() {
    int n;
    cin >> n;
    vector<double> dp(n+1);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        double h;
        cin >> h;
        vector<double> dp_new(n+1);
        for (int j = 1; j <= n; j++) {
            dp_new[j] = dp[j - 1] * h + dp[j] * (1 - h);
        }
        dp_new[0] = dp[0] * (1 - h);
//        for (int j = 0; j <= n; j++) {
//            dp[j] = dp_new[j];
//        }
        dp = dp_new;
    }
    double ans = 0;
    for (int i = n/2+1; i <= n; i++) {
        //cout<<dp[i]<<" ";
        ans += dp[i];
    }
    cout << ans;
    return 0;
}















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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt=1;
    for(int i=0; i<n-1; i++){
        if(s[i]!=s[i+1])cnt++;
    }
    cout << cnt << endl;
}

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

#define int long long

#define pii pair<int, int>

#define x1 x1228
#define y1 y1228

#define left left228
#define right right228

#define pb push_back
#define eb emplace_back

#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   

#define matr vector<vector<int> > 

#define all(x) x.begin(), x.end()


using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int n, m, v, p; 
int a[maxn]; 
int min(int a, int b, int c) {
    return min(a, min(b, c)); 
}

bool check(int id) {
    int x = a[id];
    int sum = v * m; 
    int add = max(0ll, a[p - 1] - a[id]);
    if (add > m) return false;
    sum -= add;                                 
    x += add; 
    vector<int> upper;
    vector<int> lower;
    vector<int> eq; 
    for (int i = 0; i < n; ++i) {
        if (i == id) continue; 
        if (a[i] == x) eq.pb(m); 
        else if (a[i] > x) upper.pb(a[i]);                     
        else lower.pb(a[i]); 
    } 
    for (auto v : upper) {
        sum -= min(sum, m); 
    }
    for (auto &v : lower) {
        int pp = min(sum, x - v, m);         
        v += pp; 
        if (v == x) {                
            eq.pb(m - pp); 
        }             
        sum -= pp; 
    }
    if (sum == 0) return true; 
    sort(all(eq)); 
    int ctr = p - upper.size() - 1; 
    for (int i = 0; i < ctr; ++i) {
        if (eq.size()) {
            sum -= min(sum, eq.back());
            eq.pop_back();                         
        }        
    }                
    int ptr = m - add; 
    sum -= min(sum, ptr); 
    for (auto v : eq) {
        sum -= min(sum, v, ptr); 
    }
    return sum == 0; 
}

void solve() {        
    cin >> n >> m >> v >> p; 
    for (int i = 0; i < n; ++i) cin >> a[i]; 
    sort(a, a + n);
    reverse(a, a + n); 
    int l = -1;                
    int m; 
    int r = n; 
    while (l + 1 < r) {
        m = (l + r) / 2;
        if (check(m)) l = m; 
        else r = m; 
    }
    cout << l + 1; 
}                               
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 4188
N = int(input())
S = list(input())

E_list = [0] * N
W_list = [0] * N

# print(S)

E_count = 0
for i in range(N):
    if i != 0:
        if S[i-1] == 'W':
            E_count = 1 + E_count
        E_list[i] = E_count

S.reverse()

W_count = 0
for i in range(N):
    if i != 0:
        if S[i-1] == "E":
            W_count += 1
        W_list[i] = W_count

W_list.reverse()

# print(E_list)
# print(W_list)

lll = [W_list[i] + E_list[i] for i in range(N)]
print(min(lll))




Measured memory_bytes: 31776
# -*- coding: utf-8 -*-
def main():
    N, A, B = map(int, input().split())
    S = input()
    kakutei = 0
    kaigai_rank = 1
    check = False
    for s in S:
        if kakutei < A+B:
            if s == 'a':
                kakutei += 1
                print('Yes')
            elif s == 'b':
                if kaigai_rank <= B:
                    kaigai_rank += 1
                    kakutei += 1
                    print('Yes')
                else:
                    check = True
                    print('No')
            elif s == 'c':
                print('No')
            # print('kakutei: ' + str(kakutei))
            # print('rank: ' + str(kaigai_rank))
        else:
            print('No')
            
if __name__ == '__main__':
    main()

# No
# Yes
# Yes
# Yes
# Yes
# No
# Yes
# Yes
# No
# Yes
# No
# No


Measured memory_bytes: 75348
#include <iostream>
#include <algorithm>
using namespace std;
int a[101];
int main()
{
    int n,i,j,m,s;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    m=1000000000;
    for(j=a[0];j<=100;j++)
    {
        s=0;
        for(i=0;i<n;i++)
        {
            s+=(a[i]-j)*(a[i]-j);
        }
        if(s<m)m=s;
    }
    cout<<m;
    return 0;
}

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

class Main {

	public static void main(String[] args) throws IOException {
		Stack<Integer> numberStack = new Stack<>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		for(;scanner.hasNext();) {
			String str = scanner.next();
			try {
				numberStack.push(Integer.parseInt(str));
			}catch(NumberFormatException e) {
				//読み込んだ文字列が数字ではない時
				if(str.equals("+")) {
					int n = numberStack.pop() + numberStack.pop();
					numberStack.push(n);
				}else if(str.equals("-")) {
					int n = -numberStack.pop() +numberStack.pop();
					numberStack.push(n);
				}else if(str.equals("*")) {
					int n = numberStack.pop() * numberStack.pop();
					numberStack.push(n);
				}
			}
		}
		scanner.close();

		System.out.println(numberStack.pop());


	}

}



Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> A;
    for (int i = 0;i < 2 * n; ++i) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(), A.end());

    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        ans += min(A[i + 1], A[i]);
        // cout << A[i + 1] << " " << A[i] << endl;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

vector<vector<ll>> G;
ll N,M; 
ll d[200000];

void dfs(ll p){
    d[p]++;
    for(auto &e : G[p]){
        if(d[e] > 0) continue;
        dfs(e);
    }
}

bool check(){
    for(int i=0;i<N;i++){
        if(d[i] == 0) return false;
    }
    return true;
}

int main(){
    cin >> N >> M;
    G.resize(N+M);
    for(int i=0;i<N;i++){
        ll K;
        cin >> K;
        for(int j=0;j<K;j++){
            ll L;
            cin >> L;
            L--;
            G[i].push_back(N+L);
            G[N+L].push_back(i);
        }
    }
    dfs(0);
    if(check()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  if(s[0] == 'o') ++count;
  if(s[1] == 'o') ++count;
  if(s[2] == 'o') ++count;
  cout << 700 + count * 100 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x%mod;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res%mod;
}
ll a,b,ans;
set<ll> s;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(a),read(b);
	for(ri i=2;i<=sqrt(a);++i){
		if(a%i) continue;
		while(a%i==0) a/=i;
		s.insert(i);
	}
	if(a!=1) s.insert(a);
	for(ri i=2;i<=sqrt(b);++i){
		if(b%i) continue;
		while(b%i==0) b/=i;
		ans+=(s.count(i)>0);
//		if(s.count(i)) printf("%d ",i);
	}
	ans+=(s.count(b)>0);
	print(ans+1);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    char N1 = n.charAt(0);
    char N2 = n.charAt(1);
    char N3 = n.charAt(2);
    char N4 = n.charAt(3);
    if(N1==N2||N2==N3||N3==N4){
      System.out.println("Bad");
    }else{
      System.out.println("Good");
    }
 }
}

Measured memory_bytes: 21716
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}


int main()
{
#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	long long x, y;
	cin >> x >> y;
	int cnt = 0;
	while (x <= y)
	{
		cnt++;
		x *= 2LL;
	}

	cout << cnt;

	return 0;
}

Measured memory_bytes: 256
def main():
  A,B,C,K = map(int, input().split())

  ans = 0

  if A >= K:
    print(K)
  else:
    K -= A
    ans += A
    if B >= K:
      print(ans)
    else:
      K -= B
      print(ans-K) 

if __name__ == "__main__":
  main()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int n;
    cin >> n;
    map<char,int> ansmp;
    REP(i,26) ansmp[(char)('a'+i)] = 0;
    REP(i,n) {
        string s;
        cin >> s;
        map<char,int> mp;
        REP(i,26) mp[(char)('a'+i)] = 0;
        for(const auto& it: s) mp[it]++;
        REP(i,26) chmin(ansmp[(char)('a'+i)],mp[(char)('a'+i)]);
        if(i ==0) ansmp = mp;
    }
    string ans;
    REP(i,26) {
        REP(j,ansmp[(char)('a'+i)]) ans.push_back((char)('a'+i));
    }
    cout << ans << endl;

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256