akhauriyash/Code-Regression huggingface dataset:
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a[5],sum=0; int mx=0;
	for(int i=0; i<5; i++){
		cin >> a[i];
		mx = max(mx,(a[i]%10>0)?10-a[i]%10:0);
		if(a[i]%10)a[i]+=10-a[i]%10;
		sum += a[i];
	}
	cout << sum-mx << endl;
}	


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

lli memoized(vector<lli> &memo, vector<lli> const &scores, int s) {
  if (s == 0) { return 0; }
  if (memo[s] >= 0) { return memo[s]; }

  lli ans = scores[s];
  for (int t = (-s) & s; t != s ; t = (t - s) & s) {
    auto const u = s & ~t;
    auto const car = memoized(memo, scores, t);
    auto const cdr = memoized(memo, scores, u);
    chmax(ans, car + cdr);
  }
  memo[s] = ans;
  return ans;
}

void solve(int N, vector<vector<lli>> const &As) {
  vector<lli> scores(1<<N, 0);
  REP(s, 1 << N) {
    lli score = 0;
    bitset<32> S = s;
    REP(i, N) FOR(j, i, N-1) {
      if (S[i] && S[j]) { score += As[i][j]; }
    }
    scores[s] = score;
  }
  vector<lli> memo(1 << N, -1);
  lli ans = memoized(memo, scores, (1<<N)-1);
  cout << ans << endl;
}

int main() {
  int N;
  cin >> N;
  vector<vector<lli>> As(N, vector<lli>(N));
  REP(r, N) REP(c, N) {
    cin >> As[r][c];
  }
  solve(N, As);
  return 0;
}


Measured memory_bytes: 1280
# 丁度n本の辺を持つ完全グラフが存在するか？という問題
from itertools import combinations
from collections import defaultdict
n = int(input())
# edgeを入れるとnode数が取れる
dd = defaultdict(int)
prev = 0
for i in range(1, 10**5):
    if n < prev:
        break
    dd[prev] = i
    prev += i

if dd[n]:
    print('Yes')
    print(dd[n])
    # dd[n]頂点、n辺の完全グラフを構築する
    subarrays = [set()for _ in range(dd[n])]
    cnt = 1
    for i, j in combinations(range(dd[n]), 2):
        subarrays[i].add(cnt)
        subarrays[j].add(cnt)
        cnt += 1
    for s in subarrays:
        print(len(s), *s)

else:
    print('No')

Measured memory_bytes: 22520
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define rs (x<<1|1)
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
typedef long long ll;
const int N=200005;
int main(){
	ll a,b,c,d;int n;
	read(n);read(a);read(b);read(c);read(d);
	rep(i,0,n-2){
		ll left=a-d*i+(ll)(n-i-1)*c,right=a+(ll)(n-i-1)*d-c*i;
		if(left<=b&&right>=b){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
 int x, y;
 do {
  scanf("%d%d",&x,&y);
  if(x == 0 && y == 0)break;
  else if(x <= y) {
   printf("%d %d\n",x,y);
  } else {
   printf("%d %d\n",y,x);
  }
 } while (1);
 return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair

using namespace std;

int main() {
  int N; cin >> N;
  vector<pair<int, int> > pairs(N);
  int x, y;
  for(int i=0; i<N; i++){
    cin >> x >> y;
    pairs[i] = make_pair(x, y);
  }

  sort(pairs.begin(), pairs.end());

  int max_cnt = 0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){

      // cout << "combination: ";
      // cout << "(" << pairs[i].first << "," << pairs[i].second << ")";
      // cout << "(" << pairs[j].first << "," << pairs[j].second << ")" << endl;

      int cnt = 0;
      int dx = pairs[j].first - pairs[i].first;
      int dy = pairs[j].second - pairs[i].second;

      for(int k=0; k<N; k++){
        for(int l=k+1; l<N; l++){
          if(pairs[l].first - pairs[k].first == dx && \
             pairs[l].second - pairs[k].second == dy) cnt++;
        }
      }

      max_cnt = max(max_cnt, cnt);
    
    }
  }

  cout << N - max_cnt << endl;

  return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
answer = 0
m = 0
for i in range(n+1) :
  if i < 10 ** 1 :
    if a <= i and b >= i :
      answer = answer + i
  elif i < 10 ** 2 :
    m = int(str(i)[0]) + int(str(i)[1])
    if a <= m and b >= m :
      answer = answer + i
  elif i < 10 ** 3 :
    m = int(str(i)[0]) + int(str(i)[1]) + int(str(i)[2])
    if a <= m and b >= m :
      answer = answer + i
  elif i < 10 ** 4 :
    m = int(str(i)[0]) + int(str(i)[1]) + int(str(i)[2]) + int(str(i)[3])
    if a <= m and b >= m :
      answer = answer + i
  elif i < 10 ** 5 :
    m = int(str(i)[0]) + int(str(i)[1]) + int(str(i)[2]) + int(str(i)[3]) + int(str(i)[4])
    if a <= m and b >= m :
      answer = answer + i

print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1000000000;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = -2e18;
  ans = max((ll)a * c, ans);
  ans = max((ll)a * d, ans);
  ans = max((ll)b * c, ans);
  ans = max((ll)b * d, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    char a,d,b;
    scanf("%c%c%c",&a,&d,&b);
    if(a=='H')
    printf("%c",b);
     if(a=='D')
    {
        if(b=='H')
            printf("D\n");
        else if(b=='D')
            printf("H\n");
    }
    return 0;
}

Measured memory_bytes: 1600
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int N,M;
int ar[10];
int main(){
  vector<Edge> vec;
  cin >> N >> M;
  REP(a,M){
      CIN(b);CIN(c);
      Edge E(b,c);
      vec.pb(E);
  }
  I ne(N-1);
  iota(ALL(ne),2);
  int ans = 0;
  do{
      bool result = true;
      for(int a = 0;a < N-1;a++){
          if(a==0){
              bool w = false;
              FOREACH(v,vec){
                  if(v.from==1&&v.to==ne.at(a)){
                      w = true;
                      break;
                  }
                  if(v.to==1&&v.from==ne.at(a)){
                      w = true;
                      break;
                  }
              }
              if(!w){
                 result = false;
                 break;
              }
          }else{
              bool w = false;
              FOREACH(v,vec){
                  if(v.from==ne.at(a-1)&&v.to==ne.at(a)){
                      w = true;
                      break;
                  }
                  if(v.to==ne.at(a-1)&&v.from==ne.at(a)){
                      w = true;
                      break;
                  }
              }
              if(!w){
                 result = false;
                 break;
              }
          }
      }
      if(result)ans++;
  }while(next_permutation(ALL(ne)));
  COUT(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, d, xd, wynik, x, y;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> d;
    while(n--)
    {
        cin >> x >> y;
        if(x * x + y * y <= d * d)
            wynik++;
    }
    cout << wynik << "\n";
}


Measured memory_bytes: 3616
import java.util.*;
// . >
class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		
		String a = in.nextLine(), b = in.nextLine(), c = in.nextLine();
		int ind1 = 0, ind2 = 0, ind3 = 0;
		int res = a.length() + b.length() + c.length();
		char t = 'a';
		for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		}
			
		System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C");
		
	}

}


