akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

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

D = [-1] * (n**2)
for i in range(n):
    D[i*n + i] = 0

S = [A[0]]
for i in range(1, n):
    S.append(A[i] + S[-1])
S.append(0)

# print(D)
# print(S)

def merge(l, r):
    # print(l,r)
    if D[l*n + r] != -1:
        return D[l*n + r]
    else:
        ans = float("inf")
        for i in range(l, r):
            ans = min(ans, merge(l, i) + merge(i+1, r) + S[r] - S[l-1])
        D[l*n + r] = ans
        return ans

print(merge(0, n-1))
# print(D)

Measured memory_bytes: 76128
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <class T>
bool uax(T&a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool uin (T&a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 1e5 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    int a, b, c;
    cin >> a >> b >> c;

    cout << (a * b) / 2;

    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
// N,E,S,W = 0,1,2,3;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
bool inrange(int x,int y,int w,int h){return 0<=x&&x<w && 0<=y&&y<h;}
int main(void)
{
  for(;;){
    int w,h;
    cin >> w >> h;
    if(!w&&!h) return 0;
    int ope[32][32];
    REP(j,h) REP(i,w) cin >> ope[i][j];
    int c[4];
    REP(i,4) cin >> c[i];
    set<tuple<int,int,int> > already;
    priority_queue<pair<int,tuple<int,int,int> > > dijk;
    // negc,(x,y,dir)
    dijk.push(make_pair(0,make_tuple(0,0,1)));
    while(!dijk.empty()){
      pair<int,tuple<int,int,int> > tmp;
      tmp=dijk.top();
      int negc,x,y,dir;
      negc=tmp.first;
      tie(x,y,dir)=tmp.second;
      dijk.pop();
      if(!already.insert(make_tuple(x,y,dir)).second) continue;
      if(x==w-1&&y==h-1){
	cout << -negc << endl;
	break;
      }
      REP(i,4){
	int cost=c[i];
	if(ope[x][y]==i) cost=0;
	int ndir=(dir+i)%4;
	if(inrange(x+dx[ndir],y+dy[ndir],w,h)) dijk.push(make_pair(negc-cost,make_tuple(x+dx[ndir],y+dy[ndir],ndir)));
      }
    }
  }
}

Measured memory_bytes: 1404
N,C=map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

res = 0
st = set()
for s,t,c in inl:
    nx = set()
    for t1, c1 in st:
        if not (t1 == s and c == c1) and t1 >= s:
            nx.add((t1,c1))
    nx.add((t,c))
    st = nx
    res = max(len(nx), res)

print(res)


Measured memory_bytes: 63448
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        inputK: usize,
    }

    let K: usize = inputK - 1;

    let arr = vec![
        1,
        1,
        1,
        2,
        1,
        2,
        1,
        5,
        2,
        2,
        1,
        5,
        1,
        2,
        1,
        14,
        1,
        5,
        1,
        5,
        2,
        2,
        1,
        15,
        2,
        2,
        5,
        4,
        1,
        4,
        1,
        51,
    ];

    let ans = arr[K];
    println!("{}", ans);
}


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

using namespace std ;

int n ;

int main()
{
    scanf("%d" , &n ) ;
    int now = 0 ;
    for(int i = 1 ; i <= n ; i++ ){
        int b ;
        scanf("%d" , &b ) ;
        if( b == now + 1 ) now++ ;
    }
    if( now == 0 ) printf("-1\n") ; 
    else printf("%d\n" , n - now ) ;
}


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

using namespace std;

#define ll       long long

#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)

#define  pfi(x)   printf("%d", x)
#define  pfl(x)   printf("%lld", x)
#define  pfd(x)   printf("%lf", x)
#define  pfc(x)   printf("Case %d: ", x++)
#define  ps       printf(" ")
#define  pn       printf("\n")

#define  pb       push_back
#define  ppb      pop_back
#define  pf       push_front
#define  ppf      pop_front
#define  In       insert
#define  All(a)   a.begin(), a.end()

int dp[100005][2], n, data[100];

