akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=1e6+5;
int n,tl,a[N],mid;
pair<int,int> v[N];

void init()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;++i) scanf("%d",&a[i]);
	v[0].first=-1;
}

void prework()
{
	int i;tl=0;memset(v,0,sizeof(v)); 
	for(i=1;i<n;++i)
		if(a[i]>=a[i+1])
			break;
	if(i<n) v[++tl]=make_pair(a[i+1],1);
}

int inc(int len)
{
//	cout<<len<<"!!!!!!!!!"<<endl;
	if(v[tl].first!=len)
	{
		v[++tl]=make_pair(len,1);
		return true;
	}
	if(tl==len)
	{
		int i;
		for(i=1;i<=tl;++i)
			if(v[i].second!=mid)
				break;
		if(i>tl) return false;
	}
	
	int now=tl;
	if(v[now].second<mid)
	{
		++v[now].second;
		return true;
	}
	while(v[now].first==v[now-1].first+1&&
	v[now-1].second==mid) --now;
	int tfl=(v[now-1].first==v[now].first-1);
	int tt=v[now].first-1;
	while(tl!=now) v[tl--]=make_pair(0,0);
	v[tl--]=make_pair(0,0);
	if(tfl) ++v[now-1].second;
	else v[++tl]=make_pair(tt,1);
	return true;
}

int work()
{
	
	int i;
	for(i=1;i<n;++i)
		if(a[i]>=a[i+1])
			break;
	
	for(++i;i<n;++i)
	{
	//	for(int ii=1;ii<=5;++ii) cout<<v[ii].first<<" "<<v[ii].second<<endl;
	//	cout<<"$$$$$$$"<<endl;
		if(a[i]>=a[i+1])
		{
			while(v[tl].first>a[i+1]) v[tl--]=make_pair(0,0);
			if(!inc(a[i+1])) return false;
		}
	}
	
	return true;
}

int ok()
{
	prework();
	return work();
}

int calc()
{
	int i;
	for(i=1;i<n;++i)
		if(a[i]>=a[i+1])
			return false;
	return true;
}

int main()
{
//	freopen("AGC.in","r",stdin);
//	freopen("AGC.out","w",stdout);
	init();
	if(calc())
	{
		printf("1\n");
		return 0;
	}
	
//	mid=2;cout<<ok()<<endl;
	int l=1,r=n;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(ok()) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l+1);
	return 0;
}

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

using namespace std;
typedef long long LL;

const double Pi = acos(-1.0);
const int INf = 0x7fffffff;
const double eps = 1e-9;

int sgn(double d) {
    if(fabs(d) < eps)
        return 0;
    if(d > 0)
        return 1;
    return -1;
}

int dcmp(double x, double y) {
    if(fabs(x - y) < eps)
        return 0;
    if(x > y)
        return 1;
    return -1;
}

struct Point {
    double x, y;
    Point(double _x = 0, double _y = 0):x(_x), y(_y){}
};

typedef Point Vector;

Vector operator + (Vector A, Vector B) {
    return Vector(A.x + B.x, A.y + B.y);
}

Vector operator - (Point A, Point B) {
    return Vector(A.x - B.x, A.y - B.y);
}

Vector operator * (Vector A, double p) {
    return Vector(A.x * p, A.y * p);
}

Vector operator / (Vector A, double p) {
    return Vector(A.x / p, A.y / p);
}

bool operator == (const Point &a, const Point &b) {
    if(sgn(a.x-b.x) == 0 && sgn(a.y-b.y) == 0)
        return true;
    return false;
}

double Dot(Vector A, Vector B) {
    return A.x * B.x + A.y * B.y;
}

double Cross(Vector A, Vector B) {
    return A.x * B.y - B.x * A.y;
}

double Length(Vector A) {
    return sqrt(Dot(A, A));
}

double Angle(Vector A, Vector B) {
    return acos(Dot(A, B) / Length(A) / Length(B));
}

double Area2(Point A, Point B, Point C) {
    return Cross(B - A, C - A);
}

Vector Rotate(Vector A, double rad) { // 逆时针旋转rad
    return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) - A.y * cos(rad));
}

