akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void get_value(vector <int> &L, string &S, char given_ch)
{
    int current_segment = 0;
    for(int i = 0; i < S.size(); i++)
    {
        if(S[i] == given_ch)
        {
            current_segment++;
        }
        else if(current_segment != 0 && S[i] != given_ch)
        {
            L.push_back(current_segment);
            current_segment = 0;
        }

        if(S[i] == given_ch && i + 1 == S.size())
        {
            L.push_back(current_segment);
        }
    }
}

int main()
{
    int length, max_flips;
    string S;
    cin >> length >> max_flips >> S;

    vector <int> zero_segments;
    get_value(zero_segments, S, '0');

    vector <int> one_segments;
    get_value(one_segments, S, '1');

    int max_length = 0, current_length = 0, current_0_length = 0, current_1_length = 0,left_segment = 0;
    vector <int> zero_segment_prefix_sum(length + 1, 0);
    for(int i = 0; i < zero_segments.size() || i < one_segments.size(); i++)
    {
        if(i < zero_segments.size())
        {
            current_0_length += zero_segments[i];

            //cout << "Zero " << i << " = " << zero_segments[i] << endl;
        }

        if(i < one_segments.size())
        {
            //cout << "One " << i << " = " << one_segments[i] << endl;

            current_1_length += one_segments[i];
        }

        if(i >= max_flips)
        {
            current_0_length -= zero_segments[left_segment];
            current_1_length -= one_segments[left_segment];

            left_segment++;
        }

        current_length = current_0_length + current_1_length; //cout << "Current Length = " << current_length << endl;

        if(S[0] == '0' && left_segment != 0)
        {   //cout << "Choosing a left one L = " << left_segment << " R = " << i << " Extra 1s = " << one_segments[left_segment - 1] << endl;
            current_length += one_segments[left_segment - 1];
        }

        if(S[0] == '1' && i + 1 < one_segments.size())
        {   //cout << "Choosing a right one L = " << left_segment <<  " R = " << i << " Extra 1s = " << one_segments[i + 1] << endl;
            current_length += one_segments[i + 1];
        }
        //cout << "Total = " << current_length << endl;
        max_length = max(max_length, current_length);
    }

    cout << max_length;
    return 0;
}


Measured memory_bytes: 1340
#include<iostream>
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main()
{
	LL n;
	cin>>n;
	string ans;
	LL col=n;
			while(col>0)
			{
				
				LL t1=col%26;
				col=col/26;
				if(t1==0)
				{
					ans+='Z';
					col--;
				}
				else
				ans+='A'+t1-1;
				
			}
			reverse(ans.begin(),ans.end());
			for(LL i=0; i<ans.length(); i++)
			{
				char temp=ans[i]+32;
				cout<<temp;
			}
			cout<<"\n";
}


Measured memory_bytes: 3624
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
S = sys.stdin.buffer.readline().decode().rstrip()

S = np.array(list(S), dtype='U1')
wc = (S == 'W').cumsum()
ec = (S == 'E')[::-1].cumsum()[::-1]

ans = min(wc[-2], ec[1])
for i in range(1, N - 1):
    ans = min(ans, wc[i - 1] + ec[i + 1])
print(ans)


Measured memory_bytes: 20952
#include <bits/stdc++.h>
using namespace std;
int n,a[105];
int is_ok(int x)
{
	int s=0;
	for(int i=1; i<=n; i++)
		s+=((a[i]-x)*(a[i]-x));
	return s;
 } 
int main()
{
	int i,v=2e9,ans=0;
	cin>>n;
	for(i=1; i<=n; i++)
		cin>>a[i];
	sort(a+1,a+n+1); 
	for(i=a[1]; i<=a[n];i++)
		if(is_ok(i)<v)
		{
			v=is_ok(i);
			ans=v;
		}
		
	cout<<ans;
	return 0;
}


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

int main() {
    int x[10000];
    int t, i=0;
    while (true) {
        cin >> t;
        if (t != 0) {
            x[i] = t;
            i++;
        } else break;
    }
    for (int j = 0; j < i; j++) printf("Case %d: %d\n", j+1, x[j]);
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    list<ll> b;
    rep(i, n) {
        if (i%2==0) b.push_back(a[i]);
        else b.push_front(a[i]);
    }
    if (n%2!=0) reverse(ALL(b));
    for (auto &x : b) cout << x << " ";
    cout << endl;
    return 0;
}

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

