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

using namespace std;

const int inf = 1e8;

int dist[100010][3];

int main(){
  int N,M; cin >> N >> M;
  vector<vector<int>> to(N);
  for(int i = 0; i < M; i++){
    int u,v; cin >> u >> v; u--; v--; 
    to[u].push_back(v);}
  
  for(int i = 0; i < 100010; i++){
    for(int j = 0; j < 3; j++){
      dist[i][j] = inf;}} // infは未到達
  
  int start,terminate; cin >> start >> terminate; start--; terminate--;
  dist[start][0] = 0; //dist[terminate][0]を調べたい
    
  queue<pair<int,int>> Q; Q.push(make_pair(start,0)); 
  
  while(!Q.empty()){
    pair<int,int> p = Q.front(); Q.pop();
    int s = p.first; int t = p.second; int nt = (t + 1) % 3;
    // sノードに繋がるノーどを全て調べたい  
    for(int i = 0; i < to[s].size(); i++){
      int r = to[s][i];
      if(dist[r][nt] != inf){ continue;}
      else{
        dist[r][nt] = dist[s][t] + 1; Q.push(make_pair(r,nt));}}}
  
  int answer = dist[terminate][0];
  if( answer == inf){ cout << -1 << endl;}
  else{
    cout << answer / 3 << endl;}

  return 0;}
    
    

Measured memory_bytes: 6912
list_S = list(input())
list_T = list(input())
list_S.reverse()
list_T.reverse()
num = -1
for i in range(len(list_S)):
    cnt = 0
    while True:
        if cnt == len(list_T) or i + cnt == len(list_S):
            break
        if list_S[i + cnt] == "?":
            s = list_T[cnt]
        else:
            s = list_S[i + cnt]
        if list_T[cnt] != s:
             break

        cnt += 1
    if cnt == len(list_T):
        num = i
        break

if num == -1:
    ans = "UNRESTORABLE"
