akhauriyash/Code-Regression huggingface dataset:
/****************************************

			LostMartian

****************************************/
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;

template <typename Arg1>
void pn(Arg1&& arg1) {
	cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1&& arg1, Args&&... args) { 
	cout << arg1 << " "; 
	pn(args...); 
}
template <typename Arg1>
void ps(Arg1&& arg1) { 
	cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args) { 
	cout << arg1 << " "; 
	ps(args...); 
}
template <typename Arg1>
void read(Arg1&& arg1) {
	cin >> arg1; 
}
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) { 
	cin >> arg1; 
	read(args...); 
}

#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define vpi vector<pi >
#define umap unordered_map<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define test ll t; cin>>t; while(t--)
#define ini(a, x) memset(a, x, sizeof(a))
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define iAmSpeed ios_base::sync_with_stdio(false); cin.tie(NULL);
void LOCAL();
int main()
{
	clock_t z = clock();
	//LOCAL();
	iAmSpeed
	string s;
	cin>>s;
	ll sum=0;
	ll n=s.length();
	rep(i,0,n) {
		sum+=(s[i]-'0');
	}	
	if(sum%9==0) {
		cout<<"Yes\n";
	}
	else {
		cout<<"No\n";
	}















	debug("Total Time: %.7f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}
void LOCAL() {
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}


Measured memory_bytes: 3932
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <functional>
#define rep(i, a, b) for(int i=a;i<b;++i)
#define MOD 1000000007
#define RAND 1000
using namespace std;

int main(void)
{
	int N, M, a, b;
	int n[100001] = { 0 };
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		++n[a];
		++n[b];
	}
	for (int i = 2; i <= N; ++i) {
		if (n[i] % 2) {
			cout << "NO" << endl;
			//system("PAUSE");
			return 0;
		}
	}
	cout << "YES" << endl;
	//system("pause");
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int N;
std::string S;
std::string num="0123456789";
cin>>N;
cin>>S;
int ans=0;
int a,b,c,counter;
for(int i=0;i<1000;++i){
  c=i%10;
  b=(i/10)%10;
  a=i/100;
  counter=0;
  for(int j=0;j<N;++j){
    if(counter==0){
      if(S[j]==num[a]){
        counter+=1;
      }
    }
    else if(counter==1){
      if(S[j]==num[b]){
        counter+=1;
      }
    }
    else if(counter==2){
      if(S[j]==num[c]){
        ans+=1;
        break;
      }
    }
  }
}
cout<<ans<<"\n";
return 0;
}

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,d,a;
    cin>>n>>d>>a;
    vector<pair<ll,ll>> vec(n);
    for(ll i=0;i<n;++i)
    {
    	ll a,b;
    	cin>>a>>b;
    	vec[i]=make_pair(a,b);

    }

    sort(vec.begin(),vec.end());

    long long ans=0;
    set<pair<ll,ll> >s;
    long long sum=0;
    for(ll i=0;i<n;++i)
    {
    	auto it1=s.lower_bound(make_pair(vec[i].first,-1));
    	auto it2=s.rbegin();
    	ll y=0;
    	if(it1!=s.end()&&s.size()>=1)
    	{
    	    if(it1!=s.begin())
    	    {
    	        it1--;
    	        ll start=it1->second;
    	        ll end=it2->second;
    	      
    	        
    	            y=end-start;
    	        
    	    }
    	    else
    	    {
    	        y=it2->second;
    	    }
    	}
    	
    	ll right=vec[i].first+2*d;
    	ll res=0;
    	if(vec[i].second>=y)
    	{
    	res=(vec[i].second-y+a-1)/a;
    	
    	ans+=res;

    	sum+=res*a;
    	s.insert(make_pair(right,sum));
    	}

    }

    cout<<ans<<endl;



}


Measured memory_bytes: 15872
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int sosu[1111111];
int dp[1211111];
int main(){
	
	sosu[0]=1;
	sosu[1]=1;
	
	for(int i=2;i<1111111;i++){
		if(sosu[i]==1)continue;
		for(int j=i+i;j<1111111;j+=i){
			sosu[j]=1;
		}
	}
	
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)break;
		
		rep(i,1111111)dp[i]=0;
		dp[0]=1;
		
		int item[33];
		rep(i,n){
			cin>>item[i];
		}
		
		int ans=-1;
		rep(i,m+1){
			if(dp[i]==0)continue;
			if(sosu[i]==0)ans=i;
			rep(j,n){
				if(i+item[j]>m)continue;
				dp[i+item[j]]=1;
			}
		}
		if(ans==-1){
			puts("NA");
		}else{
			printf("%d\n",ans);
		}
	}
}

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

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30;
ll A[10000000] = {}, X[1000000] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
ll a = 0, b = 0, c = 0, n = 0, sum = 0, max = INF;
str S;
ll ans = 0;

