akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int go[220000][2];

int cc = 1;

void add(char *s) {
	int n = strlen(s);
	int now = 0;
	for (int i = 0; i < n; ++i) {
		int c = s[i] - '0';
		if (go[now][c])
			now = go[now][c];
		else
			now = go[now][c] = cc++;
	}
}

int n;
ll l;
char buf[120000];
vector<ll> vv;

ll ans = 0;

void dfs1(int v, int h) {
	int cc = 0;
	for (int i = 0; i < 2; ++i)
		if (!go[v][i])
			++cc;
		else
			dfs1(go[v][i], h + 1);
	if (cc == 1) {
		ll go = 1;
		ll a = l - h;
		while (a % 2 == 0)
			a /= 2, go *= 2;
		ans ^= go;
	}
}

int main() {
	scanf("%d%lld", &n, &l);
	for (int i = 0; i < n; ++i) {
		scanf(" %s", buf);
		add(buf);
	}
	dfs1(0, 0);
	if (ans)
		cout << "Alice\n";
	else
		cout << "Bob\n";
	return 0;
}




Measured memory_bytes: 3968
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double ans = 0.0;
    int N; cin >> N;
    rep(i, N) {
        double num;
        string S;
        cin >> num >> S;
        if (S == "JPY") {
            ans += num;
        } else {
            ans += num * 380000.0;
        }
    }
    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
class ReRooting(object):
    """ 全方位木DP """
    def merge(self, a, b):
        """ 二項演算 a・b """
        return a * b % M

    def adj_bu(self, accBU, v:int):
        """
        Bottom-Upの単項演算 g(accBU[v])

        v: 頂点
        """
        return accBU + 1

    def adj_td(self, accTD, v:int, p:int):
        """
        Top-Downの単項演算 g(accTD[v])

        v: 頂点
        p: 親
        """
        return accTD + 1

    def adj_fin(self, acc, v:int):
        """
        最終結果の単項演算 g(acc[v])

        v: 頂点
        """
        return acc

    def __init__(self, V:int, e:int):
        """
        V: 頂点数
        e: 単位元
        """
        self.V, self.e = V, e
        self.edge = [[] for _ in range(V)]
        self.par = [-1] * V
        self.order = []
        self.SIZE = [1] * self.V
    
    def subtree_size(self):
        """ 部分木のサイズを求める """
        for v in reversed(self.order[1:]):
            self.SIZE[self.par[v]] += self.SIZE[v]

    def add_edge(self, u:int, v:int):
        """ 辺(u,v)をグラフに追加する """
        self.edge[u].append(v)
        self.edge[v].append(u)
    
    def topological_sort(self, root:int = 0):
        """ トポロジカルソート """
        from collections import deque
        que = deque([root])
        while que:
            v = que.popleft()
            self.order.append(v)
            for w in self.edge[v]:
                if w != self.par[v]:
                    self.par[w] = v
                    self.edge[w].remove(v)
                    que.append(w)
    
    def bottom_up(self):
        """ Bottom-Up DP """
        root = self.order[0]
        accBU = [self.e] * self.V
        resBU = [self.e] * self.V

        for v in reversed(self.order):
            resBU[v] = self.adj_bu(accBU[v], v)

            if v == root: break

            p = self.par[v]
            accBU[p] = self.merge(accBU[p], resBU[v])
        return accBU, resBU
    
    def top_down(self, resBU:list):
        """ Top-Down DP """
        accTD = [self.e] * self.V
        resTD = [self.e] * self.V

        for p in self.order:
            # 左からaccTDを更新
            ac = resTD[p]
            for v in self.edge[p]:
                accTD[v] = ac
                ac = self.merge(ac, resBU[v])

            # 右からaccTDを更新
            ac = self.e
            for v in reversed(self.edge[p]):
                accTD[v] = self.merge(accTD[v], ac)
                ac = self.merge(ac, resBU[v])
                
                resTD[v] = self.adj_td(accTD[v], v, p)
        return resTD
    
    def solve(self):
        self.topological_sort()
        #self.subtree_size()
        accBU, resBU = self.bottom_up()
        resTD = self.top_down(resBU)
        res = [self.adj_fin(self.merge(a, b), v) for v,(a,b) in enumerate(zip(accBU, resTD))]
        return res

