akhauriyash/Code-Regression huggingface dataset:
#include<bits//stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 29);
int h, m, n;
const ll MOD= 1000000007;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
        src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge& e, const Edge& f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
pair<Weight, Edges> minimumSpanningForest(const Graph& g) {
    int n = g.size();
    UnionFind uf(n);
    priority_queue<Edge> Q;
    rep(u, n) {
        for (auto e = g[u].begin(); e != g[u].end();e++) {
            if (u < e->dst) Q.push(*e);
        }
    }
    Weight total = 0;
    Edges F;
    while (F.size() < n - 1 && !Q.empty()) {
        Edge e = Q.top(); Q.pop();
        if (uf.unite(e.src, e.dst)) {
            F.push_back(e);
            total += e.weight;
        }
    }
    return pair<Weight, Edges>(total, F);
}
int main() {
    cin >> n >> m; int a, b, c;
    vector<vector<Edge>> G(m+1);
    rep(i, m) {
        cin >> a >> b >> c;
        Edge e = { a,b,c };
        G[a].push_back(e);
        e = { b,a,c };
        G[b].push_back(e);
    }
    pair<Weight, Edges> p = minimumSpanningForest(G);
    cout << p.first << endl;
}


Measured memory_bytes: 11132
N = int(input())
X = [int(i) for i in input().split()]

A = sorted(X)

