akhauriyash/Code-Regression huggingface dataset:
cnt = 0
def merge(A, left, mid, right):
  global cnt
  #print("marge ",A,left,mid,right)
  n1 = mid - left
  n2 = right - mid
  #L = [0] * (n1+1)
  #R = [0] * (n2+1)
  L = [0] * (n1+1)
  R = [0] * (n2+1)
  
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1] = 999999999
  R[n2] = 999999999
  i = 0
  j = 0
  for k in range(left,right):
    cnt+=1
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right):
  #print("margeSort ",A,left,right)
  if left+1 < right:
    mid = int((left + right)/2)
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

n = int(input())
S = list(map(int,input().split()))
mergeSort(S, 0, n)
S = map(str, S)
print(' '.join(S))
print(cnt)


Measured memory_bytes: 63872
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<vector<int>> G(N);
	for (auto i = 0; i < N - 1; ++i)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue<int> q;
	q.push(0);
	ll result = K;
	ll mod = (ll)1e9 + 7;
	vector<bool> used(N);
	used[0] = true;
	while (!q.empty())
	{
		auto u = q.front();
		q.pop();
		auto count = 0;
		for (auto v : G[u])
		{
			if (used[v])
			{
				continue;
			}

			used[v] = true;
			q.push(v);
			if (u == 0)
			{
				result = result * (K - count - 1) % mod;
			}
			else
			{
				result = result * (K - count - 2) % mod;
			}
			++count;
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 6520
val MOD = 1000000007

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()

    if (n < 2) {
        println(0)
        return
    }

    var all = 1L
    var no0 = 1L
    var no9 = 1L
    var no09 = 1L

    repeat(n) {
        all *= 10L
        all %= MOD

        no0 *= 9L
        no0 %= MOD

        no9 *= 9L
        no9 %= MOD

        no09 *= 8L
        no09 %= MOD
    }

    var ans = (all - no0) % MOD
    if (ans < 0) ans += MOD
    ans -= no9
    if (ans < 0) ans += MOD

    println((ans + no09) % MOD)
}

Measured memory_bytes: 34576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 2024
#define right cool

int n, m, q, i, j;
char mat[maxN][maxN];
int down[maxN][maxN], right[maxN][maxN], sum[maxN][maxN];
int x, y, xx, yy;

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%d%d%d\n", &n, &m, &q);
    for (i = 1; i <= n; i++) scanf("%s\n", mat[i] + 1);

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            sum[i][j] = (mat[i][j] == '1' ? 1 : 0);
            down[i][j] = (sum[i][j] && mat[i + 1][j] == '1' ? 1 : 0);
            right[i][j] = (sum[i][j] && mat[i][j + 1] == '1' ? 1 : 0);

            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
            down[i][j] += down[i - 1][j] + down[i][j - 1] - down[i - 1][j - 1];
            right[i][j] += right[i - 1][j] + right[i][j - 1] - right[i - 1][j - 1];
        }
    }

    for (i = 1; i <= q; i++) {
        scanf("%d%d%d%d", &x, &y, &xx, &yy);
        int ans = sum[xx][yy] - sum[x - 1][yy] - sum[xx][y - 1] + sum[x - 1][y - 1];
        ans -= down[xx - 1][yy] - down[x - 1][yy] - down[xx - 1][y - 1] + down[x - 1][y - 1];
        ans -= right[xx][yy - 1] - right[x - 1][yy - 1] - right[xx][y - 1] + right[x - 1][y - 1];

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


    return 0;
}


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

using namespace std;

