akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

 
int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> masu(H, vector<char> (W));

    for(int i=0 ; i<H ; i++){
        for(int j=0 ; j<W ; j++){
            cin >> masu.at(i).at(j);
        }
    }

    vector<bool> row(H);
    vector<bool> col(W);

    for(int i=0 ; i<H ; i++){
        bool flag = false;
        for(int j=0 ; j<W ; j++){
            if(masu.at(i).at(j)=='#'){flag=true; break;}
        }
        row.at(i) = flag;
    }

    for(int j=0 ; j<W ; j++){
        bool flag = false;
        for(int i=0 ; i<H ; i++){
            if(masu.at(i).at(j)=='#'){flag=true; break;}
        }
        col.at(j) = flag;
    }

    for(int i=0 ; i<H ; i++){
        for(int j=0 ; j<W ; j++){
            if(row.at(i) && col.at(j)){cout << masu.at(i).at(j);}
        }
        if(row.at(i)){cout << endl;}
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	char a, b;
	while(~scanf("%c %c", &a, &b)) {
		if(a == b) {
			puts("=");
			break;
		}
		else if(a > b) {
			puts(">");
			break;
		}
		else {
			puts("<");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
n,t = map(int,input().split())
a = list(map(int,input().split()))

a.append(1000000000000)

an = 0

for i in range(n):
    if(a[i+1]-a[i]>t):
        if(i>0):
            an += t
        elif(i==0):
            an += t
    else:
        an += a[i+1]-a[i]
    
    # print(an)
        
print(an)

Measured memory_bytes: 85584
#include <iostream>
using namespace std;
int main() {
  int n;
  int d, e;
  int t = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> d >> e;
    if (d == e) {
      ++t;
      if (t == 3) {
        break;
      }
    } else {
      t = 0;
    }
  }
  if (t == 3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main() {
	int dai, a;
	while (1) {
		cin >> dai;
		if (dai == 0) {
			goto a;
		}
		for (int i = 1; i <= 9; i++) {
			cin >> a;
			dai = dai - a;
		}
		cout << dai << endl;
	}
a:;
}


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

int main(){
	int ans=0,ans1=0;
	string s;
	cin >> s;
	int n =  s.size();
	string t = s;
	for(int i = 1;i<n;i++){
		if(t[i]==t[i-1]){
		ans++;
		t[i-1]=='0'?t[i]='1':t[i]='0';
		}

		if(s[n-i]==s[n-i-1]){
			ans1++;
			s[n-i]=='0'?s[n-i-1]='1':s[n-i-1] = '0';
		}
	}
	//cout << t << "\n" << s <<endl;
	cout << min(ans,ans1) <<endl;
return 0;
}

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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    
    vector<ll> L(N+1);
    
    L[0]=2; L[1]=1;
    for(int i=2; i<=N; i++){
        L[i] = L[i-1] + L[i-2];
    }
    
    cout << L[N] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1000000007
using namespace std;
typedef long long ll;

int main(){
  string s; cin >> s;
  string ans="";
  for(char c:s){
    switch(c){
      case '0':
      ans+='0';
      break;

      case '1':
      ans+='1';
      break;

      case 'B':
      if(ans.length()>0)  ans.pop_back();
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n;	cin >> n;
  	vector<int> a(n);
  	set<int> dc;
  	rep(i,n){
    	cin >> a.at(i);
      	if(dc.count(a.at(i)) == 0){
        	dc.insert(a.at(i));
    	}
      	else{
        	cout << "NO" << endl;
          	return 0;
        }
    }
  	cout << "YES" << endl;
  	
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);

        int bo=0,flag=0,num=1;
        int ans=a[1];

        for(int i=2;i<=n;i++)
        {
            if(!bo)
            {
                if(a[i]>ans)
                {
                    bo=1;
                    flag=1;
                    ans=a[i];
                }
                else if(a[i]<ans)
                {
                    bo=1;
                    flag=2;
                    ans=a[i];
                }
            }
            else
            {
                if(flag==1)
                {
                    if(a[i]>=ans)
                        ans=a[i];
                    else
                    {
                        flag=0;
                        bo=0;
                        ans=a[i];
                        num++;
                    }
                }
                else if(flag==2)
                {
                    if(a[i]<=ans)
                        ans=a[i];
                    else
                    {
                        flag=0;
                        bo=0;
                        ans=a[i];
                        num++;
                    }
                }
            }
        }
        printf("%d\n",num);
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll                  long long
#define rep(i,n)            for(ll i=0;i<n;i++)
#define hell                1000000007LL
#define sd(x)               scanf("%d",&x)
#define slld(x)             scanf("%lld",&x)
#define ss(x)               scanf("%s",x)
#define slf(x)              scanf("%lf",&x)
#define vi                  vector<ll>
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll Max(ll a, ll b) { return a > b ? a : b; }
ll Min(ll a, ll b) { return a < b ? a : b; }
ll power(ll x, ll y,ll p)
{
    ll res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
            res=((res%p)*(x%p))%p;
        y=y>>1;
        x=((x%p)*(x%p))%p;
    }
    return res;
}
int main()
{
    ll n,m,ans=0,x,y;
    slld(n);slld(m);
    map<ll,ll> arr;
    ll amount[n+1];
    rep(i,n+1)
    {
        amount[i]=1;
    }
    arr[1]=1;
    rep(i,n-1)
    {
        arr[i+2]=0;
    }
    rep(i,m)
    {
        cin>>x>>y;
        if(arr[x]==0)
        {
            amount[x]-=1;
            amount[y]+=1;
            if(arr[y]>0) arr[y]=amount[y];
        }
        else
        {
            amount[x]-=1;
            amount[y]+=1;
            if(amount[x]==0)
            {
                arr[x]=0;
                arr[y]=amount[y];
            }
            else
            {
                arr[y]=amount[y];
            }
        }
    }
    rep(i,n)
    {
        if(arr[i+1]>0) ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 7296
N = int(input())

ans = ''

while N != 0:
    
    
    if N % 2 !=0:
        N -=1
        ans = '1'+ans
    else:
        ans = '0'+ans
    
    N = N//-2

    
if ans == '':
    ans ='0'
    
    
print(ans)
    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int x;
  cin >> x;
  int num = x / 100;

  int l = num * 100;
  int r = num * 105;

  if(x >= l && x <= r) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);

int main(){
    ll n, k, ans = 0; cin >> n >> k;
    vector<ll> a(n);
    rep(i, n){
        ll ai; cin >> ai; ai--;
        a[ai]++;
    }
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    rep(i, n) if(a[i] != 0) pq.push(a[i]);
    while(pq.size() > k){
        ll p = pq.top(); pq.pop();
        ans += p;
    }
    cout << ans << endl;
}


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

int l[60];
int main()
{
    int n, k;
    cin >> n >> k;

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

    int t, j;
    for ( i = 1; i <= n; i++ ) {
        for ( j = i + 1; j <= n; j++ ) {
            if ( l[i] < l[j] ) {
                t = l[i];
                l[i] = l[j];
                l[j] = t;
            }
        }
    }

    int sum = 0;
    for ( i = 1; i <= k; i++ ) {
        sum += l[i];
    }

    cout << sum;
    return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
s = int(input())
def solve(n, s):
    if n == s:
        return n+1
    for b in range(2, math.floor(n**0.5)+1):
        tmp = n
        res = 0
        while tmp>=b:
            res+=tmp%b
            tmp //=b
        res += tmp
        if res == s:
            return b
    for p in range(int(n**0.5), 0, -1):
        r = s-p
        if r<0:
            continue
        if (n-r)%p == 0:
            b = (n-r)//p
            if r<b and b*b>n:
                return b
    return -1
print(solve(n, s))

Measured memory_bytes: 40300
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
                                                                                                
  
int main(){
                                                                                                
   
    int n, i;

    int m = 0;
         
    cin >> n;

    vector<int> s(n);

   
    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> s.at(i);

         m = m + s.at(i);

         }

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

    
    for( i = 0 ; i < n ; i = i + 1 ){

         if( m % 10 != 0 ) break;

         if( ( m - s.at(i) ) % 10 != 0 ){

             m = m - s.at(i);

             }

         }

    if( m % 10 == 0 ) m = 0;

    cout << m << endl;


    return 0;
                                                          
}

Measured memory_bytes: 256
def function(b, n):
    if n < b:
        return n
    else:
        return function(b, n//b) + n % b
from math import sqrt
def divs(n):
  d=[]
  for x in range(1,int(sqrt(n))+1):
    if n%x==0:
      d.extend([x,n//x])
  d=list(set(d))
  d.sort()
  return d

def main():
    n = int(input())
    s = int(input())

    if n < s:
        return("-1")
    elif n == s:
        return(n+1)
    else:
        ds = divs(n - s)
        for x in ds:
            if s == function(x+1,n):
                return(x+1)
        else:
            return("-1")

print(main())

Measured memory_bytes: 9280
N, K = map(int, input().split())
logs = list(map(int, input().split()))
maxL = max(logs)

def binsearch(minz, maxz):
    if minz >= maxz:
        return minz

    mid = (maxz + minz)//2
    ncut = 0
    for i in range(N):
        thiscut = int((logs[i] + mid - 1)/mid) - 1
        ncut += thiscut
        if ncut > K:
            return binsearch(mid+1, maxz)

    if ncut < K:
        return binsearch(minz, mid)
    #else ncut == K
    maxx = 0
    for i in range(N):
        thiscut = int((logs[i] + mid - 1)/mid) - 1
        thislen = int((logs[i] + thiscut)/(thiscut+1))
        if maxx < thislen: maxx = thislen
    return maxx

if K > 0:
    ans = binsearch(1, maxL+1)
else:
    ans = maxL
print(ans)


Measured memory_bytes: 104024
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-26 18:49:27
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=110;
int n,m,A[N][N],B[N][N],C[N][N],a[N][N],p[N],P[N],vis[N];
int id(int p){ return (p+m-1)/m; }
int dfs(int u)
{
	if(vis[u]) return 0;
	vis[u]=1;
	fr(v,1,n) if(a[u][v]&&!p[v]){ p[v]=u; return 1; }
	fr(v,1,n) if(a[u][v]&&dfs(p[v])){ p[v]=u; return 1; }
	return 0;
}
int main()
{
	n=read(); m=read();
	fr(i,1,n) fr(j,1,m) A[i][j]=read();
	fr(o,1,m)
	{
		fr(i,1,n) fr(j,1,n) a[i][j]=0;
		fr(i,1,n) p[i]=0;
		fr(i,1,n) fr(j,1,m) if(A[i][j]) a[i][id(A[i][j])]=1;
//		fr(i,1,n) fr(j,1,m) printf("%d%c",A[i][j],j==m?'\n':' ');
		fr(i,1,n)
		{
			fr(j,1,n) vis[j]=0;
			dfs(i);
		}
//		fr(i,1,n) printf("%d%c",p[i],i==n?'\n':' ');
		fr(i,1,n) P[p[i]]=i;
		fr(i,1,n) fr(j,1,m) if(A[i][j]&&id(A[i][j])==P[i])
		{
			B[i][o]=A[i][j]; A[i][j]=0; break;
		}
	}
	fr(i,1,n) fr(j,1,m) printf("%d%c",B[i][j],j==m?'\n':' ');
	fr(i,1,n) fr(j,1,m) C[id(B[i][j])][j]=B[i][j];
	fr(i,1,n) fr(j,1,m) printf("%d%c",C[i][j],j==m?'\n':' ');
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;
const int INF = 1000000000;

const double PI = 3.1415926535;
int main(){
	double r;
	cin >> r;
	printf("%.14lf\n",2*r*PI);
}


Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
#define lli long long int

using namespace std;

struct P{
	lli a;
	lli b;
	int w;
};

int main()
{	
	int n, m, q, w;
	lli a[201];
	
	while(cin >> n && n){
		w = q = 0;
		P hm[101];
		for(int i = 0; i < n; i++){
			cin >> hm[i].w >> hm[i].a >> hm[i].b;
			bool af, bf;
			af = bf = true;
			for(int j = 0; j < q; j++){
				if(a[j] == hm[i].a){
					af = false;
					if(!bf){
						break;
					}
				}
				if(a[j] == hm[i].b){
					bf = false;
					if(!af){
						break;
					}
				}
			}
			if(af){
				a[q++] = hm[i].a;
			}
			if(bf){
				a[q++] = hm[i].b;
			}
		}
		sort(a, a+q);
		
		bool f = true;
		for(int i = 0; i < q; i++){
			for(int j = 0; j < n; j++){
				if(a[i] == hm[j].a){
					w += hm[j].w;
				}
				if(a[i] == hm[j].b){
					w -= hm[j].w;
				}
			}
			if(w > 150){
				f = false;
				break;
			}
		}
		
		if(f){
			cout << "OK" << endl;
		} else {
			cout << "NG" << endl;
		}
	}
	
	return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;

    cout << H * W - h * W - H * w + h * w << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> r;
  cout << r*r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int n;
int v[100010];
int cnt1[100010] = {}, cnt2[100010] = {};
int main() {
	cin >> n;
	rep(i, n) cin >> v[i];

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			cnt1[v[i] - 1]++;
		}
		else {
			cnt2[v[i] - 1]++;
		}
	}

	int max1 = -1, max2 = -1;
	int maxi1 = -1, maxi2 = -1;

	for (int i = 0; i < 100001; i++) {
		if (max1 < cnt1[i]) {
			max1 = cnt1[i];
			maxi1 = i;
		}
		if (max2 < cnt2[i]) {
			max2 = cnt2[i];
			maxi2 = i;
		}
	}

	if (maxi1 != maxi2) {
		cout << n - max1 - max2 << endl;
	}
	else {
		sort(cnt1, cnt1 + 100001, greater<int>());
		sort(cnt2, cnt2 + 100001, greater<int>());
		cout << n - max(cnt1[0] + cnt2[1], cnt1[1] + cnt2[0]) << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long foo (long current, long f0, long f1, long f2, long t0, long t1, long t2) {
  vector<long> result(current + 1, 0);

  rep(i, current + 1) {
    if (i + 1 < current + 1 and result[i + 1] < result[i] + 1) result[i + 1] = result[i] + 1;
    if (i + f0 < current + 1 and result[i + f0] < result[i] + t0) result[i + f0] = result[i] + t0;
    if (i + f1 < current + 1 and result[i + f1] < result[i] + t1) result[i + f1] = result[i] + t1;
    if (i + f2 < current + 1 and result[i + f2] < result[i] + t2) result[i + f2] = result[i] + t2;
  }

  return result[current];
}

int main(void) {
  long N;
  long GA, SA, BA;
  long GB, SB, BB;

  cin >> N;
  cin >> GA >> SA >> BA;
  cin >> GB >> SB >> BB;

  long tmp = N;
  tmp = foo(tmp, GA, SA, BA, GB, SB, BB);
  tmp = foo(tmp, GB, SB, BB, GA, SA, BA);

  cout << tmp << endl;

  return 0;
}


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


int main() {
    int n;
    string s;
    cin >> n >> s;
    int m = n;
    rep(i, n) {
        if (s[i] == s[i + 1]) m--;
    }

    cout << m;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int X, Y, A, B, C;

	cin >> X >> Y >> A >> B >> C;
	vector<int> p;
	int temp = 0;
	for(int i=0; i<A; i++){
			cin >> temp;
			p.emplace_back(temp);
	}
	sort(p.begin(),p.end(), greater<int>());
	
	vector<int> q;
	for(int i=0; i<B; i++){
			cin >> temp;
			q.emplace_back(temp);
	}
	sort(q.begin(),q.end(), greater<int>());

	vector<int> r;
	for(int i=0; i<C; i++){
			cin >> temp;
			r.emplace_back(temp);
	}
	sort(r.begin(),r.end(), greater<int>());

	priority_queue<int> que;
	REP(i,X) que.push(p[i]);
	REP(i,Y) que.push(q[i]);
	REP(i,r.size()) que.push(r[i]);

	ll ans = 0;
	REP(i,X+Y){
		ans += que.top();
		que.pop();
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 8304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b;
  c = (a * b) % 2;

	if (c == 1) {
		cout << "Odd" << endl;
    }
   	else {
      cout << "Even" << endl;
    }
}

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

int main(){
	int a[10000],b[10000],c=0;
	cin>>a[0]>>b[0];
	while(a[c]!=0&&b[c]!=0){
		cin>>a[c+1]>>b[c+1];
		c++;
	}
	for(int d=0;d<c;d++){
		for(int i=0;i<a[d];i++){
			for(int j=0;j<b[d];j++){
				cout<<'#';
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#define N 20
using namespace std;
void func(int,int);
int jump(int,int);
int X,Y,data[N][N],memo[N][N];
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++) data[i][j] = memo[i][j] = 0;

    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++) cin >> data[i][j];

    for(int i=0;i<X;i++)
      if(data[0][i]!=1) func(0,i);

    int cnt=0;
    for(int i=0;i<X;i++) cnt+=memo[0][i];
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y>=Y-1){
    memo[y][x]++;
    return ;
  }
  if(0<=x-1 && data[y+1][x-1]==0){
    if(memo[y+1][x-1]==0) func(y+1,x-1);
    memo[y][x]+=memo[y+1][x-1];
  }
  if(x+1< X &&data[y+1][x+1]==0){
    if(memo[y+1][x+1]==0) func(y+1,x+1);
    memo[y][x]+=memo[y+1][x+1];
  }
  if(data[y+1][x]==0){
    if(memo[y+1][x]==0) func(y+1,x);
    memo[y][x]+=memo[y+1][x];
  }
  if(data[y+1][x]==2){
    int r=jump(y+1,x);
    if(r!=-1){
      if(memo[r][x]==0) func(r,x);
      memo[y][x]+=memo[r][x];
    }
  }
  if(memo[y][x]==0) data[y][x]=1;
}
int jump(int y,int x){
  while(data[y][x]==2)y+=2;
  if(data[y][x] == 0 && (data[y][x]==0||y>=Y-1)) return y;
  return -1;
}

Measured memory_bytes: 1164
#!/usr/bin/env python3
s = input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0 for _ in range(ls+1)] for _ in range(lt+1)]

for i in range(lt):
    for j in range(ls):
        if t[i] == s[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

ans = ""
ti = lt
sj = ls
while ti > 0 and sj > 0:
    if dp[ti][sj] == dp[ti-1][sj]:
        ti -= 1
    elif dp[ti][sj] == dp[ti][sj-1]:
        sj -= 1
    elif dp[ti][sj] == dp[ti-1][sj-1] + 1:
        ans += t[ti-1]
        ti -= 1
        sj -= 1
print(ans[::-1])


Measured memory_bytes: 119644
#include<stdio.h>
int main() {
    int n,i,u,k,v,j;
    scanf("%d",&n);
    int g[n][n];
    for(i=0;i<n;i++){
	for(j=0;j<n;j++){
	    g[i][j]=0;
	}
    }
    for(i=0;i<n;i++){
	scanf("%d %d",&u, &k);
	for(j=0;j<k;j++){
	    scanf("%d",&v);
	    g[u-1][v-1]=1;
	}
    }
    for(i=0;i<n;i++){
	for(j=0;j<n;j++){
	    if (j) printf(" ");
	    printf("%d",g[i][j]);
	    if(j==n-1)printf("\n");
	}
    }
    return 0;
}




Measured memory_bytes: 2108
import sys

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

import itertools
permutations = lambda a,n:itertools.permutations(a,n) # 順列
combinations = lambda a,n:itertools.combinations(a,n) # 組み合わせ
product = lambda a,b:itertools.product(a,b) # 二つのリストの直積

init_array_1dim = lambda v,n:[v for _ in range(n)]
init_array_2dim = lambda v,n,m:[[v for _ in range(n)] for _ in range(m)]

import math
# 四捨五入はround
ceil = lambda a:math.ceil(a) # 切り上げ
floor = lambda a:math.floor(a) # 切り捨て

def dfs(v,n,graph,visited):
	if all(visited):return 1
	ans = 0
	for i in range(n):
		if graph[v][i] == False:continue
		if visited[i]:continue
		visited[i] = True
		ans += dfs(i,n,graph,visited)
		visited[i] = False
	return ans

def init_graph(n,a,directed=False):
    visited = init_array_1dim(False,n)
    graph = init_array_2dim(False,n,n)
    for e in a:
        graph[e[0]-1][e[1]-1] = True
        if not directed:graph[e[1]-1][e[0]-1] = True # 無向グラフの場合
    return visited,graph

def solution():
    N,M = input_ints()
    ab = input_lines(M,input_ints_list)
    visited,graph = init_graph(N,ab)
    visited[0] = True
    print(dfs(0,N,graph,visited))

if __name__ == '__main__':
    solution()

Measured memory_bytes: 5272
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), ans = 0;
		int b[] = new int[a];
		for(int i = 0; i < a; i++){			
			b[i] = sc.nextInt();
		}
		Arrays.sort(b);
		
		for(int i = 0; i < b.length-1; i++){
			for(int j = i + 1; j < b.length; j++){
				ans = ans + b[i] * b[j];
			}
		}
		
		
		
		
		
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int m;
string s;
bool dfs(int pos,int len,int x)
{
	if(pos==len){
		if(--m==0){
			cout<<s<<endl;
			return true;
		}
		return false;
	} 
	for(int y=0;y<10;y++){
		if(pos==0&&y==0)continue;
		if(pos>0&&abs(x-y)>1)continue;
		s+=(char)('0'+y);
		if(dfs(pos+1,len,y))return true;
		s=s.substr(0,s.size()-1);
	}
	return false;
}
int main()
{
	cin>>m;
	for(int len=1;len<=10;len++)
		if(dfs(0,len,0))
			return 0;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PII pair<string,string>
#define LL long long int
using namespace std;
int main()
{

    int n;
    cin >> n;
    string str, A, B;
    cin >> str;
    for(int i = 0; i < 2 * n; i++)
    {
        if(i < n)
            A+=str[i];
        else
            B+=str[3 * n - i -1];
    }
    map<PII, LL> Maping;
    vector<PII> vv;
    for(int i = 0;  i < (1 << n); i++)
    {
        string gama, sigma, delta, beta;
        for(int j = 0; j < n; j++)
        {
            if((i >> j) & 1)
            {
                gama += A[j];
                sigma += B[j];
            }
            else
            {
                delta += A[j];
                beta += B[j];
            }
        }
        Maping[make_pair(gama, delta)]++;
        vv.push_back(make_pair(sigma,beta));
    }
    LL ans = 0;
    for(auto v : vv)
        ans += Maping[v];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 95980
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] k = new int[M];
		int[][] s = new int[M][N];
		int[] p = new int[M];
		int ans = 0;
		for(int i = 0; i < M; i++) {
			k[i] = sc.nextInt();
			for(int j = 0; j < k[i]; j++)
				s[i][j] = sc.nextInt();
		}
		for(int i = 0; i < M; i++)
			p[i] = sc.nextInt();
		for(int i = 0; i < 1 << N; i++) {
			int[] sw = new int[N];
			boolean ok = true;
			for(int j = 0; j < N; j++) {
				if((1 & i >> j) == 1)
					sw[j] = 1;
			}
			for(int x = 0; x < M; x++) {
				int row = 0;
				for(int y = 0; y < k[x]; y++)
					row += sw[s[x][y]-1];
				if(row % 2 != p[x])
					ok = false;
			}
			if(ok)
				ans++;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
    using namespace std;
	
    int main(){
    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
		string s,t;
		cin>>s>>t;
		int n1=s.size()+1;
		int n2=t.size()+1;
		int dp[n1][n2];
		for(int i=0;i<n1;i++){
			dp[i][0]=0;
		}
		for(int i=0;i<n2;i++){
			dp[0][i]=0;
		}
		for(int i=1;i<n1;i++){
			for(int j=1;j<n2;j++){
				if(s[i-1]==t[j-1]){
					dp[i][j]=max({dp[i][j-1],dp[i-1][j],dp[i-1][j-1]+1});
				}
				else{
					dp[i][j]=max({dp[i][j-1],dp[i-1][j]});
				}
			}
		}
		int i=n1-1,j=n2-1;
		string p;
		while(i>=1 and j>=1){
			int pp=dp[i][j];
			if(dp[i][j-1]==pp){
				j-=1;
			}
			else if(dp[i-1][j]==pp){
				i-=1;
			}
			else{
				i--;
				j--;
				p+=t[j];
			}
		}
		reverse(p.begin(),p.end());
		cout<<p<<"\n";
        return 0;
    }

Measured memory_bytes: 35456
function f(x,dp)
	next=dp[:]
	for i=-2500:2500
		next[3000+i+x]+=dp[3000+i]
	end
	next
end
N,A=map(x->parse(Int,x),split(readline()))
dp=zeros(Int,6666)
dp[3000]=1
for x=map(x->parse(Int,x),split(readline()))
	dp=f(x-A,dp)
end
println(dp[3000]-1)


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===


const int INF = int(1e9 + 7);
int dist[100005][3];


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<Vi> to(N);
	for (int i = 0; i < M; ++i) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		to[u].push_back(v);
	}
	int S, T;
	cin >> S >> T;
	--S; --T;

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			dist[i][j] = INF;
		}
	}

	queue<Pii> q;
	q.emplace(S, 0);
	dist[S][0] = 0;
	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for (const auto& u : to[v]) {
			int nl = (l + 1) % 3;
			if (dist[u][nl] != INF) continue;
			dist[u][nl] = dist[v][l] + 1;
			q.emplace(u, nl);
		}
	}

	int ans = dist[T][0];
	if (ans == INF) ans = -1;
	else ans /= 3;
	cout << ans << endl;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	vector<ll> b(n), p;
	ll sum = 0LL;
	int num = 0;
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
		
		if( b[i] > a[i] ) {
			sum -= (a[i] - b[i]);
			num++;
		} else {
			p.push_back(a[i] - b[i]);
		}
	}
	
	if( num == 0 ) {
		cout << 0 << endl;
		return 0;
	}
	
	int ans = num;
	sort(p.begin(), p.end(), greater<ll>());
	
	ll x = 0LL;
	for(int i = 0; i < (int)p.size(); ++i) {
		x += p[i];
		ans++;
		
		if( x >= sum ) break;
	}
	
	if( x >= sum ) cout << ans << endl;
	else cout << -1 << endl;
	
	return 0;
}


Measured memory_bytes: 5528
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n < 1200) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     LL pm;cin>>pm;
     int n;cin>>n;
     LL a[n];
     LL mn = INT_MAX;
     LL mx = -1;
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
         if(a[i]>mx)
         {
             mx = a[i];
         }
         if(a[i]<mn)
         {
             mn = a[i];
         }
     }
     sort(a,a+n);
    //for 1st house
     LL res=mx-mn;
     for(int i=1;i<n;i++)
     {
         res = min(res,(pm-a[i]+a[i-1]));
     }
     cout<<res<<endl;
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int X = scan.nextInt();
        int Y = scan.nextInt();
        if (Y < X) {
            int temp1 = A;
            int temp2 = X;
            A = B;
            B = temp1;
            X = Y;
            Y = temp2;
        }
        int type1 = A*X + B*Y;// all seperate
        int type2 = C*X*2 + (Y-X) * B;
        int type3 = C*Y*2;
        int answer = Math.min(type1, type2);
        answer = Math.min(answer,type3);
        System.out.println(answer);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>

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

  int32_t N, H;
  std::cin >> N >> H;
  int32_t max_a = 0;
  int32_t tmp_a = 0;
  std::vector<int32_t> damage_b(N);
  for (int32_t i = 0; i < N; i++){
    std::cin >> tmp_a >> damage_b[i];
    max_a = std::max(max_a, tmp_a);
  }
  std::sort(damage_b.begin(), damage_b.end());
  
  int32_t sumB = 0, numA = 0, numB = 0;
  for (auto i = damage_b.rbegin(); i != damage_b.rend(); ++i){
    if ((*i) < max_a || sumB >= H ) break;
    numB++;
    sumB += *i;
  }
  numA = (H - sumB + max_a - 1) / max_a;

  std::cout << std::max(numA, 0) + numB << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>

typedef long long ll;

using namespace std;
int main() {
    int n;
    cin >> n;
    vector<string> w(n);
    for (auto i=0; i<n; ++i) cin >> w[i];
    map<string, int> mp;
    mp[w[0]] = 1;
    string ret = "Yes";
    
    for (auto it = w.begin()+1; it != w.end(); ++it){
        if(*(it->begin())!=*((it-1)->end()-1)){
            ret = "No";
            break;
        }
        if(mp.count(*it)==1){
            ret = "No";
            break;
        }
        mp[*it] = 1;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B,C,D;
  	int L,R;
  	cin >> A >> B >> C >> D;
  	L = A + B;
  	R = C + D;
  	if(L == R){
    	cout << "Balanced" << endl;
    }
  	else if(L > R){
      	cout << "Left" << endl;
    }
  	else{
      	cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
num_str = input().split(" ")
S = input()

N = int(num_str[0])
K = int(num_str[1])
s = list(S)

if s[K-1] == "A":
  s[K-1] = "a"
elif s[K-1] == "B":
  s[K-1] = "b"
elif s[K-1] == "C":
  s[K-1] = "c"

S = "".join(s)
print(S)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int isPrime(int num);

int main(void)
{
	int N;
	int i, j;
	scanf("%d", &N);
	int* listOfInput = (int*) malloc(N * sizeof(int));
	int* listOfPrime = (int*) malloc(N * sizeof(int));
	for (i = 0; i < N; i++)
		*(listOfPrime + i) = 0;
	for (i = 0; i < N; i++)
		scanf("%d", listOfInput + i);
	j = 0;
	for (i = 0; i < N; i++)
	{
		if(isPrime(*(listOfInput + i)))
		{
			*(listOfPrime + j) = *(listOfInput + i);
			j++;
		}
	}
	printf("%d\n", j);
}

int isPrime(int num)
{
	int d;
	for (d = 2; d <= sqrt(num); d++)
	{
		if (num % d ==  0)
			return 0;
	}
	return 1;
}


Measured memory_bytes: 2048
n,m = map(int, input().split())
a = set()
b = set()
for i in range(m):
    ai, bi = map(int, input().split())
    if ai == 1:
        a.add(bi)
    if bi == n:
        b.add(ai)
        
print("POSSIBLE" if a&b else "IMPOSSIBLE") 

Measured memory_bytes: 18936
%:pragma GCC optimize("Ofast")
  %:pragma GCC optimize("inline")
#include <bits/stdc++.h>
#define int long long
#define rint register int
  using namespace std;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 3e5 + 233;
int n, id = 0, ans = 0;
int a[N], b[N];
multiset<int> s;
map <int, int> pre;
inline int find(int x) {
  return x == pre[x] ? x : pre[x] = find(pre[x]);
}

main(void) {
  read(n);
  int t = 0;
  for (int i = 1; i <= n; i ++)
    read(a[i]), t ^= a[i];
  a[n + 1] = t;
  for (int i = 1; i <= n; i ++)
    read(b[i]);
  for (int i = 1; i <= n + 1; i ++)
    s.insert(a[i]);
  for (int i = 1; i <= n; i ++) {
    if (!s.count(b[i]))
      return puts("-1"), 0;
    s.erase(s.lower_bound(b[i]));
  }
  b[++ n] = *s.begin();
  for (int i = 1; i <= n; i ++)
    if (a[i] != b[i] || i == n) {
      if (i != n) ++ ans;
      if (!pre.count(a[i])) {
        pre[a[i]] = a[i];
      }
      if (!pre.count(b[i])) {
        pre[b[i]] = b[i];
      }
      pre[find(a[i])] = find(b[i]);
    }
  for (auto i : pre)
    ans += i.first == i.second;
  cout << ans - 1 << "\n";
}


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

int main(){
    int a, b;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        if( op == '?') break;
       
        if( op == '+') cout << a + b << endl;
        else if( op == '-') cout << a - b << endl;
        else if( op == '*') cout << a * b << endl;
        else if( op == '/') cout << a / b << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;


class P
{
    static void Main()
    {
        long[] nx = Console.ReadLine().Split().Select(long.Parse).ToArray();

        Console.WriteLine(nx[0] + Solve(nx[1], nx[0] - nx[1]));
    }
    static long Solve(long up, long side)
    {
        if (up == 0 || side == 0) return 0;
        if (up > side)
        {
            if (up % side == 0) return (side * ((up / side) * 2 - 1));
            return (side * (up / side) * 2) + Solve(up % side, side);
        }
        else
        {
            if (side % up == 0) return (up * ((side / up) * 2 - 1));
            return (up * (side / up) * 2) + Solve(up, side % up);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,T,c,t,m=1001; cin >> n >> T;
    for (int i=0; i<n; i++){
        cin >> c >> t;
        if (t<=T) m = min(m,c);
    }
    if (m!=1001) cout << m << endl;
    else cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	vector<string> head(k, "zzzzzz");
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= n - i; j++) {
			string sub = s.substr(i, j);
			if (sub < head[k - 1]) {
				auto itr = find(head.begin(), head.end(), sub);
				if (itr == head.end()) {
					head[k - 1] = sub;
					sort(head.begin(), head.end());
				}
			}
		}
	}
	cout << head[k - 1] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int k[][]=new int[M][N];
		int p[]=new int[M];
		int med[]=new int[N];
		String a="";
		int z=0,y=0,x=0,sum=0,ans=0;
		int fin=0;
		while(z<M){
			y=stdIn.nextInt();
			while(x<y){
				k[z][x]=stdIn.nextInt();
				x++;
			}x=0;
			z++;
		}z=0;y=0;
		while(z<M){
			p[z]=stdIn.nextInt();
			z++;
		}z=0;
		while(z<Math.pow(2,N)){
			a=Integer.toBinaryString(z);
			while(y<N){
				if(y>=a.length())
					med[y]=0;
				else
					if(a.charAt(a.length()-y-1)=='1')
						med[y]=1;
				y++;
			}y=0;
			while(y<M){
				while(x<N){
					if(k[y][x]==0)
						break;
					if(med[k[y][x]-1]==1)
						sum++;
					x++;
				}
				if(sum%2==p[y])
					fin++;
				if(fin!=y+1)
					break;
				y++;x=0;sum=0;
			}y=0;
			if(fin==M){
				ans++;
			}
			while(y<N){
				med[y]=0;
				y++;
			}y=0;
			z++;x=0;sum=0;fin=0;
		}
		System.out.println(ans);
	}
}

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

using namespace std;

int main(){
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  for(int x = 0; x <= k; x++)
    for(int y = 0; y <= k; y++)
      if(0 <= s - x - y && s - x - y <= k)
	cnt++;
  
  cout << cnt << endl;

  
}


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

void solve(){

    string s;
    cin >> s;
    int n;
    n = s.length();
    int count = 0;
    rep(i,n/2){
        if(s[i]!=s[n-i-1]) count++;
    }
    cout << count << endl;

}

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


Measured memory_bytes: 256
n = int(input())
s1 = input()
s2 = input()
mod = 10**9 + 7
ans = 0
if s1[0] == s2[0]:
    ans = 3
    for i in range(1,n):
        if s1[i] == s2[i]:
            if s1[i-1] == s2[i-1]:
                ans *= 2

        else:
            if s1[i] == s1[i-1] and s2[i] == s2[i-1]:
                continue
            elif s1[i - 1] == s2[i - 1]:
                ans *= 2
            else:
                ans *= 3
        ans %= mod
else:
    ans = 6
    for i in range(2,n):
        if s1[i] == s2[i]:
            if s1[i-1] == s2[i-1]:
                ans *= 2

        else:
            if s1[i] == s1[i-1] and s2[i] == s2[i-1]:
                continue
            elif s1[i-1] == s2[i-1]:
                ans *= 2
            else:
                ans *= 3
        ans %= mod

print(ans)

Measured memory_bytes: 38384
L = [int(i) for i in input().split()]
K = int(input())
from itertools import product
for k in range(K+1):
    for l in product([0,1,2], repeat=K):
        LC = L[::]
        for a in l:
            LC[a] *= 2
        if LC[0] < LC[1] < LC[2]:
            print('Yes')
            exit()

print('No')


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

int main(){

    int N,P[10],max_P,sum;
    cin >> N;
    max_P = 100;
    for (int i = 0; i < N ; i++){
        cin >> P[i];
    }
    for(int i = 0; i < N ; i++){
        sum = sum + P[i];
        if (P[i] >= max_P){
            max_P = P[i];
        }
    }

    sum = sum - (max_P / 2);
    cout << sum;

    return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char maze[h][w];
    rep(i,h){
        rep(j,w){
            cin >> maze[i][j];
        }
    }
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    int ans=0;

    rep(i,h){
        rep(j,w){
            if(maze[i][j]=='#') continue;
            int sx=i;
            int sy=j;

            queue<P> que;
            que.push({sx,sy});
            int d[h][w];
            memset(d,-1,sizeof(d));
            d[sx][sy]=0;
            
            while(!que.empty()){
                P p=que.front();
                que.pop();
                rep(k,4){
                    int nx=p.first+dx[k];
                    int ny=p.second+dy[k];

                    if(nx<0 || nx>=h || ny<0 || ny>=w || d[nx][ny]!=-1 || maze[nx][ny]=='#') continue;
                    d[nx][ny]=d[p.first][p.second]+1;
                    ans=max(ans,d[nx][ny]);
                    que.push({nx,ny});
                }
            }
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
include Math
define_method :max, -> (a,b) { a > b ? a : b }
define_method :min, -> (a,b) { a < b ?  a : b }
define_method :swap, -> (a,b) { a, b = b, a }
define_method :rep, -> (num, &block) { num.times do |i| block.call(i) end }
define_method :repl, -> (st,en, &block) { st.upto en-1 do |i| block.call(i) end }
define_method :array, -> (size,init = nil) { Array.new(size){init} }
define_method :darray, -> (size1, size2, init = nil) { Array.new(size1){Array.new(size2){init}} }
define_method :gi, -> () { gets.split.map(&:to_i) }
define_method :gs, -> () { gets.chomp }
define_method :putall, -> (obj) { obj.each do |o| puts o end }


n = gi[0]

ans = n*800-200*(n/15)

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

double cross(P p,P q){
    return p.first*q.second-p.second*q.first;
}

double dot(P p,P q){
    return p.first*q.first+p.second*q.second;
}

double norm(P p){
    return sqrt(pow(p.first,2)+pow(p.second,2));
}

int ccw(P p0,P p1,P p2){ //p0p1が基準
    p1.first -= p0.first;
    p1.second -= p0.second;
    p2.first -= p0.first;
    p2.second -= p0.second;

    if(cross(p1,p2) > 0) return 1; // counter_clockwise
    if(cross(p1,p2) < 0) return -1; // clockwise
    if(dot(p1,p2)<0) return -2 ;//on_line back
    if(norm(p1)<norm(p2)) return 2; //on_line front
    return 0; // on_segment
}


vector<P> convex_hull(vector<P> ps){

    for(int i = 0; i < ps.size(); i++){
        double x = ps[i].first;
        ps[i].first = ps[i].second;
        ps[i].second = x;
    }
    sort(all(ps));
    for(int i = 0; i < ps.size(); i++){
        double x = ps[i].first;
        ps[i].first = ps[i].second;
        ps[i].second = x;
    }
    int n = ps.size(),k=0;
    vector<P> ch(n*2);
    for(int i = 0; i < n; i++){
        while(k>=2 && ccw(ch[k-2],ch[k-1],ps[i])< 0) k--;
        ch[k] = ps[i];
        k++;
    }
    int t = k+1;
    for(int i = n-2; i >= 0; i--){
        while(k >= t && ccw(ch[k-2],ch[k-1],ps[i])< 0) k--;
        ch[k] = ps[i];
        k++;
    }

    ch.resize(k-1);
    return ch;
}

int main()
{
    int n;
    cin >> n;
    vector<P> p;
    for(int i = 0; i < n; i++){
        double x,y;
        cin >> x >> y;
        p.push_back(P(x,y));
    }

    vector<P> pp = convex_hull(p);
    //sort(all(pp));
    cout << pp.size() << endl;
    for(int i = 0; i < pp.size(); i++){
        cout << pp[i].first << " " << pp[i].second << endl;
    }
    return 0;
}


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

int main() {
        int a, b, c, k;
        cin >> a >> b >> c >> k;

        if (k <= a) cout << k;
        if (k > a && k <= a + b) cout << a;
        if (k > a + b) cout << a - (k - (a + b)); 
        return 0;
}


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

int main(){
    int n;
    cin >> n;
    int ma = -1e9, mi = 2e9,r;
    rep(i,n){
        cin >> r;
        ma = max(ma,r-mi); 
        mi = min(mi,r);
    }
    cout << ma << endl;
    return 0;
}



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

int main() {
  string S ,T;
  cin >> S >> T;
  int ans=0;
  rep(i,3){
    if(S[i]==T[i]) ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256