int solve(int rem, int turn)
{
	if(rem < data[0])
		return turn;

	if(dp[rem][turn] != -1)
		return dp[rem][turn];

	int ret = turn;

	for(int i = 0; i < n; i++)
	{
		if(rem < data[i])
			break;
		
		if(turn)
			ret = ret & (solve(rem - data[i], (turn + 1) % 2));
		else
			ret = ret | (solve(rem - data[i], (turn + 1) % 2));
	}
	return dp[rem][turn] = ret;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    memset(dp, -1, sizeof dp);
    int k;
    sci(n), sci(k);

    for(int i = 0; i < n; i++)
    	sci(data[i]);

    sort(data, data + n);

    if(solve(k, 0))
    	printf("First\n");
    else
    	printf("Second\n");

    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
string latte="URDL";

int H,W;
char fld[11][11];

string ans;
bool used[11][11];
void dfs(int y,int x,int d,int c,string s){
    c--;
    used[y][x]=true;
    if(c==0){
        ans=s;
        return;
    }

    for(int malta=-1;malta<=1;malta++){
        int nd=(d+malta+4)%4;
        int ny=y,nx=x;
        while(true){
            ny+=dy[nd],nx+=dx[nd];
            if(ny<0||ny>=H||nx<0||nx>=W)break;
            if(fld[ny][nx]=='.'||used[ny][nx])continue;
            used[ny][nx]=true;
            dfs(ny,nx,nd,c,s+string(1,latte[nd]));
            used[ny][nx]=false;
            break;
        }
    }
}

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>fld[i];

    int sy,sx,sd;
    int cnt=0;
    rep(i,H)rep(j,W){
        int tmp=find(all(latte),fld[i][j])-latte.begin();
        if(tmp<4){
            sy=i;sx=j;sd=tmp;
        }
        if(fld[i][j]!='.')cnt++;
    }

    dfs(sy,sx,sd,cnt,"");
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[3001][3001];//dp[i,j] = optimul value of x in subarray i to j when p1 tries to maximize x while p2 tries to mini x;
int maxprofit(int ar[],int i, int j,int turn){
	if(i>j){
		return 0;
	}
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	if(turn==1)
		return dp[i][j]= max(ar[i]+maxprofit(ar,i+1,j,0), ar[j]+maxprofit(ar,i,j-1,0));
	else{
		return dp[i][j]=min(maxprofit(ar,i+1,j,1),maxprofit(ar,i,j-1,1));
	}
	
}

signed main(){
	int n;
	cin>>n;
	int ar[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>ar[i];
		sum+=ar[i];
	}
//	cout<<sum<<endl;
	memset(dp,-1,sizeof dp);
	int optx = maxprofit(ar,0,n-1,1);
	int opty = sum - optx;
	cout<<optx-opty<<endl;
	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

typedef pair<ll,ll> pll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n; cin>>n;
    vi a = readVector<int>(n);

    vector<ll> ps(405);
    vector<vector<ll>> dp(405, vector<ll>(405, 1LL<<60));
    FOR(i,n)
        dp[i][i] = 0,
        ps[i] = (i>0 ? ps[i-1] : 0) + a[i];

    RNG(t,1,n)
    FOR(l,n) {
        int r=l+t;
        if(r>=n) continue;
        RNG(m, l, r-1) {
            ll lcost = ps[m] - (l>0 ? ps[l-1] : 0);
            ll rcost = ps[r] - ps[m];
            dp[l][r] |= MIN(dp[l][m] + dp[m+1][r] + lcost + rcost);
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    int ans = 0;
    for (int big = 0; big < n; big++) {
        for (int mid = 0; mid < big; mid++) {
            auto iter = upper_bound(all(l), l[big] - l[mid]);
            auto small = iter - l.begin();
            ans += max(mid - small, (long)0);
            // debug(big);
            // debug(mid);
            // debug(small);
            // debug(ans);
            // out(" ");
        }
    }
    out(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	cout << (a - 1)*(b - 1) << endl;
	return 0;
}

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

int main(){
    int i, j;
    char C[5][5];
    for(i=1; i<=2; i++){
        for(j=1; j<=3; j++){
            cin >> C[i][j];
        }
    }
    
    if(C[1][1]==C[2][3] && C[1][2]==C[2][2] && C[1][3]==C[2][1])	cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}


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

int main(){
	int N,ans=0;
	cin>>N;
  	for(int i=1;i<=N;++i){
      	int count=0;
      for(int j=1;j<=N;++j)
    	if(i%2==1&&i%j==0)++count;
      	if(count==8)++ans;
    }cout<<ans<<endl;return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;


int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13)cout<<b<<endl;
    else if(a>=6)cout<<b/2<<endl;
    else cout<<0<<endl;
    
    return 0;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int n,w;
    cin>>n>>w;

    vi u(n),v(n);
    for(int i=0;i<n;i++)
    {
        cin>>u[i]>>v[i];
    }

    //dp[i][j] is the minimum weight to get total value j for the  first i elements

    int mx=0;
    vvi dp(n+1, vi(1e5+1,inf));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=1e5;j++)
        {
            if(v[i-1]==j) dp[i][j] = min(dp[i-1][j], u[i-1]);
            else if(v[i-1]<j) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + u[i-1]);
            else dp[i][j] = dp[i-1][j];
            if(dp[i][j]<=w) mx = max(mx, j); 
        }
    }

    cout<<mx<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


Measured memory_bytes: 83204
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int a,b;
    while(~scanf("%d %d",&a,&b))
    {
        if(a*b%2==0)
            printf("Even\n");
        else
            printf("Odd\n");
    }
    return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int r; cin>>r;
    if(r<1200) cout<<"ABC"<<endl;
    else if(r<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
}

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

int main() {
	
	int r, g;
	cin >> r >> g;
	cout << (g - r) + g << endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int, rdr *bufio.Reader) []string {
	var strSlice []string

	//rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

//DivideConvertInt is to divide and convert
func DivideConvertInt(line string, num int) []int {
	tmp := strings.Split(line, " ")

	intSlice := make([]int, num)

	for i := 0; i < num; i++ {
		intTmp, _ := strconv.Atoi(tmp[i])
		intSlice[i] = intTmp
	}

	return intSlice
}

func main() {
	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)
	lines := inputs(1, rdr)

	lineInt := DivideConvertInt(lines[0], 4)

	A := lineInt[0]
	B := lineInt[1]
	//C := lineInt[2]
	K := lineInt[3]

	if K <= A {
		fmt.Println(K)
		return
	}

	remaining := K - A

	if remaining <= B {
		fmt.Println(A)
		return
	}

	remaining = remaining - B

	fmt.Println(A - remaining)

}


Measured memory_bytes: 1828
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int a,b,x;

   cin>>x>>a>>b;

  if(abs(x-a)<abs(x-b))
  {
        cout<<"A"<<endl;
}
  else
 cout<<"B"<<endl;
 
    return 0;
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int F(int x){
	int ret=0;
	for(int i=1;i<=x;i++)
		if(x%i==0)
			ret++;
	return ret;
}
int main(){
	int n,tot=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i+=2)
	{
		if(F(i)==8)
			tot++;
	}
	printf("%d\n",tot);
	return 0;
}


