akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
vector<int> e[1010];
int vis[1010],h[1010][1010][2],u[201000],v[201000],n,m;
void dfs(int x,int p,int flag){
	vis[x]=1;
	for(int v:e[x]) if(!vis[v]){
		h[p][v][flag]=x;
		dfs(v,p,flag);
	}
}
int main(){
	read(n);read(m);
	for(int i=1;i<=m;i++){
		read(u[i]);read(v[i]);
		e[u[i]].push_back(v[i]);
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		dfs(i,i,0);
		reverse(e[i].begin(),e[i].end());
		memset(vis,0,sizeof(vis));
		dfs(i,i,1);
		reverse(e[i].begin(),e[i].end());
	}
	for(int i=1;i<=m;i++){
		int flag=1;
		if(h[v[i]][u[i]][0]) flag^=1;
		if(h[u[i]][v[i]][0]!=u[i]||h[u[i]][v[i]][1]!=u[i]) flag^=1;
		if(flag) puts("same");
		else puts("diff");
	}
	return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};



int main() {
    int n;cin>>n;
    double T; cin>>T;
    double A;cin>>A;
    vector<double> H(n);cin>>H;
    double mindiff = INF;
    int ind = -1;
    rep(i,n){
        if(mindiff > abs(A-(T-H[i]*0.006))){
            mindiff =abs(A-(T-H[i]*0.006));
            ind = i;
        }
    }
    cout<<ind+1<<endl;
    return 0;
}





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



