akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct SegTree {
  int n_count;
  vector<ll> pos;

  SegTree(ll N) {
    n_count = 1; while(n_count<N) n_count<<=1;
    pos.resize(2*n_count, 0);
  }

  ll operator[](const ll &k) const { return pos[k+n_count]; }

  void set(ll k, const ll x) { pos[k+n_count] = x; }
  void build() { for (int i=n_count-1; i>=0; i--) pos[i] = pos[i*2] + pos[i*2+1]; }
  void update(ll k, const ll x) { set(k,x); k += n_count; while(k >>= 1) pos[k] = pos[k*2] + pos[k*2+1]; }
  ll query(ll a,ll b) {
    ll L = 0, R = 0;
    for ( a+=n_count, b+=n_count; a<b; a>>=1, b>>=1 ) {
      if (a&1) { L+=pos[a]; a++; }
      if (b&1) { b--; R+=pos[b]; }
    }
    return L + R;
  }

};

int main() {
  ll N; cin >> N;
  ll a[N]; rep(i,N) cin >> a[i];
  ll l = 0, r = pow(10,9);
  while(l!=r) {
    ll mid = (l+r+1)/2;
    ll pm[N+1] = {};
    rep(i,N) pm[i+1] = pm[i] + (a[i]>=mid ? 1 : -1);
    SegTree tree(2*N+3);
    ll count = 0;
    rep(i,N+1) {
      count += tree.query(0,pm[i]+N+1);
      tree.update(pm[i]+N,tree[pm[i]+N]+1);
    }
    if (count>=(N*(N+1)/2+1)/2) l = mid;
    else r = mid-1;
    // rep(i,N) cout << pm[i] << " "; cout << endl;
    // cout << mid << ":" << count << endl;
  }
  int result = l;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 6012
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

    double l;
    cin>>l;

    cout<<std::setprecision(10)<<(l*l*l)/27<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;                                                                                                                   
class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int cards[][] = new int[4][13];
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 13; j++){
                cards[i][j] = 0;
            }
        }
        for(int c = 0; c < n; c++){
            String mark = in.next();
            int val = in.nextInt();
            switch(mark){
                case "S":
                    cards[0][val -1] = 1;
                    break;
                case "H":
                    cards[1][val -1] = 1;
                    break;
                case "C":
                    cards[2][val -1] = 1;
                    break;
                case "D":
                    cards[3][val -1] = 1;
            }
        }
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 13; j++){
                if(cards[i][j] == 0){
                    switch(i){
                        case 0:
                            System.out.println("S" + " " + (j + 1));
                            break;
                        case 1:
                            System.out.println("H" + " " + (j + 1));
                            break;
                        case 2:
                            System.out.println("C" + " " + (j + 1));
                            break;
                        case 3:
                            System.out.println("D" + " " + (j + 1));
                    }
                }
            }
        }
    }
}                            

Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> sum(n + 1, 0);
    rep(i, n)
    {
        int a;
        cin >> a;
        sum[i + 1] = sum[i] + a;
        //        cout << sum[i + 1] << endl;
    }
    int max_sum = 0;
    rep(i, n - k + 1)
    {
        int a = sum[i + k] - sum[i];
        //        cout << a << endl;
        chmax(max_sum, a);
    }
    printf("%.12f\n", (max_sum + k) / 2.0);
    //    cout << (max_sum + k) / 2.0 << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!(i % 3 == 0 || i % 5 == 0)) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


int N,M,Q;
struct abcd {
    int a,b,c,d;
};
ve<abcd> A;

int ans = 0;

