akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

    vector<long long> a(N), b(N);
    for (auto &x: a) cin >> x;
    for (auto &x: b)cin >> x;

    long long cnt = 0;
    for (int i = 0; i < N; i++) if (b[i] < a[i]) cnt += a[i] - b[i], b[i] = a[i];

    for (int i = 0; i < N; i++) if (a[i] < b[i]) cnt -= (b[i] - a[i]) / 2;

    if (cnt <= 0)cout << "Yes" << endl;
    else cout << "No" << endl;

}

































Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110000];
pair<int,int>q[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	std::sort(p,p+a);
	for(int i=0;i<b;i++){
		int x,y;scanf("%d%d",&x,&y);
		q[i]=make_pair(-y,x);
	}
	std::sort(q,q+b);
	int at=0;
	for(int i=0;i<b;i++){
		while(q[i].second&&at<a&&p[at]<-q[i].first){
			p[at]=-q[i].first;
			at++;
			q[i].second--;
		}
		if(at==a)break;
	}
	long long ret=0;
	for(int i=0;i<a;i++)ret+=p[i];
	printf("%lld\n",ret);
}


Measured memory_bytes: 1280
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
} 
int  days(int month, int year)
{
	if( month == 2)
	{
		if((year%400==0) || (year%4==0 && year%100!=0))	
			return 29;
		else	
			return 28;
	}
	else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8
	||month == 10 || month==12)	
		return 31;
	else 		
		return 30;
} 
int dayofweek(int d, int m, int y)  
{  
    static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };  
    y -= m < 3;  
    return ( y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;  
}  
int main()
{
	FAST
	int n,k;
	cin>>n>>k;
	vector<ld> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
	{
		a[i]=((a[i]+1)/2);
	}
//	for(int i=0;i<n;i++) cout<<a[i]<<" ";
//	cout<<endl;
	ld sum=0;
	for(int i=0;i<k;i++)
	{
		sum+=a[i];
	}
	ld max1=sum;
	for(int i=k;i<n;i++)
	{
		sum=(sum-a[i-k]+a[i]);
		max1=max(max1,sum);
	}
	cout<<std::setprecision(11);
	cout<<std::fixed;
	cout<<max1;
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<LL> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  int zero=0,one=0,two=0;
  for(int i=0;i<n;i++){
    if(a[i]==0) zero++;
    else if(a[i]==1) one++;
    else two++;
  }
  if(two==0){
    if(zero%2){
      if(one>0){
        for(int i=0;i<zero-1;i++){
          cout << 0 << endl;
        }
        cout << 1 << endl << 0 << endl;
        for(int i=0;i<one-1;i++){
          cout << 1 << endl;
        }
      }else{
        for(int i=0;i<n;i++){
          cout << a[i] << endl;
        }
      }
    }else{
      for(int i=0;i<n;i++){
        cout << a[i] << endl;
      }
    }
    return 0;
  }
  if(zero%2){
    if(one>0){
      if(a[n-2]==2&&a[n-1]==3){
        a[n-1]=2;
        a[n-2]=3;
      }
      for(int i=0;i<n;i++){
        if(a[i]>1) cout << a[i] << endl;
      }
      for(int i=0;i<zero-1;i++){
        cout << 0 << endl;
      }
      cout << 1 << endl << 0 << endl;
      for(int i=0;i<one-1;i++){
        cout << 1 << endl;
      }
    }else{
      int last=-1;
      for(int i=0;i<n;i++){
        if(a[i]>1){
          last=i;
          break;
        }
      }
      if(last<n-2&&a[n-2]==2&&a[n-1]==3){
        a[n-1]=2;
        a[n-2]=3;
      }
      for(int i=last+1;i<n;i++){
        cout << a[i] << endl;
      }
      for(int i=0;i<zero-1;i++){
        cout << 0 << endl;
      }
      cout << a[last] << endl << 0 << endl;
    }
  }else{
    if(a[n-2]==2&&a[n-1]==3){
      a[n-1]=2;
      a[n-2]=3;
    }
    for(int i=0;i<n;i++){
      if(a[i]>1) cout << a[i] << endl;
    }
    for(int i=0;i<zero;i++){
      cout << 0 << endl;
    }
    for(int i=0;i<one;i++){
      cout << 1 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3164
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
int lis(vector<int>v) {
	vector<int>L;
	L.push_back(v[0]);
	rep(i, 1, v.size()) {
		if (L.back() < v[i])L.push_back(v[i]);
		else {
			*lower_bound(all(L), v[i]) = v[i];
		}
	}
	return L.size();
}
signed main() {
	int n; cin >> n; vector<int>v(n); rep(i, 0, n)cin >> v[i];
	cout << lis(v) << endl;
	return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    vector<int> v( 4 );
    for( auto &x : v )
    {
        cin >> x;
    }
    cout << min( v[ 0 ], v[ 1 ] ) + min( v[ 2 ], v[ 3 ] ) << endl;
    return 0;
}

Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c - 1)
		cout << 0ll + b + c << endl;
	else
		cout << 0ll + a + b + b + 1 << endl;	

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  
  REP(i,ty-sy) cout << 'U';
  REP(i,tx-sx) cout << 'R';
  REP(i,ty-sy) cout << 'D';
  REP(i,tx-sx) cout << 'L';
  
  cout << 'L';
  REP(i,ty-sy+1) cout << 'U';
  REP(i,tx-sx+1) cout << 'R';
  cout << 'D' << 'R';
  REP(i,ty-sy+1) cout << 'D';
  REP(i,tx-sx+1) cout << 'L';
  cout << 'U';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n;
  int *h;
  int i;
  int count=0;
  int flag=0;
  
  scanf("%d",&n);
  h=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  
  for(i=0;i<(n-1);i++){ 
    if((h[i]-h[i+1])==1){
      count++;
    } else if((h[i]-h[i+1])>=2){
      flag=1;
    } else if((h[i]-h[i+1])<0){
      count=0;
    }
    
    if(count>=2){
      flag=1;
    }
  }
  
  if(flag==0){
    printf("Yes");
  } else {
    printf("No");
  }
  
  free(h);
}


Measured memory_bytes: 512
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

printList :: Int -> [Int] -> IO ()
printList n xs = putStrLn $ unwords ys
  where
    ys =
        [ if i `elem` xs
            then "1"
            else "0"
        | i <- [1 .. n]
        ]

main :: IO ()
main = do
    n <- readLn
    xss <- fmap (fmap readi . B.words) . B.lines <$> B.getContents
    let f [i, 0]   = (i, [])
        f (i:_:ks) = (i, ks)
    let arr = array (1, n) $ fmap f xss :: Array Int [Int]
    forM_ [1 .. n] $ \i -> printList n $ arr ! i



Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n,m;
  cin >> n >> m;
vector<vector<int>> maze(n+2, vector<int>(m+2));
  for(int i=0;i < n;i++){
    string h;
    cin >> h;
    for(int j = 0;j < m;j++){
     if(h.at(j)=='.'){
       maze.at(i+1).at(j+1) = -1;}
    }
  }
  vector<vector<int>> mazecopy(n+2, vector<int>(m+2));
  for(int i = 1;i < n+1;i++){
     for(int j = 1;j < m+1;j++){
  mazecopy.at(i).at(j) = maze.at(i).at(j);}
  }
  int a = 0;
  for(int i = 1;i < n+1;i++){
     for(int j = 1;j < m+1;j++){
     if(maze.at(i).at(j) == 0){continue;}
       mazecopy.at(i).at(j) = 1;
       for(int kk = 1;kk < 310;kk++){
         int x = 0;
       for(int k = 1;k < n+1;k++){
     for(int l = 1;l < m+1;l++){
       if ((mazecopy.at(k-1).at(l) == kk ||
           mazecopy.at(k+1).at(l) == kk ||
          mazecopy.at(k).at(l+1) == kk || 
           mazecopy.at(k).at(l-1) == kk) && mazecopy.at(k).at(l) == -1)
       {mazecopy.at(k).at(l) = kk+1;
        x++;}
     }
       }
         if(x == 0){a = max(kk-1,a);
                    break;}
       }
       for(int ii = 1;ii < n+1;ii++){
     for(int ji = 1;ji < m+1;ji++){
  mazecopy.at(ii).at(ji) = maze.at(ii).at(ji);}
  }  
     }
  }
  cout << a << endl;
           
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-08-23 00:17:05 +0900
# LastModified: 2020-08-23 00:29:38 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    x, y = map(int, input().split())
    baibai = x
    cnt = 0
    while baibai <= y:
        cnt += 1
        baibai *= 2
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9060
a, b, c, k = list(map(int, input().split()))

if k - a <= 0:
  print(1 * k)
else:
  ans = 1 * a
  if k - a - b <= 0:
    print(ans)
  
  else:
    if k - a - b - c <= 0:
      print(ans + (-1 * (k - (a + b))))
    else:
      print(ans + (-1 * c))

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

struct StGoods
{
  StGoods() : m_nPrice(0), m_nNum(0) { }

  int m_nPrice;
  int m_nNum;
};

void fnInput(int& rnTrgNum, vector<StGoods>& rvoGoods)
{
  int nGoodsSiz;
  cin >> nGoodsSiz >> rnTrgNum;
  rvoGoods.resize(nGoodsSiz);

  for (StGoods& roGoods : rvoGoods)
    cin >> roGoods.m_nPrice >> roGoods.m_nNum;
}

llong fnMinCost(int nTrgNum, const vector<StGoods>& cnrvoGoods)
{
  map<int, int> mpGoods;

  for (StGoods oGoods : cnrvoGoods)
    mpGoods[ oGoods.m_nPrice ] += oGoods.m_nNum;

  llong nCost = 0;

  for (auto PGoods : mpGoods)
  {
    int nUsedNum = min(nTrgNum, PGoods.second);
    nCost += (llong)PGoods.first * nUsedNum;
    nTrgNum -= nUsedNum;

    if ( !nTrgNum ) break;
  }
  return nCost;
}
 
int main()
{
  int nTrgNum;
  vector<StGoods> voGoods;

  fnInput(nTrgNum, voGoods);
  cout << fnMinCost(nTrgNum, voGoods) << endl;

  return 0;
}

Measured memory_bytes: 8756
/* for vjudge contest anu-cpc b */
#include <stdio.h>
#include <stdlib.h>

#define ARR_SIZE 100000

int arr[ARR_SIZE] = { 0 };
int cnt = 0;

void sort(int *a, int left, int right)
{
    int mid, n = right - left + 1;
    int *tmp, i = 0, j = 0, k = 0;
    
    if (n < 2)return;

    tmp = (int*)malloc(n * sizeof(int));

    mid = (left + right) >> 1;
    sort(a, left, mid);
    sort(a, mid + 1, right);

    i = left;
    j = mid + 1;
    while(i <= mid && j <= right)
    {
        if (a[i] < a[j])
        {
            tmp[k++] = a[i++];
        }
        else
        {
            tmp[k++] = a[j++];
        }
    }
    while (i <= mid)tmp[k++] = a[i++];
    while (j <= right)tmp[k++] = a[j++];

    i = left;
    k = 0;
    while (i <= right)a[i++] = tmp[k++];

    free(tmp);
    return;
}

int main(int argc, char** argv)
{
    int n, c, i = 0, j = 0, total = 0;
    scanf("%d", &n);
    while (i++ < n)
    {
        scanf("%d", &arr[cnt++]);
    }

    sort(arr, 0, cnt - 1);

    i = 0;
    while (i < cnt)
    {
        j = i;
        while (j < cnt && arr[j] == arr[i])j++;
        c = j - i;
        total += c < arr[i] ? c : c - arr[i];
        i = j;
    }
    printf("%d\n", total);

    return 0;
}


Measured memory_bytes: 1100
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

struct UnionFind{
	vector<int> d;
	UnionFind(int n) : d(n, -1){}
	int find(int x){
		if(d.at(x) < 0) return x;
		return d.at(x) = find(d.at(x));
	}
	bool unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return false;
		if(d.at(x) > d.at(y)) swap(x, y);
		d.at(x) += d.at(y);
		d.at(y)= x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d.at(find(x)); }
};

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	UnionFind uff(n);
	vector<int> fd(n, 0);
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		uff.unite(a, b);
		fd.at(a)++;
		fd.at(b)++;
	}
	vector<vector<int>> vb(n, vector<int>());
	rep(i, k){
		int c, d;
		cin >> c >> d;
		c--; d--;
		vb.at(c).push_back(d);
		vb.at(d).push_back(c);
	}
	rep(i, n){
		int ans = uff.size(i);

		for(int j : vb.at(i)){
			if(uff.same(i, j) == true)ans--;
		}
		ans -= fd.at(i);
		ans--;
		if(i != 0) cout << " ";
		cout << ans;
	}
	cout << endl;
	return 0;
}

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

