akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  1094
//
//  Created by cfhaiteeh on 2018/4/20.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#define LL long long
using namespace  std;

int n,m;
int ai[12];
int bi[12];
bool vis[12];
bool flag;
void DFS(int now,int sum){
    if(flag){
        return;
    }
    if(now==n+1){
     //   cout<<sum<<endl;
        int _sum=0;
        int total=0;
        for(int i=1;i<=n;i++){
            if(vis[i]){
                _sum+=ai[i];
                total+=bi[i];
                total+=(i*100*ai[i]);
            }
        }
        if(_sum>sum){
            return;
        }
        if(total>=m){
            flag=true;
            return;
        }
        
        sum-=_sum;
        for(int i=n;i>=1;i--){
            if(!vis[i]){
                if(sum>=ai[i]-1){
                    sum-=(ai[i]-1);
                    total+=i*100*(ai[i]-1);
                }
                else{
                    total+=i*100*(sum);
                    break;
                }
            }
        }
        if(total>=m){
            flag=true;
            return;
        }
        return;
    }
    vis[now]=1;
    DFS(now+1,sum);
    vis[now]=0;
    DFS(now+1,sum);
}
int main() {
    // insert code here...
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%d%d",&ai[i],&bi[i]);
        }
        flag=0;
        for(int i=1;i<=1000;i++){
            DFS(1, i);
            if(flag){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

int main(){
   ll a, b, c; cin >> a >> b >> c;
   if(a == b && b == c) cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if(a*n > b) {
        cout << b;
    }else{
        cout << a*n;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    set<string> st;

    int n; cin >> n;
    for(int i=0;i<n;i++){
        string s; cin >> s;
        st.insert(s);
    }

    cout << (int)st.size() << endl;
    return 0;
}

Measured memory_bytes: 19228
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String base = br.readLine();
            String pairBase = "T";
            if (base.equals("T")) {
                pairBase = "A";
            } else if (base.equals("C")) {
                pairBase = "G";
            } else if (base.equals("G")) {
                pairBase = "C";
            }

            System.out.println(pairBase);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 19284
#include<stdio.h>
int main()
{
    int a,b,c,x,y,z;
    scanf("%d%d%d",&a,&b,&c);
    x=a-b;
    if(c<x)
    {
        printf("0\n");
    }
    else
    {
        printf("%d\n",c-x);
    }

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    using ll=long long;
    using vin=vector<int>;
    using vll=vector<long long>;
    using vvin=vector<vector<int>>;
    using vvll=vector<vector<long long>>;
    using vstr=vector<string>;
    using vvstr=vector<vector<string>>;
    using vch=vector<char>;
    using vvch=vector<vector<char>>;
    using vbo=vector<bool>;
    using vvbo=vector<vector<bool>>;
    using vpii=vector<pair<int,int>>;
    using pqsin=priority_queue<int,vector<int>,greater<int>>;
    #define mp make_pair
    #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++)
    #define all(v) v.begin(),v.end()
    #define decp(n) cout<<fixed<<setprecision((int)n)
    const ll inf=1e9+7;
    const ll INF=1e18;
     
    int main(){
        ll n,W;cin>>n>>W;
        vvll wei(4);
        rep(i,4)wei[i].push_back(inf);
        ll w,v,tmp;cin>>w>>v;
        tmp=w;wei[0].push_back(v);
        rep(i,n-1){
            cin>>w>>v;
            wei[w-tmp].push_back(v);
        }
        rep(i,4){
            sort(all(wei[i]));
            reverse(all(wei[i]));
            wei[i][0]=0;
        }
        rep(i,4)rep(j,wei[i].size()-1)wei[i][j+1]+=wei[i][j];
        ll ans=0;
        rep(i,wei[0].size())rep(j,wei[1].size())rep(k,wei[2].size())rep(l,wei[3].size()){
            if((i+j+k+l)*tmp+j+2*k+3*l<=W){
                ans=max(ans,wei[0][i]+wei[1][j]+wei[2][k]+wei[3][l]);
            }
        }
        cout<<ans<<endl;
    }

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

void dfs(vector<vector<int>>& anc,vector<vector<P>>& G,vector<int>& depth,vector<ll>& dist,int i,int p = -1) {
    for (P& e : G[i]) if (e.first != p) {
        anc[e.first].push_back(i);
        depth[e.first] = depth[i]+1;
        dist[e.first] = dist[i]+e.second;
        dfs(anc,G,depth,dist,e.first,i);
    }
}

void init(vector<vector<int>>& anc,vector<vector<P>>& G,vector<int>& depth,vector<ll>& dist,int k) {
    depth[k] = 0;
    dist[k] = 0;
    dfs(anc,G,depth,dist,k);
    int n = anc.size();
    for (int i = 0;i < 20;++i) {
        for (int j = 0;j < n;++j) {
            if (anc[j].size() < i+1 || anc[anc[j][i]].size() < i+1) continue;
            anc[j].push_back(anc[anc[j][i]][i]);
        }
    }
}

int lca(vector<vector<int>>& anc,vector<int>& depth,vector<ll>& dist,int i,int j) {
    if (depth[i] > depth[j]) swap(i,j);
    while (depth[i] < depth[j]) {
        for (int k = anc[j].size()-1;k >= 0;--k) if (depth[anc[j][k]] >= depth[i]) {
            j = anc[j][k];
            break;
        }
    }
    while (i != j) {
        for (int k = anc[i].size()-1;k >= 0;--k) {
            if (anc[i][k] != anc[j][k]) {
                i = anc[i][k];
                j = anc[j][k];
                break;
            } else if (k == 0) {
                i = j = anc[i][0];
            }
        }
    }
    return i;
}

int calc_dist(vector<vector<int>>& anc,vector<int>& depth,vector<ll>& dist,int i,int j) {
    return dist[i]+dist[j]-dist[lca(anc,depth,dist,i,j)]*2;
}

int main() {
    int n,u,v;
    cin >> n >> u >> v;
    u--;v--;
    vector<vector<int>> anc(n);
    vector<vector<P>> edges(n);
    vector<int> depth(n);
    vector<ll> dist(n);
    for (int i = 0;i < n-1;++i) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        edges[a].push_back(P(b,1));
        edges[b].push_back(P(a,1));
    }
    init(anc,edges,depth,dist,v);
    int ans = 0;
    for (int i = 0;i < n;++i) {
        int l = lca(anc,depth,dist,u,i),a = calc_dist(anc,depth,dist,u,l),b = dist[l];
        int ret = calc_dist(anc,depth,dist,v,i);
        if (edges[i].size() == 1) ret--;
        if (a < b) ans = max(ans,ret);
    }
    cout << ans << endl;
}

Measured memory_bytes: 26368
// template version 1.8

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}


int solve(){
  int h,w;cin>>h>>w;
  vector<vector<int>> m(h, vector<int>(w));
  rep(i, h){
    string s;cin>>s;
    rep(j,w){
      m[i][j]=(s[j]=='#'?1:0);
    }
  }
  dump_2d(m, h, w);

  vvi d(h, vi(w, INF));
  typedef pair<int, pii> CP; // (cost, pos)
  // queue<CP> q;
  PQ<CP> q;
  rep(i,h)rep(j,w){
    if (m[i][j]==1) q.push(CP(0LL, pii(i, j)));
  }
  while (!q.empty()){
    auto v = q.top(); q.pop();
    int cost = v.first;
    int x = v.second.first;
    int y = v.second.second;
    if (cost < d[x][y]){
      d[x][y] = cost;
      rep(i, 4){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if (0<= nx && nx <= h-1 && 0<=ny && ny <= w-1){
          if (cost+1 < d[nx][ny]) q.push(mp(cost+1, mp(nx, ny)));
        }
      }
    }
  }
  dump_2d(d, h, w);
  int res=0;
  rep(i,h)rep(j,w){
    chmax(res, d[i][j]);
  }
  cout << res << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 66408
#include<cstdio>
int main(){
    int a,b,c,count=0;
	scanf("%d%d%d",&a,&b,&c);
	for(int i = a; i<=b; i++){
		if(c%i==0){
			count+=1;
		}
	}
	printf("%d\n",count);
}

Measured memory_bytes: 2748
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n, key, j;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) {
        cin >> a[i];
    }
    for(int i=0;i<n;i++) {
        key = a[i];
        j = i-1;
        while(j >= 0 && a[j] > key) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = key;
        for (int k=0;k<n;k++) {
            cout << a[k];
            if(k!=n-1) {
                cout << " ";
            } else {
                cout << endl;
            }
        }
    }
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define YOU setprecision
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e,f;
  string s;
  cin >>i[0]>>i[1]>>i[2];
  sort(i,i+3);
  d=abs(i[0]-i[1])+abs(i[1]-i[2]);
  cout <<d<<'\n';
  return (0);
}


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

using namespace std;

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

	int ans = 1e9;
	for (int i = 0; i < 133; ++i) {
		int tmp = 0;
		for (auto v : x) { tmp += (v - i)*(v - i); }
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
from math import ceil

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

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a), B.append(b)
max_a = max(A)
B = sorted(list(filter(lambda x: x > max_a, B)))

count = 0
while H > 0:
    if B:
        H -= B.pop()
    else:
        count += ceil(H / max_a)
        break
    count += 1
print(count)


Measured memory_bytes: 12848
#include<iostream>
using namespace std;
int main()
{
    char str;
    cin>>str;
    if(str=='A')
        cout<<"T"<<endl;
    else if(str=='T')
        cout<<"A"<<endl;
    else if(str=='C')
        cout<<"G"<<endl;
    else if(str=='G')
        cout<<"C"<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
    This code is made by ghy.
    Oj: Atcoder
    Language: C++
    Status: AC
    Complexity: O(n+val^2) 
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <utility>
#include <ctime>
#define ll long long
#define rg register
#define il inline
#define pb(a) push_back(a)
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define mst(a,b) memset(a,b,sizeof a)
#define mp(a,b) make_pair(a,b)
#define smallrootpile priority_queue <int,vector<int>,greater<int> >
#define bigrootpile priority_queue <int>
using namespace std;
il int read(){
    rg int x=0,f=1; rg char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-') f=-1; c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48); c=getchar();
    }
    return x*f;
}

const int Inf1=0x3f3f3f3f;
const int Inf2=1e9,mod=1e9+7;
const int N=2e5+5,M=8005;
int n,a[N],b[N];
ll ans,fac[M],inv[M];
int dp[4005][4005],cnt=2001;

il ll qpow(ll a,int b){
	ll ret=1;
	while(b){
		if(b&1)
			ret=(ret*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ret;
}

il void init(){
	fac[0]=1;
	for(rg int i=1;i<=8000;++i)
		fac[i]=(fac[i-1]*i)%mod;
	inv[8000]=qpow(fac[8000],mod-2);
	for(rg int i=7999;i;--i)
		inv[i]=(inv[i+1]*(i+1))%mod;
}

il ll choose(int a,int b){
	return (((fac[a]*inv[b])%mod)*inv[a-b])%mod;
}

int main(){
	n=read();
	init();
	for(rg int i=1;i<=n;++i){
		a[i]=read();
		b[i]=read();
		++dp[cnt-a[i]][cnt-b[i]];
	}
	for(rg int i=1;i<=(cnt<<1);++i)
		for(rg int j=1;j<=(cnt<<1);++j)
			dp[i][j]=((dp[i][j]+dp[i][j-1])%mod+dp[i-1][j])%mod;
	for(rg int i=1;i<=n;++i){
		ans=(ans+dp[a[i]+cnt][b[i]+cnt])%mod;
		ans=(ans-choose((a[i]<<1)+(b[i]<<1),(a[i]<<1))+mod)%mod;
	}
	printf("%lld\n",(ans*500000004)%mod);
    return 0;
}


Measured memory_bytes: 64640
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		Random r = new Random();
		
		long startMilli = System.currentTimeMillis();
		
		final int N = 26;

		int D = sc.nextInt();
		int[] c = new int[N];
		for(int i=0; i<N; i++)
			c[i] = sc.nextInt();
		
		int[][] s = new int[D][N];
		for(int i=0; i<D; i++)
			for(int j=0; j<N; j++)
				s[i][j] = sc.nextInt();
		
		int[] t = new int[D];
//		for(int i=0; i<D; i++)
//			t[i] = r.nextInt(N);

		int[] last = new int[N];
		for(int i=0; i<D; i++) {
			int bestIndex = -1;
			int bestScore = 0;
			for(int j=0; j<N; j++) {
				int score = s[i][j] + c[j]*(i+1-last[j]);
				if(bestIndex < 0 || score > bestScore) {
					bestIndex = j;
					bestScore = score;
				}
			}
			t[i] = bestIndex;
			last[bestIndex]=i+1;
		}
		
//		int score = 0;
//		int[] last = new int[N];
//		for(int i=0; i<D; i++) {
//			score += s[i][t[i]];
//			last[t[i]]=i+1;
//			for(int j=0; j<N; j++)
//				score -= c[j]*(i+1-last[j]);
//		}
		
		long currentMilli = System.currentTimeMillis();

		while(currentMilli - startMilli < 1900) {
			for(int i=0; i<1000; i++) {
				int d = r.nextInt(D)+1;
				int to = r.nextInt(N);
				int from = t[d-1];
				if(from==to)
					continue;
	
				int scoreDiff = s[d-1][to] + c[to]*(d-getIndex(t, to, d, false))*(getIndex(t, to, d, true)-d);
				scoreDiff -= s[d-1][from] + c[from]*(d-getIndex(t, from, d, false))*(getIndex(t, from, d, true)-d);
				if(scoreDiff>0)
					t[d-1] = to;
			}
			currentMilli = System.currentTimeMillis();
		}
		for(int i=0; i<D; i++)
			pw.println(t[i]+1);

		sc.close();
		pw.close();
	}
	
	static int getIndex(int[] t, int type, int base, boolean isForward) {
		int ans = base;
		int diff = isForward ? 1 : -1;
		ans += diff;
		while(1 <= ans && ans <= t.length) {
			if(t[ans-1]==type)
				return ans;
			ans += diff;
		}
		return ans;
	}
}


Measured memory_bytes: 38040
class UnionFind
    # ref : https://qiita.com/k_karen/items/5349a25c3eb7b4697f58
    def initialize(size)
        @rank = Array.new(size, 0)
        @parent = Array.new(size, &:itself)
    end
    # attr_accessor :rank, :parent
    def unite(id_x, id_y)
        x_parent = get_parent(id_x)
        y_parent = get_parent(id_y)
        return if x_parent ==y_parent
        if @rank[x_parent] > @rank[y_parent] then
            @parent[y_parent] = x_parent
        else
            @parent[x_parent] = y_parent
            @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
        end
    end
    def get_parent(id_x)
        @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
    end
    def same_parent?(id_x, id_y)
        get_parent(id_x) == get_parent(id_y)
    end
    def size
        @parent.map { |id_x| get_parent(id_x) }.uniq.size
    end
end

n, m = gets.chomp.split(' ').map(&:to_i)
roads = Array.new(m){ gets.chomp.split(' ').map(&:to_i) }

cities = UnionFind.new(n + 1)
cities.unite(0, 1)

roads.each do |road|
    a, b = road
    cities.unite(a, b)
end

puts cities.size - 1

Measured memory_bytes: 24836
include Math
dir = PI / 2
x, y = 0, 0
while (arg = gets.split(",").map(&:to_f)) != [0,0]
  x, y = x + cos(dir) * arg[0], y + sin(dir) * arg[0]
  dir -= arg[1] / 180 * PI
end
puts x.to_i, y.to_i

Measured memory_bytes: 6180
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] v = new int[n];
    for (int i = 0; i < n; i++) {
      v[i] = sc.nextInt();
    }
    int[] o = new int[100001];
    int[] e = new int[100001];
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) e[v[i]]++;
      else o[v[i]]++;
    }
    int o1 = 0, o2 = 0, e1 = 0, e2 = 0, o1i = 0, o2i = 0, e1i = 0, e2i = 0;
    for (int i = 1; i <= 100000; i++) {
      if (o2 < o[i]) {
        o2 = o[i];
        o2i = i;
      }
      if (o1 < o2) {
        int temp = o1;
        o1 = o2;
        o2 = temp;
        temp = o1i;
        o1i = o2i;
        o2i = temp;
      }
      if (e2 < e[i]) {
        e2 = e[i];
        e2i = i;
      }
      if (e1 < e2) {
        int temp = e1;
        e1 = e2;
        e2 = temp;
        temp = e1i;
        e1i = e2i;
        e2i = temp;
      }
    }
    if (o1i != e1i) System.out.println(n - o1 - e1);
    else System.out.println(Math.min(n - o1 - e2, n - o2 - e1));
  }
}

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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    Int n,m;
    cin >> n >> m;
    if(n==1||m==1){
        if(n>2||m>2)cout << n*m-2<<endl;
        else if(n==1&&m==1)cout << 1 << endl;
        else cout << 0 << endl;
        //else if(n*m-2*((n-1)+(m-1))<0)cout << 0 << endl;
    }else cout <<n*m-((n-1)+(m-1))*2 <<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

