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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
  ll H,W,M;
  cin >> H >> W >> M;
  vector<ll> h;
  vector<ll> w;
  vector<ll> Wid(W,0);
  vector<ll> Hei(H,0);
    ll hmax = 0,wmax = 0;
  ll c1 = 0,c2 = 0;
  froop1(0,M){
   ll a,b;
    cin >> a >> b;
    h.push_back(a);
    w.push_back(b);
    Wid.at(b - 1)++;
    Hei.at(a - 1)++;
        if(hmax < Hei.at(a - 1)){
          hmax = Hei.at(a - 1);
          c1 = 1;
        }else if(hmax == Hei.at(a - 1)){
          c1++;
        }
        if(wmax < Wid.at(b - 1)){
          wmax = Wid.at(b - 1);
          c2 = 1;
        }else if(wmax == Wid.at(b - 1)){
          c2++;
        }
  }
  ll pat = c1*c2;
  int sw = 0;
  for(int i = 0;i < M;i++){
    ll n = h.at(i) - 1;
    ll m = w.at(i) - 1;
    if(Wid.at(m) == wmax && Hei.at(n) == hmax) pat--;
  }
  if(pat == 0){
  cout << hmax + wmax - 1 << endl;
  }else{
    cout << hmax + wmax << endl;
  }
}



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

int main(){
	int n;
	cin >> n;

	int c[n], v[n];

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

	int cost=0;

	for(int i=0; i<n; i++){
		if(v[i] > c[i]){
			cost += v[i] - c[i];
		}
	}

	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,c,d;
    d = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(int x = a;x <= b;x++){
        if(c%x==0){
            d ++;
        }else{
        }
    }
    printf("%d\n",d);
    return 0;
}



Measured memory_bytes: 2100
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

void coutv(vector<ll> v)
{
	for (auto it : v)
		cout << it << " ";
	cout << "\n";
}

ll LCM(ll a, ll b)
{
	return (a * b) / __gcd(a, b);
}

bool is_prime(ll n)
{
	for (int i = 2; i <= n / i; i++)
		if (n % i == 0)
			return false;
	return true;
}
ll count_substring_in_string(string str, string substr)
{
	ll cnt = 0;
	ll pos = 0;
	while ((pos = str.find(substr, pos)) != string::npos)
	{
		cnt++;
		pos += substr.size();
	}
	return cnt;
}
int main()
{
	ll ans = 0;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < max(s.size(), t.size()); i++)
	{
		if (s[i] == t[i])
			continue;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int _=1;
    //cin>>_;
    while(_--)
    {
        ll n;
        cin>>n;
        ll s=0;
        s+=n/500;
        s*=1000;
        n%=500;
        ll r=n/5;
        s+=r*5;
        cout<<s;
    }
    return 0;
}

