akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Multiple of 9
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

void solve()
{
	string s;cin>>s;
	int sum=0;
	for(char c:s)
	sum+=(c-'0');
	if(sum%9==0)
	cout<<"Yes";
	else
	cout<<"No";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h,n;
	cin>>h>>n;
	int a[n+1];
	int sum=0;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<h)
	  cout<<"No";
	else
	  cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 640
let hand a =
    let t = (a.(0),a.(1),a.(2),a.(3),a.(4)) in
    match t with
    (i,j,k,l,m) when (j,k,l) = (i,i,i) || (k,l,m) = (j,j,j) -> print_endline "four card"
    | (i,j,k,l,m) when (j,l,m) = (i,k,k) || (j,k,m) = (i,i,l) -> print_endline "full house"
    | (i,j,k,l,m) when (j,k) = (i,i) || (k,l) = (j,j) || (l,m) = (k,k) -> print_endline "three card"
    | (i,j,k,l,m) when (j,l) = (i,k) || (j,m) = (i,l) || (k,m) = (j,l) -> print_endline "two pair"
    | (i,j,k,l,m) when j = i || k = j || l = k || m = l -> print_endline "one pair"
    | (i,j,k,l,m) when (i,j,k,l,m) = (i,(i+1),(i+2),(i+3),(i+4))
                     || (i,j,k,l,m) = (1,10,11,12,13) -> print_endline "straight"
    | _ -> print_endline "null"
;;

let () =
    let rec read () =
        try let line = Scanf.scanf " %d,%d,%d,%d,%d\n" (fun v w x y z -> [|v;w;x;y;z|]) in
        Array.sort compare line;
        hand line;
        read ()
        with End_of_file -> ()
    in read ()
;;

Measured memory_bytes: 2224
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
  int n,i;
  ll k,a[200005];
  
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> a[i];
  
  sort(a,a+n);
  
  ll l,r,mid,trg,t;
  ll *p;
  l=-1e18;
  r=1e18;
  while (r-l>1){
    
    mid=(l+r)/2;
    t=0;
    for (i=0;i<n;i++){
      if (a[i]==0){
        if (mid>=0) t+=n-1;
      }else if (a[i]<0){
        if (mid>=0) trg=-(mid/(-a[i]));
        else trg=(-mid-a[i]-1)/(-a[i]);
        p=lower_bound(a,a+n,trg);
        if (p<=a+i) p++;
        t+=a+n-p;
      }else{
        if (mid>=0) trg=mid/a[i];
        else trg=(mid-a[i]+1)/a[i];
        p=upper_bound(a,a+n,trg);
        if (p>a+i) p--;
        t+=p-a;
      }
    }
    if (t/2>=k) r=mid;
    else l=mid;
    
  }
  
  cout << r << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cmath>
#include <map> 
using namespace std;
#define MAXN 1000010
int ar[MAXN];
struct st{
	long long b,c;
};
bool karsilastir(st s1, st s2)
{
	return(s1.c > s2.c);
}
st s[MAXN];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	long long n,m,i,j,b,c,say=0,atut=0,stut=0;
	long long yaz=0;

	cin>>n>>m;
	for(i=0;i<n;i++) cin>>ar[i];
	sort(ar,ar+n,greater<int>());	
	for(i=0;i<m;i++)
	{
		cin>>s[i].b>>s[i].c;
	}
	sort(s, s+m, karsilastir); 
	while(say<n)
	{
		if(ar[atut]>s[stut].c)
		{
			yaz+=ar[atut++];
			say++;
		}
		else
		{
			if(say+s[stut].b>=n)
			{
				yaz+=(s[stut].c*(n-say));
				cout<<yaz<<endl;
				return 0;
			}
			yaz+=(s[stut].c*s[stut].b);
			say+=s[stut++].b;
		}
	}
	cout<<yaz<<endl;
	return 0;
}

