akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int N,M; cin >> N >> M;
    vector<int> P(M),Y(M);
    vector<vector<int>> memo(N);
    for(int i = 0; i < M; i++){
        cin >> P[i] >> Y[i];
        P[i]--;
        memo[P[i]].push_back(Y[i]);
    }
    for(int i = 0; i < N; i++) sort(memo[i].begin(),memo[i].end());
    for(int i = 0; i < M; i++){
        int id = lower_bound(memo[P[i]].begin(),memo[P[i]].end(),Y[i])-memo[P[i]].begin();
        printf("%06d",P[i]+1);
        printf("%06d\n",distance(memo[P[i]].begin(),lower_bound(memo[P[i]].begin(),memo[P[i]].end(),Y[i]))+1);
    }
}

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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x % 2) count++;
  }
  if (count % 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i;
    while ( scanf("%d %d",&a,&b) !=EOF ) {
        c = a + b;
        int count = 0;
        for (i=0;c!=0;i++) {
            c /= 10;
        }
        printf("%d\n",i);
    }
}



Measured memory_bytes: 3212
#include <stdio.h>

int main(void)
{
	int S, h, m, s;

	scanf("%d", &S);

	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 3600 % 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <algorithm>	// sort
#include <functional>	// greater<T> 構造体

using namespace std;

#define MAX_N 200001
#define ceil(x) ((x) == ll(x) ? x : ll(x) + 1) 
typedef long long ll;

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;
ll K;
ll a[MAX_N];
ll f[MAX_N];

int cond(ll x) {
	ll k = K;

	for(int i = 1; i <= N; i++) {
		if(a[i] * f[i] <= x) continue;
		// 不可能;
		if(ceil((a[i] * f[i] - x) / double(f[i]) ) > k) return 0;
 		// k更新
		k -= ceil((a[i] * f[i] - x) / double(f[i]) );
	}
	return 1;
}

int main () {

	// 個数と長さの読込み
	scanf("%d %lld", &N, &K);

	for(int i = 1; i <= N; i++)	scanf("%lld", a + i);
	for(int i = 1; i <= N; i++)	scanf("%lld", f + i);

	std::sort(a + 1, a + 1 + N);
	std::sort(f + 1, f + 1 + N, std::greater<int>());

	int i = 1;

	ll L = 0, R = a[N]*f[1]+1;	// 求める最小値xは[L, R) の範囲内

	while(R - L > 1) {
		ll m = (L + R) / 2;
		if(cond(m) == 1) {
			if(cond(m - 1) == 0) { L = m; break; }
			else R = m;
		} else {
			L = m + 1;
		}
	}

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

	return 0;
}

Measured memory_bytes: 3328
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

double L;

double ans = 0;

void solve(){
	ans = L*L*L/27.0;
}
 
int main(){
    cin >> L;
 
    solve();

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> enemy(N+1);
  vector<int> battle(N);
  for(int i = 0; i < N+1; i++){
    cin >> enemy.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> battle.at(i);
  }
  long long sum = 0;
  for(int i = 0; i < N; i++){
  if(enemy.at(i) + enemy.at(i+1) <= battle.at(i)){
    sum += enemy.at(i) + enemy.at(i+1);
    enemy.at(i+1) = 0;
  }
   if(enemy.at(i) + enemy.at(i+1) > battle.at(i)){
    sum += battle.at(i);
    if(enemy.at(i) <= battle.at(i)){
      enemy.at(i+1) -= (battle.at(i)-enemy.at(i));
    }
    if(enemy.at(i) > battle.at(i)){
      enemy.at(i) -= battle.at(i);
    }
  }
  }
  cout << sum << endl;
}


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


struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() { 
    int N;
    string S;
    cin >> N >> S;
    RollingHash rh(S);

    int res = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int lcp = rh.getLCP(i, j);
            lcp = min(lcp, j-i);
            res = max(res, lcp);
        }
    }   
        
    cout << res << endl;
}

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