int main(){
    int n,k;
    cin >> n;
    cin >> k;
    vector <int> coordinates(n); for (int i=0;i<n;i++){cin>>coordinates[i];}

    int acc = 0;
    for (auto c : coordinates){
        acc += 2 * min(c, abs(c - k));
    }
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 384
num_n = int(input())
n = map(int, raw_input().split())
num_m = int(input())
m = map(int, raw_input().split())
     
def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(n):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - n[i])
   return res
      
for k in range(num_m):
   if solve(0, m[k]):
      print "yes"
   else:
      print "no"

Measured memory_bytes: 6452
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[100];
	cin>>n;
	cin>>a[0];
	int ma=a[0],mi=a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		if(a[i]>ma) ma=a[i];
		if(a[i]<mi) mi=a[i];
	}
	int minn=1e9;
	for(int i=mi;i<=ma;i++){
		int cost=0;
		for(int j=0;j<n;j++){
			cost=cost+(a[j]-i)*(a[j]-i);
		}
       if(cost<minn) minn=cost;
	}
	cout<<minn;
	return 0;
} 

Measured memory_bytes: 764
const MOD: usize = 1_000_000_007;

fn calc(l: usize, r: usize, shift: usize, x: usize, y: usize, s: usize, dp: &mut [[[[usize; 2]; 2]; 2]; 61]) -> usize {
    if shift == 0 {
        return if s == 1 {1} else {0};
    }
    if dp[shift][x][y][s] < MOD {
        return dp[shift][x][y][s];
    }
    let p = (l >> (shift - 1)) & 1;
    let q = (r >> (shift - 1)) & 1;
    let mut ans = 0;
    //00
    if x == 1 || p == 0 {
        ans += calc(l, r, shift - 1, x, y | q, s, dp);
    }
    //01
    if (x == 1 || p == 0) && (y == 1 || q == 1) && s == 1 {
        ans += calc(l, r, shift - 1, x, y, 1, dp);
    }
    //11
    if y == 1 || q == 1 {
        ans += calc(l, r, shift - 1, x | (p == 0) as usize, y, 1, dp);
    }
    ans %= MOD;
    dp[shift][x][y][s] = ans;
    ans
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let l: usize = it.next().unwrap().parse().unwrap();
    let r: usize = it.next().unwrap().parse().unwrap();
    let mut dp = [[[[MOD; 2]; 2]; 2]; 61];
    let ans = calc(l, r, 60, 0, 0, 0, &mut dp);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a' && cnt1 < a + b) {
      cout << "Yes" << endl;
      cnt1++;
    } else if (s[i] == 'b' && cnt1 < a + b && cnt2 < b) {
      cout << "Yes" << endl;
      cnt1++;
      cnt2++;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

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

using namespace std;

int n, k, ans;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if (x >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
C[Y][X]
2^12*6*6まにあうか
*/
int main(){
  ll H,W,K,ans=0; cin>>H>>W>>K;
  vector<vector<char>> C1(H, vector<char>(W, '.')), C2(H, vector<char>(W, '.')), C3(H, vector<char>(W, '.'));
  for(ll y=0; y<H; y++){
    for(ll x=0; x<W; x++){
      char c; cin>>c;
      if(c=='.') continue;
      C1[y][x]=c;  
    }
  }
  ll h=1<<H, w=1<<W;
  for(ll i=0; i<h; i++){
    C2=C1;
    for(ll n=0; n<H; n++){
      if((i&(1<<n))>0)
        for(ll k=0; k<W; k++) C2[n][k]='.';
    }
    for(ll j=0; j<w; j++){
      C3=C2;
      for(ll m=0; m<W; m++){        
        if((j&(1<<m))>0)
          for(ll l=0; l<H; l++) C3[l][m]='.';
      }
      ll tmp=0;
      for(ll y=0; y<H; y++){
        for(ll x=0; x<W; x++){   
          if(C3[y][x]=='#') tmp++;
        }
      }
    if(tmp==K) ans++;      
    }
/*cout<<"i"<<i<<endl;
for(ll a=0; a<H; a++){
  for(ll b=0; b<W; b++) cout<<C3[a][b];
  cout<<endl;
} */       //C2判定
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
    char s[200005],t[200005];
    int count=0;
    scanf("%s",s);
    scanf("%s",t);

    for(int i=0;s[i]!='\0';i++){
        if(s[i]!=t[i]){count++;}
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b;
  cin >> a >> b;
  int w=max(a+b,a-b);
  int r=max(w,a*b);
  cout << r << endl;
}  


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

int main()
{
	int n,a,s,g;
	while(cin>>n>>a>>s>>g && n!=0){
		int LIMIT=0;
		vector<string> ans(n);
		vector<vector<vector<string> > > edge(n,vector<vector<string> >(n));//edge[i][j][k]  i->j :k番目のラベル
		for(int i=0;i<a;i++){
			int x,y; string r;
			cin>>x>>y>>r;
			edge[x][y].push_back(r);
			LIMIT+=r.size()*4;
		}

		queue<int> que;
		que.push(g);
		int count=0;

		while(!que.empty()){//無限ループするよ！
			count++;
			int to=que.front(); que.pop();
			for(int from=0;from<n;from++){
				for(int k=0;k<edge[from][to].size();k++){
					if(from==g) continue;
					string rabel=edge[from][to][k];
					if(ans[from]=="" || ans[from]>rabel+ans[to]){
						ans[from]=rabel+ans[to];que.push(from);
					}
				}
			}
			bool b=false;
			for(int i=0;i<n;i++){
				if(ans[i].size()>=LIMIT){b=true;break;}
			}
			if(b)  break;
		}
		if(ans[s].size()>=LIMIT/4 || ans[s]=="") cout<<"NO"<<endl;
		else cout<<ans[s]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1392
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;
 
template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
 
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    string s;
    cin >> s;

    if(s.back() == 's'){
        cout << s + "es"s << '\n';
    }else{
        cout << s + "s"s << '\n';
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    
}







Measured memory_bytes: 256
N, K = map(int,input().split())

H = list(map(int,input().split()))

# HPで降順ソート
H = sorted(H,reverse=True)


# 最初のK匹には必殺技
# 残りのN-K匹は普通に攻撃
ans = sum(H[K:])
print(ans)

Measured memory_bytes: 26764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    int flag=1,cnt=0;
    for(int i=0;i<l/2;i++){
        if(s[i]!=s[l-i-1]){
            flag=0;
            break;
        }
    }
    if(flag==1) cout<<0<<endl;
    else{
        for(int i=0;i<l/2;i++){
            if(s[i]==s[l-i-1]) continue;
            else{
                s[i]=s[l-i-1];
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N, K;
  cin >> N >>K;
  vector<char> vec(N);
  for (int i = 0; i<N; i++) {
    cin >> vec.at(i);
  }
  vec.at(K-1) = tolower(vec.at(K-1));
  for (int i=0; i<N; i++) {
    cout << vec.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A=list(map(int,input().split()))
max = 0
for i in range(N-1):
    if max<=A[i+1]-A[i]:
        max=A[i+1]-A[i]
if max<=A[0]+K-A[N-1]:
    max=A[0]+K-A[N-1]
print(K-max)

Measured memory_bytes: 26444
S = input()
MOD = 10**9 + 7

p = [ (10**k)%13 for k in range(6) ]
mod_tb = [ [i*p[k]%13 for i in range(10)] for k in range(6) ]
n = [0]*6
base = 0
for k in range(len(S)):
    s = S[-(k+1)]
    if s == '?':
        n[k%6] += 1
    else:
        base += p[k%6]*int(s)
        base %= 13

DP = [ [0] * 13 for _ in range(sum(n)+1) ]
DP[0][base] = 1
i = 1
for k in range(6):
    for _ in range(n[k]):
        for m in range(13):
            for d in range(10):
                DP[i][(m + mod_tb[k][d])%13] += DP[i-1][m]
        for m in range(13):
            DP[i][m] %= MOD
        i += 1
print(DP[-1][5])

Measured memory_bytes: 61916
import java.util.Scanner;

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

    int[] temp = new int[6];
    for (int i = 0; i < 6; i++) {
      temp[i] = reader.nextInt();
    }
    Dice dice1 = new Dice(temp);
    char[] order = reader.next().toCharArray();
    for (int i = 0; i < order.length; i++) {
      dice1.roll(order[i]);
    }
    dice1.printTop();
  }
}

class Dice {
  int[] number = new int[6];
  int[] surface = new int[3];

  public Dice(int[] number) {
    for (int i = 0; i < 6; i++) {
      this.number[i] = number[i];
    }
    this.surface[0] = 0;
    this.surface[1] = 1;
    this.surface[2] = 2;
  }

  public void roll(char order) {
    int temp;
    if (order == 'N') {
      temp = this.surface[0];
      this.surface[0] = this.surface[1];
      this.surface[1] = 5 - temp;
    }
    else if (order == 'S') {
      temp = this.surface[1];
      this.surface[1] = this.surface[0];
      this.surface[0] = 5 - temp;
    }
    else if (order == 'E') {
      temp = this.surface[2];
      this.surface[2] = this.surface[0];
      this.surface[0] = 5 - temp;
    }
    else if (order == 'W') {
      temp = this.surface[0];
      this.surface[0] = this.surface[2];
      this.surface[2] = 5 - temp;
    }
  }

  public void printTop() {
    System.out.println(this.number[this.surface[0]]);
  }
}

Measured memory_bytes: 26284
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int A,B,C;
int main(){
  cin>>A>>B>>C;
  int m = min(B/A,C);
  cout << m << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
map<string, int> mp;
int main()
{
	int n;
	scanf("%d", &n);
	char s[11];
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		sort(s, s + 10);
		mp[s]++;
	}
	long long ans = 0;
	for (auto &i : mp) {
		ans += 1LL * i.second * (i.second - 1) / 2;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11136
import java.util.*;

class Main{
  //QuickSort
	static void swap(int[] a, int idx1, int idx2){
 		int t = a[idx1]; a[idx1] = a[idx2]; a[idx2] = t;
	}

	static void quickSort(int[] a, int left, int right){
  		int pl = left;
  		int pr = right;
  		int x  = a[(pl+pr)/2];

  		do{
    		while (a[pl] < x) pl++;
    		while (a[pr] > x) pr--;
    		if(pl <= pr)
       			swap(a, pl++, pr--);
  		}while(pl <= pr);

  		if(left < pr) quickSort(a,left,pr);
  		if(pl < right) quickSort(a,pl,right);
	}
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[N];
    int sum_vote = 0;
    for(int i = 0; i < N; i++){
      A[i] = sc.nextInt();
      sum_vote += A[i];
    }
	
    //昇順に並び替え
    quickSort(A,0,N-1);
    
    int count = 0;
    int judge = 0;
    for(int i = N-1; i >= 0; i--){
      if ( A[i]*4*M >= sum_vote)
        count++;
      if(count == M){
        judge = 1;
        break;
      }
    }
    
    if ( judge == 0)
      System.out.println("No");
    else
      System.out.println("Yes");
    
  }
}


Measured memory_bytes: 35860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    map<char, int> cnt;
    ll ans = 1;
    rep(i, 0, n) cnt[s[i]]++;
    for (auto x : cnt) {
        ans *= (x.second + 1);
        ans %= mod;
    }

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


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

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

  string S; cin >> S;
  string str = "CODEFESTIVAL2016";
  int cnt = 0;
  for(int i = 0; i < S.length(); i++){
    if(str[i] != S[i]) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static int mod=1000000007;
	static Scanner scan=new Scanner(System.in);
	static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
	static long lcm (long a, long b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
			}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	static long modpow(long a,long n) {
		if(n==0) return 1;
		else if(n==1)return a;
		long tmp=modpow(a,n/2);
		tmp%=mod;
		tmp*=tmp;
		tmp%=mod;
		if(n%2==0)return tmp;
		else return (tmp*a)%mod;
	}
	public static void main(String[] args){
		String str=scan.next();
		System.out.println(str.substring(0,4)+" "+str.substring(4,12));
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <functional>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

int main() {
  int N;
  std::vector<int> a;

  cin >> N;
  a.resize(3 * N);
  for (int i = 0; i < 3 * N; ++i) {
    cin >> a[i];
  }

  ll sum1 = 0, sum2 = 0;
  std::vector<ll> split_num1(N + 1), split_num2(N + 1);
  std::priority_queue<int, std::vector<int>, std::greater<int> > fwd;
  std::priority_queue<int> bck;

  for (int i = 0; i < N; ++i) {
    sum1 += a[i];
    fwd.push(a[i]);
  }

  split_num1[0] = sum1;

  for (int i = N; i < 2 * N; ++i) {
    fwd.push(a[i]);
    sum1 = sum1 + a[i] - fwd.top();
    fwd.pop();
    split_num1[i - N + 1] = sum1;
  }

  for (int i = 2 * N; i < 3 * N; ++i) {
    sum2 += a[i];
    bck.push(a[i]);
  }

  split_num2[N] = sum2;

  for (int i = 2 * N - 1; i >= N; --i) {
    bck.push(a[i]);
    sum2 = sum2 + a[i] - bck.top();
    bck.pop();
    split_num2[i - N] = sum2;
  }

  ll ans = -ll(1e18);

  for (int i = 0; i <= N; ++i) {
    ans = std::max(ans, split_num1[i] - split_num2[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4088
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, ball[10];
  vector<string> result;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> ball[j];
    int j, a = 0, b = 0;
    for (j = 0; j < 10; j++) {
      if (ball[j] > a)
        a = ball[j];
      else if (ball[j] > b)
        b = ball[j];
      else
        break;
    }
    if (j == 10)
      result.push_back("YES");
    else
      result.push_back("NO");
  }

  for (int i = 0; i < n; i++)
    cout << result[i] << endl;
  return 0;
}

Measured memory_bytes: 1200
n=int(input())
A=list(map(int,input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a,b=A[0],A[1]
ans=gcd(a,b)
for i in range(2,n):
    a,b=ans,A[i]
    ans=gcd(a,b)
print(ans)

Measured memory_bytes: 14252
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

int INF = int.max/3;
void main() {
    int N = readln.chomp.to!int;
    int[] ary = readln.split.to!(int[]);
    int[] _ary = new int[N+1];
    foreach(i, e; ary) {
        _ary[e] = i.to!int;
    }
    int[] t = new int[N];
    int[] left = new int[N];
    int[] right = new int[N];
    auto rbtree = redBlackTree!((a,b)=>a>b, int)();
    foreach(i; 0..N) {
        while (!rbtree.empty && ary[i] < rbtree.front) {
            auto e = rbtree.front;
            rbtree.removeFront;
            right[_ary[e]] = abs(i-_ary[e])-1;
        }
        rbtree.insert(ary[i]);
    }
    while(!rbtree.empty) {
        auto e = rbtree.front;
        rbtree.removeFront;
        right[_ary[e]] = abs(N-_ary[e])-1;
    }
    foreach(j; 0..N) {
        auto i = N-j-1;
        while (!rbtree.empty && ary[i] < rbtree.front) {
            auto e = rbtree.front;
            rbtree.removeFront;
            left[_ary[e]] = abs(i-_ary[e])-1;
        }
        rbtree.insert(ary[i]);
    }
    while(!rbtree.empty) {
        auto e = rbtree.front;
        rbtree.removeFront;
        left[_ary[e]] = abs(-1-_ary[e])-1;
    }

    N.iota.map!(i => ary[i].to!long*(left[i]+1)*(right[i]+1)).sum.writeln;
}


Measured memory_bytes: 21392
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;

int n, d, g[MAXN], to[MAXN << 1], nxt[MAXN << 1], edgeSize;

int count(int x, int fa, int lim){
	if(!lim) return 1;
	int ret = 1, p;
	for(p = g[x]; p; p = nxt[p])
		if(to[p] != fa) ret += count(to[p], x, lim - 1);
	return ret;
}
void addEdge(int u, int v){
	nxt[++ edgeSize] = g[u];
	to[g[u] = edgeSize] = v;
}
int main(){
	int i, a, b, ans = 0, p;
	scanf("%d%d", &n, &d);
	for(i = 1; i < n; ++ i){
		scanf("%d%d", &a, &b);
		addEdge(a, b), addEdge(b, a);
	}
	for(i = 1; i <= n; ++ i)
		if(d & 1)
			for(p = g[i]; p; p = nxt[p])
				ans = max(ans, count(i, to[p], d >> 1) + count(to[p], i, d >> 1));
		else ans = max(ans, count(i, -1, d >> 1));
	printf("%d\n", n - ans);
	return 0;
}

Measured memory_bytes: 384
# 一番早いのを写経したものを弄ってアルゴリズム勉強のための試し打ち中

def floor_sum(n, m, a, b):
    res = 0
    if b >= m:
        res += n * (b // m)
        b %= m
    while True:
        if a >= m:
            res += (n - 1) * n * (a // m) // 2
            a %= m
        y_max = (a * n + b) // m
        if y_max == 0: break
        x_max = b - y_max * m
        res += (n + x_max // a) * y_max
        n, m, a, b = y_max, a, m, x_max % a
    return res


import sys
input = sys.stdin.buffer.readline

T = int(input())
res = [''] * T

for i in range(T):
    n, m, a, b = map(int, input().split())
    res[i] = str(floor_sum(n, m, a, b))

print('\n'.join(res))


Measured memory_bytes: 74432
module Main where
--import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [Double] -> Double
solve [ax,ay,bx,by] = sqrt $ (ax-bx)^2+(ay-by)^2

readLine:: IO [Double]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    l <- readLine
    print (solve l)



Measured memory_bytes: 4020
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	string s;
	getline(cin,s);
	if(s[0]=='D')
	{
		if(s[2]=='D') printf("H\n");
		else printf("D\n");
	}
	else 
	{
		if(s[2]=='H') printf("H\n");
		else printf("D\n");
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().ToCharArray();
        var hash = new HashSet<char>(n);
        WriteLine(n.Length == hash.Count ? "yes" : "no");
    }
}


Measured memory_bytes: 19616
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n;
int h[30];

int main(){
    fastio;
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>h[i];

    int sum = 1;
    for(int i = 2;i<=n;i++){
        int cnt = 0;
        for(int j = i-1;j>=1;j--){
            if(h[i] >= h[j])
                cnt++;
        }
        if(cnt == i-1)
            sum++;
    }    
    
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	
	static long n = 0;

	public static void main(String[] args) throws Exception {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			n = Long.parseLong(br.readLine());
			System.out.println(get("0"));
		}
	}
	
	public static int get(String a) {
		boolean[] bools = {false, false, false};
		List<String> num = new ArrayList<>(Arrays.asList(a.split("")));
		int count = 0;
		
		num.remove("0");
		
		if(Long.parseLong(a) > n) return 0;
		
		for (String s : num) {
			int i = Integer.parseInt(s);
			if(i == 3) bools[0] = true;
			else if(i == 5) bools[1] = true;
			else if(i == 7) bools[2] = true;
			else {
				bools[0] = false;
				break;
			}
		}
		if(bools[0] && bools[1] && bools[2]) count++;
		if(Long.parseLong(a) == 0) a = "";
		
		for (String ss : "357".split("")) {
			count += get(a + ss);
		}
		return count;
		
	}

}


Measured memory_bytes: 75764
N,M=map(int,input().split())
Accepted=[0]*N
Penalty=[0]*N
for i in range(M):
    p,S=input().split()
    p=int(p)
    if Accepted[p-1]==0 and S=="WA":
        Penalty[p-1]+=1
    elif Accepted[p-1]==0 and S=="AC":
        Accepted[p-1]=1
total_Accepted=sum(Accepted)
total_Penalty=0
for i in range(N):
  if Accepted[i-1]==1:
    total_Penalty+=Penalty[i-1]
print(total_Accepted,total_Penalty)

Measured memory_bytes: 4596
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	long long int ans = 1;
	vector<long long int>p;
	vector<long long int>m;
	vector<long long int>z;
	for (int i = 0; i < N; i++) {
		cin >> M;
		if (M > 0)p.push_back(M);
		else if (M < 0)m.push_back(-M);
		else z.push_back(M);
	}
	sort(m.begin(), m.end());
	sort(p.begin(), p.end());
	if (p.size() + m.size() < K) {
		cout << 0 << endl;
		return 0;
	}
	if (p.empty()) {
		if (z.empty()) {
			if (K & 1) {
				long long int ans = 1;
				for (int i = 0; i < K; i++) {
					ans *= MOD - m[i];
					ans %= MOD;
				}
				cout << ans << endl;
			}
			else {
				reverse(m.begin(), m.end());
				long long int ans = 1;
				for (int i = 0; i < K; i++) {
					ans *= MOD - m[i];
					ans %= MOD;
				}
				cout << ans << endl;
			}
			return 0;
		}
		else if(K % 2 == 0 && m.size() >= K) {
			reverse(m.begin(), m.end());
			long long int ans = 1;
			for (int i = 0; i < K; i++) {
				ans *= MOD - m[i];
				ans %= MOD;
			}
			cout << ans << endl;
			return 0;

		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}
	else {
		if (p.size() + m.size() == K && m.size() % 2 == 1) {
			if (z.empty()) {
				long long int ans = 1;
				for (auto i : p) {
					ans *= i;
					ans %= MOD;
				}
				for (auto i : m) {
					ans *= MOD - i;
					ans %= MOD;
				}
				cout << ans << endl;
				return 0;
			}
			else {
				cout << 0 << endl;
				return 0;
			}
		}
		else {
			reverse(p.begin(), p.end());
			reverse(m.begin(), m.end());
			int pcnt = 0;
			int mcnt = 0;
			long long int ans = 1;
			while (K) {
				if (K >= 2) {
					if (pcnt + 2+(K&1) > p.size()) {
						ans *= MOD - m[mcnt];
						ans %= MOD;
						mcnt++;
						ans *= MOD - m[mcnt];
						ans %= MOD;
						mcnt++;
					}
					else if (mcnt + 2 > m.size()) {
						ans *= p[pcnt];
						ans %= MOD;
						pcnt++;
						ans *= p[pcnt];
						ans %= MOD;
						pcnt++;
					}
					else {
						if (p[pcnt] * p[pcnt + 1] > m[mcnt] * m[mcnt + 1]) {
							ans *= p[pcnt];
							ans %= MOD;
							pcnt++;
							ans *= p[pcnt];
							ans %= MOD;
							pcnt++;
						}
						else {
							ans *= MOD - m[mcnt];
							ans %= MOD;
							mcnt++;
							ans *= MOD - m[mcnt];
							ans %= MOD;
							mcnt++;
						}
					}
					K -= 2;
				}
				else {
					K--;
					ans *= p[pcnt];
					ans %= MOD;
				}
			}
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 5696
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>


int max(int a, int b){
    if(a > b){
        return a;
    }else{
        return b;
    }
}

int min(int a, int b){
    if(a < b){
        return a;
    }else{
        return b;
    }
}


int main(){

    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    printf("%d", max(max(a,b),c) - min(min(a,b),c));

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;



int main(){
    char s[10010];
    int ans1=0,ans2=0;
    while(scanf("%s",s)!=EOF){
        ans1=0,ans2=0;
    for(int i=0;s[i+2]!='\0';i++){
        if(s[i+2]=='I')
            if(s[i+1]=='O'){
                if(s[i]=='J')
                    ans1++;
                if(s[i]=='I')
                    ans2++;
            }
    }
    
    printf("%d\n%d\n",ans1,ans2);
    }
    return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int> > A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }

    sort(A.begin(), A.end(), greater<pair<int, int> >());

    for (int i = 0; i < n; i++) {
        if (A[0].second == i)
            cout << A[1].first << endl;
        else
            cout << A[0].first << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const N = parseInt(arr[0]);
    const M = parseInt(arr[1]);
    const A = line[1].split(" ").map(Number)
    let accum = 0
    A.forEach(Ai => {
        accum += Ai;
    });
    console.log(N < accum ? -1 : N - accum);
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30528
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

ll calc(ll A){
	if(A<0)return 0;
	if(A%4==0)return A;
	if(A%4==1)return 1;
	if(A%4==2)return A+1;
	return 0;
}
int main(){
	ll A,B;cin>>A>>B;
	cout<<(calc(B)^calc(A-1))<<endl;
}

Measured memory_bytes: 256