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

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

using namespace std;

struct edge{ int u,v,d; };

const int V_MAX=100000,LG_V_MAX=17;

struct LCA_solver{
	int par[LG_V_MAX][V_MAX],dep[V_MAX];

	void build(int n,const vector<vector<edge>> &T,int root=0){
		struct info{ int u,pre,d; };
		static info S[V_MAX];
		int head=0,tail=0;
		S[tail++]=(info){root,-1,0};
		while(head<tail){
			int u=S[head].u,pre=S[head].pre,d=S[head].d; head++;
			par[0][u]=pre;
			dep[u]=d;
			for(edge e:T[u]) if(e.v!=pre) S[tail++]=(info){e.v,u,d+1};
		}

		rep(i,LG_V_MAX-1) rep(u,n) par[i+1][u]=(par[i][u]==-1?-1:par[i][par[i][u]]);
	}

	int lca(int u,int v)const{
		if(dep[u]>dep[v]) swap(u,v);
		rep(i,LG_V_MAX) if((dep[v]-dep[u])>>i&1) v=par[i][v];
		if(u==v) return u;

		for(int i=LG_V_MAX-1;i>=0;i--){
			if(par[i][u]!=par[i][v]){
				u=par[i][u];
				v=par[i][v];
			}
		}
		return par[0][u];
	}
};

pair<int,int> &operator+=(pair<int,int> &a,const pair<int,int> &b){
	a.first+=b.first;
	a.second+=b.second;
	return a;
}

pair<int,int> operator+(const pair<int,int> &a,const pair<int,int> &b){
	return make_pair(a.first+b.first,a.second+b.second);
}

pair<int,int> operator-(const pair<int,int> &a,const pair<int,int> &b){
	return make_pair(a.first-b.first,a.second-b.second);
}

const int N_MAX=2*V_MAX;

template<class T>
class Fenwick_tree{
	int n;
	T a[N_MAX];

public:
	void build(int n){
		this->n=n;
		rep(i,n) a[i]=T();
	}

	void add(int i,T v){
		for(;i<n;i|=i+1) a[i]+=v;
	}

	T sum(int i,int j){
		if(i==0){
			T s=T();
			for(;j>=0;j=(j&(j+1))-1) s+=a[j];
			return s;
		}
		return sum(0,j)-sum(0,i-1);
	}
};

int n;
vector<vector<edge>> T;

// Euler tour technique
int idx;
vector<int> down,up;
Fenwick_tree<pair<int,int>> F;

void dfs(int u,int p){
	for(edge e:T[u]) if(e.v!=p) {
		F.add(idx,make_pair(e.d,0));
		down[e.v]=idx++;
		dfs(e.v,u);
		F.add(idx,make_pair(-e.d,0));
		up[e.v]=idx++;
	}
}

struct query{ int u,v,d,id; };

int main(){
	int q; scanf("%d%d",&n,&q);
	T.resize(n);
	vector<vector<edge>> E(n-1); // E[c] := set of edges of color c
	rep(i,n-1){
		int u,v,c,d; scanf("%d%d%d%d",&u,&v,&c,&d); u--; v--; c--;
		T[u].emplace_back(edge{u,v,d});
		T[v].emplace_back(edge{v,u,d});
		E[c].emplace_back(edge{u,v,d});
	}

	LCA_solver L;
	L.build(n,T);

	F.build(2*n-2);
	down.resize(n);
	up  .resize(n);
	down[0]=-1;
	dfs(0,-1);

	vector<vector<query>> Q(n-1); // Q[c] := set of queries of color c
	rep(i,q){
		int c,d,u,v; scanf("%d%d%d%d",&c,&d,&u,&v); u--; v--; c--;
		Q[c].emplace_back(query{u,v,d,i});
	}

	vector<int> ans(q);
	rep(c,n-1) if(!Q[c].empty()) {
		for(edge e:E[c]){
			int u=e.u,v=e.v,d=e.d;
			if(L.dep[u]>L.dep[v]) swap(u,v);
			F.add(down[v],make_pair(-d, 1));
			F.add(up  [v],make_pair( d,-1));
		}

		for(query a:Q[c]){
			int u=a.u,v=a.v,d=a.d;
			int w=L.lca(u,v);
			auto b=F.sum(down[w]+1,down[u])+F.sum(down[w]+1,down[v]);
			ans[a.id]=b.first+d*b.second;
		}

		for(edge e:E[c]){
			int u=e.u,v=e.v,d=e.d;
			if(L.dep[u]>L.dep[v]) swap(u,v);
			F.add(down[v],make_pair( d,-1));
			F.add(up  [v],make_pair(-d, 1));
		}
	}

	rep(i,q) printf("%d\n",ans[i]);

	return 0;
}