int main(){

	int n , c = 0 , ans = 0;
	int count = 0;
	string name , prob , newname;

	cin >> n;
	cin >> name;

	for(int i = 0; i < n; i++){
		cin >> prob;
		int flag = 0;
		for(int e = 0; e < prob.size(); e++){
			c = 0;		
			for(int j = 0; j < prob.size(); j++){
				if(flag == 1) break;
					c++;
					newname = "";
					count = e;
				for(int k = 0; k < prob.size(); k++){
					newname += prob[count];
					count += c;
					if(newname.size() == name.size() || prob.size() < count){
						if(newname == name){
							ans++;
							flag = 1;
						}
						break;
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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 <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll ng=0,ok=n,ans=0;
    while(abs(ok-ng)>100){
        ll x=(ok+ng)/2;
        ll check=(a*x)/b-a*(x/b);
        if(ans>check){
            ok=x;
            //ans=check;
        }
        else{
            ng=x;
            ans=check;
        }
        //cout<<check<<" "<<x<<" "<<(a*x)/b<<" "<<a*(x/b)<<" ok-ng:"<<abs(ok-ng)<<endl;
    }
    //cout<<"end"<<endl;
    //cout<<ng<<" "<<ok<<endl;
    for(ll i=ng;i<ok+1;i++){
        //cout<<i-ng<<endl;
        ll num=(a*i)/b-a*(i/b);
        if(ans<num)ans=num;
    }
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

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

int main() {
	int H,W;
    cin >> H >> W;
	vector<string> a(H);
    vector<bool> X(H,false);
    vector<bool> Y(W,false);
	for (int i = 0; i < H; i++) {
		cin >> a[i];
        for(int j = 0; j < W; j++) {
            if(a[i][j] == '#') {
                X[i] = true;
                Y[j] = true;
            }
        }
    }
	for (int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(X[i]) {
                if(Y[j]) {
                    cout << a[i][j];
                }
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>

int main(){
    int dice[6],q,qnum[2];
    
    for(int i=0; i<6; i++){
        std::cin>>dice[i];
    }

    std::cin>>q;
    
    for(int i=0; i<q; i++){
        std::cin>>qnum[0]>>qnum[1];
        
        if( qnum[0]==dice[3] && qnum[1]==dice[1]){
            std::cout<<dice[0]<<std::endl;
        }else if( qnum[0]==dice[1] && qnum[1]==dice[2]){
            std::cout<<dice[0]<<std::endl;
        }else if( qnum[0]==dice[2] && qnum[1]==dice[4]){
            std::cout<<dice[0]<<std::endl;
        }else if( qnum[0]==dice[4] && qnum[1]==dice[3]){
            std::cout<<dice[0]<<std::endl;
        }
        else if( qnum[0]==dice[3] && qnum[1]==dice[5]){
            std::cout<<dice[1]<<std::endl;
        }else if( qnum[0]==dice[5] && qnum[1]==dice[2]){
            std::cout<<dice[1]<<std::endl;
        }else if( qnum[0]==dice[2] && qnum[1]==dice[0]){
            std::cout<<dice[1]<<std::endl;
        }else if( qnum[0]==dice[0] && qnum[1]==dice[3]){
            std::cout<<dice[1]<<std::endl;
        }
        else if( qnum[0]==dice[0] && qnum[1]==dice[1]){
            std::cout<<dice[2]<<std::endl;
        }else if( qnum[0]==dice[1] && qnum[1]==dice[5]){
            std::cout<<dice[2]<<std::endl;
        }else if( qnum[0]==dice[5] && qnum[1]==dice[4]){
            std::cout<<dice[2]<<std::endl;
        }else if( qnum[0]==dice[4] && qnum[1]==dice[0]){
            std::cout<<dice[2]<<std::endl;
        }
        else if( qnum[0]==dice[1] && qnum[1]==dice[0]){
            std::cout<<dice[3]<<std::endl;
        }else if( qnum[0]==dice[0] && qnum[1]==dice[4]){
            std::cout<<dice[3]<<std::endl;
        }else if( qnum[0]==dice[4] && qnum[1]==dice[5]){
            std::cout<<dice[3]<<std::endl;
        }else if( qnum[0]==dice[5] && qnum[1]==dice[1]){
            std::cout<<dice[3]<<std::endl;
        }
        else if( qnum[0]==dice[0] && qnum[1]==dice[2]){
            std::cout<<dice[4]<<std::endl;
        }else if( qnum[0]==dice[2] && qnum[1]==dice[5]){
            std::cout<<dice[4]<<std::endl;
        }else if( qnum[0]==dice[5] && qnum[1]==dice[3]){
            std::cout<<dice[4]<<std::endl;
        }else if( qnum[0]==dice[3] && qnum[1]==dice[0]){
            std::cout<<dice[4]<<std::endl;
        }
        else if( qnum[0]==dice[2] && qnum[1]==dice[1]){
            std::cout<<dice[5]<<std::endl;
        }else if( qnum[0]==dice[1] && qnum[1]==dice[3]){
            std::cout<<dice[5]<<std::endl;
        }else if( qnum[0]==dice[3] && qnum[1]==dice[4]){
            std::cout<<dice[5]<<std::endl;
        }else if( qnum[0]==dice[4] && qnum[1]==dice[2]){
            std::cout<<dice[5]<<std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int a[5];cin>>a[0];){
		repi(i,1,5)
			scanf(",%d",a+i);
		sort(a,a+5);
		
		int hist[13]={0};
		rep(i,5)
			hist[a[i]-1]++;
		sort(hist,hist+13,greater<int>());
		
		string res;
		if(hist[0]==4)
			res="four card";
		else if(hist[0]==3 && hist[1]==2)
			res="full house";
		else if(a[0]+1==a[1] && a[1]+1==a[2] && a[2]+1==a[3]&& a[3]+1==a[4] ||
				a[0]==1 && a[1]==10 && a[2]==11 && a[3]==12 && a[4]==13)
			res="straight";
		else if(hist[0]==3)
			res="three card";
		else if(hist[0]==2 && hist[1]==2)
			res="two pair";
		else if(hist[0]==2)
			res="one pair";
		else
			res="null";
		
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for(ll i = (ll)(n - 1); i > 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);
	char a;

	cin >> a;

	if (a <= 'Z')
		cout << 'A' << endl;
	else
		cout << 'a' << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int red=0,blue=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='1')blue++;
    else red++;
  }
  cout<<min(blue,red)*2<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll dp[60][60][3000];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a; cin >> n >> a;
    vi x(n + 1); for (int i = 1; i <= n; i++) cin >> x[i];
    dp[0][0][0] = 1;
    for (int j = 1; j <= n; j++) {
        for (int k = 0; k <= j; k++) {
            for (int s = 0; s <= 3000; s++) {
                if (j >= 1 && x[j] > s) {
                    dp[j][k][s] = dp[j - 1][k][s];
                } else if (j >= 1 && k >= 1 && s >= x[j]) {
                    dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
                } else {
                    dp[j][k][s] = 0;
                }
            }
        }
    }
    ll ans = 0;
    for (int k = 1; k <= n; k++) {
        ans += (ll) dp[n][k][k * a];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 69888
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=1e9+7;
signed main() {
	int n;
	cin>>n;
	int a[n+1],f[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]%=MOD;
		f[i]=a[i];
	}
	for(int i=n-1;i>=1;i--){
		f[i]+=f[i+1];
		f[i]%=MOD;
	}
	int s=0;
	for(int i=1;i<=n-1;i++){
		int t=a[i]*f[i+1];
		t%=MOD;
		s+=t;
		s%=MOD;
	}
	cout<<s;

	return 0;
}


Measured memory_bytes: 6744
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int a[MAX_N];
int b[MAX_N];


int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

  if (N%2 == 0) cout << N/2 << endl;
  else cout << N/2 + 1 << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  int A,B, C, D ,E ,F;
  string S,Sa,Sb,Sc;
  cin >> S >> Sa;
  if(S[0] == 'H')cout << Sa << endl;
  else{
    if(Sa[0] == 'H')Sa[0] ='D';
    else Sa[0] = 'H';
    cout << Sa << endl;
    
  }
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int v[N],c[N],res=0;
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    for(int i=0;i<N;i++){
        cin >> c[i];
    }
    for(int i=0;i<N;i++){
        if(v[i]-c[i]>0){
            res += v[i]-c[i];
        }
    }
    
    cout << res << endl;
}


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

// a^n mod を計算する
long modpow(long a,long n,long mod){
  long ans=1;
  while (n>0){
    if(n&1) ans=ans*a%mod;//1と共通のビットが1の時。つまり1の位が1
    a=a*a%mod;
    n=n/2;
  }
  return ans; 
}

int main(){
  long n,m;
  cin>>m>>n;
  
  cout<<modpow(m,n,1000000007)<<endl;
}



Measured memory_bytes: 3112
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(int arg_start,int arg_end,int arg_id){
		start = arg_start;
		end = arg_end;
		id = arg_id;
	}

	bool operator<(const struct Info &arg) const{
		return end < arg.end;
	};
	int start,end,id;
};

struct Data{
	Data(int arg_start,int arg_end,int arg_id){
		start = arg_start;
		end = arg_end;
		id = arg_id;
	}
	bool operator<(const struct Data &arg) const{
		return start < arg.start;
	};
	int start,end,id;
};

int main(){

	int N,W,H;

	scanf("%d %d %d",&N,&W,&H);

	int x,y,tmp_start,tmp_end;
	char dir[2];

	vector<Info> V;
	vector<Data> D;

	for(int i = 0; i < N; i++){
		scanf("%d %d %s",&x,&y,dir);

		switch(dir[0]){
		case 'N':

			if(W-x+y > H){
				tmp_start = W+H+(W-(H+x-y));
			}else{
				tmp_start = W+W-x+y;
			}

			if(x+y > H){
				tmp_end = W+H+(W-(x+y-H));
			}else{
				tmp_end = W+H+W+(H-(x+y));
			}
			break;
		case 'E':

			if(-W+x+y < 0){
				tmp_start = x+y;
			}else{
				tmp_start = W + (-W+x+y);
			}

			if(W-x+y > H){
				tmp_end = W+H+(W-(H+x-y));
			}else{
				tmp_end	= W+W-x+y;
			}
			break;
		case 'W':

			if(x+y > H){
				tmp_start = W+H+(W-(x+y-H));
			}else{
				tmp_start = W+H+W+(H-(x+y));
			}

			if(-x+y < 0){
				tmp_end = x-y;
			}else{
				tmp_end = W+H+W+(H-(-x+y));
			}

			break;
		case 'S':

			if(-x+y < 0){
				tmp_start = x-y;
			}else{
				tmp_start = W+H+W+(H-(-x+y));
			}

			if(-W+x+y < 0){
				tmp_end = x+y;
			}else{
				tmp_end = W + (-W+x+y);
			}
			break;
		}
		V.push_back(Info(tmp_start,tmp_end,i));
		D.push_back(Data(tmp_start,tmp_end,i));
	}

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

	int minimum = N,index;

	int clock_loc;


	for(int i = 0; i < N; i++){

		clock_loc = V[i].end;
		int tmp_count = 1;

		index = (i+1)%N;

		while(index != i){

			while((index != i) && ((V[index].start <= clock_loc && V[index].end >= clock_loc) ||
					(V[index].start > V[index].end && (V[index].start <= clock_loc || V[index].end >= clock_loc)))){
				index = (index+1)%N;
			}
			if(index != i){
				tmp_count++;
				clock_loc = V[index].end;
				index = (index+1)%N;
			}
		}

		minimum = min(minimum,tmp_count);
	}


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

	for(int i = 0; i < N; i++){

		clock_loc = D[i].start;
		int tmp_count = 1;

		index = (i-1+N)%N;

		while(index != i){

			while((index != i) && ((D[index].start <= clock_loc && D[index].end >= clock_loc) ||
					(D[index].start > D[index].end && (D[index].start <= clock_loc || D[index].end >= clock_loc)))){
				index = (index-1+N)%N;
			}
			if(index != i){
				tmp_count++;
				clock_loc = D[index].start;
				index = (index-1+N)%N;
			}
		}
		minimum = min(minimum,tmp_count);
	}
	printf("%d\n",minimum);

	return 0;
}

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

long long doppel(long long h) {
  long long c=1;
  if(h==1) return c;
  else {
    c += doppel(h/2)*2;
    return c;
  }
}

int main() {
  long long h;

  cin >> h;

  cout << doppel(h) << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;




signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w,ans=0,a;
    int c[10][10];
    cin>>h>>w;
    rep(i,0,10){
        rep(j,0,10){
            cin>>c[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    rep(i,0,h){
        rep(j,0,w){
            cin>>a;
            if(a>=0)ans+=c[a][1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def solve():
    s = list(input())

    cnt = 0
    for i in range(len(s)):
        if s[i] == 'W':
            cnt += i

    w = s.count('W')
    a = [int(i) for i in range(w)]
    cnt -= sum(a)

    return cnt

if __name__ == "__main__":
    print(solve())



Measured memory_bytes: 12836
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
char s[N];
int main() {
    scanf("%s", s);
    int n = strlen(s);
    int t = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'S')
            t++;
        else {
            if (t) t--, ans++;
        }
    }
    printf("%d\n", n - ans * 2);
    return 0;
}

Measured memory_bytes: 384
import sys

N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != N:
    print('No')
    sys.exit()

prev = W[0][-1]
for w in W[1:]:
    if prev != w[0]:
        print('No')
        sys.exit()
    prev = w[-1]

print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll h[100005];
ll appersum[100005];
ll ans[100005] = {};
int main() {
	ll n, m,a,b;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		appersum[a]++;
		appersum[b]++;
		if (h[a - 1] > h[b - 1]) {
			ans[a]++;
		}
		if (h[a - 1] < h[b - 1]) {
			ans[b]++;
		}
	}
	ll count = 0;
	for (int i = 1; i <= n; i++) {
		if (appersum[i] == ans[i]) {
			count++;
		}
		
	}
	cout << count << endl;
	return 0;
}

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<int>> Square(H, vector<int>(W, 0));
  char c;
  int count = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c;
      if (c == '#') {
        Square.at(i).at(j) = 1;
        count++;
      }
    }
  }
  int ans = 0;
  // 行を選ぶ
  for (int h = 0; h < (1<<H); ++h) {
    // 列を選ぶ
    for (int w = 0; w < (1<<W); ++w) {
      int black = count;
      for (int i = 0; i < H; ++i) {
        if (h & (1<<i)) {
          for (int j = 0; j < W; ++j) {
            black -= Square.at(i).at(j);
          }
        } else {
          for (int j = 0; j < W; ++j) {
            if (w & (1<<j)) {
              black -= Square.at(i).at(j);
            }
          }
        }
      }
      if (black == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
N, K = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 0
for i in range(K, N+1):
    ans += (i*(N-i+1 + N))//2 - i*(0+ 0+i-1)//2 + 1
    ans %= MOD
ans = (ans + 1) % MOD
print(ans)


Measured memory_bytes: 63636
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double ld;

const int N = 2e5 + 5;
vector<int> v[40];
int lol[40];
int a[N], b[N];

signed main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    srand(time(NULL));
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    // n = 25;
    int c1 = 0, c2 = 0;
    int c3 = 0, c4 = 0;
    fr(i, 1, n) {
        cin >> a[i];
        // a[i] = ((ll)rand() * rand()) % (1 << 28);
    }
    fr(i, 1, n) {
        cin >> b[i];
        // b[i] = ((ll)rand() * rand()) % (1 << 28);
        for(int j = 0; j <= 35; j++) {
            int val = b[i] % (1LL << (j + 1));
            v[j + 1].pb(val);
        }
    }
    fr(i, 1, 36) {
        sort(all(v[i]));
    }
    int ans = 0;
    fr(i, 1, n) {
        for(int j = 0; j <= 35; j++) {
            int val = a[i] % (1LL << (j + 1));
            val = (1LL << (j + 1)) - val;
            int x = v[j + 1].end() - lower_bound(all(v[j + 1]), val);
            x &= 1;
            lol[j + 1] ^= x;
        }
    }
    fr(j, 0, 35) {
        c1 = c2 = c3 = c4 = 0;
        fr(i, 1, n){
            if(a[i] & (1LL << j)) c1++;
            else c2++;
            if(b[i] & (1LL << j)) c3++;
            else c4++;
        }
        if((c1 * c4 + c2 * c3) & 1) lol[j] ^= 1;
    }
    fr(i, 0, 36) {
        if(lol[i]) ans ^= (1LL << i);
    }
    cout << ans << endl;
    // int brute = 0;
    // fr(i, 1, n) {
    //     fr(j, 1, n) {
    //         brute ^= (a[i] + b[j]);
    //     }
    // }
    // cout << brute << endl;
    return 0;
}

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

int main(){
  
  string str;
  int count;
  string order;
  int a,b;
  string strx;
  
  cin >> str;
  
  cin >> count;
  
  for (int i = 0; i < count; i ++ ) {
      
      cin >> order;
      
      if (order == "print") {
          
          cin >> a >> b;
          
          string print = str.substr(a,b-a+1);
          
          cout << print << endl;
          
      } else if (order == "reverse") {
          
          cin >> a >> b;
          
          int a1 = a;
          int b1 = b;
          
          string str1 = str;
          
          for (int j = 0; j < b-a+1 ;j ++){
              
              str[a1] = str1[b1];
              
              
              
              b1 -= 1;
              
              a1 += 1;
              
              
              
          }
          
      } else {
          
          cin >> a >> b >> strx;
          
          //str.erase(a,b-a+1);
          
          //str.insert(a,strx);
          
          str.replace(a,b-a+1,strx);
          
      }
      
  }
  
  return 0;
  
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int h;
    cin >> h;

    int res = 1;
    int cnt = 1;
    while(h > 1) {
        res *= 2;
        h >>= 1;
        cnt += res;
    }

    cout << cnt << endl;
    
    return 0;
}

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

using namespace std;

int n, k, x, y;

void init()
{
	scanf("%d", &n);
	scanf("%d", &k);	
	scanf("%d", &x);
	scanf("%d", &y);
	//int res = n * x;
	//int extra = n % k;
	if (n < k)
	{
		printf("%d\n", n * x);
	}
	else
	{
		int res = k * x + (n - k) * y;
		printf("%d\n", res);
	}

}

int main()
{

	//#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	//#endif

	init();

	return 0;
}

Measured memory_bytes: 256
require 'set'

def main
    n = gets.to_i
    s = gets.chomp.split("")
    rs = []
    gs = []
    bs = []
    s.each_with_index do |c, i|
        rs.push i if c == "R"
        gs.push i if c == "G"
        bs.push i if c == "B"
    end
    rgbs_asc = [rs, gs, bs].sort_by { |a| a.size }
    rgb1 = rgbs_asc[0]
    rgb2 = rgbs_asc[1]
    rgb3 = Set.new(rgbs_asc[2])

    ans = 0
    rgb1.each do |r|
        rgb2.each do |g|
            min = [r,g].min
            max = [r,g].max
            b1 = min - (max - min)
            if (max + min) % 2 == 0
                b2 = (max + min) / 2
            else
                b2 = n + 100
            end
            b3 = max + (max - min)

            ng = 0
            ng += 1 if rgb3.include? b1
            ng += 1 if rgb3.include? b2
            ng += 1 if rgb3.include? b3

            ans += rgb3.size - ng
        end
    end
    puts ans
end

main


Measured memory_bytes: 14812
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        string word = Console.ReadLine();
        int count = 0;
        while(true)
        {
            string[] str = Console.ReadLine().Split(' ');
            for(int i = 0;i < str.Length;i++)
            {
                if(str[i].ToLower() == word.ToLower())
                {
                    count++;
                }
            }
            if(str[0] == "END_OF_TEXT")break;
        }
        Console.WriteLine(count);
    }
}



Measured memory_bytes: 17884
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =2e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }

	  
	 void solve() {		 
		    int r,c,k;
		    cin>>r>>c>>k;
		    vector<string> s(r);
		    rep(i,0,r) cin>>s[i];
		    int ans=(1LL<<60);
		    
		    rep(i,0,(1LL<<(r-1))) {
				  int tmp=0;
				  int nv=__builtin_popcountll(i)+1;
				  
				  vi v(nv,0);
				  rep(j,0,c) {
					   int nax=0;
					    rep(j1,0,r) {
							  v[nax]+=s[j1][j]-'0';
							  if(i&(1LL<<j1)) nax++;
							}
							int flag=0;
							rep(j1,0,nv) {
								   if(v[j1]>k) flag=1;
								}
						   if(flag) {
							        tmp++;
							        rep(j1,0,nv) v[j1]=0;
							        nax=0;
							        rep(j1,0,r) {
										  v[nax]+=s[j1][j]-'0';
										  if(i&(1LL<<j1)) nax++;
										}
									 flag=0;
									 rep(j1,0,nv) {
										    if(v[j1]>k) flag=1;
										 }
									if(flag)
									 tmp=(1LL<<60);						   
							   }		
					  }
					  ans=min(ans,tmp+__builtin_popcountll(i));				  
				  
				}
				
				cout<<ans<<endl;  
	            
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	ll n; cin >> n;
	vector<ll> pos(n+1);
	for(int i = 0; i < n; ++i){
		ll a; cin >> a;
		pos[a] = i+1;
	}

	ll ans = 0;
	set<ll> se{0, n+1};
	for(ll i = n; i > 0; --i){
		auto r1 = se.lower_bound(pos[i]);
		auto l1 = r1;
		--l1;

		ll num = 0;

		if (*l1 != 0) {
			auto l2 = l1;
			--l2;
			num += (*l1 - *l2) * (*r1 - pos[i]);
		}

		if (*r1 != n+1) {
			auto r2 = r1;
			++r2;
			num += (pos[i] - *l1) * (*r2 - *r1);
		}

		ans += num * i;
		se.insert(pos[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
  using namespace std;
  long long MOD=1000000007;
  #define IOS() ios_base::sync_with_stdio(0); cin.tie(0);
  typedef long long ll;
  #define pb push_back
  typedef pair<ll,ll> pi;
  

int main()
{
  IOS();
  int n;
  int k;
  cin>>n>>k;
  int a[n+1];
  for (int i = 1; i <=n; ++i)
  {
      cin>>a[i];
  }

  ll dp[n+1][k+1]={0ll};

  for(int j=0;j<=k;j++)
  {
    if(j<=a[1])
      dp[1][j]=1;
    else
      dp[1][j]=0;
  }


  for(int i=2;i<=n;i++)
  {

    for(int j=0;j<=k;j++)
    {

      if(j==0)
        dp[i][j]=dp[i-1][j];

      else{
        dp[i][j]=( MOD + dp[i][j-1]+dp[i-1][j] - ((j-a[i]-1>=0)? dp[i-1][j-a[i]-1] : 0))%MOD;
       
      }
    }

  }

  cout<<dp[n][k]<<endl;

  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    double L;cin >> L;
    double a = L/3;
    double sum = pow(a,3);
    cout << setprecision(10) << sum << endl;
    return 0;
}

Measured memory_bytes: 4196
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        String s = scanner.next();
        StringBuffer sb = new StringBuffer();
        for (int i=1;i<=s.length();i++) {

        	if(i%2==1) {
        		sb.append(s.substring(i-1, i));
        	}
        }
        System.out.println(sb.toString());

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

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

int main(){
  string N; cin >> N;
  reverse(N.begin(), N.end());
  if(N[0] == '3') cout << "bon" << endl;
  else if(N[0] == '0' || N[0] == '1' || N[0] == '6' || N[0] == '8')
    cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=2e3+_;
const int mod=1e9+7;
inline int ad(int x,int y){return x>=mod-y?x-mod+y:x+y;}
inline int re(int x,int y){return x<y?x-y+mod:x-y;}
inline int mu(int x,int y){return (LL)x*y%mod;}
inline int qp(int x,int y){int r=1;while(y){if(y&1)r=mu(r,x);x=mu(x,x),y>>=1;}return r;}

int a[maxn],c[maxn];
int calc(int c,int K)
{
	return mu(mu(mu(c,K-1),K),qp(2,mod-2));
}
int main()
{
	int n,K,ans=0;
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for(int j=1;j<i;j++)
			if(a[i]<a[j])c[i]++;
		ans=ad(ans,mu(c[i],K));
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
			if(a[i]<a[j])c[i]++;
		ans=ad(ans,calc(c[i],K));
	}
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

K,X = inputIL()

ANS = [i for i in range(X-K+1,X+K)]
print(*ANS,sep=" ")

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int sq[n];
  for(int i=0; i<n; i++)
    cin >> sq[i];

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

  bool flag = true;
  for(int i=0; i<n-1; i++){
    if(sq[i] > sq[i+1]){
      flag = false;
      break;
    }
  }

  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
#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> P;
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;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

lint sgm(lint n) {
	//0からの総和を返す
	return n * (n + 1) / 2;
}

lint fact(lint n) {
	//n!を返す
	if (n == 0) return 1;
	else return n * fact(n - 1);
}

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	lint N, X;
	cin >> N >> X;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A);
	lint sum = 0;
	rep(i, N) {
		sum += A[i];
		if (sum > X) {
			cout << i << endl;
			return 0;
		}
	}
	if (sum != X) {
		N--;
	}
	cout << N << endl;
}


Measured memory_bytes: 256
s=input()
k=int(input())
n=len(s)
l = []
for i in range(n):
    l.append(s[i])
for i in range(n-1):
    l.append(s[i:i+2])
for i in range(n-2):
    l.append(s[i:i+3])
for i in range(n-3):
    l.append(s[i:i+4])
for i in range(n-4):
    l.append(s[i:i+5])

res = list(set(l))
res.sort()
print(res[k-1])


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


set<char>st;



int main()
{


   string s;

   ll d,n;

   cin>>s;
   n=s.length();


   for(ll i=0;i<s.size();i++)
   {
       st.insert(s[i]);
   }

   d=st.size();

   if(d==n)cout<<"yes"<<endl;
   else
    cout<<"no"<<endl;


    return 0;
}



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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> data(2 * M,0);
    vector<int> counter(N,0);

    for(int i = 0;i < 2 * M;i++){
        cin >> data[i];
    }

    for(int i = 0;i < N;i++){
        for(int j = 0;j < 2 * M;j++){
            if(i + 1 == data[j])counter[i]++;
        }
    }

    for(int i = 0;i < N;i++){
        cout << counter[i] <<endl;
    }
}

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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int i, j, tempL, tempR;
    int L = 1;
    int R = n;
    for (i = 0; i < m; i++)
    {
        cin >> tempL >> tempR;
        L = max({L, tempL});
        R = min({R, tempR});
    }

    cout << max(0, R - L + 1) << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> Int
solve !n !k = last $ takeWhile (<= k `div` n) $ divisors k
 where
  divisors t =
    let divHalf =
          filter (\x -> t `mod` x == 0) $ takeWhile (\x -> x * x <= t) [1 ..]
    in  divHalf ++ map (t `div`) (reverse divHalf)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine

  print $ solve n m



Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p,P;
  int have[50];
  int remain=0;
  int plase=0;
  while(1){
    for(int i=0;i<50;i++){
      have[i]=0;
    }
    cin>>n>>p;
    P=p;
    plase=0;
    if(n==0 && p==0) break;
    while(1){
      if(have[plase%n]==P) break;
      if(p==0){
	p=have[plase%n];
	have[plase%n]=0;
	plase++;
      }else{
	have[plase%n]++;
	plase++;
	p--;
      }
    }
    cout<<plase%n<<endl;
  }
  return 0;
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main()
    {

            unsigned long long n,a,b,c=0;
            cin>>n;
            unsigned long long sum=100;
            for(int i=0;;i++)
            {
                sum+=(sum/100);
                c++;
                //cout<<sum<<endl;
                if(sum>=n){break;}
            }
            cout<<c<<endl;
















        return 0;
    }


Measured memory_bytes: 3564
import java.util.*
fun main(args:Array<String>?): Unit {
    while(true){
        val n = readLine()!!.toInt()
        if (n == 0) return
        val nodes = Array(n){Stack<Edge>()}
        repeat(n - 1){
            val (a, b, t) = readLine()!!.trim().split(' ').map(String::toInt)
            nodes[a - 1].push(Edge(b - 1, t))
            nodes[b - 1].push(Edge(a - 1, t))
        }
        println(solve(nodes))
    }
}
fun solve(defaultNode: Array<out Collection<Edge>>): Int {
    val depth = Array(defaultNode.size){-1}
    val queue = LinkedList<Int>()
    depth[0] = 0
    queue.add(0)
    while(queue.isNotEmpty()){
        val current = queue.pop()
        for ((to, _) in defaultNode[current]) if (depth[to] == -1){
            depth[to] = depth[current] + 1
            queue.add(to)
        }
    }
    val memoReturns = Array(defaultNode.size){null as Int?}
    val memoNotReturns = Array(defaultNode.size){null as Int?}
    val nodes = defaultNode.mapIndexed { current, node -> node.filter{depth[it.to] > depth[current] && defaultNode[it.to].size != 1}}
    fun costReturn(current: Int): Int {
        if (memoReturns[current] == null)
            memoReturns[current] = nodes[current].map{costReturn(it.to) + it.time * 2}.sum()
        return memoReturns[current]!!
    }
    fun costNotReturn(current: Int): Int {
        if (memoNotReturns[current] == null) {
            val returns = nodes[current].map { costReturn(it.to) + it.time * 2 }.sum()
            memoNotReturns[current] = nodes[current].map{
                returns - costReturn(it.to) - it.time + costNotReturn(it.to)
            }.min() ?: 0
        }
        return memoNotReturns[current]!!
    }
    costNotReturn(0)
    return costNotReturn(0)
}
data class Edge(val to: Int, val time: Int)


Measured memory_bytes: 33372
#include <cstdio>

#define FOR( i, k, n ) for ( int i = ( k ); i < ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 0, n )

#define MAX_N 20
#define MAX_Q 200
#define MAX_M 2000

void Input( void );

int n, q;
int A[ MAX_N ], M[ MAX_Q ];
bool dp[ MAX_N + 1 ][ MAX_M + 1 ];  // dp[i+1][j] : i番目まででjが作れるか

int main() {
	Input();
	REP( i, n ) dp[ i ][ 0 ] = true;
	REP( i, n ) REP( j, MAX_M + 1 ) {
		if( A[ i ] > j ) dp[ i + 1 ][ j ] = dp[ i ][ j ];
		else if( dp[ i ][ j ] || dp[ i ][ j - A[ i ] ] ) dp[ i + 1 ][ j ] = true;
		else dp[ i + 1 ][ j ] = false;
	}
	REP( i, q ) {
		if( dp[ n ][ M[ i ] ] ) printf( "yes\n" );
		else printf( "no\n" );
	}
	return 0;
}

void Input() {
	scanf( "%d", &n );
	REP( i, n ) scanf( "%d", &A[ i ] );
	scanf( "%d", &q );
	REP( i, q ) scanf( "%d", &M[ i ] );
	return ;
}

Measured memory_bytes: 1048
#include <stdio.h>

int main(void)
{
    int X = 0;

    scanf("%d", &X);

    if (X >= 400 && X <= 599) {
        printf("8\n");
    } else if (X >= 600 && X <= 799) {
        printf("7\n");
    } else if (X >= 800 && X <= 999) {
        printf("6\n");
    } else if (X >= 1000 && X <= 1199) {
        printf("5\n");
    } else if (X >= 1200 && X <= 1399) {
        printf("4\n");
    } else if (X >= 1400 && X <= 1599) {
        printf("3\n");
    } else if (X >= 1600 && X <= 1799) {
        printf("2\n");
    } else if (X >= 1800 && X <= 1999) {
        printf("1\n");
    } else {
        printf("err¥n");
    }

    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

long double dp[3050][3050];
long double p[3050];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; cin >> n;

  rep2(i,1,n+1) cin >> p[i];

  m0(dp);
  dp[1][1] = p[1]; dp[1][0] = 1 - p[1];
  rep2(i,2,n+1) dp[i][0] = dp[i-1][0] * (1 - p[i]);
  
  rep2(i,2,n+1)rep2(j,1,n+1){
      dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * p[i]; 
  }

  long double ans = 0;
  rep2(j,n/2+1, n+1) ans += dp[n][j];
  cout << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 145664
#include <stdio.h>
int main(void)
{
    int k;
    int ss=1;
    long long int a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    scanf("%d",&k);
    for(int p=0;p<k;p++)ss*=2;
    long long int ans=0;
    if(a>=b&&a>=c)ans=a*ss+b+c;
    else if(b>=c&&b>=a)ans=a+b*ss+c;
    else ans=a+b+c*ss;
    printf("%lld",ans);
}


Measured memory_bytes: 128