int findDigits(int n) {
	int i = 0;
	while (n > 0) {

		sum += n % 10;
		n /= 10;
		i++;
	}
	return i;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Code Line
	cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4] >> n;
	if (A[4] - A[0] > n)cout << ":(" << endl;
	else cout << "Yay!" << endl;
	cin >> n;

	//Code Line
	return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int m; cin >> m; cout << 48 - m << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
  int N;
  scanf("%d", &N);
  vector<int> avail(N + 5);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &avail[i]);
  }
  vector<vector<int> > grid(H, vector<int>(W, 0));
  int color = 1;
  for (int r = 0; r < H; ++r) {
    if (r % 2 == 0) {
      // ==>
      int c = 0;
      while (c < W) {
        grid[r][c] = color;
        if (--avail[color] == 0) { ++color; }
        ++c;
      }
    }
    else {
      // <==
      int c = W - 1;
      while (c >= 0) {
        grid[r][c] = color;
        if (--avail[color] == 0) { ++color; }
        --c;
      }
    }
  }
  for (int r = 0; r < H; ++r) {
    printf("%d", grid[r][0]);
    for (int c = 1; c < W; ++c) {
      printf(" %d", grid[r][c]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 384
N, X, M = map(int, input().split())
cur = X
pos = {}
path = []
i = 0
while cur not in pos:
    pos[cur] = i
    path.append(cur)
    cur = cur ** 2 % M
    i += 1

loop_start = pos[cur]
ans = None
if N <= len(path):
    ans = sum(path[:N])
else:
    ans = sum(path)
    left = N - len(path)
    q, r = divmod(left, len(path) - loop_start)
    ans += q * sum(path[loop_start:]) + sum(path[loop_start:loop_start + r])
print(ans)

Measured memory_bytes: 15560
// !Start && !End 
//  0 se divide
//https: //www.youtube.com/watch?v=6Nb-prB-4P0&list=RD6Nb-prB-4P0&start_radio=1

// https: //www.youtube.com/watch?v=eYDI8b5Nn5s
// Electrify my OOOoooooOOOoooOOOOOoooooOOOooo!
// #pragma optimise GCC(-O2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define ve(x) vector<x>
#define f(a,b,c) for(int a=b;a<c;a++)
#define foto(x,v) for(auto x:v)
#define read(t) ll t; cin>>t;
#define reads(t) string t; cin>>t;
#define readarr(arr,n) ll arr[n]; f(i,0,n) cin>>arr[i];
#define forstl(i,v) for(auto &i: v)
#define ln endl
#define dbg(x) cout<<#x<<" = "<<x<<ln;
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it<<ln;} cout<<ln;
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cout<<ln;
#define dbgarr(v,s,e) cout<<#v<<" = "; f(i,s,e) cout<<v[i]<<", "; cout<<ln;
#define addEdge(tr,k) f(i,0,k) { ll x,y; cin>>x>>y, tr[x].push_back(y), tr[y].push_back(x);}
#define all(v) v.begin(),v.end()

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); }

//														GLOBAL VARS
ll INF =LLONG_MAX;
const ll M= 1000000007;

//														USEFUL FUNCTIONS
ll powm(ll ,ll);





// 														MAIN
int main()
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    //It gets easier day by day, but the hard part is to........
    read(r)
    double pi = 3.14159265359;
    cout<<setprecision(18)<<2*pi*r;

}










//													FUNCTIONS DECLARATIONS
ll powm(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%M;
		a=(a*a)%M;
		b>>=1;
	}
	return res;
}


Measured memory_bytes: 3804
import math

N,M = map(int, input().split())

L=1
R=N
for i in range(M):
    tL,tR = map(int, input().split())
    if tL > L:
        L = tL
    if tR < R:
        R = tR

Ans = R-L+1
if Ans < 0:
    Ans = 0

print(Ans)



Measured memory_bytes: 3060
K = int(input())
listsan = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(listsan[K - 1])

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

int main(){
  int n,h,w;
  cin >> n >> h >> w;
  int a[n],b[n];
  rep(i,n)cin >> a[i] >> b[i];
  int ans=0;
  rep(i,n)if(a[i]>=h&&b[i]>=w)ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0;i+2<s.size();i++) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int m, N;
bool is_prime[8000000];

int sieve(int n) {
	int p = 0;
	for (int i = 0; i < n; i++)is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	int cnt = 0;
	for (int i = m;; i++) {
		if (is_prime[i]) {
			cnt++;
			if (cnt == N + 1) {
				cout << i << endl;
				break;
			}
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = 0;
		}
	}
	return p;
}

int main() {
	while (cin >> m >> N&&m + N) {
		sieve(8000000);
	}
}

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

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

    int cnt = S.size();
    string Ta = T.substr(0, cnt);

    if (S == Ta) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }



}

