akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define FOR(a, b, i) for(int i=a; i<b; i++)
#define RFOR(a, b, i) for(int i=a; i>=b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, x; cin>>n>>x;
    vector<int> l(n+1);

    FOR(1, n+1, i) cin>>l[i];

    vector<int> d(n+1+2);

    d[1] = 0;

    ll count = 0;
    if(0<x) count++;

    FOR(1, n+1, i)
    {
        d[i+1] = l[i]+d[i];
        if(d[i+1]<=x)
        {
            count++;
        }
        else
        {
            break;
        }
        
    }

    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
using namespace std;

int GCD(int x, int y){
    if(x%y==0) return y;
    else if((x%y!=0)&&(x/y==0)) return 1;
    else GCD(y, x%y);
}

int main(){

    int x, y;
    scanf("%d %d", &x, &y);

    if(x>=y) printf("%d\n", GCD(x, y));
    else printf("%d\n", GCD(y, x));

    return 0;
}


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

#pragma optimize(2)

#define Reg register

using namespace std;

const int MAXN=1e5+1;
const int INF=0x3f3f3f3f;

int n,k,h[MAXN],f[MAXN]={0};

inline int qr() {
	Reg char c=getchar();
	for(; !isdigit(c); c=getchar());
	Reg int num=c-48;
	for(c=getchar(); isdigit(c); num=(num<<1)+(num<<3)+c-48,c=getchar());
	return num;
}

inline void qw(const int &x) {
	if(x>9) qw(x/10);
	putchar(x%10+48);
	return ;
}

int main() {
	n=qr(),k=qr(),h[1]=qr();
	for(Reg int i=2,j,lim; i<=n; ++i) {
		h[i]=qr();
		for(j=i-1,f[i]=INF,lim=max(1,i-k); j>=lim; --j) f[i]=min(abs(h[i]-h[j])+f[j],f[i]);
	}
	qw(f[n]),putchar('\n');
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define all(n) n.begin(),b.end()
#define F first
#define S second
#define INF (1<<27)
using namespace std;
typedef pair<int,int> P;
typedef vector<P> VP;
int n;

bool cmp(const P& a,const P& b)
{
  if(a.S != b.S)
    return a.S < b.S;
  return false;
}

int get_D(P *a,int now)
{
  if(now <= 1)
    return INF;

  int m = now/2;
  int x = a[m].F;
  int d = min(get_D(a,m),get_D(a+m,now-m));
  inplace_merge(a,a+m,a+now,cmp);

  VP b;
  for(int i=0;i<now;i++)
    {
      if(abs(a[i].F-x) >= d)
	continue;

      for(int j=b.size()-1;j>=0;j--)
	{
	  int dx = a[i].F-b[j].F;
	  int dy = a[i].S-b[j].S;
	  if(dy >= d)
	    break;

	  d = min(d,dx*dx+dy*dy);
	}
      b.push_back(a[i]);

    }
  return d;
}

int main()
{
 
  cin >> n;
  P a[n]; 
  for(int i=0;i<n;i++)
    cin >> a[i].F >> a[i].S;
  sort(a,a+n);
  cout << get_D(a,n) << endl;
  return 0;
}

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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << "\n";
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let s: String = readln();
    let s = s.as_bytes();
    let mut cnt = vec![0i32; 256];
    for x in s {
        cnt[*x as usize] += 1;
    }
    for i in 0..s.len() {
        if !(cnt['0' as usize] >= 1 && cnt['1' as usize] >= 1) {
            println!("{}", s.len() - i);
            break
        }
        cnt[s[i] as usize] -= 1;
        cnt[s[s.len()-1-i] as usize] -= 1;
    }

}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


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

int main(){
  int r,g,b,k;
  cin >> r >> g >> b >> k;
  while(r >= g && k > 0){
    k--;
    g *= 2;
  }
  if(r >= g) cout << "No" << endl;
  else {
    while(g >= b && k >0){
      k--;
      b *= 2;
    }
    
    if(g >= b) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a*b%2==0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }

       
    }
    
}


