akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    bool ok = false;

    if(S.size() < T.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for(int i=S.size()-T.size(); i>= 0; i--){
        bool notok = false;
        for(int j=0; j<T.size(); j++){
            if(S.at(j+i) == T.at(j) || S.at(j+i) == '?') continue;
            else {
                notok = true;
                break;
            }
        }

        if(!notok){
            for(int j=0; j<T.size(); j++){
                S.at(j+i) = T.at(j);
            }
            ok = true;
            break;
        }
    }

    if(ok){
        rep(i, S.size()){
            if(S.at(i) == '?') S.at(i) = 'a';
        }
        cout << S << endl;
    }
    else{
        cout << "UNRESTORABLE" << endl;
    }

}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, A, B;
  IN(N,A,B);

  ll ans = 0;
  ans += (N/(A+B))*A;
  N = N-(N/(A+B))*(A+B);
  ans += min(N, A);
  OUT(ans);

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb emplace_back
#define all(c)  c.begin(), c.end()
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define lb "\n"
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define INF 1000000007
#define MAX LLONG_MAX
#define maxn 200001
ll max(ll x,ll y){if(x>y)return x;else return y;}
ll min(ll x,ll y){if(x>y)return y;else return x;}
ll t[4*maxn];
/*void build(int v,int tl,int tr)
{
    if(tl==tr)
        t[v]=a[tl];
    else
    {
        int tm=(tl+tr)/2;
        build(2*v,tl,tm);
        build(2*v+1,tm+1,tr);
        t[v]=max(t[2*v],t[2*v+1]);
    }
}*/
ll query(ll v, ll tl,ll tr, ll l,ll r)
{
    if(l>r)
        return -INF;
    if(l==tl&&r==tr)
        return t[v];
    ll tm=(tl+tr)/2;
    return max(query(2*v,tl,tm,l,min(r,tm)),query(2*v+1,tm+1,tr,max(l,tm+1),r));
}
void update(ll v,ll tl, ll tr, ll pos,ll value)
{
    if(tl==tr)
        t[v]=value;
        else{
    ll tm=(tl+tr)/2;
    if(pos<=tm)
        update(2*v,tl,tm,pos,value);
    else
        update(2*v+1,tm+1,tr,pos,value);
    t[v]=max(t[2*v],t[2*v+1]);}
}
ll dp[200001];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
ll i,j,k,n,m,ans=0;
cin>>n;
vll h(n),a(n);
rep(i,0,n)
cin>>h[i];
rep(i,0,n)
cin>>a[i];
rep(i,0,n)
{
   dp[i]=query(1,0,n,0,h[i]-1)+a[i];
   update(1,0,n,h[i],dp[i]);
}
rep(i,0,n)
ans=max(ans,dp[i]);
cout<<ans;
return 0;
}


Measured memory_bytes: 12100
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	ld dp[n+1][n+1];
	ld p[n+1];
	for(ll i=1;i<=n;i++)
		cin>>p[i];
	dp[0][0]=1.000;
	dp[1][0]=1-p[1];
	for(ll i=2;i<=n;i++)
		dp[i][0]=dp[i-1][0]*(1-p[i]);
	for(ll i=1;i<=n;i++)
		dp[i][i]=p[i]*dp[i-1][i-1];
	for(ll i=2;i<=n;i++)
	{
		for(ll j=1;j<i;j++)
			dp[i][j]=dp[i-1][j]*(1-p[i])+p[i]*dp[i-1][j-1];
	}
	ld ans=0.000000;
	for(ll i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	cout<<fixed<<setprecision(10)<<ans;
	return 0;
}

Measured memory_bytes: 85672
import java.util.*;

class Main{
    Map<Integer, Integer> labelNum = new HashMap<Integer, Integer>();

    void search(Node node, int label){
        LinkedList<Node> open = new LinkedList<Node>();
        Set<Node>       close = new HashSet<Node>();

        open.add(node);

        while(!open.isEmpty()){
            Node n = open.getFirst();

            for(Node i : n.friend){
                if(!close.contains(i)){
                    open.add(i);
                }
            }

            n.label = label;

            open.remove(n);
            close.add(n);
        }

        labelNum.put(label, close.size());
    }

