akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	vector<int> arr(n);
	for(int i=0;i<n;i++)scanf("%d",&arr[i]);
	vector<int> dp(k+1);
	dp[0]=1;
	for(int i=1;i<=k;i++){
		int x,v=1;
		for(int j=0;j<n;j++){
			x=arr[j];
			if(i-x>=0&&dp[i-x]==1){
				v=0;
			}
		}
		dp[i]=v;
		//cout<<dp[i]<<" ";
	}
	if(dp[k]==0)puts("First");
	else puts("Second");
	
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int a[N];
int m, M;
int n;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    M = 0;
    m = n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        m = min(m, a[i]);
        M = max(M, a[i]);
    }
    if (m + 1 < M) {
        printf("No\n");
        return 0;
    }
    if (m + 1 == M) {
        int cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == m)
                cnt1++;
            else
                cnt2++;
        }
        if (cnt2 == 1) {
            printf("No\n");
            return 0;
        }
        int l = cnt1 + 1, r = cnt1 + (cnt2 / 2);
        if (l <= M && M <= r)
            printf("Yes\n");
        else
            printf("No\n");
        return 0;
    }

    if (m == n - 1) {
        printf("Yes\n");
        return 0;
    }
    if (m <= n / 2) {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int ans = 0;
		if (x >= 0 && y > 0) {
			if (y >= x) {
				ans = y - x;
			} else if (y < x) {
				ans = x - y + 2;
			}
		} else if (x < 0 && y <= 0) {
			if (y <= x) {
				ans = Math.abs(x - y) + 2;
			} else {
				ans = Math.abs(x - y);
			}
		} else {
			ans = Math.abs(x + y) + 1;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;


int main(void) {
    string n;
    cin >> n;
    Int len = (Int)n.length();
    Int count = 0;
    for (Int i = 0; i < len; ++i) {
        if (n[i] == '2') {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a, b;
    cin>>a>>b;
    if(a.length()>b.length())
        puts("GREATER");
    else if(a.length()<b.length())
        puts("LESS");
    else if(a>b)
        puts("GREATER");
    else if(a<b)
        puts("LESS");
    else
        puts("EQUAL");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
const int mod = 1000000007;
typedef long long ll;
struct mint
{
  ll x; //
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

vector<long long> enum_divisor(long long n)
{
  vector<long long> dst;
  for (long long i = 1; i * i <= n; i++)
  {
    if (n % i != 0)
      continue;
    dst.push_back(i);
    if (i * i != n)
      dst.push_back(n / i);
  }
  return dst;
}

int main()
{
  int N, K;
  cin >> N >> K;
  mint ans = 0;
  vector<mint> count(K + 1, 0);
  for (int i = K; i >= 1; i--)
  {
    mint a = K / i;
    mint cnt = a.pow(N) - count[i];
    ans += cnt * i;

    vector<long long> ed = enum_divisor(i);
    rep(j, ed.size())
    {
      count[ed[j]] += cnt;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4048
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const int MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }

int main() {
    int x, y;
    cin >> x >> y;
    cout << gcd(x,y) << endl;

    return 0;
}


Measured memory_bytes: 3100
package main
import (
	"bufio"
	"fmt"
	"io"
	"os"
	"runtime/debug"
	"sort"
	"strconv"
)
var in = NewScanner(os.Stdin, 0)
func main(){
	debug.SetGCPercent(-1)
	N := in.Int()
	a, b := in.ArrayInt(N), in.ArrayInt(N)
	t := 0
	ans := 0
	c := make([]int, N)
	for i := 0; i < N; i++{
		c[i] = b[i] - a[i]
		if c[i] > 0{
			t += c[i]
			ans++
		}
	}
	sort.Ints(c)
	for i := 0; i < N; i++{
		if c[i] < 0 && t > 0{
			t += c[i]
			ans++
		}
	}
	if t > 0{
		Pln(-1)
	} else{
		Pln(ans)
	}
}
const M7 = 1000000007
type Scanner struct{
	*bufio.Scanner
}
func NewScanner(r io.Reader, x int) *Scanner{
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if x <= 0{
		x = 1048576
	}
	s.Buffer([]byte{}, x)
	return &Scanner{s}
}
func (s *Scanner) Int() int{
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil{
		panic(e)
	}
	return int(i)
}
func (s *Scanner) ArrayInt(n int) IntSlice{
	r := make(IntSlice, n)
	for i := 0; i < n; i++{
		r[i] = s.Int()
	}
	return r
}
func isSpace(b byte) bool{
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(d []byte, e bool) (int, []byte, error){
	s := 0
	for s < len(d) && isSpace(d[s]){
		s++
	}
	for i := s; i < len(d); i++{
		if isSpace(d[i]){
			return i + 1, d[s:i], nil
		}
	}
	if e && len(d) > s{
		return len(d), d[s:], nil
	}
	return s, nil, nil
}
func Pln(s ...interface{}){
	fmt.Println(s...)
}
type ByteSlice []byte
type IntSlice []int


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

int main() {
	int N; cin >> N;

	vector<int> D(N);
	for (int i = 0; i < N; ++i) cin >> D[i];

	int sum = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = (i + 1); j < N; j++) {
			sum += D[i] * D[j];
		}
	}

	cout << sum << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n), b(n), p(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> b[i] >> p[i];
    }
    
    for(int i = 0; i < n; i++){
        int s = x[i]*b[i] + y[i]*p[i];
        if(b[i] >= 5 && p[i] >= 2){
            cout << s*4/5 << endl;
        }
        else {
            cout << min((max(5,b[i])*x[i] + max(2,p[i])*y[i])*4/5, s) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <random>
#include <complex>

#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define reset(x, y) memset(x, y, sizeof(x))
#define BUG(x) cerr << #x << " = " << (x) << endl
#define BUGP(x) cout << #x << " = " << (x)._1 << ", " << (x)._2 << endl
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
// Head

const int N = 112345;
const int MOD = 1000000007;

vector<int> G[N];
int n, k;

LL dfs(int u, int fa) {
    int num = k - 2;
    if (fa == -1) num = k - 1;

    LL ret = 1;
    for (int v : G[u]) {
        if (v == fa) continue;
        if (num < 0) { cout << 0 << '\n'; exit(0); }

        ret = ret * num % MOD;
        ret = ret * dfs(v, u) % MOD;
        --num;
    }

    return ret;
}

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

    cin >> n >> k;
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        G[x].pb(y);
        G[y].pb(x);
    }

    cout << dfs(1, -1) * k % MOD << '\n';
    return 0;
}

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

int main()
{
	int n;
	int a;
	vector<int> p;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		cin>>a;
		p.push_back(a);
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(p[i]!=i+1)cnt++;
	}
	if(cnt==2||cnt==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

int main(void){
  int N,K,Q;
  scanf("%d %d %d",&N,&K,&Q);

  int *c=(int *)malloc(sizeof(int)*N);
  
  int i,A;
  for(i=0;i<Q;i++){
    scanf("%d",&A);
    c[A-1]++;
  }
  for(i=0;i<N;i++){
    if(K+c[i]-Q<=0)
      printf("No\n");
    else
      printf("Yes\n");
  }
  
  
  //printf("%d\n",INT_MAX);
  return 0;
}


Measured memory_bytes: 2032
from operator import itemgetter
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0))
ans = 0
for i in range(N):
    ans += min(M, AB[i][1]) * AB[i][0]
    M -= min(M, AB[i][1])
    if M==0:
        break
print(ans)


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

int main () {
  int K, S; cin >> K >> S;
  
  int ans = 0;
  for (int i=0;i<=K;i++) {
    for (int j=0;j<=K;j++) {
      int k = S-i-j;
      if (0<=k && k<=K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
	w,h = map(int,input().split())
	
	A = []
	for _ in range(w):
		cmd = input()
		if cmd.count(".") != len(cmd):
			A.append(cmd)

	B = []
	for i in range(h):
		st = ""
		for a in A:
			st += a[i]
		if st.count(".") != len(st):
			B.append(st)

	#元に戻す
	C = []
	w = len(B[0])
	for j in range(w):
		st = ""
		for b in B:
			st += b[j]
		C.append(st)

	for c in C:
		print(c)

Measured memory_bytes: 9140
using System;

namespace C___Prison
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            int N = read[0];
            int M = read[1];

            int Lmax = 1;
            int Rmin = N;

            for(int i = 0 ; i < M ; i++)
            {
                var LR = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
                if(Lmax < LR[0]) Lmax = LR[0];
                if(Rmin > LR[1]) Rmin = LR[1];
            }
            var result = Lmax <= Rmin ? Rmin-Lmax + 1 : 0 ;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 15292
/*input
0011
*/
#include <bits/stdc++.h>

using namespace std;

string s;
void calc()
{
	int ans = 0;
	for (char i : s)
		if (i == '1')
			ans++;
		else
			ans--;
	cout << s.size() - abs(ans) << "\n";
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin >> s;
	calc();
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
ll mainasu(ll a,ll b,ll c){
	if(a>=b)return mainasu(a-b,b+1,c+1);
	else return c;
}
ll gojou(ll n){return pow(n,5);}
int main()
{
	ll a,b;
	cin>>a>>b;
    cout<<a*b;
}


Measured memory_bytes: 3680
#include <stdio.h>

int main()
{
    int cards[52];
    int i;
    int n;
    char c;
    int d;
    for(i = 0; i < 52; i++) {
        cards[i] = 0;
    }
    scanf("%d%*c", &n);
    for(i = 0; i < n; i++) {
        scanf("%c %d%*c", &c, &d);
        if(c == 'S') {
            cards[d-1] = 1;
        }
        if(c == 'H') {
            cards[d-1+13] = 1;
        }
        if(c == 'C') {
            cards[d-1+26] = 1;
        }
        if(c == 'D') {
            cards[d-1+39] = 1;
        }
    }
    for(i = 0; i < 52; i++) {
        if(cards[i] == 0) {
            if(i >= 0 && i < 13) {
                putchar('S');
            }
            if(i >= 13 && i < 26) {
                putchar('H');
            }
            if(i >= 26 && i < 39) {
                putchar('C');
            }
            if(i >= 39 && i < 52) {
                putchar('D');
            }
            printf(" %d\n", (i%13)+1);
        }
    }
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7

int main()
{
  int n;
  int n5 = 0, n7 = 0;

  REP(i,3) {
    cin>>n;
    if (n == 5) n5++;
    else if (n == 7) n7++;
  }

  if (n5 == 2 && n7 == 1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
def solve():
    s = input()
    first_harf = int(s[:2])
    second_harf = int(s[2:])

    if first_harf == 0 or first_harf > 12:
        if second_harf == 0 or second_harf > 12:
            print('NA')
        else:
            print('YYMM')
    else:
        if second_harf == 0 or second_harf > 12:
            print('MMYY')
        else:
            print('AMBIGUOUS')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
def examA():
    c = S()
    v = ["a", "i", "u", "e", "o"]
    ans = "consonant"
    if c in v:
        ans = "vowel"
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,n_;
ll a[100001];
vector<ll> vec;
ll dat[1<<20];
ll dat2[1<<20];
ll res[100001];

void update(int k,ll a){
	k+=n_-1;
	dat[k]+=a;
	while(k>0){
		k=(k-1)/2;
		dat[k]=dat[k*2+1]+dat[k*2+2];
	}
}

ll query(int a,int b,int k=0,int l=0,int r=n_){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	ll vl=query(a,b,k*2+1,l,(l+r)/2);
	ll vr=query(a,b,k*2+2,(l+r)/2,r);
	return vl+vr;
}


void update2(int k,ll a){
	k+=n_-1;
	dat2[k]+=a;
	while(k>0){
		k=(k-1)/2;
		dat2[k]=dat2[k*2+1]+dat2[k*2+2];
	}
}

ll query2(int a,int b,int k=0,int l=0,int r=n_){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat2[k];
	ll vl=query2(a,b,k*2+1,l,(l+r)/2);
	ll vr=query2(a,b,k*2+2,(l+r)/2,r);
	return vl+vr;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		vec.push_back(a[i]);
	}
	vec.push_back(0);
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	n_=1;
	while(n_<vec.size())n_*=2;
	for(int i=0;i<n;i++){
		a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
		update(a[i],1);
		update2(a[i],vec[a[i]]);
	}
	int now=0;
	for(int i=0;i<n;i++){
		if(vec[a[i]]>vec[now]){
			ll val=query(a[i],n_);
			res[i]=(ll)val*(vec[a[i]]-vec[now]);
			ll val2=query2(now,a[i]);
			ll val3=(ll)query(now,a[i]);
			res[i]+=(ll)val2-vec[now]*val3;
			now=a[i];
		}
		update(a[i],-1);
		update2(a[i],-vec[a[i]]);
	}
	for(int i=0;i<n;i++){
		printf("%lld\n",res[i]);
	}
	return 0;
}


Measured memory_bytes: 10740
#include <stdio.h>

int main(){
int a[10],i,j,n;
for(i=1;i<=10;i++){
scanf("%d",&a[i]);
}
for(i=1;i<=10;i++){
for(j=i+1;j<=10;j++){
if(a[i]<a[j]){
n = a[i];
a[i] = a[j];
a[j] = n;}
}
}
for(i=1;i<=3;i++){
printf("%d\n",a[i]);
}
return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
  int n;
  int ans[50];

  scanf("%d", &n);

  ans[0] = 1;
  ans[1] = 1;

  for(int i = 2; i <= n; i++) {
    ans[i] = ans[i-1] + ans[i-2];
  }

  printf("%d\n", ans[n]);

  return 0;
}

Measured memory_bytes: 1848
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;

  double probSum = 0;
  for ( int x = 1; x <= n; x++){
    if ( x >= k){
      probSum += 1/(double)n;
    } else {
      int y = ceil(log2(k) - log2(x));
      probSum += pow(2.0, -y) / (double)n;
    }
  }
  cout << setprecision(15) << probSum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A,P,Pie,S;
  
  scanf("%d%d",&A,&P);
  if(A >= 0 && P <= 100){
  S = ((A*3) + P) - ((A * 3) + P) % 2;
  Pie = S / 2;
  }
     
  printf("%d",Pie);
  
  return 0;
}


Measured memory_bytes: 128
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
#A
def A():
    a = I()
    s = input()
    if a >= 3200:
        print(s)
    else:
        print("red")
    return
 
#B
def B():
    n = I()
    a = LI()
    ans = 0
    for i in a:
        ans += 1/i
    print(1/ans)
    return
 
#C
def C():
    n = I()
    v = LI()
    q = []
    for i in v:
        heappush(q,i)
    while q:
        x = heappop(q)
        if not q:
            print(x)
            return
        y = heappop(q)
        heappush(q,(x+y)/2)
    return
 
#D
def D():
    def dfs(x,d,s):
        for y in v[x]:
            if d[y]:
                s += f[y]
                ans[y] = s
                d[y] = 0
                dfs(y,d,s)
                s -= f[y]
    n,q = LI()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    f = [0]*n
    for i in range(q):
        p,x = LI()
        p -= 1
        f[p] += x
    ans = [0]*n
    d = [1]*n
    d[0] = 0
    ans[0] = f[0]
    s = f[0]
    dfs(0,d,s)
    print(*ans)
    return
 
#E
def E():
    s = input()
    t = input()
 
    return
 
#F
def F():
 
    return
 
#Solve
if __name__ == "__main__":
    D()

Measured memory_bytes: 291188
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,m,p[200000],a[200000],b[200000],c[200000],cou[200000];
int main(){
    cin >> n >> m;
    REP(i,m)
        cin >> p[i];

    REP(i,n-1)
        cin >> a[i] >> b[i] >> c[i];

    REP(i,n-1)
        cou[i] = 0;

    REP(i,m - 1){
        ll x = p[i] - 1,y = p[i + 1] - 1;

        if(x > y)
            swap(x,y);

        FOR(i,x,y){
            cou[i]++;
        }
    }

    ll ans = 0;
    REP(i,n - 1){
        ans += min(a[i] * cou[i],b[i] * cou[i] + c[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7024
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll n,m,k,d,q;

pair<int,int> b[maxn];
int a[maxn];

int main()
{
    int n,k;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=make_pair(a[i],i+1);
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
         printf(i!=n-1?"%d ":"%d",b[i].second);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;

int main()
{
    int a,b,c;
    ///freopen(".in","r",stdin);
    ///freopen(".out","w",stdout);
    scanf("%d%d%d",&a,&b,&c);
    if((a<=c && c<=b) || (a>=c && c>=b))
        printf("Yes");
    else
        printf("No");

    return 0;
}


Measured memory_bytes: 256
// C - Train Ticket
// https://atcoder.jp/contests/abc079/tasks/abc079_c
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, d, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  a = (int)(s[0]) - 48;
  b = (int)(s[1]) - 48;
  c = (int)(s[2]) - 48;
  d = (int)(s[3]) - 48;
  vlli e = {a, b, c, d};
  SORTR(e);
  if (a + b + c + d == 7)
  {
    cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
  }
  else if (a + b + c - d == 7)
  {
    cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
  }
  else if (a + b - c - d == 7)
  {
    cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
  }
  else if (a + b - c + d == 7)
  {
    cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
  }
  else if (a - b + c - d == 7)
  {
    cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
  }
  else if (a - b + c + d == 7)
  {
    cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
  }
  else if (a - b - c - d == 7)
  {
    cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
  }
  else
  {
    cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define repvin(n) vint a(n);r(i,n)cin>>a[i];
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
signed main(){
  int n;
  cin>>n;
  vint a(n),b(n),c(n);
  repi(n)cin>>a[i];
  repi(n)cin>>b[i];
  repi(n)cin>>c[i];
  SORT(a);SORT(b);SORT(c);
  int res=0;
  for(signed j=0;j<n;++j){
    int aitr=lower_bound(all(a),b[j])-a.begin();
    int citr=upper_bound(all(c),b[j])-c.begin();
    res+=(aitr)*(n-citr);
  }
  cout<<res<<endl;

  
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(){
	int y,m,d,t;
	while(~scanf("%d%d%d",&y,&m,&d)){
		t=y*10000+m*100+d;
		if(t<18680908)
			puts("pre-meiji");
		else {
			if(t<19120730)
				printf("meiji %d",y-1867);
			else if(t<19261225)
				printf("taisho %d",y-1911);
			else if(t<19890108)
				printf("showa %d",y-1925);
			else
				printf("heisei %d",y-1988);
			printf(" %d %d\n",m,d);
		}
	}
	return 0;
}

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

int n,a[100005];
bool Free[100005];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int t=1,res=0;
    while(t!=2&&Free[t]==false)
    {
        Free[t]=true;
        t=a[t];
        res++;
    }
    if(t==2)
        cout<<res;
    else
        cout<<-1;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  char a; cin >> a;
  if(isupper(a)) cout << "A" << endl;
  else cout << "a" << endl;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main(){
  int set_num;
  int data[3] = {0};
  int tmp;
  int i,j;

  scanf("%d",&set_num);

  for(i=0; i<set_num; i++){
    scanf("%d%d%d",&data[0],&data[1],&data[2]);

    for(j=0; j<2; j++){
      if(data[j] > data[j+1]){
        tmp = data[j];
        data[j] = data[j+1];
        data[j+1] = tmp;
      }
    }

    if(data[0]*data[0] + data[1]*data[1] == data[2]*data[2]){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
    
  }

  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <unordered_set>
#include <string>

int main()
{
  int num;
  std::cin >> num;
  std::unordered_set<std::string> itemSet(num);
  while(num-- > 0)
  {
    std::string str;
    std::cin >> str;
    itemSet.insert(str);
  }
  
  std::cout << itemSet.size() << std::endl;
  
  return 0;
}

Measured memory_bytes: 17248
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N,M;
  cin >> N >> M;

  int r = M / N;

  for(int i = r;i >= 1;i--) {
    if(M % i == 0) {
      cout << i << endl;
      return 0;
    }
  }

}



Measured memory_bytes: 256
k = int(input())
from collections import deque
dic = {1:1}
queue = deque()
queue.appendleft([1,1])
while queue:
    v,cost = queue.popleft()
    v_ = (v+1)%k
    if not v_ in dic or cost+1<dic[v_]:
        dic[v_] = cost+1
        queue.appendleft([v_,cost+1])
    v_ = v*10%k
    if not v_ in dic or cost<dic[v_]:
        dic[v_] = cost
        queue.append([v_,cost])

print(dic[0])

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

int main()
{
    int n,q;
    cin >> n >> q;
    vector<tuple<int, int, int>> Kouji(n);
    vector<tuple<int, int, int>> Event;
    vector<int> d(q);

    for (int i = 0; i < n; i++)
    {
        int x,s,t;
        cin >> s >> t >> x;
        Kouji[i] = make_tuple(x, s, t);
        Event.push_back(make_tuple(s - x, -1, x));//工事開始イベント : s - x時間からxで開始
        Event.push_back(make_tuple(t - x, 0, x));//工事終了イベント : t - x時間にxで終了
    }
    for (int i = 0; i < q; i++)
    {
        cin >> d[i];
        Event.push_back(make_tuple(d[i], 1, i));//出発イベント : d[i]時間にiが出発
    }
    sort(Event.begin(), Event.end());

    vector<int> ans(q);
    multiset<int> KoujiEvents;
    for(auto nowEvent : Event)
    {
        //時間を古い順から順々に処理していく
        //工事が開始したら場所をmultisetに入れる
        //工事が終了したら場所をmultisetから抜く
        //出発したらmultisetの中の一番小さい値(場所)を取る。空なら-1
        int time, type, val;
        tie(time, type, val) = nowEvent;
        if(type == -1)KoujiEvents.insert(val);
        else if(type == 0)KoujiEvents.erase(KoujiEvents.find(val));
        else ans[val] = (KoujiEvents.empty() ? -1 : *(KoujiEvents.begin()));
    }

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

Measured memory_bytes: 23528
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    string s, t; cin>>s>>t;
    int ans=0;
    For(i, 0, sz(s)){
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3784
#include <iostream>

using namespace std;

int main(){
	double a;
	
	
	while(cin >> a)
	{	
		if(a <= 48.00){
			cout << "light fly" << endl;
		}
		
		else if(a <= 51.00 && 48.0 < a){
				cout << "fly" << endl;	}
		
		else if(a <= 54.00 && 51.00 < a){
			cout << "bantam" << endl;
			}
		
		else if(a <= 57.00 && 54.00 < a){
			cout << "feather" << endl;
		}
		
		else if(a <= 60.00 && 57.00 < a){
			cout << "light" << endl;
		}
		
		else if(a <= 64.00 && 60.00 < a){
			cout << "light welter" << endl;
		}
		
		else if(a <= 69.00 && 64.00 < a){
			cout << "welter" << endl;
		}
		
		else if(a <= 75.00 && 69.00 < a){
			cout << "light middle" << endl;
		}
		
		else if(a <= 81.00 && 75.00 < a){
			cout << "middle" << endl;
		}
		
		else if(a <= 91.00 && 81.00 < a){
			cout << "light heavy" << endl;
		}
		
		else if(a > 91.00){
			cout << "heavy" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=3005;
int mod;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n;
int C[N][N],S[N][N];
int p[N],pp[N];
int main(){
	n=read(),mod=read();
	For(i,0,n)
		C[i][0]=1;
	For(i,1,n)
		For(j,1,i)
			C[i][j]=Add(C[i-1][j]+C[i-1][j-1]);
	S[0][0]=1;
	For(i,1,n)
		For(j,0,i){
			if (j>0)
				S[i][j]=Add(S[i-1][j-1]+(LL)S[i-1][j]*j%mod);
			Add(S[i][j],S[i-1][j]);
		}
//	For(i,0,n){outarr(S[i],0,n)}
	For(i,0,n){
		p[i]=Pow(2,i);
		mod--;
		int tmp=Pow(2,i);
		mod++;
		pp[i]=Pow(2,tmp);
	}
	int ans=0;
	For(i,0,n)
		For(j,0,i){
			int v=(LL)S[i][j]*pp[n-i]%mod*Pow(p[n-i],j)%mod*C[n][i]%mod;
//			printf("(%d,%d,%d)\n",i,j,v);
			if (i&1)
				Del(ans,v);
			else
				Add(ans,v);
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 69504
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		boolean ok;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			List<Integer>[] adj = new List[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList<>();
			}
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			for (int i = 0; i < n - 1; i++) {
				int u = in.nextInt() - 1;
				int v = in.nextInt() - 1;
				adj[u].add(v);
				adj[v].add(u);
			}
			if (n == 2) {
				out.println(a[0] == a[1] ? "YES" : "NO");
				return;
			}
			int root = -1;
			for (int i = 0; i < n; i++) {
				if (adj[i].size() > 1) {
					root = i;
					break;
				}
			}
			if (root < 0) {
				throw new AssertionError();
			}
			ok = true;
			// System.out.println("root = " + root);
			long excess = dfs(root, -1, adj, a);
			out.println(ok && excess == 0 ? "YES" : "NO");
		}

		private long dfs(int v, int parent, List<Integer>[] adj, int[] a) {
			List<Long> e = new ArrayList<>();
			long sum = 0;
			for (int u : adj[v]) {
				if (u == parent) {
					continue;
				}
				long cur = dfs(u, v, adj, a);
				e.add(cur);
				sum += cur;
			}
			if (e.size() == 0) {
				return a[v];
			}
			long p = sum - a[v]; // pairs
			long s = a[v] - p; // singles
			if (p < 0 || s < 0) {
				ok = false;
				return 0;
			}
			if (p > maxPairs(e)) {
				ok = false;
				return 0;
			}
			return s;
		}

		private long maxPairs(List<Long> a) {
			long free = 0;
			long pairs = 0;
			for (long x : a) {
				long s = Math.min(x, free);
				x -= s;
				free -= s;
				if (x % 2 != 0) {
					++free;
					--x;
				}
				long d = Math.min(x, 2 * pairs);
				x -= d;

				pairs += s;
				pairs += d / 2;
				free += x;
			}
			return pairs;
		}

	}

	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: 85228
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int *prime(void)
{
    int c, cc, max = (int)10e+6;
    int *ans;
    ans = (int *)malloc(sizeof(int) * (max + 1));
    for (c = 0; c <= max; c += 2)
    {
        ans[c] = 0;
    }
    for (c = 3; c <= max; c += 2)
    {
        ans[c] = c;
    }
    ans[2] = 2;
    for (c = 3; c <= (int)10e+3; c += 2)
    {
        if (ans[c] == 0)
        {
            continue;
        }
        for (cc = 2; cc * c <= max; ++cc)
        {
            ans[c * cc] = 0;
        }
    }
    return ans;
}

long powllong(long long c, int power)
{
    int cc;
    long long c0 = c;
    for (cc = 0; cc < power - 1; ++cc)
    {
        c *= c0;
    }
    return c;
}

int main(void)
{
    int *key;
    int c, ans = 0, power;
    long long N, N0;
    scanf("%lld", &N);
    N0 = N;
    if (N == 1)
    {
        printf("0");
        return 0;
    }
    key = prime();
    for (c = 2; c <= (int)10e+6 + 2; ++c)
    {
        if (key[c] != 0)
        {
            power = 1;
            while (N % powllong((long long)c, power) == 0)
            {
                ++ans;
                N /= powllong((long long)c, power);
                ++power;
            }
        }
    }
    if (N == 1)
    {
        printf("%d", ans);
        return 0;
    }
    for (c = 2; c <= (int)10e+6 + 2; ++c)
    {
        if (key[c] != 0 && N % key[c] == 0)
        {
            printf("%d", ans);
            return 0;
        }
    }
    ++ans;
    printf("%d", ans);
    return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a - b == b - c){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
def calc(a,b,c):
    if c=="+":
        return a+b
    if c=="-":
        return a-b
    if c=="*":
        return a*b
    if c=="/":
        return a/b

while(1):
    try:
        wlist=raw_input().split()
        stack=[]
        for c in wlist:
            if c in "+-*/":
                b=stack.pop()
                a=stack.pop()
                stack.append(calc(a,b,c))
            else:
                stack.append(float(c))
        print stack[0]
    except:
        break
        

Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

ll BIT[200200], BIT2[200200];
void add(int A, int B) {
	while (A < 200200) {
		BIT[A] += B;
		A += A & -A;
	}
}

ll query(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae += BIT[A];
		A -= A & -A;
	}
	return kotae;
}

void add2(int A) {
	while (A < 200200) {
		BIT2[A]++;
		A += A & -A;
	}
}

ll query2(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae += BIT2[A];
		A -= A & -A;
	}
	return kotae;
}

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


	int Q;
	cin >> Q;

	int QL[200000];
	pair<int, int> Q1[200000];
	vector<int> za;
	rep(q, Q) {
		cin >> QL[q];
		if (QL[q] == 1) {
			int a, b;
			cin >> a >> b;
			Q1[q] = mp(a, b);
			za.pb(a);
		}
	}
	sort(za.begin(), za.end());

	ll B = 0;
	int k = 0;
	rep(q, Q) {
		if (QL[q] == 1) {
			k++;
			B += Q1[q].second;
			int QK = lower_bound(za.begin(), za.end(), Q1[q].first) - za.begin() + 1;
			add(QK, Q1[q].first);
			add2(QK);
		}
		else {
			int s = (k + 1) / 2;
			
			int L = 0;
			int R = 200199;
			while (L + 1 < R) {
				int H = (L + R) / 2;
				if (query2(H) >= s) R = H;
				else L = H;
			}
			int kari = za[R - 1];
			cosp(kari);
			ll R1 = query(R);
			ll R2 = query2(R);
			co(B + (R2 + R2 - k) * kari + query(200199) - R1 - R1);
		}
	}

	Would you please return 0;
}

Measured memory_bytes: 7032
n = int(input())

def getans(n):
    flag = False
    for i in range(1,10):
        if (n % i)  == 0 and n/i <= 9.0:
            flag = True
            return(flag)
    return(flag)

if getans(n):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (x, a, b) = listOfInt()
    println(when{
        a >= b -> "delicious"
        b - a <= x -> "safe"
        else -> "dangerous"
    })
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    int N; cin >> N;
    vector<float> x(N), y(N); REP(i, N) cin >> x[i] >> y[i];
    vector<float> per(N); REP(i, N) per[i] = i;

    int denom = 0;
    double cnt = 0;
    do {
        denom++;
        REP(i, N - 1) {
            cnt += pow((x[per[i]] - x[per[i + 1]]) * (x[per[i]] - x[per[i + 1]]) + (y[per[i]] - y[per[i + 1]]) * (y[per[i]] - y[per[i + 1]]), 0.5);
        }
    } while(next_permutation(per.begin(), per.end()));

    cout << std::setprecision(20) << cnt / denom << endl;
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

using comp = complex<int>;

bool overflow;

char *p;
char c[121];

int pri(char c) {
	if(c == '*') return 1;
	return 2;
}
void chk(comp c) {
	if(abs(c.real()) > 10000) overflow = 1;
	if(abs(c.imag()) > 10000) overflow = 1;
}
comp f(comp a, comp b, char c) {
	//cout << a << ' ' << b << ' ' << c << '\n';
	comp r;
	if(c == '+')
		r = a + b;
	if(c == '-')
		r = a - b;
	if(c == '*')
		r = a * b;
	chk(r);
	return r;
}

comp num() {
	if(*p == 'i') {
		p ++;
		return comp(0, 1);
	}
	string s = "";
	while(isdigit(*p)) {
		s += *p;
		p ++;
	}
	while(s.size() > 1 && s[0] == '0')
		s = s.substr(1);
	if(s.size() >= 6 || abs(stoi(s)) > 10000) {
		overflow = 1;
		return 0;
	}
	return stoi(s);
}

comp expr();
comp term() {
	if(*p == 'i' || isdigit(*p))
		return num();
	p ++; comp r = expr(); p ++; return r;
}

comp expr() {
	vector <char> u;
	vector <comp> v = {term()};
	while(*p != ')') {
		char c = *(p ++);
		comp t = term();
		while(u.size() && pri(c) >= pri(u.back())) {
			comp b = v.back(); v.pop_back();
			comp a = v.back(); v.pop_back();
			v.pb(f(a, b, u.back())); u.pop_back();
		}
		u.pb(c); v.pb(t);
	}
	while(u.size()) {
		comp b = v.back(); v.pop_back();
		comp a = v.back(); v.pop_back();
		v.pb(f(a, b, u.back())); u.pop_back();
	}
	return v[0];;
}

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	for(string s; cin >> s; ) {
		s = '(' + s + ')';
		for(int i = 0; i < s.size(); i ++)
			c[i] = s[i];
		c[s.size()] = 0;
		
		overflow = 0;
		p = c;
		comp ans = term();

		int r = ans.real(), i = ans.imag();
		if(overflow) cout << "overflow\n";
		else if(!r && !i) cout << "0\n";
		else if(!r) cout << i << "i\n";
		else if(!i) cout << r << '\n';
		else {
			cout << r;
			if(i > 0) cout << '+';
			cout << i << "i\n";
		}
	}

	return 0;
}

Measured memory_bytes: 3252
import bisect

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()


left = a[0] * 2
right = a[-1] * 2 + 1
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    count = 0
    for i in range(n):
        j = bisect.bisect_left(a, mid - a[i])
        count += n - j

    if count >= m:
        left = mid
    else:
        right = mid

acum = [0] * (n+1)
for i in range(n):
    acum[i+1] = acum[i] + a[i]

ans = 0
count = 0
for i in range(n):
    j = bisect.bisect_left(a, left - a[i])
    ans += acum[n] - acum[j] + a[i] * (n-j)
    count += n-j
ans -= left * (count - m)
print(ans)

Measured memory_bytes: 55744
#include<cstdio>
long long a[100005],n,s;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	    scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++)
	    if (a[i]>a[i-1]) s=s+a[i]-a[i-1];
	printf("%lld\n",s);
    return 0;
} 

Measured memory_bytes: 128