akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if ((A == B && B == C) || (A != B && B != C && A != C)) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    int cnt = 0;

    cin >> s;

    if (s[0]== '1') cnt++;
    if (s[1]== '1') cnt++;
    if (s[2]== '1') cnt++;

    cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
L = []
ans = 0
for i in range(N):
  L.append(A[i] - (i + 1))
L = sorted(L)
B = L[N // 2]
for i in range(N):
  ans += abs(A[i]-(B + i + 1))
print(ans)

Measured memory_bytes: 26180
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,M;
string S,T;
ll A[100007];

int main(){
  cin >> N >> M;
  ll Z=0,C=0;
  rep(i,N){
    cin >> A[i];
    Z+=A[i];
  }
  rep(i,N){
    if(A[i]*4*M>=Z){
      C++;
    }
  }
  if(C>=M){
    cYes;
  }
  else{
    cNo;
  }
}

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

int main() {
  
  int a,n;
  cin >> a;
  
  n = a % 10;
  
  if ( n ==2 || n == 4 || n == 5 || n == 7 || n == 9 ){
    cout << "hon" << endl;
  }else if ( n == 0 || n == 1 || n == 6 || n == 8 ){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
  
  
}



Measured memory_bytes: 3592
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return b-a;
}

const [n, k] : number[] = input[0].split(' ').map((x: string): number => +x);
const h : number[] = input[1].split(' ').map((x: string): number => +x);

h.sort(compareFunc);

if (k >= n){
    console.log(0);
}else{
    let ans : number = 0;
    for (let i = k; i<n; i++){
        ans += h[i];
    }
    console.log(ans);
}

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

#define INF INT_MAX
#define ll long long

using namespace std;

int main(){
	string str;
	while(true){
		getline(cin, str);
		if(str == "."){
			break;
		}
		vector<char> v;	//0:( 1:[
		bool flag = true;
		for(int i = 0;i < str.length();i++){
			if(str[i] == '('){
				v.push_back('(');
			}else if(str[i] == '['){
				v.push_back('[');
			}else if(str[i] == ')'){
				if(v.size() > 0 && v[v.size() - 1] == '('){
					v.pop_back();
				}else{
					flag = false;
					break;
				}
			}else if(str[i] == ']'){
				if(v.size() > 0 && v[v.size() - 1] == '['){
					v.pop_back();
				}else{
					flag = false;
					break;
				}
			}
		}
		if(v.size() > 0){
			flag = false;
		}

		if(flag){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}

	return 0;
}

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

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

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

int main(void){
    string s;
    cin >> s;
    int n = s.length();
    bool f = true;
    if (n % 2) f = false;
    REP(i,n){
        if (i % 2 == 0 && s[i] != 'h') f = false;
        if (i % 2 == 1 && s[i] != 'i') f = false;
    }
    cout << (f ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(m);
	vector<int>b(m);
	vector<int>c(m,0);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		vector<bool>cc(n, false);
		for (int j = 0; j < b[i];j++) {
			int p; cin >> p;
			cc[p-1] = true;
		}
		
		for (int j = n-1; j >= 0;j--) {
			c[i] *= 2;
			if (cc[j]) {
				c[i] += 1;
		    }
		}
	}
	int inf = 1000000000;
	vector<vector<int>>dp(m + 1, vector<int>((int)(pow(2, n)), inf));
	dp[0][0] = 0;
    for (int i = 0; i < m;i++) {
		for (int j = 0; j < pow(2, n);j++) {
			
			if (dp[i][j]!=inf) {

				dp[i + 1][j] = min(dp[i+1][j],dp[i][j]);

				dp[i + 1][j | c[i]] = min(dp[i][j]+a[i],dp[i+1][j|c[i]]);

			}
		}
	}
	/*
	for (int i = 0; i <= m;i++) {
		for (int j = 0; j < pow(2,n);j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	if (dp[m][(int)(pow(2,n))-1]!=inf) {
		cout << dp[m][(int)(pow(2, n) - 1)] << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 16384
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
vector<pair<int,long long> >g[110000];
int sz[110000];
long long ret=0;
long long mm;
bool ng=false;
int N;
int V=mod;
int ca[110000];
void dfs(int a,int b){
    sz[a]=1;
    int t=0;
    int rem=N-1;
    for(int i=0;i<g[a].size();i++){
        if(b==g[a][i].first)continue;
        dfs(g[a][i].first,a);
        sz[a]+=sz[g[a][i].first];
        t=max(t,sz[g[a][i].first]);
        rem-=sz[g[a][i].first];
        ret+=g[a][i].second*min(sz[g[a][i].first],N-sz[g[a][i].first]);
        if(sz[g[a][i].first]==N-sz[g[a][i].first]){
            mm=g[a][i].second;ng=true;
        }
      //  V=max(V,min(sz[g[a][i].first],N-sz[g[a][i].first]));
       // if(ABS(sz[g[a][i].first]==N-sz[g[a][i].first]){
         //   mm=g[a][i].second;ng=true;
       // }
       // if(ABS(sz[g[a][i].first]-(N-sz[g[a][i].first]))<=1){
        //    mm=min(mm,g[a][i].second);
       // }
    }
    t=max(rem,t);
    V=min(V,t);
    ca[a]=t;
}
void dfs2(int a,int b){
    for(int i=0;i<g[a].size();i++){
        if(b==g[a][i].first)continue;
        dfs2(g[a][i].first,a);
        if(V==min(sz[g[a][i].first],N-sz[g[a][i].first])){
            mm=min(mm,g[a][i].second);
        }
       // if(ABS(sz[g[a][i].first]==N-sz[g[a][i].first]){
         //   mm=g[a][i].second;ng=true;
       // }
       // if(ABS(sz[g[a][i].first]-(N-sz[g[a][i].first]))<=1){
        //    mm=min(mm,g[a][i].second);
       // }
    }
}
int main(){
    int a;scanf("%d",&a);
    N=a;
    mm=mod;
    for(int i=0;i<a-1;i++){
        int p,q;long long r;scanf("%d%d%lld",&p,&q,&r);
        p--;q--;g[p].push_back(make_pair(q,r));g[q].push_back(make_pair(p,r));
    }
    if(a==2){
        printf("%lld\n",g[0][0].second);return 0;
    }
    int par=0;
    for(int i=0;i<a;i++){
        if(g[i].size()>1)par=i;
    }
    dfs(par,-1);
   // dfs2(par,-1);
    for(int i=0;i<a;i++){
        if(ca[i]==V){
            for(int j=0;j<g[i].size();j++){
           if(!ng)     mm=min(mm,g[i][j].second);
            }
        }
    }
    ret*=2;
    ret-=mm;
    printf("%lld\n",ret);
}

Measured memory_bytes: 16000
#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <assert.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<int,ull> piu;
typedef pair<ull,ull> puu;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<ll,pll> plP;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<29)
#define INFL (1LL<<61)
#define fi first
#define se second
#define EPS 1e-9
#define MOD 1000000007
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(__,x.size())printf("%d%c",x[__],__+1==x.size()?'\n':' ')

int N;
int p[100000];

int main()
{
	scanf("%d",&N);
	rep(i,N)scanf("%d",&p[i]),p[i]--;
	int c=0;
	rep(i,N)
	{
		if(p[i]==i)swap(p[i],p[i+1]),c++;
	}
	printf("%d\n",c);
}

Measured memory_bytes: 640
mod = 10**9+7
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
Sum = [[1]*(M+1) for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = Sum[i-1][j-1]%mod
        else:
            dp[i][j] = 0
        Sum[i][j] = (Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1]+dp[i][j])%mod
print(Sum[N][M]%mod)        
        

Measured memory_bytes: 104540
#include <stdio.h>
 
int main() {
  int n,a[101],i,j;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  int cnt=0;
  for(i=0; i<n; i++) {
    for(j=n-1; j>i; j--) {
      if(a[j]<a[j-1]) {
    int tmp=a[j];
    a[j]=a[j-1];
    a[j-1]=tmp;
    cnt++;
      }
    }
  }
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}



int main() {
  int K,A,B;
  cin >> K >> A >> B;
  bool ans=false;
  for(int i=K;i<=1000;i+=K){
    if(A<=i&&B>=i){
      ans=true;
    }
  }
  if(ans){
    cout << "OK";
  }
  else{
    cout << "NG";
  }
}

Measured memory_bytes: 3624
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,m,dui;
const int p=998244353;
long long f[11000],inv[11000],bi[11000],ans[11000];
inline long long qpow(int a,int n){
	long long x=a,ans=1;
	while (n){
		if (n&1) ans=ans*x%p;
		x=x*x%p;
		n>>=1;
	}
	return ans;
}
inline long long C(int n,int m){
	if (m<0||m>n) return 0;
	return f[n]*inv[m]%p*inv[n-m]%p;
}
inline int wor(int n,int dui,int num){
	int w=1;long long ans=0;
	fo(i,0,dui){//not use dui
		ans+=bi[dui-i]*C(dui,i)%p*C(n+dui-i+num-1,dui-i+num-1)%p*w;//C(n+dui+num-1,dui+num-1)
		w=-w;
	}
	return (ans%p+p)%p;
}
int main(){
	scanf("%d%d",&m,&n);
	bi[0]=1;
	fo(i,1,m){
		bi[i]=bi[i-1]<<1;
		if (bi[i]>=p) bi[i]-=p;
	}
	f[0]=inv[0]=1;
	fo(i,1,n+m) f[i]=f[i-1]*i%p; 
	inv[n+m]=qpow(f[n+m],p-2);
	fd(i,n+m-1,1) inv[i]=inv[i+1]*(i+1)%p;
	//fo(i,n+m-10,n+m) printf("%d\n",f[i]*inv[i]%p);
	fo(i,2,m+1){
		if (i&1){
			dui++;
			ans[i]=wor(n,dui,m-dui*2);	
		}else{
			ans[i]=wor(n,dui,m-dui*2-1)+wor(n-1,dui,m-dui*2-1);
			if (ans[i]>=p) ans[i]-=p;
		}
		printf("%lld\n",ans[i]);
	} 
	fd(i,m,2) printf("%lld\n",ans[i]);
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<int> s;
    vector<int> ord(n+1, -1);
    int c = 1, l = 0;
    {
        int v = 1;
        while ( ord[v] == -1 ) {
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }

    if ( k < l ) cout << s[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}


Measured memory_bytes: 6668
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
using namespace std;
int Dp[3030][3030];
string s, t;
int n, m;
vector<char> Answer, BT;

int Solve(int i, int j)
{
    if (j == m || i == n) return 0;

    int &ret = Dp[i][j];
    if (ret != -1) return ret;

    int C1 = 0, C2 = 0, C3 = 0;
    if (s[i] == t[j]) C1 = Solve(i+1, j+1) + 1;
    C2 = Solve(i+1, j);
    C3 = Solve(i, j+1);

    return ret = max({C1, C2, C3});
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    memset(Dp, -1, sizeof Dp);

    cin >> s >> t;
    n = s.size();
    m = t.size();

    Solve(0, 0);

    for(int i=0, j=0; i<n && j<m;)
        if (Dp[i][j] == Dp[i][j+1]) j++;
        else if (Dp[i][j] == Dp[i+1][j]) i++;
        else{
            if (s[i] == t[j]) cout << s[i];
            i++; j++;
        }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 36608
#include <algorithm>
#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    char chars[9];
    for (int i = 0; i < 9; ++i)
    {
        cin >> chars[i];
    }
    cout << chars[0] << chars[4] << chars[8] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args)throws java.lang.NumberFormatException{
    Scanner scan=new Scanner(System.in);
    int[][] cards=new int[4][13];
    int n=Integer.parseInt(scan.next());
    for(int i=0;i<n;i++){
      char design=scan.next().charAt(0);
      int rank=Integer.parseInt(scan.next());
      if(design=='S'){
        cards[0][rank-1]=1;
      }else if(design=='H'){
        cards[1][rank-1]=1;
      }else if(design=='C'){
        cards[2][rank-1]=1;
      }else if(design=='D'){
        cards[3][rank-1]=1;
      }
    }

    for(int i=0;i<cards.length;i++){
      for(int j=0;j<cards[i].length;j++){
        if(cards[i][j]==0){
          if(i==0){
            System.out.println("S "+(j+1));
          }else if(i==1){
            System.out.println("H "+(j+1));
          }else if(i==2){
            System.out.println("C "+(j+1));
          }else if(i==3){
            System.out.println("D "+(j+1));
          }
        }
      }
    }
  }
}


Measured memory_bytes: 26028
// -*- coding:utf-8-unix -*-


use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
use itertools::Itertools;

fn main() {
/*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n: usize,
        m: usize,
        hs: [usize; n],
        ab: [(usize,usize); m]
    }
    let mut resv:Vec<Vec<usize>> = vec![vec![0]; n];
    for &(a,b) in ab.iter(){
        resv[a - 1].push(hs[b - 1]);
        resv[b - 1].push(hs[a - 1]);
    }
    let mut result = 0;
    for (i,v) in resv.iter().enumerate(){
        if hs[i] > *v.iter().max().unwrap(){
            result += 1;
        }
    }
    println!("{}",result);
}


Measured memory_bytes: 14072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main(){
	int n,curh,nexh,ans=0,nans=0;
	cin>>n;
	cin>>curh;
	for(int i=1;i<n;i++){
		cin>>nexh;
		if(curh>=nexh){
			nans++;
			ans=max(ans,nans);
		}else{
			nans=0;
		}
		curh=nexh;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,i;
    cin >> n;
    vector<int>a(n);
    for(i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[n/2]-a[n/2-1] << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  long long n;
  cin >> n;
  float half = sqrt((float)n);
  int ans = 0;
  for(int i = 0; i <= half; i++)  {
    if(i*i <= n) {
      ans = max(ans,i);
    }
  }
  cout << ans*ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <queue>
#include <stack>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define umap unordered_map
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

ll W, W2;
const int maxn = 101;
const int maxw = 400;
const int maxv = 1e7 + 100;
ll w[maxn];
int v[maxn];
int n;
int dp[maxn][maxw][maxn];

int dfs(int i, int j, int k) {
  //インデックスi番目以降の品物から
  //重さj以内で
  //残りk個選べる
  //場合の価値の最大値 == ret
  //printf("i,j,k = %3d %3d %3d\n", i, j, k);
  if (dp[i][j][k] != -1) {
    return dp[i][j][k];
  }
  int ret = 0;
  if (k == 0) {
    ret = 0;
  } else if (i == n) {
    ret = 0;
  } else if (j < w[i]) {  //少なくとも1個選べるが、i番目の品物は入らない
    ret = dfs(i + 1, j, k);
  } else {  //i番目の品物が入れられる
    ret = max(dfs(i + 1, j - w[i], k - 1) + v[i], dfs(i + 1, j, k));
  }
  dp[i][j][k] = ret;
  return dp[i][j][k];
}

void solve() {
  cin >> n >> W;
  cin >> w[0] >> v[0];
  ll wm = 0;
  for (int i = 1; i < n; ++i) {
    cin >> w[i] >> v[i];
    wm = max(w[i], wm);
    w[i] -= w[0];
  }
  ll w0 = w[0];
  w[0] = 0;
  //使う個数がt個のとき, 重さ制限はW - t*w0
  //重さW'以内になるようにt個までの品物を選択して得られる最大の価値を求めよ
  //個数制限つきナップサック問題をn回解く（min(n,W/w0)回で済む?）
  //O(N*NW')
  //W'は3*n以内
  //O(N*N*3*N) = O(N^3)
  ll ans = 0, ret;
  for (ll t = 1; t <= min((ll) n, W / w0); ++t) {
    W2 = min(W - t * w0, (wm - w0) * t);
    if (W2 < 0)
      continue;
    for (int i = 0; i < maxn; ++i) {
      for (int j = 0; j < maxw; ++j) {
        for (int k = 0; k < maxn; ++k) {
          dp[i][j][k] = -1;
        }
      }
    }
    //debug(W2);
    ret = dfs(0, W2, t);
    ans = max(ans, ret);
    //cout << "t=" << t << ":" << ret << endl;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 16128
import java.math.BigDecimal;
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);

		int l = scan.nextInt();
		BigDecimal bigL = new BigDecimal(l * l * l);
		BigDecimal big27 = new BigDecimal(27.000000);

		BigDecimal result = bigL.divide(big27, 6, BigDecimal.ROUND_HALF_UP);

		System.out.println(result);
	}

}


Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int a, b;
	while (cin >> a >> b) {
		bool b1 = 0;
		a *= 10;
		vector<int>v;
		while (1) {
			if (a == 0)goto heaven;
			for (int i : v)if (i == a)goto hell;
			v.push_back(a);
			cout << a / b;
			a = a % b * 10;
		}
	hell:cout << endl;
		for0(i, v.size()) {
			if (!b1 && v[i] != a)cout << ' ';
			if (b1 || v[i] == a) {
				cout << '^';
				b1 = 1;
			}
		}
	heaven:cout << endl;
	}
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int A,B,Q;
    cin >> A >> B >> Q;
    vl s, t;
    s.emplace_back(-LINF);
    rep(i,A){
        ll d;cin >> d;
        s.emplace_back(d);
    }
    s.emplace_back(LINF);
    t.emplace_back(-LINF);
    rep(i,B){
        ll d;cin >> d;
        t.emplace_back(d);
    }
    t.emplace_back(LINF);
    rep(i,Q){
        ll x;cin >> x;
        auto s2 = lower_bound(s.begin(),s.end(),x);
        auto s1 = s2;
        --s1;
        auto t2 = lower_bound(t.begin(),t.end(),x);
        auto t1 = t2;
        --t1;

        ll ans = LINF;
        chmin(ans, abs(x - *s1) + abs(*s1 - *t1));
        chmin(ans, abs(x - *t1) + abs(*t1 - *s1));
        chmin(ans, abs(x - *s1) + abs(*s1 - *t2));
        chmin(ans, abs(x - *t2) + abs(*t2 - *s1));
        chmin(ans, abs(x - *s2) + abs(*s2 - *t1));
        chmin(ans, abs(x - *t1) + abs(*t1 - *s2));
        chmin(ans, abs(x - *s2) + abs(*s2 - *t2));
        chmin(ans, abs(x - *t2) + abs(*t2 - *s2));
        cout << ans << endl;
    }
}

Measured memory_bytes: 3060
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        char[] c = new char[N];
        for (int i = 0; i < N; ++i) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            c[i] = sc.next().charAt(0);
        }

        System.out.println(solve(x, y, c, K));

        sc.close();
    }

    static int solve(int[] x, int[] y, char[] c, int K) {
        int[][] blackNums = new int[2 * K][2 * K];
        for (int i = 0; i < x.length; ++i) {
            if (c[i] == 'W') {
                y[i] += K;
            }

            ++blackNums[x[i] % (2 * K)][y[i] % (2 * K)];
        }

        int[][] prefixSums = new int[2 * K + 1][2 * K + 1];
        for (int i = 1; i <= 2 * K; ++i) {
            for (int j = 1; j <= 2 * K; ++j) {
                prefixSums[i][j] = prefixSums[i - 1][j] + prefixSums[i][j - 1] - prefixSums[i - 1][j - 1]
                        + blackNums[i - 1][j - 1];
            }
        }

        int result = 0;
        for (int minX = 0; minX <= K; ++minX) {
            for (int minY = 0; minY <= K; ++minY) {
                result = Math.max(result,
                        Math.max(
                                computeRectangleSum(prefixSums, minX, minY, minX + K - 1, minY + K - 1)
                                        + computeRectangleSum(prefixSums, 0, 0, minX - 1, minY - 1)
                                        + computeRectangleSum(prefixSums, minX + K, 0, 2 * K - 1, minY - 1)
                                        + computeRectangleSum(prefixSums, 0, minY + K, minX - 1, 2 * K - 1)
                                        + computeRectangleSum(prefixSums, minX + K, minY + K, 2 * K - 1, 2 * K - 1),
                                computeRectangleSum(prefixSums, 0, minY, minX - 1, minY + K - 1)
                                        + computeRectangleSum(prefixSums, minX + K, minY, 2 * K - 1, minY + K - 1)
                                        + computeRectangleSum(prefixSums, minX, 0, minX + K - 1, minY - 1)
                                        + computeRectangleSum(prefixSums, minX, minY + K, minX + K - 1, 2 * K - 1)));
            }
        }

        return result;
    }

    static int computeRectangleSum(int[][] prefixSums, int lowerX, int lowerY, int upperX, int upperY) {
        if (lowerX > upperX || lowerY > upperY) {
            return 0;
        }

        return prefixSums[upperX + 1][upperY + 1] - prefixSums[lowerX][upperY + 1] - prefixSums[upperX + 1][lowerY]
                + prefixSums[lowerX][lowerY];
    }
}

Measured memory_bytes: 104432
#include<stdio.h>
int main()
{
	char s[200010], t[200010];
	char f[30], g[30];
	for (int i = 0; i < 30; i++)
	{
		f[i] = '0';
		g[i] = '0';
    }
	scanf("%s\n%s", &s, &t);
	for (int i = 0; s[i] != '\0'; i++)
	{
		if (f[(int)(s[i] - 'a')] == '0')
		{
			f[(int)(s[i] - 'a')] = t[i];
		}
		else if (f[(int)(s[i] - 'a')] != t[i])
		{
			printf("No\n");
			return 0;
		}
	}
	for (int i = 0; t[i] != '\0'; i++)
	{
		if (g[(int)(t[i] - 'a')] == '0')
		{
			g[(int)(t[i] - 'a')] = s[i];
		}
		else if (g[(int)(t[i] - 'a')] != s[i])
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
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; }
typedef long long ll;

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

    int res = 1;
    rep(i, s.size()) {
        if (i + 1 > k) break;
        if (s[i] == '1') continue;
        else {
            res = s[i] - '0';
            break;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double v;
	double t;
	double y;
	int floor;
	
	while (scanf("%lf", &v) != EOF){
		
		t = v / 9.8;
		y = 4.9 * t * t;
		
		floor = 0;
		
		while (y > 0){
			floor++;
			y -= 5;
		}
		
		printf("%d\n", floor + 1);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int dp[1005][1<<15];
int main(){
  int n,m; cin >> n >> m;
  fill(dp[0],dp[1005],INF);
  vector<int> a(m),key(m);
  dp[0][0] = 0;
  
  rep(i,m){
    int b;
    cin >> a[i] >> b;
    int tmp = 0;
    rep(j,b){
      int c; cin >> c;
      c--;
      int tmp2 = 1 << c;
      tmp |= tmp2;
    }
    key[i] = tmp;
  }

  rep(i,m){
    rep(j,1<<n){
      if(dp[i][j] != INF){
        chmin(dp[i+1][j], dp[i][j]);
        chmin(dp[i+1][j|key[i]],dp[i][j]+a[i]);
      }
    }
  }
  
  int ans = dp[m][(1<<n)-1];
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 128896
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n, m, c;
  cin >> n >> m >> c;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> b(m);
  REP(i, m) cin >> b[i];
  REP(i, n) REP(j, m) cin >> a[i][j];
  int ans = 0;
  REP(i, n){
    int t = 0;
    REP(j, m) t += a[i][j] * b[j];
    t += c;
    if(t > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#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 <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;

int		main(void)
{
	int		N;
	cin >> N;
	string a;
	string b;
	cin >> a >> b;
	for (int i = 0; i < a.size(); i++)
	{
		cout << a.at(i);
		cout << b.at(i);
	}
	cout << endl;
}


Measured memory_bytes: 256
/**
 *   author: Shubham Srivastava
 *   created: 26 January 2020  12:21:41
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 0x7fffffff
#define sorti(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.rbegin(),v.rend())
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
ll parent[2000005];

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b;cin>>a>>b;
    cout<<(ll)ceil(a/(double)b);
return 0;
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

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

struct edge {
  int to;
  ll cost;
  edge(int t, ll c) : to(t), cost(c) {}
};

int n, m;
vector<edge> g[1000];
ll d[1000];

bool bellman_ford() {
  REP(i, n) d[i] = LINF;
  d[0] = 0;
  REP(i, n) {
    REP(v, n) {
      REP(k, g[v].size()) {
        edge e = g[v][k];
        if (d[v] != LINF && d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          if (i == n - 1 && e.to == n - 1) return true;
        }
      }
    }
  }
  return false;
}

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

  cin >> n >> m;
  REP(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back(edge(b, -c));
  }
  if (bellman_ford())
    cout << "inf" << endl;
  else
    cout << -d[n - 1] << endl;

  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{

    LL k;
    cin>>k;

    LL g=k;
    string s="";
    for(LL i=0; i<26; i++)
        s+=char(i+'a');
    string st="";
//   g--;
    while(g>0)
    {
        LL d=g%26;
//        cout<<d<<"\n";
        if(d==0)
            d=26;
        st+=s[d-1];
        g=(g-d+1)/26;
//        g--;
    }
    reverse(all(st));
    cout<<st;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n, l;
vector<ll> adj[100001];
ll timer;
ll dep[100001]={0};
vector<int> tin, tout;
vector<vector<ll>> up;
void dfs(ll v,ll p)
{
    tin[v]=++timer;
    up[v][0]=p;
    for (int i = 1; i <= l; ++i)
        up[v][i]=up[up[v][i-1]][i-1];
    for (int u : adj[v]) {
        if (u != p)
            { dep[u]=dep[v]+1;
            dfs(u, v);}
    }
    tout[v] = ++timer;
}
bool is_ancestor(ll u,ll v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}
ll lca(ll u,ll v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}
void preprocess(ll root) {
    tin.resize(n+1);
    tout.resize(n+1);
    timer = 0;
    l = ceil(log2(n+1));
    up.assign(n+1, vector<ll>(l + 2));
    dfs(root, root);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll u,v;
    cin>>n>>u>>v;
    ll a,b;
    for(int x=0;x<n-1;x++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    preprocess(1);
    ll ans=0;
    ll r=lca(u,v);
                ll k=dep[u]+dep[v]-2*dep[r];
                ans=max(ans,k/2);
    for(int x=1;x<=n;x++)
    {
        if(adj[x].size()==1)
        {
            ll d=lca(x,u);
            ll f=lca(x,v);
            ll s=dep[u]+dep[x]-2*dep[d];
            ll e=dep[x]+dep[v]-2*dep[f];
            if(s<e)
            {  //cout<<s<<" "<<e<<endl;
                ans=max(ans,e-1);
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 29440
#include<cstdio>
#include<vector>
#include<algorithm>
using std::max;

const int maxn = 2E+5 + 5;

class SegmentTree {
private:
	struct Node {
		int lef, rig;
		int val, tag;
	} t[maxn * 4];
	
	void PushDown(int now) {
		if(t[now].tag >= 0) {
			t[now << 1].val = t[now].tag;
			t[now << 1].tag = t[now].tag;
			t[now << 1 | 1].val = t[now].tag;
			t[now << 1 | 1].tag = t[now].tag;
			t[now].tag = -1;
		}
	}
public:
	void Build(int now, int nlef, int nrig) {
		t[now].lef = nlef, t[now].rig = nrig;
		t[now].val = 0, t[now].tag = -1;
		if(nlef == nrig) return;
		
		int mid = (nlef + nrig) >> 1;
		Build(now << 1, nlef, mid);
		Build(now << 1 | 1, mid + 1, nrig);
	}
	
	void Update(int now, int nlef, int nrig, int nval) {
		if(nlef <= t[now].lef && nrig >= t[now].rig) {
			t[now].val = t[now].tag = nval;
			return;
		}
		
		PushDown(now);
		
		if(t[now << 1].rig >= nlef) Update(now << 1, nlef, nrig, nval);
		if(t[now << 1 | 1].lef <= nrig) Update(now << 1 | 1, nlef, nrig, nval);
		t[now].val = max(t[now << 1].val, t[now << 1 | 1].val);
	}
	
	int Query(int now, int nlef, int nrig) {
		if(nlef <= t[now].lef && nrig >= t[now].rig)
			return t[now].val;
		
		PushDown(now);
		
		int res = 0;
		if(t[now << 1].rig >= nlef) res = max(res, Query(now << 1, nlef, nrig));
		if(t[now << 1 | 1].lef <= nrig) res = max(res, Query(now << 1 | 1, nlef, nrig));
		
		return res;
	}
} segtree;

int n;
int a[maxn], pos[maxn], f[maxn];
std::vector<int> to[maxn];

void DFS(int u, int fa) {
	f[u] = segtree.Query(1, 1, a[u] - 1) + 1;
	
	int tmp = segtree.Query(1, a[u], a[u]);
	segtree.Update(1, a[u], a[u], f[u]);
	for(int i = 0; i < to[u].size(); ++i) {
		int v = to[u][i];
		
		if(v != fa) DFS(v, u);
	}
	segtree.Update(1, a[u], a[u], tmp);
}

void DFS2(int u, int fa) {
	f[u] = max(f[u], f[fa]);
	for(int i = 0; i < to[u].size(); ++i) {
		int v = to[u][i];
		
		if(v != fa) DFS2(v, u);
	}
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]), pos[i] = a[i];
	for(int i = 1; i < n; ++i) {
		int x, y;
		
		scanf("%d%d", &x, &y);
		to[x].push_back(y), to[y].push_back(x);
	}
	
	std::sort(pos + 1, pos + n + 1);
	int cnt = std::unique(pos + 1, pos + n + 1) - pos - 1;
	
	for(int i = 1; i <= n; ++i)
		a[i] = std::lower_bound(pos + 1, pos + cnt + 1, a[i]) - pos + 1;
	
	segtree.Build(1, 1, cnt + 1);
	
	DFS(1, 0), DFS2(1, 0);
	for(int i = 1; i <= n; ++i)
		printf("%d\n", f[i]);
}

Measured memory_bytes: 34288
#include <iostream>
    using namespace std;
    int main(void){
        unsigned long long w,i,j,k,n,m,l;
        cin>>n>>w;
        unsigned long long stuff[n][2];//stuff[i][0]が重さでstuff[i][1]が価値
        for(i=0;i<n;i++){
            cin>>stuff[i][0]>>stuff[i][1];
        }
        unsigned long long chart[n+1][w+1];
        for(i=0;i<n+1;i++){
            for(j=0;j<w+1;j++){
                if(i==0||j==0){
                    chart[i][j]=0;
                    continue;
                }
                if(j<stuff[i-1][0]){
                chart[i][j]=chart[i-1][j];
                continue;
                }
                k = chart[i-1][j-stuff[i-1][0]]+stuff[i-1][1];
                l = chart[i-1][j];
                if(m<=k&&l<=k)
                chart[i][j]=k;
                else if(m<=l)
                chart[i][j]=l;
                else 
                chart[i][j]=m;
            }
        }
        cout<<chart[n][w]<<endl;
        return 0;
    }
     

Measured memory_bytes: 79104
function Main(input){
  	input =input.split(" ");
  	var a=parseInt(input[0],10);
  	var b=parseInt(input[1],10);
  	var c=a*b;
  	if (c%2===0){
      console.log("Even");
  	}else{
      console.log("Odd");
  	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,maxn=100010;
const double eps=1e-8,pi=acos(-1.0);
const int inf=0x7f7f7f7f7f7f7f7f;
using namespace std;
int a[maxn],b[maxn],v[maxn];
string s; 
signed main()
{
	ios::sync_with_stdio(0);
	int t=1;
	//cin >> t; 
	while(t--)
	{
		char x;
		cin >> x;
		if(x>='A'&&x<='Z')
			cout <<"A";
		else
			cout <<"a";
	} 
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
signed main(){
  ll a,b;
  cin>>a>>b;
  if(b>=a){
    cout<<"unsafe\n";
  }else{
    cout<<"safe\n";
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	vll h(n);
	rep(i,n) cin >> h[i];
	vvll to(n);
	rep(i,m){
		ll a,b;
		cin >> a >> b;
		a--;
		b--;
		to[a].pb(b);
		to[b].pb(a);
	}
	ll ans=0;
	rep(i,n){
		bool frag=true;
		for(auto&& e:to[i]){
			if(h[i]<=h[e]) frag=false;
		}
		if(frag) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9860
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	set<int> st;
	int t;
	int ans=0;
	For(i,0,n-1){
		cin>>t;
		if(st.count(t)) ans++;
		else st.insert(t);
	}
	cout<<n-ans-ans%2<<"\n";
	return 0;
}





























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

#define ll            long long
#define pb            push_back
#define si            set <int>
#define F             first
#define S             second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define fr(i,a,b)     for(int  i=a;i<=b;i++)
#define loop(i,n)     for(int i=0;i<n;i++)
#define all(v)        v.begin(),v.end()
#define vi            vector<int >
#define vpi           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
//#define M             1000000007
#define mp            make_pair
#define input(arr,n)  loop(i,n) cin>>arr[i]
#define output(arr,n) loop(i,n) cout<<arr[i]<<" "
#define mod           998244353
#define sof           sizeof
#define MAX_S         1000000000

using namespace std;

ll gcd(ll a,ll b){

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



void solve(int t){ 
  ll x,k,d;
  cin>>x>>k>>d;
  x=abs(x);
  ll p=x/d;
  if(p>=k){
    cout<<x-k*d;
  }
  else{
    k-=p;
    x-=p*d;
    if(k%2==0){
      cout<<x;
    }
    else cout<<min(abs(x-d),abs(x+d));
  }
}


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

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
	#endif
	

	int t;
    	t=1;
    	//cin>>t;
    	loop(i,t){

     	 solve(i);
       if(i<t-1) cout<<"\n";
   	 }
	
    return 0;

}
	


	





Measured memory_bytes: 3652