akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define  p5         100005
#define  p6         1000007
#define  PI         acos(-1)
#define  M          1000000007
#define  sc         scanf
#define  ss         second
#define  ff         first
#define  pf         printf
#define  scin(x)    sc("%d",&x)
#define  scin2(x,y) sc("%d%d",&x,&y)
#define  READ(f)    freopen(f, "r", stdin)
#define  WRITE(f)   freopen(f, "w", stdout)
#define  ll         long long
#define  pp         pair < int, int>
#define  pq         priority_queue
#define  pb         push_back
#define OK          pf("Yes\n")
#define _OK         pf("No\n")
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,i,j,cnt=0;
    string st;
    cin>>st;
    ll ln=st.size();
    for(i=0,j=ln-1;i<ln/2;i++,j--){
        if(st[i]!=st[j])
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
//https://github.com/me-shaon/bangla-programming-resources



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

using ll = long long;
using namespace std;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);

#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}


void init();
void solve();

signed main()
{
	init();
	solve();
}

void init()
{
	int A, B, K;
	cin >> A >> B >> K;
	vector<int> v;
	reps(i, 1, B+1) {
		if (A % i == 0 && B % i == 0) {
			v.PB(i);
		}
	}
	reverse(all(v));
	cout << v[K-1] << endl;
}

void solve()
{
}




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

using namespace std;

int n, m;
std::priority_queue<int> pq;

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

	for (i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		pq.push(x);
	}

	for (i = 0; i < m; i++) {
		int price = pq.top(); pq.pop();
		price /= 2;
		pq.push(price);
	}
	long long sum = 0;

	for (i = 0; i < n; i++) {
		sum += pq.top(); pq.pop();
	}

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

	return 0;
}

Measured memory_bytes: 892
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string a,s,c; cin >> a >> s >> c;
	cout << "A" << s[0] << "C" << endl;
	return 0;
}

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

#define MAX 40
vector<int> pre, in, post;
int n, pos;

void rec(int l, int r){
    if(l >= r)  return;
    int next = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), next));
    rec(l, m);
    rec(m+1, r);
    post.push_back(next);
}

void solve(){
    pos = 0;
    rec(0, pre.size());
    for(int i = 0; i < post.size(); i++){
        if(i)   cout << " ";
        cout << post[i];
    }
    cout << endl;
}

int main(){
    cin >> n;

    int k;
    for(int i = 0; i < n; i++){
        cin >> k;
        pre.push_back(k);
    }

    for(int i = 0; i < n; i++){
        cin >> k;
        in.push_back(k);
    }

    solve();

    return 0;
}



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


int main(){
	int fh, oh, fif, target, result = 0;
	cin >> fh >> oh >> fif >> target;
  for(int i=0;i <= fh ; i++){
    for(int j=0; j <= oh; j++){
      for(int k=0; k <= fif; k++){
        if(target == (i*500 + j*100 + k*50))result++;
      }
    }
  }
  cout << result << endl;
}

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

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

    set<int>values;
    for(int i=0; i < N; ++i)
        values.insert(d[i]);
    cout << values.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll fact[500001];

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll& e){
	e=0;
	if(n==0)return 1;
	ll res=mod_fact(n/p,p,e);
	e+=n/p;
	if(n/p%2!=0){
		return res*(p-fact[n%p])%p;
	}
	return res*fact[n%p]%p;
}

ll mod_comb(ll n,ll k,ll p){
	if(n<0 || k<0 || n<k)return 0;
	ll e1,e2,e3;
	ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
	if(e1>e2+e3)return 0;
	return a1*mod_inverse(a2*a3%p,p)%p;
}

int n,m;