#############################################################
N, M = map(int, input().split())
 
RR = ReRooting(N, 1)
for _ in range(N - 1):
    x, y = map(int, input().split())
    RR.add_edge(x - 1, y - 1)
 
print(*RR.solve(), sep="\n")

Measured memory_bytes: 36596
#!/usr/bin/ruby
# encoding: utf-8

# ABC 102 C - Linear Approximation

def calcHappines(center)
  s = 0
  for i in 1..N do
    s += (B[i-1]-center).abs
  end 
  return s
end

N = gets.to_i
A = gets.split.map(&:to_i)
B = Array.new

for i in 1..N do
  B[i-1] = A[i-1]-i
#  puts B[i-1]
end

B.sort!

#for debug
#p B

center = B[(N-1)/2]
happiness = calcHappines(center) 

#for debug
#puts "center= #{center}"

p happiness


Measured memory_bytes: 19656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll n;

ll ans = INFLONG;
//void calc(){
//  vector<ll> vec(n);
//}
int main(){
  ll n;
  cin >> n;
  vector<pair<ll,ll>> pa(n);
  rep(i,n){
    cin >> t1 >> t2;
    pa[i].first = t1 + t2;
    pa[i].second = t1 - t2;
  }
  sort(all(pa));
  ll ans = 0;
  t1 = -INFLONG;
  rep(i,n){
    if(pa[i].second >= t1){
      ans++;
      chmax(t1,pa[i].first);
    }else{

    }
  }
  cout << ans << endl;
}


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

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

  string board[50];

  for (int i = 0; i < h; i++) cin >> board[i];
  
  const int dx[8] = {0,-1,-1,-1,0,1,1,1};
  const int dy[8] = {1,1,0,-1,-1,-1,0,1};

  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (board[i][j] == '#') continue;

      int num = 0;
      for (int d = 0; d < 8; d++){
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if (ni < 0 or h <= ni) continue;
        if (nj < 0 or w <= nj) continue;
        if (board[ni][nj] == '#') num++;
      }

      board[i][j] = char(num + '0');

    }
  }

  for (int i = 0; i < h; i++) cout << board[i] << endl;

  return 0;
}

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

int main() {
    int a,b;
    std::cin>>a>>b;
    if(a>b){
        std::cout<<a+a-1<<std::endl;
    }else if(a<b){
        std::cout<<b+b-1<<std::endl;
    }else{
        std::cout<<a+b<<std::endl;
    }
    return 0;
}

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

using namespace std;

int n, m;
int sx, sy, tx, ty;
char s[maxn][maxn];

int f[maxn * maxn];
queue<int> q;

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

int col[maxn][maxn], cnt;

void dfs(int i, int j){
	for(int k = 0;k < 4;k++){
		int ii = i + dx[k], jj = j + dy[k];
		if(s[ii][jj] == '.' && !col[ii][jj]){
			col[ii][jj] = col[i][j], dfs(ii, jj);
		}
	}
}

vector<int> v[maxn * maxn];

int main(){
	scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &tx, &ty);
	for(int i = 1;i <= n;i++) scanf("%s", s[i] + 1);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i][j] == '.' && !col[i][j]){
				col[i][j] = ++cnt;
				dfs(i, j);
			}
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i][j] != '.') continue;
			for(int x = -2;x <= 2;x++){
				for(int y = -2;y <= 2;y++){
					if(!x && !y) continue;
					int ii = x + i, jj = y + j;
					if(ii <= 0 || ii > n || jj <= 0 || jj > m || s[ii][jj] != '.') continue;
					if(col[ii][jj] == col[i][j]) continue;
					v[col[i][j]].push_back(col[ii][jj]);
				}
			}
		}
	}
	memset(f, 0x3f, sizeof(f));
	f[col[sx][sy]] = 0, q.push(col[sx][sy]);
	while(!q.empty()){
		int x = q.front();q.pop();
		for(int i = 0;i < v[x].size();i++){
			int to = v[x][i];
			if(f[to] > f[x] + 1){
				f[to] = f[x] + 1;
				q.push(to);
			}
		}
	}
	printf("%d", f[col[tx][ty]] == 0x3f3f3f3f ? -1 : f[col[tx][ty]]);
	
}