Measured memory_bytes: 35764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N; cin >> N;
    vector<int> a(5);
    int i;
    rep(i,N){
        string s; cin >> s;
        if(s == "AC") a[0]++;
        if(s == "WA") a[1]++;
        if(s == "TLE") a[2]++;
        if(s == "RE") a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 510000
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; ++i)

int g(int n)
{
    int res = 0;
    if (n == 1)
        return 1;
    for (int i = 1; i * i <= n; ++i)
    {
        if (i * i == n)
            res++;
        else if (n % i == 0)
            res += 2;
    }
    return res;
}
void solve(void)
{
    int n;
    cin >> n;
    int ans = 0;
    for (int c = 1; c < n; c++)
    {
        int ab = n - c;
        ans += g(ab);
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main() {

	int H, W;
	cin >> H >> W;

	while (H != 0){

		int j, k;
		for (j = 0; j < H; j++){
			for (k = 0; k < W; k++){

				if ((k % 2 == 0 && j % 2 == 0) || (k % 2 == 1 && j % 2 == 1))cout << "#";
				else cout << ".";

			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}
	return 0;
}



Measured memory_bytes: 3080
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);

    rep(i, N){
        cin >> h[i];
    }

    vector<int> cost(N + 10, INF);

    cost[0] = 0;

    rep(i, N){
        int plus1 = abs(h[i] - h[i + 1]) + cost[i];
        int plus2 = abs(h[i] - h[i + 2]) + cost[i];
        
        cost[i + 1] = min(plus1, cost[i + 1]);
        cost[i + 2] = min(plus2, cost[i + 2]);
    }
    cout << cost[N - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    long long k;
    cin>>k;
    cout<<50<<endl;
    for(int i=0;i<50;i++){
        if(i!=0)cout<<" ";
        cout<<49-i+(k+49-i)/50;
    }
    cout<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n % 2 == 0) {
            System.out.println(n);
        } else {
            System.out.println(n * 2);
        }
    }
}


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

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

    if(n / 100 == 1){
        cout << 9;
    }else{
        cout << 1;
    }

    if((n % 100) /10 == 1){
        cout << 9;
    }else{
        cout << 1;
    }

    if((n % 10) == 1){
        cout << 9;
    }else{
        cout << 1;
    }
}

Measured memory_bytes: 256
// AtCoder ABC137: A - +-x
// 2019.8.26 bal4u

#include <stdio.h>

inline static void chmax(int *ma, int a) { if (*ma < a) *ma = a; }
 
