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

#define endl '\n'

const int INF = 1e6 + 5 ;

void solve()
{
	int n ;
  	cin >> n ;
  	
  	int k ;
  	cin >> k ;
  	
  	int height[n] ;
  	for (int i = 0 ; i < n ; i++) cin >> height[i] ;
  	
  	int dp[n];
  	memset (dp , INF , sizeof(dp)) ;
  	dp[0] = 0 ;
  	for (int i = 0 ; i < n ; i++) 
    {
    	for ( int j = i + 1 ; j <= ( i + k ) ; j++ )
        {
        	if ( j < n )
     	    {  dp[j] = min( dp[j] , dp[i] + abs ( height[i] - height[j] ) ) ; }
        }
    }
  	cout << dp[n - 1] << endl ;
}
int main()
{
    solve() ;
}

Measured memory_bytes: 4424
N = int(input())
A = list(map(int,input().split()))
ans = 0
l = [0]*(3*10**5+10)
for i in range(1,N):
  x = i-A[i]
  if x<0:
    continue
  else:
    l[x]+=1
if A[0]<=2*10**5:
  ans+=l[A[0]]
for i in range(1,N):
  x = i+A[i]
  if x<0:
    continue
  if x>2*10**5:
    continue
  
  if i-A[i]>=0:
    l[i-A[i]]-=1
  ans+=l[x]
  
print(ans)


Measured memory_bytes: 32376
// Aizu Vol0 // Aizu Vol0 0081: A Symmetric Point
// 2017.8.1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define WHAT  "-0.00000000"

int main()
{
	double x1, y1, x2, y2;
	double xq, yq, xp, yp;
	double a, b, c, d, e;
	char sx[20], sy[20], *px, *py;

	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) == 6) {
		a = y2 - y1, b = x1 - x2, c = -a*x1 - b*y1;
		d = a*a + b*b;
		e = a*xq + b*yq + c;

		xp = xq - 2 * a*e / d;
		yp = yq - 2 * b*e / d;

		sprintf(sx, "%.8lf", xp);
		sprintf(sy, "%.8lf", yp);
		px = sx; if (!strcmp(sx, WHAT)) px++;
		py = sy; if (!strcmp(sy, WHAT)) py++;
		printf("%s %s\n", px, py);
	}
	return 0;
}

