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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define mp make_pair

const int N = 3000;
int n, ans;
long long s[100005], prime[3000], opp[100005];
bool used[100005];

vector<long long> p;
map<long long, int> mymap;

void sieve(){
    for(int i = 0; i < 3000; i++)
        prime[i] = 1;
    for(int i = 2; i < 3000; i++){
        if(prime[i] == 1){
            p.pb(i);
            for(int j = 2 * i; j < 3000; j += i)
                prime[j] = 0;
        }
    }
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    sieve();
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> s[i];
    for(int i = 1; i <= n; i++){
        if(s[i] == 1){
            ans = 1;
            used[i] = 1;
            continue;
        }
        for(long long j = 0; j < 3000; j++){
            if(j * j * j == s[i]){
                used[i] = 1;
                ans = 1;
                break;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if(used[i]) continue;
        long long sum1 = s[i], sum2 = 1, sum3 = 1;
        for(int j = 0; j < p.size(); j++){
            if(sum1 % p[j] == 0){
                int times = 0;
                while(sum1 % p[j] == 0){
                    sum1 /= p[j];
                    times++;
                }
                times %= 3;
                for(int l = 1; l <= times; l++)
                    sum3 *= p[j];
                if(times != 0){
                    for(int l = 1; l <= 3 - times; l++)
                        sum2 *= p[j];
                }
            }
        }
        long long rem = sqrt(sum1);
        if(rem * rem == sum1) {sum3 *= rem * rem; sum2 *= rem;}
        else {sum3 *= sum1; sum2 *= sum1 * sum1;}
        s[i] = sum3;
        mymap[sum3]++;
        opp[i] = sum2;
        //cout << s[i] << " " << opp[i] << "\n";
    }
    for(int i = 1; i <= n; i++){
        if(mymap.count(s[i]) == 1){
            if(mymap[s[i]] >= mymap[opp[i]]){
                ans += mymap[s[i]];
                mymap[opp[i]] = 0;
                mymap[s[i]] = 0;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 14336
#include <stdio.h>
typedef long long ll;

ll nC2(ll n){ return n*(n-1)/2; }

int main(){
    ll n, a[200001]={0}, num[200001]={0}, total=0;
    scanf("%lld", &n);
    for(int i=0; i<n; i++){
        scanf("%lld",&a[i]);
        num[a[i]]++;
    }
    for(int i=1; i<=n; i++){
        total += nC2(num[i]);
    }
    for(int i=0; i<n; i++){
        ll ans = total - nC2(num[a[i]]) + nC2(num[a[i]]-1);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 5748
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int sum=0;

vector<int> solve(bitset<13>&used, vector<int>&nums) {
	if (used.count() == 13) {
		return vector<int>{-1};
	}
	else {
		for (int i = 0; i < 13; ++i) {
			if (!used[i]) {
				if (sum % (i + 1)==0) {
					sum+=(i+1)*nums[i];
					used[i] = true;
					auto v(solve(used, nums));
					if (!v.empty()) {
						if (v == vector<int>{-1}) {
							v.clear();
						}
						for (int j = 0; j < nums[i];++j) {

							v.push_back(i);
						}
						return v;
					}
					used[i]=false;
					sum-=(i+1)*nums[i];
				}
			}
		}
		return vector<int>();
	}

}

map<char, int>mp;

int gt() {
	char ch;cin>>ch;
	return mp[ch];
}


int main() {
	int N;cin>>N;
	for (int i = 2; i <= 9; ++i) {
		mp[(i+'0')]=i;
	}
	mp['A']=1;
	mp['T']=10;
	mp['J']=10;
	mp['Q']=10;
	mp['K']=10;
	while (N--) {
		int a(gt());
		int b(gt());
		vector<int>nums(8);
		for (int i = 0; i < 8; ++i) {
			nums[i]=gt();
		}
		bool ace=false;
		int sum=0;
		sum+=a;
		if(a==1)ace=true;
		sum+=b;
		if(b==1)ace=true;

		if (sum == 11&&ace) {
			cout<<"blackjack"<<endl;
		}
		else {
			int k=0;
			while (true) {
				if(sum>=17)break;
				if (ace) {
					if(sum>=8&&sum<=11)break;
				}
				sum+=nums[k];
				if(nums[k]==1)ace=true;
				k++;
			}
			if (sum >= 22) {
				cout<<"bust"<<endl;
			}
			else if (ace&&sum <= 11) {
				cout<<sum+10<<endl;
			}
			else {
				cout<<sum<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3020
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
# p=1,2,3
for p in range(1,4):
    print("{0:.6f}".format(sum([abs(a-b)**p for a,b in zip(X,Y)])**(1/p)))
# p=infinity
print("{0:.6f}".format(max([abs(a-b) for a,b in zip(X,Y)])))


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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	
	int n, a[100], sum = 0, med;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	for(int i = 0; i < n; i++) sum += a[i];
	float m = (float) sum / n;
	med = round(m);

	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += (med - a[i]) * (med - a[i]);
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int D;
int c[27];
int s[410][27];
const int MAX = 26;

int ans[410];

int last[27];
long long dc = 0, score = 0, sum = 0;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> D;

	for(int i = 1; i <= MAX; i++) cin >> c[i], sum += c[i];

	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= MAX; j++){
			cin >> s[i][j];
		}
	}

	for(int i = 1; i <= D; i++){
		int opt = -1; long long inc = -1e18;

		for(int j = 1; j <= MAX; j++){
			if(inc < s[i][j] - (dc + sum) + c[j] * (i - last[j])){
				opt = j;
				inc = s[i][j] - (dc + sum) + c[j] * (i - last[j]);
			}
		}

		cout << opt << "\n";

		dc += sum;
		dc -= c[opt] * (i - last[opt]);
		last[opt] = i;

		score += inc;
		// cout << (i % MAX) + 1 << "\n";
	}

	// cerr << score << "\n";

	return 0;
}

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

int main()
{
    int d,s,t,ans;
    cin>>d>>t>>s;

    ans = s*t;
    if(ans>=d){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }



    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[3];
int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		if (p <= A) cnt[0]++;
		else if (p >= B + 1) cnt[2]++;
		else cnt[1]++;
	}
	cout << min({ cnt[0],cnt[1],cnt[2] }) << endl;
}


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

vector<ll> store;

int main(void){
	ll d,n,m;
	while(cin >> d,d){
		cin >> n >> m;
		store.clear();
		store.push_back(0);
		store.push_back(d);
		
		rep(i,n-1){
			ll arg;
			cin >> arg;
			store.push_back(arg);
		}

		sort(store.begin(),store.end());
		ll ans=0LL;

		rep(i,m){
			ll h;
			cin >> h;
			int idx=lower_bound(store.begin(),store.end(),h)-store.begin();
			ans+=min(abs(h-store[idx]),abs(h-store[idx-1]));
		}
		cout << ans << endl;
	}
	return 0;
}

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

signed main() {
  int a;
  string t;
  cin >> a >> t;
  int b = 0;
  b += (t[0] - '0') * 100;
  b += (t[2] - '0') * 10;
  b += (t[3] - '0') * 1;
  cout << a * b / 100 << endl;
}


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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X;
    --Y;
    int diff[N] = {0};
    int d;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            if (i < X) {
                if (j < X) d = j - i;
                else if (X <= j && j < Y) d = X - i + min(j - X, Y - j + 1);
                else if (Y <= j) d = j - Y + X - i + 1;
            }
            else if (X <= i && i < Y) {
                if (X <= j && j < Y) d = min(j - i, Y - j + i - X + 1);
                else if (Y <= j) d = j - Y + min(Y - i, i - X + 1);
            }
            else {
                d = j - i;
            }
            ++diff[d];
        }
    }

    for (int i = 1; i < N; ++i) {
        cout << diff[i] << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


bool solve(vi&a)
{
	int n=a.size();
	map<int,int> m;
	vi x(3), y(3);

	for(int i=0;i<n;i++)
	{
		m[a[i]]++;
	}

	if(m.size()>3) return false;
	if(m.size()==2)
	{
		if(m[0]*3==n || m[1]*3==n*2) return true;
		return false;
	}
	if(m.size()==1)
	{
		return m[0]==n;
	}

	int i=0;
	for(auto&mm:m)
	{
		x[i]=mm.first;
		y[i]=mm.second;
		i++;
	}
	if((x[0]^x[1])!=x[2]) return false;

	int l=n/3;
	if(y[0]%l || y[1]%l || y[2]%l) return false;
	return true;
}


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi a(n);

		for(int i=0;i<n;i++) scanf("%d", &a[i]);
		bool ans=solve(a);
		printf("%s\n", ans?"Yes":"No");
	}
	return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<map>

using namespace std;

int N;
map<int, int> m;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		m[a]++;
	}
	int ans = 0;
	for (auto i = m.begin(); i != m.end(); i++) {
		if (i->second % 2 != 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
int N;
int a[300001];
ll xsum[300001];
ll nsum[300001];
ll ans = -10000000000000000;
int main() {
  cin >> N;

  for(int i = 0; i < 3 * N; i++) cin >> a[i];

  priority_queue<int> minq;
  priority_queue<int,vector<int>,greater<int> > maxq;

  ll suma = 0;
  ll sumb = 0;
  for(int i = 0; i < N; i++) {
    maxq.push(a[i]);
    minq.push(a[3*N-i-1]);
    suma += a[i];
    sumb += a[3*N-i-1];
  }
  xsum[N-1] = suma;
  nsum[N-1] = sumb;


  for(int i = N; i < 2 * N; i++) {
    maxq.push(a[i]);
    int tmp = maxq.top(); maxq.pop();
  xsum[i] = xsum[i-1] + a[i] - tmp;
  minq.push(a[3*N-i-1]);
  int tmp2 = minq.top(); minq.pop();
  nsum[i] = nsum[i-1] + a[3*N-i-1] - tmp2;
  //cout << nsum[i] << endl;
  }

  for(int i = N-1; i < 2 * N; i++) {
    // cout << xsum[i] << "   " << nsum[3*N-i-2]<<endl;
    ans = max(ans,xsum[i]-nsum[3*N-i-2]);
  }

  cout << ans <<endl;
}
  


Measured memory_bytes: 5236
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;


bool is_operator(string str) {
  return str == "+" || str == "-" || str == "*";
}

int calculate_polish_expression(vector<string> expression) {
  stack<int> s;
  for (auto str : expression) {
    if (is_operator(str)) {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      int res;
      if (str == "+") {
        res = a + b;
      } else if (str == "-") {
        res = b - a;
      } else {
        res = a * b;
      }
      s.push(res);
    } else {
      s.push(stoi(str));
    }
  }
  return s.top();
}

int main() {
  string str;
  getline(cin, str);
  vector<string> expression;
  istringstream istr(str);
  string tmp;
  while (getline(istr, tmp, ' ')) {
    expression.push_back(tmp);
  }
  cout << calculate_polish_expression(expression) << endl;
}

Measured memory_bytes: 1232
#include<stdio.h>

int main(void){
 int H, N;
  scanf("%d %d", &H, &N);
int i, m;
  for(i=0; i<N; i++){
    scanf("%d", &m);
    H -= m;
    if(H<=0){
      break;
    }
  }
  
  if(H<=0){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  vector<int> vec(5, 0);
  for (int i = 0; i < 5; i++  ) { cin >> vec[i]; }
  int K; cin >> K;

  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      if (vec[j] - vec[i] > K) {
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

ll cnt[100001] = {};

int main() {
    ll N, K;
    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        ll a, b;
        scanf("%lld %lld", &a, &b);
        cnt[a] += b;
    }

    ll sum = 0;
    for (int i = 1; i <= 100000; i++) {
        sum += cnt[i];
        if (sum < K) continue;
        cout << i << endl;
        return 0;
    }
    for (int i = 100000; i >= 1; i--) {
        if (cnt[i]) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
main()
{
	long long n, i, a[110], x, y, j, s, p;
	scanf("%lld", &n);
	for (i=0, x=-110, y=110; i<n; i++)
	{
		scanf("%lld", &a[i]);
		if (a[i]>x)
		{
			x=a[i];
		}
		if (a[i]<y)
		{
			y=a[i];
		}
	}
	for (i=y, p=100000000000000000; i<=x; i++)
	{
		for (j=0, s=0; j<n; j++)
		{
			s+=(a[j]-i)*(a[j]-i);
		}
		if (s<p)
		{
			p=s;
		}
	}
	printf("%lld\n", p);
	return 0;
}

Measured memory_bytes: 128
class Comb():
    def __init__(self, N, mod=1):
        self.mod = mod
        fct = [1]
        invfct = [1]
        for i in range(1, N+1):
            fct.append(fct[i-1] * i % mod)
            invfct.append(pow(fct[i], mod-2, mod))
        self.fct = fct
        self.invfct = invfct
    
    def cmb(self, n, k):
        """ Calculate nCk = n! / (k! * (n-k)!) mod self.mod """
        return self.fct[n] * self.invfct[k] * self.invfct[n-k]

    def pam(self, n, k):
        """ Calculate nPk = n! / (n-k)! mod self.mod """
        return self.fct[n] * self.invfct[n-k]
N, M = map(int, input().split())
mod = 10**9 + 7
comb = Comb(N+M, mod)
ans = 0
for k in range(N+1):
    ans += pow(-1, k) * comb.cmb(N, k) * comb.pam(M, k) * pow(comb.pam(M-k, N- k), 2)
    ans %= mod
print(ans)

Measured memory_bytes: 211004
#include<bits/stdc++.h>
using namespace std;
long long a[200005],f[200005],n,k;
bool cmp(long long x,long long y){
    return x>y;
}
bool check(long long x){
    long long sum=0;
    for(int i=1;i<=n;i++){
        if(a[i]*f[i]>x){
            sum+=(a[i]-x/f[i]);
        }
    }
    return sum<=k;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>f[i];
    }
    sort(a+1,a+1+n);
    sort(f+1,f+1+n,cmp);
    long long l=0,r=a[n]*f[1];
    while(r>=l){
        long long mid=(l+r)/2;
        if(check(mid)) r=mid-1;
        else l=mid+1;
    }
    cout<<l<<endl;
}

Measured memory_bytes: 3328
k,s = map(int, input().split())

ans = 0
for i in range(min(s,k)+1):
    for j in range(i,min(s-i,k)+1):
        l = s - i - j
        if k >= l >= j: 
            if i == j and j == l:
                ans += 1
            elif i != j and j!= l and i != l:
                ans += 6
            else:
                ans += 3

print(ans)

Measured memory_bytes: 3064
function Main(input) {
    input = input.split(" ");
    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);
    var ans = a-2*b;

    if(ans >= 0) console.log('%d',ans);
    else console.log(0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

int g(vector<int> a, int b) {
  if (b == 0) return 0;
  long long ret = 0;
  long long pow = 1;
  for (int i = a.size() - 1; i >= 0; i--) {
    if (a[i]) {
      ret = (ret + pow) % b;
    }
    pow = pow * 2 % b;
  }
  return ret;
}
int f(int n) {
  int ret = 0;
  while (n) {
    int c = __builtin_popcount(n);
    n %= c;
    ret++;
  }
  return ret;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string Xs;
  cin >> Xs;
  int pcnt = 0;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    X[i] = Xs[i] - '0';
    pcnt += X[i];
  }
  int n1, n2;
  if (pcnt - 1 > 0) n1 = g(X, pcnt - 1);
  n2 = g(X, pcnt + 1);
  vector<int> pow1(N, 1), pow2(N, 1);
  for (int i = 1; i < N; i++) {
    if (pcnt - 1 > 0) pow1[i] = pow1[i - 1] * 2 % (pcnt - 1);
    pow2[i] = pow2[i - 1] * 2 % (pcnt + 1);
  }
  for (int i = 0; i < N; i++) {
    int p = X[i] ^ 1 ? pcnt + 1 : pcnt - 1;
    int n;
    if (X[i] ^ 1) {
      n = (n2 + pow2[N - 1 - i]) % p;
    } else {
      if (p == 0) {
        cout << 0 << endl;
        continue;
      }
      n = (n1 - pow1[N - 1 - i] + p) % p;
    }
    cout << f(n) + 1 << endl;
  }
  return 0;
}


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

typedef long long ll;
const int MAX = 2001;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

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

    COMinit();

    for (int i = 1; i <= K; i++) {
        if (N - K + 1 < i) {
            cout << 0 << endl;
            continue;
        };

        cout << (COM(N - K + 1, i) * COM(K - 1, i - 1)) % MOD << endl;
    }

    return 0;
}

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

int main()
{
    int n,T,i,j,k;
    cin>>n;
    vector<long long>v(n+3);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    cin>>T;
    while(T--)
    {
        long long b,e,t;
        cin>>b>>e>>t;
        swap_ranges(v.begin()+b,v.begin()+e,v.begin()+t);
    }
   // cout<<"*"<<endl;
    long long ans=0;
    for(i=0;i<n;i++,ans++)
    {
        if(ans!=0)cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
    return 0;
}



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

int main(){
    ll a,b;
    cin >> a >> b;
    if(a == b){
        cout << 0 << endl;
        return 0;
    }
    if((a+b)% 2 == 1){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << (a+b) / 2 << endl;
}

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

int main() {
  long n,a,b,ans;
  cin >> n >> a >> b;
  ans = a*(n/(a+b));
  if(n%(a+b)!=0){
    ans+=min(n%(a+b),a);
  };
  cout << ans << endl;
}

Measured memory_bytes: 256
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
T, A = MI()
H = list(map(lambda x : T - 0.006 * int(x), input().split()))

for i in range(N):
    H[i] = abs(H[i] - A)
    
ans = H.index(min(H)) + 1

print(ans)

Measured memory_bytes: 62980
#include <stdio.h>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    int N, K, R, S, P;
    scanf("%d %d", &N, &K);
    char T[N + 1];
    scanf("%d %d %d", &R, &S, &P);
    scanf("%s", T);

    int points[N+1];
    int i;
    for(i=0;i<=N;i++) {
        points[i] = 0;
    }


    for(i=1;i<=N;i++) {
      if(i >= K && T[i-K-1] != 'x' && T[i-K-1] == T[i - 1]) {
        points[i] = points[i-1];
        if(T[i] == 'r') {
          T[i-1] = 'x';
        } else if(T[i-1] == 's') {
          T[i-1] = 'x';
        } else {
          T[i-1] = 'x';
        }
      } else {
        int point;
        if(T[i-1] == 'r') {
          point = P;
        } else if(T[i-1] == 's') {
          point = R;
        } else {
          point = S;
        }
        points[i] = points[i-1] + point;
      }
    }
    fprintf(stdout, "%d", points[N]);

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int Y, N;
    cin >> N >> Y;
    int a = -1;
    int b = -1;
    int c = -1;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            if(9000 * i + 4000 * j == Y - 1000 * N){
                a = i;
                b = j;
                c = N -i -j;
            }
        }
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
 
int main (){
  int N;
  cin>>N;
  vector<long long>A(N);
  rep(i,N) cin>>A[i];
  long long ans=0;
  rep(i,N-1){
    if(A[i]>A[i+1]){
      ans+=A[i]-A[i+1];
      A[i+1]=A[i];
    }
  }
  cout<<ans;
}

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

const int DUMMY = 1e13;
int op(int l, int r, char c) {
    if (l == DUMMY || r == DUMMY) return DUMMY;
    if (c == '+') return l + r;
    if (c == '-') return l - r;
    if (c == '*') return l * r;
    if (c == '/') return r == 0 ? DUMMY : l / r;
    assert(0);
}
bool is_op(char c) {
    return c == '+' || c =='-' || c == '*' || c == '/';
}

struct expr_t {
    int imd = -1;
    vector<expr_t> vals;
    vector<char> ops;
};
int number(string& s, int& i) {
    int acc = 0;
    while (isdigit(s[i])) {
        acc = acc * 10 + (s[i++] - '0');
    }
    return acc;
}
expr_t expr1(string& s, int& i);
expr_t expr2(string& s, int& i);

expr_t expr1(string& s, int& i) {
    expr_t ret;
    while (i < s.size() && s[i] != ')') {
        if (is_op(s[i])) {
            ret.ops.push_back(s[i++]);
        } else if (s[i] == '(') {
            ret.vals.push_back(expr1(s, ++i));
            i++;
        } else if (s[i] == ')') {
            i++;
            break;
        } else {
            ret.vals.push_back(expr2(s, i));
        }
    }
    return ret;
}
expr_t expr2(string& s, int& i) {
    return expr_t({number(s, i)});
}
set<int> calc(expr_t e) {
    if (e.imd != -1) {
        set<int> ret;
        ret.insert(e.imd);
        return ret;
    }
    assert(e.vals.size() == e.ops.size() + 1);
    int n = e.vals.size();
    vector<vector<set<int>>> dp(n, vector<set<int>>(n));
    function<set<int>(int, int)> dfs = [&](int i, int j) {
        set<int>& ret = dp[i][j];
        if (ret.size() != 0) return ret;
        if (i == j) return ret = calc(e.vals[i]);
        for (int k = i; k < j; k++) {
            set<int> ls = dfs(i, k);
            set<int> rs = dfs(k + 1, j);
            for (int l : ls) {
                for (int r : rs) {
                    ret.insert(op(l, r, e.ops[k]));
                }
            }
        }
        return ret;
    };
    return dfs(0, n - 1);
}
void solve() {
    string s; cin >> s;
    if (s == "#") exit(0);
    int i = 0;
    expr_t res = expr1(s, i);
    set<int> ret = calc(res);
    if (ret.count(DUMMY)) ret.erase(DUMMY);
    cout << ret.size() << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (1) solve();
}


Measured memory_bytes: 3304
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
#define PB push_back
struct t{
    int hr;
    int mi;
    void in(){
        scanf("%d%d",&hr,&mi);
        return ;
    }
    void out(){
        //if(hr<10)printf("0");
        printf("%d:",hr);
        if(mi<10)printf("0");
        printf("%d",mi);
    }
    bool operator !=(t a){
        return !(hr==a.hr&&mi==a.mi);
    }
};
bool cmp(t a,t b){
    return a.hr==b.hr?a.mi<b.mi:a.hr<b.hr;
}
int main(){
    int n;
    t temp;
    vector<t> v;
    scanf("%d",&n);
    while(n--){
        temp.in();
        v.PB(temp);
    }
    scanf("%d",&n);
    while(n--){
        temp.in();
        v.PB(temp);
    }
    sort(v.begin(),v.end(),cmp);
    v[0].out();
    for(int i=1;i<v.size();i++)if(v[i]!=v[i-1]){
        printf(" ");
        v[i].out();
    }
    printf("\n");
}


Measured memory_bytes: 2812
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int r;
  cin >> r;
  if(r<1200){
  cout << "ABC" << endl;
  }else if(r<2800){
  cout << "ARC" << endl;
  }else{
  cout << "AGC" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    string s;
    cin >> s;
    int n = s.size();

    vector<int> ans(n);
    vector<int> p;
    rep(i, n-1) {
        if (s[i]=='R' && s[i+1]=='L') {
            p.push_back(i);
        }
    }
    rep(i, n) {
        auto it = lower_bound(p.begin(), p.end(), i);
        if (s[i]=='L') it--;
        int j = *it;
        if (abs(j-i)%2==0) ans[j]++;
        else {
            ans[j+1]++;
        }
    }

    rep(i, n) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n && n){
		int a=0,b=0;
		
		for(int i=0;i<n;i++){
			int x,y;
			cin>>x>>y;
			if(x>y)a+=x+y;
			else if(x==y){
				a+=x;b+=y;
			}
			else b+=x+y;
		}
		cout<<a<<" "<<b<<endl;
	}
	
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

const int inf = 1e9;

struct sparse_table {
    //0-indexed, init with vector.

    //todo: call init()
    const static int LOG = 18; //todo
    int n;
    vector<int> a[LOG+1];
    vector<int> lg_floor;

    //todo
    int eval(int x, int y) {
	return min(x, y);
    }

    //todo: ll vs int
    void init(vector<int> v) {
	n = v.size();
	lg_floor.resize(n+10);
	lg_floor[1] = 0;
	for (int i=2; i<n+10; i++) lg_floor[i] = 1 + lg_floor[i/2];
	for (int j=0; j<LOG; j++) a[j].resize(n);
	for (int i=0; i<n; i++) a[0][i] = v[i];
	

	for (int j=1; j<LOG; j++) {
	    for (int i=0; i<n; i++) {
		a[j][i] = a[j-1][i];
		if (i + (1<<(j-1)) < n) {
		    a[j][i] = eval(a[j][i], a[j-1][i + (1<<(j-1))]);
		}
	    }
	}
    }

    int get(int l, int r) {
	assert(l<=r);
	int lg = lg_floor[r - l + 1];

	return eval(a[lg][l], a[lg][r-(1<<lg)+1]);
	
    }
};

int n;
vector<int> a, evens, odds;
sparse_table st_a, st_evens, st_odds;
map<int,int> ai;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    a.resize(n);
    for (int i=0; i<n; i++) {
	cin>>a[i];
	ai[a[i]] = i;
    }
    evens = a;
    odds = a;
    for (int i=1; i<n; i+=2) evens[i]=inf;
    for (int i=0; i<n; i+=2) odds[i]=inf;

    st_a.init(a);
    st_evens.init(evens);
    st_odds.init(odds);


    priority_queue<pair<int,pair<int,int>>> pq;//{lo, {l,r}}

    pq.push({-st_evens.get(0, n-1), {0, n-1}});



    auto add = [&](int l, int r) {
	if (l>r) return;
	assert((r-l+1)%2 == 0);
	int lo = l%2==0 ? st_evens.get(l,r) : st_odds.get(l,r);
	pq.push({-lo, {l,r}});
    };


    vector<int> ans;

    while (!pq.empty()) {
	auto cur = pq.top(); pq.pop();
	int x = -cur.first;
	int l = cur.second.first; int r = cur.second.second;
	int i = ai[x];
	
	assert((r-l+1)%2 == 0);
	
	int y = i%2==0 ? st_odds.get(i,r) : st_evens.get(i,r);
	int j = ai[y];
	assert(i<j);

	ans.push_back(x);ans.push_back(y);

	add(l, i-1);
	add(i+1, j-1);
	add(j+1, r);
    }


    for (int x: ans) cout<<x<<" ";
    cout<<endl;  

    return 0;
}


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

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout<<(x-z)/(y+z)<<endl;
}

Measured memory_bytes: 256
X,Y=map(int,input().split())

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

if (X+Y)%3==0 and (X+Y)//3>=abs(X-Y):
    ans=combination((X+Y)//3,( (X+Y)//3 - abs(X-Y) )//2)
    print(ans%1000000007)
else:
    print(0)

Measured memory_bytes: 40428
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node *treeMinimum(Node *x) {
	while (x->left != NIL) x = x->left;
	return x;
}

Node *find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

Node *treeSuccessor(Node *x) {
	if (x->right != NIL) return treeMinimum(x->right);
	Node *y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node *z) {
	Node *y;
	Node *x;

	if (z->left == NIL || z->right == NIL) y = z;
	else y = treeSuccessor(z);

	if (y->left != NIL) {
		x = y->left;
	} else {
		x = y->right;
	}

	if (x != NIL) {
		x->parent = y->parent;
	}

	if (y->parent == NIL) {
		root = x;
	} else {
		if (y == y->parent->left) {
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}

	if (y != z) {
		z->key = y->key;
	}

	free(y);
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	} else {
		if (z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	std::cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	std::cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, x;
	std::string com;

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		std::cin >> com;
		if (com[0] == 'f') {
			std::cin >> x;
			Node *t = find(root, x);
			if (t != NIL)std::cout << "yes" << std::endl;
			else std::cout << "no" << std::endl;
		} else if (com == "insert") {
			std::cin >> x;
			insert(x);
		} else if (com == "print") {
			inorder(root);
			std::cout << std::endl;
			preorder(root);
			std::cout << std::endl;
		} else if (com == "delete") {
			std::cin >> x;
			treeDelete(find(root, x));
		}
	}
}

Measured memory_bytes: 19960
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const int INF = 1e9;


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



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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<double> vec(N);
    double sum=0;
    for(int n=0; n<N; n++) {
        cin >> vec[n];
        sum += vec[n];
    }
    
    sort(vec.begin(), vec.end(), greater<double>());

    if(vec[M-1]<sum/(4*M)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int lim=1e5+7;

set<ll> eval() {
	queue<ll> q;
	for (int i=1; i<10; i++)
		q.push(i);
	set<ll> ret;
	while(1) {
		while(!q.empty()) {
			ll cur=q.front(); q.pop();
			ret.insert(cur);
			if(ret.size()>lim)
				return ret;
			for (int ch=0; ch<=9; ch++) {
				ll nxt=cur; nxt=nxt*10+ch;
				if(ret.count(nxt))
					continue;
				if(abs(cur%10-ch)<=1)
					q.push(nxt);
			}
		}
	}
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int K; cin>>K; K--;
	set<ll> ret=eval();
	while(K-->0) {
		ret.erase(ret.begin());
	}
	cout<<*ret.begin()<<"\n";
	return 0;
}

Measured memory_bytes: 6528
N = int(input())
A = list(map(int,input().split()))
Ansbox = [0]*(N+1)

def count(N,A,Ansbox):

    for i in range(N- 1):
        Ansbox[A[i] - 1] += 1
        
    for i in range(N):
        print(Ansbox[i])
        
count(N,A,Ansbox)

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if((a*b)%2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int[] dish = new int[5];
        int min = 999;
        int tmp;
        int answer = 0;
        for(int i = 0;i<5;i++){
            dish[i] = sc.nextInt();
            if(min > dish[i]%10&&dish[i]%10!=0){
                min = dish[i]%10;
            }
            if(dish[i]%10 != 0){
                tmp = dish[i]/10;
                dish[i] = tmp *10 +10;
            }
        }
        if(min ==999){
            min = 0;
            for(int j = 0;j<5;j++){
            answer+=dish[j];
        }        
        System.out.print(answer);
        }else{
        for(int j = 0;j<5;j++){
            answer+=dish[j];
        }        
        answer = answer + min -10;
        System.out.print(answer);
        }
    }
    
}


Measured memory_bytes: 25044
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
int N, A[100000], locate, total = 0;
cin >> N;
for(int i = 0; i < N; i++) cin >>A[i];
sort(A, A+N);
 
while(locate < N){
int num = A[locate], cnt = 0;
while(locate < N && A[locate] == num) cnt++, locate++;
total += cnt %2;
}
cout << total << endl;
return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define INF 1.0e9
using namespace std;
typedef long long ll;

int N;
const int MAX_N = 10000;
string s[MAX_N];
ll ans = 0;
int hb = 0;
int ta = 0;
int allab = 0;

void count_AB(string str) {
    int size = str.length();
    if (str[0] == 'B') hb++;
    for (int i = 0; i < size - 1; i++){
        if (str[i] == 'A' && str[i+1] == 'B') ans++;
    }
    if (str[size-1] == 'A') ta++;
    if (str[0] == 'B' && str[size-1] == 'A') allab++;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> s[i];
    for (int i = 0; i < N; i++) {
        count_AB(s[i]);
    }
    ans += min(hb, ta);

    if (ta == hb && allab == ta && ta != 0) ans = ans - 1;

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef          double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//result = sin (angle*PI/180);

//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define precision(a) fixed << setprecision(a)
#define mod 1000000007



int main()
{
 //O_O ;
 dl temp=360.0/12.0;
 dl temp2=360.0/60.0;
 dl a,b,c,d;
 cin>>a>>b>>c>>d;
 dl temp3=temp*c+d/2;
 dl temp4=temp2*d,ans=abs(temp3-temp4);
 dl ans9=abs(ans-360);
 //cout<<ans<<"*"<<nn;
 dl mi=min(ans9,ans);
 mi=mi*1.0;
// cout<<mi<<nn;
// cout<<temp3<<ss<<temp4<<"%"<<nn;
 dl ans2 = cos (mi*pi/180.0);
// cout<<ans2<<nn;
dl ans3=ans2*2*a*b;
//cout<<ans3<<nn;
//cout<<ans2<<nn;

dl ans4=sqrt(a*a+b*b-ans3);
//cout<<temp3<<ss<<temp4<<"*"<<ss<<mi<<nn;

 cout<<precision(10)<<ans4<<nn;




    return 0;
}


Measured memory_bytes: 4196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

string s;

int main(){
  cin >> s;
  string ans = "";
  if(s.size() <= 25){
    vector<int> cou(26,0);
    for(char c : s){
      cou[(int)(c - 'a')]++;
    }

    for(int i = 0;i < 26;i++){
      if(cou[i] == 0){
        ans = s;
        ans += (char)(i + 'a');
        break;
      }
    }
  }
  else{
    vector<int> cou(26,0);
    for(char c : s){
      cou[c - 'a']++;
    }
    for(int i = s.size() - 1;i >= 0;i--){
      bool fin = false;
      int now = s[i] - 'a';
      for(int j = now + 1;j <= 25;j++){
        if(cou[j] == 0){
          ans = s.substr(0,i);
          ans += (char)(j + 'a');
          fin = true;
          break;
        }
      }
      if(fin) break;
      cou[now]--;
    }
  }
  if(ans == ""){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    h,w=map(int,input().split())
    n=int(input())
    a=list(map(int,input().split()))
    ans=[[0]*w for _ in range(h)]
    x,y=0,0
    r=False
    for i,v in enumerate(a):
        i+=1
        while v > 0:
            #print("x:{} y:{} = {}".format(x,y,i))
            ans[y][x] = i
            v -= 1
            x = x-1 if r else x+1
            if x < 0 or w <= x:
                r=not r
                x = w-1 if r else 0
                y+=1
    for i in ans:
        print(*i)
    
if __name__ == "__main__":
    main()

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

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

    int n, k;
    cin >> n >> k;
    long double ans = 0;
    for (int i = 1; i <= n; i++) {
        int bonus = (k + i - 1) / i;
        int need_count = 0;
        if (bonus <= 1) {
            need_count = 0;
        } else {
            while (bonus > 1) {
                need_count++;
                bonus++;
                bonus /= 2;
            }
        }
        ans += pow((long double)0.5, (long double)need_count);
    }

    cout << fixed << setprecision(10) << ans / (long double)n << endl;
    return 0;
}

Measured memory_bytes: 384
/*
ID: jerrywcy
LINK:
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

int n;
int v[100];
double ans;

int read(){
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    n=read();
    for (int i=1;i<=n;i++)v[i]=read();
    sort(v+1,v+n+1);ans=v[1];
    for (int i=2;i<=n;i++)ans=(ans+v[i])/2.0;
    printf("%.9lf\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define INF 2000000001
int heap[500001];
int size;

void buildMaxHeap();
void maxHeapify(int);
int main (){
    int n,i,tmp;
    scanf("%d",&n);
    size=n;
    for(i=1;i<=n;i++){
        scanf("%d",&heap[i]);
    }
    buildMaxHeap();
    for(i=1;i<=n;i++){
        printf(" %d",heap[i]);
    }
    printf("\n");
    return 0;
}
void buildMaxHeap(){
    int i;
    for(i=size/2;i>0;i--){
        maxHeapify(i);
    }
}
void maxHeapify(int i){
    int l,r,largest,tmp;
    l=i*2;
    r=i*2+1;
    if(l<=size && heap[l]>heap[i]){
        largest=l;
    }
    else{
        largest=i;
    }
    if(r<=size && heap[r]>heap[largest]){
        largest=r;
    }
    if(largest!=i){
        tmp=heap[i];
        heap[i]=heap[largest];
        heap[largest]=tmp;
        maxHeapify(largest);
    }
}


Measured memory_bytes: 3812
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)

int main()
{
	int a,b;
	cin >> a >> b;
	if(a > 8 || b > 8)
		cout << ":(";
	else
		cout << "Yay!";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
const int inf = 1e9;

int main() {
	string S;
	cin>>S;
	int N=S.size();
	int ans=0;
	int a=inf,b=0;
	rep(i,N){
		if(S[i]=='A')a = min(a,i);
		else if(S[i]=='Z')b =max(b,i);
	}
	ans=b-a+1;
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int n, wt;
int v[100], w[100];
int a[101][10001];

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

	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];

	memset(a, 0, sizeof(a));

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= wt; j++) {
			a[i][j] = a[i - 1][j];
			if (j >= w[i - 1])
				a[i][j] = max(a[i - 1][j - w[i - 1]] + v[i - 1], a[i][j]);
		}
	}

	cout << a[n][wt] << endl;

	return 0;
}


Measured memory_bytes: 7060
N, M = map(int, input().split())
C1 = [0]*(N+1)
C2 = [0]*(N+1)

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        C1[b] +=1
    if b == N:
        C2[a] +=1

for i in range(1,N+1):
    if C1[i]==1 and C2[i]==1:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


Measured memory_bytes: 6132
#include<stdio.h>
#include<stdlib.h>
int max_return(int x,int y){
  if(x>y){
    return x;
  }else{
    return y;
  }
}

int min_return(int x,int y){
  if(x<y){
    return x;
  }else{
    return y;
  }
}

int cost_return(int x,int y,int a,int b){
  if(max_return(x,y)==x){
    return a;
  }
  else{
    return b;
  }
}

int main(){
  int A,B,C,X,Y;
  scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
  int a,b;

  if((A+B)>2*C){
    a=C*2*min_return(X,Y)+abs(X-Y)*cost_return(X,Y,A,B);
    b=C*2*max_return(X,Y);
    if(a<b){
      printf("%d",a);
    }
    else{
      printf("%d",b);
    }
  }else{
    printf("%d",X*A+Y*B);
  }
}



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

double s[105];

int main(){
	int n; 
	cin >> n;
	double ans = 0;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	
	for(int i = 0; i < n; i++){
		ans += 1/s[i];
	}
	printf("%.7lf", 1.0/ans);
	//cout << 1/ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P &p) const {
        return a < p.a;
    }
    int a, b;
};

template <class T>
void chmax(T &a, T b) {
    if (b > a) a = b;
}

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

    int n, t;
    cin >> n >> t;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        p[i] = { a, b };
    }
    sort(p.begin(), p.end());

    int r = 0;
    vector<int> dp(t, 0);

    for (int i = 0; i < n; i++) {
        chmax(r, dp[t - 1] + p[i].b);
        int a = p[i].a;
        int b = p[i].b;
        for (int j = t - 1; j >= a; j--) {
            chmax(dp[j], dp[j - a] + b);
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
n,k,q=n1()
a=n2(q)

b=defaultdict(int)
for i in a:
    b[i]+=1
for i in range(1,n+1):
    p0(k-q+b[i]>0)

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, t; cin >> n >> t;
    vector<int> as(n);
    for (int i = 0; i < n; i++) cin >> as[i];

    int ans = 0;
    for (auto &a: as) {
        static int m = inf, benefit = 0;

        int diff = a - m;
        if (diff > benefit) {
            benefit = diff;
            ans = 1;
        } else if (diff == benefit) {
            ans++;
        }
        m = min(m, a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;

int upb(int n)
{
  int ret=0;
  while(n>0) ret++, n/=2;
  return ret;
}

int main()
{
  for (int n; cin>>n, !(n==0); ){

    vector<vector<int> > pats(n*n+1);
    vector<vector<int> > tmp(n, vector<int>(n, 0));
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	for (int k=i; k<n; k++){
	  for (int l=j; l<n; l++){
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=1;
	    int bd=0;
	    for (int a=0; a<n; a++){
	      for (int b=0; b<n; b++){
		bd=(bd<<1)|tmp[a][b];
	      }
	    }
	    pats[upb(bd)].push_back(bd);
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=0;
	  }
	}
      }
    }

    int bd=0;
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	int t; cin>>t;
	bd=(bd<<1)|t;
      }
    }

    queue<pair<int, int> > mm;
    vector<bool> close(1<<(n*n), false);
    mm.push(make_pair(0, bd));
    close[bd]=true;
    while(!mm.empty()){
      int dep=mm.front().first;
      int cbd=mm.front().second;
      mm.pop();
      //cout<<cbd<<endl;
      int ub=upb(cbd);
      for (int i=0; i<pats[ub].size(); i++){
	int nbd=cbd^pats[ub][i];
	if (nbd==0){
	  for (int i=0; i<=dep; i++)
	    cout<<"myon";
	  cout<<endl;
	  goto _exit;
	}
	//cout<<"*** "<<nbd<<endl;
	if (close[nbd]) continue;
	close[nbd]=true;
	mm.push(make_pair(dep+1, nbd));
      }
    }
  _exit:;
  }
  return 0;
}

Measured memory_bytes: 5836
def main():
    A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = int(input())
    print(A[K-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384