int main()
{
	int a, b, ma;
	
	scanf("%d%d", &a, &b);
	ma = a+b;
	chmax(&ma, a-b);
	chmax(&ma, a*b);
	printf("%d\n", ma);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int max_a, max_b;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (max_a < a) {
      max_a = a;
      max_b = b;
    }
  }
  cout << max_a + max_b;
  return 0;
}


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

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)


using ll = long long;
using namespace std;


void solve();

int main() {

   solve();
   return 0;

}

void solve() {
	ll n;
	
	cin >> n;
	ll two = 0, ans = 1;
	RFOR(i, 1, n + 1) {

		for (int j = 1; j <10; j++) {

			if (i%llround(pow(2,j)) > 0) {
				if (j-1 > two) {
					two = j-1;
					ans = i;
				}
				break;
			}
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
#define REP(i,s,N) for(ll i=s;i<N;++i)

int main() {
	ll N;
	cin >> N;
	ll sum = 0;
	ll t = N;
	while (t > 0) {
		sum += t % 10;
		t /= 10;
	}	
	cout << ((N % sum == 0) ? "Yes" : "No") << endl;
	return 0;
}



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

A.sort(reverse=True)

cnt=1
r=[]
for i in range(1,N):
    if A[i-1]==A[i]:
        cnt+=1
    else:
        if len(r)==0 and cnt>=4:
            print(A[i-1]*A[i-1])
            exit()
        elif cnt>=2:
            r.append(A[i-1])
            if len(r)==2:
                print(r[0]*r[1])
                exit()
            cnt=1
        else:
            cnt=1
if cnt>=2:
    r.append(A[i-1])
    if len(r)==2:
        print(r[0]*r[1])
        exit()

print(0)



Measured memory_bytes: 14672
n,m = list(map(int,input().split()))

X =list(map(int,input().split()))
Y = list(map(int,input().split()))


"""
3*2 * 5*2

"""
#print( (X[-1]-X[0])*(n-1) * (m-1)*(Y[-1]-Y[0]) )# %1000000007

def calc_diff(L):
    result = 0
    #n_of_diff
    for i,l in enumerate(L):
        if i==len(L)-1:
            break
            #hidari x migi
        result += (i+1)*(len(L)-i-1)* (L[i+1]-L[i])
        result = result %1000000007
        #print(result)
    return result

print(calc_diff(X) *calc_diff(Y) %1000000007 )

Measured memory_bytes: 18624
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int N = S.Length;
		int M = T.Length;
		int[][] dp = new int[N + 1][];
		int[][] dp2 = new int[N + 1][];
		for(int i=0;i<=N;i++){
			dp[i] = new int[M + 1];
			dp2[i] = new int[M + 1];
		}
		
		for(int i=0;i<N;i++){
			for(int j=0;j<M;j++){
				if(S[i] == T[j]){
					dp[i + 1][j + 1] = dp[i][j] + 1;
					dp2[i + 1][j + 1] = 2;
				} else {
					if(dp[i][j + 1] > dp[i + 1][j]){
						dp[i + 1][j + 1] = dp[i][j + 1];
						dp2[i + 1][j + 1] = 0;
					} else {
						dp[i + 1][j + 1] = dp[i + 1][j];
						dp2[i + 1][j + 1] = 1;
					}
				}
			}
		}
		
//for(int i=0;i<=N;i++) Console.WriteLine(String.Join(" ",dp[i]));		
//for(int i=0;i<=N;i++) Console.WriteLine(String.Join(" ",dp2[i]));		
		
		var L = new List<char>();
		int r = N;
		int c = M;
		while(r != 0 && c != 0){
			if(dp2[r][c] == 2){
				r--; c--;
				L.Add(S[r]);
			} else if(dp2[r][c] == 0){
				r--;
			} else {
				c--;
			}
		}
		L.Reverse();
		Console.WriteLine(new String(L.ToArray()));
		
	}
	String S,T;
	public Sol(){
		S = rs();
		T = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 84800
############
#
# N, H
# i : Ai, Bi
#
# currentH <= max(Bi) AND max(Ai, Bi) = Bi then throw i
# currentH <= max(Ai) AND max(Ai, Bi) = Ai then Slash i
# currentH >  max(Bi) AND max(Ai, Bi) = Bi then Slash i
# currentH >  max(Ai) AND max(Ai, Bi) = Ai then Slash i
# 
# 1. select max(Ai, Bi) to Dmg
# 2. currentH = currentH - Dmg
# 2. if Dmg is belong to Bi, then discard Bi
# 3. if currentH > 0, then loop back to 1.

[N, H] = map(int, raw_input().split())

#print N, H

arrayA = []
arrayB = []

for i in range(N):
    [Ai, Bi] = map(int, raw_input().split())
    arrayA.append(Ai)
    arrayB.append(Bi)

arrayA.sort()
arrayB.sort()
arrayA.reverse()
arrayB.reverse()

count = 0

while H > 0:
    maxAi = arrayA[0]
    if len(arrayB) > 0:
        maxBi = arrayB[0]
    else:
        maxBi = 0
        
    if maxBi > maxAi:
        maxDmg = arrayB.pop(0)
        H = H -maxDmg
        count = count +1
    else:
        maxDmg = maxAi
        if maxDmg < H:
            count = count + (H / maxDmg)
            H = H % maxDmg
        else:
            count = count +1
            H = H -maxDmg

#    print H, maxDmg, count

print count


Measured memory_bytes: 12164
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int R[MAX],n;
	
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> R[i];
	}
	int maxv = -2000000000;
	int minv = R[0];
	
	for(int i=1;i<n;i++)
	{
		maxv = max(maxv,R[i]-minv);
		minv = min(minv,R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(8); } } pre__;

int main(void) {
	int N, M;
	cin >> N >> M;
	vec<int> bulb(N);
	for (int i = 0; i < M; ++i) {
		int k;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			int s;
			cin >> s;
			--s;
			bulb[s] |= 1 << i;
		}
	}
	int P = 0;
	for (int i = 0; i < M; ++i) {
		int p;
		cin >> p;
		if (p)P |= 1 << i;
	}
	int ans = 0;
	for (int b = 0; b < (1 << N); ++b) {
		int res = 0;
		for (int i = 0; i < N; ++i) {
			if (b & (1 << i)) {
				res ^= bulb[i];
			}
		}
		if (res == P)++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int  main()
{
	long n,x,y,i,j;
  cin>>n>>x>>y;
 int  hash[n+1]={};
  for(i=1;i<n;i++)
  {
  	for(j=i+1;j<=n;j++)
    {
      
      long x1=min(j-i,abs(x-i)+1+abs(j-y));
      long ans=min(x1,abs(y-i)+1+abs(j-x));
      hash[ans]++;
    }
  }
  for(i=1;i<n;i++)
    	cout<<hash[i]<<"\n";
  return 0;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
# @lru_cache(None)





n,c,k=l()
A=[l()[0] for i in range(n)]
A.sort()
i=0
count=0
while(i<n):
    j=i
    while(i<n and A[j]+k>=A[i]and i-j+1<=c):
        i+=1
    count+=1
print(count)

Measured memory_bytes: 9576
n = int(input())

one = [[0 for _ in range(10)] for _ in range(3)]
two = [[0 for _ in range(10)] for _ in range(3)]
three = [[0 for _ in range(10)] for _ in range(3)]
four = [[0 for _ in range(10)] for _ in range(3)]

d = {1:one,2:two,3:three,4:four}

while n > 0:
    b,f,r,v = map(int,input().split())
    d[b][f-1][r-1] += v
    n-= 1

c = 0
for N in [one,two,three,four]:
    for f in N:
        print(" "+" ".join([str(i) for i in f]))
    c +=1
    if c != 4:
        print("#"*20)


Measured memory_bytes: 5608
#include<stdio.h>

void buildupmaxheap(int *);
void maxheapify(int *,int);
void swap(int *,int *);
int left(int);
int right(int);

int heap;

int main(){
 
  int A[500000];
  scanf("%d",&heap);
  int i;
  for(i=1;i<=heap;i++){
    scanf("%d",&A[i]);
  }

  buildupmaxheap(A);
 
  for(i=1;i<=heap;i++){
    printf(" %d",A[i]);
  }

  printf("\n");
  
  return 0;
}

int left(int i){
  return 2*i+1;
}

int right(int i){
  return 2*i;
}

void buildupmaxheap(int *A){
  int i;
  for(i=heap/2;i>=1;i--){
    maxheapify(A,i);
  }
}

void maxheapify(int *A,int i){
  int l,r,largest;
  l=left(i);
  r=right(i);
  if(l<=heap&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=heap&&A[r]>A[largest])
    largest=r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxheapify(A,largest);
  }
}
void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
  return;
}



Measured memory_bytes: 3652
#include<stdio.h>


int main(void){
	int x,y,t,t_c,squ=0,his=0;
	
	while(scanf("%d,%d,%d",&x,&y,&t)!=EOF){
		t_c=x*x+y*y;
		if(x==y || x==y==t)his++;
		else if(t*t==t_c)squ++;
	}
	printf("%d\n%d\n",squ,his);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;
const ll MOD = 1000000007;

int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);

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

  ll mod_k_sum = (((k-1)*(k))/2) % MOD;
  ll ans = 0;
  for(int i=0; i<n; i++){
    ll cnt = 0;
    ll cnt_right = 0;
    for(int j=0; j<n; j++){
      if(a[i] > a[j]) cnt++;
      if(j > i && a[i] > a[j]) cnt_right++;
    }

    // cout << cnt << endl;
    // cout << cnt_right << endl;
    cnt = cnt % MOD;
    ans += (cnt * mod_k_sum) % MOD;
    ans = ans % MOD;
    ans += cnt_right * k;
    ans = ans % MOD;
  }

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

Measured memory_bytes: 256
import itertools

n=int(input())
A=list(map(int,input().split()))

n2=int(input())
B=list(map(int,input().split()))
S=set()
for i in range(1,n+1):
    S=S|set(map(sum,list(itertools.combinations(A,i))))
for j in B:
    if j in S:
        print('yes')
        
    else:print('no')


Measured memory_bytes: 32972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
using namespace std;
//typedef std::pair<std::string,double> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//グラフの隣接リスト
//VI g[200010];
//頂点の入次数を管理
int h[100010];

bool g[101][101];

//int dxy[5] = { -1, 0, 1, 0, -1 };

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

	int n, k; 
    while(cin >> n >> k, n||k){
	vector<string> v(n);
	REP(i, n) cin >> v[i];
	
	sort(v.begin(), v.end());
	set<string> se;
	do {
        string s="";
		for(int i=0; i<k; ++i) s += v[i];
        se.insert(s);
		
	} while (next_permutation(v.begin(), v.end()));
	
	cout << se.size() << endl;
    }
	return 0;
}


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

void swap(char *x,char *y){
  char temp;
  temp=*x;
  *x=*y;
  *y=temp;
  }

int main(void){
  int i,j,mini,N;
  char C[36][3];
  char D[36][3];
  char E[36][3];
  char key[2];
  char p,q,r,s;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",C[i]);
    D[i][0]=C[i][0];
    D[i][1]=C[i][1];
  }

  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if((int)C[j][1]<(int)C[j-1][1]){
	key[0]=C[j][0];
	key[1]=C[j][1];
	C[j][0]=C[j-1][0];
	C[j][1]=C[j-1][1];
	C[j-1][0]=key[0];
	C[j-1][1]=key[1];
      }
    }
  }

  for(i=0;i<N;i++){
    if(i!=0)printf(" ");
    printf("%c%c",C[i][0],C[i][1]);
    E[i][0]=C[i][0];
    E[i][1]=C[i][1];
  }
  printf("\n");

  for(i=0;i<N;i++){
    if(C[i][0]!=E[i][0])break;
  }
  if(i==N)printf("Stable\n");
  else printf("Not stable\n");


  
  for(i=0;i<N;i++){
    mini=i;
    for(j=i;j<N;j++){
      if(D[j][1]<D[mini][1]){
	mini=j;
      }
    }
    p=D[i][0];
    q=D[i][1];
    r=D[mini][0];
    s=D[mini][1];
    swap(&p,&r);
    swap(&q,&s);
    D[i][0]=p;
    D[i][1]=q;
    D[mini][0]=r;
    D[mini][1]=s;
  }

  for(i=0;i<N;i++){
    if(i!=0)printf(" ");
    printf("%c%c",D[i][0],D[i][1]);
  }
  printf("\n");

  for(i=0;i<N;i++){
    if(D[i][0]!=E[i][0])break;
  }
  if(i==N)printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