Measured memory_bytes: 3596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			char[] s = in.next().toCharArray();
			char[] t = in.next().toCharArray();
			if (ok(s, t) && ok(t, s)) {
				out.println(lcm(n, m));
			} else {
				out.println(-1);
			}
		}

		private boolean ok(char[] s, char[] t) {
			for (int i = 0; i < s.length; i++) {
				long x = (long) t.length * i;
				if (x % s.length != 0) {
					continue;
				}
				int j = (int) (x / s.length);
				if (j < t.length && s[i] != t[j]) {
					return false;
				}
			}
			return true;
		}

		private long lcm(int a, int b) {
			return (long) a / gcd(a, b) * b;
		}

		private int gcd(int a, int b) {
			return b == 0 ? a : gcd(b, a % b);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 25300
from math import factorial

N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())
ans = 0
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
        cnt += 1
print(ans  * (N - 1) / cnt )

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    string s = "";
    cin >> s;
    if (s[s.length() - 1] == 's')
    {
        s += "es";
    }
    else
    {
        s += "s";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3576
def solve():
    N, M = map(int, input().split())
    edges = [[] for _ in [0]*N]
    r_edges = [[] for _ in [0]*N]

    for _ in [0]*M:
        a, b = map(int, input().split())
        edges[a].append(b)
        r_edges[b].append(a)

    c = kosaraju(edges, r_edges)
    group = [0]*N
    for i in range(len(c)):
        for v in c[i]:
            group[v] = i

    result = []
    append = result.append
    for _ in [0]*int(input()):
        a, b = map(int, input().split())
        append("1" if group[a] == group[b] else "0")

    print("\n".join(result))


def kosaraju(edges, reverse_edges):
    import sys
    sys.setrecursionlimit(10**7)
    v_count = len(edges)
    order = [0]*v_count
    k = [1]

    def get_order(v):
        order[v] = 1
        for dest in filter(lambda x: order[x] == 0, edges[v]):
            get_order(dest)
        order[v] = k[0]
        k[0] += 1

    def get_components(v):
        order[v] = 0
        return [v] + [_v for dest in reverse_edges[v] if order[dest] > 0 for _v in get_components(dest)]

    for v in filter(lambda x: order[x] == 0, range(v_count)):
        get_order(v)
    return [get_components(v) for v, _ in sorted(enumerate(order), key=lambda x: x[1], reverse=True) if order[v] > 0]

if __name__ == "__main__":
    solve()

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


const int INF = 1e10;


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

	int D = s.length();

	vector<int> N(D);
	for (int i = 0; i < D; ++i) N[i] = s[D - i - 1] - '0'; // 下位桁から順に格納

	vector<int> M(D);
	int carry = 0;
	for (int i = 0; i < D; ++i) {
		M[i] = 10 - carry - N[i];
		carry = 1 - M[i] / 10;
		M[i] %= 10;
	}

	vector<int> dp0(D + 1, INF), dp1(D + 1, INF); // dp0が表、dp1が裏
	dp0[0] = dp1[0] = 0;

	for (int i = 1; i <= D; ++i) {
		int a = N[i - 1], b = M[i - 1];
		dp0[i] = min(a + dp0[i - 1], 1 + b + dp1[i - 1]);
		if (b + 1 < 10) dp0[i] = min(dp0[i], 2 + b + dp0[i - 1]);
		dp1[i] = min(b + dp1[i - 1], 1 + a + dp0[i - 1]);
		if (a + 1 < 10) dp1[i] = min(dp1[i], 2 + a + dp1[i - 1]);
	}

	cout << dp0[D] << endl;

	return 0;
}

Measured memory_bytes: 19644
#include <bits/stdc++.h>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef pair<long long int, int> P; // 距離,頂点
int main(){
	int N, M, S, T; 
	cin >> N >> M >> S >> T; 
	long long int INF = 1e18; 
	vector<P> E1[100010] = {}; //交換するまで
	vector<P> E2[100010] = {}; //交換したあと
	long long int D1[100010] = {}; //交換するまで
	long long int D2[100010] = {}; //交換したあと
	for(int i = 1; i <= N; i++){
		D1[i] = INF; D2[i] = INF; 
	}
	D1[S] = (long long) 0; D2[T] = (long long) 0; 
	priority_queue<P, vector<P>, greater<P>> que;
	for(int i = 0; i < M; i++){
		int u, v;
		long long int a, b; 
		cin >> u >> v >> a >> b; 
		E1[u].push_back(P(a, v)); 
		E1[v].push_back(P(a, u)); 
		E2[u].push_back(P(b, v)); 
		E2[v].push_back(P(b, u));
	}
	que.push(P(0, S)); // 距離,頂点 
	while(que.size()){
		P p = que.top(); que.pop(); 
		int V = p.second; 
		if(D1[V] < p.first) continue; 
		for(int i = 0; i < E1[V].size(); i++){
			if(D1[E1[V].at(i).second] > D1[V] + E1[V].at(i).first){
				D1[E1[V].at(i).second] = D1[V] + E1[V].at(i).first;
				que.push(P(D1[E1[V].at(i).second], E1[V].at(i).second)); 
			}
		}
	}
	que.push(P(0, T)); // 距離,頂点 
	while(que.size()){
		P p = que.top(); que.pop(); 
		int V = p.second; 
		if(D2[V] < p.first) continue; 
		for(int i = 0; i < E2[V].size(); i++){
			if(D2[E2[V].at(i).second] > D2[V] + E2[V].at(i).first){
				D2[E2[V].at(i).second] = D2[V] + E2[V].at(i).first;
				que.push(P(D2[E2[V].at(i).second], E2[V].at(i).second)); 
			}
		}
	}
	long long int total[100010] = {}; 
	long long int ans[100010] = {}; 
	ans[N+1] = INF; 
	for(int i = N; i >= 1; i--){
		total[i] = D1[i] + D2[i]; 
		ans[i] = min(ans[i+1], total[i]); 
	}
	for(int i = 1; i <= N; i++){
		cout << 1000000000000000 - ans[i] << endl; 
	}
}

