akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include<bits/stdc++.h>
#define Ranger159 ios_base::sync_with_stdio(false);
#define PrintLater cin.tie(0);cout.tie(0);
#define ll long long
#define phb push_back
#define break break
#define pob pop_back()
#define continue continue
#define size size
#define insrt insert
#define fir first
#define true true
#define clear clear
#define vL vector<ll> 
#define resize resize
#define sec second
#define else else
#define reverse reverse
#define lbr1 cout<<"\n";
#define lbr2 cout<<"\n\n";
#define cin(v,n) for(ll i=0;i<n;i++) cin>>v[i];
#define cout(v,n) for(ll i=0;i<n;i++) cout<<v[i]<<" "; lbr1
const ll mod=1e9+7;

int main(int argc, char const *argv[])
{
	Ranger159
	// PrintLater
	ll test=1,n,a,b,c,k;
	// cin>>test;
	while(test--)
	{
		cin>>a>>b>>c>>k;
		ll cnt=0;
		if(b<=a)
		{
			cnt+=log2(a/b)+1;
			b=b*pow(2,cnt);
		}
		if(c<=b)
			cnt+=log2(b/c)+1;
		if(cnt<=k)
			cout<<"Yes";
		else cout<<"No";
		lbr1
	}
	return 0;
}