// 2018-07-28T19:39:48+0800

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

func main() {
	var A, B int
	fmt.Scanf("%d%d", &A, &B)
	fmt.Printf("%d", max(A*B, max(A+B, A-B)))
}

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

int main()
{
    int n,d=0;
    cin>>n;
    for(int i=1; i<=9; i++)
    {
        if(n%i==0 && n/i >=1 && n/i <=9)
            d=1;
    }
    if(d) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}



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

sa = [0 for _ in range(N)]
sa[0] = A[0]
for i in range(1, N):
    sa[i] = sa[i-1] + A[i]

from collections import Counter
ca = Counter(sa)
ans = 0
for k, v in ca.items():
    if k == 0:
        ans += v
    
    if v >= 2:
        ans += v * (v-1) // 2
print(ans)

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i,n) {
        cin >> h[i];
    }
    vector<bool> ok(n,true);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        if (h[a] <= h[b]) ok[a] = false;
        if (h[b] <= h[a]) ok[b] = false;
    }
    int ans = 0;
    rep(i,n) if (ok[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3776
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long

int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=1000+10;
const char ch[4]={'L','R','D','U'};
const char dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};

int n,x[N],y[N];
vector<int> c;

signed main() {
    n=read();
    for (int i=1;i<=n;++i) x[i]=read(),y[i]=read();
    for (int i=2;i<=n;++i)
        if ((abs(x[i]+y[i])&1)!=(abs(x[1]+y[1])&1)) {
            puts("-1"); return 0;
        }
    for (int i=30;~i;--i) c.push_back(1<<i);
    if (!(abs(x[1]+y[1])&1)) c.push_back(1);
    printf("%lu\n",c.size());
    for (int i:c) printf("%lld ",i); puts("");
    for (int i=1;i<=n;++i) {
        int nx=0,ny=0;
        for (int j:c) {
            vector<pair<int,int> > o;
            for (int d=0;d<4;++d) {
                int tx=nx+dx[d]*j,ty=ny+dy[d]*j;
                o.push_back(make_pair(abs(x[i]-tx)+abs(y[i]-ty),d));
            }
            sort(o.begin(),o.end());
            int d=o.begin()->second;
            putchar(ch[d]),nx+=dx[d]*j,ny+=dy[d]*j;
        }
        puts("");
    }
    return 0;
}

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

using namespace std;

int main(){
	int n, m, p[1000];
	char N[100][9], B[9];
	long lot;
	scanf("%d %d", &n, &m);
	while (n){
		for (int i = 0; i < n; i++){
			cin >> N[i];
			scanf("%d", &p[i]);
		}
		lot = 0;
		for (int i = 0; i < m; i++){
			cin >> B;
			for (int j = 0; j < n; j++){
				int flag = 1;
				for (int k = 0; k < 8; k++){
					if (N[j][k] != '*' && N[j][k] != B[k]){
						flag = 0;
					}
				}
				if (flag){
					lot += p[j];
					break;
				}
			}
		}
		printf("%d\n", lot);
		scanf("%d %d", &n, &m);
	}

	return 0;
}

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

int main() {
    vector<int> a(5);
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
    }
    int k;
    cin >> k;
    sort(a.begin(), a.end());
    if (a.back() - a[0] > k) {
        cout << ":(" << endl;
    }
    else
        cout << "Yay!" << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

struct RollingHash {
  const int h = 1000000007;
  const int b = 10007;
  vector<int> ha;
  vector<int> po;
  RollingHash(const string &s) {
    int n = (int) s.size();
    ha.assign(n + 1, 0);
    po.assign(n + 1, 1);
    for (int i = 0; i < n; i++) {
      ha[i + 1] = ((long long) ha[i] * b + s[i]) % h;
      po[i + 1] = ((long long) po[i] * b) % h;
    }
  }
  int get(int l, int r) {
    return (ha[r] + h - ((long long) ha[l] * po[r - l]) % h) % h;
  }
};

void solve() {
  int n;
  cin >> n;
  vstr S(n);
  cin >> S;
  vstr T;
  rep(i, n) {
    string s;
    rep(j, n) s.push_back(S[j][i]);
    T.push_back(s);
  }
  rep(i, n) {
    S[i] += S[i];
    T[i] += T[i];
  }
  vector<RollingHash> srh, trh;
  rep(i, n * 2) {
    srh.push_back(RollingHash(S[i % n]));
    trh.push_back(RollingHash(T[i % n]));
  }
  int ans = 0;
  rep(i, n) {
    bool ok = true;
    rep(k, n - 1) {
      if (srh[i + k].get(k + 1, n) != trh[k].get(i + k + 1, i + n)) {
        ok = false;
        break;
      }
    }
    if (ok) ans += n;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
import java.util.*;

class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int i=0;
for(;;){
int n =sc.nextInt();
int m =sc.nextInt();
if(n==0 && m==0) break;
if(n>m){ i=n; n=m; m=i;} 
System.out.println(n+" "+m);
}
}
}

Measured memory_bytes: 27188
import math
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=a[0]
ctn=1
l=[]
l2=[]
for i in range(1,n):
  if x==a[i]:
    ctn+=1
  else:
    l.append([x,ctn])
    l2.append(x)
    x=a[i]
    ctn=1
l.append([x,ctn])
l2.append(x)

b=[]
for i in range(1,50):
  b.append(2**i)

ct=0
for i in range(len(l2)-1,-1,-1):
    x=math.floor(math.log2(l2[i]))
    x=b[x]-l2[i]
    y=bisect.bisect_left(l2,x)
    if l2[y]==x:
      if l2[y]!=l2[i]:
        m=min(l[i][1],l[y][1])
      else:
        m=l[i][1]//2
      l[i][1]-=m
      l[y][1]-=m
      ct+=m
print(ct)

Measured memory_bytes: 36500
import re
s = raw_input()

joi_pattern = '(J*)(O*)(I*)'

ans = 0

for joi_group in re.findall(joi_pattern, s):
    j = len(joi_group[0])
    o = len(joi_group[1])
    i = len(joi_group[2])
    if j >= o and o <= i:
        ans = max(ans, o)

print ans

Measured memory_bytes: 49564
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];
 
