akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <iomanip>
#include <numeric>
using namespace std;


bool func(int a, int b, int c)
{
	vector<int> n(3);
	n[0] = a;
	n[1] = b;
	n[2] = c;

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

	if (n[1] == b)
	{
		return true;
	}
	return false;
}

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);

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

	int cnt = 0;	
	for (int i = 1; i < n - 1; i++)
	{
		if (func(p[i - 1], p[i], p[i + 1]))
		{
			cnt ++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
def main():

    from collections import Counter
    import sys

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))

    d = Counter(a)


    base = sum(v * (v - 1) // 2 for v in d.values())
    e = {k: base - (v >= 2) * (v - 1) for k, v in d.items()}
    p = [str(e[x]) + '\n' for x in a]
    q = ''.join(p)
    print(q)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44276
from collections import defaultdict

def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()
lis1 = defaultdict(int)
lis2 = defaultdict(int)

for i,s in enumerate(nums):
    if i % 2 == 0:
        lis1[s] += 1
    else:
        lis2[s] += 1

maxk1 = []
maxv1 = 0
for k in lis1.keys():
    if lis1[k] == maxv1:
        maxk1.append(k)
    elif lis1[k] > maxv1:
        maxv1 = lis1[k]
        maxk1 = [k]

maxk2 = []
maxv2 = 0
for k in lis2.keys():
    if lis2[k] == maxv2:
        maxk2.append(k)
    elif lis2[k] > maxv2:
        maxv2 = lis2[k]
        maxk2 = [k]

v1 = list(lis1.values())
v1.sort(reverse=True)
v1 = v1 + [0]
v2 = list(lis2.values())
v2.sort(reverse=True)
v2 = v2 + [0]

if (len(maxk1) == 1) and (len(maxk2) == 1) and (maxk1[0] == maxk2[0]):
    rem = max(v1[0] + v2[1], v2[0] + v1[1])
    ans = n-rem

else:
    ans = n - maxv1 - maxv2
print(ans)




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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,i,j,k,l;
    cin>>n; ll arr[n];
    vector<ll> v;
    for(i=0;i<n;i++)cin>>arr[i];

    // v.push_back(arr[0]);
    ll flag=0;
    if(arr[0]<arr[1])flag=1;
    if(flag)v.push_back(arr[0]);

    for(i=2;i<n;i++){
        if(flag==1){
     
          if(arr[i]<arr[i-1]){
              flag=0;
              v.push_back(arr[i-1]);
          }
        }
        else {
            if(arr[i]>arr[i-1]){
                flag=1; v.push_back(arr[i-1]);
            }
        }
        
    }
    if(flag==1)v.push_back(arr[n-1]);
    
    ll res=1000,cnt=0;
    // if(v.size()<=1)cout<<"1000";
    // else {
        for(i=0;i<v.size();i++){
            if(i%2){
                res+=cnt*v[i];
                cnt=0;
            }
            else{
                if(i==n-1)break;
                cnt=res/v[i];
                res-= (res/v[i])*v[i];
            }
            // cout<<v[i]<<" "<<cnt<<" "<<res<<"\n";
        }
        cout<<res;
    // }

}

Measured memory_bytes: 3660
#include<iostream>
using namespace std;
int main(){
	int n;
	int a,b,c;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a >> b >> c;
		a*=a; b*=b; c*=c;
		if(a == b+c || b == a+c || c == a+b)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

int N, A[100005];
long long dp[100005][3];

int main() {
	cin >> N;
	int x;
	cin >> x;
	A[0] = x;
	for (int i = 1; i < N; i++) {
		char c;
		cin >> c >> x;
		if (c == '-') A[i] = -x;
		else A[i] = x;
	}
	memset(dp, -63, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int f = 0; f < 3; f++) {
			if (f%2 == 1) dp[i][f] = max(dp[i][f], dp[i - 1][f] - A[i - 1]);
			else dp[i][f] = max(dp[i][f], dp[i - 1][f] + A[i - 1]);
			if (i != 1 && A[i - 2] < 0) {
				if (f == 1) dp[i][f] = max(dp[i][f], dp[i - 1][f - 1] - A[i - 1]);
				else if (f == 2) dp[i][f] = max(dp[i][f], dp[i - 1][f - 1] + A[i - 1]);
			}
			if (f == 0) dp[i][f] = max(dp[i][f], max(dp[i - 1][f + 1] + A[i - 1], dp[i - 1][f + 2] + A[i - 1]));
			else if (f == 1) dp[i][f] = max(dp[i][f], dp[i - 1][f + 1] - A[i - 1]);
		}
	}
	printf("%lld\n", max(dp[N][0], dp[N][1]));
}


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