Vector Normal(Vector A) {      //A左转90°的单位法向量
    double L = Length(A);
    return Vector(-A.y / L, A.x / L);
}

bool ToLeftTest(Point a, Point b, Point c) {
    return Cross(b - a, c - a) > 0;
}

struct Line {
    Point v, p;
    Line(Point v, Point p) : v(v), p(p){}
    Point point(double t) {
        return v + (p - v) * t;
    }
};

Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
    Vector u = P - Q;
    double t = Cross(w, u) / Cross(v, w);
    return P + v * t;
}

double DistanceToLine(Point P, Point A, Point B) {
    Vector v1 = B - A, v2 = P - A;
    return fabs(Cross(v1, v2) / Length(v1));
}


double DistanceToSegment(Point P, Point A, Point B) {
    if(A == B)
        return Length(P - A);
    Vector v1 = B - A, v2 = P - A, v3 = P - B;
    if(sgn(Dot(v1, v2)) < 0)
        return Length(v2);
    if(sgn(Dot(v1, v3)) > 0)
        return Length(v3);
    return DistanceToLine(P, A, B);
}

Point GetLineProjection(Point P, Point A, Point B) {
    Vector v = B - A;
    return A + v * (Dot(v, P - A) / Dot(v, v));
}

int main() {
    Point p0, p1, p2, p3;
    Vector v1, v2;
    int q;
    scanf("%d", &q);
    while(q--) {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &p0.x, &p0.y, &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y);
        v1.x = p1.x - p0.x, v1.y = p1.y - p0.y;
        v2.x = p3.x - p2.x, v2.y = p3.y - p2.y;
        if(sgn(Cross(v1, v2)) == 0)
            printf("2\n");
        else if(sgn(Dot(v1, v2)) == 0)
            printf("1\n");
        else
            printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 3252
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b,c) make_pair(make_pair(a,b),c)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

int x,y,z;
int a[3];
int main(){
	while(cin >> a[0] >> a[1] >> a[2]){
		sort(a,a+3);
		if( a[0]+a[1] <= a[2] ) break;
		if( a[2] * a[2] == a[1] * a[1] + a[0] * a[0] ){
			x++;
		}else if( a[2] * a[2] < a[1] * a[1] + a[0] * a[0] ){
			y++;
		}else{
			z++;
		}
	}
	cout << x+y+z << " " << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 1184
#include<algorithm>
#include<cstdio>
using namespace std;

const int MAX_N = 2e5, MOD = 1e9 + 7;
int n, k;

int po(int x, int y) {
    int ans = 1;
    while (y > 0) {
        if (y & 1) ans = static_cast<long>(ans) * x % MOD;
        x = static_cast<long>(x) * x % MOD;
        y >>= 1;
    }
    return ans;
}

int fac[MAX_N + 1], inv[MAX_N + 1];

int main() {
    scanf("%d %d", &n, &k);

    fac[0] = 1;
    for (int i = 1; i <= n; i++) {
        fac[i] = static_cast<long>(fac[i - 1]) * i % MOD;
    }
    inv[n] = po(fac[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--) {
        inv[i] = static_cast<long>(inv[i + 1]) * (i + 1) % MOD;
    }

    int ans = 0;
    for (int i = 0; i < min(n, k + 1); i++) {
        ans = (ans + static_cast<long>(fac[n]) * inv[i] % MOD
            * inv[n - i] % MOD * fac[n - 1] % MOD 
            * inv[n - i - 1] % MOD * inv[i] % MOD) % MOD;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<cstdlib>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
int a,b;
int main()
{
	cin>>n>>a>>b;
	cout<<a+b+n+9*max(a,max(n,b))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)

ll inf = 1000000000000000000;

using P = pair<ll, ll>;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> d(N);
    d[0] = 0;
    repi(i,1, N) d[i] = inf;
    vector<P> ed(M);
    vector<ll> cost(M);
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        ed[i] = P(a, b);
        cost[i] = -c;
    }
    rep(i, N) {
        rep(j, M) {
            ll from = ed[j].first;
            ll to = ed[j].second;
            if (d[from] == inf)continue;
            if (d[to] > d[from] + cost[j]) {
                d[to] = d[from] + cost[j];
                if (i == N - 1) {
                    queue<ll> q;
                    q.push(to);
                    while (!q.empty()) {
                        ll x = q.front();
                        q.pop();
                        d[x] = -inf;
                        rep(k, M) if (ed[k].first == x && d[ed[k].second] != -inf) q.push(ed[k].second);
                    }
                }
            }
        }
    }
    if (d[N - 1] == -inf) cout << "inf" << endl;
    else cout << -d[N - 1] << endl;
    return 0;
}



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

const int MOD = 1000000007;
template<class T> inline void add_mod(T &a, const T b) {
	a += b;
	if(a >= MOD) a -= MOD;
}

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	auto sum = [](int l, int r){
				   return (long)(r - l + 1) * (l + r) / 2;
			   };
	long ans = 0;
	for(int i = k; i <= n + 1; i++)
		add_mod(ans, (sum(n-i+1, n) - sum(0, i-1) + 1) % MOD);
	printf("%ld\n", ans);
}


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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i<=31; i++) {
        int curr = pow(k, i);
        if(curr == n) {
            cout << i+1;
            return;
        }
        if(curr > n) {
            cout << i << '\n';
            return;
        }
    }
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [10 ** 5 for _ in range(N)]
B = list(map(int, input().split()))
for i in range(N - 1):
    if B[i] < A[i]:
        A[i] = B[i]
    if B[i] < A[i + 1]:
        A[i + 1] = B[i]
