akhauriyash/Code-Regression huggingface dataset:
import itertools
import fileinput
 
 
def solve_match(match_matrix):
    size = len(match_matrix)

    combo_list = [0] * (2**size)

    combo_indexes = [[] for _ in range(size + 1)]
    for i in range(2**size):
        count = 0
        n = i
        while (n): 
            count += n & 1
            n >>= 1
        combo_indexes[count].append(i)

    for col in range(size):
        for combo in combo_indexes[col + 1]:
            if col == 0:
                for i in range(size):
                    if (combo & (1 << i)):
                        combo_list[combo] = match_matrix[i][col]
                        break
            else:
                s = 0
                cnt = 0
                for i in range(size):
                    flag = 1 << i
                    if (combo & flag) and match_matrix[i][col] == 1:
                        s += combo_list[combo & (~flag)]
                        cnt += 1
                        if cnt == col + 1:
                            break
                
                combo_list[combo] = s % (10**9 + 7)
    return combo_list[-1]
 
 
inp = fileinput.FileInput()
n = int(inp.readline())
 
arr = []
for _ in range(n):
    arr.append([int(v) for v in inp.readline().split(" ")])
 
print(solve_match(arr))

Measured memory_bytes: 120144
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,K; cin >> N >> K;
    vector<int> A(N);
    vector<ll> x(N,1);
    
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    for(int i=0;i<N-K;i++){
        if(A[i]<A[i+K]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5636
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    ll n,k,c=0,i,j,maxe=0,mine=INFLL;
    cin>>n>>k;
    for(i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x>maxe)
        {
            maxe=x;
        }
        if(y<mine)
        {
            mine=y;
        }
    }
   // cout<<maxe<<" "<<mine<<endl;
    ll y=mine-maxe+1;
    if(y<=0)
    {
        cout<<0<<endl;
    }
    else
        cout<<y<<endl;


}


Measured memory_bytes: 3536
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String input = s.next();
    int score = 0;
    for (int i = 0; i < input.length(); i++) {
      char c = input.charAt(i);
      if (c == 'g' && i % 2 == 1) {
        score++;
      } else if (c == 'p' && i % 2 == 0) {
        score--;
      }
    }
    System.out.println(score);
  }
}


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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  string o,e; cin >> o >> e;

  for(int i=0; i<o.size()+e.size(); ++i) {
    if(i >= o.size() && i >= e.size()) break;
    if(i >= o.size()) {
      cout << e.at(i);
    }
    if(i >= e.size()) {
      cout << o.at(i);
    }
    if(i < o.size() && i < e.size()) {
      cout << o.at(i) << e.at(i);
    }
  }
  cout << '\n';

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll a[16][16];
ll p[1 << 16];
ll dp[1 << 16];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];

    for (int i = 0; i < (1 << n); ++i)
    {
        vi b;
        for (int j = i; j; j -= (j&-j))
            b.push_back(__builtin_ctz(j));

        for (int j = 0; j < b.size(); ++j)
            for (int k = j + 1; k < b.size(); ++k)
                p[i] += a[b[j]][b[k]];
    }

    for (int i = 0; i < (1 << n); ++i)
        for (int s = i; s; s = (s-1)&i)
            dp[i] = max(dp[i], p[s] + dp[i^s]);
    
    cout << dp[(1 << n) - 1];
}


Measured memory_bytes: 1280
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    a = [x for x in map(int,input().split())]
    a.sort()
    print(a[0]+a[1])
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
#include <stdio.h>