n, x = map(int, input().split(' '))
p = list(map(int, input().split(' ')))
for i in range(n):
    p[i] = abs(p[i] - x)
ans = p[0]
for i in range(n):
    ans = gcd(p[i], ans)
print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin >> d;
  if(d==25){
    cout << "Christmas" <<endl;
  }
  else if(d==24){
    cout << "Christmas" << " " << "Eve" <<endl;
  }
  else if(d==23){
    cout << "Christmas" << " " << "Eve" << " " << "Eve" <<endl;
  }
  else {
    cout << "Christmas" << " " << "Eve" << " " << "Eve" << " " << "Eve" <<endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

int main(){
	int n; cin>>n;
	ll s = 0;
	vector<ll> v(n), vv(n);
	ll X=0,x=0;
	rep(i,n){
		cin >> v[i];
		X += v[i];
	}
	ll m = 1000000000000000000LL;
	for (int i = 0; i < n-1; i++){
		x += v[i];
		m = min(m,abs(x*2 - X));
	}
	cout << m << endl;
}

Measured memory_bytes: 3328
// Problem : C - Replacing Integer
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define infl 1e18+5
#define mninfl -1e18-5
#define Mod 1000000007
#define newmod  998244353
int ah=911382323;
int bh=972663749;
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const long double pi=acos(-1);
//looping
#define int long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' ';  cout<<endl
#define pv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";  cout<<endl
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
#define deb2(x,y)  cerr << #x << " = " << x <<"   "<< #y << " = " << y << endl;
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mkp make_pair
#define all(v) (v).begin(),(v).end()
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef vector < pair <int, int> > vpii;
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
int n,k;
cin>>n>>k;
cout<<min3(n,n%k,k-n%k);
}




























Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int fread()
{
    int f=0;
    int x=1;
    char ch=getchar();
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
        {
            x=-1;
        }
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        f=f*10+ch-'0';
        ch=getchar();
    }
    return f*x;
}
int main()
{
    int tempcost; 
    int temptime;
    int route=fread();
    int rulertime=fread();
    priority_queue<int,vector<int>,greater<int> >res;
    for(register int i = 1; i <= route; ++i)
    {
        tempcost=fread();
        temptime=fread();
        if(temptime > rulertime)
        {
            continue;
        }
        else
        {
            res.push(tempcost);
        }
    }
    if(res.empty())
    {
        puts("TLE");
    }
    else
    {
        printf("%d\n",res.top());
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val k = sc.nextLong

  val iAbl = Vector.fill(n)((sc.nextInt, sc.nextInt))

  val abl = iAbl.sorted

  val acc = comulativeSum(abl)

  val res = acc.find(_._2 >= k).get._1

  println(res)

  def comulativeSum(intVector: Vector[(Int, Int)]): Vector[(Int, Long)] ={
    intVector.foldLeft(Vector.empty[(Int, Long)]){
      case (list, (v, acc)) =>
        if(list.isEmpty) Vector((v,acc))
        else list :+ (v, list.last._2 + acc)
    }
  }
}


Measured memory_bytes: 111620
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ll m = n;
  orep(i,n) {
    ans += i*m*(m+1) / 2;
    m=n/(i+1);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]-=i+1;
    }
    sort(a.begin(),a.end());
    if(n%2==1){
        ll m=a[n/2];
        ll ans=0;
        rep(i,n){
            ans+=abs(a[i]-m);
        }
        cout << ans << endl;
    }
    else{
        ll m1=a[n/2-1];
        ll m2=a[n/2];
        ll ans1=0,ans2=0;
        rep(i,n){
            ans1+=abs(a[i]-m1);
        }
        rep(i,n){
            ans2+=abs(a[i]-m2);
        }
        cout << min(ans1,ans2) << endl;
    }
    return 0;
} 

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
//const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, X;
	int ans = 1;
	int x;
	int D = 0;
	cin >> N >> X;
	rep(i, 0, N)
	{
		cin >> x;
		D += x;
		if (D <= X)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int k = sc.nextInt(), k2 = k * 2, k4 = k * 4;
		int[][] bb = new int[k4][k4];
		while (n-- > 0) {
			int i = sc.nextInt() % k2;
			int j = sc.nextInt() % k2;
			char c = sc.next().charAt(0);
			if (c == 'W')
				i += i < k ? k : -k;
			bb[i][j]++;
			bb[k2 + i][j]++;
			bb[i][k2 + j]++;
			bb[k2 + i][k2 + j]++;
		}
		for (int i = 0; i < k4; i++)
			for (int j = 1; j < k4; j++)
				bb[i][j] += bb[i][j - 1];
		for (int i = 1; i < k4; i++)
			for (int j = 0; j < k4; j++)
				bb[i][j] += bb[i - 1][j];
		int ans = 0;
		for (int i_ = 0; i_ < k2; i_++)
			for (int j_ = 0; j_ < k2; j_++) {
				int i, j, cnt = 0;
				i = i_; j = j_;
				cnt += bb[i + k][j + k] - bb[i][j + k] - bb[i + k][j] + bb[i][j];
				i = i_ + k; j = j_ + k;
				cnt += bb[i + k][j + k] - bb[i][j + k] - bb[i + k][j] + bb[i][j];
				ans = Math.max(ans, cnt);
			}
		println(ans);
	}
}


