akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define ll long long
#define N 3002
int add(int x, int y, int p) {
	int ret = (x + y);
	if (ret >= p) {
		ret -= p;
	}
	else if (ret < 0) {
		ret += p;
	}
	return ret;
}
int mul(int x, int y, int p) {
	return (ll)x*y%p;
}
int mypow(int x, int c, int p) {
	int ret = 1;
	while (c > 0) {
		if (c & 1) {
			ret = mul(ret, x, p);
		}
		x = mul(x, x, p);
		c /= 2;
	}
	return ret;
}
int a[N];
int combi[N][N];
void init(int p) {
	for (int i = 0; i < N; ++i) {
		combi[i][i] = combi[i][0] = 1;
		for (int j = 1; j < i; ++j) {
			combi[i][j] = add(combi[i - 1][j], combi[i - 1][j - 1], p);
		}
	}
}
int val[N];
void solve() {
	int p; scanf("%d", &p);
	init(p);
	for (int i = 0; i < p; ++i) {
		scanf("%d", &a[i]);
		if (a[i] == 1) {
			int tmp = 1;
			for (int j = p-1; j >=0; --j) {
				int x = mul(tmp, combi[p - 1][j], p);
				if ( ((p - 1 - j) & 1) ==0 ){
					x = -x;
				}
				val[j] = add(val[j], x, p);
				tmp = mul(tmp, i,p);
			}
		}
	}
	val[0] = a[0];
	for (int i = 0; i < p; ++i) {
		printf("%d ", val[i]);
	}
	putchar('\n');
}
int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}

Measured memory_bytes: 34304
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
const ll mod = 998244353;
const ll N = 3 * 100000 + 5;
ll Mode(ll a, ll b){
	ll sum = 1;
	while (b) {
		if (b & 1) {
			sum = (sum * a) % mod;
			b--;
		}
		b /= 2;
		a = a * a % mod;
	}
	return sum;
}
//快速幂取模 

ll inv(ll a){
	return Mode(a, mod - 2);
}
//逆元 