Measured memory_bytes: 128
N = input()

def dfs(A):
    if int(A) > int(N):
        return 0
    if all(A.count(c) for c in "753") >0:
        ans = 1
    else:
        ans = 0
        
    for i in "357":
        A += i
        ans += dfs(A)
        A = A[:-1]
        
    return ans

print(dfs("0"))

Measured memory_bytes: 3060
#include <cstdio>
#define max(a,b) (((a)>(b))?(a):(b))
#define rep(i,n) for(int i=0;i<(n);i++)

int dp[3005][3005]={};
int n,t,s;

int dat[3005][2];
int main(void){
	scanf("%d%d%d",&n,&t,&s);
	rep(i,n)scanf("%d%d",&(dat[i][0]),&(dat[i][1]));
	
	rep(i,n){
		for(int j=t+1;j>=0;j--){
			dp[i+1][j]=dp[i][j];
			if(j-dat[i][1]>=0 && (!(j-dat[i][1]<s && s<j))){
				dp[i+1][j]=max(dp[i+1][j],dp[i][j-dat[i][1]]+dat[i][0]);
			}
			//printf("%2d ",dp[i+1][j]);
		}
		//printf("\n");
	}
	
	int ans=0;
	rep(i,t+1)ans=max(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 36276
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 100000;
const int Q_MAX = 100000;
const int LOGN_MAX = 17;

int N;
int x[N_MAX];
int L;
int Q;
int a[Q_MAX];
int b[Q_MAX];

int nxt[LOGN_MAX][N_MAX];

void solve() {
  REP(i, N) nxt[0][i] = lower_bound(x + i, x + N, x[i] + L + 1) - x - 1;

  REP(k, LOGN_MAX - 1) {
    REP(i, N) {
      nxt[k + 1][i] = nxt[k][nxt[k][i]];
    }
  }

  // DUMP2D(nxt, LOGN_MAX, N);

  REP(i, Q) {
    int f, t;
    scanf("%d%d", &f, &t);
    --f; --t;
    if (f > t) swap(f, t);

    int d = 0;
    for (int k = LOGN_MAX - 1; k >= 0; k--) {
      if (nxt[k][f] < t) {
        d |= 1 << k;
        // printf("f: %d, t, %d, nxt[%d][%d]: %d, d: %d\n", f, t, k, f, nxt[k][f], d);
        f = nxt[k][f];
      }
    }
    printf("%d\n", d + 1);
  }
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", x + i);
  scanf("%d", &L);
  scanf("%d", &Q);
}

int main() {
  input();
  solve();
  return 0;
}


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

#define SPEED cin.tie(0);ios::sync_with_stdio(false);
template <class T> void chmax(T& a, const T b){a=max(a,b);}

int main() {
    SPEED
    int N; cin >> N;
    vector<int> V(N+1),W(N+1);
    for(int i = 1; i <= N; ++i) cin >> V[i] >> W[i];

    //O(Q)
    int nl = 1<<10,nr=1<<8,L_max=100001;
    vector<int> msb(nl,0);
    for(int i = 1; i < nl; ++i) msb[i]=31-__builtin_clz(i);
    vector<int> bit_w_dp(nl,0);
    vector<int> bit_v_dp(nl,0);
    vector<vector<int>> dp(nl,vector<int>(L_max,0));

    //前計算
    for(int n = 1; n < min(nl,N+1); ++n) {
        int k = 2*n;
        vector<int> l;
        while(k/=2) l.push_back(k);
        int sz=l.size();
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i-(1<<msb[i])]+W[l[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i-(1<<msb[i])]+V[l[msb[i]]];
            if(bit_w_dp[i]<=L_max) chmax(dp[n][bit_w_dp[i]],bit_v_dp[i]);
        }
        //累積max
        for(int i = 1; i < L_max; ++i) {
            chmax(dp[n][i],dp[n][i-1]);
        }
    }

    int Q; cin >> Q;
    string ans_str="";

    //クエリ
    while(Q--) {
        int p,L,l_idx=0;; cin >> p >> L;
        vector<int> r;
        p *= 2;
        while(p/=2) {
            if(p<nl) chmax(l_idx,p);
            else r.push_back(p);
        }
        int sz = r.size(),ans=dp[l_idx][L];
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i-(1<<msb[i])]+W[r[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i-(1<<msb[i])]+V[r[msb[i]]];
            if(bit_w_dp[i]<=L) chmax(ans,dp[l_idx][L - bit_w_dp[i]]+bit_v_dp[i]);
        }
        ans_str += to_string(ans)+"\n";
    }
    cout << ans_str;

    return 0;
}


