akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;
template<typename T, typename U> void amin(T &x, U y) { if(x > y) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if(x < y) x = y; }
typedef long long ll;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dy[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
const int dx[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };

int main() {
	ll H, W, N;
	ll ans[10];
	map<pair<int, int>, int> board;
	cin >> H >> W >> N;
	for(int i=0;i<10;i++) ans[i] = 0;
	ans[0] = (H-2) * (W-2);
	for(int i=0;i<N;i++) {
		int a, b;
		cin >> a >> b; a--; b--;
		for(int j=0;j<9;j++) {
			int na = a + dy[j], nb = b + dx[j];
			if( 0 < na && na < H-1 && 0 < nb && nb < W-1 ) {
				board[make_pair(na, nb)]++;
			}
		}
	}
	for(map<pair<int, int>, int>::iterator it=board.begin();it!=board.end();++it) {
		ans[it->second]++;
		ans[0]--;
	}

	for(int i=0;i<10;i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 56448
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    s = input()
    n = len(s)
    mind = HUGE
    for a in ABC:
        s_halo = a + s + a
        d = 0
        maxd = 0
        for c in s_halo:
            if c == a:
                d = 0
            else:
                d += 1
                maxd = max(maxd, d)
        mind = min(mind, maxd)
    print(mind)

main()


Measured memory_bytes: 3444
#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>;
using Graph = vector<vector<int>>;

// header area

int main(){
    int A, B, C; cin >> A >> B >> C;

    if(A+B+C>=22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 3596
import math
a,b,c,d,e,f=map(int,input().split())
m_suger=f*e/(100+e)
water=set()
w=math.floor(f/100/a)*a
water.add(w)
f_=f//100
while(1):
     w-=a
     if w<0:
          break
     w_=w
     while(w_<=f_):
          water.add(w_)
          w_+=b
water.remove(0)
m_rate=0
m_content=[0,0]
for w in water:
     res=f-w*100
     m_suger=min(w*e,res)
     s=math.floor(m_suger/c)*c
     while(1):
          if s<=m_suger:
               rate=s/(w+s)
               if rate>=m_rate:
                    m_rate=rate
                    m_content=[w,s]
          s-=c
          if s<0:
               break
          s_=s
          while(s_<=m_suger):
               rate=s_/(w+s_)
               if rate>=m_rate:
                    m_rate=rate
                    m_content=[w,s_]
               s_+=d
print(m_content[0]*100+m_content[1],m_content[1])

Measured memory_bytes: 3064
#include<cstdio>
typedef long long ll;
int n;
int masks[110];
ll p[110][15];
int num_bits[2000];
int numBits(int x)
{
	int ret = 0;
	while (x) { ret += (x & 1); x >>= 1; }
	return ret;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < 2000; i++) num_bits[i] = numBits(i);
	for (int i = 1; i <= n; i++)
	{
		int m = 0;
		for (int j = 1; j <= 10; j++)
		{
			int v;
			scanf("%d", &v);
			m = m * 2 + v;
		}
		masks[i] = m;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= 10; j++) scanf("%lld", &p[i][j]);
	}
	bool flag = false;
	ll ans = 0;
	for (int m = 1; m < (1 << 10); m++)
	{
		ll tot = 0;
		for (int i = 1; i <= n; i++)
		{
			tot += p[i][num_bits[m & masks[i]]];
		}
		if (!flag || ans < tot)
		{
			flag = true; ans = tot;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,q,a,b,d;
char c;
string e;
typedef tuple<int,int,char,int,string>P;
main(){
	cin>>n;
	vector<P>v;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c>>d>>e;
		v.emplace_back(a,b,c,d,e);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		tie(a,b,c,d,e)=v[i];
		cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
	}
}


Measured memory_bytes: 13060
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll dp[2000005];

int main()
{
    ll n;
    cin >> n;
    dp[0] = 1;
    ll s = 0;
    ll ans = 0;
    for(int i = 1; i < n; i++){
        if(i >= 3) s = (s + dp[i - 3]) % MOD;
        dp[i] = (s + dp[i - 1]) % MOD;
        ans = (ans + dp[i - 1] * (n - 1)) % MOD;
        if(i >= 2) ans = (ans + dp[i - 2] * (n - 1) % MOD * (n - 2)) % MOD;
    }
    ans = (ans + dp[n - 1] * n + dp[n - 2] * (n - 1) % MOD * (n - 2)) % MOD;
    for(int i = n; i <= n * 2 - 1; i++){
        if(i >= 3 && i <= n + 1) s = (s + dp[i - 3]) % MOD;
        if(i >= n + 2) s = (s + MOD - dp[i - (n + 2)]) % MOD;
        ans = (ans + s) % MOD;
    }
    cout << ans << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

int main() {
    IOS;

    long int a,b;
    cin>>a>>b;

    cout<<max(a+b,max(a-b,a*b));

    return 0;
}


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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,a,b,mn=0,sum=0;
	cin>>a>>b>>n;
	mn=min(b-1,n);
	sum=(long long int)((a*mn)/b)-a*(long long int)(mn/b);
	cout<<sum;
	return 0; 
} 


Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define len(s) s.length()
#define all(v) v.begin(),v.end()
const ll INF = INT_MAX;
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;
	// cin >> tc;
	while (tc--) {

		ll n, m, l, r;
		ll i, j;
		ll x, y;

		ll A, B, C, D;
		cin >>  A >> B >> C >> D;

		while (1) {
			C -= B;
			if (C <= 0) {
				cout << "Yes" << endl;
				return 0;
			}
			A -= D;
			if (A <= 0) {
				cout << "No" << endl;
				return 0;
			}

		}



	}
}

Measured memory_bytes: 3640
s = input()
if s == "SAT":
    print("1")
elif s == "FRI":
    print("2")
elif s == "THU":
    print("3")
elif s == "WED":
    print("4")
elif s == "TUE":
    print("5")
elif s == "MON":
    print('6')
else:
    print("7")

Measured memory_bytes: 2940
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
n, k = [int(i) for i in inputs[0].split()]
snacks = inputs[1:]

nusukes = {i: False for i in range(1, 1 + n)}

for n, sn in enumerate(snacks):
    if n % 2 == 0:
        continue
    else:
        temp = [int(i) for i in sn.split()]
        for i in temp:
            nusukes[i] = True

counter = 0
for key, value in nusukes.items():
    if not value:
        counter += 1

print(counter)


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

int main(){
	vector<int> in;
	int c, n, ans, x;
	n = 3;
	while(n--){
		cin >> x;
		in.push_back(x);
	}
	sort(in.begin(), in.end());
	ans = in[0] + in[1] + 10*in[2];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    for(int i=0; i<n; i+=2)
        cout << s[i];
    cout << endl;

    return 0;
}


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

int main() {
	// your code goes here
	long long n, m, ans = 0, mi = -1, ma = 999999;
    cin >> n >> m;
    for(int i = 0; i < m;i ++){
        long long l, r;
        cin >> l >> r;
        mi = max(mi, l);
        ma = min(ma, r);
    }
    for(int i = mi; i <= ma; i++){
    	ans++;
    }
    cout << ans << endl;
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;

    if (a + b == 15)
    {
        cout << "+";
    }
    else if (a * b == 15)
    {
        cout << "*";
    } else
    {
        cout << "x";
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    ll x; cin >> x;

    ll ans = x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;

    out(ans);
    return 0;
}










Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int N,S,W,Q;

int a[100000];

void solve(){

	unsigned int res=0;
	map<int,int> M;
	M.clear();

	int g = S;
	for(int i=0; i<N; i++) {
		a[i] = (g/7) % 10;
		if( g%2 == 0 ) { g = (g/2); }
		else           { g = (g/2) ^ W; }
	}

	if(Q==2 || Q==5){
		int count=0;
		for(int i=N-1;i>=0;i--){
			if(a[i]%Q==0)
				count++;
			if(a[i]!=0)
				res+=count;
		}
		cout<<res<<endl; return;
	}


	res=0;
	int mul=1;
	int bef=0;


	for(int i=N-1;i>=0;i--){
				bef = (a[i]*mul+bef)%Q;
				if(!M.count(bef)) M[bef] = 1;
				else               M[bef]++;
				mul = (10*mul)%Q;
				if(a[i] != 0) res += M[bef]-(bef!=0);
	}
	cout<<res<<endl;
}

int main(){

	while(cin>>N>>S>>W>>Q){
		if(N==0 && S==0 && W==0 && Q==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define N 100005

using namespace std;

int main()
{
    __

    int n,a[3][3],b[3][3],flag=0;
    set<int>seT;
    set<int>::iterator it;

    memset(b,0,sizeof(b));

    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin >> a[i][j];
        }
    }

    cin >> n;

    for(int val,i=0;i<n;i++){
        cin >> val;
        seT.insert(val);
    }

    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            it =seT.find(a[i][j]);
            if(it!=seT.end()) b[i][j]=1;
        }
    }

    for(int i=0;i<3;i++)
    {
        int cnt = 0;
        for(int j=0;j<3;j++)
        {
            if(b[i][j]==1) cnt++;
        }
        if(cnt == 3) {
        flag = 1;
        break;
        }
    }

    for(int i=0;i<3;i++)
    {
        int cnt = 0;
        for(int j=0;j<3;j++)
        {
            if(b[j][i]==1) cnt++;
        }
        if(cnt == 3) {
        flag = 1;
        break;
        }
    }

    if((b[0][0]==1 && b[1][1]==1 && b[2][2]==1) || (b[0][2]==1 && b[1][1]==1 && b[2][0]==1))
        flag =1;

    if(flag) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

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

    if(S[0] == 'R') {
        REP(i,0,N) {
            if(S[i] == 'L') S[i] = 'R';
            else S[i] = 'L';
        }
    }

    char prev = 'L';
    REP(i,1,N) {
        if(prev == 'L' && S[i] == 'R') K--;
        if(K < 0) break;
        prev = S[i];
        S[i] = 'L';
    }

    ll cnt = 1, g = 1;;
    prev = S[0];
    REP(i,1,N) {
        if(S[i] != prev) ++cnt;
        prev = S[i];
    }
    PR(SZ(S)-cnt);
    

    return 0;
}

/*

            

*/

Measured memory_bytes: 512
ab = [list(map(int, input().split())) for _ in range(3)]

li = []
for i in ab:
    for j in i:
        li.append(j)
res =0
for i in range(1,4):
    if(li.count(i)==2):
        res+=1

if(res==2):
    print("YES")
else:
    print("NO")


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int n;
    cin >> n;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s == "AC")
            cnt1++;
        else if (s == "WA")
            cnt2++;
        else if (s == "TLE")
            cnt3++;
        else if (s == "RE")
            cnt4++;
    }
    cout << "AC x " << cnt1 << "\n";
    cout << "WA x " << cnt2 << "\n";
    cout << "TLE x " << cnt3 << "\n";
    cout << "RE x " << cnt4 << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  char buf[200010];
  int hd, tl;
  hd = 200000; tl = 0;
  cin >> buf;
  for (char *p=buf; *p; p++){
    if (*p=='A') hd = min(hd, (int)(p-buf));
    if (*p=='Z') tl = max(tl, (int)(p-buf));
  }
  cout << (tl-hd+1) << endl;
  return 0;
}

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

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

	map<string, int> mp;
	for( int i = 0; i <= N - 3; i++ ) {
		for( int j = 0; j <= 9; j++ ) {
			char c = (char)('0' + j);
			int n = S.find( c, i + 1 );
			if( n == string::npos ) continue;
			for( int k = 0; k <= 9; k++ ) {
				char c1 = (char)('0' + k);
				int n1 = S.find( c1, n + 1 );
				if( n1 == string::npos ) continue;
				string s;
				s += S[i];
				s += c;
				s += c1;
				mp[s]++;
			}
		}
	}
	int ans = mp.size();

	cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
/* Author : Ravikumar Navale */
#define fastIo() ios_base :: sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define pb push_back
#define endl  "\n"
typedef long long int ll;
vector<pair<ll,ll> >v1, v2, v3;
const ll MOD = 1e9 + 7;
const ll NM = 1e5 + 7;
const double peek = 1e7 ;
vector<ll> v[NM];
vector<ll> dp(NM,0);
bool  b[NM];

int main()
{
    fastIo();
    ll N , M;
    cin >> N >> M;
    char  gr[N+1][M+1];
    ll dp[N+1][M+1];

    for(ll i= 1 ; i <= N ; i++)
    {
        for(ll j = 1; j <=M ; j++){
            cin >> gr[i][j];
            dp[i][j] = 0;
        }
    }
    dp[1][1] = 1;
    for(ll i= 2; i<=M ; i++)
        if(gr[1][i] =='.')
            dp[1][i] = dp[1][i-1];
    
    for(ll i=2 ; i <=N; i++)
        if(gr[i][1] == '.')
            dp[i][1] = dp[i-1][1] ;
    
    
    for(ll i= 2; i <=N ; i++)
    {
        for(ll j= 2; j <=M ; j++)
        {
                if(gr[i][j] == '.')
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
            
        }
    }
    
    
    cout << dp[N][M];
    
    
}

Measured memory_bytes: 12160
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll R, C, K;
ll a[3030][3030] = {0};
ll memo[3030][3030][4];
ll rec(ll i, ll j, ll k){
    if(i >= R || j >= C) return 0;
    if(memo[i][j][k] != -1) return memo[i][j][k];
    ll res = 0;

    if(k + 1 <= 3) res = max(res, rec(i + 1, j, 0) + a[i][j]);
    if(k + 1 <= 3) res = max(res, rec(i, j + 1, k+1) + a[i][j]);
    
    res = max(res, rec(i + 1, j, 0));
    res = max(res, rec(i, j + 1, k));

    return memo[i][j][k] = res;
}
int main(void){
    cin >> R >> C >> K;
    rep(i, K){
        ll r, c, v;
        cin >> r >> c >> v;
        r--, c--;
        a[r][c] = v;
    }


    rep(i, 3030) rep(j, 3030) rep(k, 4) memo[i][j][k] = -1;

    cout << rec(0, 0, 0) << endl;
}

Measured memory_bytes: 361760
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MAX = 100005;
ll tree[MAX];
ll parent[MAX];
ll n;
ll ord[MAX];
vll child[MAX];

void bfs() {
	queue<ll> qu;
	parent[1] = 1;
	qu.push(1);
	ll cnt = 1;
	while (!qu.empty()) {
		ll cur = qu.front();
		qu.pop();
		ord[cnt] = cur;
		cnt++;
		REP(i, 0, SIZE(child[cur]) - 1) {
			ll next = child[cur][i];
			if (next != parent[cur]) {
				qu.push(next);
			}
		}
	}
}

bool order(ll x, ll y) {
	return tree[x] > tree[y];
}

int main() {
	cin >> n;
	REP(i, 2, n) {
		cin >> parent[i];
		child[parent[i]].push_back(i);
	}
	bfs();
	PER(i, n, 1) {
		ll cur = ord[i];
		if (SIZE(child[cur]) == 0) {
			tree[cur] = 0;
		}
		else {
			sort(child[cur].begin(), child[cur].end(), order);
			ll cnt = -1;
			REP(j, 0, SIZE(child[cur]) - 1) {
				ll next = child[cur][j];
				cnt = max(cnt, tree[next] + j + 1);
			}
			tree[cur] = cnt;
		}
	}
	cout << tree[1] << endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<functional>
#include<vector>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<stack>
using namespace std;
int main()
{
  int t;
  cin>>t;
  int arr[102][102];
  for(int i=0;i<t;i++)
  {
    for(int j=0;j<2;j++)
    {
      cin>>arr[i][j];
    }
  }//00 01
   //10 11
  int count=0;
  for(int i=0;i<t;i++)
  {
   if(arr[i][0]==arr[i][1])
      {
        count++;
        if(count==3)
        {
          cout<<"Yes";
          return 0;
        }
      }
      else
      {
        count=0;
      }
  }
  cout<<"No";
  return 0;
}
/*
00 01
10 11
20 21
*/


Measured memory_bytes: 3656
N=int(input())
for i in range(N):
    s__=input()
    s_=""
    s=[]
    #step1
    for i in range(len(s__)):
        if s__[i].isdigit():
            s_+=s__[i]
        else:
            s_+=" "+s__[i]+" "
    s_=s_.split(" ")
    for i in range(len(s_)):
        if s_[i]!='':
            s.append(s_[i])

    #step2
    M=[[] for i in range(10)]
    M_=[0]*10
    D=[]
    count=0
    for i in range(len(s)):
        if s[i]=='[':
            count +=1
        elif s[i]==']':
            M[count].append(M_[count])
            M_[count]=0
            M_[count-1]+=1
            count-=1
        else:
            D.append(int(s[i]))
    for i in range(1,len(M)):
        if len(M[i])==0:
            M=M[1:i]
            break
    for i in range(len(M[-1])):
        M[-1][i]=1
    for i in range(len(M)):
        M[i]=[0]+M[i]
    for i in range(len(M)):
        for j in range(1,len(M[i])):
            M[i][j]=M[i][j]+M[i][j-1]

    #step3
    ans=[]
    for i in range(len(M)):
        ans.append([0]*(len(M[i])-1))
    for j in range(len(ans[-1])):
        ans[-1][j]=(D[j]//2)+1
    for i in range(len(M)-2,-1,-1):
        for j in range(len(ans[i])):
            partial_sorted=sorted(ans[i+1][M[i][j]:M[i][j+1]])
            ans[i][j]=sum(partial_sorted[:((len(partial_sorted)//2)+1)])

    print(ans[0][0])


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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);

    for (int i = 0; i < N; i++) {
        cin >> L.at(i);
    }

    int count = 1;
    int S = 0;

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

        S += L.at(i);

        if (S > X) {
            break;
        }

        else {
            count++;
        }

    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n,m;
    cin >> n >> m;
    priority_queue<int> q;
    vi a(n);
    rep(i,n)cin >> a[i],q.push(a[i]);
    rep(i,m){
        int t = q.top();
        q.pop();
        t /= 2;
        q.push(t);
    }
    int ans = 0;
    while(q.size()){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 2168
n=int(input()) 
s=input()
a=[]
r,w=0,0
ans=float("inf")
for i in range(n):
    if s[i]=="R":
        r+=1
    else:
        w+=1
    a.append([r,w])
if r==n or w==n:
    print(0)
    exit()
for i in range(n):
    r1,w1=a[i][0],a[i][1]
    r2,w2=r-r1,w-w1
    t=min(w1,r2)
    tmp=t+max(w1-t,0)+max(r2-t,0)
    if tmp<ans:
        ans=tmp
print(ans)

Measured memory_bytes: 93820
#include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;std::set<int>::iterator s,S;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(s=t.begin();s!=t.end();s++)for(S=s;++S!=t.end();v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=0;i<n/2;)printf("%d\n",v[++i]);}}

Measured memory_bytes: 1300
#include<stdio.h>

int main()
{
    int H,N;
    scanf("%d %d\n",&H,&N);
    for (int i=0;i<N;i++)
    {
        int A;
        scanf("%d",&A);
        H -= A;
    } 

    if (H<=0){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<pair<int,int>> E[101010];
int C[101010];
int ma;
void dfs(int cur,int pre,int par) {
	set<int> S;
	S.insert(par);
	int nex=1;
	FORR(e,E[cur]) if(e.first!=pre) {
		while(S.count(nex)) nex++;
		C[e.second]=nex;
		ma=max(ma,nex);
		dfs(e.first,cur,nex);
		nex++;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back({y-1,i});
		E[y-1].push_back({x-1,i});
	}
	
	dfs(0,-1,0);
	cout<<ma<<endl;
	FOR(i,N-1) cout<<C[i]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 13952
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long

    int res[1010][1010];

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

           int h,w,a,b;
            cin>>h>>w>>a>>b;
           
            for(int i=0;i<b;i++){
                for(int j=a;j<=w;j++)
                    res[i][j]=1;
            }

            for( int i=b;i<h;i++ ){
                for(int j=0;j<a;j++){
                    res[i][j]=1;
                }
            }

                for(int i=0;i<h;i++){
                    for(int j=0;j<w;j++)
                        cout<<res[i][j];
                        cout<<endl;
                }

            return 0;
}































Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(void){

	string s;

	cin >> s;


	int sum = 0;

	int num = 0;

	for (int i = 0; i < s.size(); i++){
		if (s[i] == '9')
			num++;
	}


	if (s.size() == 1){
		sum += s[0] - '0';
	}
	else if (s.size() == num)
		sum += 9;
	else if (s.size() - 1 == num && s[0] != '9'){
		sum += s[0] - '0';
	}
	else {
		sum += s[0] - '1';
	}

	sum += 9*(s.size()-1);


	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,K;
cin >> N >> K;
int ans = 1;
for (int i = 0;i < N;i++) {
  if (ans * 2 - ans < K) ans *= 2;
  else ans += K;
}
cout << ans << endl;




return 0;
}

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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int a, b, c, d, e, o = 0;
    cin >> a >> b >> c
    	>> d >> e;
    int min = a;
    min = (b%10 < min%10 and b%10 != 0) ? b : min;
    min = (c%10 < min%10 and c%10 != 0) ? c : min;
    min = (d%10 < min%10 and d%10 != 0) ? d : min;
    min = (e%10 < min%10 and e%10 != 0) ? e : min;

    o += (a%10)? a + 10-a%10 : a;
    o += (b%10)? b + 10-b%10 : b;
    o += (c%10)? c + 10-c%10 : c;
    o += (d%10)? d + 10-d%10 : d;
    o += (e%10)? e + 10-e%10 : e;

    o -= (min%10)? min + 10-min%10 : min;
    o += min;
    cout << o << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n,x;
  cin >>n>>x;
  vector<int> m(n);
  int ans = 0;
  int mincost = 1000;
  rep(i,n){
    cin >>m[i];
    x -= m[i];
    ans ++;
    mincost = min(mincost,m[i]);
  }
  if(x>0) ans += x/mincost;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(ll i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(ll i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007


int main(){
	string t;
	cin>>t;
	int n;
	cin>>n;
	vector<string> s(n);
	rep(i,n) cin>>s[i], s[i] += s[i];
	int ans = 0;
	rep(i,n){
		if(s[i].find(t) != string::npos) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <sstream>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int dp[3001][3001] = {0};

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

	string s; cin >> s; s = ' ' + s;
	string t; cin >> t; t = ' ' + t;

	FOR_LT(i, 1, s.size()) {
		FOR_LT(j, 1, t.size()) {
			int val = 0;
			val = max(val, dp[i][j - 1]);
			val = max(val, dp[i - 1][j]);

			if (s[i] == t[j]) {
				val = max(val, dp[i - 1][j - 1] + 1);
			}

			dp[i][j] = val;
		}
	}

	int n = s.size() - 1;
	int m = t.size() - 1;

	stringstream ans;
	while (n != 0 && m != 0) {
		int val = dp[n][m];
		if (s[n] == t[m] && dp[n - 1][m - 1] == val - 1) {
			assert(s[n] == t[m]);
			ans << s[n];
			n--;
			m--;
			continue;
		}

		if (dp[n][m - 1] == val) {
			m--;
		}
		else {
			assert(dp[n - 1][m] == val);
			n--;
		}
	}

	string ansstr = ans.str();
	FOR_DW(i, ansstr.size() - 1, 0) {
		cout << ansstr[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <vector>
using namespace std;
int n, m, x;
vector<int> c;
vector< vector< int > > a;
int main(void){
    cin >> n >> m >> x;
    c.assign(n, 0);
    a.assign(n, vector<int>(m, 0));
    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=0;j<m;j++) cin >> a[i][j];
    }
    int ans = 1e9;
    for(int i=0;i<(1<<n);i++){
        vector<int> b(m, 0);
        int cst = 0;
        for(int j=0;j<n;j++){
            if(((i>>j)&1) == 0) continue;
            cst += c[j];
            for(int k=0;k<m;k++) b[k] += a[j][k];
        }
        for(int k=0;k<m;k++){
            if(b[k] < x) cst = 1e9;
        }
        if(cst < ans) ans = cst;
    }
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct Node {
    int parent;
    int left;
    int right;
} tree[25];

void preorder(int i) {
    if (i < 0)
        return;
    cout << " " << i;
    preorder(tree[i].left);
    preorder(tree[i].right);
}

void inorder(int i) {
    if (i < 0)
        return;
    inorder(tree[i].left);
    cout << " " << i;
    inorder(tree[i].right);
}

void postorder(int i) {
    if (i < 0)
        return;
    postorder(tree[i].left);
    postorder(tree[i].right);
    cout << " " << i;
}

void treeWalk(int n) {
    int root;
    for (int i = 0; i < n; ++i) {
        if (tree[i].parent == -1) {
            root = i;
            break;
        }
    }
    cout << "Preorder" << endl;
    preorder(root);
    cout << endl << "Inorder" << endl;
    inorder(root);
    cout << endl << "Postorder" << endl;
    postorder(root);
    cout << endl;
}

int main() {
    int n, id, l, r;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        tree[i].parent = -1;
    }
    for (int i = 0; i < n; ++i) {
        cin >> id >> l >> r;
        tree[id].left = l;
        tree[id].right = r;
        if (l >= 0)
            tree[l].parent = id;
        if (r >= 0)
            tree[r].parent = id;
    }
    treeWalk(n);

    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int a, b;
    string s;
    cin >> a >> b;

    if((a + b) % 2 == 0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int h,w;
    cin >> h >> w;

    vector<string> v(h);
    REP(i,h) cin >> v[i];

    for(int i = h-1;i >= 0; i--) {
        auto it = find(ALL(v[i]),'#');
        if (it == v[i].end()) v.erase(v.begin()+i);
    }
    for(auto i = w-1; i >=0;i--) {
        bool erase = true;
        REP(j,v.size()) {
            if (v[j][i] == '#') {
                erase = false;
                break;
            }
        }
        if (erase) {
            REP(j,v.size()) v[j].erase(v[j].begin()+i);
        }
    }

    REP(i,v.size()) {
        cout << v[i] << endl;
    }

    return 0;
}

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

using namespace std;

const int INF = 1e+6;

int dp[1000][5001];
int dp_[1000][5001];
vector<int> G[1000];
int min_pair[1000];
int X[1000];
int N;

void copy_dp(int j){
    for(int i = 0; i <= 5000; i++){
        dp_[j][i] = dp[j][i];
    }
}

void clear_dp_both(int j){
    for(int i = 0; i <= 5000; i++){
        dp_[j][i] = INF;
        dp[j][i] = INF;
    }
}

void clear_dp(int j){
    for(int i = 0; i <= 5000; i++){
        dp[j][i] = INF;
    }
}

void dfs(int v){
    clear_dp_both(v);
    dp_[v][0] = 0;
    for(int i = 0; i < G[v].size(); i++){
        dfs(G[v][i]);
        int a = X[G[v][i]];
        int b = min_pair[G[v][i]];
        //if(v == 0) cout << "H "<< a << ' ' << b << endl;
        for(int j = 0; j+(min(a, b)) <= X[v]; j++){
            if(j+a <= X[v] && dp_[v][j] != INF) dp[v][j+a] = min(dp[v][j+a], dp_[v][j]+b);
            if(j+b <= X[v] && dp_[v][j] != INF) dp[v][j+b] = min(dp[v][j+b], dp_[v][j]+a);
            //if(v == 0) cout << j << ':' << dp[v][j] << endl;
        }
        copy_dp(v);
        clear_dp(v);
    }
    min_pair[v] = INF;
   // cout << "X[v]:" << X[v] << endl; 
    for(int j = 0; j <= X[v]; j++){
        min_pair[v] = min(min_pair[v], dp_[v][j]);
        //cout << dp_[v][j] << ' ';
    }
    //cout << endl;
    //cout << v << ' ' << min_pair[v] << endl;
}

int main(){
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int P;
        cin >> P;
        P--;
        G[P].push_back(i+1);
    }
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }
    dfs(0);
    if(min_pair[0] == INF){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << "POSSIBLE" << endl;
    }
}

Measured memory_bytes: 39424
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 3020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, a;
	cin >> n >> a;
	cout << ((n % 500) <= a ? "Yes" : "No") << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 305;
double dp[MAX_N][MAX_N][MAX_N];
int N;

double f(int a, int b, int c) {
  if (dp[a][b][c] >= 0) return dp[a][b][c];
  if (a+b+c == 0) return 0;
  double res = 0;
  if (a > 0) {
    res += (double)a/N * (f(a-1, b, c));
  }
  if (b > 0) {
    res += (double)b/N * (f(a+1, b-1, c));
  }
  if (c > 0) {
    res += (double)c/N * (f(a, b+1, c-1));
  }
  res += 1.0;
  res = res * (double)N / (a+b+c);
  return dp[a][b][c] = res;
}

int main2() {
  REP(i, MAX_N) REP(j, MAX_N) REP(k, MAX_N) dp[i][j][k] = -1;
  N = nextInt();
  int count[4] = {0};
  REP(i, N) {
    int x = nextInt();
    count[x]++;
  }
  double ans = f(count[1], count[2], count[3]);
  printf("%.10f\n", ans);
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}




Measured memory_bytes: 221952
def solve(a, b, c):
    l = 0; r = a;
    for t in range(514):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Measured memory_bytes: 7728
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}


int main(){
	optimizeIO();

    int n, m;
    cin >> n >> m;
    vector< vector<char> > maze(n, vector<char>(m));
    vector< vector<int> > dp(n, vector<int>(m));

    REP(i, 0, n)
        REP(j, 0, m)
            cin >> maze[i][j];

    bool flag = true;
    REP(i, 0, n){
        if( maze[i][0] == '#')
            flag = false;
        if( flag )
            dp[i][0] = 1;
        else
            dp[i][0] = 0;
    }
    flag = true;
    REP(j, 0, m){
        if( maze[0][j] == '#')
            flag = false;
        if( flag )
            dp[0][j] = 1;
        else
            dp[0][j] = 0;
    }

    REP(i, 1, n){
        REP(j, 1, m){
            if( maze[i][j] == '#' )
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
        }
    }

    cout << dp[n-1][m-1]%MOD << endl;

	return 0;
}

Measured memory_bytes: 5248
s = input()
list_0 = 0
list_1 = 0
half = 0

for i in range(len(s)):
  if s[i] == "1" and list_0 == 0:
    list_1 += 1
  elif s[i] == "1" and list_0 != 0:
    list_0 =list_0 - 1
    half += 1
  elif s[i] =="0" and list_1 == 0:
    list_0 += 1
  else:
    list_1 = list_1 - 1
    half += 1

print(half * 2)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int getLCS(char*, char*);

main(){
	char x[1001], y[1001];
	int q, i;

	scanf("%d", &q);
	for (i = 0; i < q; i++){
		scanf("%s%s", x, y);
		printf("%d\n", getLCS(x, y));
	}
	return 0;
}

int getLCS(char *x, char *y){
	int i, j, lenX, lenY;
	static int C[1001][1001];

	lenX = strlen(x);
	lenY = strlen(y);

	for (i = 1; i <= lenX; i++){
		for (j = 1; j <= lenY; j++){
		        if (i==0 || j==0) C[i][j] = 0;
			else if (x[i-1] == y[j-1]) C[i][j] = C[i-1][j-1] + 1;
			else C[i][j] = ((C[i-1][j] >=  C[i][j-1])?  C[i-1][j] : C[i][j-1]);
		}
	}

	return C[lenX][lenY];
}

Measured memory_bytes: 4520
#include<bits/stdc++.h>
std::vector<int>A['   '];int N,M,S['   '],B,L,R,I,X;void U(int z,int u){while(z<=N)S[z]+=u,z+=z&-z;}main(){std::cin>>M>>N;for(I=1;I<=M;I++)std::cin>>L>>R,A[R-L+1].push_back(L);for(L=1;L<=N;L++){B=M;for(I=L;I<=N;I+=L){R=0,X=I;while(X)R+=S[X],X-=X&-X;B+=R;}for(int u:A[L])U(u,1),U(u+L,-1),M--;std::cout<<B<<"\n";}}

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

int main(){
  int s[110][110]={0},m,n,sum;
  char a;
  cin>>m>>n;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      cin>>a;
      if(a=='o')s[i][j]=1;
      if(a=='x')s[i][j]=2;
    }
  }
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(i==1&&s[i][j]==0)s[i][j]=3;
      if(s[i][j]==1){
	if(s[i][j-1]==0)s[i][j-1]=3;
	if(s[i][j+1]==0)s[i][j+1]=3;
      }
      else if(s[i][j]==2){
	if(s[i-1][j-1]==0) s[i-1][j-1]=3;
	if(s[i-1][j]==0)   s[i-1][j]=3;
	if(s[i-1][j+1]==0) s[i-1][j+1]=3;
	if(s[i][j-1]==0)   s[i][j-1]=3;
	if(s[i][j+1]==0)   s[i][j+1]=3;
	if(s[i+1][j-1]==0) s[i+1][j-1]=3;
	if(s[i+1][j]==0)   s[i+1][j]=3;
	if(s[i+1][j+1]==0) s[i+1][j+1]=3;
      }
    }
  }
  sum=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(s[i][j]==0)sum++;
      //cout<<s[i][j];//////////
    }
    //cout<<endl;//////////////
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int Mod = 1e9 + 7;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
void Add(int &a, int b){ a = add(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
cs int N = 605;
int n, dp[2][N][N];
bool ban[N], pt[N];
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n); int ct=0;
	for(int i=1,x,y; i<=n; i++){
		scanf("%d%d",&x,&y);
		if(~x && ~y) ban[x]=ban[y]=true;
		else if(~x) pt[x] = true;
		else if(~y) pt[y] = true;
		else ++ct;
	} int now = 0, nxt = 1; dp[now][0][0] = 1;
	for(int i=n+n; i>=1; i--)if(!ban[i]){
		memset(dp[nxt],0,sizeof(dp[nxt]));
		for(int x=0,lm=n+n-i+1; x<=lm; x++)
		for(int y=0,coe; x+y<=lm; y++)
		if(coe=dp[now][x][y]){
			if(!pt[i]&&y)Add(dp[nxt][x][y-1],mul(y,coe));
			if(x)Add(dp[nxt][x-1][y],coe);
			if(pt[i])Add(dp[nxt][x][y+1],coe);
			else Add(dp[nxt][x+1][y],coe);
		} swap(now,nxt);
	} int ans = dp[now][0][0];
	for(int i=1; i<=ct; i++)Mul(ans,i);
	cout<<ans; return 0;
}

Measured memory_bytes: 3072
from collections import Counter

n = int(input())
S = [input() for i in range(n)]

s0 = Counter(S[0])

for i in S:
    for j in list(s0):
        if j in i:
            s0[j] = min(s0[j], i.count(j))
        else:
            del s0[j]

s0 = sorted(s0.items())
ans = ''
for i in s0:
    ans += i[0] * i[1]

print(ans)


Measured memory_bytes: 3444