int main(){
    int A,B,T;
    int ret=0;
    int i;
    scanf("%d %d %d",&A,&B,&T);
    while(i<=T){
        i=i+A;
        if(i<=T){
            ret = ret + B;
        }
    }
    printf("%d\n",ret);

    return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func getMin(a, min int) int {

  for ; a % min > 0;  {
    a, min = min, a % min
  }
  return min
}

func main() {
	var N int
	fmt.Scan(&N)

	var min int
	fmt.Scan(&min)
	for i := 0; i < N-1; i++ {
		var a int
		fmt.Scan(&a)
      
		if a != min {
          if a > min {
            min = getMin(a, min)
          } else {
            min = getMin(min, a)
          }
          if min == 1 {
            break
          }
        }
	}
	fmt.Println(min)
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long int llg;

const int INF = 1000001000;
#define REP(var, count) for(int var=0; var<count; var++)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

int wars[22][105][105];

int calc(vector<pair<int, int> > &table, int km) {
	int ret = 0;
	int prev = 0;
	for( auto x : table ) {
		if ( km > x.first ) {
			ret += x.second * (x.first - prev);
			prev = x.first;
		} else {
			return ret + x.second * (km - prev);
		}
	}
	throw;
}

bool loop(void) {

	int N, M, C, s, g;
	cin >> N >> M >> C >> s >> g;
	if ( N == 0 ) { return false; }
	
	s--;
	g--;
	
	Fill(wars, INF);
	
	REP(i, M) {
		int x, y, d, c;
		cin >> x >> y >> d >> c;
		
		x--;
		y--;
		c--;
		
		wars[c][x][y] = min(wars[c][x][y], d);
		wars[c][y][x] = min(wars[c][y][x], d);
	}
	
	REP(c, C) {
		REP(x, N) {
			wars[c][x][x] = 0;
		}
	}
	
	vector<pair<int, int> > table[22];
	
	int ppp[22];
	REP(i, C) {
		cin >> ppp[i];
	}
	
	REP(i, C) {
		table[i].push_back( make_pair(0,0) );
		REP(x, ppp[i] - 1) {
			int ky;
			cin >> ky;
			table[i].push_back( make_pair(ky, -1) );
		}
		table[i].push_back( make_pair(INT_MAX, -1) );
		REP(x, ppp[i]) {
			int co;
			cin >> co;
			table[i][x+1].second = co;
		}
	}
	
	// Warshall-Floyd
	REP(c, C) {
		REP(k, N) {
			REP(i, N) {
				REP(j, N) {
					wars[c][i][j] = min(wars[c][i][j], wars[c][i][k]+wars[c][k][j]);
				}
			}
		}
	}
	
	vector<pair<int, pair<int, int>>> lines;
	REP(c, C) {
		REP(i, N) {
			REP(j, N) {
				if ( wars[c][i][j] != INF ) {
					lines.push_back(make_pair(calc(table[c], wars[c][i][j]), make_pair(i,j)));
				}
			}
		}
	}
	
	int bell[105];
	Fill(bell, INF);
	bell[s] = 0;
	
	// Bellman-Ford
	REP(x_0, N-1) {
		bool update = false;
		for ( auto l : lines ) {
			int lst = l.second.first;
			int led = l.second.second;
			
			if ( bell[lst] != INF ) {
				if ( bell[led] > bell[lst] + l.first ) {
					bell[led] = bell[lst] + l.first;
					update = true;
				}
			}
		}
		
		if ( !update ) { break; }
	}
	
	if ( bell[g] == INF ) {
		cout << -1 << endl;
	} else {
		cout << bell[g] << endl;
	}
	
	return true;
}

int main(void) {
	while ( loop() ) {}
}

Measured memory_bytes: 9300
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


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

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

int n,a[110000];vector<int> v(110000), g(110000);
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  v[1] = a[0];g[n] = a[n-1];
  repd(i,1,n)v[i+1] = __gcd(a[i], v[i]);
  for(int i = n-1;i >= 1;i--){
    g[i] = __gcd(g[i+1], a[i-1]);
  }
  int ans = 0;
  repd(i,1,n+1)chmax(ans, __gcd(v[i-1], g[i+1]));
  cout << ans << endl;
  
}


Measured memory_bytes: 2688
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut dest = vec![(0i64, 0i64); n+1];
    let mut t = vec![0i64; n+1];
    let mut ans ="Yes";
    for i in 1..=n {
        t[i] = read::<i64>() - t[i-1];
        dest[i].0 = read::<i64>() - dest[i-1].0;
        dest[i].1 = read::<i64>() - dest[i-1].1;
        let c = t[i] - dest[i].0.abs() - dest[i].1.abs();
        if c >= 0 && c % 2 == 0 {
        } else {
            ans = "No";
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
const ll mod = 1e9 + 7;
const ll N = 2e5 + 200;
const ll INF = 0x3f3f3f;



int main(){
    string a,b;
    int a1,b1;
    cin>>a>>b;
    map<string,int> mp;
    cin>>mp[a]>>mp[b];
    string tmp;
    cin>>tmp;
    mp[tmp]--;
    cout<<mp[a]<<" "<<mp[b]<<endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector <bool> d(n+1);
    d[1]=true;
    for(int i=2;i*i<=n;i++){
        int tmp=i*i;
        while(tmp<=n){
            d[tmp]=true;
            tmp*=i;
        }
    }
    for(int i=n;i>=1;i--){
        if(d[i]){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
vector<int> G[MAX_N];
int A[MAX_N];
int B[MAX_N], C[MAX_N];
bool used[MAX_N];
int K;

void loop(int v) {
	used[v] = true;
	B[K] = v;
	C[K] = A[v]; K++;
	rep(i, 0, sz(G[v])) {
		int n = G[v][i];
		if(!used[n]) loop(n);
	}
}

void solve() {
	cin >> N >> M;
	rep(i, 0, N) {
		cin >> A[i]; A[i]--;
	}
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	int res = 0;
	rep(i, 0, N) {
		if(!used[i]) {
			K = 0;
			loop(i);
			sort(B, B + K);
			sort(C, C + K);
			int ba = 0, ca = 0;
			while(ba < K && ca < K) {
				if(B[ba] == C[ca]) {
					res++;
					ba++; ca++;
				}
				else if(B[ba] < C[ca]) {
					ba++;
				}
				else {
					ca++;
				}
			}
		}
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 12800
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	map<int, int> mp;
	REP(i, n)
	{
		int a;
		cin >> a;
		mp[a]++;
	}
	int ans = 0;
	REPIT(mp)
	{
		if ((*it).first > (*it).second)
			ans += (*it).second;
		else if ((*it).first < (*it).second)
			ans += (*it).second - (*it).first;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

#define int long long

int N;
int ans[1 << 18];
int A[1 << 18];
vector<pair<int, int> > dp[1 << 18];
vector<pair<int, int> > dfs(int bit) {
  if ( dp[bit].size() ) return dp[bit];
  if ( !bit ) return vector<pair<int, int> >{{A[bit], bit}};  
  vector<pair<int, int> > all{{A[bit], bit}};  
  for ( int i = 0; i < N; i++ ) {
    if ( !(bit & (1<<i)) ) continue;
    vector<pair<int, int> > sub = dfs(bit-(1<<i));
    for ( int j = 0; j < (int)sub.size(); j++ ) all.emplace_back(sub[j]);    
  }

  sort(all.begin(), all.end());  
  all.erase(unique(all.begin(), all.end()), all.end());
  sort(all.begin(), all.end(), greater<pair<int, int> >());  
  ans[bit] = all[0].first+all[1].first;  
  return dp[bit] = vector<pair<int, int> >{all[0], all[1]};
}

signed main() {
  cin >> N;
  for ( int i = 0; i < (1<<N); i++ ) cin >> A[i];

  dfs((1<<N)-1);
  for ( int i = 1; i < (1<<N); i++ ) {
    ans[i] = max(ans[i], ans[i-1]);    
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 26240
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N, D;
	cin >> N >> D;

	int d = D * 2 + 1;
	int ret = N / d;
	if (N % d) ret++;

	cout << ret << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool up_min(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool up_max(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_mdvector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_mdvector(int n, Ts ... ts){
        return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
    }

    inline ll bit(int x){
        return 1ll << x;
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    ll N;
    void run();
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef XELMH
    string test_cases = "test_B.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


void solver::run(){
    string S;
    is >> S;
    if(!is) return;
    bool R = true;
    for (auto &&s : S) {
        if(s == 'R' and !R){
            os << "No\n"; return;
        }
        else if(s == 'L' and R){
            os << "No\n"; return;
        }
        R = !R;
    } // end s
    os << "Yes\n";
}


Measured memory_bytes: 256
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N, M = [ int(x) for x in input().split() ]
KS = []
for _i in range(M):
    KS.append([ int(x) for x in input().split() ])
P = [ int(x) for x in input().split() ]

all = [[0,],[1,]]

def add_right(list):
    list0 = [ l + [0,] for l in list ]
    list1 = [ l + [1,] for l in list ]
    list0.extend(list1)
    return list0

for _i in range(N-1):
    all = add_right(all)

ans = 0
d_ans = []
for state in all:
    l_num = -1
    for ks in KS:
        l_num += 1
        switches = ks[1:]
        on = 0
        for s in switches:
            if state[s-1] == 1:
                on += 1
        if on % 2 != P[l_num]:
            break
    else:
        ans += 1

print(ans)


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

vector<int> v[100010];

int fa[100010],mx[100010],dep[100010],n,m,ans;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void dfs(int x)
{
	mx[x]=0;
	for (int i=0,siz=v[x].size();i<siz;i++)
	{
		int t=v[x][i];
		dep[t]=dep[x]+1;dfs(t);
		mx[x]=max(mx[x],mx[t]+1);
	}
	if (mx[x]==m-1&&dep[x]>1) mx[x]=-1,ans++;
}

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++) fa[i]=rd();
	ans=0;
	if (fa[1]!=1) ans++,fa[1]=1;
	for (int i=2;i<=n;i++) v[fa[i]].push_back(i);
	dfs(1);
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

int n; 
int a[maxn];
int cnt[maxn];

int main()
{
	cin>>n;
	REP(i,n) scanf("%d",a+i);
	for(int i=0;i<n;i++) cnt[a[i]]++;
	
	int ans=0;
	for(int i=0;i<=100000-2;i++){
		ans=max(ans,cnt[i]+cnt[i+1]+cnt[i+2]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
program main
    implicit none
    integer n
    integer a, i
    integer warn(2)
    integer, allocatable :: list(:)
    warn = 0
    a = 0
    read*,n
    allocate(list(n))

    read*, list
    do i=1,n
        if (list(i) /= i)then
            a = a + 1
            warn(a) = i
        endif

        if (a>2)then
            print'(a)','NO'
            stop
        endif
    enddo

    if (a == 2 .or. a==0)then
        print'(a)', 'YES'
    else
        print'(a)', 'NO'
    endif
  
end program main

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

using namespace std;

int main()
{
/*string s;
string t;

cin>>s;
cin>>t;
int contador=0;
for(int i=0;i<3;i++)
{
	if(s[i]==t[i])
	{
		contador=contador+1;
	}
	
	
}
cout<<contador;*/
/*string s;
cin>>s;
sort(s.begin(),s.end());

if((s[0]==s[1])&&(s[2]==s[3])&&(s[0]!=s[3]))
{
	cout<<"Yes"<<endl;
	
}
else
{
	cout<<"No"<<endl;
}*/

/*
int n,k;
string s;
cin>>n;
cin>>k;
cin>>s;
tolower(s[k-1]);

cout<<s<<endl;*/
/* string s;

cin>>s;
int contador1=0;
int contador2=0;
int total=s.size();
for(int i=0;i<total;i++)
{
	if(isupper(s[i]))
	{
		contador1=contador1+1;
	}
	else
	{
		contador2=contador2+1;
	}

}


	if(contador1<=contador2)
	{
		
		for(int i=0;i<total;i++)
		{
			
			cout<<char(tolower(s[i]));
		}
	}
	else
	{
		for(int i=0;i<total;i++)
		{
			cout<<char(toupper(s[i]));
		}
	}
*/




/*int n;
string s;
cin>>n;
for(int i=0;i<n;i++)
		{
			cin>>s;
			
			int total=s.size();
			if(total>10)
			{
				cout<<s[0]<<total-2<<s[total-1];
				
				
				
			}
			else
			{
				cout<<s;
			}
			
			
		}*/
		
		int n;
		string s;
		cin>> n;
		cin>>s;
		int total=s.size();
		for(int i=0;i<total;i++)
		{
			s[i]=s[i]+n;
			
		}
		int valor =int('Z');
		int valor2 =int('Z'-'A');
		for(int i=0;i<total;i++)
		{
			if(s[i]>valor)
			{
				s[i]=s[i]-valor2-1;
			}
			
		}
		cout<<s<<endl;
		
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long 
#define MOD 1000000007
 
using namespace std;
 
signed main(){
 
	int a,b,c,d;

	cin >> a>>b>>c>>d;

	vector<int> index;

	index.push_back(a);
	index.push_back(b);
	index.push_back(c);
	index.push_back(d);
	
	sort(index.begin(),index.end());

	if(index[0]!=1){
		cout << "NO"<<endl;
		return 0;
	}

	
	if(index[1]!=4){
		cout << "NO"<<endl;
		return 0;
	}

	
	if(index[2]!=7){
		cout << "NO"<<endl;
		return 0;
	}

	
	if(index[3]!=9){
		cout << "NO"<<endl;
	}
 	
 	cout <<"YES" <<endl;
 	
 	return 0;
	
 
}

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

int a[110];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N);
  reverse(a, a + N);
  int A = 0, B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      A += a[i];
    }
    else {
      B += a[i];
    }
  }
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int x,y,a,b,c;
cin >> x >> y >> a >> b >> c;
vi p(a),q(b),r(c);
rep(i,a) cin >> p[i];
rep(i,b) cin >> q[i];
rep(i,c) cin >> r[i];

sort(all(p), greater<int>());
sort(all(q), greater<int>());

rep(i,x) r.push_back(p[i]);
rep(i,y) r.push_back(q[i]);
sort(all(r), greater<int>());

ll ans = 0;
rep(i,x+y) ans += r[i];
cout << ans << endl;

return 0;
}

Measured memory_bytes: 2552
N = int(input()) # ボールの数
K = int(input()) # Bの位置
xs = [int(i) for i in input().split()] # ボールの位置

half = K / 2

total = 0
for x in xs:
    if x < half:
        total += 2*x
    else:
        total += 2*(K-x)

print(total)


Measured memory_bytes: 9180
from collections import deque

n, m = list(map(int, input().split()))

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

adj = [[] for _ in range(n+1)]

for a, b in ab:
    adj[a].append(b)
    adj[b].append(a)

visited = [False] * (n+1)

d = 0

for i in range(1, n+1):
    if not visited[i]:
        q = deque([i])
        c = 0
        while len(q) > 0:
            v = q.pop()
            c += 1
            visited[v] = True
            for w in adj[v]:
                if not visited[w]:
                    q.append(w)
                    visited[w] = True
        d = max(d, c)

print(d)


Measured memory_bytes: 67928
d,g=map(int,input().split())
pl=[]
cl=[]
for i in range(d):
  p,c=map(int,input().split())
  pl.append(p)
  cl.append(c)
bitlist=[]
for i in range(2**d):
  sub=[]
  num=i
  while num!=0:
    sub.append(num%2)
    num=num//2
  while len(sub)<d:
    sub.append(0)
  bitlist.append(sub)
ans=10000
for i in bitlist:
  l=i
  score=0
  count=0
  for i in range(d):
    if l[i]==1:
      score+=pl[i]*(i+1)*100
      score+=cl[i]
      count+=pl[i]
  if score>g:
    if count<ans:
      ans=count
  else:
    b=False
    for j in range(1,d+1):
      if not b:
        if l[-j]==1:
          pass
        else:
          m=min(pl[-j],(g-score)//((d-j+1)*100))
          score+=m*(d-j+1)*100
          count+=m
          if m==pl[-j]:
            score+=cl[-j]
          if score>g:
            b=True
    if count<ans:
      ans=count    
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,c=1,d=1;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i>0){
      if(a[i]>a[i-1]){
        if(d==1) d=2;
        else if(d==0){
          c++;
          d=1;
        }
      }else if(a[i]<a[i-1]){
        if(d==1) d=0;
        else if(d==2){
          c++;
          d=1;
        }
      }
    }
  }
  cout<<c;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long int

int main(void)
{
    ll n, k, count, m;
    int i, ls, j, lc = 0;
    int pos[200002];
    int fl[200002] = {0};

    scanf("%lld %lld", &n, &k);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &pos[i]);
        fl[i] = 1;
    }

    i = 0;
    count = 0;
    while (fl[i] != 0)
    {
        fl[i] = 0;
        i = pos[i] - 1;
        count++;
        if (count == k)
        {
            printf("%d\n", i + 1);
            return 0;
        }
    }
    //printf("%d %lld\n", i, count); //一度訪れた街に戻るまでの回数
    ls = 0;
    if (i != 0)
    {
        while (pos[ls] != i + 1) //手前の町まで移動
        {
            ls = pos[ls] - 1;
            lc++;
        }
        ls = pos[ls] - 1; //ループの頭の町に移動
        lc++;
    }
    //printf("%d %d\n", ls, lc);

    m = (k - lc) % (count - lc);
    for (i = 0; i < m; i++)
    {
        ls = pos[ls] - 1;
    }
    printf("%d\n", ls + 1);
    return 0;
}

Measured memory_bytes: 3264
N, Q = map(int, input().split())
Ss = input()
LRs = [tuple(map(int, input().split())) for _ in range(Q)]

numAC = 0
noAs, noCs = [0]*N, [0]*N
for i in range(N-1):
    if Ss[i:i+2] == 'AC':
        numAC += 1
        noAs[i] = numAC
        noCs[i+1] = numAC

noAs[-1] = numAC+1
for i in reversed(range(N-1)):
    if noAs[i] == 0:
        noAs[i] = noAs[i+1]
for i in range(1, N):
    if noCs[i] == 0:
        noCs[i] = noCs[i-1]

anss = []
for L, R in LRs:
    L, R = L-1, R-1
    anss.append(max(0, noCs[R]-noAs[L]+1))

print('\n'.join(map(str, anss)))


Measured memory_bytes: 30552
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	vector< int > ans(2, 0);
	rep(k, 2) {
		int s = 0;
		rep(i, N) {
			s += A[i];
			int tmp;
			if (i % 2) {
				tmp = max(0LL, -s + 1);
				ans[k] += tmp;
				s += tmp;
			} else {
				tmp = max(0LL, s + 1);
				ans[k] += tmp;
				s -= tmp;
			}
		}
		rep(i, N) A[i] = -A[i];
	}
	cout << min(ans[0], ans[1]) << endl;
	return 0;
}

Measured memory_bytes: 1024
module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let rec solve es vs (start, xs) (goal, ys) =
  if IntSet.subset (es start) vs then
    if IntSet.subset (es goal) vs then
      start :: xs @ List.rev (goal :: ys)
    else begin
      let goal' = IntSet.choose (IntSet.diff (es goal) vs) in
      solve es (IntSet.add goal' vs) (start, xs) (goal', goal :: ys)
    end
  else begin
    let start' = IntSet.choose (IntSet.diff (es start) vs) in
    solve es (IntSet.add start' vs) (start', start :: xs) (goal, ys)
  end

let () =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let abs = Array.init m (fun _ -> Scanf.scanf "%d %d\n" (fun a b -> a, b)) in
  let es =
    let es = Array.make n IntSet.empty in
    Array.iter (fun (a, b) ->
      es.(a - 1) <- IntSet.add b es.(a - 1);
      es.(b - 1) <- IntSet.add a es.(b - 1)) abs;
    fun i -> es.(i - 1) in
  let (start, goal) = abs.(0) in
  solve es (IntSet.add start (IntSet.singleton goal)) (start, []) (goal, [])
  |> (fun xs ->
      Printf.printf "%d\n" (List.length xs);
      List.iter (Printf.printf "%d ") xs;
      print_newline ())

Measured memory_bytes: 30336
#include <cstdio>
#include <iostream>
#define MAXN 200500
using namespace std;
int a[MAXN];
int h[MAXN];
long long ans[MAXN];
int n;
long long answer;

struct tree{
       int l;
       int r;
       long long maks;
       int left_child;
       int right_child;
}; tree g[4*MAXN];


void create_tree(int v){
     if (g[v].l == g[v].r){
        return;
     }
     g[v].left_child = v*2+1;
     g[v*2+1].l = g[v].l;
     g[v*2+1].r = (g[v].r + g[v].l) / 2;
     create_tree(2*v+1);
     g[v].right_child = v*2+2;
     g[v*2+2].l = (g[v].r + g[v].l) / 2 + 1;
     g[v*2+2].r = g[v].r;
     create_tree(2*v+2);
}


void add_tree(int v, long long k){
     int now = 0;
     while (g[now].l != g[now].r){
           g[now].maks = max(g[now].maks, k);
           if (v >= g[g[now].left_child].l && v <= g[g[now].left_child].r){
              now = g[now].left_child;
           }else{
              now = g[now].right_child;
           }
     }
     g[now].maks = max(g[now].maks, k);
}
long long find_tree(int l, int r, int v){
     //printf("find_tree: l=%i r=%i v=%i\n", l, r, v);
     if (g[v].r < l || r < g[v].l){
        //printf("  find_tree: v=%i returns 0\n", v);
        return 0;
     }
     //if (g[v].l > l && g[v].r < r){
     if (l <= g[v].l && g[v].r <= r) {
        //printf("  find_tree: v=%i returns %i\n", v, g[v].maks);
        return g[v].maks;
     }
     long long tmp = max(find_tree(l, r, g[v].left_child), find_tree(l, r, g[v].right_child));
     //printf("  find_tree: v=%i returns %i\n", v, tmp);
     return tmp;
}


void dbg(int v, long long k){
     if (g[v].l != g[v].r){
        dbg(g[v].right_child, k+1);
     }
     for (int i = 1; i <= k; i++){
         cout << "  ";
     }
     cout << g[v].maks << endl;
     if (g[v].l != g[v].r){
        dbg(g[v].left_child, k+1);
     }
}

int main(){
    cin >> n;
    g[0].l = 1;
    g[0].r = n;
    create_tree(0);
    for (int i = 1; i <= n; i++){
        cin >> h[i];
    }
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    ans[1] = a[1];
    add_tree(h[1], ans[1]);
    for (int i = 2; i <= n; i++){
        //dbg(0, 0);
        //cout << endl;
        //cout << endl;
        /*answer = 0;
        for (int j = 1; j < i; j++){
            if (h[i] > h[j] && answer < ans[j]){
               answer = ans[j];
            }
        }*/
        //printf("find_tree(1, %i - 1) = %i\n", h[i], find_tree(1, h[i] - 1, 0));
        ans[i] = a[i] + find_tree(1, h[i] - 1, 0);


        add_tree(h[i], ans[i]);
    }
    long long answer = 0;
    for (int i = 1; i <= n; i++){
        //cout << ans[i] << ' ';
        if (answer < ans[i]) answer = ans[i];
    }
    //cout << endl;
    cout << answer;
}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  bool ok = true;
  for(int i=0;i<n-1;i++){
    if(A.at(i)==A.at(i+1)){
      ok = false;
    }
  }
  if(ok){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n){
        cin >> a.at(i);
        sum += a.at(i);
    }
    
    ll ans = 0;
    ll b = 1e9 + 7;
    ll c = 0;
    rep(i, n - 1){
        sum -= a.at(i);
        if(sum >= b){
            c = sum % b;
        }
        else{
            c = sum;
        }
        
        ans += a.at(i) * c;
        if(ans >= b){
            ans %= b;
        }
    }
    cout << ans << endl;
    
    return 0;
}
 
 //vector<int> a(3);
 //a.at(0);
 //a.size();
 //vector<vector<int>> a(3, vector<int>(3));
 //uint64_t sum = 0;
 //max(a, b);
 //min(a, b);
 //swap(a, b);
 //sort(vec.begin(), vec.end());  昇順
 //reverse(vec.begin(), vec.end());  降順


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

map<int, int> mp;

int n;
string s;

int main() {
    cin >> s;
    n = s.length();
    cout << (((s[0] == s[n-1]) ^ (n % 2 == 1) ? "First" : "Second")) << endl;
}

Measured memory_bytes: 512
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	int A[N], B[N], C[N];

	rep(i, N)
	{
		cin >> A[i];
	}

	rep(i, N)
	{
		cin >> B[i];
	}

	rep(i, N-1)
	{
		cin >> C[i];
	}


	int total = 0;
	rep(i, N)
	{
		total += B[A[i] - 1];
		if (A[i] + 1 == A[i+1])
		{
			total += C[A[i]-1];
		}
	}

	cout << total << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int a, b;
	cin >> a >> b;
	
	if((a + b) % 2 == 0) {
		cout << (a + b) / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.nextLine());
    
    int max = 0;
    long ans = 0;
    int tem = 0;
    
    for(int i = 0; i < N; ++i) {
      tem = sc.nextInt();
      if(tem > max) {
        max = tem;
      } else if(tem < max) {
        ans += max - tem;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 59656
import sys
sys.setrecursionlimit(200000)

mod = int(1e9+7)

def dfs(i,dp,bad):
    if i == 0:
      return 1
    if i in dp:
      return dp[i]
    dp[i] = 0
    for d in (1,2):
      x = i-d;
      if 0 <= x and x not in bad:
        dp[i] += dfs(x,dp,bad)
        dp[i] %= mod
    return dp[i]

n,m = [int(a) for a in input().split()]
bad = set()
for _ in range(m):
  a = int(input())
  bad.add(a)
print(dfs(n,dict(),bad))


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

#define int long long
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);


main(){
	FIO
	int t;
	t=1;
	while(t--){
		int n;
		cin>>n;
		if(n){
			cout<<0<<endl;
		}
		else{
			cout<<1<<endl;
		}
	}
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int k,x;
    cin >> k >> x;
    if(x-k-1<-1000000){
        int a = -1000000;
        while(a <= x + k - 1){
            cout << a << " ";
            a++;
        }
        return 0;
    }
    else if(x + k - 1 > 1000000){
        int b = x - k + 1;
        while(b <= 1000000){
            cout << b << " ";
            b++;
        }
        return 0;
    }
    else
    {
        int c = x - k + 1;
        while(c <= x + k - 1){
            cout << c << " ";
            c++;
        }
        return 0;
    }
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	bool a[3] = {false, false, false};
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == 'a')
		{
			a[0] = true;
		}
		else if (s[i] == 'b')
		{
			a[1] = true;
		}
		else if (s[i] == 'c')
		{
			a[2] = true;
		}
	}
	cout << ((a[0] && a[1] && a[2]) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256