    Main(){
        Scanner SC = new Scanner(System.in);
        int N = Integer.parseInt(SC.next());
        int M = Integer.parseInt(SC.next());
        int K = Integer.parseInt(SC.next());

        Node[] nodes = new Node[N];
        for(int i=0;i<N;i++){
            nodes[i] = new Node();
        }

        for(int i=0;i<M;i++){
            int A = Integer.parseInt(SC.next())-1;
            int B = Integer.parseInt(SC.next())-1;

            nodes[A].addFriend(nodes[B]);
            nodes[B].addFriend(nodes[A]);
        }

        for(int i=0;i<K;i++){
            int C = Integer.parseInt(SC.next())-1;
            int D = Integer.parseInt(SC.next())-1;

            nodes[C].addBlock(nodes[D]);
            nodes[D].addBlock(nodes[C]);
        }

        int label = 0;
        for(int i=0;i<N;i++){
            if(nodes[i].label < 0){
                search(nodes[i], label);
                label++;
            }
        }

        for(int i=0;i<N;i++){
            int R = labelNum.get(nodes[i].label) - 1;
            for(Node j : nodes[i].block){
                if(j.label == nodes[i].label){
                    R--;
                }
            }
            R -= nodes[i].friend.size();
            System.out.print(R + " ");
        }
        System.out.println("");
    }

    public static void main(String[] args){
        Main main = new Main();
    }

    class Node{
        int label = Integer.MIN_VALUE;

        List<Node> friend  = new LinkedList<Node>();
        List<Node> block   = new LinkedList<Node>();

        void addFriend(Node node){
            friend.add(node);
        }

        void addBlock(Node node){
            block.add(node);
        }
    }

}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N;
  cin >> N;
  vector<LL> A(N);
  REP(i,N){
    cin >> A[i];
  }

  vector<LL> num(N, 0);

  vector<LL> ans;

  for (int i = N - 1; i >= 0;--i){
    LL M = i + 1;
    LL sum = 0;
    LL idx = 1;
    while (idx*M-1<N)
    {
      sum += num[idx * M-1];
      idx++;
    }
    if(sum%2!=A[i]){
      num[i] = 1;
      ans.push_back(i);
    }
  }

  cout << ans.size() << endl;

  REP(i,ans.size()){
    if(i!=0){
      cout << " ";
    }
    cout << ans[i] + 1;
  }
  cout << endl;
}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if(x==y){
	cout<<0<<endl;
	}
	else if(y>x){
	cout<<min(y-x,abs(y+x)+1)<<endl;
	}
	else{
	cout<<min(abs(x+y)+1,2+abs(x-y))<<endl;
	}
	return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=INF, tmp=0;
string S;