Measured memory_bytes: 138616
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    REP(i,s.length()){
        if (i % 2 == 0){
            if (s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if (s[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long Attack = 0;
    long Monster = 1;
    
    while (H > 0) {
      Attack += Monster;
      H /= 2;
      Monster *= 2;
    }

    System.out.println(Attack);
    
  }
}

Measured memory_bytes: 23888
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
lli nCr(lli n, lli r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> X >> Y;
  if((X+Y)%3!=0)Out(0);
  else{
    Z=(X+Y)/3;
    X-=Z;Y-=Z;
    COMinit();
    Out(nCr(X+Y,Y));
  }
}

Measured memory_bytes: 119808
import bisect
a,b,q=map(int,input().split())
A=[-10**11]
for i in range(a):
  A.append(int(input()))
A.append(10**11)
B=[-10**11]
for i in range(b):
  B.append(int(input()))
B.append(10**11)
for i in range(q):
  x=int(input())
  c=bisect.bisect_left(A,x,hi=len(A))
  d=bisect.bisect_left(B,x,hi=len(B))
  ans=min(abs(A[c-1]-x)+abs(B[d-1]-A[c-1]),abs(A[c-1]-x)+abs(B[d]-A[c-1]),abs(A[c]-x)+abs(B[d-1]-A[c]),abs(A[c]-x)+abs(B[d]-A[c]),abs(B[d-1]-x)+abs(B[d-1]-A[c-1]),abs(B[d-1]-x)+abs(B[d-1]-A[c]),abs(B[d]-x)+abs(B[d]-A[c-1]),abs(B[d]-x)+abs(B[d]-A[c]))
  print(ans)

Measured memory_bytes: 13364
D, N = map(int, input().split())
if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)
elif D == 1:
    if N == 100:
        print(10100)
    else:
        print(100 * N)
elif D == 2:
    if N == 100:
        print(1010000)
    else:
        print(100 * 100 * N)

Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);
      
      int N = sc.nextInt();
      int K = sc.nextInt();
      int X = sc.nextInt();
      int Y = sc.nextInt();
      
      int sum = 0;
      for(int i = 0; i < N; i++){
          if(i < K){
              sum += X;
              
          } else {
              sum += Y;
          }
          
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 22484
from sys import stdin


def get_result(data):
    N, M = data[0]
    A = data[1]
    ans = N - sum(A)
    if ans < 0:
        return -1
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 9800
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.Objects;

public class Main {
	static int MOD = (int)1e9 + 7;
	long N;
	HashMap<Key,Long> map;

	private class Key implements Comparable<Key>{
		long x,y;
		public Key(long x,long y){
			this.x = x;
			this.y = y;
		}

		public int compareTo(Key p){
			if(Long.compare(this.x,p.x) == 0){
				return Long.compare(this.y, p.y);
			}
			return Long.compare(this.x, p.x);
		}

		public boolean equals(Object o){

			if(this == o){
				return true;
			}

			if(o instanceof Key){

				Key another = (Key)o;

				return this.x == another.x && this.y == another.y;
			}
			return false;
		}

		public int hashCode(){
			return Objects.hash(Long.hashCode(this.x),Long.hashCode(this.y));
		}
	}

	public long dfs(long S,long X){

		if(S == 0)return 1;

		Key key = new Key(S,X);

		if(map.containsKey(key)){
			return map.get(key);
		}

		long ret = 0;
		ret += dfs(S >> 1,X >> 1) % MOD;
		ret %= MOD;

		if(S > 1){
			ret += dfs((S - 2) >> 1,X >> 1) % MOD;
			ret %= MOD;
		}

		ret += dfs((S - 1) >> 1,(X - 1) >> 1) % MOD;
		ret %= MOD;

		map.put(key, ret);
		return ret;
	}

	public void solve() {
		N = nextLong();
		map = new HashMap<Key,Long>();
		out.println(dfs(N,N));
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;


const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;


int main(){
       ll n;
       cin >> n;
       if(n & 1) cout << n / 2;
       else cout << n/2 - 1;
   }
       
       
       
       
       
       
       
       
       
       
       
       
       
        
    


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
 int a, b, c;
 cin >> a;
 cin >> b;
 cin >> c;
 
if (a <= b&&a <= c){
    if(b <=c){
        cout << a;
        cout << " ";
        cout << b;
        cout << " ";
        cout << c;
    }else{
    cout << a;
    cout << " ";
    cout << c;
    cout << " ";
    cout << b;
    }
 
}else if (b <= a&&b <= c){
    if(a <= c){
        cout << b;
        cout << " ";
        cout << a;
        cout << " ";
        cout << c;
    }else{
    cout << b;
    cout << " ";
    cout << c;
    cout << " ";
    cout << a;
    }
 
}else if (c <= a&&c <= b){
    if(a <= b){
        cout << c;
        cout << " ";
        cout << a;
        cout << " ";
        cout << b;
    }else{
    cout << c;
    cout << " ";
    cout << b;
    cout << " ";
    cout << a;
    }
}
 
 cout << endl;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A=sc.nextInt();
        if (N%500<=A) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 21844
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007
//#define DEBUG

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine e(seed);
std::mt19937 rng((int) seed);

void solvetask() {
    int n;
    cin >> n;
    cout << n + n*n + n*n*n << endl;
}

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

    int t = 1;

    while(t--) solvetask();
}


Measured memory_bytes: 3652
import numpy as np

def bfs(que):
  if len(que) > 0:
    nh, nw = que[0]
    que.pop(0)
    for dh, dw in directions:
      ##枠外
      if not ((0 <= nh+dh < H)and(0 <= nw+dw < W)):
        continue
      ##壁
      if G[nh+dh][nw+dw] == '#':
      	continue
   	  ##探索済み
      if dist[nh+dh][nw+dw] != -1:
      	continue
      dist[nh+dh][nw+dw] = dist[nh][nw]+1
      que.append([nh+dh, nw+dw])
    nh += dh
    nw += dw
    bfs(que)

    
      
ans_list = []
H, W = map(int, input().split())
G = [list(input()) for i in range(H)]
directions = [[0,1],[1,0],[0,-1],[-1,0]] #right, down, left, up

for nh in range(H):
  for nw in range(W):
    if G[nh][nw] == '#':
      continue
    dist = [[-1] * W for i in range(H)]
    que = [[nh,nw]] # start pos in this tine
    dist[nh][nw] = 0
    bfs(que)
    ans = np.max(dist)
    ans_list.append(ans)
      
print(max(ans_list))

Measured memory_bytes: 12436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 100005;
const ll MOD = 1000000007;

int n;
vector<int> pos;
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;
    pos.resize(n);

    for (int i=0; i<n; i++) {
        cin >> pos[i];
    }

    int bst = MOD;
    for (int x=0; x<=100; x++) {
        int sum = 0;
        for (auto v : pos) {
            sum += (v-x) * (v-x);
        }

        bst = min(bst, sum);
    }

    cout << bst << endl;


}


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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(ll N, ll M, ll X, ll Y, vector<ll> x, vector<ll> y) {
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    for (int i = X + 1; i <= Y; i++) {
        if (i > x.back() && i <= y.front()) {
            cout << "No War" << endl;
            return;
        }
    }
    cout << "War" << endl;
}


void main_(istream &cin) {
    ll M;
    ll Y;
    ll N;
    ll X;
    cin >> N;
    vector<ll> x(N - 1 + 1);
    cin >> M;
    vector<ll> y(M - 1 + 1);
    cin >> X;
    cin >> Y;
    for (int i = 0; i <= N - 1; i++) {
        cin >> x[i];
    }
    for (int i = 0; i <= M - 1; i++) {
        cin >> y[i];
    }
    solve(N, M, X, Y, x, y);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $n, $k);
$array = explode(' ', trim(fgets(STDIN)));
 
$count = 0;
 
// 何種類か確認
$syurui = count(array_unique($array));
if (isClear($k, $syurui) == false) {
  $arrayCountValues = array_count_values($array);
  sort($arrayCountValues);
  $valueCount = count($arrayCountValues);
  for ($i = 0; $i < $valueCount; $i++) {
    $count = $count + $arrayCountValues[$i];
    $syurui = $syurui - 1;
    if (isClear($k, $syurui)) {
      break;
    }
  }
}
 
function isClear($k, $syurui) {
  if ($k >= $syurui) {
    return true;
  }
  return false;
}
 
echo $count;

Measured memory_bytes: 35304
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x = in.nextInt();
            int chocEaten = 0;
            for (int i = 0; i < n; ++i) {
                int a = in.nextInt();
                int day = 1;
                while (day <= d) {
                    chocEaten++;
                    day += a;
                }
            }
            System.out.println(chocEaten + x);
        }

    }
}

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