Measured memory_bytes: 19704
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 1000000007
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
using namespace std;
typedef long long tint;
typedef pair<tint, tint> pii;
typedef vector<tint> vi;
typedef vector<vi> vvi;

struct nodo{
	vector<int> children;
	bool fin = false;
};

bool compa(const string s1, const string s2) {
	if(s1.size() != s2.size()) {
		return s1.size() < s2.size();
	}
	return s1 < s2;
}

int main()
{
	vector<nodo> trie(1);
	trie[0].children = vector<int>(30,-1);
	int n;
	cin >> n;
	vector<string> s(n);
	forn(i, n) { 
		cin >> s[i];
		reverse(s[i].begin(), s[i].end());
	}
	
	sort(s.begin(), s.end(), compa);
	tint ans = 0;
	forn(i, n) {
		string t = s[i];
		
		vi let(30, 0);
		forn(j, t.size()) {
			let[t[j]-'a']++;
		}
		
		int act = 0;
		forn(j, t.size()) {
			forn(k, 30) {
				if(let[k] && trie[act].children[k] != -1 && trie[trie[act].children[k]].fin) ans++;
			}
			
			int ind = t[j]-'a';
			if(trie[act].children[ind] == -1) {
				nodo n;
				n.children = vector<int>(30,-1);
				trie[act].children[ind] = trie.size();
				trie.push_back(n);
			}
			
			act = trie[act].children[ind];
			let[ind]--;
		}
		trie[act].fin = true;
	}
	cout << ans << endl;
}


Measured memory_bytes: 160700
#include <iostream>
#include<algorithm>

using namespace std;

struct Restaurant {
	string name;
	int p;
	int num;
};

bool comp(const struct Restaurant& r1, const struct Restaurant& r2)
{
	if (r1.name == r2.name) {
		 return r1.p > r2.p;
	}
    return r1.name < r2.name;
}

int main(int argc, char *argv[])
{
	int N;
	struct Restaurant r[101];
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		string S;
		int P;
		cin >> S >> P;
		struct Restaurant r1 = {S, P, i};
		r[i] = r1;
	}

	sort(r, r + N, comp);
	for (int i = 0; i < N; i++) {
		cout << r[i].num + 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
H = list(map(int,input().split()))

# from random import randint
# n = 10**5
# k = 100
# H = [randint(1, 10**4) for i in range(n)]

D = [float("inf") for i in range(n)]
D[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i-j >= 0:
            D[i] = min(D[i], D[i-j]+abs(H[i]-H[i-j]))
    
print(D[-1])

Measured memory_bytes: 88880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int a,b; cin>>a>>b;
    if(a+b>=10) cout<<"error"<<endl;
    else cout<<a+b<<endl;
}


Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>a>>b>>c>>d;

      if(abs(a-c)<=d || ((abs(a-b)<=d && abs(b-c)<=d)))
        cout<<"Yes"<<endl;

      else cout<<"No"<<endl;













}



Measured memory_bytes: 3640
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let arrows: Vec<(usize, usize)> = vec(m, |_| {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        (a - 1, b - 1)
    });
    let mut nexts = vec![Vec::new(); n];
    for &(i, j) in &arrows {
        nexts[i].push(j);
    }
    let mut p: Vec<f64> = vec![0.0; n];
    p[0] = 1.0;
    for i in 0..n {
        let x = p[i] / nexts[i].len() as f64;
        for &j in &nexts[i] {
            p[j] += x;
        }
    }
    let mut e: Vec<f64> = vec![0.0; n];
    let mut max: f64 = 0.0;
    for i in (0..n - 1).rev() {
        let k = nexts[i].len() as f64;
        let mut sum = 0.0;
        for &j in &nexts[i] {
            sum += e[j];
        }
        e[i] = 1.0 + sum / k;
        if nexts[i].len() > 1 {
            for &j in &nexts[i] {
                max = max.max(p[i] * (sum / k - (sum - e[j]) / (k - 1.0)));
            }
        }
    }
    println!("{}", e[0] - max);
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 123456789123456789LL

