akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e6+5;

bool is_prim(int x){
    if(x <= 1)
        return false;
    for(int i = 2; i*i <= x; i++){
        if(x % i == 0)
            return false;
    }
    return true;
}

int main(){
    int x;
    cin >> x;
    while(true){
        if(is_prim(x)){
            cout << x << "\n";
            return 0;
        }
        x++;
    }
    //
}


Measured memory_bytes: 3576
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int main()
{
    LL n,a[100010],x;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    LL sum=0;
    a[0]=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i-1]+a[i]>x)
        {
            sum+=(a[i-1]+a[i]-x);
            a[i]-=(a[i-1]+a[i]-x);
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
#define db long double
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 200050;
int n; LL a[N],b[N],tmp[N],preb[N],prebi[N];
inline void init(){
	int i,id = 1;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]);
	for (i = 1; i <= n; ++i) read(b[i]);
	for (i = 1; i <= n; ++i) if (a[i] > a[id]) id = i;
	if (id != 1){
		--id;
		for (i = 1; i <= n; ++i) tmp[i] = a[i];
		for (i = 1; i <= n; ++i) a[(i<=id?i+n-id:i-id)] = tmp[i];
		for (i = 1; i <= n; ++i) tmp[i] = b[i];
		for (i = 1; i <= n; ++i) b[(i<=id?i+n-id:i-id)] = tmp[i];
	}
	a[n+1] = a[1],b[n+1] = b[1];
	a[0] = a[n],b[0] = b[n];
	for (i = 1; i <= n+1; ++i) preb[i] = preb[i-1] + b[i],prebi[i] = prebi[i-1] + b[i] * i;
}
inline db calc(int l,int r,int m){
	if (l == r) return a[l];
	db k = r-l,b = (db)(2.0) * (r) * (preb[r-1]-preb[l]) - (db)(2.0) * (prebi[r-1] - prebi[l]),y = a[r] - a[l],x = (y - b) / k;
	return a[l] + (m-l) * x + (db)(2.0) * (m) * (preb[m-1]-preb[l]) - (db)(2.0) * (prebi[m-1] - prebi[l]);
}
int stk[N],top; db ans,mx[N];
int main(){
	init();
	int i,j,ll,rr;
	stk[0] = 1;
	for (i = 1; i <= n+1; ++i){
		while (top && calc(stk[top-1],i,stk[top]) >= calc(stk[top-1],stk[top],stk[top])) --top;
		stk[++top] = i;
	}
	for (i = 0; i <= top; ++i){
		ll = stk[i],rr = stk[i+1];
		for (j = ll; j <= rr && j <= n; ++j) mx[j] = max(mx[j],calc(ll,rr,j));
	}
	for (i = 1; i <= n; ++i) ans += mx[i];//,cerr << i << ' ' << mx[i] << '\n';
	ans /= n;
	cout << fixed << setprecision(20) << ans << '\n';
	return 0;
}

Measured memory_bytes: 15388
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int dateNum = scan.nextInt();
      	int dateFeatureNum = scan.nextInt();
      	int con = scan.nextInt();
      	int acNum = 0;	
		int[] dateFeature = new int[dateFeatureNum];
      	//B_iを配列dateFeatureに格納する
      	for(int i = 0; i < dateFeatureNum; i++){
        	dateFeature[i] = scan.nextInt();
        }
      	for(int i = 0; i < dateNum; i++){
        	int sum = 0;
            for(int j = 0; j < dateFeatureNum; j++){
            	int a = scan.nextInt();
              	sum += a*dateFeature[j];
            }
          	sum += con;
          	
          	if(sum > 0){
            	acNum++;
            }
        }
      	System.out.println(acNum);
    }
}