Measured memory_bytes: 30644
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define INF 1LL<<60

template <class X>
vector<X> dijkstra(int n, int s, const vector<vector<pair<X, int>>> &G) {
    priority_queue<pair<X, int>, vector<pair<X, int>>, greater<pair<X, int>>>
        que;
    vector<X> d(n, INF);
    d[s] = 0;
    que.push(pair<X, int>(0, s));
    while (!que.empty()) {
        pair<X, int> p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            pair<X, int> e = G[v][i];
            if (d[e.second] > d[v] + e.first) {
                d[e.second] = d[v] + e.first;
                que.push(pair<X, int>(d[e.second], e.second));
            }
        }
    }
    return d;
}

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    vector<vector<pair<long long, int>>> G1(n);
    vector<vector<pair<long long, int>>> G2(n);
    for(int i=0; i<m; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G1[u].push_back(make_pair(a, v));
        G1[v].push_back(make_pair(a, u));
        G2[u].push_back(make_pair(b, v));
        G2[v].push_back(make_pair(b, u));
    }
    s--; t--;
    vector<long long> d1 = dijkstra(n, s, G1);
    vector<long long> d2 = dijkstra(n, t, G2);

    vector<long long> ans(n, INF);
    vector<long long> d(n);
    for(int i=0; i<n; i++)
        d[i] = d1[i] + d2[i];
    ans[n-1] = d[n-1];
    for(int i=n-2; i>=0; i--){
        ans[i] = min(ans[i+1], d[i]);
    }
    for(int i=0; i<n; i++)
        cout << 1000000000000000-ans[i] << endl;

    return 0;
}


Measured memory_bytes: 21036
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
#define MOD 1000000007
using namespace std;

int main() {
	int n;
	int ans = 0, value = 0;
	cin >> n;
	vector<int>c(n), v(n);
	REP(i, n) {
		cin >> v[i];
	}
	REP(i, n) {
		cin >> c[i];
	}
	REP(i, n) {
		value += v[i] - c[i];
		if (v[i] > c[i]) {
			ans += v[i] - c[i];
		}
	}
		cout << ans << endl;
	return 0;
}

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

typedef long long LL;
LL maxn = 1e9+7;
LL N,M;