Measured memory_bytes: 3784
<?php
/*
    Problem URL : http://abc060.contest.atcoder.jp/tasks/abc060_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

list($A, $B, $C) = explode(" ", trim(fgets(STDIN)));

$t = $C;
while($t < 10000) {
    if ($t % $A == 0) {
        echo "YES\n";
        exit;
    }
    $t += $B;
}
echo "NO\n";


Measured memory_bytes: 4604
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct bian{int nxt,to;}bi[400040];
struct query
{
	int id,w;
	friend bool operator < (query a,query b){return a.w<b.w;}
}q[200020];
int n,head[200020],num,id[200020],siz[200020],idnum,mx[200020],f[200020];
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
int up[200020],sz[200020],s[200020],sum[200020],ans[200020];
int find(int x)
{
	if(up[x])return up[x]=find(up[x]);
	return x;
}
void dfs(int v,int fa)
{
	f[v]=fa;
	mx[v]=max(mx[fa],fa);
	q[v]=query{v,mx[v]};
	id[v]=++idnum;siz[v]=1;
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==fa)continue;
		dfs(u,v);siz[v]+=siz[u];
	}
}
namespace BIT
{
	long long sum[200020];
	inline void add(int p,int w){while(p<=n)sum[p]+=w,p+=p&-p;}
	inline int qry(int p){long long s=0;while(p)s+=sum[p],p-=p&-p;return s;}
}
void dfs1(int v,int res)
{
	++sum[v];
	ans[v]=res+sum[v];
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==f[v])continue;
		dfs1(u,res+sum[v]-s[u]);
	}
}
int main()
{
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	dfs(1,0);
	sort(q+2,q+1+n);
//	for(int i=2;i<=n;++i)printf("%d %d\n",q[i].id,q[i].w);
	int last=2;
	for(int i=1;i<=n;++i)
	{
		sz[i]=1;
		for(int j=head[i];j;j=bi[j].nxt)
		{
			x=bi[j].to;
			if(x!=f[i]&&x<i)up[x]=i,sz[i]+=sz[x];
		}
		if(f[i]&&f[i]<i)
		{
			up[i]=find(f[i]),sz[up[i]]+=sz[i];
			if(f[i])BIT::add(id[f[i]],sz[i]);
			if(up[i])BIT::add(id[up[i]],-sz[i]);	
		}
	//	printf("%d:\n",i);
		while(q[last].w==i)
		{
			x=q[last].id;
	//		printf("%d",x);
			for(int j=head[x];j;j=bi[j].nxt)
			{
				y=bi[j].to;
				if(y==f[x])continue;
				s[y]=sz[y]+BIT::qry(id[y]+siz[y]-1)-BIT::qry(id[y]-1);
				sum[x]+=s[y];
			}
			++last;
		}
	}
//	for(int i=1;i<=n;++i)printf("%d ",s[i]);printf("\n");
//	for(int i=1;i<=n;++i)printf("%d ",sum[i]);printf("\n");
	dfs1(1,0);
	for(int i=2;i<=n;++i)printf("%d ",ans[i]-1);
	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    each (i, a) cin >> i;
    a.push_back(0);
    a.insert(a.begin(), 0);
    
    lli sum = 0;
    for (int i = 0; i + 1 < a.size(); ++i) {
      sum += abs(a[i] - a[i + 1]);
    }

    for (int i = 1; i + 1 < a.size(); ++i) {
      lli x = sum;
      x -= abs(a[i - 1] - a[i]);
      x += abs(a[i - 1] - a[i + 1]);
      x -= abs(a[i + 1] - a[i]);
      cout << x << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1656
import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

prime100::[Int]
prime100=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]

decomp_vec::STArray s Int Int -> Int -> ST s ()
decomp_vec ar n = case n of
                  1         -> return ()
                  otherwise -> do
                                let d = head (dropWhile (\ v -> mod n v /= 0) prime100)
                                v<-readArray ar d
                                writeArray ar d (v+1)
                                decomp_vec ar (div n d)
                                return ()

gen_vec::Int -> Array Int Int
gen_vec n = runSTArray $ do
                    ar<- newArray (1,100) 0
                    forM_ [1..n] (decomp_vec ar)
                    return ar

calc_vec_2_4_4::[Int]->Int
calc_vec_2_4_4 ls = let over2 = length (filter (2<=) ls) in
                    let over4 = length (filter (4<=) ls) in
                    if (over4 < 2) || (over2 < 1)  then 0 else  (over2-2)*(div (over4*(over4-1)) 2)

calc_vec_4_14::[Int]->Int
calc_vec_4_14 ls = let over4 = length (filter (4<=) ls) in
                   let over14 = length (filter (14<=) ls) in
                   if (over4 < 1) || (over14 < 1)  then 0 else  over14*(over4-1)

calc_vec_2_24::[Int]->Int
calc_vec_2_24 ls = let over2 = length (filter (2<=) ls) in
                   let over24 = length (filter (24<=) ls) in
                   if (over2 < 1) || (over24 < 1)  then 0 else  over24*(over2-1)

calc_vec_74::[Int]->Int
calc_vec_74 ls = length (filter (74<=) ls)

solver::Int->Int
solver n = let ls =  (elems (gen_vec n))in
           (calc_vec_2_4_4 ls) + (calc_vec_4_14 ls) + (calc_vec_2_24 ls) + (calc_vec_74 ls)

main::IO()
main=(print.solver.read)=<<getLine

Measured memory_bytes: 508
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int h;
        int count=0;
        for(int i = 0; i < n; i++){
            h = scanner.nextInt();
            if(k <= h){
                count++;
            }
        }
        System.out.println(count);


    }
}

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

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

    vector<long long> H(N);
    for ( int i=0; i<N; i++ )
        cin >> H.at(i);

    vector<int> good(N, -1);
    int a, b;
    for ( int i=0; i<M; i++ ) {
        cin >> a >> b;
        a--;
        b--;
        if ( H.at(a) > H.at(b) ) {
            if ( good.at(a) != 0 )
                good.at(a) = 1;
            good.at(b) = 0;
        }
        else if ( H.at(a) < H.at(b) ) {
            if ( good.at(b) != 0 )
                good.at(b) = 1;
            good.at(a) = 0;
        }
        else {
            good.at(a) = 0;
            good.at(b) = 0;
        }
    }

    int ans = 0;
    for ( int p : good ) {
        ans += abs(p);
    }

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


Measured memory_bytes: 4576
H, W = map(int, input().split())
S    = [None] * H
for h in range(H):
    S[h] = list(input())

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        else:
            R = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if x == 0 and y == 0:
                        continue
                    elif 0 <= h + x and h + x < H and 0 <= w + y and w + y < W:
                        if S[h + x][w + y] == '#':
                            R += 1
            S[h][w] = str(R)

for s in S:
    print(''.join(s))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector <vector <pair <int, ll> > > g(n);
    for (int i = 1; i < n; ++ i) {
        int u, v; ll w; cin >> u >> v >> w;
        -- u, -- v;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    int q, k; cin >> q >> k; -- k;
    vector <ll> dis(n, -1); dis[k] = 0;
    queue <int> que; que.push(k);
    while (!que.empty()) {
        int u = que.front(); que.pop();
        for (int i = 0; i < g[u].size(); ++ i) {
            int v = g[u][i].first; ll w = g[u][i].second;
            if (!~dis[v]) {
                dis[v] = dis[u] + w;
                que.push(v);
            }
        }
    }
    while (q --) {
        int u, v; cin >> u >> v;
        -- u, -- v;
        cout << dis[u] + dis[v] << endl;
    }
    return 0;
}


Measured memory_bytes: 9984
#include <stdio.h>

int main(void)
{
	int n, m;	/* n:??????????????°, m:?????§????????? */
	int max = 0;
	int price[1000];
	int i = 0, j;

	while (1) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)
			break;
		else {
			for (i = 0; i < n; i++) {
				scanf("%d", &price[i]);
			}
			/* printf("n = %d, m = %d\n", n, m);
			for (i = 0; i < n; i++)
				printf("price[%d] = %d\n", i, price[i]);
			*/

			for (i = 0; i < n - 1; i++) {
				for (j = i + 1; j < n; j++) {
					if (max < (price[i] + price[j]) && m >= (price[i] + price[j])) {
						max = (price[i] + price[j]);
					}
					/*printf("i = %d, j = %d, max = %d, price+ = %d\n", i, j, max, price[i] + price[j]);*/
				}
			}
			if (max == 0)
				printf("NONE\n");
			else
				printf("%d\n", max);
		}
		max = 0;

	}

	return 0;
}