void swap(int *a, int *b){
	int temp = *a;
	*a = *b;
	*b = temp;
}

int partition(int *a, int p, int r){
	int x, i;
	x = a[r];
	i = p - 1;
	for(int j=p;j<r;++j){
		if(a[j]<=x){
			++i;
			swap(&(a[i]),&(a[j]));
		}
	}
	swap(&(a[i+1]),&(a[r]));
	return i+1;
}

int main() {
	int n, *a, p;
	cin>>n;
	a = new int[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	p = partition(a,0,n-1);
	for(int i=0;i<n;++i){
		if(i==p)cout<<(i?" ":"")<<"["<<a[i]<<"]";
		else cout<<(i?" ":"")<<a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1568
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
using namespace std;

const int MAX_H = 30;
const int MAX_W = 30;

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

int W, H;
int G[MAX_H][MAX_W];
int order[6];
map<char, int> id;

struct S {
  int x, y, step, face[3], cost;
};
bool vis[MAX_H][MAX_W][7][7][7][7];

int bfs(int sx, int sy) {
  S s;
  queue<S> que;
  fill(vis[0][0][0][0][0], vis[MAX_H][0][0][0][0], false);
  s.x = sx;
  s.y = sy;
  s.step = 0;
  s.face[0] = 1;
  s.face[1] = 2;
  s.face[2] = 3;
  s.cost = 0;
  que.push(s);
  while(!que.empty()) {
    s = que.front(); que.pop();
    if(G[s.y][s.x] != 0) {
      if(G[s.y][s.x] == order[s.step]) {
	++s.step;
	if(s.step == 6) return s.cost;
      } else {
	continue;
      }
    }

    for(int i = 0; i < 4; ++i) {
      S t = s;
      t.x += dx[i];
      t.y += dy[i];
      ++t.cost;
      if(t.x < 0 || t.x >= W) continue;
      if(t.y < 0 || t.y >= H) continue;
      if(G[t.y][t.x] == 7) continue;
      switch(i) {
      case 0:
	t.face[0] = 7 - s.face[2];
	t.face[2] = s.face[0];
	break;
      case 1:
	t.face[0] = s.face[1];
	t.face[1] = 7 - s.face[0];
	break;
      case 2:
	t.face[0] = s.face[2];
	t.face[2] = 7 - s.face[0];
	break;
      case 3:
	t.face[0] = 7 - s.face[1];
	t.face[1] = s.face[0];
	break;
      }
      if(G[t.y][t.x] != 0 && G[t.y][t.x] != t.face[0]) continue;
      if(vis[t.y][t.x][t.step][t.face[0]][t.face[1]][t.face[2]]) continue;
      vis[t.y][t.x][t.step][t.face[0]][t.face[1]][t.face[2]] = true;
      que.push(t);
    }
  }
  return -1;
}

int main() {
  id['w'] = 0;
  id['r'] = 1;
  id['g'] = 2;
  id['b'] = 3;
  id['y'] = 4;
  id['m'] = 5;
  id['c'] = 6;
  id['k'] = 7;
  while((cin >> W >> H) && (W || H)) {
    int sx, sy;
    char c;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	cin >> c;
	if(c == '#') {
	  sx = j, sy = i;
	  c = 'w';
	}
	G[i][j] = id[c];
      }
    }
    for(int i = 0; i < 6; ++i) {
      cin >> c;
      order[i] = id[c];
    }
    int ans = bfs(sx, sy);
    if(ans == -1) cout << "unreachable" << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 10e9 + 7;
typedef long long ll;

int main(){
	int sum = 0;
	vector<pair<int,int>> D(5);
	rep(i, 5){
		cin >> D.at(i).second;
		if(D.at(i).second % 10 != 0){
			D.at(i).first = D.at(i).second % 10;
		} else {
			D.at(i).first = 10;
		}
	}
	SORT(D);
	rep(i, 4){
		if(D.at(i + 1).second % 10 != 0){
			D.at(i + 1).second -= (D.at(i + 1).second % 10);
			D.at(i + 1).second += 10;
		}
	}
	rep(i, 5){
		sum += D.at(i).second;
//		cout << D.at(i).second << endl;
	}
	cout << sum << endl;
}

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


#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define piii pair<int,pii>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repc(i,a,n) for(int i=a;i<n;++i)
#define  repd(i,a,n) for(int i=a;i>n;--i)
#define int ll
using namespace std;
using ll = long long;
const ll N = 3*1e5 +5 ;
const ll mod = 1e9+7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
const double pi=3.14159265358979323846 ;
typedef vector<ll> vi;


void solve(){
	int n,m,a;
	cin>>n>>m;
	int sum=0;
	rep(i,m){
		cin>>a;
		sum+=a;
	}
	if(sum<=n){
		cout<<n-sum;
	}
	else cout<<-1;
	return;
	
}
	
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output1.txt", "w", stdout);
	// #endif
	solve(); 
	return  0;
}





Measured memory_bytes: 3644
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 300000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 18;

int n, q, W[N], V[N], SM[N], SM2[N], ADD[N], mark[N], dp[100010], ans[100010];
vector<pair<pii, int>> Q[N];
vi pth;

void DFS(int v){
	if(v > n) return;
	pth.pb(v);
	if (v <= 1024){
		memset(dp, 0, sizeof dp);
		for (int mask = 1; mask < (1 << (pth.size())); mask++){
			SM[mask] = (SM[mask ^ (mask & (-mask))] + V[pth[ADD[mask & (-mask)]]]);
			SM2[mask] = (SM2[mask ^ (mask & (-mask))] + W[pth[ADD[mask & (-mask)]]]);
			if (SM2[mask] < 100010) dp[SM2[mask]] = max(dp[SM2[mask]], SM[mask]);
		}
		for (int i = 1; i < 100010;i ++) dp[i] = max(dp[i], dp[i - 1]);
		for (auto u:Q[v]){
			ans[u.S] = max(ans[u.S], dp[u.F.F] + u.F.S);
		}
	}
	DFS(v * 2);
	DFS(v * 2 + 1);
	pth.pop_back();
}


int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%d", &n);
	int z = 0, p = 1;
	for (int i = 0; i < 18; i++) ADD[p] = z, z ++, p *= 2;
//	cout << "YES " << n << endl;
	for (int i = 1; i <= n; i++){
		scanf("%d %d", V + i, W + i);
	}
	scanf("%d", &q);
	for (int i = 1; i <= q; i++){
		int v, L;
		scanf("%d %d", &v, &L);
		int vv = v;
		vi F;
		while (vv > 1024){
			F.pb(vv);
			vv /= 2;
		}
		for (int mask = 1; mask < (1 << (F.size())); mask++){
			SM[mask] = (SM[mask ^ (mask & (-mask))] + V[F[ADD[mask & (-mask)]]]);
			SM2[mask] = (SM2[mask ^ (mask & (-mask))] + W[F[ADD[mask & (-mask)]]]);
			if (SM2[mask] <= L) Q[vv].pb({{L - SM2[mask], SM[mask]}, i});
		}
		Q[vv].pb({{L, 0}, i});
	}
	DFS(1);
	for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);









	return 0;
}


