akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = (1e-10);
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int check(string::iterator &itr) {
    char state[] = {'m', 'e', 'w'};
    int crtState = 0;

    while (*itr != 'T' && crtState < 3) {
        if (state[crtState] == *itr) {
            crtState++;
            itr++;
        } else {
            if (*itr == 'm') {
                if (!check(itr)) return 0;
            } else {
                return 0;
            }
        }
    }
    if (crtState == 3) return 1;
    else return 0;
}

int main(void) {
    string S;
    cin >> S;
    S.push_back('T');
    auto itr = S.begin();
    if (!check(itr) || *itr != 'T') {
        cout << "Rabbit" << endl;
        return 0;
    } 
    cout << "Cat" << endl;
    return 0;
}




Measured memory_bytes: 3224
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	k := nextInt()
	s := nextString()

	ans := func() string {
		if len(s) <= k {
			return s
		}
		s = s[:k] + "..."
		return s
	}()

	fmt.Println(ans)
}


Measured memory_bytes: 1756
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////
int f[100005];
int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int l, r;
        cin >> l >> r;
        f[l]++;f[r+1]--;
    }
    for(int i=0;i<100004;i++){
        f[i+1] += f[i];
    }
    // for(int i=1;i<=n;i++){
    //     cerr << f[i] << " ";
    // }cerr << endl;
    int r = 0;
    for(int i=1;i<=n;i++){
        if(f[i] == m)r++;
    }
    cout << r << endl;
    return 0;
}


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

int main() {
  string S; cin >> S;
  int n = 1;
  for (int i = 1; i < S.size(); i++) if (S[i] != S[i - 1]) n++;
  cout << n - 1 << endl;
  return 0;
}

Measured memory_bytes: 512
s = gets.strip.split("")
flag = true
(1..s.length).each do |i|
  if i.even?
    if s[i-1] == "R"
      flag = false
      break
    end
  else
    if s[i-1] == "L"
      flag = false
      break
    end
  end
end

if flag
  puts 'Yes'
else
  puts 'No'
end

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

m = N
x = 26
cnt = 0
while True:
    cnt += 1
    if m <= x:
        break
    m -= x
    x *= 26

m -= 1
ofs = ord('a')
c = []
while cnt:
    y = m % 26
    c.append(chr(y+ofs))
    m //= 26
    cnt -= 1


print(''.join(c[::-1]))


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++) cin >> A[i];
  int64_t sum = 0;
  for(int i = 0; i < N; i++) sum += A[i];
  int64_t sum1 = 0;
  int D = 0;
  for(int j = 0; j < (N+1)/2; j++) {
    sum1 += A[D];
    D += 2;
  }
  int64_t x1 = 2 * sum1 - sum;
  cout << x1 << endl;
  for(int i = 0; i < N - 1; i++) {
    x1 = 2 * A[i] - x1;
    cout << x1 << endl;
  }
  cout << endl;
}

Measured memory_bytes: 1664
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    item = [tuple(map(int,input().split())) for _ in range(N)]
    dp = [0] * (W + 1)
    for v,w in item:
        for j in range(W,w - 1,-1):
            dp[j] = max(dp[j],dp[j - w] + v)
    print(dp[-1])
if __name__ == '__main__':
    main()



Measured memory_bytes: 5924
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    REP(i, N) cin>>A[i];
    ll X = 0;
    REP(i, N){
        if(i%2) X+= -A[N-1-i];
        else X+= A[N-1-i];
    }
    ll l=0, r=MOD;
    vector<ll> res(N);
    while(l<r){
        ll m = (r+l)/2;
        ll y = X -m;
        if(y==m){
            res[0] = m;
            break;
        }
        if(y>m){
            l=m+1;
        } // y<ty
        else{
            r=m;
        }
    }
    for(ll i=1; i<N; i++){
        res[i] = A[i-1] - res[i-1];
    }
    REP(i, N) res[i] *= 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3712
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		//String[] s = S.split("");
		int k = Integer.parseInt(sc.next());
		ArrayList<String> list = new ArrayList<>();
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<S.length(); i++) {
		    for(int j=i; j<=Math.min(S.length(), i+k); j++) {
		        String x = S.substring(i, j);
		        if(list.contains(x)) continue;
		        else list.add(x);
		    }
		}
		Collections.sort(list);
		System.out.println(list.get(k));
	}
}

