akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

struct Point {
    int x, y;

    bool paired = false;

    Point(int p, int q) : x(p), y(q) {}
};

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

    int N;
    cin >> N;

    vector<Point> red;
    red.reserve(N);

    vector<Point> blue;
    blue.reserve(N);

    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        red.push_back(Point(x, y));
    }

    std::sort(red.begin(), red.end(), [](const Point& left, const Point& right) {
        return left.y > right.y;
    });

    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        blue.push_back(Point(x, y));
    }

    std::sort(blue.begin(), blue.end(), [](const Point& left, const Point& right) {
        return left.x < right.x;
    });

    int pair_count = 0;

    for (auto pb : blue) {
        for (int i = 0; i < red.size(); ++i) {
            auto pr = red[i];

            if (!pr.paired && pr.x < pb.x && pr.y < pb.y) {
                red[i].paired = true;
                ++pair_count;

                break;
            }
        }
    }

    //for (auto point : red) {
    //    // edge
    //    if (point.x >= N * 2 - 1 || point.y >= N * 2 - 1) continue;

    //    int min = 9999999;
    //    Point blue(-1, -1);

    //    for (int i = point.y + 1; i < N * 2; ++i) {
    //        for (int j = point.x + 1; j < N * 2; ++j) {
    //            if (square[i][j] != Blue) continue;

    //            Point t(j, i);
    //            int dist = point.dist(t);

    //            if (dist < min) {
    //                min = dist;
    //                blue = t;
    //            }
    //        }
    //    }

    //    if (blue.x != -1 && blue.y != -1) {
    //        ++pair_count;
    //        square[blue.y][blue.x] = White;
    //    }
    //}

    out(pair_count);

    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
int main(){
	int a,b,n,sq;
	char c[100];
	scanf("%d%d",&a,&b);
	sprintf(c,"%d%d",a,b);
	n=atoi(c);
	sq=(int)sqrt(n);
	if(sq*sq==n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long a, b;
int main(){
	cin >> a >> b;
	if(a <= 0 && b >=0){
		cout << "Zero" << endl;
		return 0;
	}
	if(b < 0){
		if((b-a)%2 == 0){
			cout << "Negative" << endl;
		}else{
			cout << "Positive" << endl;
		}
		return 0;
	}
	if(a >0){
		cout << "Positive" << endl;
		return 0;
	}
	return 1;
}


Measured memory_bytes: 256
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;


int main(){
    //IOS
    //freopen("output.txt","w",stdout);

    int n,m;
    cin>>n>>m;
    int val[10];
    val[0]=9999999;
    val[1]=2;
    val[2]=5;
    val[3]=5;
    val[4]=4;
    val[5]=5;
    val[6]=6;
    val[7]=3;
    val[8]=7;
    val[9]=6;
    vector<pair<int,int> >vec;
    for(int i=0;i<m;i++){

        int a;
        cin>>a;
        vec.pb({val[a],a});
    }
    string dp[n+10];
    for(int i=0;i<n+10;i++){
        dp[i]="-1";
    }

    dp[0]="";
    for(int i=0;i<n;i++){
        if(dp[i]=="-1")continue;
        for(int j=0;j<vec.size();j++){
            string cur=dp[i];
            char ch = (char)('0'+vec[j].second);
            //cout<<ch<<"\n";
            cur+=ch;
            //cout<<cur<<"\n";
            int v = i+vec[j].first;
            //cout<<v<<"\n";
            if(dp[v]=="-1"){
                dp[v]=cur;
            }
            else{
                if(dp[v].size()==cur.size()){
                    if(dp[v]<cur){
                        dp[v]=cur;
                    }
                }
                else if(dp[v].size()<cur.size()){
                    dp[v]=cur;
                }
            }

        }
    }
    cout<<dp[n]<<"\n";
}


Measured memory_bytes: 44928
#include<bits/stdc++.h>
using namespace std;
vector<int>pre,in,post;
int pos,n; 
void res(int l,int r){
	if(l>=r)return ;
	int root =pre[pos++];
	int m=distance(in.begin(),find(in.begin(),in.end(),root));
	res(l,m);
	res(m+1,r);
	post.push_back(root);
}
int main(){
	scanf("%d",&n);int k;
	for(int i=0;i<n;i++){
		scanf("%d",&k);pre.push_back(k);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&k);in.push_back(k);
  }
  res(0,n); 
  for(int i=0;i<n;i++){
 		if(i==0)printf("%d",post[i]);
 		else printf(" %d",post[i]);
  } printf("\n");
  
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;

const int maxn = 1e5 + 10;
int a[maxn];

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int n, k, s;
	cin >> n >> k >> s;
	for(int i = 1; i <= k; ++ i)
	{
		a[i] = s;
	}
	
	int ex = (int) 1e9 - 2;
	if(s == ex) ++ ex;
	for(int i = k + 1; i <= n; ++ i)
	{
		a[i] = ex;
	}
	for(int i = 1; i <= n; ++ i)
		cout << a[i] << ' ';
	cout << '\n';
	
	return 0;
}






Measured memory_bytes: 2176
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


struct city {
    int x, y, index;

    bool operator<(const city &other) const {
        return x < other.x;
    }
};

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N;
    cin >> N;
    vector<city> cities(N);

    for (int i = 0; i < N; i++) {
        cin >> cities[i].x >> cities[i].y;
        cities[i].index = i;
    }

    sort(cities.begin(), cities.end());
    vector<int> answers(N, -1);
    vector<int> queued;
    int minimum = N;

    for (int i = 0; i < N; i++) {
        minimum = min(minimum, cities[i].y);
        queued.push_back(cities[i].index);

        if (minimum == N - i) {
            int size = int(queued.size());

            for (int x : queued)
                answers[x] = size;

            queued.clear();
        }
    }

    for (int i = 0; i < N; i++)
        cout << answers[i] << '\n';
}