else:
    for j in range(cnt):
        list_S[num+j] = list_T[j]

    for i in range(len(list_S)):
        if list_S[i] == "?":
            list_S[i] = "a"
    list_S.reverse()
    ans = "".join(list_S)
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int sum;
	int n;
	int map[1000];
	int i;
	int m;
	int ans;
	int dice[1000];
	int num;
	
	while (1){
		scanf("%d %d", &n, &m);
		if (!n && !m){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf("%d", &map[i]);
		}
		
		sum = 1;
		for (i = 0 ;i < m; i++){
			scanf("%d", &dice[i]);
		}
		
		for (i = 0; i < m; i++){
			sum += dice[i];
			if (sum >= n){
				ans = i + 1;
				break;
			}
			sum += map[sum - 1];
			if (sum >= n){
				ans = i + 1;
				break;
			}
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int x; cin >> x;

	if(x<600) cout << 8 << endl;
	else if(x<800) cout << 7 << endl;
	else if(x<1000) cout << 6 << endl;
	else if(x<1200) cout << 5 << endl;
	else if(x<1400) cout << 4 << endl;
	else if(x<1600) cout << 3 << endl;
	else if(x<1800) cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll x,k,d;
    cin>>x>>k>>d;
    if(x>0){
        ll moves=x/d;
        if(k>moves){
            x-=moves*d;
            k-=moves;
            if(k%2==0) cout<<abs(x);
            else cout<<abs(x-d);
        }else{
            x-=k*d;
            cout<<abs(x);
        }
    }else if(x<0){
        x=-x;
        ll moves=x/d;
        if(k>moves){
            x-=moves*d;
            k-=moves;
            if(k%2==0) cout<<abs(x);
            else cout<<abs(x-d);
        }else{
            x-=k*d;
            cout<<abs(x);
        }
    }else{
        if(k%2==0) cout<<0;
        else cout<<d;
    }
    //cout<<abs(x);
    return 0;
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long int sum = 0;
	for (int i = 1; i < n; i++) {
		if (s[i] == s[i - 1]) {
			sum++;
		}
	}
	cout << n - sum;
}

Measured memory_bytes: 512
s = input().split()

count5 = 0
count7 = 0
 
if s[0] == "5":
    count5 = count5 + 1
if s[0] == "7":
    count7 = count7 + 1
if s[1] == "5":
    count5 = count5 + 1
if s[1] == "7":
    count7 = count7 + 1
if s[2] == "5":
    count5 = count5 + 1
if s[2] == "7":
    count7 = count7 + 1
    
if count5 == 2 and count7 == 1:
    print("YES")
else:
    print("NO")


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

const int mod = 1000000007;

long long power(int a, int b){
	if (!b) return 1;
	long long t = power(a, b >> 1);
	return b & 1 ? t * t % mod * a % mod : t * t % mod;
}

long long fac[200010], inv[200010];

long long C(int a, int b){
	return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main(){
	int n, m; cin >> n >> m;
	fac[0] = 1;
	for (int i = 1; i <= n + 100; i++){
		fac[i] = fac[i - 1] * i % mod;
	}
	inv[n + 100] = power(fac[n + 100], mod - 2);
	for (int i = n + 99; i >= 0; i--){
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
	int cnt = 0;
	long long ans = 1;
	for (int i = 2; i * i <= m; i++){
		if (m % i) continue;
		int cnt = 0;
		while (m % i == 0) m /= i, cnt++;
		ans = ans * C(cnt + n - 1, n - 1) % mod;
	}
	if (m > 1) ans = ans * C(1 + n - 1, n - 1) % mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const int MAXN=7e6+10;
const int MAXM=505;
const int INF=10000000;
const int mod=1e9+7;
 
ll power(ll a,ll b){
    ll c=1;
    while(b){
        if ((b&1)!=0) c=(c*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return c;
}
 
int f(int a){
    int len=0;
    while(a!=0){
        len++;
        a/=10;
    }
    return len;
}
 
int main(){
    int s;
    scanf("%d",&s);
    int r=0,sum=0,a=1,len1=1,b=1,len2=1;
    ll cnt1=0;
    for(int i=1;i<1e7;i++){
        if (i-1<a) sum-=len1-1;
        else a*=10,len1++,sum-=len1-1;
        while(sum<s){
            r++;
            if (r<b) sum+=len2-1;
            else b*=10,len2++,sum+=len2-1;
        }
        if (sum==s){
            cnt1++;
            if (cnt1==mod) cnt1=0;
        }
    }
    //cout<<cnt1<<endl;
    ll cnt2=0;
    for(int i=1;i*i<=s;i++){
        if (s%i!=0) continue;
        if (i*8<=s){
            cnt2+=(((power(10,s/i-1)*9)%mod-i)%mod+mod)%mod;
            cnt2%=mod;
        }
        if (i*i!=s && i>=8){
            cnt2+=(((power(10,i-1)*9)%mod-s/i)%mod+mod)%mod;   
            cnt2%=mod;
        }

    }
    ll cnt3=s/8;
    cout<<((cnt1+cnt2)%mod+cnt3)%mod<<endl;
    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    r,d,x=map(int,input().split())
    A=[0]*11
    A[0]=x
    for i in range(10):
        A[i+1]=r*A[i]-d
    for i in range(1,11):
        print(A[i])
resolve()

Measured memory_bytes: 38256
// Aizu Vol-5 0506: String
// 2017.8.30 bal4u@uu

#include <stdio.h>

char s[2][1000000];

char *d2c(char *p, int n)
{
	int i;
	static int t[7] = { 1000000, 100000, 10000, 1000, 100, 10, 1 };
	if (!n) *p++ = '0';
	else for (i = 1; i < 7; i++) if (n >= t[i]) *p++ = (n % t[i-1]) / t[i] + '0';
	return p;
}

int main()
{
	int n, r;
	int k1, k2;
	char *p, *q, a;

	while (scanf("%d", &n) && n) {
		scanf("%s", s[0]);
		for (k1 = 0, k2 = 1; n-- > 0; k1 = k2, k2 = !k2) {
			p = s[k1], q = s[k2], a = 0, r = 0;
			while (*p) {
				if (*p != a) { if (r > 0) q = d2c(q, r), *q++ = a; a = *p, r = 1; }
				else r++;
				p++;
			}
			if (r > 0) q = d2c(q, r), *q++ = a;
			*q = 0;
		}
		puts(s[k1]);
	}
	return 0;
}

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

int main() {

    int ans = 0;

    for(int i=0; i<4; i++){
        char c;
        cin >> c;
        if(c == '+'){
            ans++;
        }
        else{
            ans--;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        n,m,x,y=map(int, input().split())
        lx=list(map(int,input().split()))
        ly=list(map(int,input().split()))
        xmax=max(lx)
        ymin=min(ly)
        for i in range(x+1,y+1):
            if xmax<i and ymin >=i:
                return 'No War'
        return 'War'
    print(main())
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
const int MAXN = (int)((1e5) + 100);
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;} 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N =  (int)(1e6+5); 
signed main(){
  fio;
    int n;
    cin>>n;

    int ret = 0;
    int a = n/500;
    int b = (n%500)/5;
    ret += a*1000 + b*5;

    cout<<ret<<endl;
  rr;
}



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

using namespace std;

#define int long long

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

    int n, k, sum = 0, mx;
    cin >> n >> k;

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

    for (int i = 0; i < k; i++)
        sum += a[i];
    mx = sum;

    for (int i = k; i < n; i++)
    {
        sum -= a[i - k];
        sum += a[i];
        mx = max(mx, sum);
    }

    cout << fixed << setprecision(20);
    cout << mx * 0.5 << "\n";

    return 0;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}


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

	int X;
	cin >> X;
	int sum=0,i=1;
	for (;sum<X;sum+=i++);
	cout << i-1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int N, M, X, Y;
	int x[100], y[100];
	int i, j, k, cnt_x, cnt_y, Z;
	
	scanf("%d %d %d %d",&N,&M,&X,&Y);
	for(i = 0;i < N;i ++){
		scanf("%d",&x[i]);
	}
	for(i = 0;i < M;i ++){
		scanf("%d",&y[i]);
	}
	
	for(Z = X + 1;Z <= Y;Z ++){
		cnt_x = 0;
		cnt_y = 0;
		for(j = 0;j < N;j ++){
			if(x[j] < Z)	cnt_x++;
		}
		for(j = 0;j < M;j ++){
			if(y[j] >= Z)	cnt_y++;
		}
		if(cnt_x == N && cnt_y == M){
			printf("No War\n");
			return 0;
		}
	
	}
	
	printf("War\n");
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	getchar();
	for (int i = 0;i < n;i++) {
		string s;
		getline(cin, s);
		int a = s.size();

		if (a >= 7) {
			for (int j = 0;j < a - 6;j++) {
				string sb;
				sb = s.substr(j, 7);
				if (sb == "Hoshino") {
					s.replace(j, 7, "Hoshina");
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
const int MAX = 1e9;

class Solution {
 public:
  void solve() {
    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 0; i < k; ++i) cout << s << " ";
    for (int i = k; i < n; ++i) cout << (s == MAX ? 1 : s + 1) << " ";
  }
};

int main() {
  Solution solution = Solution();
  solution.solve();
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;





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

    int n,y;
    cin >> n >> y;
    bool ok = false;
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n-i;j++){
            int k = n-i-j;
            if(10000*i+5000*j+1000*k==y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    if(!ok) cout << -1 << " " << -1 << " " << -1 << endl;


    cout << endl;
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int N,M;

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
UnionFindTree uf(0);

int dp[111111],dp2[111111];
vint G[111111];
void dfs(int v,int p,int r){
    for(auto u:G[v]){
        if(u==p)continue;
        if(uf.find(u)!=r){
            chmax(dp2[v],dp[u]+1);
        }
        else{
            dfs(u,v,r);
            chmax(dp2[v],dp2[u]+1);
        }
    }
}

void dfs2(int v,int p,int r,int x){
    vint lis={x};
    for(auto u:G[v]){
        if(u==p)continue;
        if(uf.find(u)==r){
            lis.pb(dp2[u]+1);
        }
        else{
            lis.pb(dp[u]+1);
        }
    }
    sort(all(lis));reverse(all(lis));
    dp[v]=lis[0];

    for(auto u:G[v]){
        if(u==p||uf.find(u)!=r)continue;
        int xx;
        if(lis[0]==dp2[u]+1)xx=lis[1];
        else xx=lis[0];

        dfs2(u,v,r,xx+1);
    }
}

signed main(){
    cin>>N>>M;
    vpint es,es2;

    rep(i,M){
        int a,b,w;
        cin>>a>>b>>w;
        a--;b--;
        if(w==1)es.pb({a,b});
        else es2.pb({a,b});
    }

    uf=UnionFindTree(N);
    for(auto &p:es2){
        if(uf.areSame(p.fi,p.se)){
            cout<<"Infinite"<<endl;
            return 0;
        }
        uf.unite(p.fi,p.se);
    }


    vector<vint>D(N);
    vint deg(N);
    for(auto &p:es){
        D[uf.find(p.fi)].pb(uf.find(p.se));
        deg[uf.find(p.se)]++;
    }


    vint ord;
    rep(i,N)if(uf.find(i)==i&&deg[i]==0)ord.pb(i);
    rep(i,ord.size()){
        int v=ord[i];
        for(auto u:D[v]){
            if(--deg[u]==0)ord.pb(u);
        }
    }

    if(count(all(deg),0)!=N){
        cout<<"Infinite"<<endl;
        return 0;
    }


    for(auto &p:es)G[p.fi].pb(p.se);
    for(auto &p:es2)G[p.fi].pb(p.se),G[p.se].pb(p.fi);

    for(int i=(int)ord.size()-1;i>=0;i--){
        dfs(ord[i],-1,ord[i]);
        dfs2(ord[i],-1,ord[i],0);
    }

    cout<<*max_element(dp,dp+N)<<endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define SUBL freopen("/home/ajinkya/Desktop/input.txt","r",stdin); freopen("/home/ajinkya/Desktop/output.txt","w",stdout); 
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;




int main()
{
    fastio 
    // SUBL
  	int a, b, c;
  	cin >> a >> b >> c;
  	cout << max(0, c-a+b);
    return 0;
}         	

Measured memory_bytes: 256
import sys

def ii2ss(n):
    return [sys.stdin.readline() for _ in range(n)]

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

import functools as ft

def main2(L):
    L.sort()
    lmax = L[-1]
    lothers = ft.reduce(lambda x, y: x + y, L[:-1])
    b = lmax < lothers
    return 'Yes' if b else 'No'

def main(ss):
    L = sp2nn(ss[1])
    s = main2(L)
    print(s)

main(ii2ss(2))


Measured memory_bytes: 3572
def gcd(a, b)
  if b == 0 then
    return a
  else
    gcd(b, a % b)
  end
end

### main ###
x, y = STDIN.gets.to_s.split(" ")

x = x.to_i
y = y.to_i

if x > y then
  result = gcd(x, y)
else
  result = gcd(y, x)
end

p result

Measured memory_bytes: 8684
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int a, b, h;

    scanf("%d%d%d", &a, &b, &h);

    printf("%d\n", (a+b)*h/2);

    return 0;
}

Measured memory_bytes: 1724
#include <iomanip>
#include <iostream>

using namespace std;

int n, x, y, z;
long double dp[303][303][303];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    if (a == 3) x++;
    if (a == 2) y++;
  }
  z = n - x - y;

  for (int i = 0; i <= x; i++) {
    for (int j = 0; j <= x+y; j++) {
      for (int k = 0; k <= n; k++) {
        if (i+j+k) dp[i][j][k] = (long double)n/(i+j+k);
        if (i > 0) dp[i][j][k] += dp[i-1][j+1][k]*i/(i+j+k);
        if (j > 0) dp[i][j][k] += dp[i][j-1][k+1]*j/(i+j+k);
        if (k > 0) dp[i][j][k] += dp[i][j][k-1]*k/(i+j+k);
      }
    }
  }

  cout << fixed << setprecision(12) << dp[x][y][z] << endl;
  return 0;
}

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

int main(){
    vector<vector<int>> c(3,vector<int>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }

    bool c1=(c[1][1]==c[0][1]+c[1][0]-c[0][0]);
    bool c2=(c[2][1]==c[2][0]+c[0][1]-c[0][0]);
    bool c3=(c[1][2]==c[1][0]+c[0][2]-c[0][0]);
    bool c4=(c[2][2]==c[2][0]+c[0][2]-c[0][0]);

    if(c1&&c2&&c3&&c4){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main(){

  int N;
  cin >> N;
  string S[N];
  for (int i=0; i<N; i++)
    cin >> S[i];

  string ans[4] = {"AC", "WA", "TLE", "RE"};
  int res[4]={0};

  for (int i=0; i<N; i++)
    for (int j=0; j<4; j++)
      if (S[i] == ans[j])
        res[j]++;

  cout << "AC x " << res[0] << endl;
  cout << "WA x " << res[1] << endl;
  cout << "TLE x " << res[2] << endl;
  cout << "RE x " << res[3] << endl;

  return 0;
}

Measured memory_bytes: 5420
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
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; }
const int INF = 1e9;
const ll MOD = 1000000007;

using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >> k;
    vi A(n); rep(i,n) cin >> A[i];
    int ans = ((n-1)+(k-1)-1)/(k-1);
    cout << ans << "\n";
}



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


int main(){
    int n;cin>>n;
    int pehla = n%10;
    if(pehla == 2||pehla == 4||pehla == 5||pehla == 7||pehla == 9){
        cout<<"hon"<<endl;
    }else if(pehla == 0||pehla == 1||pehla == 6||pehla == 8){
        cout<<"pon"<<endl;
    }else if(pehla == 3){
        cout<<"bon"<<endl;
    }


    return 0;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N, M = map(int, input().split())
l = [0] * N

for i in range(M):
    a, b = map(int, input().split())
    a -= 1; b -= 1;
    l[a] += 1
    l[b] += 1

for i in range(N):
    print(l[i])

Measured memory_bytes: 4564
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main (String[] args) {
      Scanner in = new Scanner(System.in);
      int N = in.nextInt();
      int[] a = new int[N];
      for (int i = 0; i < N; i++) {
        a[i] = in.nextInt();
      }
      int[] dp = new int[N];
      dp[0] = 0;
      dp[1] = Math.abs(a[0] - a[1]);
      for(int i = 2; i< N ;i++){
        dp[i] = Math.min(dp[i-1] + Math.abs(a[i] - a[i-1]), dp[i-2] + Math.abs(a[i] - a[i-2]));
      }
      System.out.println(dp[N-1]);
	}
}


Measured memory_bytes: 51308
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

int N;
int E[400001], ne[400001], he[200001], cnt[2];
bool D[200001], d;
void dfs(int p, int prev) {
	D[p] = d;
	cnt[d]++;

	d = !d;
	for (int i = he[p]; i; i = ne[i]) {
		int to = E[i];
		if (to != prev) {
			dfs(to, p);
		}
	}
	d = !d;
}

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


	N = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		E[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}

	dfs(1, 0);

	int k0 = 0, k1 = 0, k2 = 0;
	int n0 = (N + 2) / 3;
	int n1 = (N + 1) / 3;
	int n2 = N / 3;

	if (cnt[0] < cnt[1]) {
		if (cnt[0] > N / 3) {
			rep1(i, N) {
				if (D[i] == 0) {
					if (k0 < n0) putint(k0++ * 3 + 1);
					else putint(k2++ * 3 + 3);
				}
				else {
					if (k1 < n1) putint(k1++ * 3 + 2);
					else putint(k2++ * 3 + 3);
				}
			}
		}
		else {
			rep1(i, N) {
				if (D[i] == 0) {
					putint(k2++ * 3 + 3);
				}
				else {
					if (k0 < n0) putint(k0++ * 3 + 1);
					else if (k1 < n1) putint(k1++ * 3 + 2);
					else putint(k2++ * 3 + 3);
				}
			}
		}
	}
	else {
		if (cnt[1] > N / 3) {
			rep1(i, N) {
				if (D[i] == 0) {
					if (k0 < n0) putint(k0++ * 3 + 1);
					else putint(k2++ * 3 + 3);
				}
				else {
					if (k1 < n1) putint(k1++ * 3 + 2);
					else putint(k2++ * 3 + 3);
				}
			}
		}
		else {
			rep1(i, N) {
				if (D[i] == 1) {
					putint(k2++ * 3 + 3);
				}
				else {
					if (k0 < n0) putint(k0++ * 3 + 1);
					else if (k1 < n1) putint(k1++ * 3 + 2);
					else putint(k2++ * 3 + 3);
				}
			}
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main(){
    int mp[3][3];
    vector<int> a(3), b(3);
    bool flag = true;
    

    for(int i=0; i<3; i++){
	for(int j=0; j<3; j++){
	    cin >> mp[i][j];
	}
    }
    a[0]=0;
    b[0] = mp[0][0] - a[0];
    b[1] = mp[0][1] - a[0];
    b[2] = mp[0][2] - a[0];
    a[1] = mp[1][0] - b[0];
    a[2] = mp[2][0] - b[0];

    for(int i=0; i<3; i++){
	for(int j=0; j<3; j++){
	    if(a[i]+b[j] != mp[i][j])
		flag = false;
	}
    }

    cout << (flag ? "Yes": "No") << endl;
    
    

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  char a;
  cin>>a;
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o') cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;
  return 0;
}
	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b,c;
	cin >> a >> b >> c;
	cout << (double) (a*b) /2 << endl;
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int x, y;
    cin >> x >> y;
    if (y & 1)
    {
        cout << "No\n";
        return 0;
    }
    if (y > x * 4 || y < x * 2)
    {
        cout << "No\n";
    }
    else
    {
        cout << "Yes\n";
    }
    return 0;
}

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    // random_device rnd;
    // mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L, R;
    cin >> L >> R;
    vector<int> canuse (2019,0);
    if(R-L >= 4038){
        for(int i = 0;i < 2019;i++){
            canuse[i] = 2;
        }
    }
    else{
        for(int i = L;i <= R;i++){
            canuse[i%2019]++;
        }
    }
    int ans = 2018;
    for(int i = 0;i < 2019;i++){
        for(int j = 0;j < 2019;j++){
            if(canuse[i] < 2 && i == j)continue;
            if(canuse[i] && canuse[j]){
                ans = min(ans,(i*j)%2019);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
L = list(int(i) for i in input().split()) 
cnt = 0
for i in range(n-2):
    if L[i] <= L[i+1] and L[i+1] <= L[i+2] or L[i] >= L[i+1] and L[i+1] >= L[i+2]:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int D;
	cin >> D;
	int n = 25 - D;
	cout << "Christmas";
	REP(i, n)
	{
		cout << " Eve";
	}
	cout << endl;
	return 0;
}

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



int main(){
	
	int n;
	cin >> n;
	vector<int> c(n-1), s(n-1), f(n-1);

	for(int i = 0; i < n-1; i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}

	for(int i = 0; i < n-1; i++)
	{
		int time=0;
		for(int j = i; j < n-1; j++)
		{
			if(time <= s[j]) time = s[j] + c[j];
			else if((time - s[j]) % f[j] == 0) time += c[j];
			else{
				time += f[j] - (time - s[j])%f[j] + c[j];
			}
		}
		cout << time << endl;
		
	}
	
	cout << 0 << endl;
	


	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

vector<vector<ll>> a(501, vector<ll>(501, -1));

signed main() {
  ll N, k=0, bit=1;
  cin >> N;
  for (; bit<N; bit <<= 1, k++) {
    rep(i,N) rep(j,N) {
      if ((i&bit) != (j&bit)) {
        a[i][j] = a[j][i] = k+1;
      }
    }
  }
  rep(i,N-1) {
    for (ll j=i+1; j<N; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

using ll = long long;
using ld = long double;

#define PI 3.14159265358979323846264338327950L

int main(){
  long double A, B, H, M;
 
  long double pow_A, pow_B, temp, result, pow_result;
  
  cin >> A >> B >> H >> M;
 
  long double theta = 2.0 * PI * ((H/12.0 + ((long double)M/60.0)/12.0) - (long double)M/60.0);

  pow_A = A * A;
  pow_B = B * B;
  temp = 2.0 * A * B * cos(theta);
  
  pow_result = pow_A + pow_B - temp;
  result = sqrtl(pow_result);
  
  cout << setprecision(11) << result << endl;
  
  return 0;
}

Measured memory_bytes: 4132
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 2019;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n,a,b;cin>>n>>a>>b;
    int A = n*a;
    if(A < b) cout << A;
    else  cout << b;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int m[105][105];
int s[105] = { 0 };

int main()
{
	int r, c;
	cin >> r >> c;
	REP(i, r)
	{
		int sum = 0;
		REP(j, c)
		{
			cin >> m[i][j];
			sum += m[i][j];
			s[j] += m[i][j];
			cout << m[i][j] << " ";
		}
		cout << sum << endl;
	}
	int sum = 0;
	REP(i, c)
	{
		cout << s[i] << " ";
		sum += s[i];
	}
	cout << sum << endl;
	return 0;
}


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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

long long int mod_pow(long long int x, long long int n, long long int p) {
    long long int res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

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

    int n, k;
    cin >> n >> k;

    long long t1 = 1, t2 = 1, t3 = 1, t4 = 1;
    for (int i = 1; i <= k; i++) {
        if (i > n - k + 1) {
            cout << 0 << endl;
        } else {
            t1 *= (n - k + 1) - (i - 1);
            t1 %= mod;
            t2 *= i;
            t2 %= mod;

            if (i != 1) {
                t3 *= k - 1 - (i - 2);
                t3 %= mod;
                t4 *= i - 1;
                t4 %= mod;
            } else {
                t3 = 1;
                t4 = 1;
            }

            long long temp = t1 * mod_pow(t2, mod - 2, mod) % mod;
            long long temp2 = t3 * mod_pow(t4, mod - 2, mod) % mod;

            cout << temp * temp2 % mod << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define t int t;scanf("%d",&t);for(int v=1;v<=t;v++)
#define loop_arr(i,a,b) for(int i=a;i<b;i++)
#define loop_norm(i,a,b) for(int i=a;i<=b;i++)
#define minheap priority_queue<int,vector<int>,greater<int> >
#define maaheap priority_queue<int>
#define pb push_back
#define newl "\n"
ll BIGMOD ( ll a, ll p, ll m )
{
    ll result = 1;
    ll x = a;

    while ( p )
    {
        if ( p & 1 ) //p is odd
        {
            result = ( result * x ) % m;
        }
        x = ( x * x ) % m;
        p = p >> 1;
    }

    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
string str1,str2,ans;
int lcs[3005][3005];
int eval[3005][3005];
void init(int row,int col)
{
    for(int i=0;i<=row;i++)
    {
        for(int j=0;j<=col;j++) eval[i][j]=2;
    }
}
void recursive(int i,int j)
{
    if(lcs[i][j]==0) return;
    if(eval[i][j]==0)
    {
        ans=str1[i-1]+ans;
        recursive(i-1,j-1);
    }
    else if(eval[i][j]==1)
    {
        recursive(i-1,j);
    }
    else
    {
        recursive(i,j-1);
    }

}
int main()
{
  // fastread;
  cin>>str1;
  cin>>str2;
  int len1,len2;
 // ans=NULL;
  len1=str1.length();
  len2=str2.length();
  for(int i=0;i<=len1;i++) lcs[i][0]=0;
  for(int i=0;i<=len2;i++) lcs[0][i]=0;
  for(int i=1;i<=len1;i++)
  {
      for(int j=1;j<=len2;j++)
      {
          if(str1[i-1]==str2[j-1])
          {
              eval[i][j]=0;
              lcs[i][j]=1+lcs[i-1][j-1];

          }
          else
          {
              int up=lcs[i-1][j];
              int leftt=lcs[i][j-1];
              if(up>=leftt)
              {
                  eval[i][j]=1;
                  lcs[i][j]=up;
              }
              else
              {
                  eval[i][j]=-1;
                  lcs[i][j]=leftt;
              }
          }
      }
  }
  recursive(len1,len2);
  cout<<ans<<newl;


  return 0;
}


Measured memory_bytes: 71040
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int CharToX(char c) => c == 'L' ? -1 : c == 'R' ? 1 : 0;
	int CharToY(char c) => c == 'U' ? -1 : c == 'D' ? 1 : 0;
	int[] StringToX(string S) => S.Select(CharToX).ToArray();
	int[] StringToY(string S) => S.Select(CharToY).ToArray();
	void Solve()
	{
		var I = G;
		int Y = I[0], X = I[1], N = I[2];
		I = G;
		int y = I[0] - 1, x = I[1] - 1;
		string S = Str, T = Str;
		WriteLine(Safe(x, X, N, StringToX(S), StringToX(T)) && Safe(y, Y, N, StringToY(S), StringToY(T)) ? "YES" : "NO");
	}
	bool Safe(int x, int X, int N, int[] S, int[] T)
	{
		int l = 0, r = X;
		for (var n = N - 1; n >= 0; n--)
		{
			// T[n]
			if (T[n] > 0) l = Max(l - 1, 0);
			else if (T[n] < 0) r = Min(r + 1, X);
			// S[n]
			if (S[n] > 0) { if (r - l == 1) return false; r--; }
			else if (S[n] < 0) { if (r - l == 1) return false; l++; }
		}
		return l <= x && x < r;
	}
}


Measured memory_bytes: 24032
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;struct edge{int to,next;}e[4005];
int tot=0,sz[2005],sm[2005],f[2005],last[2005];char str[2005];
inline void adde(int u,int v) {e[++tot]=(edge){v,last[u]},last[u]=tot;return;}
inline void inse(int u,int v) {return adde(u,v),adde(v,u);}
void dfs(int root,int fa) {
	int wson=0;if (str[root]^48) sz[root]=1;
	for (int i=last[root];i;i=e[i].next) {
		int ot=e[i].to;if(ot==fa) continue;
		dfs(ot,root),sz[root]+=sz[ot],sm[ot]+=sz[ot];
		sm[root]+=sm[ot];if (sm[wson]<sm[ot]) wson=ot;
	}if (!wson) return f[root]=0,void();if (sm[root]>=(sm[wson]<<1)) f[root]=sm[root]>>1;
	else f[root]=sm[root]-sm[wson]+min(f[wson],(sm[wson]+sm[wson]-sm[root])>>1);return;
}int main() {int n,ans=0x3f3f3f3f,u,v;scanf("%d%s",&n,str+1);
	for (int i=1;i<n;++i) scanf("%d%d",&u,&v),inse(u,v);
	for (int i=1;i<=n;++i) {memset(sz,0,sizeof sz);
		memset(sm,0,sizeof sm),dfs(i,0);
		if ((~sm[i]&1)&&f[i]>=(sm[i]>>1)) ans=min(ans,sm[i]);
	}printf("%d",ans==0x3f3f3f3f?-1:ans>>1);return 0;
}

Measured memory_bytes: 3368
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        StringBuilder sb = new StringBuilder();
        while (N != 0) {
            if (Math.abs(N % 2) == 1) {
                sb.append(1);
                N -= 1;
            } else {
                sb.append(0);
            }
            N = N / -2;
        }
        sb.reverse();
        if (sb.length() == 0) {
            sb.append(0);
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 22356
#include <iostream>

#include <vector>

#include <queue>

#include <algorithm>

#include <cmath>

#include <bitset>

#include <iomanip>

#include <stack>

#include <list>

#include <map>

#include <unordered_map>

#include <chrono>

#include <numeric>

using namespace std;

using ll = long long;

const ll INF = (ll)1e18+1;

const ll DIV = 1000000007;

//#define TEST

int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

#ifdef TEST

    chrono::system_clock::time_point start, end;

    start = chrono::system_clock::now();

#endif

    string S;

    cin >> S;

    ll count_zero=0, count_one=0;

    for(size_t i=0;i<S.size(); i++)

    {

        if(S[i]=='0') count_zero++;

        else count_one++;

    }

    cout << min(count_zero, count_one)*2 << endl;

#ifdef TEST

    end = chrono::system_clock::now();

    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;

#endif

    return 0;

}



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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    int count=0;
    int d;
    bool a[n]={};
    for(int i = 0; i < k; i++) {
        cin >> d;
        for(int j = 0; j < d; j++) {
            int tmp;
            cin >> tmp;
            a[tmp-1]=true;
        }
    }
    for(int i = 0; i < n; i++) {
        if(a[i]==false) count++;
    }
    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 3660
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

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

    int[] A, B;
    void input() {
        A = readln.chomp.split(" ").map!(to!int).array;
        B = readln.chomp.split(" ").map!(to!int).array;
    }
    void solve() {
        double dfs(int x, int bit, int a, int b) {
            if (x == 9) return (a > b);
            double ret = 0;
            foreach (i; 0 .. 9) {
                if (bit & (1 << i)) continue;
                int na = a, nb = b;
                (A[x] > B[i] ? na : nb) += (A[x] + B[i]);
                ret += dfs(x + 1, bit | 1 << i, na, nb) / (x + 1);
            }
            return ret;
        }
        double a = dfs(0, 0, 0, 0);
        writefln("%.5f %.5f", a, 1.0 - a);
    }

    foreach (t; 0 .. T) {
        input; solve;
    }
}

Measured memory_bytes: 1204
#include <iostream>

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



int main() {
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;

    return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize("Ofast") 

////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mod (long)(1e9+7)
#define ip(ar,n) for(int i=0;i<n;++i)cin>>ar[i];
#define op(ar,n) for(int i=0;i<n;++i)cout<<ar[i]<<" ";
#define test int t;cin>>t;while(t--)
#define tar(x) int x;cin>>x;
#define fil(ar,val) memset(ar,val,sizeof ar)
#define loop(n) for(int i=0;i<n;++i)

////////////////////////////////////////////////////////////////////////////////

typedef vector<int> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef set<int> si;
typedef map<int,int> mi;

////////////////////////////////////////////////////////////////////////////////

int a[21][21];
int n;
int dp[21][1<<21];

int rec(int ind,int bi)
{
    if(ind>=n)
        return 1;
    if(dp[ind][bi]!=-1)
        return dp[ind][bi];
        
    int x=0;
    for(int i=0;i<n;++i)
    {
        if(bi&(1<<i))
        continue;
        if(a[ind][i])
        x+=rec(ind+1,bi|(1<<i));
    }
    dp[ind][bi]=x%mod;
    return dp[ind][bi];
}



signed main() {
bew;
cin>>n;
memset(dp,-1,sizeof dp);
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
cin>>a[i][j];

cout<<rec(0,0);

return 0;
}

Measured memory_bytes: 344320
N = int(input())
H = list(map(int, input().split()))

for i in range(0, N-1):
    if H[N-1-i-1] - H[N-1-i] == 1:
        H[N-1-i-1] -= 1
    elif  H[N-1-i-1] - H[N-1-i] > 1:
        print('No')
        break
else:
    print('Yes')

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100000];

int xo;
string f(int x) {
    x ^= xo;
    if (x == 0) {
        return "First";
    }
    return "Second";
}

int main() {
    scanf("%d", &n);
    forn(i, n) {
        scanf("%d", a + i);
    }
    if (n == 1) {
        assert(a[0] == 1);
        cout << f(1) << endl;
        return 0;
    }
    xo = 0;
    while (true) {
        int need = (n % 2) ^ 1;
        int cur = 0;
        forn(i, n) {
            cur += a[i] & 1;
        }
        cur &= 1;
        if (cur == need) {
            cout << f(0) << endl;
            return 0;
        }
        int pos = -1;
        int cnt = 0;
        forn(i, n) if (a[i] % 2 == 1) {
            pos = i;
            ++cnt;
        }
        if (cnt > 1 || a[pos] == 1) {
            cout << f(1) << endl;
            return 0;
        }
        a[pos] -= 1;
        int g = a[0];
        forn(i, n) {
            g = __gcd(g, a[i]);
        }
        forn(i, n) {
            a[i] /= g;
        }
        xo ^= 1;
    }
    return 0;
}


Measured memory_bytes: 640