Measured memory_bytes: 616
N = int(input())
d = list(map(int, input().split()))
""" 
d = [9, 1, 4, 4, 6, 7]
#N = 8
N = 6
#d = [9, 1, 14, 5, 5, 4, 4, 14]
d = [9, 1, 4, 4, 6, 7]
 """
# prob
# [number,value]
prob = []
cnt = 0
for i in d:
    prob.append([cnt, i])
    cnt += 1

""" print(prob)
print(sorted(prob, key=lambda x: x[1]))
 """
sorted_d = sorted(prob, key=lambda x: x[1])

#print(d_min, d_max)
cnt = 0
# if len(sorted_d[0:i]) == len(sorted_d[i:]):
cnt += sorted_d[int(N/2)][1] - sorted_d[int(N/2-1)][1]

print(cnt)


Measured memory_bytes: 23164
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

char trump;
vector<string> card[4];
int rank['Z'];

void solve() {
    int ew=0,ns=0;
    rep(i,4) card[i].clear();
    rep(i,4) card[i].resize(13);
    rep(i,4) rep(j,13) cin>>card[i][j];
    int parent=0;

    rep(i,13) {
        int win=0,maxi=0;
        bool f=false;
        char led=card[parent][i][1];
        rep(j,4) {
            int r=rank[card[j][i][0]];
            char s=card[j][i][1];
            if(f) {
                if(s==trump && maxi<r) {
                    maxi=r;
                    win=j;
                }
            }
            else {
                if(s==trump) {
                    f=true;
                    maxi=r;
                    win=j;
                }
                else if(s==led && maxi<r) {
                    maxi=r;
                    win=j;
                }
            }
        }
        parent=win;
        if(win%2==0) ns++;
        else ew++;
    }
    if(ns<ew) {
        cout<<"EW "<<ew-6<<endl;
    }
    else {
        cout<<"NS "<<ns-6<<endl;
    }


}

