akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;

#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
    loop {
        let h: usize = get();
        let w: usize = get();
        if h + w == 0 { break; }
        let a = (0..h).map(|_| {
            (0..w).map(|_| get::<i32>()).collect::<Vec<_>>()
        }).collect::<Vec<_>>();
        let mut term = vec![];
        for i in 0..h {
            for j in 0..w {
                let v = i * w + j;
                if a[i][j] == 1 {
                    term.push(v);
                }
            }
        }
        let k = term.len();
        const INF: i32 = 1 << 30;
        let n = h * w;
        let mut g = vec![vec![]; n];
        for i in 0..h {
            for j in 0..w {
                let v = i * w + j;
                let dxy = [(0, 1), (1, 0)];
                for &(dx, dy) in &dxy {
                    let nx = i + dx;
                    let ny = j + dy;
                    if nx >= h || ny >= w { continue; }
                    let v2 = nx * w + ny;
                    g[v].push(v2);
                    g[v2].push(v);
                }
            }
        }
        let mut dp = vec![vec![INF; 1 << k]; n];
        for i in 0..k {
            dp[term[i]][1 << i] = 0;
        }
        // Unnecessarily slow (O(4^k))
        for bits in 1..1 << k {
            for i in 0..n {
                for sub in 1..bits {
                    if (sub & bits) != sub { continue; }
                    dp[i][bits] = min(
                        dp[i][bits],
                        dp[i][sub] + dp[i][bits - sub]);
                }
            }
            let mut que = BinaryHeap::new();
            for i in 0..n {
                if dp[i][bits] < INF {
                    que.push((-dp[i][bits], i));
                    dp[i][bits] = INF;
                }
            }
            while let Some((d, v)) = que.pop() {
                let d = -d;
                if dp[v][bits] <= d { continue; }
                dp[v][bits] = d;
                for &w in &g[v] {
                    que.push((-(d + 1), w));
                }
            }
        }
        let mut ma = 0;
        for i in 0..n {
            ma = max(ma, (h * w - 1) as i32 - dp[i][(1 << k) - 1]);
        }
        println!("{}", ma);
    }
}



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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long a, b, c, d;
    cin >> a >> b >> c >>d;
    long long r1 = min(a,b) * min(c,d), r2 = min (a,b) * max(c,d), r3 = max(a,b) * min(c,d), r4 = max(a,b) * max(c,d);
    cout << max(max(r1,r2), max(r3,r4));
}


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

