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

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

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

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

using namespace std;

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

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

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

// Problem Specific Parameter:
bool match(int k) {
  for(int i = 0; i < t.length(); ++i) {
    if(t[i] != s[i+k] && s[i+k] != '?') return false;
  }
  return true;
}

string construct(int k) {
  string ans = s;
  for(int i = 0; i < t.length(); ++i) {
    ans[k+i] = t[i];
  }
  for(int i = 0; i < s.length(); ++i) {
    if(ans[i] == '?') ans[i] = 'a';
  }
  return ans;
}

int main() {
  cin >> s >> t;
  int k=-1;
  string ans;
  for(int i = 0; i < s.length()-t.length()+1; ++i){
    if(match(i)) k = i;
  }
  if(k==-1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    ans = construct(k);
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
    long long ans;
    long long w=1000000007;
    long long one=0,two=0;
    for(int i=0; i<N; i++){
        one=one+(A.at(i))%w;
        two=two+(A.at(i)*A.at(i))%w;
        one=one%w; 
        two=two%w;
    }
    ans=(one*one-two)%w;
    ans=ans*(w+1)/2;
    ans=ans%w;

    cout << ans << endl;
}

    


Measured memory_bytes: 4824
#include <stdio.h>

int main(void)
{
  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  
  if (a<b)
     if (b<c)
      puts("Yes");
     else 
      puts("No");
  else 
   puts("No");  

  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long gcd(long long a, long long b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}


int main()
{
	int x, a;
	cin >> x >> a;
	cout << (x >= a ? 10 : 0);
}



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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  int Cont=0;
  int Ans=0;
  for(int i=0; i<L; i++){
    if(S.at(i)=='A' || S.at(i)=='C' || S.at(i)=='G' || S.at(i)=='T'){
      Cont++;
      Ans=max(Ans, Cont);
    }
    else{
      Cont=0;
    }
  }
  cout << Ans << endl;
}
  

Measured memory_bytes: 256
import math 
A,B,H,M=list(map(int,input().split()))
pi=math.pi
S1=2*pi*(H+(M/60))/12
S2=M*2*pi/60
print(math.sqrt((A*math.cos(S1)-B*math.cos(S2))**2+(A*math.sin(S1)-B*math.sin(S2))**2))

Measured memory_bytes: 9516
import sys
input = sys.stdin.readline

def main():
    S = input()
    a = len(S)
    
    ans = 10**3
    for i in range(a-2):
        num = int(S[i:i+3])
        ans = min(ans,abs(num-753))
        
    print(ans)
    
if __name__ == "__main__":
    main()


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

int main(){
    unsigned N, K;
    scanf("%u %u", &N, &K);
    unsigned p[N];
    for (size_t i = 0; i < N; i++){
        scanf("%u", p + i);
    }
    nth_element(p, p + K - 1, p + N);
    unsigned answer = 0;
    for (size_t i = 0; i < K; i++){
        answer += p[i];
    }
    printf("%u\n", answer);
	return 0;
}

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

int main(){
  int H, W, A, B; cin >> H >> W >> A >> B;
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if((h < B) ^ (w < A)) cout << 1;
      else cout << 0;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

//割り算に対するあまりの処理
i64 divmod(i64 a, i64 b, i64 p) {//a:割る数 b:p-2 p:余りを取る数
    if (b == 0) {
        return 1;
    }
    else if (b % 2 == 0) {
        i64 d = divmod(a, b / 2, p);
        return (d * d) % p;
    }
    else {
        return (a * divmod(a, b - 1, p)) % p;
    }
}

i64 commod(i64 a, i64 b, i64 p) {//aCb mod p
    if (a < b)return 0;
    if (2 * b > a)b = a - b;
    i64 ans = 1;
    ff(i, 0, b) {
        ans *= a - i;
        ans %= p;
    }
    ff(i, 1, b+1) {
        ans *= divmod(i, p - 2, p);
        ans %= p;
    }
    return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    ff(i, 1, k+1) {
        i64 ans = commod(n - k + 1, i, inf);
        ans *= commod(k - 1, i - 1, inf);
        ans %= inf;
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 384
<?php
$a = explode(" ", trim(fgets(STDIN)));
$d = 1;
$m = 1;
$p = pow(10, 9) + 7;

if (abs($a[0] - $a[1]) > 1) {
  echo "0\n";
} else {
  for ($i = 1; $i <= $a[0]; $i++) {
    $d = ($d * $i) % $p;
  }
  for ($i = 1; $i <= $a[1]; $i++) {
    $m = ($m * $i) % $p;
  }
  if (abs($a[0] - $a[1]) === 0) {
    echo $d * $m * 2 % $p . "\n";
  } else {
    echo $d * $m % $p . "\n";
  }
}

Measured memory_bytes: 4732
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y) {
  if (y < 0) {
    return dceil(-x, -y);
  }
  if (x < 0) {
    return -dfloor(-x, y);
  }
  return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y) {
  if (y < 0) {
    return dfloor(-x, -y);
  }
  if (x < 0) {
    return -dceil(-x, y);
  }
  return x / y;
}

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

  int la = dceil(100 * A, 8), ua = dceil(100 * (A + 1), 8) - 1;
  int lb = dceil(100 * B, 10), ub = dceil(100 * (B + 1), 10) - 1;

  int l = max(la, lb), r = min(ua, ub);
  if (l > r) {
    cout << -1 << endl;
  } else {
    cout << l << endl;
  }
  return 0;
}

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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int A[N];
	rep(i, N) cin >> A[i];
	map<int, int> mp;
	int ans = 0;
	int sum[N + 1] = {};
	rep(i, N) {
		sum[i + 1] = sum[i] + A[i];
		mp[sum[i + 1] % M]++;
		if (sum[i + 1] % M == 0) ans++;
	}
	rep(i, N) {
		int tmp = mp[sum[i + 1] % M];
		ans += tmp * (tmp - 1) / 2;
		mp[sum[i + 1] % M] = 0;
	}
	cout << ans << endl;



    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

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

    ll res = 0;
    ll mod = 1e9 + 7;
    for (int i = 0; i < 60; ++i) {
        ll sum0 = 0;
        ll sum1 = 0;
        for (int j = 0; j < n; ++j) {
            if(a[j] & (1LL<<i)){
                sum1++;
            }
            else{
                sum0++;
            }
        }
        ll mul = (1LL<<i) % mod;
        res += (sum0 * sum1 % mod) * mul;
        res %= mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	result := "No"
	for i := 0; i < len(s); i++ {
		if s == t {
			result = "Yes"
			break
		} else {
			var tmp string
			for j := 0; j < len(s); j++ {
				tmp = s[1:len(s)] + string(s[0])
			}
			s = tmp
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 1664
import java.io.IOException;

public class Main {
	/**
	* @param args
	*/
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	d = null;
		int[][]	t = new int[4][2];

		while((d = parseData()) != null) {
			for (int i = 0; i < d.length; i++) {
				if (11 <= d[i]) {
					t[0][i]++;
				} else if (6 <= d[i] && d[i] < 11){
					t[1][i]++;
				} else if (2 <= d[i] && d[i] < 6){
					t[2][i]++;
				} else {
					t[3][i]++;
				}
			}
		}

		for (int i = 0; i < t.length; i++) {
			System.out.println(t[i][0]+" "+t[i][1]);
		}
	}

	private static int[] parseData() {
		// TODO Auto-generated method stub
		int[]	d = null;
		int		n = 0;

		if((n = parseNum()) != 0) {
			d    = new int[2];
			d[0] = n;
			d[1] = parseNum();
		}

		return d;
	}

	private static int parseNum() {
		try {
			int	buf = 0;
			int	num = 0;
			int	mns = 0;
			int	skp = 1;

			// -,0〜9以外は読み飛ばす
			while (true) {
				buf = System.in.read();
				if (buf == '-') {
					mns = 1;
					skp = 0;
				} else if (buf >= '0' && buf <= '9') {
					num = num * 10 + (buf - '0');
					skp = 0;
				} else if ((skp == 0 || buf == -1) && buf != '.') {
					return (mns == 0)?num:num*(-1);
				}
			}
		} catch (IOException e) {}
		return -1;
	}
}

Measured memory_bytes: 16832
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);

int n, k;
VI node[2020];
int ans = 0;

int solve(int center1, int center2 = -1)
{
  int ret = 0;
  queue<int> dfs;
  bool visited[2020];
  memset(visited, false, sizeof visited);

  dfs.push(center1);
  if(center2 != -1){
    dfs.push(center2);
  }

  for(int i = 0; i <= k / 2; i++){
    int sz = dfs.size();

    for(int j = 0; j < sz; j++){
      int now = dfs.front();
      dfs.pop();
      if(!visited[now]){
	visited[now] = true;
	ret++;
	for(int l = 0; l < node[now].size(); l++){
	  dfs.push(node[now][l]);
	}
      }
    }
  }
  return ret;
}

signed main()
{
  cin >> n >> k;
  for(int i = 0; i < n - 1; i++){
    int a, b;
    cin >> a >> b;
    node[a].PB(b);
    node[b].PB(a);
  }

  if(k % 2){
    for(int i = 1; i <= n; i++){
      for(int j = 0; j < node[i].size(); j++){
	ans = max(ans, solve(i, node[i][j]));
      }
    }
  }
  else{
    for(int i = 1; i <= n; i++){
      ans = max(ans, solve(i));
    }
  }

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


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

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

    string s, t,ans="Yes";
    cin >> s >> t;
    int n = s.size();
    vector<int> a(26), b(26);
    rep(i,n){
        char x = s[i], y = t[i];
        a[s[i] - 'a']++;
        b[t[i] - 'a']++;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    rep(i, 26) if (a[i] != b[i]) ans = "No";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;


int main(){
  int N,T;
  cin>>N>>T;
  int cost=2000;
  rep(i,0,N){
    int c,t;
    cin>>c>>t;
    if(t<=T){
      cost=min(cost,c);
    }
  }
  if(cost==2000) cout<<"TLE"<<endl;
  else cout<<cost<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int h = sc.nextInt();
        int w = sc.nextInt();
        //ArrayList<String> a = new ArrayList<>();

        String[] a = new String[h];

        for(int i = 0; i < h; i++){
            a[i] = sc.next();
        }

        long res = 0;

        //dp指的是到达h，w坐标的最多数字
        long[][] dp = new long[h+1][w+1];
        for(int i = 0; i < h; i++){
            if(a[i].charAt(0)!='#'){
                dp[i][0]=1;
            }else {
                break;
            }
        }

        for(int j = 0; j < w; j++){
            if(a[0].charAt(j)!='#'){
                dp[0][j]=1;
            }else {
                break;
            }
        }

        for(int i = 1; i < h; i++){
            for(int j = 1; j < w; j++){
                if(a[i].charAt(j) == '#'){//如果这个地方是个砖块，那dp肯定是0
                    dp[i][j] = 0;
                }else {
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%1000000007;
                }
            }
        }

        System.out.println(dp[h-1][w-1]);

    }
}

Measured memory_bytes: 37412
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

void printvec(vi& x, int size = 0) {
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);

    int n, l;
    cin >> n >> l;

    vi ans;
    using ii = pair<int, int>;
    deque<ii> deq;
    for (int i = 0; i < l; i++) {
        int a;
        cin >> a;
        if (deq.empty()) {
            deq.push_back(ii(i, a));
        } else {
            while (deq.size() && a <= deq.back().second) {
                deq.pop_back();
            }
            deq.push_back(ii(i, a));
        }
    }
    ans.push_back(deq.front().second);
    for (int i = 0; i < n - l; i++) {
        if (deq.front().first <= i) {
            deq.pop_front();
        }
        int a;
        cin >> a;
        while (deq.size() && a <= deq.back().second) {
            deq.pop_back();
        }
        deq.push_back(ii(i + l, a));
        ans.push_back(deq.front().second);
    }
    printvec(ans);
}


Measured memory_bytes: 11312
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }

  int ans=0;
  for(int i=0;i<N;i++){
    if(i%2==0&&a[i]%2==1){
      ans++;
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

struct store
{
    ll a;
    ll b;
}sl[100005];

bool cmp(store x, store y)
{
    return x.a < y.a;
}

int main()
{
    ll n, m;
    cin>>n>>m;
    for(int i = 0; i < n; ++i)
    {
        cin>>sl[i].a>>sl[i].b;
    }
    sort(sl, sl + n, cmp);
    ll ans = 0, sum = 0;
    for(int i = 0; i < n; ++i)
    {
        if(sum + sl[i].b >= m)
        {
            ans += (m - sum) * sl[i].a;
            break;
        }
        else
        {
            sum += sl[i].b;
            ans += sl[i].b * sl[i].a;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {
  rep(i, v.size()) is >> v[i]; return is;
}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
  rep(i, v.size()) os << v[i] << " "; os << endl; return os;
}
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  // ll q; cin >> q;
  int q; scanf("%d", &q);

  priority_queue<int> l;
  priority_queue<int, V, greater<int>> r;

  ll sb = 0, sl = 0, sr = 0;

  rep(i, q) {
    // int t; cin >> t;
    int t; scanf("%d", &t);
    if (t == 2) {
      ll ans = (sr-sl)/2 + sb;
      // cout << l.top() << " " << ans << endl;
      printf("%d %lld\n", l.top(), ans);
    }
    else {
      int a, b; scanf("%d%d", &a, &b);
      // int a, b; cin >> a >> b;
      l.push(a);
      r.push(a);
      sl += a;
      sr += a;

      int lt = l.top();
      int rt = r.top();
      if (lt > rt) {
        l.pop();
        r.pop();
        l.push(rt);
        r.push(lt);
        sl += rt - lt;
        sr += lt - rt;
      }
      sb += b;
    }
  }
  return 0;
}


Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int overseaStudent = 1;
        String s = sc.next();
        int passed = 0;

        for (int i = 0; i < n; i++) {
            String x = s.substring(i,i+1);
            switch (x){
                case "a":
                    if (passed < a + b) {
                        passed += 1;
                        System.out.println("Yes");
                    } else {
                        System.out.println("No");
                    }
                    break;
                case "b":
                    if (passed < a + b && overseaStudent <= b) {
                        passed += 1;
                        overseaStudent += 1;
                        System.out.println("Yes");
                    } else {
                        System.out.println("No");
                    }
                    break;
                case "c":
                    System.out.println("No");
                    break;
            }
        }
    }
}


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

const int MOD=1e9+7;

long long dp[100100][13];

int main(){
    string s;
    cin >> s;
    int N=s.size();
    dp[0][0]=1;
    for(int i=0;i<N;i++){
        if(s[i]=='?'){
            for(int j=0;j<=12;j++){
                for(int k=0;k<=9;k++){
                    dp[i+1][(10*j+k)%13]+=dp[i][j]%MOD;
                }
            }
        }else{
            int d=s[i]-'0';
            for(int j=0;j<=12;j++){
                dp[i+1][(10*j+d)%13]+=dp[i][j]%MOD;
            }
        }
    }
    cout << dp[N][5]%MOD << endl;
}

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

int w,h;
bool maze[20][20]; //x,y
int memo[20][20]; //x,y

int solve(int x, int y){

  if(memo[x][y]) return memo[x][y];
  if(x < 0 || y < 0 || x == w || y == h) return 0;
  if(maze[x][y]) return 0;
  if(x == w-1 && y == 0) return 1;

  return memo[x][y] = solve(x+1,y) + solve(x,y-1);
}


int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    memset(maze,false,sizeof(maze));
    memset(memo,0,sizeof(memo));

    int n;
    cin >> n;
    for(int i=0;i<n;i++){
      int a,b;
      cin >> a >> b;
      maze[a-1][h-b] = true;
    }

    cout << solve(0,h-1) << endl;
  }

}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

long long comb(long long n, long long k)
{
	//cout << "comb(" << n << "," << k << ")" << endl;
	if (n < 0 || k < 0 || n < k) {
		return 0;
	}
	long long c = 1;
	for (long long i = 0; i < k; ++i) {
		c *= n - i;
	}
	for (long long i = 0; i < k; ++i) {
		c /= i + 1;
	}
	return c;
}

int main()
{
	string N;
	int K;
	cin >> N >> K;

	const int L = N.size();

	if (K > L) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 0;
	int p = 0;
	for (int i = 0; i < L; ++i) {
		//cout << "i=" << i << endl;
		if (N[i] == '0') {
			continue;
		} else {
			++p;
		}
		long long t = 1;
		for (int j = 0; j < K - p; ++j) {
			t *= 9;
		}
		for (int x = N[i] - '0' - 1; x > 0; --x) {
			ans += t * comb(L - 1 - i, K - p);
			//cout << "[1]" << t * comb(L - 1 - i, K - p) << endl;
		}

		int d = (N[i] == '0') ? 0 : +1;

		t = 1;
		for (int j = 0; j < K - p + d; ++j) {
			t *= 9;
		}
		ans += t * comb(L - 1 - i, K - p + d);
		//cout << "[2]" << t * comb(L - 1 - i, K - p + d) << endl;
	}
	
	if (count(N.begin(), N.end(), '0') == L - K) {
		++ans;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

ll a[60];
int main(){
	ll n,l,r;
	while(scanf("%lld%lld%lld",&n,&l,&r),n){
		ll ans=0;
		rep(i,0,n)scanf("%lld",a+i);
		rep(x,l,r+1){
			int flag=-1;
			rep(i,0,n)if(x%a[i]==0){
				flag=(i+1)%2;
				break;
			}
			if(flag==-1)flag=(n+1)%2;
			ans+=flag;
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2588
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn gcd(a: usize, b: usize) -> usize {
    let mut a = a;
    let mut b = b;
    while b != 0 {
        let r = b;
        b = a % b;
        a = r;
    }
    a
}
fn lcm(a: usize, b: usize) -> usize {
    return a / gcd(a, b) * b;
}

fn main() {
    let n = get!(usize);
    let v = get!([usize]);
    if n == 1 {
        println!("{}", v[0]);
        return;
    }
    let mut l = lcm(v[0], v[1]);
    if n == 2 {
        let bunbo: f64 = l as f64 / v[0] as f64 + l as f64 / v[1] as f64;
        let ans = l as f64 / bunbo;
        println!("{}", ans);
        return;
    }
    for i in 2..n {
        l = lcm(l, v[i] as usize);
    }
    // eprintln!("l: {}", l);
    let mut bunbo = 0.0;
    for i in 0..n {
        bunbo += l as f64 / v[i] as f64;
    }
    // eprintln!("bunbo: {}", bunbo);
    let ans = l as f64 / bunbo;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
  long long a;
  double b;
  scanf("%lld %lf",&a,&b);
  int c=b*100+0.5;
  //printf("%lf\n",(double)c);
  printf("%lld\n",(a*c/100));
  return 0;
}


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

int main(void) 
{
	int a, b[] = { 0,1,2,3,5,7,8,9 };
	while (cin >> a)
	{
		if (a == 0)break;
		long long e = 1, ans = 0;
		while (a != 0)
		{
			int c = a % 8;
			ans += e * b[c];
			e *= 10;
			a /= 8;
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main() {

    long long X; cin >> X;
    long long t;
    long long ans = 0;
    t = 100;

    while(X > t) {
        t = t + t*0.01;
        ans++;
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var num = Input.num;
        var ar = Input.ar;
        var ct = 0;
        var t = new bool[num];
        for(var i=0;i<num;i++)
            if (!t[i] && ar[ar[i]-1] == i+1)
            {
                t[ar[i]-1] = true;ct++;
            }
        WriteLine(ct);
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 18272
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

    long n = 1;
    double s = 1.d;
    for (long i = 1; i <= K; i++) {
      long x = n;
      long z = 0;
      long y = 1;
      while (x > 0) {
        x /= 10;
        z = z * 10 + 9;
        y *= 10;
        long t = x * y + z;
        double ts = sunuke(t);
        if (ts < s) {
          n = t;
          s = ts;
        }
      }
      System.out.println(n);
      n++;
      s = sunuke(n);
    }
  }

  private static double sunuke(long n) {
    return (double) n / sumDigits(n);
  }

  private static long sumDigits(long i) {
    long sum = 0;
    while (i > 0) {
      sum += i % 10;
      i /= 10;
    }
    return sum;
  }

  private static long numDigits(long i) {
    long d = 0;
    while (i > 0) {
      d++;
      i /= 10;
    }
    return d;
  }
}


Measured memory_bytes: 19412
import math
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))

lis = []
for i in a:
    lis.append(-1*i)

heapq.heapify(lis)

for _ in range(m):
    tmp = heapq.heappop(lis)
    heapq.heappush(lis, (-1)*(-tmp//2))

print(-sum(lis))

Measured memory_bytes: 20204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> P;
#define INF 1145141919
int x, y;
map<P, bool> s;

int f(int a, int b) {
  if (s[P(a,b)] == true) return INF;
  s[P(a,b)] = 1;
  return min(a<=b?b-a:INF, min(1+f(a,-b), 1+f(-a,b)));
}
int g(int a, int b) {
  if (s[P(a,b)] == true) return INF;
  s[P(a,b)] = 1;
  return min(a<=b?b-a:INF, min(1+g(-a,b), 1+g(a,-b)));
}

int main() {
  cin >> x >> y;
  int a = f(x,y);
  s.clear();
  a = min(a, g(x, y));
  cout << a << "\n";
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  ll ans=0;
  if(n%2==0){
    n = n/10;
    ans += n;
    rep(i,30){
      n /=5;
      ans += n;
    }
    cout << ans << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
{
  const main = (input: string): void | string | number => {
    const re = reader(input)
    const N = re.n()
    const a = re.ns()

    // gcd of 0~i
    const l: number[] = []
    const r: number[] = []

    l[0] = a[0]
    r[N - 1] = a[N - 1]

    for (let i = 1; i < N; i++) {
      l[i] = _gcd(l[i - 1], a[i])
    }
    for (let i = N - 2; i >= 0; i--) {
      r[i] = _gcd(r[i + 1], a[i])
    }

    // console.log(l)
    // console.log(r)

    let ans = 0

    for (let i = -2; i < N; i++) {
      // console.log(l[i] || r[i + 2], r[i + 2] || l[i])
      ans = Math.max(ans, _gcd(l[i] || r[i + 2], r[i + 2] || l[i]))
    }
    // Object.keys(lib).map(k => {
    //   const v = lib[k]

    //   if (v >= N - 1) {
    //     ans = Math.max(ans, Number(k))
    //   }
    // })
    return ans
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const _gcd = (a, b) => (b ? _gcd(b, a % b) : a)

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const res = main(getInput())

  if (typeof res === 'number' || typeof res == 'string') console.log(res)
}


Measured memory_bytes: 31372
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (register ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 2e6 + 100 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T = int> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, ans;

char s[maxn];

ll f[maxn] = {1}, sum, last = n + 1, nex[maxn][2], flag;

set <ll> pos[3];

signed main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	flag = 1;
	rep(i, 2, n) flag &= s[i] != s[i - 1];
	if(flag) return puts("1"), 0;
	pos[0].insert(n);
	per(i, n - 1, 0)
	{
		(sum += s[i + 1] == 'a' ? 1 : 2) %= 3;
		if(s[i + 1] == s[i + 2]) last = i + 2;
		pos[sum].insert(i);
		if(s[i + 1] == 'a') nex[i][0] = i + 1;
		else nex[i][1] = i + 1;
		if(s[i + 1] == 'b')
		{
			auto pre = pos[(sum + 2) % 3].lb(last);
			if(pre == pos[(sum + 2) % 3].end()) nex[i][0] = n + 1;
			else nex[i][0] = *pre;
		}
		else
		{
			auto pre = pos[(sum + 1) % 3].lb(last);
			if(pre == pos[(sum + 1) % 3].end()) nex[i][1] = n + 1;
			else nex[i][1] = *pre;
		}
	}
	// rep(i, 0, n - 1) printf("%lld : %lld %lld\n", i, nex[i][0], nex[i][1]);
	rep(i, 0, n - 1)
	{
		if(nex[i][0] != n + 1) (f[nex[i][0]] += f[i]) %= mod;
		if(nex[i][1] != n + 1) (f[nex[i][1]] += f[i]) %= mod;
	}
	// rep(i, 0, n) printf("f : %lld\n", f[i]);
	sum = 0, ans = f[n];
	per(i, n - 1, 1)
	{
		(sum += s[i + 1] == 'a' ? 1 : 2) %= 3;
		if(!sum) (ans += f[i]) %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 10624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] cnt = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt() - 1;
            cnt[a[i]]++;
        }
        long ans = 0;
        for (int x : cnt)
            ans += 1l * x * (x - 1) / 2;
        for (int x : a) {
            ans -= 1l * cnt[x] * (cnt[x] - 1) / 2;
            cnt[x]--;
            ans += 1l * cnt[x] * (cnt[x] - 1) / 2;
            out.println(ans);
            ans -= 1l * cnt[x] * (cnt[x] - 1) / 2;
            cnt[x]++;
            ans += 1l * cnt[x] * (cnt[x] - 1) / 2;
        }
        out.flush();
        out.close();
    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        boolean ready() throws IOException {
            return br.ready();
        }

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

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

        int nextChar() throws IOException {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

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

    }
}


Measured memory_bytes: 51756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

vector<int> to[105];

int main() {
    int n, k;
    cin >> n >> k;
    if (k > (n-2)*(n-1)/2) {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 2; i <= n; i++) {
        to[1].push_back(i);
        to[i].push_back(1);
    }
    int c = (n-2)*(n-1)/2 - k;
    for (int i = 2; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            if (c == 0) break;
            to[i].push_back(j);
            to[j].push_back(i);
            c--;
        }
    }
    vector<P> ans;
    for (int i = 1; i <= n; i++) {
        for (int x : to[i]) {
            if (i < x) ans.emplace_back(i,x);
        }
    }
    cout << ans.size() << endl;
    rep(i,ans.size()) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }
    return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
 
int main(void){
    string S,T;
    cin >> S >> T;
    int ans = 0;
    for(int i=0; i<=S.size()-T.size(); i++){
        int cnt = 0;
        FOR(j,0,T.size()){
            if(S[i+j] == T[j]) cnt++;
        }
        ans = max(ans,cnt);
    }
    cout << T.size()-ans << endl;
    return 0;
}

Measured memory_bytes: 3596
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  ll i=1;
  while(n!=0){
    while(i*(i+1)/2<n){
      i++;
    }
    cout<<i<<endl;
    n-=i;
    i=1;
  }
  
}


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

using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;

bool check(i64 x, i64 k, const vector<i64> &a) {
  // x 以下の数がk個以上ある？
  i64 cnt = 0;  // x以下の数の個数
  i64 n = a.size();

  rep(i, n) {
    i64 ci = 0;
    long double t = 0;
    if (a[i] == 0) {
      // 0とかけてx以下になる個数
      if (x < 0) {
      } else {
        ci = n - 1 - i;
      }
    } else {
      t = x / (long double)a[i];
      if (a[i] > 0) {
        // t以下の数の個数
        ci = upper_bound(a.begin() + i + 1, a.end(), t) - (a.begin() + i + 1);
      } else {
        // t以上の数の個数
        ci = a.end() - lower_bound(a.begin() + i + 1, a.end(), t);
      }
    }
    cnt += ci;
    // cout << "a[i]:" << a[i] << ", x:" << x << ", t:" << t << ", ci:" << ci
    //      << endl;
  }

  return cnt >= k;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  i64 n, k;
  cin >> n >> k;
  vector<i64> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(all(a));
  const i64 MAX = 1e18 * 2;
  i64 ok = MAX;
  i64 ng = -MAX;
  while (abs(ok - ng) > 1) {
    i64 mid = (ok + ng) / 2;
    if (check(mid, k, a)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int a[200010] ;

bool cmp (int a, int b)
{
	return a > b ;
}

int main()
{
	int n ;
	scanf ("%d", &n) ;
	
	for (int i=0; i<n; i++)
		scanf ("%d", a + i) ;
		
	sort (a, a + n, cmp) ;
	
	LL sum = a[0] ;
	int i = 1, j = 3 ;
	while (j <= n)
	{
		if (j + 1 <= n)
		{
			sum += a[i] * 2 ;
			j += 2 ;
		}
		else
		{
			sum += a[i] ;
			j++ ;
		}
		
		i++ ;
	}
		
	cout << sum << endl ;

	return 0 ;
}

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

int main()
{
    int a, b, x, y, z;
    cin >> a >> b;

    x = a + b;
    y = a - b;
    z = a * b;

    if (x > y) {
        if (x > z) {
            cout << x << endl;
        } else {
            cout << z << endl;
        }
    } else {
        if (y > z) {
            cout << y << endl;
        } else {
            cout << z << endl;
        }
    }
    
    return 0;
}

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

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

    int cnt = 0, mini = 1e9;
    rep(i, n) {
        if (mini > p[i]) {
            cnt++;
            mini = p[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>


int main(){

	int i, x, n;


	scanf( "%d", &n );

	for( i=1; i<=n; i++ ){

		x = i;
	
		if( x%3 == 0 ){
			printf( " %d", i );
			continue;
		}

		do{
			if( x%10 == 3 ){
				printf( " %d", i );
				break;
			}
			
			x /= 10;

		}while(x);

	}	

	printf( "\n" );



	return 0;

}

Measured memory_bytes: 600
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
v=list(map(int,input().split()))
even={}
odd={}
for i in range(n):
    if i%2==0:
        if v[i] not in even:
            even[v[i]]=1
        else:
            even[v[i]]+=1
    else:
        if v[i] not in odd:
            odd[v[i]]=1
        else:
            odd[v[i]]+=1
    
even=sorted(even.items(),key=lambda x: x[1],reverse=True)
odd=sorted(odd.items(),key=lambda x:x[1],reverse=True)
if even[0][0]==odd[0][0]:
    e1=even[0][1]
    e2=even[1][1] if len(even)>1 else 0
    o1=odd[0][1]
    o2=odd[1][1] if len(odd)>1 else 0
    print(min((n-e1-o2),(n-e2-o1)))
else:
    e=even[0][1]
    o=odd[0][1]
    print(n-e-o)


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

typedef pair<int, int> P;

vector<vector<P>> g;
vector<int> d;

int ma = 0;
int mav;

void dfs( int u, int p )
{
	for( P e : g[u] ) {
		int v = e.first;
		int w = e.second;
		if( v == p ) continue;
		d[v] = max( d[v], d[u] + w );
		if( d[v] > ma ) {
			ma = d[v];
			mav = v;
		}
		dfs( v, u );
	}
}

int main()
{
	int n;
	cin >> n;
	g = vector<vector<P>>( n );
	d = vector<int>( n );
	for( int i = 0; i < n - 1; i++ ) {
		int s, t, w;
		cin >> s >> t >> w;
		g[s].push_back( make_pair( t, w ) );
		g[t].push_back( make_pair( s, w ) );
	}

	dfs( 0, -1 );
	int x = mav;
	ma = 0;
	d.assign( n, 0 );
	dfs( x, -1 );

	cout << ma << endl;
}



Measured memory_bytes: 13320
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vector<string> s(n);
  rep(i,0,n)cin>>s[i];
  string ans=s[0];
  
  rep(i,0,n){//s[i]
    map<char,int> cnt;
    rep(j,0,ans.size()){
      cnt[ans[j]]++; 
    }
    ans="";
    rep(j,0,s[i].size()){
      if(cnt[s[i][j]]){
        cnt[s[i][j]]--;
        ans+=s[i][j];
      }
    }
    
    
  }
  sort(all(ans));
  cout<<ans<<endl;
}

Measured memory_bytes: 3556