Measured memory_bytes: 668
#include <stdio.h>
#include <string.h>
int main(void){
  int n,m,i,j,sum,max=0;
  char s[101][11],t[101][11];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%s",s[i]);
  scanf("%d",&m);
  for(i=0;i<m;i++) scanf("%s",t[i]);
  for(i=0;i<n;i++){
    sum=0;
    for(j=0;j<n;j++){
      if(strcmp(s[i],s[j])==0) sum++;
    }
    for(j=0;j<m;j++){
      if(strcmp(s[i],t[j])==0) sum--;
    }
    if(max<sum) max=sum;
  }
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >> X[i];
  }
  vector<int> S(N);
  S = X;
  sort(X.begin(),X.end());
  for(int i=0; i<N; i++){
    if(S[i] < X[N/2]){
      cout << X[N/2] << endl;
    }else{
      cout << X[N/2-1] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3712
import sys
N = int(input())
print(0, flush=True)
cond = input()
if cond == 'Vacant':
    sys.exit()

l = 0
r = N-1
while r-l > 3:
    mid = (l+r)//2
    if mid % 2 == 1:
        mid += 1

    print(mid, flush=True)
    I = input()
    if I == 'Vacant':
        sys.exit()
    else:
        if cond == I:
            l = mid
        else:
            r = mid

for i in range(l,r+1):
    print(i, flush=True)
    if input() == 'Vacant':
        sys.exit()


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int N;
  int al=0; 
  int bb=0; 
  int ans=0;
  int cnt=0;

  cin >> N;

  //長さNの配列を作成.
  vector<long> A(N), B(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  sort(A.begin(), A.end());
  
  for(int i=N-1; i>=0; i--){
    if(cnt %2 == 0){
      //      cout << "al for i = " << i << endl; 
      al += A[i];
      cnt++;
    }else{
      //      cout << "bb for i = " << i << endl; 
      bb += A[i];
      cnt++;
    }
  }
  
  cout << al - bb << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"

#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

int n, a[300000];
ll cnt;

int main(){
	cin >> n;
	lp(n * 3)
		cin >> a[i];
	sort(a, a + n * 3);
	cnt = 0;
	lp(n) {
		cnt += a[n * 3 - 2 - i * 2];
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
T meguru_search(T ok, T ng, function<bool(T)> check){
    while(max(ok, ng) - min(ok, ng) > T(1)){
        T mid = (ok + ng) / T(2);
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

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

    lint n, m, v, p;
    cin >> n >> m >> v >> p;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }
    SORT_INV(a);

    auto check = [&](lint mid){
        if(a[p - 1] > a[mid] + m){
            return false;
        }
        lint nokori = v;
        lint cnt = 0;
        rep(i, n){
            if(i < p - 1 || a[i] <= a[mid]){
                --nokori;
            }else{
                cnt += min(a[mid] + m - a[i], m);
            }
        }
        return cnt >= nokori * m;
    };

    lint ans = meguru_search<lint>(p - 1LL, n, check) + 1LL;
    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize("O2")
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
#include <iomanip>
#include <bitset>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
///////////////////////////////
#define int long long

void solve(){

	string s , t;
	cin>>s>>t;

	int n = s.size();
	int m = t.size();
	int dp[n+1][m + 1];
	memset(dp , 0 , sizeof dp);
	for(int i = 1 ; i <= n ; ++i){
		
		for(int j = 1 ; j <= m ;++j){
			
			if(s[i-1]==t[j-1])
				dp[i][j] = 1 + dp[i-1][j-1];
			else dp[i][j] = max(dp[i][j-1] , dp[i-1][j]);
		}
	}

	int len = dp[n][m];
	string ans = "";
	int i = n , j = m;
	while(len){
	
		while(i >=0 && dp[i][j]==len)
			--i;
		while(j >=0 && dp[i+1][j]==len)
			--j;
		ans.push_back(s[i]);
		--len;
	}
	reverse(ans.begin(),ans.end());

	// for(int i = 1 ; i <= n ;++i)
	// 	for(int j = 1 ; j <= m ; ++j)
	// 		cout<<dp[i][j]<<" \n"[j==m];

	cout<<ans<<endl;
	
}

signed main(){
 
	fast;
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 74000
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void){
    LL N;
    cin >> N;

    vector<LL> H(N);
    rep(i, N) cin >> H[i];

    vector<LL> lds;
    int length = 0;
    for(LL i = 1; i < N; i++) {
        if(H[i] <= H[i-1]){
            length++;
        }else{
            lds.push_back(length);
            length = 0;
        }
    }
    lds.push_back(length);

    sort(RALL(lds));

    cout << lds[0] << endl;

    return 0;
}


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

int MOD = 2019;

int main() {
    int l, r;
    cin >> l >> r;

    if(r - l + 1 >= MOD) {
        cout << 0 << endl;
        return 0;
    }

    int min = 1e9;
    for(int i = l; i < r; i++) {
        for(int j = i + 1; j <= r; j++) {
            int temp = ((i % MOD) * (j % MOD)) % MOD;
            if(min > temp) min = temp;
        }
    }
    cout << min << endl;

    return 0;
}

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

int main() {
    long N, A, B;
    cin >> N >> A >> B;
    
    if (A > B) cout << 0 << endl;
    else if (A == B) cout << 1 << endl;
    else if (N == 1) cout << 0 << endl;
    else cout << (A + (N - 1) * B) - (A * (N - 1) + B) + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int (i)=0;(i)<(N);(i)++)
#define REPR(i,N) for(int (i)=(N);i>=0;i--)
#define FOR (i,m,n) for(int (i)=m;(i)<(n);(i)++)

int main(){
  int animals, feets;
  bool flag=0;
  cin >>animals >>feets;

  REP(i,animals+1){
    if(i*2+(animals-i)*4==feets){
      cout <<"Yes";
      flag=1;
      break;
    }
  }
  if(flag==0)cout <<"No";
}


Measured memory_bytes: 3596
from scipy.sparse.csgraph import floyd_warshall
h,w=map(int,input().split())
table=[[0]*10 for i in range(10)]
for i in range(10):
  C=[int(i) for i in input().split()]
  for j in range(10):
    table[i][j]=C[j]
d=floyd_warshall(csgraph=table, directed=True, return_predecessors=False)
ans=0
for i in range(h):
  A=[int(i) for i in input().split()]
  for a in A:
    if a!=-1:
      ans+=int(d[a][1])
print(ans)


Measured memory_bytes: 13736
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
    FastIO io = new FastIO("in.txt");


    public void main() throws Exception {
        int T = io.nextInt();
        if(T >= 30){
            io.out("Yes\n");
        }else{
            io.out("No\n");
        }
    }

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

    class FastIO {
        BufferedReader br;
        StringTokenizer sk;

        public FastIO(String fname){
            try{
                File f = new File(fname);
                if(f.exists()) {
                    System.setIn(new FileInputStream(fname));
                }

            }catch (Exception e){
                throw new IllegalArgumentException(e);
            }

            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastIO(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while(sk==null || !sk.hasMoreElements()){
                try {
                    sk = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new IllegalArgumentException(e);
                }
            }
            return sk.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public char nextChar(){
            return next().charAt(0);
        }

        public long nextLong(){
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }

        public String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            }catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }

        public void out(String v){
            System.out.print(v);
        }

        public void out(int v) {
            System.out.print(v);
        }

        public void out(long v){
            System.out.print(v);
        }

        public void out(double v) {
            System.out.print(v);
        }
    }
}



Measured memory_bytes: 32740
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop
import bisect

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

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

mod = 998244353

DP = [[0 for _ in range(S+1)] for _ in range(N+1)]
DP[0][0] = 1

for i in range(1, N+1):
  for j in range(S+1):
    if j - A[i-1] < 0:
      DP[i][j] = 2 * DP[i-1][j] % mod
    else:
      DP[i][j] = (DP[i-1][j-A[i-1]] + 2 * DP[i-1][j]) % mod
    
ans = DP[N][S]
print(ans)

#print(DP)

Measured memory_bytes: 153120
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7
ans = 1

num = [0]*(n+1)
num[0] = 3

for i in range(0,n):
    if i < a[i]:
        print(0)
        exit()
    ans *= num[a[i]]
    ans %= mod
    num[a[i]] -= 1
    num[a[i]+1] += 1
    #print(ans)
        
    
print(ans)

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

string s;
int dp[502][2][3][10][500], m;
//dp[桁][使えるか][上下][前の数字][mod]
int rec(int p, int ok, int pre_up, int pre, int num){
	if(p == s.size())return (num == 0);
	if(dp[p][ok][pre_up][pre][num] != -1)return dp[p][ok][pre_up][pre][num];
	
	int n = ok ? 9 : s[p]-'0';
	int res = 0;
	for(int i = 0;i <= n;i++){
		if(pre_up == 1 && pre <= i)continue;
		if(pre_up == 2 && pre >= i)continue;
		if(pre_up == 0){
			if(pre == 0)res += rec(p+1, ok|(i < n), 0, i, (num*10+i)%m);
			else if(pre < i)res += rec(p+1, ok|(i < n), 1, i, (num*10+i)%m);
			else if(pre > i)res += rec(p+1, ok|(i < n), 2, i, (num*10+i)%m);
		}else if(pre_up == 1){
			res += rec(p+1, ok|(i < n), 2, i, (num*10+i)%m);
		}else{
			res += rec(p+1, ok|(i < n), 1, i, (num*10+i)%m);
		}
	}
	
	return dp[p][ok][pre_up][pre][num] = res % mod;
}

int get(string str){
	s = str;
	fill((int*)dp, (int*)(dp+502), -1);
	int ans = rec(0, 0, 0, 0, 0);
	return ans;
}

string calc(string str){
	for(int i = str.size()-1;i >= 0;i--){
		if(str[i] == '0')str[i] = '9';
		else {str[i]--;break;}
	}
	return str;
}

int main(){
	string a, b;
	cin >> a >> b >> m;
	int ans = (get(b)-get(calc(a)) + mod)%mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 62160
#include <iostream>
using namespace std;
int N,T;
int ans = 10000;
int main(void){
    cin >> N >> T;
    int c[N],t[N];
    for(int i = 0;i < N;i++){
        cin >> c[i] >> t[i];
        if(t[i] <= T){
            ans = min(ans,c[i]);
        }
    }
    if(ans == 10000){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	string s;
	long long k;
	cin>>s>>k;
	for(int i=0;i<s.size();i++) if(s[i]!='1') 
	{
		if(k<=i)
		{
			cout<<"1";
			return 0;
		}
		cout<<s[i];
		return 0;
	}
	cout<<"1";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

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

   if (A >= K) cout << K << endl;
   else if (A + B >= K) cout << A << endl;
   else cout << 2 * A + B - K << endl;
 }


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

int main() {
int n;
while(cin >> n) {
if(n == 0) break;
vector<int> a(n);
for(int i=0; i<n; i++) {
cin >> a[i];
}

sort(a.begin(), a.end());

int sum = 0;
for(int i=0; i<n; i++) {
if(i!=0 && i!=n-1) sum += a[i];
}

cout << sum / (n-2) << endl;
}
return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	String s;
	
	public void run() {
		while (true) {
			s = in.next();
			if (s.matches("#")) break;
			boolean leftFoot = true;
			boolean rightFoot = true;
			int left = 0, right = 0;
			int before = (s.charAt(0) - '0') % 3;
			if (before == 0) before = 3;
			for (int i = 1; i < s.length(); i++) {
				int next = (s.charAt(i) - '0') % 3;
				if (next == 0) next = 3;
				if ((before > next && leftFoot) || (before < next && !leftFoot)) {
					left++;
				} else {
					leftFoot = !leftFoot;
				}
				if ((before < next && rightFoot) || (before > next && !rightFoot)) {
					right++;
				} else {
					rightFoot = !rightFoot;
				}
				before = next;
			}
			System.out.println(Math.min(left, right));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 22184
a = [int(input()) for _ in range(int(input()))]

dp = [[0] * 5 for _ in range(len(a) + 1)]

for i, x in enumerate(a):
    y = x % 2 + (x == 0) * 2
    z = (x + 1) % 2
    
    dp[i+1][0] = dp[i][0] + x
    dp[i+1][1] = min(dp[i][:2]) + y
    dp[i+1][2] = min(dp[i][:3]) + z
    dp[i+1][3] = min(dp[i][:4]) + y
    dp[i+1][4] = min(dp[i]) + x

print(min(dp[-1]))

Measured memory_bytes: 67788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;

int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int n=0;
    for (int i = 0; i < k; i++)
    {
        if(a>=b){
            b*=2;
            n+=1;
        }else{break;}
    }
    for (int i = 0; i < k-n; i++)
    {
        if(b>=c){
            c*=2;
            
        }else{break;}
    }
    if(a<b&&b<c){
        cout<<"Yes"<<endl;
    }else{cout<<"No"<<endl;}
    
}

Measured memory_bytes: 3132
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

const LL mod = 1000000007;
LL DP[100+1][8];

LL rec(int n){
    if(n<=1)
        return 1;
    else
        return rec(n-1) + rec(n-2);
}

int main(void){
    int H,W,K;
    GI(H);GI(W);GI(K);
    DP[0][0] = 1;
    REP(i,H)REP(j,W){
        DP[i+1][j] += DP[i][j]*rec(W-1-j)*rec(j);
        DP[i+1][j] %= mod;
        if(0<j){
            DP[i+1][j-1] += DP[i][j]*rec(W-1-j)*rec(j-1);
            DP[i+1][j-1] %= mod;
        }
        if(j<W-1){
            DP[i+1][j+1] += DP[i][j]*rec(W-1-j-1)*rec(j);
            DP[i+1][j+1] %= mod;
        }
    }
    printf("%lld\n",DP[H][K-1]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,w;
    int value[100],weight[100];
    long int bag[101][100005]={0};
    cin >> n;
    cin >> w;
    for(int i=0;i<n;i++){
        cin >> weight[i] >> value[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=w;j++){
            if(weight[i]<=j){
                bag[i+1][j]=max(bag[i][j-weight[i]]+value[i],bag[i][j]);
            }else{
              bag[i+1][j]=bag[i][j];
            }
        }
    }
    cout << bag[n][w] << endl;
    return 0;
}

Measured memory_bytes: 79104
N, K = map(int, input().split())
P = list(map(int, input().split()))
P_sum = [0]
for p in P:
    P_sum.append(P_sum[-1] + p)

max_sum, max_P = 0, None
for i in range(N - K + 1):
    if max_sum < P_sum[i + K] - P_sum[i]:
        max_sum = P_sum[i + K] - P_sum[i]
        max_P = P[i:i + K]

print(sum([(p * (p + 1) // 2) / p for p in max_P]))


Measured memory_bytes: 137936
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

int main()
{
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        unordered_set<string> ss;
        for (int j = 1; j < s.size(); ++j) {
            auto left = s.substr(0, j);
            auto leftR = left;
            reverse(begin(leftR), end(leftR));
            auto right = s.substr(j);
            auto rightR = right;
            reverse(begin(rightR), end(rightR));
            ss.insert(left + right);
            ss.insert(left + rightR);
            ss.insert(leftR + right);
            ss.insert(leftR + rightR);
            ss.insert(right + left);
            ss.insert(rightR + left);
            ss.insert(right + leftR);
            ss.insert(rightR + leftR);
        }
        cout << ss.size() << endl;
    }
}

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

void printList(int num[], int n){
	for (int i = 0; i < n; i++){
		cout << num[i];
		if (i != n-1) cout << ' ';
	}
	cout << endl;
}

void swap(int *x, int *y){
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}

int bubbleSort(int num[], int n){
	int flag = 1;
	int count = 0;
	while (flag){
		flag = 0;
		for (int j = n-1; j != 0; j--){
			if (num[j] < num[j-1]){
				swap (&num[j], &num[j-1]);
				count++;
				flag = 1;
			}
		}
	}
	return count;
}

int main(){
	int n[100];
	int limit;
	cin >> limit;
	for (int i = 0; i < limit; i++){
		cin >> n[i];
	}
//	printList(n, limit);
	int count;
	count = bubbleSort(n, limit);
	printList(n, limit);
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3112
// 2020-07-11 21:03:55
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  REPC(xi, 1, 100) REPC(yi, 1, 100) REPC(zi, 1, 100) {
    ll x = xi, y = yi, z = zi;
    ll res = x * x + y * y + z * z + x * y + y * z + z * x;
    mp[res]++;
  }
  REPC(i, 1, n) {
    cout << mp[i] << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 6116
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct edge{int to,cost;};

template<typename T> class TreeDPRerooting
{
    using Func=function<T(T,T)>;
    vector<vector<edge>> G;
    int N;
    Func merge,lift;
    T e; // identity element

public:
    vector<vector<T>> sumL,sumR;
    vector<T> dp,res;

    TreeDPRerooting(vector<vector<edge>> G,Func merge,Func lift,T e):
        G(G),merge(merge),lift(lift),e(e),N(G.size()),dp(N),sumL(N),sumR(N),res(N)
    {
        dfs(0,-1);
        reroot(0,-1);
    } 

    T dfs(int v,int par)
    {
        // TreeDP
        T res=e;
        for(edge e:G[v]) if(e.to!=par){
            res=merge(res,lift(dfs(e.to,v),e.cost));
        }
        return dp[v]=res;
    }

    void reroot(int v,int par)
    {
        // accumulate children's information from left and right
        sumL[v].assign(G[v].size()+1,e);
        sumR[v].assign(G[v].size()+1,e);

        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            sumL[v][i+1]=merge(sumL[v][i],lift(dp[e.to],e.cost));
        }
        for(int i=G[v].size()-1;i>=0;i--){
            edge e=G[v][i];
            sumR[v][i]=merge(sumR[v][i+1],lift(dp[e.to],e.cost));
        }

        // calculate res[v] using children's information(L[v],R[v],dp)
        res[v]=sumR[v][0];

        // reroot v with its children
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(e.to!=par){
                int tmp=dp[v];
                dp[v]=merge(sumL[v][i],sumR[v][i+1]);
                reroot(e.to,v);
                dp[v]=tmp;
            }
        }
    }
};

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

    int N,M; cin>>N>>M;
    vector<vector<edge>> G(N);
    for(int i=0;i<N-1;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        G[a].push_back({b,1});
        G[b].push_back({a,1});
    }
    auto merge=[&](int a,int b)
    {
        return a*b%M;
    };
    auto lift=[&](int a,int cost)
    {
        return (a+1)%M;
    };
    TreeDPRerooting<int> treedp(G,merge,lift,1LL);
    for(int i:treedp.res) cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 45312
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 1

for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" and flag == 1 :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "#" :
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")
    

Measured memory_bytes: 3064
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll n, m, C, s, g, x[10000], y[10000], d[10000], c[10000], p[20], q[20][50], r[20][50];
vector<P> e[100][20];
ll ans[100];
priority_queue<P, vector<P>, greater<P>> pq;
ll temp_data[100];
ll INF = 10000000000000LL;

ll get(ll color, ll len) {
  ll ans = 0;
  for (ll i = 0; i < p[color]-1; i++) {
    if (len <= q[color][i]) {
      return (len - (i == 0 ? 0 : q[color][i-1])) * r[color][i] + ans;
    }
    ans += (q[color][i] - (i == 0 ? 0 : q[color][i-1])) * r[color][i];
  }
  return (len - (p[color]==1 ? 0 : q[color][p[color]-2])) * r[color][p[color]-1] + ans;
}

int main() {
  while (scanf("%lld%lld%lld%lld%lld", &n, &m, &C, &s, &g), n) {
    s--; g--;
    for (ll i = 0; i < m; i++) {
      scanf("%lld%lld%lld%lld", &x[i], &y[i], &d[i], &c[i]);
      x[i]--; y[i]--; c[i]--;
      e[x[i]][c[i]].push_back(P(y[i], d[i]));
      e[y[i]][c[i]].push_back(P(x[i], d[i]));
    }
    for (ll i = 0; i < C; i++) scanf("%lld", &p[i]);
    for (ll i = 0; i < C; i++) {
      for (ll j = 0; j < p[i]-1; j++) scanf("%lld", &q[i][j]);
      for (ll j = 0; j < p[i]; j++) scanf("%lld", &r[i][j]);
    }
    for (ll i = 0; i < n; i++) ans[i] = INF;
    pq.push(P(0, s));
    ans[s] = 0;
    while (!pq.empty()) {
      P pt = pq.top(); pq.pop();
      ll before = pt.second, cost = pt.first;
      //printf("pq! before: %lld, cost: %lld\n", before, cost);
      if (ans[before] < cost) continue;
      for (ll color = 0; color < C; color++) {
        for (ll i = 0; i < n; i++) temp_data[i] = INF;
        temp_data[before] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0, before));
        while (!que.empty()) {
          P qt = que.top(); que.pop();
          ll from = qt.second, len = qt.first, temp = get(color, len) + cost;
          if (len > temp_data[from]) continue;
          if (ans[from] > temp) {
            ans[from] = temp;
            pq.push(P(temp, from));
          }
          //printf("  que! from: %lld, len: %lld, cost: %lld\n", from, len, temp);
          for (ll i = 0; i < e[from][color].size(); i++) {
            ll to = e[from][color][i].first, len2 = len + e[from][color][i].second;
            if (temp_data[to] <= len2) continue;
            temp_data[to] = len2;
            que.push(P(len2, to));
          }
        }
      }
    }
    if (ans[g] == INF) ans[g] = -1;
    printf("%lld\n", ans[g]);
    for (ll i = 0; i < n; i++) for (ll j = 0; j < C; j++) e[i][j].clear();
  }
}



Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

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

    long long int ans = 0;
    for(int i=0; i<=min(n,k); i++){
        ans += nCr(n,i) * nCr(i+(n-i)-1,i) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int N,M,T;

int main(){
  cin>>N>>M>>T;
  int last=-M;
  int ans=0;
  
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if( a-last >= M+M){
      ans+=( (a-last)-M-M );
    }
    last=a;
  }

  if( last+M <= T){
    ans+=( T-last-M);
  }

  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3112
#include<cstdio>
#include<iostream>
#define debug(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__);
#define nc getchar
using namespace std;
typedef long long ll;
inline void read(ll &x) {
	char b = nc(); x = 0;
	for (; !isdigit(b); b = nc());
	for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
ll n, x, a[100005], ans;
int main() {
	read(n); read(x);
	for (int i = 1; i <= n; ++i) read(a[i]);
	for (int i = 2; i <= n; ++i) {
		ll t = a[i-1] + a[i];
		if (t > x) ans += t - x, a[i] -= t - x;
		a[i] = max(a[i], 0ll);
	} printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Contest
{
    class Program
    {
        private int N;

        private int Query(int n)
        {
            Console.WriteLine(n);
            string anser = Console.ReadLine();
            switch (anser)
            {
                case "Male":
                    return 1;
                case "Vacant":
                    return 0;
                case "Female":
                    return -1;
            }
            throw new Exception();
        }

        public void Solve()
        {
            N = int.Parse(Console.ReadLine());
            int left = 0;
            int right = N - 1;
            int ll = Query(left);
            if (ll == 0) return;
            int rr = Query(right);
            if (rr == 0) return;
            while (true)
            {
                int mid = (left + right+1) / 2;
                int mm = Query(mid);
                if (mm == 0) return;
                if ((mid - left) % 2 == 0)
                {
                    if (ll != mm)
                    {
                        right = mid;
                        rr = mm;
                    }
                    else
                    {
                        left = mid;
                        ll = mm;
                    }
                }
                else
                {
                    if (ll == mm)
                    {
                        right = mid;
                        rr = mm;
                    }
                    else
                    {
                        left = mid;
                        ll = mm;
                    }
                }
            }

        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13508
/**
 *    GOOGLE CODEJAM 2020
 *    Author:  dominix
 **/
#include "bits/stdc++.h"
using namespace std;
#define READ 		freopen("in.txt", "r", stdin)
#define WRITE  		freopen("out.txt", "w", stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shandom_ruffle random_shuffle
#define debug(x) cout << "hi" << x
#define pb push_back
#define nl cout << '\n'
#define br break
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vlll = vector<vll>;
using vpii = vector<pii>;
using mpii = map<int, int>;
using mpll = map<ll, ll>;
using stch = stack<char>;
using stvll = stack<vll>;
const ll nax = 1000*1007;
const ll mno = 1007;
const ll mod = 1e9 + 7;
const ll mxN = 1e5 + 5;
const ll inF = 1e18;
const ll rc = 64;
const ll MOD = 998244353; 

#define popcountL   __builtin_popcountll
#define popcount    __builtin_popcount
inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

inline ll modMul(ll a, ll b,ll mod){
    ll ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
inline ll powerMod(ll a,ll b,ll mod){
	if(b==0)return 1LL%mod;
	ll x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

inline ll lcm( ll a,ll b ){
	ll g = __gcd(a,b);
	return ((a/g) * b);
}


ll n, m, k, t;
// int x[mxN], y[mxN];
int main() {
    BOOST;
    // READ;
    // WRITE;
 	// cin >> t;
	// for(int tt = 1; tt <= t; ++tt) {
    //     cout << "Case #" << tt << ": ";

    // }
    cin >> n >> m;
    ll sum = 0;
    // vi a(m);
    for(ll i = 0, x; i < m; ++i) {
        cin >> x;
        sum += x;
    }
    if(sum > n) cout << "-1";
    else cout << n - sum;
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define CURR_MAX 1e7

using namespace std;

int recurse(int i ,int k, vector<int> &dp , vector<int> &height)
{
    if(i <= 0) return CURR_MAX;
    else
    {
        if(dp[i] >= 0) return dp[i];
        else
        {
            int min_1 = INT_MAX;
            for (int j = 1; j <= k; j++)
            {
                min_1 = min(min_1,recurse(i-j,k,dp,height) + abs(height[i-1] - height[i-1-j]));
            }
            dp[i] = min_1;
            return dp[i];
        }
        
    }
}

int main(int argc, char const *argv[])
{
    int n, k,temp;
    cin >> n >> k;
    vector<int> height(n,0);
    vector<int> dp(n+1,-1);
    for (int i = 0; i < n; i++)
    {
        cin >>temp;
        height[i] = temp;
    }
    dp[1] = 0;
    dp[2] = abs(height[1]-height[0]);
    cout << recurse(n,k,dp,height);
    return 0;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;



signed main(){

    int n;
    cin >> n;
    vector<int> a(n - 1), b(n - 1);
    vector<vector<int>> edges(n);
    vector<int> par(n, -1);
    vector<vector<int>> childs(n);
    for(int i = 0; i < n - 1; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        edges[a[i]].push_back(b[i]);
        edges[b[i]].push_back(a[i]);
    }
    auto mpow = [](auto x, i64 y){
     auto z = x;
     decltype(x) val = y & 1 ? x : decltype(x)(1);
     while(z *= z, y >>= 1)
      if(y & 1)
       val *= z;
     return val;
    };

    mint ans = 0;
    vector<int> siz(n, -1);
    function<void(int)> f = [&](int x){
        for(auto y : edges[x]){
            if(siz[y] != -1)
                continue;
            siz[y] = 1;
            f(y);
            childs[x].push_back(y);
            par[y] = x;
            siz[x] += siz[y];
        }
    };
    siz[0] = 1;
    f(0);

    for(int i = 0; i < n; ++i){
        vector<int> s;
        for(auto j : childs[i])
            s.push_back(siz[j]);
        if(par[i] != -1)
            s.push_back(n - siz[i]);

        mint pat = mpow(mint(2), n - 1);
        for(auto& t : s){
            pat -= mpow(mint(2), t) - 1;
        }
        --pat;

        ans += pat;
    }

    ans *= mpow(mpow(mint(2), n), MOD - 2);
    cout << ans << endl;
}



Measured memory_bytes: 35840
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int N,A,B,C,D,N1,N2;
	scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
	if(N%A==0){N1=N/A*B;}else{N1=(N/A+1)*B;}//セットXのときのN本買うための値段
	if(N%C==0){N2=N/C*D;}else{N2=(N/C+1)*D;}
	printf("%d\n",min(N1,N2));
	return 0;
}



Measured memory_bytes: 3156
function Main(input){
  var In = input.split(' ');
  var N = parseInt(In[0], 10);
  var Y = parseInt(In[1], 10);
  var yen10000 = -1;
  var yen5000 = -1;
  var yen1000 = -1;
  
  for(var i = 0; i <= N; i++){
    for(var j = 0; j <= N - i; j++){
      var k = N - i - j;
      var total = 10000 * i + 5000 * j + 1000 * k;
      if(total == Y){
        yen10000 = i;
        yen5000 = j;
        yen1000 = k;
      }
    }
  }
  console.log('%d %d %d', yen10000, yen5000, yen1000);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn=1, Kr=1, Knr=1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int hand[200005];

int main()
{
	int N, W[105];
	int S1=0, S2=0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> W[i];
		S2 += W[i];
	}

	int ans=5000;
	ans = max(S1, S2) - min(S1, S2);
	for (int i = 0; i < N; i++)
	{
		S1 += W[i];
		S2 -= W[i];
		ans = min(ans, max(S1, S2) - min(S1, S2));
	}
	
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  vll a(5);
  vll b(5);
  ll ans=0;
  rep(i,5){
    cin>>a[i];
    ans+=a[i];
    b[i]=10-a[i]%10;
    if(b[i]==10) b[i]=0;
  }
  sort(all(b));
  rep(i,4) {
   ans+=b[i];
  }
  COUT(ans);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	if(b < a) {
		d=a;
		a=b;
		b=d;
	}
	if(c < b) {
		d=b;
		b=c;
		c=d;
	if(b < a) {
		d=a;
		a=b;
		b=d;
	}
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	bool  flag = false;
	string ans = "No";
	rep(i, s.size()-1) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			ans = "Yes";
		}
	}
	cout << ans << endl;

	return 0;
	
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
void dfs(int nowth, int n, int letter,string ans){
	int len = ans.length();
//	if(len==0)
//		dfs(1, n, "a");
	if(nowth==n){
		cout<<ans<<endl;
	}
	else{
		for(int i=0;i<=len&&i<=letter;i++){
			string temp = ans+char('a'+i);
			if(i==letter){
//				string temp = ans+char('a'+i);
				dfs(nowth+1, n, letter+1, temp);
			}
			else{
				
				dfs(nowth+1, n, letter, temp);
			}
			
		}
	}
	return;
}
int main()
{
	int n;
	while(cin>>n){
		dfs(0, n, 0, "");
	}
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();
    if(S.equals(U)){
      A--;
    } else {
      B--;
    }

    System.out.println(A + " " + B);
  }
}


Measured memory_bytes: 21844