int main() {
    string S; cin >> S;
    int N = S.length();
    ll ans = 0;
    ll tmp;
    for (int i = 0; i < (1<<(N-1)); i++) {
        tmp = S[0] - '0';
        for (int j = 0; j < N-1; j++) {
            if (i&(1<<j)) {
                ans += tmp;
                tmp = S[j+1] - '0';
            }
            else {
                tmp *= 10;
                tmp += S[j+1] - '0';
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x, y, na, nb, nc;
    cin >> x >> y >> na >> nb >> nc;
    vector<int> a;
    vector<int> tmp(max(na, nb));
    for (int i = 0; i < na; ++i) {
        cin >> tmp[i];
    }
    sort(tmp.rbegin(), tmp.rend());
    for (int i = 0; i < x; ++i) {
        a.push_back(tmp[i]);
    }
    for (int i = 0; i < nb; ++i) {
        cin >> tmp[i];
    }
    sort(tmp.rbegin(), tmp.rend());
    for (int i = 0; i < y; ++i) {
        a.push_back(tmp[i]);
    }
    for (int i = 0; i < nc; ++i) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.rbegin(), a.rend());
    long long ans = 0;
    for (int i = 0; i < x + y; ++i) {
        ans += a[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2804
N, M = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M)]


class UnionFind:
    def __init__(self,size):
        self.rank = [-1 for _ in range(size)]
        self.number = [1 for _ in range(size)]

    def find(self,x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]


def main():
    uf = UnionFind(N)
    p = N * (N - 1) // 2
    ans = [p]
    for x, y in reversed(ab):
        px = uf.find(x)
        py = uf.find(y)
        if px != py:
            p -= uf.number[px] * uf.number[py]
            uf.union(px, py)
        ans.append(p)

    for a in reversed(ans[:-1]):
        print(a)


main()

Measured memory_bytes: 24164
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct node{
	int key;
	node *parent, *left, *right;
};

node *root, *NIL;

void insert(int k) {
	node *y = NIL;
	node *x = root;
	node *z;

	z = (node *)malloc(sizeof(node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while( x != NIL) {
		y = x;
		if( z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;
	if( y == NIL) {
		root = z;
	} else if( z->key < y->key){
		y->left = z;
	} else {
		y->right = z;
	}
}

node * find(int k) {
	node *x = root;
	node *y = NIL;
	while( x != NIL && k != x->key) {
		if( k < x->key) x = x->left;
		else if( k > x->key) x = x->right;
	}
	return x;
}

node * mini(node *u) {
	while( u->left != NIL) {
		u = u->left;
	} return u;
}

node * Successor(node *u) {
	if( u->right != NIL)return mini(u->right);
	node *y = u->parent;
	while( y != NIL && u == y->right) {
		u = y;
		y = y->parent;
	}
	return y;
}

void Delete(node *z) {
	node *y;
	node *x;
	if( z->left == NIL || z->right == NIL) y = z;
	else y = Successor(z);
	if( y->left != NIL) {
		x = y->left;
	} else {
		x = y->right;
	}

	if( x != NIL) {
		x->parent = y->parent;
	}

	if( y->parent == NIL) {
		root = x;
	} else {
		if( y == y->parent->left) {
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}

	if(y != z) {
		z->key = y->key;
	}
	free(y);
}


void Preorder(node *t) {
	if( t == NIL) return;
	printf(" %d", t->key);
	Preorder(t->left);
	Preorder(t->right);
}

void Inorder(node *t) {
	if( t == NIL) return;
	Inorder(t->left);
	printf(" %d", t->key);
	Inorder(t->right);
}

void Postorder(node *t) {
	if( t == NIL) return;
	Postorder(t->left);
	Postorder(t->right);
	printf(" %d", t->key);
}

int main(){
	int x, n;
	string st;
	cin >> n;
	for( int i = 0; i < n; i++) {
		cin >> st;
		if(st[0] == 'i') {
			cin >> x;
			insert(x);
		} else if(st[0] == 'p'){
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		} else if( st[0] == 'f'){
			cin >> x;
			node *t = find(x);
			if( t == NIL) cout << "no";
			else cout << "yes";
			cout <<endl;
		} else {
			cin >> x;
			Delete( find(x) );
		}
	}
	return 0;
}

Measured memory_bytes: 19976
#include<stdio.h>

int main() {
	int n, x;
	int A[3];
	int cnt;
	while (1) {
		cnt = 0;
		scanf("%d %d", &n, &x);
		if (!n && !x)break;
		for (A[1] = 2; A[1] <= x / 2; A[1]++) {
			for (A[0] = 1; A[0] < A[1]; A[0]++) {
				A[2] = x - A[0] - A[1];
				if (A[2] <= n && A[1] < A[2]) {
					cnt++;
				}
			}
		}
		printf("%d\n", cnt);
	}

	return 0;
}


Measured memory_bytes: 2740
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	int f=a*a*b-c;
	if(c*2<=a*a*b){
		double t=(double)c*2/a/b;
		double ans=atan(b/t)*180/PI;
		printf("%.12f\n",ans);
	}else{
		double t=(double)f*2/a/a;
		double ans=atan(t/a)*180/PI;
		printf("%.12f\n",ans);
	}
}

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

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

vector<int> par;
vector<int> rnk;

void init(int n){
    par = vector<int>(n);
    rnk = vector<int>(n);
    for (int i = 0; i < n; i++){
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x){
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) par[x] = y;
    else{
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

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

int main(){
    int n, m;
    cin >> n >> m;
    init(2 * n);
    for (int i = 0; i < n; i++){
        int p;
        cin >> p;
        unite(i, p - 1 + n);
    }
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        unite(x - 1, y - 1);
    }

    int cnt = 0;
    for (int i = 0; i < n; i++){
        if (same(i, i + n)) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var X = parseInt(input[0].split(" ")[1]);
  x = new Array(N).fill(0);
  tmp=input[1].split(" ");
  for(i=0;i<N;i++){
    x[i]=parseInt(tmp[i]);
  }
  x.push(X);
  x.sort(function(a,b){
    if( a < b ) return -1;
    if( a > b ) return 1;
    return 0;
  });
  dif=new Array();
  for(i=0;i<N;i++){
    if(x[i+1]-x[i]!=0){
    dif.push(x[i+1]-x[i]);
    }
  }
  var ans=0;
  if(dif.length==1){
    ans=dif[0];
  }else{
  for(i=1;i<dif.length;i++){
    if(i==1){
      ans=gcd(dif[i],dif[i-1]);
    }else{
      ans=gcd(ans,dif[i]);
    }
  }
}

  console.log('%s', ans);
}
function gcd(m, n) {
  var r;

  if(m < n) {
    r = m;
    m = n;
    n = r;
  }

  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }

  return n;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;


int main() {
  int a,b,c,k;
  cin >> a>>b>>c>>k;
  rep(i,k){
    if(a<b&&b<c){
      cout <<"Yes"<<endl;
      return 0;
    }
    if(a>=b){
      b*=2;
      continue;
    }
    if(b>=c){
      c*=2;
      continue;
    }
  }
  if(a<b&&b<c){
      cout <<"Yes"<<endl;
      return 0;
  }
  cout << "No"<<endl;
}

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define MOD1 1000000007
#define MOD2 998244353

int main()
{

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

	IOS

	ll a,b;
	cin >> a >> b;
	cout << a*b << endl;
}

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

int main(){

  int k;
  cin >> k;

  while( k != 0 ){
    int c;
    int sum = 0;
    for( int i = 0; i < k *(k-1)/2; i++ ){
      cin >> c;
      sum += c;
    }

    cout << sum / (k-1) << endl;
    cin >> k;
  }





  return 0;
}

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

class Rolling_Hash{
private:
  ll n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.assign(n+1,0);
    hash2.assign(n+1,0);
    mpow1.assign(n+1,1);
    mpow2.assign(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(ll a,ll b){
    ll len = min( n-a+1,n-b+1 );
    ll low=0,high=len;
    while( high-low>1 ){
      ll mid=(high+low)/2;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};

main(){

  ll n;
  string s;
  cin>>n>>s;

  Rolling_Hash rh(s);
  ll ans=0;
  rep(i,n){
    for(ll j=i+1;j<n;++j){
      ll lcp=rh.get_LCP(i,j);
      ans=max(ans,min(lcp,j-i));
    }
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 512
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
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...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		mp[a] = i;
	}
	for (auto&& var : mp) {
		cout << var.second << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5504
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, long long> pdl;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int A[1<<20];int n, a, b;

bool possible(int nblast) {

    int x = a-b;

    ll sum = 0;
    for(int i = 0;i < n;i++) {
        ll y = A[i]-nblast*ll(b);
        if(y > 0)
            sum += ceil(y*1.0/x);
    }

    return sum <= nblast;
}

int main() {
  std::ios::sync_with_stdio(false);
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin>>n>>a>>b;
  rep(i, n) cin>>A[i];
  sort(A,A+n);

  int s = 1, e = int(1e9), mid;
  int ans = e+1;

  while (s <= e) {
      mid = (s+e)/2;
      if(possible(mid)) {
          ans = mid;
          e = mid-1;
      } else s = mid+1;
  }

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
  
ll N;
 in(N);
 vl A(N+1) , B(N);
  rep(i,N+1) in(A[i]);
  rep(i,N) in(B[i]);
  ll ans =0;
  for(int i=N-1;i>=0;i--){
   if(B[i]<=A[i+1]) ans += B[i];
    else if(B[i]-A[i+1]<=A[i]){
	ans += B[i];
      A[i] -= (B[i]-A[i+1]);
    }
    else {
     ans += (A[i]+A[i+1]);
      A[i] =0;
    }
  }
  out(ans);
  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, j=1, n;
cin>>a;
for(int i=0; i<a; i++){
        cin>>n;
if(n==j){
    j++;
}
}
if(j==1){
    cout<<"-1";
}else{
    cout<<a-j+1;
}
}


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

int main() {
    int m, n;
    while(cin >> m >> n, m) {
        vector<bool> v(10000000, false);
        for(int i=m; i<v.size(); ++i) {
            if(!v[i]) {
                n--;
                for(int j=i; j<v.size(); j+=i) {
                    v[j] = true;
                }
                if(n == 0) {
                    break;
                }
            }
        }
        for(int i=m; i<v.size(); ++i) {
            if(!v[i]) {
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if(s==u){
    cout << a - 1 << " " << b << "\n";
  }else{
    cout << a << " " << b - 1 << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	int N; cin >> N; 
	vel H(N); rep(i,N) cin >> H[i];

	int cnt = 0; int ans = 0;
	rep(i,N-1) {
		if(H[i] >= H[i+1]) cnt++;
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        double[] p = new double[n];
        for(int i = 0; i < n; i++) p[i] = scan.nextDouble();
        double[][] dp = new double[n + 1][n + 1];
        dp[0][0] = 1;
        for(int i = 1; i < n + 1; i++){
            for(int j = 0; j < i + 1; j++){
                if(j > 0) dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1];
                else dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
            }
        }
        double out = 0;
        for(int i = n / 2 + 1; i <= n; i++) out += dp[n][i];
        System.out.println(out);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

const ll INF = 1000000000;
ll N;
string s[300];
ll color[300];
ll d[300][300];

bool dfs(ll i, ll col) {
  color[i] = col;
  rep(j,N) {
    if (s[i][j] == '0')
      continue;
    if (color[j] == col)
      return false;
    if (color[j] == -1 && !dfs(j, 1-col))
      return false;
  }
  return true;
}

signed main() {
  cin >> N;
  rep(i,N) {
    cin>>s[i];
    color[i]=-1;
  }

  if (!dfs(0,0)) {
    cout << -1 << endl;
    return 0;
  }

  // ワーシャルフロイド
  rep(i,N) rep(j,N) d[i][j] = INF;
  rep(i,N) rep(j,N) if (s[i][j] != '0') d[i][j] = 1;
  rep(k,N) rep(i,N) rep(j,N) {
    d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
  }
  ll ans = 0;
  rep(i,N) {
    rep(j,N) {
        if (i != j)
          ans = max(ans, d[i][j]);
    }
  }
  cout << ans + 1 << endl;
  return 0;
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            String array[] = br.readLine().split("\\s+");
 
            System.out.printf("%d",Integer.parseInt(array[array.length-1]));
            for(int i = array.length-2; i >= 0; i--){
                System.out.printf(" %d", Integer.parseInt(array[i]));
            }
            System.out.printf("\n");
 
 
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24788
def main():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]
    ans = list()
    for i in range(N):
        ans.append(sum(A[0][0:i+1]) + sum(A[1][i:]))
    print(max(ans))


if __name__ == "__main__":
    main()


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int n, T;

signed main() {
   cin >> n >> T;
   int ans = 1e8;
   rep (i, n) {
      int c, t;
      cin >> c >> t;
      if (t <= T) {
         chmin(ans, c);
      }
   }

   if (ans == 1e8) {
      cout << "TLE" << endl;
   } else {
      cout << ans << endl;
   }

   return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0;i<3;++i){
            a[i] = sc.nextInt();
        }Arrays.sort(a);
        int sum = a[2]*10+a[1]+a[0];
        System.out.println(sum);
    }
}

Measured memory_bytes: 22868
import sys
from math import sqrt, cos, radians
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


A, B, H, M = MI()

d1 = (H * 60 + M) / 720
d2 = M / 60
theta = 360 * min(abs(d1 - d2), 1 - abs(d1 - d2))
ans = sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(radians(theta)))
print(ans)


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

using namespace std;

int main() {
    string s;
    string tmp;
    vector <int> ymd(3);
    int id = 0;

    cin >> s;

    for(int i = 0; i < s.size(); i++) {

        if(s[i] == '/') {
            ymd[id] = atoi(tmp.c_str());
            id ++;
            tmp = "";
            continue;
        }

        tmp += s[i];
    }

    ymd[id] = atoi(tmp.c_str());

    if(ymd[1] > 4) {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }

    //cout << s << endl;

}

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

int main(void)
{
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for (int i = 0; i < N; i++) {
        cin >> t[i];
    }

    int tsum = 0;
    for (int i = 0; i < N - 1; i++) {
        tsum += min(t[i+1] - t[i], T);
    }
    tsum += T;
    cout << tsum << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	long double ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	long double ans=0;
	for(ll i=0;i<k;i++){
		long double now=ch[i];
		now=(now+1)/2;
		ans+=now;
	}
	long double cnt=ans;
	for(ll i=k;i<n;i++){
		long double now1=ch[i];
		now1=(now1+1)/2;
		long double now2=ch[i-k];
		now2=(now2+1)/2;
		cnt+=now1-now2;
		ans=max(ans,cnt);
	}
	printf("%.10Lf",ans);
	// your code goes here
	return 0;
}

Measured memory_bytes: 6900
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
    char c=getchar();ll f=1,x=0;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return x*f;
}
#define mod 1000000007
void MOD(int &x){if(x>=mod)x-=mod;}
#define maxn 1000010
#define inf (1<<30)
char s[maxn];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int a=0,b=0;
	FOR(i,1,n)a+=(s[i]=='0'),b+=(s[i]=='1');
	out(min(a,b)*2);
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 5005, mod = 998244353;
ll fac[MX], inv[MX];
int n, k;

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p >>= 1;
	}
	return res;
}

ll comb (int n, int k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * inv[k] % mod * inv[n-k] % mod;
}

// n espacios, k numeros
ll f (int n, int k) {
	if (!n) return 1;
	return comb(n + k - 1, n);
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	fac[0] = inv[0] = 1;
	for (ll i = 1; i < MX; i++) {
		fac[i] = i * fac[i-1] % mod;
		inv[i] = pot(fac[i], mod - 2);
	}

	cin >> k >> n;
	for (int i = 2; i <= 2 * k; i++) {
		ll res = 0;
		int a = 0, b = 0, mit = 0;

		for (int j = 1; j <= k; j++) {
			if (2 * j == i) mit = 1;
			else if (1 <= i - j && i - j <= k) a++;
			else b++;
		}

		a /= 2;

		for (int j = 0; j <= a; j++) {
			res += comb(a, j) * pot(2, j) % mod *
				(f(n - j, j + b) + mit * f(n - j - 1, j + b)) % mod;
			res %= mod;
		}

		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 384
void main()
{
    long[] tmp = rdRow;
    long n = tmp[0], m = tmp[1];

    Bridge[] br = new Bridge[m];
    foreach (i; 0 .. m)
    {
        tmp = rdRow;
        long a = tmp[0] - 1, b = tmp[1] - 1;
        br[i].from = a, br[i].to = b;
    }

    long cnt;
    foreach (i; 0 .. m)
    {
        auto tree = new UnionFind(n);
        foreach (j; 0 .. m)
        {
            if (i == j) continue;
            tree.unite(br[j].from, br[j].to);
        }

        if (!tree.same(br[i].from, br[i].to)) ++cnt;
    }

    cnt.writeln;
}

alias Tuple!(long, "from", long, "to") Bridge;

struct UnionFind
{
    long[] par;

    this(long n)
    {
        par = new long[n];
        foreach (i; 0 .. n)
        {
            par[i] = i;
        }
    }

    long root(long x)
    {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(long x, long y)
    {
        return root(x) == root(y);
    }

    void unite(long x, long y)
    {
        x = root(x), y = root(y);
        if (x == y) return;
        par[x] = y;
    }
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 2e9;
const int maxN = 5000 + 5;

ll p, c[maxN], dist[maxN], old[maxN];
int n, m;
int a[maxN], b[maxN];

void bellman(){
    for(int i = 1; i <= n + n; i++){
        for(int j = 1; j <= m; j++){
            if(dist[a[j]] < INF){
                dist[b[j]] = min(dist[b[j]], dist[a[j]] + c[j]);
            }
        }
    }
}

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

    cin >> n >> m >> p;

    for(int i = 1; i <= m; i++){
        cin >> a[i] >> b[i] >> c[i];
        c[i] = p - c[i];

        //cerr << a[i] << ' ' << b[i] << ' ' << c[i] << '\n';
    }

    fill_n(dist + 1, n, INF);
    dist[1] = 0;

    bellman();

    ll ans = dist[n];
    for(int i = 1; i <= n; i++){
        old[i] = dist[i];
    }

    bellman();

    for(int i = 1; i <= n; i++){
        if(dist[i] != old[i]){
            dist[i] = -INF;
        }
    }

    bellman();

    if(ans != dist[n]){
        cout << "-1\n";
        return 0;
    }

    cout << max(0LL, -ans) << '\n';

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MOD = 1e9 + 7;
int n, m, a[20];
long long dp[20][200001], fac[200001], inv[200001];
long long ksm(long long a, int b)
{
    long long s = 1;
    while (b)
    {
        if (b & 1)
        {
            s = s * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return s;
}
void init()
{
    fac[0] = 1;
    for (int i = 1; i <= 200000; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[200000] = ksm(fac[200000], MOD - 2);
    for (int i = 199999; i >= 0; i--)
    {
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}
long long C(long long a, long long b)
{
    if (a < b)
    {
        return 0;
    }
    return fac[a] * inv[a - b] % MOD * inv[b] % MOD;
}
int main(int argc, char const *argv[])
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
    {
        scanf("%d", &a[m - i + 1]);
    }
    init();
    dp[0][0] = 1;
    for (int i = 0; i < m; i++)
    {
        for (int S = 0; S < (1 << n); S++)
        {
            if (dp[i][S])
            {
                dp[i + 1][S] = (dp[i + 1][S] + dp[i][S]) % MOD;
                for (int j = 0; j < n; j++)
                {
                    if (!((S >> j) & 1))
                    {
                        dp[i + 1][S | (1 << j)] = (dp[i + 1][S | (1 << j)] + dp[i][S] * fac[1 << j] % MOD * C((1 << n) - a[i + 1] - S, (1 << j) - 1) % MOD) % MOD;
                    }
                }
            }
        }
    }
    long long ans = 0;
    for (int S = 0; S < (1 << n); S++)
    {
        int f = __builtin_popcount(S) & 1 ? -1 : 1;
        ans = (ans + f * dp[m][S] * fac[(1 << n) - S - 1] % MOD) % MOD;
    }
    printf("%lld", (ans * (1 << n) % MOD + MOD) % MOD);
    return 0;
}

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

static const int MAX = 4000;
int color[3][MAX], csum[3][MAX]; // col/pos
enum {R, G, B};
string seq;

int getColor(int i){
    if(seq[i] == 'R') return R;
    else if(seq[i] == 'G') return G;
    else return B;
}

int main(){
    int n;
    cin >> n >> seq;
    if(n < 3){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        if(seq[i] == 'R'){
            color[R][i]++;
        } else if(seq[i] == 'G'){
            color[G][i]++;
        } else {
            color[B][i]++;
        }
    }
    for(int c = 0; c < 3; c++){
        csum[c][0] = color[c][0];
        for(int i = 0; i < n-1; i++){
            csum[c][i+1] = color[c][i+1] + csum[c][i];
        }
    }
    ll ans = 0;
    for(int i = 0; i < n-2; i++){
        int first = getColor(i);
        for(int j = i+1; j < n-1; j++){
            int second = getColor(j);
            int dist = j - i;
            if(first == second) continue;
            int third = 3 - first - second;
            ans += csum[third][n-1];
            if(j + dist < n) ans -= color[third][j + dist];
            ans -= csum[third][j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
const int N_MAX = int(1e5) + 10;

int N;
int A[N_MAX];

int gcd(int a, int b)
{
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main()
{
  cin >> N;
  REP(i,0,N) {
    cin >> A[i];
  }

  int ans = A[0]; // N個の数のgcd
  REP(i,0,N) {
    ans = gcd(ans,A[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

struct UnionFind{
    vector<int> d;
    int n;
    UnionFind(int n):d(n,-1){}
    int root(int x){
        if(d[x]<0)return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x,int  y){
        x = root(x);y = root(y);
        if(x==y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) {return root(x) == root(y);}
    int size(int x) {return -d[root(x)];}
};

int main(){
    int n,m;cin >> n >> m;
    UnionFind u(n);
    rep(i,m){
        int x,y,z;cin >> x >> y >> z;
        --x;--y;
        u.unite(x,y);
    }

    int cnt = 0;
    rep(i,n) if(u.d[i]<0) cnt++;
    cout << cnt << endl;

    
    
}

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

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

int main(){
	int n;
	cin >> n;
	string w;
	cin >> w;
	char l = w[w.size()-1];
	set<string> st;
	st.insert(w);
	REP(i, n-1){
		cin >> w;
		if (w[0] != l){cout << "No" << endl; return 0;}
		else if (st.count(w)!=0) {cout << "No" << endl; return 0;}
		else {l = w[w.size()-1]; st.insert(w);}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
int gcd(int a, int b){
  if(a<b) swap(a,b);
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}

int main(void){
  cin >> N;
  vector<int> A(N);
  int i,g;
  for(i=0;i<N;i++) cin >> A[i];
  g = gcd(A[0],A[1]);
  for(i=2;i<N;i++){
    g = gcd(g,A[i]);
  }
  cout << g << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  bool ans = true;
  if(S[0]==S[1])
  {
    ans = false;
  }
  else if(S[1]==S[2])
  {
    ans = false;
  }
  else if(S[2]==S[3])
  {
    ans = false;
  }
  if(ans==true)
  {
    cout << "Good" << endl;
  }
  else
  {
    cout << "Bad" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  long int A = 0, B = 0, C = 0, K = 0;

  scanf("%ld %ld %ld %ld", &A, &B, &C, &K);

  if( K > A ){
    K = K - A;
  }
  else{
    printf("%ld \n", K);
    K = 0;
  }

  if( K != 0 ){
    if( K > B ){
      K = K - B;
      A = A - K;
      printf("%ld \n", A);
    }
    else{
      printf("%ld \n", A);
    }
  }

  return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#define SIZE 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a,b;
int main(){
	cin >>a >>b;
	if(a%2==0||b%2==0) cout <<"Even"<<endl;
	else cout <<"Odd"<<endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

from collections import Counter

s = input()
C = Counter(s)

a = C["a"]
b = C["b"]
c = C["c"]

li = [a,b,c]
li.sort()

if li[0]+1 >= li[2]:
    print("YES")
else:
    print("NO")

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

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class ASheepAndWolves {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int S, W;
    cin >> S >> W;
    if (W >= S) {
      cout << "unsafe" << endl;
    } else {
      cout << "safe" << endl;
    }
  }
};


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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int a[500005];
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		a[x]++;
		a[x-1]++;
		a[x+1]++;
	}
	int maxv=0;
	for(int i=0;i<=500000;i++)
		if(a[i]>maxv)
			maxv=a[i];
	cout<<maxv;
	return 0;
 } 

Measured memory_bytes: 640
if __name__ == '__main__':
    N, K, Q = map(int, input().split())
    points = [0] * N
    for i in range(Q):
        points[int(input())-1] += 1
    for p in points:
        if K - (Q - p) > 0:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 4680
#include<stdio.h>
 
int main(void)
{
	int i,min=2000,sum;
	int n=0, m=0, k;
	char s[1001], t[1001];
 
	scanf("%s", &s);
	scanf("%s",&t);
 
for(int i=0;s[i]!='\0';i++)
n++;
for(int i=0;t[i]!='\0';i++)
m++;
 
for(int i=0;i<n-m+1;i++){
 
	sum=0;
	for(int j=0;j<m;j++){
		if(s[i+j]!=t[j]){
			sum++;
		}
	}
	if(sum<min)
	min=sum;
}
printf("%d",min);
 
	return 0;
}

Measured memory_bytes: 1708
#include <stdio.h>
#include <string.h>
#include <math.h>
struct typestr{
	char str[16];
	int allow; 
};

int main()
{
	int n,h,i,len,miss,position;
	double typing=0,total_miss=0,rate;
	char tmp[16],c[2];
	struct typestr string[101];
	scanf("%d %d",&n,&h);
	fflush(stdin);
	if(h<=0){
		printf("! Game Over\n"); 
		fflush(stdout);
		return 0;
	}
	
	for(i=0;i<n;i++){	
		scanf("%s %d",&string[i].str,&string[i].allow);
		fflush(stdin);
	}
	
	for(i=0;i<n;i++){
		len=strlen(string[i].str);
		position=0;
		miss=0;
		while(1){
			typing++;
			memset(tmp,'0',16);
			strcpy(tmp,string[i].str);
			memset(tmp,'_',position);
			printf("? %s\n",tmp);
			fflush(stdout);

			memset(c,'0',2);
			scanf("%s",&c);
			fflush(stdin);
			if(string[i].str[position]==c[0] || string[i].str[position]==(c[0]-32)) position++;
			else{
				miss++;
				total_miss++;
			}
			if(position>=len) break;
			if(string[i].allow<miss){
				h--;
				break;
			}
		}
		if(h<=0){
			printf("! Game Over\n"); 
			fflush(stdout);
			return 0;
		}
	}
	rate=floor(((typing-total_miss)/typing)*1000)/10;
	printf("! Game Clear %.1f\n", rate); 
	fflush(stdout);
	return 0;
}

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

typedef long long lli;

double ans = 0;
lli n,m;
double k;
lli x;
double dfs(lli i){
	if(i == 0) return 0.0;
	return pow(0.5,m)*(1900*m+100*(n-m))+(1-pow(0.5,m))*dfs(i-1);
}

int main(){
	cin >> n >> m;
	k = 1;
	for(lli i = 0;i < 100000;i++){
		x += 1900*m+100*(n-m);
		ans += (double)x*pow(0.5,m)*k;
		k-=k*pow(0.5,m);
		//cout << k << endl;
	}
	cout << (lli)(ans+0.5) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int i;
	char s[1001] = "";
	cin >> s;
	for (i = 0; i < strlen(s); i++)
	{
		if (s[i] <= 'C')
			cout << (char)(s[i]+23);
		else
			cout << (char)(s[i]-3);
	}
	cout << endl;
}

Measured memory_bytes: 0
#include<cstdio>
const int N=5*1e5+10;
char s[N];
int a[N],n,m,sum[N],l,k,x,y,ans;
int ma(int a,int b){return a>b?a:b;}
int mi(int a,int b){return a>b?b:a;}
int main()
{
	scanf("%d%d%s",&n,&m,s);
	for(int i=1;i<=n;i++)a[i]=s[i-1]-'0';
	if(!a[1])l++;
	k=1;
	for(int i=2;i<=n;i++)
		if(a[i]==a[i-1])k++;
		else
		{
			a[++l]=k;
			k=1;
		}
	a[++l]=k;
	for(int i=1;i<=l;i++)
		sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=l;i+=2)
		ans=ma(ans,sum[mi(l,i+2*m)]-sum[i-1]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2688