Measured memory_bytes: 20820
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	int div4 = 0;
	int div2 = 0;
	int none = 0;

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

		cin >> x;
		if (x % 4 == 0) {
			div4++;
		}
		else if (x % 2 == 0) {
			div2++;
		}
		else {
			none++;
		}
	}

	// Put single non-divisible in front of divisible by 4.
	int g = std::min(none, div4);
	none -= g;
	div4 -= g;

	// Make a chain of numbers that are divide by 2.
	if (div2 > 0 && (g || div2 > 1)) {
		div2 = 0;
	}
	else if (none > 0 && g > 0) {
		none--;
	}
	
	if (none + div2 > 0) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,f=0;
    cin>>n;
    while(n>0)
    {
        if(n%10==7)
            f=1;
        n/=10;
    }
    if(f)
        Yes
    else
        No
}
return 0;
}

Measured memory_bytes: 3656
n,k,q = (int(i) for i in input().split())
a = [k]*n
d = [0]*(n+1)
for i in range(q):
	x = int(input())-1
	d[0]-=1
	d[x]+=1
	d[x+1]-=1
a[0] += d[0]
for i in range(1,n):
	a[i] = a[i-1] + d[i]
for i in range(n):
	print("Yes" if a[i]>0 else "No")


Measured memory_bytes: 8672
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 3e6 + 111;
        
using namespace std;          

int n, a, ans;

void solve(){   
	cin >> n;

	for (int i = 1; i <= n; i++){
		cin >> a;
		if (a % 2 == 0){
			if (a % 3 != 0 && a % 5 != 0){
				cout << "DENIED";
				return;
			}
		}
	}

	cout << "APPROVED";	
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  long double l; cin >> l;
  long double k = l/3.0; 
  long double ans = k*k*k;
  cout << fixed << setprecision(12) << ans << '\n';
  

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>

inline int read(void){
	int res = 0;
	char ch = std::getchar();
	while(ch < '0' || ch > '9')
		ch = std::getchar();
	while(ch >= '0' && ch <= '9')
		res = res * 10 + ch - 48, ch = std::getchar();
	return res;
}

typedef long long ll;

const int MAXN = 2e5 + 19;

namespace camel{
	struct Node{
		int val, k;
		
		bool operator<(const Node &b)const{
			return k < b.k;
		} 
	}A[MAXN], B[MAXN];
	
	int n, anum, bnum;
	ll ans;
	
	std::priority_queue<int, std::vector<int>, std::greater<int> > q;
	
	int main(){
		n = read(), ans = 0ll, anum = 0, bnum = 0;
		for(int i = 1; i <= n; ++i){
			int k = read(), l = read(), r = read();
			if(l > r)
				ans += r, A[++anum] = (Node){l - r, k};
			else
				ans += l, B[++bnum] = (Node){r - l, n - k};
		}
		std::sort(A + 1, A + 1 + anum);
		std::sort(B + 1, B + 1 + bnum);
		for(int i = 1; i <= anum; ++i){
			if(A[i].k == 0)
				continue;
			if(q.size() < A[i].k)
				q.push(A[i].val);
			else if(q.size() == A[i].k){
				if(A[i].val > q.top())
					q.pop(), q.push(A[i].val);
			}
		}
		while(!q.empty())
			ans += q.top(), q.pop();
		for(int i = 1; i <= bnum; ++i){
			if(B[i].k == 0)
				continue;
			if(q.size() < B[i].k)
				q.push(B[i].val);
			else if(q.size() == B[i].k){
				if(B[i].val > q.top())
					q.pop(), q.push(B[i].val);
			}
		}
		while(!q.empty())
			ans += q.top(), q.pop();
		std::printf("%lld\n", ans);
		return 0;
	}
}

int main(){
	for(int T = read(), i = 1; i <= T; ++i)
		camel::main();
	return 0;
}

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

int main() {
  int n,k; cin>>n>>k;
  vector<int> a(n);
  rep(i, n) cin>>a[i];

  ll res=0;
  rep(i, k) res+=a[i];
  ll tmp=res;
  for (int i=k; i<n; i++) {
    tmp+=a[i];
    tmp-=a[i-k];
    res=max(res, tmp);
  }
  double ans=(double)(res+k)/2;
  cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Console.ReadLine();
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		Console.WriteLine(h[0] + Enumerable.Range(0, h.Length - 1).Sum(i => h[i] < h[i + 1] ? h[i + 1] - h[i] : 0));
	}
}


