akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left, k);
  }
  else{
    return treeSearch(u->right, k);
  }

}

Node treeSuccessor(Node x){
  Node y;

  if(x->right != NIL){
    return (Node)treeMinimum(x->right);
  }

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL){
    y = z;
  }
  else{
    y = (Node)treeSuccessor(z);
  }
  
  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }
  
  if(x != NIL){
    x->parent = y->parent;
  }
  
  if(y->parent == NIL){
    root = x;
  }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else{
    y->parent->right = x;
  }
  
  if(y != z){
    z->key = y->key;
  } 
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }

}

void inorder(Node u){
  
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d", u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
  
}
void preorder(Node u){
  
  printf(" %d", u->key);
  if(u->left != NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int main()
{
  int n, d, x;
  cin >> n >> d >> x;

  int choco = 0;

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

    for(int j = 0; ; j++){
      if(a*j + 1 > d) break;
      choco++;

    }
  }

  cout << choco + x << endl;

  return 0;

}


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

typedef long long ll;

vector<int> pre,in,post;
int n,pos;

int findx(int root){
    for(int i=0;i<n;i++){
        if(in[i]==root)return i;
    }
    return n;
}


void solve(int l,int r){
    if(l>=r)return;
    int root=pre[pos++];
    int m=findx(root);
    solve(l,m);
    solve(m+1,r);
    post.push_back(root);
}

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

    cin >> n;
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        pre.push_back(k);
    }
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        in.push_back(k);
    }
    solve(0,pre.size());
    for(int i=0;i<n;i++){
        if(i)cout << " ";
        cout << post[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3172
#include<iostream>
using namespace std;
int main(void)
{
	int N,K;
		cin >> N >> K;
	long r=0,n=K;
	while(n<=N){
		r++;
		n+=K;
	}
	if(!(K%2)){
		n=K/2;
		long s=0;
		while(n<=N){
			s++;
			n+=K;
		}
		cout << r*r*r+s*s*s << endl;
	}
	else
		cout << r*r*r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    long long n, div3, div5, divL;

    cin >> n;

    div3 = n/3;
    div5 = n/5;
    divL = n/15;

    div3 = 3*(div3*(div3+1))/2;
    div5 = 5*(div5*(div5+1))/2;
    divL = 15*(divL*(divL+1))/2;

    cout << ((n*(n+1))/2) - div3 - div5 + divL;

    return 0;
}


Measured memory_bytes: 3596
//Problem link - https://atcoder.jp/contests/dp/tasks/dp_c

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define mod 1000000007

int main()
{
	fast;
	ll n;
	cin>>n;
	ll arr[n][3];
	for(ll i=0;i<n;i++)
		for(ll j=0;j<3;j++)
			cin>>arr[i][j];
	ll dp[n][3];
	for(ll j=0;j<3;j++)
		dp[n-1][j]=arr[n-1][j];
	for(ll i=n-2;i>=0;i--)
	{
		dp[i][0]=arr[i][0]+max(dp[i+1][1],dp[i+1][2]);
		dp[i][1]=arr[i][1]+max(dp[i+1][0],dp[i+1][2]);
		dp[i][2]=arr[i][2]+max(dp[i+1][0],dp[i+1][1]);
	}
	cout<<max({dp[0][0],dp[0][1],dp[0][2]});
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int A;
int B;
int main(){
  rd(N);
  if(N==1){
    wt_L("Hello World");
    wt_L('\n');
  }
  else{
    rd(A);
    rd(B);
    wt_L(A+B);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190714-1

// --- original code ---
// int N, A, B;
// {
//   rd(N);
//   if(N==1){
//     wt("Hello World");
//   } else {
//     rd(A,B);
//     wt(A+B);
//   }
// }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>

typedef long long int llint;

int main(void){

  llint a, b, c, k;

  std::cin >> a >> b >> c >> k;

  llint score = std::min(a,k);
  k-=a;
  
  if(k>0){
    k-=b;
  }

  if(k>0){
    score -= k;
  }

  std::cout << score << std::endl;
 
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
vector<long long int> factors(long long int n) 
{
    vector<long long int> f;
    for (long long int x = 2; x*x <= n; x++) 
    {
        if (n%x == 0) 
        {

            f.push_back(x);
            while(n%x==0)
            {

                n /= x;
            }
        }
    }
    if (n > 1) 
        f.push_back(n);
    return f;
}
int main()
{
    ll a,b;
    cin >> a >> b;
    vector<ll> aprime;
    vector<ll> bprime;
    ll anum=a;
    ll bnum=b;
    vector<ll>facta=factors(a);
    vector<ll>factb=factors(b);
    sort(facta.begin(),facta.end());
    sort(factb.begin(),factb.end());


   /* for(ll i=0;i<facta.size();i++)
    {
        cout << facta[i]<<" ";
    }
    cout << "\n";
    for(ll i=0;i<factb.size();i++)
    {
        cout << factb[i];
    }*/
    ll count=0;
    for(ll i=0;i<facta.size();i++)
    {
        for(ll j=0;j<factb.size();j++)
        {
            if(facta[i]==factb[j])
            {
                count++;
            }
        }
    }
    cout << count+1;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define i64 long long
using namespace std;
vector<int>adj[52];
int main() {
	// your code goes here
	int n,m,u,v;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i=1;i<=n;i++) printf("%d\n",adj[i].size());
	return 0;
}

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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<string, pair<unsigned long, unsigned long>>> rest(N);
    for(unsigned long i = 0; i < N; ++i){
        cin >> rest[i].first >> rest[i].second.first;
        rest[i].second.first ^= ~0;
        rest[i].second.second = i + 1;
    }
    sort(rest.begin(), rest.end());
    for(const auto& i : rest)cout << i.second.second << endl;
    return 0;
}

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

int main()
{
    int A, B;
    cin >> A >> B;
    vector<int> nums{1,2,3};
    nums.erase(remove(nums.begin(), nums.end(), A), nums.end());
    nums.erase(remove(nums.begin(), nums.end(), B), nums.end());
    int ans = nums.at(0);
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    K = Scanner.int()
    A, B = Scanner.map_int()
    for i in range(A, B + 1):
        if i % K == 0:
            print('OK')
            return
    print('NG')


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10728
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n){return mpow(n,mod-2);}

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
    int W,H,N;
    cin>>W>>H>>N;
    int d[100][100];
    rep(i,W) rep(j,H) d[i][j]=1;
    rep(i,N){
    	int x,y,a;
    	cin>>x>>y>>a;
    	if(a==1&&x>0) rep(i,x) rep(j,H) d[i][j]=0;
    	if(a==2&&x<W) rep(i,x,W) rep(j,H) d[i][j]=0;
    	if(a==3&&y>0) rep(i,W) rep(j,y) d[i][j]=0;
    	if(a==4&&y<H) rep(i,W) rep(j,y,H) d[i][j]=0;
    }
    int ans=0;
    rep(i,W){ 
    	rep(j,H) ans+=d[i][j];
    	//cout<<endl;
    }
    cout<<ans<<endl;
}

int mpow(int a,int x){
	int ans=1;
	while(x>0){
		if(x%2==1) (ans*=a)%=mod;
		(a*=a)%=mod;
		x>>=1;
	}
	return ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    ll N,K,X,Y;
    cin>>N>>K>>X>>Y;
    
    if(N<=K)cout<<N*X<<endl;
    else cout<<K*X+(N-K)*Y<<endl;
    
    return 0;
}



Measured memory_bytes: 256
/*{{{*/
#include <numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int a[SIZE];
void solve(){
    int N; R(N);
    REP(i,1<<N)R(a[i]);
    sort(a,a+(1<<N),greater<int>());
    if(a[0]==a[1]){
        W("No");
        return;
    }
    int cnt[19]={};
    cnt[1]=1;
    for(int i=1,j;i<(1<<N);i=j){
        for(j=i+1;j<(1<<N)&&a[i]==a[j];j++);
        int num=j-i;
        int tmp[19]={};
        FOR(k,1,N){
            if(!num)break;
            int v=min(cnt[k],num);
            cnt[k]-=v;
            num-=v;
            if(k<N){
                cnt[k+1]+=v;
                tmp[k+1]=v;
            }
        }
        if(num){
            W("No");
            return;
        }
        FOR(k,1,N)cnt[k]+=tmp[k];
    }
    W("Yes");
}
int main(){
    solve();

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
             
            using namespace std;
             
            int main(){
              int n;
              cin >> n;
              int count = 0;
              int ecount = 0;
              vector<int> h(n);
              for(int i = 0;i < n;i++){
                cin >> h[i];
              }
              //int temp = h[0];
              for(int j = 1;j < n-1;j++){
                if(h[j] > h[j-1]){
                  h[j]--;
                }
                if(h[j] > h[j+1]){
                  cout << "No" << endl;
                  return 0;
                }
              }
              cout << "Yes" << endl;
              return 0;
            }

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int i,n;
	char a[41];
	cin >> a;
	n = strlen(a);
	for(i=n-1;i>=0;i--)
	{
		cout << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3052
# https://atcoder.jp/contests/abc174/tasks/abc174_c

K = gets.to_i

K /= 7 if (K % 7).zero?

if K.even? || (K % 5).zero?
  puts(-1)
  exit 0
end

ws = 10.times.map { |i| K * i }
n = m = 1
v = 1

K.times do
  # p [n, m, v]
  w = ws.find { |a| a % 10 == v % 10 }
  while v < w
    v += 10**m
    n += 1
    m += 1
    # p [' ', n, m, v]
  end
  v -= w
  if v.zero?
    puts n
    exit 0
  end
  v /= 10
  m -= 1
end

puts(-1)


Measured memory_bytes: 14380
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll h; cin >> h;
    ll n; cin >> n;
    REP(i, n){
        ll a; cin >> a;
        h -= a;
    }
    if (h <= 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#from time import time
#t = time()
n = input()
d=[]
abc =[chr(x) for x in range(97, 123)]
for i in abc:
    if i not in  n:
        d.append(i)
if d != []:
    print(sorted(d)[0])
else:
    print('None')

#print(mn[0] * mm[1])
#tt= time()
#print(tt-t)
    
                


Measured memory_bytes: 3188
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int[] a = new int[n];
		long sum=0;
		int max=-1000000,min=1000000;

		for(int i=0; i<n; i++)
		{
			a[i] = scan.nextInt();
			sum += a[i];

			max = Math.max(max, a[i]);
			min = Math.min(min, a[i]);
		}

		System.out.printf("%d %d %d\n", min, max, sum);

		scan.close();
	}
}

Measured memory_bytes: 42188
S=input()

nagasa=len(S)

countA=0
countB=0
for i in range(nagasa):
    if i%2==0:
        if S[i]=="0":
            countA+=1
    else:    
        if S[i]=="1":
            countA+=1
    if i%2==0:
        if S[i]=="1":
            countB+=1
    else:    
        if S[i]=="0":
            countB+=1
print(min(countA,countB))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(int a,int b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(int a,int b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  string s;
  cin>>s;
  vector<char> t;
  rep(i,len(s)){
    if(s[i]!='B'){
      t.push_back(s[i]);
    }
    if(s[i]=='B'){
      if(t.size()>0){
        t.pop_back();
      }
      if(t.size()==0) continue;
    }
  }
  rep(i,t.size()){
    cout<<t[i];
  }
  cout<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

class Rect{
  public:
    int x;
    int h;
    int w;
};

int main(){
  int h,w;
  list<Rect> r;

  Rect tmp;
  //cout << r.max_size() << endl;
  rep(i,150){
    auto itr=r.begin();
    rep(j,150){
      tmp.x=pow(150-i,2)+pow(j+1,2);
      tmp.h=150-i;tmp.w=j+1;
      if(tmp.w<=tmp.h) continue;
      if(tmp.h==149) r.pb(tmp);
      else while(itr!=r.end()){
        if(itr->x>=tmp.x){
          r.insert(itr,tmp);
          break;
        }
        else itr++;
      }
      //cout << tmp.h << " " << tmp.w << endl;
    }
    //cout << j << endl;
  }

  /*auto itr=r.begin();
  rep(j,150){
    rep(i,150){
      cout << itr -> h << " " << itr -> w << endl;
      itr++;
    }
  }*/

  while(cin>>h>>w&&h+w!=0){
    auto itr=r.begin();
    while(itr->h!=h||itr->w!=w)itr++;
    itr++;
    cout << itr->h <<" " << itr->w << endl;
  }
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
using namespace std;
template<class T>il read(T &x){
	x=0;int f=1;char k=getchar();
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>9) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
int n,m;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	int ans=n*(n-1)+m*(m-1);
	print(ans>>1);
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N,X,Y = map(int,input().split())
G = [[] for i in range(N+1)] 
for i in range(1,N+1):
  if i-1 >= 1:
    G[i].append(i-1)
  if i+1 <= N:
    G[i].append(i+1)

G[X].append(Y)
G[Y].append(X)

dl = [0]*(N+1)
def bfs(p):
  seen = [False]*(N+1)
  seen[p] = True
  dist = [0]*(N+1)
  d = deque([p])
  while len(d) > 0:
    v = d.popleft()
    for i in G[v]:
      if seen[i] == False:
        seen[i] = True
        dist[i] = dist[v]+1
        dl[dist[i]] += 1
        d.append(i)      


for i in range(1,N+1):
  bfs(i)

for i in range(1,N):
  print(dl[i]//2)

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

int main() {
  int n, k, x=0, d=0;
  cin >> n >> k;
  for(int i=0; i<n; i++){
    int a, b;
    cin >> x;
    a = 2*x;
    if(x>k){
      b = 2*(x-k);
    }
    else{
      b = 2*(k-x);
    }
    if(a<b){
      d += a;
    }
    else{
      d += b;
    }
  }
  cout << d << endl;
}

Measured memory_bytes: 256
using System;

class Program {
    static void Main() {
        while (true) {
            var hands = new int[5];
            var flags = new bool[3];

            for (var i = 0; i < 5; i++) {
                var hand = int.Parse(Console.ReadLine());
                if (hand == 0)
                    return;

                hands[i] = hand;
                flags[hand - 1] = true;
            }

            if (flags[0] ^ flags[1] ^ flags[2]) {
                for (var i = 0; i < 5; i++)
                    Console.WriteLine('3');
            }
            else {
                var win = flags[0] ? (flags[1] ? 1 : 3) : 2;

                foreach (var hand in hands)
                    Console.WriteLine(hand == win ? '1' : '2');
            }
        }
    }
}

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

string y = "YES";
string n = "NO";

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

    int cnt=0;
    for( int i=0; i<s.length(); i++ ){
        if( s[i]=='o' ) cnt++;
    }
    if( cnt+15-s.length() >= 8) cout << y << endl;
    else cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int[][] grid = new int[3][3];
      for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++)
          grid[i][j] = sc.nextInt();
      }
      for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
          if(grid[i][j] + grid[i+1][j+1] != grid[i][j+1] + grid[i+1][j]) {
            System.out.println("No");
            return;
          }
        }
      }
      System.out.println("Yes");
  }
}

Measured memory_bytes: 25044
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,k;

signed main(){
	
	cin>>n>>m;
	int cnt1=ceil2(m,2),cnt2=m/2;
	if(n==1 || m==1){
		cout<<1<<endl;
	}
	else if(n%2==0){
		cout<<(cnt1+cnt2)*(n/2)<<endl;
	}
	else{
		cout<<(cnt1+cnt2)*(n/2)+cnt1<<endl;
	}
}


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

const int INF = 1 << 30;

class State
{
public:
  int v, c, f;
  State(int _v, int _c, int _f)
    :v(_v), c(_c), f(_f) {}
  bool operator < (const State& st) const
  {
    return this->f > st.f;
  }
};

int main()
{
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d) {
    if ((c|n|m|s|d) == 0)
      break;

    --s;
    --d;
    vector<vector<int> > path(n, vector<int>(n, INF));
    for (int i = 0; i < m; ++i) {
      int a, b, f;
      cin >> a >> b >> f;
      --a;
      --b;
      path[a][b] = path[b][a] = f;
    }

    priority_queue<State> que;
    que.push(State(s, c, 0));
    vector<vector<int> > dp(n, vector<int>(c+1, INF));
    while (!que.empty()) {
      const State st = que.top();
      que.pop();

      if (st.v == d) {
	cout << st.f << endl;
	break;
      }

      if (dp[st.v][st.c] < st.f)
	continue;
      dp[st.v][st.c] = st.f;

      for (int i = 0; i < n; ++i) {
	if (path[st.v][i] == INF)
	  continue;

	if (st.c > 0) {
	  if (dp[i][st.c-1] > st.f + path[st.v][i]/2) {
	    dp[i][st.c-1] = st.f + path[st.v][i]/2;
	    que.push(State(i, st.c-1, dp[i][st.c-1]));
	  }
	}

	if (dp[i][st.c] > st.f + path[st.v][i]) {
	  dp[i][st.c] = st.f + path[st.v][i];
	  que.push(State(i, st.c, dp[i][st.c]));
	}
      }
    }

  }
  return 0;
}

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

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, ans = 0;
	cin >> n;
	for(int i=1; i<=n; i++) {
		int t;
		cin >> t;
		if((i&1) && (t&1))
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3612
#pragma warning( disable : 6031)

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;
using std::vector;
using std::pair;
using std::string;
using std::map;
long long kn(long long k, int n) {
	long long res = 1;
	while (n) {
		if (n & 1) {
			res *= k;
			res %= mod;
		}
		k *= k;
		k %= mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	long long res = 0;
	auto C = new long long[K + 1]{};
	for (int i = K; i >= 1; i--) {
		long long c = kn(K / i, N);
		for (int j = 2; i * j <= K; j++) {
			c += mod - C[i * j] % mod;
			c %= mod;
		}
		C[i] = c;
		res += i * c;
		res %= mod;
	}
	printf("%lld", res);
	return 0;
}

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

int main(int argc, char *argv[]) {

	std::set<uint32_t> group1({1, 3, 5, 7, 8, 10, 12});
	std::set<uint32_t> group2({4, 6, 9, 11});
	std::set<uint32_t> group3({2});

	uint32_t x = 0;
	uint32_t y = 0;

	std::cin >> x;
	std::cin >> y;

	//  たかだか3グループなので、全て調べる
	bool in_same_group(false);
	if (x == 2 || y == 2) {
		// group 3 に2つ属することはない
		in_same_group = false;
	} else if (group2.find(x) != group2.end()
			&& group2.find(y) != group2.end()) {
		// group 2
		in_same_group = true;
	} else if (group1.find(x) != group1.end()
			&& group1.find(y) != group1.end()) {
		// group 1
		in_same_group = true;
	} 
		
	std::cout << ((in_same_group) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N;
    cin >> N;
    vector<int> A( N );
    for( auto &x : A )
    {
        cin >> x;
    }
    map<int,int> mp;
    for( auto &x : A )
    {
        mp[ x ]++;
        mp[ x + 1 ]++;
        mp[ x - 1 ]++;
    }
    int res{};
    for( auto x : mp )
    {
        res = max( res, x.second );
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  while(getline(cin,s)){
    s+=' ';
    stack<double>st;
    double p=0;
    int t=1;
    r(i,s.size()){
      if(s[i]==' '&&isdigit(s[i-1])){
        if(p!=0){
          if(!t)st.push(p),p=0;
          else st.push(t*p),p=0,t=1;
        }
      }
      else if(s[i]=='*'){
        double x1=st.top();st.pop();
        double x2=st.top();st.pop();
        st.push(x2*x1);
      }
      else if(s[i]=='+'){
        double x1=st.top();st.pop();
        double x2=st.top();st.pop();
        st.push(x2+x1);
      }
      else if(s[i]=='/'){
        double x1=st.top();st.pop();
        double x2=st.top();st.pop();
        st.push(x2/x1);
      }
      else if(s[i]=='-'){
        if(isdigit(s[i+1]))t=-1;
        else{
          double x1=st.top();st.pop();
          double x2=st.top();st.pop();
          st.push(x2-x1);
        }
      }
      else if(isdigit(s[i])){
        p*=10,p+=s[i]-'0';
      } 
    }
    printf("%.6f\n",st.top());
  }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int MOD=1e9+7ll;
int n,a,b,ans1,ans2,ans3,ans;

inline int pow(int a,int n)
{
	int res=1ll;
	while (n)
	{
		if (n&1ll) res=res*a%MOD;
		n>>=1ll;
		a=a*a%MOD;
	}
	return res;
}

inline int qpow(int a,int b)
{
    if(b==1) return a;
    int t=qpow(a,b/2);
    t=t*t%MOD;
    if(b&1ll) t=t*a%MOD;
    return t;
}

inline int C(int n,int m)
{
    if(n<m) return 0;
    if(m>n-m) m=n-m;
    int a=1,b=1;
    for(int i=0;i<m;i++)
	{
        a=(a*(n-i))%MOD;
        b=(b*(i+1))%MOD;
    }
    return a*qpow(b,MOD-2ll)%MOD;
}
inline int Lucas(int n,int m)
{
    if(m==0) return 1ll;
    return Lucas(n/MOD,m/MOD)*C(n%MOD,m%MOD)%MOD;
}

signed main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	ans1=pow(2ll,n); 
	ans2=Lucas(n,a);
	ans3=Lucas(n,b);
//	printf("%lld\n",ans1);
//	printf("%lld\n",ans2);
//	printf("%lld\n",ans3);
	ans=((ans1-ans2-ans3-1ll)%MOD+MOD)%MOD;
	printf("%lld\n",ans); 
return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[][] arr=new int[n+1][3];
		for(int i=1;i<n+1;i++)
		{
			for(int j=0;j<3;j++)
			{
				arr[i][j]=sc.nextInt();		
				
			}
		}
		System.out.println(jolve(arr,n));
		
		sc.close();
	}
	private static int  max(int x,int y,int z)
	{
		int mm=Math.max(x, y);
		int nn=Math.max(mm, z);
		return nn;
	}

	
	private static int jolve(int[][] arr,int n)
	{
		
		int[][] dp=new int[n+1][3];
		dp[1][0]=arr[1][0];
		dp[1][1]=arr[1][1];
		dp[1][2]=arr[1][2];
		for(int i=2;i<=n;i++)
		{
			dp[i][0]=arr[i][0]+Math.max(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=arr[i][1]+Math.max(dp[i-1][0],dp[i-1][2]);
			dp[i][2]=arr[i][2]+Math.max(dp[i-1][1],dp[i-1][0]);
			
		}
		
		return max(dp[n][0],dp[n][1],dp[n][2]);
		
	}

}



Measured memory_bytes: 63856
#include<stdio.h>

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

int main(void){
  int n,k; scanf("%d%d",&n,&k);
  int sunuke[n]; rep(i,0,n-1){sunuke[i] = 0;}

  rep(i,1,k){
    int d; scanf("%d",&d);
    int a[d];
    rep(j,0,d-1){
      scanf("%d",&a[j]);
      sunuke[a[j]-1] ++;
    }
  }

  int cnt = 0;
  rep(i,0,n-1){
    if(sunuke[i] == 0){
      cnt ++;
    }
  }
  printf("%d",cnt);
  return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int len[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;
    cout << len[k-1] << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=1000010,MOD=int(1e9)+7;
int N,M,K;
int fac[maxn],inv[maxn],invfac[maxn],pow3[maxn];
int C(int n,int m){
	if(n<m||m<0)
		return 0;
	return 1LL*fac[n]*invfac[n-m]%MOD*invfac[m]%MOD;
}
int main(){
	//freopen("in","r",stdin);
	pow3[0]=inv[0]=inv[1]=fac[0]=invfac[0]=1;
	for(int i=2;i<maxn;i++)
		inv[i]=1LL*(MOD-MOD/i)*inv[MOD%i]%MOD;
	for(int i=1;i<maxn;i++){
		pow3[i]=1LL*pow3[i-1]*3%MOD;
		fac[i]=1LL*fac[i-1]*i%MOD;
		invfac[i]=1LL*invfac[i-1]*inv[i]%MOD;
	}
	N=read(),M=read(),K=read();
	if(K>M)swap(M,K);
	int ans=0,cur=1;
	for(int i=0;i<=M+K;i++){
		ans=(ans+1LL*C(i+N-1,i)*pow3[M+K-i]%MOD*cur%MOD)%MOD;
		if(i<K)cur=cur*2%MOD;
		else if(i<M)cur=(1LL*cur*2-C(i,K)+MOD)%MOD;
		else cur=(1LL*cur*2-C(i,M)-C(i,K)+2*MOD)%MOD;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 16000
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int h,w;
    while(cin >> h >> w && (h != 0 || w != 0))
    {
        for(int i = 0;i < h;i++)
        {
            for(int j = 0;j < w;j++)
            {
                if(i == 0 || i == h - 1 || j == 0 || j == w - 1)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << "\n";
        }
        cout << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, K;
int h[112345];

int main() {
	cin >> N >> K;
	REP(i, N) {
		scanf("%d", h + i);
	}
	
	int ans = 0;
	REP(i, N) if (h[i] >= K) ans++;
	cout << ans << endl;
	
	return 0;
}

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

int main()
{
  int x;
  cin>>x;
  if(x>=400 && x<600)
    cout<<8<<endl;
  else if(x>=600 && x<800)
    cout<<7<<endl;
  else if(x>=800 && x<1000)
    cout<<6<<endl;
  else if(x>=1000 && x<1200)
    cout<<5<<endl;
  else if(x>=1200 && x<1400)
    cout<<4<<endl;
  else if(x>=1400 && x<1600)
    cout<<3<<endl;
  else if(x>=1600 && x<1800)
    cout<<2<<endl;
  else
    cout<<1<<endl;
}

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

bool is_prime[100000];

int main(){

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<100000;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<100000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<100000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	while(true){
		int n;
		cin>>n;

		if(n==0)
			break;

		int count=0;
		for(int i=2;i<=n/2;i++){
			if(is_prime[i]&&is_prime[n-i]){
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0; 
}


Measured memory_bytes: 3164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n;
ll d[100005];
map<ll,int> m;
ll dp[100005];
int sz[100005];// subtree size
vector<pii> ans;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;++i){
		cin>>d[i];m[d[i]]=i;sz[i]=1;
	}
	sort(d+1,d+n+1);reverse(d+1,d+n+1);
	memset(dp,0,sizeof(dp));
	for (int i=1;i<n;++i){
		int u=m[d[i]];
		ll want=d[i]+(sz[u]<<1)-n;
		if (!m.count(want)){
			cout<<-1<<endl;return 0;
		}
		int pa=m[want];
		ans.pb(mp(u,pa));
		sz[pa]+=sz[u];
		dp[pa]+=dp[u]+sz[u];
	}
	if (dp[m[d[n]]]!=d[n]){
		cout<<-1<<endl;return 0;
	}
	for (int i=0;i<n-1;++i) cout<<ans[i].F<<' '<<ans[i].S<<endl;
	return 0; 
}

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


void solve(long long N, long long X, std::vector<long long> L){
    long long sum = 0;
    long long ans = 1;
    for(long long i = 0;i < L.size();i++){
        sum += L[i];
        if (sum <= X) ans ++;
        else{
            cout << ans <<endl;
            return;
        }
    }
    cout << ans << endl;
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, X, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
const int p=998244353;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,m,mx,ans,SG[3][maxn],sum[3][maxn],buck[maxn];
vector<int>G[3][maxn];
void Add(int &x,int y)
{
	x+=y;
	if(x>=p)
		x-=p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
int fpow(int x,int y)
{
	int res=1;
	while(y)
	{
		if(y&1)
			res=mul(res,x);
		x=mul(x,x);
		y>>=1;
	}
	return res;
}
int main()
{
	read(n);
	for(int k=0;k<3;k++)
	{
		read(m);
		for(int i=1;i<=m;i++)
		{
			int x,y;
			read(x,y);
			if(x>y)swap(x,y);
			G[k][x].push_back(y);
		}
		for(int i=n;i>=1;i--)
		{
			for(auto j:G[k][i])
				buck[SG[k][j]]=true;
			for(int j=0;j<=mx+1;j++)
			{
				if(buck[j])
					continue;
				SG[k][i]=j;
				mx=max(mx,j);
				break;
			}
			Add(sum[k][SG[k][i]],fpow(10,18*i));
			for(auto j:G[k][i])
				buck[SG[k][j]]=false;
		}
	}
	for(int a=0;a<=mx;a++)
		if(sum[0][a])
			for(int b=0;b<=mx;b++)
				if(sum[1][b])
					Add(ans,mul(mul(sum[0][a],sum[1][b]),sum[2][a^b]));
	printf("%d\n",ans);
    return 0;
}


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

int main() {
  
  int N; cin >> N; int64_t sum = 0;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i];
  
  for (int i = 0; i < N - 1; i++) {
    
    if (vec[i + 1] < vec[i]) {
      
      sum += vec[i] - vec[i + 1];
      
      vec[i + 1] = vec[i];
      
    }
    
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 4048
#include <stdio.h>

int main()
{
  int i, n, rank;
  int card[4][14];
  char id;

  for( i = 0 ; i <= 3 ; i++ )
  {
    for( rank = 0 ; rank <= 13 ; rank++ )
      card[i][rank] = 0;
  }
  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ )
  {
    scanf("%c", &id);
    scanf("%c %d", &id, &rank);
    if( id == 'S' )
      card[0][rank] = 1;
    else if( id == 'H' )
      card[1][rank] = 1;
    else if( id == 'C' )
      card[2][rank] = 1;
    else if( id == 'D' )
      card[3][rank] = 1;
  }

  for( i = 0 ; i <= 3 ; i++ )
  {
    for( rank = 1 ; rank <= 13 ; rank++ )
    {
      if( card[i][rank] != 1 )
      {
        if(i == 0)
          printf("S %d\n", rank);
        else if(i == 1)
          printf("H %d\n", rank);
        else if(i == 2)
          printf("C %d\n", rank);
        else
          printf("D %d\n", rank);
      }
    }
  }
}



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

main(){
  int n;
  int M[15][15];
  while( cin >> n && n ) {
    for ( int i = 0; i < n; i++ )
      for ( int j = 0; j < n; j++ ) M[i][j] = 0;
    int cnt = 0;
    int pi = n/2+1, pj = n/2;
    M[pi][pj] = ++cnt;
    pi++; pj++;
    while(cnt < n*n){
      if ( pj >= n ){
	pj = 0;
      } else if ( pj < 0 ){
	pj = n-1;
      } else if ( pi >= n ){
	pi = 0;
      } else if ( M[pi][pj] ){
	pi++; pj--;
      } else {
	M[pi++][pj++] = ++cnt;
      }
    }
    for ( int i = 0; i < n; i++ ){
      for ( int j = 0; j < n; j++ ){
	printf("%4d", M[i][j]);
      }
      cout << endl;
    }
  }
}

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

#define FOR(i, a, b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define YYS(x, arr) for(auto& x: arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9 + 7;

template<class T> T &chmin(T &a, const T &b){return a = min(a, b);}
template<class T> T &chmax(T &a, const T &b){return a = max(a, b);}
template<class T> void UNIQUE(vector<T> &a){a.erase(unique(a.begin(), a.end()), a.end());}

template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")" << endl; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[10000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

vector<int> G[200010];
vector<int> H[200010];

int distG[200010];
int distH[200010];
int par[200010][20];

void dfs1(int x, int p = -1, int d = 0){
  distG[x] = d;
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    dfs1(w, x, d+1);
  }
}

void dfs2(int x, int p = -1, int d = 0){
  distH[x] = d;
  par[x][0] = p;
  YYS(w, H[x]){
    if(w == p){
      continue;
    }
    dfs2(w, x, d+1);
  }
}

int lca(int a, int b){
  if(distH[a] > distH[b]){
    swap(a, b);
  }
  for(int i = 19; i >= 0; i--){
    if((distH[b] - distH[a]) & PW(i)){
      b = par[b][i];
    }
  }
  if(a == b){
    return a;
  }
  for(int i = 19; i >= 0; i--){
    if(par[a][i] != par[b][i]){
      a = par[a][i];
      b = par[b][i];
    }
  }
  assert(a != b);
  assert(par[a][0] == par[b][0]);
  return par[a][0];
}

int dist(int a, int b){
  return distH[a] + distH[b] - 2 * distH[lca(a, b)];
}

int ans;

void dfs3(int x, int p = -1){
  chmax(ans, 2 * distH[x]);
  if(distG[x] < distH[x]){
    YYS(w, G[x]){
      if(w == p){
        continue;
      }
      if(dist(x, w) >= 3){
        ans = INF;
      }
      if(distG[w] <= distH[w]){
        dfs3(w, x);
      }
    }
  }
}

int main(){

  int n = in();
  int x = in() - 1;
  int y = in() - 1;
  REP(i, n-1){
    int a = in() - 1;
    int b = in() - 1;
    G[a].pb(b);
    G[b].pb(a);
  }
  REP(i, n-1){
    int a = in() - 1;
    int b = in() - 1;
    H[a].pb(b);
    H[b].pb(a);
  }

  dfs1(x);
  dfs2(y);

  FOR(i, 1, 20){
    REP(j, n){
      if(par[j][i-1] == -1){
        par[j][i] = -1;
      } else {
        par[j][i] = par[par[j][i-1]][i-1];
      }
    }
  }

  dfs3(x);

  if(ans == INF){
    ans = -1;
  }
  
  cout << ans << endl;
  
  return 0;
}




Measured memory_bytes: 49280
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int D, N;
	cin >> D >> N;
	if (N == 100) N = 101;
	while (D--) N *= 100;
	cout << N << endl;
}

Measured memory_bytes: 256