Measured memory_bytes: 7304
#include<vector>
#include<algorithm>
#include<functional>

#include<iostream>
#include<string>
using namespace std;


template<class T>
class IntervalHeap{
	std::vector<T> data;
	template<int b,class C>
	void heapup(C cmp,int k=-1){
		if(k==-1)k=(1+size())/2-1;
		int p;
		while(k){
			p=(k-1)/2;
			if(!cmp(data[2*k+b],data[2*p+b]))break;
			std::swap(data[2*k+b],data[2*p+b]);
			k=p;			
		}
	}
	template<int b,class C>
	void heapdown(C cmp){
		int x,k=0;
		while(1){
			x=2*k+1;
			if(size()<=2*x+b)break;
			if(2*(x+1)+b<size()&&cmp(data[2*(x+1)+b],data[2*x+b]))x++;
			if(!cmp(data[2*x+b],data[2*k+b]))break;
			std::swap(data[2*x+b],data[2*k+b]);
			if(2*x+1<size()&&data[2*x+1]<data[2*x])
				std::swap(data[2*x+1],data[2*x]);
			k=x;
		}
	}
public:
	int size()const{return data.size();}
	void push(T v){
		if(size()&1){
			data.push_back(v);
			if(data[size()-2]>data[size()-1]){
				std::swap(data[size()-2],data[size()-1]);
				heapup<0>(std::less<T>());
			}else heapup<1>(std::greater<T>());
		}else {
			data.push_back(v);
			if(2<size()){
				int k=(1+size())/2-1;
				int p=(k-1)/2;
				if(data[2*p]>data[2*k])heapup<0>(std::less<T>());
				else if(data[2*p+1]<data[2*k]){
					std::swap(data[2*p+1],data[2*k]);
					heapup<1>(std::greater<T>(),p);
				}
			}
		}
	}
	T min()const{return data.front();}
	T max()const{return 1<size()?data[1]:data[0];}
	void deleteMin(){
		data[0]=data[size()-1];
		data.pop_back();
		heapdown<0>(std::less<T>());
	}
	void deleteMax(){
		if(size()==1){
			data.pop_back();
			return;
		}
		data[1]=data[size()-1];
		data.pop_back();
		heapdown<1>(std::greater<T>());
	}
};


int main(){
	IntervalHeap<int> heap;
	string s;
	while(1){
		cin>>s;
		if(s=="end")break;
		if(s=="insert"){
			int n;
			cin>>n;
			heap.push(n);
		}else if(s=="extract"){
			cout<<heap.max()<<endl;
			heap.deleteMax();
		}
	}
	return 0;
}