Measured memory_bytes: 11348
def agc026_a():
  n = int(input())
  A = list(map(int, input().split()))
  # 同じ数が連続した個数を2で切り捨て？
  B = []
  num = A[0]
  count = 1
  for i in range(1, n):
    if A[i] == num:
      count += 1
    else:
      B.append(count)
      num = A[i]
      count = 1
  else:
    B.append(count)
  ans = 0
  for b in B:
    ans += b // 2
  print(ans)

agc026_a()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define endl '\n'
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

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

int32_t main()
{
	IO_OP;
	
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	for(int i=0;i<x;i++)
		cin >> a[i];
	for(int i=0;i<y;i++)
		cin >> b[i];
	for(int i=0;i<z;i++)
		cin >> c[i];
	vi v;
	for(int i=0;i<x;i++)
		for(int j=0;j<y;j++)
			v.PB(a[i]+b[j]);
	sort(ALL(v), greater<int>());
	if((int)v.size() > k)
		v.resize(k);
	vi ans;
	for(int i=0;i<(int)v.size();i++)
		for(int j=0;j<z;j++)
			ans.PB(v[i]+c[j]);
	sort(ALL(ans), greater<int>());
	for(int i=0;i<k;i++)
		cout << ans[i] << endl;

}



Measured memory_bytes: 43108
arr = Array.new(26) {0}

while line = gets
  line.chomp!

  line.downcase.gsub(/[^a-z]/, '').each_codepoint {|c| arr[c - 0x61] += 1}
end

arr.each_with_index {|c, i| puts "#{"%c" % (i + 0x61)} : #{c}"}



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