ll n,i,j=1;
ll a,b;
bool flag = false;
long long int x[55];
int d,ans=0;
char s[100005];
bool k[100005];

int main(){
	cin>>n;
	cin>>s;
	//仮定１
	k[1]=k[2]=true;
	while(true){
		ans=0;
		for(i=3;i<=n;i++){
			if((s[i-2]=='o' && k[i-1]) || (s[i-2]=='x' && !k[i-1])){
				k[i]=k[i-2];
			}else{
				k[i]=!k[i-2];
			}
		}
		// for(i=1;i<=n;i++)cout<<k[i]<<endl;
		if((k[n] && k[1]==k[n-1] && s[n-1]=='o') || (k[n] && k[1]!=k[n-1] && s[n-1]=='x') || (!k[n] && k[1]==k[n-1] && s[n-1]=='x') || (!k[n] && k[1]!=k[n-1] && s[n-1]=='o')){
			ans ++;
		}
		if((k[1] && k[2]==k[n] && s[0]=='o') || (k[1] && k[2]!=k[n] && s[0]=='x') || (!k[1] && k[2]==k[n] && s[0]=='x') || (!k[1] && k[2]!=k[n] && s[0]=='o')){
			ans ++;
		}
		if(ans==2){
			for(i=1;i<=n;i++){
				if(k[i])cout<<"S";
				else cout<<"W";
			}
			break;
		}else{
			if(k[1]&&k[2]){
				k[1]=true;
				k[2]=false;
			}else if(k[1] && !k[2]){
				k[1]=false;
				k[2]=true;
			}else if(!k[1] && k[2]){
				k[1]=k[2]=false;
			}else{
				cout<<-1;
				break;
			}
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2944
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] a = new int[n];
            PriorityQueue<Integer> p = new PriorityQueue<>(Collections.reverseOrder());
            for (int i = 0; i < n; i++) {
                a[i] = s.nextInt();
                p.add(a[i]);
            }
            int x = p.poll(), y = p.poll();
            for (int i = 0; i < n; i++) {
                w.println(a[i] == x ? y : x);
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 44996
#include<bits/stdc++.h>
using namespace std;
string s;
int num[30],k;
int main(){
	cin>>s;
	int l=s.size();
	for(int i=0;i<l;i++){
		num[s[i]-'A']++;
		if(num[s[i]-'A']==2)k++;
	}
	if(k==2)puts("Yes");
	else puts("No");
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define fio() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long  ll;
typedef double coord_t;     
typedef double coord2_t;
const ll inf = 1e9;
const ll MOD = 1e9 + 7;
const ll zero = 0;
const ll maxn = 1e5 + 5;

struct Point {
	coord_t x, y;

	bool operator <(const Point &p) const {
		return y < p.y || (y == p.y && x < p.x);
	}
};


coord2_t cross(const Point &O, const Point &A, const Point &B)
{
	return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}


vector<Point> convex_hull(vector<Point> P)
{
	ll n = P.size(), k = 0;
	if (n == 1) return P;
	vector<Point> H(2*n);

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

	for (int i = 0; i < n; ++i) {
		while (k >= 2 && cross(H[k-2], H[k-1], P[i]) < 0) k--;
		H[k++] = P[i];
	}

	for (int i = n-2, t = k+1; i >= 0; i--) {
		while (k >= t && cross(H[k-2], H[k-1], P[i]) < 0) k--;
		H[k++] = P[i];
	}

	H.resize(k-1);
	return H;
}
vector<Point> v, ans;
Point p;
ll n, x, y;
int main(){ 
	fio();
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> x >> y;
		p.x = x + inf;
		p.y = y + inf;
		v.pb(p);
	}
	ans = convex_hull(v);
	cout << ans.size() << endl;
	for ( int i = 0; i < ans.size(); i++ ) {
		p = ans[i];
		if ( p.x >= 0)
			cout << p.x - inf << " " << p.y - inf << endl;
	}
	return(0);
}


Measured memory_bytes: 9192
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back

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

    vector<bool> can(N, false);

    char f;
    for(int i = 0; i < N; i++){
        cin >> f;
        if(f == '.'){
            can[i] = true;
        }
    }

    //Bはとにかくいければよい
    for (int i = B; i < D - 1; i++)
    {
        if (can[i] == false && can[i + 1] == false)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = A; i < C - 1; i++)
    {
        if (can[i] == false && can[i + 1] == false)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    // 重ならない場合
    if (C < D || C < B)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        for (int i = B - 1; i < D; i++)
        {
            if(can[i] && can[i+1] && can[i+2]){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7


def cmb(n,r):
    mod = 10**9+7
    ans = 1
    for i in range(r):
        ans *= n-i
        ans %= mod
    for i in range(1,r+1):
        ans *= pow(i,mod-2,mod)
        ans %= mod
    return ans


total = pow(2, n, mod) - cmb(n, a) - cmb(n, b) - 1
print(total % mod)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    cout << 180 * (N - 2) << endl;
    return 0;
}


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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int MAX = 1e5;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for(int i=0; i<MAX; ++i) {
    if(!is_prime[i]) continue;
    for(int j=i*2; j<MAX; j+=i) is_prime[j] = 0;
  }
  vector<int> a(MAX, 0);
  for(int i=0; i<MAX; ++i) {
    if(i % 2 == 0) continue;
    if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
  }

  vector<int> s(MAX+1, 0);
  for(int i=0; i<MAX; ++i) s[i+1] = s[i] + a[i];

  int q; cin >> q;
  for(int i=0; i<q; ++i) {
    int l, r; cin >> l >> r;
    ++r;
    cout << s[r] - s[l] << '\n';
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int x,y,z,k;cin >> x >> y >> z >> k;
   vector<ll> A(x);rep(i,x)cin >> A[i];
   vector<ll> B(y);rep(i,y)cin >> B[i];
   vector<ll> C(z);rep(i,z)cin >> C[i];

   sort(All(A),greater<ll>());
   sort(All(B),greater<ll>());
   sort(All(C),greater<ll>());
   
   vector<ll> ans(k);
   rep(a,x){
      rep(b,y){
         if(a*b > k)break;
         rep(c,z){
            if(a*b*c <= k)ans.push_back(A[a]+B[b]+C[c]);
            else break;
         }
      }
   }
   sort(All(ans),greater<ll>());
   rep(i,k){
      cout << ans[i] << endl;
   }
   return 0;
}

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

void bsort(double a[], int n)
{
	for (int i = 0; i < n - 1; i++) {
		for (int j = n - 1; j > i; j--) {
			if (a[j - 1] > a[j]) {
				int temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
			}
		}
	}
}

int main()
{
	int N = 0;
	double v[1000] = { 0 };
	double res = 0;

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

	bsort(v, N);

	res += v[0] / pow(2, N - 1);
	for (int i = 1; i < N; i++) {
		res += v[i] / pow(2, N - i);
	}
	
	cout << res;

	return 0;
}



Measured memory_bytes: 512
// #define CPP_IO

#pragma region

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T>;

#define f first
#define s second

#ifdef LOCAL
#define debug cout
#define eprintf(format, ...) printf(format, __VA_ARGS__)
#else
#define debug \
    if (0) cout
#define eprintf(format, ...) 42
#endif

#define DUMP(a) debug << #a " = " << (a) << "\n";
#define DUMP2(a, b) debug << #a " = " << (a) << " " #b " = " << (b) << "\n";
#define DUMP3(a, b, c) debug << #a " = " << (a) << " " #b " = " << (b) << " " #c " = " << (c) << "\n";
#define DUMP4(a, b, c, d) debug << #a " = " << (a) << " " #b " = " << (b) << " " #c " = " << (c) << " " #d " = " << (d) << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, V> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
#ifdef CPP_IO
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
#endif
    solve();
}

#pragma endregion

const char ZERO = '.', ONE = '#';
int dp[200005][2];
void solve() {
    int n;
    string s;
    cin >> n >> s;
    dp[0][0] = (s[0] == ZERO ? 0 : 1);
    dp[0][1] = 0;
    for (int i = 1; i < n; ++i) {
        dp[i][0] = (s[i] == ZERO ? 0 : 1) + dp[i - 1][0];
        dp[i][1] = min((s[i] == ZERO ? 0 : 1) + dp[i - 1][0], (s[i] == ONE ? 0 : 1) + dp[i - 1][1]);
        DUMP3(i, dp[i][0], dp[i][1]);
    }
    printf("%d\n", dp[n - 1][1]);
}

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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

// cos p = (a*a+b*b-c*c) / 2ab
int main() {
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double l=360*(1.0*(h+1.0*m/60)/12),r=360*(1.0*m/60);
    double p=r-l;
    if(p<0) p=-p;
    if(p>180) p=360-p;
    cout<<fixed<<setprecision(10)<<sqrt(a*a+b*b-2*a*b*cos(p/360*2*acos(-1.0)))<<endl;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a;
  cin>>a;
  vector<P> b(a);
  rep(i,a)
    cin>>b[i].second>>b[i].first;
  sort(all(b));
  int g=0;
  bool ans=1;
  rep(i,a){
  g+=b[i].second;
    if(b[i].first<g)
      ans=0;
  }
  if(ans)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int X,N;
    cin>>X>>N;
    int lis[2000];
    for(int i=0;i<N;i++)cin>>lis[i];
    sort(lis,lis+N);
    int ans=-200;
    for(int i=-300;i<300;i++){
        int flg=1;
        for(int j=0;j<N;j++){
            if(i==lis[j])flg=0;
        }
        if(!flg)continue;

        if(abs(ans-X)>abs(i-X))ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    long double S;
    cin >> S;
    lint x = (lint)ceil(sqrtl(S));
    lint y = -S + (x*x);
    cout << 0 << " " <<  0 << " " <<  x << " " <<  y << " " <<  1 << " " << x << endl;
}

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

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t; cin >> s >> t;
    int r = t.size();
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int x = 0;
        for (int j = 0; j < t.size(); j++) {
            x += (s[i + j] != t[j]);
        }
        r = min(r, x);
    }
    cout << r << endl;
    return 0;
}



Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int N, Q;

int as[100000+10];
ll cs[100000+10];
ll ecs[100000+10];
ll ocs[100000+10];
       
int go(int x) {
  int left = 1;
  int right = N;
  while(left+1 < right) {
    int md = (left + right) / 2;
    int v2 = as[N-(md+1)/2-1]; // 青木くんの最大
    int v3 = as[N-md]; // 青木くんの最小
    int d = max(abs(v2-x), abs(v3-x));
    if(abs(as[N-md-1]-x) <= d) {
      left = md;
    } else {
      right = md;
    }
  }
  return right;
}

int main(void) {
  scanf("%d%d", &N, &Q);
  REP(i, N) {
    scanf("%d", &as[i]);
  }
  REP(i, N) {
    cs[i+1] = cs[i] + as[i];
    ecs[i+1] = ecs[i] + (i%2 == 0 ? as[i] : 0);
    ocs[i+1] = ocs[i] + (i%2 == 1 ? as[i] : 0);
  }
  
  REP(i, Q) {
    int x;
    scanf("%d", &x);
    int t = go(x);
    // 後ろから(t+1)/2個は高橋くんゾーン、t/2個は青木くんゾーン
    // 前側N-t個は交互
    ll res = 0;
    res += cs[N] - cs[N-(t+1)/2];
    // aoki += cs[N-(t+1)/2] - cs[N-t];
    if(N % 2 == 0) {
      res += ocs[N-t];
    } else {
      res += ecs[N-t];
    }
    cout << res << endl;
  }

  return 0;
}


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

int main(){
	int n;
	cin>>n;
	map <int, long long>mp;
	for(long long x = 1; x*x <= n;x++)
		for(long long y = 1; y*y <= n-x*x; y++){
			for(long long z = 1; z*z <= n - x*x - y*y; z++){
				long long sum = x*x + y* y + z*z + x *y + x*z +y *z;
				mp[sum]++;
			}
		}
	for(int i = 1; i<=n; i++){
		cout<<mp[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4552