m_r = A[N//2]
m_l = A[N//2-1]

for i in range(N):
    if X[i] >= m_r:
        print(m_l)
    else:
        print(m_r)


Measured memory_bytes: 25620
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main() {

	char S[101];
	cin >> S;
	int res = 0;
	int size = strlen(S); //文字列の数を取得
	for (int i = 0; i < size/2; ++i) {
		if (S[i] != S[size - (1 + i)]) ++res;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define rep(i,j,k) for(register int i = j; i <= k; i++) 
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define fi first
#define se second
//#define P pair<ull,ull>
//#define PP pair<int,pair<int,int> >
//#define mp(a,b) make_pair(a,b)
#define ll long long
#define ull unsigned long long
using namespace std;
 
inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 1e5+7, p = 1e9+7;
inline void out() { puts("No"), exit(0); }

int main() {
	int x, minl = N, maxl = 0, n1 = 0, n2 = 0, n = read();
	rep(i,1,n) { 
		x = read();
		if( x < minl ) minl = x, n1 = 1;
		else if( x == minl ) n1++;
		
		if( x > maxl ) maxl = x, n2 = 1;
		else if( x == maxl ) n2++;
	}
	
	if( maxl - minl > 1 ) out();
	if( minl == maxl ) { 
		if( minl != n - 1 && maxl > n / 2 ) out();
	} else { 
		if( n1 >= maxl ) out();
		maxl -= n1;
		if( maxl * 2 > n - n1 ) out();
	}
	puts("Yes");
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll x;
    cin >> x;
    ll a = 0;
    rep(i,1e5){
        a += (ll)i;
        if(a>=x){
            if(a-x <= (ll)i){
                cout << i << endl;
                return 0;
            }
        }
    }

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
//#define mod 1000000007ll
#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
ll dp[3010][3010];
int main()
{
    cout << fixed << setprecision(30);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    Loop(i, A, C + 1)
    {
        Loop(j, B, D + 1)
        {
            if (i > A)
                dp[i][j] += (dp[i - 1][j] * j) % mod;
            if (j > B)
                dp[i][j] += (dp[i][j - 1] * i) % mod;
            if (i > A && j > B)
                dp[i][j] -= (((dp[i - 1][j - 1] * (i - 1)) % mod) * (j - 1)) % mod;
            dp[i][j] %= mod;
            if (dp[i][j] < 0)
                dp[i][j] += mod;
        }
    }
    putout(dp[C][D]);
    return 0;
}


Measured memory_bytes: 73996
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> s(100002,0);
    int a;
    for(int i = 0;i < n;i++){
        cin >> a;
        s[a]++;s[a+1]++;s[a+2]++;
    }
    int ans = 0;
    for(int i = 0;i < s.size();i++){
        if(ans < s[i]) ans = s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
from collections import defaultdict


def get_dic(dic_data, x):
    while x != dic_data[x]:
        x = dic_data[x]
    return x

def main():
    num, hinto = map(int, input().split())
    data_flg = [-1 for i in range(num + 1)]
    ans = 0
    modoru = 0

    dic_data = {i: i for i in range(num + 1)}

    real_ans = 0

    for i in range(hinto):
        x, y, z = map(int, input().split())

        if data_flg[x] == -1 and data_flg[y] == -1:
            data_flg[x] = ans
            data_flg[y] = ans
            ans += 1
            real_ans += 1
        elif data_flg[x] == -1 or data_flg[y] == -1:
            aaa = max(data_flg[x], data_flg[y])
            data_flg[x] = aaa
            data_flg[y] = aaa
        else:
            # print(data_flg[x], data_flg[y])
            nnn = get_dic(dic_data, data_flg[x])
            bbb = get_dic(dic_data, data_flg[y])
            if nnn != bbb:
                dic_data[nnn] = ans
                dic_data[bbb] = ans
                modoru += 1
                ans += 1

    real_ans -= modoru

    for i in range(1, num + 1):
        if data_flg[i] == -1:
            real_ans += 1

    print(real_ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 59692
#include <iostream>
#include <string>

bool check(std::string s[], int i, int j, int H, int W) 
{
  bool can = false;
  if ( i - 1 >= 0 ) {
    can =  s[i-1][j] == '#';
  }
  if ( !can && i + 1 < H ) {
    can =  s[i+1][j] == '#';
  }
  if ( !can && j - 1 >= 0 ) {
    can =  s[i][j-1] == '#';
  }
  if ( !can &&  j + 1 < W ) {
    can =  s[i][j+1] == '#';
  }
  return can;
}

int main()
{
  int H, W;
  std::cin >> H >> W;
  
  std::string s[H];
  for ( int i = 0; i < H; i++ ) std::cin >> s[i];

  bool can_draw = true;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      if ( s[i][j] == '#' && !check(s, i, j, H, W) ) {
        can_draw = false;
        break;
      }
    }
  }
  if ( can_draw ) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }
  return 0;
}


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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}
};

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	std::vector<bool> isBroken(N);
	for (int i{}; i < M; i++)
	{
		int a;
		scanf("%d", &a);
		isBroken[a] = true;
	}
	std::vector<ModInt<>> dp(N + 2);
	dp[0] = ModInt<>(1ll);
	for (int i{}; i <= N - 1; i++)
	{
		if (!isBroken[i + 1])
			dp[i + 1] += dp[i];
		if (!isBroken[i + 2])
			dp[i + 2] += dp[i];
	}
	printf("%lld\n", (int64_t)dp[N]);
	return 0;
}

Measured memory_bytes: 1024
N = input()
ls = list(map(int, input().split()))
dic = {}
for item in ls:
    if item in dic:
        dic[item] += 1
    else:
        dic[item] = 1 
    item_u = item+1
    if item_u in dic:
        dic[item_u] += 1
    else:
        dic[item_u] = 1
    item_l = item-1
    if item_l in dic:
        dic[item_l] += 1
    else:
        dic[item_l] = 1
print(max(dic.values()))

Measured memory_bytes: 19672
<?php

fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s", $a);
    fscanf(STDIN, "%s", $b);
    $x = new BigInt();
    if (!$x->setNum($a)) {
        echo 'overflow' . PHP_EOL;
        continue;
    }
    $y = new BigInt();
    if (!$y->setNum($b)) {
        echo 'overflow' . PHP_EOL;
        continue;
    }
    $total = $x->add($y);
    if ($total === NULL) {
        echo 'overflow' . PHP_EOL;
        continue;
    }
    echo $total;
    echo PHP_EOL;
}

class BigInt
{
    const PLACE = 18;
    public $num = array();
    public $maxLen;
    private $zero;

    public function __construct($maxLen = 80) {
        $this->maxLen = $maxLen;
        $n = ceil($maxLen / self::PLACE);
        for ($i = 0; $i < $n; $i++) {
            $this->num[] = '';
        }
        $this->zero = implode(array_fill(0, self::PLACE, '0'));
    }