int main() {
  int a,b,c;
  cin >> a >> b ;
  c=a+b;
  if(c%2==0){
    cout << c/2 << endl;
  }
  if(c%2==1){
  cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;

bool sol(double r){
  if(r<1) return false;
  return floor(r)==ceil(r);
}

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

  for(double j=1;j<3501;j+=1){
    for(double i=j;i<3501;i+=1){
      if(4.0*i*j-N*i-N*j<=0) continue;
      if(sol((N*i*j)/(4.0*i*j-N*i-N*j))){
        cout<<ll((N*i*j)/(4.0*i*j-N*i-N*j))<<" "<<ll(i)<<" "<<ll(j)<<endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = (0..3 * n).map(|_| read::<i64>()).collect();
    a.sort();
    println!("{}", (0..n).map(|i| a[n + i * 2]).sum::<i64>());
}

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


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int a, b;
  cin >> a >> b;
  if (a > 8 || b > 8) cout << ":(";
  else cout << "Yay!";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

vector<ll> r, g, n;
multiset<ll> xset;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x, y, a, b, c, i;
    cin >> x >> y >> a >> b >> c;
    ll tmp;
    rep(i, a) {
        cin >> tmp;
        r.pb(tmp);
    }
    rep(i, b) {
        cin >> tmp;
        g.pb(tmp);
    }
    rep(i, c) {
        cin >> tmp;
        n.pb(tmp);
    }
    ll ans(0);
    sort(r.begin(), r.end(), greater<ll>());
    sort(g.begin(), g.end(), greater<ll>());
    sort(n.begin(), n.end(), greater<ll>());
    rep(i, min(int(r.size()), x)) {
        ans += r[i];
        xset.insert(r[i]);
    }
    int ncnt(0);
    for (; i < x; i++) {
        ans += n[ncnt];
        xset.insert(n[ncnt]);
        ncnt++;
    }
    
    rep(i, min(int(g.size()), y)) {
        ans += g[i];
        xset.insert(g[i]);
    }
    for (; i < y; i++) {
        ans += n[ncnt];
        xset.insert(n[ncnt]);
        ncnt++;
    }
    while (ncnt < int(n.size())) {
        auto w = xset.begin();
        if (*w < n[ncnt]) {
            ans += n[ncnt] - *w;
            xset.erase(w);
            xset.insert(n[ncnt]);
            ncnt++;
        } else {
            break;
        }
    }
    cout << ans << endl;
 
}


Measured memory_bytes: 10996
#include<iostream>

using namespace std;

int main() {
	int A, B, C, D;	cin >> A >> B >> C >> D;
	int answer = 0;

	if (A >= B) {
		answer += B;
	}
	else {
		answer += A;
	}

	if (C >= D) {
		answer += D;
	}
	else {
		answer += C;
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);

        int a = cin.nextInt();
        int b = cin.nextInt();

        if(1<=a && a<=9 && 1<=b && b<=9){
            System.out.println(a*b);
        }else{
            System.out.println(-1);
        }

    }
}

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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=1e6;
int n,a[N];
int st[N],top;

bool ok(int t)
{
	top=0;
	rep(i,1,n)
	if(a[i]>a[i-1])st[++top]=-(a[i]-a[i-1]);
	else
	{
		int d=a[i-1]-a[i];
		while(d)
		{
			if(st[top]>=0)
			{
				--top;
				--d;
			}
			else
			{
				if(d>=-st[top])
				{
					d-=-st[top];
					--top;
				}
				else 
				{
					st[top]+=d;
					d=0;
				}
			}
		}
		if(t==1)return 0;
		int i=top;
		while(i&&st[i]==t-1)
		{
			st[i]=0;
			--i;
		}
		if(!i)return 0;
		if(st[i]>=0)++st[i];
		else
		{
			if(st[i]==-1)st[i]=1;
			else
			{
				++st[i];
				per(j,top,i)st[j+1]=st[j];
				++top;
				st[i+1]=1;
			}
		}
	}
	return 1;
}

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	cin>>n;
	rep(i,1,n)a[i]=read();
	int l=0,r=N;
	while(l+1!=r)
	{
		int mid=(l+r)/2;
		if(ok(mid))r=mid;
		else l=mid;
	}
	cout<<r;
}


Measured memory_bytes: 5120
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,K=LI()
AS=LI()
SUMM= sum(AS)

DIVS=set()
for i in range(1,40000):
    if SUMM % i == 0:
        DIVS.add(i)
        DIVS.add(SUMM//i)
# print(DIVS)

DIFF=[0]*N

res = 0
for div in DIVS:
    for i in range(N):
        DIFF[i] = AS[i]%div
    DIFF.sort()
    i = 0
    j = N-1
    sm = 0
    cost = 0
    while i <= j:
        if sm + DIFF[j] >= div:
            sm -= (div - DIFF[j])
            j -= 1
        else:
            cost += DIFF[i]
            sm += DIFF[i]
            i += 1
    # print("div:{} sum: {} cost: {}".format(div, sm, cost))
    if cost <= K: res = max(res, div)

# print(DIFF)
print(res)


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,kk;
int main()
{
    cin>>a>>b>>c;
    if(b>=a)//第一天到达
    {
        cout<<1<<endl;
        exit(0);//强制结束程序，子程序可用
    }
    if(c>=b)//出不去
    {
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1)kk=1;
    cout<<((a-b)/(b-c)+kk)*2+1<<endl;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

void Sequence() {
	string s;
	cin >> s;
	int p = 0;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] == 'p') p++;
	}
	int pc = s.size() / 2;
	cout << (pc - p) << endl;

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



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N,W;
  cin >>N>>W;
  vector<int> w(N);//weight
  vector<int> v(N);//value
  rep(i,N)cin>>w[i]>>v[i];
  
  uint64_t dp[110][100010]={0};//値の中身は品物i-1まで入れてOKとしたときの価値上限jの時の合計価値のMAX。
  //↑初期値0のvector<vector<int>>と同じこと
  //縦i=0~N:どの番号まで品物を入れてよいか。（dp[i]ではi-1までの品物はどれでも入れられる。）
  //(dp[0]は品物が何も入れられない状態、価値の上限によらず一律で0とする)
  //各価値上限でのdp[i]が分かっているとしたら
  //1.品物iが入れられるギリギリまで重さの価値上限が決まっている状態dp[i][j-w[i]]のとき、dp[i+1][j]でiの品物を足す。(+w[i])
  //2.品物iを入れない場合、i-1番の品物まででめいっぱい入れたときの価値だからdp[i][j]
  //横j=0~Wは決められた価値の総和。これを超えないように品物を決定。
  
  rep(i,N){//各品物に対して（i=0~N-1のN個）
    for(int j=0;j<=W;j++){//入れられる重さを１ずつ増やしていき、各場合において価値MAXとなる組み合わせを求める
      //(w[i],v[i])=iの品物を入れられる限り最優先で入れる（j>=w[i]）
      if(j>=w[i]){
        dp[i+1][j]=dp[i][j-w[i]]+v[i];//まず入れる場合を代入
      }
      //入れる場合と入れない場合で比べる。もしif~が行われていない場合は自動的に入れない場合が入る
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
  }
  cout<<dp[N][W]<<endl;
  return 0;
}


Measured memory_bytes: 86144
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

A,B = inpl()
print(max(A+B,A-B,A*B))


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

int main(){
    int h,w;
    cin >> h >> w;
    
    string board[50];
    rep(i,h) cin >> board[i];
    
    const int dx[8] = {1,1,1,-1,-1,-1,0,0};
    const int dy[8] = {1,0,-1,1,0,-1,1,-1};
    
    for(int i = 0; i < h; i++){
        
        for(int j = 0; j < w; j++){
            
            if(board[i][j] == '#') continue;
            
            int num = 0;
            
            for(int k = 0; k < 8; k++){
                int x = j + dx[k];
                int y = i + dy[k];
                
                if(x<0 or x>=w) continue;
                if(y<0 or y>=h) continue;
                if(board[y][x] == '#') num++;
                
            }
            
            board[i][j] = num + '0';
            
            
        }
    }
    rep(i,h) cout << board[i] << endl;
}


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

using namespace std;

const int mod = 2019;

string str;
map<int, int> remap;

int main() {
    long long res = 0;
    remap[0]++;
    cin >> str;
    int pow10 = 1, prefix = 0;
    reverse(str.begin(), str.end());
    for (char ch: str) {
        (prefix += (ch - '0') * pow10) %= mod;
        res += remap[prefix];
        remap[prefix]++;
        (pow10 *= 10) %= mod;
    }
    cout << res;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define int long long
#define regi register long long
int n,m;
int a[1100001];
int sstack[1100001];
int left[5011][211];
int right[5011][211];
int matrix[5011][5011];
int b[5011][211];
int max;
inline int read(){int r=0,c=0,w;for(;!isdigit(c=getchar());r=c);for(w=c^48;isdigit(c=getchar());w=w*10+(c^48));return r^45?w:-w;}
main(){
  n=read();
  m=read();
  a[0]=a[1]=0;
  for(regi i=2;i<=n;++i)
    a[i]=a[i-1]+read();
  for(regi i=1;i<=n;++i)
    for(regi j=1;j<=m;++j)
      b[i][j]=read();
  for(regi j=1;j<=m;++j){
  	int top=0;
  	for(regi i=1;i<=n;++i){
  		while(top&&b[sstack[top]][j]<b[i][j])
  		  top--;
  		left[i][j]=top?sstack[top]+1:1;
  	  sstack[++top]=i;
  	}
  	top=0;
  	for(regi i=n;i;--i){
  		while(top&&b[sstack[top]][j]<b[i][j])
  		  top--;
  		right[i][j]=top?sstack[top]-1:n;
  		sstack[++top]=i;
  	}
  	for(regi i=1;i<=n;++i){
  	  matrix[left[i][j]][i]+=b[i][j];
  	  matrix[left[i][j]][right[i][j]+1]-=b[i][j];
  	  matrix[i+1][i]-=b[i][j];
  	  matrix[i+1][right[i][j]+1]+=b[i][j];
  	}
  }
  for(regi i=1;i<=n;++i){
  	for(regi j=1;j<=n;++j)
    	matrix[i][j]+=matrix[i][j-1];
    for(regi j=1;j<=n;++j)
    	matrix[i][j]+=matrix[i-1][j];
    for(regi r=i;r<=n;++r)
      max=std::max(max,matrix[i][r]-a[r]+a[i]);
  }
  printf("%lld\n",max);
	return 0;
}

Measured memory_bytes: 223488
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 2e5 + 123;
int n , m , k;
int a[N];                                             
string s;
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n;
	cin >> s;
	if(n % 2 == 1)
		ret("No");

	if(s.substr(0,n/2) + s.substr(0,n/2) == s)
		ret("Yes");
	cout <<"No";
}


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

void Main() {
  long long N;
  cin >> N;

  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    ans += (N / i + 1) * (N / i) / 2 * i;
  }
  cout << ans << endl;
}

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



Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main()
{
 int i,k,n,s;
 cin >> n >> k >> s;
 if(s==1000000000)
 {
  for(i=0;i<k;i++)
  cout << s << " ";
  for(i=1;i<=(n-k);i++)
  cout << "1 ";
 }
 else
 {
  for(i=0;i<k;i++)
  cout << s << " ";
  for(i=1;i<=(n-k);i++)
  cout << "1000000000 ";
 }
 return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n;
  clr(d,0);
  rep(i,0,n){
    cin >> s;
    d[s[0] - 'A']++;
  }
  rep(i,0,30){
    if(d[i] != 0)l++;
  }
  if(l == 3)puts("Three");
  else puts("Four");
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#define FOR(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;

int N;
int main(void)
{
	cin >> N;
	ll ans = 0;
	FOR(i, 0, N) {
		int a;
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    deque<ll> q;
    bool is_front = n % 2;
    rep(i, n) {
        ll num; cin >> num;
        if (is_front) q.push_front(num);
        else q.push_back(num);

        is_front = !is_front;
    }

    while (!q.empty()) {
        cout << q.front() << " ";
        q.pop_front();
    }
    cout << endl;
    return 0;
}

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

using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int count = 0;
    for(int i=0; i<3; i++){
       if(s[i]==t[i]) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string st;
    int cnt=0,sz,i;
    cin>>st;
    sz=st.size();
    for(i=0;i<sz;i++)
    {
        cnt=cnt+int(st[i]-'0');
    }
    if(cnt%9==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
}



Measured memory_bytes: 3680
import sys
input = sys.stdin.readline

n, h, w = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    if ab[i][0] >= h and ab[i][1] >= w:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(long long*)a - *(long long*)b;
}

int min_comp(int min, int a)
{

}
int max_comp(int max, int a)
{
  if(max>a)    return max;
  else    return a;
}

int double_num(int num, int time)
{
if(time>=1){
    time = time - 1;
    num = num * 2;
    num = double_num(num, time);
     return num;
  }
if(time<=0) return num;
 }

int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  long long min=0;
  int A, B, C, K;
  int sosu[20000]={};
  int i,j,k;
  int flag=0;  
//    int k=0;

  scanf("%d", &A);
  //printf("%d\n", A);

        int cnt=1;
        sosu[0] = 2;
	for(i=3;i<=55555;i+=2){
		k=0;
		for(j=3;j<=sqrt(i);j+=2){
			if(i%j==0)	{
				k=1;
				break;
			}
		}
		if(k==0) {
                sosu[cnt]= i;
                cnt++;
                }            
	}
  cnt=0;
  for(i=0;i<20000;i++){
        if(sosu[i] %5 ==1){
         printf("%d  ", sosu[i]);
         cnt++;
         if(cnt==A) break;
       }
   }
   printf("\n");

return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;

int N, x;
int a[110];

int main(){
	scanf("%d %d", &N, &x);
	for(int i = 0; i < N; i++) scanf("%d", &a[i]);
	sort(a, a + N);
	int res = 0;
	int i;
	for(i = 0; i < N; i++){
		if(x < a[i]) break;
		res++;
		x -= a[i];
	}
	if(x != 0 && x >= a[i]) res--;
	printf("%d\n", max(0, res));
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int m, f, r;

    while (scanf("%d %d %d", &m, &f, &r))
    {
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }
        else if (m == -1 || f == -1)
        {
            printf("F\n");
        }
        else if (m + f >= 80)
        {
            printf("A\n");
        }
        else if (m + f >= 65)
        {
            printf("B\n");
        }
        else if (m + f >= 50)
        {
            printf("C\n");
        }
        else if (m + f >= 30)
        {
            if (r >= 50)
            {
                printf("C\n");
            }
            else
            {
                printf("D\n");
            }
        }
        else
        {
            printf("F\n");
        }
    }
}


Measured memory_bytes: 2596
def main():
    cnt = 0
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if same(i, p[i]):
            cnt += 1
    print(cnt)
        
def root(x):
    if parent[x] == x:
        return x
    parent[x] = root(parent[x])
    return parent[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
        elif rank[x] > rank[y]:
            parent[y] = x
        else:
            parent[y] = x
            rank[x] += 1

if __name__ == "__main__":
    n, m = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    parent = list(range(n+1))
    rank = [0]*(n+1)
    main()


Measured memory_bytes: 94700
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A + B >= 24) cout << (A + B) - 24 << endl;
	else cout << A + B << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

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;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b,c; cin >> a>>b>>c;
	//string s; cin >> s;
	int t = min(a + b, b + c);
	cout << min(t, a + c);
	


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import Data.Bits
import Data.List
import Data.Foldable(foldlM)
import Data.Maybe(fromJust)
import Control.Monad
import Data.Array as A ((!),accumArray)
import Data.Graph
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Char8 as BS

toTuple :: [a] -> (a,a)
toTuple (x:y:_) = (x,y)
toTuple _ = undefined

getInt :: IO Int
getInt = fst . fromJust. BS.readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine

getLineB :: (Read a) => IO [a] --直接入力
getLineB = map (read.BS.unpack) . BS.words <$> BS.getLine

build :: Int -> Int -> [(Int,(Int,Int))] -> V.Vector Int
build s n ls = runST $ do
  vec <- VM.replicate (n+1) maxBound
  VM.write vec s 0
  sub vec s 0
  V.freeze vec
  where
    graph = A.accumArray (flip (:)) [] (1,n) ls
    sub vec s par = do
      forM_ (graph A.! s) $ \(vw,v) -> do
        d  <- VM.read vec v
        sd <- VM.read vec s
        if d > sd + vw && v /= par then VM.write vec v (sd+vw)
          else return ()
      --V.freeze vec >>= \vec -> traceShowM (graph A.! s, vec)
      forM_ (graph A.! s) $ \(_,v) -> if v == par then return () else sub vec v s

solve :: Int -> V.Vector Int -> IO ()
solve q vec = do
  replicateM_ q $ do
    [x,y] <- getIntList
    print $ (vec V.! x) + (vec V.! y)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- fmap concat $ replicateM (n-1) $ do
    [a,b,c] <- getIntList
    return [(a,(c,b)),(b,(c,a))]
  [q,k] <- getIntList
  solve q $ build k n as


Measured memory_bytes: 44924
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  double w, h, x, y;
  cin >> w >> h >> x >> y;
  
  double ans = w*h / 2.0;
  cout << setprecision(16) << ans << ' ';
  cout << (w/2 == x && h/2 == y) << endl;
  return 0;
}

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

