akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int p,q,a;
int sum;

//  p/q >= s/b + 1/x = ( s x + b ) / bx = SXB / bx 
void check( int n ,int s, int b, int x, int bx ){
  if( n==0 )
    return;

  int pbx = p*bx;
  int SXB= s*x + b;
  int qSXB = q * SXB;
  if( pbx == qSXB ){
    ++sum; return;
  } else if( pbx < qSXB )
    return;

  int nBX = bx * x;
  while( nBX<=a ){
    check( n-1, SXB, bx, x, nBX );
    x++; 
    nBX = bx * x;
  }
}

int main(){
  int n,i;

  while( cin>>p>>q>>a>>n && (p||q||a||n) ){
    sum=0;
    for( i=1; p*i < q;i++ ); // Åàå«¢PÊªðßé.
    for( ; i<=a;i++ ){
      check( n,0,1,i, i );
    }
    cout << sum << endl;
  }

  return 0;
}

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

const long long MAX_N = 1e5 + 5e4 + 5, inf = 1e9 + 7;
long long n;
long long Arr[MAX_N];
long long P[MAX_N];
long long psum[MAX_N];
long long cnt[MAX_N];
long long dp[MAX_N];

void process(long long d) {
	memset(cnt, 0, sizeof cnt);
	memset(dp, 0, sizeof dp);
	for (long long i = 1; i <= n; i++) {
		P[i] = (d <= Arr[i]? +1: -1);
		psum[i] = P[i] + psum[i - 1];
	}
}

long long calc(long long d) {
	long long res = 0;
	cnt[50000] = 1;
	
	for (long long i = 1; i <= n; i++) {
		dp[i] = dp[i - 1];
		if (P[i] == +1)
			dp[i] += cnt[50000 + psum[i - 1]];
		else
			dp[i] -= cnt[50000 + psum[i]];
			
		res += dp[i] + cnt[50000+ psum[i]];
		cnt[50000+ psum[i]]++;
	}
	
	return res;
}

int main() {
	scanf("%d", &n);
	for (long long i = 1; i <= n; i++)
		scanf("%d", &Arr[i]);
	
	long long s = 1, e = inf;
	while (e - s > 1) {
		long long mid = e + s >> 1;
		
		process(mid);
		if (calc(mid) < ((((n * (n + 1)) >> 1) + 1) >> 1))
			e = mid;
		else
			s = mid;
	}
	
	printf("%d\n", s);
	return 0;
}

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

