akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int N;

int main() {
  cin >> N;
  vi p(N), q(N), v(N);
  rep(i, N) cin >> p[i];
  rep(i, N) cin >> q[i];
  rep(i, N) v[i] = i + 1;

  int idx = 1;
  int a, b;
  do {
    if (p == v) a = idx;
    if (q == v) b = idx;
    idx++;
  } while (next_permutation(all(v)));

  cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define soa(arr,n) sort(arr,arr+n)
#define sov(arr) sort(arr.begin(),arr.end())
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    while(t--) {
        string s;
        cin>>s;
        ll val=0;
        fr(i,0,s.length()-1) val=val+s[i]-'0';
        if(val%9==0) cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}


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

int main() {
    do {
        int m, f, r;
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        
        if (m == -1 || f == -1) {
            cout << "F" << endl;
        } else if (m + f >= 80) {
            cout << "A" << endl;
        } else if (m + f >= 65) {
            cout << "B" << endl;
        } else if (m + f >= 50 || (m + f >= 30 && r >= 50)) {
            cout << "C" << endl;
        } else if (m + f >= 30 && r < 50) {
            cout << "D" << endl;
        } else {
            cout << "F" << endl;
        }
    } while (1);
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll X, Y;
    cin >> X >> Y;
    if(X > Y) swap(X, Y);
    
    if(abs(X - Y) <= 1){
        output("Brown");
        return 0;
    }
    output("Alice");
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char S[105];
int V[30], N;
int Solve(int nb, char c)
{
    int ans = 0;
    for(int i = 1; i <= N - nb; i++)
    {
        int val = N;
        for(int j = i; j <= N; j++)
            if(S[j] == c)
                val = min(val, max(j - i, i - j));
        ans = max(ans, val);
    }
    return ans <= nb;
}

void Read()
{
    cin.getline(S + 1, 105);
    N = strlen(S + 1);
    for(int i = 1; i <= N; i++)
        V[S[i] - 'a' + 1]++;
    int ans = N;
    for(int i = 1; i <= 26; i++)
    {
        if(V[i] == 0)
            continue;
        int j = 0;
        while(Solve(j, (char)(i + 'a' - 1)) == 0)
            ++j;
        ans = min(ans, j);
    }
    cout << ans << "\n";
}
int main()
{
    Read();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;
#define n_max 100000

#define rep(i,n) for(int i = 0; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int d[n];
    int ans = 0;

    rep(i,n) { cin >> d[i]; } 

    rep(i,n-1) {
        for(int j = i+1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    vector<int> N, X;
    for(;;){
        int n, x;
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        N.push_back(n);
        X.push_back(x);
    }

    for(int i = 0; i < N.size(); i++){
        int ans = 0;
        int n = N.at(i), x = X.at(i);
        for(int j = 1; j <= n; j++){
            for(int k = j+1; k <= n; k++){
                for(int l = k+1; l <= n; l++){
                    if(j + k + l == x){
                        ans++;
                        //cout << j << "+" << k << "+" << l << endl;
                    }
                }
            }
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, K; cin >> N >> K;
	int x = (N + 1) / 2;
	cout << (x >= K ? "YES" : "NO") << "\n";

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <bitset>

int main() {

    int N, K, X, A, B, D, tmp1, tmp2, i = 0, ans = 0, cst = 1;


    std::cin >> N;

    int p[N];

    while(std::cin >> tmp1){
        p[i] = tmp1;
        i++;
        if(i >= N){
            break;
        }
    }

    int cnt=0;
    for(int i=0;i<N; i++){
        if((i+1) != p[i]){
            cnt++;
            if(cnt == 3){
                std::cout << "NO" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "YES" << std::endl;
    return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p_list = sorted(list(map(int, input().split())))
q_list = sorted(list(map(int, input().split())))
r_list = sorted(list(map(int, input().split())))

p_list = p_list[a - x:]
q_list = q_list[b - y:]

pqr_list = p_list + q_list + r_list
pqr_list = sorted(pqr_list,reverse=True)
pqr_list = pqr_list[:x + y]

print(sum(pqr_list))

  

Measured memory_bytes: 22720
#include <bits/stdc++.h>
using namespace std;
int compare(string x,string y,int i);

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

    int i=0;

    if(a.size()>b.size()){
        cout<<"GREATER"<<endl;
    }else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
    }else{
        compare(a,b,i);
    }
}

int compare(string x,string y,int i){
    if(x[i]==y[i] && i+1<x.size()){
        i++;
        compare(x,y,i);
    }else if(x[i]>y[i]){
        cout<<"GREATER"<<endl;
    }else if(x[i]<y[i]){
        cout<<"LESS"<<endl;
    }else{
        cout<<"EQUAL"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
    	#ifdef LOCAL
    		freopen("in.txt","r",stdin);
    		freopen("out.txt","w",stdout);
    	#endif
     
    	int n;
    	cin >> n;
    	long long sum = 0;
    	for(long long i = 1;i <= n;i++){
    		if(i % 3 == 0 or i % 5 == 0) continue;
    		sum+=i;
    	}
    	cout << sum;
    }

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int a, z;
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == 'A') {
			a = i;
			break;
		}
	}
	rep(i, s.size()) {
		if (s[i] == 'Z') {
			z = i;
		}
	}
	cout << z - a+1 << endl;
}

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

using namespace std;


#define PI 3.14159265
#define int long long


bool cmp(pair <string, pair <int, int> > &a, pair <string, pair <int, int> > &b){
	if(a.first == b.first){
		return a.second > b.second;
	}else{
		return a.first < b.first;
	}
}



main(){

	int n; cin >> n;

	vector <string> s(n);
	vector <int> p(n);

	vector < pair <string, pair <int, int> > > v(n);

	for(int i = 0; i < n; i++){
		cin >> s[i] >> p[i];
		v[i].first = s[i];
		v[i].second.first = p[i];
		v[i].second.second = i;
	}

	sort(v.begin(), v.end(), cmp);


	for(int i = 0; i < n; i++){
		cout << v[i].second.second + 1 << endl;
	}


	
	
	return 0;
}

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

void fnInput(vector<int>& rvnValue)
{
  int nValueSiz;
  cin >> nValueSiz;
  rvnValue.resize(nValueSiz);

  for (int& rnValue : rvnValue)
    cin >> rnValue;
}
  
double fnMaxValueGet(const vector<int>& cnrvnValue)
{
  vector<int> vnAsdValue(cnrvnValue);
  sort(begin(vnAsdValue), end(vnAsdValue));

  double nMaxValue = vnAsdValue[0];

  for (int n = 1; n < vnAsdValue.size(); n++)
    nMaxValue = (nMaxValue + vnAsdValue[n]) / 2;

  return nMaxValue;
}
  
int main()
{
  vector<int> vnValue;

  fnInput(vnValue);
  cout << fnMaxValueGet(vnValue) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int a,b,x;
int main()
{
	cin>>a>>b>>x;
	int now=a*a*b;
	long double h=2.0*(now-x)/a/a;
	if(x*2<=now) h=2.0*x/a/b,printf("%.10Lf\n",atan(b/h)/3.1415926535897*180.0);
	else printf("%.10Lf\n",atan(h/a)/3.1415926535897*180.0);
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll md=0;
    ll ans=0;
    vector<ll>v;
    for(int i=0; i<5; i++)
    {
        ll x;
        cin>>x;
        ll ok=(10-x%10);
        if(ok>=md and ok!=10)
        {
            md=ok;
            ans=x;
        }
        v.pb(x);

    }
    //cout<<ans<<endl;
    ll sum=0;
    bool f=0;
    for(int i=0; i<5; i++)
    {
        ll t=v[i];
        if(v[i]==ans and f==0)
        {
            sum+=v[i];
            f=1;
        }
        else
        {
            if(v[i]%10==0)
            {
                sum+=v[i];
            }
            else
            {
                sum+=(v[i] + (10-v[i]%10));
            }
        }
        //cout<<sum<<endl;
    }
    cout<<sum<<endl;
}


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

int f(long long a,long long N){
	while(a>0 and N > 0){
		if( a <= N ) N -= a;
		a--;
	}
	return N == 0;
}
int out(long long a,long long N){
	while(a>0 and N > 0){
		if( a <= N ) N -= a, cout << a << endl;
		a--;
	}
	return N == 0;
}
void solve(long long N){
	long long l = 0 , r = N;
	while( l != r ){
		long long m = (l+r) / 2;
		if( f(m,N) ){
			r = m;
		}else{
			l = m+1;
		}
	}
	out(l,N);
}



int main(){	
	ios::sync_with_stdio(false);
	long long N;
	cin >> N;
	solve(N);
	return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
int x[10003],y[10003];
int main()
{

string s;cin>>s;
int a=s.size();
int sum=0;
for(int i=0;i<a;i++)
    if(s[i]==s[i+1])
{
    sum=1;break;
}
if(sum)cout<<"Bad";
else cout<<"Good";
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{	
	int m, f, r;
	
	while (true)
	{
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;

		if (m == -1 || f == -1) cout << "F" << endl;
		else if (m + f >= 80) cout << "A" << endl;
		else if (m + f >= 65) cout << "B" << endl;
		else if (m + f >= 50) cout << "C" << endl;
		else if (m + f >= 30)
		{
			if (r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}

	return 0;
}



Measured memory_bytes: 3108
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 16:16:00 +0900
# LastModified: 2020-06-26 19:11:55 +0900
#


import os
import sys
from math import sqrt
# import numpy as np
# import pandas as pd


def F(a, b):
    if len(str(a)) > len(str(b)):
        print(len(str(a)))
    else:
        print(len(str(b)))


def main():
    n = int(input())
    for i in range(int(sqrt(n)+1), -1, -1):
        if n % i == 0:
            a = i
            b = n//i
#            print(a,b)
            F(a, b)
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 9164
import math


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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


a, b = map(int, input().split())
a_div = make_divisors(a)
b_div = make_divisors(b)
a_b_div = list(set(a_div).intersection(set(b_div)))
cnt = 0
for num in a_b_div:
    if is_prime(num):
        cnt += 1
print(cnt)

Measured memory_bytes: 5264
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int x=stdIn.nextInt(),a=0,b,p,i,t;
		for(b=1;b<=x;b++) {
			t=b;
			for(p=2;p<=x;p++) {
				t*=b;
				if(t<=x&&a<t) a=t;
			}
		}
		if(x==1) a=1;
		System.out.print(a);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N  = 200007;
ll par[N] , X[N] , Y[N] ;
int root(ll i){
    while(par[i] != i)
        i = par[i];
    
    return i;
}
void Union(int a , int b){
    int r_a = root(a);
    int r_b = root(b);
    if(r_a == r_b)
        return;
    if(X[r_a]+Y[r_a] > X[r_b] + Y[r_b])
        swap(r_a , r_b);

    par[r_a] = r_b;
    X[r_b] += X[r_a];
    Y[r_b] += Y[r_a];
  
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    for(int i = 0 ;i < N ; i++)
        par[i] = i;
    for(int i = 0 ;i <= 100000 ; i++)
        X[i] = 1;
    for(int i = 100001 ; i < N ; i++)
        Y[i] = 1;


    ll n , x , y ; cin >> n;
    for(int i = 0 ;i < n; i++){
        cin >> x >> y;
        y += 100000;
        Union(x , y);
    }
    ll ans = 0;
    for(int i = 0 ;i < N ; i++){
        if(par[i] == i){
            ans += X[i]*Y[i];
        }
    }
    cout << ans-n << endl;

   

    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define RANGE_1(e) (boost::irange(0,(e)))
#define RANGE_2(s,e) (boost::irange((s),(e)))
#define RANGE_3(s,e,step) (boost::irange((s),(e),(step)))
#define RANGE_SELECTER(_1,_2,_3,SELECT,...) SELECT
#define range(...) RANGE_SELECTER(__VA_ARGS__, RANGE_3, RANGE_2, RANGE_1) (__VA_ARGS__)
#define guard(x) if(x);
#define CINS(x) for(auto&& __E__:(x))cin>>__E__
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define CALL(x) (x).cbegin(),(x).cend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define BIT(n) (1LL<<(n))
#define MOD 1000000007

using namespace std;
using lint = long long;

// template<class T>class irange{private:struct I{T x;T operator*(){return x;}bool operator!=(I&lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:irange(T i,T n):i({i}),n({n}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>class srange{private:struct I{T x,s;T operator*(){return x;}bool operator!=(I&lhs){if(s<(T)0)return x>lhs.x;return x<lhs.x;}void operator++(){x=x+s;}};I i,n;public:srange(T i,T n,T s):i({i,s}),n({n,s}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>irange<T>range(T n){return irange(0,n);}template<class T>irange<T>range(T i,T n){return irange(i,n);}template<class T>srange<T>range(T i,T n,T s){return srange(i,n,s);}
template<class T>bool amax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool amin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

struct initialize{initialize(){cin.tie(nullptr);ios::sync_with_stdio(false);};}__ini__;

int main(){
    lint n;
    cin >> n;

    string s = "";

    string alpha = "abcdefghijklmnopqrstuvwxyz";

    while (true) {
        --n;
        s = alpha[n % 26] + s;
        n /= 26;
        if (n <= 0) {
            break;
        }
    }

    cout << s << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main()
{
    int n = -1;
    int numeros[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    scanf("%d", &n);
    printf("%d", numeros[n-1]);

    return 0;
}

Measured memory_bytes: 128
/** 
 *                                                                   
 *   |    |                        ,   .              ,--.,--.,--.,--.
 *   |    |    ,---..    ,,---.    |   |,---..   .      -||  ||  ||  |
 *   |    |    |   | \  / |---'    `---'|   ||   |       ||  ||  ||  |
 *   `    `---'`---'  `'  `---'      |  `---'`---'    `--'`--'`--'`--'
 *                                   `                                
**/
#include <bits/stdc++.h>
using namespace std;

int n, sushi, cnt[5];
double dp[301][301][301];
bool visited[301][301][301];

double solve(int a, int b, int c) {
	if (!a && !b && !c) return 0;
	if (visited[a][b][c]) return dp[a][b][c];

	double res = (double) n / (a + b + c);
	if (c) res += solve(a, b + 1, c - 1) * ((double) c / (a + b + c));
	if (b) res += solve(a + 1, b - 1, c) * ((double) b / (a + b + c));
	if (a) res += solve(a - 1, b, c) * ((double) a / (a + b + c));

	visited[a][b][c] = 1;
	return dp[a][b][c] = res;
}

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

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

	cout << setprecision(12) << fixed << solve(cnt[1], cnt[2], cnt[3]) << '\n';

	return 0;
} 

Measured memory_bytes: 239872
#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 vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;}
template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int main() {
    int n; cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans =0;
    for(int i=0;i<n;i++){
	auto itr = lower_bound(a.begin(),a.end(),b[i]);
	ll p = distance(a.begin(),itr);
	auto itr2 = upper_bound(c.begin(),c.end(),b[i]);
	ll q = distance(itr2,c.end());	
	ans += p*q;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int A,B,C;
    int ab_price = 0;
    int sa = 0;
    int harf_price = 0;
    int harf_price2 = 0;
    vector<int> price;
    
    cin >> A >> B >> C;
    
    int X,Y;
    
    cin >> X >> Y;
    
    ab_price = A + B;
    sa = abs(X - Y);
    if(ab_price < C*2){
        cout << A * X + B * Y << endl;        
    }else{
        if(X > Y){
            harf_price = Y * C * 2;
            if(A < C*2){
                cout << harf_price + sa * A << endl;
            }else{
                cout << harf_price + sa * C * 2 << endl;
            }
        }else{
            harf_price2 = X * C * 2;
            if(B < C*2){
                cout << harf_price2 + sa * B << endl;
            }else{
                cout << harf_price2 + sa * C * 2 << endl;
            }                   
        }
    } 
    return 0;
}

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

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = dp[i][j - A_list[i+1]]
        
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])


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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int mx = max(a, max(b, c));
  int mn = min(a, min(b, c));
  cout << mx - mn << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    string s; cin >> s;
    s += s[0];
    vector<char> T(N + 2);
    rep(i, 4) {
        if(i == 0) {
            T[0] = 'S'; T[1] = 'S';
        }
        if(i == 1) {
            T[0] = 'S'; T[1] = 'W';
        }
        if(i == 2) {
            T[0] = 'W'; T[1] = 'S';
        }
        if(i == 3) {
            T[0] = 'W'; T[1] = 'W';
        }
        Rep(j, 2, N + 2) {
            if(s[j - 1] == 'o' && T[j - 1] == 'S') {
                T[j] = T[j - 2];
            }
            else if(s[j - 1] == 'o' && T[j - 1] == 'W') {
                T[j] = (T[j - 2] == 'S' ? 'W' : 'S');
            }
            else if(s[j - 1] == 'x' && T[j - 1] == 'W') {
                T[j] = T[j - 2];
            }
            else {
                T[j] = (T[j - 2] == 'S' ? 'W' : 'S');
            }
        }
        if(T[N] == T[0] && T[N + 1] == T[1]){
            rep(k, N) {
                cout << T[k];
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
n = int(input())
l = [0] * (n // 2)
for i in range(1, n // 2 + 1):
    sum1 = sum([int(d) for d in str(i)])
    sum2 = sum([int(d) for d in str(n - i)])
    l[i - 1] = sum1 + sum2
print(min(l))

Measured memory_bytes: 9228
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   ll x, y;
   cin >> x >> y;
   ll ans = 2e9 + 10;
   
   if (x <= y) chmin(ans, y - x);
   if (- x <= y) chmin(ans, y + x + 1);
   if (x <= -y) chmin(ans, -y - x + 1);
   if (- x <= - y) chmin(ans, -y + x + 2);
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
def equal(B):
    temp=B[:]
    S=set()
    for i in range(4):
        for j in range(4):
            for k in range(4):
                roll(0,2,5,3,temp)
                S.add(tuple(temp))
                L.append(temp)
            roll(0,1,5,4,temp)
        roll(1,2,4,3,temp)
    return S

def roll(i,j,k,l,temp):
    t=temp[i]
    temp[i]=temp[j]
    temp[j]=temp[k]
    temp[k]=temp[l]
    temp[l]=t

while True:
    n=input()
    if n==0:break
    L=[raw_input().split() for i in range(n)]
    cnt=0
    for i in range(n-1):
        for j in range(i+1,n):
            S=equal(L[j])
            if tuple(L[i]) in S:
                cnt+=1
                break
    print cnt

Measured memory_bytes: 4668
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

typedef pair<string, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}



int main()
{
	int n;
	cin >> n;
	vector<pair<string, int>>res(n);
	map<int, int>num;
	rep(i, n) {
		cin >> res[i].F >> res[i].second;
	
		num[res[i].S] = i + 1;
	}

    sort(all(res),ps4);
	stable_sort(all(res), ps1);


	rep(i, n) {
		cout << num[res[i].S] << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int n, k, count=1;
 	cin >> n >> k;

 	for(int i=0;i<n;i++){
 		if(count*2<count+k)
 			count *= 2;
 		else
 			count += k;
 	}
 	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define maxn 200020
#define ll long long int 
using namespace std;

int n;

struct ele{
	int id, l, r;
	ele(int id, int l, int r) : id(id), l(l), r(r){}
	ele(){}
	bool operator < (const ele b) const{
		return (l == b.l) ? ((r == b.r) ? (id < b.id) : r < b.r) : l < b.l;
	}
}p[maxn];

bool vis[maxn];
int dp[maxn];
int DP(int pos){
	if (pos == n + 1) return 0;
	if (vis[pos]) return dp[pos];
	vis[pos] = 1;
	int& ans = dp[pos];
	return ans = max(DP(pos + 1), 1 + DP(lower_bound(p + 1, p + 1 + n, ele(-1, p[pos].r, p[pos].r)) - p));
}

int main(){
	
		//freopen("B.in", "r", stdin);
		
	int x, y;
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d%d", &x, &y), p[i] = ele(i, x - y, x + y);
	sort(p + 1, p + 1 + n);
	printf("%d", DP(1));
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define itn int
#define int ll
using namespace std;

string S;
int N;

signed main(void) {
    cin>>S;
    N=S.size();
    //左端を黒にする
    int bl=0;
    if (S[0]=='1') bl++;
    int target=1;
    Rep(i,1,N) {
        if (target==1&&S[i]=='0') {
            bl++;
            target=0;
        } else if (target==0&&S[i]=='1') {
            bl++;
            target=1;
        } else if (target==1) {
            target=0;
        } else if (target==0) {
            target=1;
        }
    }
    //左端を白にする
    int wh=0;
    if (S[0]=='0') wh++;
    target=0;
    Rep(i,1,N) {
        if (target==1&&S[i]=='0') {
            wh++;
            target=0;
        } else if (target==0&&S[i]=='1') {
            wh++;
            target=1;
        } else if (target==1) {
            target=0;
        } else if (target==0) {
            target=1;
        }
    }
    cout<<min(bl, wh)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  a[0] = 0;
  for(int i=0;i<3;i++) b[i] = c[0][i] - a[0];
  for(int i=1;i<3;i++) a[i] = c[i][0] - b[0];

  string ans = "Yes";

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(a[i] + b[j] != c[i][j]) ans = "No";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) //cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll num(ll a,ll b){
    if(a<=b)return 0;
    else{
        ll res = 0;
        while(a>b){
            b*=4;
            res++;
        }
        return res;
    }
}
ll hoge(ll a,ll b){
    ll res = 0;
    while(a*4<=b){
        a*=4;
        res++;
    }
    return res;
}
vector<ll> f(const vector<ll>&a){
    int n = (int)a. size();
    vector<ll>res(n);
    vector<ll>yoyuu(n);
    stack<pair<ll,ll>>st;//id,num
    res[n-1] = 0;
    for(int i = n-1; i>= 1; i--){
        show(i);
        ll k = num(a[i-1],a[i]);
        show(num(a[i-1],a[i]));
        res[i-1] = res[i] + k;
        ll t = i+1;
        while(st.size()){
            auto p = st.top();
            st.pop();
            if(p.second >= k){
                p.second-=k;
                st.push(p);
                res[i-1] += (p.first-t)*k;
                k = 0;
                break;
            }else{
                res[i-1] += (p.first-t)*k;
                k-=p.second;
                t = p.first;
            }
        }
        show(t);
        show(k);
        res[i-1] += (n-t)*k;
        show(res[i-1]);
        if(hoge(a[i-1],a[i]))st.emplace((ll)i,hoge(a[i-1],a[i]));
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    auto dp1 = f(a);
//    rep(i,dp1.size()){
//        cout << dp1[i] << endl;
//    }
    reverse(a.begin(),a.end());
    auto dp2 = f(a);
    ll ans = min(dp1[0]*2,dp2[0]*2+n);
    //    rep(i,n){
    //        cout << dp2[i] << endl;
    //    }
    rep(i,n-1){
        ans = min(ans, dp1[i+1]*2 + (i+1) + dp2[n-1-i]*2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6500
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
A = list(map(int, input().split()))
acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + A[i - 1]

ans = INF
for i in range(1, N):
    left = acc[i]
    right = acc[-1] - acc[i]
    ans = min(ans, abs(left - right))
print(ans)


Measured memory_bytes: 32500
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  string s;cin>>s;
  int a,b,c,d;
  a=s[0]-'0';
  b=s[1]-'0';
  c=s[2]-'0';
  d=s[3]-'0';
  int x=a*10+b;
  int y=c*10+d;
  if(x>0 and x<13){
    if(y>0 and y<13){
      cout<<"AMBIGUOUS"<<endl;
      return 0;
    }
    else cout<<"MMYY"<<endl;
    return 0;
  }
  else if(y>0 and y<13){
    cout<<"YYMM"<<endl;
    return 0;
  }
  else cout<<"NA"<<endl;
  return 0;
}


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

//region Template
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;

using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	#ifdef LOCAL
	((std::cout << args << " "), ...);
	cout << endl;
	#endif
}
 */
//endregion

/* Notes:
 * Farah </3
 */
const int MAXN = 2e3 + 6;

ll fact[MAXN];

long long modPow(ll b , long long pow){
	long long ans = 1;
	long long p = b;
	while(pow){
		if(pow & 1)
			ans = (ans * p) % MOD;
		p = (p * p) % MOD;
		pow >>= 1;
	}
	return ans;
}

void pre(){
	fact[0] = fact[1] = 1;

	for(ll i = 2; i <= 2005; i++){
		fact[i] = (i * fact[i - 1]) % MOD;
	}
}

ll ncr(int n, int r){
	ll x =  (fact[n] * modPow( fact[r], MOD - 2)) % MOD;
	x = (x * modPow( fact[n - r], MOD - 2)) % MOD;

	return x;
}

char g[MAXN][MAXN];
int comprow[MAXN][MAXN];
int compcol[MAXN][MAXN];

int rowval[MAXN][MAXN];
int colval[MAXN][MAXN];

int h, w;

void prow(int r){
	int cur = 1;
	for(int i = 0; i < w; i++){
		if(g[r][i] == '#') cur++;
		else {
			comprow[r][i] = cur;
			rowval[r][cur]++;
		}
	}
}

void pcol(int c){
	int cur = 1;
	for(int i = 0; i < h; i++){
		if(g[i][c] == '#') cur++;
		else {
			compcol[i][c] = cur;
			colval[c][cur]++;
		}
	}
}

int main() {
	#ifdef LOCAL

	setIn("in.txt");
	setOut("out.txt");
	#endif

	cin >> h >> w;

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> g[i][j];
		}
	}

	for(int i = 0; i < h; i++){
		prow(i);
	}
	for(int i = 0; i < w; i++){
		pcol(i);
	}

	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ans = max(ans, rowval[i][comprow[i][j]] + colval[j][compcol[i][j]] - 1);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 67072
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 55, LOG=7;

ll n, m, k, u, v, x, y, t, a, b, ans;
int sum[MAXN], par[MAXN][LOG], h[MAXN];
int E[MAXN][3];
vector<int> G[MAXN], topol;

void dfs(int node){
	h[node]=h[par[node][0]]+1;
	for (int i=1; i<LOG; i++) par[node][i]=par[par[node][i-1]][i-1];
	for (int v:G[node]) if (v!=par[node][0]){
		par[v][0]=node;
		dfs(v);
	}
	topol.pb(node);
}

int Lca(int x, int y){
	if (h[x]>h[y]) swap(x, y);
	for (int i=0; i<LOG; i++) if ((h[y]-h[x])&(1<<i)) y=par[y][i];
	if (x==y) return x;
	for (int i=LOG-1; ~i; i--) if (par[x][i]!=par[y][i]){
		x=par[x][i];
		y=par[y][i];
	}
	return par[x][0];
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<n; i++){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(1);
	cin>>m;
	for (int i=0; i<m; i++) cin>>E[i][0]>>E[i][1], E[i][2]=Lca(E[i][0], E[i][1]);
	for (int mask=0; mask<(1<<m); mask++){
		memset(sum, 0, sizeof(sum));
		for (int i=0; i<m; i++) if (mask&(1<<i)){
			sum[E[i][0]]++;
			sum[E[i][1]]++;
			sum[E[i][2]]-=2;
		}
		for (int v:topol) for (int u:G[v]) if (u!=par[v][0]) sum[v]+=sum[u];
		
		ll tmp=0;
		for (int i=2; i<=n; i++) if (!sum[i]) tmp++;
		tmp=(1ll<<tmp);
		if (__builtin_popcount(mask)&1) tmp=-tmp;
		ans+=tmp;
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & -x)

using namespace std;

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

    cin.tie(0);
    cout.tie(0);
    //freopen("a.in", "r", stdin);

    int n;
    cin >> n;
    vector<vector<int>> v(n + 1, vector<int> (3, 0));
    for(int i = 1; i <= n; i ++)
        for(int j = 0; j < 3; j ++)
            cin >> v[i][j];

    vector<vector<int>> dp(n + 1, vector<int> (3, 0));
    for(int i = 1; i <= n; i ++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + v[i][2];
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]});

    return 0;
}


Measured memory_bytes: 11264
n,p=map(int,input().split())
a=[int(i)%2 for i in input().split()]

c0=a.count(0)
c1=n-c0

def c(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))

q=0
for i in range(c0+1):
    q+=c(c0,i)


i=p
ans=0
while i<=c1:
    ans+=c(c1,i)*q
    i+=2
print(ans)

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

int main(){
	char S[100000];
	scanf("%s",S);
	int i,a=0;
	int n = strlen(S);
	for(i=0;i<n-1;i++){
		if(S[i]!=S[i+1])
			a++;
	}
	printf("%d\n",a);
	return 0;
}

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

int yakusu(int x) {
	int res=0;
	for (int i = 1; i*i <= x; i++) {
		if (x%i == 0) {
			if (i*i == x)res++;
			else res += 2;
		}
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 2 != 0 && yakusu(i) == 8) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    c = Counter(S)
    max_v = max(c.values())
    ans = [k for k, v in c.items() if v == max_v]
    ans.sort()

    print("\n".join(ans))


if __name__ == "__main__":
    main()


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

typedef long long int int64;

const int mod=998244353;

int modPow(int r,int n){
  int t=1;
  int s=r;
  while(n>0){
    if(n&0x01) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    n>>=1;
  }
  return t;
}

int *fact=NULL;
int *iFact=NULL;
void init(int n){
  fact=(int *)calloc(n+1,sizeof(int));
  iFact=(int *)calloc(n+1,sizeof(int));
  fact[0]=1;
  int i;
  for(i=1;i<=n;i++) fact[i]=(int64)i*fact[i-1]%mod;
  iFact[n]=modPow(fact[n],mod-2);
  for(i=n-1;i>=0;i--) iFact[i]=(int64)(i+1)*iFact[i+1]%mod;
  return;
}

int comb(int n,int k){
  if(!(0<=k && k<=n)) return 0;
  return (int64)fact[n]*iFact[k]%mod*iFact[n-k]%mod;
}

void run(void){
  int k,n;
  scanf("%d%d",&k,&n);
  init(2*(n+k));
  int i;
  for(i=2;i<=2*k;i++){
    int64 ans=0;
    int p=0;
    for(int j=1,l=i-1;j<=l;j++,l--) if(j<=k && l<=k) p++;
    for(int q=0,pow2=1;q<=p;q++,pow2=pow2*2%mod){
      ans+=(int64)comb(p,q)*pow2%mod*comb(n-q+(k-(2*p-q))-1,k-(2*p-q)-1)%mod;
      ans%=mod;
    }
    printf("%lld\n",ans);
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v._size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v._size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;

        ll pow(ll base, ll q, ll mod){
            ll answer = 1;
            while(q > 0){
                if(q & 1LL)
                    answer = (answer * base) % mod;

                q = q >> 1LL;
                base = (base*base) % mod;
            }
            return answer % mod;
        }

        

        

        

        void solve1(){
            cin >> n;
            string s1,s2;
            cin >> s1 >> s2;
            if(s1 == s2){
                cout << "0\n";
                return;
            }
            int len1 = 0, len2 = 0;
            for(int i=0;i < n; i++){
                if(s1[i] == '1') len1++;
                if(s2[i] == '1') len2++;
            }
            if(len1 != len2) {cout << "-1\n"; return;}
        }


        void solve(){
            char ch; cin >> ch;
            if(ch >= 'a' && ch <= 'z') cout << "a";
            else cout << "A";
        }

       
    


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

           

            

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

Measured memory_bytes: 3652
from collections import Counter

n=int(input())
s=[]
for i in range(n):
	s.append(input())
m=int(input())
t=[]
for i in range(m):
	t.append(input())

c=Counter(s).most_common()
p=[]
for i in range(len(c)):
	p.append(c[i][1]-t.count(c[i][0]))
point=max(p)
if point<0:
	point=0
print(point)


Measured memory_bytes: 3316
n = list(map(int,input()))[::-1]
n.append(0)
for i in range(len(n)):
    if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):
        n[i] = 10 - n[i]
        n[i+1] += 1
print(sum(n))


Measured memory_bytes: 20336
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

const char *TABLE[] = {
	"",
	"',.!?",
	"abcABC",
	"defDEF",
	"ghiGHI",
	"jklJKL",
	"mnoMNO",
	"pqrsPQRS",
	"tuvTUV",
	"wxyzWXYZ"
};

int main(){
	string line;
	while(cin >> line){
		stringstream ss;
		int prev = 0, cnt = 0;
		if(line[line.size() - 1] != '0'){ line += "0"; }
		for(int i = 0; i < line.size(); ++i){
			int c = line[i] - '0';
			if(c == prev){
				if(c == 0){
					ss << " ";
				}else{
					if(TABLE[c][++cnt] == '\0'){ cnt = 0; }
				}
			}else{
				if(prev != 0){ ss << TABLE[prev][cnt]; }
				cnt = 0;
			}
			prev = c;
		}
		cout << ss.str() << endl;
	}
	return 0;
}

Measured memory_bytes: 0