int descending_compare(const void *a, const void *b){
    return (int)(*(int*)b - *(int*)a);
}

int ascending_compare(const void *a, const void *b){
    return (int)*(int*)a - *(int*)b;
}

int nums[10005];

int main(void){
    int n, a, b;
    int answer = 0;
    int i;
    int tmp;
    int tmp2 = 0;

    for (i = 0; i < 10005; i++){
        nums[i] = 0;
    }
    scanf("%d %d %d", &n, &a, &b);
    for (i = 1; i <= n; i++){
        tmp = i;
        while (tmp != 0){
            tmp2 += tmp%10;
            tmp = tmp/10;
        }
        if (tmp2 <= b && tmp2 >= a){
            nums[i] = 1;
        }
        tmp2 = 0;
    }
    
    for (i = 0; i < 10005; i++){
        if (nums[i] == 1){
            answer += i;
        }
    }

    printf("%d\n", answer);




    return 0;
}


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

vector<ll> num;
queue<ll> que;
bool ok = false;

int d[3] = {3,5,7};

bool check(ll can){
    vector<bool> flag(3,false);
    bool end = false;
    while(can > 0){
        if(can%10 == 3) flag[0] = true;
        if(can%10 == 5) flag[1] = true;
        if(can%10 == 7) flag[2] = true;
        can /= 10;
    }
    if(flag[0] && flag[1] && flag[2]) end = true;
    return end;
}