Measured memory_bytes: 336564
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using iii = pair<int, ii>;
using viii = vector<iii>;

using ll = long long int;
using vc = vector<char>;
using vb = vector<bool>;
using ib = pair<int, bool>;
using vib = vector<ib>;

#define MOD 1000 * 1000 * 1000 + 7
#define INF 1000 * 1000 * 1000
#define EMPTY -10
#define mp(a, b) make_pair(a,b)

bool resuelveCaso() {
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	if (!cin) return false;

	int m = min({ a,b,c,d,e }), n = max({ a,b,c,d,e });

	if (n - m <= k) cout << "Yay!\n";
	else cout << ":(\n";

	return true;
}

int main() {
	while (resuelveCaso()) {}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string s_a = "CODEFESTIVAL2016";
int main(){
  string s;cin>>s;
  int a = 0;
  for(int i = 0; 16 > i; i++){
    if(s_a[i]!=s[i])a++;
  }
  cout << a << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            HashSet<string> S = new HashSet<string>();
            foreach(string x in Console.ReadLine().Trim().Split(' ')) S.Add(x);
            int q = int.Parse(Console.ReadLine());
            int count = 0;
            foreach (string x in Console.ReadLine().Trim().Split(' '))
                count =  S.Contains(x) ? count + 1 : count;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 34432
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int n, r;
    cin >> n >> r;

    if(n >= 10){
        cout << r << endl;
    }
    else{
        cout << r + 100 * (10 - n) << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int MAXV = 400;

int main() {
  ll x;
  cin >> x;
  vector<ll> value(MAXV);
  rep(i, MAXV) {
    value[i] = pow(i, 5);
    // if(i != 0) cout << value[i] - value[i - 1] << endl;
  }

  for (ll i = -MAXV + 1; i < MAXV; ++i) {
    for (ll j = -MAXV + 1; j < MAXV; ++j) {
      // cout << j << endl;
      ll a = value[abs(i)];
      if (i < 0) a = -a;
      ll b = value[abs(j)];
      if (j < 0) b = -b;
      if (a - b == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

vector<int> to[100005];
vector<int> d(100005,-1);
int dfs(int v) {
  if(d[v]!=-1)return d[v];
  for (int u : to[v]) {
    chmax(d[v],dfs(u)+1);
  }
  chmax(d[v],0);
  return d[v];
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }
  int ans = 0;
  rep(i,n)chmax(ans,dfs(i));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7424
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a; i < b; i++)

int main() {

	int n;
	cin >> n;

	vector<double> x(n), y(n), s(n);
	rep(i, 0, n) {
		cin >> x[i] >> y[i];
		s[i] = i;
	}

	int count = 1, m = n;
	while (m > 1) {
		count *=  m;
		m--;
	}

	ll ansx = 0, ansy = 0;
	double ans = 0;
	do {
		rep(i, 0, n - 1) {
			ansx = x[s[i]] - x[s[i + 1]];
			ansx *= ansx;
			ansy = y[s[i]] - y[s[i + 1]];
			ansy *= ansy;
			ans += sqrt(ansx + ansy);
		}
	} while (next_permutation(s.begin(), s.end()));

	ans /= count;

	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}

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

#define MAX_N (100)
#define MAX_C (1000)

int main(int argc, char *argv[]) {
  int N, T, c[MAX_N], t[MAX_N];
  int c_min;
  scanf("%d %d", &N, &T);
  for (int i = 0; i < N; i++)
    scanf("%d %d", &c[i], &t[i]);
  c_min = MAX_C + 1;
  for (int i = 0; i < N; i++)
    if (t[i] <= T && c[i] < c_min)
      c_min = c[i];
  if (c_min <= MAX_C)
    printf("%d\n", c_min);
  else
    printf("TLE\n");
  
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/



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

    int a, b, t; cin >> a >> b >> t;

    cout << b * (t / a) << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int A,B; cin >> A >> B;
    cout << max({A+B,A-B,A*B}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

ll A[100000];
ll B[100000];
int main()
{
	Iint(n); ll s = 0,t=0;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &A[i], &B[i]);
	}
	for (int i = n - 1; i >= 0; --i)
	{
		t = (B[i] - (A[i] + s) % B[i])%B[i];
		s += t;
	}

	std::cout << s;

}











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

using namespace std;
typedef long long ll;

int main() {
    int a,b,c; cin >> a >> b >> c;
    if (a == b || b == c || c == a) {
        if (a == b && b == c) {
            cout << "No\n";
            return 0;
        }
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int x;
  R x;
  cout << "ABC" << x << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int r, c;
    cin >> r >> c;
    int x[r+1][c+1];
    int sum_r, sum_c;
    for (int i = 0; i < r; i++) {
        sum_r = 0;
        for (int j = 0; j < c; j++) {
            cin >> x[i][j];
            sum_r += x[i][j];
        }
        x[i][c] = sum_r;
    }
    for (int i = 0; i <= c; i++) {
        sum_c = 0;
        for (int j = 0; j < r; j++) {
            sum_c += x[j][i];
        }
        x[r][i] = sum_c;
    }
    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            cout << x[i][j];
            if (j < c) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3112
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int sqr(int x) { return x * x; }

int main() {
	int N, D;
	cin >> N >> D;
	
	Vec< Vec< int > > x(N, Vec< int >(D));
	for_(i,0,N) for_(j,0,D) cin >> x[i][j];
	
	int ans = 0;
	for_(i,0,N) for_(j,i+1,N) {
		int sum = 0;
		for_(k,0,D) sum += sqr(x[i][k] - x[j][k]);
		int z = sqrt(sum);
		if (z * z == sum) ++ans;
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {

	
	string s;
	cin >> s;
	REP(i, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;


}


Measured memory_bytes: 256
A,B,C,D=map(int, input().split())

if A % D == 0:
    aoki_turn = A // D
else:
    aoki_turn = A // D + 1

if C % B == 0:
    taka_turn = C // B
else:
    taka_turn = C // B + 1

if taka_turn <= aoki_turn:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,c0=0,c1=0,c2=0,c3=0;
        cin>>n;
        string A;
        for(ll i=0;i<n;i++)
        {
            cin>>A;
            if(A[0]=='A')
            c0++;
            else if(A[0]=='W')
            c1++;
            else if(A[0]=='T')
            c2++;
            else
            c3++;
        }
        cout<<"AC"<<" "<<"x"<<" "<<c0<<endl; 
        cout<<"WA"<<" "<<"x"<<" "<<c1<<endl;
        cout<<"TLE"<<" "<<"x"<<" "<<c2<<endl;
        cout<<"RE"<<" "<<"x"<<" "<<c3<<endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n;

int a[N],dp[N];

int main(){
		
	NFS

	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	dp[2]=abs(a[2]-a[1]);
	
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
	
	cout << dp[n] << endl;	
	
	ioi
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            sc.nextInt();
            while (sc.hasNextInt()) {
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                if (a*a == b*b+c*c) {
                    System.out.println("YES");
                } else if (b*b == c*c+a*a) {
                    System.out.println("YES");
                } else if (c*c == a*a+b*b) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            }
        }
    }
}


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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int N = 200007;

int pref[N], suf[N];

bool good_p[N], good_s[N];

string w;

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    int n, k, c;
    cin >> n >> k >> c;
    cin >> w;
    int maks = 0;
    c++;
    for(int i = 0; i < n; i++){
        if(i-c >= 0) maks = max(maks, pref[i-c]);
        if(w[i] != 'x'){
            pref[i] = maks+1;
        }
    }
    maks = 0;
    for(int i = n-1; i >= 0; i--){
        maks = max(maks, suf[i+c]);
        if(w[i] != 'x'){
            suf[i] = maks+1;
        }
    }
    int wieksze = 0;
    for(int i = 0; i < n; i++){
        if(i-c >= 0){
            if(pref[i-c]+suf[i-c]-1 >= k) wieksze--;
        }
        if(w[i] != 'x'){
            if(wieksze == 0 && pref[i]+suf[i]-1 == k){
                good_p[i] = true;
            }
            if(pref[i]+suf[i]-1 == k) wieksze++;
        }
    }
    wieksze = 0;
    for(int i = n-1; i >= 0; i--){
        if(i+c < n){
            if(pref[i+c]+suf[i+c]-1 >= k) wieksze--;
        }
        if(w[i] != 'x'){
            if(wieksze == 0 && pref[i]+suf[i]-1 == k){
                good_s[i] = true;
            }
            if(pref[i]+suf[i]-1 == k) wieksze++;
        }
    }
    for(int i = 0; i < n; i++){
        //cout << pref[i] << " " << suf[i] << '\n';
        if(good_p[i] && good_s[i]){
            cout << i+1 << '\n';
        }
    }
    
    

	return 0;
}


Measured memory_bytes: 3732
#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[i];

    long long max = *max_element(a.begin(), a.end());
    double mid = max / 2.;
    long long nearest = 0, min = 1e12;
    for(int i = 0; i < n; i++){
        if(min >= abs(mid - a[i]) && a[i] != max){
            min = abs(mid - a[i]);
            nearest = a[i];
        }
    }

    cout << max << " " << nearest << endl;

    return 0;
}

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

const ll MOD = 1e9 + 7;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N+1, 0);
    rep(i, M) {
        int b;
        cin >> b;
        a[b] = 1;
    }

    if (a[N] == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll dp[N + 1] = {};

    dp[0] = 1;
    dp[1] = 1;

    for (int i = 2; i < N + 1; i++) {
        if (a[i - 2] == 1 && a[i - 1] == 1) {
            cout << 0 << endl;
            return 0;
        }
        if (a[i] == 0) {
            if (a[i - 1] == 1 && a[i - 2] == 0) {
                dp[i] = dp[i - 2];
            }
            else if (a[i - 1] == 0 && a[i - 2] == 1) {
                dp[i] = dp[i - 1];
            }
            else {
                dp[i] = dp[i - 2] + dp[i - 1];
            }
        }
        dp[i] %= MOD;
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=1e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline ll read(){
    ll x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
ll n,m,s[N],a[N],res,cnt;
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
	ll L=0,R=2e5+1;
	while(L<R){
		ll mid=L+R+1>>1;
		res=cnt=0;
		for(int i=1;i<=n;i++){
			ll tmp=lower_bound(a+1,a+n+1,mid-a[i])-a;
			cnt+=n-tmp+1,res+=s[n]-s[tmp-1]+a[i]*(n-tmp+1);
		}
		if(cnt>=m) L=mid;
		else R=mid-1;
	} 
	cout<<(res-(cnt-m)*R)<<endl;
	return 0;
}


Measured memory_bytes: 5112
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

char m[255][255];
int n,dp1[255][255],dp2[255][255],dp3[255][255],dp4[255][255];

int main(){
	while(cin>>n&&n){
		rep(i,n){
			fill(dp1[i],dp1[i]+n,0);
			fill(dp2[i],dp2[i]+n,0);
			fill(dp3[i],dp3[i]+n,0);
			fill(dp4[i],dp4[i]+n,0);
		}
		rep(i,n)rep(j,n){cin>>m[i][j];m[i][j]-='0';}
		rep(i,n)rep(j,n)if(m[i][j]){
			dp1[i][j]=(i>0?dp1[i-1][j]+1:1);
			dp2[i][j]=(j>0?dp2[i][j-1]+1:1);
			dp3[i][j]=(i>0&&j>0?dp3[i-1][j-1]+1:1);
			dp4[i][j]=(i>0&&j<n-1?dp4[i-1][j+1]+1:1);
		}
		int ans=0;
		rep(i,n)rep(j,n){
			int a=max(dp1[i][j],dp2[i][j]),b=max(dp3[i][j],dp4[i][j]);
			ans=max(ans,max(a,b));
		}
		cout<<ans<<endl;
	}
}

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

X = [{'idx': i, 'ord': -1, 'val': int(x)} for i, x in enumerate(input().split())]

order = sorted(X, key=lambda x: x['val'])

for i in range(N):
    X[order[i]['idx']]['ord'] = i

for x in X:
    if (x['ord'] < N / 2):
        bi = N // 2
    else:
        bi = (N - 2) // 2
    print(order[bi]['val'])

Measured memory_bytes: 90944
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	string s1 = s;
	reverse(all(s1));
	if(s == s1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

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

  vector<int> v;
  SV(n,v);

  llong ans = INF;
  FOR(i,-100,101){
    llong sum = 0;
    REP(j,n){
      sum += (i - v[j]) * (i - v[j]);
    }
    ans = min(ans, sum);
  }

  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

    public static void main(String[] args) {
        while (sc.hasNext()){
            String alf = sc.next();
            if (alf.equals("-"))
                break;
            int m = sc.nextInt();
            for (int i = 0; i < m; i++){
                int subNum = sc.nextInt();
                String tmpSub = alf.substring(0,subNum);
                String tmp = alf.substring(subNum);
                alf = tmp + tmpSub;
            }
            System.out.println(alf);

        }
    }
}



Measured memory_bytes: 26384
#include<iostream>
using namespace std;
#define int long long

signed main() {
	int K,S;
	cin >> K >> S;
	int answer = 0;
	for(int i = 0;i <= K;i++) {
		for(int j = 0;j <= K;j++) {
			if(S - i - j >= 0 && S - i - j <= K) {
				answer++;
			}
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))

pos_start = bisect_right(a, 0)
neg_end = bisect_left(a, 0)

pos_cnt = n - pos_start
neg_cnt = neg_end

pairs_cnt = n * (n - 1) // 2
pos_pairs_cnt = pos_cnt * (pos_cnt - 1) // 2 + neg_cnt * (neg_cnt - 1) // 2
neg_pairs_cnt = pos_cnt * neg_cnt

if k <= neg_pairs_cnt:
    high = 0
    low = -10 ** 18
    while abs(high - low) > 1:
        mid = (high + low) // 2
        cnt = 0
        r = pos_start
        for l in range(neg_end):
            while r < n and mid < a[r] * a[l]:
                r += 1
            cnt += pos_cnt - (r - pos_start)

        if cnt >= k:
            high = mid
        else:
            low = mid

    print(high)

elif pairs_cnt - pos_pairs_cnt < k:
    k -= (pairs_cnt - pos_pairs_cnt)
    high = 10 ** 18
    low = 0
    while abs(high - low) > 1:
        mid = (high + low) // 2
        cnt = 0
        r = n - 1
        for l in range(pos_start, n):
            while l < r and mid < a[r] * a[l]:
                r -= 1
            cnt += max(0, r - l)
        
        l = 0
        for r in range(neg_end-1, -1, -1):
            while l < r and mid < a[r] * a[l]:
                l += 1
            cnt += max(0, r - l)

        if cnt >= k:
            high = mid
        else:
            low = mid

    print(high)

else:
    print(0)

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

int main(){
    int N,M,C;
    int i,j;
    int A_j;
    int accept=0;
    int judge;
    scanf("%d %d %d",&N,&M,&C);
    int B[M];
    int A[M];
    for(i=0;i<M;i++){
        scanf("%d",&B[i]);
    }
    
    for(i=0;i<N;i++){
        judge=0;
        for(j=0;j<M;j++){
            scanf("%d",&A_j);
            judge+=A_j*B[j];
        }
        judge+=C;
        if(judge>0){
            accept+=1;
        }
    }
    printf("%d\n",accept);
    return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

ll a[60];
ll p(ll n,ll x){//レベルnでx層食べるときのパティの枚数
  if(n==0)return 1;
  if(x==1)return 0;
  if(x==a[n-1]+2)return p(n-1,a[n-1])+1;
  if(x==2*a[n-1]+3)return 2*p(n-1,a[n-1])+1;
  if(1<x && x<a[n-1]+2)return p(n-1,x-1);
  if(a[n-1]+2<x && x<2*a[n-1]+3)return p(n-1,a[n-1])+p(n-1,x-a[n-1]-2)+1;
}

int main(){
  ll n,x;
  a[0] = 1;
  for(int i=1; i<=50; i++){
    a[i] = 2*a[i-1]+3;
  }

  cin >> n >> x;
  cout << p(n,x) << endl;
}

Measured memory_bytes: 256
//xsharawi is back
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
#if !defined(ONLINE_JUDGE)
#include "C:\debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define ins insert
#define vl vector<ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
    speed;
    ll n;
    cin >> n;
    cout << ( n + n * n + n * n * n ) << endl;



















return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define N 500006
#define mo 1000000007
using namespace std;
map<long long,long long>g;
long long n,k,cnt,tot,s[N],t[N],d[N],ls[25*N],rs[25*N],v[25*N];long long ans;
inline long long read()
{
	long long x=0,c=getchar(),f=1;while(c<'0'||c>'9')f=(c=='-'?-f:f),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-48,c=getchar();return f>0?x:-x;
}
void print(long long x)
{
	if(x>9LL)print(x/10LL);putchar(x%10+48);
}
long long build(long long l,long long r)
{
	long long mid=(l+r)>>1,rt=++tot;
	if(l==r)return rt;
	ls[rt]=build(l,mid);
	rs[rt]=build(mid+1,r);
	return rt;
}
void change(long long rt,long long nrt,long long l,long long r,long long x)
{
	v[nrt]=v[rt]+1;if(l==r)return;long long mid=(l+r)>>1;
	if(x<=mid){
		ls[nrt]=++tot;
		rs[nrt]=rs[rt];
		change(ls[rt],ls[nrt],l,mid,x);
	}else{
		rs[nrt]=++tot;
		ls[nrt]=ls[rt];
		change(rs[rt],rs[nrt],mid+1,r,x);
	}
}
long long ask(long long lrt,long long rrt,long long l,long long r,long long x,long long y)
{
	if(x<=l&&r<=y)return v[rrt]-v[lrt];
	long long mid=(l+r)>>1,tmp=0;
	if(x<=mid)tmp=ask(ls[lrt],ls[rrt],l,mid,x,y);
	if(y>mid)tmp+=ask(rs[lrt],rs[rrt],mid+1,r,x,y);
	return tmp;
}
int main()
{
	n=read();k=read();
	for(long long i=1;i<=n;i++)s[i]=s[i-1]+read()-k,d[i]=s[i];
	d[n+1]=0;sort(d+1,d+n+2);d[0]=-2147483647;
	for(long long i=1;i<=n+1;i++)if(d[i]!=d[i-1])g[d[i]]=++cnt;
	t[0]=build(1,cnt);
	for(long long i=1;i<=n;i++)t[i]=++tot,change(t[i-1],t[i],1,cnt,g[s[i]]);
	for(long long i=1;i<=n;i++)ans+=1LL*ask(t[i-1],t[n],1,cnt,g[s[i-1]],cnt);
	printf("%lld\n",ans);
}

Measured memory_bytes: 123392
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int N;
	cin >> N;
	vector<int> a(N), b(N);
	rep(i,N) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(all(a));
	rep(i,N) {
		if(a[N/2] <= b[i])
			cout << a[N/2-1] << endl;
		else
			cout << a[N/2] << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    S = in_s()

    mod = 10**9 + 7
    orda = ord('a')
    ordz = ord('z')
    ans = 1
    for c in range(orda, ordz + 1):
        ans *= (S.count(chr(c)) + 1)
        ans %= mod

    print(ans - 1)


if __name__ == '__main__':
    main()


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n;
  cin >> n;

  string s;
  cin >> s;

  vi h(n), b(n);

  REP(i, n) {
    if (s[i] == '.')
      h[i]++;
    else
      b[i]++;

    if (i > 0) {
      h[i] += h[i - 1];
      b[i] += b[i - 1];
    }
  }

  /*
  REP(i, n) cout << h[i] << " ";
  cout << endl;

  REP(i, n) cout << b[i] << " ";
  cout << endl;
  */

  int ans = n;

  REP(i, n + 1) {
    int a = 0;
    if (i > 0) {
      a += b[i - 1];
      a -= h[i - 1];
    }
    a += h[n - 1];
    ans = min(ans, a);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2196