akhauriyash/Code-Regression huggingface dataset:
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n;
int activities[100010][4];
int memo[100010][4];

int dp(int at, int last)
{
    if (at > n) return -INF;
    if (at == n) return 0;
    if (memo[at][last] != -1) return memo[at][last];
    int ans = -INF;
    for (int i = 0; i < 3; i++) {
        if (i != last) {
            ans = max(ans, dp(at + 1, i) + activities[at][i]);
        }
    }
    return memo[at][last] = ans;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    memset(memo, -1, sizeof(memo));
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> activities[i][j];
        }
    }
    cout << dp(0, 5) << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h,vector<char>(w));
    vector<vector<char>> c2(h,vector<char>(w));
    vector<vector<char>> c3(h,vector<char>(w));
    vector<int> bit_w(w);
    vector<int> bit_h(h);
    int count=0;
    int ans=0;
    int num_h=1;
    int num_w=1;
    rep(i,h){
        num_h*=2;
    }
    rep(i,w){
        num_w*=2;
    }
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
        
    }


    rep(i,num_h){
        int p=i;
        rep(j,h){
            rep(k,w){
                c2[j][k]=c[j][k];
            }
            
        }
        int j=0;
        while(p>=1){
            bit_h[j++]=p%2;
            p/=2;
        }
        while(j<h){
            bit_h[j++]=0;
        }

        


        rep(j,h){
            if(bit_h[j]==1){
                rep(k,w){
                    c2[j][k]='.';
                }
            }
        }/*
        rep(j,h){
            rep(k,w){
                cout << c2[j][k];
            }
            cout << endl;
        }*/
        
        rep(j,num_w){

            rep(k,h){
                rep(l,w){
                    c3[k][l]=c2[k][l];
                }
            
            }


            int l=0;
            int q=j;
            while(q>=1){
                bit_w[l++]=q%2;
                q/=2;
            }
            while(l<w){
                bit_w[l++]=0;
            }
            /*
            rep(k,w){
                cout <<bit_w[k];
            }
            cout << endl;*/
            
            rep(m,w){
                if(bit_w[m]==1){
                    rep(o,h){
                        c3[o][m]='.';
                    }
                }
            }

            rep(m,h){
                rep(o,w){
                    if(c3[m][o]=='#'){
                        count++;
                    }
                }
            }
            if(count==k){
                ans++;
            }
            count=0;
            
            rep(k,w){
                bit_w[k]=0;
            }
        }
        rep(k,h){
            bit_h[k]=0;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
n = int(input())
d = {}
for i in range(n):
    s = input()
    for j in range(len(s)):
        if s[j] not in d:
            d[s[j]] = [0] * n
            d[s[j]][i] += 1
        else:
            d[s[j]][i] += 1
ans = ""
for k, v in d.items():
    ans += k * min(v)
print("" .join(sorted(ans)))


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

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int a1;
    int n;
    cin>>n;
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a1;
        if(a1&1 && i&1)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,c,k;
string s,t;
signed main()
{
	cin>>a>>b>>k;
	if(k<=a){
		a=a-k;
	}else{
		b=b-(k-a);
		a=0;
		if(b<0){
			b=0;
		}
	}
	cout<<a<<' '<<b<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n; cin >> n;
  ll ans = n*(n-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (a*b)/gcd(a, b);}


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    map<string,int> a;
    int mx = -1;
    for(int i=0;i<n;++i){
        string s; cin>>s;
        a[s]++;
        mx = max(mx,a[s]);
    }
    set<string> x; for(auto l : a) if(l.second==mx) x.insert(l.first);
    for(auto l : x) cout<<l<<'\n';
}


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

using namespace std;

bool a[15][15];

void umple(int x,int y) {
    a[x][y] = 0;
    if(a[x+1][y]) {
        umple(x+1, y);
        return;
    }
    if(a[x][y+1])
        umple(x, y+1);
}

int main() {
    int n, m;
    char ch;
    cin >> n >> m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++) {
            cin >> ch;
            a[i][j] = (ch == '#');
        }
    umple(1, 1);
    bool ok = 1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            ok = (ok && !a[i][j]);
    if(ok)
        cout << "Possible\n";
    else
        cout << "Impossible\n";
}


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

typedef pair<int, int> P;

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<P, vector<P>, greater<P>> que;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        que.push(P(a, b));
    }

    long long res = 0;
    int cnt = 0;
    while (cnt < M) {
        P p = que.top(); que.pop();
        p.second--;
        cnt++;
        res += p.first;
        if (p.second > 0)
            que.push(p);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
using namespace std;

int main() {
	int n;
	cin >> n;
	int x[100000], y[100000], t[100000];
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	int x2 = 0, y2 = 0, sa_time = 0;
	for (int i = 0; i < n; i++) {
		int sa = abs(x[i] - x2) + abs(y[i] - y2);
		if (sa <= t[i] - sa_time&&sa % 2 == (t[i] - sa_time) % 2) {
			x2 = x[i];
			y2 = y[i];
			sa_time = t[i];
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

bool ispal(const string &s){
	return string(s.rbegin(), s.rend()) == s;
}

bool check(int x){
	static char buf[16];
	sprintf(buf, "%d", x);
	return ispal(buf);
}

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

	for(int i = 0; ; ++i){
		if(check(n - i)){
			printf("%d\n", n - i);
			break;
		}
		if(check(n + i)){
			printf("%d\n", n + i);
			break;
		}
	}
}

Measured memory_bytes: 1080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

pair<pair<ll, ll>, ll> dfs(int key, vector<vector<int>> &p, vector<vector<int>> &q, vector<int> &r, vector<int> &s){
    ll res=p[key].size(), me=1, ot=0;
    for(int i=0; i<p[key].size(); ++i){
        if(s[p[key][i]]==0){
            s[p[key][i]]=r[key];
            pair<pair<ll, ll>, ll> P=dfs(p[key][i], q, p, s, r);
            me += P.first.second;
            ot += P.first.first;
            res += P.second;
        }
    }
    return make_pair(make_pair(me, ot), res);
}

int main() {
	int N;
	cin >> N;
	map<int, vector<int>> xx, yy;
	for(int i=0; i<N; ++i){
	    int x, y;
	    cin >> x >> y;
	    xx[x].push_back(y);
	    yy[y].push_back(x);
	}
	map<int, int> xc, yc;
	int xnow=0, ynow=0;
	for(auto itr=xx.begin(); itr!=xx.end(); ++itr){
	    xc[itr->first]=xnow;
	    ++xnow;
	}
	for(auto itr=yy.begin(); itr!=yy.end(); ++itr){
	    yc[itr->first]=ynow;
	    ++ynow;
	}
	vector<vector<int>> xf(xnow), yf(ynow);
	int now=0;
	for(auto itr=xx.begin(); itr!=xx.end(); ++itr){
	    for(int i=0; i<itr->second.size(); ++i){
	        xf[now].push_back(yc[itr->second[i]]);
	    }
	    ++now;
	}
	now=0;
	for(auto itr=yy.begin(); itr!=yy.end(); ++itr){
	    for(int i=0; i<itr->second.size(); ++i){
	        yf[now].push_back(xc[itr->second[i]]);
	    }
	    ++now;
	}
	vector<int> xs(xnow, 0), ys(ynow, 0);
	ll ans=0;
	int h=1;
	for(int i=0; i<xnow; ++i){
	    if(xs[i]==0){
	        xs[i]=h;
	        pair<pair<ll, ll>, ll> cnt=dfs(i, xf, yf, xs, ys);
	        ans += cnt.first.first*cnt.first.second-cnt.second/2;
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 30464
#include <stdio.h>
int main(void){
     char S[100000],temp[100000];
    int i,len,cnta=0,cntb=0;
   
    scanf("%s",&S);
    len = strlen(S);
    for(i=0;i<len;i++)
        temp[i]=S[i];
/* 101010...に揃える */
        for(i=0;i<len;i++){
        if(i%2==0){
        if(S[i]=='0'){
        S[i]='1';
        cnta++;
        }
        }
        if(i%2==1){
        if(S[i]=='1'){
        S[i]='0';
        cnta++;
        }
        }
    }
/* 01010101...に揃える */
    for(i=0;i<len;i++){
        S[i]=temp[i];     /*文字列を元に戻す*/
        if(i%2==1){
        if(S[i]=='0'){
        S[i]='1';
        cntb++;
        }
        }
        if(i%2==0){
        if(S[i]=='1'){
        S[i]='0';
        cntb++;
        
        }
        }
     }
     
    if(cnta>cntb)  
    printf("%d",cntb);
    else
    printf("%d",cnta);
    return(0);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
int n,l,a[100005];
int main(){
	n=read(),l=read();
	for(int i=1;i<=n;++i) a[i]=read();
	int tmp=0,minn;
	for(int i=1;i<n;++i){
		if(a[i]+a[i+1]>tmp) tmp=a[i]+a[i+1],minn=i;
	}
	if(tmp>=l){
		printf("Possible\n");
		for(int i=1;i<minn;++i) printf("%d\n",i);
		for(int i=n-1;i>minn;--i) printf("%d\n",i);
		printf("%d\n",minn);
	}
	else printf("Impossible\n");
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
using namespace std;
const int MAX = 200000;

int main(){
  int n;
  cin >> n;
  
  vector<int> a(MAX);
  for(int i=0; i<n; i++){
  	cin >> a.at(i);
  }
 
  int last = -1;
  int ct = 0;    //見つかった数
  bool IsFind = false;
  
  for(int i=1; i<=n; i++){ //探している数字
    IsFind = false;
    for(int j=last+1; j<n; j++){ //最初から順に
      if(a.at(j)==i){
        last = j; //サーチし終わった範囲
        ct++;
        IsFind = true;
        break; //見つかったら次の数へ
      }
    }
    if(IsFind==false){ //一周しても見つからない
      break; //見つからなかったら抜ける
    }
  }

  if(ct){
    cout << n - ct << endl;
  }
  else{
    cout << "-1" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int a[3], b[3];
int c[3][3];

int main() {
    REP(i,3) REP(j,3) cin >> c[i][j];
    for (a[0] = 0; a[0] <= 100; a[0]++) {
        for (a[1] = 0; a[1] <= 100; a[1]++) {
            for (a[2] = 0; a[2] <= 100; a[2]++) {
                if (a[0] == 0 && a[1] == 1 && a[2] == 0) {
                    
                }
                b[0] = c[0][0] - a[0];
                b[1] = c[1][1] - a[1];
                b[2] = c[2][2] - a[2];
                bool f = true;
                REP(i,3) REP(j,3) {
                    if (a[i] + b[j] != c[i][j]) f = false;
                }
                if (f) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> ii;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int arr[MAX];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n;

    cin>>n;

    ll ans = 1LL * n * (n - 1);
    ans /= 2;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int H[105][105],x[100],y[100],h[100];

int main()
{
	int N,idx;
	cin >> N;
	rep(i,N)
	{
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) idx = i;
	}

	bool ok;
	
	for (int j = 0; j <= 100; ++j)
	{
		for (int k = 0; k <= 100; ++k)
		{
			ok = true;
			int H = h[idx] + abs(j-x[idx]) + abs(k-y[idx]);
			//cout << j << " " << k << " " << H << endl;
			if (H > 0)
			{
				for (int l = 0; l < N; ++l)
				{
					if (l != idx && max(0,H - abs(j-x[l]) - abs(k-y[l])) != h[l])
					{
						ok = false;
						//cout << " false" << endl;
						break;
					}
				}

				if (ok)
				{
					//cout << " true ";
					cout << j << " " << k << " " << H << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

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

int main(){
  int a,c,d,e;
  c=0;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
  }
  sort(b.begin(),b.end());
  for(int i=0;i<a;i=i){
    e=b.at(i);
    d=0;
    for(int j=0;i<a&&b.at(i)==e;j=j){
      d++;
      i++;
    }
    c+=d%2;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n) {
    if (a[i] % 2 == 1) ans++;
  }
  if (ans % 2 == 1) NO();
  else YES();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

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

  int64_t a = 2; 
  int64_t b = 1;
  
  if (N == 0) {
    cout << a << endl;
  }
  else if (N == 1) {
    cout << b << endl;
  }
  else {
    for (int i = 2; i < N + 1; i++) {
      int64_t tmp = b;
      b = a + b;
      a = tmp;
    }
    cout << b << endl;
  }

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int n;
int cnt[4];
double dp[301][301][301];

double dfs(int c1,int c2,int c3){
  if(dp[c1][c2][c3]!=-1.0)return dp[c1][c2][c3];
  int c0=n-c1-c2-c3;
  if(c0==n)return 0.0;
  double res=0;

  if(c1>0)res+=(dfs(c1-1,c2,c3)+1.0)*((double)c1/(double)n);
  if(c2>0)res+=(dfs(c1+1,c2-1,c3)+1.0)*((double)c2/(double)n);
  if(c3>0)res+=(dfs(c1,c2+1,c3-1)+1.0)*((double)c3/(double)n);
  res+=(double)c0/(double)n;
  res*=(double)n/(double)(n-c0);

  return dp[c1][c2][c3]=res;
}

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

  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    cnt[a]++;
  }
  rep(i,301)rep(j,301)rep(k,301)dp[i][j][k]=-1.0;
  printf("%.10f\n", dfs(cnt[1],cnt[2],cnt[3]));

  return 0;
}


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

int main(){
	int n;
	cin >> n;
	int value[n], cost[n];
	int sum = 0;
	for(int i = 0; i < n;i++){
		cin >> value[i];
	}
	for(int i = 0; i < n;i++){
		cin >> cost[i];
		if(value[i] > cost[i]){
			sum += value[i] - cost[i];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define jaldi ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define kuch(a,n) for(ll i=0;i<n;i++) cin>>a[i]
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define bs(v,x)	binary_search(v.begin(),v.end(),x)
#define mci(b)	cout<<b<<"\n"
#define bvb(n)	long long n;cin>>n;

typedef long long ll;
typedef vector<long long> vll ;
typedef long double ld;
const ll maxn = 1e9, mod = 1e9 + 7;


ll gcd(ll a,ll b)
{
	if(a == 0)
		return b;
	return gcd(b%a, a);
}

ll lcm(ll a, ll b)  
{  
    return (a*b)/gcd(a, b);  
} 

int main()
{
	jaldi;
	ll n,k;cin>>n>>k;
	ll arr[n];kuch(arr,n);
	vll dp(n,maxn);
	dp[0]=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<=i+k;j++)
		{
			if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
		}
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <limits.h>
 
#define MAX 200000
#define INF INT_MAX
 
void merge(int*, int, int, int);
void mergesort(int*, int, int);
 
long int ans;
 
int n, a[MAX];
 
int main(){
  int i;
 
  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" ,a + i);
  }
  mergesort(a,0,n);
  printf("%ld\n" ,ans);
 
  return 0;
}
 
void merge(int a[], int left, int mid, int right){
  int n1 = mid - left, n2 = right - mid;
  int L[n1+1], R[n2+1], i, j, k;
  
  for(i = 0 ; i < n1 ; i++){
    L[i] = a[left + i];
  }
  
  for(i = 0 ; i < n2 ; i++){
    R[i] = a[mid + i];
  }
  
  L[n1] = R[n2] = INF;
  
  for(i = 0, j = 0, k = left ; k < right ; k++){
    if(i < n1 && (j == n2 || L[i] <= R[j])){
      a[k] = L[i++];
    }else{
      ans += (n1 + n2) / 2 - i;
      a[k] = R[j++];
    }
  }
}
  
void mergesort(int a[], int left, int right){
  int mid;
  
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    merge(a, left, mid, right);
  }
}


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

using namespace std;

int main() {
   long n,b_sum=0;
   cin >> n;
   long a[n],b[n],c[n];
   for(int i=0;i<n;i++){
      cin >> a[i] >> b[i];
      c[i] = a[i] + b[i];
      b_sum += b[i];
   }

   sort(c,c+n);
   reverse(c,c+n);

   long score=0;
   for(int i=0;i<n;i++){
      if(i%2==0){
         score += c[i];
      }
   }
   score -= b_sum;
   cout << score << endl;
   return 0;
}


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

#define pi 3.14159265358979323846

int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double hdeg=(long double)h*30;
    long double mdeg= (long double)m*6;
    hdeg+=mdeg/12;
    long double deg = abs(hdeg-mdeg);
    //apply law of cosines
    long double cosdeg = cos(deg* pi/180);
    long double asqr = a*a;
    long double bsqr= b*b;
    long double c = sqrt(asqr+bsqr-2*a*b*cosdeg);
    cout << fixed << showpoint;
    cout << setprecision(20);
    cout << c << endl;
}


Measured memory_bytes: 4132
s = [1 for i in range(13)]
h = [1 for i in range(13)]
c = [1 for i in range(13)]
d = [1 for i in range(13)]

#pattern = ["S", "H", "C", "D"]

n = int(input())

for i in range(n):
    p, num = input().split()
    if p == 'S':
        s[int(num) - 1] = 0
    elif p == 'H':
        h[int(num) - 1] = 0
    elif p == 'C':
        c[int(num) - 1] = 0
    elif p == 'D':
        d[int(num) - 1] = 0

for i in range(13):
    if s[i] == 1:
        print('S',i+1)
for i in range(13):
    if h[i] == 1:
        print('H',i+1)
for i in range(13):
    if c[i] == 1:
        print('C',i+1)
for i in range(13):
    if d[i] == 1:
        print('D',i+1)


Measured memory_bytes: 5620
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [h, w]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${h == 1 || w == 1 ? 1 : Math.ceil(h * w / 2)}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int D = sc.nextInt();

		int X = sc.nextInt();

		int[] A = new int[N];

		for(int i=0;i<N;i++) {

			A[i] = sc.nextInt();
		}

		int choco = 0;

		for(int i=0;i<N;i++) {

			int Ai = A[i];

			for(int j=0;j<D;j+=Ai) {

				choco++;
			}
		}

		choco += X;

		System.out.println(choco);

	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N, M;
vector<int> s, c;

bool ok(string str) {
    if (str.size() != N) return false;
    for (int i = 0; i < M; ++i) if (str[s[i]] != (char)(c[i] + '0')) return false;
    return true;
}

string solve() {
    for (int i = 0; i <= 999; ++i) {
        stringstream iss; iss << i;
        string str = iss.str();
        if (ok(str)) return str;
    }
    return "-1";
}

int main() {
    cin >> N >> M;
    s.resize(M); c.resize(M);
    for (int i = 0; i < M; ++i) cin >> s[i] >> c[i], --s[i];
    cout << solve() << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    readline = sys.stdin.buffer.readline
    sys.setrecursionlimit(10 ** 7)

    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort(reverse=True)
    idx = 1
    ans = a[0]
    for aa in a[1:]:
        if idx + 2 >= n:
            if idx + 1 < n:
                ans += aa
            break
        idx += 2
        ans += aa * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 100908
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// go run ./main.go < in

func main() {
	var n int
	fmt.Scan(&n)

	var strInputs []string
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	strInputs = strings.Split(sc.Text(), " ")

	var inputs []int
	for _, v := range strInputs {
		num, _ := strconv.Atoi(v)
		inputs = append(inputs, num)
	}

	count, end := 0, false
	for {
		for j, v := range inputs {
			if v%2 == 0 {
				inputs[j] /= 2.0
				count++
			} else {
				end = true
			}
		}
		if end {
			break
		}
	}
	fmt.Println(count / n)
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] t = new int[n];
    int sum = 0;
    for(int i = 0; i < n; i++) {
      t[i] = sc.nextInt();
      sum += t[i];
    }
    int m = sc.nextInt();
    for(int i = 0; i < m; i++) {
      int p = sc.nextInt() - 1;
      int x = sc.nextInt();
      System.out.println(sum - t[p] + x);
    }
  }
}

Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll lcm(ll x, ll y)
{
    return x * y / __gcd(x, y);
}

int count_step(int a, int m)
{
    ll x = 1, step = 0;
    do {
        x = (a * x) % m;
        step++;
    } while(x != 1);
    return step;
}

int main()
{
    int a1,m1,a2,m2,a3,m3;
    while(cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3 && a1) {
        cout << lcm(count_step(a1, m1), lcm(count_step(a2, m2), count_step(a3, m3))) << endl;
    }
}

Measured memory_bytes: 0
def getid(node, m, n):
    if node == 'H':
        return 0
    elif node == 'D':
        return m + n + 1
    elif node[0] == 'C':
        return int(node[1:])
    else:
        return m + int(node[1:])
import heapq

#??±???????±?????????±???????????????????????????
def ex_dijkstra(graph, m, size, start=0):
    distance = [float('inf')] * size
    distance[start] = 0
    que = []
    heapq.heappush(que, (0, start))
    while len(que):
        _, u = heapq.heappop(que)
        for length, vi in graph[u]:
            if distance[vi] > distance[u] + length:
                distance[vi] = distance[u] + length
                if 1 <= vi <= m:
                    continue
                heapq.heappush(que, (distance[vi], vi))
    return distance
import sys
f = sys.stdin

from collections import defaultdict
from itertools import permutations
from itertools import chain

while True:
    m,n,k,d = map(int, f.readline().split())
    if m == 0:
        break
    cake = [0] + list(map(int, f.readline().split()))
    graph = defaultdict(list)
    for a, b, dist in [f.readline().split() for _ in range(d)]:
        a, b, dist = getid(a,m,n), getid(b,m,n), int(dist) * k
        graph[a].append((dist,b))
        graph[b].append((dist,a))
    compressed_graph = [ex_dijkstra(graph, m, m + n + 2, i) for i in range(m + 1)]

    calorie = []
    for combination in chain(*[permutations(range(1,m + 1), i) for i in range(m + 1)]):
        combination = (0,) + combination + (m + n + 1,)
        temp = -sum(cake[i] for i in combination[:-1])
        for s, e in zip(combination,combination[1:]):
            temp += compressed_graph[s][e]
        calorie.append(temp)
    print(min(calorie))

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

vector< vector< long long int > > v;
bool f[5001] = {};
bool tonari[5001][5001] = {};
vector< long long int > ans;

void kansu( long long int n ) {

  if ( f[n] == true ) return;

  f[n] = true;

  for ( long long int i = 0; i < v[n].size(); i++ ) {
    kansu( v[n][i] );
  }

  cout << n << endl;
  ans.push_back( n );

  return;

}

int main() {

  long long int n, m;
  cin >> n >> m;

  for ( long long int i = 0; i <= n; i++ ) {

    vector< long long int > l;
    v.push_back( l );

  }

  for ( long long int i = 0; i < m; i++ ) {

    long long int x, y;
    cin >> x >> y;

    v[y].push_back( x );
    tonari[x][y] = true;
    tonari[y][x] = true;

  }

  for ( long long int i = 1; i <= n; i++ ) {
    kansu( i );
  }

  for ( long long int i = 0; i < n - 1; i++ ) {

    if ( tonari[ ans[i] ][ ans[i + 1] ] == false ) {
      cout << 1 << endl;
      return 0;
    }

  }

  cout << 0 << endl;

  return 0;

}

Measured memory_bytes: 27060
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int fn(0);
for(int i=0; i<s.length(); ++i)
{
if((s[i]!='h'&&i%2==0)||(s[i]!='i'&&i%2))
{
fn=1;
break;
}
}
if(fn==0&&s.length()%2==0)
cout<<"Yes";
else
cout<<"No";
}

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

using namespace std;
typedef long long ll;

int main() {
   ll n;
   cin >> n;
   ll count = 0;
   vector<ll> a(n);
   for(auto &it : a) cin >> it;
   for(ll i = 0; i < n; i++){
       for(ll j = 0; j < n; j++){
           for(ll k = 0; k < n; k++){
               if(i < j && j < k){
                   if(a[i] == a[j]) continue;
                   if(a[j] == a[k]) continue;
                   if(a[k] == a[i]) continue;
                   if(a[i] + a[j] + a[k] <= max({a[i], a[j], a[k]})*2) continue;
                   count++;
               }
           }
       }
   }
   cout << count << endl;
   



}



Measured memory_bytes: 3532
#include <stdio.h>
int a[10001],n,m,x,sum=0,i,j;
int main(){
    scanf("%d",&n);
    for ( i = 0; i < n; ++i) scanf("%d",&a[i]);
    scanf("%d",&m);
    for (i = 0; i < m; ++i) {
        scanf("%d",&x);
        for ( j = 0; j < n; ++j)
            if(x==a[j]){
                sum++;
                break;
            }
    }
    printf("%d\n",sum);
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  int ans = 0;
  int x;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &x);
    ans += 2 * min(x, abs(K - x));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int N, train,taxi;
    int trainTotal;
    scanf("%d",&N);
    scanf("%d",&train);
    scanf("%d",&taxi);
    trainTotal = train *N;

    if(trainTotal >= taxi){
        printf("%d",taxi);
    }else {
        printf("%d",trainTotal);
    }

}

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

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

using ll = long long;

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

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

int main() {
  string X;
  cin>>X;
  vector<int> ch;
  int cnt = 0;
  int l = X.size();
  rep(i,l){
    if(X[i]=='S') cnt++;
    if(X[i]=='T') cnt--;
    if(i==l-1) ch.push_back(cnt);
    else if(X[i]!=X[i+1]) {
      ch.push_back(cnt);
      cnt=0;
    }
  }
  int len = ch.size();
  int s = 0;
  rep(i,len){
    if(ch[i]<0) continue;
    s = ch[i];
    while(s>=0){
      if(i==len-1) break;
      i++;
      s+=ch[i];
    }
  }
  cout<<s*2<<endl;
}

Measured memory_bytes: 1024
import math
n = int(input())
X = list(map(int, input().split()))

p1=math.ceil(sum(X)/n)
p2=math.floor(sum(X)/n)
cnt1=0
cnt2=0
for x in X:
  cnt1 += (x-p1)**2
  cnt2 += (x-p2)**2
print(min(cnt1, cnt2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  ll t = 1, a = 1;
  rep(i, n){
    ll it, ia;
    cin >> it >> ia;
    ll n = max((t+it-1)/it, (a+ia-1)/ia);
    t = n*it;
    a = n*ia;
  }
  cout << t+a << endl;
  return 0;
}

Measured memory_bytes: 3612
#include"bits/stdc++.h"
using namespace std;

int64_t sum = 0;
vector<int64_t> a(90, 0);
int64_t luca(int64_t n) {
	if (a.at(n)) return a.at(n);
	sum = luca(n - 1) + luca(n - 2); a.at(n) = sum;
	return sum;
}

int main() {
	int N;
	cin >> N;
	a.at(0) = 2;
	a.at(1) = 1;
	cout << luca(N) << endl;
}

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

int main() {
  int N=0;
  string S;
  cin >> S;
  
  for(int i=0; i<4;i++){
    for(int j=0; j<4;j++){
      if(S[i]==S[j])
        N++;
    }
  }
  if(N==8)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	getline(cin, s);
	
	REP(i, s.size()) {
		if(islower(s[i])) transform(s.begin() + i, s.begin() + i + 1, s.begin() + i, ::toupper);
		else transform(s.begin() + i, s.begin() + i + 1, s.begin() + i, ::tolower);
	}
	
	cout << s << "\n";
	
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>

using namespace std;

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

    int n, m;
    cin >> n >> m;
    string a = "", b = "";
    for (int i = 0; i < n; i++) a += (char)('0' + m);
    for (int i = 0; i < m; i++) b += (char)('0' + n);
    cout << (a < b ? a : b) << "\n";

    return 0;
}


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

int main(){
    long long int n;
    double ans=0;
    cin>>n;
    vector<double>a(1000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),std::greater<>());
    ans=(a[n-1]+a[n-2])/2;
    for(int i=n-3;i>=0;i--){
        ans=(ans+a[i])/2;
    }
    cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 8064
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 100005
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

N = int(input())
X = list(map(int, input().split()))

ans = 0
prepro = [1]
for i in range(2, N+1):
    prepro.append((prepro[-1]+inverse[i]) % MOD)

for i in range(N-1):
    ans += (X[i+1]-X[i]) * prepro[i] % MOD

ans *= factrial[N-1]  # 期待値の総和に(N-1)!をかける

print(ans % MOD)


Measured memory_bytes: 26748
#include <iostream>
#include <algorithm>
#define INF 1000000
using namespace std;

int main(){
    int n,m,a,b,c,d;
    char ch;
    int cost[21][21];

    for(int i=0;i<21;i++){
        for(int j=0;j<21;j++){
            cost[i][j]=INF;
        }
    }

    cin>>n>>m;

    for(int i=0;i<m;i++){
        cin>>a>>ch>>b>>ch>>c>>ch>>d;
        cost[a][b]=c;
        cost[b][a]=d;
    }

    cin>>a>>ch>>b>>ch>>c>>ch>>d;

    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
            }
        }
    }

    cout<<c-cost[a][b]-cost[b][a]-d<<endl;

    return 0;
}

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

int main(){
  int H,W;
  cin >>H>>W;
  
  string S[H];
  rep(i,0,H) cin >>S[i];
  
  const int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  const int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
  
  rep(y,0,H){
    rep(x,0,W){
      if(S[y][x]=='#') continue;
      int num = 0;
      rep(d,0,8){
        const int nx = x + dx[d];
        const int ny = y + dy[d];
        
        if(nx<0 or W<=nx)continue;
        if(ny<0 or H<=ny)continue;
        if(S[ny][nx]=='#') num++;
      }
      S[y][x] = char('0'+num);
    }
  }
  rep(i,0,H) cout << S[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int r, d, x; cin>>r>>d>>x;
    for(int i=0; i<10; i++){
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){

	int a;
	cin >> a;
	if(a==25){
		cout << "Christmas"<<endl;
	}else if(a==24){
		cout << "Christmas Eve" <<endl;
	}else if(a==23){
		cout << "Christmas Eve Eve" <<endl;
	}else{
		cout << "Christmas Eve Eve Eve" <<endl;
	}

	return 0;

}

Measured memory_bytes: 256
a=int(input())
if 1<=a<=9:
    b=a
if 10<=a<=99:
    b=9
if 100<=a<=999:
    b=a-90
if 1000<=a<=9999:
    b=909
if 10000<=a<=99999:
    b=a-9090
if a==100000:
    b=90909
print(b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,d=0,l[10005]={};
  int count=0;
  cin>>n>>x;
  for(int i=1; i<=n; i++){
    cin>>l[i];
  }
  for(int i=0; i<=n; i++){
    d+=l[i];
    if(d<=x)count++;
  }
  cout<<count<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int ,int>::iterator sit;
const int N = 100010;
char c;
int a[N]; bool b[N];
LL s[N], sa[N];
int main() {
	int n; scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d",&a[i]);
		if (i < n) {
			c = getchar(); while (c != '-' && c != '+') c = getchar();
			if (c == '-') b[i + 1] = true; else b[i + 1] = false;
		}
	}
	dep(i,n,1) sa[i] = sa[i + 1] + a[i];
	rep(i,1,n) if (b[i]) a[i] = -a[i];
	rep(i,1,n) s[i] = s[i - 1] + a[i];
	LL ans = s[n]; int last = 0;
	rep(i,1,n) if (b[i]) {
		if (last) {
			ans = max(ans, s[last] - (sa[last + 1] - sa[i]) + sa[i]);
		}
		last = i;
	}
	cout <<ans<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

using namespace std;
int main() {
	int n, w; cin >> n >> w;


	vector<vector<char>>d(n + 2, vector<char>(w + 2));
	for (int i = 1; i < n + 1; i++) {
		for (int j = 1; j < w + 1; j++) {
			cin >> d[i][j];
		}
	}
	
	vector<vector<int>>a(n + 2, vector<int>(w + 2));
	for (int i = 1; i < n + 1; i++) {
		for (int j = 1; j < w + 1; j++) {
			if (d[i][j] == '.') {
				if (d[i - 1][j - 1] == '#')a[i - 1][j - 1]++;
				if (d[i - 1][j] == '#')a[i - 1][j - 1]++;
				if (d[i - 1][j + 1] == '#')a[i - 1][j - 1]++;
				if (d[i][j - 1] == '#')a[i - 1][j - 1]++;
				if (d[i][j + 1] == '#')a[i - 1][j - 1]++;
				if (d[i + 1][j - 1] == '#')a[i - 1][j - 1]++;
				if (d[i + 1][j] == '#')a[i - 1][j - 1]++;
				if (d[i + 1][j + 1] == '#')a[i - 1][j - 1]++;
			}
			if (d[i][j] == '#') {
				a[i - 1][j - 1] = 9;
			}
		}
	}
	rep(i, n) {
		rep(j, w) {
			if(a[i][j] == 1 || a[i][j] == 2 || a[i][j] == 3 || a[i][j] == 4 || a[i][j] == 5 || a[i][j] == 6 || a[i][j] == 7 || a[i][j] == 8 || a[i][j] == 0)
			cout << a[i][j];
			else {
				cout << d[i + 1][j + 1];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
long long ans;
int main(void)
{
  int n, k;
  scanf("%d %d", &n, &k);
  if(n == 1){
    printf("%d\n", k);
    return 0;
  }
  ans =  k*pow((double)(k-1), (double)(n-1));
  printf("%lld\n",ans);
  return 0;
}

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

int main(){
	int i,j,n,nn,k=10000,*A,*B,*C;
	scanf("%d",&n);
	nn=n;
	A = malloc(sizeof(int)*n+2);
	i=1;
	while(nn--){
		scanf("%d",(A+i));
		i++;
	}

	B = malloc(sizeof(int)*n+2);
	C = malloc(sizeof(int)*k+2);
	for(i=0; i<=k; i++){
		C[i] = 0;
	}
	for(j=1; j<=n; j++){
		C[A[j]]++;
	}
	for(i=1; i<=k; i++){
		C[i] = C[i] + C[i-1];
	}
	for(j=n; j>=1; j--){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	for(i=1; i<=n; i++){
		i != n ? printf("%d ",B[i]):printf("%d\n",B[i]);
	}
	return 0;
}

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

long a[100000];

int cmp(const void* a,const void *b){
	return *(long*)a-*(long*)b;
}

int main(){
	long c,n,p,i,time=0,one=0;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
	}
	qsort(a,n,sizeof(long),cmp);
	p=a[0];
	c=0;
	for(i=0;i<n;i++){
		if(a[i]==p){
			c++;
		}else{
			if(c%2==0) one++;
			p=a[i];
			time+=(c-1)/2;
			c=1;
		}
	}
	if(c%2==0) one++;
	time+=(c-1)/2;
	time+=(one+1)/2;
	printf("%ld\n",n-2*time);
	return 0;
}

Measured memory_bytes: 1788
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    ll H,W; cin>>H>>W;
    if(H==1 || W==1){
        cout<<1<<endl; 
        return 0;
    }
    if(H%2==0){
        cout<<(H/2LL)*W<<endl;
        return 0;
    }
    if(W%2==0){
        cout<<(W/2LL)*H<<endl;
        return 0;
    }
    cout<<(H-1LL)/2LL*W+(W+1LL)/2LL<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;
 
typedef tuple<ll,ll,ll> T;
 
int main(){
	int N,K;
	cin >> N >> K;
	int ok=0;
	vector<string> p(N);
	for(int i=0;i<N;i++){
		cin >> p[i];
	}
	vector<int> pp(26,0);
	for(char c='A';c<='Z';c++){
		int now=0;
		for(int i=0;i<N;i++){
			if(p[i][0]==c)
				now++;
		}
		pp[c-'A']=now;
	}
	int ans=0;
	for(int n=1;n<=20000;n++){
		for(char c='A';c<='Z';c++){
			ok+=min(n,pp[c-'A']);
		}
		if(ok>=n*K)
			ans=n;
		ok=0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n-1).map(|_| iter.next().unwrap().parse().unwrap()).collect();
    let mut ans = vec![0; n];

    for x in a {
        ans[x-1] += 1;
    }

    println!("{}", ans.into_iter().map(|v| v.to_string()).collect::<Vec<_>>().join("\n"));
}


Measured memory_bytes: 15088