const int INF = 1e9;
const int MOD = 1000000007;

int main() {
  size_t N;
  cin >> N;
  string s;
  std::map<string, int> m;
  for (size_t i = 0; i < N; ++i) {
    cin >> s;
    m.insert(make_pair(s, i));
  }
  cout << m.size() << endl;

  return 0;
}


Measured memory_bytes: 19164
#include <bits/stdc++.h>
using namespace std;
#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define contests_de_diya_kar 0
#define PB push_back
#define MP make_pair
#define int long long
#define MOD ((long long) (1000*1000*1000 + 7))
#define inf (int) 2e15
#define exit(a, b) return cout << a, b;
#define eps (double)1e-8
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define vb vector<bool>
#define all(v) v.begin(), v.end()
#define ll long long 
#define pii pair<int, int>
#define mii map<int, int> 
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

const int MODULO = MOD;
int n;
bool vis[3][1001][4];
int dp[3][1001][4];
bool blocked[3][1001];

int rec (int row, int col, int type) {
	if (vis[row][col][type]) return dp[row][col][type];
	vis[row][col][type] = true;
	if (blocked[row][col]) {
		dp[row][col][type] = 0;
		return 0;
	}
	if (type == 0) {
		if (row >= 1) {
			if (col >= n - 1 && row != 2) {
				dp[row][col][type] = 0;
				return 0;
			}
			dp[row][col][type] += rec(row - 1, col, 2);
			dp[row][col][type] %= MODULO;
		}
	} 
	if (type == 1) {
		if (row <= 1) {
			if (col >= n - 1) {
				dp[row][col][type] = 0;
				return 0;
			}
			dp[row][col][type] += rec(row + 1, col, 3);
			dp[row][col][type] %= MODULO;
		}
	}
	if (type == 2) {
		if (col == 0 && row == 0) {
			dp[row][col][type] = 1;
			return dp[row][col][type];
		}
		if (col >= 1 && row < 2) {
			dp[row][col][type] += rec(row, col - 1, 0);
			dp[row][col][type] %= MODULO;
			dp[row][col][type] += rec(row, col - 1, 1);
			dp[row][col][type] %= MODULO;
		}
	}
	if (type == 3) {
		if (col >= 1 && row >= 1) {
			dp[row][col][type] += rec(row, col - 1, 0);
			dp[row][col][type] %= MODULO;
			dp[row][col][type] += rec(row, col - 1, 1);
			dp[row][col][type] %= MODULO;
		}
		else {
			dp[row][col][type] = 0;
			return dp[row][col][type];
		}
	}
}
signed main () {
	start_routine;
	
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif 

	const int maxn = 100000;
	vi ans(maxn + 1, inf);

	ans[0] = 0;
	for (int i = 1; i <= maxn; i += 1) ans[i] = i;
	int i = 1;
	for (int p = 6; p <= maxn; p *= 6) ans[p] = i;
	i = 1;
	for (int p = 9; p <= maxn; p *= 9) ans[p] = i;

	for (int i = 1; i <= maxn; i += 1) {
		if (i + 1 <= maxn) ans[i + 1] = min(ans[i] + 1, ans[i + 1]);
		int j = 1;
		for (int p = 6; p + i <= maxn; p *= 6) ans[i + p] = min(ans[i] + j, ans[i + p]);
		j = 1;
		for (int p = 9; p + i <= maxn; p *= 9) ans[i + p] = min(ans[i] + j, ans[i + p]);
	}

	int n;
	cin >> n;

	cout << ans[n];	
	end_routine;
}


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

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

  while(A > 0 && C > 0) {
    C -= B;
    if(C > 0) {
     A -= D;
    } else {
      break;
    }
  }

  string result;

  if (C > A) {
    result = "No";
  } else {
    result = "Yes";
  }

  cout << result << endl;

  return 0;
}

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

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

  vector<int> c(27);
  long long csum = 0;
  for (int i = 1; i <= 26; i++) {
    cin >> c.at(i);
    csum += c.at(i);
  }

  vector<vector<pair<int, int>>> s(d+1, vector<pair<int, int>>(27));
  for (int i = 1; i <= d; i++) {
    for (int j = 1; j <= 26; j++) {
      int ss;
      cin >> ss;
      s.at(i).at(j).first = ss;
      s.at(i).at(j).second = j;
    }
  }

  for (int i = 1; i <= d; i++) {
    sort(s.at(i).begin(), s.at(i).end());
  }

  vector<int> last(27, 0);
  long long curc = 0;
  long long satisfy = 0;
  for (int i = 1; i <= d; i++) {
    pair<int, int> t = s.at(i).at(26);
    curc += csum - (c.at(t.second) * (i - last.at(t.second)));
    last.at(t.second) = i;
    satisfy += t.first - curc;
    cout << t.second << endl;
  }

  return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



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

	int a,sum = 0,cnt = 0;
	for (int i = 0; i < n; i++) {
		sum = 0;
		for (int j = 0; j < m; j++) {
			cin >> a;
			sum += a * b[j];
		}
		if (sum + c > 0) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N, D := nextInt(), nextInt()
	count := 0
	for i := 0; i < N; i++ {
		X, Y := nextInt(), nextInt()
		if X*X+Y*Y <= D*D {
			count++
		}
	}
	fmt.Fprintf(out, "%d\n", count)
}


