akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long comb[60][60] , arr[60];
int main(){
    for(ll j = 0 ; j < 60 ; j++){
        comb[j][0] =1 ;
        for(ll i = 1 ; i <= j ; i++)
            comb[j][i] = comb[j-1][i] + comb[j-1][i-1];
    }
    ll a = 0 , b = 0;
    ll n , P;
    cin>>n>>P;
    for(ll j = 1 ; j <= n ; j++){
        cin>>arr[j];
        if(arr[j]%2) b++;
        else a++;
    }
    ll theta = 0;
    if(P == 0){
        for(ll j = 0 ; j <= b ; j+=2)
            theta += comb[b][j];
    }
    else{
        for(ll j = 1 ; j <= b ; j+=2)
            theta += comb[b][j];
    }
    ll ans = theta;
    ans *= (1ll << a);
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 5;
char s[N];
vector<pair<int, int>> pa, pb;
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%s", s);
        int a = 0, b = 0;
        for(int j = 0; s[j]; j++) {
            if(s[j] == '(') a++;
            else if(a) a--;
            else b++;
        }
        if(a <= b) pa.push_back({a, b});
        else pb.push_back({a, b}); 
    }
    sort(pa.begin(), pa.end());
    sort(pb.begin(), pb.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.second > b.second;
    });
    int sum = 0;
    bool flag = true;
    for(int i = 0; i < pa.size(); i++) {
        sum -= pa[i].first;
        if(sum < 0) flag = false;
        sum += pa[i].second;
    }
    for(int i = 0; i < pb.size(); i++) {
        sum -= pb[i].first;
        if(sum < 0) flag = false;
        sum += pb[i].second;
    }
    if(sum) flag = false;
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 11188
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 100001;
const ll mod = 1e9+7;
int r,c,n;
struct point{
  int id;
  int val;
};
vector<point> v[4];
bool check(int x, int y){
  if(x == 0 || x == r || y == 0 || y == c) return true;
  return false;
}
void push(int id, int x, int y){
  if(x == 0) v[0].pb({id, y});
  else if(y == c) v[1].pb({id, x});
  else if(x == r) v[2].pb({id, y});
  else if(y == 0) v[3].pb({id, x});
}
bool cmp1(point a, point b){
  return a.val < b.val;
}
bool cmp2(point a, point b){
  return a.val > b.val;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  cin >> r >> c >> n;
  int x1,x2,y1,y2;
  for(int i = 1; i <= n; i++){
    cin >> x1 >> y1 >> x2 >> y2;
    if(check(x1,y1) && check(x2,y2))
      push(i,x1,y1),push(i,x2,y2);
  }
  sort(v[0].begin(), v[0].end(),cmp1);
  sort(v[1].begin(), v[1].end(),cmp1);
  sort(v[2].begin(), v[2].end(),cmp2);
  sort(v[3].begin(), v[3].end(),cmp2);
  stack<int> s;
  for(int j = 0; j < 4; j++)
    for(int i = 0; i < v[j].size(); i++){
    if(s.size() == 0) {s.push(v[j][i].id); continue;}
    if(s.top() == v[j][i].id) s.pop();
    else s.push(v[j][i].id);
  }

  cout << (s.empty() ? "YES" : "NO" )<< endl;
  return 0;
}

Measured memory_bytes: 2520
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize,
        n: usize
    }
    if n >= b {
        println!("{}", (b - 1) * a / b);
    } else {
        println!("{}", n * a / b);
    }
}


Measured memory_bytes: 2136
import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A[0:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  exit()
A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 *= a
    ans1 %= MOD
  print(ans1)
  exit()

A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  exit()

#while ansA>0:
#  ansA-=MOD

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]
 
if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
B1.remove(Bp[-1])
B1.append(min(B2[0],0))

ansB = 1
for a in B1[0:K]:
  ansB *= a
  ansB %= MOD

C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC *= a
  ansC %= MOD

BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2

if ansBB1==1:
  print(ansC)
  exit()
if ansBB2==1:
  print(ansB)
  exit()

if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

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