int main()
{
    while(scanf("%lld",&N)!=EOF&&(N>=1&&N<=10e5))
    {
        M = 1;
        for(LL i=1;i<=N;i++)
        {
            M = (M%maxn)*(i%maxn)%maxn; //可以分别模除后再乘积
        }
        printf("%lld\n",M);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	/*
	int n,i,a,b;
	cin>>n;
	vector<int> a(n,0),b(n,0);
	rep(i,n)cin>>a[i]>>b[i];
	*/
	
	string s;
	int i;
	cin>>s;
	int ans=0;
	rep(i,s.length()){
		ans+=s[i]-'0';
	}
	if(ans==1)ans=10;
	fin(ans);
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}











Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807/2;
const int MOD = 1000000007;
const int N_MAX = pow(10,5);

vector<int> dp(N_MAX, -1); 
vector<vector<int>> from(N_MAX);

int dfs(int v) {
  if (dp[v] != -1) return dp[v];
  if (from[v].empty()) return dp[v] = 0;
  int result = 0;
  for (auto w: from[v]) result = max(result, dfs(w)+1);
  return dp[v] = result;
}

int main() {
  int N, M; cin >> N >> M;
  rep(i, M) {
    int x, y; cin >> x >> y; x--; y--;
    from[y].push_back(x);
  }

  rep(i, N) if (dp[i]==-1) dfs(i);
  // rep(i, N) cout << dp[i] << " "; cout << endl;
  int result = 0; rep(i, N) result = max(result, dp[i]);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1'000'000'007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll M, K;
    cin >> M >> K;
    ll K_max = bit(M) - 1;
    if(K > K_max){
        cout << -1 << endl;
        return 0;
    }
    if(K == 0){
        rep(i,bit(M)){
            cout << i << " " << i << " ";
        }
        cout << endl;
        return 0;
    }
    if(K == 1 && M == 1){
        cout << -1 << endl;
        return 0;
    }
    // 1 <= K <= Kmax
    deque<int> ans;
    ans.push_back(K);
    for(int i = 1; i < bit(M); i++){
        if(i == K)continue;
        ans.push_back(i);
        ans.push_front(i);
    }
    ans.push_back(0);
    ans.push_back(K);
    ans.push_back(0);
    for(auto a: ans){
        cout << a << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4652
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 200000;
const int INF = 0x3f3f3f3f;

int n;
char s[MaxN + 1];

vector<int> adj[MaxN + 1];

int dep[MaxN + 1][3];
int sum[MaxN + 1];

s64 res = 1ll;

int dfs1(const int &u, const int &fa)
{
	sum[u] = s[u] == '1';
	dep[u][0] = s[u] == '1' ? 0 : INF;

	for (int v : adj[u])
		if (v != fa)
		{
			sum[u] += dfs1(v, u);

			int d = dep[v][1] + 1;
			if (d > dep[u][1])
				dep[u][2] = dep[u][1], dep[u][1] = d;
			else if (d > dep[u][2])
				dep[u][2] = d;

			if (sum[v] > 0)
				dep[u][0] = min(dep[u][0], d);
		}

	return sum[u];
}

void dfs2(const int &u, const int &fa)
{
	for (int v : adj[u])
		if (v != fa)
		{
			int d = dep[u][dep[v][1] + 1 == dep[u][1] ? 2 : 1] + 1;
			if (d > dep[v][1])
				dep[v][2] = dep[v][1], dep[v][1] = d;
			else if (d > dep[v][2])
				dep[v][2] = d;

			if (sum[v] < sum[1])
				dep[v][0] = min(dep[v][0], d);

			dfs2(v, u);
		}

	int up = min(dep[u][1] - 1, dep[u][2] + 1);
	if (up >= dep[u][0])
		res += up - dep[u][0] + 1;
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		int u = getint(), v = getint();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	scanf("%s", s + 1);

	dfs1(1, 0);
	dfs2(1, 0);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include <vector>
#include <limits>

using namespace std;
constexpr int INF = std::numeric_limits<int>::max();
int main() {
  int N;
  cin >> N;
  vector<vector<int>> hap(N,vector<int>(3));
  for (int i = 0; i < N; i++) {
    cin >> hap[i][0] >> hap[i][1] >> hap[i][2];
  }
  vector<vector<int>> hapsum(N+1,vector<int>(3));
  for (int i = 0; i < N; i++) {
    for (int a1 = 0; a1 < 3; a1++) {
      for (int a2 = 0; a2 < 3; a2++) {
        if( a1 == a2 ) continue;
        hapsum[i+1][a1] = max(hapsum[i+1][a1],hapsum[i][a2] + hap[i][a2]);
      }
    }
  }
  cout << max(max(hapsum[N][0],hapsum[N][1]),hapsum[N][2]) << endl;
}


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

using namespace std;

int main(){

  string c;
  cin >> c;

  string v = "aiueo";

  if (v.find(c) != string::npos){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//
// Created by chuta on 2020/09/19.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n;
    cin >> n;
    int c = 0;
    int ma = 0;
    int x, y;
    rep(i,n){
        cin >> x >> y;
        if(x==y) c++;
        else c=0;
        ma = max(ma, c);
    }
    if(ma>=3) CYES;
    else CNO;
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
p0, p1 = list(map(int, input().split()))
p = [p0, p1]
for i in range(n-1):
    pi = list(map(int, input().split()))
    p.append(pi[1])
    
dp = [[10**10]*(n+2) for _ in range(n+2)]

for i in range(0, n+2):
    dp[i][i] = 0

for l in range(2,n+1):
    for i in range(1, n-l+2):
        j = i + l - 1
        for k in range(i, j):
            dp[i][j] = min([dp[i][j], 
              dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]])

print(dp[1][n])



Measured memory_bytes: 5672
#include <bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
 
using namespace std;
using ll = long long;
 
const double PI = 3.14159265358979;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
 
 
 
void solve()
{
  int n, k, a_input;
  cin >> n >> k;
  vector<ll> a_posi;
  vector<ll> a_nega;
  for(int i = 0; i < n; ++i)
  {
    cin >> a_input;
    (a_input < 0 ? a_nega : a_posi).emplace_back(a_input);
  }
 
  if (a_posi.size() == 0 && (k & 1))
  {
    sort(a_nega.begin(), a_nega.end(), greater<ll>());
  }
  else
  {
    sort(a_nega.begin(), a_nega.end());    
    sort(a_posi.begin(), a_posi.end(), greater<ll>());
  }
  if (k == 1)
  {
    mint ans = 0;
    if (a_posi.size()) ans = a_posi[0];
    else ans = a_nega[0];
    cout << ans;
    return;
  }
  if (n == k)
  {
    mint ans = 1;
    for(const auto& a : a_posi) ans *= a;
    for(const auto& a : a_nega) ans *= a;
    cout << ans;
    return;
  }

  int ip = 0, in = 0;
  mint ans = 1;
  for(int i = 0; i < k; i += 2)
  {
    if (k - i == 1)
    {
      if (ip < a_posi.size()) ans *= a_posi[ip];
      else ans *= a_nega[in];
      continue;
    }
 
    ll mp = -1;
    ll mn = -1;
    if (ip + 2 < a_posi.size())
    {
      mp = a_posi[ip] * a_posi[ip + 1];
    }
    else if (ip + 1 < a_posi.size() && ((k & 1) == 0) )
    {
      mp = a_posi[ip] * a_posi[ip + 1];
    }
    if (in + 1 < a_nega.size())
    {
      mn = a_nega[in] * a_nega[in + 1];
    }
 
    if (mp < mn)
    {
      ans *= mn;
      in += 2;
    }
    else if (mn < mp)
    {
      ans *= mp;
      ip += 2;
    }
    else
    {
      ans *= a_posi[ip] * a_posi[ip + 1];
      ip += 2;
    }
    
  }
 
  
 
  cout << ans;
}
 
int main()
{
  fastio;
  solve();
 
  return 0;
}

Measured memory_bytes: 5568
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,X,C=0,l=1,r=1;
    cin >> N >> X;
    rep(i,N){
        r=r*2+3;
    }
    rRep(i,N,0){
        if(i==0){
            C++;
            break;
        }
        if(X==l){
            break;
        }
        else if(X==((r+l)/2)){
            ll K=0;
            rep(j,i){
                K=K*2+1;
            }
            C+=K;
            C++;
            break;
        }
        else if(X==r){
            ll K=1;
            rep(j,i){
                K=K*2+1;
            }
            C+=K;
            break;
        }
        else if(X<(r+l)/2){
            l++;
            r=(l+r)/2-1;
        }
        else{
            ll K=0;
            rep(j,i){
                K=K*2+1;
            }
            C+=K+1;
            l=(l+r)/2+1;
            r--;
        }
    }
    cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define unordered_map umap
typedef long long ll;
typedef long double ld;
ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}
bool isPrime(int n){if(n<2){return false;}for(int i=2;i<sqrt(n)+1;i++){if(n%i==0) return false;}return true;}

int main(){
  int L = 55555+1;
  bool prime[L];
  vector<int> pv = {2};
  int count = 0;
  int N; cin >>N;
  for(int i=3;i<L;i++){
    bool fp = true;
    for(int x:pv){ if(i%x==0){fp = false;break;} }
    if(fp){
      if(i%5==3){
	    printf("%d ",i);
    	count++;
      	if(count==N) break;
      }
      pv.push_back(i);
    }
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		HashMap<Integer, ArrayList<Integer>> m = new HashMap<Integer, ArrayList<Integer>>();
		int N = sc.nextInt();
		int M = sc.nextInt();
		for(int i=0; i<N; i++) {
			m.put(i+1, new ArrayList<Integer>());
		}
		for(int i=0; i<M; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			m.get(a).add(b);
			m.get(b).add(a);
		}
		for(int e : m.get(1)) {
			if(m.get(e).contains(N)) {
				print("POSSIBLE");
				return;
			}
		}
		print("IMPOSSIBLE");
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

Measured memory_bytes: 188208
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define ROW_MAX 1000
#define COL_MAX ROW_MAX
#define BUF_SIZE (ROW_MAX+20)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

struct point2d {
    int row;
    int col;
};

struct point2d dist[4] = {
    {0, 1}, // right direction
    {1, 0}, // bottom direction
};

static char map[ROW_MAX+1][COL_MAX+1];
static char dst_cnt[ROW_MAX+1][COL_MAX+1];
static uint64_t ans[ROW_MAX+1][COL_MAX+1];
#define DIVISOR 1000000007

void dfs(struct point2d p, uint64_t cnt) {
    ans[p.row][p.col] = (ans[p.row][p.col]+cnt)%DIVISOR;
#ifdef DEBUG
    printf("(%d %d) -> %d [prev_dst: %d]\n", p.row, p.col, (int)ans[p.row][p.col], dst_cnt[p.row][p.col]);
#endif
    int i;
    // wait until all previous path were analyzed
    if(dst_cnt[p.row][p.col]) return;
    // no longer needed
    map[p.row][p.col] = 0;
    for(i = 0; i < 2; i++) {
        struct point2d np = {
            p.row + dist[i].row,
            p.col + dist[i].col
        };
        if(map[np.row][np.col]) {
            dst_cnt[np.row][np.col]--;
            dfs(np, ans[p.row][p.col]);
        }
    }
}

int main(void) {
    int row, col;
    static char buf[BUF_SIZE];
    get_int2(&row, &col);
    int i, j;
    for(i = 1; i <= row; i++) {
        get_str(&buf[1], BUF_SIZE-1);
        for(j = 1; j <= col; j++) {
            map[i][j] = buf[j] == '.';
        }
    }
    for(i = 1; i <= row; i++) {
        for(j = 1; j <= col; j++) {
        }
    }
    // delete unused mass
    for(i = 1; i <= row; i++) {
        for(j = 1; j <= col; j++) {
            // assume that (1,1) should be empty.
            if(i==1 && j==1) continue;
            int cnt = 0;
            if(i!=1 && map[i-1][j]) cnt++;
            if(j!=1 && map[i][j-1]) cnt++;
            if(cnt==0) map[i][j]=0;
            dst_cnt[i][j] = cnt;
        }
    }
    struct point2d start = {1, 1};
    dfs(start, 1);
    printf("%d\n", (int)ans[row][col]);
    return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,x1=0,a;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a;
        if(i%2!=0 && a%2!=0)
        {
            x1++;
        }
    }
    cout<<x1;
    }


Measured memory_bytes: 3568
#include <stdio.h>
int main() {
	int a, b, k, h,c = 0;
	scanf("%d", &a);
	scanf("%d", &b);
	if (b / 100 > 0)
		k = a * 1000 + b;
	else if (b / 10 > 0)
		k = a * 100 + b;
	else
		k = a * 10 + b;

	for (h = 0; h < k; h++) {
		if (k == (h * h)){
			c = 1;
			break;
	    }else {
			c = 0;
		}
	}
	if (c == 1)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

bool check(string s){
    string r = s;
    reverse(r.begin(), r.end());
    bool flag = true;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != r[i]) flag = false;
    }
    return flag;
}

int main(){
    string s;
    cin >> s;
    int n = s.length();
    if (check(s) && check(s.substr(0, (n-1)/2)) && check(s.substr((n+1) / 2, (n-1)/2))) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
while True:
    h,w = map(int, input().split())
    if h == 0 and w == 0: break
    for j in range(h):
        for i in range(w):
            if i == 0 or j == 0 or i == w-1 or j == h-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7000
macro_rules! debug {
    ( $x:ident [ $i:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}] = {}", stringify!($x), $i, $x[$i]);
        }
    };
    ( $x:ident [ $i:expr ][ $j:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}][{}] = {}", stringify!($x), $i, $j, $x[$i][$j]);
        }
    };
    ( $x:expr ) => {
        if cfg!(debug_assertions) {
            println!("{}:{} {} = {:?}", line!(), column!(), stringify!($x), $x);
        }
    };
}

fn main() {
    use std::cmp::{max, min};
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let N: usize = stdin.read();
    let A: i32 = stdin.read();
    let B: i32 = stdin.read();
    let mut count1 = 0;
    let mut count2 = 0;
    let mut count3 = 0;
    for i in 0..N {
        let P:i32 = stdin.read();
        if P <= A {
            count1 += 1;
        } else if P <= B {
            count2 += 1;
        } else {
            count3 += 1;
        }
    }
    let result = min(min(count1, count2), count3);
    println!("{}", result);
}

mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}



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