Measured memory_bytes: 5868
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int size1=s.size();
    int s_num=0;
    int couple_num=0;
    for(int i=0;i<size1;i++)
    {
        if(s.at(i)=='S')
        s_num++;
        else
        {
            if(s_num>0)
            {
                s_num--;
                couple_num++;
            }
        }  
    }
    cout<<size1-2*couple_num<<endl;
    return 0;
}

Measured memory_bytes: 640
// Stable_Sort.cs

using System;

class Stable_Sort {
	public static void Main() {

		string num = Console.ReadLine();
		int n = int.Parse(num);

		string[] arr = new string[n];

		string cards = Console.ReadLine();
		arr = cards.Split();

		string[] mem = new string[n];
		for(int i = 0; i < n; i++) {
			mem[i] = arr[i];
		}

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

				if((int)arr[i][1] < (int)arr[i - 1][1]) {
					Swap(ref arr[i], ref arr[i - 1]);
				}

			}
		}

		for(int i = 0; i < n; i++) {
			if(i != n - 1)
			Console.Write(arr[i] + " ");
			else
			Console.WriteLine(arr[i]);
		}
		Console.WriteLine("Stable");

		// ------------------------------- Not stable
		int min;
		int minn = 0;
		for(int i = 0; i < n - 1; i++) {
			min = mem[i][1];
			for(int j = 1 + i; j < n; j++) {

				if((int)mem[j][1] < min) {
					min = (int)mem[j][1];
					minn = j;
				}
			}
			if((int)mem[i][1] != min) {
				Swap(ref mem[i], ref mem[minn]);
			}

		}

		for(int i = 0; i < n; i++) {
			if(i != n - 1)
			Console.Write(mem[i] + " ");
			else
			Console.WriteLine(mem[i]);
		}

		string mem_str = "";
		string arr_str = "";

		for(int i = 0; i < n; i++) {
			mem_str += mem[i];
			arr_str += arr[i];
		}

		if(mem_str.CompareTo(arr_str) == 0)
		Console.WriteLine("Stable");
		else 
		Console.WriteLine("Not stable");


	}

	static void Swap(ref string x, ref string y) {
		string comp = x;
		x = y;
		y = comp;
		return;
	}
}