struct edge {int from, to; long cost;};

// Bellman-Ford
bool bellmanFord(int from, vector<long> &d, vector<edge> &es){
  d[from]=0;
  int n=d.size();
  rep(i,n){
    bool update=false;
    for(int j=0; j<es.size(); j++){
      edge e = es[j];
      long target = d[e.from]+e.cost;
      if(d[e.from]!=INF && d[e.to]>target){
        d[e.to] = target;
        update=true;
      }
    }
    if(!update) return true;
  }
  return false;
}

int main(){
  int n,m;
  cin>>n>>m;
  vector<long> d(n);
  vector<edge> vec(m);

  rep(i,m){
    cin>>vec[i].from>>vec[i].to>>vec[i].cost;
    vec[i].from--;vec[i].to--;
    vec[i].cost *= -1;
  }

  fill(all(d), INF);
  if( bellmanFord(0,d,vec) == false){
    long old = d[n-1];
    bellmanFord(0,d,vec);
    if( old == d[n-1] ) cout << -d[n-1] << endl;
    else cout << "inf" << endl;
  } else {
    cout << -d[n-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
program bbb

implicit none
integer :: n,i,co,res
integer,dimension(6) :: a

read*, n

a(1)=int(n/(10**5))
a(2)=int(n/(10**4)-a(1)*10**1)
a(3)=int(n/(10**3)-a(1)*10**2-a(2)*10**1)
a(4)=int(n/(10**2)-a(1)*10**3-a(2)*10**2-a(3)*10**1)
a(5)=int(n/(10**1)-a(1)*10**4-a(2)*10**3-a(3)*10**2-a(4)*10**1)
a(6)=int(n/(10**0)-a(1)*10**5-a(2)*10**4-a(3)*10**3-a(4)*10**2-a(5)*10**1)

do i=1,6
if (a(i)==0) cycle
co=i
exit
end do

res=0

if (co==5) res=9
if (co==3) res=909
if (co==1) res=90909
if (co==6) res=a(6)
if (co==4) then
res=((a(4)-1)*10**2+a(5)*10+a(6)+10)
end if
if (co==2) then
res=((a(2)-1)*10**4+a(3)*10**3+a(4)*10**2+a(5)*10+a(6)+910)
end if

write(*,'(i0)') res

end program

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i=0;i<n;i++){
        cin >> s.at(i);
    }
    set<string> st;
    for (int i=0;i<n;i++){
        st.insert(s.at(i));
    }
    cout << st.size() << endl;
    return 0;
}



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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

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

struct Vector2D {
  int x, y;
  Vector2D() {}
  Vector2D(int x, int y) : x(x), y(y) {}

  bool operator<(Vector2D v) const { return tie(x, y) < tie(v.x, v.y); }
  bool operator==(Vector2D v) const { return tie(x, y) == tie(v.x, v.y); }
  bool operator>(Vector2D v) const { return tie(x, y) > tie(v.x, v.y); }
  bool operator<=(Vector2D v) const { return tie(x, y) <= tie(v.x, v.y); }
  bool operator>=(Vector2D v) const { return tie(x, y) >= tie(v.x, v.y); }

  Vector2D normalize() {
    if (x == 0) {
      return Vector2D(0, 1);
    }
    if (y == 0) {
      return Vector2D(1, 0);
    }
    int g = gcd(x, y);
    Vector2D norm(x / g, y / g);
    if (norm.y < 0) norm.x = -norm.x, norm.y = -norm.y;
    return norm;
  }
  Vector2D normalized_orthogonal() {
    if (x == 0) {
      return Vector2D(1, 0);
    }
    if (y == 0) {
      return Vector2D(0, 1);
    }
    int g = gcd(x, y);
    Vector2D ort = Vector2D(-y / g, x / g);
    if (ort.y < 0) ort.x = -ort.x, ort.y = -ort.y;
    return ort;
  }
};

void solution() {
  map<pair<Vector2D, Vector2D>, ii> m;
  int n;
  cin >> n;
  int pot2[n + 1];
  pot2[0] = 1;
  for (int i = 1; i <= n; i++) pot2[i] = mod(pot2[i - 1] * 2LL, M);
  int lixo = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      lixo++;
      continue;
    }
    Vector2D vec(a, b);
    vec = vec.normalize();
    auto ort = vec.normalized_orthogonal();
    if (m.count(mp(vec, ort)))
      m[mp(vec, ort)].ff++;
    else if (m.count(mp(ort, vec)))
      m[mp(ort, vec)].ss++;
    else
      m[mp(vec, ort)] = ii(1, 0);
  }
  set<Vector2D> vis;
  int ans = 1LL;
  for (auto p : m) {
    int cnt = p.ss.ff;
    int cnt2 = p.ss.ss;
    ans = mod(ans * mod(pot2[cnt] + pot2[cnt2] - 1LL, M), M);
  }
  ans = mod(ans + lixo - 1LL, M);
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  solution();
}