Measured memory_bytes: 24148
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let (a, b, _c, k) = (
        it.next().unwrap(),
        it.next().unwrap(),
        it.next().unwrap(),
        it.next().unwrap(),
    );
    if k <= a {
        println!("{}", k);
    } else if k <= a + b {
        println!("{}", a);
    } else {
        println!("{}", a - (k - a - b));
    }
}


Measured memory_bytes: 2072
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll mod = 1e9+7;
ll dp[22][(1<<22)];

ll fun( vector< vector<ll>> &comp, ll N, ll i, ll woman_bit)
{
    //Base case
    if(i == N+1)
    {
        if(woman_bit == 0)
        return 1;
        return 0;
    }
    
    //Lookup
    if(dp[i][woman_bit] != -1)
    return dp[i][woman_bit];
    
    //Rec case
    ll ans = 0;
    for(ll w=0;w<N;w++)
    {
        bool is_avail = ( ((1<<w) & woman_bit) != 0) ? 1 : 0;
        
        if(is_avail && comp[i][w+1])
        {
            ans += fun( comp,N,i+1, (woman_bit ^ (1<<w)));
            ans %= mod;
        }
    }
    return dp[i][woman_bit] = ans;
}

int main()
{
    fast_io;
    
    ll N;
    cin>>N;
    
    vector< vector<ll>> comp(N+1, vector<ll>(N+1));
   //int comp[22][22];
    for(ll i=1;i<=N;i++)
    {
        for(ll j=1;j<=N;j++)
        cin>>comp[i][j];
    }
    
    memset(dp,-1,sizeof(dp));
    cout<<fun(comp,N,1,(1<<N)-1)<<endl;
    
    return 0;
}






Measured memory_bytes: 721280
long = int(input())
p = input()
plng = []
pstr = p.split(" ")
n = 0

for i in range(long):
    plng.append(int(pstr[i]))



for i in range(long-2):
    three = [plng[i],plng[i+1],plng[i+2]]
    three.sort()

    if three[1] == plng[i + 1]:
     n = n + 1

print(n)


Measured memory_bytes: 3060
#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(void){
    int H1,H2,M1,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    

    cout << (H2 * 60 + M2) - (H1 * 60 + M1) - K << endl;

    return 0;
}

Measured memory_bytes: 3632
function main(argString) {
  	var input = argString.split(' ').map(v => Number(v));
  	console.log(...loop(input[0], input[1]));
}