Measured memory_bytes: 9804
#include "bits/stdc++.h"
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target ("avx,avx2")

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)

void solve(){

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	if(s[(int)s.size()-1] == 's'){
		cout << s << "es" << "\n";
	}else{
		cout << s << "s" << "\n";
	}
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define V2(T, x, y) (x, vector<T>(y, 0))
template<typename T> struct Sum2 {
	typedef vector<vector<T>> A;
	A s;
	int X, Y;
	
	Sum2() { X = Y = -1; }
	Sum2(A & p) { init(p); }
	void init(A & p) {
		X = p.size();
		Y = p[0].size();
		s = A V2(T, X + 1, Y + 1);
		
		inc1(x, X) {
		inc1(y, Y) {
			s[x][y] = p[x - 1][y - 1];
		}
		}
		inc1(x, X) {
		inc1(y, Y) {
			s[x][y] += s[x - 1][y];
		}
		}
		inc1(x, X) {
		inc1(y, Y) {
			s[x][y] += s[x][y - 1];
		}
		}
	}
	T sum(int xl, int xh, int yl, int yh) { // [xl, xh) × [yl, yh)
		assert(inII(xl, 0, X));
		assert(inII(xh, 0, X));
		assert(inII(yl, 0, Y));
		assert(inII(yh, 0, Y));
		assert(xl <= xh);
		assert(yl <= yh);
		return s[xh][yh] - s[xh][yl] - s[xl][yh] + s[xl][yl];
	}
};

// ----

int n, k;
vector<vector<int>> p V2(int, 2000, 1000);

int main() {
	cin >> n >> k;
	inc(i, n) {
		int x, y; string c;
		cin >> x >> y >> c;
		if(c == "B") { x += k; }
		int z = (x / k + y / k) % 2 * k;
		x %= k; x += z;
		y %= k;
		p[x][y]++;
	}
	
	Sum2<int> s(p);
	int ans = 0, l = k * 2;
	incII(x, 0, l) {
	incII(y, 0, k) {
		int e = max(0, x - k);
		int f = min(l, x + k);
		int v =
			s.sum(0, e, y, k) +
			s.sum(e, x, 0, y) +
			s.sum(x, f, y, k) +
			s.sum(f, l, 0, y)
		;
		setmax(ans, v);
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 16128
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main()
 {
	int n;
	cin >> n;
	vector<int> hash(n-1);
	for(auto &x:hash)
		cin>>x;
	vector<int> ans(n,0);
	map<int,int> ne;
	for(auto  x: hash)
		ne[x]++;
	for(auto x:ne){
		ans[x.first-1]=x.second;
	}
	for(auto x:ans)
		cout<<x<<'\n';
}

//0 1 1 2 2


Measured memory_bytes: 13992
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		int max = Integer.MIN_VALUE;
		Scanner san = new Scanner(System.in);
		int listCount = san.nextInt();
		int[] list = new int[listCount];
		for(int i = 0; i < listCount; i++){
			list[i] = san.nextInt();
		}
		int min = list[0];
		for(int i = 1; i < listCount; i++){
			max = Math.max(max, list[i] - min);
			min = Math.min(min, list[i]);
		}
		System.out.println(max);
	}
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  ull K;
  ull N = 50;

  cin >> K;
  cout << N << endl;

  FOR(i, K % N) {
    cout << N + K / N + N - K % N << " ";
  }

  FOR1(i, K % N, N) {
    cout << N + K / N - K % N - 1 << " ";
  }

  cout << endl;

  return 0;
}


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

using namespace std;

string s[10],srev[10];
string H[5],W[5];
bool eq[10];

bool valid(int idx){
  for(int i = 0 ; i < 5 ; i++){
    if(W[idx][i] == H[i][idx]){
      return false;
    }
  }
  return true;
}

int solve(int idx,int S){
  if(S == (1<<10)-1){
    return 1;
  }
  int res = 0;
  for(int i = 0 ; i < 10 ; i++){
    if((S >> i) & 1) continue;
    if(idx < 5){
      H[idx] = s[i];
      res += solve(idx+1,S|(1<<i));
      if(!eq[i]){
        H[idx] = srev[i];
        res += solve(idx+1,S|(1<<i));
      }
    }else{
      W[idx-5] = s[i];
      if(valid(idx-5)){
        res += solve(idx+1,S|(1<<i));
      }
      if(!eq[i]){
        W[idx-5] = srev[i];
        if(valid(idx-5)){
          res += solve(idx+1,S|(1<<i));
        }
      }
    }
  }
  return res;
}

int main(){ 
  while(cin >> s[0], s[0] != "END"){
    memset(eq,false,sizeof(eq));
    string tmp = s[0];
    reverse(tmp.begin(),tmp.end());
    srev[0] = tmp;
    eq[0] = s[0] == srev[0];
    for(int i = 0 ; i < 9 ; i++){
      cin >> s[i+1];
      tmp = s[i+1];
      reverse(tmp.begin(),tmp.end());
      srev[i+1] = tmp;
      eq[i+1] = s[i+1] == srev[i+1];
    }
    cout << solve(0,0)/8 << endl;
  }
  return 0;
}

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

diff = [a - b for a, b in zip(A, B)]
diff.sort()
if sum(A) < sum(B):
    print(-1)
else:
    minus_sum = 0
    ans = 0
    for i in range(N):
        if diff[i] < 0:
            minus_sum += diff[i]
            ans += 1
        else:
            break

    for i in range(N - 1, 0, -1):
        if minus_sum >= 0:
            break
        else:
            ans += 1
            minus_sum += diff[i]

    print(ans)


Measured memory_bytes: 18356
// Aizu 1103: Board Arrangements for Concentration Gam...
// 2017.9.16 bal4u@uu

#include <stdio.h>
#include <string.h>

int rel[4][2];
char map[4][4];
int ans;

void combi(int k)
{
	int i, x, y, x2, y2;

	if (k == 9) { ans++; return; }
	for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) {
		if (map[y][x]) continue;
		map[y][x] = k;
		for (i = 0; i < 4; i++) {
			x2 = x + rel[i][0], y2 = y + rel[i][1];
			if (x2 < 0 || x2 >= 4 || y2 < 0 || y2 >= 4 || map[y2][x2]) continue;
			map[y2][x2] = k, combi(k+1), map[y2][x2] = 0;
		}
		map[y][x] = 0;
		return;
	}
	return;
}

int main()
{
	int i, x, y;

	while (scanf("%d", &x) && x < 4) {
		scanf("%d", &y), rel[0][0] = x, rel[0][1] = y;
		for (i = 1; i < 4; i++) scanf("%d%d", &x, &y), rel[i][0] = x, rel[i][1] = y;
		memset(map, 0, sizeof(map)), ans = 0; map[0][0] = 1;
		for (i = 0; i < 4; i++) {
			x = rel[i][0], y = rel[i][1];
			if (x >= 0 && y >= 0) map[y][x] = 1, combi(2), map[y][x] = 0;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1836
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.nextLine();
		String[] b = x.split(" ");
		int[] e = new int[3];
		e[0] = Integer.parseInt(b[0]);
		e[1] = Integer.parseInt(b[1]);
		e[2] = Integer.parseInt(b[2]);
		Arrays.sort(e);
		System.out.println(e[0] + " " + e[1] + " " + e[2]);

	}
}

Measured memory_bytes: 26176
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  int cnt5=0;
  int cnt7=0;
  for(int i=0;i<3;i++){
    if(a[i]==5) cnt5++;
    if(a[i]==7) cnt7++;
  }

  if(cnt5==2 && cnt7==1){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

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

  if(c == 'A')
    cout << 'T' << endl;
  else if(c == 'T')
    cout << 'A' << endl;
  else if(c == 'G')
    cout << 'C' << endl;
  else if(c == 'C')
    cout << 'G' << endl;

  return 0;
}

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

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	char dif='A'-'a';
	cout<<char(a[0]+dif)<<char(b[0]+dif)<<char(c[0]+dif)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 510
#define pa pair<int,int>
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int n,ans[N*N],id[N*N],cnt[N],num=0;
pa a[N];
int main(){
//	freopen("a.in","r",stdin);
	n=read();for(int i=1;i<=n;++i){
		int x=read();id[x]=i;a[i]=make_pair(x,i);
	}sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		int x=a[i].second,pos=a[i].first;ans[pos]=x;cnt[x]=n-x;
		for(int owo=1;owo<x;++owo){
			while(ans[++num]&&num<=pos) continue;
			if(num>pos){puts("No");return 0;}
			ans[num]=x;
		}
	}queue<int>q;
	for(int i=1;i<=n*n;++i){
		if(id[i]&&cnt[id[i]]) q.push(id[i]);
		if(ans[i]) continue;
		if(q.empty()){puts("No");return 0;}int x=q.front();
		ans[i]=x;if(--cnt[x]==0) q.pop();
	}puts("Yes");
	for(int i=1;i<=n*n;++i) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 2944