void solve(int n){
    while(!que.empty()){
        ll can = que.front(); que.pop();
        for(int i = 0; i < 3; i++){
            if(can*10+d[i] > n) continue;
            bool flag = check(can*10+d[i]);
            que.push(can*10+d[i]);
            if(!flag) continue;
            num.push_back(can*10+d[i]);
        }
    }
}

int main(){
    int n;
    cin >> n;
    int s[3] = {3,5,7};
    for(int i = 0; i < 3; i++){
        if(s[i] > n) continue;
        que.push(s[i]);
    }
    solve(n);
    cout << num.size() << endl;
}

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

using namespace std;

const int N = 300005;

int a[N];

int main()
{
  int n;
  scanf("%d", &n);
  
  for (int i = 0; i < 3 * n; ++i) {
    scanf("%d", a + i);
  }
  
  sort(a, a + 3 * n, greater <int>());
  
  long long sum = 0;
  int j = 1;
  for (int i = 0; i < n; ++i) {
    assert(j < 3 * n);
    sum += a[j];
    j += 2;
  }
  
  printf("%lld\n", sum);
  return(0);
}

Measured memory_bytes: 1408
def main():
    n = int(input())

    A = 'zabcdefghijklmnopqrstuvwxyz'
    ans = ''
    while n > 0:
        ans = A[n % 26] + ans
        if(n % 26 == 0):
            n = n // 26 - 1
        else:
            n = n // 26

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61768
import java.util.Arrays;
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] arr = new int[m];
    for (int i = 0; i < arr.length; i++) {
      arr[i] = sc.nextInt();
    }
    long sum = Arrays.stream(arr).sum();
    if (n - sum < 0) {
      System.out.println("-1");
    } else {
      System.out.println(n - sum);
    }
  }
}



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