Measured memory_bytes: 23808
def gcd(a,b):
    if b < a:
        b,a = a,b
    if a==0:
        return b
    
    return gcd(b%a,a)

def main():
    k = int(input())
    ans = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            tmp = gcd(i,j)
            for k in range(1,k+1):
                ans += gcd(tmp,k)
    print(ans)
    

if __name__== "__main__":
    main()

Measured memory_bytes: 71636
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
using namespace std;

int main(){
    //drink M, shops N
    int N, M;
    cin >> N >> M;
    //N*1の配列を2つ作成
    //price A, number B
    vector<int> A(N);
    vector<int> B(N);
    //配列に格納
    for(int i=0; i<N; i++){
        cin >> A[i];
        cin >> B[i];
    }

    /*
    for(int x:A){
        cout << x << endl;
    }
    */
    //価格が安い順に並び替え
    //std::vector<int> array = {3, 2, 5, 7, 1};

    // 配列のインデックス indiecs = {0, 1, 2, 3, 4} を作成する。
    //std::vector<size_t> indices(array.size());
    //std::iota(indices.begin(), indices.end(), 0);

    vector<size_t> indecs(N);
    iota(indecs.begin(), indecs.end(), 0);

    // ソートする。
    std::sort(indecs.begin(), indecs.end(), [&A](size_t i1, size_t i2) {
        return A[i1] < A[i2];
    });

    int sum = 0;
    long long price = 0;
    for(int x : indecs){
        //cout << x << endl;
        if(sum+B[x]<=M){
            sum += B[x];
            price += (long long)A[x]*B[x];
        }
        else{
            int rest = M-sum;
            price += (long long)A[x]*rest;
            break;
        }
        
    }
    cout << price << endl;
}


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

