akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  vector<int> a;
  int x;
  for(int i=0;i<10;i++){
    cin >> x;
      a.push_back(x);
  }
  sort(a.begin() ,a.end(),greater<int>());
  for(int i=0;i<3;i++){
    cout << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int n; cin >> n;
    vector<int> A(n), B(n), C(n-1);
    rep(i, n) {cin >> A[i]; A[i]--;}
    rep(i, n) cin >> B[i];
    rep(i, n-1) cin >> C[i];

    int res = 0, bef = -10;
    rep(i, n){
        int num = A[i]; res+=B[num];
        if(num == bef + 1) res+=C[num-1];
        bef = num;
    }
    cout << res << ln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register 
#define ll long long
#define in inline
using namespace std;
inline ll read(){
	int t=0;
	char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+v-'0';
		v=getchar();
	}
	return t;
}
ll n,m,a[2002],l,r,ans;
int main(){
	n=read();
	for(re ll i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);
	for(re ll i=1;i<=n-2;++i){
		l=i+1;
		for(re ll j=i+1;j<=n-1;++j){
			l=max(l,j+1);
			r=n;
			while(l<r){
				m=(l+r)>>1;
				if(a[m]>=a[i]+a[j])r=m;
				else l=m+1;
			}
			while(a[l]>=a[i]+a[j])l--;
			if(l>j);
			ans+=l-j;
		}
	}
	printf("%lld",ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <sstream>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '-') count++;
  }
  if(s.find('-') == a && count == 1) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()

def point(str):
    if str=="r":
        return P
    elif str=="s":
        return R
    elif str=="p":
        return S


ans=0
o=[False]*K
for i in range(N):
    if i<K:
        ans+=point(T[i])
        o[i%K]=True
    else:
        if T[i]==T[i-K]:
            if o[i%K]==False:
                ans+=point(T[i])
                o[i%K]=True
            else:
                o[i%K]=False
        else:
            ans+=point(T[i])
            o[i%K]=True
print(ans)


Measured memory_bytes: 3956
N = int(input())
ans = [0 for _ in range(10001)]
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            v = x**2+y**2+z**2+x*y+y*z+z*x
            if v<10001:
                ans[v] += 1
for i in range(N):
    print(ans[i+1])


Measured memory_bytes: 9192
h,w = map(int,input().split())

aa = [input() for _ in range(h)]
aa_rm=[]
target_row=[]
for row,a in enumerate(aa):
    if a.count('.') < w:
        target_row.append(row)

target_col=[]
for iw in range(w):
    col=[]
    for ih in range(h):
        col.append(aa[ih][iw])
    # print(col)
    if col.count('.') < h:
        target_col.append(iw)

ans =[]
for row in target_row:
    s=""
    for col in target_col:
        s+=aa[row][col]
    ans.append(s)
for a in ans:
    print(a)


Measured memory_bytes: 3064
n = int(input())
ans = [0] * 10010
for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            x = i * i + j * j + k * k + i * j + j * k + k * i
            if x <= n:
                ans[x] += 1
for i in range(1, n+1):
    print(ans[i])

Measured memory_bytes: 9248
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static int[] a;
    static int k;
    static void Main()
    {
        var nk = ReadLine().Split().Select(int.Parse).ToArray();
        int n = nk[0];
        k = nk[1];
        a = ReadLine().Split().Select(int.Parse).ToArray();


        int lb = 0, ub = 1000000001;
        while (ub - lb > 1)
        {
            int mid = (ub + lb) / 2;
            if (c(mid)) lb = mid;
            else ub = mid;
        }
        WriteLine(ub);
    }
    static bool c(int mid)
    {
        long num = 0;
        foreach (var i in a)
        {
            num += i / mid;
            if (i % mid == 0) num--;
        }
        return num > k;
    }
}