using namespace std;

const int MAXN = 1000;
int a[MAXN], b[MAXN], sa[MAXN], sb[MAXN];
int ans, n;
int main() {
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
		sa[i] = sa[i-1] + a[i];
	}
	for (int i=1; i<=n; i++) {cin >> b[i]; sb[i]=sb[i-1]+b[i];}
	for (int i=1; i<=n; i++)
	ans = max(ans, sa[i] + sb[n] - sb[i-1]);
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 101;

int h[MAXN];

int main()
{
    int t; cin >> t;
    REP(t)
    {
        int n;
        int up = 0, down=0 ;
        cin >> n >> h[0];
        rep(j,n - 1)
        {
            cin >> h[j+1];
            if(h[j] < h[j+1]) up = max(up, h[j+1]-h[j]);
            else down = max(down, h[j]-h[j+1]);
        }
        cout << up << " " << down << endl;
        
    }
    return 0;
}

Measured memory_bytes: 0
use proconio::input;

fn main() {
  input! {
    n: usize,
    mut vals: [(isize, isize);n]
  }
  
  let mut xis: Vec<isize> = vec![0;n];
  for i in 0..n {
    xis[i] = vals[i].0 - vals[i].1;
  }
  xis.sort();
  
  let mut xiis: Vec<isize> = vec![0;n];
  for i in 0..n {
    xiis[i] = vals[i].0 + vals[i].1;
  }
  xiis.sort();  
  let result = std::cmp::max(
    xis.last().unwrap() - xis[0],
    xiis.last().unwrap() - xiis[0]
  );
  
  println!("{}", result);
}