int main() {
  ll n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  vector<char> t(n);
  vector<ll> v(n);
  rep(i, n) {
    cin >> t[i];
    if (t[i] == 'r')
      v[i] = p;
    else if (t[i] == 's')
      v[i] = r;
    else if (t[i] == 'p')
      v[i] = s;
  }
  ll ans = 0;
  rep(i, n) {
    if (i >= k) {
      if (v[i] == v[i - k] && t[i] == t[i - k]) {
        v[i] = 0;
      }
    }
    ans += v[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll a1 = 0, a2 = 0;
string s;
int main() {
	cin >> s;
	REP(i, s.size()) {
		if (i % 2 == 0 and s[i] != '0')a1++;
		if (i % 2 == 1 and s[i] != '1')a1++;
	}
	REP(i, s.size()) {
		if (i % 2 == 1 and s[i] != '0')a2++;
		if (i % 2 == 0 and s[i] != '1')a2++;
	}
	cout << min(a1, a2) << endl;
}

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

int main(){
 long long N,K,ans,a,b;
cin>>N;
  vector<long long>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  a=H[N-1];
    for(int i=N-2;i>=0;i--){
    if(H[i]>a){
      H[i]--;
      if(H[i]>a){
        cout<<"No"<<endl;
        return 0;
      }
      continue;
    }
      else if(H[i]==a){
        continue;
      }
      else{
     a=H[i];
      }
    }
      cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
 
int main(){
	fast;
	lli n,a,b;
	cin>>n>>a>>b;
	lli ans=0, tot=a+b;
	ans+=((n/tot)*a);
	if(n%tot >= a) ans+=a;
	else ans+=(n%tot);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i>=l;++i)
#define fd(i,j,l) for(int i=j;i<=l;--i)

using namespace std;
typedef long long ll;
const ll N=12e4;

int a,b;

int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	scanf("%d%d",&a,&b);
	int ans=a-b+1;
	if(ans<=0)ans=0;
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,d,sum=0;
//double dis=0;
struct node {
	int x[11];
} q[11];
int main() {
	cin>>n>>d;
	for(int t=1; t<=n; t++) {
		for(int i=1; i<=d; i++) {
			cin>>q[t].x[i];
		}
	}
	for(int t=1; t<=n; t++) {
		for(int i=t+1; i<=n; i++) {
			double dis=0;
			for(int j=1; j<=d; j++) {
				dis+=pow(q[t].x[j]-q[i].x[j],2);
			}
			int di=sqrt(dis);
//			cout<<" "<<dis<<" "<<di<<endl;
			if(pow(di,2)==dis) {
				sum++;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    static InputStreamReader r;
    public static void main(String[] args) throws Exception {
        r = new InputStreamReader(System.in);
        int N = nextInt();
        String S = nextString();

        int ans = 0;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if ('A' == S.charAt(i)) {
                cnt = 1;
            }
            else if (cnt == 1 && 'B' == S.charAt(i)) {
                cnt = 2;
            }
            else if (cnt == 2 && 'C' == S.charAt(i)) {
                ans++;
                cnt = 0;
            }
            else {
                cnt = 0;
            }
        }
        System.out.println(ans);
    }

    public static String nextString() throws Exception {
        String res = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            res += (char)c;
        }
        return res;
    }

    public static int nextInt() throws Exception {
        return Integer.parseInt(nextString());
    }

    public static long nextLong() throws Exception {
        return Long.parseLong(nextString());
    }
}


Measured memory_bytes: 21204
#include<stdio.h>
int main()
{
    int c,i;
    long long a,b,l=0;
    scanf("%lld%lld",&a,&b);
    if(b>=2*a)
    {
        l+=a;
        b-=2*a;
    }
    else
    {
        l+=b/2;
        b=0;
    }
    if(b>=4)
    {
        l+=b/4;
    }
    printf("%lld",l);
}

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

int main()
{
  int n;
  cin>>n;
  int arr[n], count = 0;
  for(int i = 0; i < n; i++)
  {
    cin>>arr[i];
  }
  for(int i = 0; i < n; i++)
  {
    if((i+1)%2 != 0 && arr[i]%2 != 0)
    {
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

typedef struct Node_ {
    long long int   cnt;
    struct Node_    *parent;
} Node;

int main (void) {
    int n, q, i;
    scanf("%d%d", &n, &q);
    Node *node;
    node = (Node *)calloc(n + 1, sizeof(Node));
    int a, b;
    for (i = 1; i < n; i++) {
        scanf("%d%d", &a, &b);
        (node[b].parent) = &node[a];
    }
    int p, x;
    for (i = 0; i < q; i++) {
        scanf("%d%d", &p, &x);
        (node[p].cnt) += x;
    }

    for (i = 1; i <= n; i++) {
        if ( i != 1 ) {
            node[i].cnt += (node[i].parent)->cnt;
        }
        printf("%lld ", node[i].cnt);
    }
    printf("\n");
    free(node);
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 200, INF = 1e18; 
vector<pair<ii, int> > adj[maxn]; 

int dis[maxn], n, m; 
bool vis[1050]; 

void dijk(int s) {
	vector<int> g[maxn]; 
	for(int i = 1; i <= n; i++) dis[i] = INF; 
	dis[s] = 0; 
	heap<ii, vector<ii>, greater<ii>> pq; 
	pq.push({0, s}); 
	while(!pq.empty()) {
		ii T = pq.top(); pq.pop(); 
		int u = T.se, d = T.fi; 
		if(d > dis[u]) continue; 
		for(auto v : adj[u]) {
			if(dis[v.fi.fi] > d + v.fi.se) {
				dis[v.fi.fi] = d + v.fi.se; 
				g[v.fi.fi].clear(); 
				pq.push({d + v.fi.se, v.fi.fi});  
			}
			if(dis[v.fi.fi] == d + v.fi.se) 
				g[v.fi.fi].pb(v.se); 
		}
	}
	for(int i = 1; i <= n; i++) 
		for(auto x : g[i]) 
			vis[x] = 1; 
}

signed main()
{
	cin >> n >> m; 
	for(int i = 1; i <= m; i++) {
		int u, v, w; 
		cin >> u >> v >> w; 
		adj[u].pb({{v, w}, i}); 
		adj[v].pb({{u, w}, i}); 
	}
	for(int i = 1; i <= n; i++) dijk(i); 
	int ans = 0; 
	for(int i = 1; i <= m; i++) 	
		ans += (!vis[i]); 
	cout << ans; 
}


Measured memory_bytes: 384
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});

reader.on("close", function() {
  var numN: number = Number(lines[0]);

  var redPoints: { x: number; y: number; isMatch: boolean }[] = [];
  for (var i = 1; i < numN + 1; i++) {
    redPoints.push({
      x: Number(lines[i].split(" ")[0]),
      y: Number(lines[i].split(" ")[1]),
      isMatch: false
    });
  }

  var bluePoints: { x: number; y: number; isMatch: boolean }[] = [];
  for (var i = numN + 1; i < lines.length; i++) {
    bluePoints.push({
      x: Number(lines[i].split(" ")[0]),
      y: Number(lines[i].split(" ")[1]),
      isMatch: false
    });
  }

  // sort redPoints order by y desc
  redPoints.sort((a, b) => {
    return b["y"] < a["y"] ? -1 : 1;
  }); // sort bluePoints order by x asc
  bluePoints.sort((a, b) => {
    return b["x"] < a["x"] ? 1 : -1;
  });

  // console.log(redPoints);
  // console.log(bluePoints);
  var result: number = 0;
  for (var i = 0; i < numN; i++) {
    if (!bluePoints[i].isMatch) {
      for (var j = 0; j < numN; j++) {
        if (!redPoints[j].isMatch) {
          if (
            redPoints[j].x < bluePoints[i].x &&
            redPoints[j].y < bluePoints[i].y
          ) {
            // console.log("Pair:", redPoints[j], bluePoints[i]);
            redPoints[j].isMatch = true;
            bluePoints[i].isMatch = true;
            result++;
            break;
          }
        }
      }
    }
  }
  console.log(result);
});


Measured memory_bytes: 7868
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char asqw[1000];
    int t,i;
    while(gets(asqw))
    {
        t=0;
        for(i=0;i<4;i++)
        {
            if(asqw[i]=='+')
                t++;
            if(asqw[i]=='-')
                t--;
        }
        printf("%d\n",t);
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
typedef long long ll;
#include<vector>
#define pb push_back

using namespace std;
#define rep(i, a, b) for(int i=(a); i<(b); i++)
int main(){
  string S;
  vector<ll> result;
  cin >> S;
  result.resize(S.size());
  ll Nr=0,Nl=0;
  ll l_index=0;
  S.append("R");
  rep(i,0,S.size()){
    if(S[i] == 'R'){
      Nr++;
      if(l_index > 0 && Nl>0){
	result[l_index-1]+= Nl/2;
	result[l_index] += Nl/2+ Nl%2;
	Nl=0;
      }
      if(Nl==1) Nl=0;
    }
    if(S[i] == 'L'){
      if(Nl==0) l_index = i;
      Nl++;
      if(Nr > 0){
	result[i]  += Nr/2;
	result[i-1] += Nr/2+ Nr%2;
	Nr=0;
      }
    }
  }
  rep(i,0,result.size()){
    cout << result[i] << endl;
  }
}


Measured memory_bytes: 1408
data class Node(
        val value: Int,
        var prev: Node?,
        var next: Node?
)

class DoublyLinkedList() {
    private var start: Node? = null
    private var last: Node? = null
    private var size: Int = 0

    fun insert(x: Int) {
        val node = Node(x, null, start)
        when (size) {
            0 -> {
                start = node
                last = node
            }
            else -> {
                start?.prev = node
                start = node
            }
        }
        size++
    }

    fun delete(x: Int) {
        if (size != 0) {
            var node = start
            while (node != null) {
                if (node.value == x) {
                    node.prev?.next = node.next
                    node.next?.prev = node.prev
                    if (node.prev == null) {
                        start = node.next
                    }
                    if (node.next == null) {
                        last = node.prev
                    }
                    size--
                    break
                }
                node = node.next
            }
        }
    }

    fun deleteFirst() {
        when (size) {
            0 -> return
            1 -> {
                start = null
                last = null
                size--
            }
            else -> {
                start = start?.next
                start?.prev = null
                size--
            }
        }
    }

    fun deleteLast() {
        when (size) {
            0 -> return
            1 -> {
                start = null
                last = null
                size--
            }
            else -> {
                last = last?.prev
                last?.next = null
                size--
            }
        }
    }

    override fun toString(): String {
        var node = start
        val b = mutableListOf<Int>()
        while (node != null) {
            b.add(node.value)
            node = node.next
        }
        return b.joinToString(" ")
    }
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val l = DoublyLinkedList()
    for (x in 1..n) {
        val ss = readLine()!!.split(" ")
        val command = ss[0]
        when (command) {
            "insert" -> l.insert(ss[1].toInt())
            "delete" -> l.delete(ss[1].toInt())
            "deleteFirst" -> l.deleteFirst()
            "deleteLast" -> l.deleteLast()
        }
    }
    println(l.toString())
}



Measured memory_bytes: 315972
# -*- coding: utf-8 -*-
S = int(input())

dp = [0]*(S+1)
dp[0] = 1
for i in range(1, S+1):
  for j in range(0, (i-3)+1):
    dp[i] += dp[j]
    dp[i] %= 10**9 + 7
print(dp[S])

Measured memory_bytes: 64672
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
#include <map>
#include <list>
#include <bitset>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

Int solve(string s){
    Int ans = 0;
    char c = 'C';
    for(auto a: s){
        if(a != c){
            ans++;
            c = a;
        }
    }
    return ans - 1;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    cout << solve(s) << "\n";

    return 0;
}


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

int main() {
    int ans = 0;
    int N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N + 1, 0), B(M);
    rep(i, N) { cin >> A[i + 1]; }
    rep(i, M) { cin >> B[i]; }
    rep(i, N) { A[i + 1] += A[i]; }
    rep(i, M - 1) { B[i + 1] += B[i]; }
    rep(i, N + 1) {
        if(A[i] <= K) {
            ll x = K - A[i];
            auto it = upper_bound(B.begin(), B.end(), x);
            int index = it - B.begin();
            ans = max(ans, i + index);
        } else
            break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6424
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int e=0;
  char A[11];
  char A2[1001];
  scanf("%s",&A);
  for(c=0;c<strlen(A);c++){
    if(isupper(A[c])){
      A[c]=tolower(A[c]);
    }
  }
  while(1){
    scanf("%s",&A2);
    if(strcmp(A2,"END_OF_TEXT")==0)break;
    for(b=0;b<strlen(A2);b++){
      if(isupper(A2[b])){
    A2[b]=tolower(A2[b]);
      }
    }
    if(strcmp(A,A2)==0){
      a=a+1; 
    }
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 2060