int main() {
    rep(i,10) rank[i+'0']=i;
    rank['T']=10;
    rank['J']=11;
    rank['Q']=12;
    rank['K']=13;
    rank['A']=14;
    while(cin>>trump) {
        if(trump == '#') break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1192
def main():
    N, M, V, P = map(int, input().split())
    A = list(map(int, input().split()))
    sorted_A = sorted(A, reverse=True)

    def is_possible(i):
        # Aは降順 -> sorted_A、
        # i+1番目以降の問題のスコアをi番目の問題のスコア以下になるように投票すれば
        # i番目の問題に採用される可能性が生まれるという考え方

        # 投票前の上位P問は採用される可能性がある
        if i < P:
            return True

        # 残り投票数
        num_votes = V * M

        # i番目の問題を採用させようとする場合は、M人のジャッジ全員がi番目の問題に投票すればよい
        score_i = sorted_A[i] + M
        num_votes -= M

        # M人のジャッジ全員がi番目の問題に投票しても、上位P問にスコアが上がらない場合は採用される可能性がない
        if sorted_A[P - 1] > score_i:
            return False

        # 上の操作からi+1番目以降のの問題のスコアを、i番目の問題のスコアを超えることがないため、
        # M人のジャッジ全員がi+1番目以降の問題に投票してもよい
        num_votes -= (N - i - 1) * M

        # i番目の問題が上位P問に入ればよいので、P-1位の問題にもM人のジャッジ全員が投票してもよい
        num_votes -= (P - 1) * M

        # P番目からi番目
        # print('margin: {}, num_votes: {}'.format(sum(score_i - j for j in sorted_A[P-1 : i]), num_votes))
        return sum(score_i - j for j in sorted_A[P-1 : i]) >= num_votes

    # 1番目は必ず採用される
    # N番目は採用されるか
    if is_possible(N-1):
        print(N)

    # 1番目:採用、N番目:採用されない
    # -> [1:N-1]のどこに採用の境界があるかを二分探索する
    else:
        low = 0
        hight = N - 1

        while hight - low > 1:
            middle = (hight + low) // 2
            # print('PRE - low:{}, middle:{}, hight:{}'.format(low, middle, hight))
            if is_possible(middle):
                low = middle
            else:
                hight = middle
            # print('AFT - low:{}, middle:{}, hight:{}'.format(low, middle, hight))

        print(low + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14964
#include <iostream>
using namespace std;
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main(void){
    // Your code here!
    int array[110];
    int n;int A;int B;int i=0;
	cin>>n;
	cin>>A;
	cin>>B;
	int a=0;int b=0;int c=0;
	rep(i,n){
		cin>>array[i];
		if(array[i]<=A){
		    a++;
		}
		else if(array[i]>B){
		    c++;
		}
		else{
		    b++;
		}
	}

	cout<<min(a,min(b,c))<<endl;
    
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
  
#define SENTINEL (1000000001)
#define putChar(c) ; *p = (char)(c); ++p;
  
int c = 0;
int S[500000];
int L[250001];
int R[250001];
char str[5500010];
char *p = str;
  
int getNum(void) {
    int n = 0;
    while ((*p >= '0') && (*p <= '9')) {
        n = n * 10 + (int)(*p - '0');
        ++p;
    }
    ++p;
    return n;
}
  
void putNum(int n) {
    int d;
    if (n < 10) {
        putChar( '0' + n );
        return;
    }
    d = n / 10;
    if (d) putNum(d);
    putChar( '0' + (n % 10) );
}
  
void Merge(int A[], int left, int mid, int right) {
    int i = 0, j = 0, k = left;
    int n1 = mid - left;
    int n2 = right - mid;
    memcpy(L, A + left, n1 * sizeof(int));
    memcpy(R, A + mid, n2 * sizeof(int));
    L[n1] = R[n2] = SENTINEL;
    for (; k < right; ++k) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            ++i;
        } else {
            A[k] = R[j];
            ++j;
        }
    }
}
  
void MergeSort(int A[], int left, int right) {
    int mid;
    if (left + 1 < right) {
        mid = (left + right) >> 1;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
        c += right - left;
    }
}
  
int main(void) {
    register int i;
    int n;
      
    fread(str, 1, 5500000, stdin);
    n = getNum();
    for (i = 0; i < n; ++i) {
        S[i] = getNum();
    }
      
    MergeSort(S, 0, n);
      
    --n;
    p = str;
    for (i = 0; i < n; ++i) {
        putNum(S[i]);
        putChar( ' ' );
    }
    putNum(S[i]);
    putChar( '\n' );
      
    putNum(c);
    putChar( '\0' );
      
    puts(str);
  
    return 0;
}

Measured memory_bytes: 10284
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int X; cin >> X;
    int hour;
    while(1){
        if ((1+hour)*hour/2>=X) break;
        else hour++;
    }
    cout << hour << endl;
}

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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  map<int, int> data;
  int key;
  int value;
  /*
  *一桁が指定されて、あたえられるデータが0件の場合。0を出力して終了する。
  */
  if(n == 1 && m == 0){
    cout << 0 << endl;
    return 0;
  }
  /*
  *指定された回数だけデータを入力する
  *同じ桁に2種類の数を指定しようとしたら、-1を出力して終了する。(同じ桁でも、同じ数字の指定なら許す)
  */
 for (int i = 0; i < m; i++)
 {
   cin >> key >> value;
   if (data.find(key) != data.end() && data.find(key)->second != value)
   {
     cout << -1 << endl;
     return 0;
   }
   data[key] = value;
  }
  /*
  *1桁目に0が指定されているとき、総桁数が1桁なら0を出力し、それ以外の桁数なら-1を出力する。出力後は終了する。
  */
  if(data.find(1) != data.end() && data.find(1)->second == 0){
    if(n == 1){
      cout << 0 << endl;
    }else{
      cout << -1 << endl;
    }
    return 0;
  }
  /*
  *ansに指定された桁に指定された数字をいれていく。
  */
  int ans = 0;
  for(map<int, int>::iterator i = data.begin(); i != data.end(); i++){
    ans += i->second * pow(10,n - i->first);
  }
  /*
  *ansの値が指定された桁数になっていなかったら、pow(10, 指定桁 - 1)を足して桁数を合わせる。
  */
  if(ans < pow(10, n - 1)){
    ans += pow(10, n - 1);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
        queue<long long> que;
        int N;
        cin >> N;

        if(N<10){
                cout << N;
                return 0;
        }

        for(int i=1; i<=9 ; i++){
                que.push(i);
        }
        int count = 9;
        while(count != N){
                long long number = que.front();
                que.pop();
                vector<int> nexts;
                short last = number%10;
                switch(last){
                        case 0:
                                                   nexts.push_back(0);
                                nexts.push_back(1);
                                break;
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                                for(int i= last-1;i<= last+1; i++ ){
                                        nexts.push_back(i);
                                }
                                break;
                        case 9:
                                nexts.push_back(8);
                                nexts.push_back(9);
                }
                for(short next: nexts){
                        count++;
                        if(count == N){
                                cout << number*10 + next;
                                break;
                        }
                        que.push(number *10 + next);
                }
        }
}

Measured memory_bytes: 768
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int v[25], c[25];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> v[i];
	rep(i, n)cin >> c[i];
	int sum = 0;
	rep(i, n) {
		if (v[i] - c[i] >= 0)sum += v[i] - c[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 5;
ll i,n,m,a,cnta,cntb;
string b;
map<ll,ll> p[2];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,0,m){
        cin>>a>>b;
        if(b == "AC") p[0][a] = 1;
        else{
            if(p[0].find(a) == p[0].end())
                p[1][a] += 1;
        }
    }
    for(auto it: p[0]){
        cnta += 1;
        cntb += p[1][it.f];
    }
    cout<<cnta<<" "<<cntb;
    return 0;
}

Measured memory_bytes: 12800
#include<stdio.h>
#define A 100001

typedef struct{
	int p,l,r;
}Node;

Node N[A];

int dep(int i,int d){
	if(N[i].p == -1) return d;
	else return dep(N[i].p,d+1);
}

int sib(int i){
	if(N[i].p == -1) return -1;
	if(N[N[i].p].r == i) return N[N[i].p].l;
	if(N[N[i].p].l == i) return N[N[i].p].r;
	return -1;
}

int deg(int i){
	int x = 0;
	if(N[i].l != -1) x++;
	if(N[i].r != -1) x++;
	return x;
}

int hei(int i){
	int x = 0,y = 0;
	if(N[i].l != -1) x = hei(N[i].l)+1;
	if(N[i].r != -1) y = hei(N[i].r)+1;
	if(x > y) return x;
	else return y;
}

int main(){
	int i,n,id,ch,le,ri;

	scanf("%d",&n);
	for(i=0; i<n; i++){
		N[i].p = -1;
		N[i].l = -1;
		N[i].r = -1;
	}

	for(i=0; i<n; i++){
		scanf("%d %d %d",&id,&le,&ri);
		N[id].l = le;
		N[id].r = ri;
		N[le].p = id;
		N[ri].p = id;
	}

	for(i=0; i<n; i++){
		ch = 0;
		if(N[i].l != -1) ch++;
		if(N[i].r != -1) ch++;

		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,N[i].p,sib(i),ch,dep(i,0),hei(i));
		if(N[i].p == -1) printf("root");
		else if(N[i].l == -1 && N[i].r == -1) printf("leaf");
		else printf("internal node");
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 2112
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L,T;
ll A[300005] = {};
ll B[300005] = {};
ll C[100][3005] = {};
bool f, ff;
string S,SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;
queue<ll> ql;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;
	

	bool operator<(const ST& another) const
	{
		return first < another.first;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}


bool itta[300000];

int main() {
	
	cin >> a>>b;

	a--;
	b--;

	cout << a*b << endl;

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())
#define ll long long

using namespace std;


#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

const ll inf =1000000007;
typedef pair<ll,ll> Pair;


typedef vector<ll> vl;

void solve(){
    ll n;
    cin >>n;
    map<ll,ll> mp;
    ll ans=0;
    rep(i,n){
        ll a;
        cin >>a;
        //足し算
        if(mp.find(i-a)!=mp.end()){
            ans+=mp[i-a];
        }
        if(mp.find(i+a)!=mp.end()){
            mp[i+a]++;
        }
        else{
            mp[i+a]=1;
        }
    }
    kaku(ans);
}


int main(){
    solve();
}

Measured memory_bytes: 15976
#include<iostream>

void call(int n){
  int i = 1;
  while(++ i <= n){
    int x = i;
    if(x % 3 == 0){
      std::cout << " " << i;
      continue;
    }
    while(x){
      if(x % 10 == 3){
	std::cout << " " << i;
	break;
      }
      x /= 10;
    }
  }
  std::cout << std::endl;
}

int main(){
  int n;
  std::cin >> n;
  call(n);
  return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int h[n];
  for(i=0;i<n;i++)cin>>h[i];
  cnt=0;
  int ma=0;
  for(i=0;i<n-1;i++){
    if(h[i+1]<=h[i]){
      cnt++;
    }else cnt=0;
    ma=max(ma,cnt);
  }
  cout<<ma;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int dp[100000][3];
int main(){
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	dp[0][0]=a,dp[0][1]=b,dp[0][2]=c;
	for(int i=1;i<n;i++){
		cin>>a>>b>>c;
		dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b+max(dp[i-1][2],dp[i-1][0]);
		dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string n;cin>>n;
  ll k,l=n.length();cin>>k;
  lvector dgt(l,0); rep(i,l) dgt[i]+=n[i]-'0';
  reverse(dgt.begin(),dgt.end());
  ll dp[l+1][k+1][2]; memset(dp,0,sizeof(dp));
  dp[0][0][0]=1;
  for(ll i=1;i<=l;++i) {
    ll v=dgt[i-1];
    rep(j,k+1) dp[i][j][0]+=dp[i-1][j][0];
    if(v>0) rep(j,k+1) dp[i][j][0]+=dp[i-1][j][1];
    else    rep(j,k+1) dp[i][j][1]+=dp[i-1][j][1];
    for(ll x=1;x<10;++x) {
      if(x<v) 
        for(ll j=1;j<=k;++j) dp[i][j][0]+=dp[i-1][j-1][0]+dp[i-1][j-1][1];
      else if(x==v)
        for(ll j=1;j<=k;++j) {
          dp[i][j][0]+=dp[i-1][j-1][0];
          dp[i][j][1]+=dp[i-1][j-1][1];
        }
      else 
        for(ll j=1;j<=k;++j) dp[i][j][1]+=dp[i-1][j-1][0]+dp[i-1][j-1][1];
    }
  }
  print(dp[l][k][0]);
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var empty = byte('.')

func main() {
	sc := NewScanner(os.Stdin)
	h, w := sc.Int(), sc.Int()

	var grid [1001][1001]bool
	for i := 0; i < h; i++ {
		line := sc.Bytes()
		for j := 0; j < w; j++ {
			grid[i][j] = line[j] == empty
		}
	}

	var dp [1001][1001]int
	dp[0][0] = 1

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if i+1 < h && grid[i+1][j] {
				dp[i+1][j] = (dp[i][j] + dp[i+1][j]) % Mod
			}
			if j+1 < w && grid[i][j+1] {
				dp[i][j+1] = (dp[i][j] + dp[i][j+1]) % Mod
			}
		}
	}

	fmt.Println(dp[h-1][w-1])
}

// generated by https://github.com/murosan/gollect

const Mod = 1000000007

func BytesToInt(b []byte) (n int) {
	var i int
	negative := b[0] == 45
	if negative {
		i++
	}
	for ; i < len(b); i++ {
		n = n*10 + int(b[i]-'0')
	}
	if negative {
		return -n
	}
	return
}

type Scanner struct{ *bufio.Scanner }

func NewScanner(r io.Reader) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &Scanner{Scanner: s}
}

func (s *Scanner) Bytes() []byte { s.Scan(); return s.Scanner.Bytes() }

func (s *Scanner) Int() int { return BytesToInt(s.Bytes()) }


Measured memory_bytes: 11392
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return input().split()
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size

#solve
def solve():
    n = II()
    s = S()
    q = II()
    ans = [BinaryIndexedTree(n + 1) for i in range(27)]
    lis = [ord(si) - ord("a") for si in s]
    for i in range(n):
        ans[lis[i]].add(i+1, 1)
    for _ in range(q):
        t, i, c = LS()
        i = int(i)
        if t == "1":
            ans[lis[i-1]].add(i, -1)
            ans[ord(c) - ord("a")].add(i, 1)
            lis[i-1] = ord(c) - ord("a")
        else:
            l = i - 1
            r = int(c)
            res = 0
            for i in range(27):
                res += ans[i].sum(r) - ans[i].sum(l) > 0
            print(res)
    


    return


#main
if __name__ == '__main__':
    solve()


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll a,b,c;cin>>a>>b>>c;
	if(a<c&&b<c){
		ll n=(c-a-b)*(c-a-b),m=4*a*b;
		if(m<n)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <chrono>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <cctype>
# include <unordered_map>
# include <unordered_set>
//#include <bits/stdc++.h>
 
#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
 
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forx(i,x,n) for (int i = x; i < (n); i++)
#define form(i, n) for (int i = n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned ll
#define srt(a) sort(a.begin(), a.end());
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define ar array
#define endl '\n';
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }
 
const ll MAXN = 2e5 + 7, K = 200043, M = 1000043, INF = 1e18 + 7;
// the good way to get PI number
const ld PI = acos(-1.0);
ll MOD = 1e9 + 7;

template <class T> T sqr(T a) {
    return a * a;
}

ll mul(ll a, ll b) {
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll sum(ll a, ll b) {
    return ((a % MOD) + (b % MOD)) % MOD;
}

ll sub(ll a, ll b) {
    return sum(a, MOD - b);
}

ll bin_pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}

ll inv(ll x) {
    return bin_pow(x, MOD - 2) % MOD;
}

ll fact[MAXN];

ll C(ll n, ll k) {
    return mul(mul(fact[n], inv(fact[k])), inv(fact[n - k]));
}

void solve() {
    int n;
    cin >> n;
    
    vi a(n), even, odd;
    set <int> s;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if ((i % 2) == 0) {
            even.pb(a[i]);
            s.insert(a[i]);
        }
    }
    
    sort(a.begin(), a.end());
    
    for (int i = 0; i < even.size(); ++i) {
        if (s.count(a[2*i]))
            s.erase(a[2*i]);
    }
    
    cout << s.size() << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t = 1;
//    cin >> t;
    
    while (t --> 0)
        solve();
    return 0;
}


Measured memory_bytes: 6256
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
ll po(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1) res = res * a;
        a = a * a;
        b >>= 1LL;
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    ll st = x;
    ll j = 0;
    while(st * po(2, j) <= y){
        j++;
    }
    cout << j;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main() {
  char c;
  cin>>c;

  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
    cout<<"vowel"<<endl;
  }else{
    cout<<"consonant"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int main ()
{
	ll a,b,h,n;
	scanf("%lld%lld",&h,&n);
    vector<pair<ll,ll>> A;
    for(int i = 0; i < n; ++ i) {
        scanf("%lld%lld",&a,&b);
        A.pb(mp(a,b));
    }
    sort(all(A));
    vl ans(h+1, 1e12);
    for(int i = 0; i <= h; ++ i) {
        if (i == 0) { ans[i] = 0; continue; }
        ll m = 1e12;
        for(int j = 0; j < n; ++j) {
            ll x = A[j].first;
            if (i-x >= 0) {
                m = min(m, ans[i-x] + A[j].second);
            } else if (i < x){
                m = min(m, A[j].second);
            }
        }
        ans[i] = min(m, ans[i]);
    }
    cout << ans[h] << endl;
	return 0;
}

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

int main() {
  int n,q,j,k;
  cin >> n >> q;
  vector<pair<int, int>> a(n-1);
  for(int i=0;i<n-1;i++){
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(),a.end());
  int res[n+1];
  for(int i=0;i<n+1;i++)res[i]=0;
  for(int i=0;i<q;i++){
    cin >> j >> k;
    res[j]+=k;
  }
  for(int i=0;i<n-1;i++){
    res[a[i].second]+=res[a[i].first];
  }
  for(int i=1;i<n;i++)cout << res[i] << ' ';
  cout << res[n] << endl;
}


Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include <vector>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vi a(n), c(n - 1);
	int sum = 0;
	rep(i, n) cin >> a[i];
	rep(i, n) {
		int k;
		cin >> k;
		sum += k;
	}
	rep(i, n - 1) cin >> c[i];
	rep(i, n - 1) {
		if (a[i + 1] == a[i] + 1) sum += c[a[i] - 1];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char o[60];
	char e[60];

	scanf("%s %s", o, e);

	char answer[120];
	for (int i = 0; i < 60; i++) {
		if (o[i] == '\0') {
			answer[i * 2] = '\0';
			break;
		}
		answer[i * 2] = o[i];
	}
	for (int i = 0; i < 60; i++) {
		if (e[i] == '\0') {
			answer[i * 2 + 1] = '\0';
			break;
		}
		answer[i * 2 + 1] = e[i];
	}
	printf("%s", answer);
}

Measured memory_bytes: 128
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

   int x; cin>>x;

   for(ll a = -1000; a <= 1000; a++){
       for(ll b = -1000; b <= 1000; b++){
           if(pow(a, 5ll) - pow(b, 5ll) == x){
               cout<<a<<" "<<b<<"\n";
               return 0;
           }
       }
   }

    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 4024
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll, ll K, string S) {
  S[K-1] -= 'A' - 'a';
  cout << S << endl;
}

int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  string S;
  cin >> S;
  solve(N, K, S);
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import heapq

WHITE = 0
GRAY = 1
BLACK = 2

INF = 2000000000


def dijkstra():
    PQ = []
    heapq.heapify(PQ)
    color = [WHITE] * n
    d = [INF] * n
    
    d[0] = 0
    heapq.heappush(PQ, (0, 0))
    color[0] = GRAY
    
    while len(PQ) != 0:
        
        f = heapq.heappop(PQ)
        u = f[1]
        color[u] = BLACK
        
        if d[u] < f[0]:
            continue
        
        for j in range(len(adj[u])):
            v = adj[u][j][0]
            if color[v] == BLACK:
                continue
            if d[v] > d[u] + adj[u][j][1]:
                d[v] = d[u] + adj[u][j][1]
                heapq.heappush(PQ, (d[v], v))
                color[v] = GRAY
    for i in range(n):
        print(i, d[i])


n = int(input())

adj = [[] for j in range(n)]
for i in range(n):
    nums=list(map(int,input().split()))
    for j in range(nums[1]):
        adj[nums[0]].append((nums[2*j+2], nums[2*j+3]))
        

dijkstra()
        
        
        
        
        
        
        
        
        
        
        
        


Measured memory_bytes: 68988
#include<stdio.h>
int main(){
	int n,m,i,t;
	scanf("%d",&n);
	t=0,i=n;
	while(n>0){
		m=n%10;
		t+=m;
		n/=10;
	}
	if(i%t==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int count = 0;
    sort(arr, arr + n);
    for (int i = 0; i < n - 2; i++){
        for (int j = i + 1; j < n - 1; j++){
            if(arr[i] != arr[j]){
                for(int k = j +1; k < n; k++){
                    if(arr[k]!=arr[j]){
                        if(arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[j] + arr[k] > arr[i] )
                            count++;
                    }
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std ;

const int N = 200010 ;

int n ;
int res ;
int ans ;
int t[N] ;
int s[N] ;
int _odd[N] ;
int _eve[N] ;
int base[N] ;

bool compo(int x, int y){
    return _odd[x] > _odd[y] ;
}
bool compe(int x, int y){
    return _eve[x] > _eve[y] ;
}
int main(){
    cin >> n ; res = n ;
    for (int i = 1 ; i <= n ; ++ i){
        cin >> base[i] ;
        if (i & 1) _odd[base[i]] ++ ;
        else _eve[base[i]] ++ ;
    }
    for (int i = 1 ; i < N ; ++ i) s[i] = t[i] = i ;
    sort(s + 1, s + N, compo) ;
    sort(t + 1, t + N, compe) ;
    ans = n / 2 - _odd[s[1]] ;
    for (int i = 1 ; i < N ; ++ i)
        if (t[i] != s[1]){ ans += n / 2 - _eve[t[i]] ; break ; }
    res = min(res, ans) ;
    ans = n / 2 - _eve[t[1]] ;
    for (int i = 1 ; i < N ; ++ i)
        if (s[i] != t[1]){ ans += n / 2 - _odd[s[i]] ; break ; }
    res = min(res, ans) ;
    cout << res << endl ; return 0 ;
}


Measured memory_bytes: 2944
#include<stdio.h>
#include<string.h>
int main(){
    int n,i,j,p[100],t,x[100][100];
    char s[100][100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %d",&s[i],&p[i]);
        x[i][0] = 0;
        x[i][1] = i+1;
    }
    for(i=0;i<n;i++){
        for(j=i;j<n;j++){
            t=strcmp(s[i],s[j]);
            if(t>0 || (t==0 && p[i]<p[j])) x[i][0]++;
            else x[j][0]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i+1==x[j][0]) printf("%d\n",x[j][1]);
        }
    }
    return 0;
}


Measured memory_bytes: 256