    public function setNum($num) {
        if (strlen($num) > $this->maxLen) {
            return FALSE;
        }
        $n = ceil($this->maxLen / self::PLACE);
        for ($i = 0; $i < $n; $i++) {
            if (strlen($num) <= self::PLACE) {
                $this->num[$i] = implode(array_fill(0, self::PLACE - strlen($num), '0')) . $num;
                break;
            }
            $this->num[$i] = substr($num, - self::PLACE);
            $num = substr($num, 0, strlen($num) - self::PLACE);
        }
        return TRUE;
    }

    public function add(BigInt $a) {
        $num = $this->num;
        $n = ceil($this->maxLen / self::PLACE);
        $up = 0;
        for ($i = 0; $i < $n; $i++) {
            $num[$i] = (int) $num[$i] + (int) $a->num[$i] + $up;
            if ($num[$i] > 0) {
                $num[$i] = (string) $num[$i];
            } else {
                $num[$i] = $this->zero;
            }
            if (strlen($num[$i]) > self::PLACE) {
                $num[$i] = substr($num[$i], - self::PLACE);
                $up = 1;
            } elseif (strlen($num[$i]) < self::PLACE) {
                $num[$i] = implode(array_fill(0, self::PLACE - strlen($num[$i]), '0')) . $num[$i];
                $up = 0;
            }
        }
        $total = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $total .= $num[$i];
        }
        $total = preg_replace('/^0*/', '', $total);
        if ($total === '') {
            $total = '0';
        }
        if (strlen($total) > $this->maxLen) {
            return NULL;
        }
        return $total;
    }
}

Measured memory_bytes: 6848
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	const int MAX_N = 100 , MAX_V = 1000 , MAX_W = 10000;
	int n,W;
	cin >> n >> W;
	int v[n]={},w[n]={};
	rep(i,0,n)
		cin >> v[i] >> w[i];
	
	int dp[MAX_N+1][MAX_W+1]={};
	
	rep(i,0,n){
		rep(j,0,W+1){
			if( j < w[i] )
				dp[i+1][j] = dp[i][j];
			else
				dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
		}
	}
	

	P(dp[n][W]);
	ret 0;
}