int main() {
  string s;
  cin >> s;

  for(int i=0;i<s.size();i++) {
    if(i == 0 || i == s.size()-1) {
      cout << s[i];
    } else if (i == s.size()-2) {
      cout << s.size() - 2;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
import numpy as np

n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k - q]*(n+1)

for i in range(q):
  score[a[i]] += 1

for i in range(1,n+1):
  if score[i] > 0:
    print('Yes')
  else:
    print('No')

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	vector<int64> l(N);
	REP(i, N) cin >> l[i];
	sort(all(l));
	int64 sum = 0;
	REP(i, N-1) sum += l[i];
	cout << (l[N-1] < sum ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break
    cards = [n-i for i in range(n)]
    for i in range(r):
        p, c = map(int, input().split())
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
    print(cards[0])



Measured memory_bytes: 5616
//arc060_c.cpp
//Sat Jun 23 13:19:44 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int n,a,X;
int x[50];
ll dptable[51][51][2501];

int main(){
	cin >> n >> a;
	X = a;
	for (int i=0;i<n;i++){
		cin >> x[i+1];
		X = max(X,x[i+1]);
	}

	for (int j=0;j<=n;j++){
		for (int k=0;k<=n;k++){
			for (int s=0;s<=2500;s++){
				if (j==0 && k==0 && s==0){
					dptable[j][k][s] = 1;
				}else if (j>=1 && s<x[j]){
					dptable[j][k][s] = dptable[j-1][k][s];
				}else if (j>=1 && k>=1 && s>=x[j]){
					dptable[j][k][s] = dptable[j-1][k][s] + dptable[j-1][k-1][s-x[j]];
				}else {
					dptable[j][k][s] = 0;
				}
			}
		}
	}

	ll ans = 0;

	for (int k=1;k<=n;k++){
		ans += dptable[n][k][k*a];
	}

	cout << ans << endl;
}

Measured memory_bytes: 51072
n, x = map(int, input().split())
L = [int(i) for i in input().split()]

out = 0
diff = 0
for i in range(n-1):
  if L[i] > x:
    diff = L[i] - x
    out += diff
    L[i] = x
  if L[i] + L[i+1] > x:
    diff = L[i] + L[i+1] - x
    out += diff
    L[i+1] = x - L[i]
print(out)

Measured memory_bytes: 14132
h, w = map(int, input().split())
r = [list(input()) for i in range(h)]
for i in range(h):
    if not '#' in r[i]:
        r[i] = 'Nan'
r = [i for i in r if i != 'Nan']
l = list(map(list, zip(*r)))
for i in range(len(l)):
    if not '#' in l[i]:
        l[i] = 'Nan'
l = [i for i in l if i != 'Nan']
l = list(map(list, zip(*l)))
for i in range(len(l)):
    print(''.join(l[i]))


Measured memory_bytes: 3316
def get_input():
    while True:
        try:
            yield ''.join(raw_input().strip())
        except EOFError:
            break
inlist = list(get_input())
instr = "".join(inlist)
instr = instr.lower()
ascstart = 97
ascfin = 122
strlist = [0 for i in xrange(97,122+1)]
# print len(strlist)
for x in xrange(len(instr)):
    if ord(instr[x]) < ascstart or ord(instr[x]) > ascfin:
        continue
    strlist[ord(instr[x])-ascstart] +=1

for x in xrange(ascstart,ascfin+1):
    print "%s : %d" % (chr(x),strlist[x-ascstart])

Measured memory_bytes: 6388
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) cin >> S[i];
    UnionFind uf(H*W);

    REP(y, H-1) {
        REP(x, W-1) {
            if(S[y][x+1] != S[y][x]) uf.merge(y*W + x, y*W + (x+1));
            if(S[y+1][x] != S[y][x]) uf.merge(y*W + x, (y+1)*W + x);
        }
        if(S[y+1][W-1] != S[y][W-1]) uf.merge(y*W + W-1, (y+1)*W + W-1);
    }

    REP(x, W-1) if(S[H-1][x+1] != S[H-1][x]) uf.merge((H-1)*W + x, (H-1)*W + (x+1));

    set<ll> parents;
    map<ll, ll> white, black;
    REP(y, H) REP(x, W) {
        parents.insert(uf.root(y*W+x));
        if(S[y][x] == '#') black[uf.root(y*W+x)]++;
        else white[uf.root(y*W+x)]++;
    }
    ll ans = 0;
    
    // (H-1) * W + (W-1) = H*W - 1
    for(ll p: parents) {
        ans += black[p]*white[p];
    }

    cout << ans << endl;

    return 0;
}

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

int N, X, Y, ans[1 << 18], dist[1 << 18];
vector<int> G[1 << 12];

int main() {
	cin >> N >> X >> Y;
	G[X].push_back(Y);
	G[Y].push_back(X);
	for (int i = 1; i <= N - 1; i++) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) dist[j] = (1 << 30);
		dist[i] = 0; queue<int>Q; Q.push(i);
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			for (int j : G[pos]) {
				if (dist[j] != (1 << 30)) continue;
				dist[j] = dist[pos] + 1;
				Q.push(j);
			}
		}
		for (int j = i + 1; j <= N; j++) ans[dist[j]]++;
	}
	for (int i = 1; i <= N - 1; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void)
{
    char S[1005];
    scanf("%s", S);

    int len = strlen(S);
    if(S[len-1]=='s') {
        strcat(S, "es");
    } else {
        strcat(S, "s");
    }
    printf("%s", S);
    return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        boolean A = false;
        boolean B = false;
        for(int i = 0; i < s.length; i++) {
            if(s[i] == 'A') A = true;
            if(s[i] == 'B') B = true;
        }
        if(A && B)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

}


Measured memory_bytes: 22740
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < (n); i++)

