akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const int inf=1e9;
const int maxn=1e5+50;
const int maxp=maxn<<1;
int n,m;
int N;
int a[maxn];
int b[maxn];
int P[maxn];
int Q[maxn];
int head[maxp];
struct edge
{
	int to,nex,cap,flow;
	edge(int to=0,int nex=0,int cap=0,int flow=0):to(to),nex(nex),cap(cap),flow(flow){}
};
vector<edge> G;
inline void addedge(int u,int v,int c)
{
	G.push_back(edge(v,head[u],c,0)),head[u]=G.size()-1;
	G.push_back(edge(u,head[v],0,0)),head[v]=G.size()-1;
}
namespace dinic
{
	int cur[maxp];
	int dis[maxp];
	bool BFS(int s,int t)
	{
		static int que[maxp];
		int hd=0,tl=0;
		memset(dis,-1,sizeof(dis));
		que[tl++]=s;
		dis[s]=0;
		while(hd<tl)
		{
			int u=que[hd++];
			for(int i=head[u];~i;i=G[i].nex) if(G[i].cap!=G[i].flow)
			{
				int v=G[i].to;
				if(dis[v]==-1)
				{
					dis[v]=dis[u]+1;
					que[tl++]=v;
				}
			}
		}
		return dis[t]!=-1;
	}
	int DFS(int u,int flow,int t)
	{
		if(u==t||flow==0) return flow;
		int rec=flow;
		for(int &i=cur[u];~i;i=G[i].nex)
		{
			int v=G[i].to;
			if(dis[v]==dis[u]+1)
			{
				int d=DFS(v,min(flow,G[i].cap-G[i].flow),t);
				G[i].flow+=d,G[i^1].flow-=d;
				flow-=d;
				if(flow==0) break;
			}
		} 
		return rec-flow;
	}
	int maxflow(int s,int t)
	{
		int flow=0;
		while(BFS(s,t))
		{
			memcpy(cur,head,sizeof(head));
			flow+=DFS(s,inf,t);
		}
		return flow;
	}
}
void findcircle(int &n,int *a,int *P)
{
	for(int i=0;i<N;++i) if(!a[i])
	{
		a[i]=++n;
		for(int u=P[i];u!=i;u=P[u]) a[u]=n;
	}
}
int solve()
{
	findcircle(n,a,P);
	findcircle(m,b,Q);
	memset(head,-1,sizeof(head));
	int an=N;
	int p=n+m;
	for(int i=0;i<N;++i)
	{
		if(P[i]==i&&Q[i]==i) --an;
		else if(P[i]==i)
		{
			addedge(n+b[i],p+1,1);
		}
		else if(Q[i]==i)
		{
			addedge(0,a[i],1);
		}
		else
		{
			addedge(n+b[i],a[i],1);
			if(P[i]==Q[i])
			{
				addedge(a[i],n+b[i],1);
			}
		}
	}
	an-=dinic::maxflow(0,p+1);
	return an;
}
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;++i) scanf("%d",&P[i]);
	for(int i=0;i<N;++i) scanf("%d",&Q[i]);
	printf("%d\n",solve());
	return 0;
} 