Measured memory_bytes: 6772
#include <iostream>
using namespace std;
int main() {
    string A, B; cin >> A >> B;
    int diff = A.size()-B.size();
    string z = "";
    for(int i = 0; i < abs(diff); i++) z+="0";
    if(diff < 0) A = z+A;
    else if (diff > 0) B = z+B;
    if(A > B) cout << "GREATER";
    else if(A < B) cout << "LESS";
    else cout << "EQUAL";
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  int ans = 0;

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

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

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

  for (int i = 0; i < n; i++){
    ans += b[i];
    if(i != n - 1 && a[i] + 1 == a[i + 1]) 
    ans += c[a[i] - 1];
  }

  cout << ans << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
char s[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    r(m);
    LL ans=0;
    FOR(i,1,len-1)
	{
        if(m==1)
		{
            ans+=9;
        }
        else if(m==2)
		{
            if(i>=2) ans+=81*(i-1);
        }
        else if(m==3)
		{
            if(i>=3) ans+=81ll*9*(i-1)*(i-2)/2;
        }
    }

    if(m==1) ans+=s[1]-'0';
    else if(m==2)
	{
        int get=s[1]-'0'-1;
        if(get>0) ans+=get*9*(len-1);
        FOR(i,2,len)
		{
            bool flag=1;
            FOR(j,2,i-1) if(s[j]!='0') 
			flag=0;
            if(flag)
			{
                ans+=s[i]-'0';
            }
            else ans+=9;
        }
    }
    else if(m==3)
	{
        int get=s[1]-'0'-1;
        if(get>0) ans+=get*9*9*(len-1)*(len-2)/2;
        FOR(i,2,len)
		{
            bool flag=1;
            FOR(j,2,i-1) if(s[j]!='0') flag=0;
            if(flag){
                int gg=s[i]-'0'-1;
                if(gg>0) ans+=gg*9*(len-i);
                if(gg>=0)
				{
                    FOR(j,i+1,len)
					{
                        bool ff=1;
                        FOR(k,i+1,j-1) if(s[k]!='0') ff=0;
                        if(ff)
						{
                            ans+=s[j]-'0';
                        }
                        else ans+=9;
                    }
                }
            }
            else{
                ans+=9*9*(len-i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>

using namespace std;

int main()
{
	int n,a;
	int i,j;
	set<int> T_card,H_card;
	int turn,field;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		T_card.clear();
		H_card.clear();
		turn=0;
		field=0;
		
		for(i=0;i<n;i++)
		{
			cin >> a;
			T_card.insert(a);
		}
		
		set<int>::iterator it=T_card.begin();
		
		
		for(i=1;i<=n*2;i++)
		{
			if(*it!=i)
			{
				H_card.insert(i);
			}
			else
				it++;
		}
		set<int>::iterator it_h=H_card.begin();
		
		set<int>::iterator t_serch=T_card.begin();
		set<int>::iterator h_serch=H_card.begin();
		
		for(;;)
		{
			if(T_card.empty() || H_card.empty())
				break;
/*			cout << "field:" << field << endl;
			
			t_serch=T_card.begin();
			h_serch=H_card.begin();
			
			for(;t_serch!=T_card.end();t_serch++)
				cout << "T_card: " << *t_serch << endl;
			for(;h_serch!=H_card.end();h_serch++)
				cout << "H_card: " << *h_serch << endl;
*/			
			if(turn==0)
			{
				if(T_card.upper_bound(field)!=T_card.end())
				{
					it=T_card.upper_bound(field);
					field=*it;
					T_card.erase(it++);
					turn=1;
				}
				else
				{
					field=0;
					turn=1;
				}
			}
			else
			{
				if(H_card.upper_bound(field)!=H_card.end())
				{
					it_h=H_card.upper_bound(field);
					field=*it_h;
					H_card.erase(it_h++);
					turn=0;
				}
				else
				{
					field=0;
					turn=0;
				}
			}
		}
/*		it=T_card.begin();
		for(;it!=T_card.end();)
		{
			cout << "T_card:" << *it << endl;
			it++;
		}
		it_h=H_card.begin();
		for(;it_h!=H_card.end();)
		{
			cout << "H_card:" << *it_h << endl;
			it_h++;
		}
*/		
		cout << H_card.size() << "\n" << T_card.size() << endl;
	}
}

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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N; cin >> N;
	N = N % 1000;
	if (N == 0)cout << 0 << endl;
	else cout << 1000 - N << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
 
class State{
public:
    int p[31];  // p[0]???????????????
    int n;      // ???????????°
 
    bool is_over()
    {
        return p[1]==p[2] && p[2]==p[3] && p[3]==p[4] && p[4]==p[5]
            && p[5]==p[6] && p[6]==p[7] && p[7]==p[8] && p[8]==p[9]
            && p[10]==p[11] && p[11]==p[12]
            && p[13]==p[14] && p[14]==p[15]
            && p[16]==p[17] && p[17]==p[18]
            && p[19]==p[20] && p[20]==p[21];
    }
 
    void rot1()
    {
        swap(p[ 7], p[22]);  swap(p[ 8], p[23]);  swap(p[ 9], p[24]);
        swap(p[10], p[12]);  swap(p[13], p[18]);
    }
 
    void rot2()
    {
        swap(p[ 1], p[28]);  swap(p[ 2], p[29]);  swap(p[ 3], p[30]);
        swap(p[19], p[21]);  swap(p[15], p[16]);
    }
 
    void rot3()
    {
        swap(p[ 1], p[24]);  swap(p[ 4], p[27]);  swap(p[ 7], p[30]);
        swap(p[16], p[18]);  swap(p[10], p[21]);
    }
 
    void rot4()
    {
        swap(p[ 3], p[22]);  swap(p[ 6], p[25]);  swap(p[ 9], p[28]);
        swap(p[13], p[15]);  swap(p[12], p[19]);
    }
};
 
int main()
{
    int N;
    cin >> N;
 
    for(int i=0; i<N; i++){
        State now;
        for(int j=1; j<=30; j++){
            cin >> now.p[j];
        }
        now.n = 0;
 
        queue<State> que;
        que.push(now);
 
        while(!que.empty()){
            now = que.front();
            que.pop();
 
            if(now.is_over()){
                cout << now.n << endl;
                break;
            }
 
            State nex1 = now;  nex1.rot1();  nex1.n++;  que.push(nex1);
            State nex2 = now;  nex2.rot2();  nex2.n++;  que.push(nex2);
            State nex3 = now;  nex3.rot3();  nex3.n++;  que.push(nex3);
            State nex4 = now;  nex4.rot4();  nex4.n++;  que.push(nex4);
        }
    }
 
    return 0;
}

Measured memory_bytes: 13788
#include <iostream>
#include <cstdlib>

int main()
{
    struct travel {
        int t;
        int x;
        int y;
    };
    travel prev;
    prev.t = 0;
    prev.x = 0;
    prev.y = 0;
    int n;
    scanf("%d", &n);
    int i;
    for (i = 0; i < n; i++) {
        travel curr;
        scanf("%d %d %d", &curr.t, &curr.x, &curr.y);
        int absx = abs(curr.x - prev.x);
        int absy = abs(curr.y - prev.y);
        //std::cout << (((absx + absy) - (curr.t - prev.t)));
        if (((absx + absy) - (curr.t - prev.t)) > 0 \
             || ((absx + absy) - (curr.t - prev.t)) % 2 != 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
        prev.t = curr.t;
        prev.x = curr.x;
        prev.y = curr.y;
    }
        std::cout << "Yes" << std::endl;
        return 0;
}


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

struct StCst
{
  int m_nNo;
  int m_nSeq;
  bool m_bDone;

  static bool AsdNo(const StCst& cnroLeft, const StCst& cnroRight) 
  { return cnroLeft.m_nNo < cnroRight.m_nNo; }
};

void fnInput(vector<StCst>& rvoSort)
{
  int nMaxSiz, nCnt = 0;
  cin >> nMaxSiz;

  rvoSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
  {
    cin >> rvoSort[i].m_nNo;
    rvoSort[i].m_nSeq = nCnt++;
  }
}

void fnMinCostSort(vector<StCst>& rvoSort, int& rnSwpCnt)
{
  sort(begin(rvoSort), end(rvoSort), StCst::AsdNo);
  int nMinNo = rvoSort[0].m_nNo;

  int nCost;
  for (int i = 0; i < rvoSort.size(); i++)
  {
    if (rvoSort[i].m_bDone)  continue;

    int nTotal  = rvoSort[i].m_nNo;
    int nCurMin = rvoSort[i].m_nNo; 
    int nCurSize = 1;
    rvoSort[i].m_bDone = true;

    int j = rvoSort[i].m_nSeq;
    while  (rvoSort[j].m_nNo != rvoSort[i].m_nNo)
    {
      nTotal += rvoSort[j].m_nNo;
      nCurSize++;
      rvoSort[j].m_bDone = true;
      j = rvoSort[j].m_nSeq;
    }

    if (nCurSize == 1)
        nCost = 0;
    else
        nCost = min(nTotal + (nCurSize - 2) * nCurMin, 
                    nTotal + nCurMin + (nCurSize + 1) * nMinNo);
    rnSwpCnt += nCost;
  }
}

void fnResult(int nSwpCnt)
{
  cout << nSwpCnt << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StCst> voSort;

  fnInput(voSort);

  int nSwpCnt = 0;
  fnMinCostSort(voSort, nSwpCnt);

  fnResult(nSwpCnt);
  return 0;
}

Measured memory_bytes: 3208
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		sc.close();

		double p = 100.0;
		int cnt = 0;
		while (p < X) {
			p = Math.floor(p * 1.01);
			cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 35776
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);std::cout<<std::fixed<<std::setprecision(10);
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    char bef = S[0];
    int how = 0;
    REP(i,N){
        if(bef != S[i])how++;
        bef = S[i];
    }
    if(N-1 > N - how - 1 + 2*K){
    cout <<N - how - 1 + 2*K<< "\n";
    }else{
    cout <<N-1 <<  "\n";
    }
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static int[] Next(int[] array)
        {
            return Enumerable.Repeat(0, array.Length - 1)
                .Select((_, x) => (array[x] + array[x + 1]) % 10)
                .ToArray();
        }

        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var d = line.Select(x => x - '0').ToArray();
                while (d.Length > 1) d = Next(d);
                Console.WriteLine(d[0]);
            }
        }
    }
}

Measured memory_bytes: 5908
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define I 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
struct P { int x, y; bool b; };

ll d[200000][2];
int x[200000], y[200000], dx[][2]{ {0,0},{1,-1} }, dy[][2]{ {1,-1},{0,0} }, D[1000][1000][2];
vector<int>X[100000], Y[100000];
bool b[1000][1000];
struct st {
	int p; bool b; ll c;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int main() {
	int m, n, k; scanf("%d%d%d", &m, &n, &k);
	if (m <= 1000 && n <= 1000) {
		memset(D, 0x3f, sizeof(D));
		rep(i, k) {
			scanf("%d%d", &x[i], &y[i]); x[i]--; y[i]--; b[x[i]][y[i]] = true;
		}
		queue<P>que; D[0][0][0] = 0; que.push({ 0,0,0 });
		while (!que.empty()) {
			P p = que.front(); que.pop();
			rep(i, 2) {
				int nx = p.x + dx[p.b][i], ny = p.y + dy[p.b][i];
				if (0 <= nx&&nx < m && 0 <= ny&&ny < n&& D[nx][ny][p.b] == I) {
					D[nx][ny][p.b] = D[p.x][p.y][p.b] + 1;
					que.push({ nx,ny,p.b });
				}
			}
			if (D[p.x][p.y][!p.b] == I && b[p.x][p.y]) {
				D[p.x][p.y][!p.b] = D[p.x][p.y][p.b] + 1;
				que.push({ p.x,p.y,!p.b });
			}
		}
		int ans = min(D[m - 1][n - 1][0], D[m - 1][n - 1][1]);
		if (ans == I)puts("-1");
		else printf("%d\n", ans);
		return 0;
	}
	priority_queue<st>que;
	memset(d, 0x3f, sizeof(d));
	rep(i, k) {
		scanf("%d%d", &x[i], &y[i]); x[i]--; y[i]--;
		X[x[i]].push_back(i); Y[y[i]].push_back(i);
		if (x[i] == 0) {
			d[i][1] = y[i];
			que.push({ i,1,d[i][1] });
		}
	}
	while (!que.empty()) {
		st p = que.top(); que.pop();
		if (d[p.p][p.b] != p.c)continue;
		if (p.b) {
			for (int u : Y[y[p.p]]) {
				if (d[u][0] > p.c + abs(x[p.p] - x[u]) + 1) {
					d[u][0] = p.c + abs(x[p.p] - x[u]) + 1;
					que.push({ u,0,d[u][0] });
				}
			}
		}
		else {
			for (int u : X[x[p.p]]) {
				if (d[u][1] > p.c + abs(y[p.p] - y[u]) + 1) {
					d[u][1] = p.c + abs(y[p.p] - y[u]) + 1;
					que.push({ u,1,d[u][1] });
				}
			}
		}
	}
	ll Min = INF;
	for (int u : X[m - 1])Min = min(Min, d[u][1] + abs(y[u] - n + 1));
	for (int u : Y[n - 1])Min = min(Min, d[u][0] + abs(x[u] - m + 1));
	if (Min == INF)puts("-1");
	else printf("%lld\n", Min);
}

Measured memory_bytes: 24064
#include <bits/stdc++.h>
using namespace std;
#define LL long long

int N;
int A[200010], pre[200010], suc[200010], H[200010], f[200010];
LL pp = (1e9) + 7;

int main(){
	cin >> N;
	for (int i = 1; i <= N; i++){
		cin >> A[i];
		pre[i] = H[A[i]];
		suc[H[A[i]]] = i;
		H[A[i]] = i;
	}
	f[N] = 1;
	for (int i = N - 1; i >= 1; i--){
		f[i] = f[i + 1];
		if ((suc[i] != 0) & (suc[i] > i + 1))
			f[i] = (f[i] + f[suc[i]]) % pp;
	}
	cout << f[1] << endl;
}

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

int main()
{
    string s;
    char ans;
    
    for(int i = 0;i < 3;i++){
        cin >> s;
        if(i == 1) ans = s[0];
    }
    cout << "A" << ans << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
import copy

n = int(input())

a = [0] * n

for i in range(n):
    a[i] = int(input())

a_sort = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sort[0]:
        print(a_sort[1])
    else:
        print(a_sort[0])



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

int main() {
    int N, M; cin >> N >> M;
    int X[100100]; for (int i = 0; i < M; i++) cin >> X[i];

    sort(X, X + M);
    int Y[100100];
    for (int i = 0; i < M - 1; i++) {
        Y[i] = X[i + 1] - X[i];
    }

    sort(Y, Y + M - 1, greater<int>());

    int sum = X[M - 1] - X[0];

    if (N != 1) {
    for (int i = 0; i < N - 1; i++) sum -= Y[i];
    }

    if (N >= M) sum = 0;

    printf("%d\n", sum);
}

Measured memory_bytes: 1024
// g++ -std=c++14

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) (c.begin(),c.end())
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll
int32_t main(){ _
  int n;
  cin >> n;
  vector<int> dp(n, INT_MAX), h(n, 0);
  for(int i = 0; i < n; i++)
    cin >> h[i];
  dp[0] = 0;
  for(int i = 1; i < n; i++){
    if(i > 0)
      dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if(i > 1)
      dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 4732
//what the fuck was this question
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
#define f(i,a,b) for(ll i = a; i < b; i++)
int ed(string s1,string s2,int n,int m)
{
    int dp[n+1][m+1] = {};
    for(int i = 0; i <= n; i++)
    dp[i][0] = i;
    for(int i = 0; i <= m; i++)
    dp[0][i] = i;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(s1[i] == s2[j])
            dp[i][j] = dp[i-1][j-1];
            else
            dp[i][j] = 1 + min(min(dp[i-1][j],dp[i-1][j-1]),dp[i][j-1]);
        }
    }
    return dp[n][m];
}
int Lcs(int a[],int n)
{
    int d[n+1] = {};
    for(int i = 1; i <= n; i++)
    {
        if(a[i] > a[i-1])
        d[i] = 1+d[i-1];
        else
        d[i] = d[i-1];
    }
    return d[n];
}
  
int main() {
    
       ll n,m;
       cin>>n>>m;
       cout<<n*m<<endl;
    
	return 0;
 
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,D,Q;
const int MAX_N = 500000;
int A [MAX_N];
int pre [MAX_N + 1],suf [MAX_N + 1];
const int INF = 2e9;

int main()
{
	scanf("%d%d",&N,&D);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}
	pre [0] = D;
	FOR(i,0,N){
		pre [i + 1] = min(pre [i],abs(pre [i] - A [i]));
	}
	suf [N] = 0;
	for(int i = N - 1;i >= 0;i--){
		if(suf [i + 1] * 2 + 1 >= A [i]){
			suf [i] = min(INF,suf [i + 1] + A [i]);
		}
		else{
			suf [i] = suf [i + 1];
		}
	}

	scanf("%d",&Q);
	FOR(i,0,Q){
		int x;
		scanf("%d",&x);
		x--;
		puts(pre [x] <= suf [x + 1] ? "NO" : "YES");
	}

	return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;


int main() {
	int size = 100000;
	int N;
	cin >> N;
	vector<int>V(N);
	rep(i, N) {
		cin >> V[i];
	}
	vector<int>VO(size);
	vector<int>VE(size);
	rep(i, N) {
		if (i % 2 == 0) {
			VE[V[i] - 1]++;
		}
		else {
			VO[V[i] - 1]++;
		}
	}
	vector<int>vo(size);
	vector<int>ve(size);
	rep(i, size) {
		vo[i] = VO[i];
		ve[i] = VE[i];
	}
	sort(VO);
	reverse(VO);
	sort(VE);
	reverse(VE);
	int O0 = VO[0], O1 = VO[1], E0 = VE[0], E1 = VE[1];
	int IO = 0, IE = 0;
	rep(i, size) {
		if (vo[i] == O0) {
			 IO = i;
		}
		if (ve[i] == E0) {
			 IE = i;
		}
	}
	if (O0 == O1 || E0 == E1) {
		cout << N - (O0 + E0) << endl;
	}
	else {
		if (IO == IE) {
			cout << N - max(O0 + E1, O1 + E0) << endl;
		}
		else {
			cout << N - (O0 + E0) << endl;
		}
	}
}

Measured memory_bytes: 2304
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String A = sc.next();
  String B = sc.next();
  String C = sc.next();
  int counterA = 0;
  int counterB = 0;
  int counterC = 0;
  char next = 'a';
  for(;;){
    if(next == 'a'){
      counterA++;
      if(counterA == A.length()+1){
        System.out.println("A");
        break;
      }
      else next = A.charAt(counterA-1);
    }
    else if(next == 'b'){
      counterB++;
      if(counterB == B.length()+1){
        System.out.println("B");
        break;
      }
      else next = B.charAt(counterB-1);
    }
    else if(next == 'c'){
      counterC++;
      if(counterC == C.length()+1){
        System.out.println("C");
        break;
      }
      else next = C.charAt(counterC-1);
    }
  }
}}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define REP(a,b,c) for((a)=(b);(a)<(c);(a)++)

using namespace std;

int main(){
    int a, b, c; 
    cin >> a >> b >> c;
    if(a + b + c < 22){
        cout << "win" << endl;
    }else{
        cout << "bust" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a=list(map(str,input().split()))
b=list(map(str,input().split()))
c=list(map(str,input().split()))
n=int(input())
s=[input() for i in range(n)]
if b[1]in s and a[0] in s and c[2] in s:
    print("Yes")
elif b[1]in s and a[1] in s and c[1] in s:
    print("Yes")
elif b[1]in s and  a[2] in s and c[0] in s:
    print("Yes")
elif b[1]in s and b[0] in s and b[2] in s:
    print("Yes")
elif a[0] in s and a[1] in s and a[2] in s:
    print("Yes")
elif a[0] in s and b[0] in s and c[0] in s:
    print("Yes")
elif c[2] in s and a[2] in s and b[2] in s:
    print("Yes")
elif c[2] in s and c[0]in s and c[1] in s:
    print("Yes")
else:
  print("No")

Measured memory_bytes: 9252
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


const int N = 402;
const int M = 100002;


int n, m, X_[M], Y_[M];
bool valid[N], killed[N][N];



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

    cin>>n>>m;
    for(int i=1;i<=m;i++)
    	cin>>X_[i]>>Y_[i];

    for(int i=1;i<=n;i++){
    	killed[i][i] = true;
    	valid[i] = true;
    	for(int j=m;j>=1;j--)
    		if(killed[i][X_[j]] && killed[i][Y_[j]]){
    			valid[i] = false;
    			break;
    		}
    		else if(killed[i][X_[j]])
    			killed[i][Y_[j]] = true;
    		else if(killed[i][Y_[j]])
    			killed[i][X_[j]] = true;
    }

// cout<<"valid: ";for(int i=1;i<=n;i++)	cout<<valid[i]<<" ";cout<<endl;

    int ans = 0;
    for(int i=1;i<=n;i++)
    	for(int j=i+1;j<=n;j++)
    		if(valid[i] && valid[j]){
    			bool good = true;
    			for(int k=1;k<=n;k++)
    				if(killed[i][k] && killed[j][k])
    					good = false;
    			ans += good;
    		}

    cout<<ans;
    return 0;
}




 



Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
 	int a, b;
 	int c[3];
 	cin >> a >> b;
 	c[0] = a+b;
 	c[1] = a-b;
 	c[2] = a*b;
 	sort(c, c+3);
 	cout << c[2];
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] ss = new String[n];
		for(int i=0; i<n; i++){
			ss[i] = sc.next();
		}
		
		int last_a = 0;
		int first_b = 0;
		int first_and_last = 0;
		
		for(int i=0; i<n; i++){
			String[] str = ss[i].split("");
			if(str[0].equals("B")){
				if(str[str.length-1].equals("A")){
					first_and_last++;
				}
				else{
					first_b++;
				}
			}
			else if(str[str.length-1].equals("A")){
				last_a++;
			}
			for(int j=0; j<str.length-1; j++){
				if(str[j].equals("A") && str[j+1].equals("B")){
					ans++;
				}
			}
		}
		
		if(last_a == 0 && first_b == 0){
			if(first_and_last > 0){
				ans += first_and_last - 1;
			}
		}
		else{
			ans += Math.min(last_a, first_b) + first_and_last;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 41824
import numpy as np
N = int(input())
cost_list = np.array((4,7))
dp = np.ones(N+1, dtype=np.bool) * False
dp[0] = True
for i in range(1,N+1):
    for j in range(len(cost_list)):
        cost = cost_list[j]
        if i - cost >= 0 and dp[i-cost]:
            dp[i] = True
            break

res = "Yes" if dp[N] else "No"

print(res)

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

int main(){
  int n, a;
  map<int, int> mp;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    mp[a]++;
  }
  int sum = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    if(itr->first < itr->second) sum += itr->second - itr->first;
    else if(itr->first > itr->second) sum += itr->second;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4736
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)


class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| push(a)}
  end

  def insert(element)
    @data.push(element)
    bottom_up
  end

  def pop
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end


  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  def size
    @data.size
  end

  def parent_idx(target_idx)
    (target_idx - (target_idx.even? ? 2 : 1)) / 2
  end

  def bottom_up
    target_idx = size - 1
    return if target_idx == 0
    parent_idx = parent_idx(target_idx)
    while (@data[parent_idx] > @data[target_idx])
      swap(parent_idx, target_idx)
      target_idx = parent_idx
      break if target_idx == 0
      parent_idx = parent_idx(target_idx)
    end
  end

  def top_down
    target_idx = 0

    # child がある場合
    while (has_child?(target_idx))

      a = left_child_idx(target_idx)
      b = right_child_idx(target_idx)

      if @data[b].nil?
        c = a
      else
        c = @data[a] <= @data[b] ? a : b
      end

      if @data[target_idx] > @data[c]
        swap(target_idx, c)
        target_idx = c
      else
        return
      end
    end
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end
end

pq = PriorityQueue.new
arr.each do |a|
	pq.insert(a)
end

while pq.size > 1
	p1 = pq.pop
	p2 = pq.pop
	pq.insert((p1 + p2) / 2.0)
end
puts pq.pop


Measured memory_bytes: 14292
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (x, y, z, k) = {
      let v: Vec<i64> = read_vec();
      (v[0], v[1], v[2], v[3])
    };


    let mut a: Vec<i64> = read_vec();
    let mut b: Vec<i64> = read_vec();
    let mut c: Vec<i64> = read_vec();

    // solve1(k as usize, &a, &b, &c);
    solve2(k as usize, x as usize,  &mut a, y as usize, &mut b, z as usize, &mut c);
}