Measured memory_bytes: 23252
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,l;
    cin >> n >> m >> l;
    vvll d(n,vll(n,LLINF));
    REP(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    REP(i,n) d[i][i] = 0;
    REP(k,n){
        REP(i,n){
            REP(j,n){
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    vvll d2(n,vll(n,LLINF));
    REP(i,n){
        REP(j,n){
            if(i==j){
                d2[i][j] = 0;
            }else if(d[i][j]<=l){
                d2[i][j] = 1;
            }
        }
    }
    REP(k,n){
        REP(i,n){
            REP(j,n){
                d2[i][j] = min(d2[i][j], d2[i][k]+d2[k][j]);
            }
        }
    }
    int q;
    cin >> q;
    vint s(q),t(q);
    REP(i,q){
        cin >> s[i] >> t[i];
        s[i]--;
        t[i]--;
    }
    REP(i,q){
        if(d2[s[i]][t[i]]==LLINF){
            cout << -1 << endl;
        }else{
            cout << d2[s[i]][t[i]]-1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T,U;
  cin >> S >> T;
  
  int A,B;
  cin >> A >> B;
  
  cin >> U;
  
  if(U == S)
    A--;
  else if(U == T)
    B--;
  
  cout << A << " "<< B;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int n;
	int a[103];

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

	int ans = INF;

	for (int i = -100; i < 101; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (i - a[j]) * (i - a[j]);
		}
		ans = std::min(ans, sum);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in range(n):
    l.append([1,a[i]])
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:x[1], reverse=True)
c=0
ans=0
for i in range(n+m):
    ans+=l[i][1]*l[i][0]
    c+=l[i][0]
    if c>n:
        ans-=l[i][1]*(c-n)
        break
print(ans)


Measured memory_bytes: 97816
import math
A, B, H, M = [int(i) for i in input().split()]
r1 = A
r2 = B
t1 = (H*60+M) / 720 * math.pi * 2
t2 = M / 60 * math.pi * 2
print((r1**2 + r2**2 - 2*r1*r2*math.cos(t1-t2))**(1/2))


Measured memory_bytes: 9504
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef rd
#define endl '\n'
#endif
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
#define double long double
//typedef long double f80;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=2e9;
const int mod=1e9+7;
typedef vector<int> vi;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk=clock();
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int a[200005];
int dp[200005];
int st[200005];
int run[200005];
void solve() {
	int n;
	cin>>n;
	fr(i,1,n)
		cin>>a[i];
	dp[0]=1;
	fr(i,1,n) {
		dp[i]+=dp[i-1];
		dp[i]%=mod;
		if(a[i-1]!=a[i]) {
			st[a[i]]+=run[a[i]];
			st[a[i]]%=mod;
			run[a[i]]=0;
			dp[i]+=st[a[i]];
			dp[i]%=mod;
			st[a[i]]=0;
			run[a[i]]+=dp[i];
			run[a[i]]%=mod;
		}
	}
	cout<<dp[n]<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cerr<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 6528
import heapq
import math
n,m = map(int,input().split())
s = list(map(int,input().split()))
s = list(map(lambda x:int(x)*(-1), s))
heapq.heapify(s)
for i in range(m):
  heapq.heappush(s,math.ceil(heapq.heappop(s)/2))
print(sum(s)*(-1))

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

int main(){
    int N;
    cin >> N;
    vector<long> dam(N);
    vector<long> mountain(N);
    long total=0;
    for (int i=0;i<N;i++){
        cin >> dam[i];
        total +=dam[i];
    }
    mountain[0] = total;
    for (int j = 1 ; 2*j <= N-1  ; j++){
        mountain[0] -= 2*dam[2*j-1];
    }
    for (int k = 1; k < N; k++){
        mountain[k] = 2*dam[k-1]-mountain[k-1];
    }
    for (int l=0;l<N-1;l++) cout << mountain[l] << " ";
    cout << mountain[N-1] << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){

int r, d, x, ans;
cin>> r >> d >> x;

for(int i=0;i<10;i++){
	ans = r * x - d;
	cout<< ans <<endl;
	x = ans;
}

}


Measured memory_bytes: 256
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, W = map(int, input().split())
dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    w, v = map(int, input().split())
    for sum_w in range(W+1):
        # i番目の品を取る
        if w <= sum_w:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w] + v)
        # i番目の品を取らない
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])

Measured memory_bytes: 171528
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll s;
  cin >> s;
  if(s==1000000000000000000LL){
    cout << 0 << " " << 0 << " ";
    cout << 1000000000 << " " << 1000000000 << " ";
    cout << 1000000000 << " " << 0 << endl;
    return 0;
  }
  ll t = s/1000000000;
  ll x = s-t*1000000000;
  cout << 0 << " " << t << " ";
  cout << 1000000000 << " " << t+1 << " ";
  cout << x << " " << 0 << endl;
  return 0;
}

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

int main(void){
    int N;

    scanf("%d", &N);

    int *A = (int *) malloc(sizeof(int) * N);
    int i;

    for(i = 0; i < N; i ++){
        scanf("%d", A + i);
    }
    int sum = abs(A[0] - 0);

    for(i = 1; i < N; i ++){
        sum += abs(A[i] - A[i - 1]);
    }
    sum += abs(0 - A[N - 1]);

    printf("%d\n", sum - abs(A[0] - 0) - abs(A[1] - A[0]) + abs(A[1] - 0));
    
    for(i = 1; i < N - 1; i ++){
        printf("%d\n", sum - abs(A[i] - A[i-1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]));
    }
    printf("%d\n", sum - abs(A[N - 1] - A[N - 2]) - abs(0 - A[N - 1]) + abs(0 - A[N - 2]));

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(N);
	long long X = 0;
	for(int i=0;i<N;i++){
		cin>>A[i];
		//cout<<(bitset<10>)A[i]<<endl;
	}
	
	vector<int> cnt(60,0);
	
	for(int i=0;i<N;i++){
		for(int j=0;j<60;j++){
			if((((long long)1<<j)&A[i])!=0)cnt[j]++;
		}
	}
	
	long long ans = 0;
	
	for(int i=0;i<60;i++){
		if(cnt[i]%2==1){
			ans+=((long long)1<<i);
			for(int j=0;j<N;j++){
				if((((long long)1<<i)&A[j])!=0){
					A[j]-=((long long)1<<i);
				}
			}
		}
	}
	//for(int i=0;i<N;i++)cout<<(bitset<10>)A[i]<<endl;
//	cout<<endl;
	int last = 0;
	for(int i=59;i>=0;i--){
		long long a = ((long long)1<<i);
		int K = -1;
		for(int j=last;j<N;j++){
			if((A[j]&a)!=0){
				K=j;
				break;
			}
		}
		if(K==-1)continue;
		for(int j=0;j<N;j++){
			if(K==j)continue;
			if((A[j]&a)!=0){
				A[j] ^= A[K];
			}
		}
		swap(A[last],A[K]);
		last++;
		//for(int i=0;i<N;i++)cout<<(bitset<10>)A[i]<<endl;
		//cout<<endl;

	}
	
	long long a = 0;
	for(int i=0;i<N;i++){
		a^=A[i];
	}
	
	ans += a*2;
	
	cout<<ans<<endl;
		
		
	
	return 0;
}

Measured memory_bytes: 1024
#C
H,W = map(int,input().split())
whole = H*W

MIN = float("inf")
for h in range(H):
    s1 = (h+1)*W
    s2 = W*((H-(h+1))//2)
    s3 = whole - (s1+s2)
    s4 = (H-(h+1))*(W//2)
    s5 = whole - (s1+s4)
    kari1 = max({s1,s2,s3})-min({s1,s2,s3})
    kari2 = max({s1,s4,s5})-min({s1,s4,s5})
    MIN = min({kari1,kari2,MIN})
for w in range(W):
    s1 = (w+1)*H
    s2 = H*((W-(w+1))//2)
    s3 = whole - (s1+s2)
    s4 = (W-(w+1))*(H//2)
    s5 = whole - (s1+s4)
    kari1 = max({s1,s2,s3})-min({s1,s2,s3})
    kari2 = max({s1,s4,s5})-min({s1,s4,s5})
    MIN = min({kari1,kari2,MIN})
    
print(MIN)

        
    



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
struct mmp { int a, b; }z[10];
int main()
{
	int a;
	scanf("%d", &a);
	for (int i = 0; i < a; i++)
		scanf("%d%d", &z[i].a, &z[i].b);
	double f=0, g;
	for (int p = 0; p < a; p++)
	{
		for (int i = p+1; i < a; i++)
		{
			g = (z[i].a - z[p].a) * (z[i].a - z[p].a) + (z[i].b - z[p].b) * (z[i].b - z[p].b);
			g = g * 1.0;
			f += sqrt(g);
		}
	}
	printf("%.10lf\n", f*2/a);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 




vector<pair<int,int>> adj[100005];
ll dist[100005];
int n;
void dfs(int node,int par){
     for(auto ch:adj[node]){
          if(ch.fi==par)continue;
          dist[ch.fi]=dist[node]+ch.se;
          dfs(ch.fi,node);
     }
}




int main()
{
     int n,m;
     cin>>n>>m;
     vector<pair<int,int>> vec;
     for(int i=0;i<m;i++){
          int x,y;
          cin>>x>>y;
          vec.push_back({x,y});
     }
     sort(vec.begin(),vec.end());
     int ct=0;
     int s=vec[0].fi,e=vec[0].se;
     for(int i=1;i<vec.size();i++){
          int a=vec[i].fi,b=vec[i].se;
          if(a==s){
               e=min(e,b);
          }
          else if(a>s&&a<e){
               s=max(a,s);
               e=min(b,e);
          }
          else if(a>=e){
               ct++;
               s=a;
               e=b;
          }
     }
     if(s<e)ct++;
     cout<<ct;
}






















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

int main(){
    string s,t;
    cin >> s >> t;
    
    vector<int> start(26,-1),goal(26,-1);
    rep(i,s.size()){
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if(start[a] != -1 || goal[b] != -1){
            if(start[a] != b || goal[b] != a){
                cout << "No" << endl;
                return 0;
            }
        }else{

            start[a] = b;
            goal[b] = a;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while (true) {
        string s; cin >> s;
        if (s=="#") break;
        int y, m, d; cin >> y >> m >> d;

        string ret;
        if (y>31 || (y==31&&m>=5)) {
            ret+="? ";
            y-=30;
        }
        else ret+="HEISEI ";

        cout << ret << y << " " << m << " " << d << endl;
    }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

using G=vector<vector<int>>;

int Dreyfus_wagner(const G &graph,const auto &term){
	using W=int; W inf=1<<28;
	const int n=int(graph.size()),t=int(term.size());
	if(t<=1) return 0;
	auto dist=graph;
	vector<vector<W>> opt(1<<t,vector<W>(n,inf));

	rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j],dist[i][k]+dist[k][j]);
	
	map<int,int> dict;
	rep(i,t){
		dict[term[i]]=1<<i;
		rep(j,n) opt[1<<i][j]=dist[term[i]][j];
		rep(j,t) opt[(1<<i)|(1<<j)][term[j]]=dist[term[i]][term[j]];
	}

	auto next_combination=[&](int s){
		int x=s&-s,y=s+x;
		return ((s&~y)/x>>1)|y;
    };

	rep(k,2,t){
		for(int s=(1<<k)-1;s<(1<<t);s=next_combination(s)){
			rep(i,n){
				int ns=s|dict[i];
				if(dict[i] and s==ns) continue;
				for(int u=(s-1)&s;u!=0;u=(u-1)&s){
					int c=s&(~u);
					chmin(opt[ns][i],opt[u][i]+opt[c][i]);
				}
			}
		}
		for(int s=(1<<k)-1;s<(1<<t);s=next_combination(s)){
			rep(i,n){
				int ns=s|dict[i];
				if(dict[i] and s==ns) continue;
				rep(j,n) chmin(opt[ns][i],opt[s][j]+dist[j][i]);
			}
		}
	}

	const int mask=(1<<t)-1;
	W ans=opt[mask][0];
	rep(i,n) chmin(ans,opt[mask][i]);
	return ans;
}

int main(void){
	int h,w;
	while(cin >> h >> w){
		if(h==0) break;
		const int inf=1<<28;

		G graph(h*w,vector<int>(h*w,inf));
		rep(i,h*w) graph[i][i]=0;
		vector<int> term;

		rep(i,h*w){
			int in;
			cin >> in;
			if(in) term.push_back(i);
		}
		
		rep(i,h)rep(j,w){
			const int cur=w*i+j;
			if(i+1<h) graph[cur][cur+w]=graph[cur+w][cur]=1;
			if(j+1<w) graph[cur][cur+1]=graph[cur+1][cur]=1;
		}
		int res=Dreyfus_wagner(graph,term);
		cout << h*w-1-res << endl;
	}
	return 0;
}

Measured memory_bytes: 3260
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> RL(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        RL[i] = make_pair(b, a);
    }
    sort(RL.begin(), RL.end());
    ll ans = 0;
    int now_pos = 0;
    rep(i, M) {
        if (now_pos <= RL[i].second) {
            ans++;
            now_pos = RL[i].first;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long int LL;
typedef vector<int> VI;

int main(){
  int N, K;
  cin >> N >> K;
  if(N < K * 2 - 1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long


using namespace std;

ll MOD = 1000000007;
int main(){
  int n;
  int k;
  cin >> n >> k;
  vector<ll> a(n+1);
  for( int i = 0 ; i < n ; i++ ){
    cin >> a[i];	  
  }
  vector<vector<ll>> dp(n+100,vector<ll> (k+100,0));
  for( int i = 0 ; i <= a[0] ; i++ ) dp[0][i] = 1;
  for( int i = 1 ; i < n ; i++ ){
    for( int j = 0 ; j <= k ; j++ ){
      if( j <= a[i] ){//[0,a[i]]
        if( j == 0 ) dp[i][j] = dp[i-1][j];
        else{
          dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
        }
      }
      else{
        dp[i][j] = (dp[i][j-1]  - dp[i-1][j-a[i]-1] + MOD + dp[i-1][j] ) % MOD;
      }
    }
  }
///  for( int i = 0 ; i < n ; i++ ){
///    for( int j = 0 ; j <= k ; j++ ){
///      cout << dp[i][j] << " " ;
///    }
///    cout << endl;
///  }
  cout << dp[n-1][k] << endl;
  return 0;
}


Measured memory_bytes: 157824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
ll n,m,q,ans=0;
vector<vector<ll>> v(100,vector<ll> (4));
void f(ll *a,ll i,ll p)
{
	if(i==n+1)
	{
		ll sum=0;
		ll j=0;
		while(j<q)
		{
			if(a[v[j][1]]-a[v[j][0]]==v[j][2])
				sum+=v[j][3];
			j++;
		}
		ans=max(sum,ans);
		return;
	}
	while(p<=m)
	{
		a[i]=p;
		f(a,i+1,p);
		p++;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin>>n>>m>>q;
  ll i=0;
  while(i<q)
  {
  	cin>>v[i][0]>>v[i][1]>>v[i][2]>>v[i][3];
  	i++;
  }
  ll a[n+10];
  f(a,1,1);
  deb(ans);
}

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

int main(){
    int n , k , total = 0;
    cin >> n >> k;
    vector <int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin() , a.end());
    for(int i = 0; i < k; i++){
        total += a[i];
    }
    cout << total << endl;
}

Measured memory_bytes: 3628
import java.lang.*;
import java.io.*;
import java.util.*;

public class Main {
  public static void main(String arg[]) throws IOException { new Main().bw.close(); }

  BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
  BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

  StringTokenizer st = null;
  String nxttok() { 
    try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); }
    catch(Exception e) { return "";}
    return st.nextToken();
  }

  int nxtint() { return Integer.parseInt(nxttok()); }
  long nxtlong() { return Long.parseLong(nxttok()); }

  Set<Long> w = new TreeSet<Long>();
  Set<Long> s = new TreeSet<Long>();

  Long[] sa;
  long a, b, c, d, e, f;

  boolean ok(long s, long w) {
    long tt = s + w;
    if (tt > f) return false;
    //if (s / w > e / 100) return false;
    if (s * 100 > w * e) return false;
    return true;
  }

  Main() throws IOException {
    a = nxtint(); b = nxtint(); c = nxtint(); d = nxtint(); e = nxtint(); f = nxtint();

    for (int i = 0; i < 30; ++i) {
      for (int g = 0; g < 30; ++g) {
        if ((i * a + g * b) * 100 > f) continue;
        if (i + g == 0) continue;
        w.add((i * a + g * b) * 100);
      }
    }
    for (int i = 0; i <= 3000; ++i) 
      for (int g = 0; g < 3000; ++g) {
        if (i * c + g * d > f) continue;
        s.add((i * c + g * d));
      }
    sa = new Long[s.size()];
    s.toArray(sa);
    long ans1 = 0, ans2 = 100 * a;
    for (long tw : w) {
      int l = 0, r = sa.length - 1;
      while (l < r) {
        int mid = l + (r - l + 1) / 2;
        long ts = sa[mid];
        if (ok(ts, tw)) l = mid;
        else r = mid - 1;
      }
      long ts = sa[l];
      if (!ok(ts, tw)) continue;
      //if (ts / (ts + tw) > ans1 / ans2) continue;
      if (ts * ans2 > (ts + tw) * ans1) {
        ans1 = ts;
        ans2 = ts + tw;
      }
    }
    bw.write(ans2 + " " + ans1);
  }
}


Measured memory_bytes: 29416
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>(), k = get<int>();

    long ans = 0;
    ans += pow(n/k,3); // mod 0
    if (k % 2 == 0)
        ans += pow(n/(k/2) - n/k, 3); // mod (k/2)

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	public void run() {
		int n = in.nextInt(), m = in.nextInt();
		int[] array = new int[n+1];
		
		for (int i = 0; i < m; i++) {
			int c = in.nextInt(), d = in.nextInt();
			for (int j = c; j < d; j++) {
				array[j] = 1;
			}
		}
		
		int cnt = 0;
		for (int i = 0; i < n; i++)
			if (array[i] == 1) cnt++;
		
		System.out.println(cnt * 2 + n + 1);
		
		out.close();
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Measured memory_bytes: 20156
//************************
//*  Date: 2018.9.28     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int n,a,b;
	cin>>n;
	if(n==1) puts("Hello World");
	else
	{
		cin>>a>>b;
		cout<<a+b<<endl;
	 } 
	rt0;
}

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



/*以下便利なマクロを定義する。*/

#define refor(i, min, max) for(i=min; i<=max; i=i+1)



#define if_forall(i, min, max, prop)\
	bool if_forall_condition=1;\
\
	for(i=min; i<=max; i=i+1)\
	{\
		if(!(prop))\
		{\
			if_forall_condition=0;\
			break;\
		}\
	}\
\
	if(if_forall_condition==1)\



#define if_exists(i, min, max, prop)\
	bool if_exists_condition=0;\
\
	for(i=min; i<=max; i=i+1)\
	{\
		if(prop)\
		{\
			if_exists_condition=1;\
			break;\
		}\
	}\
\
	if(if_exists_condition==1)\











/*以下便利な関数を定義する。*/



void ini_int(int a[], int num)
{
	int i=0;

	for(i=0; i<=num; i=i+1)
	{
		a[i]=0;
	}

}



void ini_char(char array[], int num)
{
	int i=0;

	for(i=0; i<=num; i=i+1)
	{
		array[i]='\0';
	}

}



int powi(int base, unsigned int exponent)
{
	int answer=1;

	answer=(int)pow((double)base, (double)exponent);

	return answer;
}



void sort_asc_int(int a[], int min, int max)
{
	int i, j;
	int dumy;

	for(i=min; i<=max; i=i+1)
	{
		for(j=i+1; j<=max; j=j+1)
		{
			if(a[i]>a[j])
			{
				dumy=a[i];
				a[i]=a[j];
				a[j]=dumy;
			}
		}
	}
}



void sort_des_int(int a[], int min, int max)
{
	int i, j;
	int dumy;

	for(i=min; i<=max; i=i+1)
	{
		for(j=i+1; j<=max; j=j+1)
		{
			if(a[i]<a[j])
			{
				dumy=a[i];
				a[i]=a[j];
				a[j]=dumy;
			}
		}
	}
}



int max(int a, int b)
{
	int answer=a;
	if(a<b)
	{
		answer=b;
	}

	return answer;
}



int min(int a, int b)
{
	int answer=a;
	if(a>b)
	{
		answer=b;
	}

	return answer;
}



int max_int(int a[], int min, int max)
{
	int i;
	int answer;

	answer=a[min];

	for(i=min+1; i<=max; i=i+1)
	{
		if(answer<a[i])
		{
			answer=a[i];
		}
	}

	return answer;
}



int min_int(int a[], int min, int max)
{
	int i;
	int answer;

	answer=a[min];

	for(i=min+1; i<=max; i=i+1)
	{
		if(answer>a[i])
		{
			answer=a[i];
		}
	}

	return answer;
}



bool containelement_int(int array[], int min, int max, int element)
{
	int i;
	bool answer=0;

	if_exists(i, min, max, array[i]==element)
	{
		answer=1;
	}

	return answer;
}



int count_differentelement_int(int array[], int min, int max)
{
	int i=min;
	int pickup[max];
	ini_int(pickup, max);
	int answer=0;

	for(i=min; i<=max; i=i+1)
	{
		if(containelement_int(pickup, 0, answer-1, array[i])==0)
		{
			pickup[answer]=array[i];
			answer=answer+1;
		}
	}

	return answer;
}



int count_equalelement_int(int array[], int min, int max, int element)
{
	int i;
	int answer=0;

	for(i=min; i<=max; i=i+1)
	{
		if(array[i]==element)
		{
			answer=answer+1;
		}
	}

	return answer;
}











int main()
{

	int a, b, h;
	scanf("%d %d %d", &a, &b, &h);
	printf("%d\n", (a+b)*(h/2));
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

    static int NOT_FOUND = 99999999;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] sArr = new int[n + 1];
        for (int i = 0; i < n; i++) {
            sArr[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] tArr = new int[q + 1];
        int count = 0;
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            tArr[i] = x;
            if (linearSearch(n, sArr, x) != NOT_FOUND) count++;
        }
        System.out.println(count);
    }

    public static int linearSearch(int n, int[] arr, int key) {
        int i = 0;
        arr[n] = key;
        while (arr[i] != key) {
            i++;
        }
        if (i == n) {
            return NOT_FOUND;
        }
        return i;
    }
}



Measured memory_bytes: 39808
N = gets.to_i
Hn = gets.split.map(&:to_i)
res = 'Yes'
prev = -999

N.times do |i|
  hi = Hn[i]
  next prev = hi - 1 if prev <= hi - 1
  next prev = hi if prev <= hi

  res = 'No'
end

puts res

Measured memory_bytes: 11012
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
        q: usize,
        bc: [(i64, i64); q],
    }

    let mut r = 0;
    let mut h = HashMap::new();
    for aj in a {
        *h.entry(aj).or_insert(0) += 1;
        r += aj;
    }

    for i in 0..q {
        let (b, c) = bc[i];
        let hbv = {
            let hb = h.entry(b).or_insert(0);
            let hbv = *hb;
            *hb = 0;
            hbv
        };
        let hc = h.entry(c).or_insert(0);
        *hc += hbv;

        r += hbv * (c - b);
        println!("{}", r);
    }
}


Measured memory_bytes: 9552
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = np.array(a)
a.sort()
p = a[a>0]
z = a[a==0]
m = a[a<0]
low = -10**18
high = 10**18
while high-low>1:
    mid = (high + low) //2
    count = 0
    if mid >= 0:
        count += len(z)*n
    count += a.searchsorted(mid//p,side = "right").sum()
    count += (n-a.searchsorted(-(-mid//m),side = "left")).sum()
    count -= np.count_nonzero(a*a <= mid)
    count /= 2
    if count >= k:
        high = mid
    if count < k:
        low = mid
print(high)


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

int main(){
    long long N;
    long long buf;
    cin >>N;
    vector<long long> aaa = vector<long long>(N+1, 0);
    for(int i = 1; i< N+1; i++){
        cin >> buf;
        aaa.at(i) = buf + aaa.at(i-1);
    }
    bool be = true;
    bool af;
    vector<long long> ans = vector<long long>(2, 0);
    // long long ans = 0;
    long long change = 0;
    for(int l = 0; l < 2; l++){
        vector<long long> aa = aaa;
        if(l == 0){
            be = true;
        }else{
            be = false;
        }
        change = 0;
        for(int i = 1; i<N+1; i++){
            if(ans.at(1) > ans.at(0)){
                break;
            }
            aa.at(i) += change;
            
            if(aa.at(i) == 0){

                if(be){
                    //負を生に
                    change += 1-aa.at(i);
                    ans.at(l) += 1-aa.at(i);
                    // for(int j=i; j<N+1; j++){
                    //     aa.at(j) += change;
                    // }
                    be = false;
                }else{
                    //セイヲフニ
                    change += -(aa.at(i) + 1);
                    ans.at(l) += 1 + aa.at(i);
                    // for(int j=i; j<N+1; j++){
                    //     aa.at(j) += change;
                    // }
                    be = true;
                }
            }else{
                if (aa.at(i) < 0)
                {
                    af = true;
                }
                else
                {
                    af = false;
                }
                if (af == be)
                {
                    if (af)
                    {
                        // printf("1 %d\n", i);
                        //負を生に
                        change += 1 - aa.at(i);
                        ans.at(l) += 1 - aa.at(i);
                        // for (int j = i; j < N + 1; j++)
                        // {
                        //     aa.at(j) += change;
                        // }
                        be = false;
                    }
                    else
                    {
                        // printf("2 %d\n", i);
                        //セイヲフニ
                        change += -(aa.at(i) + 1);
                        ans.at(l) += 1 + aa.at(i);
                        // for (int j = i; j < N + 1; j++)
                        // {
                        //     aa.at(j) += change;
                        // }
                        be = true;
                    }
                }
                else
                {
                    // printf("3 %d\n", i);
                    be = af;
                }
            }
            
        }
        // for(int i = 1; i<=N; i++){
        //     cout << aa.at(i) << " ";
        // }
        // cout << endl;

    }




    long long tt = min(ans.at(0), ans.at(1));

    std::cout << tt << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=100;
int N;
ll x,a[MAX_N];
int main(){
	cin>>N>>x;
	REP(i,N){
		cin>>a[i];
	}
	sort(a,a+N);
	int ans=0;
	ll sm=0;
	REP(i,N){
		if (sm+a[i]<=x){
			sm+=a[i];
			ans++;
		}else{
			break;
		}
	}
	if (ans==N){
		if (sm!=x){
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
tree=[[] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  tree[a-1].append((b-1,c))
  tree[b-1].append((a-1,c))
from collections import deque
visited=[-1 for i in range(N)]
Q,K=map(int,input().split())
visited[K-1]=0
q=deque([])
q.append(K-1)
while q:
  u=q.popleft()
  for v,d in tree[u]:
    if visited[v]==-1:
      visited[v]=visited[u]+d
      q.append(v)
    
for i in range(Q):
  x,y=map(int,input().split())
  print(visited[x-1]+visited[y-1])

Measured memory_bytes: 103100
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		ArrayList<String> lines = new ArrayList<String>();
		int in = 0;

		while (true) {
			String string = sc.nextLine();

			if (string.equals("-1 -1 -1")) {
				break;
			}
			lines.add(string);
			in++;
		}

		int[] gr = new int[3];

		for (int i = 0; i < in; i++) {
			String[] kari = lines.get(i).split(" ");

			for (int j = 0; j < 3; j++) {
				gr[j] = Integer.parseInt(kari[j]);
			}

			if (gr[0] == -1 || gr[1] == -1) {
				System.out.println("F");
			} else if (gr[0] + gr[1] >= 80) {
				System.out.println("A");
			} else if (gr[0] + gr[1] >= 65) {
				System.out.println("B");
			} else if (gr[0] + gr[1] >= 50
					|| (gr[0] + gr[1] >= 30 && gr[2] >= 50)) {
				System.out.println("C");
			} else if (gr[0] + gr[1] >= 30) {
				System.out.println("D");
			} else {
				System.out.println("F");
			}
		}
	}

}

Measured memory_bytes: 26076
#include <algorithm>
#include <iostream>

int main() {
  int a, b, c, d, e, f;
  std::cin >> a >> b >> c >> d >> e >> f;
  std::cout << a + b + c + d - std::min({a, b, c, d}) + std::max(e, f) << std::endl; 
}



Measured memory_bytes: 3092
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,k,n,sum,temp;
void solve()
{
    cin>>n>>k;vector<ll>ar(n),arr(n-1);
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    sort(ar.begin(),ar.end());
    for(int i=0;i<n-1;i++)
        arr[i]=ar[i+1]-ar[i];
    k--;
    for(int i=0;i<k;i++)
    {
        temp+=arr[i];
    }
    ans=temp;
    for(int i=k;i<n-1;i++)
    {
        temp+=arr[i];temp-=arr[i-k];
        //cout<<temp<<endl;
        ans=min(temp,ans);
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)
 
using namespace std;
 
inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
// inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
// inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}
 
// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle
      //freopen("in.txt", "r", stdin);
    //#endif

    int sx=rr,sy=rr,tx=rr,ty=rr;

    int lim=ty-sy;
    loop(i,lim)putchar('U');
    lim=tx-sx;
    loop(i,lim)putchar('R');

    lim=ty-sy;
    loop(i,lim)putchar('D');
    lim=tx-sx;
    loop(i,lim)putchar('L');
    
    putchar('L');
    lim=ty-sy+1;
    loop(i,lim)putchar('U');
    lim=tx-sx+1;
    loop(i,lim)putchar('R');
    putchar('D');

    putchar('R');
    lim=ty-sy+1;
    loop(i,lim)putchar('D');
    lim=tx-sx+1;
    loop(i,lim)putchar('L');
    putchar('U');

    putchar('\n');

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int a;
	int b;
	scanf("%d %d",&a,&b);
	if(a<=b){
		printf("%d",a);
	}
	else{
		printf("%d",a-1);
	}
	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 REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    ll a[3010];
    cin >> n;
    rep(i,n) cin >> a[i];

    ll ans=0;
    rep(i,n) ans += a[i];
    ans -=n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<iomanip>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n, t, l, b;
  while(cin >> n >> t >> l >> b && n){
    vector<vector<double> > f(n+1, vector<double>(2, 0));
    vector<bool> lose(n+1, false);
    vector<bool> back(n+1, false);
    for(int i = 0; i < l; i++){
      int a; cin >> a;
      lose[a] = true;
    }
    for(int i = 0; i < b; i++){
      int b; cin >> b;
      back[b] = true;
    }
    f[0][1] = 1.0;
    for(int i = 0; i < t; i++){
      vector<vector<double>> tmp(n+1, vector<double>(2, 0));
      for(int j = 0; j < n; j++){
        for(int k = 1; k <= 6; k++){
          int nx;
          if(j + k > n){
            nx = n - (j+k - n);
          }
          else{
            nx = j+k;
          }
          if(back[nx]) nx = 0;
          if(lose[nx]){
            tmp[nx][0] += f[j][1] / 6.0;
          }
          else{
            tmp[nx][1] += f[j][1] / 6.0;
          }
        }
        tmp[j][1] += f[j][0];
      }
      tmp[n][1] += f[n][1];
      f = tmp;
    }
    cout << fixed << setprecision(6) << f[n][1] << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



Measured memory_bytes: 3304