akhauriyash/Code-Regression huggingface dataset:
#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>;
const int mod = 1000000007;
const ll INF = ll(1e18)+1;
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; }

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  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*(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;
  }
};
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    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];
  }
} comb(2000005);
 

mint f2(int n, int k) {
  return comb(n+k-1,k-1);
}
mint f(int n, int k) {
  if (n < k) return 0;
  if (n == 0 && k == 0) return 1;
  if (k < 1) return 0;
  return f2(n-k,k);
}
 
int main() {
  int n, k;
  cin >> n >> k;
 
  for (int i = 1; i <= k; i++) {
    mint blue = f(k,i);
    mint red = 0;
    {
      red += f(n-k,i-1);
      red += f(n-k,i);
      red += f(n-k,i);
      red += f(n-k,i+1);
    }
    mint ans = blue*red;
    printf("%lld\n", ans.x);
  }
  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (1) {
		if (b > a)break;
		k--;
		b *= 2;
		if (k == 0) {
			if (a < b&&b < c) {
				ps(Yes);
			}
			else {
				ps(No);
			}
			return 0;
		}
	}
	FOR(i, 1, k) {
		c *= 2;
	}
	if (a < b&&b < c) {
		ps(Yes);
	}
	else {
		ps(No);
	}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;



int main()
{
	int a, b;
	cin >> a >> b;
	cout << (a+b <= b+(b-1) ? b+(b-1) : (a+b <= a+(a-1) ? a+(a-1) : a+b )) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<bool>	vb;
ll mod = 1e9 + 7;



int main(){  
    string s;
    string t;
    cin >> s >> t;
    ll ns = 0;
    rep(i,0,s.length()){
        if(s[i] != t[i]) ns++;
    }
    cout << ns;
}

Measured memory_bytes: 3916
'use strict'

const INF = 900719925474099 // Number.MAX_SAFE_INTEGER / 10;

function Main(input){
	let temp = input.trim().split('\n');
	let temp2 = temp[0].split(' ').map((v)=>parseInt(v));
	let n = temp2.shift();
	let w = temp2.shift();
	let wv = new Array(n+10);

	for(let i=0;i<n;i++){
		wv[i] = temp[i+1].split(' ').map((v)=>parseInt(v));
	}

	let dp = [...new Array(n+10)].map(()=>(new Array( n*1000 + 10).fill(INF)));
	
	//初期化
	dp[0][0] = 0;

	//console.log(wv);
	//もらうDP
	for(let i=0;i<n;i++){
		//console.log('-------------------------',i);
		for(let j=0,l=dp[0].length;j<l;j++){
			//入れる
			if(j - wv[i][1] >= 0){
				//console.log("in:",dp[i+1][j], dp[i][j - wv[i][1]] + wv[i][0],wv[i][1],wv[i][0]);
				dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j - wv[i][1]] + wv[i][0]);
			}
			//入れない
			//console.log("out:",dp[i+1][j], dp[i][j],wv[i][1],wv[i][0]);
			dp[i+1][j] = Math.min(dp[i+1][j],dp[i][j]);
		}
	}
	//console.log(dp);
	let max = 0;
	for(let i=dp[n].length-1;i>=1;i--){
		if( dp[n][i] <= w ){
			max = i;
			break;
		}
	}
	console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 129280
import itertools


n, m, x = map(int, input().split())
book_costs = list()
book_skills = list()
for i in range(n):
    line = list(map(int, input().split()))
    book_cost = line[0]
    book_skill = line[1:]
    book_costs.append(book_cost)
    book_skills.append(book_skill)
    

ans = 12 * 101001
for flags in itertools.product(*[[True, False]] * n):
    cost = 0
    skill = [0 for i in range(m)]
    for i, flag in enumerate(flags):
        if flag:
            cost += book_costs[i]
            for j, skl in enumerate(book_skills[i]):
                skill[j] += skl
    
    if min(skill) >= x:
        ans = min(ans, cost)

if ans == 12 * 101001:
    print(-1)
else:
    print(ans)
    


Measured memory_bytes: 9236
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int f(int n) {
  if( (n&1)==0) return n/2;
  else return 3*n + 1;
}


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

  int pre = s;
  int cnt = 1;
  map<int, int> dic;
  dic[pre] = cnt;

  cnt++;
  while(true) {
    int next = f(pre);
    //cout << next << endl;
    if(dic[next]==0) {
      dic[next] = cnt;
      cnt++;
      pre = next;
    }
    else {
      break;
    }
  }

  cout << cnt << endl;


  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int res[2];
int a, b, c;

int main()
{
  while(scanf("%d,%d,%d", &a, &b, &c) != EOF){
    if(a * a + b * b == c * c) res[0] += 1;
    if(a == b) res[1] += 1;
  }

  cout << res[0] << endl << res[1] << endl;

  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//
int 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;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

        signed main() {
            COMinit();
           int n,k;
           cin>>n>>k;
           int a[n];
           for(int i=0;i<n;i++)cin>>a[i];
           sort(a,a+n);
           int ans=0;
           for(int i=0;i<n;i++){
               ans=(ans+a[i]*COM(i,k-1)%MOD)%MOD;
               ans=(ans+(MOD- a[i]*COM(n-1-i,k-1)%MOD))%MOD;
           }
           cout<<ans;

          
            
         return 0;

        }


Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.1415926535897932384626433832795028841971693993751058209749445923078164062862089;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
	int x=0;
	char ch=' ';
	bool flag=false;
	while(!isdigit(ch))
	{
		if(ch=='-')flag=true;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return flag?-x:x;
}
const int MAX_N=2005;
int n;
int A[MAX_N];
bool vis[MAX_N];
vec g[MAX_N];
vec g2[MAX_N];
int in[MAX_N];
void dfs(int v)
{
	if(vis[v])return;
	vis[v]=true;
	Forenska(it,g[v])
	{
		if(!vis[*it])
		{
			g2[v].pb(*it);
			dfs(*it);
		}
	}
}
void topo()
{
	set <int> s;
	rep(i,0,n)if(!vis[i])
	{
		dfs(i);
		s.insert(-i);
	}
	while(!s.empty())
	{
		int t=-*s.begin();
		s.erase(s.begin());
		Forenska(it,g2[t])
		{
			s.insert(-*it);
		}
		cout<<A[t]<<" ";
	}
}
int main()
{
	cin>>n;
	rep(i,0,n)cin>>A[i];
	sort(A,A+n);
	rep(i,0,n)rep(j,0,n)if(__gcd(A[i],A[j])>1)
	{
		g[i].pb(j);
	}
	topo();
	return 0;
}



Measured memory_bytes: 15872
S = gets.chomp
T = gets.chomp

found = false
ss = []

0.upto(S.size - T.size) do |i|
  f = true
  S[i...(i + T.size)].chars.each_with_index do |c, i|
    unless c == '?'
      if T[i] == c
        next
      end
      f = false
      break
    end
  end

  if f
    found = true
    s = S.dup
    s[i...(i + T.size)] = T
    ss << s.gsub(/\?/, 'a')
  end
end

if found
  puts ss.sort.first
else
  puts 'UNRESTORABLE'
end

Measured memory_bytes: 1788
import sys
from collections import Counter


class UnionFindTree:
    def __init__(self, n: int) -> None:
        self.par = list(range(n))
        self.rank = [0] * n

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


def resolve(in_, out):
    N, K, L = map(int, next(in_).split())

    k = UnionFindTree(N + 1)
    l = UnionFindTree(N + 1)
    for _ in range(K):
        p, q = map(int, next(in_).split())
        k.unite(p, q)
    for _ in range(L):
        p, q = map(int, next(in_).split())
        l.unite(p, q)
   
    d = Counter((k.find(i), l.find(i)) for i in range(1, N + 1))

    ans = ' '.join(str(d[(k.find(i), l.find(i))]) for i in range(1, N + 1))
    print(ans)


def main():
    resolve(sys.stdin.buffer, sys.stdout)


if __name__ == '__main__':
    main()


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

typedef long long ll;
using namespace std;

int main() {
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<ll>());
    vector<ll> acum(n);
    acum[0] = a[0];
    for (int i = 1; i < n; i++) {
        acum[i] = acum[i - 1] + a[i];
    }
    ll lb = 0;
    ll ub = 1e10;
    while (ub - lb > 1) {
        ll mid = (lb + ub)/2;
        ll count = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] * 2 < mid)
                break;
            int l = i;
            int u = n;
            while (u - l > 1) {
                int mi = (l + u)/2;
                if (a[i] + a[mi] >= mid)
                    l = mi;
                else
                    u = mi;
            }
            count += 1 + 2 * (l - i);
        }
        if (count < m)
            ub = mid;
        else
            lb = mid;
    }
    ll c = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] * 2 < lb)
            break;
        int l = i;
        int u = n;
        while (u - l > 1) {
            int mi = (l + u)/2;
            if (a[i] + a[mi] >= lb)
                l = mi;
            else
                u = mi;
        }
        c += 1 + 2 * (l - i);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] * 2 < lb)
            break;
        int l = i;
        int u = n;
        while (u - l > 1) {
            int mi = (l + u)/2;
            if (a[i] + a[mi] >= lb)
                l = mi;
            else
                u = mi;
        }
        ans += a[i] * 2 + 2 * (acum[l] - acum[i] + a[i] * (l - i));
    }
    cout << ans - lb * (c - m);
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define MAX 200000