fn solve1(k: usize, a: &Vec<i64>, b: &Vec<i64>, c: &Vec<i64>) {
  let mut v: Vec<i64> = Vec::new();

  for &e1 in a {
    for &e2 in b {
      v.push(e1+e2);
    }
  }
  v.sort_by(|a, b| b.cmp(a));

  let mut res: Vec<i64> = Vec::new();
  let vup: usize = cmp::min(v.len(), k);
  let cup: usize = cmp::min(c.len(), k);

  for i in 0..vup {
    for j in 0..cup {
        res.push(v[i] + c[j]);
    }
  }
  res.sort_by(|a, b| b.cmp(a));

  for i in 0..k  {
    println!("{}", res[i]);
  }
}

fn solve2(K: usize, x: usize, a: &mut Vec<i64>, y: usize, b: &mut Vec<i64>, z:usize, c: &mut Vec<i64>) {
  a.sort_by(|a, b| b.cmp(a));
  b.sort_by(|a, b| b.cmp(a));
  c.sort_by(|a, b| b.cmp(a));
  let mut res: Vec<i64> = Vec::new();

  for i in 0..x {
    for j in 0..y {
      for k in 0..z {
        if (i+1) * (j+1) * (k+1) <= K {
            res.push(a[i] + b[j] + c[k]);
            //println!("{}", 1);
        }
        else {
          break;
        }
      }
    }
  }
  res.sort_by(|a, b| b.cmp(a));

  for i in 0..K {
    println!("{:?}", res[i]);
  }
}