int main()
{
    int h, n;
    cin >> h >> n;

    int A[n], B[n];
    repi(i, n, 0)
    {
        cin >> A[i] >> B[i];
    }
    int dp[n + 1][h + 1];
    fill(dp[0], dp[n + 1], INF);
    dp[0][0] = 0;
    repi(i, n, 0)
    {
        repi(j, h + 1, 0)
        {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);                                          //i番目を使った時と使わなかったときのjダメージの最小
            dp[i + 1][min(j + A[i], h)] = min(dp[i + 1][min(j + A[i], h)], dp[i + 1][j] + B[i]); //i番目を使った時と使わなかったときのj+Aiダメージの最小
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 39296
char era[1000000]={1,1};
main(){
	int i,j,n,c;
	for(i=2;i<1000;i++)	if(!era[i])	for(j=i*i;j<1000000;j+=i)	era[j]=1;
	while(~scanf("%d",&n)){
		c=0;
		for(i=0;i<=n;i++)	if(!era[i])	c++;
		printf("%d\n",c);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int MOD = 1000000007;

int counter(int x){
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    int N;
    cin >> N;
    vector<int>state(N,1);

    vector<vector<pair<int,int>>> comments;
    rep(i, N){
        int n;
        cin >> n;
        comments.push_back(vector<pair<int,int>>());
        rep(j, n){
            int x, y;
            cin >> x >> y;
            comments[i].push_back(make_pair(--x,y));
        }
    }

    // cout << "input comments" << endl;
    // for(auto& v: comments) {
    //     for(auto& p: v) 
    //         cout << "(" << p.first << "," << p.second << ")" << endl;
    // }

    int result = 0;
    // 全探索をおこなう。矛盾がないケースの正直者の数の最大値を返す
    for(int bit = 0; bit < (1<<N); ++bit){
        bool status = true;
        // cout << "check state" << endl;
        // for(auto& s: state) cout << s;
        // cout << endl;
        rep(i, N){
            if(!(bit & (1 << i))) continue;
            for(auto& p: comments[i]) {
                if(((bit >> (p.first)) & 1) ^ p.second) status = false;
            }
        }
        // cout << bit << ": " << status << endl;
        if(status == true) {
            result = max(result, counter(bit));
        }
    }
    cout << result << endl;
    return;
}

int main() {
    solve();
    return 0;

}

Measured memory_bytes: 256
s = input()
k = int(input())

#正解(全列挙してソートしてる)
sub_string=[]
for i in range(len(s)):
  for j in range(1,k+1):
    sub_string.append(s[i:i+j])
sub_string=list(set(sub_string))
sub_string.sort()
print(sub_string[k-1])

Measured memory_bytes: 5068
#include <iostream>
#include <vector>

using namespace std;

int main(){
    long long N;
    cin >> N;

    long long ans;

    for (long long i = 1; i * (i + 2) <= N; i++){
        if ((N - i) % i == 0){
            ans += (N - i) / i;
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, n, v, x, y, z, dx, dy;
  char *p, buf[32];
  buf[31]=0;
  buf[30]='\n';
  fgets(buf, 32, stdin);
  for (n=0,p=buf; *p!=' '; n=n*10+*(p++)-'0'); 
  int s[n], d[n];
  for (i=0; i<n; s[i]=i,d[i++]=0);
  while (fgets(buf, 32, stdin)) {
    for (x=0,p=buf+2; *p!=' '; x=x*10+*(p++)-'0');
    for (y=0,p++; *p>='0'; y=y*10+*(p++)-'0');
    if (buf[0]=='0') { // relate x y z
      for (z=0,p++; *p!='\n'; z=z*10+*(p++)-'0');
      for (dx=0; s[x]!=x; dx+=d[x],x=s[x]);
      for (dy=0; s[y]!=y; dy+=d[y],y=s[y]);
      if (x<y) {
	s[y] = x;
	d[y] = dx + z - dy;
      }	else if (x>y){
	s[x] = y;
	d[x] = dy - z - dx;
      } else continue;
    } else { // diff
      for (v=0; s[x]!=x; v-=d[x], x=s[x]);
      for (;s[y]!=y; v+=d[y], y=s[y]);
      if (x!=y) {
	putc_unlocked('?', stdout);
	putc_unlocked('\n', stdout);
      } else {
	i=30;
	if (v>0)  for (; v>0; buf[--i]='0'+v%10,v/=10);
	else if (v<0) {
	  for (; v<0; buf[--i]='0'-v%10,v/=10);
	  buf[--i] = '-';
	} else  buf[--i] = '0';
	fputs_unlocked(buf+i, stdout);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2392
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

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

	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}

	sort(v.begin(),v.end());
	int ans=0;
	for(int i=0;i<k;i++){
		ans+=v[i];
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int main(){
	int N,A,B;
	cin>>N>>A>>B;
	if(abs(A-B)%2==0){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Borys"<<endl;
	}
	return(0);
}

Measured memory_bytes: 764
#include<stdio.h>
#include<string.h>
int main(void)
{
  int len,n=0,w=0,s=0,e=0;
  char str[1010];
  scanf("%s",str);
  len=strlen(str);
  for(int i=0;i<len;i++){
    switch(str[i]){
      case 'N':n++;break;
      case 'W':w++;break;
      case 'S':s++;break;
      case 'E':e++;break;
    }
  }
  puts((n==0&&s!=0)||(s==0&&n!=0)||(w==0&&e!=0)||(e==0&&w!=0)?"No":"Yes");
  return 0;
}


Measured memory_bytes: 128
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,k;
ll a[100111];
ll pre[100111],suf[100111];
int main()
{
	getii(n,k);
	for(int i=1;i<=n;i++)geti(a[i]);
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+max(a[i],0ll);
	for(int i=n;i>=1;i--)suf[i]=suf[i+1]+max(a[i],0ll);
	for(int i=1;i<=n;i++)a[i]+=a[i-1];
	ll ans=-4e18;
	for(int i=1;i<=n-k+1;i++)
	{
		ans=max(ans,max(0ll,a[i+k-1]-a[i-1])+pre[i-1]+suf[i+k]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2688
#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 main()
{
	int W, H, N;
	cin >> W >> H >> N;
	int left = 0, right = W, up = H, down = 0;
	for (int i = 0; i < N; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) left = max(left, x);
		else if (a == 2) right = min(right, x);
		else if (a == 3) down = max(down, y);
		else up = min(up, y);
	}
	cout << max(0, right - left) * max(0, up - down) << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    int a[n];
    FOR(i, 0, n-1) {
        cin >> a[i];
    }

    int b[n], c[n];
    memset(b, 0, sizeof b);
    memset(c, 0, sizeof c);
    vector<int> ans;
    RFOR(i, n-1, 0) {
        RFOR(j, n-1, 0) if (!c[j]) {
            if (b[j] == a[j]-1) {
                //cout << "select " << j << " = " << a[j] << endl;
                ans.push_back(a[j]);
                c[j] = 1;
                FOR(k, j+1, n-1) ++b[k];
                break;
            }
        }
    }

    if (SZ(ans) != n) cout << -1 << '\n';
    else {
        for (auto x : ans) cout << x << '\n';
    }
}


Measured memory_bytes: 256
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define pb push_back

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

int x,y;

int dis;

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

  cin>>x>>y;

  dis=abs(x)-abs(y);
  dis=abs(dis);
  
  if(x==y)
    {
      cout<<0<<endl;
      return 0;
    }
  
  if(x>=0)
    {
      if(y<0)
	dis+=1;
      else if(y<x)
	dis+=1+(y!=0);
    }
  else
    {
      if(y>0)
	dis+=1;
      else if(y<x)
	dis+=1+(y!=0);
    }

  cout<<dis<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 5;
ll n, ans = 0;
ld d;
int main()
{
    IOS;
    cin >> n >> d;
    for(ll i = 1; i <= n; i++)
    {
        ll x, y;
        cin >> x >> y;
        ld chk = (ld)sqrt(x * x  + y * y);
        // cout << chk << endl;
        if((ld)chk <= (ld)d)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> p(3);
    cin >> p[0];
    cin >> p[1];
    cin >> p[2];
    sort(p.begin(),p.end());
    cout << p[1] + p[0] << endl;
    
    
    
    
    
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    ll N,M;
    cin >> N >> M;
    ll ans;
    if(N == 1 && M == 1){
        ans = 1;
    }else if(N > 2 && M > 2){
        ans = (N-2)*(M-2);
    }else if(N == 2 || M == 2){
        ans = 0;
    }else{
        ans = max(N,M) - 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

S = raw_input()
K = input()

cnt = 0
c1 = ''
for c in S:
    if c == '1':
        cnt += 1
    else:
        c1 = c
        break

if cnt >= K:
    print 1
else:
    print c1

Measured memory_bytes: 2812
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>

using namespace std;

const int MAX = 101;
bool used[MAX];

struct data{double x,y,z,r;};
struct State{
  data d;
  double t;
  int n;
  State(){}
  State(data d, double t, int n):d(d),t(t),n(n){}
  bool operator < (const State& s) const {return t > s.t;}
};

int N;
vector<data> V;

void init(){
  V.clear();
  V.resize(N);
  fill(used,used+MAX,false);
}

void input(){
  for(int i = 0; i < N; i++)
    cin >> V[i].x >> V[i].y >> V[i].z >> V[i].r;
}


double getDis(data d1, data d2){
  return sqrt(pow(d1.x-d2.x,2.0)+pow(d1.y-d2.y,2.0)+pow(d1.z-d2.z,2.0));
}
void solve(){
  priority_queue<State> Q;
  Q.push(State(V[0],0,0));
  
  double ans = 0;
  while(!Q.empty()){
    State now = Q.top();
    Q.pop();
    
    if(used[now.n]) continue;
    used[now.n] = true;
  
    ans += now.t;
    
    for(int i = 0; i < N; i++){
      double dis = max(getDis(now.d,V[i])-now.d.r-V[i].r,0.0);
      if(!used[i]) Q.push(State(V[i],dis,i));
    }
  }
  printf("%.3f\n",ans);
}

int main(){
  while(cin >> N && N){
    init();
    input();
    solve();
  }
  return 0;
}

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

int main() {
  int N,l,r;
  int x = 0;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> l >> r;
    int y = r - l + 1;
    x += y;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main() {
    string s;
    cin>>s;
    ll ca=0,cb=0;
    for(ll i=0;i<s.length();i++){
        if(s[i]=='A') ca++;
        if(s[i]=='B') cb++;
    }
    if(ca>=1 && cb>=1) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp3
{
    internal class Class2
    {
        private static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(" ").Select(long.Parse).ToArray();
            var n = (int)nk[0];
            var k = nk[1];

            var orderedEnumerable = Enumerable.Range(0, n)
                .Select(_ =>
                {
                    var ab = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();

                    return (A: ab[0], B: ab[1]);
                })
                .OrderBy(x => x.A);

            foreach (var (a, b) in orderedEnumerable)
            {
                if (k <= b)
                {
                    Console.WriteLine(a);
                    break;
                }

                k -= b;
            }
        }
    }
}

Measured memory_bytes: 48636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0008
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = ReadSt();
                if (line == null) break;

                int n = int.Parse(line);
                int cnt = 0;
                for (int i = 0 ; i < 10 ; i++)
                {
                    for (int j = 0 ; j < 10 ; j++)
                    {
                        for (int k = 0 ; k < 10 ; k++)
                        {
                            for (int l = 0 ; l < 10 ; l++)
                            {
                                if (i + j + k + l == n) cnt++;
                            }
                        }
                    }
                }
                Console.WriteLine(cnt);
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15924
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            string myStr= cin.ReadLine;
            char first = myStr[0];
          	//char first = cin.ReadLine;
			char nextChar = (char)((int) first + 1);
            //var a = cin.ReadInt;
            //var b = cin.ReadInt;
            WriteLine(nextChar);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  REP(i, n)
  {
    cin >> a[i] >> b[i];
  }

  ll ans = 0;
  for (int i = n - 1; i >= 0; i--)
  {
    a[i] += ans;
    if (a[i] % b[i] != 0)
      ans += b[i] - (a[i] % b[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
//http://agc010.contest.atcoder.jp/tasks/agc010_c?lang=en

#include <bits/stdc++.h>

using namespace std;

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

const int MAXN = 1e5 + 10;
int n, A[ MAXN ], deg[ MAXN ];
vector< int > graph[ MAXN ];
map< pii, ll > edge;
bool visited[ MAXN ];


bool check( int u ){
	if( graph[ u ].size() == 1 ) return edge[ make_pair( min( u, graph[ u ][ 0 ] ), max( u, graph[ u ][ 0 ] ) ) ] == A[ u ];
	ll sum = 0;
	for( int i = 0; i < graph[ u ].size(); ++i ){
		ll val = edge[ make_pair( min( u, graph[ u ][ i ] ), max( u, graph[ u ][ i ] ) ) ];
		if( val > A[ u ] ) return false;
		sum += val;
	}
	return sum == (A[ u ] << 1);
}

int main(){
	scanf( "%d", &n );
	for( int i = 1; i <= n; ++i ) scanf( "%d", &A[i] );
	for( int i = 1, a, b; i < n; ++i ){
		scanf( "%d%d", &a, &b );
		graph[ a ].push_back( b );
		graph[ b ].push_back(  a );
		++deg[ a ]; ++deg[ b ];
	}
	queue< int > q;
	for( int i = 1; i <= n; ++i )
		if( deg[ i ] == 1 ) q.push( i );

	bool flag = true;

	while( flag && !q.empty() ){
		int u = q.front(); q.pop();
		//cout << u << endl;
		visited[ u ] = true;
		ll sum = 0; int v = -1;
		for( int i = 0; i < graph[ u ].size(); ++i ){
			int ne = graph[ u ][ i ];
			if( visited[ ne ] ) sum += edge[ make_pair( min( u, ne ), max( ne, u ) ) ];
			else v = ne;
		}
		if( v != -1 ){
			--deg[ v ];
			if( deg[ v ] == 1 ) q.push( v );
			if( graph[ u ].size() == 1 ){
				edge[ make_pair( min( u, v ), max( u, v ) ) ] = A[ u ];
			}
			else{
				if( (A[ u ] << 1) < sum ) flag = false;
				else edge[ make_pair( min( u, v ), max( u, v ) ) ] = (A[ u ] << 1) - sum;
			}
		}
	}

	/*for( map< pii, ll >::iterator it = edge.begin(); it != edge.end(); ++it ){
		cout << (it->first).first << '-' << (it->first).second << ": " << it->second << endl;
	}*/

	if( flag )
		for( int i = 1; i <= n && flag; ++i )
			flag  = check( i );

	if( flag ) puts( "YES" );
	else puts( "NO" );

	return 0;
}

Measured memory_bytes: 12928
#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)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const int INF=1e9;

int n;

int main(){
  string s;
  cin>>s;
  rep(i,s.size()) cout<<"x";
  return 0;
  

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cmath>
#define int long long
using namespace std;
const int mo = 2019;
main()
{
    int l,r;
    cin >> l >> r ;
    if( r - l >= 2019 ) { cout << 0 << endl;}
    else
    {
        int ans = 2019;
        for( int i = l; i < r; i++ )
        {
            for( int j = i + 1; j <= r; j++ )
            {
                ans = min( ans, i * j % mo );
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define N 500043
#define mp(a,b) make_pair(a,b)
#define loop(a,b) for(int i=a;i<b;i++)
#define test int t; cin >> t; while(t--)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int i=0;
    while(i<=k&&a>=b)
    {
        b*=2;
        i++;
    }
    if(i>k)
    {
        cout << "No";
        return 0;
    }
    while(i<=k&&b>=c)
    {
        c*=2;
        i++;
    }
    if(i>k)
    {
        cout << "No";
        return 0;
    }
    else
    {
        cout << "Yes";
    }
}


Measured memory_bytes: 3652
#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(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b){
        swap(a,b);
    }
    if (b > c){
        swap(b,c);
    }
    if (a > b){
        swap(a,b);
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    double ans=0;
    rep(i,n) {
        repr(j,i+1,n) {
            double tans=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))/2;
            ans=(tans>ans)?tans:ans;
        }
    }
    rep(i,n) {
        repr(j,i+1,n) {
            repr(k,j+1,n) {
                double a=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
                double b=sqrt(pow(x[k]-x[j],2)+pow(y[k]-y[j],2));
                double c=sqrt(pow(x[i]-x[k],2)+pow(y[i]-y[k],2));
                if (a<b) swap(a,b);
                if (b<c) swap(b,c);
                if (a<b) swap(a,b);
                double s=(a+b+c)/2;
                double ss=sqrt(s*(s-a)*(s-b)*(s-c));
                if (ss>0 && a*a<b*b+c*c) {
                    double tans=a*b*c/(4*ss);
                    ans=(tans>ans)?tans:ans;
                }
            }
        }
    }
    cout << fixed << setprecision(15) << ans << endl;

    return 0;   
}

Measured memory_bytes: 3796
days = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday']
month = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]
while True:
	m, d = map(int, raw_input().split())
	if m == 0: break
	for i in range(0, m):
		d += month[i]
	print days[d%7]


Measured memory_bytes: 4640
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
vector<int> arr(n);
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr.begin(),arr.end());
int sum=0;
for(int i=0;i<k;i++)
{
sum+=arr[i];
}
cout<<sum<<endl;
return 0;
}

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

int gcd(int a,int b){
  if(b==0)
    return a;
  return gcd(b,a%b);
}
int lcn(int a,int b){
  int s,t;
  s = a/gcd(a,b);
  t = b/gcd(a,b);
  return gcd(a*t,b*s);

}
int main(){
  int a,b;

  while(cin >> a >> b){


    cout << gcd(a,b) << " " << lcn(a,b) << endl;

  }


}

Measured memory_bytes: 1160
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

int1 = lambda x: int(x) - 1

N = int(input())
P = np.array([tuple(map(int1, input().split())) for _ in range(N - 1)]).T

matr = csr_matrix((np.ones(N - 1, dtype=int), P), shape=(N, N))
way_F = dijkstra(matr, indices=0, directed=False).astype(int)
way_F[way_F < 0] = N + 1
way_S = dijkstra(matr, indices=N - 1, directed=False).astype(int)
way_S[way_F < 0] = N + 1

fc = np.count_nonzero(way_F <= way_S)
print('Fennec' if fc > N - fc else 'Snuke')


Measured memory_bytes: 29092
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>

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

const int MAX = 100;
const int INF = (1<<12);

int main() {
  int a, b;
  int c;
  string s;
  cin >> a >> b;
  s = to_string(a) + to_string(b);
  c = stoi(s);
  int res = sqrtl(c);
  if (c == res * res) cout << "Yes";
  else cout << "No";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        String ans = "APPROVED";

        for(int i=0;i<N;i++){
            if(A[i] % 2 == 0){
                if(A[i] % 3 != 0 && A[i] % 5 !=0){
                    ans = "DENIED";
                    i = N;
                }
            }
        }
        System.out.println(ans);

    }
}








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

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  string s = a+b+c;
  if(s=="557" || s=="575" || s=="755")
    cout << "YES" << endl;
  else
    cout << "NO" <<endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll>vec;
int main() 
{
    ll x;
    cin>>x;
    ll ans=0;
    ll p=100;
    for(;p<x;ans++)
    {
        p=p*(1.01);
    }
    cout<<ans<<endl;
    
    return 0;
}


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


public class Contest
{
	public static void Main()
	{
		int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));

//		int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		int[] d = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
/*
		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) e[i] = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
*/

		List<int> r = new List<int>();
		r.Add(a[0]);
		while(true) {
			int k = (r[r.Count-1]%2==0)?(r[r.Count-1]/2):(r[r.Count-1]*3+1);
			if(-1<r.IndexOf(k)) break;
			r.Add(k);
		}

		string ans = (r.Count+1).ToString();

		Console.WriteLine(ans);
	}
	
	private static int calc_main(int[] a,int[] b,int[] c,int[] d) {



		return 0;
	}




}


Measured memory_bytes: 13268
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0

for i in range(0,a+1):
  for j in range(0,b+1):
    for k in range(0,c+1):
      if 500*i+100*j+50*k == x:
        cnt += 1
        
print(cnt)

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

using namespace std;

string S;
int tmp[100001];
int tmp2[100001];
int ans;

int main() {
  cin >> S;
  for(int i = 0; i < S.length();i++){
    if(S[i] == 'g') tmp[i] = 0;
    else tmp[i] = 1;
    if(i < (S.length() + 1) / 2) tmp2[i] = 0;
    else tmp2[i] = 1;
  }
  for(int i = 0; i < S.length(); i++) {
    ans += tmp2[i] - tmp[i];
  }

  cout << ans << endl;
}
  
  


Measured memory_bytes: 1280
#include <stdio.h>

int main(){

	int i,j;
	int x[10];
	int y = 0;

	for(i=0;i<10;i++){
		x[i] = 0;
		scanf("%d",&x[i]);
	}

	for(i=0;i<10;i++){
		for(j=i+1;j<10;j++){
            if(x[j] < x[i]){
            	y = x[i];
            	x[i] = x[j];
            	x[j] = y;
            }
		}
	}

	printf("%d\n",x[9]);
	printf("%d\n",x[8]);
	printf("%d\n",x[7]);
    
    return 0;
    
}

Measured memory_bytes: 600
n, m = gets.split.map(&:to_i)
w = (1..m).map {gets.chomp.split("")}.transpose.map {|a| a.count(?W)}
min_error = error = w.inject(:+)
ans = 0
(0..n-1).each do |i|
    error += m - 2 * w[i]
    if error < min_error
        min_error = error
        ans = i + 1
    end
end
puts "#{ans} #{ans + 1}"


Measured memory_bytes: 64028
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

//#define __DEBUG__

class Dice {

	private:
		int iNS[4];
		int iEW[4];

	public:
		Dice( int v1, int v2, int v3, int v4, int v5, int v6 ) {
			iNS[0] = v1;
			iNS[1] = v2;
			iNS[2] = v6;
			iNS[3] = v5;

			iEW[0] = v1;
			iEW[1] = v3;
			iEW[2] = v6;
			iEW[3] = v4;

#ifdef __DEBUG__
			printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void rotateN() {
			int iTmp = iNS[0];
			iNS[0] = iNS[1];
			iNS[1] = iNS[2];
			iNS[2] = iNS[3];
			iNS[3] = iTmp;

			iEW[0] = iNS[0];
			iEW[2] = iNS[2];

#ifdef __DEBUG__
			printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void rotateS() {
			int iTmp = iNS[0];
			iNS[0] = iNS[3];
			iNS[3] = iNS[2];
			iNS[2] = iNS[1];
			iNS[1] = iTmp;

			iEW[0] = iNS[0];
			iEW[2] = iNS[2];

#ifdef __DEBUG__
			printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void rotateE() {
			int iTmp = iEW[0];
			iEW[0] = iEW[3];
			iEW[3] = iEW[2];
			iEW[2] = iEW[1];
			iEW[1] = iTmp;

			iNS[0] = iEW[0];
			iNS[2] = iEW[2];

#ifdef __DEBUG__
			printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif

		}

		void rotateW() {
			int iTmp = iEW[0];
			iEW[0] = iEW[1];
			iEW[1] = iEW[2];
			iEW[2] = iEW[3];
			iEW[3] = iTmp;

			iNS[0] = iEW[0];
			iNS[2] = iEW[2];

#ifdef __DEBUG__
			printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		int getTop() {
			return iNS[0];
		}

};

int main(void) {


	int v1, v2, v3, v4, v5, v6;
	char cmd[128];

	v1 = v2 = v3 = v4 = v5 = v6 = 0;

	scanf("%d %d %d %d %d %d", &v1, &v2, &v3, &v4, &v5, &v6 );
	scanf("%s", &cmd );

	Dice *d = new Dice(v1, v2, v3, v4, v5, v6);

	int iLen = strlen(cmd);
	for (int i = 0; i < iLen; i++) {
		char c = cmd[i] & 0xdf;
		switch (c) {
			case 'N':
				d->rotateN();
				break;
			case 'S':
				d->rotateS();
				break;
			case 'E':
				d->rotateE();
				break;
			case 'W':
				d->rotateW();
				break;
			default:
				break;
		}
	}

	printf("%d\n", d->getTop());


}

Measured memory_bytes: 2736
n = int(input())
from collections import defaultdict
a = list(map(int, input().split()))
p1 = defaultdict(int)
p2 = defaultdict(int)
for i in range(n):
    p1[a[i]-i] +=1
    p2[a[i]+i] +=1
result = 0
for i in p1.keys():
    result += p1[i] * p2[-1*i]
print(result)



Measured memory_bytes: 164096
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <numeric>
#include <set>

#define MOD 1000000007
#define INF 2000000000
#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(YY, yy) for(long long yy = 0; yy < YY; ++yy)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef vector<pair<int, pair<int, int> > > vpip;
typedef vector<bool> vb;
typedef priority_queue<int> pqi;

int N, K, Q;

int main(int argc, char **argv)
{
    ios::sync_with_stdio(); cin.tie(0);
    cin >> N >> K >> Q;
    vi players(N, 0);
    for(int i = 0; i < Q; ++i)
    {
        int p = 0; cin >> p; p--;
        players[p]++;
    }
    for(int i = 0; i < N; ++i)
    {
        if(K - (Q - players[i]) <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }


    return 0;
}

//cikisir



Measured memory_bytes: 1024
N = int(input())
name_list = [input() for i in range(N)]

M_list = []
A_list = []
R_list = []
C_list = []
H_list = []

for name in name_list:
    if name[0:1] == 'M':
        M_list.append(name)
    elif name[0:1] == 'A':
        A_list.append(name)
    elif name[0:1] == 'R':
        R_list.append(name)
    elif name[0:1] == 'C':
        C_list.append(name)
    elif name[0:1] == 'H':
        H_list.append(name)

M = len(M_list)
A = len(A_list)
R = len(R_list)
C = len(C_list)
H = len(H_list)

def cal(x,y,z):
    return x*y*z

print(cal(M,A,R)+cal(M,A,C)+
      cal(M,A,H)+cal(M,R,C)+
      cal(M,R,H)+cal(M,C,H)+
      cal(A,R,C)+cal(A,R,H)+
      cal(A,C,H)+cal(R,C,H))


Measured memory_bytes: 10864
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i!=n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n,b) << endl;
}


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e5;
const int C = 70;

double dp[N + 1]; // i日目が「食べていない日」の最終日であるときのそれ
double p[N + 1];
double ans[N + 1];

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  double p2[C], p2s[C];
  p2s[0] = p2[0] = 1;
  for(int i = 1; i < C; i++) p2[i] = p2[i-1] * .5;
  for(int i = 1; i < C; i++) p2s[i] = p2[i] * p2s[i-1];

  p[0] = 1;

  for(int i = 1; i <= N; i++) {
    for(int j = 1; j < C && i-j-1 >= 0; j++) if(p[i-j-1] > 0) {
      // j日間食べ続け，最後に食べない
      p[i] += p[i-j-1] * p2s[j-1] * (1 - p2[j]);
      dp[i] += (dp[i-j-1] / p[i-j-1] + j) * p[i-j-1] * p2s[j-1] * (1 - p2[j]);
      // j日間食べ続け，最後に食べない
      ans[i] += (dp[i-j-1] / p[i-j-1] + j + 1) * p[i-j-1] * p2s[j];
    }
    ans[i] += dp[i];
    if(p[i-1] > 0) ans[i] += (dp[i-1] / p[i-1] + 1) * p[i-1];
  }

  int n;
  cout << fixed << setprecision(10);
  while(cin >> n, n) {
    cout << ans[n] << "\n";
  }
  return 0;
}



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

int main() {
  char S;
  cin >> S;
  
  if( S=='a' || S=='i' || S=='u' || S=='e' || S=='o' ){
    cout << "vowel" << endl;
  }
  
  else{
    cout << "consonant" << endl;
  }

  // ここにプログラムを追記
}


Measured memory_bytes: 256