Measured memory_bytes: 12780
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b=1010,s=0,t,T,c,i;
    cin>>n>>T;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t<=T)
        {
            if(c<=b)
            {
            b=c;
            s++;
            }

        }
    }
    if(s==0)
        cout<<"TLE"<<endl;
    else
        cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	string s; cin >> s;
	ll ans = 0;
	for (int i = 0; i < s.size(); ++i) {
		ans += s[i] - '0';
	}
	if (ans % 9 == 0)cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 3756
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

const int N = 1e5 + 7;

int stones[N], cost[N], n;

int find_cost(int stone)
{
    if(stone > n)   return 1e9;
    if(stone == n)  return 0;

    int &ans = cost[stone];

    if(ans != -1)   return ans;
    
    ans = min(abs(stones[stone]-stones[stone+1])+find_cost(stone+1), abs(stones[stone]-stones[stone+2])+find_cost(stone + 2));
    return ans;
}

int32_t main()
{
    IOS; //FIO;
    cin >> n;
    memset(cost,-1,sizeof(cost));
    for(int i = 1; i <= n; ++ i)
    cin  >> stones[i];
    cout << find_cost(1);
    return 0;
}

Measured memory_bytes: 3328
#import<iostream>
using namespace std;
 
int main() {
  while (true) {
  int a, b;
  char op;
  cin >> a >> op >> b;
 
  if (op == '?') { break; }
 
  int answer = 0;
  if (op == '+') {
    answer = a + b;
  } else if (op == '-') {
    answer = a - b;
  } else if (op == '*') {
    answer = a * b;
  } else if (op == '/') {
    answer =  a /b;
  }
 
  cout << answer << endl;
  }
  return 0;
}

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