Measured memory_bytes: 6396
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}



//N_C_a を M で割った余り
ll my_combination(ll N, ll a, ll M) {
	ll answer = 1;

	rep(i, a) {
		answer *= (N - i);
		answer %= M;
	}

	rep(i, a) {
		answer *= my_pow(i + 1, M - 2, M);
		answer %= M;
	}

	return answer;
}



ll my_gcd(ll& a, ll& b) {
	if (b == 0) return a;
	ll temp = a % b;
	return my_gcd(b, temp);
}



// long long型 n を、base 進法での、i 桁目の数が入った vector にする。
void ll_to_vector(ll base, ll n, vector<ll>& v) {
	ll tempo = n;

	ll n_digit = floor(log10(n) / log10(base)) + 1;
	v.assign(n_digit, 0);

	//ll n_digit = v.size();

	for (ll i = 0; i < n_digit; i++) {
		v.at(i) = tempo / pow(base, n_digit - 1 - i);
		tempo -= v.at(i) * pow(base, n_digit - 1 - i);
	}
}







signed main() {
	int S, W;
	cin >> S >> W;

	if (W >= S) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}

Measured memory_bytes: 3628
N = int(input())
T, A = map(int, input().split())
hLst = list(map(int, input().split()))

ans = 0
tmp = 1000000000
for i in range(N):
    ansTmp = abs(A - (T - (hLst[i] * 0.006)))
    if tmp >= ansTmp:
        ans = i + 1
        tmp = ansTmp

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define R1(i, n) for(int i = 1; i <= n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int main() {
	char c;
	SC(c);
	if (c >= 65 && c <= 90) printf("A");
	else printf("a");
}

Measured memory_bytes: 3756
n,m=map(int,input().split())
p=[[]for _ in range(n)]
c=[0]*n
import sys
sys.setrecursionlimit(10**6)
for i in range(m):
    x,y=map(int,input().split())
    p[x-1].append(y-1)
from functools import lru_cache
@lru_cache(maxsize=n)
def l(k):
    return max([l(i)for i in p[k]]+[0])+1
print(max([l(i)for i in range(n)])-1)

Measured memory_bytes: 203992
#include "bits/stdc++.h"
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;

int main() {
	cpp_int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "GREATER" << endl;
	}
	else if (a < b) {
		cout << "LESS" << endl;
	}
	else {
		cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    map<int,int> mp;
    rep(i,N){
        cin>>A.at(i);
        mp[A.at(i)]++;
    }
    sort(A.begin(),A.end());
    vector<int> check(A.at(N-1)+1);
    rep(i,N){
        for(int j=2;j*A.at(i)<=A.at(N-1);j++){
            check.at(j*A.at(i))=1;
        }
    }
    int ans=0;
    rep(i,N){
        if(mp[A.at(i)]==1){
            if(!check.at(A.at(i))){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long x;
        cin >> x;

        for (long a = -2e3; a < 2e3; a++) {
            for (long b = -2e3; b < 2e3; b++) {
                long a5 = a*a*a*a*a;
                long b5 = b*b*b*b*b;
                if (a5 - b5 == x) {
                    printf("%lld %lld\n", a, b);
                    return 0;
                }
            }
        }
    }
}


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

using namespace std;

int main() {
    int n, x[2] = {0,0};
    cin >> n;
    string s;
    cin >> s;
    for(int i=0; i<n; i++) {
        if(s[i] == 'I') {
            x[0] += 1;
        } else {
            x[0] -= 1;
        }
        if(x[1] < x[0]) {
            x[1] = x[0];
        }
    }
    cout << x[1] << endl;
}

Measured memory_bytes: 256
#include <iostream>

struct {
  auto &operator>>(int &x) {
    char c;
    do
      c = std::cin.rdbuf()->sbumpc();
    while (!isdigit(c));
    for (x = 0; isdigit(c); c = std::cin.rdbuf()->sbumpc())
      x = x * 10 + (c ^ 48);
    return *this;
  }
} io;

const int MAX_N = 100000;
const int MAX_M = 100000;

struct Edge {
  int v, next;
} e[MAX_M * 2 + 1];

int g[MAX_N + 1], cnt, q[MAX_N + 1], top, deg[MAX_N + 1];
int f[MAX_N + 1];

inline void addEdge(int u, int v) {
  e[++cnt].v = v;
  e[cnt].next = g[u];
  g[u] = cnt;
  deg[v]++;
}

int main() {
  int n, m;
  io >> n >> m;
  for (int i = 0, u, v; i < m; ++i) {
    io >> u >> v;
    addEdge(u, v);
  }
  for (int i = 1; i <= n; ++i)
    if (!deg[i]) q[++top] = i;
  for (int u; top;) {
    u = q[top--];
    for (int i = g[u], v; i; i = e[i].next) {
      v = e[i].v;
      f[v] = std::max(f[v], f[u] + 1);
      if (--deg[v] == 0) q[++top] = v;
    }
  }
  int ret = 0;
  for (int i = 1; i <= n; ++i) ret = std::max(ret, f[i]);
  std::cout << ret;
  return 0;
}

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

int main() {
  int X, Y; // 動物の総数、あし
  cin >> X >> Y;
  int amari = Y - (X * 2);
  if (X * 2 <= Y && amari % 2 == 0 && amari / 2 <= X) {
  	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 3600
Mod = 1000000000 + 7

def fastpow(x,y):
    ans = 1

    global Mod
    while y:
        if (y & 1): ans = (ans * x) % Mod
        x = (x * x) % Mod
        y >>= 1
    return ans

def solve(N,K):
    # f[i] is number (x1,....xn) such that gcd(x1,..,xK) = i
    
    f = [0]*(K + 1)
    for i in range(K,0,-1):
        f[i] = fastpow(K//i,N)
        for j in range(i + i,K + 1,i):
            f[i] -= f[j]

    global Mod
    ans = 0
    for i in range(1,K + 1):
        ans = (ans + i*f[i]) % Mod
    return ans


if __name__ == "__main__":
    
    N, K = map(int,input().split())
    print(solve(N,K))


Measured memory_bytes: 11156
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
void dfs();
void visit(int);
int color[101];
int graph[101][101];
int d[101];
int f[101];
int n;
int time;
int main()
{
  
  int i,j,x,y,z;
  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
	{
	  graph[i][j]=0;
	}
    }

  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&x,&y);
      
      for(j=1;j<=y;j++)
	{
	  scanf("%d",&z);
	  
	  graph[x][z]=1;
	    }
    }

  dfs();

  return 0;
}

void dfs()
{
  int i;
  for(i=1;i<=n;i++)
    color[i]=WHITE;

  time =0;
  for(i=1;i<=n;i++)
    if(color[i]==WHITE)
      visit(i);

  for(i=1;i<=n;i++)
    {
      printf("%d %d %d\n",i,d[i],f[i]);
    }
}

void visit(int i)
{
  int j;
  color[i] = GRAY;
  d[i]=++time;
  for(j=1;j<=n;j++)
    {
      if(color[j]==WHITE && graph[i][j]!=0){
	visit(j);
      }
	  }
  color[i] = BLACK;
  f[i] = ++time;
}

Measured memory_bytes: 640
#include<iostream>


int main() {


	int x,y,z;

	int man = 0;

	std::cin >> x >> y >> z;

	x -= z;
	
	
	
	while (x >= (y + z)) {
		x -= (y + z);
		man++;
	}
	
	std::cout << man;




	return 0;

}

Measured memory_bytes: 256