akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define mod 998244353
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
//#include<bits/stdc++.h>
bool sortbydesc(int a,int b){
	return a>b;
}
bool sortbydesc1(pair<int,int> a,pair<int,int> b){
	return a.first>b.first;
}
struct triple{
	int n1;

	int n2;
	int n3; 
};
struct edge{
	int s;
	int e;
	int w;

};

class Graph 
{ 
	int V; 
	list<int> *adj; 
public: 
	Graph(int V); 
	void addEdge(int v, int w);
	void DFSUtil(int v, bool *visited,std::vector<int> &v1); 
}; 

Graph::Graph(int V) 
{ 
	this->V = V; 
	adj = new list<int>[V]; 
} 

void Graph::addEdge(int v, int w) 
{ 
	adj[v].push_back(w);}

void Graph::DFSUtil(int v, bool *visited,vector<int>&v1) 
{ 
	
	visited[v] = true;
	v1.push_back(v); 
	// cout << v << " "; 

	
	list<int>::iterator i; 
	for(i = adj[v].begin(); i != adj[v].end(); ++i) 
		if(!visited[*i]) 
			DFSUtil(*i, visited,v1); 
} 
// ll dp(ll n,ll k,ll *h,ll *a){
// 	if(n>=k){
// 		return 0;
// 	}
// 	else if(n==k-1){
// 		return a[k-1];
// 	}
// 	else if(n==k-2||n==k-3){
// 		return a[k-2];
// 	}
// 	else if(h[n]==-1){
// 		//return max(a[n]+)

// 	}
// }

int maxlen(int **dp,int n,std::vector<vector<int>> &v,int k){
	if(v[k].size()==0){
		dp[k][0]=0;
		dp[k][1]=0;
		return dp[k][0];
	}
	else{
		int max1=-1;
		for(int i=0;i<v[k].size();i++){
			if(dp[v[k][i]][1]==0){
				max1=max(max1,maxlen(dp,n,v,v[k][i]));

			}
			else{
				max1=max(max1,dp[v[k][i]][0]);

			}
			
		}
		//cout<<k<<" "<<max1+1<<endl;
		dp[k][0]=1+max1;
		dp[k][1]=1;
		return dp[k][0];
	}
}