void rec(int n,vi B = {}, int las = 1){
    
    if(n == N){
        //outve(B);
        int an = 0;
        rep(i,Q){
            if(B[A[i].b-1] - B[A[i].a-1] == A[i].c) an += A[i].d;
        }
        chmax(ans,an);
        
        return;
    }
    
    reps(i,las,M+1){
        B.pb(i);
        rec(n+1,B,i);
        B.pop_back();
        //cout << B.size() << endl;
    }
    
}


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

    cin >> N >> M >> Q;
    A.resize(Q);
    rep(i,Q) cin >> A[i].a >> A[i].b >> A[i].c >> A[i].d;
    
    
    rec(0);
    cout << ans << endl;
    
    
    return 0;
}


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

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(void){
   int n, count = 0, x;
   long long result_p = 0, result_q =0;
   
   cin >> n;
   
   int p[n], q[n];
   
   for(int i = 0; i < n; i++){
       cin >> p[i];
   }
    for(int i = 0; i < n; i++){
       cin >> q[i];
   }
   
   for(int i = 0; i < n; i++){
       for(int j = 0; j < i; j++){
           if(p[j] < p[i]){
               count++;
           }
       }
       x = p[i] - count;
       count = 0;
       result_p += (x - 1)*facctorialMethod(n - 1 - i);
   }
    
    for(int i = 0; i < n; i++){
       for(int j = 0; j < i; j++){
           if(q[j] < q[i]){
               count++;
           }
       }
       x = q[i] - count;
       count = 0;
       result_q += (x - 1)*facctorialMethod(n - 1 - i);
   }
   
   cout << abs(result_p - result_q) << endl;
   
   return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

params = input().split()
n = int(params[0])
m = int(params[1])

penaltyCount = dict()
penaltyCount = defaultdict(lambda: 0, penaltyCount)

correct = 0
penalty = 0

for i in range(m):
    submission = input().split()
    p = int(submission[0]) - 1
    status = submission[1]

    if penaltyCount[p] == -1:
        continue
    if status == "WA":
        penaltyCount[p] += 1
    else:
        penalty += penaltyCount[p]
        penaltyCount[p] = -1
        correct += 1

print(str(correct) + " " + str(penalty))



Measured memory_bytes: 15460
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;

/*
const int MAX_E=2*(100-1);
const int MAX_V=100;
const long long int INF=100000000;
struct edge { int from,to,cost;};
edge es[MAX_E];
//int d[MAX_V];
int V,E;
void shortest_path(int s,int e,vector<int>& d);
int main(){
	int n,k;
	while(cin >> n >> k&&n!=0&&k!=0){
		int V=n;
		int E=2*(n-1);
		vector<int> land(V);
		int l=0;
		for(int i=0; i<E; ++i){
			es[i].cost=-1;
			es[i].from=-1;
			es[i].to=-1;
		}
		for(int i=0; i<k; ++k){
			int m;
			cin >> m;
			if(m==0){
				int a,b;
				cin >> a >> b;
				shortest_path(a,b,land);
				cout << land[b] << "\n";
			} else if(m==1){
				int c,d,e;
				cin >> c >> d >> e;
				es[l].from=c;
				es[l].to=d;
				es[l].cost=e;
				es[l+1].from=d;
				es[l+1].to=c;
				es[l+1].cost=e;
				l+=2;
			}
		}
	}
	return 0;
}

void shortest_path(int s,int e,vector<int>& d){
	cout << "ok1\n";
	for(int i=0; i<V; ++i) {
		cout << "ok\n";
		d[i]=INF;
	}
	d[s]=0;
	while(true){
		cout << "ok2\n";
		bool update=false;
		for(int i=0; i<E; ++i){
			edge e=es[i];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				update=true;
			}
		}
		if(!update) break;
	}
}
*/
/*
const int INF=100000000;
int main(){
	int n;
	while(cin >> n&&n!=0){
		vector<int> color;
		for(int i=0; i<n; ++i){
			int t;
			cin >> t;
			color.push_back(t);
		}
		int maxDel=INF;
		for(int i=0; i<n; ++i){
			for(int j=1; j<=3; ++j){
				if(color[i]==j) continue;
				int up=i-1;
				int down=i+1;
				int sum=0;
				int c=1;
				int col=j;
				while(1){
					int nCal=-1;
					while(1){
						if(up<0) break;
						if(color[up]!=col){
							nCal=color[up];
							break;
						}
						up--;
						c++;
					}
					while(1){
						if(down>=n) break;
						if(color[down]!=col){
							if(nCal==-1) nCal=color[down];
							break;
						}
						++down;
						++c;
					}
					if(c>=4){
						sum+=c;
					} else{
						break;
					}
					c=0;
					if(nCal==-1){
						break;
					}else{
						col=nCal;
					}
				}
				maxDel=min(maxDel,n-sum);
			}
		}
		cout << maxDel << "\n";
	}
	return 0;
}
*/

int main(){
	string str;
	cin >> str;
	int n,cnt=0;
	cin >> n;
	for(int i=0; i<n; ++i){
		string tmp;
		cin >> tmp;
		tmp += tmp;
		if(tmp.find(str)!=-1) ++cnt;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct E {
  int u,v,c;
  E(int u,int v,int c):u(u),v(v),c(c){}
};
vector<int> g[2][2505];
vector<bool> path;
void dfs(int x, int u){
  if(path[u]) return;
  path[u] = true;
  for(int v:g[x][u]) dfs(x,v);
}
int main() {
  int n,m,p;
  cin >> n >> m >> p;
  vector<E> es;
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    --a; --b; c=p-c;
    es.emplace_back(a,b,c);
    g[0][a].emplace_back(b);
    g[1][b].emplace_back(a);
  }
  sort(es.begin(),es.end(),[](E l,E r){ return P(l.u,l.v) < P(r.u,r.v); });

  vector<bool> used(n,true);
  path = vector<bool>(n); dfs(0,0);
  rep(i,n) used[i] = used[i] && path[i];
  path = vector<bool>(n); dfs(1,n-1);
  rep(i,n) used[i] = used[i] && path[i];

  vector<int> d(n,1e9);
  d[0] = 0;
  while(true){
    static int cnt = 0;
    bool loop = false;
    rep(i,m){
      int u = es[i].u, v = es[i].v, c = es[i].c;
      if(!used[u]||!used[v]) continue;

      if(d[u]+c < d[v]){
        d[v] = d[u]+c;
        loop = true;
      }
    }
    if(++cnt>n){
      cout << -1 << endl;
      return 0;
    }
    if(!loop) break;
  }
  cout << max(0,-d[n-1]) << endl;
}


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

int main() {
	int n, m; cin >> n >> m;
	vector<int> s(m), c(m);
	rep(i, m) cin >> s[i] >> c[i];
	for (int i = 0; i < 1000; ++i) {
		string t = to_string(i);
		if (t.size() != n) continue;
		bool elf = true;
		rep(i, m) {
			if (t[s[i] - 1] != char(c[i] + '0')) elf = false;
		}
		if (elf) {
			cout << t << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//

int main() {
	cin >> N;
	vpll A(N);
	for (i = 0; i < N; i++) {
		ll x, l;
		cin >> x >> l;
		A[i]=make_pair(x - l, x + l);
	}
	sort(A.begin(), A.end(),pairCompare);
	ll border = -INF;
	for (i = 0; i < N; i++) {
		if (border <= A[i].first) {
			ans++;
			border = A[i].second;
			//cout << A[i].first << " " << A[i].second << " " << border << endl;
		}
	}
	cout << ans;
}


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


int main()
{
    int X,Y;
    cin>>X>>Y;
    for(int c=0;c<=X;c++) {
        if(c*2+(X-c)*4 == Y) {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

int w, h, xs, ys, xg, yg, board[105][105], start_color;

int dfs(int x, int y){
  int i;
  if(board[x][y] != start_color)return 0;
  if(x == xg && y == yg)return 1;
  board[x][y] = 0;
  int xi[] = {0, 1, 0, -1}, yi[] = {1, 0, -1, 0};
  for(i = 0;i < 4;i++)
    if(dfs(x + xi[i], y + yi[i]))
      return 1;

  return 0;
}

int main(){
  int n, c, d, x, y, i, j;
  while(1){
    memset(board, 0, sizeof(board));
    scanf("%d%d", &w, &h);
    if(w == 0 && h == 0)return 0;
    scanf("%d%d", &xs, &ys);
    scanf("%d%d", &xg, &yg);
    scanf("%d", &n);
    while(n--){
      scanf("%d%d%d%d", &c, &d, &x, &y);
      if(d == 1){
	for(i = x;i < x + 2;i++)
	  for(j = y;j < y + 4;j++)
	    board[i][j] = c;
      }
      if(d == 0){
	for(i = x;i < x + 4;i++)
	  for(j = y;j < y + 2;j++)
	    board[i][j] = c;
      }
    }
    start_color = board[xs][ys];
    if(start_color != 0 && dfs(xs, ys))
      puts("OK");
    else
      puts("NG");
  }
}

Measured memory_bytes: 632
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <string>

using namespace std;

// stringをintに
// string a = "123";
// stoi(a)
//
// intをstringに
// int a = 123;
// to_string(a)
//
// charをintに
// char a = '1';
// (int)a - 48 // asciiコードを値にする

// stringのソート
// string str = "abccba";
// sort(str.begin(), str.end());
//
// ハッシュテーブル
// unordered_map<string, int> mp;
// mp["aabbcc"] = 0;

// 配列Aにcinする
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }

  vector<int> C(50);
  for (int i = 0; i < 50; i++) {
    C.at(i) = 0;
  }
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i);
  }

  int sum = 0;
  //cout << "" << endl;
  for (int i = 0; i < N; i++) {
    sum += B.at(A.at(i) - 1);
    //cout << A.at(i) << endl;
    if (i < N - 1 && A.at(i + 1) - A.at(i) == 1) {
      //cout << "A.at(i) = "  << A.at(i) << endl;
      //cout << "C.at(A.at(i)-1) = "  << C.at(A.at(i)-1) << endl;
      sum += C.at(A.at(i)-1);
    }
  }
  cout << sum << endl;

  return 0;
}

// 標準入出力
//int main() {
//	int a, b;
//	cin >> a >> b;
//  if (a * b % 2 == 0) {
//	  cout << "Even" << endl;
//  } else {
//	  cout << "Odd" << endl;
//  }
//  return 0;
//}

// 文字列を1文字ずつループ
//int main() {
//  string str;
//  cin >> str;
//  int sum = 0;
//  for(int i = 0; i < (int)str.size(); ++i){
//    char ch = str[i];
//
//    if (ch == '1') {
//      sum++;
//    }
//  }
//  cout << sum << endl;
//  return 0;
//}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <string>
using namespace std;
int main(){
    string s;
    int res=0;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+') res++;
        else res--;
    }
    cout<<res<<endl;
    return 0;
}





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


using namespace std;

int main() {
	int p,q,r;
	cin >> p >> q >> r;
	
	cout << p+q+r- max(p,max(q,r)) << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fast() ios_base::sync_with_stdio (false); cin.tie (NULL)

using namespace std;
const unsigned int MOD = 1e9+7;

int N;

void solve () {
    cin >> N;
    vector <int> height(N);
    for (int &x : height) cin >> x;
    vector <int> dp(N);
    for (int i=1;i<N;i++) {
        dp[i] = min (dp[i-1] + abs (height[i]-height[i-1]), (i-2 < 0 ? INT_MAX : dp[i-2] + abs (height[i] - height[i-2])));
    }
    
    
    cout << dp[N-1] << endl;
}

int main()
{
	
    fast();
    solve ();
    return 0;
}





Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
using namespace std;
double n;
double dp[310][310][310];
void solve (int c1, int c2, int c3) {
	if (c1 == 0 && c2 == 0 && c3 == 0) return;
	if (dp[c1][c2][c3] > 0) return;
	dp[c1][c2][c3] = n;
	if (c1 > 0) {
		solve(c1-1, c2, c3);
		dp[c1][c2][c3] += c1*dp[c1-1][c2][c3];
	}
	if (c2 > 0) {
		solve(c1+1, c2-1, c3);
		dp[c1][c2][c3] += c2*dp[c1+1][c2-1][c3];
	}
	if (c3 > 0) {
		solve(c1, c2+1, c3-1);
		dp[c1][c2][c3] += c3*dp[c1][c2+1][c3-1];
	}
	dp[c1][c2][c3] /= (c1+c2+c3);
}
int main () {
	cout << fixed << setprecision(15);
	cin >> n;
	int c1 = 0, c2 = 0, c3 = 0;
	int ai;
	for (int i=0; i<n; i++) {
		cin >> ai;
		if (ai == 1) c1++;
		if (ai == 2) c2++;
		if (ai == 3) c3++;
	}
	dp[0][0][0] = 0;
	solve(c1, c2, c3);
	cout << dp[c1][c2][c3] << endl;
}

Measured memory_bytes: 114288
#include<iostream>
#define A 1000000007
using namespace std;
typedef unsigned long long ull;

ull dp[100001] = {0};

ull fact(ull n){
	if(dp[n]){
		return dp[n];
	}else if(!n){
		return 1;
	}else{
		return dp[n] = (n * (fact(n - 1) % A) % A);
	}
}

int main(){
	ull n, m; cin >> n >> m;
	if(n == m){
		cout << 2 * ((fact(n) % A) * (fact(m) % A) % A) % A << endl;
	}else if(n - m == 1 || n - m == -1){
		cout << (fact(n) % A) * (fact(m) % A) % A << endl;
	}else{
		cout << 0 << endl;
	}
	return 0;
}

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

int main(){
  int  N, A , B;
  cin >> N >> A >> B;
  vector<int> P(N);
  for(int i = 0; i < N; i++) cin >> P[i];
  sort(P.begin(), P.end() ,greater<int>());
  
  int c1, c2, c3; 
  c1 = 0,c2 =0,c3 = 0;
  for(int i = 0; i < N; i++){
  if(P[i] <= A){
    c1++;
  }else if(P[i] >= A + 1 && P[i] <= B){
    c2++;
  }else if(P[i] >=B){
    c3++;
  }
}
cout << min(c1,min(c2,c3));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans=0;
char s[4040];
int n;
int sr[4040],sg[4040],sb[4040];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	sr[0]=0;
	sg[0]=0;
	sb[0]=0;
	int i=1,j=1,k=1;
	while(i<=n)
	{
		sr[i]+=sr[i-1]+(s[i]=='R');
		sg[i]+=sg[i-1]+(s[i]=='G');
		sb[i]+=sb[i-1]+(s[i]=='B');
		++i;
	}
	j=1;
	while(j<n)
	{
		k=j+1;
		while(k<=n)
		{
			if(s[j]!=s[k])
			{
				if(((s[j]=='R')&&(s[k]=='G'))||((s[j]=='G')&&(s[k]=='R'))) ans+=sb[j-1];
				if(((s[j]=='R')&&(s[k]=='B'))||((s[j]=='B')&&(s[k]=='R'))) ans+=sg[j-1];
				if(((s[j]=='B')&&(s[k]=='G'))||((s[j]=='G')&&(s[k]=='B'))) ans+=sr[j-1];
				int tt=k-j;
				if(j-tt>=1)
				{
					i=j-tt;
					if((s[i]!=s[j])&&(s[i]!=s[k])&&(s[j]!=s[k])) --ans;
				}
			}
			++k;
		}
		++j;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

const int inf = (int) 2.01e9;

const int N = 1234567;

int a[N], b[N], c[N];

int main() {
  int X, Y, Z;
  scanf("%d %d %d", &X, &Y, &Z);
  int n = X + Y + Z;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", a + i, b + i, c + i);
    ans -= c[i];
    a[i] = c[i] - a[i];
    b[i] = c[i] - b[i];
    c[i] = c[i] - c[i];
  }
  set < pair <int, int> > free_a, free_b, not_free_a, not_free_b;
  for (int i = 0; i < n; i++) {
    free_a.insert(make_pair(a[i], i));
    free_b.insert(make_pair(b[i], i));
  }
  int rX = X, rY = Y;
  for (int it = 0; it < X + Y; it++) {
    int ca = (*free_a.begin()).first;
    int cb = (*free_b.begin()).first;
    int cab = (*not_free_a.begin()).first + (*free_b.begin()).first;
    int cba = (*not_free_b.begin()).first + (*free_a.begin()).first;
    if (rX == 0) {
      ca = cab = inf;
    }
    if (rY == 0) {
      cb = cba = inf;
    }
    int best = min(min(ca, cb), min(cab, cba));
    ans += best;
    if (ca == best) {
      int id = (*free_a.begin()).second;
      free_a.erase(make_pair(a[id], id));
      free_b.erase(make_pair(b[id], id));
      not_free_b.insert(make_pair(b[id] - a[id], id));
      rX--;
      continue;
    }
    if (cb == best) {
      int id = (*free_b.begin()).second;
      free_a.erase(make_pair(a[id], id));
      free_b.erase(make_pair(b[id], id));
      not_free_a.insert(make_pair(a[id] - b[id], id));
      rY--;
      continue;
    }
    if (cab == best) {
      int id1 = (*not_free_a.begin()).second;
      int id2 = (*free_b.begin()).second;
      not_free_a.erase(not_free_a.begin());
      not_free_b.insert(make_pair(b[id1] - a[id1], id1));
      free_a.erase(make_pair(a[id2], id2));
      free_b.erase(make_pair(b[id2], id2));
      not_free_a.insert(make_pair(a[id2] - b[id2], id2));
      rX--;
      continue;
    }
    if (cba == best) {
      int id1 = (*not_free_b.begin()).second;
      int id2 = (*free_a.begin()).second;
      not_free_b.erase(not_free_b.begin());
      not_free_a.insert(make_pair(a[id1] - b[id1], id1));
      free_a.erase(make_pair(a[id2], id2));
      free_b.erase(make_pair(b[id2], id2));
      not_free_b.insert(make_pair(b[id2] - a[id2], id2));
      rY--;
      continue;
    }
    assert(false);
  }
  cout << -ans << endl;
  return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	int64_t l[n]; rep(i,n) cin >> l[i];
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			for(int k = j + 1; k < n; ++k) {
				if(l[i] == l[j]) continue;
				if(l[k] == l[j]) continue;
				if(l[k] == l[i]) continue;
				if(l[i] + l[j] <= l[k]) continue;
				if(l[k] + l[j] <= l[i]) continue;
				if(l[k] + l[i] <= l[j]) continue;
				++ans;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
 
	ll n,s=0;
	cin>>n;
	ll h[n];
	for(ll i=0;i<n;i++)
	{
	    cin>>h[i];
	   
	}
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	for(ll i=2;i<n;i++)
	{
	    ll d1=abs(h[i]-h[i-1]);
	    ll d2=abs(h[i]-h[i-2]);
	    dp[i]=min(dp[i-1]+d1,dp[i-2]+d2);
	    
	}
	cout<<dp[n-1]<<endl;
}
	

  

Measured memory_bytes: 1920
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>

using namespace std;
int a[1000010];
int main(){
	int n,k;
	long long sum=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=k;i++){
		sum+=a[i];
	}
	printf("%lld\n",sum);
	
}

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

int main()
{
	int N, A, B;
	cin >> N >> A >> B;

	if (N*A > B)
	{
		cout << B << endl;
	}
	else
	{
		cout << N * A << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define all(x) x.begin(),x.end()
#define ss second
#define ff first
#define mit map<ll,ll>::iterator
#define sit unordered_set<ll>::iterator
#define lit list<ll>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pf push_front
#define printf __mingw_printf
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vec4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
int main()
{
     io;
    //string hudai(1000000,'a');
    int T=1;
   // cin>>T;
     for(int cas=1;cas<=T;cas++)
    {
        ll N,W;
        cin>>N>>W;
        vl w(N+1),v(N+1);
        for(ll i=1;i<=N;i++)
        {
            cin>>w[i]>>v[i];
        }
        vector<vl> dp(N+1,vl(W+1,0));
        for(ll i=1;i<=N;i++)
        {
            for(ll j=1;j<=W;j++)
            {
                if(w[i]<=j)
                {
                    dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
                }
                else dp[i][j]=dp[i-1][j];
            }
        }
        cout<<dp[N][W];

    }
    return 0;
}


Measured memory_bytes: 83208
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	d := 1
	ans := 0
	for i := 0; i < 3; i++ {
		r := n % 10
		switch r {
		case 1:
			r = 9
		case 9:
			r = 1
		}
		ans += d * r
		d *= 10
		n /= 10
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
n = int(input())
a = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    S = ''.join(s)
    if S in a:
        a[S] += 1
    else:
        a[S] = 1

for j in a.values():
    ans += j * (j-1) // 2
print(ans)

Measured memory_bytes: 17932
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int n;
int a[111111];
int b[111111];
map<int,int> m;
int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b,b+n);
  
  for(int i = 0; i < n; i++){
    m[b[i]] = i;
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    if(m[a[i]]%2 != i%2)
      ans++;
  }

  cout << ans/2 << endl;
}



Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
string s;
vector<int> oper[2];
int x,y;
int x_cnt, y_cnt;
int dp[2][4002][16002];

bool dfsx(int idx, int cx, bool flag) {
  if (dp[0][idx][cx]>=0) return dp[0][idx][cx];
  if (idx==oper[0].size()) return cx==x+8001;
  bool ret = dfsx(idx+1, cx+oper[0][idx], true);
  if (flag) ret |= dfsx(idx+1, cx-oper[0][idx],true);
  dp[0][idx][cx] = ret;
  return ret;
}

bool dfsy(int idx, int cy) {
  if (dp[1][idx][cy]>=0) return dp[1][idx][cy];
  if (idx==oper[1].size()) return cy==y+8001;
  bool ret = dfsy(idx+1, cy+oper[1][idx]) || dfsy(idx+1, cy-oper[1][idx]);
  dp[1][idx][cy] = ret;
  return ret;
}


int main() {
  cin >> s;
  cin >> x >> y;
  int cnt=0;
  bool flag=false;
  bool xdir=false;
  rep(i, (int)s.size()) {
    if (i==0 && s[i]=='T') xdir=true;
    if (s[i]=='F') cnt++;
    else {
      if (cnt) oper[flag].push_back(cnt);
      flag = !flag;
      cnt=0;
    }
  }

  if (cnt) oper[flag].push_back(cnt);
  rep(k, 2) rep(i, 4002) rep(j, 16002) dp[k][i][j] = -1;
  string ans = dfsx(0, 8001, xdir) & dfsy(0, 8001)?"Yes":"No";
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 504112
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}
static const ll INF = 1e18;

int main() {
  int x, n; cin >> x >> n;
  vector<bool> v(n+1, false);
  rep(i, n){
    int p; cin >> p;
    v[p] = true;
  }

  int ans = 0;
  reps(i, 101){
    if(v[i]) continue;
    if(abs(x-ans)>abs(x-i)){
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3584
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		while(true){
			int n=s.nextInt();
			if(n==0)System.exit(0);
			String str=s.next();
			for(int i=0;i<n;i++){
				char now=str.charAt(0);
				int times=0;
				StringBuffer next=new StringBuffer("");
				for(int j=0;j<str.length();j++){
					if(now==str.charAt(j))times++;
					else{
						next.append(""+times+now);
						now=str.charAt(j);
						times=1;
					}
				}
				if(times>0)next.append(""+times+now);
				str=next.toString();
				//System.out.println(str);
			}
			System.out.println(str);
		}
	}
}

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

int main(){
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='a')a++;
        else if(s[i]=='b')b++;
        else c++;
    }
    if(a==1 && b==1 && c==1)cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> d;
	copy_n(istream_iterator<int>(cin), n, back_inserter(d));
	
	sort(d.begin(), d.end());
	int gap = d[n/2] - d[n/2 - 1];
	
	if (gap == 0)
		cout << 0 << '\n';
	else
		cout << gap << '\n';
}


Measured memory_bytes: 892
mod = 2019
l,r = map(int,input().split())
INF = float("inf")
if (r-l) >= mod:
    print(0)
else:
    a = l % mod 
    b = r%mod
    if b > a:
        m = +INF
        for i in range(a,b+1):
            for j in range(i+1,b+1):
                curr = (i*j) % mod
                if curr < m:
                    m =curr
        print(m)
    else:
        print(0)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;//a以上b以下の回分数の数を求める
  cin >> a >> b;
  int cnt = 0;
  for(int i=a;i<=b;i++){
    int d5 = i / (int)(pow(10,4));
    int d4 = (i - d5*10000) / (int)(pow(10,3));
    int d3 = (i - d5*10000 - d4*1000) / (int)(pow(10,2));
    int d2 = (i - d5*10000 - d4*1000 - d3*100) / (int)(pow(10,1));
    int d1 = (i - d5*10000 - d4*1000 - d3*100 - d2*10) / (int)(pow(10,0));
    if((d5 == d1) && (d4 == d2)){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <array>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int dpa[n];
    int dpb[n];
    int dpc[n];
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for (int i=0; i<n; ++i){
        cin >> a[i] >> b[i] >> c[i];
        dpa[i] = 0;
        dpb[i] = 0;
        dpc[i] = 0;
    }
    for (int i=0; i<n; ++i){
        if(i == 0){
            dpa[0] = a[0];
            dpb[0] = b[0];
            dpc[0] = c[0];
        }
        else {
            dpa[i] = max(dpb[i-1] + a[i], dpc[i-1] + a[i]);
            dpb[i] = max(dpa[i-1] + b[i], dpc[i-1] + b[i]);
            dpc[i] = max(dpa[i-1] + c[i], dpb[i-1] + c[i]);
        }
    }
    int answer = max(dpa[n-1], max(dpb[n-1], dpc[n-1]));
    cout << answer << endl;
    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll x;

int main() {
   cin >> x;

   int i = 0;
   ll dist = x;
   for ( ; ; i++) {
      dist -= i;
      if (dist <= 0) {
         cout << i << endl;
         return 0;
      }
   }

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S,T;
	cin>>S>>T;
	int c=T.size(),t=T.size(),s=S.size();
	for(int i=0;i<s-t+1;i++){
		int q=0;
		for(int j=0;j<t;j++){
			if(T[j]==S[j+i]){
				q++;
			}
		}
		if(c>t-q){
			c=t-q;
		}
	}
	cout<<c;
}


Measured memory_bytes: 3588
n = int(input())
tour = [0]*20
for i in range(1<<n):
    tmp = 0
    a = int(input())
    while tour[tmp] != 0:
        a = abs(tour[tmp]-a) if a!=tour[tmp] else a
        tour[tmp] = 0
        tmp += 1
    tour[tmp] = a
print(tour[n])


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}


signed main() {
	int n;
	cin >> n;
	cout << n * n * n << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

  int a, b;
  cin >> a >> b;

  cout << max(0, a - 2*b) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int n;
	
	cin >> n;

	int a[n];
	
	map<int, int> even;
	map<int, int> odd;
	
	rep(i, n)
	{
		cin >> a[i];
		if (i & 0x01)
		{
			odd[a[i]]++;
		}
		else
		{
			even[a[i]]++;
		}
	}

	map<int, int>::iterator ite = even.begin();

	int em[2];
	int em_v[2];

	memset(em, 0, sizeof(em));
	memset(em_v, 0, sizeof(em_v));
	
	for(; ite != even.end(); ite++)
	{
		if(ite->second >= em[0])
		{
			em[1] = em[0];
			em_v[1] = em_v[0];
			em[0] = ite->second;
			em_v[0] = ite->first;
		}
		else if (ite->second >= em[1])
		{
			em[1] = ite->second;
			em_v[1] = ite->first;
		}
	}

	map<int, int>::iterator ito = odd.begin();

	int om[2];
	int om_v[2];

	memset(om, 0, sizeof(om));
	memset(om_v, 0, sizeof(om_v));
	
	for(; ito != odd.end(); ito++)
	{
		if(ito->second >= om[0])
		{
			om[1] = om[0];
			om_v[1] = om_v[0];
			om[0] = ito->second;
			om_v[0] = ito->first;
		}

		else if (ito->second >= om[1])
		{
			om[1] = ito->second;
			om_v[1] = ito->first;
		}
	}
	int count = 0;
	if (om_v[0] == em_v[0])
	{
		if (om[1] > em[1])
		{
			count = n - om[1] - em[0];
		}
		else
		{
			count = n - om[0] - em[1];
		}
	}
	else
	{
		count = n - om[0] - em[0];
	}

	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,K;
	cin >> N >> K;
	string S;
	cin >> S;
	int L = 0;
	int R = 0;
	for(int i = 0;i < N;i++) {
		if(S.at(i) == 'L') {
			L++;
		}
		else {
			R++;
		}
	}
	int A = 0;
  	int C = 0;
	char s = S.at(0);
	bool B = false;
	for(int i = 1;i < N;i++) {
		if(S.at(i) != s) {
			C = i + 1;
			if(i == N - 1) {
				if(A == K) {
					C = N;
				}
				else {
					A == N;
				}
			}
			if(B == true) {
				continue;
			}
			A++;
			B = true;
			if(A == K + 1) {
				A = i;
				break;
			}
		}
		else {
			B = false;
		}
	}
	if(A <= K) {
		A = C;
	}
	for(int i = 0;i < A;i++) {
		S.at(i) = s;
	}
	int ret = 0;
	for(int i = 0;i < N - 1;i++) {
		if(S.at(i) == S.at(i + 1)) {
			ret++;
		}
	}
	cout << ret << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  long long K, A, B;
  cin >> K >> A >> B;

  if (A + 2 >= B || K < A - 1) {
    cout << K + 1 << endl;
    return 0;
  } else {
    long long tot = A;
    long long cnt = K - A + 1;
    if ((K - A) % 2 == 0) tot++, cnt--;
    tot += (B - A) * (cnt / 2);
    cout << tot << endl;
  }
}

Measured memory_bytes: 256
import scala.io.StdIn._



object Main extends App {
  var n = readInt()
  while (n != 0) {
    val parents = readLine.trim.split(' ').map(_.toInt - 1)
    val lengths = readLine.trim.split(' ').map(_.toInt)
    val allRemove = lengths.sum
    if (n == 2) {
      println(allRemove)
    }else {
      val islands = Array.fill(n) {
        Nil: List[Bridge]
      }
      for (i ← parents.indices) {
        islands(i + 1) ::= Bridge(parents(i), lengths(i))
        islands(parents(i)) ::= Bridge(i + 1, lengths(i))
      }
      val isLeaf = islands.map {
        _.lengthCompare(1) == 0
      }
      val minLength = Array.fill(n) {
        Int.MaxValue
      }

      def setMax(current: Int, len: Int = 0): Unit = {
        if (minLength(current) > len) {
          minLength(current) = len
          for (Bridge(next, length) ← islands(current)) {
            setMax(next, len + length)
          }
        }
      }

      setMax(0)
      val start = islands.indices.filterNot(isLeaf).maxBy(minLength)
      minLength.indices.foreach(i ⇒ minLength(i) = Int.MaxValue)
      setMax(start)
      val doubleMove = islands.indices.map { i ⇒ if (isLeaf(i)) 0 else islands(i).filterNot(e ⇒ isLeaf(e.to)).map(_.length).sum }.sum
      val singleMove = islands.indices.filterNot(isLeaf).map(minLength).max
      println(allRemove + doubleMove - singleMove)
    }
    n = readInt()
  }

  case class Bridge(to: Int, length: Int)

}


Measured memory_bytes: 85000
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int A,B,N;
  cin >> N >> A >> B;
  cout << ((B-A)%2==0 ? "Alice" : "Borys") << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
	int N,a[10000],kaisu=0;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<N;i++){
		if(a[i]%2==0){
			a[i]/=2;
			kaisu++;
			i--;
		}
	}
	printf("%d\n",kaisu);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll n=in();
    ll mi=INFLL;REP(i,5)mi=min(mi,in());
    ll g=(n+mi-1)/mi;
    cout<<g+4<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5)

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  edge[u].append((v,w))
  edge[v].append((u,w))

#print(edge)

def dfs(u,v):
  for e,w in edge[u]:
    if e != v:
      ans[e] = (w + ans[u]) % 2
      # print(ans)
      dfs(e,u)

ans = [0] + [-1] * (N-1)
dfs(0,-1)
print(*ans)


Measured memory_bytes: 160288
import sys

N=int(input())

for h in range(1,3*N//4+1):
    if 4*h>N:
        for n in range(1,(2*N*h)//(4*h-N)+1):
            if (4*h-N)*n>N*h:
                if (N*h*n)%((4*n*h-N*n-N*h))==0:
                    w=(N*h*n)//((4*n*h-N*n-N*h))
                    print(h,n,w)
                    sys.exit()

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

using namespace std;

const long long MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    int P[N];
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }
    int a[N];
    for (int i = 0; i < N; i++) {
        a[P[i] - 1] = i;
    }
    int big = 1;
    int now = 1;
    for (int i = 0; i < N - 1; i++) {

        if (a[i] < a[i + 1]) {
            now++;
        } else {

           now=1;
        }
        big=max(big,now);
    }
    cout << N-big << endl;
    /*for(int i=0;i<N;i++){
        cout<<a[i]<<endl;
    }*/

}













Measured memory_bytes: 1792
N=int(input())
h=[int(i) for i in input().split()]
dp=[0]*(N+1)
dp[1]=dp[0]+abs(h[0]-h[1])
for i in range(2,N):
  dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[N-1])

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

int main(){
  int n;
  cin>>n;
  int ans = 0;
  int bi = 1;
  while(bi<=n){
    bi*=2;
    ans++;
  }
  cout<<bi/2<<endl;
  return 0;
}

Measured memory_bytes: 256