Measured memory_bytes: 7056
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(n);
  GVI(p, n);
  int ans = 0;
  FOR(i, n - 2) {
    vector<int> list;
    FORIN(j, i, i + 3) { list.push_back(p[j]); }
    sort(ALL(list));
    if (list[1] == p[i + 1])
      ans++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "string"


int main()
{
	int a, b, result;
	char op;
	while (true)
	{
		std::cin >> a >> op >> b;
		if (op == '+') result = a + b;
		if (op == '-') result = a - b;
		if (op == '*') result = a * b;
		if (op == '/') result = a / b;
		if (op == '?') break;
		std::cout << result << std::endl;
	}
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <utility>
#include <functional>
#include <valarray>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>

using namespace std;

#define REP(i, n) for(i = 0; i < (n); i++)
#define FOR(i, a, n) for(i = a; i < n; i++)
#define REV(i, a, n) for(i = a; i > n; i--)

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}


struct UnionFind {
    int N, *id, *sz;

    UnionFind(int N) {
        this->N = N;
        id = new int[N];
        sz = new int[N];
        for(int i = 0; i < N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UnionFind() {
        delete[] id;
        delete[] sz;
    }
    int root(int i) {
        while(i != id[i]) {
            id[i] = id[id[i]];
            i = id[i];
        }
        return i;
    }
    bool find(int p, int q) {
        return root(p) == root(q);
    }
    void unite(int p, int q) {
        int i = root(p);
        int j = root(q);
        if(i == j) return;
        if(sz[i] < sz[j]) {
            id[i] = j; sz[j] += sz[i];
        } else {
            id[j] = i; sz[i] += sz[j];
        }
    }
};

struct Edge {
    int a, b, cost;
    Edge(){}
    Edge(int _a, int _b, int _cost): a(_a), b(_b), cost(_cost){}
    bool operator<(const Edge& e) const {
        return cost < e.cost;
    }
};

typedef long long ll;
typedef long double ld;

int i, j, value, s, d;

int main(void) {
    while(scanf("%d%d", &s, &d) ==  2 && !(s == 0 && d == 0)) {
        vector<Edge> ve;
        REP(i, s) REP(j, d) {
            scanf("%d", &value);
            if(value != 0) {
                ve.push_back(Edge(i, s + j, value));
            }
        }
        REP(i, d - 1) {
            FOR(j, i + 1, d) {
                scanf("%d", &value);
                if(value != 0) {
                    ve.push_back(Edge(s + i, s + j, value));
                }
            }
        }
        REP(i, s) FOR(j, i+1, s) {
            ve.push_back(Edge(i, j, 0));
        }
        sort(ve.begin(), ve.end());
        UnionFind uf((s + d) * 3);
        int cost = 0;
        REP(i, ve.size()) {
            if(!uf.find(ve[i].a, ve[i].b)) {
                cost += ve[i].cost;
                uf.unite(ve[i].a, ve[i].b);
            }
        }
        printf("%d\n", cost);
    }
    return 0;
}

Measured memory_bytes: 1268
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
	int x,y;
	scanf("%d %d",&x,&y);
	int a=x,b=y;
	x*=100;
	y*=10;
	if(x%8==0){
		x=x/8;
	}else{
		x=x/8+1;
	}
	int t=max(x,y);
	int aa=t*0.08;
	int bb=t*0.1;
	if(aa==a&&bb==b){
		printf("%d",t);
	}else{
		printf("-1");
	}
	
}


Measured memory_bytes: 128
R,G,B,N = gets.strip.split.map(&:to_i)
s = 0
k = 0
for i in 0..(N/R) do
  for j in 0..(N/G) do
    k = (N - i*R - j*G) / B;
    s += 1 if k >= 0 && i*R + j*G + k*B == N
  end
end
puts s

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
using namespace std;


int main()
{
    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

const int QUEUE_SIZE = 100000;

struct Process {
  int time;
  int remain;
  std::string name;
};

int main() {
  int n = 0;
  int q = 0;

  std::cin >> n;
  std::cin >> q;

  struct Process queue[QUEUE_SIZE];
  int count = 0;

  int front = 0;
  int rear = 0;

  for (int i = 0; i < n; i++) {
    std::cin >> queue[i].name;
    std::cin >> queue[i].time;

    rear++;
  }

  int time = 0;

  while (front != rear) {
    struct Process p = queue[front];
    front++;
    
    front = front % QUEUE_SIZE;
    
    p.time -= q;

    if (p.time > 0) {
	time += q;
      
	queue[rear] = p;
	rear++;

	rear = rear % QUEUE_SIZE;
      } else {
	time += q + p.time;
      
	std::cout << p.name << " " << time << std::endl;;
      }
  }
  
  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    string a, b; cin >> a >> b;

    string ab = a + b;
    for(int i = 1; i < stoi(ab) / 2; ++i) {
        if(i == stoi(ab) / i && stoi(ab) % i == 0) {
            cout << "Yes" << endl;
            break;
        }

        if(i == (stoi(ab) / 2) - 1) {
            cout << "No" << endl;
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  REP(i, n+1){
    REP(j, n+1){
      int amari = n - r*i - g*j;
      if (amari >= 0  and amari % b == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

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

    ll value = 7;

    if (k % 2 == 0 | k % 5 == 0) {
        cout << -1;
        return 0;
    }

    int cnt = 0;
    while (true) {
        cnt++;
        value %= k;
        if (value == 0) {
            break;
        }
        value = value * 10 + 7;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<math.h>
#define lli long long int
#define MAX 100005

lli min(lli a, lli b)
{
	return a>b?b:a;
}

using namespace std;

int main(void)
{
	lli i,n,a[MAX],s[MAX];
	cin>>n;
	if(n==1)
	{
		cin>>a[0];
		cout<<"0"<<endl;
	}
	else if(n==2)
	{
		cin>>a[0]>>a[1];
		cout<<fabs(a[0]-a[1])<<endl;
	}
	else
	{
		cin>>a[0]>>a[1];
		s[0]=0;
		s[1]=fabs(a[1]-a[0]);
		for(i=2;i<n;i++)
		{
			cin>>a[i];
			s[i] = min(s[i-2] + fabs(a[i]-a[i-2]),(s[i-1] + fabs(a[i-1]-a[i])));
//			printf("s[%lld] = %lld\n",i,s[i]);
		}

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



	return 0;
}


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

int main(){
    int a,h,m,s;
    cin >> a;
    h = a / 3600;
    m = (a % 3600) / 60;
    s = a % 3600 % 60;



    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3104
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	getInt()
	S := getString()
	// out(N, S)
	ans := 0
	for i := 0; i < 1000; i++ {
		a := make([]int, 3)
		idx := 2
		for n := i; n > 0; n /= 10 {
			a[idx] = n % 10
			idx--
		}
		idx = 0
		// out("----", idx)
		for _, v := range S {
			// out(v)
			if a[idx] == int(v-'0') {
				idx++
				// out(idx)
				if idx == 3 {
					ans++
					break
				}
			}
		}
	}
	out(ans)
}


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

int main() {
  int N ;
  cin >> N ;
  vector <int> a(N);
  int sum = 0 ;
  for ( int i=0 ; i<N ; i++){
    cin >> a.at(i) ;
    sum += a.at(i) ;
  }
  int M ;
  cin >> M ;
  vector <int> d(M) ;
  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    p.at(i) = make_pair(b, c);  // b, a の順でペアにする
  }
  for ( int i=0 ; i<M ; i++){
    int b, c;
    tie(b, c) = p.at(i);
    d.at(i) = sum -a.at(b-1) +c;
    cout << d.at(i) << endl;
  }
}

Measured memory_bytes: 3636
#include <cstring>
#include <cstdio>
using namespace std;
const int L = 200010;
const int P = 1339;
typedef unsigned long long ull;
int ans=1,n;
ull bin[L],hash[L];
char str[L];
ull geth(int l,int r){
	return hash[r]-hash[l-1]*bin[r-l+1];
}
int main(){
	scanf("%s",str);
	n=strlen(str);
	bin[0]=1;
	for(int i=1; i<n; i++){
		bin[i]=bin[i-1]*P;
	}
	hash[0]=str[0]-'a'+1;
	for(int i=1; i<n; i++){
		hash[i]=hash[i-1]*P+str[i]-'a'+1;
	}
	ull last=geth(0, 0),now=0;
	int l=1,r=1;
	while(l<=r && r<n){
		now=geth(l, r);
		if(now==last){
			r++;
		}
		else{
			ans++;
			l=r+1;
			r=l;
			last=now;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3584
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    n =int(input())
    ans =1
    for i in range(1,n+1):
        ans = ans *i
        ans = ans % (10**9 +7)
    print(ans)



Measured memory_bytes: 5144
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);

    public static void main(String[] args) {
        scn.useDelimiter("\\D+");
        int cnt = 0;
        while(scn.hasNextInt()) {
            cnt += scn.nextInt();
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26208
"use strict";
    
const main = arg => {
    const N     = arg.split("\n")[0];
    const cards = arg.split("\n")[1].split(" ").sort((a,b)=>b-a).map(n=>parseInt(n));
    let alice = 0;
    let bob = 0;
    
    for(let i in cards) {
        if(i % 2 === 0) {
            alice += cards[i];
        } else {
            bob += cards[i];
        }
    }
    console.log(alice - bob);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
# -*- coding: utf-8 -*-

s = int(input())

def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

a = [s]
while True:
    if f(a[-1]) in a:
        print(len(a) + 1)
        break
    else:
        a.append(f(a[-1]))


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

using namespace std;

int f(vector<pair<int, int>> arr) {
    int result = 0;
    for (int i = 0; i < arr.size(); i++) {
        result += arr[i].second - arr[i].first + 1;
    }
    return result;
}

int main() {

    int n;
    cin >> n;

    vector<pair<int, int>> arr;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;

        int r;
        cin >> r;

        pair<int, int> tmp = make_pair(l, r);
        arr.push_back(tmp);
    }

    int result = f(arr);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b-a > k or c-a > k or d-a > k or e-a > k or c-b > k or d-b > k or e-b > k or d-c > k or e-c > k or e-d > k:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
vector<bool> isPrime;
void sieve(int max) {
  if (max+1 > isPrime.size()) isPrime.resize(max+2,true);

  isPrime[0] = false;
  isPrime[1] = false;
  
  for (int i = 2; i*i <= max; i++)
  {
    if (!isPrime[i]) continue;
    for (int j = 2; j*i <= max; j++) isPrime[i*j] = false;
  }
}
const int MAX_N = 100010;
int main() {
  int q;
  cin >> q;
  sieve(MAX_N);
  vector<int> sum(MAX_N+1,0);
  for (int i = 3; i <= MAX_N; i += 2)
  {
    if (isPrime[i] && isPrime[(i+1)/2]) sum[i] = sum[i-2] + 1;
    else sum[i] = sum[i-2];
  }
  //rep(i,10) cout << sum[i] << endl;
  int l,r;
  rep(i,q)  {
    cin >> l >> r;
    cout << sum[r] - sum[max(l-2,0)] << endl;
  }
  return 0;
}

Measured memory_bytes: 3792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int a = 0;
        int b = 0;
        int ans = 0;
        String op = "";

        Scanner sc= new Scanner(System.in);

        while( true ) {
        	a = sc.nextInt();
        	op = sc.next();
        	b = sc.nextInt();

        	if( op.equals( "?" ) ) {
        		break;
        	}

        	switch( op ) {
        	case "+":
        		ans = a + b;
        		break;
        	case "-":
        		ans = a - b;
        		break;
        	case "*":
        		ans = a * b;
        		break;
        	case "/":
        		ans = a / b;
        		break;
        	}
        System.out.println( ans);
        }
    sc.close();
    }
}


Measured memory_bytes: 26424
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
	int n;
  cin >> n;
  cout << n*n*n;
}

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

#define SZ(x) (((int)x.size()))

typedef long long ll;

using namespace std;

const int maxc = 26, maxn = 100*1000+10;
string s, t;
vector<int> loc[maxc];
bool mark[maxc];
int cur, ans, tmp, x;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s >> t;
	for (int i = 0; i < SZ(s); i++)
	{
		loc[s[i] - 'a'].push_back(i);
		mark[s[i] - 'a'] = 1;
	}
	for (int i = 0; i < SZ(t); i++)
	{
		x = t[i] - 'a';
		if (!mark[x])
		{
			cout << -1;
			return 0;
		}
		tmp = lower_bound(loc[x].begin(), loc[x].end(), cur) - loc[x].begin();
		if (tmp < SZ(loc[x]))
			cur = loc[x][tmp] + 1;
		else
		{
			ans++;
			tmp = lower_bound(loc[x].begin(), loc[x].end(), 0) - loc[x].begin();
			cur = loc[x][tmp] + 1;
		}
	}
	cout << (ll)ans * SZ(s) + cur;
	return 0;
}


Measured memory_bytes: 1228
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
ab = [LIST() for _ in range(N)]

ab.sort(key = lambda x : x[0])

cnt = 0
for i in range(N):
	cnt += ab[i][1]
	if cnt >= K:
		print(ab[i][0])
		break

Measured memory_bytes: 39088
#include<map>
#include<queue>
#include<cmath>
#include<ctime>
#include<stack>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
inline char gc(){
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	return getchar();
}
inline int read(){
	int ans=0,fh=1;
	char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-') fh=-1; ch=gc();}
	while(ch>='0'&&ch<='9')	ans=(ans<<1)+(ans<<3)+ch-'0',ch=gc();
	return ans*fh;
}
int main(){
//	freopen(".in","r",stdin);
	int n,x,ok=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(x%2==1) ok=1;
	}
	if(ok) printf("first\n");
	else printf("second\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <tuple>
#include <unordered_map>
#include <map>
#include <cmath>

#define endl "\n"
#define eb emplace_back
#define ll long long

using namespace std;

int dp[1000][1000];
int mod = 1e9 + 7;

int main() {

    cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int r, c;
    cin >> r >> c;

    string grid[r];
    for (int i = 0; i < r; i++) {
        cin >> grid[i];
        for (int j = 0; j < c; j++)
            dp[i][j] = 0;
    }

    for (int i = 0; i < r && grid[i][0] != '#'; i++)
        dp[i][0] = 1;
    for (int i = 0; i < c && grid[0][i] != '#'; i++)
        dp[0][i] = 1;

    for (int i = 1; i < r; i++) {
        for (int j = 1; j < c; j++) {
            if (grid[i][j] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
        }
    }

    cout << dp[r-1][c-1] << endl;

    return 0;

}

Measured memory_bytes: 8616
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  ulong n = readln.chomp.to!ulong;
  ulong[] a = readln.chomp.split.map!(to!ulong).array;
  // ulong[] a = make(50 * 10_000_000_000_000_000L);
  // ulong n = a.length;
  ulong k = 0;
  ulong cnt = 0;
  for (;;) {
    ulong trg = 0;
    ulong trg_index = 0;
    foreach (i, v; a) {
      if (trg < v) {
        trg = v;
        trg_index = i;
      }
    }
    if (trg < n) {
      break;
    }
    ulong sub = trg / n;
    k += sub;
    a[trg_index] -= sub * n;
    foreach (i, ref v; a) {
      if (i == trg_index) {
        continue;
      }
      v += sub;
    }
    ++cnt;
  }
  // stderr.writeln("loop count : ", cnt);
  k.writeln;
}

ulong[] make(ulong k)
{
  enum N = 50;
  long v = k / N;
  immutable remain = k % N;
  ulong[] arr;
  foreach (i; 0..N) {
    if (i < remain) {
      arr ~=  v + N * 2 - remain;
    } else {
      arr ~= v + N - (remain + 1);
    }
  }
  return arr;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  int m=n%1000;
  if(m==0)
    cout<<0<<endl;
  else{
    cout<<1000-m<<endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    vector<int> x(5);
    rep(i, 5) cin >> x[i];
    rep(i, 5)
    {
        if (x[i] == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3616
from bisect import bisect_left

def main():
    N = int(input())
    L = list(map(int, input().split()))
    
    L.sort()
    ans = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            k = bisect_left(L, a + L[j])
            ans += (k - (j + 1))

    print(ans)

    
if __name__ == "__main__":
    main()

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

int main() {
	int num[24];
	double time[24];
	for(int i=0;i<24;i++)cin>>num[i]>>time[i];
	int thr[3];
	double ti[3];
	for(int i=0;i<3;i++){
		for(int j=0,kawa;j<3;j++){
			kawa=0;
			for(int k=8*i;k<(i+1)*8;k++)if(time[k]<time[kawa])kawa=k;
			if(j==2){
				thr[i]=num[kawa];
				ti[i]=time[kawa];
			}
			else {
				cout<<num[kawa]<<" "<<time[kawa]<<endl;
				time[kawa]=10000;
			}
		}
	}
	for(int i=0,kawa;i<2;i++){
		kawa=0;
		for(int j=0;j<3;j++)if(ti[kawa]>ti[j])kawa=j;
		cout<<thr[kawa]<<" "<<ti[kawa]<<endl;
		ti[kawa]=10000;
	}
	return 0;
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define V vector<ll>
#define A for(auto &x:a)cin>>x;
#define B for(auto &x:b)cin>>x;
#define C for(auto &x:c)cin>>x;
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define I ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    ll n,i,j,ans=1;
    cin>>n;
    map<ll,ll>m;
    for(i=0;i<n;i++){
        cin>>j;
        m[j]++;
    }
    if(n%2==0){
        for(i=1;i<n;i+=2)if(m[i]!=2){i=-1;break;}
        if(i==-1)ans=0;
        else{
            for(i=0;i<n/2;i++){
                ans*=2;
                ans%=(ll)1e9+7;
            }
        }
    }
    else{
        for(i=2;i<n;i+=2)if(m[i]!=2){i=-1;break;}
        if(m[0]!=1)i=-1;
        if(i==-1)ans=0;
        else{
            for(i=0;i<n/2;i++){
                ans*=2;
                ans%=(ll)1e9+7;
            }
        }
    }
 //   for(auto x:m)cout<<x.first<<" "<<x.second<<endl;
    cout<<ans;
}


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

using namespace std;

int main() {
    int n, c;
    cin >> n >> c;
    int cnt[3][30] = {{0}},
        d[c][c];
    for (auto &di:d)
        for (auto &dij:di)
            cin >> dij;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            int cij; cin >> cij;
            cnt[(i+j)%3][cij-1]++;
        }
    }
    int sc[3], best = 250000001;
    for (sc[0]=0; sc[0]<c; sc[0]++) {
        for (sc[1]=0; sc[1]<c; sc[1]++) {
            if (sc[0] == sc[1]) continue;
            for (sc[2]=0; sc[2]<c; sc[2]++) {
                if (sc[2] == sc[0] || sc[2] == sc[1]) continue;
                int sum = 0;
                for (int i=0; i<3; i++)
                    for (int j=0; j<c; j++)
                        sum += d[j][sc[i]] * cnt[i][j];
                best = min(best, sum);
                //cerr << sc[0] << ' ' << sc[1] << ' ' << sc[2] << ' ' << sum << '\n';
            }
        }
    }
    cout << best << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(long long int a,long long int b){
    return a>b;
}
int main(){
    long long int x,y,z,k,t;
    cin>>x>>y>>z>>k;
    vector <long long int> a,b,c,d,e;
    for(long long int i=0;i<x;i++){
        cin>>t;
        a.push_back(t);
    }
    for(long long int i=0;i<y;i++){
        cin>>t;
        b.push_back(t);
    }
    for(long long int i=0;i<z;i++){
        cin>>t;
        c.push_back(t);
    }
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);
    for(long long int i=0;i<min(k,x);i++){
        for(long long int j=0;j<min(k,y);j++){
            d.push_back(a[i]+b[j]);
        }
    }
    sort(d.begin(),d.end(),cmp);
    long long int size=d.size();
    for(long long int i=0;i<min(size,k);i++){
        for(long long int j=0;j<min(k,z);j++){
            e.push_back(d[i]+c[j]);
        }
    }
    sort(e.begin(),e.end(),cmp);
    for(long long int i=0;i<k;i++) cout<<e[i]<<endl;
}

Measured memory_bytes: 43384
import java.util.Scanner;
     
class Main{
    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        //sc.nextLine();
        //String S = sc.nextLine();
        sc.close();
        //String[] s = S.split(" ");
        //int[] n = new int[N];
        
        //for(int i = 0; i < N; i++) {
        //	String tmp = s[i];
        //	n[i] = Integer.parseInt(tmp);
        //}
        
        System.out.println(calc(A,B,C,X));    
    }
    
    public static int calc(int A,int B,int C,int X) {
    	int count = 0;
    	for(int i = 0; i <= A; i++){
            for(int j = 0; j <= B; j++){
                for(int k = 0; k <= C; k++){
                    if( X == 500*i + 100*j + 50*k){
                        count++;
                    }
                } 
            }
        }
		return count;
    }
}

Measured memory_bytes: 22996
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)


def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

sys.setrecursionlimit(10**6)


def main():
    n, m = map(int, input().split())

    graph = [[] for _ in range(n)]
    for i in range(m):
        x, y = map(int, input().split())
        graph[x - 1].append(y - 1)

    dp = [-1] * n
    for node, children in enumerate(graph):
        if children == []:
            dp[node] = 0

    def solve(x):
        for child in graph[x]:
            if dp[child] == -1:
                solve(child)

        dp[x] = 1 + max(dp[child] for child in graph[x])

    for i in range(n):
        if dp[i] == -1:
            solve(i)

    print(max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 80924
N = int(input())

A = sorted([int(i) for i in input().split()],reverse=True)

if 0 in A:
  print(0)
  exit();

x = A[0]  
for i in A[1:]:
  x *= i
  if x > 10**18:
    print('-1')
    exit();
    
print(x) 

Measured memory_bytes: 21512
N = int(input())
A_list = list(map(int,input().split()))
even_list = [i for i in A_list if i % 2 == 0]
flag = 0
for i in even_list:
  if i % 3 == 0 or i % 5 == 0:
    continue
  else:
    flag = 1
if flag == 0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    long long int n,m,sum=0;
    
    
    cin>>n>>m;
    
    long long int numbers[10000];
    
    for(long long int a=0;a<m;a++)
    {
     
    
        cin>>numbers[a];
        
        sum+=numbers[a];
    
    }
   
    
    if(sum<=n)
    {
      
        cout<<n-sum<<"\n";
    
    }
    else
    {
        
        cout<<"-1"<<"\n";
        
    }
    
}


Measured memory_bytes: 3752