int main() {

	int X, A, B, C,ans=0;
	cin >> A >> B >> C >> X;
	for (int i = 0; i <= (X / 500)&&i<=A; i++)
	{
		for (int j = 0; j <= (X - 500 * i) / 100&&j<=B; j++)
		{
			int k = X - 500 * i - 100 * j;
			if ((k % 50) == 0 && (k / 50) <= C)
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
for i in range(n):
    a=list(map(float,input().split()))
    if a[0]**2+a[1]**2==a[2]**2:
         print("YES")
    elif a[1]**2+a[2]**2==a[0]**2:
        print("YES")
    elif a[2]**2+a[0]**2==a[1]**2:
        print("YES")
    else:
        print("NO")


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

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b)
{
	while (b) a %= b,swap(a,b);
	return a;
}

ll powmod(ll b, ll e)
{
	ll r= 1;
	while (e) {
		if (e&1) r = r*b%mod;
		e>>=1;
		b=b*b%mod;
	}
	return r;
}

ll inv(ll x) { return powmod(x, mod - 2); }

void test3(int n)
{
	vector<ll> pf(n + 1);
	pf[0] = 0LL;
	REP(i, n) pf[i+1] = (pf[i] + inv(i+1)) % mod;

	ll f = 1LL; REP(i, n) f = f * (i+1) % mod;

	ll ret = 0;
	for (int j = 0; j < n; j++) {
		ll bj = (pf[j + 1] + pf[n - j] + mod - 1) % mod;
		ll x;
		cin >> x;
		ret += x * f % mod * bj % mod;
		if (ret >= mod) ret -= mod;

		// cerr << (f * bj % mod) << " ";
	}
	cout << ret << endl;
	// cerr << endl;
}

void test2(int n)
{
	// given length L, index I: what is the coefficient?
	vvi C(n + 1);
	ll fact = 1;
	for (int i = 1; i <= n; i++) {
		fact = fact * i % mod;

		// populate C[i]
		C[i] = vi(i, fact);

		ll waysL = 1LL;
		for (int j = 0; j < i; j++) {
			// remove j
			for (int k = j + 1; k < i; k++) {
				C[i][k] += waysL * C[i - j - 1][k - j - 1] % mod;
				if (C[i][k] >= mod) C[i][k] -= mod;
			}
			waysL = waysL * (i - 1 - j) % mod;
		}
		ll waysR = 1LL;
		for (int j = i - 1; j >= 0; j--) {
			// remove j
			for (int k = 0; k < j; k++) {
				C[i][k] += waysR * C[j][k] % mod;
				if (C[i][k] >= mod) C[i][k] -= mod;
			}
			waysR = waysR * j % mod;
		}
	}
	REP(i, n) cerr << C[n][i] << " ";
	cerr << endl;
/*
	ll g = 0;
	REP(i, n) g = gcd(g, C[n][i]);
	cerr << g << endl;
*/
}

void test(int n)
{
	vi a(n);
	REP(i, n) a[i] = i;

	vi C(n, 0);
	do {
		REP(i, n) {
			int j = -1, k = n;
			REP(x, i) if (a[x] < a[i]) j = max(j, a[x]); else k = min(k, a[x]);
			rep(x, j + 1, k) C[x]++;
		}
	} while (next_permutation(all(a)));

	REP(i, n) cerr << C[i] << " ";
	cerr << endl;
/*
	ll nfact = n;
	REP(i, n) nfact *= (i + 1);

	REP(i, n) cerr << (nfact - C[i]) << " ";
	cerr << endl;

	ll ans = 0;
	REP(i, n) { int x; cin >> x; ans += 1LL * x * C[i]; }
	cout << ans << endl;
*/
}


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

	int n;
	cin >> n;
	// test2(n);
	test3(n);
	// rep(i, 1, n + 1) test(i);

	return 0;
}


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

const int mod = 1e9+7;
const int INF = 2000000;


int main() {
    int N;
    cin >> N;
    int h[N],dp[N];
    rep(i,N) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<N;++i) dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
K, X = map(int, input().split())

x_min = X - K + 1
x_max = X + K - 1

if x_min < -1000000:
    x_min = -1000000

if x_max > 1000000:
    x_max = 1000000


result = []
for i in range(x_min, x_max+1):
    result.append(str(i))

print(' '.join(result))


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

typedef long long ll;
typedef int keytype;

int main(){
    ll n, k;

    scanf("%lld %lld", &n, &k);

    ll ans;
    if((n % k) <= k - (n % k)) ans = (n % k);
    else ans = k - (n % k);

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

    return 0;
}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,M,R;
vector<int>v;
int dist[222][222];
int ans=2e18;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N>>M>>R;
    for(int i=0;i<R;i++){
        int x;
        cin>>x;
        v.push_back(--x);
    }
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(i!=j)dist[i][j]=2e18;
    for(int i=0;i<M;i++){
        int a,b,x;
        cin>>a>>b>>x;
        a--;b--;
        dist[a][b]=dist[b][a]=x;
    }
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            for(int k=0;k<N;k++)
                dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
    sort(v.begin(),v.end());
    do {
        int sum=0LL;
        int x=v.front();
        for(int i:v){
            sum+=dist[x][i];
            x=i;
        }
        ans=min(ans,sum);
    } while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<set>
#include<string>
#define min(_x, _y)_y^((_x^_y)&-(_y>_x))
using namespace std;
 
int main(){
    int K, n;
    string str,str2;
    cin >> str;
    cin >> K;
    set<string>s;
    n = str.size();
    for(int i = 0; i < n; i++){
        int j = min(n-i,K);
        for(; j > 0; j--){
            str2 = str.substr(i,j);
            s.insert(str2);
        }
    }
    set<string>::iterator it=s.begin();
    for(int i = 0; i < K-1; i++, it++);
    cout << *it << endl;

}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int main() {
	string s;
	cin >> s;
	ll k;
	cin >> k;
	ll ans = 0;
	int n = s.length();
	bool flag = true;
	rep(i, n-1) {
		if (s[i] != s[i + 1]) {
			flag = false;
			break;
		}
	}
	if (s[0] != s[n - 1]) {
		for (int i = 0;i < n-1;++i) {
			if (s[i] == s[i + 1]) {
				ans++;
				++i;
			}
		}
		ans*= k;
	}
	else {
		int a = 0, b = 0;
		for (int i = 0;i < n;++i) {
			if (s[0] == s[i]) {
				a++;
			}
			else {
				break;
			}
		}
		for (int i = n - 1;i >= 0;--i) {
			if (s[0] == s[i]) {
				b++;
			}
			else {
				break;
			}
		}
		rep(i, n - 1) {
			if (s[i] == s[i + 1]) {
				ans++;
				++i;
			}
		}
		ans *= k;
		if (a % 2 != 0 && b % 2 != 0) {
			ans += (k - 1);
		}
	}
	if (flag) {
		ans = n * k / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
	string N;
	int K;
	cin >> N >> K;
	bool CanUse[10];
	for (int i = 0; i < 10; i++) CanUse[i] = true;
	for (int i = 0; i < K; i++) {
		int d;
		cin >> d;
		CanUse[d] = false;
	}
	char minnotzero = '0';
	for (int i = 1; i < 10; i++) {
		if (CanUse[i]) {
			minnotzero += i;
			break;
		}
	}
	char min = (CanUse[0] ? '0' : minnotzero);
	string ans = "";
	for (int i = 0; i < N.length(); i++) {
		ans.push_back(N[i]);
		if (!CanUse[N[i] - '0']) {
			int j = i;
			while (!CanUse[ans[j] - '0']) {
				if (ans[j] != '9') ans[j]++;
				else {
					ans[j] = min;
					if (j == 0) ans.insert(ans.begin(), minnotzero);
					else {
						j--;
						ans[j]++;
					}
				}
			}
			i++;
			for (; i < N.length(); i++) ans.push_back(min);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    	a:usize,
        b:usize
    }
    println!("{}", 6-a-b);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    string s;
    cin >> s;
    bool con1, con2;
    con1 = true;
    rep(i, s.size()) {
        if (s[i] != s[s.size()-1-i]) con1 = false;
    }
    if (con1 == false) {
        cout << "No" << endl;
        return 0;
    }
    //cout << "here" << endl;
    con2 = true;
    rep(i, s.size()/2) {
        if (s[i] != s[ceil((s.size()-1)/2.0) - i - 1]) con2 = false;
    }
    if (con2 == false) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
vector<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	V[s] = true;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		out.push_back(u);
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if (indeg[v] == 0 && !V[v]) {
				V[v] = true;
				q.push(v);
			}
		}
	}
}

void tsort() {
	for (int i = 0; i < N; i++) {
		indeg[i] = 0;
	}

	for (int u = 0; u < N; u++) {
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]++;
		}
	}

	for (int u = 0; u < N; u++)
		if (indeg[u] == 0 && !V[u]) bfs(u);

	int unique = 1;
	for (int i = 0; i < out.size(); i++) {
		cout << out[i] + 1 << endl;
		if (i + 1 < out.size()) {
			int u = 0;
			for (int j = 0; j < G[out[i]].size(); j++) {
				int to = G[out[i]][j];
				u |= to == out[i + 1];
			}
			unique &= u;
		}
	}
	cout << !unique << endl;
}

