akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>

using namespace std;

void solve() {
    int n; cin >> n;
	int cur{0}, res{0};
	while (cur < n) {
	    cur++;
	    if (cur == 10 || cur == 1000 || cur == 100000) {
	        cur *= 10;
	        if (cur <= n) {
	            res++;
	        }
	        continue;
	    }
	    res++;
	}
	
	cout << res << endl;    
}

int main() {
	solve();
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    int k, n, ans = 0;
    cin>>k>>n;
    VI a(n);
    REP(i,n) cin>>a[i];
    ans = a[0] + k - a[n-1];
    REP(i,n-1) {
        CHMAX(ans, a[i+1] - a[i]);
    }
    cout<<k-ans<<endl;

    return 0;
}


Measured memory_bytes: 4048
#include <cstdio>
#include <algorithm>
#include <vector>

int longest[100005];

std::vector<int> edges[100005];

void dfs(int node){
  if(longest[node]) return;
  for(int next:edges[node]){
    dfs(next);
    longest[node]=std::max(longest[node],longest[next]);
  }
  longest[node]++;
}

int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    int X,Y;
    scanf("%d %d",&X,&Y);
    X--,Y--;
    edges[X].push_back(Y);
  }
  for(int i=0;i<N;i++){
    dfs(i);
  }
  printf("%d\n",*std::max_element(longest,longest+N)-1);
  return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>

int paper[10][10] = {0};

int loccheck(int x, int y)
{
    if (x >= 0 && x <= 9) if(y >= 0 && y <= 9) return 1;
    return 0;
}

void inksim(int x, int y, int s)
{
    int i, j;
    if (loccheck(x, y)) paper[x][y]++;

    for(i = 1; i <= 2; i++){
        if(s == 1 || s == 2)    if (i == 2)  break;
        
        if (loccheck(x, y + i)) paper[x][y + i]++;
        if (loccheck(x, y - i)) paper[x][y - i]++;
        if (loccheck(x + i, y)) paper[x + i][y]++;
        if (loccheck(x - i, y)) paper[x - i][y]++;
    }

    if (s == 1) return ;

    for(i = -1; i <= 1; i += 2){
        for(j = -1; j <= 1; j += 2){
            if (loccheck(x + i, y + j)) paper[x + i][y + j]++;
        }
    }
    return ;
}