print(sum(A))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    int arr[n];
    forn(i, n) cin >> arr[i];
    int cnt = 0;
    while (1) {
        forn(i, n) {
            if (arr[i] % 2 == 0)
                arr[i] /= 2;
            else {
                goto done;
            }
        }
        cnt++;
    }
done:;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m, c;
  cin >> n >> m >> c;
  ll res = 0;
  vector <ll> v(m);
  rep(i, m) cin >> v.at(i);
  rep(i, n) {
    ll tmp = c;
    rep(j, m) {
      ll a;
      cin >> a;
      tmp += a*v.at(j);
    }
    if (tmp > 0) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),

int n,ans[100001];
vii adj[100001];

void dfs(int cur,int par,int h){
    ans[cur]=h&1;
    for(pii ch:adj[cur]){
        if(ch.first==par)continue;
        dfs(ch.first,cur,h+ch.second);
    }
}

signed main(){
    FASTER;
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b,c;cin>>a>>b>>c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    dfs(1,-1,0);
    for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
}

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

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

    ll tot= 0;

    for( int i=1;i<=n;i++ )
    {
        ll a= i;

        ll l= 1, r= n, ans= 1;

        while(l<=r)
        {
            ll mid= (l+r)/2;

            if( mid*a>=n )
                r= mid-1;
            else
                ans= mid, l= mid+1;
        }

        if( ans*a==n )
            ans--;

        tot+= ans;
    }

    cout<< tot <<"\n";
}






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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), C(N - 1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int s;
        cin >> s;
        sum += s;
    }
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i];
    }

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

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double a = sc.nextDouble();
			int k = 1;
			double s = a;
			while(++k<=10){
			      if(k%2==0)a*=2;
			      else a=a/3;
			      s+=a;
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 19216
#include <iostream>
using namespace std;
int main()
{
  string A, B, C;
  cin >> A >> B >> C;
  string ans = "NO";
  if (A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0])
    ans = "YES";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
main(){
	int n;
	while(scanf("%d",&n),n){
		int a,b,c = 0,d = 0;
		while(n--){
			scanf("%d%d",&a,&b);
			c+=a>b?a+b:a==b?a:0;
			d+=b>a?a+b:a==b?b:0;
		}
		printf("%d %d\n",c,d);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	int t = 0;
	int ms = 1e9;
	for (int i = 0; i < N-1; i++) {
		int s1 = 0, s2 = 0;
		for (int j = 0; j < N; j++) {
			if (j <= i) {
				s1 += W[j];
			}
			else {
				s2 += W[j];
			}
		}
		if (abs(s1 - s2) < ms) {
			ms = abs(s1 - s2);
			t = i;
		}
	}

	t++;
	cout << ms << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define debug(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define TAU PI * 2
using ll = long long;
using ull = unsigned long long;
ll MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    int ans = 0;
    int current = a[0];
    int cnt = 0;
    rep(i, n){
        if(current == a[i]){
            cnt++;
        }else{
            ans += cnt / 2;
            current = a[i];
            cnt = 1;
        }
    }

    ans += cnt / 2;

    println(ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

static class ModeValue
{
    static void Main()
    {
        Console.In.ReadToEnd()
            .Split( 
                new[] { '\r', '\n' },
                StringSplitOptions.RemoveEmptyEntries )
            .Select( int.Parse )
            .GroupBy( x => x )
            .OrderBy( x => x.Key )
            .Select( x => new { k = x.Key, c = x.Count() } )
            .Aggregate(
                new { max = 0, modes = new List<int>() },
                (x, y) => {
                    if ( x.max < y.c ) x.modes.Clear();
                    if ( x.max <= y.c ) x.modes.Add( y.k );
                    return new
                    {
                        max = Math.Max( x.max, y.c ),
                        modes = x.modes
                    };
                },
                x => x.modes )
            .ForEach( Console.WriteLine );
    }
}

Measured memory_bytes: 6768
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij=[(1,0),(-1,0),(0,1),(0,-1)]

def main():
    sa = sb = 0
    hp1 = []
    hp2 = []
    m = None
    for _ in range(II()):
        ab=input().split()
        if ab[0]=="1":
            a,b=int(ab[1]),int(ab[2])
            sb+=b
            heappush(hp1,-a)
            heappush(hp2,a)
            while -hp1[0]>hp2[0]:
                heappush(hp1,-heappop(hp2))
                heappush(hp2,-heappop(hp1))
            if m==None:
                m=a
                continue
            if -hp1[0]>m:
                d=-hp1[0]-m
                sa+=(len(hp1)-1)//2*d-(len(hp2)+1)//2*d
            if -hp1[0]<m:
                d=hp1[0]+m
                sa+=-(len(hp1))//2*d+(len(hp2))//2*d
            sa += abs(m - a)
            m=-hp1[0]
        else:
            print(m,sa+sb)

main()

Measured memory_bytes: 19068
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i,n,l;
    cin>>n>>l;
    string str[n], ans;
    
    for(i=0; i<n; i++){
        cin>>str[i];
    }
    sort(str, str+n);
    for(i=0; i<n; i++){
        ans+=str[i];
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define lld double
#define vi vector<ll>
#define pii pair<int,int>
#define piii pair<pii, ll>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define ppb pop_back
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<x<<" "<<y<<"\n"
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
using namespace std;
const ll mod = 1e9+7;



int main()
{
    char c[11];
    cin>>c;

    int i=0;
    while(c[i])
    {
        if(c[i]=='h'&&c[i+1]=='i')
        {
            i+=2;
            continue;
        }
        else
        {
            d1("No");return 0;
        }
    }

    d1("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  cin >> N;
  long long M[5] = {0,0,0,0,0};
  long long ans = 0;

  int P[10] = {0,0,0,0,0,0,1,1,1,2};
  int Q[10] = {1,1,1,2,2,3,2,2,3,3};
  int R[10] = {2,3,4,3,4,4,3,4,4,4};
  string S;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S.at(0) == 'M') M[0]++;
    if (S.at(0) == 'A') M[1]++;
    if (S.at(0) == 'R') M[2]++;
    if (S.at(0) == 'C') M[3]++;
    if (S.at(0) == 'H') M[4]++;
  }
  for (int i = 0; i < 10; i++) {
    ans += M[P[i]] * M[Q[i]] * M[R[i]];
  }
  cout << ans << endl;
}

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

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

typedef long long int64;

int main() {
    int64 n;
    int64 ans = 0;
    cin >> n;
    if (n%2) {
        cout << 0 << endl;
        return 0;
    }

    ans += n /= 10;
    while(n != 0) {
        ans += n /= 5;
    }

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

Measured memory_bytes: 256
N = gets.to_i
num_seq = []
N.times { num_seq << gets.to_i }
sorted_num_seq = num_seq.sort.reverse

results = num_seq.each_with_object([]) do |num, arr|
  max = (num == sorted_num_seq[0]) ? sorted_num_seq[1] : sorted_num_seq[0]
  arr << max
end

puts results


Measured memory_bytes: 11936
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_TREE_MAX		100000									// 最大木数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Tree[D_TREE_MAX];									// 木
static int siTCnt;												// 木数
static int siSCnt;												// 選択数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// ソート関数 - int昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// int昇順
	if (*lipVal1 > *lipVal2) {
		return 1;
	}
	else if (*lipVal1 < *lipVal2) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 木数・選択数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siTCnt, &siSCnt);

	// 木 - 取得
	for (i = 0; i < siTCnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d", &si1Tree[i]);
	}

	// 木 - ソート
	qsort(si1Tree, siTCnt, sizeof(int), fSortFnc);

	// 最小値 - 取得
	int liMin = INT_MAX;
	for (i = 0; i < siTCnt - siSCnt + 1; i++) {
		int liVal = si1Tree[i + siSCnt - 1] - si1Tree[i];
		if (liMin > liVal) {
			liMin = liVal;
		}
	}

	// 結果 - セット
	sprintf(lc1Out, "%d\n", liMin);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;

int main() {
  ll N,T,A;
  cin >> N >>T >>A;
  vector<pair<double,int>> K(N);
  rep(i,N){
   int H;
    cin >>H;
    double k = abs(A - (T - (H * 0.006)));
    K[i] = mp(k,i+1);
  }
  sort(all(K));
  out (K[0].S);
}

Measured memory_bytes: 256
function main()
  
  (S,T) = split(chomp(readline())," ")
  (A,B) = map(x -> parse(Int,x), split(readline()))
  U = chomp(readline())
  
  if S == U
    print(A-1)
    println(" ",B)
  else
    print(A)
    println(" ",B-1)
  end
  
end

main()

Measured memory_bytes: 165252
#include <iostream>
#include <string>
using namespace std;
int main(){
	string str;
	string st;
	cin >> str >> st;
	str += str;
	//int ans = str.find(st);
	//cout << str.find(st) << endl;
	if( str.find(st) > 101 )
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#define GET_MAX 52
using namespace std;

struct mn
{
	char mark;
	int num;
	int tf;
};

int main()
{
	struct mn set[GET_MAX];
	for (int i = 0; i <= GET_MAX; i++)
	{
		if (i/13 == 0)
		{
			set[i].mark = 'S';
		}
		else if (i/13 == 1)
		{
			set[i].mark = 'H';
		}
		else if (i/13 == 2)
		{
			set[i].mark = 'C';
		}
		else if (i / 13 == 3)
		{
			set[i].mark = 'D';
		}
		if ((i + 1) % 13 == 0)
		{
			set[i].num = 13;
		}
		else
		{
			set[i].num = (i + 1) % 13;
		}
		set[i].tf = 1;
	}

	int count;
	cin >> count;
	char mark;
	int number;
	for (int i = 0; i < count; i++)
	{
		cin >> mark >> number;
		for (int i = 0; i <GET_MAX ; i++)
		{
			if (set[i].mark == mark && set[i].num == number)
			{
				set[i].tf = 0;
			}
		}
	}

	for (int i = 0; i < GET_MAX; i++)
	{
		if (set[i].tf == 1)
		{
			cout << set[i].mark << ' ' << set[i].num << endl;
		}
	}
	return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

vint calc[33][10];
vint top1[33];
vint ans[33];
int K;
signed main() {
    cin >> K;
    int all = 9;
    int cnt = 2, digit = 10, lead = 1;
    top1[0].push_back(0);
    top1[1].push_back(1);
    reps(i, 9) {
        ans[1].push_back(i);
        calc[1][i].push_back(i);
    }
    while (all < K) {
        vint cur;
        if (lead == 1) {
            rep(i, cnt - 1) {
                rep(j, top1[i].size()) {
                    cur.push_back(top1[i][j] + lead * digit);
                }
            }
        }

        rep(i, 3) {
            int x = lead + i - 1;
            if (0 < x && x < 10) {
                rep(j, calc[cnt - 1][x].size()) { cur.push_back(calc[cnt - 1][x][j] + lead * digit); }
            }
        }

        rep(i, cur.size()) {
            ans[cnt].push_back(cur[i]);
            if (lead == 1) { top1[cnt].push_back(cur[i]); }
            calc[cnt][lead].push_back(cur[i]);
            all++;
        }

        if (lead == 9) {
            lead = 1;
            cnt++;
            digit *= 10;
        } else {
            lead++;
        }
    }
    vint lans;
    reps(i, cnt) {
        rep(j, ans[i].size()) { lans.push_back(ans[i][j]); }
    }
    cout << lans[K - 1] << endl;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int INF=(1<<30)-1;
const int MOD=1000000007;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll x, ans = 1LL;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> x;
    ll p = x / 11;
    ll a = x - p * 11;
    if (a == 0) ans = p * 2;
    else if (a > 6) ans = p * 2 + 2;
    else ans = p * 2 + 1;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
A = [int(i) for i in input().split()]
a = 0
b = 0
mod = 10**9+7
for i in range(N) :
    for j in range(N) :
        if A[i]>A[j] :
            if i < j :
                a += 1
            else :
                b += 1
ans = ( a * ((K+1)*K) // 2 + b * (K*(K-1)) // 2) %mod
print(ans)

Measured memory_bytes: 9260
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    sub: [(usize1, chars); m],
  }
  let mut ac = vec![false; n];
  let mut wa = vec![0; n];
  for &(p, ref s) in &sub {
    if s[0] == 'A' {
      ac[p] = true;
    } else {
      if ! ac[p] {
        wa[p] += 1;
      }
    }
  }
  let mut total_ac = 0;
  let mut total_wa = 0;
  for i in 0 .. n {
    if ac[i] {
      total_ac += 1;
      total_wa += wa[i];
    }
  }

  puts!("{} {}\n", total_ac, total_wa);
}


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

long long a[555333];

int main() {

    int n,k;
    scanf("%d%d", &n, &k);

    for(int i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a,a+n);

    long long r = 0;
    for(int i=0; i<n-k; i++) {
        r += a[i];
    }

    printf("%lld\n", r);

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <stdio.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};
 
int N, x;
int a[2020];

//f[i][j], i回回すことを許して、スライムjを取る最小コスト
int f[2020][2020];
 
signed main()
{
  cin >> N >> x;
  REP(i,N) cin >> a[i];

  REP(i,N) REP(j,N) {
    if (i == 0) {
      f[i][j] = a[j];
    } else {
      if (j - i < 0) {
        f[i][j] = min(f[i-1][j], a[N+(j-i)]);
      } else {
        f[i][j] = min(f[i-1][j], a[j-i]);
      }
    }
  }

  // REP(i,N) {
  //   REP(j,N) {
  //     cout << f[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  int ans = INF;
  REP(i,N) {
    int sum = 0;
    REP(j,N) {
      sum += f[i][j];
    }
    ans = min(ans, sum + x * i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 31872
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringJoiner;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		int n = Integer.parseInt(br.readLine());
		
		int[] array = new int[n];
		for(int i = 0; i < n; i++){
			array[i] = Integer.parseInt(br.readLine());
		}
		
		shellSort(array);
	}
	
	public static int insertionSort(int[] array, int g){
		int count = 0;
		for(int i = g; i < array.length; i++){
			int v = array[i];
			int j = i - g;
			while(0 <= j && v < array[j]){
				array[j+g] = array[j];
				j -= g;
				count++;
			}
			array[j+g] = v;
		}
		
		return count;
	}
	
	public static void shellSort(int[] array){
		int count = 0;
		
		List<Integer> gList = new ArrayList<>();
		for(int i = 1; ; i++){
			int g = (int)((Math.pow(3, i) - 1) / 2);
			if(g <= array.length){
				gList.add(g);
			}else{
				break;
			}
		}
		Collections.reverse(gList);
		for(int g: gList){
			count += insertionSort(array, g);
		}
		
		System.out.println(gList.size());
		StringJoiner sj = new StringJoiner(" ");
		gList.forEach(gv -> sj.add(String.valueOf(gv)));
		System.out.println(sj);
		System.out.println(count);
		Arrays.stream(array).forEach(System.out::println);
	}
}



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

const int INF = -10;
typedef pair<int, int> P;

char maze[200][200];
int N, M;
int sx, sy, gx, gy;
int d[200][200];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int BFS(){
    queue<P> que;
    for(int i=0; i<N; i++)
	for(int j=0; j<M; j++)
	    d[i][j] = INF;
    
    // start
    que.push(P(sx, sy));
    d[sx][sy] = 0;

    while(que.size()){
	P p = que.front();
	que.pop();

	//search
	if(p.first == gx && p.second == gy)
	    break;

	for(int i=0; i<4; i++){
	    int nx = p.first + dx[i], ny = p.second + dy[i];	    
	    if(0<=nx && nx<N && 0<=ny && ny<M && maze[nx][ny]!='#' && d[nx][ny]==INF){
		que.push(P(nx, ny));
		d[nx][ny] = d[p.first][p.second] + 1;
	    }
	}
    }    
    return d[gx][gy];
}


int main(){
    cin >> N >> M;
    for(int i=0; i<N; i++)
	cin >> maze[i];

    sx = 0;
    sy = 0;
    gx = N-1;
    gy = M-1;
    
    int ans=BFS();

    int cnt=0;
    for(int i=0; i<N; i++){
	for(int j=0; j<M; j++){
	    if(maze[i][j]=='#')
		cnt++;
	}
    }
    if(ans==INF)
	cout << -1 << endl;
    else
	cout << N*M-ans-1-cnt << endl;


    
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a,b;

    scanf("%c%c",&a,&b);

    if(a=='9')
    {
        printf("Yes\n");
    }
    else if(b=='9')
    {
        printf("Yes\n");
    }
    else
    {
        printf("No");
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <functional>
#include <list>
#include <vector>
#include <iterator>
#include <ctime>
#include <iomanip>
#include <cstdlib>
#include <random>
#include <cstdio>
#include <sstream>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <chrono> 
#include <numeric> 

using llong = long long;
using ullong = unsigned long long;
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define FORD(i, s, n) for (int i = (s); i > (n); i--)
#define FORW(i, s, n, p) for (int i = (s); i < (n); i += p)
#define FORDW(i, s, n, p) for (int i = (s); i > (n); i -= p)

using namespace std;

int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	llong n, k;
	cin >> n >> k;
	vector <llong> nums(n);
	for (int i = 0; i < n; i++)
		cin >> nums[i];
	sort(nums.begin(), nums.end());

	llong l = min(nums[0] * nums[1], nums[0] * nums.back()) - 1;
	llong r = max(nums[0] * nums[1], nums.back() * nums[nums.size() - 2]) + 1;

	llong maxAns = l;

	while (l + 1 < r) {

		llong mid = (l + r) / 2;
		llong cnt = 0;
		
		for (int i = 0; i < n; i++) {

			if (nums[i] > 0) {

				int lt = -1, rt = n;

				while (lt + 1 < rt) {

					int mt = (lt + rt) / 2;
					if (nums[i] * nums[mt] < mid)
						lt = mt;
					else
						rt = mt;

				}

				cnt += rt;

			}
			else {

				int lt = -1, rt = n;

				while (lt + 1 < rt) {

					int mt = (lt + rt) / 2;

					if (nums[i] * nums[mt] < mid)
						rt = mt;
					else
						lt = mt;

				}

				cnt += (n - rt);

			}

		}

		for (int i = 0; i < n; i++)
			if (nums[i] * nums[i] < mid)
				cnt--;

		cnt /= 2; 

		if (cnt >= k)
			r = mid;
		else
			l = mid;

	}

	cout << l;

}

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

ll C(ll n) {
  ll T = 1;
  int D = 0;
  while(T <= n) T *= 10, D++;
  ll ret = 0;
  for(int d=0; d<D; d++) {
    ll all = n - T / 10 + 1;
    ll fizz = n / 3 - (T / 10) / 3;
    ll buzz = n / 5 - (T / 10 - 1) / 5;
    ll fizzbuzz = n / 15 - (T / 10) / 15;
    ll sum = (all - fizz - buzz + fizzbuzz) * (D - d);
    sum += (fizz + buzz) * 4;
    ret += sum;
    T /= 10;
    n = T - 1;
  }

  return ret;
}

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

  ll L = 0, H = 1e17;
  while(L + 1 < H){
    ll M = (L + H) / 2;
    ll tmp = C(M);
    if(tmp >= n){
      H = M;
    }
    else{
      L = M;
    }
  }
  
  string res;
  for(ll i = L + 1; i < L + 22; i++) {
    if(i % 3 == 0) res += "Fizz";
    if(i % 5 == 0) res += "Buzz";
    if(i % 3 && i % 5) res += to_string(i);
  }

  ll p = C(L) + 1;
  
  for(int i=0;; i++) {
    assert(i < res.size());
    if(p >= n + 20) break;
    if(n <= p) cout << res[i];
    p ++;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3252
a,b,c,x,y = map(int,input().split())
cnt = 0
if 2*c < a+b:
    cnt += min(x,y)*c*2
    if x >= y:
        cnt += min((x-y)*a,(x-y)*2*c)
    else:
        cnt += min((y-x)*b,(y-x)*2*c)
else:
    cnt += a*x + b*y
print(cnt)

Measured memory_bytes: 3064
#define MOD 1000000007

#include <iostream>
#include <vector>
using namespace std;

long pow(long a, long b) {
	if (b == 0) return 1;
	long c = pow(a, b / 2);
	if (b % 2) c = a * c % MOD * c % MOD;
	else c = c * c % MOD;
	return c;
}

int main() {
	long n, k;
	cin >> n >> k;
	if (k < n) cout << 0;
	else {
		vector<long> a(k + 1, 1), b(k + 1, 1);
		for (int i = 1; i <= k; i++) {
			a[i] = a[i - 1] * i % MOD;
			b[i] = pow(a[i], MOD - 2);
		}
		cout << a[k] * b[k - n] % MOD * b[n] % MOD;
	}
	cout << endl;
}


Measured memory_bytes: 3132
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    int[] s;
    long mod = 1000000000+7;
    String str;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        // binary search
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        str = sc.next();
        char[] ss = str.toCharArray();
        s = new int[n];
        for(int i=0;i<n;i++) s[i] = ss[i]-'a';
        long ans = 0;
        // first check the lower limit
        int lo = 1;
        if(!valid(lo)) return 0;
        int hi = s.length/2+1;
        while(hi>lo+1){
            int mid = (hi+lo)/2;
            if(valid(mid)) lo = mid;
            else hi = mid;
        }
        return lo;
    }
    boolean valid(int len){
        // check whether len is valid
        if(2*len>s.length) return false;
        HashMap<Long, HashSet<Integer>> rec = new HashMap<>(s.length);
        long curHash = 0;
        for(int i=0;i<len;i++){
            curHash = (26*curHash+s[i])%mod;
        }
        HashSet<Integer> temp = new HashSet<>();
        temp.add(0);
        rec.put(curHash,temp);
        long pow26len = power(26,len-1); // factor for decrease at rolling
        for(int i=1;i+len-1<s.length;i++){
            curHash = (curHash+mod-s[i-1]*pow26len%mod)%mod;
            curHash = (curHash*26+s[i+len-1])%mod;
            if(rec.get(curHash)==null){
                HashSet<Integer> curSet = new HashSet<>();
                curSet.add(i); // starting at i
                rec.put(curHash,curSet);
            } else{
                HashSet<Integer> curSet = rec.get(curHash);
                for(int start : curSet){
                    if(i < start+len) continue;
                    if(str.substring(start,start+len).equals(str.substring(i,i+len))){
                        return true; // there exist such two substrings
                    }
                }
                rec.get(curHash).add(i);
            }
        }
        return false;
    }
    long power(long base, long po){
        long ans = 1;
        while(po>0){
            if(po%2>0){
                ans = (ans*base)%mod;
            }
            base = base*base%mod;
            po /= 2;
        }
        return ans;
    }
}



Measured memory_bytes: 36316
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 2 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 


    int n , k;

    cin>>n>>k;
    double ans = 0;
    for(int i=1; i<=n; ++i){
       double q = 1;

       for(int j=i; j< k; j*=2)
            q/=2;
       ans += q/n;
    }
    cout<<fixed<<setprecision(20)<<ans<<endl;


    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("cin","r",stdin);
    freopen("cout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256