int main() {
    string s; cin >> s;
    int cnt = 0;
    int  ans = 0;
    rep(i,3) {
        if (s[i] == 'R') {
            cnt ++;
            ans = max(ans,cnt);
        }
        else cnt = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

class Main{
    private static int[] g;
    private static ArrayList<Integer>[] f;
    @SuppressWarnings("unchecked")
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in = br.readLine();
        final int n = Integer.parseInt(in.substring(0, in.indexOf(' ')));
        final int m = Integer.parseInt(in.substring(in.indexOf(' ')+1));
        g = new int[n];
        f = new ArrayList[n];
        for(int i = 0; i<n; i++)
            f[i] = new ArrayList<Integer>();
        for(int i = 0; i<m; i++){
            in = br.readLine();
            final int s = Integer.parseInt(in.substring(0, in.indexOf(' ')));
            final int t = Integer.parseInt(in.substring(in.indexOf(' ')+1));
            f[s].add(t);
            f[t].add(s);
        }
        int id = 0;
        for(int i = 0; i<n; i++){
            if(g[i]==0) group(i, ++id);
        }
        final StringBuilder sb = new StringBuilder();
        final int q = Integer.parseInt(br.readLine());
        for(int i = 0; i<q; i++){
            in = br.readLine();
            final int s = Integer.parseInt(in.substring(0, in.indexOf(' ')));
            final int t = Integer.parseInt(in.substring(in.indexOf(' ')+1));
            sb.append(g[s]==g[t] ? "yes\n" : "no\n");
        }
        System.out.print(sb);
    }
    private static void group(int u, int id){
        final ArrayDeque<Integer> st = new ArrayDeque<Integer>();
        st.push(u);
        while(!st.isEmpty()){
            final int uid = st.pop();
            if(g[uid]!=0) continue;
            g[uid] = id;
            for(int i = 0, n = f[uid].size(); i<n; i++){
                st.push(f[uid].get(i));
            }
        }
    }
}

Measured memory_bytes: 74324
import sys
from math import ceil, sqrt

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')


def main():
    N = INT()

    num = [i + 1 for i in range(ceil(sqrt(N)))]

    minimum = INF
    for i in num:
        if N % i == 0:
            temp = i + N//i
            if temp < minimum:
                minimum = temp

    print(minimum - 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 113904
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
P = iil()
ans = 0
for i in range(1,n-1):
    if (P[i-1] < P[i] < P[i+1]) or (P[i+1] < P[i] < P[i-1]):
        ans += 1
print(ans)

Measured memory_bytes: 3064
n,m = map(int, input().split())

if n==2 or m == 2:
    print(0)
elif n==1 and m == 1:
    print(1)
elif n==1:
    print(m-2)
elif m==1:
    print(n-2)
else:
    print((n-2)*(m-2))

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

int main() {
  int N,X;
  vector<int> doughnut(100);
  int counter;

  cin >> N >> X;
  for(int i = 0;i < N;i++){
    cin >> doughnut.at(i);
  }

  sort(doughnut.begin(),doughnut.end());
  reverse(doughnut.begin(),doughnut.end());

  X = X- accumulate(doughnut.begin(),doughnut.end(),0);
  counter = N;
  
  counter += X / doughnut.at(N-1);
  
  cout << counter << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200050;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

ll T[2], A[2], B[2];
void solve() {
	cin >> T[0] >> T[1];
	cin >> A[0] >> A[1];
	cin >> B[0] >> B[1];
	if (A[0] < B[0]) {
		swap(A[0], B[0]);
		swap(A[1], B[1]);
	}
	if (T[0] * A[0] + T[1] * A[1] == T[1] * B[1] + T[0] * B[0]) {
		print("infinity"); return;
	}
	int dif = 0;
	if (T[0] * A[0] + T[1] * A[1] - T[1] * B[1] - T[0] * B[0] > 0) {
		print(0); return;
	}
	int d1 = T[0]* A[0] - T[0] * B[0];
	int d2 = T[1] * (B[1] - A[1]);
	int ok = 1, ng = 1e10;
	ll ans = 0;
	ans = d2 / (d2 - d1);
	ans *= 2; ans--;
	if (d2 % (d2 - d1) == 0)ans--;
	print(ans);
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>



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

	int N;
	cin >> N;
	std::vector<std::pair<int,int>> jobs(N);
	for (auto& job : jobs)
	{
		cin >> job.second >> job.first;
	}

	std::sort(jobs.begin(), jobs.end());

	int now = 0;
	bool ok = true;
	for (auto job : jobs)
	{
		now += job.second;
		if (now > job.first)
		{
			ok = false;
			break;
		}
	}

	cout << (ok ? "Yes" : "No") << std::endl;

	return 0;
}


Measured memory_bytes: 1792
A, B, C, X, Y = gets.split.map(&:to_i)
money = 0
if (A + B) >= (C * 2)
    if X <= Y
        money += ((X * 2) * C)
        money +=  B >= (C*2) ? ((Y - X) * (C*2)) : ((Y - X) * B)
    else
        money += ((Y * 2) * C)
        money +=  A >= (C*2) ? ((X - Y) * (C*2)) : ((X - Y) * A)
    end
else
    money += (A * X) + (B * Y)
end
puts money

Measured memory_bytes: 1788
import math
A,B,H,M = map(int,input().split())

H = (H+M/60)*30
M *= 6

d = abs(H-M)
if d > 180:
    d = 360 - d

#print(d)

C = pow(A**2+B**2-2*A*B*math.cos(math.radians(d)),0.5)

print(C)

Measured memory_bytes: 9496
program main
  implicit none
  integer(8) i, see, ans, N
  integer(8),allocatable :: A(:)
  read(*, *)N
  allocate(A(N))
  read(*, *) (A(i), i = 1,N)
  ans = 0
  see = 1
  do i = 1,N
    if (A(i) == see) then
      see = see + 1
    else
      ans = ans + 1
    end if
  end do
  if (see == 1) then
    ans = -1
  end if

  write(*, *) ans
end program main


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<P> p(M);
    rep(i, M) cin >> p[i].first >> p[i].second;
    rep(x, 1000) {
        int k  = 1;
        int nx = x / 10;
        vector<int> d(1, x % 10);
        while(nx) {
            k++;
            d.push_back(nx % 10);
            nx /= 10;
        }
        if(k != N)
            continue;
        bool ok = true;
        reverse(d.begin(), d.end());
        rep(i, M) {
            if(d[p[i].first - 1] != p[i].second) {
                ok = false;
            }
        }
        if(ok) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
 
void dfs(int v, int p, ll sum, vector<ll> &V, vector<vector<int>> &G) {
	sum += V[v];
	V[v] = sum;
	for (int i = 0; i < G[v].size(); i++) {
	    if (G[v][i] == p) continue;
	    dfs(G[v][i], v, sum, V, G);
	}
}

void solve() {
	int N, Q;
	cin >> N >> Q;
	vector<vector<int>> G(N);
	for (int i = 0; i < N - 1; i++) {
	    int a, b;
	    cin >> a >> b;
	    a--, b--;
	    G[a].push_back(b);
	    G[b].push_back(a);
	}
	vector<ll> V(N);
	for (int i = 0; i < Q; i++) {
	    int p, x;
	    cin >> p >> x;
	    p--;
	    V[p] += x;
	}
	ll sum = 0;
	dfs(0, -1, sum, V, G);

	for (int i = 0; i < N; i++) {
	    cout << V[i] << " ";
	}
	cout << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    string s; cin >> s;
    int n = s.size();
    ll res = 0;
    ll p = 0,g = 0;
    rep(i,n){
        if(s[i] == 'g'){
            if(p < g)p++,res++;
            else g++;
        }
        else{
            if(p < g)p++;
            else g++,res--;
        }
    }
    out(res);
}

Measured memory_bytes: 3740
#include <stdio.h>
 
int main(){
    int i,count=0;
    char w[11],m[101];
    scanf("%s",&w);
    while (1){
        scanf("%s",&m);
        if (strcmp("END_OF_TEXT",m)==0) break;
        for (i=0;i<101;i++){
            if (m[i]>='A'&&m[i]<='Z')
                m[i]=m[i]+32;
        }
        if (strcmp(w,m)==0) count++;
    }
    printf("%d\n",count);
    return 0;
}   


Measured memory_bytes: 2108
// abc116_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int a, b, c;
    cin >> a >> b >> c;

    int ans = (a * b) / 2;
    print(ans);

    return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main() {
  string s; cin>>s;
  int c=-1;
  int f=s.size();
  rep(i,s.size()){
    if(s[i]=='C'){
      c=i;
      break;
    }
  }
  
  rep(i,s.size()){
    if(s[s.size()-1-i]=='F'){
      f=s.size()-1-i;
      break;
    }
  }
  if(0<=c && f<s.size() && c<f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
      
}



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

int main() {
 long long n;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
    long long k;
    cin>>k;
    a[i]=k;
  }
  int count=1;
  for(int i=0;i<n;i++){
    if(a[i]==count)count++;
  }
  if(count==1)cout<<-1<<endl;
  else cout<<n-count+1<<endl;
}


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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n){
		string s;
		int t=n;
		while(t){
			s+=(t%10+'0');
			t/=10;
		}
		int flag=1;
		int len=s.length();
		for(int i=0;i<len;i++){
			if(s[i]!=s[len-1-i]){
				flag=0;
			}
		}
		if(flag){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}

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

#define Maxn 200010
#define LL long long

using namespace std;

const int MOD = 1e9 + 7;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

struct Edge {
    int next, to;
}
edge[Maxn * 2];
int head[Maxn], edge_num;

void add_edge(int from, int to) {
    edge[++edge_num].next = head[from];
    edge[edge_num].to = to;
    head[from] = edge_num;
}

LL n, siz[Maxn], inv[Maxn];

LL Pow(LL a, LL b) {
    LL ans = 1, base = a;
    while(b) {
        if(b & 1) ans = ans * base % MOD;
        base = base * base % MOD;
        b >>= 1;
    }
    return ans;
}

void dfs1(int u, int f) {
    siz[u] = 1;
    for(int i = head[u]; i; i = edge[i].next) {
        int v = edge[i].to;
        if(v != f) dfs1(v, u), siz[u] += siz[v];
    }
}

void dfs2(int u, int f) {
    if(u != 1) inv[u] = inv[f] * (n - siz[u]) % MOD * Pow(siz[u], MOD - 2) % MOD;
    for(int i = head[u]; i; i = edge[i].next) {
        int v = edge[i].to;
        if(v != f) dfs2(v, u);
    }
}

int main() {
    n = read();
    int u, v;
    for(int i = 1; i < n; ++i) {
        u = read(); v = read();
        add_edge(u, v);
        add_edge(v, u);
    }
    LL mul = 1; for(int i = 1; i <= n; ++i) mul = mul * i % MOD;
    dfs1(1, 0); inv[1] = 1;
    for(int i = 1; i <= n; ++i) inv[1] = inv[1] * siz[i] % MOD; 
    dfs2(1, 0);
    for(int i = 1; i <= n; ++i) printf("%lld\n", mul * Pow(inv[i], MOD - 2) % MOD);
    return 0;
}

Measured memory_bytes: 10872