int main(void)
{
    int i, j;
    int x, y, s;
    int max, clean;

    while(scanf("%d,%d,%d", &x, &y, &s) == 3){

        inksim(x, y, s);
        // for (i = 0; i < 10; i++){
        //     for (j = 0; j < 10; j++){
        //         printf("%d  ", paper[i][j]);
        //     }
        //     putchar('\n');
        // }
    }

    max = 0;
    clean = 0;
    for (i = 0; i < 10; i++){
        for (j = 0; j < 10; j++){
            if(paper[i][j] == 0) clean++;
            if(paper[i][j] > max) max = paper[i][j];
        }

    }
    printf("%d\n%d\n", clean, max);
    return (0);
}



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

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

    for(int i = 0; i * 10000 <= Y; ++i){
        for(int j = 0; i * 10000 + j * 5000 <= Y; ++j){
            int k =  (Y - (i * 10000 + j * 5000)) / 1000;
            if(i + j + k == N){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
// 4_abc142_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

long long gcd(long long a, long long b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

bool is_prime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);

    int ans = 0;
    for(int i = 2; i <= sqrt(c); i++){
        if(!is_prime(i)) continue;

        if(c % i == 0){
            ans++;
            while(c % i == 0){
                c /= i;
            }
        }
    }
    if(is_prime(c)) ans++;
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int n,m,a[50] = {0},b[50] = {0};

	int cnt[50]= {0};

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

	for(int i = 0; i < m; i++)
	{
		cnt[a[i]-1]++;
		cnt[b[i]-1]++;
	}

	for(int i = 0; i < n; i++)
	{
		cout << cnt[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 1e9 + 7;


int main(){
   int n, m;
   cin >> n >> m;
   Graph G(n);
   rep(i, m){
      int a, b;
      cin >> a >> b;
      a--;b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }
   vector<int> al(n);
   rep(i, n)al[i] = i;
   int res = 0;
   do{
      if(al[0] != 0)continue;

     
      bool f = true;
      rep(i, n - 1){
         int v = al[i];
         bool g = false;
         for(int nv : G[v]){
            if(nv == al[i + 1])g = true;
         }
         if(!g)f = false;
      }
      if(f)res++;
   }while(next_permutation(ALL(al)));
   cout << res << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    long a[3*N];
    for(int i=0;i<3*N;i++) cin >> a[i];
    sort(a, a+3*N, greater<int>());
    long cnt=0;
    for(int i=0;i<N;i++) cnt += a[2*i+1];
    cout << cnt <<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    rep(i, 0, n){
        cin >> a[i];
        mp[a[i]]++;
    }
    int ans = 0;
    for(auto i : mp){
        if(i.second > i.first) ans += i.second - i.first;
        else if(i.second < i.first) ans += i.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7040
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int d,i,j,k;
  cin >> d;
  double a[1000]={},b[1000]={};
  for(i=0;i<d;i++) cin >> a[i];
  for(i=0;i<d;i++) cin >> b[i];
  double o1=0,o2=0,o3=0,oe=0;
  for(i=0;i<d;i++){
    o1+=fabs(a[i]-b[i]);
    o2+=fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    o3+=fabs(a[i]-b[i])*fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    oe=max(oe,fabs(a[i]-b[i]));
  }
  printf("%.6f\n",o1);
  printf("%.6f\n",sqrt(o2));
  printf("%.6f\n",pow(o3,1.0/3.0));
  printf("%.6f\n",oe);
  return 0;
}


Measured memory_bytes: 3400
a,b=map(str,input().split())
xa=int(a)
xb=int(b)
n=xb-xa
ans=0
for i in range(n+1):
    if a[0]==a[4]and a[1]==a[3]:
        ans+=1
    xa+=1
    a=str(xa)
print(ans)

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

int main(void){
    // Here your code !
    int timeS;
    int second;
    int minute;
    int hour = timeS / 60 / 60;
    
    cin >> timeS;
        
    second = timeS % 60;
    minute = timeS / 60 % 60;
    hour = timeS / 60 / 60;
    
    std::cout << hour << ":" << minute << ":" << second << std::endl;
    
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int i = 0; i < n; i++ ){ cout << x[i] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

string s;

set<char> ss;

bool find( char c ){
  return ss.find( c ) != ss.end();
}

int main(){

  s = stin();
  YYS( w , s ){
    ss.insert( w );
  }

  if( find( 'N' ) == find( 'S' ) and find( 'W' ) == find( 'E' ) ){
    puts( "Yes" );
  } else {
    puts( "No" );
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    int a=0,b=0;
    int answer=0;
    int op;
    
    while(1){
        scanf("%d %c %d", &a, &op, &b);//読み込み
        
        if(op == '+'){
            answer = a + b;//＋のとき和
        }else if(op == '-'){
            answer = a - b;//ーのとき差
        }else if(op == '*'){
            answer = a * b;//＊のとき積
        }else if(op == '/'){
            answer = a / b;// /のとき商
        }else{
            break;
        }
        
        printf("%d\n",answer);

    }

    return 0;
}


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

int N, M, Q;
vector<vector<int>> A;

void f(vector<int> v, int n) {
  if (n == N) {
    A.push_back(v);
    return;
  }
  int mx = (v.size()) ? *max_element(v.begin(), v.end()) : 1;
  for (int i = mx; i <= M; i++) {
    vector<int> v2;
    v2 = v;
    v2.push_back(i);
    f(v2, n + 1);
  }
}

int main() {
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (int i = 0; i < Q; i++) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  vector<int> tmp;
  f(tmp, 0);
  int mx = 0;
  for (auto au : A) {
    int sum = 0;
    for (int i = 0; i < Q; i++) {
      if (au.at(b.at(i) - 1) - au.at(a.at(i) - 1) == c.at(i)) sum += d.at(i);
    }
    mx = max(mx, sum);  
  }

  cout << mx << "\n";
}

Measured memory_bytes: 9836
class SegmentTree:  # 0-indexed
    def __init__(self, array, operation=min, identity=10**30):
        self.identity = identity
        self.n = len(array)
        self.N = 1 << (self.n - 1).bit_length()
        self.tree = [self.identity] * 2 * self.N
        self.opr = operation
        for i in range(self.n):
            self.tree[i+self.N-1] = array[i]
        for i in range(self.N-2, -1, -1):
            self.tree[i] = self.opr(self.tree[2*i+1], self.tree[2*i+2])

    def value(self, k):
        return self.tree[k+self.N-1]

    def update(self, k, x):
        k += self.N-1
        self.tree[k] = x
        while k+1:
            k = (k-1)//2
            self.tree[k] = self.opr(self.tree[k*2+1], self.tree[k*2+2])

    def query(self, p, q):  # [p,q)
        if q <= p:
            print("Oops!  That was no valid number.  Try again...")
            exit()
        p += self.N-1
        q += self.N-2
        res = self.identity
        while q-p > 1:
            if p & 1 == 0:
                res = self.opr(res, self.tree[p])
            if q & 1 == 1:
                res = self.opr(res, self.tree[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.opr(res, self.tree[p])
        else:
            res = self.opr(self.opr(res, self.tree[p]), self.tree[q])
        return res


n = int(input())
h = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

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

ST = SegmentTree(dp, max, -1)

for i in range(n):
    ST.update(h[i], a[i] + ST.query(0, h[i]))

print(ST.query(0, n+1))


Measured memory_bytes: 119444
from bisect import bisect
from itertools import accumulate

n = int(input())
a_list = sorted(map(int, input().split()))
b_list = sorted(map(int, input().split()))
c_list = sorted(map(int, input().split()))

b_c_table_ = list(accumulate(reversed(tuple(n - bisect(c_list, b) for b in b_list))))
b_c_table_.reverse()
b_c_table_ += [0]

print(sum(b_c_table_[bisect(b_list, a)] for a in a_list))


Measured memory_bytes: 24736
#include <bits/stdc++.h>
using namespace std;
int arr2[12];
int main(){
	int n, m, x, ans=1e8;
	cin >> n >> m >> x;
	int arr[n][m+1];
	for(int i=0; i<n; ++i){
		for(int j=0; j<m+1; ++j){
			cin >> arr[i][j];
		}
	}
	int cost=0;
	for(int i=0; i<=(1<<n)-1; ++i){
		for(int j=0; j<n; ++j){
			if((i>>j)&1==1){
				for(int k=0; k<m+1; ++k){
					if(k==0){
						cost+=arr[j][k];
						continue;
					}
					arr2[k-1]+=arr[j][k];
				}
			}
		}
		bool check = true;
		for(int j=0; j<m; ++j){
			if(arr2[j]<x){
				check = false;
			}
			arr2[j] = 0;
		}
		if(check){
			ans = min(ans, cost);
		}
		cost = 0;
	}
	if(ans == 1e8){
		cout << -1;
	}
	else{
		cout << ans;
	}
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
int main(){
    int N,M,p;
    std::cin >> N >> M >> p;
    std::vector<int> d;
    for(int i = 0; i < M; ++i){
        int a;
        std::cin>>a;
        a -= p;
        if(a < 0)a += N;
        d.push_back(a);
    }
    d.push_back(0);
    M = d.size();
    std::sort(d.begin(), d.end());
    int ans = 1e9;
    for(int i = 0; i < M; ++i){
        //i+1 ??¨ i+2??????????????????????????????0???????§???????,??¨????????????
        int bet = abs(d[0] - d[(i + 1) % M]);
        int bet2 = N - abs((d[0] - d[(i + 2) % M]));
        if(bet2 == N)bet2 = 0;
        if(bet > bet2)std::swap(bet, bet2);
        ans = std::min(ans, bet * 2 + bet2);
    }
    std::cout << ans * 100 << std::endl;
    return 0;
}

Measured memory_bytes: 1324
#include<cstdio>
#include<iostream>
#include<string>
struct Node {
    int id;
    Node* parent;
    Node* l_child;
    Node* r_child;
    
    Node(int i,Node* p,Node* l,Node* r){
        id = i;
        parent = p;
        l_child = l;
        r_child = r;
    }
    
};

class RootedTree {
    Node** Tree;
    Node* nil =NULL;
    Node* cur;
    
    public :RootedTree(int c){
        Tree = new Node*[c];
        for(int i = 0;i < c;++i) Tree[i] = new Node(i,nil,nil,nil);
    }

    void ChangeCurNode(int id){
	    cur = Tree[id];
    }

    void AddChild(int l_c,int r_c) {
        if(l_c != -1){
            Tree[l_c] -> parent = cur;
            cur->l_child = Tree[l_c];
        }
        if(r_c != -1){
            Tree[r_c] -> parent = cur;
            cur->r_child = Tree[r_c];
        }
	}
	   
    void PreOrder(int id){
        printf(" %d",id);
        if(Tree[id] -> l_child != nil){
            PreOrder(Tree[id] -> l_child -> id);
        }
        if(Tree[id] -> r_child != nil){
            PreOrder(Tree[id] -> r_child -> id);
        }
    }
    
    void InOrder(int id){
        if(Tree[id] -> l_child != nil){
            InOrder(Tree[id] -> l_child -> id);
        }
        printf(" %d",id);
        if(Tree[id] -> r_child != nil){
            InOrder(Tree[id] -> r_child -> id);
        }
    }
    
     void PostOrder(int id){
        if(Tree[id] -> l_child != nil){
            PostOrder(Tree[id] -> l_child -> id);
        }
        if(Tree[id] -> r_child != nil){
            PostOrder(Tree[id] -> r_child -> id);
        }
        printf(" %d",id);
    }
    int GetRoot(int c){
        for(int i = 0;i < c;++i){
            if(Tree[i] -> parent == nil) return i;
        }
        
        return -1;
    }

};


int main(){
    int n,id,l_c,r_c;
    RootedTree *rt;
    scanf("%d",&n);
    rt = new RootedTree(n);
    for(int i = 0;i < n;++i){
        scanf("%d %d %d",&id,&l_c,&r_c);
        rt -> ChangeCurNode(id);
        rt -> AddChild(l_c,r_c);
    }
    
    printf("Preorder\n");
    rt -> PreOrder(rt -> GetRoot(n));
    printf("\nInorder\n");
    rt -> InOrder(rt -> GetRoot(n));
    printf("\nPostorder\n");
    rt -> PostOrder(rt -> GetRoot(n));
    printf("\n");
    
}


Measured memory_bytes: 3204
#include<stdio.h>

int main(void){
    
    int a,b,d,r;
    double f;
    
    scanf("%d %d",&a,&b);
    
    d=a/b;
    r=a%b;
    f=a*1.0/b;
    
    printf("%d %d %f\n",d,r,f);
    
    return 0;
}


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

int main() {
 char B;
 cin >> B;
 string enki = "ACGT";
 if(enki[0] == B){
    cout << "T" << endl;
 }
 else if(enki[1] == B){
    cout << "G" << endl;
 }
 else if(enki[2] == B)
 {
    cout << "C" << endl;
 }
 else {
    cout << "A" << endl;
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

ll max3(ll a,ll b,ll c)
{
  return max(max(a,b),c); 
}

int main()
{
  ll X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  ll pp,qq,rr;
  priority_queue<ll, vector<ll>> p;
  priority_queue<ll, vector<ll>> q;
  priority_queue<ll, vector<ll>> r;
  for (int i=0;i<A;i++)
  {
    cin>>pp;
    p.push(pp);
  }
  for (int i=0;i<B;i++)
  {
    cin>>qq;
    q.push(qq);
    
  }
  for (int i=0;i<C;i++)
  {
    cin>>rr;
    r.push(rr);
  }
  
  //priority_queue<ll, vector<ll>, greater<ll> > q;
  
  ll ans = 0;
  ll i=0;
  ll j=0;
  ll k=0;
  while (k<X+Y)
  {
    pp=p.top();
    qq=q.top();
    rr=r.top();
    
    if (p.empty() || i>=X) pp = -1;
    if (q.empty() || j>=Y) qq = -1;
    if (r.empty()) rr = -1;
    
    if (i<X && pp==max3(pp,qq,rr))
    {
      ans += pp;
      //cout<<"p"<<pp<<endl;
      p.pop();
      i++;
    }
    else if (j<Y && qq==max3(pp,qq,rr))
    {
      ans += qq;
      //cout<<"q"<<qq<<endl;
      q.pop();
      j++;
    }
    else if (rr==max3(pp,qq,rr))
    {
      ans += rr;
      //cout<<"r"<<rr<<endl;
      r.pop();
    }
    k++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 3316
from collections import deque

N,M = map(int,input().split())
 
S=[[] for _ in range(N+1)]

for _ in range(M):
    a,b = map(int,input().split())
    S[a].append(b)
    S[b].append(a)
 
ans = [0] * (N+1)

queue = deque([1])
while queue:
    now = queue.popleft()
    for i in S[now]:
        if ans[i] == 0:
            ans[i] = now
            queue.append(i)
            
if 0 in ans[2:]:
    print('No')
else:
    print('Yes')
    for i in ans[2:]:
        print(i)


Measured memory_bytes: 34956
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const ll inf = 9e18;
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vd(vector<T> vec)
{
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T> void debug::vd2(vector<vector<T>> vec)
{
    for(auto vv : vec) for(auto vvv : vv) cout << vvv << " ";
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

double dp[3000][3000];

class ICoins {
public:
    void solve(std::istream& in, std::ostream& out)
    {
        int n;
        in >> n;
        vector<double> p(n);
        for(int i=0; i<n; i++){
            in >> p[i];
        }

        Fill(dp, 0.0);
        dp[0][0] = 1.0;
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dp[i+1][j+1] += dp[i][j] * p[i];
                dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
            }
        }

        double res = 0.0;
        for(int i=(n+1)/2; i<=n; i++){
            res += dp[n][i];
        }

        out << setprecision(10) << res << endl;
    }
};


int main() {
	ICoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 70528
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    const vector<char> ch = {'N','E','W','S'};
    const vector<int> dy = {1,0,0,-1};
    const vector<int> dx = {0,1,-1,0};
    while (1) {
        int N; cin >> N;
        if (N == 0) break;
        vector<vector<bool>> field(21, vector<bool>(21));
        rep(i,N) {
            int x,y; cin >> x >> y;
            field[y][x] = true;
        }
        int x = 10;
        int y = 10;
        field[y][x] = false;
        int M; cin >> M;
        rep(i,M) {
            char c; cin >> c;
            rep(j,4) {
                if (c != ch[j]) continue;
                int k; cin >> k;
                while (k) {
                    y += dy[j];
                    x += dx[j];
                    field[y][x] = false;
                    k--;
                }
            }
        }
        bool ok = true;
        rep(i,21) {
            rep(j,21) {
                if (field[i][j]) ok = false;
            }
        }

        cout << (ok ? "Yes" : "No") << endl;
    }
}



Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	String s;
	int k, cnt;

	void run() {
		try (Scanner sc = new Scanner(System.in)) {
			s = sc.next();
			k = sc.nextInt();
			System.out.println(fnc(""));
		}
	}

	String fnc(String str) {
		for (int i = 97; i <= 122; i++) {
			String next = str + (char) i;
			if (s.contains(next)) {
				cnt++;
				if (cnt == k) {
					return next;
				}

				String tmp = fnc(next);
				if (!tmp.equals("")) {
					return tmp;
				}
			}
		}

		return "";
	}

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

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	unordered_map<int,int> m;
	int n;
	cin>>n;
	while(n--) {
		int val;
		cin>>val;
		m[val]++;
	}
	ll sum = 0;
	bool even = false;
	for(auto a:m) {
		sum++;
		if(a.S%2==0)even=!even;
	}
	if(even)sum--;
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 7220
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var h = o.a();
  var w = o.a();
  var n = o.a();
  var sy = o.a();
  var sx = o.a();
  var s = o.a(1);
  var t = o.a(1);
  var l = 1, r = w, u = 1, d = h;
  var L = "L", R = "R", U = "U", D = "D";
  for(var i = n-1; i >= 0; i--){
    switch(t[i]){
      case L: r = Math.min(r+1, w); break;
      case R: l = Math.max(l-1, 1); break;
      case U: d = Math.min(d+1, h); break;
      case D: u = Math.max(u-1, 1);
    }
    switch(s[i]){
      case L: l++; break;
      case R: r--; break;
      case U: u++; break;
      case D: d--;
    }
    if(u > d || l > r)return "NO";
  }
  if(sy < u || sy > d || sx < l || sx > r)return "NO";
  return "YES"
}

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int n;
string s;
ll ans = 0;

void solve(ll x,ll y)
{
    if(x==n+1)
    {
        ans += y;
        return;
    }
    ll cur = 0;
    for(ll i=x; i<=n; i++)
    {
        cur = (10*cur) + (s[i]-'0');
        solve(i+1,y+cur);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll dig=accumulate(s.begin(),s.end(),0,[&](ll k,char ch){return k=k+(ch-'0');});
    ll sum=0;
    for(auto x: s){
        sum=10*sum+(x-'0');
        sum%=dig;
    }
    if(sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	if a < c && c < b || b < c && c < a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
n = int(input())
arms = []
for _ in range(n):
    x, l = map(int, input().split())
    arms.append((x - l, x + l))
arms.sort(key = lambda x : x[1])

last_right = arms[0][1]
ans = 1
for i in range(1, n):
    left, right = arms[i]
    if left < last_right:
        continue
    last_right = right
    ans += 1

print(ans)

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

int main() {
  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  ll ans = 0;
  ll count = 0;
  rep(i, n-1) {
    if (h[i] >= h[i+1]) count++;
    else count = 0;
    ans = max(ans, count);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
n,a,b,c,d = map(int,input().split())
s = input()
flag = 'Yes'

if '##' in s[a-1:c] or '##' in s[b-1:d]:
    flag = 'No'
if not '...' in s[b-2:d+1] and c > d:
    flag = 'No'
print(flag)


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#define ll long long
using namespace std;
int record[1000010];

int main(){
 //cout<<123<<endl;
  int s;
  cin>>s;
  record[s]++;
  for(int i=2;;i++){
    s = s%2==0 ? s/2 : 3*s+1;
    record[s]++;
    if(record[s] >1){ cout<<i<<endl;break;}
  }
  
  
  
 
  return 0;
}


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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef pair<int,int> pii;
typedef vector<pii> vii;
int n,k,memo[10][2001];
vector<int> book[10];
int f(int nu=0,int cou=0){
    if(nu>=10||cou>=k){
        return 0;
    }else if(memo[nu][cou]>0){
        return memo[nu][cou];
    }else{
        int ans=f(nu+1,cou);
        rep(i,0,book[nu].size()){
            if((i+cou)>=k)break;
            ans=max(ans,f(nu+1,cou+i+1)+book[nu][i]);
        }
        return memo[nu][cou]=ans;
    }
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i,0,10){
        rep(j,0,2001){
            memo[i][j]=0;
        }
    }
    rep(i,0,n){
        int x,y;
        cin >> x >> y ;
        book[y-1].pb(x);
    }
    rep(i,0,10){
        if(!book[i].empty())sort(ALL(book[i]),greater<int>());
    }
    rep(i,0,10){
        rep(j,1,book[i].size()){
            book[i][j]+=book[i][j-1];
           // cout << i << " "<<book[i][j] << endl;
        }
    }
    rep(i,0,10){
        rep(j,0,book[i].size()){
            book[i][j]+=j*(j+1);
        }
    }
    cout << f() << endl;
    //cout << book[1][3] << endl;
    return 0;
}

Measured memory_bytes: 3392
#include <iostream>
#include <cmath>

using namespace std;
int a,b,c,d;

int main()
{
    cin >> a >> b >> c >> d;
    if(abs(c-a) <= d){
        cout << "Yes";
    } else if (abs(b-a) <= d && abs(c-b) <= d) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	if(!n){
		cout << 0 << endl;
		return 0;
	}
	int cnt=0;
	vector<char> a;
	while(abs(n) != 0){
		char tmp;
		if(n%2){
			a.insert(a.begin(),'1');
			if(cnt%2) n++;
			else  n--;
		}else{
			a.insert(a.begin(),'0');
		}
		cnt++;
		n /=2;
		//cout << n << endl;
	}
	for(auto itr : a) cout << itr;
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,b;
    cin >>a>>b;
    int coin[3];
    coin[0]=a+a-1;
    coin[1]=a+b;
    coin[2]=b+b-1;
    int max=coin[0];
    for(int i = 1;i<3;i++){
        if(max<coin[i]) max = coin[i];
    }
    cout<<max<<endl;
    return 0;
}



Measured memory_bytes: 256
INF=float('inf')
def solve1():
    dp=[[-INF]*2 for i in range(N+1)]
    dp[0][0]=0;dp[1][0]=A[0];dp[2][1]=A[1]
    for i in range(N):
        if dp[i+1][0]==-INF:
            if i-1>=0:
                dp[i+1][0]=max(dp[i+1][0],dp[i-1][0]+A[i])
        if dp[i+1][1]==-INF:
            if i-1>=0:
                dp[i+1][1]=max(dp[i+1][1],dp[i-1][1]+A[i])
            if i-2>=0:
                dp[i+1][1]=max(dp[i+1][1],dp[i-2][0]+A[i])
    print(max(dp[N][1],dp[N-1][0]))
    return
def solve2():
    dp=[[-INF]*3 for i in range(N+1)]
    dp[0][0]=0;dp[1][0]=A[0];dp[2][1]=A[1];dp[3][2]=A[2]
    for i in range(N):
        if dp[i+1][0]==-INF:
            if i-1>=0:
                dp[i+1][0]=max(dp[i+1][0],dp[i-1][0]+A[i])
        if dp[i+1][1]==-INF:
            if i-1>=0:
                dp[i+1][1]=max(dp[i+1][1],dp[i-1][1]+A[i])
            if i-2>=0:
                dp[i+1][1]=max(dp[i+1][1],dp[i-2][0]+A[i])
        if dp[i+1][2]==-INF:
            if i-1>=0:
                dp[i+1][2]=max(dp[i+1][2],dp[i-1][2]+A[i])
            if i-2>=0:
                dp[i+1][2]=max(dp[i+1][2],dp[i-2][1]+A[i])
            if i-3>=0:
                dp[i+1][2]=max(dp[i+1][2],dp[i-3][0]+A[i])
    print(max(dp[N][2],dp[N-1][1],dp[N-2][0]))
    return

N=int(input())
A=list(map(int,input().split()))

if N%2==0:
    solve1()
else:
    solve2()

Measured memory_bytes: 126136
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = [0] * N
for i in range(N): a[i] = int(input())
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]
#print(cs)
table = [0] * (N + 1)
for i in range(1, N + 1): table[i] = cs[i] - i * K
#print(table)
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 1)
    self.el = [0] * (n + 1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j = None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)

fwk = BIT(N + 1)

def compress(init_val):
  t = sorted(set(init_val))
  d = dict([[t[i], i] for i in range(len(t))])
  res = [0] * len(init_val)
  for i in range(len(init_val)): res[i] = d[init_val[i]]
  return res

comtable = compress(table)

for i in range(N + 1): fwk.add(comtable[i] + 1, 1)

res = 0
for i in range(N):
  fwk.add(comtable[i] + 1, -1)
  res += fwk.get(comtable[i], N + 1)
print(res)

Measured memory_bytes: 97076
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <unordered_map>

#define MaxN 200010

using namespace std;

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

int n, k, p = 1000000007;

int main() {
    scanf("%d%d", &n, &k);
    ll ans = 0;
    for (int i = k; i <= n + 1; ++i) {
        // choose i elements.
        // 0 + .. i - 1 = i * (i - 1) / 2
        // n + 1 - i, +  ... n
        ans += ll(n + 1 - i + n) * ll(i) / 2LL;
        ans -= ll(i) * ll(i - 1) / 2LL;
        ans += 1;
        ans %= p;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3776
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <array>

using namespace std;

void re(int& x);

template<class T> void re(std::vector<T>& a);

void pr(long long x);

void pr(const char *x);

void ps();
template<class T, class... Ts> void ps(const T& t, const Ts&... ts);

#ifdef FFDBG

#else
#define dbg(x...) dsfdsfsdfasd
#endif

int n;
vector<int> v;

long long go(int a, int b, int ca, int cb) {
    if (a+1 == b) return 0;

    long long ans = 4e18;
    for (int i = a+1; i < b; i++) {
        ans = min(ans, v[i] * 1ll *(ca+cb) + go(a,i,ca,cb+ca) + go(i,b,ca+cb,cb));
    }
    return ans;
}

void solve()
{
    re(n);
    v.resize(n); re(v);

    ps(v[0] + v[n-1] + go(0, n-1, 1, 1));
}

int main() {

    solve();
}

void re(int& x) { scanf("%d", &x); }

template<class T> void re(std::vector<T>& a) { for (int i = 0; i < a.size(); i++) re(a[i]); }

void pr(long long x) { printf("%lld", x); }

void pr(const char *x) { printf("%s", x); }

void ps() { pr("\n"); }
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) { 
    pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); 
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string s,h,t,res;
    cin >> s;
    h = s.substr(0,2);
    t = s.substr(2);

    res = (1 <= stoi(h) && stoi(h) <= 12) ?
        (1 <= stoi(t) && stoi(t) <= 12) ? "AMBIGUOUS": "MMYY"
        :(1 <= stoi(t) && stoi(t) <= 12) ? "YYMM": "NA";
    
    cout << res << endl;
    return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    
    int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    
    int x, y;
    cin >> x >> y;

    if(a[x]==a[y]) Yes;
    else No;
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            //var c = Console.ReadLine();
            //var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var P = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray()

            long AC = 0;
            long WA = 0;
            long TLE = 0;
            long RE = 0;


            for (int i = 0; i < N; i++)
            {
                var inp = Console.ReadLine();
                if (inp == "AC")
                {
                    AC++;
                }else if (inp == "WA")
                {
                    WA++;
                }else if(inp == "RE")
                {
                    RE++;
                }
                else
                {
                    TLE++;
                }
            }


            Console.WriteLine("AC x  "+AC);
            Console.WriteLine("WA x " + WA);
            Console.WriteLine("TLE x " + TLE);
            Console.WriteLine("RE x " + RE);

        }
    }

}


Measured memory_bytes: 30696
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        String u, nl = System.getProperty("line.separator");
        StringBuilder
            p = new StringBuilder(1000),
            d = (new StringBuilder(100)).append("."),
            s = (new StringBuilder(100)).append("#"),
            k = new StringBuilder(100);
        Scanner r = new Scanner(System.in);
        int h, w, ww;
        d.append(d).append(d).append(d).append(d);
        s.append(s).append(s).append(s).append(s);
        ww = d.length();
        while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
            while (w > ww) {
                d.append(d);
                s.append(s);
                ww = d.length();
            }
            p.append(u = s.substring(0, w)).append(nl);
            k.setLength(0);
            k.append('#').append(d.substring(2, w))
            	.append('#').append(nl);
            while (2 != h--) {
                p.append(k);
            }
            p.append(u).append(nl).append(nl);
        }
        System.out.print(p);
    }
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int count = 0;
  for (int i = 0; 1 <= n; i++) {
    n /= k;
    count++; 
  }
  cout << count << endl;

return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    K = int(input())
    n = len(S)
    ALL = set()
    
    cnt = 0
    for i in range(n):
        for j in range(1,K+1):
            if i+j<=n:
                ALL.add(S[i:i+j])

    ALL = sorted(list(ALL))
    print(ALL[K-1])

main()

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

int main(){
    int n,k,score = 0;
    string s;
    cin >> n >> k >>s;
    for(int i=0;i<n-1;i++){
        if(s[i] == s[i+1]) score++;
    } 
    int ans = min(score + k*2 , n-1);
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int m = cin.nextInt();
        int x = cin.nextInt();
        int [] a = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = cin.nextInt();
        }
        if (x == n) {
            System.out.println(0);
            return;
        }

        long left = Arrays.stream(a).filter(ai -> { return (ai < x); }).count();
        long right = Arrays.stream(a).filter(ai -> { return (ai > x); }).count();

        System.out.println(Math.min(left, right));
    }
}


Measured memory_bytes: 26964