int main(){
	long long N, C, vsum = 0, a = 0, ans = 0;
	cin >> N >> C;
	long long x[N], v[N], L[N], LL[N], R[N], RR[N];
	for(int i=0; i<N; i++){
		cin >> x[i] >> v[i];
		vsum += v[i];
	}
	for(int i=0; i<N; i++){
		if(i == 0){
			L[i] = v[i] - x[i];
			R[i] = vsum + v[i] - C - L[i];
			LL[i] = L[i] - x[i];
			RR[i] = R[i] - (C - x[i]);
		}else{
			L[i] = L[i-1] + v[i] - (x[i] - x[i-1]);
			R[i] = R[i-1] - v[i-1] + (x[i] - x[i-1]);
			LL[i] = L[i] - x[i];
			RR[i] = R[i] - (C - x[i]);
		}
	}
	for(int i=0; i<N; i++){
		if(i == 0){
			if(ans < R[i]){
				ans = R[i];
			}
		}else{
			if(a < L[i-1]){
				a = L[i-1];
			}
			if(ans < RR[i] + a){
				ans = RR[i] + a;
			}
		}
	}
	a = 0;
	for(int i=N-1; i>=0; i--){
		if(i == N-1){
			if(ans < L[i]){
				ans = L[i];
			}
		}else{
			if(a < R[i+1]){
				a = R[i+1];
			}
			if(ans < LL[i] + a){
				ans = LL[i] + a;
			}
		}
	}
	for(int i=0; i<N; i++){
		if(ans < L[i]){
			ans = L[i];
		}
		if(ans < R[i]){
			ans = R[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
struct Node {
  int key;
  Node *parent = nullptr, *left = nullptr, *right = nullptr;
};
void insert(Node *root, int key) {
  auto x = root;
  auto *parent = x->parent;

  while (x != nullptr) {
    parent = x;
    if (x->key > key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  if (parent->key > key) {
    parent->left = new Node{key, parent, nullptr, nullptr};
  } else {
    parent->right = new Node{key, parent, nullptr, nullptr};
  }
}
bool find_bitree(Node *root, int key) {
  Node *parent = nullptr;
  auto x = root;

  while (x != nullptr) {
    parent = x;
    if (x->key == key) {
      return true;
    } else if (x->key > key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  return false;
}
void printNodePreOrder(Node *root) {
  if (root == nullptr) return;
  cout << ' ' << root->key;
  printNodePreOrder(root->left);
  printNodePreOrder(root->right);
}
void printNodeInOrder(Node *root) {
  if (root == nullptr) return;
  printNodeInOrder(root->left);
  cout << ' ' << root->key;
  printNodeInOrder(root->right);
}
int main() {
  string op;
  int m, k;
  Node *root = nullptr;
  cin >> m;
  for (size_t i = 0; i < m; i++) {
    cin >> op;
    if (op == "insert") {
      cin >> k;
      if (root == nullptr) {
        root = new Node{k};
      } else {
        insert(root, k);
      }

    } else if (op == "print") {
      printNodeInOrder(root);
      cout << endl;
      printNodePreOrder(root);
      cout << endl;
    } else if (op == "find") {
      cin >> k;
      if (find_bitree(root, k)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}



Measured memory_bytes: 21788
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 30;

vector<ll> dp;

ll N,K;
vector<ll> h(N);

ll ans(ll n) {
	if (dp[n] != -1) return dp[n];

	//if (n <= 0) return 0;


	ll res = INF;
	for (int i = 1; i <= K; i++) {
		if (n - i < 0) break;
		res = min(res,abs(h[n] - h[n - i]) + ans(n - i));
	}

	dp[n] = res;
	return dp[n];
}


int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	cin >> N >> K;

	h = vector<ll>(N);
	dp = vector<ll>(N, -1);
	dp[0] = 0;

	rep(i, N) cin >> h[i];


	cout << ans(N - 1) << endl;


ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for(auto it = v.begin();it != v.end();it++) 
		min = std::min(min,*it);
	return min;
}
int vmax(vector<int> v) {
	int max = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}


Measured memory_bytes: 8312
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

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

    int treeSize(int x) {
        

        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}

bool IsPrime(long long N) {
    if (N == 1) {
        return false;
    }
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            return false;
        }
    }

    return true;
}

bool IsPE(long long z) {
    for (long long i = 2; i <= z; i++) {
        if (z % i == 0 && IsPrime(i)) {
            long long test = i;
            while (test < z) {
                test *= i;
            }
            if (test == z) {
                return true;
            }
        }
    }

    return false;
}

long long  solve(long long N) {
    long long answer = 0;
    long long divider = 2;
    
    while (N >= divider) {
        if (N % divider == 0 && IsPE(divider)) {
            //cout << divider << endl;
            answer++;
            N /= divider;
        }
        
        divider++;
    }

    return answer;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({ a, ex });
    }

    // 最後に残った数について
    if (N != 1) res.push_back({ N, 1 });
    return res;
}

int main() {
    long long H;
    cin >> H;

    long long count = 1;
    long long h = 1;
    while (h * 2 <= H) {
        h *= 2;
        count = count * 2 + 1;
    }

    cout << count << endl;
    return 0;
}

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

void call(int n) {
    int i = 1;
CHECK_NUM:
    int x = i;
    if (x % 3 == 0) {
        cout << " " << i;
        goto END_CHECK_NUM;
    }
INCLUDE3:
    if (x % 10 == 3) {
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    x /= 10;
    if (x) goto INCLUDE3;
END_CHECK_NUM:
    if (++i <= n) goto CHECK_NUM;

    cout << endl;
}

int main() {
    int n;
    cin >> n;
    call(n);

    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

struct input_form{
	int a;
	int b;
	int c;
	int check;
};

input_form in_s[2000];

int main(){
	
	int a_, b_, c_, N, sum;
	
	int part[500];
	while(true){
		cin >> a_ >> b_ >> c_;
		if(a_ == 0 && b_ == 0 && c_ == 0){
			break;
		}
		cin >> N;
		
		sum = a_ + b_ + c_;
		
		for(int i = 1; i <= sum; i++){
			part[i] = 2;
		}
		
		for(int i = 0; i < N; i++){
			cin >> in_s[i].a >> in_s[i].b >> in_s[i].c >> in_s[i].check;
		}
		
		for(int i = 0; i < N; i++){
			if(in_s[i].check == 1){
				part[in_s[i].a] = 1;
				part[in_s[i].b] = 1;
				part[in_s[i].c] = 1;
			}
		}
		
		for(int i = 0; i < N; i++){
			if(in_s[i].check == 0){
				if(part[in_s[i].a] == 1 && part[in_s[i].b] == 1){
					part[in_s[i].c] = 0;
				}else if(part[in_s[i].b] == 1 && part[in_s[i].c] == 1){
					part[in_s[i].a] = 0;
				}else if(part[in_s[i].c] == 1 && part[in_s[i].a] == 1){
					part[in_s[i].b] = 0;
				}
			}
		}
		
		for(int i = 1; i <= sum; i++){
			printf("%d\n", part[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
import itertools


def main():
    L, R = map(int, input().split())
    if R - L > 2017:
        print(0)
        return
    xs = [n % 2019 for n in range(L, R + 1)]
    ans = 2018
    for i, j in itertools.combinations(xs, 2):
        tmp = (i * j) % 2019
        if tmp == 0:
            ans = 0
            break
        else:
            if tmp < ans:
                ans = tmp

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        if (s.length() == 26) {
        	TreeSet<Character> set = new TreeSet<>();
        	set.add(s.charAt(25));
        	for (int i = 24; 0 <= i; i--) {
        		if (set.higher(s.charAt(i)) != null) {
        			System.out.println(s.substring(0, i) + set.higher(s.charAt(i)));
        			return;
        		} else {
        			set.add(s.charAt(i));
        		}
        	}
        	
        	System.out.println(-1);
        } else {
        	for (int i = 'a'; i <= 'z'; i++) {
        		if (s.indexOf(i) == -1) {
        			System.out.println(s + (char)i);
        			break;
        		}
        	}
        }
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
double factorial(int n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

double dist(pair<int,int> a,pair<int,int> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    string s,t;
    cin>>s>>t;
    ll a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s){
        cout<<a-1<<" "<<b<<endl;
    }
    else{
        cout<<a<<" "<<b-1<<endl;
    }

    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
 
/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
 
/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
/* func */
 
/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
 
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
 
//#define int ll
//#define int long long
 
int func(int n){
if(n < 10) return n;
  return func(n/10)+n%10;
}
 
signed main()
{
  int n; cin >> n;
  int s = func(n);
  if(n % s == 0)
    cout << "Yes";
  else
    cout << "No";
  
  return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	double r;
	cin >> r;
	double ans = PI * 2 * r;
	printf("%.6f\n", ans);
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<double> a(n);
    double x=0.0000000000000001;
    for(int i=0;i<n;i++){
        cin>>a[i];
        x+=1/(a[i]+0.00000000000001);
        //cout<<x<<endl;
    }
    cout<<1/x+0.000000001<<endl;


}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

bool vis[1005];
int main(){
    int n;
    scanf("%d", &n);
    int ans = 1;
    for(int i=2;i<=n;i++){
        if(vis[i]) continue;
        int res = 0;
        for(int j=i;j<=n;j+=i){
            vis[j] = 1;
            int x = j, cnt = 0;
            while(x%i == 0) x/=i, cnt++;
            res += cnt;
        }
        ans = ans*1ll*(res+1)%mod;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3732
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in();
    vector<vector<ll>>edge(n);
    REP(i, n - 1) {
        ll a = in() - 1, b = in() - 1;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<ll>c(n);
    REP(i, n)c[i] = in();
    sort(ALL(c));

    vector<ll>d(n);
    queue<ll>nodes; nodes.push(0);
    set<ll>pushed; pushed.insert(0);
    while (!nodes.empty()) {
        auto node = nodes.front(); nodes.pop();
        d[node] = c.back(); c.pop_back();
        REPC(child, edge[node]) {
            if (!pushed.count(child)) {
                nodes.push(child);
                pushed.insert(child);
            }
        }
    }

    ll ans = 0;
    REP(i, n) {
        REPC(n, edge[i]) {
            ans += min(d[i], d[n]);
        }
    }
    cout << ans / 2 << endl;
    REP(i, n) {
        if (i != 0)cout << ' ';
        cout << d[i];
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using namespace std;
long long f[100][10];
long long p[100][11];
long long d[10];
long long n;

int main() {
	vector<int> v(4);
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++) {
		v[i]= int(s[i]-'0');
	}
	
	for (int i = 0; i < 8; i++) {
		int sum = v[0];
		vector<char> vc;
		for (int j = 0; j < 3; j++) {
			if (i >> j & 1) {
				sum += v[j + 1];
				vc.push_back('+');
			}
			else {
				sum -=v[j + 1];
				vc.push_back('-');
			}
		}
		if (sum == 7) {
			for(int k = 0; k < 4; k++) {
				if (k)
					cout << vc[k-1];
				cout << v[k];
			}
			cout << "=7"<< endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
	var n int
	var a,sum,t int
	var temp float64
	fmt.Scan(&n)
	t = 1000000000000000000
	temp = float64(t)
	sum = 1
	flag := true
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&a)
		sum *= a
		if float64(a) > temp {
			flag = false
		}
		temp = float64(temp/float64(a))
		if sum < 0 || t < sum {
			flag = false
		}
		if !flag && a == 0{
			flag = true
			sum = 0
		}
//fmt.Println(sum)
	}
	if !flag{
		fmt.Println("-1")
	} else {
		fmt.Println(sum)
	}
}


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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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

void countChar(vector<vector<int>>& vc, string str){
    for(int i = 0; i < str.size(); i++){
        vc.at(i).at(str.at(i)-'a')++;
    }
}

int getSum(vector<vector<int>>& vc){
    int ret = 0;
    for(auto vv : vc){
        sort(vv.begin(), vv.end());
        ret+=3-*vv.rbegin();
    }
    return ret;
}

void solve(){
    int n;
    string a,b,c;
    cin >> n >> a >> b >> c;
    vector<vector<int>> vCounter(n, vector<int>(26, 0));
    countChar(vCounter, a);
    countChar(vCounter, b);
    countChar(vCounter, c);
    cout << getSum(vCounter) << endl;
}
int main(){
    solve();
    return 0;
}

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

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define END(ans) {ans = 0; break;}

using lli = long long int;

constexpr int mod = 1e9 + 7;
std::vector<int> A, B;
std::vector<bool> P, Q;


int main(void){
    int n; scanf("%d", &n);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    B.resize(n); REP(i, n) scanf("%d", &B[i]);
    P.resize(n, false); FOR(i, 1, n) if(A[i-1] < A[i]) P[i] = true; P[0] = true;
    Q.resize(n, false); FOR(i, 1, n) if(B[i-1] > B[i]) Q[i-1] = true; Q[n-1] = true;
    lli res = 1;
    REP(i, n){
        if(P[i]){if(A[i] > B[i]) END(res)}
        else if(Q[i]){if(B[i] > A[i]) END(res) }
        else (res *= (A[i] > B[i]) ? B[i] : A[i]) %= mod;
    }
    printf("%lld\n", res);  
    return 0;
}

Measured memory_bytes: 1024
fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let v: Vec<f64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
  let (w, h, x, y) = (v[0], v[1], v[2], v[3]);
  let ans1 = w * h / 2.0;
  let ans2 = if x * 2.0 == w && y * 2.0 == h { 1 } else { 0 };
  println!("{} {}", ans1, ans2);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,input;
    cin>>n;
    set<int> a;
    rep(i,n){
        cin>>input;
        a.insert(input);
    }
    if(a.size() == n){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

//lli gcd(lli a,lli b){
//    lli x,y;
//    x=max(a,b);
//    y=min(a,b);
//    if(x%y==0){
//        return y;
//    }
//    else{
//        return gcd(y,x%y);
//    }
//}
//
//lli lcm(lli a,lli b){
//    lli x,y;
//    x=max(a,b);
//    y=min(a,b);
//    return x*y/gcd(x,y);
//}

struct work{
    lli w;
    lli t;
    bool operator<(const work &another)const{
        return t<another.t;
    }
};

int main(){
    lli n,by=0,sum=0;
    work job;
    string ans="Yes";
    vector<work> vec;
    lli i,j;
    cin>>n;
    rep(i,0,n){
        cin>>job.w>>job.t;
        vec.push_back(job);
        sum+=job.w;
        by=max(by,job.t);
    }
    if(by<sum){
        ans="No";
    }
    else{
        sum=0;
        by=vec[0].t;
        sort(vec.begin(),vec.end());
        rep(i,0,vec.size()){
            if(i>0){
                if(vec[i].t!=vec[i-1].t){
                    if(sum>by){
                        ans="No";
                        break;
                    }
                    by=vec[i].t;
                }
            }
            sum+=vec[i].w;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#include<numeric>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    int n;
    cin>>n;
    vvi in(n,vi(2));
    rep(i,n)rep(j,2)cin>>in[i][j];
    vi t(n);
    iota(all(t),0);
    double sum=0;
    do{
        rep(i,n-1)sum+=hypot(in[t[i]][0]-in[t[i+1]][0],in[t[i]][1]-in[t[i+1]][1]);
    }while(next_permutation(all(t)));
    rep(i,n)sum/=i+1;
    cout<<shosu(9)<<sum<<endl;
}


Measured memory_bytes: 256
N ,P= map(int,input().split())
S = input()
ten = [0] * len(S)
for i in range(len(S)):
    if i == 0:
        ten[i] = 1
    else:
        ten[i] = (ten[i-1] * 10) %P
if P != 2 and P != 5:
    mod_dic ={}
    mod_dic[0] = 1
    mod = 0
    for i in range(len(S)):
        mod +=  int(S[N-1-i]) * ten[i]
        mod = mod%P
        if mod not in mod_dic:
            mod_dic[mod] = 1
        else:
            mod_dic[mod] += 1
        ans = 0
    a = list(mod_dic.values())
    for i in range(len(a)):
            ans += a[i] * (a[i]-1) //2
    print(ans)
elif P == 2:
    ans = 0
    for i in range(len(S)):
        if int(S[len(S)-1-i])%2 == 0:
            ans += N-i
    print(ans)
else:
    ans = 0
    for i in range(len(S)):
        if int(S[len(S)-1-i])%5 == 0:
            ans += N-i
    print(ans)


Measured memory_bytes: 44748
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> P;
int main(){
  int h,w;
  bool mas[10][10000];
  while( cin >> h >> w , h ){
    for(int i = 0 ; i < h ; i++ ){
      for(int j = 0 ; j < w ; j++ ){
        cin >> mas[i][j];
      }
    }
    int ans = 0;
    for(int i = 0 ; i < (1 << h) ; i++ ){
      int sum = 0;
      for(int j = 0 ; j < w ; j++ ){
        int cnt = 0;
        for(int k = 0 ; k < h ; k++ ){
          cnt += mas[k][j]^(i>>k&1);
        }
        sum += max( h - cnt , cnt );
      }
      ans = max( sum , ans );
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int a,b,c,k;
int main(void){
	cin>>a>>b>>c>>k;
	if(a>k){
		cout<<k<<endl;
	}else if(k<=a+b){
		cout<<a<<endl;
	}else{
		cout<<a-(k-a-b)<<endl;
	}
	
}


Measured memory_bytes: 3612
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(n**(0.5)) + 1):
        if n % k == 0:
            return False
    return True

x = int(input())
for i in range(x,10**6):
    if is_prime(i):
        ans = i
        break
print(ans)

Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
    int A,B,N,i,j,num;
    int total=0,tnum=0;
    scanf("%d%d%d",&N,&A,&B);
    for(j=1;j<=N;j++){
        num = j;
    for(i=0;num!=0;i++){
        total += num%10;
        num = num/10;
    }
        if(total>=A&&total<=B)tnum+=j;
        total = 0;
    }
    printf("%d",tnum);
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A1 = []
A2 = []
for _ in range(N):
    a = input().split()
    A1.append((a[0], int(a[1])))
    A2.append((a[0], int(a[1])))

snt = 10 ** 9 + 1

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x[1]:
            i += 1
            A[i], A[j] = A[j], A[i]
    i += 1
    A[i], A[r] = A[r], A[i]
    return i


def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q - 1)
        quick_sort(A, q + 1, r)

def merge(A, left, mid, right):
    L = A[left:mid] + [('SNT', snt)]
    R = A[mid:right] + [('SNT', snt)]
    i, j = 0, 0
    for k in range(left, right):
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

quick_sort(A1, 0, N - 1)
merge_sort(A2, 0, N)

print('Stable' if A1 == A2 else 'Not stable')
for a1 in A1: print(*a1)


Measured memory_bytes: 27200
#include <stddef.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>

using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2, s3 = "";
    cin >> s1 >> s2;
    size_t m = max(s1.size(), s2.size());
    while (s1.size() < m)
      s1.insert(s1.begin(), '0');
    while (s2.size() < m)
      s2.insert(s2.begin(), '0');
    char c = 0;
    auto it1 = s1.rbegin();
    auto it2 = s2.rbegin();
    for (; it1 != s1.rend(); it1++, it2++) {
      char add = *it1 - '0' + *it2 - '0' + c;
      char ch = add % 10 + '0';
      c = add / 10;
      s3.insert(s3.begin(), ch);
    }
    if (c) s3.insert(s3.begin(), c + '0');
    cout << ((s3.size() > 80) ? "overflow" :s3) << endl;
  }
}

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

int main() {

	string s; cin >> s;
	stack<char> st;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') st.push(s[i]);
		else if (s[i] == '1') st.push(s[i]);
		else {
			if (!st.empty()) st.pop();
		}
	}
	string ans = "";
	while (!st.empty()) {
		ans += st.top();
		st.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
    return 0;
}

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

const int MAX_V = 10;
const int MAX_E = 45;
const int INF = 100000000;

int dist[MAX_V][MAX_V];

int main() {
  while (true) {
    int n; scanf("%d", &n);
    if (n == 0) break;

    for (int i = 0; i < MAX_V; i++) {
      for (int j = 0; j < MAX_V; j++) dist[i][j] = (i == j ? 0 : INF);
    }

    int vnum = 0;
    for (int i = 0; i < n; i++) {
      int u, v, d; scanf("%d %d %d", &u, &v, &d);
      dist[u][v] = dist[v][u] = d;
      vnum = max(vnum, max(u, v) + 1);
    }

    // Warshall-Froyd
    for (int k = 0; k < vnum; k++) {
      for (int i = 0; i < vnum; i++) {
        for (int j = 0; j < vnum; j++) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    int minV = -1;
    int minSum = INF;
    int ans = INF;
    for (int i = 0; i < vnum; i++) {
      int sum = 0;
      for (int j = 0; j < vnum; j++) {
        if (j != i) sum += dist[i][j];
      }
      if (sum < minSum) {
        minV = i;
        minSum = sum;
      }
    }
    printf("%d %d\n", minV, minSum);
  }
}

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

int main() {
    int n; cin >> n;
    int arr[n];
    int ans = 0;
    rep(i, 0, n) cin >> arr[i];
    rep(i, 0, n) {
        if ((i+1)%2!=0 && arr[i] %2!=0)
            ans++;
    }
    cout << ans << el;

    return 0;
}




Measured memory_bytes: 3588
h,w,d=[int(i) for i in input().split()]
a=[]
for i in range(h):
    a.append([int(i) for i in input().split()])
q=int(input())
lr=[]
for i in range(q):
    lr.append([int(i) for i in input().split()])

location_x=[0 for i in range(h*w)]
location_y=[0 for i in range(h*w)]
for i in range(h):
    for j in range(w):
        location_x[a[i][j]-1]=j
        location_y[a[i][j]-1]=i

mpp=[0 for i in range(h*w)]

for i in range(d):
    j=1
    while i+j*d<=h*w-1:
        mpp[ i+j*d]=mpp[ i+j*d-d]+abs(location_x[i+j*d-d]-location_x[i+j*d])+abs(location_y[i+j*d-d]-location_y[i+j*d])
        j+=1

for i in range(q):
    print( mpp[lr[i][1]-1] - mpp[lr[i][0]-1] )

#print(mpp)


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int h=read(),w=read(),n=read();
	vector<vi> ans(h,vi(w));
	int x=0,y=0;
	REP(i,n){
		int a=read();
		REP(_,a){
			ans[y][x]=i+1;
			if(y%2==0){
				if(x==w-1)
					y++;
				else
					x++;
			}else{
				if(x==0)
					y++;
				else
					x--;
			}
		}
	}
	REP(i,h)
		REP(j,w)
			print(ans[i][j],j==w-1?1:2);
}

Measured memory_bytes: 384
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * AtCoder Beginner Contest 129<br>
 * B - Balance<br>
 * <br>
 * <a href=
 * "https://atcoder.jp/contests/abc129/tasks/abc129_b">AtCoderへのリンク</a><br>
 */
public class Main {

    /**
     * エントリポイント
     */
    public static void main(String[] args) {
        // 入力
        Model m = input(System.in);
        // 演算
        int result = proc(m);
        // 出力
        System.out.println(result);
    }

    /**
     * 入力モデル
     */
    static class Model {
        /** オモリの数 */
        int N;
        /** オモリの重さリスト */
        List<Integer> list = new ArrayList<Integer>();
    }

    /**
     * 入力値より入力モデルを作成する
     */
    static Model input(InputStream in) {
        Model m = new Model();
        try (Scanner sc = new Scanner(in)) {
            String[] line1 = sc.nextLine().split(" ");
            String[] line2 = sc.nextLine().split(" ");

            m.N = Integer.parseInt(line1[0]);
            for (String str : line2) {
                m.list.add(Integer.parseInt(str));
            }
        }
        return m;
    }

    /**
     * 演算を行う
     */
    static int proc(final Model m) {
        int answer = 10000;
        int total = 0;
        int s1 = 0;
        
        for (int i = 0; i < m.N; i++) {
            total += m.list.get(i);
        }

        for (int i = 0; i < m.N; i++) {
            s1 += m.list.get(i);
            answer = Math.min(answer, Math.abs(s1 - (total - s1)));
        }
        return answer;
    }
}


Measured memory_bytes: 23892
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
const int maxn=5e5+10;
int n,a[maxn],w[maxn],d[maxn];
int ff[maxn];
ll sum[maxn];

int sz[maxn],fa[maxn],S[maxn];
int find(int x){
    if(fa[x]==x) return x;
    return fa[x]=find(fa[x]);
}
struct point{
    int w,s,f;
    bool operator <(const point &rhs) const{
        return 1ll*w*rhs.s>1ll*rhs.w*s;
    }
};
priority_queue<point> q;
int main(){
    n=read();
    REP(i,2,n) ff[i]=read();
    REP(i,1,n) w[i]=read();
    REP(i,1,n) fa[i]=i,sz[i]=!w[i],S[i]=w[i],sum[i]=0,q.push((point){w[i],!w[i],i});
    int m=n-1;
    while(!q.empty()){
        point u=q.top();q.pop();
        if(u.s!=sz[u.f] || u.w!=S[u.f] || u.f==1) continue;
//		cerr<<u.f<<endl;
        --m;
        int x=find(ff[u.f]);
        fa[find(u.f)]=x;
        sum[x]+=1ll*sz[u.f]*S[x]+sum[u.f];
        S[x]+=S[u.f];
        sz[x]+=u.s;
        if(!m) break;
        if(x) q.push((point){S[x],sz[x],x});
    }
    printf("%lld\n",sum[1]);
    return 0;
}


Measured memory_bytes: 19956
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    cout << to[i].size() << endl;
  }
}

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

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

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i].first;
        A[i].second = i + 1;
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < N; i++){
        cout << A[i].second;
        if(i != N - 1)cout << " ";
        else cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

bool arr[101];

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

uint32_t h[100000];
uint8_t is[100000];

int main(void){
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	for(uint32_t i=0; i<n; i++){
		h[i]=nextpint();
	}
	for(uint32_t i=0; i<m; i++){
		uint32_t a=nextpint()-1;
		uint32_t b=nextpint()-1;
		if(h[a]>h[b]){
			is[b]=1;
		}else if(h[a]<h[b]){
			is[a]=1;
		}else{
			is[a]=1;
			is[b]=1;
		}
	}
	uint32_t ans=0;
	for(uint32_t i=0; i<n; i++){
		ans+=is[i];
	}
	printint(n-ans);
}


Measured memory_bytes: 2012
package main

import "fmt"

func main() {
	array := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	var n int
	fmt.Scan(&n)
	fmt.Println(array[n-1])
}


Measured memory_bytes: 512
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 X              PIC 9(10).
01 dv             PIC 9(10).
01 dv5            PIC 9(10).
01 rm             PIC 9(10).
01 ans            PIC 9(10).
01 zs             PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT X.
  COMPUTE dv = X / 500.
  COMPUTE rm = X - dv * 500.
  COMPUTE dv5 = rm / 5.
  COMPUTE ans = dv * 1000 + dv5 * 5.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


Measured memory_bytes: 384
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()

    odd = 0
    for a in A:
        if a % 2:
            odd += 1
    return 'YES' if odd % 2 == 0 else 'NO'


print(main())


Measured memory_bytes: 14264
#define NDEBUG

#include <iostream>
#include <atcoder/dsu>

namespace ac = atcoder;

void solve() {
    int n, q;
    std::cin >> n >> q;

    ac::dsu dsu(n);
    while (q--) {
        int t, u, v;
        std::cin >> t >> u >> v;

        switch (t) {
            case 0:
                dsu.merge(u, v);
                break;
            case 1:
                std::cout << dsu.same(u, v) << "\n";
                break;
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3888
main = interact $ unlines . map show . sum_and_average . map (map read . splitOn ',') . lines

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)

sum_and_average sas = [sum_, average_]
 where
  sum_ = sum $ map product sas
  average_ = round' $ fromIntegral (sum $ map last sas) / fromIntegral (length sas)
  round' n
   | n - fromIntegral (floor n) == 0.5 = ceiling n
   | otherwise = round n

Measured memory_bytes: 3648