function loop(N, Y) {
  	for (var i = 0; i <= N; i++) {
      	for (var k = 0; k <= N - i; k++) {
        	var m = N - i - k;
        	if ((i + k + m) === N && (i * 10000 + k * 5000 + m * 1000) === Y) return [i, k, m];
        }
    }
  	return [-1, -1, -1];
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
	ll n,h;
	cin >> n >> h;
	vector<ll> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	ll ans = 0;
	ll damage = 0;
	while(b[ans] > a[0]) {
		damage += b[ans];
		ans++;
		if (damage >= h) break;
		if (ans >= n) break;
	}
	if (damage < h) ans += (h - damage + a[0] - 1) / a[0]; 
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.Arrays;

public class Main
{
	public static void main(String[] args)
	{
		final int MAXNUM = 1000000;		
		int[] ptable = new int[MAXNUM];
		Arrays.fill(ptable, 1);
		ptable[0]=ptable[1]=0;
		
		for(int i=2; i*i<MAXNUM; i++)
		{
			if(ptable[i] == 1)
			for(int j=i*i; j<MAXNUM; j+=i)
			{
				ptable[j]=0;
			}
		}
		
		int num = 0;
		for(int i=0; i<MAXNUM; i++)
		{
			num+=ptable[i];
			ptable[i] = num;
		}
		
		Scanner cin = new Scanner(System.in);
		
		while(cin.hasNext())
		{
			num = cin.nextInt();
			System.out.println(ptable[num]);
		}
	}
}

Measured memory_bytes: 15000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string n;
    cin >> n;
    int ans = 0;
    rep(i,4){
        if(n[i]=='2') ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
template<class T>
using V = vector<T>;
template<class T>
using VV = vector<vector<T>>;
typedef unsigned long long ULL;

void input();
void solve();

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

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

int N;
VI H;

void input() {
	cin >> N;
	H.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> H[n];
	}
}

void solve() {
	int ans = 1;
	for (int n = 1; n < N; n++) {
		bool flag = true;
		for (int s = 0; s < n; s++) {
			if (H[s] > H[n])flag = false;
		}
		if (flag)ans++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3176
x,y,a,b,c=map(int,input().split())
p=[0]*a
q=[0]*b
r=[0]*c
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
List=[]
newp=sorted(p,reverse=True)
newq=sorted(q,reverse=True)
for i in range(max(x,y,c)):
  if (i<x):
    List.append(newp[i])
  if (i<y):
    List.append(newq[i])
  if (i<c):
    List.append(r[i])

#print(List)
ans=sorted(List,reverse=True)
print(sum(ans[:x+y]))

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

using namespace std;

const int N = 51;

int coorX[N], coorY[N];
int prevX[N], prevY[N];

int main(){
  int n, k;
  scanf("%d %d", &n, &k);
  for(int i = 0; i < n; ++i){
    scanf("%d %d", &coorX[i], &coorY[i]);
    prevX[i] = coorX[i];
    prevY[i] = coorY[i];
  }
  sort(coorX, coorX + n);
  sort(coorY, coorY + n);
  long long ans = (long long)(coorX[n - 1] - coorX[0]) * (long long)(coorY[n - 1] - coorY[0]); 
  for(int di = 0; di < n; ++di){
    for(int dj = di + 1; dj < n; ++dj){
      for(int hi = 0; hi < n; ++hi){
        for(int hj = hi + 1; hj < n; ++hj){
          int x_i = coorX[di];
          int x_j = coorX[dj];
          int y_i = coorY[hi];
          int y_j = coorY[hj];
          int no_can = k;
          for(int i = 0; i < n; ++i){
            if(x_i <= prevX[i] && prevX[i] <= x_j && y_i <= prevY[i] && prevY[i] <= y_j){
              no_can--;
            } 
          }
          if(!no_can){
            ans = min(ans, (long long)(x_j - x_i) * (long long)(y_j - y_i)); 
          }
        }
      }
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 998244353LL
#define mod1 1000000007LL
#define MAXN 1000002
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
vector<ll> v[200002];
ll rang[200002][2];
ll bit[200002];
ll gg=1;
void dfs(ll i,ll par){
  rang[i][0]=rang[i][1]=gg++;
  for(auto it: v[i]){
    if(it!=par){ 
      dfs(it,i);
      rang[i][1]=max(rang[it][1],rang[i][1]);
    }
  }
}
ll n;
void sett(ll i,ll x){
  for(;i<=n;i+=(i&(-i))) bit[i]+=x;
}
ll get(ll i){
  ll ret=0;
  for(;i>0;i-=(i&(-i))) ret+=bit[i];
    return ret;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,q;
    cin>>n>>q;
    for(i=0;i<n-1;i++){
      ll x,y;
      cin>>x>>y;
      v[x].pb(y);
      v[y].pb(x);
    }
    dfs(1,-1);
    while(q--){
      ll p,x;
      cin>>p>>x;
      sett(rang[p][0],x);
      sett(rang[p][1]+1,-x);
    }
    for(i=1;i<=n;i++)
      cout<<get(rang[i][0])<<" ";

    return 0;
}

Measured memory_bytes: 30336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
typedef vector<int > vi;
int p = 1e9+7;
ll exp(int a,int b){
	if(b==0)return 1;
	ll tde = exp(a,b/2);
	tde = (tde*tde)%p;
	if(b%2!=0)tde = (tde*a)%p;
	return tde;
}
int main(){
	int n;
	cin>>n;
	//number of integer seq of length n
	//such that it contains atleast one 0 and one 9
	//nC2*2 - ()
	ll a1 = (2*exp(9,n))%p;
	ll a2 = (a1-exp(8,n)+p)%p;
	ll a3 = (exp(10,n)-a2+p)%p;
	cout<<a3;
	
}


Measured memory_bytes: 3672
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

double xx[3], yy[3], x, y;

void solve(){
	double v1[2], vp[2];
	bool sign[3];
	rep(i,3){
		v1[0]=xx[(i+1)%3]-xx[i];
		v1[1]=yy[(i+1)%3]-yy[i];
		vp[0]=x-xx[i];
		vp[1]=y-yy[i];
		
		if(v1[0]*vp[1] - v1[1]*vp[0]>0)sign[i]=true;
		else sign[i]=false;
	}
	if((sign[0]&&sign[1]&&sign[2]) || (!sign[0]&&!sign[1]&&!sign[2]))puts("YES");
	else puts("NO");
}

int main(){
	
	while(cin>>xx[0]){
		cin>>yy[0]>>xx[1]>>yy[1]>>xx[2]>>yy[2]>>x>>y;
		solve();
	}
	
	return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

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

int main(){

    ll a, b; cin >> a >> b;

    cout << a*b/gcd(a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
num_input = int(input())
set_of_nine = set()

for i in range(9, 100, 10):
    set_of_nine.add(i)

for tmp in range(90, 100, 1):
    set_of_nine.add(tmp)

if num_input in set_of_nine:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9032
import java.util.Scanner;

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

	int w = sc.nextInt();
	int a = sc.nextInt();
	int b = sc.nextInt();

	System.out.println(Math.abs(a - b) <= w ? 0 : Math.abs(a - b) - w);

	sc.close();
	}

}


Measured memory_bytes: 21716
package main

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

type graph [][]int

var (
	g     graph
	count []int
	xs    []int
)

func dfs(now, prev, sum int) {
	sum += xs[now]
	count[now] = sum

	for _, next := range g[now] {
		if next == prev {
			continue
		}

		dfs(next, now, sum)
	}
}

func main() {
	n, q := getInt(), getInt()
	g = make(graph, n)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		a, b := getInt()-1, getInt()-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	xs = make([]int, n)
	for i := 0; i < q; i++ {
		p, x := getInt()-1, getInt()
		xs[p] += x
	}

	count = make([]int, n)
	dfs(0, -1, 0)

	for _, c := range count {
		fmt.Println(c)
	}
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 49536
from sys import stdin
H, W = [int(x) for x in stdin.readline().rstrip().split()]
sa = 0
sb = 0
sc = 0
ans = 10**9

for h in range(1, H):
    sa = h*W
    sb = (H-h)*(W//2)
    sc = (H-h)*(W-(W//2))
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for w in range(1, W):
    sa = H*w
    sb = (W-w)*(H//2)
    sc = (W-w)*(H-(H//2))
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for h in range(1, H):
    sa = h*W
    sb = ((H-h)//2)*W
    sc = ((H-h)-((H-h)//2))*W
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for w in range(1, W):
    sa = H*w
    sb = ((W-w)//2)*H
    sc = ((W-w)-((W-w)//2))*H
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

print(ans)

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

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

ll N;
ll A[202020];

ll i, j, k;

int main(){
    scanf("%lld",&N);
    
    rep(i,0,N){
        scanf("%lld", &A[i]);
    }

    k = 0;
    rep(i,1,N){
        j = max(j + A[i - 1] - A[i], 0ll);
        k += j;
    }
    printf("%lld\n", k);

    return 0;
}

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

int main() {
	int N;
	cin >> N;
  	string S;
  	cin >> S;
  
  if( N % 2 == 1 ) cout << "No" << endl;
  else if( S.substr(0, N/2) == S.substr(N/2, N-1)) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c;
  d =  c-(a-b)>0 ? c-(a-b):  0;
  cout << d ;}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N, M;
ll dp[MAX/10];
set<ll> s;
ll c[]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

void rec(ll n, ll len) {
    if(n==0) return;
    ll i;
    ll max=0;
    for(set<ll>::iterator it=s.begin(); it!=s.end(); it++) {
        i=*it;
        if(n<c[i]) continue;
        if(dp[n-c[i]]==len-1) chmax(max, i);
    }
    cout << max;
    rec(n-c[max], len-1);
}

int main(void) {
    cin >> N >> M;
    ll i, j;
    
    for(i=0; i<M; i++) {
        ll a;
        cin >> a;
        s.insert(a);
    }
    
    memset(dp, -1, sizeof(dp));
    dp[0]=0;
    for(i=0; i<=N; i++) {
        if(dp[i]==-1) continue;
        for(set<ll>::iterator it=s.begin(); it!=s.end(); it++) {
            j=*it;
            if(i+c[j]<=N) chmax(dp[i+c[j]], dp[i]+1);
        }
    }
    
    rec(N, dp[N]);
    cout << "\n";
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll t[100010];
int main(){
    ll n, c, k;
    cin >> n >> c >> k;
    rep(i, n) cin >> t[i];

    sort(t, t + n);

    ll cnt = 0;
    ll head = t[0];
    ll ans = 1;
    int i = 0;
    while(i < n){
        if (head + k >= t[i] && cnt < c){
            cnt++;
            i++;
        }
        else if (head + k < t[i] || cnt >= c){
            ans ++;
            cnt = 1;
            head = t[i];
            i++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int main() {
	cin>>s;
	if (s=="SSS") puts("0");
	else if (s=="SSR") puts("1");
	else if (s=="SRS") puts("1");
	else if (s=="RSS") puts("1");
	else if (s=="SRR") puts("2");
	else if (s=="RRS") puts("2");
	else if (s=="RSR") puts("1");
	else puts("3");
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	ll N; cin >> N;
	ll a[10010], b[10010];
	ll asum, bsum;
	asum = 0; bsum = 0;
	REP(i, N) {
		cin >> a[i];
		asum += a[i];
	}
	REP(i, N) {
		cin >> b[i];
		bsum += b[i];
	}
	if (asum > bsum) {
		cout << "No" << endl;
		return 0;
	}
	ll diff = bsum - asum;
	ll cnt = 0;
	REP(i, N) {
		if (b[i] > a[i]) {
			cnt += (b[i] - a[i]+1) / 2;
		}
	}
	if (cnt > diff) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

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

#define ff first
#define endl "\n"
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fr(i,x,n) for(ll i=x;i>=n;i--)
inline ll min(ll a, ll b, ll c) { return min(min(a, b), c);}
inline ll max(ll a, ll b, ll c) { return max(max(a, b), c);}
inline void fastio(){ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);}

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



int main(){
	fastio();

	int a,b; cin>>a>>b;
	if(a>b){
		f(i,1,a) cout<<b;
	}
	else{
		f(i,1,b) cout<<a;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
INF = 10 ** 9
MOD = 10 ** 9 + 7

def main(): 
    n,k = map(int,input().split())
    
    if k > (n-1)*(n-2)//2:
        print(-1)
        exit()
    
    print(n*(n-1)//2 - k)
    for i in range(2,n+1):
        print(1,i)
    
    x = (n-1)*(n-2)//2 - k
    i = 2
    j = 3
    while x > 0:
        x -= 1
        print(i,j)
        j += 1
        if j == n + 1:
            i += 1
            j = i + 1
   
if __name__=='__main__':
    main()


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 5;

int main()
{
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());
  vector<int> d;
  for (int i = 0; i < x; i++) {
    d.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    d.push_back(q[i]);
  }
  for (int i = 0; i < c; i++) {
    d.push_back(r[i]);
  }
  sort(d.begin(), d.end(), greater<int>());
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += d[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

string s[12];
int dx[4] = {1,0,-1,0}; 
int dy[4] = {0,1,0,-1};

void dfs(int x,int y)
{
	s[x][y] = '0';

	rep(i,4)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(0 <= nx && nx < 12 && 0 <= ny && ny < 12)
		{
			if(s[nx][ny] == '1')
			{
				dfs(nx,ny);
			}
		}
	}
	return;
}


int main()
{
	while(cin >> s[0])
	{
		REP(i,1,12)
		{
			cin >> s[i];
		}

		int res = 0;
		rep(i,12)
		{
			rep(j,12)
			{
				if(s[i][j] == '1')
				{
					dfs(i,j);
					res++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
s = input()
K = int(input())

substr = []
for i in range(len(s)):
    for j in range(i+1, i+K+1):
        if len(s) >= K:
            substr.append(s[i:j])
        else:
            if j == len(s)+1:
                break
            substr.append(s[i:j])

substr = list(set(substr))
substr.sort()

print(substr[K-1])

Measured memory_bytes: 41020
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define N         100005
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
    
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
} 
ll n,a[17][17]; vector<ll> dp(1<<17,0),dd(1<<17,-1);
ll maxi(ll p,ll q,ll r,ll s,ll t,ll u)
{
	return max(p,max(q,max(r,max(s,max(t,u)))));
}
ll count(ll x)
{
	ll m=0;
	if(x==0)
	return dd[0]=0;
	if(x==1)
	return dd[1]=dp[1];
	if(dd[x]!=-1)
	return dd[x];
	rep(i,1,x)
	{
	    ll aa=count(i);
	    ll bb=count(x-i);
		m=maxi(m,dp[i]+dp[x-i],dp[i]+bb,dp[x-i]+aa,aa+bb,dp[x]);
	}
	return dd[x]=m;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
//	cout<<setprecision(12)<<fixed;
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,first,last,x,k;
    	cin>>n;
    	rep(i,0,n)
    	{
    		rep(j,0,n)
    		{
    			cin>>a[i][j];
			}
		}
		rep(mask,1,1<<n)
		{
			rep(i,0,n)
			{
				if(mask & 1<<i)
				{
					rep(j,i+1,n)
					{
						if(mask & 1<<j)
						dp[mask]+=a[i][j];
					}
				}
			}
		}
		rep(mask,1,1<<n)
		{
			for(j=mask;j>0;j=(j-1)&mask)
			dp[mask]=max(dp[mask],dp[j]+dp[mask^j]);
		}
 		cout<<dp[(1<<n)-1];
	}
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double R;
    cin >> R;

    double ans = 2 * R * 3.1415926535;
    printf("%f\n", ans);
    return 0;
}

Measured memory_bytes: 3768
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include<bits/stdc++.h>
#include<iomanip>
#define inf  (int)1e18
#define EPS   1e-9
#define MOD 1000000007
#define all(k) sort(k.begin(),k.end())
#define Pi 3.14159
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define repk(i,a,n) for(ll i=a;i<=(n);i++)
#define ll  long long
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vi vector<int>
#define mi map<int,int>
#define ml map<ll,ll>
#define umap unordered_map<ll,int>
using namespace std;

void sol() {

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	set<ll> s;
	s.insert(a * c);
	s.insert(a * d);
	s.insert(b * c);
	s.insert(b * d);

	cout << *max_element(s.begin(), s.end());

}

int main() {


	int t = 1;


	// cin >> t;
	for (int i = 0; i < t; ++i) {
		sol();

	}


	return 0;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    long long ans = LLONG_MAX;
    for(int i=0; i<(1<<n); ++i){
        bitset<15> bs(i);
        if(bs.count() != k)
            continue;

        long long cost = 0;
        int h = 0;
        for(int i=0; i<n; ++i){
            if(bs[i]){
                cost += max(0, h + 1 - a[i]);
                h = max(h+1, a[i]);
            }
            else{
                h = max(h, a[i]);
            }
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

struct Edge {
  int from;
  int to;
};

vector<vector<Edge>> G;

int main() {
  int N, M;
  cin >> N >> M;
  G.resize(N);
  for (int i = 0; i < M; i++) {
    int from, to;
    cin >> from >> to;
    from--;
    to--;
    G[from].push_back({from, to});
    G[to].push_back({to, from});
  }

  vector<bool> visits(N, false);
  vector<int> prev(N, -1);

  queue<int> Q;
  Q.push(0);
  visits[0] = true;

  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();

    for (const auto& e : G[v]) {
      if (visits[e.to]) continue;
      Q.push(e.to);
      visits[e.to] = true;
      prev[e.to] = v;
    }
  }

  bool ok = true;
  for (int v = 0; v < N; v++) {
    if (!visits[v]) {
      ok = false;
      break;
    }
  }

  if (ok) {
    cout << "Yes" << endl;
    for (int v = 1; v < N; v++) {
      cout << prev[v] + 1 << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 12448
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int N,M;
int A[200000];
int B[200000];//i番目に木を植えるとB[i]番目から植えられる
LL dp[200000];

LL solve(int now){
	if(now == N) return 0;
	if(dp[now] != -1) return dp[now];
	return dp[now] = max(solve(now+1), A[now]+solve(B[now]));
}

int main(){
    iostream::sync_with_stdio(false);
    
	cin >> N >> M;
	for(int i=0; i<N; i++) cin >> A[i];
	vector<pair<int,int> > RL;
	for(int i=0; i<M; i++){
		int r,l;
		cin >> l >> r;
		r--;l--;
		RL.push_back(MP(r,l));
	}
	sort(RL.begin(), RL.end());
	reverse(RL.begin(), RL.end());

	for(int i=0; i<N; i++){
		B[i] = i+1;
		dp[i] = -1;
	}
	int tmp = N-1;//oldl
	for(int i=0; i<M; i++){
		int l = RL[i].second;
		int r = RL[i].first;
		for(int j=l; j<min(r,tmp); j++){
			B[j] = r+1;
		}
		tmp = min(tmp,l);
	}

	cout << solve(0) << endl;
    
    return 0;
}



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

using namespace std;
typedef long long ll;


int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    ll h[n], ans = 0;
    cin >> h[0];
    ll tmp = h[0];
    for (int i = 1; i < n; i++) {
        cin >> h[i];
        ans += max(0LL,tmp-h[i]);
        tmp = max(tmp,h[i]);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 5172
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int num= scan.nextInt();
int numm=scan.nextInt();
int sum=0;

if(num==3){
    sum=sum+100000;
}
if(num==2){
    sum=sum+200000;
}
if(num==1){
    sum=sum+300000;
}
if(numm==3){
    sum=sum+100000;
}
if(numm==2){
    sum=sum+200000;
}
if(numm==1){
    sum=sum+300000;
}
if(num==1&&numm==1){
    sum=sum+400000;
}
System.out.println(sum);
}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=sqrt(n);++i){
        if(n%i)continue;
        ll tmp=n/(i+1)+1;
        ll up=n/i;
        if(up-1>=tmp)
            ans+=up-1;
        else break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
input_num = int(input())
sequence = '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'
list = sequence.split(',')
term = list[input_num - 1]
print(int(term))

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, k;
    cin >> n >> k;
    int max_num = n - k;
    if ( k == 1 ) cout << 0 << endl;
    else          cout << max_num << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{

    class Program
    {
        class Node {
            internal bool visted;
            internal List<int> adj;
            internal int d, f;
            public Node() {
                d = f = 0;
                adj = new List<int>();
                visted = false;
                
            }
        }
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Node[] nodes = new Node[n + 1];
            for (int i = 0; i < n; i++)
            {
                int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                nodes[temp[0]] = new Node();
                for (int k = 0; k < temp[1]; k++)
                {
                    nodes[temp[0]].adj.Add(temp[k + 2]);
                }
            }
            for (int i = 1; i <= n; i++)
                BFS(nodes, i);

            for (int i = 1; i <= n; i++)
                Console.WriteLine(i + " " + nodes[i].d);

        }

        static void BFS(Node[] nodes, int pos) {
            Queue<int[]> q = new Queue<int[]>();
            HashSet<int> visted = new HashSet<int>();
            q.Enqueue(new int[2]{ 1, 0});
            while (q.Count > 0) {
                int[] curr = q.Dequeue();
                visted.Add(curr[0]);
                if (curr[0] == pos)
                {
                    nodes[pos].d = curr[1];
                    return;
                }
                for (int i = 0; i < nodes[curr[0]].adj.Count; i++)
                    if(!visted.Contains(nodes[curr[0]].adj[i])) q.Enqueue(new int[2] { nodes[curr[0]].adj[i], curr[1] + 1 });
            }

            nodes[pos].d = -1;
        }
		
    }
}




Measured memory_bytes: 39088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    ll h = readll();
    ll w = readll();
    if (h == 1 || w == 1)
    {
        printf("1\n");
        return 0;
    }
    ll ans = 0ll;
    ans += h / 2ll * w;
    if (h & 1)
    {
        ans += w / 2ll;
        if (w & 1)
        {
            ans++;
        }
    }
    printf("%lld\n", ans );
    return 0;
}




Measured memory_bytes: 256
n,k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

if a[0] == 1
  p 1
  exit
end

a.unshift(nil)

cicle = 0
flags = Array.new(n+1, false)

i = 1
now = 1
fi = 0
loo = 0
while true
  ne = a[now]
  if flags[ne]
    fi = flags[ne]
    loo = i - flags[ne]
    break
  end
  flags[ne] = i
  now = ne
  i += 1
end

if k < fi
  now = 1
  ne = nil
  1.upto(k) do |j|
    ne = a[now]
    now = ne
  end
  p now
  exit
end

tar = ((k-fi) % loo) + fi

now = 1
ne = nil
1.upto(tar) do |j|
  ne = a[now]
  now = ne
end
p now


Measured memory_bytes: 31008
import java.util.*;

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

        int N = sc.nextInt();
        int n = N;
        int K = sc.nextInt();
        int ans = 0;
        if(n>=K){
            for(int i=1; i<n; i++){
                ans = i;
                if(N/K<K){
                    ans = i + 1;
                    break;
                }
                N = (int)N / K;
            }
        
            System.out.println(ans);
        }
        else if(n<K){
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
#include<cmath>
#include<algorithm>
using namespace std;

int main(void)
{
	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> student(N);
	for(int i=0; i<N; i++)
	{
		int a, b;
		cin >> a >> b;

		student[i] = make_pair(a, b);
	}

	vector<pair<int, int>> point(M);
	for(int i=0; i<M; i++)
	{
		int c, d;
		cin >> c >> d;

		point[i] = make_pair(c, d);
	}

	vector<vector<int>> d(N, vector<int>(M));
	for(int i=0; i<N; i++)
		for(int j=0; j<M; j++)
			d[i][j] = abs(student[i].first - point[j].first) + abs(student[i].second - point[j].second);

	for(int i=0; i<N; i++)
		cout << min_element(d[i].begin(), d[i].end()) - d[i].begin() + 1 << endl;

	return 0;
}


Measured memory_bytes: 256