Measured memory_bytes: 3840
m=10**9+7
f=max
r=range
for _ in r(int(input())):
	x,y=sorted(map(int,input().split()))
	s=-1
	i=j=1
	while j<=x and i+j<=y:i,j,s=j,i+j,s+1
	if x<2 or y<3:print(1,x*y%m);continue
	a=f(0,(y-j)//i+1)+f(0,(x-j)//i+1)
	i=j=1
	for c in r(s):
		k,l=j,i+j*2
		for _ in r(s-c):k,l=l,k+l
		if x>=k:a+=f(0,(y-l)//k+1)
		if y>=k:a+=f(0,(x-l)//k+1)
		i,j=j,i+j
	print(s+1,a%m)

Measured memory_bytes: 81268
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int m,f,r;
	while (cin >> m >> f >> r, (m != -1)||(f != -1)||(r != -1) ) {
		if (m < 0 || f < 0) {
			cout << "F" << endl;
		}
		else if (m+f >= 80) {
			cout << "A" << endl;
		}
		else if (m+f >= 65) {
			cout << "B" << endl;
		}
		else if (m+f >= 50 || (m+f >= 30)&&(r >= 50)) {
			cout << "C" << endl;
		}
		else if (m+f >= 30) {
			cout << "D" << endl;
		}
		else {
			cout << "F" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	long long int N,W;
	cin>>N>>W;
	vector<long long int> v(N);
	vector<long long int> w(N);
	for(int i=0;i<N;i++)
	{
		cin>>w[i]>>v[i];
	}
	vector <vector<long long int> > dp(N+1,vector<long long int> (W+1));
	for(long long int i=0;i<=N;i++)
	{
		for(long long int j=0;j<=W;j++)
		{
			if(i==0 or j==0)
			{
				dp[i][j]=0;
			}
			else if(w[i-1]>j)
			{
				dp[i][j]=dp[i-1][j];
			}
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
			}
		}
	}
	cout<<dp[N][W];


}

Measured memory_bytes: 80256
def main():
    x = int(input())
    a = 1
    diff = 1
    while True:
        res = a ** 5 - (a - diff) ** 5
        if res < x:
            a += 1
            continue
        if res == x:
            print(a, a - diff)
            break
        while True:
            diff += 1
            if x % diff == 0:
                break
        a = (diff + 1) // 2

if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	string s;
	cin >> s;
	int n = s.length();
	bool ok = true;
	for (int i = 0; i < n; i += 2) {
		if (s[i] == 'L') {
			ok = false;
		}
	}
	for (int i = 1; i < n; i+= 2) {
		if (s[i] == 'R') {
			ok = false;
		}
	}
	if (ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3572
import copy
n=int(input())
A=sorted(list(map(int,input().split())))
B=copy.deepcopy(A)
for i in range(1,n):
    B[i]=B[i]+B[i-1]

cnt=1
for i in reversed(range(n-1)):
    if B[i]*2>=A[i+1]:
        cnt +=1
    else:break
print(cnt)

Measured memory_bytes: 14956
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    bool p=false;
    int a[n],ans[n+1];
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==1)
        {
            p=true;
        }
    }
    ans[0]=0;
    if(p)
    {
        for(int i=0;i<n;i++)
        {
            if(ans[a[i]]==-1 && ans[a[i]-1]!=-1)
            {
                ans[a[i]]=i+1;
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(ans[i]==-1 && ans[i-1]!=-1)
            {
                ans[i]=n+1;
                break;
            }
        }
        int total=0;
        for(int i=0;i<n;i++)
        {
            if(ans[i]!=-1 && ans[i+1]!=-1)
            {
                total+=ans[i+1]-ans[i]-1;
            }
        }
        cout<<total;
    }
    else
    {
        cout<<-1;
    }
    return 0;
}







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

int main(){
  int n,count=0,flag=1;
  cin >> n;
  vector<int> v(n,0);
  r(i,n)cin >> v.at(i);
  while(flag){
    r(i,n){
      if(v.at(i)%2==0)v.at(i)/=2;
      else {
        flag=0;
        break;
      }
    }
    count++;
  }
  cout << count-1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char S[60];
char T[60];
int n,m;
bool chk(){
	for(int i=0;i<=n-m;i++){
		bool ok=true;
		for(int j=0;j<m;j++){
			if(S[i+j]!='?'&&S[i+j]!=T[j])ok=false;
		}
		if(ok)return true;
	}
	return false;
}
int main(){
	scanf("%s%s",S,T);
	n=strlen(S);
	m=strlen(T);
	for(int i=0;i<n;i++){
		bool fl=false;
		if(S[i]=='?')fl=true;
		for(int j=0;j<26;j++){
			if(fl)S[i]=j+'a';
			if(chk()){break;}
			else if(j==25){
				printf("UNRESTORABLE\n");return 0;
			}
		}
	}
	printf("%s\n",S);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double p[1010];
    int n;
    int t,a,x;
    int place=0;
    double u=1000;
    cin>>n>>t>>a;
    for(int i=1;i<=n;i++)
      {
        cin>>x;
        double tmp=t-(x*0.006);
        p[i]=tmp;
      }
    for(int i=1;i<=n;i++)
    {
        if(abs(a-p[i])<u)
            u=abs(a-p[i]),place=i;
    }
    printf("%d\n",place);
	return 0;
}


Measured memory_bytes: 256
# coding: UTF-8
import os

def remove_empty(target_list: list):
    empty_removed_list = [x for x in target_list if x]
    return empty_removed_list


def get_stdin_str_list(input_str=None):
    if input_str is None:
        input_str = input()
    input_str = input_str.strip()
    input_str_list = input_str.split()
    return input_str_list


def get_stdin_int_list(input_str=None):
    input_str_list = get_stdin_str_list(input_str)
    input_int_list = list(map(int, input_str_list))
    return input_int_list


def get_stdin_str_multi_list(input_str=None):
    if input_str is None:
        input_str = input()
    input_str = input_str.strip()
    input_str_line_list = input_str.split("\n")
    input_str_multi_list = list()
    for str_line in input_str_line_list:
        input_str_list = get_stdin_str_list(str_line)
        input_str_multi_list.append(input_str_list)
    return input_str_multi_list


def get_stdin_int_multi_list(input_str=None):
    input_str_multi_list = get_stdin_str_multi_list(input_str)
    input_int_multi_list = list()
    for str_list in input_str_multi_list:
        input_int_list = list(map(int, str_list))
        input_int_multi_list.append(input_int_list)
    return input_int_multi_list

def get_most_far_pos_index_from_both_neighbors(pos_list, end_pos_distance=None):
    if end_pos_distance is None:
        end_pos_distance = pos_list[-1]
    N = len(pos_list)
    max_distance = 0
    most_far_pos_index = 0
    for i, p in enumerate(pos_list):
        if i == 0:
            distance = end_pos_distance - pos_list[-1] + pos_list[i+1]
        elif i == N-1:
            distance = end_pos_distance - pos_list[i-1] + pos_list[0]
        else:
            distance = pos_list[i+1] - pos_list[i-1]
        
        if distance > max_distance:
            max_distance = distance
            most_far_pos_index = i

    return most_far_pos_index

def get_longest_interval(pos_list, end_pos_distance=None):
    if end_pos_distance is None:
        end_pos_distance = pos_list[-1]
    N = len(pos_list)
    longest_interval = 0

    for i, p in enumerate(pos_list):
        if i == N-1:
            pos_n_1 = end_pos_distance + pos_list[0]
        else:
            pos_n_1 = pos_list[i+1]

        interval = pos_n_1 - p

        if interval > longest_interval:
            longest_interval = interval

    return longest_interval

K, N = get_stdin_int_list()
A = get_stdin_int_list()
longest_interval = get_longest_interval(A, K)
shortest_distance = K - longest_interval
print(shortest_distance)

Measured memory_bytes: 26444
#include <iostream>

int main() {
  int S, h, m, s;

  std::cin >> S;

  s = S % 60;
  m = S / 60;
  
  h = m / 60;
  m = m % 60;

  std::cout << h << ":" << m << ":" << s << std::endl;

  return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;

#define MAXI 150
 
struct ITEM{
	int h, p, q;
	
	ITEM(){h = p = q = 0;}
	ITEM(int h, int p, int q):h(h), p(p), q(q){}
	
	bool operator<(const ITEM r){
		return h < r.h;
	}
	
};
 
int main(){

	int n, m, a;
	while(cin >> n >> m >> a, n, m, a){
		vector<ITEM> item(m);
		rep(i, m){
			int h, p, q;
			cin >> h >> p >> q;
			item[i] = ITEM(h, p, q);
		}
		
		SORT(item);
		vector<int> ans(n+1);
		rep(i, n+1) ans[i] =i;
		rep(i, m)swap(ans[item[i].p], ans[item[i].q]);
		
		cout << ans[a] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3096
from copy import deepcopy
from collections import deque
h,w=map(int,input().split())
ss=[]
u=[(-1,0),(1,0),(0,1),(0,-1)]
ans=0
for i in range(h):
    ss.append(list(input()))
for i in range(h):
    for j in range(w):
        s=deepcopy(ss)
        if s[i][j]=="#":
            continue
        if s[i][j]==".":
            tmp=0
            x,y=i,j
            s[x][y]=0
            que=deque()
            que.append([x,y])
            while que:
                x,y=que.popleft()
                for xx,yy in u:
                    nx,ny=x+xx,y+yy
                    if 0<=nx<h and 0<=ny<w:
                        if s[nx][ny]==".":
                            s[nx][ny]=s[x][y]+1
                            if tmp<s[nx][ny]:
                                tmp=s[nx][ny]
                            que.append([nx,ny])
        if tmp>ans:
            ans=tmp
print(ans)            

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    int n, m;
    cin >> n >> m;
    VEC(ll, m, x, 0);
    VEC(ll, m-1, y, 0);
    REP(i,m) cin >> x[i];
    sort(ALL(x));
    REP(i, m -1)
    {
        y[i] = x[i+1]-x[i];
    }
    sort(ALL(y));

    if( n >= m ) cout << 0 << endl;
    else
    {
    ll ans = 0;
    REP(i,m-n) ans += y[i];
    cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
#define all(c) c.begin(),c.end()
#define pb push_back
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
vector<string> s;
int w,h;
vector<P> p;
vector<vector<int> > dist;
map<P,int> mp;
vector<vector<int> > dp;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
bool inf(int y,int x){
	if(x>=0&&x<w&&y>=0&&y<h)
	return true;
	return false;
}
int TSP(int now,int bit){
	if(bit==(1<<p.size())-1){
		return 0;
	}
	if(dp[bit][now]!=-1)
		return dp[bit][now];
	int ret=INF;
	for(int i=1;i<p.size();i++){
		if( !( (1<<i) &bit ) ){
			ret=min(TSP(i,bit|(1<<i))+dist[now][i],ret);
		}
	}
	
	return dp[bit][now]=ret;
}
int main(){
	while(cin>>w>>h,w||h){
		
		s.resize(h);
		p.resize(1);
		mp.clear();
		p[0]=P(0,0);
		
		for(int i=0;i<h;i++){
			cin>>s[i];
			for(int j=0;j<w;j++){
				if(s[i][j]=='o'){
					p[0]=P(i,j);
					mp[P(i,j)]=0;
				}else if(s[i][j]=='*'){
					mp[P(i,j)]=p.size();
					p.pb(P(i,j));
				}
			}
		}
		dist=vector<vector<int> >(p.size(),vector<int>(p.size(),INF));
		bool flag=true;
		for(int i=0;i<p.size();i++){
			queue<P> que;
			vector<vector<int> > d(h,vector<int>(w,INF));
			vector<vector<bool> > used(h,vector<bool>(w,false));
			d[p[i].first][p[i].second]=0;
			que.push(p[i]);
			int cnt=0;
			while(!que.empty()){
				P t=que.front();
				que.pop();
				if(used[t.first][t.second]){
					continue;
				}
				if(find(all(p),t)!=p.end()&&dist[i][mp[t]]==INF){
					dist[i][mp[t]]=d[t.first][t.second];
					cnt++;
				}
				used[t.first][t.second]=true;
				for(int i=0;i<4;i++){
					int nx=dx[i]+t.second,ny=dy[i]+t.first;
					if(inf(ny,nx)&&!used[ny][nx]&&d[ny][nx]==INF&&s[ny][nx]!='x'){
						que.push(P(ny,nx));
						d[ny][nx]=d[t.first][t.second]+1;
					}
				}
			}
			if(cnt!=p.size()){
				flag=false;
				break;
			}
		}
		if(!flag){
			cout<<-1<<endl;
			continue;
		}
		
		dp=vector<vector<int> >((1<<p.size()),vector<int>(p.size(),-1));
		cout<<TSP(0,1)<<endl;
	}
	return 0;
}

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

int main() {
    long long x, y, n, k;
    cin>>n>>k>>x>>y;
    if(n<=k){
       cout<<x*n<<endl; 
    }else{
       int m=(k*x)+(n-k)*y;
       cout<<m<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define MAX 500000

void insert(int);
int find(int);
void print();
void pO(int);
void iO(int);

int Root = NIL;
int l[MAX],r[MAX],key[MAX],p[MAX];

int main(){
  
  int i,j,k=0;
  int N;
  char in[15];
  
  scanf("%d",&N);
  for(i=0;i<MAX;i++) key[i]=l[i]=r[i]=p[i]=NIL;
  for(i=0;i<N;i++){
    scanf("%s",in);
    if(in[0]=='i'){
      scanf("%d",&j);
      key[k]=j;
      insert(k++);
    }
    else if(in[0]=='p')print();
    else if(in[0]=='f'){
       scanf("%d",&j);
       if(find(j)==1)printf("yes\n");
       else printf("no\n");
    }
  }
  
  return 0;
}

void insert(int a){
  int x=NIL;
  int y=Root;
  while(y!=NIL){
    x=y;
    if(key[a]<key[y]) y=l[x];
    else y=r[y];
  }
  p[a]=y;
  if(x==NIL) Root=a;
  else if(key[a]<key[x]) l[x]=a;
  else r[x]=a;  
}

int find(int b){
  int i=0;
  int x=NIL,y=Root;
   while(y!=NIL){
     if(key[y]==b)return 1;
    x = y;
    if(b<key[y]) y=l[y];
    else y=r[y];
  }
   return 0;
}

void print(){
  iO(Root);
  printf("\n");
  pO(Root);
  printf("\n");
}

void pO(int c){
  if(c==NIL)return;
  printf(" %d",key[c]);
  pO(l[c]);
  pO(r[c]);
}

void iO(int d){
  if(d==NIL)return;
  iO(l[d]);
  printf(" %d",key[d]);
  iO(r[d]);
}





Measured memory_bytes: 9672
a=gets.to_i 
b=gets.to_i
c=gets.to_i
x=gets.to_i
sum=0
for i in 0..a do
  for j in 0..b do
    for k in 0..c do
      way = i*500 + j*100 + k*50
      if way == x 
        sum = sum+1 
      end
    end
  end
end
puts sum

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n);re(i, n) std::cin >> a[i];
  ll ans = 10000000000;
  for(ll i=1;i<=100;i++){
    ll tmp = 0;
    re(j, n) tmp += (a[j] - i)*(a[j] - i);
    ans = min(ans, tmp);
  }
  std::cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main()
{
    int x;
    stack<int> st;
    while (cin >> x) {
        if (x == 0) {
            cout << st.top() << endl;
            st.pop();
        } else {
            st.push(x);
        }
    }
    return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
#define rep(n,k) for(int i = (int)n;i<k;i++)
using Int =long long int;
using Graph =vector<vector<int>>;
int main(){
  int D,T,S;
  cin>>D>>T>>S;
  if(S*T>=D)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

bool validate(char c){
	if(c == 'A' || c == 'C' || c == 'T' || c == 'G')return true;
	return false;
}

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

  string s;
  cin >> s;
  int n = s.size();
  int ans = 0, cnt = 0;
  forn(i, 0, n){
	  if(validate(s[i]))cnt++;
	  else{
		  ans = max(ans, cnt);
		  cnt = 0;
	  }
  }
  ans = max(ans, cnt);
  cout << ans << endl;

}




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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int D = A % B;

    int E = D;
    do
    {
        if (E % B == C)
        {
            cout << "YES" << endl;
            return 0;
        }
        E = (E + D) % B;
    } while (E != D);
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define debug(x) #x << "=" << (x)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc054/tasks/abc054_c 

int p[10][10] = {};

int main() {
    int N, M; cin >> N >> M;

    int a, b;
    REP(i, M) {
        cin >> a >> b;
        p[a][b] = 1;
        p[b][a] = 1;
    }

    vector<int> perm(N-1);
    REP(i, N-1) perm[i] = i+2;
    sort(perm.begin(), perm.end());

    int ans = 0;
    do {
        int current = 1;
        for (int i = 0; i < perm.size(); i++) {
            if (!p[current][perm[i]]) break;
            current = perm[i];
            if (i == perm.size() - 1) ans++;
        }
    } while(next_permutation(perm.begin(), perm.end()));

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("E.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
struct bit{
	int n;
	ll a[100002];
	void add(int p,int v){
		for(;p;p-=p&-p)
			a[p]+=v;
	}
	ll query(int p){
		ll ans=0;
		for(;p<=n;p+=p&-p)
			ans+=a[p];
		return ans;
	}
}b,c;
pair<int,int> w[100002];
int a[100002],pre[100002];
ll sum[100002],cnt[100002];
int main(){
	init();
	int n=readint();
	for(int i=1;i<=n;i++){
		a[i]=readint();
		if (a[i]>=a[pre[i-1]])
			pre[i]=i;
		else pre[i]=pre[i-1];
		w[i]=make_pair(a[i],i);
	}
	sort(w+1,w+n+1);
	b.n=c.n=n;
	for(int i=n;i;i--){
		sum[w[i].second]=c.query(w[i].second+1);
		cnt[w[i].second]=b.query(w[i].second+1);
		b.add(w[i].second,1);
		c.add(w[i].second,w[i].first);
	}
	sum[0]=c.query(1);
	cnt[0]=n;
	for(int i=1;i<=n;i++){
		// printf("%d %lld %lld\n",pre[i],sum[i],cnt[i]);
		if (pre[i]==pre[i-1]){
			puts("0");
			continue;
		}
		ll ans=cnt[i]*(a[i]-a[pre[i-1]]);
		ans+=(sum[pre[i-1]]-sum[i])-(cnt[pre[i-1]]-cnt[i])*a[pre[i-1]];
		printf("%lld\n",ans);
	}
}


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

int n,m,x,y;
int p[100001];

int par[100001];

int root(int x){
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
}

void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    par[x]=y;
}

bool same(int x,int y){
    return root(x)==root(y);
}

int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){cin>>p[i];par[i]=i;}
    for(int i=0;i<m;i++){
        cin>>x>>y;
        unite(x,y);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(same(i,p[i]))ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int ans;
    long double a,b,s;
	cin>>a>>b;
	s=a*b;
	ans=(long long int) s;
	cout<<ans;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int fact[MAX_N];
int ifact[MAX_N];

int power(int x, int n) {
	int res = 1LL;
	while (n > 0) {
		if (n & 1) (res *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	return res % MOD;
}

int inv(int x) {
	return power(x, MOD - 2);
}

int nCr(int n, int r) {
	if (n < 0 || r < 0 || r > n) return 0;
	if (r > n / 2) r = n - r;
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

void init_fact() {
  fact[0] = ifact[0] = 1;
	for (int i=1; i<MAX_N; ++i) {
		(fact[i] = fact[i - 1] * i) %= MOD;
		ifact[i] = inv(fact[i]);
	}
}

struct Eratosthenes {
  vector< bool > prime;
  Eratosthenes(int _size) {
    init(_size);
  }

  void init(int n) {
    prime.resize(n + 1);
    for(int i = 0; i < prime.size(); ++i) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i = 2; i < sqrt(n); i++) {
      if (prime[i]) {
        for (int j = 0; i * (j + 2) < n; j++) {
					prime[i * (j + 2)] = false;
				}
      }
    }
  }

	map< int, int > prime_factorize(int n) {
		map< int, int > res;
		for (int i=2; i*i<=n; ++i) {
			if (!prime[i]) continue;
			if (n % i != 0) continue;
			int num = 0;
			while (n % i == 0) {
				res[i]++;  n /= i;
			}
		}
		if (n != 1) res[n]++;
		return res;
	}
};

signed main() {
  INIT;
	init_fact();
	VAR(int, n, m);

	Eratosthenes e(MAX_N);
	map< int, int > mp = e.prime_factorize(m);

	int ans = 1;
	EACH(mi, mp) {
		(ans *= nCr(mi.second + n - 1, n - 1)) %= MOD;
	}

	OUT(ans)BR;
	
  return 0;
}




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

int main(){
  int N; cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i++){
    for(int j=1; j<=N; j++){
      for(int k=1; k<=N; k++){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

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

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int x;
    int res=0;
    for(int i=0;i<5;i++){
        cin>>x;
        if(x==0)    res=i+1;
    }
    cout<<res<<endl;
    return 0;
}
    


Measured memory_bytes: 3508
#include <stdio.h>
 
int main( void )
{
    int i,n,x[100];
	
    scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%d", &x[i]);
	}
	
	for(i = 0; i < n; i++){
		printf((i == n-1) ? "%d\n" : "%d ", x[n-1-i]);
	}
    
    return 0;
}

Measured memory_bytes: 596
while True:
    n=int(raw_input())
    if n==0:
        break

    sum_a=0
    sum_b=0

    for i in xrange(n):
        a,b = (int(x) for x in raw_input().split())
        if a>b :
            sum_a += a+b
        elif a==b:
            sum_a += a
            sum_b += b
        else:
            sum_b += a+b
    print "%d %d" % (sum_a, sum_b)

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

int main(){
  long long int N,K,ans=0;
  cin>>N>>K;
  long long int a=N/K;
  ans += a*a*a;
  long long int b=(N/(K/2)+1)/2;
  if(K%2==0) ans += b*b*b;
  cout<<ans<<endl;
}

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

int main()
{
  ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
  string s;
  cin >> s;
  
  s[5] = ' ';
  s[13] = ' ';
  
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

char s[10];

void solve(void)
{
	scanf("%s",s+1);
	if(s[3]==s[4] && s[5]==s[6]) printf("Yes\n");
	else printf("No\n");
}

int main(void)
{
	int T=1;
	while(T--) solve();
	return 0;
}

Measured memory_bytes: 128
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  while(true) {
    int n,ans=0;
    cin >> n;
    if(n==0) {
      return 0;
    }
    string s,g;
    int t[86500]={};
    for(int i=0; i<n; i++) {
      int x,y;
      cin >> s >> g;
      x=(stoi(s.substr(0,2)))*3600+(stoi(s.substr(3,2)))*60+stoi(s.substr(6,2));
      y=(stoi(g.substr(0,2)))*3600+(stoi(g.substr(3,2)))*60+stoi(g.substr(6,2));
      x++,y++;
      t[x]++,t[y]--;
    }
    for(int i=1; i<=86450; i++) {
      t[i]+=t[i-1];
      ans=max(ans,t[i]);
    }
    cout << ans << endl;
  }
}


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

using namespace std;

int main(){
    long A, B, C, D, E, F;
    cin>>A>>B>>C>>D>>E>>F;
    
    long a, b, c, d, e, f;
    a = F/(100*A);
    b = F/(100*B);
    c = F/C;
    d = F/D;

    long alpha=100*A, beta=0;
    double rate = 0;
    double max_rate = 100.0 * E / (100 + E);
    for(int i=0; i<=a; ++i){
        if(100*A*i > F){
            break;
        }
        for(int j=0; j<=b; ++j){
            if(100*A*i + 100*B*j > F){
                break;
            }
            for(int k=0; k<=c; ++k){
                if(100*A*i + 100*B*j + k*C > F){
                    break;
                }
                for(int l=0; l<=d; ++l){
                    long sugar = k*C + l*D;
                    long x = 100*A*i + 100*B*j + sugar;
                    if(x <= F){
                        double r = 100.0 * sugar / x;
                        if(r > rate && r <= max_rate){
                            rate = r;
                            alpha = x;
                            beta = sugar;
                        }
                    }
                }
            }
        }
    }
    cout<<alpha<<" "<<beta<<endl;

    return 0;
}









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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    cin >> N;
    ll answer = 0;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            answer += d[i]*d[j];
        }
    }

    cout << answer;
    return 0;
}

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

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

    ll sum = 0;
    for(auto c : s)
    {
        sum += c - '0';
    }

    if(sum % 9 == 0) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 3740
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

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

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vector<int> digits(n, -1);

  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (digits[s] != -1 &&  digits[s] != c ) {
      cout << -1 << endl;
      return 0;
    }
    else {
      digits[s] = c;
    }
  }

  if (n == 1 && digits[0] == -1) {
    cout << 0 << endl;
    return 0;
  }
  if (n > 1 && digits[0] == 0) {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    if (i == 0 && digits[i] == -1) {
      digits[i] = 1;
    }
    else if (digits[i] == -1) {
      digits[i] = 0;
    }
  }

  int num = 0;
  int base = 1;
  for (int i = n - 1; i >= 0; --i) {
    num += base * digits[i];
    base *= 10;
  }

  cout << num << endl;

  return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  int h[n];
  for( int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> adj[n];
  for(int i = 0; i < m; i++) {
	int a,b;
    cin >> a >> b;
    a--,b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  bool is_good = false;
  int cnt_good = 0;
  for( int i = 0; i < n; i++) {
    is_good = true;
    for( int v : adj[i]) {
      if(h[i] > h[v]) continue;
      else {
        is_good = false;
        break;
      }
    }
    if(is_good) cnt_good++;
  }
  
  cout << cnt_good;
  return 0;
}
    
    
    
    
    
    
    
    
    
    
    
    
    
    

Measured memory_bytes: 9120
h,w,k = map(int,input().split())
mod = 10**9+7
dp = [[0]*(w+2) for _ in range(h+1)]
dp[0][1] = 1

#左右の余白を埋める場合の数
ref = [1,2,3,5,8,13,21]
pat = lambda l,r:ref[max(l,0)]*ref[max(r,0)]

for i in range(h):
	for j in range(1,w+1):
		dp[i+1][j] = dp[i][j-1]*pat(j-3,w-j-1) + dp[i][j]*pat(j-2,w-j-1) + dp[i][j+1]*pat(j-2,w-j-2)
		dp[i+1][j] %= mod
print(dp[-1][k])

Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))
ok = False
for i in range(N-2, -1, -1):
    if H[i] <= H[i+1]:
        continue
    H[i] -= 1
    if H[i] <= H[i+1]:
        continue
    break
else:
    ok = True

print("Yes" if ok else "No")





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

int main(){
    long long h,w;
    cin >> h >> w;
    long long ans;
    ans = (h/2)*w + (h%2)*(w-w/2);
    if(h == 1 || w == 1) ans = 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ld = long double;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll A(N);
  ll ans = 0;
  REP(i, 0, N) {
    cin >> A[i];
    if (i % 2 == 0 && A[i] % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3616
H, W = gets.split.map(&:to_i)
head = []
H.times do |i|
  gets.each_char.with_index do |c, j|
    if c == '#'
      head << i * W + j
    end
  end
end
field = Array.new(H * W)

count = -1
until head.empty?
  head_new = []
  res = false
  head.each do |ij|
    i = ij / W
    j = ij % W
    next if field[ij]
    res = true
    field[ij] = 0
    head_new << i * W + j - 1 if 0 < j && field[i * W + j - 1].nil?
    head_new << i * W + j + 1 if j < W - 1 && field[i * W + j + 1].nil?
    head_new << (i - 1) * W + j if 0 < i && field[(i - 1) * W + j].nil?
    head_new << (i + 1) * W + j if i < H - 1 && field[(i + 1) * W + j].nil?
  end
  head = head_new
  count += 1 if res
end

puts count


Measured memory_bytes: 45936
import sys
sys.setrecursionlimit(10000000)
import math
import bisect
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
n = int(input())
a = list(map(int,input().split()))
q = int(input())

alis = [0 for i in range(10**5+1)]
ans = 0
for i in a:
    alis[i]+=1
    ans+=i

bc = []
for i in range(q):
    b,c = map(int,input().split())
    bc.append([b,c])

for ii in bc:
    [b,c] = ii
    if alis[b]!=0:
        ans+=(c-b)*alis[b]
        alis[b],alis[c] = 0,alis[b]+alis[c]
    #print(alis[0:5])
    print(ans)


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    int a[2][n];

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

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

    ll ans = 0;

    for (int i = 0; i < n; ++i) {
        ll sum = 0;
        for (int j = 0; j <= i; ++j) {
            sum += a[0][j];
        }

        for (int k = i; k < n; ++k) {
            sum += a[1][k];
        }

        ans = max(ans, sum);
    }

    cout << ans << endl;
}

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

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
#define mpr make_pair

void solve(){
    int n; cin>>n;
    vl a(n);
    lint xand = 0;
    for (int i=0; i<n; ++i){
        cin>>a[i];
        xand ^= a[i];
    }
    if (xand == 0) {
        cout<<"DRAW\n"; return;
    }
    int bit = 33;
    for (bit=33; bit>=0; bit--){
        if (xand & (1LL<<bit)) break;
    }
    int cnt = 0;
    for (lint v : a)
        if (v & (1LL<<bit))
            cnt++;
    assert(cnt%2);
    int k = cnt/2;

    if (k % 2 == 0) cout<<"WIN\n";
    else
    {
        if ((n- cnt)%2==0 ) cout<<"LOSE\n";
        else cout<<"WIN\n";
    }
}

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

    int n; cin>>n;
    vl a(n);
    for (lint &i : a) cin>>i;

    lint cur = 1000;
    lint sto = 0;
    for (int i = 0; i<n-1; ++i){
        if (a[i+1] > a[i]){
            sto += cur/a[i];
            cur -= cur/a[i]*a[i];
        }
        else {
            cur += sto * a[i];
            sto = 0;
        }
    }
    cout<<cur + sto * a[n-1];

}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 100001;
int n, k,arr[3][MAX], dp[3][MAX];
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> n;
  
  for(int i=1;i<=n;i++)cin>>arr[0][i]>>arr[1][i]>>arr[2][i];
  
  //dp[0][1]=arr[0][1];
  //dp[1][1]=arr[1][1];
  //dp[2][1]=arr[2][1];
  
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k)continue;
      	dp[k][i+1]=max(dp[k][i+1], dp[j][i]+arr[k][i+1]);
      }
    }
  }
  
  cout<<max(dp[0][n],max(dp[1][n],dp[2][n]))<<endl;
}

Measured memory_bytes: 2560
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#define ll long long
#define MN 131072
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
vector<int> e[MN+5];
vector<pair<ll,ll> >v[MN+5];
int n,a[MN+5];ll d[MN+5],mid;
 
ll Check(int x,ll s)
{
	ll l=0,r=v[x].size()-1,Mid,res=-1;
	while(l<=r)
	{
		Mid=l+r>>1;
		if(v[x][Mid].first<=s) res=Mid,l=Mid+1;
		else r=Mid-1;	
	}
	return res<0?res:v[x][res].second;
}
 
void dfs(int x)
{
	v[x].clear();
	if(!e[x].size())return v[x].push_back(make_pair(d[x],d[x]));
	int l=e[x][0],r=e[x][1];
	d[l]=d[x]+a[l];dfs(l);
	d[r]=d[x]+a[r];dfs(r);
	if(v[l].size()>v[r].size()) swap(l,r);
	for(int i=0;i<v[l].size();++i)
	{
		ll rd=Check(r,d[x]+mid-(v[l][i].second-d[x]));
		if(rd!=-1) v[x].push_back(make_pair(v[l][i].first,rd));
	}
	int top=v[x].size();
	for(int i=0;i<top;++i) v[x].push_back(make_pair(v[x][i].second,v[x][i].first));
	sort(v[x].begin(),v[x].end());
	for(int i=1;i<v[x].size();++i) v[x][i].second=min(v[x][i].second,v[x][i-1].second);
}
 
int main()
{
	n=read();
	for(int i=2;i<=n;++i) e[read()].push_back(i),a[i]=read();
	ll l=0,r=(ll)2e10,res;
	while(l<=r)
	{
		mid=l+r>>1;dfs(1);
		if(v[1].size()) res=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 31988
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll sol(ll n) {
    if (n == 1) return 1;
    return sol(n / 2) * 2 + 1;
}

int main() {
    ios::sync_with_stdio(false);
    int h, n, a, b = 0;
    cin >> h >> n;
    while (n--) cin >> a, b += a;
    if (b >= h) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<a.length; ++i){
			a[i] = scn.nextInt();
		}
      	int count = 0;
      	for(int i=0; i<a.length; ++i){
          if(a[a[i]-1]==i+1) count++;
        }
      	System.out.println(count/2);
	}
}


Measured memory_bytes: 59172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iC = int.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "No";
            if (iA + iB >= iC) { sOut = "Yes"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 11220