int main(){
	double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;

	while (cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2)
		cout << ((xb1 <= xa2 && xa1 <= xb2 && yb1 <= ya2&&ya1 <= yb2) ? "YES" : "NO") << endl;
}

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

namespace ITP2_1_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] ll= new int[n * 2 + 1];
            int head = n;
            int trail = n;

            for (int i = 0 ; i < n ; i++)
            {
                int[] line = ReadIntAr();
                switch (line[0])
                {
                    case 0:     
                        if (line[1] == 0)
                        {
                            ll[head - 1] = line[2];
                            head--;
                        }
                        else
                        {
                            ll[trail] = line[2];
                            trail++;
                        }
                        break;
                    case 1:
                        Console.WriteLine(ll[head + line[1]].ToString());
                        break;
                    case 2:
                        if (line[1] == 0)
                        {
                            ll[head] = 0;
                            head++;
                        }
                        else
                        {
                            ll[trail-1] = 0;
                            trail--;
                        }
                        break;
                }
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";

int main() {
    int n;
    cin>>n;
    vin a(n);
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==0){
            if(a[i]%5!=0&&a[i]%3!=0){
                cout<<"DENIED"<<endl;
                return 0;
            }
        }
    }
    cout<<"APPROVED"<<endl;
  
}


Measured memory_bytes: 3596
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
h = list(map(int, input().split()))
good = [True] * n
for j in range(m):
    ab = list(map(int, input().split()))
    a = ab[0]
    b = ab[1]
    if  h[a - 1] == h[b - 1]:
        good[a-1]=good[b-1]=False
    smaller_tower_index = a - 1 if h[a - 1] < h[b - 1] else b - 1
    if good[smaller_tower_index]:
        good[smaller_tower_index] = False
