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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li table[26];
bool fixedd[26];

int main() {
    rep(i, 26) {
        table[i] = i;
        fixedd[i] = false;
    }
    string s, t;
    cin >> s >> t;
    li n = sz(s);
    rin{
        li now_s = s[i] - 'a';
        li now_t = t[i] - 'a';
        if (table[now_s] != now_t) {
            if (fixedd[now_s]) {
                puts("No");
                return 0;
            }
            li pos = -1;
            rep(i, 26) {
                if (table[i] == now_t) {
                    pos = i;
                    break;
                }
            }
            if (pos == -1 || fixedd[pos]) {
                puts("No");
                return 0;
            }
            swap(table[now_s], table[pos]);
        }
        fixedd[now_s] = true;
    }
    puts("Yes");
    return 0;
}

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

vector<int> a;
void dfs(int n) {
  a.emplace_back(n);
  if (n >= 3234566668) {
    return;
  }
  string t = to_string(n);
  reverse(t.begin(), t.end());
  int j = t[0] - '0';
  dfs(n * 10 + j);
  if (j + 1 <= 9) {
    dfs(n * 10 + j + 1);
  }
  if (j - 1 >= 0) {
    dfs(n * 10 + j - 1);
  }
}
signed main() {
  int K;
  cin >> K;
  dfs(1);
  dfs(2);
  dfs(3);
  dfs(4);
  dfs(5);
  dfs(6);
  dfs(7);
  dfs(8);
  dfs(9);
  sort(a.begin(), a.end());
  cout << a[K - 1] << endl;
}

