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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec_in (H, vector<char>(W));//入力配列
  vector<vector<char>> vec_su (H+2, vector<char>(W+2,'#')); //一回り大きい配列．

  //入力値
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> vec_in.at(i).at(j);
    }
  }
  
  //入力値をH+2, W+2の配列に埋め込み
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      vec_su.at(i+1).at(j+1)=vec_in.at(i).at(j);
    }
  }
  
  //出力
  for (int i=0; i<H+2; i++) {
    for (int j=0; j<W+2; j++) {
      cout << vec_su.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

long P = 10^^9+7;
long[10^^6*2+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

void main()
{
    init();
    auto rc = readln.split.to!(long[]);
    auto r1 = rc[0];
    auto c1 = rc[1];
    auto r2 = rc[2];
    auto c2 = rc[3];
    writeln((comb(r2+c2+2, c2+1) - comb(r1+c2+1, c2+1) - comb(r2+c1+1, c1) + P*2 + comb(r1+c1, c1)) % P);
}

Measured memory_bytes: 33944
from decimal import *
getcontext().prec = 14  # あんまり大きいと計算遅いかも

N, D = map(int, input().split())

def distance(x1, x2, y1, y2):
    dx = x2-x1
    dy = y2-y1
    return (dx*dx + dy*dy).sqrt()

ans = 0
for i in range(N):
    X, Y = map(Decimal, input().split())
    if (distance(0, X, 0, Y) <= D):
        ans += 1

print(ans)


Measured memory_bytes: 9988
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second
#define pb push_back

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string S;cin>>S;
  int ans=0,now=0;
  REP(i,0,S.size()){
    if(S.at(i)=='W'){
      ans+=i-now;
      now++;
    }
  }
  print(ans);


}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(void){
    int A, B, C;
    cin >> A >> B >> C;
    
    string res = "No";
    
    if ((A <= C) && (C <= B)) res = "Yes";
    else if ((B <= C) && (C <= A)) res = "Yes";
    
    cout << res << endl;
    
    
}


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

struct s {
	int id, p, q, r;
	s(){}
	s(int id_, int p_, int q_, int r_) {
		id = id_; p = p_; q = q_; r = r_;
	}
	bool operator<(const s & obj) const {
		return this->id < obj.id;
	}
};

int main() {
	int n;
	while(cin >> n, n) {
		int P, Q, R, C;
		vector
 v;
		for(int i = 0; i < n; i++) {
			s a;
			cin >> a.id >> a.p >> a.q >> a.r;
			v.push_back(a);
		}
		cin >> P >> Q >> R >> C;
		bool flg = true;
		for(int i = 0; i < v.size(); i++) {
			int cal = (v[i].p + v[i].r) * 4 + v[i].q * 9;
			if(v[i].p <= P && v[i].q <= Q && v[i].r <= R && cal <= C) {
				flg = false;
				cout << v[i].id << endl;
			}
		}
		if(flg)
			cout << "NA" << endl;
	}
}

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

int main() {
    int price, num;
    char com;
    int income = 0, total = 0, cnt = 0;

    while (cin >> price >> com >> num) {
        income += price * num;
        total += num;
        cnt++;
    }
    cout << income << endl;
    cout << round((double)total / (double)cnt) << endl;
    return 0;
}

Measured memory_bytes: 3340
#include<stdio.h>
int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  for(int i=a;i<=1000;i++){
    if((i*8)/100==a&&(i*10)/100==b){
      printf("%d\n",i);
      return 0;
    }
  }

  puts("-1");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

int n;
vector<string> table;
vector<vector<ll>> dp;

int main(){
	while (cin >> n&&n){
		table.clear();
		dp.clear();
		table.resize(n);
		dp.resize(n);
		REP(i, n){
			table[i].resize(n);
			dp[i].resize(n);
		}
		REP(i, n){
			string s;
			cin >> s;
			REP(j, n){
				table[i][j] = s[j];
				if (i == 0 || j == 0)dp[i][j] = (s[j] == '.');
			}
		}
		FOR(i, 1, n){
			FOR(j, 1, n){
				if (table[i][j] == '*')continue;
				dp[i][j] = min(dp[i][j - 1], min(dp[i - 1][j - 1], dp[i - 1][j])) + 1;
			}
		}
		ll ans = 0;
		REP(i, n){
			REP(j, n){
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 11888
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vi a(n);
  REP(i, n) cin >> a[i];
  REP(i, n) a[i]--;

  vi st;
  vi ord(n, -1);
  int c = 1, l = 0;
  {
    int v = 0;
    while (ord[v] == -1) {
      ord[v] = st.size();
      st.emplace_back(v);
      v = a[v];
    }
    c = st.size() - ord[v];
    l = ord[v];
  }

  if (k < l) cout << st[k]+1 << endl;
  else {
    k -= l;
    k %= c;
    cout << st[l+k]+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 5884
import sys
import math
M = 1000000
B = int(math.sqrt(M)+1)
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = [1] * N1
m = [1] * N2
for i in range(5,B,6):
    p = (i-5)//6
    ini = (i*5-1)//6
    if l[p] == 1:
        l[p+i::i] = [0] * len(l[p+i::i])
        m[ini-1::i] = [0] * len(m[ini-1::i])
    if m[p] == 1:
        m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
        l[ini+1::i+2] = [0] * len(l[ini+1::i+2])

for i in sys.stdin:
    n = int(i)
    r =  n-1 if n < 4 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
    print(r)

Measured memory_bytes: 11940
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    map<long, int> nums_count;
    long nums[N];
    for(int i = 0; i < N; i++){
        cin >> nums[i];
        nums_count[nums[i]]++;
    }
    if(nums_count[-1] + nums_count[-2] <= 1){
        cout << nums_count[2] << endl;
        for(int i = 0; i < N; i++){
            if(nums[i] == 2){
                cout << i + 1 << endl;
            }
        }
    }else if(nums_count[-1]){
        vector<int> choose_num;
        long ans = 1;
        for(int i = 0; i < N; i++){
            if(nums[i] == 2 || nums[i] == -2){
                choose_num.push_back(i);
                ans *= nums[i];
            }
        }
        if(ans < 0){
            for(int i = 0; i < N; i++){
                if(nums[i] == -1){
                    choose_num.push_back(i);
                    ans *= -1;
                    break;
                }
            }
        }
        sort(choose_num.begin(), choose_num.end());
        cout << choose_num.size() << endl;
        for(int i = 0; i < choose_num.size(); i++){
            cout << choose_num[i] + 1 << endl;
        }
    }else{
        vector<int> choose_num;
        vector<int> choose_num_minus;
        long ans = 1;
        for(int i = 0; i < N; i++){
            if(nums[i] == 2){
                choose_num.push_back(i);
                ans *= nums[i];
            }else if(nums[i] == -2){
                choose_num_minus.push_back(i);
                ans *= nums[i];
            }
        }
        if(ans < 0){
            choose_num_minus.pop_back();
        }
        for(int i = 0; i < choose_num_minus.size(); i++){
            choose_num.push_back(choose_num_minus[i]);
        }
        sort(choose_num.begin(), choose_num.end());
        cout << choose_num.size() << endl;
        for(int i = 0; i < choose_num.size(); i++){
            cout << choose_num[i] + 1 << endl;
        }
    }
}



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

using namespace std;

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

const int INF = 1e9 + 7, N = 4004;

int r[N], g[N], b[N];

signed main()
{
	IO_OP;
	
	int n;
	string s;
	cin >> n >> s;
	for(int i=0;i<n;i++) {
		if(s[i] == 'R') r[i] = 1;
		else if(s[i] == 'G') g[i] = 1;
		else b[i] = 1;
		r[i] += r[i-1];
		g[i] += g[i-1];
		b[i] += b[i-1];
	}
	ll ans = 0;
	for(int i=1;i<n;i++) {
		for(int j=i+1;j<n;j++) {
			if(s[i] != s[j]) {
				int l = i - (j - i);
				if(s[i] != 'R' && s[j] != 'R') {
					ans += r[i-1] - (l >= 0 && s[l] == 'R');
				}
				if(s[i] != 'G' && s[j] != 'G') {
					ans += g[i-1] - (l >= 0 && s[l] == 'G');
				}
				if(s[i] != 'B' && s[j] != 'B') {
					ans += b[i-1] - (l >= 0 && s[l] == 'B');
				}
			}
		}
	}
	cout << ans << endl;
}





Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
using namespace std;
map <int,int> mp_w,mp_s;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
int A,B,C,D,E,F,max_w,max_s;
double max_d=-1.0;
ll water,sugar;
int main(){
    cin>>A>>B>>C>>D>>E>>F;

    for(int i=0;i<=30;i++){
        for(int j=0;j<=30;j++){
            water=A*i+B*j;
            mp_w[water]++;
        }
    }

    for(int i=0;i<=2900;i++){
        for(int j=0;j<=2900;j++){
            sugar=C*i+D*j;
            mp_s[sugar]++;
        }
    }

    for(auto pw:mp_w){

        water=pw.first*100;
        if(water>F||water==0)continue;

        for(auto ps:mp_s){
            sugar=ps.first;
            if(water+sugar>F)continue;

            double d=(double)sugar/(water+sugar);
            double e=(double)sugar*100/water;
            if(e>E)continue;

            if(max_d<d){
                max_w=water;
                max_s=sugar;
                max_d=d;
            }
        }
    }

    cout<<max_w+max_s<<" "<<max_s<<"\n";

    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    ll L,R;cin>>L>>R; ll ans=2020;
    if(R-L >= 2018) {ans = 0;}
    else{
      for(int i=L; i<R;i++){
        for(int j=i+1; j<=R;j++){
          ll t= ( (i%2019) * (j%2019) )% 2019;
          ans = min(ans , t);
        }
      }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int N, a[100009], dp[100009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
dp[0] = 0;
int inc = 0, dec = 0;
for (int i=1; i<=N; i++)
{
    if (a[i] >= a[i - 1]) inc ++;
    else inc = 1;
    if (a[i] <= a[i - 1]) dec ++;
    else dec = 1;
    dp[i] = min (dp[i - inc] + 1, dp[i - dec] + 1);
}
printf ("%d\n", dp[N]);

return 0;
}


Measured memory_bytes: 1024
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
u="U"
d="D"
r="R"
l="L"
print(u*dy+r*dx+d*dy+l*dx+l+u*(dy+1)+r*(dx+1)+d+r+d*(dy+1)+l*(dx+1)+u)

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 1010;

int N, K;
int a[MN];

int main() {
	cin >> N >> K;
	rep(i, N) {
		cin >> a[i];
	}
	ll ans = 0;

	vector<ll> cand;

	rep(i, N) {
		ll s = 0;
		for (int j = i; j < N; ++j) {
			s += a[j];
			cand.pb(s);
		}
	}

	for (int i = 40; i >= 0; --i) {
		int t = 0;
		vector<ll> nx;
		for (ll x : cand) {
			if ((x >> i) & 1) {
				nx.pb(x);
			}
		}
		if (nx.size() >= K) {
			ans += (1LL << i);
			cand = nx;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6128
a,b,c,d,=map(int,input().split())
def func(a,b,c,d):
    while a>0 and c>0:
        c-=b
        if c<=0:
            return "Yes"
        a-=d
        if a<=0:
            return "No" 
print(func(a,b,c,d))

Measured memory_bytes: 9180
package main

import (
	"fmt"
)

func main() {
	var t1, t2 int64
	var a1, a2 int64
	var b1, b2 int64
	fmt.Scan(&t1, &t2)
	fmt.Scan(&a1, &a2)
	fmt.Scan(&b1, &b2)

	p := (a1 - b1) * t1
	q := (a2 - b2) * t2
	if p > 0 {
		p *= -1
		q *= -1
	}

	if p+q == 0 {
		fmt.Println("infinity")
		return
	}

	ans := int64(0)

	if p+q < 0 {
		ans = 0
	} else {
		s := (-p) / (p + q)
		t := (-p) % (p + q)
		if t != 0 {
			ans = s*2 + 1
		} else {
			ans = s * 2
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
package main

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

const mod = 1000000007

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	nm := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(nm[0])
	m, _ := strconv.Atoi(nm[1])
	bads := make(map[int]int)
	for i := 0; i < m; i++ {
		sc.Scan()
		bad, _ := strconv.Atoi(sc.Text())
		bads[bad] = 1
	}

	dp := make([]int, n+1, n+1)
	dp[0] = 1
	if bads[1] == 0 {
		dp[1] = 1
	} else {
		dp[1] = 0
	}
	for i := 2; i <= n; i++ {
		if bads[i] == 0 {
			dp[i] += dp[i-1]
		}
		if bads[i] == 0 {
			dp[i] += dp[i-2]
		}
		dp[i] %= mod
	}
	fmt.Println(dp[len(dp)-1])
}


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

int main() {
//   int N;
//   int M;
//   int X;
  
//   cin >> N >> M >> X;
  
//   int i;
//   vector<int> C(N);
//   vector<vector<int>> A(N,vector<int>(M));
  
//   int sum=0;
//   int j;
  
//   for(i=0;i<N;i++){
//       cin >> C.at(i);
//       for(j=0;j<M;j++){
//           cin >> A.at(i).at(j);
//       }
//   }
//   for(i=0;i<M;i++){
//       sum=0;
//       for(j=0;j<N;j++){
//           sum+=A.at(j).at(i);
//       }
//       if(sum<X){
//           cout << -1 << endl;
//           return 0;
//       }
//   }
  
//   int min_value;
//   vector<int> C_has(N,1);
//   for(i=0;)
//     cout << 1 << endl;
  
  long int K;
  int N;
  cin >> N >>K;
  int i;
  vector<int> A(N);
//   cout << K<<endl;
  for(i=0;i<N;i++){
      cin >> A.at(i);
  }
  
  vector<int> visited(N,-1);
  visited.at(0)=0;
  int g =0;
  int move = 0;
//   cout << A.at(0)<<endl;
  while(true){
      move ++;
      g=A.at(g)-1;
      if(visited.at(g)>-1){
          break;
      }
      visited.at(g)=move;
    //   cout << g+1 << " "<<move << endl;
      if(move==K){
          cout << g+1 <<endl;
          return 0;
      }
  }
  int first_visit=visited.at(g);
  int second_visit=move;
//   cout << "A"<<first_visit << " "<<second_visit << endl;
  
  int result_move = (K-first_visit)%(second_visit-first_visit);
//   cout << result_move << endl;
  
  g=0;
  for(i=0;i<(first_visit+result_move);i++){
      g=A.at(g)-1;
  }
  cout << g+1 << endl;
}

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

int main()
{
 long a,b,c,x,y,count=0;
 cin>>a>>b>>c>>x>>y;
 if((a+b)>(2*c))
 {
     if(x>y)
     {
         if(a>(2*c))
             count= x*c*2;
          else
          {
              count= y*c*2 + (x-y)*a;
          }
     }
     else
     {
         if(b>(2*c))
             count=y*c*2;
             else
                 count= x*c*2 + (y-x)*b;
     }
    
 }
 else
 {
     count= x*a + y*b;
 }
 cout<<count<<endl;
 return 0;
}

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

int N,M;
int s[50001],t[50001],e[50001];
int end;
int L;
int b[101][10001];

int val[10001];

int main(){
	scanf("%d%d",&N,&M);
	for(int i = 0; ; i++){
		scanf("%d%d%d",&s[i],&t[i],&e[i]);
		if(s[i] == 0){
			end = i;
			break;
		}
	}
	scanf("%d",&L);
	for(int i = 0; i < L; i++){
		for(int j = 1; j <= M; j++){
			scanf("%d",&b[i][j]);
		}
	}
	
	for(int i = 0; i < L; i++){
		for(int j = 1; j <= N; j++){
			val[j] = 0;
		}
		for(int j = 0; j < end; j++){
			val[s[j]] += b[i][t[j]] * e[j]; 
		}
		for(int j = 1; j <= N; j++){
			printf("%d%s",val[j],j == N ? "" : " ");
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 7736
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			y[i] = sc.nextInt();
		}

		System.out.println(distance(x, y, 1));
		System.out.println(distance(x, y, 2));
		System.out.println(distance(x, y, 3));
		System.out.println(distance_inf(x, y));

	}
	private static double distance_inf(int[] x, int[] y) {
		double D = 0.0;

		for (int i = 0; i < x.length; i++) {
			D = Math.max(D, Math.abs((double)x[i] - (double)y[i]));
		}

		return D;
	}
	private static double distance(int[] x, int[] y, int power) {
		double D = 0.0;

		for (int i = 0; i < x.length; i++) {
			D += Math.pow(Math.abs((double)x[i] - (double)y[i]), (double)power);
		}

		D = Math.pow(D, 1/(double)power);

		return D;
	}

}


Measured memory_bytes: 26588
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  if(s[0]=='9'||s[1]=='9')
  puts("Yes");
  else
  puts("No");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
template <typename T> using
Treap = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define endl "\n"
#define all(V) V.begin( ), V.end( )
#define Unique(V) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
std::mt19937 rng( chrono::steady_clock::now().time_since_epoch().count() );
#define ran(a, b) rng() % ( (b) - (a) + 1 ) + (a)
#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template < typename Arg1 >
void __f( const char* name , Arg1&& arg1 ) { cerr <<name<<" : "<<arg1<< "\n"; }
template < typename Arg1 , typename... Args >
void __f( const char* names , Arg1&& arg1 , Args&&... args ) {
const char* comma = strchr( names + 1 , ',' );
cerr.write( names , comma - names ) <<" : "<<arg1<<" , "; __f( comma+1 , args...);}

typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <long long,long long> pll;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;

int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( nullptr );
        #ifdef forthright48
            freopen( "input.txt" , "r" , stdin );
        #endif // forthright48
        int a , b , c;
        cin >> a >> b >> c;
        if( a == b && b == c ) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}











Measured memory_bytes: 384
// --------------
// Tejas Pandey  |
// 13 - 09 - 20  |
// Atcoder BC 178|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<ll,ll>> vp(n);
  vector<ll> v1(n),v2(n),v3(n);
  for(int i = 0;i < n;i++){
	cin >> vp[i].first >> vp[i].second;
	v1[i] = vp[i].first + vp[i].second;
	v2[i] = vp[i].second - vp[i].first;
	v3[i] = vp[i].first - vp[i].second;
  }
  sort(v1.begin(),v1.end());
  ll ans = v1[n - 1] - v1[0];
  sort(v2.begin(),v2.end());
  ans = max(ans,v2[n - 1] - v2[0]);
  sort(v3.begin(),v3.end());
  ans = max(ans,v3[n - 1] - v3[0]);
  cout << ans << "\n";
}


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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(){
  int h,w;cin>>h>>w;
  int ch, cw, dh, dw;cin>>ch>>cw>>dh>>dw; ch--;cw--;dh--;dw--;
  vector<string>s(h);
  rep(i, h)cin>>s[i];

  vector<vector<int>>c(h, vector<int>());
  rep(i, h)rep(j, w)c[i].push_back(INF);

  priority_queue< pair<int, pi>, vector<pair<int, pi>>, greater<pair<int, pi>> > q;
  q.push({0, {ch, cw}});
  while(q.size()){
    auto cp = q.top();q.pop();
    pi now = cp.second;
    int cs = cp.first;

    int y = now.first;
    int x = now.second;
    if(y<0 || y>=h || x<0 || x>=w)continue; // 盤外は飛ばし

    if(s[y][x] == '#')continue; // 壁は飛ばし
    if(c[y][x] <= cs)continue; // スコアが既に低ければ飛ばし
    c[y][x]=cs;

//cout<<cs<<' '<<y<<' '<<x<<' '<<q.size()<<endl;

    // nowから見て4方向とワープ可能位置をpush
    q.push({cs, {y-1, x}});
    q.push({cs, {y+1, x}});
    q.push({cs, {y, x+1}});
    q.push({cs, {y, x-1}});
    for(int i=-2; i<=2; i++){
      if(y-2>=0 && x+i>=0 && x+i < w && s[y-2][x+i]=='.') q.push({cs+1, {y-2, x+i}});
      if(y+2<h && x+i>=0 && x+i < w && s[y+2][x+i]=='.') q.push({cs+1, {y+2, x+i}});
      if(x-2>=0 && y+i>=0 && y+i<h && s[y+i][x-2]=='.') q.push({cs+1, {y+i, x-2}});
      if(x+2<w && y+i>=0 && y+i<h && s[y+i][x+2]=='.') q.push({cs+1, {y+i, x+2}});
    }
    q.push({cs+1, {y+1, x+1}});
    q.push({cs+1, {y+1, x-1}});
    q.push({cs+1, {y-1, x+1}});
    q.push({cs+1, {y-1, x-1}});
  }

  if(c[dh][dw]==INF){cout<<-1<<endl; return 0;}
  cout<<c[dh][dw]<<endl;

  return 0;

  rep(i, h){
    rep(j, w)cout<<c[i][j]<<' ';cout<<endl;
  }

  return 0;
}


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

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct restaurant {
    string city;
    int rating;
    int id;
};

typedef struct restaurant restaurant;

bool restaurantSort(restaurant f, restaurant s){
    if(f.city == s.city){
        return f.rating > s.rating;
    }
    return f.city < s.city;
}

int32_t main() {

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

    int n; cin >> n;
    vector<restaurant> restaurants;
    list(i,n){
        string s; cin >> s;
        int p; cin >> p;
        restaurant thisRest;
        thisRest.id = i+1;
        thisRest.city = s;
        thisRest.rating = p;
        restaurants.eb(thisRest);
    }
    sort(restaurants.begin(),restaurants.end(),restaurantSort);
    for(auto c: restaurants){
        cout << c.id << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	long r = Long.parseLong(sc.next());
	long d = Long.parseLong(sc.next());
	long x = Long.parseLong(sc.next());
	for(int i = 0; i<10; i++) {
	    x = r*x -d;
	    System.out.println(x);
	}

    }
}

Measured memory_bytes: 22484
#include <cstdio>
#include <vector>
#include <functional>
using namespace std;

int main() {
        int n, m;
        scanf("%d %d", &n, &m);
        vector<vector<pair<int, long long>>> g(n);
        for (int i = 0; i < m; i ++) {
                int l, r;
                long long d;
                scanf("%d %d %lld", &l, &r, &d);
                l --, r --;
                g[l].push_back({r, d});
                g[r].push_back({l, -d});
        }
        vector<bool> used(n, false);
        vector<long long> dist(n);
        function<void (int, long long)>  dfs = [&](int u, long long d) {
                used[u] = true;
                dist[u] = d;
                for (auto e : g[u]) {
                        if (!used[e.first]) {
                                dfs(e.first, d + e.second);
                        } else  if (dist[e.first] != d + e.second) {
                                puts("No");
                                exit(0);
                        }

                }
        };
        for (int i = 0; i < n; i ++) if (!used[i]) {
                dfs(i, 0);
        }
        puts("Yes");
        return 0;
}


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

int main() {
	int x = 0;
	cin >> x;
	int ans = 1;
	int t = 0;
	while(1) {
		t += ans;
		// cout << t << endl;
		if(t >= x) break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int n;
vector<pair<double, double>> point;

double f(double x, double y){
    double ans = 0;
    for(int i=0; i<n; i++){
        double dist = (point[i].first - x)  * (point[i].first - x) 
                    + (point[i].second - y) * (point[i].second - y);
        dist = sqrt(dist);
        //cout << dist << " ";
        ans = max(ans, dist);
    }
    return ans;
}

double g(double x){
    double y_left = 0, y_right = 1000, y_mid1, y_mid2;
    for(int t=0; t<100; t++){
        y_mid1 = (2 * y_left + y_right) / 3.0;
        y_mid2 = (y_left + 2 * y_right) / 3.0;

        if(f(x, y_mid1) > f(x, y_mid2)) y_left = y_mid1;
        else y_right = y_mid2;
    }
    return f(x, y_left);
}

int main(){
    cin >> n;
    
    point.resize(n);
    for(int i=0; i<n; i++){
        cin >> point[i].first >> point[i].second;
    }

    double x_left = 0, x_right = 1000, x_mid1, x_mid2;
    for(int t=0; t<100; t++){
        x_mid1 = (2 * x_left + x_right) / 3.0;
        x_mid2 = (x_left + 2 * x_right) / 3.0;
        //cout << x_mid1 << " (" << g(x_mid1) << "), " << x_mid2 << " (" << g(x_mid2) << ")" << endl;

        if(g(x_mid1) > g(x_mid2)) x_left = x_mid1;
        else x_right = x_mid2;
    }
    
    cout << fixed << setprecision(12) << g(x_left) << endl;
    return 0;
}

Measured memory_bytes: 3812
#include <iostream>

int main()
{
	char n[3];
	int a = 0, b = 0, c = 0;
	std::cin >> n;
	for(int i = 0; i < 3; i++)
	{
		if(n[i] == 'a')
		{
			a++;
			//std::cout << "ok" << std::endl;
		}
		else if(n[i] == 'b')
		{
			b++;
		}
		else if(n[i] == 'c')
		{
			c++;
		}
	}
	if(a == 1 && b == 1 && c == 1)
	{
		std::cout << "Yes" << std::endl;
	}else
	{
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func max(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := next()
	cnt := make([]int, 3)
	for i := range s {
		cnt[int(s[i]-'a')]++
	}

	if max(cnt)-2 >= min(cnt) {
		puts("NO")
	} else {
		puts("YES")
	}
}


Measured memory_bytes: 896
#include<stdio.h>
long long a,b,c,d;
 
long long dai(long long x,long long y){
  int z;
while( x % y != 0 )
         {
             z = x % y;
             x = y;
             y = z;
         }
  return y;
}

long long baisuu(long long k){
  return b/k-(a-1)/k;
}
 
int main(){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
 // printf("%lld¥n",baisuu(1));
  printf("%lld",baisuu(1)-(baisuu(c)+baisuu(d)-baisuu(c*d/dai(c,d))));
  return 0;
}

Measured memory_bytes: 128
while True:
	n, p = map(int, input().split())
	if (n, p) == (0, 0):
		break
	
	i = 0
	m = p;
	a = [0] * n

	while True:
		if p == 0:
			p = a[i]
			a[i] = 0
		else:
			p -= 1
			a[i] += 1
		if a[i] == m:
			print(i)
			break
		i += 1
		i %= n

Measured memory_bytes: 7576
s = input().split()

stack = []

for i in s:
    if i == '+':
        a = stack.pop()
        b = stack.pop()
        stack.append(a + b)
    elif i == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif i == '*':
        a = stack.pop()
        b = stack.pop()
        stack.append(a * b)
    else:
        stack.append(int(i))

print(stack[0])

Measured memory_bytes: 7724
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vei vector<int>
#define vep vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++){cout<<a[i]<<" ";cout<<endl;}}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1LL; while (b > 0) {if (b & 1LL) {c = a * c%mod;}a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
ll POOW(int a) {
	int c = 1;
	REP (i,a) {
		c *= 3;
		c %= mod;
	}
	return c;
}

int b[2005][2005][4];
//上下左右

string L;
int cnt[100005];

int dfs(int pos) {
	if (cnt[pos] != 0) return cnt[pos];
	if (L[pos] == '1') {
		return cnt[pos] = (POW(3,L.size()-pos-1) + 2*dfs(pos+1))%mod;
	} else {
		
		return cnt[pos] = dfs(pos+1)%mod;
	}
}

bool solve() {
	cin >> L;
	if (L[L.size()-1] == '1') cnt[L.size()-1] = 3;
	else cnt[L.size()-1] = 1;
	int ans = 0;
	ans += POW(3,L.size()-1);
	if (L.size()==1) {
		cout << 3 << endl;
		return 0;
	}
	cout << dfs(0) << endl;
	// ans += tmp;
	ans %= mod;
	// cout << ans << endl;


}

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

	solve();
}

Measured memory_bytes: 4432
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && c <= b) cout << "Yes" << endl;
  else cout << "No" << endl;	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


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

void maxH(int *, int, int);

main(){
  int i, n;
  int t[500001];

  scanf("%d", &n);

  for(i = 1;i <= n;i++) scanf("%d", &t[i]);

  for(i = n/2;i > 0;i--) maxH(t, i, n);


  for(i = 1;i <= n;i++) printf(" %d", t[i]);

  printf("\n");
  return 0; 
}
void maxH(int *t, int i, int n){
  int l, r, large, c;

  if( i*2+1 < n + 1) r = i*2+1;
  else r = i;
  if( i*2 < n + 1) l = i*2;
  else l = i;

  if(l <= n && t[l] > t[i]) large = l;
  else large = i;

  if(r <= n && t[r] > t[large])large = r;

  if(large != i){
    c = t[i];
    t[i] = t[large];
    t[large] = c;
    maxH(t, large, n);
  }
}

Measured memory_bytes: 2552
#include <iostream>

int main(int argc, const char * argv[]) {
    int m, f, r;
    char grade;
    for ( ; std::cin >> m >> f >> r && !(m == -1 && f == -1 && r == -1); ) {
        if (m == -1 || f == -1) {
            grade = 'F';
        } else if (m + f >= 80) {
            grade = 'A';
        } else if (m + f >= 65) {
            grade = 'B';
        } else if (m + f >= 50) {
            grade = 'C';
        } else if (m + f >= 30) {
            if (r >= 50) {
                grade = 'C';
            } else {
                grade = 'D';
            }
        } else {
            grade = 'F';
        }
        std::cout << grade << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3096
from operator import itemgetter
from collections import deque

N = int(input())

xs, ys = [], []
for _ in range(N):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)
    
xis = sorted(list(enumerate(xs)), key = itemgetter(1))
yis = sorted(list(enumerate(ys)), key = itemgetter(1))

xds, yds = [], []
for i in range(N-1):
    xds.append((xis[i+1][1] - xis[i][1], (xis[i][0], xis[i+1][0])))
    yds.append((yis[i+1][1] - yis[i][1], (yis[i][0], yis[i+1][0])))

xdq, ydq = deque(sorted(xds)), deque(sorted(yds))

par = list(range(N))
def find(x):
    if x == par[x]: 
        return x 
    else:
        par[x] = find(par[x])
        return par[x]

def union(x,y):
    rx, ry = find(x), find(y)
    par[ry] = rx

ans = 0
while xdq or ydq:
    if xdq and (not ydq or xdq[0] < ydq[0]):
        d, (i,j) = xdq.popleft()
    else:
        d, (i,j) = ydq.popleft()
    if find(i) != find(j): #Kruskal法
        ans += d
        union(i,j)

print(ans)

Measured memory_bytes: 71680
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v;
    vector<int> x(m), z(m);
    map<int, int> map1;
    for (int i = 0; i < m; ++i) {
        int p, y;
        scanf("%d %d", &p, &y);
        v.emplace_back(vector<int>{p, y, i});
        z[i] = p;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < m; ++i) {
        map1[v[i][0]]++;
        x[v[i][2]] = map1[v[i][0]];
    }
    for (int i = 0; i < m; ++i) {
        printf("%06d%06d\n", z[i], x[i]);
    }
    return 0;
}


Measured memory_bytes: 12464
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
int main(){
unsigned long long n,a,b;cin>>n>>a>>b;
if((b-a)%2==0)cout<<(b-a)/2<<endl;
else{
     cout<< min(min(n-a,min(a,n-b+1)+(b-a-1)/2),b-1);


}}

Measured memory_bytes: 888
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,a,ans;
int main(){
  while(scanf("%d",&n)&&n){
    int t[1000001]={0};
    ans=-1;
    for(int i=0;i<n;i++){
      scanf("%d",&a);
      if(a>1000000)continue;
      t[a]++;
      if(t[a]>n/2)ans=a;
    }
    if(ans==-1)printf("NO COLOR\n");
    else printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 4956
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();
        System.out.println(Math.min(a, b) + Math.min(c, d));
    }
}


Measured memory_bytes: 21844
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n; i++)
#define pb push_back
#define pl pair<ll, ll>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;


bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v){
    ll n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}
//------------fenwick--------------
/*vector<ll> f(maxn,0);
void fenwick_update(ll idx, ll val){
    while(idx <= maxn){
        f[idx]+=val;
        idx += (idx & -idx);
    }
}
ll read_fenwick(ll idx){
    ll sum = 0;
    while(idx > 0){
        sum += f[idx];
        idx -= (idx & -idx);
    }
    return sum;
}*/


ll longestPrefixSuffix(string s) { 
    ll n = s.length(); 
    ll lps[n]; 
    lps[0] = 0; 
    ll len = 0, i=1;
    while (i < n){ 
        if (s[i] == s[len]){ 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else{ 
            if (len != 0) 
                len = lps[len-1]; 
            else
                lps[i] = 0,i++;
        } 
    } 
    ll res = lps[n-1]; 
    return (res > n/2)? n/2 : res; 
} 
void solve(){
    ll n,m;
    cin >> n >> m;
    cout << (n*(n-1) + m*(m-1))/2 << "\n";
}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();

    }
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        w: usize,
        h: usize,
        n: usize,
    }

    let mut x: Vec<usize> = Vec::new();
    let mut y: Vec<usize> = Vec::new();
    let mut a: Vec<usize> = Vec::new();
    for i in 0..n {
        input!{
            x_tmp: usize,
            y_tmp: usize,
            a_tmp: usize,
        }
        x.push(x_tmp);
        y.push(y_tmp);
        a.push(a_tmp);
    }

    let mut sx = 0;
    let mut sy = 0;
    let mut dx = w;
    let mut dy = h;
    for i in 0..n {
        if a[i]==1 {
            sx = max(sx,x[i]);
        } else if a[i]==2 {
            dx = min(dx,x[i]);
        } else if a[i]==3 {
            sy = max(sy,y[i]);
        } else {
            dy = min(dy,y[i]);
        }
    }

    if sx<dx && sy<dy {
        println!("{}", (dx-sx)*(dy-sy));
    } else {
        println!("0");
    }

}


Measured memory_bytes: 2136
(function () {
	var max, max_log2, series, col, j, str, i, line, hw, even, odd;
	
	max = 300;
	max_log2 = max.toString(2).length - 1;

	series = [1, 2];
	col = ['#', '#.'];
	j = 2;
	str = '#.';
	for (i = 2; i <= max_log2; i++) {
		series.push(j *= 2);
		col.push(str = str + str);
	}
	series.push(series[series.length-1] * 2);

	function get_column(w) {
		var i, res;
		res = "";
		for (i = 1; i < series.length; i++) {
			if (w < series[i]) break;
			if (w % series[i+1] >= series[i])
				res = res + col[i];
		}
		if (w % 2 === 1) res = res + '#';
		return res;
	}

	line = require('fs').readFileSync('/dev/stdin', 'ascii').split('\n');
	for (i in line) {
		if (line[i] === '0 0') break;
		hw = line[i].split(' ').map(Number);
		even = get_column(hw[1]);
		odd = even.slice(1) + ((hw[1] % 2 === 0) ? '#' : '.');
		for (j = 0; j < hw[0]; j++) {
			if (j % 2 === 0) console.log(even);
			else console.log(odd);
		}
		console.log("");
	}
}) ();

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

ll dp[100010];
ll X[100000];

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

	ll N, A, B;
	cin >> N >> A >> B;
	for(int i = 0; i < N; i++) {
		cin >> X[i];
	}

	for(int i = 0; i < N - 1; i++) {
		dp[i + 1] = dp[i] + min((X[i + 1] - X[i]) * A, B);
	}
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define VFOR(x,begin,num) for(int x=(begin);x<((begin)+(num));x++)
#define INF__ ((long long)1 << 60)
int main(){
  int N, M,Good[100005],Bad[100005]; cin >> N >> M;
  VFOR(i,0,100005){
    Good[i] = 0;
    Bad[i] = 0;
  }
  VFOR(i,0,M){
    int q,con; string S;
    cin >> q >> S;
    if(S[0]=='A') con = 1;
    else con = 0;
    if(con == 1){
      Good[q] = 1;
    }else if(con == 0 && Good[q] == 0) Bad[q]++;
  }
  VFOR(i,0,N+2){
    if(Good[i]==0) Bad[i] = 0;
  }
  int g=0,b=0;
  VFOR(i,0,N+2){
    g += Good[i];
    b += Bad[i];
  }
  cout << g << " " << b;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint  = long long;
vector<vector<lint> > G;
vector<lint> ans;

void dfs(lint now, lint ago){
  for(lint i = 0; i < G[now].size(); i++){
    lint next = G[now][i];
    if(next == ago) continue;
    ans[next] += ans[now];
    dfs(next, now);
  }
}

signed main(){
  lint N, Q; cin >> N >> Q;
  G.resize(N);
  ans.resize(N);
  for(lint i = 1; i < N; i++){
    lint a, b; cin >> a >> b;
    G[a - 1].push_back(b - 1); G[b - 1].push_back(a - 1);
  }
  for(lint i = 0; i < Q; i++){
    lint p, x; cin >> p >> x;
    ans[p - 1] += x;
  }
  dfs(0, -1);
  for(lint i = 0; i < N; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 24320