ll jc[N];
void init() //预处理算阶乘
{
    jc[0] = 1;
    for(int i = 1; i < N; ++i)
    jc[i] = jc[i-1] * i % mod;
}
ll C(ll n, ll m){
    if(n<0||m>n)
        return 0;
    return ((jc[n] % mod) * ((inv(jc[m]) * inv(jc[n - m])) % mod)) % mod;
}//组合数 
int main(){
//	ios::sync_with_stdio(false);
//	ifstream cin("data.txt");
//	freopen("data.txt", "r", stdin);
	init();
	ll n, a, b, k;
	ll ans = 0;
	cin >> n >> a >> b >> k;
	if(k == 0){
		cout << 1 << endl;
		return 0;
	}
	for(ll i = 0; i <= n; i++){	
		if(!((k - a * i) % b)){
			ll t1 = i;
			ll t2 = ((k - a * i) / b); 
			if(t2 < 0)continue;
			ll cnt = C(n, t1);
			cnt %= mod;
			cnt *= C(n, t2);
			cnt %= mod; 
			ans += cnt;
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    long n,cnt[30]={},ans=1;
    char s[200010];
    scanf("%s",s);
    n=strlen(s);
    for(int i=0;i<n;i++){
        cnt[s[i]-'a']++;
    }
    for(int i=0;i<30;i++){
        for(int j=i+1;j<30;j++){
            ans+=cnt[i]*cnt[j];
        }
    }
    printf("%ld\n",ans);
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int inf = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

int n;
ll inp[N + N];

map < ll , int > mymap;

vector < ll > v;

int main(){
  fastScan(n);
  for(int i = 1; i <= n; i++){
    fastScan(inp[i]);
    mymap[inp[i]]++;
  }
  sort(inp + 1, inp + n + 1);
  for(int i = 0; (1ll << i) <= 1ll * 1e12; i++){
    v.pb((1ll << i));
  }
  int ans = 0;
  for(int i = n; i >= 1; i--){
    if(mymap[inp[i]] == 0){
      continue;
    }
    mymap[inp[i]]--;
    int j = upper_bound(v.begin(), v.end(), inp[i]) - v.begin();
    ll need = v[j] - inp[i];
    if(mymap[need] > 0){
      ans++;
      mymap[need]--;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 26752
let () =
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in
    let lcm a b = let g = gcd a b in a / g * b in
    let calc a c d =
        let divisible_by_c = a / c in
        let divisible_by_d = a / d in
        let divisible_by_c_and_d = a / lcm c d in
        a - divisible_by_c - divisible_by_d + divisible_by_c_and_d
    in
    let main () =
        let a, b, c, d = Scanf.sscanf (read_line ()) "%d %d %d %d" (fun a b c d -> a, b, c, d) in
        let s = calc b c d - calc (a - 1) c d in
        Printf.printf "%d\n" s
    in
    main ()

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

using Pdi = pair<double, int>;

signed main(){

    int N; cin >> N;
    vec x(N), y(N);
    vector<Pdi> p(N);

    REP(i, N){
        cin >> x[i] >> y[i];
        double theta = atan2((double)x[i], (double)y[i]);
        p[i] = Pdi(theta, i);
    }
    Sort(p);
    REP(i, N) p.pb(p[i]);

    int ans = 0;
    REP(i, N){
        int X = 0, Y = 0;
        REP(j, N){
            int i0 = p[i + j].s;
            X += x[i0]; Y += y[i0];
            Max(ans, X * X + Y * Y);
        }
    }
    Out(sqrt(ans));

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[100];
int main(){
	int a;scanf("%d",&a);
	int at=0;
	if(a==0){
		printf("0\n");return 0;
	}
	while(a){
		if(ABS(a)%2==1){
			in[at]='1';
			a--;
		}else in[at]='0';
		a/=-2;
		at++;
	}
	for(int i=at-1;i>=0;i--){
		printf("%c",in[i]);
	}printf("\n");
}


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

bool can[100010];
char buf[100010];

bool chck(int at, const char *pat)
{
	for (int i = 0;pat[i];i++) if (buf[at+i] != pat[i])
		return false;
	return true;
}

int main()
{
	scanf("%s", buf);
	can[0] = true; int i = 0;
	for (;buf[i];i++) if (can[i])
	{
		if (chck(i, "dream")) can[i+5] = true;
		if (chck(i, "dreamer")) can[i+7] = true;
		if (chck(i, "erase")) can[i+5] = true;
		if (chck(i, "eraser")) can[i+6] = true;
	}
	if (can[i]) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

int main(){
    int p,q,r;
    cin >> p >> q >> r;
    
    int min=p+q;
    
    if(min>p+r){
        min=p+r;
    }
    if(min>q+r){
        min=q+r;
    }
    
    cout << min << endl;
    return 0;
}

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

int main()
{
  int N, A, B;
  string S;
  cin >> N >> A >> B >> S;
  int ApB = A+B;
  int p = 0;
  int r = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == 'a'){
      if(p < ApB){
        cout << "Yes" << endl;
        p++;
      }else{
        cout << "No" << endl;
      }
    }else if(S[i] == 'b'){
      r++;
      if(p < ApB && r <= B){
        cout << "Yes" << endl;
        p++;
      }else{
        cout << "No" << endl;
      }
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 896
package main

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

const Mod = int(1e9) + 7

func main() {
	S = ReadString()
	memo = make([][]*int, len(S))
	for i := 0; i < len(S); i++ {
		memo[i] = make([]*int, 13)
	}
	fmt.Println(recur(0, 0))
}

var S string
var memo [][]*int

func recur(i int, r int) int {
	if i == len(S) {
		if r == 5 {
			return 1
		}
		return 0
	}
	if memo[i][r] != nil {
		return *memo[i][r]
	}
	ans := 0
	if S[i] == '?' {
		for x := 0; x <= 9; x++ {
			ans += recur(i+1, (r*10+x)%13)
			ans %= Mod
		}
	} else {
		x := int(S[i] - '0')
		ans += recur(i+1, (r*10+x)%13)
		ans %= Mod
	}
	memo[i][r] = &ans
	return ans
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 33932
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    pair <string, pair<int, int> > s[110];
    rep(i, n){
        string S;
        int a;
        cin>>S>>a;
        s[i].first=S;
        s[i].second.first=a*(-1);
        s[i].second.second=i+1;
    }

    sort(s, s+n);

    rep(i, n){
        cout<<s[i].second.second<<endl;
    }




}


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

const ll mod = 1000000007;


int main() {
	int n, r; cin >> n >> r;
	if(n >= 10) cout << r << endl;
	else cout << r + 100*(10 - n) << endl;
} 

Measured memory_bytes: 256
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
if 0 in L_A:
    print(0)
else:
    k = 1
    for i in range(N):
        k *= L_A[i]
        if k > 10**18:
            print("-1")
            break
    else:
        print(k)

Measured memory_bytes: 21640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i=0;
		try (Scanner scn = new Scanner(System.in)) {
			while(true) {
				i++;
				if(scn.nextInt() == 0) {
					System.out.println(i);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 35684
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
int H, W, M;
set<i_i> st;
 
void input() {
    cin >> H >> W >> M;
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        st.insert({a, b});
    }
}
 
void solve() {
    map<int, int> mph, mpw;
    int hmaxval = 0;
    int wmaxval = 0;
    vector<int> hmax, wmax;
    for(auto tmp : st) {
        chmax(hmaxval, ++mph[tmp.first]);
        chmax(wmaxval, ++mpw[tmp.second]);
    }
    for(auto tmp : mph) {
        if(hmaxval == tmp.second) hmax.push_back(tmp.first);
    }
    for(auto tmp : mpw) {
        if(wmaxval == tmp.second) wmax.push_back(tmp.first);
    }
    int ANS = hmaxval + wmaxval - 1;
    for(auto h : hmax) {
        for(auto w : wmax) {
            if(st.find({h, w}) == st.end()) {
                ANS++;
                cout << ANS << endl;
                return;
            }
        }
    }
    cout << ANS << endl;
}
 
int main() {
    input();
    solve();
    return 0;
}


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

struct S {
    int no;
    int member;
};

bool operator<(const S& left, const S& right) {
        return left.member < right .member;
}
int main() {
    int N;
    cin >> N;

    vector<S> A;
    for (int i = 0; i < N; i++ ) {
        int val;
        cin >> val;
        S s = {i+1, val};
        A.push_back(s);
    }

    std::sort(A.begin(), A.end() );

    for (auto s : A){
        cout << s.no << ' ';
    }

    return 0;
}



Measured memory_bytes: 1780
n = int(input())
s = str(input())
cnt = {}
for i in s:
    if i in cnt:
        cnt[i] += 1
    else:
        cnt[i] = 1
ans = 1
for i in cnt:
    ans = ans * (cnt[i] +1)
ans -= 1
print(ans % (10**9 + 7))


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

#define infi            1e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
//inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
// inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//

int A[50],B[50],C[50];
int dp[50][500][500];
int aa,bb,n;

int solve(int ind, int Ma, int Mb){
    if(ind==n){
        int g=gcd(Ma,Mb);
        if(g!=0 && Ma/g==aa && Mb/g==bb)return 0;
        else return infi;
    }
    if(dp[ind][Ma][Mb]!=-1){
        return dp[ind][Ma][Mb];
    }

    return dp[ind][Ma][Mb]=min(solve(ind+1,Ma+A[ind],Mb+B[ind])+C[ind], solve(ind+1,Ma,Mb));
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle
    //freopen("in.txt", "r", stdin);//#endif
    
    n=rr;aa=rr;bb=rr;

    loop(i,n){
        A[i]=rr;
        B[i]=rr;
        C[i]=rr;
    }
    ms(dp, -1);

    int ans=solve(0,0,0);

    cout << (ans==infi?-1:ans) << endl;

    return 0;
}

Measured memory_bytes: 49152
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int s[575];

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n){
    cin >> s[i];
  }
  int m = 1e9;
  ll sum = 0LL;

  REP(i, n){
    sum += s[i];
    if(s[i] < m && s[i]%10 != 0) m = s[i];
  }
  if(sum%10 == 0 && m == 1e9) cout << "0" << endl;
  else if(sum%10 == 0) cout << sum-m << endl;
  else cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
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; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,m;
  cin >> n >> m;
  UnionFind<int>tree(n);
  if(m==0){
    cout << "Yes" << endl;
    return 0;
  }
    
  rep(i,m){
    int l,r,d;
    cin >> l >> r >> d;
    l--;
    r--;
    if(tree.issame(l,r)){
      int diff=tree.diff(l,r);
      if(d!=diff){
        cout << "No" << endl;
        return 0;
      }
    }
    else tree.merge(l,r,d);
  }
  cout << "Yes"<< endl;
  
}


Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory>
#include <queue>
#include <set>

class Node {
public:
  explicit Node(int number) {
    m_number = number;
    w_num = -1;
    b_num = -1;
  }
  int getId() const {
    return m_number;
  }
  std::vector<Node *> getChildren() const {
    return m_children;
  }
  void setAsRoot() {
    for (auto& child : m_children) {
      child->registerParent(m_number);
    }
  }
  void registerParent(const int parent_id) {
    for (auto it = m_children.begin(); it != m_children.end(); ++it) {
      if ((*it)->getId() == parent_id) {
        m_children.erase(it);
        break;
      }
    }
    for (auto& child : m_children) {
      child->registerParent(m_number);
    }
  }

  void addChild(Node *const child) {
    m_children.push_back(child);
  }

  int64_t getWNum() const {
    if (w_num >= 0) {
      return w_num;
    }
    int64_t total = 1;
    for (const auto &child : m_children) {
      total *= ((child->getBNum() + child->getWNum())) % 1000000007LL;
      total %= 1000000007LL;
    }
    w_num = total;
    return total;
  }
  int64_t getBNum() const {
    if (b_num >= 0) {
      return b_num;
    }
    int64_t total = 1;
    for (const auto &child : m_children) {
      total *= child->getWNum();
      total %= 1000000007LL;
    }
    b_num = total;
    return total;
  }

private:
  int m_number;
  std::vector<Node *> m_children;
  mutable int64_t w_num;
  mutable int64_t b_num;

};

int64_t getIndependentNum(const std::vector<std::pair<int, int>> &edges) {
  const int nodes_num = static_cast<int>(edges.size() + 1);
  std::vector<std::vector<int>> edges2(nodes_num);
  for (const auto &edge : edges) {
    edges2[edge.first - 1].push_back(edge.second - 1);
    edges2[edge.second - 1].push_back(edge.first - 1);
  }
  std::vector<std::shared_ptr<Node>> nodes(nodes_num);
  for (int i = 0; i < nodes_num; ++i) {
    nodes[i] = std::make_shared<Node>(i);
  }
  for (int i = 0; i < nodes_num; ++i) {
    for (const auto &child_id : edges2[i]) {
      nodes[i]->addChild(nodes[child_id].get());
    }
  }
  nodes[0]->setAsRoot();
  for (const auto &node : nodes) {
    if (!node) {
      std::cout << "something is wrong" << std::endl;
      return 0;
    }
  }
  return (nodes[0]->getBNum() + nodes[0]->getWNum()) % 1000000007LL;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> edges;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    std::cin >> a >> b;
    edges.emplace_back(a, b);
  }
  std::cout << getIndependentNum(edges) << std::endl;
  return 0;
}


Measured memory_bytes: 22644
#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>
#include <string.h>
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 dp[100100];
int ans;
int m[1000];
int a[1000];
int n;
bool flag;

void solve(int K){
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  rep(i,n){
    rep(j,K+1){
      if(dp[j]>=0){
        dp[j]=m[i];
      }else if(j<a[i] || dp[j-a[i]]<=0){
        dp[j]=-1;
      }else{
        dp[j]=dp[j-a[i]]-1;
      }
    }
  }
  if(dp[K]>=0 && K%10!=0){
    flag=true;
  }
}

int main(){
  int sum=0;
  flag=false;
  int N;
  cin >> N;
  vector<int> s(N);
  rep(i,N)cin >> s[i];
  sort(s.begin(),s.end());
  int temp=0;
  rep(i,N)sum+=s[i];
  int cnt=0;
  while(temp<N){
    m[cnt]=upper_bound(s.begin(),s.end(),s[temp])-lower_bound(s.begin(),s.end(),s[temp]);
    a[cnt]=s[temp];
    temp=upper_bound(s.begin(),s.end(),s[temp])-s.begin();
    cnt++;
  }
  n=cnt;
  
  for(int i=sum;i>=0;i--){
    solve(i);
    if(flag || i==0){
      cout << i << endl;
      return 0;
    }
  }
return 0;}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String T = sc.next();
        int A = sc.nextInt();
        int B = sc.nextInt();
        String U = sc.next();

        if (S.equals(U))
            System.out.println((A - 1) + " " + B);
        else
            System.out.println(A + " " + (B - 1));

        sc.close();
    }

}


Measured memory_bytes: 23764
// Copyright (C) 2016 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <ctime>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <string>

#define x first
#define y second
#define MP std::make_pair
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long LL;
typedef std::pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
std::string procStatus()
{
    std::ifstream t("/proc/self/status");
    return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            f = -1;
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
char S[MAXN];

void input()
{
    scanf("%s", S + 1);
    N = strlen(S + 1);
}

void solve()
{
    static bool can[MAXN];

    can[0] = true;
    for (int i = 1; i <= N; ++i) {
        if (i >= 5 && S[i - 4] == 'd' && S[i - 3] == 'r' && S[i - 2] == 'e' && S[i - 1] == 'a' && S[i - 0] == 'm')
            can[i] |= can[i - 5];
        if (i >= 5 && S[i - 4] == 'e' && S[i - 3] == 'r' && S[i - 2] == 'a' && S[i - 1] == 's' && S[i - 0] == 'e')
            can[i] |= can[i - 5];
        if (i >= 6 && S[i - 5] == 'e' && S[i - 4] == 'r' && S[i - 3] == 'a' && S[i - 2] == 's' && S[i - 1] == 'e' && S[i] == 'r')
            can[i] |= can[i - 6];
        if (i >= 7 && S[i - 6] == 'd' && S[i - 5] == 'r' && S[i - 4] == 'e' && S[i - 3] == 'a' && S[i - 2] == 'm' && S[i - 1] == 'e' && S[i] == 'r')
            can[i] |= can[i - 7];
    }
    puts(can[N] ? "YES" : "NO");
}

int main()
{
#ifdef __DEBUG
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>

using namespace std;

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

int sum[100000];

int main(){
    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<int>> A(H, vector<int>(W));
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            cin >> A[i][j];
        }
    }
    int Q;
    cin >> Q;
    vector<int> L(Q), R(Q);
    for(int i = 0; i < Q; ++i){
        cin >> L[i] >> R[i];
    }
    
    // キーに対応する座標を格納するコンテナ
    unordered_map<int, P> coord;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            coord[A[i][j]] = P(i + 1, j + 1);
        }
    }
    
    for(int i = H * W - D + 1; i <= H * W; ++i){
        int now = i;
        while(now > D){
            int temp = sum[now];
            P p1 = coord[now];
            now -= D;
            P p2 = coord[now];
            
            sum[now] = temp + abs(p2.first - p1.first) + abs(p2.second - p1.second);
        }
    }
    
    for(int i = 0; i < Q; ++i){
        cout << sum[L[i]] - sum[R[i]] << endl;
    }
}

Measured memory_bytes: 6436
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

using namespace std;

const double EPS = 1e-10;
const int64_t INF = 1e9;
typedef long long ll;

int main()
{
	int n;
	scanf("%d", &n);
	ll cnt = 0;

	for (int i = 1; i < n; ++i) {
		cnt += n / i;
		if (n % i == 0) --cnt;
	}

	printf("%lld\n", cnt);
	return 0;
}


Measured memory_bytes: 3232
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

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

int main(void){
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,M,i,j,A[9],num[9]={2,5,5,4,5,6,3,7,6};
string dp[10101];
void chmax(string &s,string t){
  if(s=="_"||s.size()<t.size()||(s.size()==t.size()&&s<t))s=t;
}
main(){
  cin>>N>>M;
  for(i=0;i<M;i++)cin>>A[i];
  fill(dp,dp+10101,"_");
  dp[0]="";
  for(i=0;i<=N;i++){
    if(dp[i]=="_")continue;
    for(j=0;j<M;j++)chmax(dp[i+num[A[j]-1]],dp[i]+to_string(A[j]));
  }
  cout<<dp[N]<<endl;
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll x; cin >> x;
    cout << x * x * x << endl;

}


Measured memory_bytes: 3096
k, n = map(int, input().split())
A = list(map(int, input().split()))

A_dis = [a - A[i-1] if i > 0 else 0 for i, a in enumerate(A)]

A_dis.append(k - A[-1] + A[0])

A_dis.remove(max(A_dis))

print(sum(A_dis))


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

int h;

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i;
}

int right(int i){
  return 2 * i + 1;
}

void maxHeapify(int *A, int i){
  int l, r, largest;
  
  l = left(i);
  r = right(i);
  
  if(l <= h && A[l] > A[i]) largest = l;
  else largest = i;
  
  if(r <= h && A[r] > A[largest]) largest = r;
  
  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(A, largest);
  }
}

int heapExtractMax(int *A){
  if(h < 1) return -1;
  
  int max = A[1];
  A[1] = A[h];
  h--;
  maxHeapify(A, 1);
  
  return max;
}

void heapIncreaseKey(int *A, int i, int key){
  if(key < A[i]) return ;
  
  A[i] = key;
  while(i > 1 && A[parent(i)] < A[i]){
    swap(A[i], A[parent(i)]);
    i = parent(i);
  }
}

void maxHeapInsert(int *A, int key){
  h++;
  A[h] = -1;
  heapIncreaseKey(A, h, key);
}

int main(){
  
  int k, a[2000010];
  string command;
  
  while(cin >> command, command != "end"){
    if(command == "insert"){
      cin >> k;
      maxHeapInsert(a, k);
    }else if(command == "extract"){
      cout << heapExtractMax(a) << endl;
    }
  }
  
  return 0;
}



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

int main() {
	long long n,  N = 1e7+5, ans = 0, f[N];
	memset(f,0,sizeof(f));
	cin >> n;
	for(long long i = 1; i < N; i++){
		for(long long j = i; j < N; j+=i){
			f[j]++;
		}
	}
	for(long long i = 1; i <= n; i++){
		ans += f[i]*i;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 81732
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	string l, r;
	cin >> N;
	cin >> l >> r;
	for (int i = 0; i <= N; i++) {
		if (l.substr(i, N - i) == r.substr(0, N - i)) {
			cout << N + i << endl;
			return 0;
		}
	}
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

bool vis[N + 5];
int cost[N + 5];
vector<int>g[N + 5];
int n;
void dfs(int u){
  vis[u] = true;
  cost[u] = 1;
  for (int v : g[u]){
    if (vis[v] == false){
      dfs(v); 
      cost[u] += cost[v];
    }
  }
}

int main(){
  FASTER;
  cin >> n;
  for (int i = 1; i < n; i++){
    int x;
    cin >> x;
    cost[x]++;
  }
  for (int i = 1; i <= n; i++){
    cout << cost[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 9012
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i,t,n) for(int i=t;i<n;i++)
#define nd "\n"
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>




/*ll power(ll x,ll t){
if(t<=0){
    return 1;
}
ll y=(power(x,t/2));
y=(y*y)%ma;
if(t%2)
    y=(y*x)%ma;
return y;

}*/
/*ll ph[100001];
void E_phi(int n){

ph[0]=0;
ph[1]=1;
for(int i=2;i<=n;i++){
    ph[i]=i;
}
for(int i=2;i<=n;i++){
    if(ph[i]==i){
        for(int j=i;j<=n;j+=){
            ph[j]-=ph[j]/i;
        }
    }
}


}*/
/*string s,t;
vector<int>  z_fun(string s){

int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}*/

/*struct st{
ll sum,pre,suf,ans;
st(){}
st(ll k){
ans=k,pre=k,suf=k,sum=0;
}

};
ll t[4*200001+4];
ll a[200001];
ll lazy[4*200001+4];
ll mx=1e14;



void push(int ind){
int l=2*ind+1,r=2*ind+2;
t[l]+=lazy[ind];
t[r]+=lazy[ind];
lazy[l]+=lazy[ind];
lazy[r]+=lazy[ind];
lazy[ind]=0;

}

void build(int ind,int l,int r){
if(l==r){
    t[ind]=a[l];
return;
}
int mid=(l+r)/2;
build(2*ind+1,l,mid);
build(2*ind+2,mid+1,r);

  t[ind] =min(t[ind*2+1] , t[ind*2+2]);



}
ll query(int ind,int l,int r,int p,int q){

if(l>q || r<p )
    return mx;
    int mid=(l+r)/2;

if(l>=p && r<=q )
    {
      return t[ind];
    }
    push(ind);
ll x=query(2*ind+1,l,mid,p,q);
ll y=query(2*ind+2,mid+1,r,p,q);


return min(x,y);
}

void update(int ind,int l,int r,int p,int q,int val){
if(l>q || r<p )
    return;

if(l>=p && r<=q )
    {
      t[ind]+=val;
      lazy[ind]+=val;
      return;
    }
push(ind);
int mid=(l+r)/2;
    update(2*ind+1,l,mid,p,q,val);
     update(2*ind+2,mid+1,r,p,q,val);
    t[ind]=min(t[2*ind+1],t[2*ind+2]);



}


ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}
*/
ll ma=1e9+7;

ll power(ll x,ll t){
if(t<=0){
    return 1;
}
ll y=(power(x,t/2));
y=(y*y)%ma;
if(t%2)
    y=(y*x)%ma;
return y;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    ll x[n],y[n];
    rep(i,0,n)
    cin>>x[i]>>y[i];
    ll p=x[0]+y[0],q=x[0]+y[0];
    ll r=x[0]-y[0],s=x[0]-y[0];
    for(int i=0;i<n;i++){
        p=max(p,x[i]+y[i]);
         q=min(q,x[i]+y[i]);
         r=max(r,x[i]-y[i]);
         s=min(s,x[i]-y[i]);
    }
    cout<<max(p-q,r-s)<<endl;
}


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

int get_depth(vector<vector<int> >& parents, int x, map<int, int>& depth) {
  if (depth.count(x)) {
    return depth[x];
  }
  int ret = 0;
  for (int i = 0; i < parents[x].size(); i++) {
    int p = parents[x][i];
    ret = max(ret, get_depth(parents, p, depth) + 1);
  }
  depth[x] = ret;
  return ret;
}

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int> > parents(n+1);
  vector<vector<int> > children(n+1);
  for (int i = 0; i < n + m - 1; i++) {
    int a, b; cin >> a >> b;
    parents[b].push_back(a);
    children[a].push_back(b);
  }
  int root;
  for (int i = 1; i <= n; i++) {
    if (parents[i].size() == 0) {
      root = i;
    }
  }
  map<int, int> depth;
  for (int i = 1; i <= n; i++) get_depth(parents, i, depth);
  for (int i = 1; i <= n; i++) {
    int d = depth[i];
    int ans = 0;
    for (int j = 0; j < parents[i].size(); j++) {
      int p = parents[i][j];
      if (depth[i] == depth[p] + 1) {
        ans = p;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 22400
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}
template <class T1, class T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) { return in >> x.first >> x.second; }

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    out_impl(std::forward<Args>(args)...);
}
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    int a, p;
    std::cin >> a >> p;
    out((a * 3 + p) / 2);
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int cnt_N=N;
    int s=0;
    while(cnt_N){
        s+=cnt_N%10;
        cnt_N/=10;
    }
    if(N%s==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fo(i,n)   for(i=0;i<n;i++)
#define mod       1000000007
using namespace std;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("codefi.txt", "r", stdin);
	freopen("codefo.txt", "w", stdout);
#endif

	 int h,w;
    cin>>h>>w;
    if(h==1 or w==1)
    {
        cout<<1<<endl;
    }
    else
    {
      int ans=h*w;
      if(ans%2==0)
        {
            cout<<(h*w)/2<<endl;
        }
       else
       {
        cout<<((h*w)+1)/2<<endl;
       }
    }
}


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

void solve() {
    int N;
    cin >> N;
    vector<pair<ll,int>> v(N);
    for(int i=0;i<N;i++) {
        cin >> v[i].first;
        v[i].second=i;
    }
    sort(v.begin(),v.end());
    int cnt=0;
    for(int i=0;i<N;i++) {
        if((v[i].second&1) != (i&1)) cnt++;
    }
    cout << (cnt+1)/2 << "\n";
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

template <class T>
class graph {
 public:
  graph(int n) : n_(n) { data_.resize(n_); }
  struct edge {
    int from, to;
    T cost;
  };
  int n_;
  std::vector<std::vector<int>> data_;
  std::vector<edge> edges_;

  virtual void add(int from, int to, T cost) = 0;
};

template <class T>
class forest : public graph<T> {
 public:
  using graph<T>::n_;
  using graph<T>::data_;
  using graph<T>::edges_;

  forest(int n) : graph<T>(n) {}

  void add(int from, int to, T cost = 1) {
    int id = edges_.size();
    assert(id < n_ - 1);
    data_[from].emplace_back(id);
    data_[to].emplace_back(id);
    edges_.push_back({from, to, cost});
  }
};

template <class T>
class digraph : public graph<T> {
 public:
  using graph<T>::n_;
  using graph<T>::data_;
  using graph<T>::edges_;

  digraph(int n) : graph<T>(n) {}

  void add(int from, int to, T cost = 1) {
    int id = edges_.size();
    data_[from].emplace_back(id);
    edges_.push_back({from, to, cost});
  }

  digraph<T> reverse() const {
    digraph<T> rev(n_);
    for (auto& e : edges_) {
      rev.add(e.to, e.from, e.cost);
    }
    return rev;
  }
};

template <class T>
class undigraph : public graph<T> {
 public:
  using graph<T>::n_;
  using graph<T>::data_;
  using graph<T>::edges_;

  undigraph(int n) : graph<T>(n) {}

  void add(int from, int to, T cost = 1) {
    int id = edges_.size();
    data_[from].emplace_back(id);
    data_[to].emplace_back(id);
    edges_.push_back({from, to, cost});
  }
};

template <class T>
std::vector<T> bfs(const graph<T>& g, int s) {
  std::vector<T> dist(g.n_, -1);
  dist[s] = 0;
  std::queue<int> que;
  que.emplace(s);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (int id : g.data_[cur]) {
      auto& e = g.edges_[id];
      int nxt = e.from ^ e.to ^ cur;
      if (dist[nxt] != -1) continue;
      dist[nxt] = dist[cur] + e.cost;
      que.emplace(nxt);
    }
  }
  return dist;
}

template <class T>
T tree_diameter(const forest<T>& g) {
  std::vector<T> d1 = bfs(g, 0);
  std::vector<T> d2 = bfs(g, std::distance(d1.begin(), std::max_element(d1.begin(), d1.end())));
  return *std::max_element(d2.begin(), d2.end());
}

void GRL_5_A() {
  int n; cin >> n;
  forest<int> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int s, t, d; cin >> s >> t >> d;
    g.add(s, t, d);
  }
  cout << tree_diameter(g) << '\n';
}

int main() {
  GRL_5_A();
}


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

AB = []
for i in range(N):
    A, B = map(int, input().split())
    AB.append((B, A))

AB.sort()

Asum = 0
check = 0
for i in range(N):
    Asum += AB[i][1]
    if Asum > AB[i][0]:
        check = 1
        break

if check == 0:
    print('Yes')
else:
    print('No')

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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = n;
	rep(i, n-1) {
		if(s[i] != s[i+1]) ans = min(ans, max(i+1, n-i-1)); 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
cin>>n;
long long int sum=0;
for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0 && i%15!=0){
        sum+=i;
    }
}
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

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

  int ans=0;
  rep(i,1000){
    string t = to_string(i);
    while(t.size()<3) t = '0' + t;
    bool ok[3]={};
    rep(j,n){
      if(s[j]==t[0] && !ok[0]){
	ok[0]=true;
	continue;
      }
      if(s[j]==t[1] && !ok[1] && ok[0]){
	ok[1]=true;
	continue;
      }
      if(s[j]==t[2] && ok[0] && ok[1]) ok[2]=true;
    }
    if(ok[0] && ok[1] && ok[2]){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256