Measured memory_bytes: 6564
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int N;
	cin>>N;
	for(int n = 1; n <= N; n++){
		ll ans = 0;
		for(int x = 1; x <= 100; x++){
			for(int y = 1; y <= 100; y++){
				double dx,dy,dn;
				dx = x;
				dy = y;
				dn = n;
				double dz = sqrt(dn - (dx*dx + dy*dy +dx*dy) +((dx+dy)/2)*((dx+dy)/2))-(dx+dy)/2;
				int z = dz;
				if( x*x + y*y + z*z + x*y + y*z + z*x == n && z >= 1){
					ans++;
					//cout<<n<<" "<<x*x + y*y + z*z + x*y + y*z + z*x<<endl;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {

  int n;
  cin >> n;

  deque <int> que;
  string command;
  int x;
  
  for (int i = 0; i < n; i++) {  
    cin >> command;
    if (command == "deleteFirst") {
      que.pop_front();
    } else if (command == "deleteLast") {
      que.pop_back();
    } else if (command == "insert") {
      cin >> x;
      que.push_front(x);
    } else {
      cin >> x;
      for (auto it = que.begin(); it != que.end();) {
        // 条件一致した要素を削除する
        if (*it == x) {
          // 削除された要素の次を指すイテレータが返される。
          que.erase(it);
          break;
        }
        // 要素削除をしない場合に、イテレータを進める
        else {
          ++it;
        }
      }
    }
  }

  while (!que.empty()) {
    cout << que.front();
    que.pop_front();
    if (!que.empty()) {
      cout << " ";
    }
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 7056
n,m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ope = readlines.map{|line| line.split.map(&:to_i)}
a.sort!
ope.sort!{|e,f| f[1] <=> e[1]}

sum = 0

ope.each do |i|
  if a[0] == nil
      break
  elsif a[0] >= i[1]
    sum += a.inject(:+)
    a = [0]
    break
  end
  i[0].times do
    if a[0] == nil
        break
    elsif a[0] < i[1]
      a.shift
      sum += i[1]
    else
      break
    end
  end
end

if a[0] == nil
    puts sum
else
    puts sum + a.inject(:+)
end

Measured memory_bytes: 19192
def main():
    N, M, K = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *P, = accumulate(A)
    *Q, = accumulate(B)

    ans = 0
    j = len(Q) - 1
    for i, x in enumerate(P):
        while j > 0 and x + Q[j] > K:
            j -= 1
        if x + Q[j] <= K:
            ans = max(ans, i + j)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 146360
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n; cin >> n;
    ll k = s.size();
    string ans;
    ll c = 0;
    while(c < k){
        ans += s[c];
        c += n;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

int main()
{
	LL n;
	cin >> n;
	cout << pow(n, 3) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 100000
using namespace std;
int n;
int A[2000010],B[2000010];

void Csort(){
  int cnt[N]={};
  for(int i=0;i<n;i++) cnt[A[i]]++;
  for(int i=1;i<N;i++) cnt[i]+=cnt[i-1];
  for(int i=0;i<n;i++) B[cnt[A[i]]--] = A[i];
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) scanf("%d",&A[i]);
  Csort();
  for(int i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  cout<<endl;
  return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    vector< i64 > A(N);
    cin >> A;
    
    vector< i64 > cnt(N + 1);
    for (auto i : A) cnt[i]++;
    
    i64 ans = 0;
    range(i, 1, N + 1) ans += cnt[i] * (cnt[i] - 1) / 2;
    
    for (auto i : A) {
        if (cnt[i]) cout << ans - cnt[i] * (cnt[i] - 1) / 2 + (cnt[i] - 1) * (cnt[i] - 2) / 2<< endl;
        else cout << ans << endl;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
string str;
int main() {
    for (int i=0; i<3;i++) {
        for (int j=0; j<3;j++) {
            if (i==j) {
                string str_tmp;
                cin >> str_tmp;
                str += str_tmp[i];
            }
        }
    }
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e6+5;
char s[maxn];long long kk,tt;
long long sa[maxn],t[maxn],t2[maxn],c[maxn],n,m;
long long height[maxn],rk[maxn];
void build_sa(long long m){
    long long *x=t,*y=t2;
    for(int i=0;i<=m;i++)c[i]=0;
    for(int i=1;i<=n;i++)c[x[i]=s[i]]++;
    for(int i=1;i<=m;i++)c[i]+=c[i-1];
    for(int i=n;i>0;i--)sa[c[x[i]]--]=i;
    for(int k=1;k<=n;k*=2){
        long long p=0;for(long long i=n-k+1;i<=n;i++)y[++p]=i;
        for(long long i=1;i<=n;i++)if(sa[i]>k)y[++p]=sa[i]-k;
        for(int i=0;i<=m;i++)c[i]=0;
        for(int i=1;i<=n;i++)c[x[y[i]]]++;
        for(int i=1;i<=m;i++)c[i]+=c[i-1];
        for(int i=n;i>=1;i--)sa[c[x[y[i]]]--]=y[i];
        swap(x,y);p=1;x[sa[1]]=1;
        for(int i=2;i<=n;i++)x[sa[i]]=y[sa[i-1]]==y[sa[i]]&&y[sa[i-1]+k]==y[sa[i]+k]?p:++p;
        if(p==n)break;m=p;
    }
}void getHeight(){
    int i,j,k=0;
    for(i=1;i<=n;i++)rk[sa[i]]=i;
    for(i=1;i<=n;i++){
    	if(k>0)k--;
    	j=sa[rk[i]-1];
    	while((i+k<=n)&&(j+k<=n)&&(s[i+k]==s[j+k]))k++;
    	height[rk[i]]=k;
	}
}int main(){
	scanf("%s",s+1);n=strlen(s+1);
	build_sa(127);getHeight();
	tt=1;
	while(tt--){
		long long ss=0,tt=0,tp=0;
		scanf("%d",&kk);
		for(int i=1;i<=n;i++){
			if(tp+n-sa[i]+1-height[i]<kk)tp+=n-sa[i]+1-height[i];
			else{
				tp=kk-tp;ss=sa[i];
				tt=sa[i]+height[i]+tp-1;
				break;
			}
		}if(ss!=0){
			for(int i=ss;i<=tt;i++)printf("%c",s[i]);
			printf("\n"); 
		}else printf("-1\n");
	}
}

Measured memory_bytes: 12544
#include <stdio.h>
#include <algorithm>
long long p = 1000000001;
int r, c, kn;
long long x, y, v, e;
long long s[200000];
long long tv[6000];
long long er[200000];
long long m, l, tx, ty;
long long d[6000][4];
long long z[6000][4];
int main() {
	scanf("%d%d%d", &r, &c, &kn);
	for (int i = 0; i < kn; i++) {
		scanf("%lld%lld%lld", &x, &y, &v);
		x--;
		y--;
		e = x + y;
		e *= 10000;
		e += x;
		e *= p;
		e += v;
		s[i] = e;
	}
	std::sort(s, s + kn);
	for (int i = 0; i <= c + r - 2; i++) {
		m = 0;
		while (l < kn && (s[l] / p / 10000) == i) {
			tx = s[l] / p % 10000;
			tv[tx] = s[l] % p;
			er[m] = tx;
			l++;
			m++;
		}
		for (int j = 0; j < r; j++) {
			for (int k = 0; k <= 3; k++) {
				e = d[j][k];
				if (j + 1 < r) {
					if (tv[j + 1] ) {
						if (z[j + 1][1] < e + tv[j + 1]) {
							z[j + 1][1] = e + tv[j + 1];
						}
					}
					if (z[j + 1][0] < e) {
						z[j + 1][0] = e;
					}
				}
				if (i - j < c) {
					if (tv[j] && k < 3) {
						if (z[j][k + 1] < e + tv[j]) {
							z[j][k + 1] = e + tv[j];
						}
					}
					if (z[j][k] < e) {
						z[j][k] = e;
					}
				}
			}
		}
		for (int j = 0; j < m; j++) {
			tv[er[j]] = 0;
		}
		for (int j = 0; j < r; j++) {
			for (int k = 0; k <= 3; k++) {
				d[j][k] = z[j][k];
				z[j][k] = 0;
			}
		}
		/*for (int j = 0; j < r; j++) {
			for (int k = 0; k < 4; k++) {
				printf("%lld ", d[j][k]);
			}
			printf("\n");
		}
		printf("\n");*/
	}
	e = 0;
	for (int k = 0; k <= 3; k++) {
		if (d[r - 1][k] > e)e = d[r - 1][k];
	}
	printf("%lld\n", e);
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}

class sieve
{
protected:
    int _n;
    std::vector<bool> _f;
public:
    sieve(int n) : _n(n), _f(n+1, true) {
        _f[0] = false;
        _f[1] = false;
        for (int i = 4; i < _f.size(); i+=2)
            _f[i] = false;
        for (int i = 3; i*i < _f.size(); i+=2) {
            if (!_f[i]) continue;
            for (int j = i*i; j < _f.size(); j += i)
                _f[j] = false;
        }
    }
    bool prime(int x) const { return _f[x]; }
    int size() const { return _n; }
};

#define MOD 1000000007

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;

    sieve sv(N);

    ll ans = 1;

    for (int i = 2; i <= N; i++) {
        if (sv.prime(i)) {
            int s = 0;
            for (int j = 1; powi(i, j) <= N; j++)
                s += N / powi(i, j);
            ans = ans * (s + 1) % MOD;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int mp[512][512];

int main()
{
    int w, h, n;
    int s, t;
    
    while (scanf("%d", &n) && n){
        scanf("%d %d", &w, &h);
        
        memset(mp, 0, sizeof(mp));
        
        for (int i = 0; i < n; i++){
            int x, y;
            scanf("%d %d", &x, &y);
            mp[--y][--x]++;
        }
        
        scanf("%d %d", &s, &t);
        
        int r = 0;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                if (i) mp[i][j] += mp[i - 1][j];
                if (j) mp[i][j] += mp[i][j - 1];
                if (i && j) mp[i][j] -= mp[i - 1][j - 1];
                
                int tmp = mp[i][j];
                
                if (i - t >= 0) tmp -= mp[i - t][j];
                if (j - s >= 0) tmp -= mp[i][j - s];
                if (i - t >= 0 && j - s >= 0) tmp += mp[i - t][j - s];
                
                r = max(tmp, r);
            }
        }
        
        printf("%d\n", r);
    }
    
    return (0);
}

Measured memory_bytes: 2220
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n);
	vector<pair<int, int>> c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i] = make_pair(a[i], b[i]);
	}
	sort(c.begin(), c.end());
	long long ans = 0;
	for (int i = 0; i < n; i++) {

		long long x = min(m, c[i].second);
		m -= x;
		ans += x*c[i].first;
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
	int D, G;
	cin >> D >> G; G /= 100;
	vector<int> p(D), c(D);
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i]; c[i] /= 100;
	}
	int res = accumulate(p.begin(), p.end(), 0);
	for (int i = 0; i < (1 << D); i++) {
		int tmp = G, cnt = 0;
		for (int j = 0; j < D; j++) {
			if (i & (1 << j)) {
				cnt += p[j];
				tmp -= p[j] * (j + 1) + c[j];
			}
		}
		for (int j = D; tmp > 0 && j > 0; j--) if ((i & (1 << (j - 1))) == 0) {
			int t = min((tmp + j - 1) / j, p[j - 1]);
			cnt += t;
			tmp -= t * j + (t == p[j - 1] ? c[j - 1] : 0);
		}
		assert(tmp <= 0);
		res = min(res, cnt);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Scanner sc2 = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 1;
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            list.add(sc.nextInt());
        }
        for (int i = 1; i < N; i++) {
            for (int j = 0; j < i+1; j++) {
                if (list.get(i) < list.get(j)) { 
                    break;
                }
                if ( j == i-1) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 25172
/* created   : 2019-10-28 23:57:16
 * accepted  : 2019-10-29 00:16:18
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mt make_tuple
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

vector<int> a;
vector<int> b;
int n;
ll k;

bool check(ll md) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((ll) a[i] * b[i] > md) {
      cnt += max(0ll, a[i] - md / b[i]);
    }
  }
  return cnt <= k;
}

void solve() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  b.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end());
  ll mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, (ll) a[i] * b[i]);
  }
  ll lo = 0;
  ll hi = mx + 1;
  while (lo + 1 < hi) {
    ll md = lo + (hi - lo) / 2;
    if (check(md)) {
      hi = md;
    }
    else {
      lo = md;
    }
  }
  trace(lo, hi, check(lo));
  cout << (check(lo) ? lo : hi) << '\n';
}

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


Measured memory_bytes: 1792
N = int(input())
H = list(map(int, input().split()))
H.reverse()
f = 0
h = H[0]
for i in range(1, N):
  if H[i] >= h + 2:
    print("No")
    f = 1
    break
  else:
    h = min(h, H[i])
if f == 0:
  print("Yes")

Measured memory_bytes: 85372
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    int n;
    bool key = false;;
    
    cin >> n;
    rep(i,n){
        int t;cin >> t;
        if(t%2==1)key = true;
    }
    
    if(key)cout << "first"<<endl;
    else cout << "second"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(isize,isize);n],
        cm: [(isize,isize);m]
    }
    for i in ab.iter() {
        let mut min_dis = std::isize::MAX;
        let mut min_pos = 0;
        for (k, j) in cm.iter().enumerate() {
            let dis = (i.0 - j.0).abs() + (i.1 - j.1).abs();
            if dis < min_dis {
                min_dis = dis;
                min_pos = k + 1;
            }
        }
        println!("{}", min_pos);
    }
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace std;
#define int long long
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n)
	{
    	if(n==1) return true;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
	}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
unsigned int factorial(unsigned int n) 
{ 
    if (n == 0) 
    return 1; 
    return n * factorial(n - 1); 
} 
const int inf=1e17+7;
//const int N=2e5+5;
int dp[100001];
vector<int> graph[100005];
bool visited[100005]={false};
int sieve[1000001];
signed main(){
	FAST
	int n,m;
	cin>>n>>m;
	char a[n][m];
	int b[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
		
		cin>>a[i][j];
		if(a[i][j]=='.'){
			b[i][j]=0;
		}
		else{
			b[i][j]=-1;
		}
	}
	}
	b[0][0]=1;
	int flag=0;
	for(int i=1;i<n;i++){
		if(b[i][0]!=-1 && flag==0){
			b[i][0]=1;
			//flag++;
		}
		else{
			b[i][0]=-1;
			flag++;
		}
		//cout<<b[i][0]<<" ";
	}
	flag=0;
	//cout<<endl;
	for(int i=1;i<m;i++){
		if(b[0][i]!=-1 && flag==0){
			b[0][i]=1;
			//flag++;
		}
		else{
			b[0][i]=-1;
			flag++;
		}
		//cout<<b[0][i];
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			//if(b[i])
			if(b[i][j]!=-1){
			if(b[i-1][j]==-1 && b[i][j-1]==-1){
				b[i][j]=-1;
			}
			else if(b[i-1][j]==-1){
				b[i][j]=b[i][j-1]%mod;
			}
			else if(b[i][j-1]==-1){
				b[i][j]=b[i-1][j]%mod;
			}
			else{
				b[i][j]=(b[i-1][j]%mod+b[i][j-1]%mod)%mod;
			}
			}
			//cout<<b[i][j]<<" ";
		}
		//cout<<endl;
	}
	if(b[n-1][m-1]!=-1)cout<<b[n-1][m-1];
	else cout<<"0";
}

Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
typedef long long ll;

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

    int n;
    cin >> n;
    int d[n];
    rep (i, n) cin >> d[i];

    sort(d, d + n);
    int half = n/2 - 1;
    int res = d[half + 1] - d[half];
    cout << res << endl;
}

Measured memory_bytes: 4020
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int sum = 0;
  vector<int> vec(n);
  REP(i,n) {
    cin >> vec[i];
    sum += vec[i];
  }
  int m1n = sum;
  REP(i,n) m1n = min(m1n, abs(sum - n * vec[i]));
  REP(i,n) {
    if (abs(sum - n * vec[i]) == m1n) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll E = 1E9 + 7;

int main() {
    //frEopEn("input.txt", "r", stdin);
    //frEopEn("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> y[i];
    }
    ll w = x[n - 1] - x[0];
    ll h = y[m - 1] - y[0];
    ll len = w;
    ll tw = 0;
    for (int i = n - 1; i > 0; --i) {
        tw = (tw + len) % E;
        len -= x[i] - x[i - 1];
    }
    len = tw;
    for (int i = 0; i + 1 < n; ++i) {
        len = (len - (n - i - 1) * (x[i + 1] - x[i]) % E + E) % E;
        tw = (tw + len) % E;
    }
    len = h;
    ll th = 0;
    for (int i = m - 1; i > 0; --i) {
        th = (th + len) % E;
        len -= y[i] - y[i - 1];
    }
    len = th;
    for (int i = 0; i + 1 < m; ++i) {
        len = (len - (m - i - 1) * (y[i + 1] - y[i]) % E + E) % E;
        th = (th + len) % E;
    }
    cout << tw * th % E;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var ABC = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (R, G, B) = (ABC[0], ABC[1], ABC[2]);
        var K = int.Parse(ReadLine());

        for (int i = 0; i < K; i++)
        {
            if (G <= R)
                G *= 2;
            else if (B <= G)
                B *= 2;
        }

        if (B > G && G > R)
            WriteLine("Yes");
        else
            WriteLine("No");

    }
}


Measured memory_bytes: 28276
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int W, H;
	cin >> W >> H;
	vector<pair<Int, Int>> cost;
	for (int i = 0; i < W; ++i) {
		Int p; cin >> p;
		cost.emplace_back(p, 0);
	}
	for (int i = 0; i < H; ++i) {
		Int q; cin >> q;
		cost.emplace_back(q, 1);
	}

	sort(cost.begin(), cost.end());
	Int ans = 0;
	Int cntH = 0, cntW = 0;
	for (auto p : cost) {
		if (p.second) {
			ans += p.first * (W + 1 - cntW);
			++cntH;
		} else {
			ans += p.first * (H + 1 - cntH);
			++cntW;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6512
fun main(args:Array<String>):Unit {
    println(Array(readLine()!!.toInt()){
        val (x, y) = readLine()!!.split(' ').map(String::toInt)
        Point(x, y)
    }.sorted().joinToString("\n"))
}
data class Point(val x:Int, val y:Int):Comparable<Point> {
    override fun compareTo(other: Point): Int {
        return if (x == other.x) y.compareTo(other.y) else x.compareTo(other.x)
    }

    override fun toString(): String {
        return "$x $y"
    }
}


Measured memory_bytes: 86080
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n;
    cin >> n;

    int total=0;
    for(int i=1; i<=n; i+=2){
        int count=0;
        for(int j=1; j<=i; j++){
            if(i%j==0){
                count++;
                if(count==8){
                    total++;
                }
            }
        }
    }
    cout << total << endl;
    return 0;
}

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

void solver() {
  int a, b;

  cin >> a >> b;

  int s = min(a, b);
  int c = max(a, b);

  for (int i = 0; i < c; i++) {
    cout << s;
  }
  cout << "\n";
}

int main() {
  solver();
}


Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1
 
for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar
 
print(ans0, ans1)


Measured memory_bytes: 73852
/** MIT License Copyright (c) 2018-2019 Vasilev Daniil **/
#include <bits/stdc++.h>
using namespace std;
template<typename T> using v = vector<T>;
#define int long long
typedef double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
const long double EPS = 1e-11;
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin >>
#define put fout <<
#else
#define get cin >>
#define put cout <<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
int getInt(){int a; get a; return a;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//code starts here

void run() {
	int l, r;
	read(l, r);
	if (r - l + 1 >= 2019)
		put 0;
	else {
		int ans = 2019;
		rep(a, l, r + 1)
			rep(b, a + 1, r + 1)
				ans = min(ans, a * b % 2019);
		put ans;
	}
}
signed main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); put fixed << setprecision(12); run();}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string a,b; cin>>a>>b;
    a+=b;
    int k=stoi(a);
    int x=sqrt(k);
    cout<<(x*x==k? "Yes":"No")<<endl;
}


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

using namespace std;

int main()
{
	long double N,K, ans = 0;
	cin >> N >> K;
	
	for (int i = 1; i < K & i <= N; i++)
	{
		int cur = i;
		long double p = 1;
		while (cur < K)
		{
			cur *= 2;
			p /= 2;
		}
		ans += p;
		
	}
	ans /= N;
	if ((N-K+1)/N > 0)
		ans += (N-K+1)/N;
	printf("%.12Lf", ans);
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(input())

    S = set()
    for _ in range(N):
        s = input().strip()
        S.add(s)
    print(len(S))


if __name__ == "__main__":
    main()


Measured memory_bytes: 31736
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

struct difference{
    int index;
    int dif;

    bool operator<(const difference& ano) const{
        return dif < ano.dif;
    };
};

int main() {
    int n, m; cin >> n >> m;
    if(n > m) n = m;
    vector<int> x(m);
    vector<difference> diff(m);
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());

    //debug
//    for(int i = 0; i < m; i++){
//        cout << x[i] << " ";
//    }
//    cout << endl;

    for(int i = 0; i < m; i++){
        difference tmp;
        if(i == 0) {
            tmp = {0,0};
            diff[i] = tmp;
        }
        else {
            tmp = {i, abs(x[i] - x[i-1])};
            diff[i] = tmp;
        }
    }
    sort(diff.begin(), diff.end());

    vector<int> point(n);
    for(int i = 0; i < n; i++){
        if (i == 0) point[0] = 0;
        else point[i] = diff[m-i].index;
    }
    sort(point.begin(),point.end());

    // debug
//    for(int i = 0; i < n; i++){
//        cout << point[i] << " ";
//    }
//    cout << endl;

    int count = 0;
    for(int i = 0; i < n; i++){
        int minval = x[point[i]];
        int maxval = (i!=n-1) ? x[point[i+1]-1] : x[m-1];
        count += maxval - minval;
    }

    cout << count << endl;
}

Measured memory_bytes: 1792
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] A = new char[H][W];
		Queue<int[]> queue = new ArrayDeque<int[]>();
		for (int i=0;i<H;i++) {
			String row=sc.next();
			for (int j=0;j<W;j++) {
				A[i][j]=row.charAt(j);
				if (A[i][j]=='#') {
					int[] start = {i,j,0};
					queue.add(start);
				}
			}
		}

		int[][] flag = new int[H][W];
		int ans=0;
		//DFS
		int[] dx = {1,-1,0,0};
		int[] dy = {0,0,1,-1};
		loop:while (!queue.isEmpty()) {
			int[] temp=queue.remove();
			int y=temp[0];
			int x=temp[1];
			int depth=temp[2];
			for (int i=0;i<4;i++) {
				if (0<=y+dy[i] && y+dy[i]<=H-1 && 0<=x+dx[i] && x+dx[i]<=W-1) {
					if (flag[y+dy[i]][x+dx[i]]==0 && A[y+dy[i]][x+dx[i]]=='.') {
						flag[y+dy[i]][x+dx[i]]=1;
						int[] queue_add={y+dy[i],x+dx[i],depth+1};
						queue.add(queue_add);
						ans=depth+1;
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 70132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int m = stdIn.nextInt();
		int n = stdIn.nextInt();
		int a[][] = new int[m][n];
		int b[] = new int[n];
		int ans;
		for(int i=0; i < m; i++){
			for(int j=0; j < n; j++){
				a[i][j]=stdIn.nextInt();
			}
		}
		for(int k=0; k < n; k++){
			b[k]=stdIn.nextInt();
		}
		stdIn.close();
		for(int x=0; x < m; x++){
			ans =0;
			for(int y=0; y < n; y++){
			ans+=a[x][y]*b[y];
			}
			System.out.println(ans);
		}
	}
}



Measured memory_bytes: 40388
#include<stdio.h>
#include<string.h>
int main(){
    int i,m,h,x,sum,len,cot;
    char S[201];
    while(1){
        sum = 0;
        cot = 0;
        scanf("%s",S);
        if(strcmp(S,"-") == 0) break;
        scanf("%d",&m);
        for(i=0;i<m;i++){
            scanf("%d",&h);
            sum += h;
        }
        len = strlen(S);
        x = sum % len;
        for(i=x;cot<len;i++){
            cot++;
            printf("%c",S[i]);
            if(cot == len) break;
            if(len-1 == i) i = -1;
        }
        printf("\n");
    }
    return 0;
}


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

namespace AOJ.Volume0
{
    public class Trading
    {
        public static void Main()
        {
            var company = new Dictionary<int, int>();
            var output = new List<int>();

            // 今月
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                int id = int.Parse(input.Substring(0, input.IndexOf(',')));
                if (company.ContainsKey(id)) { company[id]++; }
                else { company.Add(id, 1); }
            }

            // 先月
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                int id = int.Parse(input.Substring(0, input.IndexOf(',')));
                // 出現回数をカウントするが、今月取引がなかった場合は何もしない
                if (company.ContainsKey(id)) { company[id]++; }
                // 出力リストに入っていない場合は今月の取引があるかチェック
                if (!output.Contains(id))
                {
                    if (company.ContainsKey(id)) { output.Add(id); }
                }
            }

            // 出力
            output.Sort();
            foreach (var id in output)
            {
                Console.WriteLine(string.Format("{0} {1}", id, company[id]));
            }
        }
    }
}

Measured memory_bytes: 9748
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        Set<Integer> primeNumberSet = primeNumberSet(Math.max(a, b));
        Map<Integer, Integer> divisorSetA = getDivisorList(a, primeNumberSet);
        Map<Integer, Integer> divisorSetB = getDivisorList(b, primeNumberSet);
        divisorSetB.keySet().forEach(k -> divisorSetA.put(k, Math.max(divisorSetB.get(k), divisorSetA.getOrDefault(k, 0))));
        List<Integer> list = divisorSetA.keySet().stream().map(k -> (int) Math.pow(k, divisorSetA.get(k))).collect(Collectors.toList());
        long n = 1;
        for (int num : list) {
            n = n * num;
        }
        System.out.println(n);
    }

    static Map<Integer, Integer> getDivisorList(int n, Set<Integer> primeNumberSet) {
        return primeNumberSet.stream().filter(f -> f <= n).filter(m -> n % m == 0).collect(Collectors.toMap(m -> m, m -> count(n, m)));
    }

    static Set<Integer> primeNumberSet(int n) {
        if (n < 2) return new HashSet<>();
        return IntStream.rangeClosed(2, n).filter(Main::isPrimeNumber).boxed().collect(Collectors.toSet());
    }

    static boolean isPrimeNumber(int n) {
        if (n == 2) return true;
        if (n % 2 == 0) return false;
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    static int count(int m, int n) {
        int count = 0;
        while (m % n == 0) {
            m = m / n;
            count++;
        }
        return count;
    }
}


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

struct DLL{
  ll x;
  DLL *next;
  DLL *prev;
};

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  DLL *head;
  head = (DLL *)malloc(sizeof(DLL));
  head->x = -1;
  head->next = head;
  head->prev = head;
  for(int i = 0; i < n; i++){
    string comm; ll v;
    cin >> comm;
    if(comm == "insert"){
      cin >> v;
      DLL *x;
      x = (DLL *)malloc(sizeof(DLL));
      x->x = v;
      x->next = head->next;
      head->next->prev = x;
      head->next = x;
      x->prev = head;
    }
    if(comm == "delete"){
      cin >> v;
      DLL *key;
      key = head->next;
      while(1){
        if(key == head) break;
        if(key->x == v){
          key->prev->next = key->next;
          key->next->prev = key->prev;
          free(key);
          break;
        }
        key = key->next;
      }
    }
    if(comm == "deleteFirst"){
      DLL *key = head->next;
      key->prev->next = key->next;
      key->next->prev = key->prev;
      free(key);
    }
    if(comm == "deleteLast"){
      DLL *key = head->prev;
      key->prev->next = key->next;
      key->next->prev = key->prev; 
      free(key);
    }
  }

  DLL* a;
  a = head->next;
  while(a != head){
    if(a->next == head)
      cout << a->x << endl;
    else
      cout << a->x << " ";
    a = a->next;
  }

  return 0;
}

Measured memory_bytes: 32480
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)((x).size())
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
//#define debug(x) cerr << #x << " : " << (x) << " "
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

ll cost[3], D;
ll val[3] = {2, 3, 5};
map<ll, ll> mem;

const ll MAX_ANSWER = 2LL * 60 * 1000000000;

bool overflow(ll a, ll b)
{
    return a > MAX_ANSWER/b;
}

ll f(ll n)
{
    if (n == 1)
        return D;
    if (mem.count(n))
        return mem[n];
    ll &ret = mem[n];
    ret = LLONG_MAX;
    if (!overflow(n, D)) // no division
        ret = n * D;

    for (int i = 0; i < 3; ++i)
    {
        ll mod = n%val[i];
        ll to = (n - mod)/val[i];
        ret = min(ret, f(to) + mod * D + cost[i]);

        mod = val[i] - mod;
        to = (n + mod)/val[i];
        ret = min(ret, f(to) + mod * D + cost[i]);
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    int tc;
    cin >> tc;
    while(tc--)
    {
        mem.clear();
        ll n;
        cin >> n >> cost[0] >> cost[1] >> cost[2] >> D;

        cout << f(n) << '\n';
    }

}

Measured memory_bytes: 4844
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int sum = 0;

		for(int i=0; i<N; i++){
			a[i] = sc.nextInt();
			sum += a[i];
		}

		int dmin = 100*N;
		int frame = -1;
		for(int i=0; i<N; i++){
			int d = Math.abs(sum-(a[i]*N));
			if(d<dmin){
				dmin = d;
				frame = i;
			}
		}
		System.out.println(frame);
	}
}


Measured memory_bytes: 23764
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int[] x = new int[N];
		long ans = 0;
		for(int i = 0; i < N; i++)
			x[i] = sc.nextInt();
		long[][][] dp = new long[N+1][N+1][A*N+1];
		dp[0][0][0] = 1;
		for(int i = 1; i <= N; i++) {
			for(int j = 0; j <= N; j++) {
				for(int k = 0; k <= A*N; k++) {
					dp[i][j][k] = dp[i-1][j][k];
					if(k >= x[i-1] && j >= 1)
						dp[i][j][k] += dp[i-1][j-1][k-x[i-1]];
				}
			}
		}
		for(int j = 1; j <= N; j++)
			ans += dp[N][j][A*j];
		System.out.println(ans);

	}

}

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

int main() {
	
	string s, t;
	cin >> s >> t;
	
	int n = int(s.size());
	int m = int(t.size());
	
	vector<vector<int>> is(26);
	rep(i, n) is[ s[i] - 'a' ].push_back(i);
	rep(i, n) is[ s[i] - 'a' ].push_back(i+n);
	
	ll ans;
	
	int p = 0;
	
	rep(i, m){
		int c = t[i] - 'a';
		if(int(is[c].size()) == 0){
			puts("-1");
			return 0;
		}
		p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
		if(p >= n){
			p -= n;
			ans += n;
		}
		
	}
	ans += p;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
typedef long long ll;
#define PII pair<ll,ll>
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-10;
using namespace std;
int main()
{
	double l;
	scanf("%lf",&l);
	printf("%.12f\n",l*l*l/27);
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]

AB_sort = sorted(AB, key = lambda x: x[1])

A = [x[0] for x in AB_sort]
B = [x[1] for x in AB_sort]

A_cum = np.array(A).cumsum()

for i in range(N):
    if A_cum[i] > B[i]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 59836