Measured memory_bytes: 52708
package main

import "fmt"

func solve() {
	var R, G int
	fmt.Scan(&R, &G)

	fmt.Println(R + (G-R)*2)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	solve()
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,x,y;
  cin>>n>>x>>y;
  int ans[n-1]={0};
  repi(i,1,n+1){
    repi(j,i+1,n+1){
      int num=j-i;
      num=min(num,abs(i-x)+abs(j-y)+1);
      num=min(num,abs(j-x)+abs(i-y)+1);
      ans[num-1]++;
    }
  }
  rep(i,n-1){
    cout<<ans[i]<<endl;
  }

  return 0;
}


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'

int main()
{
    fastio;
    int r;
    cin>>r;
    cout<<setprecision(20)<<2*M_PI*r<<endl;
}

Measured memory_bytes: 3804
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<set>

using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)

#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。

int main(){
    int n,k;
    cin>>n>>k;
    deque<int> deq;
    rep0(i,n){
        int v;
        cin>>v;
        deq.push_back(v);
    }
    ll ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=n;j++){
            if(i+j>k) continue;
            else{
                for(int r=0;r<=j;r++){
                    int l=j-r;
                    vector<int> pos;
                    deque<int> deq2;
                    deq2=deq;
                    rep0(waa,r){
                        int ppos=deq2.front();
                        deq2.pop_front();
                        pos.push_back(ppos);
                    }
                    rep0(ghaa,l){
                        int ppos=deq2.back();
                        deq2.pop_back();
                        pos.push_back(ppos);
                    }
                    sort(pos.begin(),pos.end());
                    reverse(pos.begin(),pos.end());
                    ll pppos=0;
                    rep0(gg,j-i){
                        pppos+=pos[gg];
                    }
                    ans=max(ans,pppos);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int a[110000];
int sum1[110000],sum2[110000];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	bool b1=true,b2=true;
	int d1=1,d2=1;
	for(int i=3;i<=n;i+=2)
	{
		if(a[i]!=a[i-2]) b1=false;	
		d1++;
	}
	for(int i=1;i<=n;i+=2) sum1[a[i]]++;
	for(int i=4;i<=n;i+=2)
	{
		if(a[i]!=a[i-2]) b2=false;
		d2++;
	}
	for(int i=2;i<=n;i+=2) sum2[a[i]]++;
	if(b1==true&&b2==true&&a[1]!=a[2]){printf("0\n");return 0;}
	else
	{
		if(b1==true&&b2==true)
		{
			printf("%d\n",min(d1,d2));
			return 0;
		}
		int m11=0,m12=0,t11,t12;
		int m21=0,m22=0,t21,t22;
		if(b1==false&&b2==true)
		{
			for(int i=1;i<=100000;i++)
			{
				if(m11<sum1[i])
				{
					swap(m11,m12);swap(t11,t12);
					m11=sum1[i];t11=i;
				}
				else if(m12<sum1[i])
				{
					m12=sum1[i];t12=i;
				}
			}
			if(a[2]==t11) printf("%d\n",min(d2+d1-m11,d1-m12));
			else printf("%d\n",d1-m11);
		}
		else if(b1==true&&b2==false)
		{
			for(int i=1;i<=100000;i++)
			{
				if(m11<sum2[i])
				{
					swap(m11,m12);swap(t11,t12);
					m11=sum2[i];t11=i;
				}
				else if(m12<sum2[i])
				{
					m12=sum2[i];t12=i;
				}
			}
			if(a[1]==t11) printf("%d\n",min(d1+d2-m11,d2-m12));
			else printf("%d\n",d2-m11);
		}
		else
		{
			for(int i=1;i<=100000;i++)
			{
				if(m11<sum1[i])
				{
					swap(m11,m12);swap(t11,t12);
					m11=sum1[i];t11=i;
				}
				else if(m12<sum1[i])
				{
					m12=sum1[i];t12=i;
				}
			}
			for(int i=1;i<=100000;i++)
			{
				if(m21<sum2[i])
				{
					swap(m21,m22);swap(t21,t22);
					m21=sum2[i];t21=i;
				}
				else if(m22<sum2[i])
				{
					m22=sum2[i];t22=i;
				}
			}
			if(t11!=t21) printf("%d\n",d1+d2-m11-m21);
			else
			{
				int mmin=1<<30;
				if(t11!=t22) mmin=min(mmin,d1+d2-m11-m22);
				if(t21!=t12) mmin=min(mmin,d1+d2-m21-m12);
				printf("%d\n",mmin);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
int main() {
	string s,t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0;i < 3;++i) {
		if (s[i] == t[i]) {
			++cnt;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  long long int n, i, j, k;
  unsigned long long int sum = 0;
  cin>>n;
  for (i = 1; i <= n; i++)
    if (i % 3 != 0 && i % 5 != 0)
        sum += i;
  cout<<sum;
  return 0;
}

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

using namespace std;

int main(){
	int n, k; cin >> n >> k;
	long long a = 0, b = 0;
	long long ans = 0;
	for(int i = 1; i <= n; ++i) if(i % k == 0) a++;
	for(int i = 1; i <= n; ++i) if(i % k == k / 2) b++;
	ans = (k%2==0?1LL*a*a*a+b*b*b:1LL*a*a*a);
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        int k = sc.nextInt();

        ArrayList<Long> list = new ArrayList<>();

        for (long i = 0; i < n ; i++) {
            list.add(sc.nextLong());
        }
        Collections.sort(list);

        PriorityQueue queue = new PriorityQueue();

        for (int i = 0; i < n - k + 1; i++) {
            long value = list.get(i + k - 1) - list.get(i);
            queue.add(list.get(i + k - 1) - list.get(i));
            if (value == 0) {
                break;
            }
        }

        System.out.println(queue.peek());
    }
}


Measured memory_bytes: 60544
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N, X;
int L[110];

void solve() {

	cin >> N >> X;
	int ans = 1;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		sum += L[i];
		if (sum > X) {
			cout << ans << endl;
			return;
		}
		ans++;
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int N,K;
  scanf("%d%d",&N,&K);
  int x[N];
  int i;
  i = 0;
  while (i < N)
  {
    scanf("%d",&x[i]);
    i++;
  }
  int sum;
  sum = 0;
  i = 0;
  while (i < N)
  {
    if (x[i] < K - x[i])
    {
      sum += x[i] * 2;
    }
    else
    {
      sum += (K - x[i]) * 2;
    }
    i++;
  }
  printf("%d",sum);
}

Measured memory_bytes: 128
import bisect

N = int(input())
L = sorted(list(map(int, input().split())))

res = 0
for i in range(N):
    np = i
    for j in range(i + 1, N):
        idx = bisect.bisect_left(L, L[i] + L[j]) - 1
        cnt = idx - j
        if idx <= j or np > idx:
            continue
        res += cnt
        np = idx

print(res)


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

void doScan(vector<int>& d){
    for(int i=0;i<d.size();i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
}
int main() {
    int n;
    long long counter=0;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    doScan(a);
    doScan(b);
    doScan(c);
    long long  d,e;
    for(int i=0;i<n;i++){
        d = lower_bound(a.begin(),a.end(),b[i]) -a.begin();
        e= c.end() - upper_bound(c.begin(),c.end(),b[i]);
       counter +=  d*e ;
    }


    cout << counter << endl;
}




Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    long long int h, n, i;
    vector<long long int> v;
    long long int u[200000];
    
    cin >> n;
    
    for(i = 0; i < n; i++){
        cin >> h;
        v.push_back(h);
    }

    for(i = 0; i < n; i++){
        u[i] = 1000000000;
    }
    
    u[0] = 0;
    
    for(i = 0; i < n-1; i++){
        u[i+1] = min(u[i+1], u[i] + abs(v[i] - v[i+1]));
        u[i+2] = min(u[i+2], u[i] + abs(v[i] - v[i+2]));
    }
    
    cout << u[n-1] << endl;
}


Measured memory_bytes: 1908
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let a = get!([usize]; 3);
    let n= get!(usize);
    let b = get!(usize;n);
    let mut res = vec![vec![false; 3];3];

    for e in b {
        for i in 0..3 {
            for j in 0..3 {
                if a[i][j] == e {
                    res[i][j] =  true;
                }
            }
        }
    }

    let mut cross = true;
    let mut cross2  = true;
    for i in 0..3 {
        if res[i].iter().all(|e|*e) || res.iter().all(|e| e[i]) {
            println!("Yes");
            return;
        }
        cross &= res[i][i];
        cross2 &= res[i][3-i-1];
    }
    if cross || cross2 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

char str[10004][15];

int cnt[4]={0};

int min(int x,int y){return x<y?x:y;}
int max(int x,int y ){return x>y?x:y;}
int main(){
    int n;scanf("%d",&n);
    char f,l;
    int ans=0;
    for(int i=0;i<n;i++){
        scanf("%s",str[i]);
        f=str[i][0];
        for(int j=1;;j++){
            if(str[i][j]=='\0'){
                l=str[i][j-1];break;
            }
            if(str[i][j-1]=='A'&&str[i][j]=='B'){
                ans++;
                //printf("%s\n",str[i] );
            }
        }
        if(f=='B'&&l=='A')cnt[3]++;
        else if(f=='B'&&l!='A')cnt[2]++;
        else if(f!='B'&&l=='A')cnt[1]++;
    }
    //printf("%d %d%d%d\n",ans,cnt[1],cnt[2],cnt[3] );
    ans=ans+min(cnt[1],cnt[2]);
    ans=ans+max(cnt[3]-1,0);
    if(cnt[3]>0&&(cnt[1]>0||cnt[2]>0))ans++;
    //if(cnt[2]>0&&cnt[3]>0)ans++;
    //if (cnt[3]&&cnt[2]&&cnt[1]) ans++;
    printf("%d\n",ans );
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


// a,bの最小公倍数
ll lcm(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll gcd(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}
// MOD
ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}


int main(){


    int n;
    cin >> n;
    ld x[n];
    char u[n][3];
    rep(i,n) cin >> x[i] >> u[i];

    ld ans = 0;
    rep(i,n) {
        if (u[i][0] == 'J') ans += x[i];
        else ans += x[i] * 380000;
    }

    cout << ans << endl;



}



//              g++ -std=c++1z


Measured memory_bytes: 888
n=int(input())
if n%11==0 or n%7==0 or n%4==0:
    print("Yes")
else:
    i=1
    flag=0
    m=1
    while n>0 and m>0:
        m=n-(7*i)
        t=n-m
        #print(t,m)
        if m>0 and n>0 and (t%7==0 or t%4==0 or t%11==0) and (m%4==0 or m%7==0 or m%11==0):
            #print(n,m)
            flag=1
            break
        i+=1
    if flag==1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <list>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <string>
#define N 100005
#define INF (1 << 30)
typedef long long ll;
using namespace std;

vector<int> child[N];   //??±?????????????????°????????????vector????????????
int parent[N];
int GetDepth(int idx)
{
    int ret = 0;
    while (parent[idx] != -1)
    {
        ++ret;
        idx = parent[idx];
    }
    return ret;
}
const char *str[3] = { "root", "internal node", "leaf" };
int main()
{
  //  freopen("in.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
    int n;
    scanf("%d", &n);
    fill(parent, parent + n, -1);
    int id, k, c;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d %d", &id, &k);
        for (int j = 0; j < k; ++j)
        {
            scanf("%d", &c);
            parent[c] = id;
            child[id].push_back(c);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        int depth = GetDepth(i);
        int status;
        if (depth == 0)
            status = 0;
        else if (child[i].size())
        {
            status = 1;
            sort(child[i].begin(), child[i].end());
        }
        else
            status = 2;
        printf("node %d: parent = %d, depth = %d, %s, ", i, parent[i], depth, str[status]);
        printf("[");
        for (int j = 0; j < child[i].size(); ++j)
        {
            if (j)
                printf(", ");
            printf("%d", child[i][j]);
        }
        printf("]\n");
    }
    return 0;
}

Measured memory_bytes: 6664
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;


int main()
{
  fastio
  ll n;
  cin >> n;
  ll ans = n*(n+1)/2;
  ll temp = n/3;
  ans -= 3*temp*(temp+1)/2;
  temp = n/5;
  ans -= 5*temp*(temp+1)/2;
  temp = n/15;
  ans += 15*temp*(temp+1)/2;
  cout << ans;  



  return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
int k, n;
vector<ii> d;

ll solve() {
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  set<int> vari;

  vector<ll> spare;
  vector<int> a[N];
  for (int i = 0; i < k; i++) {
    a[d[i].second].push_back(d[i].first);
  }
  for (int i = 1; i <= n; i++) {
    sort(a[i].begin(), a[i].end());
    for (int j = 0; j < sz(a[i]) - 1; j++) spare.push_back(a[i][j]);
  }
  sort(spare.begin(), spare.end());
  reverse(spare.begin(), spare.end());

  ll sm = 0;
  for (int i = 0; i < k; i++) {
    sm += d[i].first;
    vari.insert(d[i].second);
  }
  ll v = sz(vari);
  ll ans = sm + v * v;
  for (int i = k; i < n; i++) {
    if (vari.count(d[i].second) || spare.empty()) continue;
    sm -= spare.back();
    spare.pop_back();
    vari.insert(d[i].second);
    sm += d[i].first;
    v++;
    ans = max(ans, sm + v * v);
  }
  return ans;
}

int main() {
  scanf("%d%d", &n, &k);
  int u, v;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &u, &v);
    d.push_back({v, u});
  }
  printf("%lld\n", solve());
}



Measured memory_bytes: 8564
# 深さ優先探索
from sys import setrecursionlimit


def genid(a, b):
    if b < a:
        a, b = b, a
    return a * 100000 + b


def paint(currentNode, usedColor, parentNode, edges, colors):
    color = 1
    for childNode in edges[currentNode]:
        if childNode == parentNode:
            continue
        if color == usedColor:
            color += 1
        colors[genid(currentNode, childNode)] = color
        paint(childNode, color, currentNode, edges, colors)
        color += 1


setrecursionlimit(10 ** 6)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

edges = [[] for _ in range(N)]
for a, b in ab:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

colors = {}
paint(0, -1, -1, edges, colors)

print(max(len(e) for e in edges))
for a, b in ab:
    print(colors[genid(a - 1, b - 1)])


Measured memory_bytes: 86564
#include <iostream>

using namespace std;

int main()
{
    int n, i;
    long long l[87];
    l[0] = 2;
    l[1] = 1;
    cin >> n;
    for(i = 2; i <= n; i++)
    {
        l[i] = 0;
        l[i] = l[i-1] + l[i-2];
    }
    cout << l[n]<< endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;

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

using edge=struct {int to,cap,cost,rev;};
using G=vector<vector<edge>>;
const int inf=1<<29;

void add_edge(G &graph,int a,int b,int c,int d){
	graph[a].push_back({b,c,d,int(graph[b].size())});
	graph[b].push_back({a,0,-d,int(graph[a].size()-1)});
}

using ord=tuple<int,int>;
vector<ord> top;

int min_cost_flow(G &graph,int s,int t,int f){
	const int n=graph.size();
	vector<int> h(n,0);

	rep(i,n){
		int v=get<1>(top[i]);
		for(auto &e:graph[v]){
			if(e.cap>0)
				chmin(h[e.to],h[v]+e.cost);
		}
	}

	int res=0;
	while(f){
		vector<int> dist(n,inf),pv(n,0),pe(n,0);
		
		using state=tuple<int,int>;
	    priority_queue<state,vector<state>,greater<state>> q;
	    dist[s]=0,q.push(state(0,s));
	     
	    while(!q.empty()){
	        int c,v;
	        tie(c,v)=q.top();q.pop();
	        if(dist[v]<c) continue;
	        rep(i,graph[v].size()){
				edge &e=graph[v][i];
				if(e.cap>0 && chmin(dist[e.to],dist[v]+e.cost+h[v]-h[e.to])){
					pv[e.to]=v,pe[e.to]=i;
					q.push(state(dist[e.to],e.to));
				}
			}
	    }
 
		if(dist[t]==inf) return -1;

		rep(v,n) h[v]+=dist[v];

		int d=f;
		for(int v=t;v!=s;v=pv[v]) chmin(d,graph[pv[v]][pe[v]].cap);
		f-=d,res+=d*h[t];

		for(int v=t;v!=s;v=pv[v]){
			edge &e=graph[pv[v]][pe[v]];
			e.cap-=d;
			graph[v][e.rev].cap+=d;
		}
	}
	return res;
}

int x[3010],t[3010],p[3010];

int main(void){
	int n,v,xl,xr;
	cin >> n >> v >> xl >> xr;
	
	const int src=2*n,dst=src+1,l=dst+1,r=l+1,all=r+1;
	G graph(all);

	top.push_back(ord(0,src));
	top.push_back(ord(0,l));
	top.push_back(ord(0,r));
	top.push_back(ord(inf,dst));
	
	rep(i,n){
		cin >> x[i] >> t[i] >> p[i];
		top.push_back(ord(t[i],i));
		top.push_back(ord(t[i],n+i));
	}


	sort(_all(top));

	add_edge(graph,src,l,1,0);
	add_edge(graph,src,r,1,0);
	add_edge(graph,src,dst,2,0);
	

	rep(i,n){
		if(abs(xl-x[i])<=v*t[i]) add_edge(graph,l,i,1,0);
		if(abs(xr-x[i])<=v*t[i]) add_edge(graph,r,i,1,0);
		
		add_edge(graph,i,i+n,1,-p[i]);
		add_edge(graph,i,i+n,1,0);
		
		add_edge(graph,i+n,dst,2,0);
	}

	rep(i,n)rep(j,n){
		if(i==j) continue;
		if(abs(x[i]-x[j])<=v*(t[j]-t[i])) add_edge(graph,i+n,j,2,0);
	}

	cout << -min_cost_flow(graph,src,dst,2) << endl;
	return 0;
}

Measured memory_bytes: 241504
n1, n2 = [int(i) for i in input().split()]

d1 = {}
r1 = 0
r2 = 0

for i1 in range(n2):
    t1, t2 = [i for i in input().split()]
    if t1 in d1:
        t3 = d1.get(t1)
        if t3 != 0:
            if t2 == "AC":
                r1 += 1
                r2 += t3
                d1[t1] = 0 
            else:
                d1[t1] =  t3 + 1
    else:
        if t2 == "AC":
            d1[t1] = 0 
            r1 += 1
        else:
            d1[t1] = 1
        
print(str(r1) + " " + str(r2))


Measured memory_bytes: 17176
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
//const ll MOD=(ll)1e9+7;
const ll inf=(ll)1e15;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
ll d[1001];
vector<pair<int,ll> > v[1001];
bool used[1001];

void dfs(int now){
  used[now]=1;
  for(int i=0;i<(int)v[now].size();i++){
    if(!used[v[now][i].fi])dfs(v[now][i].fi);
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int from,to;
    ll cost;
    cin>>from>>to>>cost;
    from--;to--;
    v[from].push_back({to,-cost});
  }
  for(int i=0;i<n;i++){
    d[i]=inf;
  }
  d[0]=0;
  ll temp=0;
  for(int i=0;i<=m+10;i++){
    for(int j=0;j<n;j++){
      int now=j;
      if(d[now]==inf)continue;
      for(int k=0;k<(int)v[now].size();k++){
        if(d[now]+v[now][k].se>=d[v[now][k].fi])continue;
        d[v[now][k].fi]=d[now]+v[now][k].se;
      }
    }
    if(i==m)temp=d[n-1];
  }
  bool circle=0;
  if(temp!=d[n-1])circle=1;
  if(circle){
    print("inf");
  }else{
    print(-d[n-1]);
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






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

using namespace std;

int main(void) {
    int n, a, cnt[9] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a >= 3200) cnt[8]++;
        else cnt[a / 400]++;
    }

    int sum = 0;
    for (int i = 0; i < 8; i++)
        if (cnt[i]) sum++;
    
    cout << max(sum, 1) << " " << sum + cnt[8] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, k;
	cin >> n >> k;

	ll result = 0;
	RANGE(b, k + 1, n + 1) {
		int i;
		for(i = 0; i * b + k <= n; i++) {
		}
		if(i * b > n) {
			result +=
				i * (b - k) - (i * b - n - ((i * b + k) % b == 0 ? 0 : 1));
		} else {
			result += i * (b - k);
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };



vector<pair<double, int> > ans;

vector<pair<double, int> > b;

int main() {
	for ( int i = 0; i < 3; i++ ) {
		vector<pair<double, int> > a( 8 );
		for ( int j = 0; j < 8; j++ ) {
			scanf( "%d %lf", &a[ j ].second, &a[ j ].first );
		}
		sort( a.begin(), a.end() );
		ans.insert( ans.end(), a.begin(), a.begin() + 2 );
		a.erase( a.begin(), a.begin() + 2 );
		b.insert( b.end(), a.begin(), a.end() );
	}
	sort( b.begin(), b.end() );
	ans.insert( ans.end(), b.begin(), b.begin() + 2 );
	for ( int i = 0; i < ans.size(); i++ ) {
		printf( "%d %.2lf\n", ans[ i ].second, ans[ i ].first );
	}
	return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int n = input();
    vector< int > as(n + 1);
    cin >> as;

    i64 vote = 1;
    i64 sum = whole(accumulate, as, 0ll);

    i64 ans = 0;
    range(i, 0, n + 1) {
        ans += vote;
        vote -= as[i];

        if (vote < 0) {
            cout << -1 << endl;
            return;
        }

        sum -= as[i];
        vote = min(2 * vote, sum);
    }

    cout << ans << endl;

}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3768
X,Y=map(int,input().split())
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
if (X+Y)%3!=0:
  print(0)
else:
  n=2*Y-X
  m=2*X-Y
  mod=10**9+7
  if n<0 or m<0:
    print(0)
  else:
    n=int(n/3)
    m=int(m/3)
    print(cmb(n+m,m)%mod)

Measured memory_bytes: 44024
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: step_by_step
 * Time: 2020-02-16 20:55:45
**/

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, L;
    cin >> n >> L;
    deque<pair<ll, ld> > segm;
    ld tot = 0;
    rep(i, 0, n) {
        ll t, v;
        cin >> t >> v;
        if (i > 0) {
            ll rem = v;
            while (rem > 0) {
                if (segm.back().fi <= rem) {
                    rem -= segm.back().fi;
                    tot -= segm.back().se;
                    segm.pop_back();
                } else {
                    tot -= segm.back().se;
                    segm.back().se *= (ld)(segm.back().fi - rem) / segm.back().fi;
                    segm.back().fi -= rem;
                    tot += segm.back().se;
                    break;
                }
            }
        }
        segm.push_front({v, t * v});
        tot += t * v;
        while (sz(segm) >= 2 && segm[0].fi * segm[1].se - segm[0].se * segm[1].fi >= 0) {
            segm[1].fi += segm[0].fi;
            segm[1].se += segm[0].se;
            segm.pop_front();
        }
        cout << (tot / L) << "\n";
    }
    return 0;
}

Measured memory_bytes: 31804
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b){
      if(b<c){
          cout<<"Yes"<<endl;
      }else{
          cout<<"No"<<endl;
      }
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084