akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep_r(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define resize(x, n) x.resize(n)
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MAX = 100000;
struct edge {
    ll from, to, weight;
    edge(ll f, ll t, ll w) : from(f), to(t), weight(w) { }
};
vector<vector<edge>> edges;
vector<vector<ll>> graph;
vector<bool> visited;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll n, m, r, answer;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vl s(3);
    rep(i, 3) cin >> s[i];
    ll cnt = 0;
    while (not (s[0] == s[1] && s[1] == s[2])) {
        sort(all(s));
        if (s[0] < s[1] && s[1] < s[2]) {
            s[0]++;
            s[1]++;
        } else if (s[0] < s[1] && s[1] == s[2]) {
            s[0] += 2;
        } else if (s[0] == s[1] && s[1] < s[2]) {
            s[0]++;
            s[1]++;
        }
        cnt++;
    }
    printf("%ld\n", cnt);
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::set<int> s;
    for (int i = 0; i < 4; i++) {
        int a;
        std::cin >> a;
        s.insert(a);
    }

    if (s.find(1) != s.end() && s.find(4) != s.end() && s.find(7) != s.end() && s.find(9) != s.end()) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    
    N,M = LMIIS()
    edge = defaultdict(list)
    for i in range(M):
        a,b = LMIIS()
        edge[a].append(b)
        edge[b].append(a)

    #ダイクストラで1から各部屋への最短距離を求める
    visited = [-1] * (N+1)


    #根が１の木を作る
    #根から子を辿って、ルートを確定させていく
    roots = deque()
    roots.append(1)
    visited = [INF]*(N+1)
    visited[1] = 0
    lights = [0]*(N+1)
    while len(roots) > 0:
        root = roots.popleft()
        length = visited[root]
        for v in edge[root]:
            if length + 1 < visited[v]:
                visited[v] = length + 1
                lights[v] = root
                roots.append(v)
    print('Yes')
    for i in range(2,N+1):
        print(lights[i])





main()

Measured memory_bytes: 103992
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] b = new int[n + 1];
		for (int i = 1; i < n; i++)
			b[i] = sc.nextInt();

		int[] a = new int[n + 1];

		a[1] = b[1];
		a[n] = b[n - 1];
		for (int i = 2; i < n; i++)
			a[i] = Math.min(b[i - 1], b[i]);

		int ans = 0;
		for (int i = 1; i < n + 1; i++)
			ans = ans + a[i];
		System.out.println(ans);

	}

	static class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main(){
    string s;
    cin >> s;
    for(int i = s.size() - 1; i >= 2; i--){
        if(i % 2) continue;
        string t = s.substr(0, i);
        string u = s.substr(0, i / 2);
        if(u + u == t){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
t, t1, t2, t3 = 0, 0, 0, 0
while 1:
    a, b, c = sorted(map(int,input().split()))
    if a + b <= c: break
    t += 1
    D = a*a + b*b - c*c
    if   D > 0: t2 += 1
    elif D < 0: t3 += 1
    else:       t1 += 1         
print(t, t1, t2, t3)


Measured memory_bytes: 5604
#include <stdio.h>

int main(void){
  int n,i,j;
  int a,b[200001]={0};
  
  scanf("%d", &n);
  
  for(i=0;i<=n-2;i++){
    scanf("%d", &a);
    b[a]++;
  }
  
  for(i=1;i<=n;i++)printf("%d\n", b[i]);
  
  return 0;
}



Measured memory_bytes: 2516
n,k=map(int,input().split())
s=input()
if s[k-1]=='A':
  s = s[:k-1] + "a" + s[k:]
elif s[k-1]=='B':
  s=s[:k-1] + "b" + s[k:]
else:
  s=s[:k-1] + "c" + s[k:]
print(s)

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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int p[N], deg[N], res[N];
vector<int> vec[N], G[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> p[i];

    return true;
}

bool check(int v, int x) {
    res[v] = x;
    vec[p[v]].emplace_back(x);

    for (int u = p[v]; u != v; u = p[u]) {
        auto vv = vec[u];
        sort(vv.begin(), vv.end());
        vv.resize(unique(vv.begin(), vv.end()) - vv.begin());
        
        for (int i = 0; res[u] == -1; ++i)
            if (i >= vv.size() || i != vv[i])
                res[u] = i;

        vec[p[u]].emplace_back(res[u]);
    }

    for (int v = 0; v < n; ++v) {
        vector<int> vv;

        for (auto to : G[v])
            vv.emplace_back(res[to]);

        sort(vv.begin(), vv.end());
        vv.resize(unique(vv.begin(), vv.end()) - vv.begin());

        for (int i = 0; ; ++i)
            if (i >= vv.size() || i != vv[i]) {
                if (res[v] != i)
                    return false;

                break;
            }
    }

    return true;
}

void solve() {
    for (int i = 0; i < n; ++i) {
        ++deg[--p[i]];
        G[p[i]].emplace_back(i);
    }

    fill(res, res + n, -1);
    queue<int> Q;

    for (int i = 0; i < n; ++i)
        if (deg[i] == 0)
            Q.push(i);

    for (; !Q.empty(); Q.pop()) {
        auto v = Q.front();
        sort(vec[v].begin(), vec[v].end());
        vec[v].resize(unique(vec[v].begin(), vec[v].end()) - vec[v].begin());
        
        for (int i = 0; res[v] == -1; ++i)
            if (i >= vec[v].size() || i != vec[v][i])
                res[v] = i;

        vec[p[v]].emplace_back(res[v]);

        if (--deg[p[v]] == 0)
            Q.push(p[v]);
    }

    vector<int> cc;

    for (int v = 0; v < n; ++v)
        if (res[v] == -1)
            cc.emplace_back(v);

    assert(!cc.empty());
    auto v = cc[0];
    vector<int> mex, vv = vec[v];
    
    for (int k = 0; k < 2; ++k) {
        sort(vv.begin(), vv.end());
        vv.resize(unique(vv.begin(), vv.end()) - vv.begin());

        for (int i = 0; mex.size() != k + 1; ++i)
            if (i >= vv.size() || i != vv[i])
                mex.emplace_back(i);

        vv.emplace_back(mex.back());
    }

    if (check(v, mex[0])) {
        cout << "POSSIBLE\n";
        return ;
    }

    for (const auto& u : cc) {
        res[u] = -1;
        vec[u].pop_back();
    }

    if (check(v, mex[1])) {
        cout << "POSSIBLE\n";
        return ;
    }

    cout << "IMPOSSIBLE\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 23160
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k;
    cin >> n >> k;

    vector <double> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

    double cur = 0;
    for (int i = 0; i < k; i++) {
        cur += (p[i] + 1) / 2.0;
    }

    double ans = cur;
    for (int i = k; i < n; i++) {
        cur = cur + (p[i] + 1) / 2.0 - (p[i - k] + 1) / 2.0;
        ans = max(ans, cur);
    }

    cout << fixed << setprecision(12) << ans << "\n";
    return 0;
}

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

int main()
{
    int i,j,m=0,c=0,n=0;
    char str[1005];
    cin>>str;
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]=='R')
            n+=90;
        else
            n-=90;
        if(n==360)
        {
            c++;
            n=0;
        }
        else if(n==-360)
        {
            n=0;
        }
    }
   cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

int buf[105];

void run_case() {
    int n; cin >> n;
    int sum = 0;
    for(int i = 0; i < n; ++i) {
        cin >> buf[i];
        sum += buf[i];
    }
    int pos1 = ceil((double)sum / n);
    int pos2 = floor((double) sum / n);
    LL ans1 = 0, ans2 = 0;
    for(int i = 0; i < n; ++i) {
        ans1 += (pos1-buf[i])*(pos1-buf[i]);
        ans2 += (pos2-buf[i])*(pos2-buf[i]);
    }
    cout << min(ans1, ans2);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 256
import sys; from collections import deque; readline = sys.stdin.readline;

N, K, Q = map(int, readline().split())
A = [int(readline()) for i in range(Q)]

wins = [0 for n in range(N)]

for a in A:
    wins[a - 1] += 1

totalWins = sum(wins)

for n in range(N):
    if K - (totalWins - wins[n]) <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 51036
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void) {
	int a, b, c;
	
	cin >> a >> b >> c;
	cout << max({a,b,c})*10+(a+b+c-max({a,b,c})-min({a,b,c})) + min({a,b,c}) << endl;
	
	return 0;
}

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

int main()
{
	long long h,w;
cin>>h;
cin>>w;

if(h==1 || w==1)
{
cout<<"1";
return 0;
}

long long s=ceil(h/2.0)*ceil(w/2.0)+floor(h/2.0)*floor(w/2.0);
cout<<s;
return 0;
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int in(){
    unsigned x;
    scanf("%x",&x);
    return x;
}

void out(int y){
    unsigned x=y;
    printf("%x",x);
}

int A[8],B;
int dp[50][50];
void solve(){
    rep(i,8)A[i]=in();
    B=in();
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    rep(i,32){
        rep(j,50){
            if(dp[i][j]==-1)continue;
            rep(k,2){
                int tmp=j,foo=(B>>i&1)^k;
                rep(l,8)tmp+=(A[l]>>i&1)^k;
                if(tmp%2!=foo)continue;
                dp[i+1][tmp/2]=dp[i][j]|(k<<i);
            }
        }
    }
    rep(i,50){
        if(dp[32][i]!=-1){
            out(dp[32][i]);cout<<endl;
            return;
        }
    }
    cout<<"oh..."<<endl;

}


signed main(){
    int T;cin>>T;
    while(T--)solve();
    return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;


int main(){
    int a,b,c,d=0,beginn;
    scanf("%d %d %d",&a,&b,&c);
    beginn=min(a,b);
    while(d!=c){
        if(a%beginn==0&&b%beginn==0){
            d++;
        }
        beginn--;
    }
    printf("%d",beginn+1);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        bigOrSmall(a, b);
        
    }
    public static void bigOrSmall(int a, int b){
        if(a > b){
            System.out.println("a > b");
            
        }else if(a < b){
            System.out.println("a < b");
        }else{
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26064
fn main() {
    let nm = read_vec::<i64>();
    let mut n = nm[0];
    let m = nm[1];

    n = n % m;

    loop {
        if n > (n - m).abs() {
            n = (n - m).abs();
        } else {
            break;
        }
    }
    println!("{}",n);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int c[3][3];

int main() {
	rep(i,3) rep(j,3) cin>>c[i][j];
	bool ans=true;
	rep(i,2) rep(j,2) {
		if(c[i][j]-c[i+1][j]!=c[i][j+1]-c[i+1][j+1]) ans=false;
		if(c[i][j]-c[i][j+1]!=c[i+1][j]-c[i+1][j+1]) ans=false;
	}
	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 084 C / Link: http://abc084.contest.atcoder.jp/tasks/abc084_c  ----- */


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

	LL N; 
	cin >> N;

	VL c(N), s(N), f(N);
	FOR(i, 1, N) {
		cin >> c[i] >> s[i] >> f[i];
	}
	FOR(start, 1, N+1) {
		LL ans = 0LL;
		FOR(i, start, N) {
			if (ans < s[i]) {
				ans = s[i];
			}
			ans = ((ans - 1 + f[i]) / f[i])* f[i];
			ans += c[i];

		}
		cout << (ans) << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

#define MAX 1000000

int dp1[MAX+1], dp2[MAX+1];
int tetraNum[200];

int main(void)
{
    
    rep(i, 200) {
        tetraNum[i] = i*(i+1)*(i+2)/6;
    }

    rep(i, MAX+1) dp1[i] = dp2[i] = i;

    rep(i, MAX + 1) {
        rep(j, 200) {
            if(i + tetraNum[j] <= MAX) dp1[i + tetraNum[j]] = min(dp1[i + tetraNum[j]], dp1[i] + 1);
            if(tetraNum[j]%2 && i + tetraNum[j] <= MAX) dp2[i + tetraNum[j]] = min(dp2[i + tetraNum[j]], dp2[i] + 1);
        }
    }

    while(1) {
        int n;
        cin >> n;
        if(n == 0) break;

        cout << dp1[n] << " " << dp2[n] << endl;
    }
    
    return 0;
}


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    char b, ans;

    cin >> b;

    switch(b){
        case 'A':
            ans = 'T';
            break;
        case 'C':
            ans = 'G';
            break;
        case 'G':
            ans = 'C';
            break;
        default:
            ans = 'A';
            break;
    }

    cout << ans << endl;

    return 0;
}

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

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

class UnionFind {
    vector<int> par, Size;

  public:
    UnionFind(int n) : par(n), Size(n) {
        rep(i, n) {
            par[i] = i;
            Size[i] = 1;
        }
    }

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

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(Size[x] > Size[y]) {
            Size[x] += Size[y];
            par[y] = x;
        } else {
            Size[y] += Size[x];
            par[x] = y;
        }
    }

    int size(int x) { return Size[root(x)]; }
};

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

    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    vector<ll> px(n), py(n);
    rep(i, n) px[i] = py[i] = i;
    sort(ALL(px), [&](int a, int b) { return x[a] < x[b]; });
    sort(ALL(py), [&](int a, int b) { return y[a] < y[b]; });
    struct edge {
        int a, b;
        ll cost;
        edge(int a, int b, ll c) : a(a), b(b), cost(c) {}
    };
    vector<edge> e;
    rep(i, n - 1) {
        e.push_back(edge(px[i], px[i + 1], x[px[i + 1]] - x[px[i]]));
        e.push_back(edge(py[i], py[i + 1], y[py[i + 1]] - y[py[i]]));
    }
    sort(ALL(e), [&](edge a, edge b) { return a.cost < b.cost; });
    UnionFind UF(n);
    ll ans = 0;
    for(edge i : e) {
        if(!UF.same(i.a, i.b)) {
            UF.unite(i.a, i.b);
            ans += i.cost;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9584
n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|i| i.to_i}

min=10**10

#aの上限・下限によらない方法が存在するのかもしれない
#この問題の場合はaの範囲が狭いのでこれでもTLEしない(はず)
-100.upto(100) do |i|
	sum=0
	a.each do |j|
		sum+=(j-i)**2
	end
	if sum<min then
		min=sum
	end
end

puts min

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0;i < H;i++){
            for (int j = 0;j < W;j++){
                if ((i + j) % 2 == 0) cout << "#";
                if ((i + j) % 2 == 1) cout << ".";
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;

const int N = 300003;
const int MOD = 1e9 + 7;

inline int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int n = getInt();
  vi h(n), ans(n);
  for (int &x : h) {
    x = getInt();
  }
  int a = 0, b = abs(h[0] - h[1]);
  for (int i = 2; i < n; i++) {
    int c = min(a + abs(h[i] - h[i - 2]), b + abs(h[i] - h[i - 1]));
    a = b, b = c;
  }
  printf("%d\n", b);
  return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().strip().split())
v = list(map(lambda i : (int(i) + 1) / 2, input().strip().split()))
m = tM = sum(v[:k])
for i in range(k, n):
    tM += v[i] - v[i-k]
    m = max(m, tM)
print(m)


Measured memory_bytes: 23652
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	int sum=0;
	for(int i=1;i<=k;i++)
		sum+=a[i];
	cout<<sum<<endl;
    return 0;
}

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


int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int sum =0;
    rep(i,N){
        cin >> a.at(i);
        sum += a.at(i);
        a.at(i) *= N;
    }

    int mn = 100*N;
    int ix = 100;
    rep(i,N){
        if(abs(a.at(N-1-i)-sum) <= mn){
            mn = abs(a.at(N-1-i)-sum);
            ix = N-1-i;
        }
    }
    cout << ix << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
class NewVector: private vector<int>
{
public:

	NewVector(): vector<int>() {}

	void pushBack(int x)
	{
		push_back(x);
	}

	void randomAccess(int p)
	{
		cout << at(p) << endl;
	}

	void popBack()
	{
		pop_back();
	}

};

int main()
{
	NewVector a;
	int n;
	cin >> n;
	for (int i=0; i<n; ++i)
	{
		int c;
		cin >> c;
		if (c == 0)
		{
			int x;
			cin >> x;
			a.pushBack(x);
		}
		else if (c == 1)
		{
			int p;
			cin >> p;
			a.randomAccess(p);
		}
		else
		{
			a.popBack();
		}
	}
	return 0;
}


Measured memory_bytes: 3868
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n) cin >> a.at(i);
  ll count=0;
  int flag = 0;
  rep(i,n-1){
    if(a.at(i+1) - a.at(i) >0) {
      if(flag == -1){
        count ++;
        flag = 0;
      }
      else flag = 1;
    }
    else if(a.at(i+1) - a.at(i) <0){
      if(flag == 1){
        count ++;
        flag=0;
      }
      else flag = -1;
    }
  }
  cout << count + 1<< endl;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll h[MAXN];
ll dp[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> h[i];

    return true;
}

void solve() {
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for (int i = 2; i < n; ++i)
        dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));

    cout << dp[n - 1] << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 5120
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int A = reader.nextInt();
        int B = reader.nextInt();
        int ans = A<10 && B<10 ? A*B : -1;
        System.out.println(ans);
    }

    public static long[][] warshall(int n, long[][]matrix) {
        long[][] ans = matrix;
        for(int i=0; i<n; i++) {
            ans[i][i] = 0;
        }
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                for(int k=0; k<n; k++) {
                    ans[j][k] = Math.min(ans[j][k], ans[j][i]+ans[i][k]);
                }
            }
        }
        return ans;
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

const intmax_t MOD = (intmax_t)(1e9 + 7);

int main (void)
{
    size_t N, K;
    intmax_t A[2000];
    intmax_t tentousuu = 0, s = 0, ans = 0;

    scanf("%zu%zu", &N, &K);
    for(size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
    }

    for (intmax_t i = 0; i < (N - 1); i++) {
        for (intmax_t j = (i + 1); j < N; j++) {
            if (A[i] > A[j]) tentousuu++;
        }
    }
    tentousuu %= MOD;

    for (intmax_t i = 0; i < N; i++) {
        for (intmax_t j = 0; j < N; j++) {
            if (A[i] > A[j]) s++;
        }
    }
    s %= MOD;

    ans = tentousuu * K;
    ans %= MOD;

    ans += s * ((K * (K - 1) / 2) % MOD);
    ans %= MOD;

    printf("%jd\n", ans);

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define ff first
#define ss second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define d(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define IO ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define mem(a, b) memset(a,b,sizeof(a))

int main()
{
    int n; cin >> n;
    n = n%10;
    if(n == 0 or n == 1 or n == 6 or n == 8)
        cout << "pon" << endl;
    else if(n == 3)
        cout << "bon" << endl;
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


a, b, x = MI()
print("YES") if a <= x <= a + b else print("NO")


Measured memory_bytes: 5184
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let x: i64 = it.next().unwrap().parse().unwrap();
    let y: i64 = it.next().unwrap().parse().unwrap();
    let mut ans = std::i64::MAX;
    if x < y {
        ans = std::cmp::min(ans, y - x);
    }
    if -x <= y {
        ans = std::cmp::min(ans, 1 + y + x);
    }
    if x <= -y {
        ans = std::cmp::min(ans, 1 + -y - x);
    }
    if -x <= -y {
        ans = std::cmp::min(ans, 2 + -y + x);
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<utility>

using namespace std;
typedef pair<int, int> P;
const int INF = (1 << 30);
int V, E, r;
int dp[100000];
struct edge{
	int to, cost;
	edge(int to,int cost=1):to(to),cost(cost){}
};
vector<edge> G[100000];



int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	 cin >> V >> E >> r;
	for (int i = 0; i < E; ++i) {
		int s, t, d;
		cin >> s >> t >> d;
		edge e(t,d);
		G[s].emplace_back(e);
	}
	fill(dp, dp + V, INF);
	dp[r] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	P start(0, r);
	que.push(start);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (dp[p.second] < p.first)continue;

		int v = p.second;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (dp[e.to]>dp[v] + e.cost) {
				dp[e.to] = dp[v] + e.cost;
				que.push(P(dp[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < V; ++i) {
		if (dp[i] == INF)cout << "INF\n";
		else cout << dp[i] << "\n";
	}
	cout << flush;
	return 0;
}

Measured memory_bytes: 11280
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String str = null;
		String[] item = new String[3];
		int a, b;
		while(true){
			str = scan.nextLine();
			item = str.split(" ");
			a = Integer.parseInt(item[0]);
			b = Integer.parseInt(item[2]);
			if(item[1].equals("?")){
				break;
			}
			switch(item[1]){
				case "+":
					System.out.println( a + b );
					break;
				case "-":
					System.out.println( a - b );
					break;
				case "*":
					System.out.println( a * b );
					break;
				case "/":
					System.out.println( a / b );
					break;

			}
		}
	}
}


Measured memory_bytes: 26064
import java.util.Scanner;

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

	void solver() {
		Scanner sc = new Scanner(System.in);
		long[] len = new long[3];
		for (int i = 0; i < 3; i++) {
			len[i] = sc.nextLong();
		}

		long ans = 1L << 60;
		for (int i = 0; i < 3; i++) {
			long tmp = 1;
			for (int j = 0; j < 3; j++) {
				if (i != j)
					tmp *= len[j];
			}
			ans = Math.min(ans, tmp * Math.abs(len[i] / 2 - (len[i] - len[i] / 2)));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 9428
import scala.io.StdIn

object Main extends App {
  val a = StdIn.readLine().split(' ')
  println((Integer.parseInt(a(0)) to Integer.parseInt(a(1))).foldLeft(0){ (acc, i) =>
    val tmp = i.toString
    if(tmp.take(2).reverse == tmp.takeRight(2)) acc + 1 else acc
  })
}


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

#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 rep0c(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

int N, M;
vector<ll> as;
vector<pair<ll, ll> > cbs;

void solve() {
  sort(as.begin(), as.end());
  sort(cbs.begin(), cbs.end(), greater<pair<int, int> >());
  ll min_a = as.front();
  ll max_c = cbs.front().first;
  decltype(cbs)::iterator cb_itr = cbs.begin();
  for(decltype(as)::iterator a_itr = as.begin(); a_itr != as.end(); a_itr++) {
    if(cb_itr->first<=(*a_itr)) break;
    (*a_itr) = cb_itr->first;
    if(--(cb_itr->second) == 0) cb_itr++;
    if(cb_itr == cbs.end()) break;
  }
  ll res = 0;
  for(const ll& a : as) res += a;
  printf("%lld\n", res);
}

int main() {
  scanf("%d %d", &N, &M);
  ll a, b, c;
  rep(i, N) {
    scanf("%lld", &a);
    as.push_back(a);
  }
  rep(i, M) {
    scanf("%lld %lld", &b, &c);
    cbs.push_back(make_pair(c, b));
  }
  solve();
  return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
typedef string::const_iterator State;
Def expr(State &i);
Def term(State &i);
Def factor(State &i);
Def number(State &i);
void consume(State &i,char expected){
	if(*i==expected)i++;
	else{
		exit(0);
	}
}
Def expr(State &i){
	Def out=term(i);
	while(*i=='+'||*i=='-'){
		char op=*i;
		i++;
		Def out1=term(i);
		if(op=='+')out+=out1;
		else out-=out1;
	}
	return out;
}
Def term(State &i){
	Def out=factor(i);
	while(*i=='*'||*i=='/'){
		char op=*i;
		i++;
		Def out1=factor(i);
		if(op=='*')out*=out1;
		else out/=out1;
	}
	return out;
}
Def factor(State &i){
	if(isdigit(*i))return number(i);
	//'('
	i++;
	Def out=expr(i);
	i++;
	return out;
}
Def number(State &i){
	Def out=0;
	while(isdigit(*i))out=out*10+*(i++)-'0';
	return out;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		State begin=s.begin();
		cout<<expr(begin)<<endl;
	}
}

Measured memory_bytes: 3008
#include <stdio.h>

int main(){
	int N;
	int T;
	int X=0;
	scanf("%d %d",&N,&T);
	//はじめは0s
	int t2=0;
	int t1=0;
	int i=0;
	for(int i=0;i<N+1;i++){
		t1=t2;
		if(i==N){X+=T;break;}
		scanf("%d",&t2);
		if((t2-t1)>T)	X+=T;
		else X+=		(t2-t1);
	}
	printf("%d",X);
}

Measured memory_bytes: 128
//
//  main.cpp
//  AtCoderABC176
//
//  Created by Glen Cahilly on 9/2/20.
//  Copyright © 2020 Glen Cahilly. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

/*

Problem A

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double n, x, t;
    cin >> n >> x >> t;
    if (x==0) {
        cout << 0 << "\n";
    } else {
        long k = ceil(n/x)*t;
        cout << k << "\n";
        
    }
}
*/

//Problem B

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    long count=0;
    for (int k=0; k<s.size(); k++) {
        count+=s[k]-48;
    }
    if (count%9==0) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 3784
// Era Name
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    int m = kbd.nextInt();
	    if(n!=0 && m!=0){
		solve(n, m);
	    }
	}
    }

    static void solve(int n, int m){
	Era[] era = new Era[n];
	int i=0;
	// 時代設定ここから
	while(i<n){
	    String name = kbd.next();
	    int eY = kbd.nextInt();
	    int gY = kbd.nextInt();
	    era[i] = new Era(name, eY, gY);
	    i++;
	}

	i=0;
	while(i<m){
	    int year = kbd.nextInt();
	    search(era, year);
	    i++;
	}
    }
    
    static void search(Era[] era, int year){
	int i;
	int ans=0;
	String eraname="";
	for(i=0; i<era.length; i++){
	    if(era[i].searchEra(year) > 0){
		ans = era[i].searchEra(year);
		eraname = era[i].getName();
	    }
	}
	if(ans != 0)
	    System.out.println(eraname+" "+ans);
	else 
	    System.out.println("Unknown");
    }
}

class Era{
    String name;
    int ke;
    int kg;
    public Era(String n, int e, int g){
	name = n;
	ke = e;
	kg = g;
    }

    public int searchEra(int g){
	if(kg-g >=0){
	    int ans = ke-(kg-g);
	    return ans;
	}
	else return 0;
    }

    public String getName(){
	return name;
    }
}

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

typedef long long ll;

int n,x[15],y[15],p[15],D[15],d[15];
ll ans[16];

int main(){

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

    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>p[i];
    memset(ans,0x3f,sizeof(ans));
    ans[0]=0;
    for(int i=0;i<n;i++){
        D[i]=min(abs(x[i]),abs(y[i]));
        ans[0]+=(ll)p[i]*D[i];
    }
    for(int s=0;s<1<<n;s++){
        for(int t=s;true;t=(t-1)&s){
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
            if(t==0)break;
        }
       /* {
            int t=0;
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    // if(t>>i&1){
                    //     for(int j=0;j<n;j++){
                    //         d[j]=min(d[j],abs(x[i]-x[j]));
                    //     }
                    // }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                   // }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }*/
    }
    for(int i=0;i<=n;i++)cout<<ans[i]<<'\n';

    return 0;
}


Measured memory_bytes: 3664
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s,w=LI()
  if w>=s:
    return 'unsafe'
  return 'safe'

# main()
print(main())


Measured memory_bytes: 10752
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001
#define MOD 1000000007

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool turn = true;

  while((a > 0) && (c > 0)) {
    if (turn) c -= b;
    else a -= d;
    
    turn = !turn;
  }

  cout << (turn ? "No" : "Yes") << endl;
  
}


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

int main() {
    int N;
    cin >> N;
    int tmp;
    for (int i=0; i<N; i++) {
        cin >> tmp;
        if (tmp%2==0) {
            if (tmp%3!=0 && tmp%5!=0) {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        if(A[i] % 2 !== 0 && (~~i + 1) % 2 !== 0) {
            answer++;
        }    
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29640
A, B, C = (int(i) for i in input().split())

first = min(B, C)

B = B - first
C = C - first

if(B == 0):
    if(A >= C-1):
        second = C
    else:  # A>=C
        second = min(A, C)+1
else:  # C==0
    second = B

print(int(first * 2 + second))


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

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

char s[1100][1100];
int n, m;
struct task {
	int x, y;
	int res;
};
queue<task>q;


int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(s[i][j] == '#') q.push({i, j, 0});
		}
	}
	int ans = 0;
	while(!q.empty()) {
		task now = q.front(); q.pop();
		ans = max(ans, now.res);
		for(int i = 0; i < 4; ++i) {
			int x = now.x + dx[i], y = now.y + dy[i];
			if(s[x][y] == '.') {
				s[x][y] = '#';
				q.push({x, y, now.res + 1});
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n, k, x;
    vector<ll> positive, negative;
    cin >> n >> k;
    rep(i, n){
        cin >> x;
        if(x > 0) positive.push_back(x);
        else negative.push_back(x);
    }

    sort(positive.begin(), positive.end());
    sort(negative.begin(), negative.end(), greater<ll>());

    ll resmin = inf;

    if(positive.size() == 0) resmin = abs(negative[k-1]);
    else if(negative.size() == 0) resmin = positive[k-1];
    else{
        rep(i, positive.size()){
            rep(j, negative.size()){
                if((i+1)+(j+1) != k) continue;
                ll cnt = min(positive[i] + 2*abs(negative[j]), 2*positive[i] + abs(negative[j]));
                chmin(resmin, cnt);
            }
        }
    }

    cout << resmin << endl;

    return 0;
}

Measured memory_bytes: 1656