akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

void modsum(ll &a,ll b,ll m){
  a+=b;
  a%=m;
}

void modsub(ll &a,ll b,ll m){
  a-=b;
  a+=m;
  a%=m;
}

void modmul(ll &a,ll b,ll m){
  a*=b;
  a%=m;
}

void modquo(ll &a,ll b,ll m){
  a*=modinv(b,m);
  a%=m;
}

int main(){

  ll n,p;
  string s;
  cin >> n >> p >> s;

  ll ans=0;

  if(p==2){
    for(ll i=n-1;i>=0;i--){
      if(ctoi(s[i])&1);
      else ans+=i+1;
    }
  }
  else if(p==5){
    for(ll i=n-1;i>=0;i--){
      if(ctoi(s[i])%5!=0);
      else ans+=i+1;
    }
  }
  else{
    vec a(n+1);
    ll d=1;
    for(ll i=0;i<n;i++){
      ll b=ctoi(s[n-1-i]);
      if(i!=0)d=(d*10)%p;
      a[i+1]=a[i]+d*b%p;
      a[i+1]%=p;
    }

    vec b=a,c=a;
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    c.erase(unique(c.begin(),c.end()),c.end());
    for(ll i=0;i<c.size();i++){
      ll e=upper_bound(b.begin(),b.end(),c[i])-lower_bound(b.begin(),b.end(),c[i]);
      ans+=e*(e-1)/2;
    }
  }
  

  cout << ans << endl;

}

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

const ll INF = 1e25;

struct edge{
	int to;
	ll A, B;
	edge(int v, ll a, ll b) : to(v), A(a), B(b) {}
};