#define max(a, b) a > b ? a : b
#define min(a, b) a < b ? a:b

int main(void)
{
    int n, R[MAX], j;
    
    scanf("%d", &n);
    
    for (j = 0; j < n; j++)
    scanf("%d", &R[j]);

    int maxv = -2000000000;
    int minv = R[0];

    for (j = 1; j < n; j++){
    maxv = max(maxv, R[j]-minv);
    minv = min(minv, R[j]);
    }

    printf("%d\n", maxv);

    return 0;
}


Measured memory_bytes: 2528
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	vector<int> A(3);
	for(int i=0;i<3;++i){
		cin>>A[i];
	}
	sort(A.begin(),A.end());
	int ans = 0;
	int res;
	res = (A[2]-A[0])/2;
	ans += res;
	A[0] += 2*res;
	
	res = (A[2]-A[1])/2;
	ans += res;
	A[1] += 2*res;

	sort(A.begin(),A.end());
	A[2] -= A[0];
	A[1] -= A[0];
	A[0] -= A[0];
	if( A[2] == 0 ){
		
	}else if( A[1] == 0){
		ans += 1;
	}else{
		ans += 2;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 384
#include <iostream>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n;
string pre, suf;

int main() {
    cin >> n;
    cin >> pre >> suf;
    for (int i = 0; i < n; i++) {
        bool flag = true;
        for (int j = i; j < n; j++) {
            if (pre[j] != suf[j - i]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << i + n << endl;
            return 0; 
        }
    }
    cout << 2 * n << endl;
}

Measured memory_bytes: 256
# すめけくんは現在のレートが 1200 未満ならば AtCoder Beginner Contest (ABC) に、
# そうでなければ AtCoder Regular Contest (ARC) に参加することにしました。 すめけくんの現在のレート x が与えられます。
# すめけくんが参加するコンテストが ABC ならば ABC と、そうでなければ ARC と出力してください。

x = int(input())

if x < 1200:
    print('ABC')

else:
    print('ARC')

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

int main()
{
  // 入力受け取り
  int N,K;
  string S;
  cin >> N >> K;
  cin >> S;
  
  S[K-1]=tolower(S[K-1]);
  
  cout << S << endl;   
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int n, k;
ll a[115000];
char c[115000];
ll dp[115000][5];

int main()
{
    cin >> n;
    cin >> a[0];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j < 5; j++)
            dp[i][j] = -1e15;
    dp[0][0] = a[0];
    for (int i = 1; i < n; i++)
    {
        cin >> c[i] >> a[i];
        if (c[i] == '+')
        {
            for (int k = 0; k < 5; k++)
            {
                for (int nk = 0; nk <= k; nk++)
                {
                    dp[i][nk] = max(dp[i][nk], dp[i - 1][k] + (k % 2 == 0 ? a[i] : -a[i]));
                }
            }
        }
        else
        {
            for (int k = 0; k < 4; k++)
            {
                for (int nk = 0; nk <= k + 1; nk++)
                {
                    dp[i][nk] = max(dp[i][nk], dp[i - 1][k] + (k % 2 == 0 ? -a[i] : a[i]));
                }
            }
        }
    }
    cout << dp[n - 1][0] << endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],k,ab[220000],ac[220000],ad[220000],mx,mi;
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n>>m>>k;
    rep(i,n){
        cin>>aa[i];
        ac[i]=ac[i-1]+aa[i];
    }
    rep(i,m){
        cin>>ab[i];
        ad[i]=ad[i-1]+ab[i];
    }
    rep(i,n+1){
        if(ac[i-1]>k){
            break;
        }
        mi=-1;
        mx=m;
        while(1){
            if(ad[(mx+mi)/2]>k-ac[i-1]){
                mx=(mx+mi)/2;
            }else{
                mi=(mx+mi)/2;
            }
            if(mx-1==mi){
                cnt=max(i+mi+1,cnt);
                break;
            }
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 16764
let rec euclid m n =
  if n = 0 then
    m
  else
    euclid n (m mod n);;

let () =
  let rec read () =
    try let (m,n) = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
        Printf.printf "%d\n" (euclid m n);
        read ()
    with End_of_file -> ()
  in read ()
;;

Measured memory_bytes: 2212
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> e(n+1);
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    int k;
    cin >> k;
    vector<int> d(n+1);
    for(int i = 0; i <= n; i++)
    {
        d[i] = 1e9;
    }
    for(int i = 0; i < k; i++)
    {
        int v, p;
        cin >> v >> p;
        que.push(P(p, v));
        d[v] = p;
    }
    while(!que.empty())
    {
        P p = que.top();
        que.pop();
        for(auto nx : e[p.second])
        {
            if(d[nx] == 1e9)
            {
                d[nx] = p.first + 1;
                que.push(P(d[nx], nx));
            }
            else if(d[nx] != p.first + 1 && d[nx] != p.first - 1)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i <= n; i++)
    {
        cout << d[i] << endl;
    }
}


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

int main() {
	// your code goes here
	int n,d;
	cin>>n;
	cin>>d;
	long long int x,y;
	int c=0;
	while(n--){
		cin>>x>>y;
		long double f=sqrt((abs(x)*abs(x))+abs((y)*abs(y)));
				long long int g=ceil(f);
		if(g<=d){
			c++;
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

void solve(){
  int a, b; cin >> a >> b; int t=1; int ans = 0;
  while(t<b) { ans++; t += (a-1);}
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}

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

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

    int ans = 0;
    for (int i = s.size() - 2; i >= 2; i -= 2) {
        if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
           cout<<i<<endl;
          return 0;
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

ll f(ll a, ll x){
    if(a<0) return 0;

    return a/x+1;
}

int main(){
    ll a, b, x;
    cin >> a >> b >> x;

    cout << f(b,x)-f(a-1,x) << endl; 
}

Measured memory_bytes: 256
x,k,d=list(map(int, input("").split()))
x=abs(x)
c=x//d
m=x%d
if c<k:
    m=abs(m)
    if (k-c)%2==0:
        x=m
    else:
        if abs(m+d) <= abs(m-d):
            x=m+d
        else:
            x=m-d
else:
    x=x-k*d
print(abs(x))

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N;
//エラトステネスの篩
bool is_prime[ 100000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int main(){
    ll N;
    cin >> N;
    if(N > 99991){
        cout << 100003 << "\n";
        return 0;
    }
    Eratosthenes(100000);
        for(int i = 0; ; i++){
        if(P[i] >= N){
            cout << P[i] << "\n";
            return 0;
        }
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    int P[100001], Y[100001];
    vector<int> list[100001];
    for (int i = 0; i < M; i++)
    {
        cin >> P[i] >> Y[i];
        list[P[i]].push_back(Y[i]);
    }
    for (int i = 0; i < N; i++)
    {
        sort(list[i + 1].begin(), list[i + 1].end());
    }
    int temp;
    for (int i = 0; i < M; i++)
    {
        cout << setfill('0') << right << setw(6) << P[i];
        temp = int(lower_bound(list[P[i]].begin(), list[P[i]].end(), Y[i]) - list[P[i]].begin()) + 1;
        cout << setfill('0') << right << setw(6) << temp;
        cout << endl;
    }
    // cin >> N;
}

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


using namespace std;
#define l long long int 
#define vl vector<l>
#define vvi vector<vector<int>>
#define rep(i,n) for (i = 0; i < n; i++) 
#define REP(i,k,n) for (i = k; i <= n; i++) 
#define REPR(i,k,n) for (i = k; i >= n; i--) 
#define pii pair<int,int>

int  main(int arg,char** argc)
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);    
    // l s,w;
    // cin>>s>>w;
    // if(s>w)
    // {
    //     cout<<"safe\n";
    // }
    // else{
    //     cout<<"unsafe\n";
    // }
    l a,b,c,d;
    l flag=0;
    cin>>a>>b>>c>>d;
    while(a>0 && c>0)
    {
        if(flag%2)
        {
            a=a-d;
        }
        else{
            c=c-b;
        }
        flag++;
    }
    // cout<<a<<" "<<c;
    if(a<=0)
    {
        cout<<"No";
    }
    else if(c<=0)
    {
        cout<<"Yes";
    }
    // l n;
    // cin>>n;
    // string s;
    // l x=1,ans=0;
    // unordered_map<string,l> map;
    // for(l i=0;i<n;i++)
    // {
    //     x=1;
    //     cin>>s;
    //     if(map.count(s)==0)
    //     {
    //         map[s]=x;
    //         ans++;
    //     }
        
    // }
    // cout<<ans;


    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,a[200010];

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

    int i; LL sum=0;
    for (i=1; i<=N; i++){
        cin >> a[i];
        sum+=a[i];
    }

    LL cr=0,res=(1LL<<60);
    for (i=1; i<N; i++){
        cr+=a[i];
        if (abs(sum-2*cr)<res)
            res=abs(sum-2*cr);
    }

    cout << res << "\n";

    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  char c;
  double sum = 0,ave = 0,cnt=0;
  while(cin >> a >> c >> b){
    ++cnt;
    sum += a * b;
    ave += b;
  }
  cout << sum <<endl << (int)(ave/cnt+0.5)<<endl;
  return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
char a[1005],b[1005];
int o[1005],p[1005];
int cmp1(char a,char b){
	return a<b;
}
int cmp2(char a,char b){
	return a>b;
}
int main(){
	gets(a);
	gets(b);
	int c=strlen(a),d=strlen(b);
	sort(a,a+c,cmp1);
	sort(b,b+d,cmp2);
	if(strcmp(a,b)<0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:u32 = read();
    let mut p:Vec<u32> = (0..n).map(|_| read()).collect();
    p.sort();
    let sum = p.iter().fold(0, |acc, x| acc + x) - p[p.len()-1] / 2;
    println!("{}", sum);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;


int main(){
 int N; cin>>N;
 if(N==1){ cout<<0<<endl;return 0;}
 vector <int> H;
 for(int i=0;i<N;i++){
     int h ; cin>>h;
     H.push_back(h);
 }

 int ans = -1;
 int kouho = 0;

 for(int i=1;i<N;i++){
     if(H[i-1] >= H[i] ){ kouho++; ans = max(kouho,ans);}
     else {ans = max(kouho,ans);kouho = 0;}


 }

 cout<<ans<<endl;

    return 0 ;
}

Measured memory_bytes: 892
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N;
    cin >> N;
    vector<int64> A(N);
    vector<int64> pref(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        pref[i] = (!i ? A[i] : pref[i-1] + A[i]);
    }

    vector<vector<int64>> dp(N, vector<int64>(N));

    auto Sum = [&] (int l, int r) {
        return pref[r] - (l - 1 >= 0 ? pref[l-1] : 0);
    };

    for (int i = 0; i < N; i++)
        dp[i][i] = A[i];

    for (int l = 2; l <= N; l++) {
        for (int i = 0; i + l - 1 < N; i++) {
            int j = i + l - 1;

            dp[i][j] = max(A[i] + Sum(i+1, j) - dp[i+1][j], A[j] + Sum(i, j-1) - dp[i][j-1]);
        }
    }

    cout << 2 * dp[0][N-1] - Sum(0, N - 1) << "\n";

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    vector<ll> count(n);
    rep(i,n) count[i] = c.end() - upper_bound(all(c),b[i]);
    vector<int> count_a(n);
    rep(i,n) count[i] *= lower_bound(all(a),b[i]) - a.begin();
    ll ans = 0;
    rep(i,n) ans += count[i];
    cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    ll n,m; cin >> n >> m;
    vector<P> is(m);
    rep(i,m) cin >> is[i].first >> is[i].second;
    vector<int> id(n);
    rep(i,n) id[i]=i;
    vector<ll> sz(n,1);
    vector<ll> ans(m);
    ans[m-1]=((n-1)*n)/2;

    for(int i=m-1; i>=1; i--){
        int f=is[i].first;
        int s=is[i].second;
        f--; s--;
        int fp=f;
        int sp=s;
        while(fp!=id[fp]){
            fp=id[fp];
            //cout << fp << ' ' << id[f] << ' ' << "fff" << endl;
        }
        while(sp!=id[sp]){
            sp=id[sp];
        }
        //cout << fp << ' ' << sp << endl;
        if(fp==sp){
            ans[i-1]=ans[i];
            continue;
        }
        ll tmp=sz[fp]*sz[sp];
        ans[i-1]=ans[i]-tmp;
        int mip,map;
        if(sz[sp]>sz[fp]){
            mip=sp;
            map=fp;
        }
        else{
            mip=fp;
            map=sp;
        }
        sz[mip]=sz[fp]+sz[sp];
        id[map]=mip;
    }
    rep(i,m) cout << ans[i] << endl;
return 0;
}



Measured memory_bytes: 4864
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := ""
	for n != 0 {
		if n%-2 == 0 {
			ans = "0" + ans
		} else {
			ans = "1" + ans
			n--
		}
		n /= -2
	}
	if ans == "" {
		ans = "0"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin >> A >> B;
    if (A==1) A+=13;
    if (B==1) B+=13;
    if (A==B)
        cout << "Draw" << endl;
    else if (A>B)
        cout << "Alice" << endl;
    else 
        cout << "Bob" << endl;
        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second 
//#pragma GCC optimize "trapv"
char a[1000+10][1000+10];
int vi[1000+10][1000+10];
	int ch,cw,dh,dw;
	int h,w;
	int mrk[1004][1004];
void bfs(int x,int y)
{
	priority_queue<pair<ll, pair<ll, ll>>>q;
	q.push({0,{x,y}});
	vi[x][y]=0;
	while(!q.empty())
	{
		int x1 = q.top().se.fi;
		int y1 = q.top().se.se;

		q.pop();
		if(mrk[x1][y1]==1)
			continue;
		mrk[x1][y1];

		for(int i=-1;i<=1;i++)
		{
			for(int j=-1;j<=1;j++)
			{
				if(abs(i)==abs(j))
					continue;
				int x2 = x1 + i;
				int y2 = y1 + j;
				if(x2<0 || x2 >=h || y2 <0 ||y2 >=w )
					continue;

				if(a[x2][y2]=='#')
					continue;

				if((vi[x2][y2]>vi[x1][y1])|| vi[x2][y2]==-1)
				{
					vi[x2][y2] = vi[x1][y1];

					q.push({-1*vi[x2][y2],{x2,y2}});
				}

			}
		}


		for(int i=-2;i<=2;i++)
		{
			for(int j=-2;j<=2;j++)
			{
				int x2 = x1+i;
				int y2 = y1 + j;
				if(x2<0 || x2 >=h || y2 <0 ||y2 >=w )
					continue;

				if(a[x2][y2]=='#')
					continue;

				if((vi[x2][y2]>vi[x1][y1]+1 )|| vi[x2][y2]==-1)
				{
					vi[x2][y2] = vi[x1][y1]+1;
					q.push({-1*vi[x2][y2],{x2,y2}});

				}

			}
		}




	}

}




int main()
{
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
	cin>>h>>w;
	cin>>ch>>cw;
	cin>>dh>>dw;
	ch--;
	cw--;
	dh--;
	dw--;
	// memset(vi,-1,sizeof(vi));
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			vi[i][j] = -1;	
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	{
		cin>>a[i][j];
	}

	bfs(ch,cw);
	if(vi[dh][dw]!=-1)
			cout<<vi[dh][dw]<<"\n";
	else
		cout<<"-1\n";

}


Measured memory_bytes: 8684
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int count = 0;
		
		for(int i = 0; i < n; i++) {
			long l = Long.parseLong(sc.next());
			while(l % 2 == 0) {
				l /= 2;
				count++;
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 31172
package main

import "fmt"

const (
	// N is the length of a side of a square
	N = 8
)

// Board represents a board to put queens
type Board struct {
	board          [N * N]int
	queenLocations [N]int
	doneRow        []int
}

func main() {
	// Initialize board with 0
	board := &Board{}

	// Receive input
	var k int
	fmt.Scanf("%d", &k)
	for i := 0; i < k; i++ {
		var r, c int
		fmt.Scanf("%d %d", &r, &c)
		board.updateBoard(r, c, 1)
		board.queenLocations[r] = c
		board.doneRow = append(board.doneRow, r)
	}

	board.calcAnswer(0)

	board.printAnswer()
}

func (b *Board) printAnswer() {
	for r := 0; r < N; r++ {
		for c := 0; c < N; c++ {
			if b.queenLocations[r] == c {
				fmt.Print("Q")
			} else {
				fmt.Print(".")
			}
		}
		fmt.Println()
	}
}

func (b *Board) updateBoard(r, c, diff int) {
	// row and column direction
	for i := 0; i < N; i++ {
		b.board[i*N+c] += diff
		b.board[r*N+i] += diff
	}

	// diagonal direction
	for i := 1; i < N; i++ {
		upperRow, lowerRow := r-i, r+i
		leftCol, rightCol := c-i, c+i
		// upper left
		if 0 <= upperRow && 0 <= leftCol {
			b.board[upperRow*N+leftCol] += diff
		}
		// upper right
		if 0 <= upperRow && rightCol < N {
			b.board[upperRow*N+rightCol] += diff
		}
		// lower left
		if lowerRow < N && 0 <= leftCol {
			b.board[lowerRow*N+leftCol] += diff
		}
		// lower right
		if lowerRow < N && rightCol < N {
			b.board[lowerRow*N+rightCol] += diff
		}
	}
}

func (b *Board) calcAnswer(r int) bool {
	if r >= N {
		return true
	}
	// doneRow has r?
	for _, v := range b.doneRow {
		if v == r {
			// this r is skipped.
			return b.calcAnswer(r + 1)
		}
	}
	for c := 0; c < N; c++ {
		if b.board[r*N+c] == 0 {
			// try to put queen
			b.queenLocations[r] = c
			b.updateBoard(r, c, 1)
			if !b.calcAnswer(r + 1) {
				// back
				b.updateBoard(r, c, -1)
			} else {
				return true
			}
		}
	}
	return false
}



Measured memory_bytes: 1152
#include<stdio.h>

int change_char(char cards_ch){
    int i;
    if(cards_ch == 'S') i = 0;
    if(cards_ch == 'H') i = 1;
    if(cards_ch == 'C') i = 2;
    if(cards_ch == 'D') i = 3;
    return i;
}

void change_num(int i){
    if(i == 0) printf("S");
    if(i == 1) printf("H");
    if(i == 2) printf("C");
    if(i == 3) printf("D");
}

int main(){
    int i, j, n, cards_num, cards[4][13] = {};
    char cards_ch;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%c", &cards_ch);
        scanf("%c %d", &cards_ch, &cards_num);
        cards[change_char(cards_ch)][cards_num - 1] = 1;
    }
    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            if(cards[i][j] == 0){
                change_num(i);
                printf(" %d\n", j + 1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2044
def aaa(a,v,b,w,t):
  if v <= w:
    return False
  if abs(b-a) / (v-w) <= t:
    return True
  return False
  

a, v  = map(int, input().split())
b, w  = map(int, input().split())
t = int(input())

ret = "YES" if aaa(a,v,b,w,t) else "NO"
print(ret)

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

int main() {
    string s, t;
    cin >> s >> t;
    ll ans = s.size();
    rep(i,s.size()-t.size()+1) {
        string tmp = s.substr(i,t.size());
        ll cnt = 0;
        rep(j,t.size()) if (tmp[j] != t[j]) cnt++;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n; n =in.nextInt();
		int k; k = in.nextInt();
		int[] h = new int[n];
		for(int i=0;i<n;i++) h[i]=in.nextInt();
		int[] dp = new int[n];
		for(int i=0;i<n;i++) dp[i]=1000000000;
		dp[0]=0;
		for(int i=1;i<n;i++)
		{
			for(int j=1;j<=k;j++)
			{
				if(i-j>=0) dp[i]=Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		//for(int i=0;i<n;++i) System.out.println(dp[i]);
		System.out.print(dp[n-1]);
	}
}


Measured memory_bytes: 53068
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cmath>

#define eps 1e-12

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int main() {
	LL x;
	cin >> x;
	LL a = 100;
	int t = 0;
	while (a < x) {
		a = (LL)(a * (1.01 + eps));
		t += 1;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 3640
n,*a = map(int,open(0).read().split())
a = sorted([(j,i) for i,j in enumerate(a)],reverse=True)
dp = [0]
for i,(j,k) in enumerate(a):
  ldp =  [abs(k-i+a)*j+b for a,b in enumerate(dp)]
  rdp =  [abs(n-1-k-a)*j+b for a,b in enumerate(dp)]
  dp = [max(a,b) for a,b in zip(ldp+[0],[0]+rdp)]
print(max(dp))

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

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

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] cnt = new int[N];
            for (int i = 2; i <= N; i++) {
                int p = in.Int();
                cnt[p - 1]++;
            }
            for (int i = 0; i < N; i++) {
                out.println(cnt[i]);
            }
        }

    }

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

        public MyScanner(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 Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 50724
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
    int n; 
    cin >> n;

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

    int ans = 100000;
    for(int i = 0; i <= n; ++i){
        int a = 0, b = 0;
        for(int j = 0; j < n; ++j){
            if(j <= i)a += w[j];
            else b += w[j];
        }
        ans = min(ans, abs(a-b));
    }

    cout << ans << endl;

}

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

int main() {
  int N,a,b,c,d;
  cin >> N;
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = (N-a*1000-b*100-c*10);
  
  if (((a==b)&&(b==c))||((b==c)&&(c==d)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, q;
string s, t, d;
int main() {
  cin >> n >> q >> s;
  for (lli i=0; i<q; ++i) {
    char c, e; cin >> c >> e;
    t.push_back(c);
    d.push_back(e);
  }

  lli sum = 0;
  lli p = n;
  for (lli i=q-1; i>=0; --i) {
    if (p > 0 && t[i] == s[p-1] && d[i] == 'R') --p;
    if (p < n && t[i] == s[p] && d[i] == 'L') ++p;
  }
  sum += n - p;
  p = -1;
  for (lli i=q-1; i>=0; --i) {
    if (p < n - 1 && t[i] == s[p+1] && d[i] == 'L') ++p;
    if (p >= 0 && t[i] == s[p] && d[i] == 'R') --p;
  }
  sum += p + 1;

  lli ans = max(0ll, n - sum);
  cout << ans << '\n';
  return 0;
}



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

using namespace std;

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

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

  vector<int> seq;
  for (int i = 1; i <=N; ++i) seq.push_back(i);

  int a, b, p = 0;
  do {
    if (seq == P) a = p;
    if (seq == Q) b = p;
    p++;
  } while(next_permutation(seq.begin(), seq.end()));
  

  cout << abs(a-b) << endl;
  

	return 0;
}



Measured memory_bytes: 256