print(good.count(True))

Measured memory_bytes: 84872
#include<iostream>
#include<string>
#include <cstdio>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

string s;

int main(void) {
	cin >> s;
	int ret = 0, tmp = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			tmp++;
			if (tmp > ret)
				ret = tmp;
		}
		else tmp = 0;
	}
	cout << ret << endl;
	return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep1(i,n) for(long long i=1; i<=(long long)(n);i++)
//rep1は「１からnまで」の繰り返し
#define rep-(i,n) for(long long i=n;i>=0;i--)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    if((abs(a-c)<=d)||((abs(a-b)<=d)&&(abs(b-c)<=d)))
        cout<<"Yes"<<endl;
    else {
        cout<<"No"<<endl;
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> T.at(i);
    sum+=T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for(int i=0; i<M; i++){
    cin >> P.at(i) >> X.at(i);
  }
  
  for(int i=0; i<M; i++){
    cout << sum-T.at(P.at(i)-1)+X.at(i)<<endl;
  }
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val d = Array.fill(n)(readLine().split(" ").map(_.toInt))
    .map(list => (list(0) == list(1)))
  def solve(): String = {
    for(i <- 0 to n-3) {
      if(d(i) && d(i+1) && d(i+2)) return "Yes"
    }
    "No"
  }

  println(solve())

}



Measured memory_bytes: 54700
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}

double rec(LL i, LL j, LL k, LL& N, vector<vector<vector<double>>>& dp) {
    if (dp[i][j][k] >= 0.0) return dp[i][j][k];
    double expect = N;
    expect += i - 1 >= 0 ? rec(i - 1, j, k, N, dp) * i : 0.0;
    expect += j - 1 >= 0 ? rec(i + 1, j - 1, k, N, dp) * j : 0.0;
    expect += k - 1 >= 0 ? rec(i, j + 1, k - 1, N, dp) * k : 0.0;
    expect /= i + j + k;
    return dp[i][j][k] = expect;
}

int main() {
    LL N;
    cin >> N;
    VI A(4);
    REP(i, N) {
        LL a;
        cin >> a;
        A[a]++;
    }

    vector<vector<vector<double>>> dp(N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1, -1.0)));
    dp[0][0][0] = 0.0;
    cout << fixed << setprecision(10) << rec(A[1], A[2], A[3], N, dp) << endl;
	
    return 0;
}


Measured memory_bytes: 216960
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <set>

using namespace std;

set <string> hav;