struct djk {
	ll time;
	int v;
	djk(ll t, int i) : time(t), v(i) {}
	bool operator>(const djk& that) const {
		return time > that.time;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M, s, g;
	cin >> N >> M >> s >> g; --s, --g;
	vector<vector<edge>> G(N);
	for (int i = 0; i < M; i++) {
		int U, V;
		long long A, B;
		cin >> U >> V >> A >> B; --U, --V;
		G[U].emplace_back(V, A, B);
		G[V].emplace_back(U, A, B);
	}
	vector<ll> d(N, INF);
	priority_queue<djk, vector<djk>, greater<djk>> pq;
	pq.emplace(0, s);
	while (!pq.empty()) {
		auto p = pq.top(); pq.pop();
		int v = p.v;
		if (d[v] != INF) continue;
		d[v] = p.time;
		for (auto& e : G[v]) if (d[e.to] == INF) {
			if ((d[v] + e.A) <= e.B / (d[v] + e.A)) {
				ll t = sqrt((long long)e.B) - e.A;
				ll cost = INF;
				for (ll time = max(d[v], t - 2); time <= t + 2; time++) {
					cost = min(cost, time + (e.B + time + e.A - 1) / (time + e.A));
				}
				pq.emplace(cost, e.to);
			}
			else {
				pq.emplace(d[v] + (e.B + p.time + e.A - 1) / (p.time + e.A), e.to);
			}
		}
	}
	if (d[g] == INF) {
		cout << -1 << endl;
		return 0;
	}
	if (d[g] == 0) {
		cout << 0 << endl;
		return 0;
	}
	string S;
	while (d[g]) {
		S.push_back((int)(d[g] % 10) + '0');
		d[g] /= 10;
	}
	reverse(S.begin(), S.end());
	cout << S << endl;
	return 0;
}



Measured memory_bytes: 45492
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

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

fn main() {
    input! {
    s:Chars
    }

    let mut zerocnt = 0;
    let mut onecnt = 0;
    for i in 0..s.len() {
        if i % 2 == 1 {
            if s[i] == '0' {
                zerocnt += 1;
            } else {
                onecnt += 1;
            }
        } else {
            if s[i] == '0' {
                onecnt += 1;
            } else {
                zerocnt += 1;
            }
        }
    }

    println!("{}", min!(zerocnt, onecnt));
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  string S, T;
  int q;
  cin >> S >> T >> q;

  vector<int> SA(S.length() + 1, 0);
  vector<int> TA(T.length() + 1, 0);
  REP(i,S.length()) SA[i + 1] = SA[i] + (S[i] == 'A');
  REP(i,T.length()) TA[i + 1] = TA[i] + (T[i] == 'A');

  REP(i,q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a; --b; --c; --d;
    //int s = (SA[b + 1] - SA[a]) - (b - a + 1 - SA[b + 1] + SA[a]);
    //cout << SA[b + 1] - SA[a] << " ";
    //cout << b - a + 1 - SA[b + 1] + SA[a] << endl;
    int s = 2 * SA[b + 1] - 2 * SA[a] - b + a - 1;
    int t = 2 * TA[d + 1] - 2 * TA[c] - d + c - 1;
    int tmp = (s % 3) - (t % 3);
    while(tmp < 0) tmp += 3;
    if(tmp % 3 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC");
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 21;
const int dx[] = { 1,-1,0,0 };
const int dy[] = { 0,0,-1,1 };
char B[maxn][maxn]; int h,w;

int bfs(const int x, const int y)
{
    int dist[maxn][maxn];
    FOR(i,0,maxn) FOR(j,0,maxn)
        dist[i][j] = inf;
    dist[x][y] = 0;
    queue<int> Q; Q.push(x); Q.push(y);
    while (Q.size()) {
        const int i = Q.front(); Q.pop();
        const int j = Q.front(); Q.pop();
        FOR(k,0,4) {
            const int ii = i+dx[k];
            const int jj = j+dy[k];
            if (0 <= ii && ii < h && 0 <= jj && jj < w) {
                if (B[ii][jj] == '.') {
                    const int d = dist[i][j] + 1;
                    if (dist[ii][jj] > d) {
                        dist[ii][jj] = d;
                        Q.push(ii); Q.push(jj);
                    }
                }
            }
        }
    }
    int ans = 0;
    FOR(i,0,h) FOR(j,0,w) if (B[i][j] == '.')
        ans = max(ans,dist[i][j]);
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> h >> w) {
        FOR(i,0,h) FOR(j,0,w)
            cin >> B[i][j];
        int ans = 0;
        FOR(i,0,h) FOR(j,0,w) if (B[i][j] == '.')
            ans = max(ans,bfs(i,j));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

//bit全探索
vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> skill(n, vector<int>(m));

    vector<int> bad(m);
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> skill[i][j];
            bad[j] += skill[i][j];
        }
    }
    bool ok = true;
    rep(j, m)if(bad[j] < x)ok = false;
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    int res = INF;
    for(int bit = 0; bit < (1 << n); bit++){
        vector<int> S = bitSearch(bit, n);
        if(S.empty())continue;
        vector<int> sum(m, 0);
        int cost = 0;

        for(int i : S){
            cost += c[i];
            rep(j, m){
                sum[j] += skill[i][j];
            }
        }
        bool f = true;
        rep(i, m){
            if(sum[i] < x)f = false;
        }
        if(f){
            res = min(res, cost);
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 3196
data class Edge(val to: Int, val id: Int)
fun main(args: Array<String>) {
    val N = nextInt()
    val G = Array(N) { mutableListOf<Edge>() }
    val ans = IntArray(N - 1)
    repeat(N - 1) {
        val (a, b) = listOfInt(-1)
        G[a].add(Edge(b, it))
        G[b].add(Edge(a, it))
    }
    tailrec fun dfs(v: Int, c: Int = -1, p: Int = -1) {
        var k = 1
        for (e in G[v]) {
            val u = e.to
            val ei = e.id
            if (u == p) continue
            if (k == c) k++
            ans[ei] = k++
            dfs(u, ans[ei], v)
        }
    }
    dfs(0)
    val max = G.map { it.size }.max()!!
    println(max)
    ans.forEach { println(it) }
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun printErr(value: Any) = System.err.println(value)


Measured memory_bytes: 82612
#include<iostream>
using namespace std;
int main(){
    int lst[4][13];
    int n;
    cin>>n;
    for(int a=0;a<4;a++){
        for(int b=0;b<13;b++){
            lst[a][b]=b+1;
        }
    }
    for(int c=0;c<n;c++){
        char mark;
        cin>>mark;
        if (mark=='S'){
            int number;
            cin>>number;
            for (int d=0;d<13;d++){
                if(lst[0][d]==number) lst[0][d]=0;
            }
        }if (mark=='H'){
            int number;
            cin>>number;
            for (int d=0;d<13;d++){
                if(lst[1][d]==number) lst[1][d]=0;
            }
        }if (mark=='C'){
            int number;
            cin>>number;
            for (int d=0;d<13;d++){
                if(lst[2][d]==number) lst[2][d]=0;
            }
        }if (mark=='D'){
            int number;
            cin>>number;
            for (int d=0;d<13;d++){
                if(lst[3][d]==number) lst[3][d]=0;
            }
        }
    }
    for(int e=0;e<13;e++){
        if (lst[0][e]!=0) cout<<"S "<<lst[0][e]<<endl;
    }for(int f=0;f<13;f++){
        if (lst[1][f]!=0) cout<<"H "<<lst[1][f]<<endl;
    }for(int g=0;g<13;g++){
        if (lst[2][g]!=0) cout<<"C "<<lst[2][g]<<endl;
    }for(int h=0;h<13;h++){
        if (lst[3][h]!=0) cout<<"D "<<lst[3][h]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>

int main (void){

    int N,i,count=0;
    int X;
    int L[101];
    int D[101];
    
    scanf("%d %d",&N,&X);

    for(i=0;i<N;i++){
        scanf("%d ",&L[i]);
    }

    
    for(i=0;i<=N;i++){
        if(i==0){
            D[0]=0;
        }else{
            D[i]=D[i-1]+L[i-1];
        }

        if(D[i]<=X){
            count++;
        }
    }

    printf("%d",count);

    return 0 ;

}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N;
  cin >> N;
  vec<ll> L(N), R(N);

  ll l, accl = 0;
  REP(i, N) {
    cin >> l;
    accl += l;
    L[i] = accl;
  }

  ll accr = 0;
  vec<ll> tmp(N);
  REP(i, N) cin >> tmp[i];
  reverse(ALL(tmp));
  REP(i, N) {
    accr += tmp[i];
    R[i] = accr;
  }
  reverse(ALL(R));

  ll answer = 0;
  REP(i, N) { answer = max(answer, L[i] + R[i]); }
  cout << answer << endl;
  return 0;
}


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

int main()
{
    int n;
    int p[20] = {0};
    std::cin >> n;
    for (int i = 0; i < n; i++) { std::cin >> p[i]; }

    int cnt = 0;

    for (int i = 1; i < n - 1; i++){
        int pi = p[i];
        int temp[] = {p[i-1], p[i], p[i+1]};

        std::sort(temp, temp+3);

        if(temp[1] == pi){ cnt++; } 
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define ll long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define mod(n) (n) % 1000000007
#define sp << " "
#define precision(n) cout << fixed << setprecision(n);
#define startTime time_t start, end;time(&start);
#define endTime time(&end);double tt = double(end-start);cout<<"Time taken : "<<fixed<<tt<<setprecision(5);cout <<" sec"<< endl;
 
using namespace std;
 
int main() { 
    IOS;
    ll x, k, d;
    cin >> x >> k >> d;
    if ((double)x / d <= -k) {
    	cout << abs(x + k * d) << endl;
    } else {
    	double inx = (double) x / (2 * d) + (double) k / 2;
    	if (inx >= k) {
    		cout << abs(x - k * d) << endl;
    	} else {
    		ll in = inx;
    		ll in1 = (in + 1 <= k)? in + 1: in;
    		ll in2 = (in - 1 >= 0)? in - 1: in;
    		ll v1 = abs(x + d * (k - 2 * in));
    		ll v2 = abs(x + d * (k - 2 * in1));
    		ll v3 = abs(x + d * (k - 2 * in2));
    		cout << min(v1, min(v1, v2)) << endl;
    	}
    }
}

Measured memory_bytes: 3640
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;
int main(){
    int a,b,c,x,ans=0;
    cin >> a >> b >> c >> x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50 == x){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
    
}

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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 1e5 + 10;

int n, rt, dp[maxn];
vector<int> g[maxn];

int dfs(int u, int p = 0) {
	int f = 0;
	for (int &v: g[u]) {
		if(v != p) {
			int t = dfs(v, u);
			if(t) {
				dp[u] += t;
			}
			else {
				dp[u] += f;
				f = 1;
			}
		}
	}
	return dp[u];
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		++u;
		++v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; ++i) {
		if(g[i].size() > 2) {
			rt = i;
			break;
		}
	}
	if(!rt) {
		puts("1");
		return 0;
	}
	printf("%d\n", dfs(rt));
	return 0;
}



Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...


int N;
void test_case(){
	cin >> N;
	int x = ceil((double)N/1000);
	cout << x*1000-N;
}
	
	



	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    dump(a);

    ll ret = 0;
    map<ll,ll> mp;
    for(ll i=n-1; i>=0; --i) {
        dump(mp);
        if(mp.find(a[i]+i) != mp.end()) {
            dump(i, a[i]+i, mp[a[i]+i])
            ret += mp[a[i]+i];
        }
        mp[i-a[i]]++;
    }
    cout << ret << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int N, Q;
vector<vector<int>> g;
vector<ll> dp;
vector<bool> visited;

void dfs(int p){
	visited[p] = true;
	for(int x : g[p]){
		if(visited[x]) continue;
		dp[x] += dp[p];
		dfs(x);
	}
}

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

	cin >> N >> Q;
	g.resize(N, vector<int>());

	rep(i, N-1){
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	dp.resize(N, 0);
	visited.resize(N, false);

	rep(i, Q){
		int p;
		ll x;

		cin >> p >> x;
		p--;
		dp[p] += x;
	}

	dfs(0);

	rep(i, N){
		cout << dp[i] << endl;
	}
}


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

int main() {
  int N, M, X;
  int A[M];
  cin >> N >> M >> X;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  int up = 0;
  int down = 0;
  for (int i = 0; i < M; i++) {
    if (A[i] < X) {
      down++;
    } else {
      up++;
    }
  }
  cout << min(up, down) << endl;
}


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

int main(){
	int T;
	cin >> T;
	string dummy;
	getline(cin,dummy);
	while(T--){
		string l;
		getline(cin,l);
		l.erase(remove(l.begin(),l.end(),'\r'),l.end());
		int p = 0;
		int M;
		cin >> M;
		getline(cin,dummy);
		l += " ";
		for(int i = 0 ; i < M ; i++){
			string t;
			getline(cin,t);
			t.erase(remove(t.begin(),t.end(),'\r'),t.end());
			stringstream ss(t);
			string a,b;
			ss >> a;
			char c;
			ss.get(c);
			getline(ss,b);
			if(a == "forward" && b == "char"){
				p = min(p+1,(int)l.size()-1);
			}
			if(a == "forward" && b == "word"){
				while(p+1 < l.size() && l[p] == ' ')p++;
				while(p+1 < l.size() && l[p] != ' ')p++;
			}
			if(a == "backward" && b == "char"){
				p = max(p-1,0);
			}
			if(a == "backward" && b == "word"){
				if( p ) p--;
				while(p >= 1 && l[p] == ' ')p--;
				while(p >= 1 && l[p] != ' ')p--;
				if( p != l.size()-1 && l[p] == ' ') p++;
			}
			if(a == "insert" ){
				b = b.substr(1,b.size()-2);
				l.insert(p,b);
				p += b.size();
			}
			if(a == "delete" && b == "char"){
				if(p < l.size()-1) l.erase(p,1);
			}
			if(a == "delete" && b == "word"){
				int t = p;
				int f = 0;
				while(t+1 < l.size() && l[t] == ' ')t++;
				while(t+1 < l.size() && l[t] != ' ')t++,f=1;
				if(f){
					int d = t - p ;
					l.erase(p,d);
				}
			}
		}
		for(int j = 0 ; j+1 < l.size() ; j++){
			if( j == p ){
				cout << "^";
			}
			cout << l[j];
		}
		if( p == l.size()- 1) cout << "^";
		cout << endl;
	}
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
//	freopen("in.txt", "r", stdin);
	int n, m, x;
	cin >> n >> m >> x;
	bool gate[n+1];
	memset(gate, false, sizeof(gate));
	for(int i=0; i<m; i++){
		int cur;
		cin >> cur;
		gate[cur] = true;
	}
	int ans = 0;
	int cost1 = 0, cost2 = 0;
	for(int i=x; i>=0; i--){
		if(gate[i]) cost1++;
	}
	for(int i=x; i<=n; i++){
		if(gate[i]) cost2++;
	}
	ans = min(cost1, cost2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; For(i, n){ Cin(T, x); map[x] ++; }
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Couty(cond) Cout((cond) ? "Yes" : "No")
#define CoutY(cond) Cout((cond) ? "YES" : "NO")

using namespace std;
using ll = long long;

int main(void){
  Cin(int, n);
  ll a = 2, b = 1;
  while(n > 1){
    n --;
    ll k = a+b;
    a = b, b = k;
  }
  Cout(b);
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define ln() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
	bool operator>(const edge& right) const {
		return cost > right.cost;
	}
};

struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
	bool operator>(const point& right) const {
		return x == right.x ? y > right.y : x > right.x;
	}
};

ll bisect_left(ll arr[], ll arr_size, ll key) {
	return distance(arr, lower_bound(arr, arr + arr_size, key));
}

ll bisect_left(vector<ll> vc, ll key) {
	return lower_bound(vc.begin(), vc.end(), key) - vc.begin();
}

ll pow_mod(ll a, ll x) {
	if (x == 0) return 1;
	if (x == 1) return a;
	ll ret = pow_mod(a, x / 2);
	if (x % 2 == 0) ret = (ret*ret) % MOD;
	else ret = (a * ((ret*ret) % MOD)) % MOD;
	return ret;
}

void build_mod_fact(ll arr[], ll n) {
	arr[0] = 1;
	repi(i, 1, n + 1) {
		arr[i] = (arr[i - 1] * i) % MOD;
	}
	return;
}

void build_mod_fact_inv(ll arr_fact[], ll arr_fact_inv[], ll n) {
	arr_fact_inv[n] = pow_mod(arr_fact[n], MOD - 2);
	repd(i, n - 1, -1) {
		arr_fact_inv[i] = (arr_fact_inv[i + 1] * (i + 1)) % MOD;
	}
	return;
}

ll comb_mod(ll n, ll r, ll arr_fact[], ll arr_fact_inv[]) {
	return (((arr_fact[n] * arr_fact_inv[n - r]) % MOD) * arr_fact_inv[r]) % MOD;
}


///////////////////////////////////////////////////////////////////////////////////////

ll N, Ma, Mb;
ll a[50], b[50], c[50];
ll dp[50][500][500];
ll ans = MAX_10p18;

int main() {
	cin >> N >> Ma >> Mb;
	repi(i, 0, N) cin >> a[i] >> b[i] >> c[i];

	repi(i, 0, N + 1) {
		repi(j, 0, 401) {
			repi(k, 0, 401) {
				dp[i][j][k] = MAX_10p18;
			}
		}
	}

	dp[0][0][0] = 0;
	repi(i, 0, N + 1) {
		repi(j, 0, 401) {
			repi(k, 0, 401) {
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
			}
		}
	}
	repi(i, 0, 401) {
		repi(j, 0, 401) {
			if (Ma*j == Mb * i && i != 0 && j != 0) ans = min(ans, dp[N][i][j]);
		}
	}
	if (ans == MAX_10p18) ans = -1;
	cout << ans << endl;
	return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program

ll mypow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	clock_t begin = clock();
	int n, k;
  	cin >> n >> k;
  	multiset<int, greater<int> > S;
  	REP(i, n){
  		int tmp;
      	cin >> tmp;
      	S.insert(tmp);
    }
  	while (k--){
      	int first = *S.begin();
      	first /= 2;
      	S.erase(S.begin());
      	S.insert(first);
    }
  	ll sum = 0;
  	for (auto x : S){
      	sum += (ll)x;
    }
  	cout << sum << endl;
	clock_t end = clock();
    double esecs = double(end - begin) / CLOCKS_PER_SEC;
    //cout << esecs << " seconds" << endl;
	return 0;	
}

Measured memory_bytes: 4992
import java.util.*;
import java.util.ArrayList;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        loop:for(int i=2; i<=55555; i++){
            for(int j=2; j<=Math.sqrt(i)+1; j++){
                if(i%j==0){
                    continue loop;
                }
            }
            if(i%5==1){
                list.add(i);
            }
            if(list.size()==N){
                break loop;
            }
        }

        for(int i=0; i<N-1; i++){
            System.out.println(list.get(i) + " ");
        }
        System.out.println(list.get(N - 1));
    }
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int k, x;
	cin >> k >> x;

	for(int i = max(-1000000, x - k + 1); i <= min(1000000, x + k - 1); ++i){
		cout << i << " ";
	}

    return 0;
}


Measured memory_bytes: 256
#88 C - X: Yet Another Die Game
import decimal
x = decimal.Decimal(input())

n = x/decimal.Decimal(11)
ans = n*decimal.Decimal(2)
judge = int(ans)
if ans - judge < decimal.Decimal(0.1):
    print(int(ans))
else:
    print(int(ans) + 1)

Measured memory_bytes: 96980
#include<stdio.h>
#define TRUE 1
#define FALSE 0
int A[1000];
int B[1000];
int n,m;

int main(){
  int i;

  scanf("%d",&n);
     
  for(i=0;i<n;i++)
    {
    scanf("%d",&A[i]);
    }
    
  scanf("%d",&m);

  for(i=0;i<m;i++)
    {
    scanf("%d",&B[i]);
  }

  for(i=0; i<m; i++){
    if(solve(0, B[i]) == 1) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int solve(int i, int l)
{
  if (l == 0)return 1;
  if (i >= n)return 0;
  return solve(i + 1, l) || solve(i + 1, l - A[i]);
}
  
 

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

using namespace std;

int main(void){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  int ans = 900000;
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      if(i == j) continue;
      ans = min(a[i]+a[j],ans);
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	b1,b2 := 1,1
	
	for i := 0; i < n; i++ {
		t := scanInt()
		a := scanInt()

		c1 := (b1+t-1)/t*(t+a)
		c2 := (b2+a-1)/a*(t+a)
		

		if c1 > c2 {
			if (b2+a-1)/a*t < b1 {
				b1 = (b1+t-1)/t*t
				b2 = (b1+t-1)/t*a
			} else {
				b1 = (b2+a-1)/a*t
				b2 = (b2+a-1)/a*a
			}
		} else {
			if (b1+t-1)/t*a < b2 {
				b1 = (b2+a-1)/a*t
				b2 = (b2+a-1)/a*a
			} else {
				b1 = (b1+t-1)/t*t
				b2 = (b1+t-1)/t*a
			}
		}

		// debug(b1,b2)
	}

	fmt.Fprintln(wr, b1+b2)
}


Measured memory_bytes: 640
def solve():
  n= int(input())
  a = list(int(i) for i in input().split())
  a.sort() 
  #前から一*n人削除
  a = a[n::]
  #後から二人分削除
  ans = 0
  for i in range(2*n):    
   if i%2 == 0: ans += a[i]
  return ans
  
  
if __name__ == '__main__':
  print(solve())

Measured memory_bytes: 37084
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    s += " ";
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        if (s[i] != s[i - 1]) {
            cnt++;
        }
    }
    cout << cnt;
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 512
// B.

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int n, a[100000], f[100000] = {};
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
	}
	int pos = 0, ans = 0;
	while (pos != 1 && !f[pos]) {
		++ans;
		f[pos] = 1;
		pos = a[pos];
	}
	cout << (pos == 1 ? ans : -1) << endl;
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

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

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int k,x;
void input()
{
    cin>>k>>x;
    return;
}

void solve()
{
    if(500*k>=x) cout<<"Yes\n";
    else cout<<"No\n";
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  
  int cor= 0, fal=0, a= 300;
  
  for (int i=0; i < n; i++){
    cor += l + i;
  }
  
  for (int i = 0; i < n; i++){
    fal = l + i;
    a = min(abs(fal), a);
  }
  
  if (l < -1){
    cout << cor + a << endl;
  }
  else {
    cout << cor - a << endl;
  }
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int X, N;
    cin >> X >> N;
    vector<int> p(N);
    REP(i, N) cin >> p[i];

    auto isInP = [&](int i){
        REP(j, N){
            if(p[j] == i) return true;
        }
        return false;
    };

    int ans, diff = 1000;
    REP(i, 102){
        if(diff > abs(X-i) and !isInP(i)){
            diff = abs(X-i);
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,m,x,y,k,dp[5][10010],cnt[200],h;
string a;

int main()
{
	int i;
	cin>>n>>k;
	h=k;
	for(i=2;i<=n;i++) h*=(k-1);
	cout<<h;
}

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

const int MOD = 1e9+7;
int add(int a, int b){return ((ll)a + (ll)b)%MOD;}
int sub(int a, int b){return add(a+MOD, -b);}
int mul(int a, int b){return ((ll)a * (ll)b)%MOD;}

void solve(){
    int x; cin >> x;
    int l = -6208; 
    int r = -6208;
    while(r <= 6208){
        ll ans = (ll)r*r*r*r*r - (ll)l*l*l*l*l;
        if(ans == x){
            cout << r << " " << l << '\n';
            return;
        }
        else if(ans > x){
            l++;
        }
        else{
            r++;
        }
    }
    assert(false);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3672
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, readline().split()))
    s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
    ul = [[0] * w for _ in range(h)]
    dl = [[0] * w for _ in range(h)]
    ll = [[0] * w for _ in range(h)]
    rl = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if i == 0:
                ul[i][j] = 1 if s[i][j] != "#" else 0
                dl[-i-1][j] = 1 if s[-i-1][j] != "#" else 0
            else:
                ul[i][j] = 1 + ul[i-1][j] if s[i][j] != "#" else 0
                dl[-i-1][j] = 1 + dl[-i][j] if s[-i-1][j] != "#" else 0
            if j == 0:
                ll[i][j] = 1 if s[i][j] != "#" else 0
                rl[i][-j-1] = 1 if s[i][-j-1] != "#" else 0
            else:
                ll[i][j] = 1 + ll[i][j-1] if s[i][j] != "#" else 0
                rl[i][-j-1] = 1 + rl[i][-j] if s[i][-j-1] != "#" else 0
    mt = 0
    for i in range(h):
        for j in range(w):
            mt = max(mt, ul[i][j] + dl[i][j] + ll[i][j] + rl[i][j] - 3)
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 308360
#include "bits/stdc++.h"
using namespace std;

int main() {
	string s;
	cin>>s;
	int e=s.size();
	if(e%2==0) {
		for(int i=0;i<e;i+=2) {
			cout<<s.at(i);
		}
	}
	else {
		for(int i=0;i<=e;i+=2) {
			cout<<s.at(i);
		}
	}
	cout<<endl;
}

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

int main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	vector<int> wa(0);
	vector<int> sh(0);
	for(int i=0; i>=0; i++){
		if(100*a*i >= f) break;
		for(int j=0; j>=0; j++){
			if(100*a*i+100*b*j >= f) break;
			wa.push_back(100*a*i+100*b*j);
		}
	}
	sort(wa.begin(), wa.end());
	for(int i=0; i>=0; i++){
		if(c*i*100 > f*e) break;
		for(int j=0; j>=0; j++){
			if((c*i+d*j)*100 > f*e) break;
			sh.push_back(c*i+d*j);
		}
	}
	sort(sh.begin(), sh.end());
	vector<int> w(0);
	vector<int> s(0);
	rep(i, wa.size()-1) if(wa.at(i+1) != wa.at(i)) w.push_back(wa.at(i+1));
	rep(i, sh.size()-1) if(sh.at(i+1) != sh.at(i)) s.push_back(sh.at(i+1));
	double ma = 0;
	int answs = w.at(0);
	int anss = 0;
	rep(i, w.size()){
		rep(j, s.size()){
			int ws = w.at(i) + s.at(j);
			double wsd = w.at(i) + s.at(j);
			if(ws > f) continue;
			double r = s.at(j);
			r *= 100;
			r /= w.at(i);
			double ed = e;
			if(r > ed) continue;
			if(r > ma){
				ma = r;
				answs = ws;
				anss = s.at(j);
			} 
		}
	}
	cout << answs << ' ' << anss << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, a[51], b[51];
bool g[51][51], d[51];

bool dfs(int x) {
    d[x] = true;
    bool all_visited = true;
    rep(i, 0, n) if (!d[i]) {
        all_visited = false;
        break;
    }
    if (all_visited) return true;

    bool flag = false;
    rep(i, 0, n) {
        if (!d[i] && g[x][i]) {
            flag = dfs(i);
        }
    }
    return flag;
}

int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    int ans = 0;
    rep(i, 0, m) {
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        if (!dfs(0)) ans++;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
        fill(d, d+51, false);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int H1, M1, H2, M2, K;
  cin>>H1>>M1>>H2>>M2>>K;

  Int a = H1 * 60 + M1;
  Int b = H2 * 60 + M2;
  Int ans = max(0LL, (b - a) - K);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3664
# -*- coding: utf-8 -*-
import sys 
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(readline())
edges = [[] for _ in range(K)]
INF = 10 ** 31
dist = [INF]*K
for i in range(K):
    edges[i].append(((i+1)%K,1))
    j = 10*i % K
    if i != j:
        edges[i].append((j,0))

q = deque([1])
dist[1] = 0
while q:
    x = q.popleft()
    for y,c in edges[x]:
        d = dist[x] + c
        if d < dist[y]:
            dist[y] = d
            if c == 1:
                q.append(y)
            else:
                q.appendleft(y)
print(dist[0]+1)

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

int main() {
  int N;
  vector<int> arr;

  cin >> N;

  while (N--) {
    int input;
    cin >> input;
    arr.push_back(input);
  }

  int count = 0;
  sort(arr.begin(), arr.end());
  for (int i = 0;i < arr.size();i++) {
    if(arr[i] == arr[i+1]) {
      count++;
    }
  }

  if (count > 0) {
    cout << "NO";
  }
  else {
    cout << "YES";
  }

  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int n;
    cin>>n;
    map<string, int> mp;
    rep(i,0,n){
        string s;
        cin>>s;
        mp[s]=1;
    }
    cout<<mp.size()<<endl;
    return 0;
}

Measured memory_bytes: 19264
#include <iostream>

using namespace std;

int main(void){
  int D;
 re:
  cin >> D;

  if(D == 25)
    cout << "Christmas" << endl;
  else if(D == 24)
    cout << "Christmas Eve" << endl;
  else if(D == 23)
    cout << "Christmas Eve Eve" << endl;
  else if(D == 22)
    cout << "Christmas Eve Eve Eve" << endl;
  else
    goto re;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

typedef vector<ll> vec;
typedef vector<vec> mat;
ll m;

mat mul(mat& A, mat& B) {
    mat C(A.size(), vec(B[0].size(), 0));
    for(int i = 0; i < A.size(); ++i) {
        for(int j = 0; j < B[0].size(); ++j) {
            for(int k = 0; k < B.size(); ++k) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n) {
    mat B(A.size(), vec(A.size(), 0));
    for(int i = 0; i < A.size(); ++i) {
        B[i][i] = 1LL;
    }
    while(n > 0) {
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

void solve() {
	ll l, a, b; cin >> l >> a >> b >> m;
    ll x0 = 0, s0 = a % m, k0 = 1;
    for(int d = 1; d <= 18 ; ++d) {
        mat A(3, vec(3));
        A[0][0] = (ll)pow(10, d) % m; A[0][1] = 1; A[0][2] = 0;
        A[1][0] = 0; A[1][1] = 1; A[1][2] = b % m;
        A[2][0] = 0; A[2][1] = 0; A[2][2] = 1;
        if(a > (ll)pow(10, d)) continue;
        ll cnt = ((ll)pow(10, d) - 1 - a) / b - ((ll)pow(10, d - 1) - 1 - a) / b;
        if(a > (ll)pow(10, d - 1)) cnt = 1 + ((ll)pow(10, d) - 1 - a) / b;
        if(l >= cnt) {
            l -= cnt;
        } else {
            cnt = l;
            l = 0;
        }
        //debug(cnt);
        //debug(l);
        A = pow(A, cnt);
        ll x = (A[0][0] * x0 % m + A[0][1] * s0 % m + A[0][2] * k0 % m) % m;
        ll s = (A[1][0] * x0 % m + A[1][1] * s0 % m + A[1][2] * k0 % m) % m;
        ll k = (A[2][0] * x0 % m + A[2][1] * s0 % m + A[2][2] * k0 % m) % m;
        x0 = x; s0 = s; k0 = k;
    }
    cout << x0 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256