int main(void){
	fact[0]=1;
	for(ll i=1;i<=500000;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	scanf("%d%d",&n,&m);
	ll ans=0;
	for(int i=0;i<=n;i++){
		ll val=mod_comb(m,n,MOD);
		val=val*fact[n]%MOD;
		ll val2=mod_comb(n,i,MOD);
		ll val3=mod_comb(m-i,n-i,MOD);
		val3=val3*fact[n-i]%MOD;
		//printf("%lld %lld %lld\n",val,val2,val3);
		val2=val2*val3%MOD;
		val=val*val2%MOD;
		if(i%2==0){
			ans+=val;
			ans%=MOD;
		}else{
			ans+=MOD-val;
			ans%=MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

int sum[501][501] = {};

int main(){ 
    int n, m, Q;
    scanf("%d %d %d\n", &n, &m, &Q);

    int l, r, p, q;
    for(int i = 0; i < m; i++){
        scanf("%d %d\n", &l, &r);
        sum[l][r]++;
    }

    for(int i = 0; i <= n; i++){
        for(int j = 1; j <= n; j++){
            sum[i][j] += sum[i][j-1];
        }
    }

    for(int i = 0; i < Q; i++){
        scanf("%d %d\n", &p, &q);
        int ans = 0;
        for(int j = p; j <= q; j++){
            ans += sum[j][q] - sum[j][p-1];
        }
        printf("%d\n", ans);
    }

    return 0;
}

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

typedef long long ll;

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


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

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

  ll n; cin>>n;
  map<ll,ll> mp;
  
  for (ll i=2; i<=n; i++) {
    ll x=i;
    for (ll j=2; j*j<=x; j++) {
      while (x%j==0) {
	mp[j]++;
	x=x/j;
      }
    }
    if (x>1) mp[x]++;
  }

  ll res = 1;
  for (auto p: mp) {
    res = res * (p.second+1);
    res %= mod;
  }

  res %= mod;
  res += mod;
  res %= mod;
  cout<<res<<endl;

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#define ll long long
#define inf 20021225
#define N 250010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
const ll mdn = 1000000000000122571ll, bs = 2002122571ll, inv = 938258839498508531ll;
ll mul(ll a,ll b){return (__int128)a*b%mdn;}
ll add(ll a,ll b){return (__int128)(a+b)%mdn;}
map<ll,int> f; char ch[N]; ll ans,val[N],pos[N];
int main()
{
	int n=read(); scanf("%s",ch+1); pos[0]=1;
	for(int i=1;i<=n;i++)
	{
		pos[i]=pos[i-1],val[i]=val[i-1];
		if(ch[i]=='+')	val[i]=add(val[i],pos[i]);
		if(ch[i]=='-')	val[i]=add(val[i],mdn-pos[i]);
		if(ch[i]=='>')	pos[i]=mul(pos[i],bs);
		if(ch[i]=='<')	pos[i]=mul(pos[i],inv);
	}
	for(int i=n;i;i--)
	{
		f[val[i]]++;
		ans+=f[add(mul(val[n],pos[i-1]),val[i-1])];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 35584
import fractions
import math
ans=1
a,b=map(int, input().split())
c=fractions.gcd(a,b)
d = []
for i in range(1, int(c**0.5)+1):
    if a % i == 0 and b % i == 0:
        d.append(i)
        if i != c // i :
            d.append(c//i)
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
for i in d:
    if is_prime(i):
        ans+=1
print(ans)

Measured memory_bytes: 5308
while 1:
    n,c=input(),0
    if int(n)==0:break
    if n.count(n[0])==4:
        print('NA')
        continue
    while n!='6174':
        n=''.join(sorted(n))
        n = str(int(n[::-1]) - int(n)).zfill(4)
        c+=1
    print(c)

Measured memory_bytes: 7600
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#include <iomanip>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 * (a + j) / (b + k) = (x / y)
 * y * (a + j) - x * b = k * x
 * Can we prove that it is better to add j and k whose sum is minimum
 */
int main() {
	int n;
	cin >> n;
	ll a = 0, b = 0;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (i == 0) {
			a = x;
			b = y;
		}
		else {
			ll val1 = (a + x - 1) / x;
			ll val2 = (b + y - 1) / y;
			ll val = max(val1, val2);
			a = x * val;
			b = y * val;
		}
	}
	cout << a + b;
}
		
				


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;

LL fact[20];
string d;
LL d_sum=0, d_prod=1;
int n;
vector<int> cnt(10, 0);
LL ans;
void rec(int k, vector<int> now){
    rep(i, 10){
        if(now[i] == 0) continue;
        if(i > d[k]-'0'){
            return;
        }else{
            if(i > d[k]-'0') return;
            now[i]--;
            if(i == d[k]-'0') rec(k+1, now);
            else{
                LL tmp = fact[n-k-1];
                rep(j, 10) tmp /= fact[now[j]];
                ans += tmp;
            }
            now[i]++;
        }
    }
}
    

void solve(vector<int> now){
    LL n_sum = 0, n_prod = 1;
    rep(i, 10) n_sum+=i*now[i];
    rep(i, 10)rep(j, now[i]) n_prod*=i+1;
    if(n_sum < d_sum || n_sum==d_sum&&n_prod<d_prod){
        LL tmp=fact[n];
        rep(i, 10) tmp /= fact[cnt[i]];
        ans += tmp;
    }else if(n_sum == d_sum && n_prod == d_prod){
        vector<int> rem = now;
        rec(0, rem);
    }
}    

        
void dfs(int k, int st){
    for(int i=st; i<10; i++){
        cnt[i]++;
        if(k == n-1) solve(cnt);
        else dfs(k+1, i);
        cnt[i]--;
    }
}

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

    cin >> d;
    for(auto &x: d) d_sum += x-'0';
    d_prod = 1;
    for(auto &x: d) d_prod *= (x-'0')+1;
    n = d.size();
    fact[0] = 1;
    rep1(i,16) fact[i] = i*fact[i-1];

    dfs(0, 0);
    cout << ans << endl; 
    
}



Measured memory_bytes: 3240
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int a = scanner.nextInt();
        if (x < a) {
            System.out.println("0");
        }else {
            System.out.println("10");
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

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

#define N 1000100
int n, a[N];
int b[N];
map<int, int> F;

int main () {
	cin >> n;
	int S = 0;
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		S ^= a[i];
		b[i] = a[i] ^ (a[i]-1);
	}
	sort(b, b+n);
	int m = unique(b, b+n)-b;
	int T = -1;
	int m2 = m/2;
	for (int p = 0; p < (1<<m2); p ++) {
		int SS = S;
		for (int i = 0; i < m2; i ++)
			if ((p>>i)&1) SS ^= b[i];
		if (F.find(SS) == F.end()) F[SS] = pct(p);
		else F[SS] = min(F[SS], pct(p));
	}
	for (int p = 0; p < (1<<m-m2); p++) {
		int SS = 0;
		for (int i = 0; i < m-m2; i ++)
			if ((p>>i)&1) SS ^= b[i+m2];
		if (F.find(SS) != F.end()) {
			int c = F[SS] + pct(p);
			if (T == -1 || T > c) T = c;
		}
	}
	cout << T << endl;
	return 0;
}

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

const int MOD = 1e9 + 7;
int add(ll x, ll y) {return (x+y) % MOD;}
int sub(ll x, ll y) {return add(x, MOD-y);}
int mul(ll x, ll y) {return (x*y) % MOD;}
int bp(ll x, ll y) {
	int ans = 1;
	while (y) {
		if (y&1) ans = mul(ans, x);
		x = mul(x, x);
		y>>=1;
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	ll a[n], b[n];
	int za = 0, zb = 0, zero = 0;
	map<pii,pii> cnt;
	for (int i=0; i<n; i++) {
		cin >> a[i] >> b[i];
		ll g = __gcd(abs(a[i]), abs(b[i]));
		if (g) a[i] /= g;
		if (g) b[i] /= g;
		ll p, q;
		p = a[i]; q = b[i];
		if (p==0 && q==0) zero++;
		else if (p==0) za++;
		else if (q==0) zb++;
		else if (cnt.count({p, q})) cnt[{p, q}].first++;
		else if (cnt.count({-p, -q})) cnt[{-p, -q}].first++;
		else if (cnt.count({-q, p})) cnt[{-q, p}].second++;
		else if (cnt.count({q, -p})) cnt[{q, -p}].second++;
		else cnt[{p, q}].first++;
	}
	int ca, cb, ans = 1;
	ca = mul(ans, bp(2, za));
	cb = mul(ans, bp(2, zb));
	ans = sub(add(ca, cb), ans);
	for (auto xx : cnt) {
		ca = mul(ans, bp(2, xx.second.first));
		cb = mul(ans, bp(2, xx.second.second));
		ans = sub(add(ca, cb), ans);
	}
	cout << add(sub(ans, 1), zero) << '\n';
}

Measured memory_bytes: 19232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (scan.hasNextLine()) {
			String st = scan.nextLine();
			sb.append(st);
		}
		String st = sb.toString();

		sc(st,'a');
		sc(st,'b');
		sc(st,'c');
		sc(st,'d');
		sc(st,'e');
		sc(st,'f');
		sc(st,'g');
		sc(st,'h');
		sc(st,'i');
		sc(st,'j');
		sc(st,'k');
		sc(st,'l');
		sc(st,'m');
		sc(st,'n');
		sc(st,'o');
		sc(st,'p');
		sc(st,'q');
		sc(st,'r');
		sc(st,'s');
		sc(st,'t');
		sc(st,'u');
		sc(st,'v');
		sc(st,'w');
		sc(st,'x');
		sc(st,'y');
		sc(st,'z');
	}
	static void sc(String st,char cha) {
		int count = 0;
		for ( int i = 0; i < st.length(); i++) {
			if ( cha == st.charAt(i) ||
					Character.toUpperCase(cha) == st.charAt(i) ) {count++;}
		}
		System.out.println(cha + " : " + count);
	}

}

Measured memory_bytes: 26292
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#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
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    vector<int> v(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    int ans = 0 ;
    for(int i = 1; i < n; i++){
        if ( v[i] < v[i - 1] ){
            ans += v[i - 1] - v[i] ;
            v[i] = v[i - 1] ;
        }
        debug() << imie(v) ;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 4748
# -*- coding: utf-8 -*-
import random
random.seed(0)

D = int(input())
C = list(map(int, input().split()))
list_S = [list(map(int, input().split())) for _ in range(D)]

answer = []
L = [0 for _ in range(26)]
for S in list_S:
  contest_index = -1
  contest_manzoku = -10**9
  for i in range(26):
    i_manzoku = S[i]+C[i]+L[i]
    if i_manzoku > contest_manzoku:
      contest_index = i
      contest_manzoku = i_manzoku
  answer.append(contest_index)
  for i in range(26):
    if i==contest_index:
      L[i] = 0
    else:
      L[i] += C[i]

def manzoku(A):
  score = 0
  L = [0 for _ in range(26)]
  for i in range(D):
    contest_index = A[i]
    for j in range(26):
      if j==contest_index:
        L[j] = 0
        score += list_S[i][contest_index]
      else:
        L[j] += C[j]
        score -= L[j] 
  return score

manzoku_now = manzoku(answer)
answer_tmp = [answer[i] for i in range(D)]
for j in range(2000):
  day = j%D
  contest = random.randrange(26)
  answer_tmp[day] = contest
  manzoku_tmp = manzoku(answer_tmp)
  if manzoku_now < manzoku_tmp:
    manzoku_now = manzoku_tmp
    answer[day] = contest
  else:
    answer_tmp[day] = answer[day]

for index in answer:
  print(index+1)

Measured memory_bytes: 78540
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 2000000
#define INF 2000000000
int size;
int A[N];
int left(int i){
  return (i*2);
}
int right(int i){
  return (i*2+1);
}
int parent(int i){
  return floor(i/2);
}

void increase(int i,int key){
  int tmp;
  if(key<A[i]) return;
  A[i] = key;
  while(i>1 && A[parent(i)]<A[i]){
    tmp=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=tmp;
    i = parent(i);
  }
}

void insert(int key){
  size+=1;
  A[size]=-INF;
  increase(size,key);
}

void Heapify(int i){
  int l,r,tmp;
  int largest;
  l = left(i);
  r = right(i);
  if(l <=size && A[l]>A[i]) largest = l;
  else largest = i;
  if(r <=size && A[r]>A[largest]) largest = r;
  if(largest != i){
    tmp = A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    Heapify(largest);
  }
}
int extract(){
  int max;
  if(size<1) return;
  max = A[1];
  A[1] = A[size];
  size-=1;
  Heapify(1);
  return max;
}

int main(){
  char com[100];
  int x,i;
  int A[N];
  size=0;
  while(com[2]!='d'){
    scanf("%s",com);
    if(com[0] == 'i' ){
      scanf("%d",&x);
      insert(x);
    }
    else if (com[1] == 'x'){
      printf("%d\n",extract());
    }
  }
  return 0;
}

Measured memory_bytes: 4696
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e5;
typedef long long LL;

int n, t;
int a[2 * MaxN + 10];
LL ans;

int bin(int x)
{
	if(a[n] <= x) return n;
	int l = 0, r = n;
	int mid = 0;
	while(l <= r - 1)
	{
		mid = (l + r) / 2;
		if(a[mid] <= x)
			l = mid;
		else if(a[mid] > x)
			r = mid;
		if(l == r - 1) return l;
	}
	return mid;
}
int main()
{
	while(scanf("%d %d", &n, &t) != EOF)
	{
		ans = 0;
		for(int i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		//int pos = bin(9);
		//printf("%d\n", pos);
		int l = 1, r = 1;
		int pos = 1;
		int dd = a[1] + t;
		while(true)
		{
			r = bin(dd);
			if(r == pos)
			{
				ans = ans + (LL)(a[r] - a[l] + t);
				l = r + 1;
				r = l;
			}
			if(r == n)
			{
				ans = ans + (LL)(a[r] - a[l] + t);
				l = r + 1;
				r = l;
			}
			if(l > n) break;
			pos = r;
			dd = a[r] + t;
		}
		printf("%lld\n", ans);
		memset(a, 0, sizeof(a));
	}
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)

bool solve() {

	int n; cin >> n;
	if (n == 0)return false;

	vector<string> w(n);
	REP(i, 0, n)cin >> w[i];

	REP(i, 0, n)
	{
		list<int> mojisu{5,7,5,7,7};
		REP(j, i, n)
		{
			mojisu.front()-=w[j].length();
			if (mojisu.front() == 0)
			{
				mojisu.pop_front();
				if (mojisu.empty())
				{
					cout << i + 1 << endl;
					return true;
				}
			}
			else if(mojisu.front() < 0)
			{
				break;
			}
		}
	}
}

signed main() {
	while (solve()) {
	}
	return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
    string S;
    ll K;
    cin >> S >> K;
    v(ll) v;
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i]) ++j;
        v.push_back(j - i);
        i = j;
    }
    if (S[0] != S.back()) {
        ll sum = 0;
        for (auto c : v) sum += c/2;
        cout << sum * K << endl;
    }
    else {
        if (v.size() == 1) cout << v[0] * K / 2 << endl;
        else {
            ll left = v[0], right = v.back(), mid = 0;
            for (int i = 1; i+1 < v.size(); ++i) mid += v[i]/2;
            cout << mid*K + (left+right)/2 * (K-1) + left/2 + right/2 << endl;
        }
    }
}

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

int main() {
  string s; cin >> s;
  cout << (s=="ABC" ? "ARC" : "ABC") << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x;
    }else{
        set<int> st;
        for(int i=0;i<n;i++){
            int a;
            cin>>a;
            st.insert(a);
        }
        if(!st.count(x)){
            cout<<x;
        }else{
            for(int i=1;i<200;i++){
                if(!st.count(x-i)){
                    cout<<x-i<<'\n';
                    break;
                }else if(!st.count(x+i)){
                    cout<<x+i<<'\n';
                    break;
                }
            }
        }


    }




return 0;
}


//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***


Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 20004
#define D 202
using namespace std;
typedef long long ll;
const ll Mod = 1e9 + 7;

int n, d;
ll f[N][D];
char s[N];

ll DP(int len, int now, int op) {
    if (len == 0) return !now;
    if (!op && f[len][now] != -1) return f[len][now];
    int num = s[n - len + 1] - '0';
    ll res = 0;
    for (int i = 0; i <= (op ? num : 9); ++i)
        (res += DP(len - 1, (now - i + d) % d, op & (i == num))) %= Mod;
    if (!op) f[len][now] = res;
    return res;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    memset(f, -1, sizeof f);
    scanf("%s", s + 1);
    n = strlen(s + 1);
    cin >> d;
    cout << ((DP(n, 0, 1) - 1) % Mod + Mod) % Mod;
    return 0;
}


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


#define pb push_back
#define ll long long int
#define mp make_pair
#define mt make_tuple
#define mod 100000
#define for1(k,n) for(ll i=k;i<n;i++)
#define for2(k,n) for(ll j=k;j<n;j++)
#define E cout<<endl
#define max 50000
#define IOS ios_base:: sync_with_stdio(false);cin.tie(0);
//ACTUALLY DIJKSTRA'S ALGORITHM USED FOR FINDING SHORTEST PATH FROM ONE SOURCE TO ALL THE VERTICES OF THE GRAPH......

int main()
{
#ifndef ONLINE_JUDGE
	clock_t tStart = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base:: sync_with_stdio(false);
	cin.tie(0);

//////////////////////////////////////start...............
	//many of the variables are declared globally for not passing to functions.....

	int a;
	cin >> a;

	cout << a + (a * a) + (a * a * a) << endl;





/////////////////////////////end................................... ....


#ifndef ONLINE_JUDGE
	//cout << "\nDone in " << (double) clock() / CLOCKS_PER_SEC << "sec" << endl;
#endif
	return 0;

}

//c v a s selecting text or x for selecting cut
//ctrl+d after selecting text to select same type
//ctrl+shift+d for copy and paste the line below it
//ctrl+del to delete a text
//ctrl+left to jump left of line or vice versa
//ctrl+shift+"/"  to comment whole block and vice versa for undo
//ctrl+"/" for commenting a line


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)

typedef long long ll;
typedef pair<int,int> pii;
const int N = 300010;
ll inv[N],fac[N];
ll mod = 998244353;
ll fastmod(ll b,ll exp){
    ll res=1;
    while(exp){
        if(exp&1ll)res=(res*b)%mod;
        b = (b*b)%mod;
        exp/=2ll;
    }
    return res;
}
ll comb(int n,int r){
    ll ans = (inv[r]*inv[n-r])%mod;
    return (fac[n]*ans)%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j;
    int lim = 3e5+2;
    fac[0]=1;
    for(int i=1;i<=lim;i++)fac[i]=(fac[i-1]*1ll*i)%mod;
    inv[lim]=fastmod(fac[lim],mod-2);
    for(int i=lim-1;i>=0;i--)inv[i]=(inv[i+1]*1ll*(i+1))%mod;

    ll k;
    ll a,b;
    cin>>n>>a>>b>>k;
    ll ans = 0;
    for(int i=0;i<=n;i++)
    {
        ll num = comb(n,i);
        ll mol = k-(1ll*i*a);
        if(mol%b!=0)continue;
        ll reqd = mol/b;
        if(reqd>=0 && reqd<=n){
            num = (num*comb(n,reqd))%mod;
            ans =(ans+num)%mod;
        }
    }
    cout<<ans<<"\n";


    
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N,D;
    cin >> N >> D;
    int m = D * 2 + 1;
    cout << (N-1+m)/m << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
S = [0]*N
S[0] = a[0]

for i in range(1,N):
    S[i] = S[i-1] + a[i]

count = [0]*N
num = [0]*2
for i in range(2):
    value = 0
    for j in range(N):
        if (S[j]+value)*((-1)**(i+j)) <= 0:
            num[i] += abs(S[j] + value - (-1)**(i+j))
            value += (-1)**(i+j) - (S[j]+value)
        #print(i,num,value)

#print(S)
print(min(num))

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

int main(){
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(x>y){
        swap(x,y);
        swap(a,b);
    }
    ll ans=0;
    if(a+b>=2*c){
        ans+=2*c*x;
    }else{
        ans+=(a+b)*x;
    }
    //cout<<ans<<endl;
    if(b>=2*c){
        ans+=2*c*(y-x);
    }else{
        ans+=b*(y-x);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n, x;
int a[100000];

int main(){
  cin >> n >> x;
  rep(i, n) cin >> a[i];
  ll s = accumulate(a, a + n, 0ll);
  rep(i, n - 1){
    a[i + 1] -= min(a[i + 1], max(a[i] + a[i + 1] - x, 0));
    a[i] -= max(a[i] + a[i + 1] - x, 0);
  }
  s -= accumulate(a, a + n, 0ll);
  cout << s << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	char s[100];
	int a[1001]={},b[1001]={},i;
	while(fgets(s,1000,stdin)!=NULL&&strlen(s)>1)a[atoi(s)]++;
	while(fgets(s,1000,stdin)!=NULL&&strlen(s)>1)b[atoi(s)]++;
	rep(i,1001){
		if(a[i]&&b[i])print2(i,a[i]+b[i]);
	}
	return 0;
}


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

int main(){
  double W,H,x,y;
  cin >> W >> H >> x >> y;
  double ans;
  ans=W*H/2;
  cout << ans << " ";
  if(x==W/2&&y==H/2)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;

ll bit[200010];
//ll kai[3010];
ll Cnt[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }



/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/



void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; 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 comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

void makePrimeList(ll x) {
	ll X = x;
	for (ll j = 2; j * j <= x; j++) {
		ll cnt = 0;
		while (X % j == 0) {
			cnt++;
			X /= j;
		}
		if (cnt) {
			Cnt[j] = max(Cnt[j], cnt);
		}
	}
	if (X != 1) Cnt[X] = max(Cnt[X], 1LL);
}

ll N;
ll t[110];
double v[110];
double mx[40010];
double ans;

void solve() {
	cin >> N;
	rep(i, N) {
		cin >> t[i + 1];
		t[i + 1] *= 2;
		t[i + 1] += t[i];
	}
	rep(i, N) {
		cin >> v[i + 1];
		v[i + 1] *= 2;
	}
	rep(i, N) {
		for (ll j = t[i]; j <= t[i + 1]; j++) {
			if (j != 0 && j != t[N] && mx[j] == 0) mx[j] = v[i + 1];
			else mx[j] = min(v[i + 1], mx[j]);
		}
	}
	rep(i, t[N]) mx[i + 1] = min(mx[i] + 1, mx[i + 1]);
	revrep(i, t[N]) mx[i] = min(mx[i + 1] + 1, mx[i]);
	rep(i, t[N]) {
		ans += (mx[i] + mx[i + 1]) / 2;
	}
	ans /= 4;
	printf("%.5lf\n", ans);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 640
#include<cstdio>
using namespace std;
int a,b,c,i,j,n,ans;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for (i=0;i<=a;i++)
     for (j=0;j<=b;j++)
      if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
     int H,W,i,j;
     while(1){
       scanf("%d %d",&H,&W);
       if(W==0&&H==0) break;
       for (i=0;i<W;i++){
          printf("#");
       }
       printf("\n");
       for(i=0;i<H-2;i++){
          printf("#");
          for(j=0;j<W-2;j++){
               printf(".");
          }
          printf("#\n");
        }
     for (i=0;i<W;i++){
          printf("#");
     }
     printf("\n");
     printf("\n");
     }

     return 0;
}

Measured memory_bytes: 588
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    s = [0]
    for i in range(n+1):
        s.append(s[-1]+a[~i])
    s.reverse()
    max_nodes = 1
    ans = 0
    for i in range(n+1):
        if a[i] > max_nodes:
            print(-1)
            return
        ans += min(max_nodes, s[i])
        max_nodes -= a[i]
        max_nodes *= 2

    print(ans)
        
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 20136
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int n,x;
	cin>>n>>x;
	while( n != 0 || x != 0){
		int ans = 0;
		for(int i = 1; i <= n - 2; i++){
			for(int j = i + 1; j <= n-1; j++){
				for(int k = j + 1; k <= n; k++){
					if( i + j + k == x) ans++;
				}	
			}
		}
		cout<<ans<<endl;
		cin>>n>>x;
	}
	return 0;
}




Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    int n;
    cin>>n;
    vector<vector<int>> v(n,vector<int>(3));
    for(int i=0; i<n; i++) cin>>v[i][0]>>v[i][1]>>v[i][2];
    vector<vector<int>> dp(n,vector<int>(3));
    dp[0][0]=v[0][0];
    dp[0][1]=v[0][1];
    dp[0][2]=v[0][2];

    for(int i=1; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(j==k) continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][j]);
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    
    return 0;
}


Measured memory_bytes: 14196
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    H = LI()
    H = sorted(H)
    while K > 0 and len(H) > 0:
        H.pop()
        K -= 1
    print(sum(H))
main()



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

using namespace std;

class UnionFind {
private:
	vector<int> parent;

public:
	UnionFind(int n) : parent(n) {
		for (int i = 0; i < n; ++i) parent[i] = i;
	}
	void unite(int a, int b) {
		parent[root(a)] = root(b);
	}
	int root(int n) {
		if (parent[n] == n) return n;
		return parent[n] = root(parent[n]);
	}
	bool isUnited(int a, int b) {
		return root(a) == root(b);
	}
};

struct Edge {
	int from, to, cost;
};
bool operator<(const Edge& e1, const Edge& e2) {
	return e1.cost < e2.cost;
}

int main() {
	int N, M;
	while ( cin >> N >> M, N || M ) {
		map<int, vector<int> > m;
		for (int i = 0; i < N; ++i) {
			int d; cin >> d;
			m[-d].push_back(i);
		}
		vector<Edge> edges;
		for (int i = 0; i < M; ++i) {
			int from, to, cost; cin >> from >> to >> cost; --from, --to;
			edges.push_back((Edge){from, to, cost});
		}
		sort(edges.begin(), edges.end());

		int ans = 0;
		UnionFind uf(N);
		vector<bool> isAlive(N, false);
		for (map<int, vector<int> >::iterator it = m.begin(); it != m.end(); ++it) {
			vector<int>& ids = it->second;
			for (int i = 0; i < ids.size(); ++i) {
				isAlive[ids[i]] = true;
			}
			for (int i = 0; i < edges.size(); ++i) {
				Edge& e = edges[i];
				if (isAlive[e.from] && isAlive[e.to] && !uf.isUnited(e.from, e.to)) {
					ans += e.cost;
					uf.unite(e.from, e.to);
				}
			}
			bool f = true;
			int id = -1;
			for (int i = 0; i < N; ++i) {
				if (isAlive[i]) {
					id = i;
					break;
				}
			}
			for (int i = 0; i < N; ++i) {
				if (isAlive[i] && !uf.isUnited(i, id)) {
					f = false;
					break;
				}
			}
			if (!f) {
				uf = UnionFind(N);
				ans = 0;
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        string s;
        int x = 0;
        for (int j = 0; j < 2; j++){
            cin >> s;
            int p = (int)s.size();
            for (int i = 0; i < p; i++){
                if (s[i] == 'm'){
                    if (i == 0) x += 1000;
                    else x += (s[i-1] - '0') * 1000;
                }
                else if (s[i] == 'c'){
                    if (i == 0 || s[i-1] == 'm') x += 100;
                    else x += (s[i-1] - '0') * 100;
                }
                else if (s[i] == 'x'){
                    if (i == 0 || s[i-1] == 'c' || s[i-1] == 'm') x += 10;
                    else x += (s[i-1] - '0') * 10;
                }
                else if (s[i] == 'i'){
                    if (i == 0 || s[i-1] == 'x' || s[i-1] == 'c' || s[i-1] == 'm') x++;
                    else x += (s[i-1] - '0');
                }
            }
        }
        if (x > 1999){
            cout << x / 1000 << 'm';
            x -= 1000 * (x / 1000);
        }
        if (x > 999){
            cout << 'm';
            x -= 1000;
        }
        if (x > 199){
            cout << x / 100 << 'c';
            x -= 100 * (x / 100);
        }
        if (x > 99){
            cout << 'c';
            x -= 100;
        }
        if (x > 19){
            cout << x / 10 << 'x';
            x -= 10 * (x / 10);
        }
        if (x > 9){
            cout << 'x';
            x -= 10;
        }
        if (x > 1){
            cout << x << 'i';
            x = 0;
        }
        if (x > 0){
            cout << 'i';
            x = 0;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3164
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];
	
void merge(struct Card A[] , int n , int left , int mid , int right){
	int i,j;
	int n1=mid-left;
	int n2=right-mid;
	
	for(i = 0; i < n1; i++){
		L[i]=A[left+i];
	}

	for(i = 0; i < n2; i++){
		R[i]=A[mid+i];
	}
		
	L[n1].value=R[n2].value=SENTINEL;
	i=0;
	j=0;
		for( int k = left; k < right; k++){
			if(L[i].value<=R[j].value){
				A[k]=L[i++];
			}
			else{
				A[k]=R[j++];
			}
		}
}
	
void mergeSort(struct Card A[], int n, int left, int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}
	
int partition(struct Card A[], int n, int p, int r){
	struct Card x=A[r];
	struct Card temp;
	int i=p-1;
	int j;
	for(j = p; j < r; j++){
		if(A[j].value<=x.value){
			i++;
			temp=A[i];
			A[i]=A[j];
			A[j]=temp;
		}
	}
	temp=A[i+1];
	A[i+1]=A[r];
	A[r]=temp;
	
	return i+1;
}
	
void quickSort(struct Card A[], int n , int p , int r){
		int q;
		if(p<r){
			q = partition(A,n,p,r);
			quickSort(A,n,p,q-1);
			quickSort(A,n,q+1,r);
	}
}	

int main(void){
	int n,i,v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable=1;
	
	scanf("%d",&n);
	
	for(i=0; i<n; i++){
		scanf("%s %d",S,&v);
		
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i=0; i<n; i++){
		if(A[i].suit!=B[i].suit){
			stable=0;
		}
	}
	
	if(stable==1){
		printf("Stable\n");
	}
	else{
		printf("Not stable\n");
	}
	for(i=0; i<n; i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	
	return 0;
}	


Measured memory_bytes: 4060
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    ans = 0
    for i in range(n - 1):
        if A[i + 1] < A[i]:
            ans += A[i] - A[i + 1]
            A[i + 1] = A[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31476
n,m=map(int,input().split())
x=['0' for _ in range(n)]

for _ in range(m):
  s,c=map(int,input().split())
  
  if x[s-1] != '0' and x[s-1] != str(c):
    print(-1)
    exit()
  if s==1 and c==0 and n>1:
    print(-1)
    exit()
  else:
    x[s-1] = str(c)
if n==1:
  print(x[0])
elif x[0]=='0':
  x[0]='1'
  print(''.join(x))
else:
  print(''.join(x))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>

#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(NULL);
        std::cout.tie(NULL);
    }

    int n;
    std::cin >> n;
    std::vector<int> v;
    v.reserve(n + 2);
    for (int i = 0; i <= n; ++i) {
        int a;
        std::cin >> a;
        v.push_back(a);
    }
    auto u = v;
    u.push_back(0);
    for (int i = n - 1; i >= 0; --i)
        u[i] += u[i + 1];
    int ans = 1;
    int x = 1;
    for (int i = 0; i <= n; ++i) {
        x -= v[i];
        if (x < 0) {
            std::cout << -1;
            return 0;
        }
        x = std::min(2 * x, u[i + 1]);
        ans += x;
    }
    std::cout << ans;
    return 0;
}

Measured memory_bytes: 5580