int main()
{
	string a, a0;
	int n, flg = 1;
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
	{
		cin>>a;
		if(i!=1 && (*a0.rbegin()!=*a.begin() || hav.count(a))) flg = 0;
		else a0 = a, hav.insert(a);
	}
	printf("%s\n", (flg) ? ("Yes") : ("No"));
	return 0;
}

Measured memory_bytes: 256
//Half and Half

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int a,b,c,x,y,ans;cin>>a>>b>>c>>x>>y;
    int amai=x,bmai=y;
    ans=a*amai+b*bmai;
    rep(i,1,x+y+1){
        amai--;
        bmai--;
        if(amai<0)amai=0;if(bmai<0)bmai=0;
        ans=min(ans,amai*a+bmai*b+c*2*i);
    }
    cout << ans << nnn;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
N=int(input())
s=list(accumulate(map(int,input().split())))
def f(N,s):
    ans=s[-1]
    p=0
    q=2
    for i in range(2,N-1):
        while abs(s[i-1]-2*s[p])>abs(s[i-1]-2*s[p+1]):
            p+=1
        while abs(s[q]*2-s[i-1]-s[-1])>abs(s[q+1]*2-s[i-1]-s[-1]):
            q+=1
        t=[s[i-1]-s[p],s[p],s[q]-s[i-1],s[-1]-s[q]]
        ans=min(ans,max(t)-min(t))
    print(ans)
    return 
f(N,s)

Measured memory_bytes: 25972
#include <bits/stdc++.h>
 #include <string> 
 #include <math.h>
 #include <bitset>
 #include <numeric>
 #include <stdio.h>
 #include <algorithm>

 using namespace std;

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

    cout << A*B << endl;

    return 0;
 }









Measured memory_bytes: 3636
/*
*/

#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-9
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 350

using namespace std;

const int INF = 1e9;
const int N = 220031;

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	string Z = "CODEFESTIVAL2016";
	string st;
	cin >> st;
	int ans = 0;
	for (int i = 0; i < st.size(); i++)
	{
		if (st[i] != Z[i])
			++ans;
	}
	cout << ans << endl;


	cin.get(); cin.get();
	return 0;
}

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

int main()
{
    int x, n ;
    cin >> x >> n;
    set<int> p ;
    int a ;
    rep(i,n)
    {
        cin >> a ;
        p.insert(a) ;
    }

    int b = x ;
    if(p.find(b)==p.end())
    {
        cout << b << endl ;
        return 0;
    }
    
    int minus = -1 ;

    int plus = -1 ;

    while(1)
    {
        b-- ;
        if(p.find(b)==p.end())
        {
            minus = b ;
            break ;
        }
    }
    b=x ;

    while (1)
    {
        b++ ;
        if(p.find(b)==p.end())
        {
            plus  = b ;
            break ;
        }
    }

    if(abs(x-minus)>abs(x-plus))
    {
        cout << plus << endl ;
    }
    else
    {
        cout << minus << endl ;
    }
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long  ll;
//typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set
// this for long double
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 1010;
const int INF = 1e8;
const ll MOD1=1073741824;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
string bin_rep(int n)
{
          string s="";
      for(int i=31;i>=0;i--)
   {
           if(n&(1<<i)) s+='1';
           else s+='0';
   }
   return s;
}
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 char c;
 cin>>c;
 if(c>='A' && c<='Z') cout<<"A";
 else cout<<"a";
         

    
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
ll n;
vg dp;
vec weight,value;
ll func(ll ind,ll w) {
	if(ind == n)
		return 0;
	if(dp[ind][w] != -1)
		return dp[ind][w];
	ll res;
	if(weight[ind] > w)
		res = func(ind + 1,w);
	else
		res = max(func(ind + 1,w),func(ind + 1,w - weight[ind]) + value[ind]);
	return dp[ind][w] = res;
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll w;
	cin >> n >> w;
	dp.resize(n,vector<ll>(w + 1,-1));
	weight.resize(n);
	value.resize(n);
	ll i;
	for(i = 0 ; i < n ; i++)
		cin >> weight[i] >> value[i];
	cout << func(0,w);
	return 0;
}


Measured memory_bytes: 79488