Measured memory_bytes: 14444
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  vector<ll> a(n + 1);
  vector<ll> memo(n + 1);

  REP(i, n + 1) cin >> a[i];
  memo[n] = a[n];
  RREP(i, n) {
    memo[i] = memo[i + 1] + a[i];
  }

  ll node = 1;
  REP(i, n + 1) {
    if(node <= 0 || memo[i] <= 0) {
      cout << -1 << endl;
      return 0;
    }

    if(node < memo[i]) memo[i] = node;
    if(memo[i] < node) node = memo[i];

    node = 2 * (node - a[i]);
    if(i == n && node != 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  ll ans = 0;
  REP(i, n + 1) ans += memo[i];

  cout << ans << endl;
}


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

int main() {
  int A,B,C,X,p=0;
  cin >> A >> B >> C >> X;
  for(int i=0;i<=A;i++){
    int Xa=X-500*i;
    if(Xa<0)
      continue;
    if(Xa==0){
      ++p;
      continue;
    }
    for(int j=0;j<=B;j++){
      int Xb=(Xa-100*j)/50;
      if(0<=Xb&&Xb<=C)
        ++p;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict
import sys
Chi = defaultdict(lambda: [])
F = defaultdict(lambda: [])
N = int(input())
Par = [0] + [int(i)-1 for i in input().split()]
Dis = [-1]*N
X = inpl()
Col = [()]*N
for i in range(N):
    Chi[Par[i]].append(i)
Q = [0]
ctr = 0
while ctr < N:
    st = Q.pop()
    if not Chi[st]:
        continue
    for j in Chi[st]:
        Dis[j] = Dis[st] + 1
        ctr += 1
        Q.append(j)
Chi[0].remove(0)
mD = max(Dis)
for i in range(N):
    F[Dis[i]].append(i)
for d in range(mD, -1, -1):
    for i in F[d]:
        if not Chi[i]:
            Col[i] = (0,X[i])
            continue
        Su = 0
        H = defaultdict(lambda: 0)
        H[0] = 0
        for j in Chi[i]:
            a, b = Col[j]
            Su += a+b
            G = defaultdict(lambda: 0)
            for k in H.keys():
                if a + k <= X[i]:
                    G[a+k] = 1
                if b + k <= X[i]:
                    G[b+k] = 1
            H = G.copy()
            if not H:
                break
        else:
            Col[i] = (Su-max(H), X[i])
            continue
        break
    else:
        continue
    break
else:
    print('POSSIBLE')
    sys.exit()
print('IMPOSSIBLE')

Measured memory_bytes: 4560
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  sort(s,s+n);
  for(int i=0;i<n;i++){
    cout <<s[i];
  }
  cout <<"\n";
}


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

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

int main(){
  long long A,B,C,D;
  cin>>A>>B>>C>>D;
  long long E=C/__gcd(C,D)*D;
  cout<<B-A+1-((B/C-(A-1)/C)+(B/D-(A-1)/D)-(B/E-(A-1)/E))<<endl;
}

Measured memory_bytes: 256
# 初期位置が隣同時の子供が同じマスに残ることはない
# 右隣にRがあるRのコマ、左隣にLがあるLのコマは0になる。
# 両サイドも0人
# 最後はRLの順番で連続してるマスにのみ子供が存在する状態になる。
S = input()

ans = [1 for _ in range(len(S))]
count = 0
for i in range(len(S) - 1):
    if S[i] == 'R' and S[i+1] == 'R':
        count += 1
        ans[i] -= 1
    if S[i] == 'R' and S[i+1] == 'L':
        ans[i] += count // 2
        ans[i+1] += count // 2
        if count % 2 == 1:
            ans[i+1] += 1
        count = 0

count = 0
for i in range(len(S) - 1):
    if S[-i-1] == 'L' and S[-i-2] == 'L':
        count += 1
        ans[-i-1] -= 1
    if S[-i-1] == 'L' and S[-i-2] == 'R':
        ans[-i-1] += count // 2
        ans[-i-2] += count // 2
        if count % 2 == 1:
            ans[-i-2] += 1
        count = 0

for i in range(len(S)):
    if i != len(S) - 1:
        print(ans[i], end=" ")
    else:
        print(ans[i])

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

const long long INF = 1LL << 60;

int N;
long long a[409];
long long dp[409][409];

long long solve(int l, int r) {
    if(l == r) return 0;
    if(dp[l][r] != 0) return dp[l][r];

    long long res = INF;
    for(int i = l; i < r; i++)
        res = min(res, solve(l, i) + solve(i + 1, r));

    return dp[l][r] = res + a[r] - a[l - 1];
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
        a[i] += a[i - 1]; // 累積和を取る
    }

    cout << solve(1, N) << endl;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    int last;
    if (s.size() <= t.size()) last = s.size();
    else if (s.size() > t.size()) last = t.size();
    
    bool check = false;
    int x = 0;

    for (int i = 0; i < last; i++){
          if (s.at(i) < t.at(i)){
            check = true;
            break;
          }
          if (s.at(i) == t.at(i)){
              x++;
              if (s.size() < t.size() && x == last){
                  check = true;
                  break;
              }
          }
     }
    
    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;
    

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace cswork {
    class Program {
        static void Main (string[] args) {
            List<int> l = ReadListInt ();
            int n = l[0];
            int m = l[1];
            int x = l[2];

            int[] cost = new int[n];
            int[][] skill = new int[n][];
            for (int i = 0; i < n; i++) {
                List<int> book = ReadListInt ();
                cost[i] = book[0];
                skill[i] = new int[m];
                for (int j = 0; j < m; j++) {
                    skill[i][j] = book[j + 1];
                }
            }

            int ans = int.MaxValue;
            for (int i = 0; i < 1 << n; i++) {
                int tmpCost = 0;
                int[] d = new int[m];

                for (int j = 0; j < n; j++) {
                    if ((i >> j & 1) == 1) {
                        tmpCost += cost[j];
                        for (int k = 0; k < m; k++) {
                            d[k] += skill[j][k];
                        }
                    }
                }

                bool ok = true;
                for (int j = 0; j < m; j++) {
                    if (d[j] < x) {
                        ok = false;
                        break;
                    }
                }

                if (ok) {
                    ans = Math.Min (ans, tmpCost);
                }
            }

            if (ans == int.MaxValue) {
                Write (-1);
            } else {
                Write (ans);
            }

            Exit ();
        }

        public static void Write (string str) {
            Console.WriteLine (str);
        }

        public static void Write (int i) {
            Console.WriteLine (i);
        }

        public static void Write (double d) {
            Console.WriteLine (d);
        }

        public static string ReadStr () {
            return Console.ReadLine ();
        }

        public static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }

        public static long Read () {
            return long.Parse (Console.ReadLine ());
        }

        public static double ReadDouble () {
            return double.Parse (Console.ReadLine ());
        }

        public static void Exit () { }

        public static List<string> ReadListStr () {
            return new List<string> (ReadStr ().Split (" "));
        }

        public static List<long> ReadList () {
            return ReadListStr ().ConvertAll (x => long.Parse (x));
        }

        public static List<int> ReadListInt () {
            return ReadListStr ().ConvertAll (x => int.Parse (x));
        }
    }
}

Measured memory_bytes: 28136
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    char english[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    char a;
    cin >> a;
    for (int i = 0; i < 26; i++)
    {
        if (a == english[i])
        {
            cout << "a" << endl;
            return 0;
        }
    }
    cout << "A" << endl;
    return 0;
}

Measured memory_bytes: 3648
while 1:
    n = int(raw_input())
    if n == 0: break
    table = []
    index = {}
    for k in range(n):
        i, p, q = raw_input().split()
        record = index.get(i)
        if not record:
            record = [i, 0]
            table.append(record)
            index[i] = record
        record[1] += int(p) * int(q)
    found = False
    for record in table:
        if record[1] >= 1000000:
            print record[0]
            found = True
    if not found:
        print 'NA'

Measured memory_bytes: 4360
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}


signed main()
{
    int N;
    int a[105];

    cin >> N;
    rep(i, 0, N) cin >> a[i];

    sort(a, a+N);

    cout << a[N-1] - a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
	long long int N;
	cin>>N;
	string s;
	vector <int> vect(4,0);
	int i,j,k;
	for(i=0;i<N;i++)
	{
		cin>>s;
		if(s.compare("AC")==0)
		vect[0]++;
		else if(s.compare("WA")==0)
		vect[1]++;
		else if(s.compare("TLE")==0)
		vect[2]++;
		else
		vect[3]++;
	}
	cout<<"AC x "<<vect[0]<<"\n";
	cout<<"WA x "<<vect[1]<<"\n";
	cout<<"TLE x "<<vect[2]<<"\n";
	cout<<"RE x "<<vect[3]<<"\n";
	
	return 0;
}

Measured memory_bytes: 3628
#include "stdio.h"
#include "string.h"

int main(int argc, char const *argv[])
{
    char S[1001], T[1001];
    scanf("%s\n%s%*c", S, T);
    int s = strlen(S), t = strlen(T), mn = t, c;

    for (int i = 0; i <= s - t; i++) {
        c = 0;
        for (int j = i; j < i + t; j++)
            c += S[j] != T[j - i];
        c < mn && (mn = c);
    }

    printf("%d\n", mn);
    
    return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=5000005;
int suf[N],n,ans,mn=1e9,p;
pii a[N];

int main(){
	read(n);
	rep(i,1,n){
		read(a[i].fi);
		read(a[i].se);
		mn=min(mn,a[i].se);
	}
	sort(a+1,a+n+1);
	while(a[p].se!=mn) p++;
	int L=1,R=1e9;
	per(i,n,1){
		L=max(L,a[i].fi);
		R=min(R,a[i].se);
		suf[i]=max(0,R-L+1);
	}
	/*
	rep(i,1,n){
		printf("%d %d   %d\n",a[i].fi,a[i].se,suf[i]);
	}
	*/
	rep(i,p,n){
		int nL=a[i].fi;
		int val=max(0,mn-nL+1);
		ans=max(ans,val+suf[i+1]);
	}
	int mx=0;
	rep(i,1,n-1) if(i!=p){
		mx=max(mx,a[i].se-a[i].fi+1);
	}
	ans=max(ans,max(0,a[p].se-a[n].fi+1)+mx);
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <math.h>

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

int main(){
	int n,m;
	while(cin >> n, n){
	
	cin >> m;
	
	int val,res,sugo;
	res = 0;
	sugo = 1;

	vector<int> data,dice;
	
	rep(i,n){
		cin >> val;
		data.push_back(val);
	}
	
	rep(i,m){
		cin >> val;
		dice.push_back(val);
	}
	
	rep(i,m){
		val = dice[i];
		//cout << "dice." << val << endl;
		sugo += val;
		//cout << "," << sugo << endl;
		val = sugo - 1;
		//cout << "..." << sugo << endl;		
		
		if(0 < data[val]) sugo += abs(data[val]);
		else if(data[val] < 0) sugo -= abs(data[val]);
		else sugo += 0;
		
		//cout << "," << data[val] << endl;
		//cout << "..." << sugo << endl;		
		
		if(sugo >= n) break;
		res++;
	}

	cout << res + 1 << endl;
	/*
	rep(i,5) sugo += -1;
	cout << "//" << sugo << endl;
	*/
	}
	
	return 0;
}

Measured memory_bytes: 1224
// https://atcoder.jp/contests/abc077/tasks/arc084_a
// lower_bound upper_bound

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include<iomanip>

using namespace std;

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

typedef long long ll;

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; }

int A[100010];
int B[100010];
int C[100010];
ll lb_a[100010];
ll ub_c[100010];

void Main()
{
	int N; cin >> N;
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N) cin >> C[i];

	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);
	rep(i,N) {
		lb_a[i] = lower_bound(A, A + N, B[i]) - A;
		ub_c[i] = upper_bound(C, C + N, B[i]) - C;
	}
	ll res = 0;
	rep(i,N) {
		res += lb_a[i] * (N - ub_c[i]);
	}
	cout << res << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
int n;
ll m, ans = 1000000000000000000ll;
ll a[N];
struct bit {
	ll tree[N * 2];
	inline int lowbit(int i)
	{
		return i & -i;
	}
	void update(int pos, int num)
	{
		for(int i = pos; i <= 2 * m; i += lowbit(i)) 
			tree[i] += num;
	}
	ll query(int pos)
	{
		ll ret = 0;
		for(int i = pos; i; i -= lowbit(i)) 
			ret += tree[i];
		return ret;
	}
} t1, t2;
int main()
{
	scanf("%d%lld", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	ll now = a[1], all = 0, to;
	for(int i = 2; i <= n; ++i)
	{
		to = a[i] - 1;
		now = a[i - 1] - 1;
		if(to < now) to += m;
		all += to - now;
		t1.update(now + 1, now);
		t1.update(to + 1, - now);
		t2.update(now + 1, 1);
		t2.update(to + 1, - 1);	
	}
	for(int i = 1; i <= m; ++i)
	{
		ll sum1 = t1.query(i), sum2 = t2.query(i), sum = all;
		sum -= (ll)i * sum2 - sum1 - sum2;
		sum1 = t1.query(i + m); 
		sum2 = t2.query(i + m);
		sum -= (ll)(i + m) * sum2 - sum1 - sum2;
		ans = min(ans, sum);  
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
int main(void){
    int x1,x2,y;
    int i,cnt1,cnt2;
    int max=10;
    int flag;
    if((max-3)%2==0)flag=(max-3)/2;
    else flag=(max-3)/2+1;
    
    while(scanf("%d %d %d",&x1,&x2,&y)==3){
        cnt1=0;
        cnt2=0;
        for(i=1;i<=max;i++){
            if(i==x1||i==x2||i==y)continue;
            if(20>=x1+x2+i)cnt1++;
            else cnt2++;
            if(cnt1>=flag||cnt2>=flag)break;
        }
        if(cnt1>=flag)printf("YES\n");
        else if(cnt2>=flag) printf("NO\n");
    }
    
    return 0;
}



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

int main() {
	stack<int> s;
	int n;
	while(cin>>n){
		if(n==0){
			printf("%d\n",s.top());
			s.pop();
		}else{
		s.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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





///////////////////////////


int main() {
	ll N, K;

	cin >> N >> K;

	vector<pair<ll, ll>> s(N + 1);

	repn(i, N) {
		cin >> s[i].second >> s[i].first;
	}

	sort(++s.begin(), s.end(),greater<pair<ll,ll>>());

	vector<ll> see(N + 1, 0);

	vector<ll> f(N + 1,0);//各ネタで最もおいしい寿司か

	repn(i,N){
		if (see[s[i].second] == 0) {
			f[i] = 1;
			see[s[i].second] = 1;
		}
	}

	//repn(i, N) { cout << s[i].first << s[i].second << f[i] << endl; }

	ll var = 0;

	ll now = 0;

	repn(i, K) {
		if (f[i] == 1) { var++; }
		now += s[i].first;
	}

	now += var * var;

	ll ans = now;

	ll omit = K;//次削る候補

	for (int i = K + 1; i <= N; i++){
		if (f[i] == 0) { continue; }

		while (omit > 0 && f[omit] == 1) { omit--; }
		if (omit == 0) { break; }
		omit--;

		var++;
		now = now - s[omit+1].first + s[i].first + 2 * var - 1;
		ans = max(now, ans);

		//cout << i << omit << now << endl;
	}

	cout << ans;

	system("PAUSE");

}


Measured memory_bytes: 3576
#include <stdio.h>
#include <math.h>

int main(void)
{
    int a,b,C;
    double S,L,h;
    double rad;
    double PI = acos(-1);

    scanf("%d %d %d", &a, &b, &C);

    rad = C * PI / 180;

    S = 0.5 * a * b * sin(rad);
    L = a + b + sqrt( (a * a) + (b * b) - 2 * a * b * cos(rad));
    h = b * sin(rad);

    printf("%lf\n%lf\n%lf\n", S, L, h);

    return (0);
}




Measured memory_bytes: 2064
n=int(input())
l=sorted(list(map(int,input().split())),reverse=1)
from heapq import heapify, heappop, heappush
h=[-l[0]]

ans=0
for i in range(1,n):
    p=-heappop(h)
    ans+=p
    heappush(h,-l[i])
    heappush(h,-l[i])
print(ans)

Measured memory_bytes: 31616
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int N,L;
    cin >> N >> L;
    int a[N];
    int sum = 0;
    for(int i=0; i<N; i++){
        a[i] = L + i;
        sum += a[i];
    }
    int mini = 0;
    for(int i=1; i<N; i++){
        if(abs(a[mini]) > abs(a[i])) mini = i;
    }
    sum -= a[mini];
    cout << sum << endl;
    return 0;
}


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

typedef signed long long ll;
const int MX = 1e3 + 5;

int main() {
    string S, R;
    for( ; cin >> S ; ) {
        char ch = toupper(S[0]);
        R.push_back(ch);
    }

    cout << R << endl;
    return 0;
}

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


int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	vector<int> c(n);
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1;i <= n;i++) {
		cin >> b[i];
	}
	for (int i = 1;i <= n-1;i++) {
		cin >> c[i];
	}
	int cnt = 0;
	for (int i = 1;i < n;i++) {
		cnt += b[a[i]];
		if (a[i] + 1 == a[i + 1]) {
			cnt += c[a[i]];
		}
	}
	cnt += b[a[n]];
	cout << cnt << endl;
	return 0;
}


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

int main(){
    int a;
    cin >> a;
    int b;
    cin >> b;
    string c = "";
    if(a < b){
        for(int i = 0; i < b; i++){
            cout << a;
        }
    }
    else {
        for(int i = 0; i < a; i++){
            cout << b;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// finish date: 2018/03/10

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>

void minusMapSecond(map<int, int> &mp, int key) {
    mp[key]--;
    if (mp[key] == 0) mp.erase(key);
}

int main() {
    int N;
    cin >> N;
    int a;
    map<int, int> possibleNode;
    rep(i, N) {
        cin >> a;
        possibleNode[a]++;
    }
    int ma = possibleNode.rbegin()->first;
    minusMapSecond(possibleNode, ma);

    FOR(i, 1, ma + 1) {
        if (possibleNode.count(max(i, ma - i)) == 0) {
            cout << "Impossible" << endl;
            return 0;
        }
        minusMapSecond(possibleNode, max(i, ma - i));
    }
    if (possibleNode.empty()) {
        cout << "Possible" << endl;
        return 0;
    }
    bool con1 = (ma + 1) / 2 + 1 <= possibleNode.begin()->first;
    bool con2 = possibleNode.rbegin()->first <= ma;
    if (con1 && con2) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

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

int main() { 
    ll A, B, K;
    cin >> A >> B >> K;
    if (A > K)
    {
        ll a = A - K;
        cout << a << ' ' << B << endl;
    }

    else if(B > K - A)
    {
        cout << 0 << ' ' <<  B-K+A << endl;
    }

    else
    {
        cout << 0 << ' ' << 0 << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  cin >> n;
  int sita = (n + 104) / 105;
  int ue = n / 100;
  for (int i = sita; i <= ue; i++)
  {
    if(n>=i*100&&n<=i*105){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define pb push_back
#define ull unsigned long long int

#define IO ios::sync_with_stdio(false);
typedef vector<int> vi;
#define H return 0;
#define C continue;
#define B break;
#define sec second

int n,k,q;
    int main()
{   IO
   cin.tie(0);
  string s,t;
  char temp;
     cin>>s>>t;
n=s.length();
int x=n;
while(x--)
{
    if(s==t)
    {
        cout<<"Yes"<<endl;
        H
    }temp=s[n-1];

    for(int i=n-1;i>0;i--)
    {
        s[i]=s[i-1];
    }
    s[0]=temp;


}
cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};

int main()
{
    int N, K;
    std::cin >> N >> K;
    std::vector<ll> a(N);
    for (int i = 0; i < N; i++) { std::cin >> a[i]; }
    for (int i = 1; i < N; i++) { a[i] += a[i - 1]; }
    std::multiset<ll> A;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            A.insert(a[j] - (i == 0 ? 0LL : a[i - 1]));
        }
    }
    ll ans = 0;
    for (int i = 50; i >= 0; i--) {
        int cnt = 0;
        for (const ll B : A) {
            if (B & (1LL << i)) { cnt++; }
        }
        if (cnt >= K) {
            ans += (1LL << i);
            std::multiset<ll> n;
            for (const ll B : A) {
                if (B & (1LL << i)) { n.insert(B); }
            }
            A = n;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 28928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 200005;
string s[10], c[10];
int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	for (int i = 0; i < h; i++)
		cin >> s[i];
	int ans = 0;
	for (int i = 0; i < (1 << h); i++) {
		for (int j = 0; j < (1 << w); j++) {
			// cout<<j<<endl;
			for (int k = 0; k < h; k++)
				c[k] = s[k];
			for (int k = 0; k < h; k++) {
				if (i & (1 << k))
					for (int q = 0; q < w; q++)
						c[k][q] = 'r';
			}
			for (int k = 0; k < w; k++)
				if (j & (1 << k))
					for (int q = 0; q < h; q++)
						c[q][k] = 'r';
			int sum = 0;
			for (int p = 0; p < h; p++)
				for (int q = 0; q < w; q++)
					if (c[p][q] == '#')
						sum++;
			// for (int k = 0; k < h; k++)
			// 	cout << c[k] << endl;
			// cout<<sum<<endl;
			if (sum == k) ans++;
		}
	}
	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 rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n;cin>>n;
    int c[n-1],s[n-1],f[n-1];
    rep(i,n-1)cin>>c[i]>>s[i]>>f[i];
    rep(a,n){
        int res =0;
        rep2(i,a,n-1){
            if(res>s[i]){
                res=ceil((double)res/(double)f[i])*f[i];
            }
            else{
                res = s[i];
            }
            res+=c[i];
        }
        cout<<res<<endl;
    }
    
    }

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

using namespace std;

int main() {
   int n;
   cin >> n; 
   cout << (n%2==0 ? n : n*2) << endl; 
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] != s[i + 1]) ++ans;
  }
  cout << ans << endl;
}


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

#define za ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod %1000000007
#define moz 1000000007
#define nl "\n"
#define S second
#define F first
#define PB push_back
#define MP make_pair
#define V vector
//#define P pair
#define LEN length()
#define SZ size()
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
typedef complex<ll> P;
#define X real()
#define Y imag()


int main()
{
    za ;
    int x;
    int arr[100009]={0};
    int n;
    cin >> n;
    loop(i,0,n-1)
    {
        cin >> x;
        arr[x]++;
    }
    int maxi=0;
    loop(i,0,100000-2)
    {
        maxi=max(maxi,(arr[i]+arr[i+1]+arr[i+2]));
    }
    cout << maxi << nl;
}


Measured memory_bytes: 640
import sys
import itertools
l = [int(x) for x in sys.stdin.readlines()]
k = l[-1]
del l[-1]
pairs = list(itertools.combinations(l, 2))
flag = 0
for pair in pairs:
    if not max(pair) - min(pair) <= k:
        print(":(")
        flag += 1
        break
if not flag:
    print("Yay!")

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

int main(){
  int D,N;
  cin >> D >> N;
  vector <int> v;
  int i=1;
  while(true){
    if(int((pow(100,D)*i))%int(pow(100,D+1))!=0){
      v.push_back(pow(100,D)*i);
    }
    if(v.size()==N){
      break;
    }
    i++;
  }
  cout << v.at(N-1) << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
mx=a[n]
sm=sum(a)
stem=1
ans=0
for i in range(n):
    if stem<a[i]:
        print(-1)
        exit()
    ans += stem
    stem -= a[i]
    sm -=a[i]
    stem=min(stem*2,sm)
if stem<mx:
    print(-1)
    exit()
ans += mx
print(ans)

Measured memory_bytes: 20024
#include<bits/stdc++.h>
#define long long long
using namespace std;
long q,a,b,lo,hi,md,x,sc,ans,y,ex;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin>>q;
  while(q--)
  {
    ex=0;
    cin>>a>>b;
    sc=a*b;
    lo=1;
    hi=sc-1;
    while(hi-lo>2)
    {
      md=(lo+hi)/2;
      long x=(sc-1)/md;
      if(x<md)hi=md;
      else lo=md;
    }
    for(long i=lo;i<=hi;i++)
    {
      x=i;
      y=(sc-1)/x;
      if(x==y)ex=1;
      if(y<x)break;
      ans=i;
    }
    if(a<=ans||b<=ans)ex++;
    ans=ans*2;
    ans-=ex;
    cout<<ans<<endl;
  }
  return 0;
}


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

int main(){

	int H,W = 0;
	scanf("%d %d",&H,&W);

	char	C[H][W];

	for(int i=0; i<H; i ++){
		scanf("%s",C[i]);	
		printf("%s\n",C[i]);
		printf("%s\n",C[i]);
	}

	return 0;


}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

k = ni()

def bfs():
    q = deque()
    for i in range(1, 10):
        q.append(i)
    cnt = 1
    while len(q):
        p = q.popleft()
        if cnt == k:
            return p
        if p % 10 != 0:
            q.append(p * 10 + (p % 10 - 1))
        q.append(p * 10 + p % 10)
        if p % 10 != 9:
            q.append(p * 10 + (p % 10 + 1))
        cnt += 1

print(bfs())

Measured memory_bytes: 12488
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = int(input())
	b = int(input())
	c = int(input())
	d = int(input())
	e = int(input())
	print(math.ceil(n/min([a,b,c,d,e]))+4)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 65260
while True:
    m = int(input())
    if m == 0: break
    sx, sy = map(int, input().split())
    star = []
    for i in range(m-1):
        x, y = map(int, input().split())
        star.append((x-sx, y-sy))
    
    
    n = int(input())
    starlist = [tuple(map(int, input().split())) for i in range(n)]
    for i in range(n):
        flag = True
        for j in range(len(star)):
            dx = starlist[i][0] + star[j][0]
            dy = starlist[i][1] + star[j][1]
            if (dx, dy) not in starlist:
                flag = False
                break
        if flag == True:
            print("{} {}".format(str(starlist[i][0] - sx), str(starlist[i][1] -sy)))
            break
    

Measured memory_bytes: 7008
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    int n;
    long long int x[200005],y[200005];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[i]=x[i];
    }
   
    sort(x,x+n,greater<int>());
    for(int i=0;i<n;i++){
        if(x[n/2-1]>y[i])cout<<x[n/2-1]<<endl;
        else cout<<x[n/2]<<endl;
    
    }
    
    return 0;

}

Measured memory_bytes: 5376
#include <iostream>
#include <string>

using namespace std;

int main() {
  string N;
  cin >> N;
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < N.size(); ++i) {
    if (i % 2 == 0) {
      if (N[i] == 'R' || N[i] == 'U' || N[i] == 'D') {
        ++cnt1;
      }
    } else {
      if (N[i] == 'L' || N[i] == 'U' || N[i] == 'D') {
        ++cnt2;
      }
    }
  }
  auto len = N.size() / 2;
  if (N.size() % 2 == 1) {
    len += 1;
    if (cnt1 == len && cnt2+1 == len) {
    	cout << "Yes" << endl;
  	} else {
    	cout << "No" << endl;
    }
  } else {
  	if (cnt1 == len && cnt2 == len) {
    	cout << "Yes" << endl;
  	} else {
    	cout << "No" << endl;
    }
  }
  return 0;
}

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

int main(int argc, const char * argv[]) {
    char C[3][3], x;
    
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> x;
            C[i][j] = x;
        }
    }
    for (int i = 0; i < 3; i++) {
        cout << C[i][i];
    }
    cout << endl;
    
    
    return 0;
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int k, n;
	cin >> n >> k;
	v1 p(n);
	rep(i,n){
		cin >> p.at(i);
	}
   	/*int m = 1e8;
	for(int bit = 0; bit < (1<<n); bit++){
		int sum = 0;
		int ck = 0;
		rep(i, n){
			if(bit & (1<<i)){
				sum += p.at(i);
				ck ++;
			}
		}
		if(ck != k || ck == 0) continue;
		if(m > sum) m = sum;
	}*/
	sort(p.begin(), p.end());
	int sum = 0;
	rep(i, k){
		sum += p.at(i);
	}
	cout << sum << endl;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#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__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, a;
	string s, ss;

	cin >> n;

	multiset<ll> ms;

	REP(i, n) {
		cin >> a;
		ms.insert(a);
	}

	ll ans = 0;
	bool flag;

	while (ms.size() > 1) {
		auto itr = ms.end();
		a = *(--itr);
		if (a == 1) {
			ans++;
			itr = ms.erase(itr);
			ms.erase(--itr);
			continue;
		}
		/*
		if (a % 2) {
			s = "1";
		}
		else {
			s = "0";
		}
		a = (a >> 1);
		*/
		bitset<32> bs(a);
		ll start = 0;
		REP(i, 32) {
			if (bs[i]) {
				start = i;
				break;
			}
		}
		flag = true;
		s = "";
		ss = "";
		RFOR(i, start + 1, 32) {
			if (flag) {
				if (bs[i]) {
					flag = false;
				}
			}
			if (!flag) {
				if (bs[i]) {
					ss = ss + "0";
				}
				else {
					ss = ss + "1";
				}
			}
		}
		REP(i, start + 1) {
			if (bs[i]) {
				s = "1" + s;
			}
			else {
				s = "0" + s;
			}
		}
		s = ss + s;
		if (s[s.size() - 1] == '0' && bs.count() == 1) {
			if (*(--itr) == a) {
				ans++;
				itr = ms.erase(itr);
				ms.erase(itr);
			}
			else {
				ms.erase(++itr);
			}
		}
		else if (stoi(s, 0, 2) == 0) {
			auto itr2 = ms.find(2);
			if (itr2 != ms.end()) {
				ans++;
				ms.erase(itr);
				ms.erase(itr2);
			}
			else {
				ms.erase(itr);
			}
		}
		else {
			auto itr2 = ms.find(stoi(s, 0, 2));
			if (itr2 != ms.end()) {
				ans++;
				ms.erase(itr);
				ms.erase(itr2);
			}
			else {
				ms.erase(itr);
			}
		}
		/*
		for (auto it = ms.begin(); it != ms.end(); it++) {
			cout << *it << " ";
		}
		cout << endl;
		//*/
	}

	cout << ans << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    SRT(a,3);
    REV(a,3);
    cout<<(a[0]-a[1])+(a[1]-a[2])<<NL;
    return 0;
}



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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<ll,ll> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	
	int n; cin >>n;
	VI a(n), b(n);
	rep(i,n) cin >>a[i];
	rep(i,n) cin >>b[i];

	VI odf(n);
	rep(i,n) odf[i] = a[i] - b[i];
	sort(all(odf)); reverse(all(odf));
	

	int ans =0;
	ll sm =0;
	rep(i,n)if(odf[i]<0){ sm -=odf[i]; ans++;}
	
	rep(i, n){
		if(odf[i]<=0 || sm <=0) break;
		sm -= odf[i];
		ans++;
	}
	if(sm >0) puts("-1");
	else cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int, greater<int>> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    rep(i, m) {
        int b, c;
        cin >> b >> c;
        mp[c] += b;
    }

    ll ans = 0;
    int count = 0;
    for (auto x : mp) {
        while (x.se > 0) {
            ans += x.fi;
            x.se--;
            count++;
            if (count >= n) {
                cout << ans << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string a;
map<string,int>q;
int main(){
	int n;
	scanf("%d",&n);
	ll ans=0;
	for(int i=1;i<=n;++i){
		cin>>a;
		sort(a.begin(),a.end());
		ans+=q[a];q[a]++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 11136
//ITP_1_2_C
#include<iostream>
using namespace std;

int main()
{
	int a,b,c,s;
	cin>>a>>b>>c;
	
	if(a>=b){
		s = b;
		b = a;
		a = s;
	}
	if(b>=c){
		s = c;
		c = b;
		b = s;
	}
	if(a>=b){
		s = a;
		a = b;
		b = s;
	}
	
	cout<<a<<" "<<b<<" "<<c<<endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct Node
{
	int num;
	struct Node* next;
	struct Node* pre;
}Node,*List;


int commond(char* str)
{
	if (!strcmp(str, "insert"))
		return 1;
	if (!strcmp(str, "delete"))
		return 2;
	if (!strcmp(str, "deleteFirst"))
		return 3;
	if (!strcmp(str, "deleteLast"))
		return 4;
}
///有头节点
void insert(List L,int x)
{
	Node* t = (List)malloc(sizeof(Node));
	if (!t)
		exit(-1);
	t->num = x;
	t->next = L->next;
	t->pre = L;
	L->next->pre = t;
	L->next = t;
	if(t->next==L)
		L->pre = t;
}

void deleteFirst(List L)
{
	Node* t = L->next;
	L->next = t->next;
	t->next->pre = L;
	free(t);
}

void deleteLast(List L)
{
	List t = L->pre;
	L->pre = t->pre;
	t->pre->next = L;
	free(t);
}

void deleteX(List L, int x)
{
	List t = L->next;
	while (t->num!=x&&t->next!=L->next)
	{
		t = t->next;
	}
	if (t->next == L->next)
		return;
	t->pre->next = t->next;
	t->next->pre = t->pre;
	free(t);
}

int main()
{
	int n;
	scanf("%d", &n);
	char str[30];
	List L=(List)malloc(sizeof(Node));
	L->next = L;
	L->pre = L;
	for (int i = 0; i < n; i++)
	{
		scanf("%s", str);
		int com = commond(str);
		switch (com)
		{
		case 1:
		{
			int x = 0;
			scanf("%d", &x);
			insert(L, x);
			break;
		}
		case 2:
		{
			int x = 0;
			scanf("%d", &x);
			deleteX(L, x);
			break;
		}
		case 3:
		{
			deleteFirst(L);
			break;
		}
		case 4:
		{
			deleteLast(L);
			break;
		}
		}
	}

	List e = L->next;
	int em = 0;
	while (1)
	{
		if (e == L)
			break;
		if (em++>0)
			printf(" ");
		printf("%d", e->num);
		e = e->next;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 33948
#include <iostream>
using namespace std;
int main(void){
    int n;
    while (cin >> n && n) {
        int w, h;
        cin >> w >> h;
        bool field[w][h];
        fill(field[0], field[w], 0);
        for (int i = 0; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            field[x-1][y-1] = 1;
        }
        int s, t;
        cin >> s >> t;
        int res = 0;
        for (int sy = 0; sy <= h - t; ++sy) {
            for (int sx = 0; sx <= w - s; ++sx) {
                int count = 0;
                for (int dy = 0; dy < t; ++dy) {
                    for (int dx = 0; dx < s; ++dx) {
                        count += field[sx + dx][sy + dy];
                    }
                }
                res = max(res, count);
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B, T;
  cin >> A >> B >> T;
  ll ans = T / A * B;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
struct node
{
    int id,num;
};
bool cmp(node a,node b)
{
    return a.num>b.num;
}
node odd[maxn],even[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(i%2)
            odd[a[i]].num++;
        else
            even[a[i]].num++;
    }
    for(int i=1;i<=100000;i++)
        odd[i].id=even[i].id=i;
    sort(odd+1,odd+100000+1,cmp);
    sort(even+1,even+100000+1,cmp);
    int ans=-1;
    if(odd[1].id!=even[1].id)
        ans=n-odd[1].num-even[1].num;
    else
        ans=min(n-odd[1].num-even[2].num,n-even[1].num-odd[2].num);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2176