#define eb emplace_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Vi = vector<int>;

void run() {
    // long double a, b;
    ull a;
    double b;
    cin >> a >> b;
    cout << (ll) a * (ll) (b*100+0.01) / 100 << endl;
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    double st = clock();

    int t = 1;
    // cin >> t;

    while(t--) {
        run();
    }

    cerr << "\n" << "time = " << (clock() - st) / CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;

int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };



int main() {
	string s;
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	bool used[26]{};
	for (int i = 0; i < s.size(); i++) {
		used[s[i] - 'a'] = true;
	}
	for (int i = 0; i < 26; i++) {
		if (!used[i]) {
			s.push_back('a' + i);
			cout << s << endl;
			return 0;
		}
	}
	for (int i = s.size() - 1; i >= 0; i--) {
		int m = s[i] - 'a';
		used[m] = false;
		s.pop_back();
		for (int j = m + 1; j < 26; j++) {
			if (!used[j]) {
				s.push_back('a' + j);
				cout << s << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        if(n >= (a + b)){
            a = b = 0;
        }else{
            if(n <= a){
                a -= n;
            }else{
                n -= a;
                b -= n;
                a = 0;
            }
        }
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <string.h>

char s[100005];

int main() {

	scanf("%s",s);

	int len = strlen(s);

	int even;

	if (len % 2 == 0) { even = 1; }
	else { even = 0; }

	int match;

	if (s[0] == s[len - 1]) { match = 1; }
	else { match = 0; }

	if (even == 0 && match == 0) { printf("First\n"); }
	else if (even == 0 && match == 1) { printf("Second\n"); }
	else if (even == 1 && match == 0) { printf("Second\n"); }
	else { printf("First\n"); }

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int factorize(int n, int p[], int m[])
{
	int i, k;
	for (i = 2, k = 0; i * i <= n; i++) {
		if (n % i != 0) continue;
		p[k] = i;
		for (m[k] = 0; n % p[k] == 0; m[k]++, n /= p[k]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

int main()
{	
	int N, M;
	scanf("%d %d", &N, &M);
	if (N == 1 || M == 1) {
		printf("1\n");
		fflush(stdout);
		return 0;
	}

	int k, p[100], m[100];
	k = factorize(M, p, m);
	
	int h, i, j, l, n, bit[100];
	for (i = 1, n = 0, bit[0] = 1; i <= k; i++) {
		n += m[i-1];
		bit[i] = bit[i-1] * (m[i-1] + 1);
	}
	if (n > N) n = N;
	long long dp[50][2000] = {};
	for (i = 1, dp[0][0] = 1; i <= n; i++) {
		for (j = bit[k] - 1; j > 0; j--) {
			for (l = j - 1; l >= 0; l--) {
				for (h = 0; h < k; h++) if (j % bit[h+1] / bit[h] < l % bit[h+1] / bit[h]) break;
				if (h >= k) dp[i][j] += dp[i-1][l];
			}
			dp[i][j] %= Mod;
		}
	}
	
	long long ans = 0, fact[100001], fact_inv[100001];
	for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	for (i = 1; i <= n; i++) ans = (ans + dp[i][bit[k]-1] * fact_inv[i] % Mod * fact_inv[N-i]) % Mod;
	printf("%lld\n", ans * fact[N] % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4084
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
int a[103];
int main(){
	int n,m,x,c=0,b=0,ans;
	cin>>n>>m>>x;
	for (int i=0;i<m;i++){
	  cin>>a[i];
	  if (a[i]<x) c++;
	  if (a[i]>x) b++;
}
	ans=min(c,b);
	cout<<ans;
	system ("pause");
	return 0;
}

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

int INF = 1e9;

int N;
vector<vector<int>> S;
vector<int> color;

bool dfs(int v, int c) {
  color[v] = c;
  for (int u = 0; u < N; u++) {
    if (S[v][u] == 1) {
      if (color[u] == -1) {
        if (!dfs(u, 1 - c)) {
          return false;
        }
      } else if (color[u] == 1 - c) {
        continue;
      } else {
        return false;
      }
    }
  }
  return true;
}

int main() {
  cin >> N;
  S.assign(N, vector<int>(N));
  color.assign(N, -1);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < N; j++) {
      S[i][j] = s[j] - '0';
    }
  }
  if (!dfs(0, 0)) {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i != j && S[i][j] == 0) {
        S[i][j] = INF;
      }
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        S[i][j] = min(S[i][j], S[i][k] + S[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (S[i][j] != INF) {
        ans = max(ans, S[i][j]);
      }
    }
  }

  cout << ans + 1 << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    vector< P > res;

    if( n % 2 == 0 ) {
        for( int i = 1; i < n; ++i ) {
            for( int j = i + 1; j <= n; ++j ) {
                if( i + j != n + 1 ) {
                    res.pb(MP(i, j));

                }
            }
        }
    } else {
        for( int i = 1; i < n; ++i ) {
            for( int j = i + 1; j <= n; ++j ) {
                if( i + j != n ) {
                    res.pb(MP(i, j));

                }
            }
        }
    }

    cout << res.size() << endl;
    for( int i = 0; i < res.size(); ++i ) {
        cout << res[i].F << " " << res[i].S << endl;

    }
    return 0;
}



Measured memory_bytes: 384
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int t[n], v[n];
    for (int i = 0; i < n; i++) cin >> t[i];
    for (int i = 0; i < n; i++) cin >> v[i];
    int dp[2][101] = {}, cur = 0, prev = 1;
    const int INF = 1<<30;
    fill(dp[prev]+1, dp[prev]+101, -INF);
    for (int i = 0; i < n; i++) {
        int vmax= v[i];
        while (t[i]--) {
            for (int v = 0; v <= 100; v++) {
                int temp = -INF;
                if (v < vmax) temp = dp[prev][v] + 4 * v + 1;
                if (v <= vmax && v > 0)
                    temp = max(temp, dp[prev][v-1] + 4 * v - 2);
                if (v < vmax && v < 100)
                    temp = max(temp, dp[prev][v+1] + 4 * v + 2);
                if (v <= vmax)
                    temp = max(temp, dp[prev][v] + 4 * v);
                dp[cur][v] = temp;
            }
            swap(cur, prev);
        }
    }
    cout << setprecision(12) << dp[prev][0] * 0.25 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	string s1,s2;
	cin>>s1>>s2;
	s1+=s1.substr(0,s1.size()-1);
	if(s1.find(s2)==string::npos)
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for(int i=0;i<n;++i){
        int z;
        scanf("%d", &z);
        z--;
        v.push_back(z);
    }
    int now=0, c=0;
    for(;;){
        if(now==1){
            printf("%d\n",c);
            break;
        }
        if(c>=n){
            printf("-1\n");
            break;
        }
        c++;
        now = v[now];
    }
    }

Measured memory_bytes: 892
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N;
long long sum [10000010], ret = 0;

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N;
    for(int i = 1; i <= N; i++)
        for(int j = i; j <= N; j += i)
            sum[j]++;
    for(int i = 1; i <= N; i++) ret += (long long)i*sum[i];
    cout << ret << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 81720
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int m, n;
        cin >> m >> n;
        if(m == 0)
            return 0;

        queue<pair<int, int> > t;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            t.push(make_pair(i+1, a));
        }

        vector<vector<int> > car(2, vector<int>(m, -1));
        vector<vector<int> > rest(2, vector<int>(m));

        int next = 0;
        queue<pair<int, int> > wait;
        vector<int> ret;
        while(ret.size() < n){
            if(next == 0 && !t.empty()){
                wait.push(t.front());
                t.pop();
                next = 10;
            }
            -- next;

            for(int i=0; i<2; ++i){
                for(int j=0; j<m; ++j){
                    if(car[i][j] != -1)
                        -- rest[i][j];
                }
            }

            for(int j=0; j<m; ++j){
                if(car[0][j] != -1 && rest[0][j] <= 0){
                    ret.push_back(car[0][j]);
                    car[0][j] = -1;
                }
                if(car[0][j] == -1 && car[1][j] != -1 && rest[1][j] <= 0){
                    ret.push_back(car[1][j]);
                    car[1][j] = -1;
                }
            }

            while(!wait.empty()){
                bool ok = false;
                for(int i=0; i<m; ++i){
                    if(car[1][i] == -1){
                        car[1][i] = wait.front().first;
                        rest[1][i] = wait.front().second;
                        wait.pop();
                        ok = true;
                        break;
                    }
                }
                if(ok)
                    continue;

                int k = -1;
                for(int i=0; i<m; ++i){
                    if(car[0][i] == -1 && rest[1][i] >= wait.front().second && (k == -1 || rest[1][i] < rest[1][k]))
                        k = i;
                }

                if(k == -1){
                    for(int i=0; i<m; ++i){
                        if(car[0][i] == -1 && (k == -1 || (rest[1][i] > rest[1][k])))
                            k = i;
                    }
                }

                if(k == -1)
                    break;
                car[0][k] = wait.front().first;
                rest[0][k] = wait.front().second;
                wait.pop();
            }
        }

        cout << ret[0];
        for(int i=1; i<n; ++i)
            cout << ' ' << ret[i];
        cout << endl;
    }
}

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

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

	if (a < b) {
		rep(i, b) cout << a;
		cout << endl;
	}
	else {
		rep(i, a) cout << b;
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)	
#define REP(i,b) FOR(i,0,b)
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
using pi=pair<int,int>;
const int inf=LLONG_MAX/3;
void chmin(int&a,int b){
	a=a<b?a:b;
}
void chmax(int&a,int b){
	a=a>b?a:b;
}

signed main(){
	int x=read(),y=read(),z=read(),n=x+y+z,ans=0;
	vector<pi> d(n);
	REP(i,n){
		int a=read(),b=read(),c=read();
		ans+=c;
		d[i]=pi(a-c,b-c);
	}
	sort(ALL(d),[](pi a,pi b){
		return a.first-a.second>b.first-b.second;
	});
	vi w(n,0);
	{
		priority_queue<int,vi,greater<int>> pq;
		int t=0;
		REP(i,n){
			w[i]+=t;
			t+=d[i].first;
			pq.push(d[i].first);
			if(int(pq.size())>x){
				int s=pq.top();pq.pop();
				t-=s;
			}
		}
	}
	{
		priority_queue<int,vi,greater<int>> pq;
		int t=0;
		for(int i=n-1;i>=0;i--){
			t+=d[i].second;
			pq.push(d[i].second);
			if(int(pq.size())>y){
				int s=pq.top();pq.pop();
				t-=s;
			}
			w[i]+=t;
		}
	}
	int h=-inf;
	FOR(i,x,n-y+1)
		chmax(h,w[i]);
	cout<<ans+h<<endl;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#include<stdio.h>
#include<math.h>
typedef long long ll;
using namespace std;
ll sz=1000009;
ll vis[1000005]={0};
ll prime[1000005];
ll digitprime[10000000];

void sieve()
{
    ll k=sqrt(sz),i,j,m=0,ans,ans1;
    for(i=2;i<=k;i++)
    {
        if(vis[i]==0)
        {
            for(j=i*i;j<=sz;j+=i)
            {
                vis[j]=1;
            }
        }
    }
    vis[1]=1;
    	for(i=2;i<=sz;i++){
        if(vis[i]==0){
            prime[m]=i;
            m++;
        }
	}

}
ll numdpf(ll n){
 ll ind=0,pf=prime[ind],ans=0;
 while(pf*pf<=n){
       if(n%pf==0) ans++;
    while(n%pf==0){n=n/pf;}
    pf=prime[++ind];
 }
 if(n!=1)ans++;
 return ans;
}

int main()
{
    ll j,x,b,i,t,n,flag;
       sieve();
      scanf("%lld%lld",&n,&x);
      ll ans=__gcd(n,x);
      ll res=numdpf(ans);
      cout<<res+1<<endl;
      return 0;
 }


Measured memory_bytes: 12160
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    sum += A[i];
    sum %= mod;
  }
  ll ans = 0;
  for(int i=0; i<N; i++){
    sum -= A[i];
    sum += mod;
    sum %= mod;
    ans += sum*A[i];
    ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}


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

constexpr unsigned long long MOD = 1000000;

template<class container>
void multiply(const container& matrix, vector<unsigned long long>& vec){
    int n = vec.size();
    assert(n == end(matrix) - begin(matrix));
    vector<unsigned long long> ret(n);
    for(int i = 0; i < n; ++i){
        ret[i] = inner_product(vec.begin(), vec.end(), matrix[i], 0ULL) % MOD;
    }
    copy(ret.begin(), ret.end(), vec.begin());
}

int main(){
    long long N, M;
    cin >> N >> M;
    if(N < M)swap(N, M);
    if(M == 1){
        unsigned long long ans;
        if(N >= 68){
            N -= 68;
            ans = 825856;
        }else if(N >= 34){
            N -= 34;
            ans = 869184;
        }else{
            ans = 1;
        }
        cout << (ans << N) % MOD << endl;
    }else{
        constexpr unsigned long long mats[7][5][5] = {{{1, 1, 1, 0, 1}, {1, 1, 1, 0, 0}, {1, 1, 1, 1, 0}, {1, 0, 0, 1, 0}, {0, 0, 1, 0, 1}}, {{3, 3, 4, 1, 2}, {3, 3, 3, 1, 1}, {4, 3, 3, 2, 1}, {2, 1, 1, 1, 1}, {1, 1, 2, 1, 1}}, {{38, 33, 38, 17, 16}, {33, 29, 33, 14, 14}, {38, 33, 38, 16, 17}, {16, 14, 17, 7, 8}, {17, 14, 16, 8, 7}}, {{4521, 3927, 4522, 1963, 1964}, {3927, 3411, 3927, 1705, 1705}, {4522, 3927, 4521, 1964, 1963}, {1964, 1705, 1963, 853, 853}, {1963, 1705, 1964, 853, 853}}, {{19918, 602393, 19918, 801197, 801196}, {602393, 291629, 602393, 145814, 145814}, {19918, 602393, 19918, 801196, 801197}, {801196, 145814, 801197, 72907, 72908}, {801197, 145814, 801196, 72908, 72907}}, {{443121, 528647, 443122, 264323, 264324}, {528647, 571731, 528647, 785865, 785865}, {443122, 528647, 443121, 264324, 264323}, {264324, 785865, 264323, 392933, 392933}, {264323, 785865, 264324, 392933, 392933}}, {{803438, 755833, 803438, 877917, 877916}, {755833, 234029, 755833, 617014, 617014}, {803438, 755833, 803438, 877916, 877917}, {877916, 617014, 877917, 308507, 308508}, {877917, 617014, 877916, 308508, 308507}}};
        vector<unsigned long long> ans({1, 1, 1, 1, 0});
        for(int i = 0; i < 7; ++i){
            if((N >> i) & 1){
                multiply(mats[i], ans);
            }
        }
        cout << ans[2] << endl;
    }
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define INF 900000000

using namespace std;

int main()
{
	int a,b,c;
	
	cin>>a>>b>>c;
	
	if(a<=b&&b<=c)cout<<a<<" "<<b<<" "<<c<<endl;
	else if(a<=c&&c<=b)cout<<a<<" "<<c<<" "<<b<<endl;
	else if(b<=c&&c<=a)cout<<b<<" "<<c<<" "<<a<<endl;
	else if(b<=a&&a<=c)cout<<b<<" "<<a<<" "<<c<<endl;
    else if(c<=a&&a<=b)cout<<c<<" "<<a<<" "<<b<<endl;
	else if(c<=b&&b<=a)cout<<c<<" "<<b<<" "<<a<<endl;
	 return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main( void )
{
	int a;
	char t;
	string b;

	vector <int> result( 4, 0 );

	while ( cin >> a >> t >> b )
	{
		if ( b == "A" )
			result[0]++;
		else if ( b == "B" )
			result[1]++;
		else if ( b == "AB" )
			result[2]++;
		else if ( b == "O" )
			result[3]++;
	}

	for ( int i = 0; i < 4; i++ )
	{
		cout << result[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <queue>

template <class T>
constexpr T inf=(T(1)<<(8*sizeof(T)-3));

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;

  Edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const Edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
using Graph=std::vector<std::vector<Edge<Weight>>>;

template <class Weight>
bool is_bipartite_component(
    const Graph<Weight> &g, size_t i, std::vector<int> &color) {

  color[i] = 1;
  std::queue<size_t> q;
  q.emplace(i);
  while (!q.empty()) {
    size_t v=q.front();
    q.pop();
    for (const auto &e: g[v]) {
      if (color[v] == color[e.dst]) return false;
      if (color[e.dst]) continue;
      color[e.dst] = -color[v];
      q.emplace(e.dst);
    }
  }
  return true;
};

template <class Weight>
bool is_bipartite(const Graph<Weight> &g, std::vector<int> &color) {
  for (size_t i=0; i<g.size(); ++i)
    if (!color[i] && !is_bipartite_component(g, i, color))
      return false;

  return true;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  Graph<int> g(N);
  for (size_t i=0; i<M; ++i) {
    size_t A, B;
    scanf("%zu %zu", &A, &B);
    --A;
    --B;

    g[A].emplace_back(A, B);
    g[B].emplace_back(B, A);
  }

  std::vector<int> color(N);
  if (is_bipartite(g, color)) {
    size_t B=std::count(color.begin(), color.end(), 1);
    printf("%zu\n", B*(N-B)-M);
  } else {
    printf("%zu\n", N*(N-1)/2-M);
  }
}



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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> cnt(26);
  for (char c : s) {
    ++cnt[c - 'a'];
  }
  int res = 1;
  const int md = 1e9 + 7;
  for (int i = 0; i < 26; i++) {
    res = (long long) res * (cnt[i] + 1) % md;
  }
  cout << (res + md - 1) % md << '\n';
  return 0;
}

Measured memory_bytes: 3720
n, x = map(int, input().split())
ls = list(map(int, input().split()))
bounds = [0]
count = 0

for i in range(1, n+1):
    bounds.append(bounds[i-1] + ls[i-1])

#print(bounds)

for i in range(len(bounds)):
    if bounds[i] <= x:
        count += 1
    else:
        break

print(count)

Measured memory_bytes: 3064
import math
cnt = int(input())
data  = list(map(int, input().strip().split()))

avr = int(math.floor(sum(data)/2))
i = 0
sum_ = 0
while sum_ < avr:
    sum_ += data[i]
    i += 1
i = i - 1

left = sum(data[i+1:])
right = sum(data[i+1:])

#if left - right

'''
print("---")
print(i)
print(left)
print(right)
'''
diff = sum(data[:i+1]) - sum(data[i+1:])
diff = abs(diff)
diff2 = sum(data[:i]) - sum(data[i:])
diff2 = abs(diff2)
#print("diff:"+ str(diff))
#print("diff2:"+ str(diff2))
if diff < diff2:
    print(diff)
else:
    print(diff2)

Measured memory_bytes: 27300
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int m = sc.nextInt();
			int n = sc.nextInt();
			if(n>m){
				int l = m;
				m=n;
				n=l;
			}
			int a = m;
			int b = n;			
			while(n!=0){
				int l = n;
				n = m%n;
				m = l;
			}
			System.out.println(m);
		}
	
	}	
}

Measured memory_bytes: 17204
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int a[N];

signed main(){
    IOS;
    int n;
    cin >> n;
    int prev = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] == prev + 1) {
            prev = a[i];
            ans++;
        }
    }
    if (ans == 0) cout << -1 << endl;
    else cout << n - ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	double p,me,syu,r;
	scanf("%lf",&r);
	p=3.14159265358979;
	
	
	me=r*r*p;
	syu=2*r*p;
	printf("%1f %1f\n",me,syu);
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  map<char,ll>m;
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    m[s[0]]++;
  }
  string S="MARCH";
  ll ans=0;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      for(int k=j+1;k<5;k++){
        ans+=m[S[i]]*m[S[j]]*m[S[k]];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[[int(i) for i in input().split()] for _ in range(n)]

dp=[0,0,0]
for i in range(n):
    nextdp=[]
    for j in range(3):
        x=dp[j+1:]+dp[:j]
        nextdp.append(max(x)+l[i][j])
    dp=nextdp

print(max(dp))    


Measured memory_bytes: 90068
#include <atcoder/lazysegtree>

#include <cstdio>

using ll = long long;

struct S { int c0, c1; ll inversion; };
struct F { bool flip; };
S op(S a, S b) { return S{a.c0 + b.c0, a.c1 + b.c1, a.inversion + b.inversion + (ll)a.c1 * b.c0}; }
S e() { return S{0, 0, 0}; }
S mapping(F f, S x) {
	if (!f.flip) return x;
	int sum = x.c0 + x.c1;
	ll ni = (ll)sum * (sum - 1) / 2;
	ni -= x.inversion; // 1 0
	ni -= (ll)x.c1 * (x.c1 - 1) / 2; // 1 1
	ni -= (ll)x.c0 * (x.c0 - 1) / 2; // 0 0
	// ni = 0 1
	return S{x.c1, x.c0, ni};
}
F composition(F f, F g) { return F{f.flip ^ g.flip}; }
F id() { return F{false}; }

int main() {
	int N, Q;
	scanf("%d %d", &N, &Q);
	std::vector<S> A(N);
	for (int i = 0; i < N; ++i) {
		int a;
		scanf("%d", &a);
		A[i] = S{a == 0, a == 1, 0};
	}
	atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
	
	while (Q--) {
		int t, l, r;
		scanf("%d %d %d", &t, &l, &r);
		if (t == 1) seg.apply(l - 1, r, F{true});
		else printf("%lld\n", seg.prod(l - 1, r).inversion);
	}
}

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

using namespace std;

// 10進数⇒base進数, digit桁目を取得(0桁目~) 計算量O(N)
template <typename type>
type BaseChange(type num, type base, type digit)
{
    for(type i=0;i<digit;i++) num/=base;        
    return num%base;
}

int main()
{
    int n;
    cin >> n;
    vector<int> c(n),v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    for(int i=0;i<n;i++) cin >> c[i];

    int ans=-1;
    for(int i=0;i<(1<<n);i++){
        int x=0,y=0;
        for(int j=0;j<n;j++){
            if(BaseChange(i,2,j)){
                x+=v[j];
                y+=c[j];
            }
        }
        ans=max(ans,x-y);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func main() {
	var A, B, C, X, Y int
	fmt.Scan(&A, &B, &C, &X, &Y)

	ans := intMin(A+B, 2*C) * intMin(X, Y)
	if X > Y {
		ans += intMin(2*C, A) * (X - Y)
	} else {
		ans += intMin(2*C, B) * (Y - X)
	}
	fmt.Println(ans)
}


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

int main(){
    int a_0, a_1, a_2;
    cin >> a_0 >> a_1 >> a_2;
    if( (a_0 + a_1 + a_2) >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}


Measured memory_bytes: 256
from math import ceil


def get_required_time(trains, station_num, station):
    arrival = [0] * station_num
    for i in range(station, station_num):
        if arrival[i - 1] < trains[i - 1][1]:
            arrival[i] = trains[i - 1][0] + trains[i - 1][1]
        else:
            arrival[i] = trains[i - 1][0] + trains[i - 1][2] * ceil(arrival[i - 1] / trains[i - 1][2])
    return arrival


def main():
    station_num = int(input())
    trains = [list(map(int, input().split())) for _ in range(station_num - 1)]
    for i in range(1, station_num):
        print(get_required_time(trains, station_num, i)[-1])
    print(0)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)

    def list(self):
        return self.__q

    def length(self):
        return len(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    B = [0] * N
    for i in reversed(range(1, N+1)):
        now = 0
        j = i
        while j <= N:
            if B[j - 1] == 1:
                now += 1
            j += i
        if now % 2 != A[i - 1]:
            B[i - 1] = 1
    print(B.count(1))
    for i in range(N):
        if B[i] == 1:
            print(i + 1)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 63632
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
#define int ll
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=1000002;
vi adj[N],eul;
int tmx=0;
int in[N],out[N];

void dfs(int u,int p){
	in[u]=tmx++;
	for(auto i:adj[u]){
		if(i!=p){
			dfs(i,u);
		}
	}
	out[u]=tmx;
}
int st[4*N];
void update(int v,int tl,int tr,int l,int r,int val){
	if(l>r||tl>tr)return;
	if(l<=tl&&tr<=r){
		st[v]+=val;
		return;
	}
	int mid=(tl+tr)/2;
	update(2*v,tl,mid,l,min(r,mid),val);
	update(2*v+1,mid+1,tr,max(l,mid+1),r,val);
	//~ st[v]=st[2*v]+st[2*v+1];
}
int get(int v,int tl,int tr,int ind){
	if(tl==tr)return st[v];
	if(ind<=(tl+tr)/2){
		return st[v]+get(2*v,tl,(tl+tr)/2,ind);
	}
	else{
		return st[v]+get(2*v+1,(tl+tr)/2+1,tr,ind);
	}
}
void solve(){
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(0,-1);
	while(q--){
		int p,x;
		cin>>p>>x;
		p--;
		update(1,0,n-1,in[p],out[p]-1,x);
	}
	for(int i=0;i<n;i++)
	cout<<get(1,0,n-1,in[i])<<' ';
	
}

 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;
}


Measured memory_bytes: 55424
using System;

public class Hello
{
	public static void Main()
	{
		var s = Console.ReadLine().Trim();
		var a = s.ToCharArray();
		Array.Sort(a);
		Console.WriteLine(a[0] == a[1] && a[2] == a[3] && a[1] != a[2] ? "Yes" : "No");
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  if(a.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

using namespace std;

int main(){
    int n, k;

    cin >> n >> k;

    vector<int> h(n) ;

    int c =0;

    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(k <= h[i]){
            c++;
        }
    }

    cout << c << endl;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N; cin >> N;
    for(int i=1;i<=N;i++){
        double tmp=i*1.08;
        if(tmp>=N&&tmp<N+1){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        int count = 0;
        for(int i = 0; i < n; i++){
            int minj = i;
            for(int j = i; j < n; j++){
                if(a[j] < a[minj]){
                    minj = j;
                }
            }
            if(minj != i){
                int x = a[minj];
                a[minj] = a[i];
                a[i] = x;
                count++;
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            sb.append(a[i]).append(" ");
        }
        sb.deleteCharAt(sb.length()-1);
        sb.append(System.lineSeparator());
        sb.append(count);
        
        System.out.println(sb);
    }
}


Measured memory_bytes: 26216
#include <stdio.h>

int N, M, A, B;
int D[1024];

int main(void) {
	int i;
	int count = 0;

	if (scanf("%d%d%d%d", &N, &M, &A, &B) != 4) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &D[i]) != 1) return 1;
	}

	for (i = 0; i < N; i++) {
		if (D[i] >= A) {
			count++;
		} else {
			break;
		}
	}

	if (N - count < M) {
		while (count > 0) {
			if (D[count - 1] <= B) count--; else break;
		}
	}

	printf("%d\n", count);
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;





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

    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;

    rep(i,ty-sy){
        cout <<'U';
    }
    rep(i,tx-sx){
        cout << 'R';
    }
    rep(i,ty-sy){
        cout <<'D';
    }
    rep(i,tx-sx){
        cout <<'L';
    }
    cout << 'L';
    rep(i,ty-sy+1){
        cout <<'U';
    }
    rep(i,tx-sx+1){
        cout << 'R';
    }
    cout <<"DR";
    rep(i,ty-sy+1){
        cout <<'D';
    }
    rep(i,tx-sx+1){
        cout <<'L';
    }
    cout <<'U'<<endl;;



}


Measured memory_bytes: 256