int main() {
	int s, t, M;

	cin >> N >> M;

	for (int i = 0; i < N; i++) V[i] = false;

	for (int i = 0; i < M; i++) {
		cin >> s >> t;
		G[s - 1].push_back(t - 1);
	}

	tsort();

	return 0;
}

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

constexpr int inf = 1e9;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        g[a - 1].push_back(b - 1);
    }

    vector<int> ans;
    for(int s = 0; s < n; ++s) {
        queue<int> que;
        vector<int> d(n, inf), prev(n, -1);
        d[s] = 1;
        que.push(s);
        while(!que.empty()) {
            const int v = que.front(); que.pop();
            for(auto const to : g[v]) {
                if(d[to] != inf) continue;
                d[to] = d[v] + 1;
                prev[to] = v;
                que.push(to);
            }
        }

        int min_cycle = inf, cur = -1;
        for(int from = 0; from < n; ++from) {
            for(auto to : g[from]) {
                if(to != s) continue;
                if(min_cycle > d[from]) {
                    min_cycle = d[from];
                    cur = from;
                }
            }
        }
        if(min_cycle == inf) continue;

        if(ans.empty() || (int)ans.size() > min_cycle) {
            ans.clear();
            do {
                ans.push_back(cur);
                cur = prev[cur];
            } while(cur != -1);
        }
    }

    if(ans.empty()) {
        cout << -1 << endl;
    } else {
        cout << ans.size() << endl;
        for(auto const v : ans) {
            cout << v + 1 << endl;
        }
    }
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100005],b[100005];
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		++b[a[i]];
	}
	int ans=0;
	for(int i=1;i<=100000;++i){
		ans=max(ans,b[i-1]+b[i]+b[i+1]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
import java.math.BigDecimal
import java.util.*

data class Point(val x: Int, val y: Int)

fun main(args: Array<String>) {
    var (x1, y1, x2, y2) = readLine()!!.split(' ').map(String::toInt)
    if (x1 > x2) { var t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t }
    val swapY: (Int) -> Int = if (y1 > y2) {{99999999 - it}} else {{it}}
    val p1 = Point(x1, swapY(y1))
    val p2 = Point(x2, swapY(y2))
    val n = readLine()!!.toInt()
    val points = ArrayList<Point>()
    for (i in 1..n) {
        val (x, y) = readLine()!!.split(' ').map(String::toInt)
        val p = Point(x, swapY(y))
        if (p.x in p1.x..p2.x && p.y in p1.y..p2.y) points.add(p)
    }
    points.sortBy { it.x }
    val ansMap = TreeMap<Int, Int>()
    ansMap.put(p1.y - 1, 0)
    for (p in points) {
        val fc = ansMap.floorEntry(p.y).value + 1
        val cy = ansMap.ceilingKey(p.y)
        if (cy != null) ansMap.remove(cy)
        ansMap.put(p.y, fc)
    }
    val q = ansMap.lastEntry().value
    var res = bd(100) * bd((p2.x - p1.x + p2.y - p1.y).toLong()) - (bd(20) - bdPI * bd(5)) * bd(q.toLong())
    if (q == p2.x - p1.x + 1 || q == p2.y - p1.y + 1) res += bdPI * bd(5)
    println(res.toPlainString())
}

fun bd(q: Long) = BigDecimal.valueOf(q)!!
val bdPI = BigDecimal("3.14159265358979323846264338327950288419716939937510")


Measured memory_bytes: 118992
package main

import "fmt"

func main() {
	var N, M, C int
	fmt.Scan(&N, &M, &C)
	B := make([]int, M)
	for i := range B {
		fmt.Scan(&B[i])
	}
	A := make([][]int, N)
	for i := range A {
		A[i] = make([]int, M)
		for j := range A[i] {
			fmt.Scan(&A[i][j])
		}
	}
	var count, sum int
	for i := 0; i < N; i++ {
		sum = 0
		for j := 0; j < M; j++ {
			sum += A[i][j] * B[j]
		}
		if sum+C > 0 {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int x[15][15];
int n, d;

int chk(int i){
    int sq = (int) sqrt(i);
    if(sq * sq == i) return 1;
    return 0;
}

int main(){
    scanf("%d%d", &n, &d);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++) scanf("%d", &x[i][j]);
    }
    int cnt = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            int sm = 0;
            for(int k = 0; k < d; k++) sm += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            if(chk(sm)) cnt++;
        }
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
priority_queue<int> p;

int main(){
    cin>>N;
    rep(i,N){
        int x;
        cin>>x;
        p.push(x);
    }

    int ans=0;
    ans+=p.top()/2;
    p.pop();
    while(!p.empty()){
        ans+=p.top();
        p.pop();
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL A[100000 + 1000];
LL N;
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%lld", &N);
	for (LL i = 1; i <= N; ++i) scanf("%lld", &A[i]);
	LL Ans = 0;
	for (LL i = 1; i <= N; ++i)
	{
		if (A[i + 1] >= A[i] - A[i - 1])
		{
			Ans += A[i];
			if (A[i - 1] > A[i])
				Ans += ((A[i - 1] - A[i]) / 2);
			A[i + 1] -= max(0ll, (A[i] - A[i - 1]));
			A[i - 1] = max(0ll, A[i - 1] - A[i]);
			A[i - 1] -= (A[i - 1] / 2) * 2;
			A[i] = 0;
		}
		else 
		{
			Ans += (A[i - 1]);
			A[i] -= A[i - 1];
			Ans += (A[i] / 2);
			A[i] -= (A[i] / 2) * 2;
		}
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

ll f(ll A, ll B, ll x) {
    return A * x  / B - A * (x / B);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, N;
    cin >> A >> B >> N;
    if (N >= B - 1) {
        cout << f(A, B, B - 1) << endl;
    } else {
        cout << f(A, B, N) << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
A = tuple(map(int, input().split()))
m = 1000
kabu = 0
for pa, aa in zip(A[:n], A[1:]):
    if pa < aa:
        # buy all
        kk, m = divmod(m, pa)
        kabu += kk
    elif pa > aa:
        # sel all
        m += kabu * pa
        kabu = 0

if kabu > 0:
    m += kabu*aa

print(m)


Measured memory_bytes: 61828
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);
#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

const int N = 2e3 + 50;
const int mod = 998244353 ;

int main(){
    io();

    int n;
    cin >> n;
    set<string> st;
    while(n--) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size();

}



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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int C[3];

int main()
{
    string S;
    cin >> S;
    REP(i, S.length())
    {
        C[S[i] - 'a']++;
    }
    if (abs(C[0] - C[1]) <= 1 && abs(C[1] - C[2]) <= 1 && abs(C[2] - C[0]) <= 1)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

bool myfunction( char i, char j ){
	return (i>j); 
}

int main(){
	string s, t;
	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), myfunction);
	
	if( s < t )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int cnt[2][202020];

int main(){
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    int a[n];
    rep(i,n)a[i]=(s[i]=='A');
    vector<int> v[n];
    rep(i,m){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
        cnt[a[x]][y]++;
        cnt[a[y]][x]++;
    }
    bool ok[n];
    queue<int> q;
    rep(i,n){
        ok[i]=(cnt[1][i]>0&&cnt[0][i]>0);
        if(!ok[i])q.push(i);
    }
    while(q.size()){
        int x=q.front();q.pop();
        for(auto& u:v[x]){
            if(!ok[u])continue;
            if(--cnt[a[x]][u]==0){
                ok[u]=false;
                q.push(u);
            }
        }
    }
    rep(i,n){
        if(ok[i]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 13060
function Count(p) {
    var cnt = 0;
    while (p % 2 == 0) {
        cnt++;
        p >>= 1;
    }
    return cnt;
}
function Main(input) {
    input = input.split("\n");
    a = input[1].split(" ").map(p => Count(p));
    console.log(a.reduce((p, q) => p + q));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9676
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  if(N >= 2) {
    for(int i=N-1; i>0; i--) {
      if(H[i-1]-H[i] > 1) {
        cout << "No" << endl;
        return 0;
      }
      if(H[i-1]-H[i] == 1)
        H[i-1]--;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	if n == 0 || k == 1 {
		fmt.Println(0)
		return
	}

	for {
		a := n / k
		if a == 0 {
			ab := abs(n - k)
			if n > ab {
				fmt.Println(ab)
				return
			}
			fmt.Println(n)
			return
		}
		n = n % k
	}
}

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

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

int main() {
	int n, m; cin >> n >> m;
	vector<int>a(m), b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}

	vector<int>road(50, 0);
	for (int i = 0; i < m; i++) {
		road[a[i] - 1]++;
		road[b[i] - 1]++;
	}
	
	for (int i = 0; i < n; i++) {
		cout << road[i] << endl;
	}

	return 0;
}

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

using ll = long long;
const int AMAX = 100000;
ll bucket[AMAX + 1];

int main()
{
  int N;
  ll K;
  cin >> N >> K;

  int a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    bucket[a] += b;
  }

  for (int i = 1; i <= AMAX; i++) {
    if (K <= bucket[i]) {
      cout << i << endl;
      break;
    }
    K -= bucket[i];
  }
  return 0;
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc114/tasks/abc114_c

N = int(input())


def f(s):
    if len(s) > 0 and int(s) > N:
        return 0

    ans = 1 if all(s.count(c) > 0 for c in '753') else 0

    for c in '753':
        ans += f(s + c)

    return ans


print(f(""))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b;
    cin>>a>>b;
    int ans=0;
    rep(i,b-a) ans+=i;
    cout<<ans-a;
}

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

int N;
vector<int> L;
vector<int> A; // A, B, C

int main() {
    cin >> N;
    A.resize(3);
    for (int i = 0; i < 3; ++i) cin >> A[i];
    L.resize(N);
    for (int i = 0; i < N; ++i) cin >> L[i];

    int res = 1<<29;
    vector<int> bit(3);
    for (bit[0] = 1; bit[0] < (1<<N); ++bit[0]) { // 0 は含めない
        for (bit[1] = 1; bit[1] < (1<<N); ++bit[1]) { // 0 は含めない
            // 共通要素あったらダメ
            if (bit[1] & bit[0]) continue;
            for (bit[2] = 1; bit[2] < (1<<N); ++bit[2]) { // 0 は含めない
                // 共通要素があったらダメ
                if (bit[2] & bit[0]) continue;
                if (bit[2] & bit[1]) continue;
                
                // sums: A〜C に選んだ竹の長さの合計、nums: A〜C に選んだ竹の本数
                vector<int> sums(3, 0), nums(3, 0);
                for (int i = 0; i < N; ++i) {
                    for (int j = 0; j < 3; ++j) {
                        if (bit[j] & (1<<i)) {
                            sums[j] += L[i];
                            nums[j]++;
                        }
                    }
                }

                // score を求める
                int score = 0;
                for (int i = 0; i < 3; ++i) {
                    score += abs(sums[i] - A[i]); // +1, -1 のコスト
                    score += (nums[i] - 1) * 10; // 合体のコスト
                }
                res = min(res, score);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    cin >> N;
    int a = 0;
    REP(i, N) {
        int x;
        cin >> x;
        if(x % 2 == 1) a++;
    }
    if(a % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 764
//-----------------------
// author : xyqkoala
// time : 2020-07-27
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

bool dfs(int s,int len,int &k,string &temp,string &res){
	if(len==0){
		k--;
		if(k==0){
			res = temp;
			return true;
		}
		return false;
	}

	for(int i=max(0,s-1);i<=min(9,s+1);i++){
		temp.push_back('0'+i);
		if(dfs(i,len-1,k,temp,res)) return true;
		temp.pop_back();
	}
	return false;
}

void solve(){
	int k;
	cin>>k;
	string res;
	int len = 1;
	while(k){
		for(int i=1;i<10;i++){
			string temp = to_string(i);
			if(dfs(i,len-1,k,temp,res)) break;
		}
		len++;
		if(res.size()!=0) break;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3676
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

map<int,int> res;
void prime_factor(int n){
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1) res[n]++;
    return;
}

int main(){
    int N;
    cin>>N;
    ll ans=1;
    for(int i=1;i<=N;i++){
        prime_factor(i);
    }
    for(int i=1;i<=N;i++){
        ans =ans*(res[i]+1)%MOD;
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;
int main() {
	int a, b;
	cin >> a >> b;
	if (b > a)swap(a, b);
	int ans = a;
	ans += max(a - 1, b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
import java.util.HashMap;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt(), K = scanner.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
            if (i>=K) {
                System.out.println(arr[i]>arr[i-K]?"Yes":"No");
            }
        }
    }

    private static boolean max1(int a, int b, int c, int k) {
        boolean ans = true;
        while (k>0) {
            if (b<=a) {
                b*=2;
                k--;
            } else if (c<=b) {
                c*=2;
                k--;
            }
            if (c>b&&b>a)
                break;
        }
        return c>b&&b>a;
    }

}


Measured memory_bytes: 51212
#include<stdio.h>
#include<stdlib.h>
#define ll long long
int cmp(const void *a,const void *b){return *(long long*)a-*(long long*)b;}
int main(){
    ll n,i;
    scanf("%lld",&n);
    ll a[n],b[n];
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        b[i]=a[i];
    }
    qsort(b,n,sizeof(long long),cmp);
    for(i=0;i<n;i++)
        if(a[i]==b[n-1])
            printf("%lld\n",b[n-2]);
        else
            printf("%lld\n",b[n-1]);
    return 0;
}

Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, X;
	cin >> n >> X;
	vector<ll> x(n);
	rep(i, n) cin >> x[i];
	x.emplace_back(X);
	sort(all(x));
	ll ans = x[n] - x[0];
	rep(i, n - 1) ans = gcd(ans, x[i + 1] - x[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
  int a,i,k[205][2],xmax,xmin,ymax,ymin,b,c;
  while(1){
    scanf("%d",&a);
    if(a==0)break;
    if(a==1){
      printf("1 1\n");
      continue;
    }
    for(i=0;i<a;i++){
      k[i][0]=0;
      k[i][1]=0;
    }
    xmin=0;
    xmax=0;
    ymin=0;
    ymax=0;
    for(i=1;i<a;i++){
      scanf("%d %d",&b,&c);
      k[i][0]=k[b][0];
      k[i][1]=k[b][1];
      if(c==0)k[i][1]--;
      else if(c==1)k[i][0]--;
      else if(c==2)k[i][1]++;
      else if(c==3)k[i][0]++;
      //printf("%d %d ",k[i][0],k[i][1]);///
      if(k[i][0]>xmax)xmax=k[i][0];
      else if(k[i][1]>ymax)ymax=k[i][1];
      else if(k[i][0]<xmin)xmin=k[i][0];
      else if(k[i][1]<ymin)ymin=k[i][1];
      //printf("%d %d %d %d\n",xmax,xmin,ymax,ymin);///
    }
    printf("%d %d\n",ymax-ymin+1,xmax-xmin+1);
  }
  return 0;
}

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

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

    int strike = 0;
    bool found = false;
    while (n--) {
        int a, b;
        cin >> a >> b;

        if (a == b)
            ++strike;
        else
            strike = 0;

        if (strike == 3 && !found) {
            found = true;
            cout << "Yes";
        }
    }

    if (!found)
        cout << "No";
    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<BigInteger> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => BigInteger.Parse(x)); }
}

namespace AtCoder.C
{
    public class Program
    {
        public static BigInteger N { get; private set; }
        public static int K { get; private set; }
        public static List<BigInteger> H { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetTexts().ToList();
            N = BigInteger.Parse(inputs[0]);
            K = int.Parse(inputs[1]);
            H = CR.GetIntegers().ToList();

            var h = H.OrderByDescending(x => x).Skip(K);
            BigInteger sum = 0;
            foreach (var item in h)
            {
                sum += item;
            }
            return sum;
        }
    }
}


Measured memory_bytes: 44840
N = int(input())
red_ls = list()
blue_ls = list()
for i in range(N):
    red_ls.append([int(i) for i in input().split()])
for i in range(N):
    blue_ls.append([int(i) for i in input().split()])


red_ls = sorted(red_ls, key=lambda x:(x[1], x[0]), reverse=True)
#red_x, red_y = zip(*red_ls)
blue_ls = sorted(blue_ls, key=lambda x:(x[0], x[1]))

cnt = 0
pre_ind = -1
yet_ls = list()
for (blue_x, blue_y) in blue_ls:
    flg = 0
    for ind, (red_x, red_y) in enumerate(red_ls):
        if red_y >= blue_y:
            continue
        if red_x >= blue_x:
            continue
        if ind in yet_ls:
            continue
        cnt += 1
        yet_ls.append(ind)
        break
print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 200005;

struct Edge
{
	int u, v;
	LL w;
	bool operator < (const Edge &b) const { return w < b.w; }
};

int n, a[MAXN], f[MAXN], siz[MAXN];
vector <pii> adj[MAXN];
vector <Edge> edg;
vector <int> seq;
bool vis[MAXN];
LL d[MAXN];

inline int Find(int x)
{
	while (x ^ f[x])
		x = f[x] = f[f[x]];
	return x;
}

inline void FindRoot(int x, int p, int Siz, int &c)
{
	bool f = true;
	siz[x] = 1;
	for (auto e : adj[x])
		if (!vis[e.xx] && (e.xx ^ p))
			FindRoot(e.xx, x, Siz, c), f &= siz[e.xx] <= Siz >> 1, siz[x] += siz[e.xx];
	f &= siz[x] >= Siz >> 1;
	if (f)
		c = x;
}

inline void FindSize(int x, int p)
{
	seq.pb(x), siz[x] = 1;
	for (auto e : adj[x])
		if (!vis[e.xx] && (e.xx ^ p))
			d[e.xx] = d[x] + e.yy, FindSize(e.xx, x), siz[x] += siz[e.xx];
}

inline void Solve(int x, int Siz)
{
	int c, p = 0;
	FindRoot(x, 0, Siz, c);
	vis[x = c] = true, d[x] = 0, seq.clear();
	FindSize(x, 0);
	LL val = 1LL << 60;
	for (auto y : seq)
		if ((d[y] += a[y]) < val)
			val = d[y], p = y;
	for (auto y : seq)
		edg.pb({p, y, d[p] + d[y]});
	for (auto e : adj[x])
		if (!vis[e.xx])
			Solve(e.xx, siz[e.xx]);
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read();
	for (int i = 1, x, y, w; i < n; i ++)
		x = Read(), y = Read(), w = Read(), adj[x].pb(mp(y, w)), adj[y].pb(mp(x, w));
	Solve(1, n);
	sort(edg.begin(), edg.end());
	for (int i = 1; i <= n; i ++)
		f[i] = i;
	LL ans = 0;
	for (auto e : edg)
		if (Find(e.u) ^ Find(e.v))
			f[Find(e.u)] = Find(e.v), ans += e.w;
	return printf("%lld\n", ans), 0;
}


Measured memory_bytes: 90852
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>

using namespace std;


int main() {
	char S[100001], S_nox[100001];
	int len_S, len_S_nox, i, j, num_x[100001], ans;

	scanf("%s", S);
	len_S = strlen(S);
	j = 0;
	for (i = 0; i < len_S + 1; i++) {
		num_x[i] = 0;
	}
	for (i = 0; i < len_S; i++) {
		if (S[i] != 'x') {
			S_nox[j] = S[i]; j++;
		}
		else {
			num_x[j]++;
		}

	}
	len_S_nox = j;
	for (i = 0; i < len_S_nox; i++) {
		if (S_nox[i] != S_nox[len_S_nox - 1 - i]) {
			printf("-1\n"); return 0;
		}
	}

	ans = 0;
	for (i = 0; i < len_S_nox - i; i++) {
		ans = ans + max(num_x[i] - num_x[len_S_nox - i], -num_x[i] + num_x[len_S_nox - i]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 768
N = int(input())
H = list(map(int, input().split()))

step = 0
tmp = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        tmp += 1
    else:
        if tmp > step:
            step = tmp
        tmp = 0

if tmp > step:
    step = tmp

print(step)


Measured memory_bytes: 14252
import sys
n, x = map(int, sys.stdin.readline().split())
llist =list(map(int, sys.stdin.readline().split()))

d = 0
ans = 1
for l in llist:
  ans += 1
  d += l
  if d > x:
    ans -= 1
    break
  elif d == x:
    break
  
  if ans >= n+1:
    print(n+1)
    exit()
print(ans)

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int x;
    cin >> x;

    if(x<1200){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();

        if ((a + b) % 2 == 0) {
            System.out.println((a + b) / 2);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
long long INF = (long long)1E17;
#define i_7 (long long)(1E9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE = 400'010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
  invinit();
  using namespace std;
  long long n, k;
  cin>>n>>k;
  long long ans = 0;
  if(k >= n - 1){
    ans = comb(2 * n - 1, n);
    cout<<ans<<endl;
    return 0;
  }
  for(long long m = 0; m <= k; m++){
    ans += mod(comb(n, m) * comb(n - 1, m));
    ans = mod(ans);
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 9728
//#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
// constexpr int INF = 1<<30;
// constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
int N;

int main(int argc, char** argv) {
  cin >> N;
  vll A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }

  multiset<ll> ret;
  ret.insert(A[0]);

  for (int i=1; i<N; i++) {
    const ll a = A[i];
    auto it = ret.lower_bound(a);
    if (it != begin(ret)) {
      it--;
      ret.erase(it);
    }
    ret.insert(A[i]);
  }

  cout << ret.size() << endl;
  return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>>task;
  for(int i=0;i<3;i++)
    task.push_back({0});
  
  for(int i=0;i<n;i++){
    int a;
    for(int j=0;j<3;j++){
      cin>>a;
      if(j==0)task[0].push_back(max(task[1][i],task[2][i])+a);
      if(j==1)task[1].push_back(max(task[0][i],task[2][i])+a);
      if(j==2)task[2].push_back(max(task[1][i],task[0][i])+a);
    }
  }
  cout<< max(task[0][task[0].size()-1],max(task[1][task[1].size()-1],task[2][task[2].size()-1]))<<endl;
}

Measured memory_bytes: 1644