Measured memory_bytes: 256
# ABC145b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    n = int(input())
    s = input()[:-1]
    print('Yes' if s[:n//2] == s[n//2:] else 'No')


if __name__ == '__main__':
    main()

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

maxI = (N // 4)+1 
maxJ = (N // 7)+1

flag = False
for i in range(maxI):
    for j in range(maxJ):
        total = 4*i + 7*j
        if total == N:
            flag = True
            break
if flag:
    print("Yes")
else:
    print("No")

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

const int MAX_N=100000;
bool prime[MAX_N+1];
int m,p,q;
double dab,dpq;

void sieve()
{
  prime[0]=prime[1]=false;
  for(int i=2;i<=MAX_N;++i)
    prime[i]=true;
  for(int i=2;i<=MAX_N;++i)
    if(prime[i])
      for(int j=i*2;j<=MAX_N;j+=i)
	prime[j]=false;
}

void product()
{
  int upper=0;
  for(int i=0;i<=sqrt(m);i++)
    if(prime[i])
      for(int j=i;j<=m/3;j++){
	if(prime[j]){
	  dpq=(double)i/j;
	  if(upper<=i*j&&i*j<=m&&dpq>=dab){
	    p=i; q=j; upper=p*q;
	  }
	}
      }
}

int main()
{
  int a,b;

  sieve();
  for(;;){
    cin>>m>>a>>b;
    if(!(m|a|b)) break;
    dab=(double)a/b;
    product();
    cout<<p<<" "<<q<<endl;
  }
}


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

    char chess(int h,int w){
    if((h+w)%2 == 0){
        return '#';
        }
    return '.';
    }

    int main(void){
        int H,W;
        cin >> H >> W;
    while(H != 0 && W != 0){
        for(int j = 0; j < H; j++){
            for(int i = 0; i < W; i++){
                cout << chess(i,j);
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  string s;
  cin >> s;
  set<char> se;
  for(int i=0;i<s.size();i++) se.insert(s[i]);
  if(se.size() == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm> 
using namespace std;


long long N,M,K,ans;


int main(){
	cin >> N;
	ans = 0;
	vector<long long> a;
	for (int i = 0; i < N; i++) {
		cin >> M;
		a.push_back(M);
		ans += M;
	}
	sort(a.begin(), a.end());
	if (ans % 10 != 0) {
		cout << ans << endl;
		return 0;
	}
	for (int i = 0; i < a.size(); i++) {
		if (a[i] % 10 == 0)continue;
		cout << ans - a[i] << endl;
		return 0;
	}
	cout << 0 << endl;
	return 0;
}

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

if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(N-99 + 9)
elif N < 10000:
    print(909)
elif N < 100000:
    print(N-9999 + 909)
else:
    print(90909)

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

using namespace std;
#define lint long long
#define P pair<int, int>

int main() {
    string S;
    cin >> S;

    for(int i = 0; i < S.length() - 1; ++i){
        if(S[i] == 'A' && S[i + 1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
def main() :
	S = input()

	remove_len = len(S)  - 7

	for i in range(len(S) - remove_len) :
		# s = S[i:i+7]
		s = S[0:i] + S[i+remove_len:]
		if (s == "keyence") :
			print("YES")
			return

	print("NO")


main()

Measured memory_bytes: 2940
a = raw_input().split()
W = int(a[0])
H = int(a[1])
x = int(a[2])
y = int(a[3])
r = int(a[4]) 

if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H :
	print "Yes"
else :
	print "No"

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

int main(){
  int r,D,x2000; cin >> r >> D >> x2000;
  
  int ans = r * x2000 - D;
  cout << ans << endl;
  for(int i = 0; i < 9; i++){
      ans = r*(ans) - D;
      cout << ans << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<cstdlib>
    using namespace std;
    typedef long long ll;
     
    const ll INF = 0x3f3f3f3f3f3f3f3f;
    const int MAXN = 55;
    const int MAXM = 205;
     
    int n,m,S,len;
    int head[MAXN],in[MAXN][MAXN * MAXN];
    ll dis[MAXN][MAXN * MAXN],c[MAXN],d[MAXN];
    queue<pair<int,ll> > q;
     
    struct Edge{
    	int to,next;
    	ll a,b;
    } e[MAXM];
     
    void add(int u,int v,ll a,ll b){
    	e[++len].to = v;
    	e[len].next = head[u];
    	e[len].a = a;
    	e[len].b = b;
    	head[u] = len;
    }
     
    void spfa(){
    	for(int i = 1;i <= n;i++){
    		for(int j = 0;j <= 2500;j++)
    			dis[i][j] = INF;
    	}
    	dis[1][S] = 0;
    	q.push(make_pair(1,S));
    	while(!q.empty()){
    		int u = q.front().first;
    		ll w = q.front().second;
    		q.pop();
    		in[u][w] = 0;
    		for(int i = head[u];i != -1;i = e[i].next){
    			int v = e[i].to;
    			ll a = e[i].a,b = e[i].b;
    			if(w >= a && dis[v][w - a] > dis[u][w] + b){
    				dis[v][w - a] = dis[u][w] + b;
    				if(!in[v][w - a])
    					q.push(make_pair(v,w - a));
    			}
    		}
    		int t = min(w + c[u],2500ll);
    		if(dis[u][t] > dis[u][w] + d[u]){
    			dis[u][t] = dis[u][w] + d[u];
    			if(!in[u][t])
    				q.push(make_pair(u,t));
    		}
    	}
    }
     
    int main(){
    	//freopen(".in","r",stdin);
    	//freopen(".out","w",stdout);
    	memset(head,-1,sizeof(head));
    	scanf("%d%d%d",&n,&m,&S);
    	S = min(S,2500);
    	for(int i = 1;i <= m;i++){
    		int u,v;
    		ll a,b;
    		scanf("%d%d%lld%lld",&u,&v,&a,&b);
    		add(u,v,a,b);
    		add(v,u,a,b);
    	}
    	for(int i = 1;i <= n;i++)
    		scanf("%lld%lld",&c[i],&d[i]);
    	spfa();
    	for(int i = 2;i <= n;i++){
    		ll res = INF;
    		for(int j = 0;j <= 2500;j++)
    			res = min(res,dis[i][j]);
    		printf("%lld\n",res);
    	}
    	return 0;
    }
     

Measured memory_bytes: 6132
n =int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            v = i*i+j*j+k*k+i*j+j*k+k*i
            if v<10050:
                ans[v]+=1

for i in range(n):
    print(ans[i+1])

Measured memory_bytes: 9148
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
   int n;
   string s;
   cin >> n >> s;
   int cntr=0;
   int cntb=0;
   rep(i,n){
       if(s.at(i)=='R')cntr++;
       else if(s.at(i)=='B')cntb++;
   }
   if(cntr>cntb)cout << "Yes" << endl;
   else cout << "No" << endl;

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int h,n;
    cin >>h>>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];
    int sum =0;
    rep(i,n) sum +=a[i];
    if (sum>=h)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
const int MAX = 1000000;
const int MOD = 1000000007;

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> p(n);
	REP(i,n){
		cin>>p[i];
	}
	int sum=0;
	
	REP(i,k){
		sum+=p[i];
	}
	int ma=sum;
	for(int i=k;i<n;i++){
		sum+=p[i]-p[i-k];
		ma=max(ma,sum);
	}
	double ans=0;
	ans=(double)ma/2+(double)k/2;
	printf("%.7lf\n",ans);
	return 0;
}

Measured memory_bytes: 1024
function Main(s){
  s = s.split("\n").map(a=>+a);
  var n = s[0];
  if(s[1] !== 0){console.log(-1);return;}
  var ans = 0;
  for(var i = n; i > 1; i--){
    if(s[i] >= i){console.log(-1);return;}
    if(s[i] === s[i-1] + 1){
      ans++;
    }else{
      if(s[i] >= s[i-1] + 2){console.log(-1);return;}
      ans += s[i];
    }
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 34108
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f; 
typedef long long ll;
ll n,m,x;
struct st{
	ll val;
	ll sk[20];
}a[20];
ll ans=1e18;
void dfs(ll bfx,st now){
	ll i,j;
	for(i=1;i<=m;i++){
		if(now.sk[i]<x)break;
	}
	if(i==m+1){
		ans=min(ans,now.val);
		return;
	}
	st nxt;
	for(i=bfx+1;i<=n;i++){
		nxt.val=now.val+a[i].val;
		for(j=1;j<=m;j++){
			nxt.sk[j]=now.sk[j]+a[i].sk[j];
		}
		dfs(i,nxt);
	}
}
int main(){
	ll i,j;
	scanf("%lld%lld%lld",&n,&m,&x);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i].val);
		for(j=1;j<=m;j++){
			scanf("%lld",&a[i].sk[j]);
		}
	}
	for(i=1;i<=n;i++){
		st now;
		for(j=1;j<=m;j++){
			now.sk[j]=a[i].sk[j];
		}
		now.val=a[i].val;
		dfs(i,now);
	}
	if(ans==1e18)printf("-1");
	else printf("%lld",ans);
    return 0;
}
 

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

int main() {
  int n, c = 0;
  cin >> n;
  for (int i = 0; i < n; i ++) {
    int l, r;
    cin >> l >> r;
    c += r - l + 1;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

string query(int x) {
    cout << x << endl;
    string res;
    cin >> res;
    if (res == "Vacant") exit(0);
    return res;
}

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

    int n;
    cin >> n;
    int l = 0;
    int r = n-1;
    string x = query(0);
    string y = query(n-1);
    while (true) {
        int mid = (l + r) >> 1;
        string z = query(mid);
        if ((z == x) != (l % 2 == mid % 2)) {
            r = mid;
            y = z;
        } else {
            l = mid;
            x = z;
        }
    }
}


Measured memory_bytes: 3832
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


alphabet = [chr(i+97) for i in range(26)]
dS,dT = {},{}
for s in alphabet:
    dS[s] = []
    dT[s] = []

S,T = LS2(),LS2()
N = len(S)
for i in range(N):
    dS[S[i]].append(i)
    dT[T[i]].append(i)

count_S,count_T = [0]*N,[0]*N  # Si,Ti と同じ文字が何回現れるか
for i in range(N):
    count_S[i] = len(dS[S[i]])
    count_T[i] = len(dT[T[i]])

print('Yes' if count_S == count_T else 'No')


Measured memory_bytes: 107620
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int v;
  char m;
}C;

C in[36],b[36],s[36];

void bubblesort(int);
void selectionsort(int);
int isstable(C*,int);

int main(){
  int n,i;
  char temp[4];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%s",temp);
    in[i].m = b[i].m = s[i].m = temp[0];
    in[i].v = b[i].v = s[i].v = atoi(temp+1);
  }

  bubblesort(n);
  selectionsort(n);

  for(i = 0; i < n; i++){
    printf("%c%d",b[i].m,b[i].v);
    if(i != n-1) printf(" ");
  }
  printf("\n");
  if(isstable(b,n) == 1) printf("Stable\n");
  else printf("Not stable\n");

  for(i = 0; i < n; i++){
    printf("%c%d",s[i].m,s[i].v);
    if(i != n-1) printf(" ");
  }
  printf("\n");
  if(isstable(s,n) == 1) printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;

}

void  bubblesort(int n){
  int i,j;
  C temp;

  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(b[j].v < b[j-1].v){
	temp = b[j];
	b[j] = b[j-1];
	b[j-1] = temp;
      }
    }
  }
}

void selectionsort(int n){
  int i,j,minj;
  C temp;
  
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(s[j].v < s[minj].v)
	minj = j;
    }
    temp = s[i];
    s[i] = s[minj];
    s[minj] = temp;
  }
}

int isstable(C *out,int n){
  int i,j,a,b;

  for(i = 0; i < n; i++){
    for(j = i+1; j < n; j++){
      for(a = 0; a < n; a++){
	for(b = a+1; b < n-1; b++)
	  if(in[i].v == in[j].v){
	    if(in[i].v == out[b].v && in[i].m == out[b].m &&
	       in[j].v == out[a].v && in[j].m == out[a].m)
	      return 0;
	  }
      }
    }
  }
  return 1;
}



Measured memory_bytes: 2092
N,A,B,C=map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

#n本目の竹をどう扱うかを考える

def dfs(n,a,b,c):
  if n == N:
    if min(a,b,c) > 0:
      return abs(a-A)+abs(b-B)+abs(c-C) - 30
    else:
      return INF

  rate_add_Not = dfs(n+1,a,b,c)
  rate_add_A   = dfs(n+1,a+l[n],b,c) + 10
  rate_add_B   = dfs(n+1,a,b+l[n],c) + 10
  rate_add_C   = dfs(n+1,a,b,c+l[n]) + 10
  return min(rate_add_Not,rate_add_A,rate_add_B,rate_add_C)

print(dfs(0,0,0,0))


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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  rep(i,n-2){
    if(s[i]=='A' &&s[i+1]=='B'&&s[i+2]=='C')ans++;
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
import java.util.*;

import javax.naming.BinaryRefAddr;

import static java.lang.System.*;

class Main {
    public static Scanner sc = new Scanner(in);
    public static Random rand=new Random();



    public void run() {
    	List<Integer> pollock=new ArrayList<Integer>();

    	for(int i=1;i*(i+1)*(i+2)/6<1000000;i++){
    		pollock.add(i*(i+1)*(i+2)/6);
    	}

    	int[] dp=new int[1000000],dp2=new int[1000000];

    	for(int i=1;i<1000000;i++){
    		int min=Integer.MAX_VALUE;
    		for(int j:pollock){
    			if(i-j>=0)min=Math.min(min,dp[i-j]+1);
    		}
    		dp[i]=min;
    	}

    	for(int i=1;i<1000000;i++){
    		int min=Integer.MAX_VALUE;
    		for(int j:pollock){
    			if(i-j>=0 && j%2==1)
    				min=Math.min(min,dp2[i-j]+1);
    		}
    		dp2[i]=min;
    	}


    	while(true){
        	int n=sc.nextInt();
        	if(n==0)return;

        	ln(dp[n]+" "+dp2[n]);
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }

    public int[] nextIntArray(int n){
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            res[i]=sc.nextInt();
        }
        return res;
    }
    public static void pr(Object o) {
        out.print(o);
    }
    public static void ln(Object o) {
        out.println(o);
    }
    public static void ln() {
        out.println();
    }
}

Measured memory_bytes: 66340
#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;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
#define ll long long
ll mod = 1000000000+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    ll T;
    T=1;
    //cin>>T;
    start:
    while(T--)
    {
       ll a;
       cin>>a;
       cout<<a+a*a+a*a*a<<endl;
        
    }
    return 0;
}



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

int main(){
  int n,max=0,cnt=0;
  bool flag = true;
  cin>>n;
  vector<int>v(n);
  for(int i = 0; i < n; i++){
    cin>>v[i];
    if(v[i]>max)
      max = v[i];
  }
  
  while(max>0){
    for(int j = 0; j < n; j++){
      
      if(v[j]!=0){        
        if(flag==true){
          flag = false;
          cnt++;
        }
        v[j]--;
      }
      
      else if(v[j]==0)
        flag = true;
      
      if(j==n-1){
        flag = true;
        max--;
      }
    }
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
INF = int(1e4)
def countingSort(A, k):
    n = len(A)
    output = [INF for _ in range(n+1)]
    count = [0 for _ in range(k)]
    for i in range(n):
        count[A[i]] += 1

    for i in range(1, k):
        count[i] = count[i] + count[i-1] 

    for i in reversed(range(n)): 
        output[count[A[i]]] = A[i]
        count[A[i]] -= 1

    return output[1:]

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = countingSort(a, INF)
    for i in range(n):
        if i == n-1:
            print(ans[i])
        else:
            print(ans[i], end=' ')
main()


Measured memory_bytes: 224260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1e9;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,K;
    cin >> N >> K;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    ll ret = 0;
    for(int i = 0;i < N - K;i++) {
        ret += vec.at(i);
    }
    cout << ret << endl;
}

Measured memory_bytes: 1792
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $c);

$p1 = abs($b - $a) + abs($c - $b);
$p2 = abs($c - $a) + abs($b - $c);
$p3 = abs($a - $b) + abs($c - $a);
$p4 = abs($c - $b) + abs($a - $c);
$p5 = abs($a - $c) + abs($b - $a);
$p6 = abs($b - $c) + abs($a - $b);

echo min($p1, $p2, $p3, $p4, $p5, $p6) . PHP_EOL;


Measured memory_bytes: 4728
n,k =input().split()
N=int(n)
K=int(k)
H=[int(i) for i in input().split()]
H.sort(reverse=True)
ans=0
if K==0:
    for j in range(N):
        ans = ans + H[j] 
elif N<=K:
    ans ==0
else:
    H = H[K:]
    for l in range(N-K):
       ans = ans + H[l]
print(ans) 

Measured memory_bytes: 25872
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math"
	"math/big"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

func scan(a interface{}) {
	_, _ = fmt.Fscan(reader, a)
}

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func AbsInt64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func MinInt64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func MaxInt64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer writer.Flush()

	n := NextInt()
	W := NextInt64()

	dp := make([]int64, 100001)

	for i := range dp {
		dp[i] = math.MaxInt64 / 2
	}
	dp[0] = 0
	
	for i := 0; i < n; i++ {
		w := NextInt64()
		v := NextInt()

		for j := 100000; j >= v; j-- {
			dp[j] = MinInt64(dp[j], dp[j - v] + w)
		}
	}

	answer := int64(0)
	for i := 0; i <= 100000; i++ {
		if dp[i] <= W {
			answer = MaxInt64(answer, int64(i))
		}
	}
	println(answer)
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N;

//再帰DFSで全列挙
void dfs(string s, char mx) {
  if (s.length() == N) {
    cout << s << endl;
    return;
  }
  for (char c = 'a'; c <= mx+1; c++) {
    string res = s + c;
    dfs(res, max(mx, c));
  }
}

int main() {
  cin >> N;
  dfs("", 'a'-1);
  return 0;
}


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

int main()
{
    double taka_hp, taka_attack, ao_hp, ao_attack;
    cin >> taka_hp >> taka_attack >> ao_hp >> ao_attack;
    int n_taka_die = ceil(taka_hp / ao_attack);
    int n_ao_die = ceil(ao_hp / taka_attack);
    if(n_ao_die > n_taka_die) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3708
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase
#include <ctime>    // clock

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int A[n+1];
    for(int i=0; i<n+1; i++) cin >> A[i];
    long long Ruiseki = 0;
    for(int i=0; i<n+1; i++) Ruiseki += A[i];
    long long ans = 1;
    long long node = 1;
    bool ok = true;
    if(n!= 0 && A[0] != 0) ok = false;
    if (n == 0){
		if (A[0] == 1)
			cout << 1 << endl;
		else
			cout << -1 << endl;
		return 0;
	}
    for(int i=1; i<n+1; i++)
    {
        if(Ruiseki >= node*2)
        {
            node *= 2;
            ans += node;
        }
        else
        {
            node = Ruiseki;
            ans += node;
        }
        node -= A[i];
        Ruiseki -= A[i];
        if(node < 0) ok = false;
        if(i<n && node==0) ok = false;
    }
    if(ok) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 4008
#include <iostream>

using namespace std;

enum {A, X, Y, Z, W, B, NOT};

int main()
{
    string inp;
    int map[6][2];

    map[A][0] =  X;
    map[A][1] =  Y;
    map[X][0] =  NOT;
    map[X][1] =  Z;
    map[Y][0] =  X;
    map[Y][1] =  NOT;
    map[Z][0] =  W;
    map[Z][1] =  B;
    map[W][0] =  B;
    map[W][1] =  Y;
    map[B][0] =  Y;
    map[B][1] =  X;

    while (cin >> inp, inp != "#") {
        int nxt = A;
        bool flag = true;

        for (int i = 0; i < inp.size(); i++) {
            nxt = map[nxt][inp[i] - '0'];

            if (nxt == NOT) {
                flag = false;
                break;
            }
        }
        if (nxt == B && flag)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1180
if __name__ == "__main__":
    N, M = [int(i) for  i in input().split()]
    shops = []
    for i in range(N):
        shops.append([int(i) for i in input().split()])
    shops = sorted(shops)
    result = 0
    for price, stock in shops:
        if stock >= M:
            result += price * M
            break
        elif stock < M:
            result += price * stock
            M -= stock
    print(result)

Measured memory_bytes: 22376
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int x[5];
  rep(i,5){
    cin>>x[i];
  }
  rep(i,5){
    if(x[i] == 0){
      cout<<i+1<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) (a).begin(), (a).end()
#define pw(x) (1ll<<(x))
#define lb(x) ((x) & -(x))
#define endl "\n"
#define FI(x) freopen(#x".in","r",stdin)
#define FO(x) freopen(#x".out","w",stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
//typedef uniform_int_distribution<ll> RR;
const int P = 1e9 + 7;
//ll rnd(ll l, ll r) { mt19937 gen(rand()); RR dis(l, r); return dis(gen); }
int add(int a, int b) {if((a += b) >= P) a -= P; return a < 0 ? a + P : a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----

const int N = 1e5 + 7;
int n, t, d[10], now, a[3][N], b[10], w[N];
vi c[10];

void upd(int p) {
	for (; p <= n; p += lb(p)) w[p] ^= 1;
}

int qry(int p) {
	int r = 0;
	for (; p; p -= lb(p)) r ^= w[p];
	return r;
}

int main() {
	//FI(a);
	ios::sync_with_stdio(0);
	cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n; 
	rep(j, 0, 3) rep(i, 1, n+1) cin >> a[j][i];
	rep(i, 1, n+1) {
		rep(j, 0, 3) b[j] = a[j][i];
		sort(b, b+3);
		if (a[1][i] != b[1] || b[2] - b[0] != 2 || b[0] % 3 != 1 || ((i & 1) != ((b[2] / 3) & 1))) {
			cout << "No";
			return 0;
		}
		c[i & 1].pb(b[2] / 3);
		d[i & 1] ^= a[0][i] > a[1][i];
	}
	rep(j, 0, 2) {
		rep(i, 0, n+1) w[i] = 0;
		per(i, 0, sz(c[j])) {
			//rep(k, i+1, sz(c[j])) if (c[j][i] > c[j][k]) d[j ^ 1] ^= 1; 
			d[j ^ 1] ^= qry(c[j][i]);
			upd(c[j][i]);
		}
	}
	if (d[0] == 0 && d[1] == 0) {
		cout << "Yes";
	}else cout << "No";
	return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;

  int temp;
  temp = A + B;

  if (temp % 2) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << temp / 2 << endl;
  }
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int k;
    cin >> k;
    for(int i=0;i<n;i++){
        if(s[i]!=s[k-1])s[i]='*';
    }
    cout << s << endl;
}

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


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli ok[100001] = {};

int main(void) {

	lli N, M;
	cin >> N >> M;

	for (lli i = 0; i < M; i++) {
		lli L, R;
		cin >> L >> R;

		ok[L - 1]++;
		ok[R]--;
	}

	lli ans = 0;

	FOR(N) {
		ok[i + 1] += ok[i];
		if (ok[i] == M)
			ans++;
	}

	COUT(ans);

	return 0;
}

Measured memory_bytes: 1152
S = input()
M = 0
con = 0

L = ["A","C","G","T"]

for i,s in enumerate(S):
  if S[i] in L:
    con += 1
    M = max(M,con)
  elif S[i] not in L:
    con = 0
    M = max(M,con)

print(M)

Measured memory_bytes: 2940
li=input()
n=len(li)
child_li=[0]*n


ruiseki=0
for i in range(n-1):
    if li[i]=='R':
        ruiseki+=1
        if li[i+1]=='L':
            child_li[i+1]=ruiseki//2
            child_li[i]=(ruiseki+1)//2
    else:
        ruiseki=0

        
ruiseki=0
for i in range(n-1, 0, -1):
    if li[i]=='L':
        ruiseki+=1
        if li[i-1]=='R':
            child_li[i-1]+=ruiseki//2
            child_li[i]+=(ruiseki+1)//2
    else:
        ruiseki=0
        
print(*child_li)

Measured memory_bytes: 6400
#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() {
    string n;
    int K;
    cin >> n >> K;

    int l = n.size();
    if(K > l) {
        cout << 0 << endl;
        return 0;
    }
    V(vvi) dp(105, vvi(2, vi(105, 0)));
    dp[0][0][0] = 1;

    rep(i, l) {
        int D = n[i]-'0';
        rep(j, 2) {
            rep(k, 105) {
                for(int d=0; d<=(j ? 9 : D); d++) {
                    if(d==0) dp[i+1][j || (d<D)][k+1] += dp[i][j][k];
                    else dp[i+1][j || (d<D)][k] += dp[i][j][k];
                }
            }
        }
    }

    cout << dp[l][0][l-K] + dp[l][1][l-K] << endl;
    
    return 0;
}

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

int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<int> p(n, 0), q(n);
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        p[i] = x + y;
        q[i] = x - y;
    }
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    cout << abs(max(abs(p[0] - p[n - 1]), abs(q[0] - q[n - 1]))) << '\n';
}

Measured memory_bytes: 6420
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pipii;

void realsolve() {
  ll a, b;
  cin >> a >> b;
  if(a > b) swap(a, b);
  ll prod = a*b;
  ll ret = a-1;
  ll amt = sqrt(a*b);
  ll lhs = a+1;
  while(true) {
    bool upd = false;
    for(int d = 30; d > 0; d--) {
      ll nlhs = lhs + (1 << d);
      ll nrhs = (prod-1) / nlhs;
      if(nrhs > nlhs) {
        upd = true;
        ret += 1 << d;
        lhs = nlhs;
      }
    }
    if(upd) continue;
    ll rhs = (prod-1) / lhs;
    if(rhs <= lhs) {
      ret += rhs;
      break;
    }
    else {
      ret++;
      lhs++;
    }
  }
  cout << ret << "\n";
}

void solve() {
  int n;
  cin >> n;
  while(n--) realsolve();
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
open Batteries
let n = Scanf.scanf "%d" (fun x -> x)
let stats =
  Array.init n (fun _ -> Scanf.scanf " %s" (fun s ->
    let l = String.to_list s in
    Array.init 26 (fun i ->
      let c = char_of_int (i + 97) in
      List.filter ((=) c) l |> List.length
    )))

let () =
  Array.init 26 (fun i ->
    let c = char_of_int (i+97) in
    Array.init n (fun j -> stats.(j).(i))
    |> Array.fold_left min 50
    |> fun z -> Enum.iter (fun v -> Printf.printf "%c" c) (1--z)
  ) |> ignore;
  print_newline ()

Measured memory_bytes: 1408
import math
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    answer = 0
    for i in range(1, N):

        answer += A[math.floor(i / 2)]

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 33044
N, K = map(int, input().split())

if ((N-1) * (N-2)) // 2 < K:
    print(-1)
else:
    ans = [0] * (N-1)
    for i in range(N-1):
        ans[i] = [i+1, N]
    minus = ((N-1) * (N-2)) // 2 - K
    M = N-1
    for i in range(1, N):
        for j in range(i+1, N):
            if minus > 0:
                ans.append([i, j])
                minus -= 1
                M += 1
    print(M)
    for branch in ans:
        print(' '.join(map(str, branch)))


Measured memory_bytes: 42096
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

namespace mod {
ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll inverse(ll x) { return power(x, MOD - 2); }

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

ll multiChoose(int n, int k) {
  if (n == 0 && k == 0) {
    return 1;
  } else {
    return choose(n + k - 1, k);
  }
}
}  // namespace mod

int main() {
  mod::initFact(200000 + 10);
  int H, W, A, B;
  while (cin >> H >> W >> A >> B) {
    ll ans = mod::choose(H - 1 + W - 1, W - 1);
    for (int i = 1; i <= B; i++) {
      ll ng = mod::choose(H - A - 1 + i - 1, i - 1) *
              mod::choose(A - 1 + W - i, W - i) % MOD;
      ans = (ans - ng + MOD) % MOD;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int K = sc.nextInt();
        int S = sc.nextInt();
 
        int cnt = 0;
        for (int x = 0; x <= K; ++x) {
            for (int y = 0; y <= K; ++y) {
                int z = S - x - y;
                if (0 <= z && z <= K) {
                    ++cnt;
                }
            }
        }
        _out.println(cnt);
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  ll R, S, P;
  string T;
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;
  ll ret = 0;
  for (int i=0; i<N; i++) {
    if (i >= K && T[i-K] == T[i]) {
      T[i] = '?';
    } else {
      switch (T[i]) {
        case 'r': ret += P; break;
        case 's': ret += R; break;
        case 'p': ret += S; break;
      }
    }
  }
  cout << ret << endl;
}

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

int N, M;
int mod = 1e9 + 7;

int main() {
    cin >> N >> M;
  	if (N == 1 && M == 1) {
      cout << 1 << endl;
      return 0;
    }
    if (N == 1 || M == 1) {
        cout << max(0, max(N, M) - 2) << endl;
        return 0;
    }
    cout << 1ll * (N - 2) * (M - 2) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int h;
 
	if (a>b) {
		h=b;
		b=a;
		a=h;
	}
	
	if (b>c) {
		h=c;
		c=b;
		b=h;
	}
	
	if (a>b) {
		h=b;
		b=a;
		a=h;
	}
	
	printf("%d %d %d\n", a, b, c);
	return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second
// setprecision()

int delt(int s, int t) {
  int d = s - t;
  d *= d;
  return d;
}

int main() {
  int N;
  double sum = 0;
  cin >> N;
  vector<PII> P;
  REP(i,N) {
    int x, y;
    cin >> x >> y;
    PII p = MP(x,y);
    P.PB(p);
  }
  REP(i,N) {
    for(int j = i+1; j < N; j++) {
      double l;
      l = delt(P.at(i).FI,P.at(j).FI) + delt(P.at(i).SE,P.at(j).SE);
      sum += sqrt(l);
    }
  }
  double ans = sum * 2 / N;
  cout << setprecision(8) << ans << endl;
  return 0;
}

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

def main(N,K,X):
    ans = 0
    for x in X:
        ans += min(abs(K-x)*2,x*2)
    print(ans)

if __name__ == '__main__':
    N = int(input())
    K = int(input())
    X = [int(x) for x in input().split()]
    main(N,K,X)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int n,total = 0;
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
        total += a[i];
    }
    total -= a[0];
    int sun = a[0];
    int ans = abs(total - sun);
    FOR(i,1,n-1){
        total -= a[i];
        sun += a[i];
        int b = abs(total-sun);
        ans = min(ans,b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  
  vector<tuple<string, ll ,ll> > Res;
  string s;
  ll p;
  rep2(i, n) {
    cin >> s >> p;
    Res.push_back(make_tuple(s, -1*p, i));
  }
  sort(all(Res));
  
  for(auto i: Res) cout << get<2>(i) << newl;
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  int sum = 0;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  if(vec.at(m-1) * 4 * m >= sum)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256