int main() {
  ll n,a,b,c,d,e;cin>>n>>a>>b>>c>>d>>e;
  ll mn=min({a,b,c,d,e});
  cout<<(n+mn-1)/mn+4;    
}

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

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

  vector<int> rm(T,0);
  for(int ci=0;ci<C;++ci){
    vector<int> tt(T,0);
    for(int i=0;i<N;++i){
      if(c[i]==ci+1){
        tt[s[i]-1] += 1;
        tt[t[i]-1] -= 1;
      }
    }
    for(int ti=1;ti<T;++ti){
      if(tt[ti]==1 && tt[ti-1]==0){
        tt[ti] = 0;
        tt[ti-1] = 1;
      }
    }
    for(int ti=0;ti<T-1;++ti){
      tt[ti+1] = tt[ti+1]+tt[ti];
    }
    for(int ti=0;ti<T;++ti){
      if(tt[ti]>0){
        rm[ti] += 1;
      }
    }
  }
  int ret = 0;
  for(int i=0;i<T;++i){
    if(ret<rm[i]){
      ret = rm[i];
    }
  }
  cout<<ret<<endl;
}


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

int main() {
	int N;

	cin >> N;
	vector<vector<int>> v_edge(N);
	vector<pair<int,int>> edge;

	for(int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		v_edge[a].emplace_back(b);
		v_edge[b].emplace_back(a);
		edge.emplace_back(a, b);
	}

	int K = 0;
	map<pair<int,int>,int> I;
	vector<int> cs(N,0);
	vector<int> used(N,0);
	queue<int> que;
	used[0] = 1;
	que.emplace(0);
	while(!que.empty()) {
		int v = que.front();
		que.pop();
		if (K < (int)v_edge[v].size()) K = v_edge[v].size();
		int cur = 1;
		for(int u:v_edge[v]) {
			if(used[u]) continue;
			if(cur==cs[v]) cur++;
			cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
			used[u] = 1;
			que.emplace(u);
		}
	}

	cout << K << endl;
	for(auto e:edge) cout << I[e] << endl;

	return 0;
}


Measured memory_bytes: 20084
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,max=-1;
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++)
	{
		int add;
		cin>>add;
		sum+=add;
		max=max>add?max:add;
	}
	cout<<sum-max/2;
	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  ll ans = 2*N;
  rep(i, N){
    if(s.substr(i, N-i)==t.substr(0, N-i)){
      ans = min(ans, i+N);
    }
  }

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


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

int main() {
  while(1) {
    long long x, y;
    cin >> x >> y;
    if(x + y == 0) break;
    cout << min(x, y) << " " << max(x, y) << endl;
  }
  return 0;
}


Measured memory_bytes: 3012