Measured memory_bytes: 408220
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout << x << '\n'
#define showh(x) cout << x << ' '
#define go(i, a, n) for (ll i = a; i < n; i++)
#define gor(i, a, n) for (ll i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
#define maxn 100001
ll expo(ll a, ll b)
{
    a = a % mod;
    b = b % mod;
    if (b == 0)
        return 1;
    if (b % 2)
        return ((a % mod) * (expo((a * a) % mod, b / 2) % mod)) % mod;
    return expo((a * a) % mod, b >> 1) % mod;
}
ll mul(ll a, ll b)
{
    a = a % mod;
    b = b % mod;
    if (b == 0)
        return 0;
    if (b % 2)
        return ((a % mod) + (mul((a + a) % mod, b / 2) % mod)) % mod;
    return mul((a + a) % mod, b >> 1) % mod;
}

bool ispoweroftwo(ll x)
{
    return x && !(x & (x - 1));
}
ll xorcal(ll n)
{
    if (n % 4 == 0)
        return n;
    if (n % 4 == 1)
        return 1;
    if (n % 4 == 2)
        return n + 1;
    if (n % 4 == 3)
        return 0;
}
void sieve(ll n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = false;
    prime[1] = false;
    for (ll i = 2; i * i <= n; i++)
    {
        if (prime[i] == true)
        {
            for (ll j = i * i; j <= n; j += i)
            {
                prime[j] = false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 or n % 3 == 0)
        return false;

    for (ll i = 5; i * i <= n; i += 6)
    {
        if (n % i == 0 or n % (i + 2) == 0)
            return false;
    }
    return true;
}

ll modinverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m;
        a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0)
    {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else
    {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
ll findset(ll parent[], ll a)
{
    if (parent[a] == a)
        return a;
    return parent[a] = findset(parent, parent[a]);
}
bool ispalindrome(string s)
{
    string t = s;
    reverse(t.begin(), t.end());
    if (t == s)
        return true;
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    sieve(30007);
    ll n;
    cin >> n;
    ll a[n];
    go(i, 0, n) cin >> a[i];
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    go(i, 2, n) dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    show(dp[n - 1]);
    return 0;
}


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

using namespace std;

int A[5][100002];
int dp[100002][5]; /// dp table

int go(int pos, int prev) {
    if(pos < 0) return 0;

    if(dp[pos][prev] != -1) return dp[pos][prev];

    int ans = 0;

    for(int i = 0; i < 3; i++) {
        if(i == prev) continue;

        ans = max(ans, A[i][pos] + go(pos - 1, i));
    }

    return dp[pos][prev] = ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;

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

    memset(dp, -1, sizeof dp);

    cout << go(n - 1, 3) << endl; /// 3 == no prev
}

/**
 * Vacation
 */

Measured memory_bytes: 11136
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main(void){
	int N,A[105],i;
    double ans,sum=0.0;
	scanf("%d",&N);
  for(i=0;i<N;i++){
	scanf("%d",&A[i]);
    sum=sum+(1/(double)A[i]);
  }
	ans = 1 / sum;
  printf("%f",ans);
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> b(n - 1);
  for(int i = 0; i < n - 1; i++) cin >> b.at(i);
  
  int ans = 0;
  ans += b.at(0);
  ans += b.at(b.size() - 1);
  for(int i = 0; i < n - 2; i++) ans += min(b.at(i), b.at(i + 1));
  
  cout << ans << endl;
}

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

using namespace std;

struct UnionFindRange
{
  vector< int > data;
  vector< int > left, right;

  UnionFindRange(int sz)
  {
    data.assign(sz, -1);
    left.resize(sz);
    right.resize(sz);
    for(int i = 0; i < sz; i++) left[i] = i;
    for(int i = 0; i < sz; i++) right[i] = i;
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    left[x] = min(left[x], left[y]);
    right[x] = max(right[x], right[y]);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  pair< int, int > range(int k)
  {
    k = find(k);
    return {left[k], right[k]};
  };

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int N, V, X[200000];
vector< int > vs;
int left_cover_jump[19][200000], right_cover_jump[19][200000];
int left_cover[1 << 18], right_cover[1 << 18];

int main()
{
  scanf("%d %d", &N, &V);
  for(int i = 0; i < N; i++) {
    scanf("%d", &X[i]);
  }
  while(V > 0) {
    vs.push_back(V);
    V /= 2;
  }
  vs.push_back(0);


  UnionFindRange uf(N);
  for(int i = (int) vs.size() - 1; i >= 0; i--) {
    for(int j = 1; j < N; j++) {
      if(X[j] - X[j - 1] <= vs[i]) uf.unite(j - 1, j);
    }
    for(int j = 0; j < N; j++) {
      auto p = uf.range(j);
      left_cover_jump[i][j] = p.second;
      right_cover_jump[i][j] = p.first;
    }
  }

  auto chmax = [&](int &a, int b) { a = max(a, b); };
  auto chmin = [&](int &a, int b) { a = min(a, b); };
  fill_n(left_cover, 1 << 18, -1);
  fill_n(right_cover, 1 << 18, N);
  int restsz = (int) vs.size() - 1;
  for(int i = 0; i < (1 << restsz); i++) {
    for(int j = 0; j < restsz; j++) {
      if((i >> j) & 1) continue;
      chmax(left_cover[i | (1 << j)], left_cover_jump[j + 1][min(left_cover[i] + 1, N - 1)]);
      chmin(right_cover[i | (1 << j)], right_cover_jump[j + 1][max(0, right_cover[i] - 1)]);
    }
  }
  int mask = (1 << restsz) - 1;

  int isok[200002] = {};
  for(int i = 0; i < (1 << restsz); i++) {
    auto L = left_cover_jump[0][min(left_cover[i] + 1, N - 1)];
    auto R = right_cover_jump[0][max(right_cover[i ^ mask] - 1, 0)];
    if(R <= L) isok[R]++, isok[L + 1]--;
  }
  int sum = 0;
  for(int i = 0; i < N; i++) {
    sum += isok[i];
    if(sum > 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 38016
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] element = br.readLine().split(" ");
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        }
        
        int count = bubbleSort(a);

        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
        System.out.println(count);
    }

    public static int bubbleSort (int[] a) {
        int i, j, temp;
        int n = a.length - 1;
        int count = 0;
        for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        }
        return count;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<endl;
        return 0;
    }else{
        ll a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return  0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

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

a.sort(reverse=True)
total = sum(a)
if all([x >= total / (4 * m) for x in a[:m]]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9148
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int pow(int k)
{
  int ans = 1;
  for (int i = 0;i < k;i++)
  {
    ans *= 2;
  }
  return ans;
}

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

  double ans = 0;

  int tmp = 1,count = 0;
  for (int i = 1;i <= n;i++,count = 0)
  {
    for (int j = i;j < k;j *= 2,count++)
    {
      
    }
    tmp = pow(count) * n;
    ans += 1 / (double)tmp;
  }
  cout << fixed<< setprecision(11);
  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
int n,m,d;
int q,l[111111],r[111111];
int sum[211111];
unordered_map<int,P> lis;
signed main(){
	
	cin>>n>>m>>d;
	rep(i,n)rep(j,m){
		int a;
		cin>>a;
		lis[a-1]={i,j};
	}
	cin>>q;
	rep(i,q)cin>>l[i]>>r[i];
	rep(i,d){
		for(int j=i;j+d<n*m;j+=d){
			sum[j+d]=sum[j]+(abs(lis[j].first-lis[j+d].first)+abs(lis[j].second-lis[j+d].second));
		}
	}
	rep(i,q){
		cout<<sum[r[i]-1]-sum[l[i]-1]<<endl;
	}

}


Measured memory_bytes: 8612
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ld l;
    cin >> l;
    ld x = l / (ld)3;
    cout << fixed << setprecision(10);
    cout << (x * x * x);
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int W,H,x,y,r;

scanf("%d",&W);
scanf("%d",&H);
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&r);


if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(b-a>0){
        if(b-a>x){
            cout << "dangerous" << endl;
        }else{
            cout << "safe" << endl;
        }
    }else{
        cout << "delicious" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = STDIN.readline.to_i

exists = {}
i = 1
while not exists.has_key?(s) do
    exists[s] = i
    if s.modulo(2) == 0 then
        s = s / 2
    else
        s = 3 * s + 1
    end
    i += 1
end
puts(i)

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
#include <random>
using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
const ll MOD = 1e9 + 7;

int main()
{
    int n; cin >> n;
    set<string> S;
    rep(i, 0, n) {
        string s; cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;


 
    return 0;
}



Measured memory_bytes: 19260
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: "List[str]"):
    s = {'AC': 0, 'WA': 0, 'TLE':0, 'RE':0}
    for c in S:
        s[c] += 1
    for c in ['AC', 'WA', 'TLE', 'RE']:
        print('{} x {}'.format(c, s[c]))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 75496
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::vector<int64_t> h(N);
	for (auto& elem : h) {
		std::cin >> elem;
	}

	// bool ans_fg = true;
	int64_t ans = 0;
	while(true) {
		bool water_fg = false;
		for (int64_t i = 0; i < N; i++) {
			if (h[i] != 0 && !water_fg) {
				water_fg = true;
			}
			if (h[i] == 0 && water_fg) {
				ans++;
				water_fg = false;
			}
			if (h[i] != 0) {
				h[i]--;
			}
		}
		if (water_fg) {
			ans++;
		}
		if (*std::max_element(h.begin(), h.end()) == 0) {
			break;
		}
	}

	std::cout << ans << std::endl;

}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


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

namespace AtCoderProg {
    class B_121 {
        static void Main(string[] args) {
            int num;
            int i = 1;
            bool result = false;

            string[] input = Console.ReadLine().Split(' ');
            string str = input[0] + input[1];

            num = int.Parse(str);

            while(i < num) {
                if((i * i) == num) {
                    result = true;
                }
                i++;
            }

            if (result) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9044
// javac Main.java && java _

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) { new Main(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);
	
	HashMap<String, Integer> ans;	
	
	Main() {
		ans = new HashMap<>();
		ans.put("SUN", 7);
		ans.put("SAT", 1);
		ans.put("FRI", 2);
		ans.put("THU", 3);
		ans.put("WED", 4);
		ans.put("TUE", 5);
		ans.put("MON", 6);

		out.println(ans.get(in.next()));
		out.close();
	}
	
	

	int min(int a, int b) { if (a < b) return a; return b; }	
	int max(int a, int b) { if (a > b) return a; return b; }	
	long min(long a, long b) { if (a < b) return a; return b; }	
	long max(long a, long b) { if (a > b) return a; return b; }	

	boolean z(int x) { if (x == 0) return true; return false; }
	boolean z(long x) { if (x == 0) return true; return false; }
	
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}



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

using str = string;
using ss = stringstream;

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

    str s;cin>>s;
    
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='B')
        {
            s[i]='2';
            for(int j=i;j>=0;j--)if(s[j]=='0'||s[j]=='1'){s[j]='2';break;}
        }
    }

    str ans="";
    for(int i=0;i<s.size();i++)if(s[i]=='0'||s[i]=='1')ans.push_back(s[i]);

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long   ll;
typedef pair<ll,ll> pll;
typedef long double ld; 
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb           push_back
#define F            first
#define S            second
#define ios          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define hell   1000000007LL
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0) {if (y & 1) res = (res*x) % p;y = y>>1;
  x = (x*x) % p;} return res;} 

const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
ll euclid(ll x,ll y,ll a,ll b){
  return (a-x)*(a-x)+(b-y)*(b-y);
}
ll n,m,k;
std::vector<ll> suma,sumb;
bool valid(ll x)
{
  ll i; 
  for(i=0;i<=x;i++)
  {
    if(i<=n && x-i<=m && suma[i]+sumb[x-i]<=k)
      return true;
  }
  return false;
}
void solve()
{
  cin>>n>>m>>k;
  std::vector<ll> a(n+1),b(m+1);
  ll i,j;
  suma.pb(0);
  for(i=1;i<=n;i++)
  {
    cin>>a[i];
    suma.pb(suma.back()+a[i]);
  }
  sumb.pb(0);
  for(i=1;i<=m;i++)
  {
    cin>>b[i];
    sumb.pb(sumb.back()+b[i]);
  }
  ll ans=0,lo=0,hi=n+m;
  while(lo<=hi)
  {
    ll mid = (lo+hi)/2;
    if(valid(mid))
    {
      ans = max(ans,mid);
      lo = mid+1;
    }
    else
      hi = mid-1;
  }
  cout<<ans<<endl;
}

int main()
{ 
  ios; 
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t=1,i=1;
  // cin>>t;
  while(i<=t)
  {
    solve();
    i++;
  }
  return 0;
}


Measured memory_bytes: 11040
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	int peach;
	int apple;
	getline(cin,str);
	for(int i=0;i<str.size()-4;++i){
		if(str.substr(i,5)=="apple"){
			str.replace(i,5,"peach");
			continue;
		}
		if(str.substr(i,5)=="peach"){
			str.replace(i,5,"apple");
			continue;
		}
	}
	cout<<str<<endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> grid(h+2);
    for(int i = 0; i < grid.size(); i++)
    {
        grid[i] = string(w+2, '#');
    }

    for(int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for(int j = 0; s[j]; j++)
        {
            grid[i+1][j+1] = s[j];
        }
    }

    for(int i = 0; i < grid.size(); i++)
    {
        cout << grid[i] << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


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


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


int main() {
	int A, B, C;
	cin >> A >> B >> C;
	bool ok = false;
	REP(i, 1000000000) {
		if (C >= A && C <= B)ok = true;
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256