int32_t main(){
	int n;
	cin>>n;
	int m;
	cin>>m;
	vector <vector<int>> a(n+1);
	for(int i=0;i<m;i++){
		int p,q;
		cin>>p>>q;
		a[p].push_back(q);
	}
	//cout<<"hello"<<endl;

	// for(int i=1;i<n+1;i++){
	// 	for(int j=0;j<a[i].size();j++){
	// 		cout<<a[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	//cout<<"hello"<<endl;
	int **dp=new int *[n+1];
	for(int i=0;i<n+1;i++){
		dp[i]=new int[2];
	}
	for(int i=0;i<n+1;i++){
		dp[i][0]=0;
		dp[i][1]=0;
	}

	for(int i=1;i<n+1;i++){
		if(dp[i][1]==0){
			dp[i][0]=maxlen(dp,n,a,i);
			dp[i][1]=1;

		}
	}
	int max1=-1;
	for(int i=1;i<n+1;i++){
		max1=max(max1,dp[i][0]);
	}
	// for(int i=1;i<n+1;i++){
	// 	cout<<dp[i][0]<<" ";
	// }
	// cout<<endl;
	 cout<<max1<<endl;



	
	return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h> 
  
using namespace std; 
  
void Solve(){
    long long n;
    string s;
    cin>>n>>s;
    string pre = "", suf = "";
    int i = 0;
    while(i < s.size()){
        while(i < s.size() && s[i] != '.'){
            pre += s[i];
            i++;
        }
        i++;
        while(i < s.size()){
            suf += s[i];
            i++;
        }
    }
    int pree = stoi(pre);
    int suff = stoi(suf);
    long long res = n * pree;
    res += n * suff / 100;
    cout<<res<<'\n';
} 
int main() 
{ 
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    Solve();
}

  

Measured memory_bytes: 3652
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


//最大公約数
int gcd(ll x,ll y){

	x = abs(x);
	y = abs(y);

	if(x < y){
		swap(x,y);
	}
	if(y == 0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}

int main(){

	int K;
	scanf("%d",&K);

	int ans = 0;

	for(int a = 1; a <= K; a++){
		for(int b = 1; b <= K; b++){
			for(int c = 1; c <= K; c++){

				ans += gcd(a,gcd(b,c));
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 3768
#include<stdio.h>
#include<algorithm>
const int maxm=10001;
int u[maxm];
void makeset()
{
    for(int i=1;i<maxm;i++)
        u[i]=i;
}
int Find(int x)
{
    if(x!=u[x])
    {
        u[x]=Find(u[x]);
    }
    return u[x];

}
int Union(int a1,int a2)
{
    int r1=Find(a1);
    int r2=Find(a2);
    if(r1!=r2)
    {u[r2]=r1;
    return 1;
    }
    return 0;
}
using namespace std;
int main()
{
    long long int m,i,j,k,n,a,b;

    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        if(n<=0&&m>=0)
        {
           printf("Zero\n") ;
        }

            if(m<0&&(m-n-1)%2==0)
        {
            printf("Positive\n");
        }
        if(m<0&&(m-n)%2==0)
            printf("Negative\n");
        if(n>0) printf("Positive\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,B,N;
ll ans=(1LL<<60);
int main(){
  cin>>A>>B>>N;
  for(ll i=1;i<=N;i++)
    for(ll j=1;j<=N;j++)
      if(B*j%i==0)// na*i == B*j
        ans=min(ans, abs(A-B*j/i));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3096
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
getIntList = map readInt . BS.words <$> BS.getLine
getIntMatrix = map (map readInt . BS.words) . BS.lines <$> BS.getContents

main = do
  [age,regularPrice] <- getIntList
  print $ price age regularPrice

price age regularPrice
  | age >= 13 = regularPrice
  | age <= 5 = 0
  | otherwise = regularPrice `div` 2

Measured memory_bytes: 380
import numpy as np
mod=10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))
 
ans=0
 
for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1
 
print(ans%mod)

Measured memory_bytes: 48820
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  rep2(k,1,b+1){
    if(k*a%b==c) {
      cout<<"YES"<<endl;
    return 0;
  }
  } 
  cout<<"NO"<<endl;
return 0;
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

num a, b;

num gcd(int a, int b) {
    return !b ? a : gcd(b, a % b);
}

num inline lcm(num a, num b) {
    return a * b / gcd(a, b);
}

int main() {
    cin >> a >> b;
    cout << lcm(a, b) << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int arith_sum1(long long int,long long int,long long int);
long long int arith_sum2(long long int,long long int,long long int);
long long int series_sum(long long int);

int main(){
    double a,b,x,V;
    double ans;
    cin>>a>>b>>x;
    V=a*a*b;
    if(x>V/2){
        ans=(180/M_PI)*atan(2*(V-x)/pow(a,3));
    }else{
        ans=(180/M_PI)*atan(a*b*b/(2*x));
    }
    printf("%.8lf\n",ans);
}

Measured memory_bytes: 4216
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)  
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int n;
int a[100];
long long dp[100+1][20+1];

long long solve() {
  memset(dp, 0, sizeof(dp));
  dp[1][a[0]] = 1;
  FOR (i, 1, n-1) REP (j, 21) {
    if (j + a[i] <= 20)
      dp[i+1][j+a[i]] += dp[i][j];
    if (j - a[i] >= 0)
      dp[i+1][j-a[i]] += dp[i][j];
  }
  return dp[n-1][a[n-1]];
}

int main(int argc, char *argv[])
{
  ios::sync_with_stdio(false);
  cin >> n;
  REP (i, n) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

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

int main(){
    int n;cin>>n;
    int A[n];
    rep(i,n)scanf("%d",&A[i]);
    sort(A,A+n);
    int sum=0;
    rep(k,n){
        rep(j,k){
            rep(i,j){
                if(A[i]!=A[j]&&A[i]!=A[k]&&A[j]!=A[k]){
                    if(A[k]<A[i]+A[j])sum++;
                }
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;
using P = pair<int,int>;

int n,k,r;
string s,t;

int main() {
  cin >> n >> r;
  cout << (n>=10 ? r : r+100*(10-n)) << endl;
}

Measured memory_bytes: 256
import math
import collections
def modpow(a,b,MOD):#a**b(MOD)
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
MOD=998244353
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    print(0)
    exit()
else:
    l=l[1:]
if 0 in l:
    print(0)
    exit()
cl=collections.Counter(l)
ans=1
tmp=1
for i in range(1,max(l)+1):
    c=cl[i]
    if c==0:
        print(0)
        exit()
    ans*=modpow(tmp,c,MOD)
    ans%=MOD
    tmp=c
print(ans)

Measured memory_bytes: 19912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;

ll factor(int n){
    ll ret=1;
    for(int i=2;i<=n;i++) ret*=i;
    return ret;
}

int main(){
    int H,N;
    cin>>H>>N;
    vll A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    ll sum=0;
    for(int i=0;i<N;i++) sum+=A[i];
    
    if(sum>=H) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
X, K, D = map(int, input().split())

X = abs(X)

if K < X // D:
    print(X - (K * D))
    exit()
else:
    # 残りが偶数か奇数か
    if (K - X // D) % 2 == 0:
        print(X % D)
        exit()
    else:
        print(min(abs(X % D - D), abs(X % D + D)))
        exit()


Measured memory_bytes: 9112
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll>ma;
int main(int argc, char *argv[])
{
	ll n,i,j,k,l,m,p;
	p=-100000000000000000;
	ll a[3][3];
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		ma[m]=p;
	}
	
	k=1;
	
    for(i=0;i<3;i++){
    	ll po=0;
    	for(j=0;j<3;j++){
    		if(ma[a[i][j]]==p){
    			po++;
    		}
    	}
    	if(po==3&&k==1){
    		k=0;
    		cout<<"Yes\n";
    		break;
    	}
    }
    
    for(i=0;i<3;i++){
    	ll po=0;
    	for(j=0;j<3;j++){
    		if(ma[a[j][i]]==p){
    			po++;
    		}
    	}
    	if(po==3&&k==1){
    		k=0;
    		cout<<"Yes\n";
    		break;
    	}
    }
    
    ll po=0;
    for(i=0;i<3;i++){
    
    	
    		if(ma[a[i][i]]==p){
    			po++;
    		}
    }
    	if(po==3&&k==1){
    		k=0;
    		cout<<"Yes\n";
    		
    	}
    
    
    if(ma[a[2][0]]==p&&ma[a[1][1]]==p&&ma[a[0][2]]==p&&k==1){
    	k=0;
    	cout<<"Yes\n";
    }
    
    if(k==1)cout<<"No\n";
    
    		
		
	
	
}

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

using namespace std;
 
 
int data[10];
 
bool searchB (int a){
    vector<int >sea;
 
    for(int i=0;i<10;i++){
        if(a>>i & 1)sea.push_back(data[i]);
    }
    if(sea.size()>1){
    for(int i=0;i<sea.size()-1;i++){
        if(sea[i]>sea[i+1])return false;
    }
    }
    return true;
}
 
int main(){
 
    int n=0;
    cin>>n;
 
    for(int i=0;i<n;i++){
         
 
    for(int j=0;j<10;j++){
        cin>>data[j];
    }
    bool suc=false;
    for(int i=0;i<1024;i++){
        if(searchB(i) && searchB(~i)){
            cout<<"YES"<<endl;
            suc=true;
            break;
        }
    }
    if(!suc)cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include "algorithm"
#include "iostream"
#include "set"
#include "vector"

using namespace std;

int main() {
	int n;
	cin >> n;
	vector< pair< int, pair<string, int>>> v;
	for (int i = 0; i < n; ++i) {
		string s;
		int t;
		cin >> s >> t;
		v.emplace_back(i + 1, make_pair(s, t));
	}

	sort(v.begin(), v.end(), [](pair< int, pair<string, int>>a, pair< int, pair<string, int>>b){
		if (a.second.first == b.second.first) return a.second.second > b.second.second;
		return a.second.first < b.second.first;
	});

	for (auto x: v) cout << x.first << endl;

}

Measured memory_bytes: 256
N = int(input())
table = []
for i in range(N):
    a, b, c = map(int, input().split())
    table.append((a,b,c))

dpA = [0]*(N+1)
dpB = [0]*(N+1)
dpC = [0]*(N+1)

for i in range(N):
    a, b, c = table[i]
    dpA[i+1] = max(dpB[i], dpC[i]) + a
    dpB[i+1] = max(dpC[i], dpA[i]) + b
    dpC[i+1] = max(dpA[i], dpB[i]) + c

print(max(dpA[N], dpB[N], dpC[N]))


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

bool palindromic(int n){
  int digit[5];
  for(int i=0;i<5;i++){
    digit[i] = n%10;
    n /=10;
  }
  if(digit[4] == digit[0] && digit[3] == digit[1]) return true;
  return false;
}

int main(){
  int a,b,ans=0;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(palindromic(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

signed main(){
    ll N,W;
    cin >> N >> W;
    //DP[i] := sum(v)=iとなるような最小のW
    ll DP[500000];
    DP[0] = 0;
    FOR(i,1,500000)DP[i] = LINF;
    FOR(i,0,N){
        ll w,v;
        cin >> w >> v;
        REP(j,0,100010){
            if(DP[j] != LINF){
                DP[j+v] = min(DP[j+v],DP[j]+w);
            }
        }
    }
    ll ans = 0;
    FOR(i,0,300000){
        if(DP[i] <= W){
            ans = max(ans,i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define SZ 5000000
#define X 998244353
#define Qinv(x) Qpow(x,X-2)
#define Inc(x,y) ((x+=(y))>=X&&(x-=X))
#define C(x,y) ((x)<(y)?0:1LL*Fac[x]*IFac[y]%X*IFac[(x)-(y)]%X)
#define S(x,y) C((x)+(y)-1,(y)-1)
using namespace std;
int n,m,Fac[SZ+5],IFac[SZ+5];
I int Qpow(RI x,RI y) {RI t=1;W(y) y&1&&(t=1LL*t*x%X),x=1LL*x*x%X,y>>=1;return t;}
int main()
{
	RI i,ans=0;for(scanf("%d%d",&n,&m),Fac[0]=i=1;i<=SZ;++i) Fac[i]=1LL*Fac[i-1]*i%X;
	for(IFac[SZ]=Qinv(Fac[SZ]),i=SZ-1;~i;--i) IFac[i]=1LL*IFac[i+1]*(i+1)%X;
	for(i=m&1;i<=m;i+=2) ans=(1LL*C(n,i)*S(3*m-i>>1,n)+ans)%X;
	for(i=2*m+1;i<=3*m;++i) ans=(X-1LL*n*S(3*m-i,n-1)+ans)%X;
	return printf("%d",ans),0;
}

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

int main(){
  int h,w;
  char c[102][102];
  for(int i=0;i<102;i++)
    for(int j=0;j<102;j++)
      c[i][j]='#';
  cin>>h>>w;
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)
      cin>>c[i][j];

  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      cout<<c[i][j];
    }
    cout<<endl;
  }
}

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

using namespace std;

int main(){
  int N, M;
  vector<int> A;
  int a, b, c;
  long long ans = 0;
  cin >> N >> M;
  vector<pair<int,int>> pairs;
  for(int i=0; i < N; i++){
    cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  for(int i=0; i < M; i++){
    cin >> b >> c;
    pairs.push_back(make_pair(c,b));
  }
  sort(pairs.begin(), pairs.end(), greater<pair<int,int>>());
  int itr = 0;
  for(int i=0; i<N; i++){
    if(A[i] < pairs[itr].first && itr < M){
      A[i] = pairs[itr].first;
      pairs[itr].second--;
      if(pairs[itr].second == 0){
        itr++;
      }
    }
    else break;
  }
  for(int i=0; i<N; i++){
    ans += A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1784
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,h[100005]={},a,b,ans=0,cnt=0;
  cin >> n >> m;
  vector<ll> g[100005];
  for(int i=0; i<n; i++) {
    cin >>h[i];
  }
  for(int i=0; i<m; i++) {
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(int i=0; i<n; i++) {
    cnt=0;
    for(auto p:g[i]) {
      if(h[i]<=h[p]) {
        cnt++;
      }
    }
    if(cnt==0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 10252
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll N, K, Q; cin >> N >> K >> Q;
    ll A[Q]; rep(i,Q) cin >> A[i];
    ll Point[N]; rep(i,N) Point[i] = K;
    ll tmp[N]; rep(i,N) tmp[i] = 0;
    rep(i,Q) tmp[A[i]-1] += 1;
    rep(i,N) tmp[i] = (Q-tmp[i]);
    rep(i,N) Point[i] -= tmp[i];
    rep(i,N){
        if(Point[i] <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}


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

int main() {

	int M1 = 0;
	int M2 = 0;
	int D1 = 0;
	int D2 = 0;

	cin >> M1;
	cin >> D1;

	cin >> M2;
	cin >> D2;

	if (M1 == M2) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int year, month, day;
    scanf("%d/%d/%d", &year, &month, &day);
    if(year < 2019) cout << "Heisei" << endl;
    else{
        if(month <= 4) cout << "Heisei" << endl;
        else{
            cout << "TBD" << endl;
        }
    }
}

Measured memory_bytes: 256
h, n = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
INF = 10**18

dp = [INF] * (h + 1)
dp[h] = 0
for i in range(n):
    a, b = info[i]
    for j in range(h + 1)[::-1]:
            dp[max(j - a, 0)] = min(dp[j] + b, dp[max(j - a, 0)])
print(dp[0])


Measured memory_bytes: 42972
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 1) cout << "1";
	else if (2 <= n && n < 4) cout << "2";
	else if (4 <= n && n < 8) cout << "4";
	else if (8 <= n && n < 16) cout << "8";
	else if (16 <= n && n < 32) cout << "16";
	else if (32 <= n && n < 64) cout << "32";
	else cout << "64";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
read(a);
read(b);
if(a<b){
    f(i,0,b){
        cout<<a;
        
    }
    cout<<endl;
}
else{
    f(i,0,a){
        cout<<b;
        
    }
    cout<<endl;
}
    
    
    


   

}

Measured memory_bytes: 256
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
 
const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
 
 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
 
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;

void solve(){
    int n; cin>>n;
    map <string,int> m;
    for(int i=0;i<n;i++){
        string a; cin>>a;
        m[a]++;
    }
    cout<<"AC"<<" x "<<m["AC"]<<endl;
    cout<<"WA"<<" x "<<m["WA"]<<endl;
    cout<<"TLE"<<" x "<<m["TLE"]<<endl;
    cout<<"RE"<<" x "<<m["RE"]<<endl;
}
int main(){
    fastio();
    //write code
    int t; t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int a,b;
    cin>>a>>b;
    cout<<a*a-b<<endl;
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
    	PrintWriter out = new PrintWriter(outputStream);

        int i, n, m, k;
		
      StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
      	k = Integer.parseInt(st.nextToken());
      	int q = Integer.parseInt(st.nextToken());
      	
        HashMap<Integer,Integer> hp = new HashMap<>();
        
     int max=Integer.MIN_VALUE;
        
      for(int j=1;j<=q;j++)
      {
        int tmp=Integer.parseInt(br.readLine());
        if(!hp.containsKey(tmp))
          	hp.put(tmp,1);
        else
          	hp.put(tmp,hp.get(tmp)+1);
      }
      for(i=1;i<=n;i++)
      {
        if(hp.containsKey(i) && k-(q-hp.get(i))>0)
          out.println("Yes");
        else
        if(k-q>0)
          out.println("Yes");
        else
          out.println("No");
      }
	out.flush();
	out.close();
	}
}

Measured memory_bytes: 39140
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] data = new int[10];
		for (int i = 0; i < 10; i++) {
			data[i] = scan.nextInt();
		}

		int afterData, beforeIndex;
		
		for(int i = 1; i < 10; i++) {
			afterData = data[i];
			beforeIndex = i - 1;
			
			while (beforeIndex >= 0 && data[beforeIndex] > afterData) {
				data[beforeIndex + 1] = data[beforeIndex];
				beforeIndex--;
			}

			data[beforeIndex + 1] = afterData;			
		}
	
		System.out.println(data[9]);
		System.out.println(data[8]);		
		System.out.println(data[7]);

		scan.close();
	}

}

Measured memory_bytes: 26052
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int W[N];
  for (int i=0; i<N; i++) scanf("%d", &W[i]);

  int diff = 0;
  for (int i=0; i<N; i++) {
    diff += W[i];
  }
  int diff_min = 10000;
  for (int i=0; i<N; i++) {
    diff -= W[i] * 2;
    if (abs(diff) < diff_min) {
      diff_min = abs(diff);
    }
  }
  printf("%d\n", diff_min);
}


Measured memory_bytes: 128
A, B = map(int, input().split())

N = A*B

if A >= B:
    a = int(N/A)
    for i in range(a):
        if A*(a-i) % B == 0:
            N = A*(a-i)

else:
    b = int(N/B)
    for i in range(b):
        if B*(b-i) % A == 0:
            N = B*(b-i)

print(N)


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

using namespace std;



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

	int N;
	cin >> N;
	

	long long ans = 0;

	for(int i = 1; i <= N; ++i) {
		if (i % 3 == 0 || i % 5 == 0)
			continue;

		ans += i;
	}

	cout << ans << '\n';

	return 0;	
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
std::vector<int> days[100010];
std::vector<int> cost[3];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i< n; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        days[i].push_back(a);
        days[i].push_back(b);
        days[i].push_back(c);
        if(!i)
        {
            cost[0].push_back(a);
            cost[0].push_back(b);
            cost[0].push_back(c);
        }
        else
        {
           cost[i].push_back(0);
            cost[i].push_back(0);
            cost[i].push_back(0);
        }
    }

    for(int i=0; i<n-1; i++)
    {

        //activity a
        if(cost[i+1][1]<cost[i][0]+days[i+1][1])
            cost[i+1][1]=cost[i][0]+days[i+1][1];

        if(cost[i+1][2]<cost[i][0]+days[i+1][2])
            cost[i+1][2]=cost[i][0]+days[i+1][2];

        //activity b
        if(cost[i+1][0]<cost[i][1]+days[i+1][0])
            cost[i+1][0]=cost[i][1]+days[i+1][0];

        if(cost[i+1][2]<cost[i][1]+days[i+1][2])
            cost[i+1][2]=cost[i][1]+days[i+1][2];

        //activity c
        if(cost[i+1][0]<cost[i][2]+days[i+1][0])
            cost[i+1][0]=cost[i][2]+days[i+1][0];

        if(cost[i+1][1]<cost[i][2]+days[i+1][1])
            cost[i+1][1]=cost[i][2]+days[i+1][1];



    }

    int max=cost[n-1][0];
    if(max<cost[n-1][1])
        max=cost[n-1][1];
    if(max<cost[n-1][2])
        max=cost[n-1][2];
    cout<<max<<endl;

    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	int N,K;
	cin>>N>>K;
	
	string S;
	cin>>S;
	vector<int> num;
	for(int i=0;i<S.size();i++){
		char c = S[i];
		int cnt = 1;
		while(true){
			i++;
			if(i==S.size())break;
			if(S[i]==c)cnt++;
			else{
				i--;
				break;
			}
		}
		num.push_back(cnt);
	}
	/*
	for(int i=0;i<num.size();i++){
		cout<<num[i]<<endl;
	}*/
	
	int X = num.size();
	//cout<<X<<endl;
	X = max(1,X-2*K);
	
	cout<<N-X<<endl;
	
	return 0;
}

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

int main() {
  int A;
  cin >> A;
  int B;
  cin  >> B;
 if (B <= (A-1) ) {
    cout << 2*A-1 << endl;
  }
  
  if (A <= (B-1) ) {
    cout << 2*B-1 << endl;
  }
  if ((A-1) < B  && B < A) {
    cout << A+B << endl;
  }
  if ( (B-1) < A && A < B ){
    cout << A+B << endl;
}
  if (A == B) {
    cout << A+B << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[20],a[30],ans;
ll solve(ll mask){
    ll n=0;
    if(cnt[0]>0)a[n++]=0;
    for(ll i=0;i<12;i++){
        if(cnt[i+1]==0)continue;
        if(cnt[i+1]==2){
            a[n++]=i+1;
            a[n++]=-(i+1);
            continue;
        }

        if( (mask>>i)&1 )a[n++]=i+1;
        else a[n++]=-(i+1);
    }
    sort(a,a+n);
    a[n++]=a[0]+24;
    ll ans=24;
    for(ll i=0;i<n-1;i++)ans=min(ans , a[i+1]-a[i]);
    return ans;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=0,x;i<n;i++)cin>>x,cnt[x]++;
    cnt[0]++;
    if(cnt[0]>1)return cout<<"0" , 0;
    for(ll i=1;i<=12;i++)if(cnt[i]>2)return cout<<"0" , 0;
    for(ll mask=0;mask<(1ll<<12);mask++)ans=max(ans,solve(mask));
    cout<<ans;
}

Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)

list = []
for aa in a:
    for bb in b:
        list.append(aa+bb)
list.sort(reverse = True)
list = list[:k]

list1 = []
for ab in list:
    for cc in c:
        list1.append(ab+cc)
list1.sort(reverse = True)
list1 = list1[:k]

for i in range(k):
    print(list1[i])

Measured memory_bytes: 160632
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long

int main() {
  ul h,w;
  cin>>h>>w;

  if (h==1||w==1) {
    cout <<1<<endl;
    return 0;
  }

  ul rc[2];
  rc[0]=(w+1)/2;
  rc[1]=w/2;
  ul ct=rc[0]*((h+1)/2) + rc[1]*(h/2);

  cout<<ct<<endl;

  return 0;
}


Measured memory_bytes: 256
//17D8101026B 横川　大貴
//Java

import java.util.Scanner;

class Main{
    private static int[] A;
    private static int count=0;
    private static int max = 1100000000;
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	A = new int[n];
	for(int i=0;i<n;i++){
	    A[i] = sc.nextInt();
	}
       
	mergeSort(0,n);

	for(int i=0;i<n; i++){	
	    System.out.print(A[i]);
		if(i<n-1){
		    System.out.print(" ");
		}else{
		    System.out.println();
		}
	}
	System.out.println(count);
	
	
    }
    public static void merge(int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int[] L = new int[n1+1];
	int[] R = new int[n2+1];
	for(int i=0; i<n1; i++){
	    L[i] = A[left+i];
	}
	for(int i=0; i<n2; i++){
	    R[i] = A[mid+i];
	}
	L[n1]=max;
	R[n2]=max;
	int i=0;
	int j=0;
	for(int k=left;k<right;k++){	    
	    if(L[i] <= R[j]){
		A[k] = L[i];
		i++;
		count++;
	    }else{
		A[k] = R[j];
		j++;
		count++;
	    }
	}
    }
    public static void mergeSort(int left,int right){
	if(left+1<right){
	    int mid = (left+right)/2;
	    mergeSort(left, mid);
	    mergeSort(mid, right);
	    merge(left,mid, right);
	}
    }
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const int MAX = 200005;
const ll MOD = 998244353;
const ll INF = (1LL << 62);

ll N, M, K;

long long fac[MAX], finv[MAX], inv[MAX];

ll cache2[200005];

void initComb() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long comb(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void init2() {
  ll v = 1;
  for (ll i = 0; i < 200005; i++) {
    cache2[i] = v;
    v = v * (M - 1);
    v %= MOD;
  }
}

int main() {
  scanf("%lld %lld %lld", &N, &M, &K);

  initComb();
  init2();

  ll ans = 0;

  for (ll k = 0; k <= K; k++) {
    ll c = comb(N - 1, k) * M % MOD;

    ll m = cache2[(N - k - 1)];
    c = c * m;
    c %= MOD;

    // cout << "c:" << c << endl;
    // cout << "m:" << m << endl;

    ans = ans + c;
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 10012
def calc(a, op, b):
    if op == '+':
        return a + b
    if op == '-':
        return a - b
    if op == '*':
        return a * b
    if op == '/':
        return a // b


if __name__ == '__main__':
    while True:
        a, op, b = (i for i in input().split())
        if op == '?':
            break
        else:
            print(calc(int(a), op, int(b)))



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

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

    long long sum = 0;

    for(int i = 1; i <= n; i++)
    {
        if(i%3 != 0 && i%5 != 0)
            sum += (long long) i;
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
  int N , x = 1 , y = 0;
  cin >> N;
  
  vector<int> vec(N);
  for(int i = 0 ; i < N ; i++) {
    cin >> vec.at(i);
  }//配列を受け取る
  
	for(int i = 0 ; i < N ; i++)/*N回ループ*/ {
      
      x = vec.at(x-1); //xにx(=0)項目を代入
      
      if(x == 2) {
        y = i + 1; 
        break;
    }
  
    }
  
  if(x == 2){
    cout << y << endl;
  }
      
  else {
    cout << -1 << endl;
  }

      
      
    
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

long int powint(long int a, long int b){
    long int res = 1;
    for (long int i = 0; i < b; i++){
        res *= a;
    }
    return res;
    
}

int main(){
    long int x;
    cin >> x;
    long int a, b;
    for (long int i = -1000; i < 1000; i++){
        long int dx = x - powint(i, (long int)5);
        for (long int j = -1000; j < 1000; j++){
            if(dx == powint(j, (long int)5)){
                cout << i << " " <<  - j << endl;
                return 0;
            }
        }
        
    }
    
}


Measured memory_bytes: 3624
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
def main():
    # 全部ゼロ
    if c[0] == n:
        ok = True
        return ok
    if n % 3 != 0:
        ok = False
        return ok
    # ゼロとその他1個でかつぜろが1/3個
    if c[0] == n // 3 and len(c) == 2:
        ok = True
        return ok
    # 全部違ってて1/3ずつでxorして0
    if len(c) != 3:
        ok = False
        return ok
    xor = 0
    for x in c:
        if c[x] != n // 3:
            ok = False
            return ok
        xor ^= x
    if xor == 0:
        ok = True
    else:
        ok = False
    return ok
        
if __name__ == '__main__':
    print("Yes" if main() else "No")

Measured memory_bytes: 20916
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; i--)
#define REP(i, k, n) for(int i=(int)(k); i<(int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const int INF = INT_MAX;
const ll inf = 1e18;
const ll mod = 998244353;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

template<typename T>
struct BIT{
	int n;
	vector<T> d;
	BIT(int n=0):n(n),d(n+1){}
	void add(int i, T x=1) {
		for(i++; i <= n; i += i&-i){
			d[i] += x;
		}
	}
	T sum(int i) {
		T x = 0;
		for(i++; i; i -= i&-i){
			x += d[i];
		}
		return x;
	}
	T sum(int l, int r){
		return sum(r-1) - sum(l-1);
	}
};

ll f(int x){
	return ((ll)x*(x+1))/2;
}

const int MX = 200010;
int N, k, in[MX], out[MX];
vector<int> G[MX], c[MX];

void dfs(int v, int p=-1){
	in[v] = k++;
	for(auto to:G[v]){
		if(to == p) continue;
		dfs(to, v);
	}
	out[v] = k;
}

bool comp(int i, int j){
	return in[i] < in[j];
}

int main(){
	cin >> N;
	rep(i, N){
		int cl; cin >> cl;
		cl--;
		c[cl].pb(i);
	}
	rep(i, N-1){
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0);
	BIT<int> bit(N);
	rep(i, N) bit.add(i);
	rep(i, N){
		ll ans = f(N);
		vector<P> memo;
		sort(all(c[i]), comp);
		rrep(j, c[i].size()){
			int su = 0;
			for(auto to:G[c[i][j]]){
				if(in[to] < in[c[i][j]]) continue;
				int num = bit.sum(in[to], out[to]);
				su += num;
				ans -= f(num);
			}
			bit.add(in[c[i][j]], -su-1);
			memo.pb(P(in[c[i][j]], su+1));
		}
		ans -= f(bit.sum(N-1));
		rep(j, memo.size()){
			bit.add(memo[j].first, memo[j].second);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;

    bool ok = true;
    string ac = s.substr(a, c-a+1);
    string bd = s.substr(b, d-b+1);
    if (ac.find("##") != string::npos) ok = false;
    if (bd.find("##") != string::npos) ok = false;
    if (d < c) {
        string _bd_ = s.substr(b-1, d-b+3);
        if (_bd_.find("...") == string::npos) ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   cin>>s;
   if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')cout<<3;
   else if(s[0]=='R'&&s[1]=='R'&&s[2]=='S')cout<<2;
   else if(s[0]=='S'&&s[1]=='R'&&s[2]=='R')cout<<2;
   else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S')cout<<0;
   else cout<<1;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		// a > b ??¨????????¢????????????
		if (a < b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long d = 0; // d : gcd(a,b)
		while (true) {
			long r = a % b; // a == n*b + r ( r < b )

			if (r == 0) {
				d = b;
				break;
			}

			a = b;
			b = r;
		}

		System.out.println(d);
	}

}

Measured memory_bytes: 26156
K,N = list(map(int, input().split()))
A = [int(x) for x in input().split()]

dct = sorted(A)
ans = [] * (N + 1)
new = K + dct[0] - dct[N-1]

ans.append(new)

for i in range(N-1):
    ans.append(dct[i+1] - dct[i])

print(sum(ans) - max(ans))


Measured memory_bytes: 26436
#include <stdio.h>

int main(void) {
    int a;
    int b;
    int c;
    int flg = 0;
    
    scanf("%d %d %d",&a, &b, &c);
    
    if (((a + b) == c) ||
        ((b + c) == a) ||
        ((a + c) == b)) {
            flg = 1;
    }
    
    if (flg == 1) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    Rep(i, 1, 10)
    {
        if (n % i == 0 && n / i < 10)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[88],a[88];

int main(void){
	int n,i,j,k;
	ll ans = 1000ll;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a[i];
	}
	for(i=1; i<n; ++i){
		if(a[i-1]<a[i]){
			ans = ans%a[i-1]+a[i]*(ans/a[i-1]);
		}
	}
	std::cout << ans << std::endl; 
	return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
long long H, h, W, w;
long long a[1090][1090];
bool check() {
    long long sum = 0;
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j)
            sum += a[i][j];
    return sum > 0;
}
int main() {
    scanf("%lld %lld %lld %lld", &H, &W, &h, &w);
    for (int i = h; i <= H; i += h)
        for (int j = w; j <= W; j += w)
            a[i][j] = -(long long)(h*w-1LL)*4000LL-1LL;
    for (int i = 1; i <= H; ++i)
        for (int j = 1; j <= W; ++j)
            if (a[i][j] == 0) a[i][j] = 4000;
    if (check()) {
        puts("Yes");
        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j <= W; ++j)
                printf("%lld ", a[i][j]);
            putchar('\n');
        }
    }
    else puts("No");
}


Measured memory_bytes: 7552
using System;
using System.Collections.Generic;


    class Program
    {
        static void Main(string[] args)
        {
            string input =Console.ReadLine();
            char[] c = input.ToCharArray();
            List<char> odd = new List<char>();
            List<char> even = new List<char>();
            string output="";

            for(int i=0; i<c.Length-1 ; i=i+2)
            {
                odd.Add(c[i]);
                even.Add(c[i+1]);
            }
            if(c.Length%2==1)
            {
                odd.Add(c[c.Length-1]);
            }

            if(odd.Contains('L') || even.Contains('R'))
            {
                output = "No";
            }
            else
            {
                output = "Yes";
            }

            Console.WriteLine(output);

        }

    }


Measured memory_bytes: 13152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5+100;
char s[maxn];

int a[maxn];
struct node{
    int l,r;
};

vector<node>v;

int main()
{
    scanf("%s",s);
    int len = strlen(s);
    int x = 0;
    int y = 0;
    if(s[0]=='>')
        x++;
    else
        y++;
    int num = 0;
    for(int i=1;i<len;i++){
        if(s[i]=='>'&&s[i]!=s[i-1]){
            num = num + x + y;
            v.push_back(node{x,y});
            x=1;
            y=0;
        }
        else if(s[i]=='>'){
            x++;
        }
        else{
            y++;
        }
    }
    if(num!=len)
        v.push_back(node{x,y});
//    for(auto x:v)
//        cout<<x.l<<" "<<x.r<<endl;
    len = v.size();
    ll ans = 0;
    ans = ans + (1LL + v[0].l) * v[0].l /2;
    ans = ans + (1LL * v[0].r - 1) * v[0].r /2;
        //cout<<ans<<endl;
    for(int i = 1;i<len;i++){
        ans = ans + max(v[i-1].r,v[i].l);
        ans = ans + (1LL * v[i].l - 1) * v[i].l /2;
        ans = ans + (1LL * v[i].r - 1) * v[i].r /2;
        //cout<<ans<<endl;
    }
    ans += v[len-1].r;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1912
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e18;
const double eps = 1e-8;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}int n, m,s,t,r,Q,a,b,c;
struct edge {
    int to;
    ll cost;
};
vector<vector<vector<edge>>> G(2);
using p = pair<ll, ll>;
vector<ll> dijkstra(int s,int ti) {
    priority_queue<p, vector<p>, greater<p>> q;
    vector<ll> d(n,1e18);
    d[s] = 0;
    q.push(p(0, s));
    while (!q.empty()) {
        p now = q.top(); q.pop();
        int v = now.second;
        if (d[v] < now.first) continue;
        rep(i, G[ti][v].size()) {
            edge e = G[ti][v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push(p(d[e.to], e.to));
            }
        }
    }return d;
}
int main(void) {
    cin >> n >> m >> s >> t; G[0].resize(n);
    G[1].resize(n); s--; t--;
    rep(i, m) {
        cin >> a >> b >> r >> c; a--; b--;
        G[0][a].push_back({ b,r });
        G[0][b].push_back({ a,r });
        G[1][a].push_back({ b,c });
        G[1][b].push_back({ a,c });
    }
    auto d = dijkstra(s, 0), dd = dijkstra(t, 1);
    priority_queue<p> pq;
    rep(i, n) {
        pq.push({ 1e15 - d[i] - dd[i],i });
    }
    rep(i, n) {
        while (pq.top().second < i) pq.pop();
        pair<ll,ll> ans = pq.top();
        cout << ans.first << endl;
    }
}

Measured memory_bytes: 19836