signed main(){
    cin >> S;
    ans = S.size();
    for(int i=0;i<S.size()-1;i++) {
        if(S[i]!=S[i+1]) {
            ans = min(ans, max(i+1, (int)S.size()-i-1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

X = int(read())

def make_prime(U):
    is_prime = np.zeros(U,np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1
    M = int(U**.5)+1
    for p in range(3,M,2):
        if is_prime[p]:
            is_prime[p*p::p+p] = 0
    return is_prime, is_prime.nonzero()[0]

_, primes = make_prime(10 ** 5 + 10000)

large = primes[primes >= X]
answer = large.min()
print(answer)

Measured memory_bytes: 21708
#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 300001;


struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};


int arr[MAX_N];
vector<vector<int> > v;
int P[101];
int ans = 0;

int check(int m)
{

        rep(i,0,m)
        {
            int x=0;
            rep(j,0,(int)v[i].size())
            {
                x+=arr[v[i][j]-1];
            }
            if(x&1 && !P[i])
                return 0;
            if((x&1) ==0 && P[i])
                return 0;
        }
        return 1;
}

void solve(int idx, int n, int m){
if(idx==n){
    ans+= check(m);
return ;
}
arr[idx]=0;
solve(idx+1,n,m);
arr[idx]=1;
solve(idx+1,n,m);
}

int main()
{
        init_io();
        int n,m;
        cin>>n>>m;
        v.resize(m+1);
        rep(i,0,m){
                int k,x;
                cin>>k;
                rep(j,0,k)
                {
                    cin>>x;
                    v[i].push_back(x);
                }
        }
        rep(i,0,m)
            cin>>P[i];
        solve(0,n,m);
        cout<<ans<<endl;

        return 0;
        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,p,q,x[200001],y,k,h,w,sum,mi,ma,ans,l,r,res;
string s;
typedef vector<int> VI;
typedef vector<pair<int,int> > VP;

int main(){
    cin>>n;
    VI v;
    rep(i,n){
        cin>>x[i];
        v.pb(x[i]);
    }
    sort(all(v));
    rep(i,n){
        if(x[i]<=v[n/2-1])p(v[n/2]);
        else p(v[n/2-1]);
    }
    return 0;
}


Measured memory_bytes: 4724
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define FastIO ios::sync_with_stdio(0)
#define Mod 1000000007
typedef long long ll;
int n;
ll memo[3003][3003],a[3003];
ll dp(int left, int right) {
	if (left > right)
		return 0;

	ll &ret = memo[left][right];
	if (ret != -1)return ret;
	
	if (n%2 == (right-left+1)%2)//taro
		ret = max(a[left] +	 dp(left + 1, right), a[right]+ dp(left, right - 1));
	else //jaro
		ret = min(dp(left + 1, right)-a[left],  dp(left, right - 1)-a[right]);
		
	return ret;

}
int main() {
	FastIO;
#ifndef ONLINE_JUDGE
	//write; read;
#endif 
	memset(memo,-1,sizeof memo);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << dp(0, n - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 70912
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()
	N := len(A)
	matrix := make([]bool, 1e6+1)
	sort.Ints(A)
	count := 0
	for i := 0; i < N; i++ {
		if matrix[A[i]] {
			count++
			continue
		}
		for k := A[i]; k < len(matrix); k += A[i] {
			matrix[k] = true
		}
		if i < N-1 && A[i] == A[i+1] {
			count++
		}
	}
	fmt.Println(N - count)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 11052
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))

C = [[0]*w for _ in range(h)]
x = 0
y = 0
d = (0, 0)
i = 0
j = 0

def printC():
    for _y in range(h):
        print(' '.join(map(str, C[_y])))

while(True):
    nx = x + d[0]
    ny = y + d[1]
    #printC()
    #print()
    #print('(%d, %d) + %s = (%d, %d)' % (x, y, d, nx, ny))
    if d == (1, 0):
        if nx >= w or C[ny][nx] > 0:
            #print('X1')
            d = (0, 1)
            continue
    elif d == (0, 1):
        if ny >= h or C[ny][nx] > 0:
            #print('X2')
            d = (-1, 0)
            continue
    elif d == (-1, 0):
        if nx < 0 or C[ny][nx] > 0:
            #print('X3')
            d = (0, -1)
            continue
    elif d == (0, -1):
        if ny < 0 or C[ny][nx] > 0:
            #print('X4')
            d = (1, 0)
            continue
    elif d == (0, 0):
        d = (1, 0)
    x = nx
    y = ny
    C[y][x] = i+1
    #print(i, j)
    j += 1
    if j >= A[i]:
        i += 1
        if i >= n:
            break
        j = 0
printC()

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

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

    vector<int> h(n);

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

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for(int i = 2; i < n; i++)
    {
        for(int j = 1; i - j >= 0 && j <= k; j++)
        {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[n - 1];

    return 0;
}

Measured memory_bytes: 3956
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[200000];
int x[200000];
bool used[200000];
int ans;
void dfs(int v){
	used[v]=1;
	int sum=0;
	for(auto y:g[v]){
		if(used[y]) continue;
		dfs(y);
		sum+=x[y];
	}
	int m=min(x[v], sum);
	x[v]-=m;
	ans+=m;
}
int main()
{
	int n;
	cin>>n;
	ll a[200000];
	map<ll, int> mp, num;
	for(int i=0; i<n; i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	int c=0;
	for(auto p:mp){
		num[p.first]=c;
		x[c]=p.second;
		c++;
	}
	for(auto p:mp){
		ll v=p.first;
		for(ll i=2; i<(1ll<<32); i*=2){
			auto itr=num.find(i-v);
			if(itr!=num.end()){
				ll v2=itr->first;
				if(v2==v){
					continue;
				}
				g[num[v]].push_back(itr->second);
			}
		}
	}
	for(int i=0; i<c; i++){
		if(!used[i]) dfs(i);
	}
	for(ll i=1; i<(1ll<<31); i*=2){
		auto itr=num.find(i);
		if(itr!=num.end()){
			ans+=(x[itr->second]/2);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 37760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

int main()
{
    ll n; cin >> n;
    vector<ll> v;
    ll x = sqrt(n);

    for (ll i = x; i >= 1; --i) {
        if (n % i == 0) {
            ll tmp = n / i;
            v.push_back(i +  tmp - 2);
        }
    }

    cout << *min_element(v.begin(), v.end()) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define EPS  1e-10//sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)  cerr << #x << " = " << (x) << endl;//debug
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
struct node {
  int id,parent,left,right;

};
typedef struct node *bint;
struct node T[100000];
int D[10000],H[100000];
void depth(int u,int d){
  if(u==-1)return;
  D[u]=d;
  depth(T[u].left,d+1);
  depth(T[u].right,d+1);
}
int hight(int u){
  int h1=0,h2=0;
  if(T[u].left!=-1)h1=hight(T[u].left)+1;
  if(T[u].right!=-1)h2=hight(T[u].right)+1;
  return H[u]=max(h1,h2);
}
int sibling(int u){
  if(T[u].parent==-1)return -1;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=-1)return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=-1)return T[T[u].parent].right;
  return -1;
}
int degree(int u){
  return (T[u].left!=-1?1:0) + (T[u].right!=-1?1:0);
}

int main(){
  int id,left,right,root = -1,n;
  cin>>n;
  rep(i,n)T[i].parent=-1;
  rep(i,n){
    cin>>id>>left>>right;
    T[id].left=left;
    T[id].right=right;
    if(left!=-1)T[left].parent=id;
    if(right!=-1)T[right].parent=id;
  }
  rep(i,n)if(T[i].parent==-1)root=i;
  depth(root,0);
  hight(root);
  rep(i,n){
    cout<<"node "<<i<<": parent = "<<T[i].parent<<", sibling = "<<sibling(i)<<
      ", degree = "<<degree(i)<<", depth = "<<D[i]<<", height = "<<H[i]<<", ";
    if(T[i].parent==-1)cout<<"root"<<endl;
    else if(T[i].left!=-1||T[i].right!=-1)cout<<"internal node"<<endl;
    else cout<<"leaf"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>

const long long int mod = 1000000007;

int main() {

    long long int n;
    std::cin >> n;

    long long int power = 1;

    for(long long int i=1; i<=n; i++){
        power *= i;
        power %= mod;
    }

    std::cout << power << std::endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007

int32_t main()
{
	fastio;
	int i, j, k, n, m, q;
	int x, y, l, r;
	string s, t;
	cin >> s >> t;
	vector <int> v(26, -1);
	
	
	s = '$' + s;

	n = s.size();
	vector <vector <int> > next(n, vector <int> (26, -1));


	for(i=n-1;i>=0;i--){
		for(j=0;j<26;j++)
			next[i][j] = v[j];
		if(i!=0)
			v[s[i]-'a'] = i;
	}
	for(i=0;i<n;i++){
		for(j=0;j<26;j++){
			if(next[i][j]==-1)
				next[i][j] = v[j];
		}
	}

	m = t.size();
	int c, cnt = 0, cur = 0;

	for(i=0;i<m;i++){
		// cout << cur << endl;
		c = t[i]-'a';
		if(next[cur][c]==-1){
			cout << "-1" << endl;
			return 0;
		}
		else{
			if(next[cur][c]<=cur)
				cnt++;
			cur = next[cur][c];
		}
	}
	cout << cnt*(n-1) + (cur) << endl;
	return 0;
}

Measured memory_bytes: 24684
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

      Scanner in = new Scanner(System.in);

      long A = in.nextLong();
      long B = in.nextLong();
      long K = in.nextLong();
      long a = A;
      long cnt = 0;

      // A〜Bの範囲を超えて探索しないように
      if(K > B - A) {
          K = B-A+1;
      }
      // 小さい方から出力
      while(cnt < K) {
          System.out.println(a);
          a++;
          cnt++;
      }
      // 大きい方から出力
      long cnt2 = 0;
      long b = B - K + 1;
      while(cnt2 < K) {
          if(b >= a) {
              System.out.println(b);
          }
          cnt2++;
          b++;
      }

    }

}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
	cin >> a >> b >> c >> d;
	int x=c-a,y=d-b;
	cout << c-y << " " << d+x << " " << a-y << " " << b+x <<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Scc Puzzle
            var line = ReadLine();
            long s = line[0]; //'s'型ピース
            long c = line[1]; //'c'型ピース

            if (c >= s * 2)
            {
                Console.WriteLine((c - s * 2) / 4 + s);
            }
            else
            {
                Console.WriteLine(c / 2);
            }                       
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => long.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 11348
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const ll inf = 1e9 + 7;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

int n, m, q;
int a[N], b[N];
int ans, mn1 = inf, mn2 = inf;

int main(){
    Speedforce
    //fop("", "")
    cin >> n >> m >> q;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
        mn1 = min(mn1, a[i]);
    }
    for(int i = 1;i <= m;i ++){
        cin >> b[i];
        mn2 = min(mn2, b[i]);
    }
    //for(int )
    ans = mn1 + mn2;
    for(int i = 1;i <= q;i ++){
        int x, y, c;
        cin >> x >> y >> c;
        //cout << a[x] << " " << b[y] << " " << c << endl;
        ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans;
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int x;cin>>x;

  rep(i,1,x+1){
    int num=i*(i+1)/2;
    if(num>=x){out(i);return 0;}
  }


  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
const int N=2000010;
const int mod=1e9+7;
int x[10],y[10],fact[N+5],inv[N+5];
ll ans;
int C(int x,int y){
    return 1ll*fact[x+y]*inv[x]%mod*inv[y]%mod;
}
int F(int x1,int y1,int x2,int y2){
    return (1ll*C(x2+1,y2+1)+1ll*C(x1,y1)-1ll*C(x1,y2+1)-1ll*C(x2+1,y1)+mod+mod)%mod;
}
int main()
{
	for(int i=1;i<=6;i++)
        scanf("%d",&x[i]);
	for(int i=1;i<=6;i++)
        scanf("%d",&y[i]);
	fact[0]=1;
	for(int i=1;i<=N;i++)
        fact[i]=1ll*fact[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<=N;i++)
        inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;
	for(int i=1;i<=N;i++)
        inv[i]=1ll*inv[i]*inv[i-1]%mod;
	for(int i=x[3];i<=x[4];i++)
		ans+=1ll*(mod-y[3]-i)%mod*F(i-x[2],y[3]-1-y[2],i-x[1],y[3]-1-y[1])%mod*F(x[5]-i,y[5]-y[3],x[6]-i,y[6]-y[3])%mod,ans%=mod;
	for(int i=x[3];i<=x[4];i++)
		ans+=1ll*(i+y[4]+1)%mod*F(i-x[2],y[4]-y[2],i-x[1],y[4]-y[1])%mod*F(x[5]-i,y[5]-y[4]-1,x[6]-i,y[6]-y[4]-1)%mod,ans%=mod;
	for(int i=y[3];i<=y[4];i++)
		ans+=1ll*(mod-x[3]-i)%mod*F(i-y[2],x[3]-1-x[2],i-y[1],x[3]-1-x[1])%mod*F(y[5]-i,x[5]-x[3],y[6]-i,x[6]-x[3])%mod,ans%=mod;
	for(int i=y[3];i<=y[4];i++)
		ans+=1ll*(i+x[4]+1)%mod*F(i-y[2],x[4]-x[2],i-y[1],x[4]-x[1])%mod*F(y[5]-i,x[5]-x[4]-1,y[6]-i,x[6]-x[4]-1)%mod,ans%=mod;
	printf("%lld\n",ans);
}


Measured memory_bytes: 15744
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int d, n;
	cin >> d >> n;
	/*if (d == 0)
	{
		if (n == 100) cout << 101 << endl;
		else cout << n << endl;
		
	}
	else if (d == 1)
	{
		if (n == 100) cout << 10100 << endl;
		else cout << 100 * n << endl;
	}
	else
	{
		if (n == 100) cout << 1010000 << endl;
		else cout << 10000 * n << endl;
	}*/
	if (n <= 99)
	{
		cout << n * pow(100, d) << endl;
	}
	else
	{
		cout << (int)(n * pow(100, d) + pow(100, d)) << endl;
	}
}

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

using namespace std;

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

    if(A >= K){
        cout << A-K << " " << B << endl;
    }else if(B >= K-A){
        cout << 0 << " " << B-(K-A) << endl;
    }else{
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

if a >= c:
  while k >= 1:
    c *= 2
    k -= 1
    if c > a:
      break

if a >= b:
  while k >= 1:
    b *= 2
    k -= 1
    if b > a:
      break
if b >= c:
  while k >= 1:
    c *= 2
    k -= 1
    if c > b:
      break

if c > b > a and k >= 0:
  print('Yes')
else:
  print('No')
    

Measured memory_bytes: 9184
#include <stdio.h>

int main() {

  int m, f, r, sum;

  while(1){
    scanf("%d %d %d", &m, &f, &r);

    if ((m == -1) && (f == -1) && (r == -1))
      break;
    sum = m + f;
    if ((m == -1) || (f == -1))
      printf("F\n");
    else if (sum >= 80)
      printf("A\n");
    else if ((sum >= 65) && (sum < 80))
      printf("B\n");
    else if ((sum >= 50) && (sum < 65))
      printf("C\n");
    else if ((sum >= 30) && (sum < 50))
      if (r >= 50)
	printf("C\n");
      else
	printf("D\n");
    else if (sum < 30)
      printf("F\n");
  }

  return 0;

}

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

const int INF=100000000;
int main() {
  int n,m,w1,w2;
  cin >>n>>m;
  vector<int> ro[100003];
  rep(i,m){
    cin >>w1>>w2;
    w1--;w2--;
    ro[w1].push_back(w2);
    ro[w2].push_back(w1);
  }
  queue<int> q;
  vector<int> acc(n,INF);
  vector<int> pre(n,-1);
  acc[0]=0;
  q.push(0);
  while(!q.empty()){
    int v=q.front();
    q.pop();
    for(int u:ro[v]){
      if(acc[u]!=INF) continue;
      acc[u]=acc[v]+1;
      pre[u]=v;
      q.push(u);
    }
  }
  cout <<"Yes"<<endl;
  for(int i=1;i<n;i++){
    cout << pre[i]+1<<endl;
  }
}


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

using namespace std;


int main() {
    int h, w;
    char field[60][60] = {""};
    bool flag = true;
    cin >> h >> w;
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            cin >> field[i][j];
        }
    }
    for (int k = 1; k <= h; ++k) {
        for (int i = 1; i <= w; ++i) {
            if(field[k][i] == '#' && field[k+1][i] != '#' && field[k-1][i] != '#' && field[k][i+1] != '#' && field[k][i-1] != '#') {
                flag = false;
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ANextAlphabet solver = new ANextAlphabet();
        solver.solve(1, in, out);
        out.close();
    }

    static class ANextAlphabet {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            w.println((char) (s.next().charAt(0) + 1));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

int main() {
  int N,A,B; cin >>N >>A >>B;
  string S; cin >>S;
  int a=1;
  int b=1;
  rep(i,0,N) {
    if (S[i]=='a') {
      if (a<=A+B) {
        cout <<"Yes" <<endl;
        a++;
      } else {
        cout <<"No" <<endl;
      }
    } else if (S[i]=='b') {
      if (a<=A+B && b<=B) {
        cout <<"Yes" <<endl;
        a++;
        b++;
      } else {
        cout <<"No" <<endl;
      }
    } else {
      cout <<"No" <<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3760
#include <stdio.h>

int main (void) {

int S;

scanf("%d", &S);

printf("%d:%d:%d\n", S / 3600, (S - (S / 3600 * 3600)) / 60, S - (S / 3600 * 3600 + (S - S / 3600 * 3600) / 60 * 60));

return 0;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				ans += __gcd(__gcd(i, j), k);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b == c){
    cout << "No" << endl;
  }else if((a == b && b !=c )|| (a == c && a !=b )|| (b == c &&  c!=a)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int n,a;
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d",&a);
		if (a%2==0){
			if (a%3!=0&&a%5!=0){
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const ll Inf = 1e18;

vector <vector <ll>> calc(vector <int> a, vector <int> p) {
  int n = a.size();
  vector <vector <ll>> best(1 << n, vector <ll> (n + 1));
  for (int mask = 0; mask < (1 << n); ++mask) {
    vector <int> gs;
    for (int i = 0; i < n; ++i) {
      if (mask & (1 << i)) {
        gs.push_back(i);
      }
    }
    sort(gs.begin(), gs.end(), [&] (int i, int j) {
      return a[i] < a[j];
    });
    int k = gs.size();
    vector <vector <ll>> go(k, vector <ll> (k + 1));
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < k; ++j) {
        go[i][j + 1] = (ll)p[gs[j]] * abs(a[gs[i]] - a[gs[j]]);
      }
    } 
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < k; ++j) {
        go[i][j + 1] += go[i][j];
      }
    }
    vector <vector <vector <ll>>> cost(k, vector <vector <ll>> (k, vector <ll> (2, Inf)));
    for (int who = 0; who < k; ++who) {
      for (int l = 0; l < k; ++l) {
        for (int r = l; r < k; ++r) {
          cost[l][r][1] = min(cost[l][r][1], go[who][r + 1] - go[who][l]);
        }
      }
    }   
    for (int l = 0; l < k; ++l) {
      for (int r = l; r < k; ++r) {
        ll sum = 0;
        for (int i = l; i <= r; ++i) {
          sum += (ll)p[gs[i]] * abs(a[gs[i]]);
        }
        cost[l][r][0] = sum;
      }
    }

    vector <vector <ll>> dp(k + 1, vector <ll> (k + 1, Inf));
    dp[0][0] = 0;
    for (int i = 0; i < k; ++i) {
      for (int c = 0; c <= k; ++c) {
        for (int j = i; j < k; ++j) {
          dp[j + 1][c] = min(dp[j + 1][c], dp[i][c] + cost[i][j][0]);
          if (c + 1 <= k) {
            dp[j + 1][c + 1] = min(dp[j + 1][c + 1], dp[i][c] + cost[i][j][1]);
          }
        }
      }
    }
    for (int i = 0; i <= k; ++i) {
      best[mask][i] = dp[k][i];
    }
  }
  return best;
} 

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> x(n), y(n), p(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> p[i];
  }
  vector <ll> ans(n + 1, Inf);
  auto f = calc(x, p);
  auto s = calc(y, p);

  for (int mask_f = 0; mask_f < (1 << n); ++mask_f) {
    int mask_s = ((1 << n) - 1) ^ mask_f;
    for (int cnt_l = 0; cnt_l <= n; ++cnt_l) {
      for (int cnt_r = 0; cnt_r + cnt_l <= n; ++cnt_r) {
        ans[cnt_l + cnt_r] = min(ans[cnt_l + cnt_r], f[mask_f][cnt_l] + s[mask_s][cnt_r]); 
      }
    }
  }
  for (int i = 0; i <= n; ++i) {
    cout << ans[i] << '\n';
  }
}



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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 510;

struct Number{
	int o, x;

	bool operator < (const Number& A) const{
		return x < A.x;
	}
}A[N];

int n;
int P[N * N];

int main(){
	
	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &A[i].x), A[i].o = i;
	sort(A + 1, A + n + 1);

	int pos = 1;
	For(i, 1, n){
		P[A[i].x] = A[i].o;
		For(j, 1, A[i].o - 1){
			while(P[pos]) ++pos;
			P[pos] = A[i].o;
		}

		if(pos > A[i].x){
			puts("No");
			return 0;
		}
	}

	pos = n * n;
	Forr(i, n, 1){
		For(j, A[i].o + 1, n){
			while(P[pos]) --pos;
			P[pos] = A[i].o;
		}

		if(pos < A[i].x){
			puts("No");
			return 0;
		}
	}

	puts("Yes");
	For(i, 1, n * n) printf("%d%c", P[i], i == n * n ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 2176
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n, m, x = map(int, readline().split())
ca = [list(map(int, readline().split())) for _ in range(n)]
ans = float('inf')
for bit in product([0, 1], repeat=n):
    cnt = 0
    memo = [0] * m
    for i in range(n):
        if bit[i] == 1:
            cnt += ca[i][0]
            for j in range(m):
                memo[j] += ca[i][j + 1]
    for j in range(m):
        if memo[j] < x:
            break
    else:
        ans = min(ans, cnt)
if ans == float('inf'):
    ans = -1
print(ans)


Measured memory_bytes: 68348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}


int main(){
	int n,m; cin >> n >> m;
	int l2,rr;
	l2 = 0; rr = n;
	int l,r;
	Rep(m){
		cin >> l >> r;
		l2 = max(l,l2);
		rr = min(r,rr);
	}
	cout << max(0, rr-l2+1)<< endl;
}

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

int main(){
  int k, size;
  string s;
  
  cin >> k;
  cin >> s;
  size = s.length();
  
  if(size <= k) cout << s << endl;
  else cout << s.erase(k) << "..." << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
   int H , W ;
   cin >> H >> W ;
   int h , w ;
   cin >> h >> w ;
   cout << (H-h)*(W-w);

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 256
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, q;
	cin >> n >> q;
	int a[n];
	for(int i = 0; i < n; i ++) {
		cin >> a[i];
	}
	Query queries[q]; 
	for(int i = 0; i < q; i ++) {
		int l, r;
		cin >> l >> r;
		queries[i].l = l-1;
		queries[i].r = r-1;
		queries[i].idx = i;
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 19340
H,W = map(int,input().split())
maze = []
for i in range(H):
  s = input()
  maze.append(s)
def distance(maze,H,W):
  wall = []
  for i in range(H):
    w = [-1]
    for j in range(W):
      if maze[i][j] == '#':
        w.append(j)
    w.append(W)
    wall.append(w)

  wd = [[0]*W for _ in range(H)]
  for i in range(H):
    w1 = 0
    for j in range(W):
      if maze[i][j] == '#':
        w1 = min(w1+1,len(wall[i])-1)
        continue
      wd[i][j] = j-wall[i][w1]-1+wall[i][w1+1]-j-1

  return wd

wd = distance(maze,H,W)
maze = [list(x) for x in zip(*maze)]
hd = distance(maze,W,H)
max_dist = 1

for i in range(H):
  for j in range(W):
    max_dist = max(max_dist,wd[i][j] + hd[j][i]+1)
print(max_dist)

Measured memory_bytes: 297860