akhauriyash/Code-Regression huggingface dataset:
export class Main {
  static main(input): string {
    const n: number = Number(input.split("\n")[0]);
    let result: number = 0;
    let i: number = 1;
    while (true) {
      const q: number = (n - i) / i;
      if (q <= i) {
        break;
      }
      const r: number = (n - i) % i;
      if (r == 0) {
        result += q;
      }
      ++i;
    }
    return `${result}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,A[200009],B[200009],pas;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a+1; b++) cin>>A[b];
	for(b=1; b<=a; b++) cin>>B[b];
	for(b=1; b<=a; b++){
		if(A[b]>=B[b]){
			pas+=B[b];
			A[b]-=B[b];
		}else{
			B[b]-=A[b];
			pas+=A[b];
			A[b]=0;
			pas+=min(A[b+1],B[b]);
			A[b+1]=max(0LL,A[b+1]-B[b]);
		}
	}
	cout<<pas;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt();
		if(a>b)
		{
			System.out.println(a-b);
		}
		else
		{
			System.out.println("0");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H * W - w * H - h * W + h * w;
	//xxx
	//xxx
}


 // a b c a b c a b c a b c
 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  //	cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 256
#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 h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int st = h1*60 + m1;
	int en = h2*60 + m2;
	cout << (en - k) - st << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
  int s;
  cin>>s;
  int a=s/100;
  int b=s%100;
  if(1<=a&&a<=12){
    if(1<=b&&b<=12)cout<<"AMBIGUOUS"<<endl;
    else cout<<"MMYY"<<endl;
}
  else {
    if(1<=b&&b<=12)cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,s1;
    int n,i;
    cin>>n;
    while(n--){
        cin>>s>>s1;
        int w1=1,w2=0,w3=0,w4=0;
        int sum=0;
        for(i=0;i<s.size();i++){
            if(s[i]>='2'&&s[i]<='9')w1=s[i]-'0';
            else if(s[i] == 'm'){sum+=1000*w1;w1=1;}
            else if(s[i] == 'c'){sum+=100*w1;w1=1;}
            else if(s[i] == 'x'){sum+=10*w1;w1=1;}
            else if(s[i] == 'i'){sum+=w1;w1=1;}
        }
        for(i=0;i<s1.size();i++){
            if(s1[i]>='2'&&s1[i]<='9')w1=s1[i]-'0';
            else if(s1[i] == 'm'){sum+=1000*w1;w1=1;}
            else if(s1[i] == 'c'){sum+=100*w1;w1=1;}
            else if(s1[i] == 'x'){sum+=10*w1;w1=1;}
            else if(s1[i] == 'i'){sum+=w1;w1=1;}
        }
        w1=sum/1000;
        if(w1==1)cout<<"m";
        else if(w1>1)cout<<w1<<"m";
        w2=(sum-w1*1000)/100;
        if(w2==1)cout<<"c";
        else if(w2>1)cout<<w2<<"c";
        w3=(sum-w1*1000-w2*100)/10;
        if(w3==1)cout<<"x";
        else if(w3>1)cout<<w3<<"x";
        w4=(sum-w1*1000-w2*100-w3*10);
        if(w4==1)cout<<"i";
        else if(w4>1)cout<<w4<<"i";
        cout<<endl;
    }
    return 0;
}
 

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
int main()
{
  string a;
  cin >> a;
  if (a.size()==3){
    cout << a.at(2) << a.at(1) << a.at(0) << endl;
  }
  else {
    cout << a.at(0) << a.at(1) << endl;
      
  }
    
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
priority_queue<pii,vector<pii>,greater<pii>> hp;
struct node{int a,b,c;}w[MAXN];
bool cmp(node n1,node n2){return n1.a-n1.b>n2.a-n2.b;}
int X,Y,Z,n;
LL a1[MAXN];
int main()
{
	X=read();Y=read();Z=read();n=X+Y+Z;
	for(int i=1;i<=n;i++)w[i].a=read(),w[i].b=read(),w[i].c=read();
	sort(w+1,w+1+n,cmp);LL sum=0;
	for(int i=1;i<=n;i++)
	{
		pii temp=mp(w[i].a-w[i].c,i);sum+=w[i].a;
		hp.push(temp);
		if(hp.size()==X+1)temp=hp.top(),hp.pop(),sum-=temp.first;
		a1[i]=sum;
	}
	while(!hp.empty())hp.pop();sum=0;
	for(int i=n;i>=1;i--)
	{
		pii temp=mp(w[i].b-w[i].c,i);sum+=w[i].b;
		hp.push(temp);
		if(hp.size()==Y+1)temp=hp.top(),hp.pop(),sum-=temp.first;
		a1[i-1]+=sum;
	}LL ans=0;
	for(int i=1;i<=n;i++)if(i>=X&&n-i>=Y)ans=max(ans,a1[i]);
	pr2(ans);
	return 0;
}


Measured memory_bytes: 3320
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);

        if(n % 2 == 1) {
            long min = a[n/2];
            long max = b[n/2];
            System.out.println(max-min+1);
        } else {
            long min1 = a[n/2-1];
            long min2 = a[n/2];
            long max1 = b[n/2-1];
            long max2 = b[n/2];
            System.out.println(max1+max2-min1-min2+1);
        }



    }



}

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

int f(int n,int k)
{
  if(n==1)return 0;
  return (f(n-1,k)+k)%n;
}

int main()
{
  int n,k,m;
  while(cin>>n>>k>>m,n|k|m){
    m=(m-k+1+n)%n;
    cout<<(f(n,k)+m-1+n)%n+1<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

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(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    /*
    rep(i,n){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    rep(i,n){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    rep(i,n){
        cout<<c[i]<<" ";
    }
    cout<<endl;
    */
    vector<int64_t> cnt(n);
    int64_t ans=0;
    //b[0]を中段において作れるのは、(a<b[0]の数) * (b[0]<cの数)
    rep(i,n){
        int64_t cnt_of_a,cnt_of_c;
        int cpoint;
        cnt_of_a = lower_bound(a.begin(),a.end(),b[i])-a.begin();
        //ソート済み配列a内で、b[i] 以上の値が出る添え字を返す

        cpoint = upper_bound(c.begin(),c.end(),b[i])-c.begin();
        //ソート済み配列c内で、b[i]「より大きい」値が出る添え字を返す
        //なかったら配列の大きさ、つまりnを返す
        cnt_of_c = n - cpoint;
        cnt[i] = cnt_of_a*cnt_of_c;
        //cout<<cnt[i]<<endl;
        ans += cnt[i];
        
    }
    cout<<ans<<endl;
}

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

struct E{ int x, c; };

int n, s[100010], c, ms;
ll ans, msd, md = 1e9;
vector<E> e[100010];

int sf(int x, int p){
	s[x] = 1;
	for(auto &i : e[x]){
		if(i.x == p) continue;
		s[x] += sf(i.x, x);
	}
	return s[x];
}

int cf(int x, int p, int t){
	for(auto &i : e[x]){
		if(i.x != p && s[i.x] > t / 2) return cf(i.x, x, t);
	}
	return x;
}

void g(int x, int p, ll d){
	ans += 2 * d;
	for(auto &i : e[x]){
		if(i.x == p) continue;
		if(ms < s[i.x]){
			ms = s[i.x];
			msd = d + i.c;
		}
		md = min(md, d + i.c);
		g(i.x, x, d + i.c);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 0, x, y, z; i < n - 1; i++){
		scanf("%d%d%d", &x, &y, &z);
		e[x].push_back({y, z});
		e[y].push_back({x, z});
	}
	c = cf(1, 0, sf(1, 0));
	sf(c, 0);
	g(c, 0, 0);
	if(!(n & 1) && ms == n / 2) printf("%lld\n", ans - msd);
	else printf("%lld\n", ans - md);
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> A(N);
    REP(i,N)A[i] = in();
    sort(ALL(A));
    cout << A[N/2] - A[N/2-1] << "\n";
}


Measured memory_bytes: 640
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())
d = [int(input()) for _ in range(n)]

print(len(set(d)))


Measured memory_bytes: 9004
#! /usr/bin python3
N, M = map(int, input().split())
H = list(map(int, input().split()))

check = [1]*N 
for i in range(0, M):
    a, b = map(int, input().split())
    a = a-1
    b = b-1
    if H[a] < H[b]:
        check[a] = 0
    elif H[a] > H[b]:
        check[b] = 0
    else:
        check[a] = 0
        check[b] = 0

print(check.count(1))

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

int main() {
    string s, t, ans = "Yes";
    cin >> s >> t;
    map<char, int> sm, tm;
    rep(i, s.size()) {
        sm[s[i]]++;
    }
    rep(i, t.size()) {
        tm[t[i]]++;
    }

    vector<int> sv, tv;
    for (auto it = sm.begin(); it != sm.end(); it++) {
        pair<char, int> p = *it;
        sv.push_back(p.second);
    }
    for (auto it = tm.begin(); it != tm.end(); it++) {
        pair<char, int> p = *it;
        tv.push_back(p.second);
    }
    if (sv.size() != tv.size()) ans = "No";

    sort(sv.begin(), sv.end());
    sort(tv.begin(), tv.end());
    rep(i, min(sv.size(), tv.size())) {
        if (sv[i] != tv[i]) ans = "No";
    }

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

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> tenbodais(n);
    rep(i, n){
        cin >> tenbodais[i];
    }
    vector<vector<int>> vec(n, vector<int>());
    rep(j, m){
        int a, b;
        cin >> a >> b;
        vec[a-1].push_back(b-1);
        vec[b-1].push_back(a-1);
    }
    int cnt = 0;
    rep(i, n){
        bool yoi = true;
        for(int j=0; j<vec[i].size(); j++){
            if(tenbodais[i] <= tenbodais[vec[i][j]]) yoi = false;
        }
        if(yoi) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 8732
#include <stdio.h>
 
int main(void) {
	int n,m,x=0,y=0,z=0,i,j;
	scanf("%d %d",&n,&m);
	m=m/1000;
 
	for(i=0;i<=m;i++){
		z=i;
		for(j=0;j<=(m-i)/5;j++){
			y=j;
			if(((m-z-5*y)%10)==0){
				x=(m-z-5*y)/10;
				if((x+y+z)==n){
					printf("%d %d %d",x,y,z);
					return 0;
				}
			}
		}
	}
	printf("-1 -1 -1");
	return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (A+B+C>=22){
    cout << "bust" << endl;
  }
  else if (A+B+C<=21){
    cout << "win" << endl;
  }
    
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int n,k;
  int ans=0;
  cin >> n >> k;

  vector<int> a(n);

  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];

  rep(i,n) {
    if (a[i] >= k) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
    double n,d,cnt=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        double x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3764
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int N, A, B;
ll high, low , mid;
ll mx = 0;
ll H[100010];

ll solve(ll n) {
	ll num_A = 0;
	for (int i = 0; i < N; i++) {
		ll num_B = H[i] - B*n;
		if (num_B > 0) {
			num_A += (num_B - 1) / (A - B) + 1;
			if (num_A > n)return false;
		}
	}
	return true;
}

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

	for (int i = 0; i < N; i++) {
		cin >> H[i];
		if (mx < H[i])
			mx = H[i];
	}

	high = mx;
	while (low < high) {
		mid = (low + high) / 2;
		if (solve(mid))high = mid;
		else low = mid + 1;
	}
	cout << high << endl;
	return	0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

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

int input[52],n,summ;
int ans[52];
int cnt[14];

bool dfs(int cc,int sum) {
    if(cc == n) return true;
    rep(i,14) {
        if(cnt[i] == 0) continue;
        if((sum-i)%i == 0) {
            cnt[i]--;
            ans[cc] = i;
            if(dfs(cc+1,sum-i)) return true;
            ans[cc] = -1;
            cnt[i]++;
        }
    }
    return false;
}

int main() {
    while(scanf("%d", &n), n) {
        summ = 0;
        memset(cnt, 0, sizeof(cnt));
        rep(i,n) {
            scanf("%d", input+i);
            summ += input[i];
            cnt[input[i]]++;
        }

        if(dfs(0,summ)) {
            for(int i=n-1; i>0; --i)  printf("%d ", ans[i]);
            printf("%d\n",ans[0]);
        }else{
            printf("No\n");
        }
    }
}

Measured memory_bytes: 760
#include<stdio.h>
int main(){
	int a,b,c,t;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
while True:
    n=int(input())
    if n==0:
        break
    m=10000
    M=0
    sum=0
    for i in range(n):
        s=int(input())
        m=min(m,s)
        M=max(M,s)
        sum+=s
    print((sum-M-m)//(n-2))


Measured memory_bytes: 5588
#include<iostream>
double m(double a,double b){return a>b?a:b;}
main(){for(double a,b,c,d,e,f,g,h;std::cin>>a>>b>>c>>d>>e>>f>>g>>h;){if(((m(e,g)+m(-a,-c))*(m(a,c)+m(-e,-g))>=0)&&((m(f,h)+m(-b,-d))*(m(b,d)+m(-f,-h))>=0))std::cout<<"YES\n";else std::cout<<"NO\n";}}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  int r, c;
  while (r = in(), c = in(), r){
    if (r % 2 == 0 || c % 2 == 0){
      puts("yes");
    }
    else {
      puts("no");
    }
  }
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iterator>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define VE vector<int>
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int N;
  string S,T;
  cin>>N>>S>>T;
  FOR(i,0,N){
    int j=0;
    while(i+j<N&&S[i+j]==T[j]){
      j++;
    }
    if(i+j==N){
      cout<<N+i<<endl;
      return 0;
    }
  }
  cout<<2*N<<endl;
  return 0;
}


Measured memory_bytes: 256
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n,k = MI()
h = [0]+ LI()
#h[i]はi番目の高さ
#0-indexedにしておくと考えにくいので1-indexedにしておく
#dp[i]は足場iにいくのに必要な最小コスト
dp = [10**15]*(n+1)
#これも1-indexedにしておく
dp[1] = 0
#2番目の足場に移るのは1番目の足場からいくしかないのでわけて考える
#最初蛙は足場1にいるため最小コストは0としておく
for i in range(2,n+1):
  for j in range(1,k+1):
    if i - j >= 0:
      dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
print(dp[n])

Measured memory_bytes: 85520
///in the name of ALLAH
#include<bits/stdc++.h>
#define mx 100005
using namespace std;
typedef long long ll;
vector<ll>adj[mx];
bool visited[mx];
void dfs(ll u)
{
    visited[u]=1;
    for(int i=0;i<adj[u].size();i++)
    {
        ll v=adj[u][i];
        if(visited[v]!=1)
        dfs(v);
    }
}
int main()
{
    ll node,edge,x,y,comp=0;
    cin>>node>>edge;
    for(int i=0;i<edge;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i=1;i<=node;i++)
    {
        if(visited[i]==0)
        {
            comp++;
            dfs(i);
        }
    }
    cout<<comp-1<<endl;

}


Measured memory_bytes: 10364
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int a,b;
 cin>>a>>b;
 cout<<(a+b)%24;
 system("pause");
 return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef long double ld;
vector<pair<ld,int>> p;
vector<ll> v;
ll a[200010],b[200010],dp[200010][40],c[200010];
int main(){
	ll i,j,n,t;
	cin >> n >> t; t++;
	for(i=0;i<n;i++){
		cin >> a[i] >> b[i];
		a[i]++; b[i]++;
		if(a[i]>=2){
			p.push_back({(ld)(a[i] - 1)/(ld)b[i],i});
		}else{
			v.push_back(b[i]);
		}
	}
	sort(p.rbegin(),p.rend());
	sort(v.begin(),v.end());
	for(i=0;i<=p.size();i++){
		for(j=0;j<40;j++){
			dp[i][j] = 100000000000;
		}
	}
	dp[0][0] = 1;
	for(i=1;i<=p.size();i++){
		for(j=0;j<40;j++){
			int k = p[i - 1].second;
			if(dp[i - 1][j]<=t) dp[i][j] = min(dp[i][j],dp[i - 1][j]);
			if(j>=1 && dp[i - 1][j - 1]<=t && a[k]*dp[i - 1][j - 1] + b[k]<=t) dp[i][j] = min(dp[i][j],a[k]*dp[i - 1][j - 1] + b[k]);
		}
	}
	ll sum = 0;
	int k = 0;
	for(j=39;j>=0;j--){
		while(k<v.size() && dp[p.size()][j] + sum + v[k]<=t){
			sum += v[k];
			k++;
		}
		c[j] = k;
	}
	ll ans = 0;
	for(j=0;j<40;j++){
		if(dp[p.size()][j]<=t){
			ans = max(ans,j + c[j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 73832
import java.util.Scanner;
import java.util.ArrayList;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    ArrayList <Integer> li = new ArrayList <Integer>();
    ArrayList <Integer> lili = new ArrayList <Integer>();
    for(int i=0; i<number-1; i++){
      int a = sc.nextInt();
      li.add(a);
    }
    for(int i=0;i<number-1;i++){
      lili.add(0);
    }
    for(int i=0; i<number-1; i++){
      int a = li.get(i);
      lili.set(a-1,lili.get(a-1)+1);
    }
    for(int i=0;i<number-1;i++){
      System.out.println(lili.get(i));
    }
    System.out.println(0);
  }
}


Measured memory_bytes: 62432
N, A, B = map(int, input().split())
S = list(input())

answer = 0
b_list = 0
for idx, moji in enumerate(S):
    if moji == "a" and answer < A + B:
        answer += 1
        print("Yes")
        continue
    elif moji == "b":
        b_list += 1
        if answer < A + B and b_list <= B:
            answer += 1
            print("Yes")
            continue
    print("No")


Measured memory_bytes: 4708
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REPI(i, S, N) for(int i=int(S); i<int(N); i++)
#define REP(i, N) REPI(i, 0, N)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> D,T,S;


  return ((S * T >= D) ? "Yes" : "No");
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
typedef std::vector<pl> vpl;
const long double EPS = 1e-9;

#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c) 
#define rsort(a,n) sort(a,a+n,greater<>())
#define Forchar(c,a,z) for(char (c) = (a); (c) <= (z); (c)++) 
#define cntchar(s,c) count(all((s)), c)

const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100000;

int main(void){
    ll a, b;
    str s,t;
 
    in1(a);
    if (a<2) pr(1);
    else if (a < 4) pr(2);
    else if (a < 8) pr(4);
    else if (a < 16) pr(8);
    else if (a < 32) pr(16);
    else if (a < 64) pr(32);
    else if (a < 128) pr(64);

 
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef pair<string, string> S;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int H, W, h, w;

void solve() {
    int a[H][W];
    if (H % h == 0 && W % w == 0) {
        cout << "No" << endl;
        return;
    } else if (H % h != 0) {
        for (int i = 0; i < W; i++) {
            for (int j = 0; j < H; j++) {
                a[j][i] = ((j+1)%h==0 ? -100000*(h-1)-1  : 100000);
            }
        }
    } else {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                a[i][j] = ((j+1)%w==0 ? -100000*(w-1)-1 : 100000);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << a[i][j];
            if (j < W-1)
                cout << " ";
        }
        cout << endl;
    }
}

void input() {
    cin >> H >> W >> h >> w;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


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

typedef long long ll;

#define rep0(i, n) for(ll i=0; i<(ll)(n); i++)
#define rep1(i, n) for(ll i=1; i<=(ll)(n); i++)
#define rep(i, a, b) for(ll i=(ll)a; i<=(ll)(b); i++)
#define rep0r(i, n) for(ll i=(ll)(n)-1; i>=0; i--)
#define rep1r(i, n) for(ll i=(ll)(n); i>0; i--)
#define repr(i, a, b) for(ll i=(ll)b; i>=(ll)(a); i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a * b / __gcd(a, b)


void solve() {
    ll n, m, sum = 0;

    cin >> n >> m;

    rep0(i, m) {
        ll x;
        cin >> x;
        sum += x;
    }
    
    if(n >= sum) {
        cout << n - sum << '\n';
    } else {
        cout << -1 << '\n';
    }

}


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

Measured memory_bytes: 3652
use std::cmp;

// input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// body
fn main() {
    input! {
        _n: usize,
        m: usize,
        ranges: [(usize, usize); m],
    };

    let mut ans = ranges[0];
    for range in ranges {
        let min = cmp::max(ans.0, range.0);
        let max = cmp::min(ans.1, range.1);
        ans = (min, max);
    };
    if ans.0 > ans.1 {
        println!("{}", 0);
    } else {
        println!("{}", ans.1 - ans.0 + 1);
    };
}


Measured memory_bytes: 6396
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

//h = max(H-|X-Cx|-|Y-Cy|, 0)
//Cx, Cy, H

typedef struct xyh_{
    ll x;
    ll y;
    ll h;
}xyh;


bool func(xyh a, xyh b){
    if(a.h > b.h) return true;
    else if(a.h == b.h && (a.x + a.y)>(b.x + b.y)){
        return true;
    }
    else return false;
}

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

    vector<xyh> P, INP;
    rep(i, N){
        xyh inp;
        cin >> inp.x >> inp.y >> inp.h;
        INP.pb(inp);
    }
    sort(all(INP), func);

    rep(times,N){
        ll xi = INP[times].x;
        ll yi = INP[times].y;
        ll hi = INP[times].h;

        if(times == 0 ){
            rep(x, 101)rep(y,101){//rep(h,101){
                ll h = hi + abs(x-xi) +abs(y-yi);
                xyh Pi;
                Pi.x = x;
                Pi.y = y;
                Pi.h = h;
                P.pb(Pi);
            }
        }
        else{
            for(ll i = P.size()-1; i>=0; i--){
                ll x = P[i].x;
                ll y = P[i].y;
                ll h = P[i].h;
                if(hi != max(h - abs(x-xi)-abs(y-yi) , 0LL)){
                    P.erase(P.begin() + i);
                }
            }
        }
    }

    cout << P[0].x << " " << P[0].y << " " << P[0].h << endl;
    //数学的に解けると思うが。。。。





    return 0;
}

/*
/^[\w!\x22\#$%&@\'() * +,-.\/;:]+$/
*/


Measured memory_bytes: 832
n,k=map(int,input().split())
count=10**18 
if abs(n)>abs(k):
  a=n//k
  n=abs(n)-a*k
  
  
for i in range(10*18):
  n=abs(n-k)
  if count>n:
    count=n
  if count==0:
    print(0)
    exit()
    
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define ll              long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define sort(x)         sort(all(x))
#define umii            unordered_map<int,int>
#define lli             list<int>             
#define gcd(m,n)        __gcd(m,n)   
#define mib             map<int,bool>

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
 
//////////////////////////////code//////////////////////////////
int lower(vector<int>&a,int key,int low,int high)
{
    int ans=-1;
    while(low<=high)
    {
        int mid = (low+high)/2;
        if(a[mid]>=key)
        {
            ans=mid;
            high=mid-1;
        }
         else
          low=mid+1;
    }
    return ans;
}
int upper(vector<int>&a,int key,int low,int high)
{
    int ans=-1;
    while(low<=high)
    {
        int mid = (low+high)/2;
        if(a[mid]<=key)
        {
            ans=mid;
           low=mid+1;
        }
        else
         high=mid-1;
    }
    return ans;
}
int32_t main()
{
  fast();
  int n;
  cin>>n;
  vi a(n-1);
  
  for(int i=0;i<n-1;i++) cin>>a[i];
  
  sort(a);
 
  
  for(int i=1;i<=n;i++)
  {
  	int x = upper(a,i,0,n-2);
  	int y = lower(a,i,0,n-2);
  	if(x!=-1 && y!=-1)
  	cout<<x-y+1<<"\n";
  	else
  	cout<<0<<'\n';
  }
  

}

Measured memory_bytes: 4752
import numpy as np
from collections import deque
H, W = map(int, input().split())
L = []

for i in range(H):
  S = input()  
  L.append(list(1 if s == "." else 0 for s in S))
L = np.array(L)
S = np.zeros((H,W))
Q = deque(())
Q.append((0,0))

while Q:
  i, j = Q.popleft()
  for ti, tj in ((i+1, j), (i, j+1), (i-1, j), (i, j-1)):
    if 0 <= ti < H and 0 <= tj < W:
      if L[ti][tj] and S[ti][tj] == 0:
        S[ti][tj] = S[i][j] + 1
        Q.append((ti, tj))
print (int(np.sum(L) - S[-1][-1] - 1) if S[-1][-1] != 0 else -1)

Measured memory_bytes: 12500
import sys
sys.setrecursionlimit(10**7)
K=int(input())
S=input()
M=len(S)
N=K+M
mod=10**9+7
ans=pow(26,N,mod)
class Data():
    def __init__(self):
        self.power=1
        self.rev=1     
class Combi():
    def __init__(self,N,mod):
        self.lists=[Data() for _ in range(N+1)]
        self.mod=mod  
        for i in range(2,N+1):
            self.lists[i].power=((self.lists[i-1].power)*i)%self.mod
        self.lists[N].rev=pow(self.lists[N].power,self.mod-2,self.mod)
        for j in range(N,0,-1):
            self.lists[j-1].rev=((self.lists[j].rev)*j)%self.mod

    def combi(self,K,R):
        if K<R:
            return 0
        else:
            return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev))%self.mod
        
c=Combi(2*10**6+10000,mod)
for i in range(M):
    ans-=c.combi(N,i)*pow(25,N-i,mod)
    ans%=mod
print(ans%mod)


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


bool solve(int N, vi& a, vi& b, int K, vi& v, vi& p) {
    priority_queue<ii, vector<ii>, greater<ii>> pq;

    vvi nxt(N);
    rep(i,N-1) {
        nxt[a[i]].pb(b[i]);
        nxt[b[i]].pb(a[i]);
    }
    vi fixed(N, -1);
    rep(i,K){
        fixed[v[i]] = p[i];
        pq.emplace(p[i], v[i]);
    }

    while (!pq.empty()) {
        ii t = pq.top(); pq.pop();
        int value = t.first, u = t.second;
        for (int v: nxt[u]) {
            if (fixed[v] == -1) {
                fixed[v] = value+1;
                pq.emplace(value+1, v);
            } else {
                if (abs(fixed[v] - value) != 1) return false;
            }
        }
    }

    printf("Yes\n");
    rep(i,N){
        printf("%d\n", fixed[i]);
    }
    return true;
}

int main() {
    int N; scanf("%d",&N);
    vi a(N-1), b(N-1);
    rep(i,N-1){
        scanf("%d%d",&a[i],&b[i]);
        --a[i]; --b[i];
    }
    int K; scanf("%d",&K);
    vi v(K), p(K);
    rep(i,K){
        scanf("%d%d",&v[i],&p[i]);
        --v[i];
    }
    if (!solve(N,a,b,K,v,p)){
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 9336
A,B,C,X,Y = map(int,input().split())
ans1 = X * A + Y * B
ans2 =max(X, Y) * 2 * C
if X > Y:
    ans3 = 2 * C * Y + A * (X - Y)
else:
    ans3 = 2 * C * X + B * (Y - X)
print(min(ans1,ans2,ans3))

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

int main() {
  int N;
  map<string, int> poll;

  cin >> N;
  for (int i = 0; i < N; i++) {
    string name;
    cin >> name;
    poll[name]++;
  }

  int max_vote = 0;
  for (auto& vote : poll) {
    max_vote = max(max_vote, vote.second);
  }

  for (auto& vote : poll) {
    if (vote.second == max_vote) {
      cout << vote.first << endl;
    }
  }
}

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

using namespace std;

int main() {
    string weather;
    cin >> weather;
    if (weather == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (weather == "Cloudy") {
        cout << "Rainy" << endl;
    } else if (weather == "Rainy") {
        cout << "Sunny" << endl;
    }
}

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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  
  int ans = 0;
  
  for(char first = '0'; first <= '9'; ++first){
  	for(char second = '0'; second <= '9'; ++second){
  		for(char third = '0'; third <= '9'; ++third){
  			int dp[3] = {0,0,0};
  			for(int i = 0; i < n; i++){
  				if(s[i] == third && dp[1]){
  					dp[2] = 1;
  				}
  				
  				if(s[i] == second && dp[0]){
  					dp[1] = 1;
  				}
  				
  				if(s[i] == first){
  					dp[0] = 1;
  				}
  			}
  			ans += dp[2];
  		}
  	}
  }
  
  cout<< ans << endl;
  
}

Measured memory_bytes: 256
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日  1/14 20:40:13 2018
 * Ended  Time*  : 日  1/14 20:46:12 2018
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

const int MaxN = 1e5;
int n;
int a[MaxN + 5];


int main()
{
	while(~scanf("%d", &n)){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		LL Min = 2, Max = 2;
		for(int i = n; i >= 1; i--){
			if(Min % a[i] != 0)  Min = a[i]*(Min/a[i]+1);
			Max = a[i]*(Max/a[i]+1)-1;
		}
		if(Min > Max) printf("-1\n");
		else printf("%lld %lld\n", Min, Max);
	}
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define RED 0
#define YELLOW 1
#define GREEN 2
void dfs(int s, int p, vector<vector<int> >& G, vector<int>&visited, int & ans){
	visited[s] = YELLOW;
	ans++;
	int v;
	for (int i = 0; i < G[s].size() ; ++i)
	{
		v = G[s][i];
		if(v==p) continue;
		if(visited[v]==RED)
			dfs(v, s, G, visited, ans);
	}
	visited[s] = GREEN;
}

int main(int argc, char const *argv[])
{
	int N, M, a, b;
	cin>>N>>M;
	vector<vector<int> > G(N);
	for (int i = 0; i < M; ++i)
	{
		scanf("%d%d",&a,&b);
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> visited(N, RED);
	int ans = 0;
	int SIZE;
	for (int i = 0; i < N; ++i)
	{
		if(visited[i]==RED){
			SIZE = 0;
			dfs(i, -1, G, visited, SIZE);
			ans = max(ans, SIZE);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 30772
#include<iostream>
#include<vector>
#include<string.h>

using namespace std;

int main()
{
    vector<char> s;
    char ch[201];

    int m;

    while(cin>>ch&&ch[0]!='-')
    {
        for(int i=0;i<strlen(ch);i++)
        {
            s.push_back(ch[i]);
        }
        cin>>m;
        int h;
        for(int i=0;i<m;i++)
        {
            cin>>h;
            for(int i=0;i<h;i++)
            {
                s.push_back(s[0]);
                s.erase(s.begin());
            }
        }

        for(int i=0;i<s.size();i++)
        {
            cout<<s[i];
        }
        cout<<endl;

        s.clear();
    }



    return 0;
}



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

int main()
{
    int n;
    int g=0;
    scanf("%d",&n);
    if(n<4) printf("No\n");
    else if(n%4==0 || n%7==0) printf("Yes\n");
    else
    {
        for(int i=0; i<=30; i++)
        {
            int t=n-i*4;
            if(t<=0)
            {
                g=1;
                break;
            }
            else if(t%7==0) break;
        }
        if(g==1) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
int d=a*100+b*10+c;
if(d%4==0)
cout<<"YES";
else
cout<<"NO";
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rint register int 
using namespace std;
const int Maxn = 1e5 + 5;

char buf[1 << 20], *p1, *p2;
#define getchar() ((p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)
int read() {
	rint s = 0, f = 1; register char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); }
	return s * f;
}

int n, tot = 0, a[Maxn], b[Maxn], sum[Maxn];

int l, r;

struct Treearray {
  
  int c[Maxn << 1];
  void clear() { for (rint i = 1; i <= n * 2; ++i) c[i] = 0; }
  void add(int x, int y) { for (; x <= n * 2; x += (x & -x)) c[x] += y; }
  int query(int x) {
    rint res = 0;
    for (; x; x -= (x & -x)) res += c[x];
    return res;
  }
} t;

void input() {
  n = read();
  for (rint i = 1; i <= n; ++i) a[i] = read(), r = max(r, a[i]);
  ++r;
}

namespace Solution {

  namespace Binary_ans {
    bool check(int mid) {
      t.clear();
      sum[0] = 0;
      for (rint i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] >= mid ? 1 : -1);
      long long res = 0;
      for (rint i = 0; i <= n; ++i) {
        res += t.query(sum[i] + n);
        t.add(sum[i] + n, 1);
      }
      return res >= 1LL * n * (n + 1) / 4;
    }
    void Binary() {
      while (r - l > 1) {
      	rint mid = (l + r) >> 1;
      	check(mid) ? l = mid : r = mid;
			}
    }
  } 

  void solve() {
    Binary_ans :: Binary();
    printf("%d\n", l);
  }
}

signed main() {
  input(); 
  Solution :: solve();
  return 0;
}

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

int a[10],x[11][11][10];

int dfs(int B,int C,int m){//a[m]????????????????£????
	if(m==10){
		return 0;
	}else if(x[B][C][m]>=0){
		return x[B][C][m];
	}else if(a[m]>B){
		if(dfs(a[m],C,m+1)==0){
			x[B][C][m]=0;
			return 0;
		}else if(a[m]>C){
			if(dfs(B,a[m],m+1)==0){
				x[B][C][m]=0;
				return 0;
			}else{
				x[B][C][m]=1;
				return 1;
			}
		}else{
			x[B][C][m]=1;
			return 1;
		}
	}else if(a[m]>C){
		if(dfs(B,a[m],m+1)==0){
			x[B][C][m]=0;
			return 0;
		}else{
			x[B][C][m]=1;
			return 1;
		}
	}else{
		x[B][C][m]=1;
		return 1;
	}
}

int main(){
	int n;
	cin>>n;
	for(int q=0;q<n;++q){
		for(int i=0;i<10;++i){
			cin>>a[i];
			a[i];
		}
		for(int i=0;i<11;++i){
			for(int j=0;j<11;++j){
				for(int k=0;k<10;++k){
					x[i][j][k]=-1;
				}
			}
		}
		if(dfs(0,0,0)==0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

Measured memory_bytes: 1156
let f h w =
  let rec pr_hash w' =
    if w' < -1 then print_newline ()
    else (print_char '#' ; pr_hash (pred w'))
  in
  let rec pr_row h' =
    if h' <= 0 then ()
    else
      Scanf.scanf "%s\n" (fun row ->
          Printf.printf "#%s#\n" row; pr_row (pred h'))
  in
  pr_hash w;
  pr_row h;
  pr_hash w;;

let () = Scanf.scanf "%d %d\n" f

Measured memory_bytes: 512