Measured memory_bytes: 44748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N;
	vector<int> vc;
	cin>>N;
	rep(i,N*2){
		int x;
		cin>>x;
		vc.pb(x);
	}
	sort(all(vc));
	int ans=0;
	rep(i,N) ans+=vc[i*2];
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <random>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
string s;
int main() {
  cin >> n >> s;
  lli l=0, o=0;
  for (char c : s) {
    if (c=='(') ++o;
    else {
      if (o==0) ++l;
      else --o;
    }
  }
  string t = string(l, '(') + s + string(o, ')');
  cout << t << '\n';
  return 0;
}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<ll> A(max(N, M), 0);
	priority_queue<p> Q;
	ll result = 0;

	repeat(i, N) {
		ll a;
		cin >> a;
		Q.push( make_pair(a, 1) );
	}

	repeat(i, M) {
		ll b , c;
		cin >> b >> c;
		Q.push( make_pair(c, b) );
	}

	repeat(i, N) {
		p _p = Q.top();
		Q.pop();
		result += _p.first;
		if (_p.second > 1) {
			_p.second--;
			Q.push(_p);
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 7280
#include <iostream>
#include <vector>

using namespace std;
int main(void){
	int x;
	cin >> x;
	int ans=1;
	int i;
	for(i=2; i<=x; i++){
		int v=i*i;
		while(v <= x){
			ans = max(ans, v);
			v*=i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vvin edge(n+1);
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vin d(n+1,inf);d[1]=0;
    queue<int> q;q.push(1);
    while(q.size()){
        auto p=q.front();q.pop();
        for(auto e:edge[p]){
            if(d[e]==inf){
                d[e]=d[p]+1;
                q.push(e);
            }
        }
    }
    int tmp=(d[n]-1)/2;int white=0;
    //cout<<tmp<<endl;
    q.push(n);
    vbo arrived(n+1,false);
    while(q.size()){
        auto p=q.front();q.pop();
        if(d[p]==d[n]-tmp-1)continue;
        arrived[p]=true;white++;
        for(auto e:edge[p]){
            if(!arrived[e])q.push(e);
        }
    }
    //cout<<white<<endl;
    if(n%2==0){
        if(n-white<=white)cout<<"Snuke"<<endl;
        else cout<<"Fennec"<<endl;
    }
    else{
        if(n-white<white)cout<<"Snuke"<<endl;
        else cout<<"Fennec"<<endl;
    }
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std; void solve(); int main(){cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); solve();}
using ll=int_fast64_t; using ld=long double; using pll=pair<ll,ll>; using pld=pair<ld,ld>;
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> void vecout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}

template <std::uint_fast64_t Modulus> class modint {
public:
  ll a;
  constexpr modint(const ll x = 0) noexcept : a(x % Modulus) {}
  constexpr ll &value() noexcept { return a; }
  constexpr const ll &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    ll exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

void solve(){
	const ll MOD=1000000007;
	string k; cin>>k;
	ll d; cin>>d;
	ll n=k.size();
	auto dp=make_v(n+1,d,2,modint<MOD>(0));
	dp[0][0][0]=modint<MOD>(1);
	rep(i,n){
		ll a=k[i]-'0';
		rep(j,d)rep(l,2)rep(b,10){
      ll nj=(j+b)%d, nl=l;
      if(!l && b>a) continue;
      if(b<a) nl=1;
      dp[i+1][nj][nl]+=dp[i][j][l];
    }
	}
	cout<<(dp[n][0][0]+dp[n][0][1]-1).a<<"\n";
}

Measured memory_bytes: 55424
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int p[4][300];
int cost[300];
int dp[301][301];
int n,m;

int solve(int now, int money, int pp){
  if(now == n) return 0;
  if(dp[now][money] != -1) return dp[now][money];
  int ret = 0;
  for(int i = 0; i*cost[now] <= money; i++)
    ret = max(ret, i*p[pp][now] + solve(now+1,money-i*cost[now],pp));
  return dp[now][money] = ret;
}

int main(){
  string str;
  while(getline(cin,str)){
    stringstream ss(str);
    ss >> n >> m;

    REP(i,n){
      getline(cin,str);
      getline(cin,str);
      stringstream ss2(str);
      ss2 >> cost[i] >> p[0][i] >> p[1][i] >> p[2][i];
    }

    int ans = 0;
    REP(pp,4){
      memset(dp,-1,sizeof(dp));
      ans = max(ans, solve(0,m,pp));
    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 1308
import itertools

A, B, C = map(int, input().split())

 
list=[]
list.append(A*10+B+C)
list.append(A*10+C+B)
list.append(B*10+A+C)
list.append(B*10+C+A)
list.append(C*10+A+B)
list.append(C*10+B+A)

list.append(A+B*10+C)
list.append(A+C*10+B)
list.append(B+A*10+C)
list.append(B+C*10+A)
list.append(C+A*10+B)
list.append(C+B*10+A)


print(max(list))
    
    
    
    


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t;  using i64 = int64_t;  using str = string;
using u32 = uint32_t; using u64 = uint64_t; using usize = size_t;
using f64 = double_t; template <typename T> using vec = vector<T>;
#define times(n, i) for (i64 i = 0; i < (n); ++i)
#define range(n, m, i) for (i64 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i64 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i64 i = (n); i >= (m); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n;
i32 a[100000];

i32 main()
{
    cin >> n;
    times(n, i) {
        cin >> a[i];
    }

    i64 ans = 0; i64 acc = 0;
    times(n, i) {
        if (a[i] == 0) {
            ans += acc/2;
            acc = 0;
        } else {
            acc += a[i];
        }
    }

    cout << ans + acc/2 << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

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

		int n = sc.nextInt();
		String str = sc.next();

		if(str.length() % 2 == 1) {
			System.out.println("No");
			return;
		}

		if(str.substring(0, str.length()/2).equals(str.substring(str.length()/2))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21204
//#include <fstream>
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <stdio.h>


using namespace std;


int main(void) {
    //ifstream ifs;
    //ifs.open("./input.txt", ifstream::in);
    double x1, x2, y1, y2;
    
    cin >> x1;
    cin >> y1;
    cin >> x2;
    cin >> y2;
    
    //cout << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;
    printf("%.8lf", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
    return 0;
}

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

int main()
{
    int n, q;
    int order, index, value;

    cin >> n >> q;

    vector<int> a[n];

    for( int i = 0; i < q; i++ )
    {
        cin >> order >> index;

        switch(order)
        {
            case 0:
                cin >> value;
                a[index].push_back(value);
                break;
            case 1:
                if( a[index].size() == 0 )
                {
                    cout << endl;
                    break;
                }
                for( int j = 0; j < a[index].size() - 1; j++ )
                    cout << a[index][j] << " ";
                cout << a[index][a[index].size() - 1] << endl;
                break;
            case 2:
                if( a[index].size() == 0 )
                    break;
                else
                    a[index].clear();
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 5896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    int sum[100001] = {};
    sum[0] = 0;
    for (int i = 1; i < 100000; i++) sum[i] += sum[i-1] + i;
    rep(i , 100000) {
        if (sum[i] < X && X <= sum[i+1]) {
            cout << i+1 << endl;
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long L = (long) Integer.parseInt(sc.next());
		Long R = (long) Integer.parseInt(sc.next());
		sc.close();
		long a = L / 2019;
		long b = R / 2019;
		long base = 2019;
		if(a != b) {
			System.out.println(0);
		}else {
			for(long i = L; i < R; i++) {
				for(long j = L + 1; j <= R; j++) {
					long c = i % 2019;
					long d = j % 2019;
					long check = c * d;
					long checkValue = check % 2019;
					if(checkValue <= base) {
						base = checkValue;
					}
				}
			}
			System.out.println(base);
		}
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N;cin>>N;
    int x[N];
    REP(i,N)cin>>x[i];
    LL L;cin>>L;
    int logN = (int)log2(N) + 1;

    int doub[N][logN+1];
    fill(doub[0],doub[N],-1);
    REP(i,N-1)doub[i][0]=upper_bound(x,x+N,x[i]+L)-x-1;
    REP(k,logN)REP(i,N)if(doub[i][k]!=-1)doub[i][k+1]=doub[min(N-1,doub[i][k])][k];

    int q;cin>>q;
    REP(i,q){
        int a,b;cin>>a>>b;
        if(a>b)swap(a,b);
        a--;b--;

        int ans=0;
        for(int i=logN-1;i>=0;i--){
            if(doub[a][i]>=0&& doub[a][i]<b){
                ans+= 1<<i;
                a = doub[a][i];
            }
        }
        cout<<ans+1<<endl;
    }
    return 0;
}

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

int main(){
  long long A, B, K; cin >> A >> B >> K;
  
  if(K >= A+B){
    cout << 0 << ' ' << 0;
  }else if(K <= A){
    cout << A-K << ' ' << B;
  }else{
    cout << 0 << ' ' << B-(K-A);
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2147483647)
#define mod (1000000007)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)

void solve()
{
    double n,a;
    cin>>n;
    double sum;
    REP(i,n){cin>>a;sum+=1/a;}
    cout<<setprecision(10)<<1/sum<<endl;
}

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

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

using namespace std ;
int main(){
 pair<pair<string,int>,int> m[110];
  
  int a;
  cin>>a;
  for(int i =0;i<a;i++){
    int t ;
    string city;
    
    cin>>city>>t;
    
    m[i] = make_pair(make_pair(city,-t),i);
  }
  sort(m,m+a);
  for(int i =0;i<a;i++){
  
   
      cout<<m[i].second+1<<endl;
    
  } 
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#define DEBUG(X) {printf("!"); printf(X);}

constexpr int ORD(int n){
    int res = 1;
    for(int i=0; i < n; i++){
      res *= 10;
    }
    res++;
    return res;
}

using namespace std;

int N;
int M;
pair<unsigned long long, int> data[ORD(5)];


int check(){
  for(int i=0; i < N; i++){
    printf("%d %d\n", data[i].first, data[i].second);
  }
}

int calc(){
  // check();
  sort(data, data+N, [](auto a, auto b)->int{return (int)(a.first < b.first);});
  // check();
  int i = 0;
  unsigned long long money = 0;
  while(M != 0){
    int n = min(data[i].second, M);
    money += data[i].first * n;
    M -= n;
    i++;
  }
  printf("%lld\n", money);
}

int write(){

}



int main(){
      // input
      scanf("%d %d", &N, &M);
      for(int i=0; i < N; i++){
        unsigned long long a;
        int b;
        scanf("%lld %d", &a, &b);
        data[i] = make_pair(a, b);
      }
      // calc
      calc();
      // out
      write();
      return 0;
}

Measured memory_bytes: 1664
X = int(input())

l = []
for i in range(1, 32):
    for j in range(2, 10):
        if i ** j <= 1000:
            l.append(i ** j)

l = sorted(list(set(l)), reverse = True)

for i in range(len(l)):
    if l[i] <= X:
        print(l[i])
        break
    

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>

int ask(int i)
{
    static char buf[7];
    printf("%d\n", i);
    fflush(stdout);
    scanf("%s", buf);
    if (strcmp(buf, "Vacant") == 0) {
        return 0;
    }
    return strcmp(buf, "Male") == 0 ? 1 : 2;
}

int main()
{
    int n;
    scanf("%d", &n);
    int x0 = ask(0);
    if (!x0) {
        return 0;
    }
    int l = 0;
    int xl = x0;
    int r = n;
    int xr = x0;
    while (true) {
        int m = l + r >> 1;
        int xm = ask(m);
        if (!xm) {
            return 0;
        }
        if ((m - l & 1) != (xl != xm)) {
            r = m, xr = xm;
        } else {
            l = m, xl = xm;
        }
    }
}


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

using namespace std;

int main(){
  string str;
  cin >> str;
  if(str.size()%2 !=0){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0; i<=str.size()-2;i+=2){
    if(str[i]!='h' || str[i+1]!='i'){
      cout << "No" << endl;
      return 0;
    }

  }
  cout << "Yes" << endl;
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

using D = double;
const D PI = acos(D(-1)), EPS = 1e-10;

int sgn(D a) { return (abs(a) <= EPS) ? 0 : (a < 0 ? -1 : 1); }
int sgn(D a, D b) { return sgn(a-b); }
//relative sign
// int rsgn(D a, D f) {
//     if (abs(a) <= f*EPS) return 0;
//     return (a < 0) ? -1 : 1;
// }
struct Pt2 {
    D x, y;
    Pt2() {}
    Pt2(D _x, D _y) : x(_x), y(_y) {}
    Pt2 operator+(const Pt2 &r) const { return Pt2(x+r.x, y+r.y); }
    Pt2 operator-(const Pt2 &r) const { return Pt2(x-r.x, y-r.y); }
    Pt2 operator*(const Pt2 &r) const { return Pt2(x*r.x-y*r.y, x*r.y+y*r.x); }

    Pt2 operator*(const D &r) const { return Pt2(x*r, y*r); }
    Pt2 operator/(const D &r) const { return Pt2(x/r, y/r); }

    Pt2& operator+=(const Pt2 &r) { return *this=*this+r; }
    Pt2& operator-=(const Pt2 &r) { return *this=*this-r; }
    Pt2& operator*=(const Pt2 &r) { return *this=*this*r; }
    Pt2& operator*=(const D &r) { return *this=*this*r; }
    Pt2& operator/=(const D &r) { return *this=*this/r; }
    
    Pt2 operator-() const { return Pt2(-x, -y); }

    bool operator<(const Pt2 &r) const { return 2*sgn(x, r.x)+sgn(y, r.y)<0; }
    bool operator==(const Pt2 &r) const { return sgn((*this-r).rabs()) == 0; }

    D norm() const { return x*x + y*y; }
    D abs() const { return sqrt(norm()); }
    D rabs() const { return max(std::abs(x), std::abs(y)); } // robust abs
    D arg() const { return atan2(y, x); }

    pair<D, D> to_pair() const { return make_pair(x, y); }
    static Pt2 polar(D le, D th) { return Pt2(le*cos(th), le*sin(th)); }
};
ostream& operator<<(ostream& os, const Pt2 &p) {
    return os << "P(" << p.x << ", " << p.y << ")";
}
using P = Pt2;

struct L {
    P s, t;
    L() {}
    L(P _s, P _t) : s(_s), t(_t) {}
    P vec() const { return t-s; }
    D abs() const { return vec().abs(); }
    D arg() const { return vec().arg(); }
};
ostream& operator<<(ostream& os, const L &l) {
    return os << "L(" << l.s << ", " << l.t << ")";
}

D cross(P a, P b) { return a.x*b.y - a.y*b.x; }
D dot(P a, P b) { return a.x*b.x + a.y*b.y; }

P project(const L &l, const P &p) {
    P v = l.vec();
    return l.s + v * (dot(v, p-l.s) / (v.x*v.x + v.y*v.y));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
    
    L l;
    D x, y;
    cin >> x >> y; l.s = P(x, y);
    cin >> x >> y; l.t = P(x, y);
    int q;
    cin >> q;
    for (int ph = 0; ph < q; ph++) {
        P p;
        cin >> x >> y; p = P(x, y);
        P q = project(l, p);
        P r = q*D(2) - p;
        cout << r.x << " " << r.y << endl;
    }
    return 0;
}



Measured memory_bytes: 3308
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int x = sc.nextInt();
		int min = 100001;
		int sum = 0;

		for (int i = 0; i < n; i++) {
			int m = sc.nextInt();
			sum += m;
			if (m < min) {
				min = m;
			}
		}

		System.out.println(n + (x - sum) / min);

		sc.close();
	}
}


Measured memory_bytes: 25172
N = io.read("*n")
A = {}
for i = 1, N do
    A[i] = io.read("*n")
end

A_max = 0
for i = 1, N do
    A_max = math.max(A_max, A[i])
end
counter = 0
for i = 1, N do
    if A[i] == A_max then
        counter = counter + 1
    end
end
A_max2 = 0
for i = 1, N do
    if A[i] ~= A_max then
        A_max2 = math.max(A_max2, A[i])
    end
end
for i = 1, N do
    if counter >= 2 then
        print(A_max)
    else
        if A[i] == A_max then
            print(A_max2)
        else
            print(A_max)
        end
    end
end

Measured memory_bytes: 5752
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

if n == 1:
    if m == 0:
        print(0)
        exit()
    ans = "0"
    s, c = inintm()
    ans = str(c)
    for i in range(m-1):
        s, c = inintm()
        if ans != str(c):
            print(-1)
            exit()
    print(ans)
elif n == 2:
    if m == 0:
        print(10)
        exit()
    ans = ["0","0"]
    flag = ["0","0"]
    for i in range(m):
        s, c = inintm()
        if flag[s-1] == "1":
            if str(c) != ans[s-1]:
                print(-1)
                exit()
        flag[s-1] = "1"
        ans[s-1] = str(c)
    if ans[0] == "0":
        if flag[0] == "1":
            print(-1)
            exit()
        else:
            ans[0] = "1"
    print("".join(ans))
else:
    if m == 0:
        print(100)
        exit()
    ans = ["0","0","0"]
    flag = ["0","0","0"]
    for i in range(m):
        s, c = inintm()
        if flag[s-1] == "1":
            if str(c) != ans[s-1]:
                print(-1)
                exit()
        flag[s-1] = "1"
        ans[s-1] = str(c)
    if ans[0] == "0":
        if flag[0] == "1":
            print(-1)
            exit()
        else:
            ans[0] = "1"
    print("".join(ans))


Measured memory_bytes: 62304
#include <iostream>

int main() {
    uint32_t s;
    std::cin >> s;

    uint32_t hour = s / 3600;
    s %= 3600;
    uint32_t minute = s / 60;
    uint32_t second = s % 60;

    std::cout << hour << ':' << minute << ':' << second << std::endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<map>
#include<utility>
using namespace std;
int main(){
  string s;cin>>s;
  map<string,int> mp;
  mp["SUN"]=7;
  mp["MON"]=6;
    mp["TUE"]=5;
    mp["WED"]=4;
    mp["THU"]=3;
    mp["FRI"]=2;
    mp["SAT"]=1;
  cout<<mp[s]<<endl;
  return 0;
}
    
  

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string, str[];
		
		int a, b;
		while((string = reader.readLine()) != null){
			int data[] = new int[100];
			str = string.split(" ");
			a = Integer.valueOf(str[0]) - 1;
			b = Integer.valueOf(str[1]) - 1;
			data[a]++;
			data[b]++;
			
			while(!(string = reader.readLine()).equals("0 0")){
				str = string.split(" ");
				a = Integer.valueOf(str[0]) - 1;
				b = Integer.valueOf(str[1]) - 1;
				data[a]++;
				data[b]++;
			}
			
			a = 0;
			if(data[0] % 2 == 0 || data[1] % 2 == 0){
				a = 1;
			}else{
				for(int i = 2; i < 100; i++){
					if(data[i] % 2 == 1 && data[i] != 0){
						a = 1;
						break;
					}
				}
			}
			System.out.println(a == 0 ? "OK" : "NG");
		}
		reader.close();
	}
}

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

using namespace std;

int main ()
{
    int x,y;
    char m;
    cin>>x>>m>>y;
    while(m!='?')
    {
        if(m=='+')
        {
            cout<<x+y<<endl;
        }
        if(m=='-')
        {
            cout<<x-y<<endl;
        }
        if(m=='*')
        {
            cout<<x*y<<endl;
        }
        if(m=='/')
        {
            cout<<x/y<<endl;
        }
        cin>>x>>m>>y;
    }
    return 0;
}


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

int main() {
    string S,T,U;
    int A,B;
    cin >>S>>T>>A>>B>>U;
    if(U==S){
        A--;
    }
    else if(U==T){
        B--;
    }
    cout <<A <<" "<<B;
    return 0;
}


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

int main()
{
  ll x; cin>>x;
  ll sum = 0;
  ll i = 0;
  while (sum < x) {
    i++;
    sum += i;
  }
  cout << i << endl;

  return 0;
}


Measured memory_bytes: 256
//A
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int n;
	scanf("%d", &n);
	int x = n / 1000 + (n % 1000 != 0);
	printf("%d\n", 1000 * x - n);
}

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

int main(){
	int n, v, a[1000], i, j, k;
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	for(k = 0; k < n-1; k++){
			cout << a[k] << ' ';
	}
	cout << a[n-1] << endl;
	
	for(i = 1; i < n; i++){
		v = a[i];
		j = i-1;
		while(j >= 0 and a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		
		for(k = 0; k < n-1; k++){
			cout << a[k] << ' ';
		}
		cout << a[n-1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(input())
ans = "NO"
if a > b:
    if a - v * t <= b - w * t:
        ans = "YES"
if a < b:    
    if a + v * t >= b + w * t:
        ans = "YES"
print(ans)

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

using namespace std;

const int mxN = 1e7;
int f[mxN + 1];

long long D(int N) {
	long long res = 0;

	for (int i = 1; i <= N; i++)
		f[i] = 1;
	
	for (int i = 2; i <= N; i++)
		for (int j = i; j <= N; j += i)
			f[j]++;
	
	for (int i = 1; i <= N; i++)
		res += (long long) i * f[i];
	
	return res;
}

int main() {
	int N;
	cin >> N;
	cout << D(N);
	return 0;
}

Measured memory_bytes: 42676
n, t = map(int, input().split())

data = []

for i in range(n):
    tmp = input().split()
    tmp[0] = int(tmp[0])
    tmp[1] = int(tmp[1])
    data.append(tmp)

data.sort()


flg = False
for i in range(len(data)):
    if data[i][1] <= t:
        print(data[i][0])
        flg = True
        break

if not flg:
    print("TLE")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <fstream> 
#include <bits/stdc++.h>
using namespace std;
typedef long long LL; 

LL calc(LL H, LL W) {
	LL ret = 1e10;
	for (int i = 1; i < H; i ++) {
		LL s1 = i * W;
		LL s2 = max((H-i)/2 * W, (H-i)*(W/2));
		LL s3 = H * W - s1 - s2;
		LL maxx = max(s1, max(s2, s3));
		LL minn = min(s1, min(s2, s3));
		ret = min(ret, maxx - minn);
	}
	return ret;
}

int main() { 
	LL H, W; cin >> H >> W;
	cout << min(calc(H, W), calc(W, H)) << endl;
	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >>n >>s;
	
	if(n==2){
		if( s=="WE") puts("1");
		else puts("0");
		return 0;
	}
	VI a1(n), a2(n);
	rep(i,n) if(s[i]=='W') a1[i]=1;
	rep(i,n-1) a1[i+1] += a1[i];
	//for(auto x :a1) printf("%d, ",x); puts("");
	rep(i,n) if(s[i]=='E') a2[i]=1;
	reverse(all(a2));
	rep(i,n-1) a2[i+1] += a2[i];
	reverse(all(a2));
	//for(auto x :a2) printf("%d, ",x); puts("");
	
	int ans = 999999999;
	rep(i,n){
		int ct =0;
		if(i==0) ct = a2[1];
		else if(i==n-1) ct = a1[n-2];
		else ct = a2[i+1] + a1[i-1];
		//printf("%d:%d:%d  ",i,ct,ans);
		ans = min(ans, ct);
	}
	
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 2948
# coding: utf-8

n = int(input())
ew = [None] * n
for i in range(n):
    ew[i] = list(map(int, input().split()))

elist = []
for i in range(n):
    for j in range(i+1, n):
        if ew[i][j] > -1:
            elist.append((ew[i][j], i, j))


class UnionFind(object):
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def find_root(self, i):
        if self.parent[i] != i:
            p = self.parent[i]
            self.parent[i] = self.find_root(p)
        return self.parent[i]

    def same_group(self, i, j):
        return self.find_root(i) == self.find_root(j)

    def union(self, i, j):
        i = self.find_root(i)
        j = self.find_root(j)
        if i != j:
            self.parent[j] = i


uf = UnionFind(n)
esum = 0
for edge in sorted(elist):
    if not uf.same_group(edge[1], edge[2]):
        uf.union(edge[1], edge[2])
        esum += edge[0]

print(esum)

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
  ll N, tmp;
  cin >> N;
  vector<ll> D;
  for (ll i=0; i<N; i++){
    cin >> tmp;
    D.push_back(tmp);
  }
  sort(D.begin(), D.end());
  ll med1 = N / 2 - 1, med2 = N / 2;
  if (D[med1] == D[med2]){
    cout << 0 << endl;
  }
  else{
    cout << D[med2] - D[med1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	if(n>=400&&n<600){
		printf("8");
	}
	if(n>=600&&n<800){
		printf("7");
	}
	if(n>=800&&n<1000){
		printf("6");
	}
	if(n>=1000&&n<1200){
		printf("5");
	}
	if(n>=1200&&n<1400){
		printf("4");
	}
	if(n>=1400&&n<1600){
		printf("3");
	}
	if(n>=1600&&n<1800){
		printf("2");
	}
	if(n>=1800&&n<2000){
		printf("1");
	}
	return 0;
}

Measured memory_bytes: 1664
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split(' '))))

rank = np.argsort(X)
irank = {k: v for v, k in enumerate(rank)}

for i in range(N):
    if irank[i] < N//2:
        print(X[rank[N//2]])
    else:
        print(X[rank[N//2 - 1]])



Measured memory_bytes: 44488
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        int answer = int.MaxValue;
        for (int a = 1; a < n; a++)
        {
            int b = n - a;

            int sumA = a.ToString().Select(c => int.Parse(c.ToString())).Sum();
            int sumB = b.ToString().Select(c => int.Parse(c.ToString())).Sum();

            answer = Math.Min(answer, sumA + sumB);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 15440
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

typedef long long ll;
// #define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int a, b, t; cin >> a >> b >> t;
  cout << b*(t/a) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end(), greater<int>());

    int ans = 0;
    rep(i, K) { ans += v[i]; }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
set<int> si;
map<int, int> mii;
int prime[maxn], sieve[maxn], cnt;
void init()
{
    prime[1] = 1;
    for (int i = 2; i < maxn; ++i){
        if (!prime[i]) sieve[++cnt] = i;
        for (int j = 1; j <= cnt && i * sieve[j] < maxn; ++j){
            prime[i * sieve[j]] = 1;
            if (i % sieve[j] == 0) break;
        }
    }
    for (int i = 1; i <= cnt; ++i) mii[sieve[i]] = i;
    return ;
}
int pan = (1 << 30) - 1;
bool dis(int x)
{
    int cur = 0;
    bool is = true;
    for (int i = 1; i * i <= x && i <= cnt; ++i){
        int p = sieve[i];
        if (x % p == 0){
            while (x % p == 0) x /= p;
            if (si.count(p)) is = false;
            else si.insert(p);
            cur |= (1 << (i - 1));
        }
    }
    if (x != 1){
        if (si.count(x)) is = false;
        else si.insert(x);
        cur |= (1 << (mii[x] - 1));
    }
    pan &= cur;
    return is;
}
int main()
{
    init();
    bool pc = true;
    int n, x;
    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> x;
        if (!dis(x)) pc = false;
    }
    if (pc) cout << "pairwise coprime" << endl;
    else if (!pan) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 10992
p=*0..gets.to_i;s=0;
f=->a{a>p[a]?p[a]=f[p[a]]:a};
a,b=$<.map(&:split).transpose.map{|a|i=0;a.map{|a|[a.to_i,i+=1]}.sort.each_cons(2).map{|(x,i),(y,j)|[y-x,i,j]}};
(a+b).sort_by{|a|a[0]}.map{|c,a,b|a,b=[f[a],f[b]].sort;(s+=c;p[b]=a)if a!=b};
p s

Measured memory_bytes: 55044
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int X, N;
	cin >> X >> N;
	vector<bool> is_appeared(105);
	rep(i,0,N){
		int input; cin >> input;
		is_appeared[input] = true;
	}
	int index = -1;
	int minimum = k_mod;
	rep(i,0, 105){
		if (is_appeared[i])
			continue;
		int temp = abs(X-i);
		if (temp < minimum){
			minimum = temp;
			index = i;
		}
	}
	if (X < minimum){
		index = 0;
	}
	cout << index << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n), l(n), r(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  int ans = 0;
  l[0] = a[0], r[n-1] = b[n-1];
  for (int i = 1; i < n; i++) l[i] = l[i-1] + a[i];
  for (int i = n - 2; i >= 0; i--) r[i] = r[i + 1] + b[i];
  rep(i, n){
    ans = max(ans, l[i] + r[i]);
  }
  cout << ans << endl;
}

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

int main(){
    int a;
    int b;
    int x;
    int s;
    
    cin >> a >> b;
    
    x = 2*a + 2*b;
    s = a*b;
    
    cout << s << " " << x << endl;
    return 0;
    
}


Measured memory_bytes: 3112
n, m = input().split()
m = int(m)
s = 0
r = 'Yes'
v = [ int(x) for x in input().split(' ') if x != ' ']
v.sort(reverse=True)
for i in v:
  s += i
s = s / 4 / m
for i in range(m):
  if v[i] < s:
    r = 'No'
    break
    
print(r)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let m:usize = read();
    let mut arr = vec![true; n];
    for _ in 0..m {
        let x:usize = read();
        arr[x] = false;
    }

    let mut s = vec![0; n+1];
    s[0] = 1;
    s[1] = 1;
    for i in 2..=n {
        if arr[i-1] {
            s[i] += s[i-1];
        }
        if arr[i-2] {
            s[i] += s[i-2];
        }
        s[i] %= 1_000_000_007
    }
    println!("{}", s[n]);
}

Measured memory_bytes: 2516
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    X, Y, Z, K = read_ints()
    A = read_ints()
    B = read_ints()
    C = read_ints()
    BC = [b+c for b in B for c in C]
    BC.sort(reverse=True)
    A.sort(reverse=True)
    low, high = 2, max(A)+max(BC)+1
    while high-low > 1:
        min_deliciousness = low+(high-low)//2
        count_k = 0
        i = len(BC)-1
        for a in A:
            while i > -1 and a+BC[i] < min_deliciousness:
                i -= 1
            count_k += (i+1)
        if count_k > K:
            low = min_deliciousness
        else:
            high = min_deliciousness
    answer = []
    for a in A:
        for bc in BC:
            if a+bc < low:
                break
            else:
                answer.append(a+bc)
    answer.sort(reverse=True)
    for a in answer[:K]:
        print(a)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 252332
#include <stdio.h>

int main()
{
    int n, x;
    int count;
    int i, j, k;
    
    while(1){
    	count = 0;
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0) break;
        
        for (i = 1; i <= n - 2; i++){
            for (j = i + 1; j <= n - 1; j++){
                for (k = j + 1; k <= n; k++){
                    if (i + j + k == x) count++;
                }
            }
        }
        printf("%d\n", count);
    }
    
    return  0;
}

Measured memory_bytes: 600