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

struct cww{cww(){
    ios::sync_with_stdio(false);cin.tie(0);
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

namespace _DSU{
    int cnt=0;
    int mem[2][212345];
    int* get(){
        return mem[cnt++];
    }
}
LL res[112345];
int S[112345];
int T[112345];
set<int> query[41234];
int task[112345];
class UnionFind{
private:
    int *par,*rank;
    int find(int x){
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
public:
    UnionFind(int n,int *par,int *rank) :par(par),rank(rank){
        for(int i = 0; i < n; i++)par[i] = i,rank[i] = 0;
    }
    UnionFind(int n):UnionFind(n,_DSU::get(),_DSU::get()){}
    int unite(int x, int y){
        x = find(x);y = find(y);
        if (x == y)return -1;
        int sz=0;
        if(query[x].size()>query[y].size())swap(x,y);
        for(auto &it:query[x]){
            if(query[y].count(it)){
                task[sz++]=it;
                query[y].erase(it);
            }
            else query[y].insert(it);
        }
        query[x].clear();
        if (rank[x] < rank[y])swap(x,y);
        if(query[x].size()==0)swap(query[x],query[y]);
        par[y] = x;
        if (rank[x] == rank[y])rank[x]++;
        return sz;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};
typedef tuple<LL,int,int> E;
int main(){
    int N,M,Q;
    cin>>N>>M;
    vector<E> e(M);
    REP(i,M){
        int s,t;LL c;
        cin>>s>>t>>c;
        e[i]=E(c,s,t);
    }
    sort(e.begin(),e.end());
    
    cin>>Q;
    REP(i,Q){
        cin>>S[i]>>T[i];
        query[S[i]].insert(i);
        query[T[i]].insert(i);
    }
    LL cost=0;
    UnionFind uf(N+1);
    REP(i,M){
        int a,b;LL c;
        tie(c,a,b)=(e[i]);
        int k=uf.unite(a,b);
        if(k==-1)continue;
        REP(i,k){
            res[task[i]]=c;
        }
        cost+=c;
    }
    REP(i,Q)cout<<cost-res[i]<<fin;
    
    return 0;
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[200001],b[200001];
vector<pint> c;
int main(){
    int n;
    cin>>n;
    int cnt=0;
    ll sum=0,sub=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        if(a[i]<=b[i]){
            if(a[i]==b[i])++cnt;
            sum+=b[i];
            sub+=b[i]-a[i];
        }
        else{
            c.pb(-b[i],a[i]-b[i]);
        }
    }
    sort(c.begin(),c.end());
    int m=c.size();
    rep(i,m){
        if(sub>c[i].second){
            sum+=-c[i].first;
            sub-=c[i].second;
        }
    }
    if(cnt==n) cout<<0<<endl;
    else cout<<sum<<endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<si> vsi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vsi> vvsi;


// bool sieve[100005];

// void sieveoferat()
// {
// 	for(ll p = 2; p*p<100005 ; p++)
// 	{
// 		if(sieve[p])
// 		{
// 			for(int j = p*p; j<100005; j+=p)
// 				sieve[j] = false;
// 		}
// 	}
// }

// void dp(sp_1, sp_2.....)
// {
// 	if()//exit statement
// 	if()//using the memoization 
// 	ll ans = //default/dummy answer
// 	//recursions
// 			//max/min
// 	return memo[][].. = ans;

// }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	cout.tie(NULL);
 	//memset(memo, -1, sizeof memo);
 	// memset(sieve, true, sizeof sieve);
 	// sieveoferat();
 	double w, h, x,y;
 	cin>>w>>h>>x>>y;
 	cout<<fixed<<setprecision(6)<<w*h/2<<" ";
 	
 	if(w/2==x && h/2==y)
 		cout<<1<<endl;
 	else
 		cout<<0<<endl;
 	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
    long n;
    cin >> n;
    vector<int> a(3 * n,0);
    long ans = 0;
    for(int i = 0;i < 3 * n;i++){
          cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i = 0;i < n;i++){
          ans += a[i * 2 + 1];
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 4224
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "c.cpp"

int main() {
  ll n;
  cin >> n;

  ll cnt = 0;
  ll sum = 0;
  ll x = 1;

  do {
    cnt++;
    x *= 26;
    sum += x;
  } while (n > sum);

  ll p = n-(sum-x)-1;

  vector<char> ans(cnt);
  rep(i, cnt) {
    ans[i] = 'a'+p%26;
    p /= 26;
  }

  per(i, cnt) {
    cout << ans[i];
  }
  cout << el;
}


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

int N, T;
int A[100000], B[100000] = {0}, C[100000];

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

    cin >> N >> T;
    for(int i=0; i<N; i++) cin >> A[i];
    B[N-1] = A[N-1];
    for(int i=N-2; i>=0; i--) {
        B[i] = max(A[i], B[i+1]);
    }
    int cmax = 0;
    for(int i=0; i<N; i++){
        C[i] = B[i] - A[i];
        cmax = max(cmax, C[i]);
    }

    int ans = 0;
    for(int i=0; i<N; i++)
        if(C[i] == cmax)
            ans++;

    cout << ans << endl;


	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
 int main()
{
 int i, n;
 int arr[100];
 scanf("%d", &n);
 for(i=0;i<n;i++)
{
 scanf(" %d", &arr[i]);
 }
 for(i=0;
i<n;
i++)
{
 if(i)printf(" ");
 printf("%d", arr[n-i-1]);
 }
 printf("\n");
 return 0;
 } 


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const int MAXV = 100005;
int P[MAXV];
int Find(int A) {
  if(P[A] < 0) return A;
  return Find(P[A]);
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }

  reverse(all(a));
  reverse(all(b));
  rep(j, n) P[j] = -1;

  vector<ll> ans(m);
  ans[0] = (ll)n * (n - 1) / 2;
  rep(i, m - 1) {
    ans[i + 1] = ans[i];
    int pa = Find(a[i]), pb = Find(b[i]);
    if(pa != pb) {
      ans[i + 1] -= (ll)P[pa] * P[pb];
      if(P[pa] > P[pb]) swap(pa, pb);
      P[pa] += P[pb];
      P[pb] = pa;
    }
  }

  reverse(all(ans));
  rep(i, m) printf("%lld\n", ans[i]);
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
struct line
{
    ll k, b;
    line() = default;
    line(ll kk, ll bb)
    {
        k = kk;
        b = bb;
    }
    ll eval(ll x)
    {
        return k * x + b;
    }
};
ld inter(line f, line s)
{
    return 1.0 * (s.b - f.b) / (f.k - s.k);
}
int n;
ll C, h[maxn], dp[maxn], siz, it;
line hull[maxn];
void add(line a)
{
    while(siz >= 2 && inter(hull[siz - 1], hull[siz - 2]) >= inter(hull[siz - 2], a))
        siz--;
    hull[siz++] = a;
}
ll get(ll x)
{
    while(it < siz && hull[it].eval(x) > hull[it + 1].eval(x))
        it++;
    return hull[it].eval(x);
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> C;
    for(int i = 0; i < n; i++)
        cin >> h[i];
    add(line(-2 * h[0], h[0] * h[0]));
    for(int i = 1; i < n; i++)
    {
        dp[i] = h[i] * h[i] + get(h[i]) + C;
        add(line(-2 * h[i], h[i] * h[i] + dp[i]));
    }
    cout << dp[n - 1] << "\n";
    return 0;
}


Measured memory_bytes: 6528
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut a: [usize; n+1],
        mut b: [usize; n],
    }
    let mut cnt = 0;
    for i in 0..n {
        let acc = min(a[i], b[i]);
        a[i] -= acc;
        b[i] -= acc;
        cnt += acc;
        let acc = min(a[i+1], b[i]);
        a[i+1] -= acc;
        cnt += acc;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 6396
/* ITP1_8_A */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();

      String str = br.readLine();

      for(char c : str.toCharArray()){
        if(Character.isUpperCase(c)){
          sb.append(Character.toLowerCase(c));
        }else if(Character.isLowerCase(c)){
          sb.append(Character.toUpperCase(c));
        }else {
          sb.append(c);
        }
      }
      System.out.println(sb);

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24268
H, W = map(int, input().split())
INF = H+W+W

grid = [[v for v in input()] for _ in range(H)]

dp = [[INF]*W for _ in range(H)]

DX = [0, 1]
DY = [1, 0]
##移動
dp[0][0] = 0

for x in range(H):
    for y in range(W):
        for dx, dy in zip(DX, DY):
            nx = x+dx#移動後
            ny = y+dy
            if 0 <= nx < H and 0 <= ny < W:
                if grid[x][y] == "." and grid[x][y] != grid[nx][ny]:
                    dp[nx][ny] = min(dp[nx][ny], dp[x][y]+1)
                else:
                    dp[nx][ny] = min(dp[nx][ny], dp[x][y])
if grid[0][0] == "#":
    dp[-1][-1] += 1
print(dp[-1][-1])


Measured memory_bytes: 3188
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int h, w;
        cin >> h >> w;
        if(h == 0)
            return 0;

        vector<string> s(h);
        for(int i=0; i<h; ++i)
            cin >> s[i];

        vector<int> height(w+1, 0);
        int ret = 0;
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                if(s[i][j] == '.')
                    ++ height[j];
                else
                    height[j] = 0;
            }
            stack<pair<int, int> > stk;
            stk.push(make_pair(0, w));
            for(int j=0; j<w+1; ++j){
                int k = j;
                while(height[j] < stk.top().first){
                    k = stk.top().second;
                    ret = max(ret, stk.top().first * (j-k));
                    stk.pop();
                }
                if(height[j] > stk.top().first)
                    stk.push(make_pair(height[j], k));
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
sx, sy, tx, ty = map(int, input().split())

res = ''

for _ in range(ty-sy):
    res += 'U'
for _ in range(tx-sx):
    res += 'R'

for _ in range(ty-sy):
    res += 'D'
for _ in range(tx-sx):
    res += 'L'

res += 'LU'
for _ in range(ty-sy):
    res += 'U'
for _ in range(tx-sx):
    res += 'R'
res += 'RD'

res += 'RD'
for _ in range(ty-sy):
    res += 'D'
for _ in range(tx-sx):
    res += 'L'
res += 'LU'

print(res)

Measured memory_bytes: 73156
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int n = sc.nextInt();
            int[] a = new int[n];
            long sum = 0;
            for(int i=0 ; i<n ; i++) {
                a[i] = sc.nextInt();
                sum += a[i];
            }

            int mod = 1_000_000_007;
            long ans = 0;
            for(int i=0 ; i<n ; i++) {
                sum -= a[i];
                ans += (a[i]*(sum%mod))%mod;
                ans %= mod;
            }

            pw.println(ans);

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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


Measured memory_bytes: 55488
#include <iostream>
using namespace std;
#define MOD 1000000007

int pow(int a, int n) {
  int res = 1;
  for (; n; n >>= 1) {
    if (n & 1) res = 1LL * res * a % MOD;
    a = 1LL * a * a % MOD;
  }
  return res;
}

int fact(int n) {
  int res = 1;
  for (int i = 1; i <= n; i++)
    res = 1LL * res * i % MOD;
  return res;
}

int comb(int p, int q) {
  int inv_fact_p = pow(fact(p), MOD-2);
  int inv_fact_q = pow(fact(q), MOD-2);
  int tmp = 1LL * inv_fact_p * inv_fact_q % MOD;
  return 1LL * tmp * fact(p+q) % MOD;
}

int main() {
  int x, y;
  cin >> x >> y;
  if ((x + y) % 3) {
    cout << 0 << endl;
    return 0;
  }
  int p = (y * 2 - x) / 3;
  int q = y - p * 2;
  if (p < 0 || q < 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << comb(p, q) << endl;
}

Measured memory_bytes: 256
#coding:utf-8
#1_2_D
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v

def shellSort(A, n):
    G = [1]
    while True:
        g = 3*G[0] + 1
        if g > n:
            break
        G.insert(0, g)
    m = len(G)
    for i in range(m):
        insertionSort(A, n, G[i])
    return [m, G]

n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
m, G = shellSort(A, n)
print(m)
print(" ".join(map(str, G)))
print(cnt)
print("\n".join(map(str, A)))

Measured memory_bytes: 127896
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    Edges=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=map(int,input().split())
        a-=1; b-=1
        Edges[a].append(b)
        Edges[b].append(a)
    m=int(input())
    C=[]
    for _ in range(m):
        u,v=map(int,input().split())
        u-=1; v-=1
        C.append((u,v))
    
    def normalized(u,v):
        return (min(u,v),max(u,v))
    def findpath(u,v,visited=None):
        if visited is None:
            visited=set()
        if u==v:
            return set()
        if u in visited:
            return None
        visited.add(u)
        for x in Edges[u]:
            P=findpath(x,v,visited)
            if P is not None:
                P.add(normalized(u,x))
                return P
    def set_path(Pairs,Paths):
        if len(Pairs)<=1:
            yield ((Pairs[0],),Paths[Pairs[0]])
            yield ((),set())
        else:
            for S,P in set_path(Pairs[1:],Paths):
                yield ((Pairs[0],)+S,P|Paths[Pairs[0]])
                yield (S,P)
    
    Paths={}
    for u,v in C:
        Paths[(u,v)]=findpath(u,v)
    ans=pow(2,(n-1))
    for S,P in set_path(C,Paths):
        l=len(S)
        if l<=0:
            continue
        c=pow(2,(n-1)-len(P))
        flag=1 if l%2==0 else -1
        ans+=flag*c
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 47452
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MAX 0x7f7f7f7f
#define maxn 200000+10
LL a[maxn];
LL sum[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    LL s=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        s+=a[i];
        sum[i]=sum[i-1]+a[i];//---
    }
    LL minn=MAX;
    for(int i=1;i<n;i++)
    {
        minn=min(minn,abs((LL)(s-sum[i]-sum[i])));//---
    }
    printf("%lld\n",minn);
}


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

using namespace std;

const int MaxN = 1e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int f(int x)
{
    int res = 0;
    while(x)
    {
        res += x % 10;
        x /= 10;
    }

    return res;
}

int main()
{
//    freopen("output.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    int ans = MOD;

    int n;
    cin >> n;

    for(int i = 1; i < n; ++i)
    {
        ans = min(ans, f(i) + f(n - i));
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define int long long int

using namespace std ;

const int N = 2e6 + 100 ;
int n , a[3][N] , dp[3][N];

int32_t main(){
	cin >> n ;
	for(int i = 0 ; i < n ; i++)cin >> a[0][i] >> a[1][i] >> a[2][i] ;
	dp[0][0] = a[0][0] ;
	dp[1][0] = a[1][0] ;
	dp[2][0] = a[2][0] ;
	for(int i = 1 ; i < n ; i++)
	for(int j = 0 ; j < 3 ; j++)
	dp[j][i] = a[j][i] + max(dp[(j + 1) % 3][i - 1] , dp[(j + 2) % 3][i - 1]) ;
	cout << max(max(dp[1][n - 1] , dp[2][n - 1]) , dp[0][n - 1]) ;
	return 0 ;
}
/*
#include <radman/roderc++.h>
                     ....._____
                 .~~~~~////////\\                                                                                           ...
              .:::::////////////\\                                          ....::////////..                              (/\\\\...
           .::::://////   \\\\///\\              .:::://                ..:::::///////////////.                           \\\\\$$$$$$
         \\\\\//////      \\\\///\\           //\\\//////             \\\\\////////////////////.                           ""\\$$$$$$$
         \\\\\////         \\\\////         |||||////////.            \\\\\/////     ~~~~~//////          ...                  "\$$$$
         \\\\\//\         ////|||/          \\\\\/////////            \\\\\//\       ~~~~~//////        (/\\\\...                   .
         \\\\\//\        ////|||/          |||||////*\\///.           \\\\\//\       ~~~~~//////        \\\\\$$$$$$                 .@@@@@.
         \\\\\//\       ////|||/           \\\\\///|\\\////           \\\\\//\       ~~~~~//////         ""\\$$$$$$$               @@@@////\
         \\\\\//\ ____---/|||/            |||||///|\\\\\///.          \\\\\//\       ~~~~~//////             "\$$$$                @@@@\///\
         \\\\\//\--|||||||_-'             \\\\\///|\\\\\////          \\\\\//\       ~~~~~//////                                  ,@@@@|///|
         \\\\\//\|||||_"-\\\\\           |||||///|  ~~~~~///.         \\\\\//\      ~~~~~//////     .@@@@.                    /@@@@@|/////
         \\\\\//\///"""\\\\\\\\          \\\\\///|~~~~[[[////.        \\\\\//\     ~~~~~//////      @@@@@@@@                ..@@@@@.//////
         \\\\\//\    \"""\\\\\\\        |||||///|~~[[[[["\////.       \\\\\//\    ~~~~~//////      '@@@@/////\       .:;@@@@@@@..///////"
         \\\\\//\      \"""\\\\\\       \\\\\///|[[[[*\\\\\////.      \\\\\//\   ~~~~~//////        *@@@\//////\@@@@@@@@..//////////"
         \\\\\//\       \:::\\\\/      |||||///|[[[*   \\\\\\///      \\\\\//\~~~~~///////'            *@@\/////////////////////"
         \\\\\//\        \___\\/       \\\\\///|*       \\\\\/"       \\\\\//\~~////////'                 **"///////////"""
         \\\\\//\                     |||||///|                       \\\\\//\///////"
         \\\\\//\                     \\\\\///|                       \\\\\//\////"
         \\\\\///                    |||||////|                       \\\\\////"
         \\\\\/"                     \\\\\///*                        \\\\\/"
                                     """""*
*/


Measured memory_bytes: 15360
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  int a,b,c;
  cin >> a;
  if(a == 1) {
    cout << "Hello World" << endl;
    return 0;
  }
  else 
    cin >> b >> c;
    cout << b+c << endl;
}

Measured memory_bytes: 3532
#include"bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


int main() {
	int A, B;
	cin >> A >> B;
	if ((A - (2 * B)) < 0)cout << 0 << endl;
	else cout << A - 2 * B << endl;

	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() {
   int X, N; cin >> X >> N;
   set<int> p;
   rep(i, 0, N) {
     int tmp; cin >> tmp;
     p.insert(tmp);
   }

   int ans;
   for (int i = 0;;i++) {
     if (!p.count(X - i)) {
       ans = X - i;
       break;
     }
     if (!p.count(X + i)) {
       ans = X + i;
       break;
     }
   }
   cout << ans << endl;
 }


Measured memory_bytes: 3636
import java.util.Scanner;


public class Main {
	static int[][] d ;
	static int N;
	static int W;
	static int[][] item;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		W = Integer.parseInt(sc.next());
		//d[i][j] := i-1番目までの品物の中から重さがj以下になるように選んだときの価値の最大値
		//			 ※i=0のとき、一つも品物を選んでいない。
		d = new int[N+1][W+1];
		
		for(int i=0; i<N; i++){
			for(int j=0; j<W+1; j++){
				d[i][j] = 0;
			}
		}
		item = new int[N][2];
		for(int i=0; i<N; i++){
			item[i][0] = Integer.parseInt(sc.next());
			item[i][1] = Integer.parseInt(sc.next());
		}
		
		for(int i=0; i<N; i++){
			for(int j=0; j<W+1; j++){
				if(i==0)d[i][j] = 0;
				if(item[i][1] > j){
					d[i+1][j] = d[i][j];
				}else{
					d[i+1][j] = Math.max(d[i][j], d[i][j-item[i][1]] + item[i][0]);
				}
			}
		}
		
		System.out.println(d[N][W]);
		
		sc.close();
	}

	
}



Measured memory_bytes: 32088
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k, t;
	cin >> k >> t;
	ll sum = 0, mx = 0;
	rep(i,t){
		ll a;
		cin >> a;
		chmax(mx, a);
		sum += a;
	}
	if(mx*2 <= sum) cout << 0 << endl;
	else{
		cout << mx*2 - sum - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
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 (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;

int main(){
    ll n,z,w;
    cin>>n>>z>>w;
    V vec(n);
    rep(i,n)cin>>vec[i];
    ll res=abs(vec[n-1]-w);
    if(n>=2)chmax(res,abs(vec[n-1]-vec[n-2]));
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,b,f,r,v,a[4][3][10]={};
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    a[b-1][f-1][r-1]+=v;
  }
  int j,k;
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",a[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3){
      printf("####################\n");
    }
  }
  return 0;
}


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

int main() {
    ll n;
    cin >> n;

    cout << (n*(n-1)/2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if(rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  REP(i, N) cin >> p[i];
  vector<int> x(M);
  vector<int> y(M);
  REP(i, M) cin >> x[i] >> y[i];
  UnionFind uf(N + 1);
  for(int i = 0; i < M; i++) {
    uf.unite(x[i], y[i]);
  }
  int ans = 0;
  for(int i = 0; i < N; i++) {
    if(uf.same(i + 1, p[i])) { ans++; }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
s = input()
if s == 'RRR':
    print(3)
elif s == 'RRS':
    print(2)
elif s == 'SRR':
    print(2)
elif s == 'SSR':
    print(1)
elif s == 'SRS':
    print(1)
elif s == 'RSS':
    print(1)
elif s == 'RSR':
    print(1)
else:
    print(0)


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int n;
  string s;
  cin >> n >> s;

  char now = s[0];
  int res = 1;
  rep (i, 1, n) {
    if (now != s[i]) {
      res++;
      now = s[i];
    }
  }

  cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: n,m,lMax,rMin,i
      integer(16),allocatable :: l(:),r(:)
      
      read*,n,m
      allocate( l(m),r(m) )
      do i = 1,m
        read*,l(i),r(i)
      end do
      
      
      
      rMin = minval( r )
      lMax = maxval( l )
      
      
      print*,max(0,rMin - lMax + 1)
      
      
      
      
      END PROGRAM

Measured memory_bytes: 3456
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int M = nextInt();
		Pair[] p = new Pair[M];
		ArrayList<Pair> list = new ArrayList<>();
		for(int i =0;i<M;i++){

			p[i]=new Pair(nextInt(),nextInt(),i);
			list.add(p[i]);
		}
		Collections.sort(list,Pair.getComparator());

		int cnt=0;
		int bef=-1;
		for(Pair x:list){
			if(bef!=x.N){
				cnt=0;
				bef=x.N;
			}
			cnt++;
			x.cnt=cnt;
		}
		PrintWriter pw = new PrintWriter(System.out);
		for(Pair x:p){
			pw.printf("%06d%06d\n",x.N,x.cnt);
		}
		pw.flush();
	}

	public static class Pair {
		int N;
		int V;
		int idx;
		int cnt;

		Pair(int N, int V,int idx) {
			this.N = N;
			this.V = V;
			this.idx=idx;
		}

		public int getN() {
			return N;
		}

		public int getV() {
			return V;
		}


		public int getIdx() {
			return idx;
		}

		public void setIdx(int idx) {
			this.idx = idx;
		}

		public static Comparator<Pair> getComparator() {
			return Comparator.comparing(Pair::getN).thenComparing(Pair::getV);
		}
		public static Comparator<Pair> getComparator2() {
			return Comparator.comparing(Pair::getIdx);
		}
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 69000
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

  string s;
  cin >> s;

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

  return 0;
}

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

import itertools

"""
・「必要」とは～～が存在
・x を含まない、[K-x,K) 内の総和が存在
・集合を指定すると、ある値段より上側
・全体としても単調性がある
"""

N,K,*A = map(int,read().split())

A = [x if x <= K else K + 1 for x in A]
A.sort()

mask = (1 << K) - 1

def test(x):
    # x番目は必要
    if A[x] > K:
        return True
    dp = 1
    for a in itertools.chain(A[:x], A[x+1:]):
        dp |= (dp << a)
        dp &= mask
    dp >>= (K - A[x])
    return (dp > 0)

left = -1 # 必要
right = N # 不要
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        right = x
    else:
        left = x

answer = left + 1
print(answer)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 105
int n, on;
int b[MN];
int ans[MN];

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

    cin >> n;
    on = n;
    FOR(i, 1, n){
        cin >> b[i];
    }
    int tog = -1;
    FOR(i, 1, on){
        tog = -1;
        RFOR(j, n, 1){
            if(b[j] == j){
                tog = j;
                break;
            }
        }

        if(tog == -1){
            cout << "-1\n";
            return 0;
        }

        //cout << "deleting " << tog << "\n";
        ans[i] = tog;
        FOR(j, tog, n-1){
            b[j] = b[j+1];
        }
        n--;
    }

    RFOR(i, on, 1){
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 896
N = int(input())
S = []
for _ in range(N):
    S.append(int(input()))
S.sort(reverse=True)   
AAA = sum(S)
for _ in range(len(S)):
    total = AAA
    if total % 10 == 0:
        total -= S.pop()
    if total % 10 != 0:
        print(total)
        break
else:
    print(0)

Measured memory_bytes: 3060
n,m,k=map(int,input().split(" "))
# a=list(map(int,input().split(" ")))
a=map(int,input().split(" "))
# b=list(map(int,input().split(" ")))
b=map(int,input().split(" "))

t=0
i=0
la=[]
for x in a :
    if t+x>k :
        break
    t+=x
    i+=1
    la.append(x)
# while i<n :
#     if t+a[i]>k :
#         break
#     t+=a[i]
#     i+=1

# j=0
# while j<m :
#     if t+b[j]>k :
#         break
#     t+=b[j]
#     j+=1
j=0
for x in b :
    # print("mk1 x=",x)
    if t+x>k :
        break
    t+=x
    j+=1

ans=i+j
while i>0 :
    i-=1
    t-=la[-1]
    la.pop(-1)
    if t+x>k :
        continue
    else:
        t+=x
        j+=1
    for x in b :
        # print("mk2 x=",x)
        if t+x>k :
            break
        t+=x
        j+=1
    # while j<m and t+b[j]<=k :
    #     t+=b[j]
    #     j+=1
    ans=max(ans,i+j)

print(ans)


Measured memory_bytes: 47292
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
	n=str(input())
	print(n.count('2'))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

int main()
{
  int q1,b,c1,c2,q2;
  for(;cin>>q1,q1;)
    {
      cin>>b>>c1>>c2>>q2;
      int ans1=-1,ans2;
      for(int i=1;i<=q2;i++)
	{
	  int money=b;
	  money-=i*c1;
	  if((money/c2)+i>=q1 && money>=0)
	    {
	      ans1=i;
	      ans2=money/c2;
	    }
	}
      if(ans1==-1)
	cout<<"NA"<<endl;
      else
	cout<<ans1<<" "<<ans2<<endl;
    }
}

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

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

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut map: Vec<Vec<i64>> = vec![];

    for _ in 0..h {
        let row: Vec<i64> = read::<String>()
            .chars()
            .map(|x| if x == '#' { -1 } else { 0 })
            .collect();
        map.push(row);
    }

    for i in 0..h {
        for j in 0..w {
            if map[i][j] == -1 {
                // above row
                if i > 0 {
                    if j > 0 {
                        if map[i - 1][j - 1] != -1 {
                            map[i - 1][j - 1] += 1;
                        }
                    }
                    if map[i - 1][j] != -1 {
                        map[i - 1][j] += 1;
                    }
                    if j + 1 < w {
                        if map[i - 1][j + 1] != -1 {
                            map[i - 1][j + 1] += 1;
                        }
                    }
                }

                // middle row
                if j > 0 {
                    if map[i][j - 1] != -1 {
                        map[i][j - 1] += 1;
                    }
                }
                if j + 1 < w {
                    if map[i][j + 1] != -1 {
                        map[i][j + 1] += 1;
                    }
                }
                // below row
                if i + 1 < h {
                    if j > 0 {
                        if map[i + 1][j - 1] != -1 {
                            map[i + 1][j - 1] += 1;
                        }
                    }
                    if map[i + 1][j] != -1 {
                        map[i + 1][j] += 1;
                    }
                    if j + 1 < w {
                        if map[i + 1][j + 1] != -1 {
                            map[i + 1][j + 1] += 1;
                        }
                    }
                }
            }
        }
    }

    for i in 0..h {
        let rowStr: String = map[i]
            .iter()
            .map(|x| {
                if *x == -1 {
                    '#'
                } else {
                    char::from_str(&x.to_string()).unwrap()
                }
            })
            .collect();
        println!("{}", rowStr);
    }
}


Measured memory_bytes: 2152
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE (1000000+50)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int main(void) {
    static char nstr[BUF_SIZE];
    // dp[digits][carry]
    static int dp[BUF_SIZE][2];
    nstr[0] = '0'; // guard
    get_str(&nstr[1], BUF_SIZE);
    int len = strlen(nstr) - 1;

    int i;
    int d0 = nstr[len-1] - '0';
    dp[1][0] = d0;
    dp[1][1] = 10 - d0;

#ifdef DEBUG
    printf("[%d] %d vs %d\n", 1, dp[1][0], dp[1][1]);
#endif

    for(i = 2; i <= len; i++) {
        int ch = nstr[len-i] - '0';
        dp[i][0] = min(
            dp[i-1][0] + ch,
            // carry
            dp[i-1][1] + (ch+1)
        );
        dp[i][1] = min(
            dp[i-1][0] + (10-ch),
            dp[i-1][1] + (9-ch)
        );
#ifdef DEBUG
        printf("[%d] %d vs %d\n", i, dp[i][0], dp[i][1]);
#endif
    }
    printf("%d\n", dp[len][0]);
    return 0;
}

Measured memory_bytes: 8960
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 5010
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,a[N],p[N],g[N],size[N],t;
ll sum[N],f[N][N];
struct data{int to,nxt;
}edge[N<<1];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void dfs(int k,int from)
{
	sum[k]=a[k];
    for (int i=p[k];i;i=edge[i].nxt)
    if (edge[i].to!=from)
	{
		dfs(edge[i].to,k);
		sum[k]+=sum[edge[i].to];
	}
    if (a[k]>0)
    {
        g[k]=0;
        for (int i=p[k];i;i=edge[i].nxt)
        if (edge[i].to!=from)
        {
            int x=g[edge[i].to];
            for (int j=0;j<=n;j++)
            if (f[edge[i].to][j]<0) {x=min(x,j+1);break;}
            g[k]+=x;
        }
    }
    f[k][0]=a[k];
    size[k]=1;
    for (int i=p[k];i;i=edge[i].nxt)
    if (edge[i].to!=from)
    {
        for (int j=size[k]+size[edge[i].to];j>=0;j--)
        {
        	f[k][j]+=sum[edge[i].to];if (j-g[edge[i].to]-1>=0) f[k][j]=min(f[k][j],f[k][j-g[edge[i].to]-1]);
        	for (int x=max(0,j-size[k]);x<=min(j,size[edge[i].to]);x++)
        	{
        		if (x) f[k][j]=min(f[k][j],f[k][j-x]+f[edge[i].to][x]);
        		if (x<j&&f[edge[i].to][x]<0) f[k][j]=min(f[k][j],f[k][j-x-1]);
        	}
        }
        size[k]+=size[edge[i].to];
    }
}
int main()
{
	/*freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);*/
    n=read();
    for (int i=1;i<=n;i++) a[i]=read();
    for (int i=1;i<n;i++)
    {
        int x=read(),y=read();
        addedge(x,y),addedge(y,x);
    }
    memset(g,42,sizeof(g));
    memset(f,42,sizeof(f));
    dfs(1,1);
    /*for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
    for (int i=1;i<=n;i++) cout<<g[i]<<' ';cout<<endl;
    cout<<endl;
    for (int i=1;i<=n;i++)
    {
    	for (int j=0;j<n;j++)
    	cout<<f[i][j]<<' ';
    	cout<<endl;;
    }
    for (int i=1;i<=n;i++) cout<<sum[i]<<' ';cout<<endl;*/
    int ans=g[1];
    for (int i=0;i<=n;i++) 
    if (f[1][i]<0) {ans=min(ans,i);break;}
    cout<<ans;
    return 0;
}
 

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

using namespace std;

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

  int n;
  string s;
  cin >> n >> s;
  vector<int> can(1000);
  vector<vector<int>> dp(n, vector<int>(10, -1));
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 10; ++j) {
      if (i != n - 1) {
        dp[i][j] = dp[i + 1][j];
      }
      if (s[i] - '0' == j) {
        dp[i][j] = i;
      }
    }
  }
  for (int i = 0; i < n - 2; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int k = 0; k < 10; ++k) {
        if (dp[i + 1][j] == -1 or dp[i + 1][j] == n - 1 or dp[dp[i + 1][j] + 1][k] == -1) {
          continue;
        }
        can[(s[i] - '0') * 100 + j * 10 + k] = true;
      }
    }
  }
  cout << accumulate(can.begin(), can.end(), 0);

  return 0;
}

Measured memory_bytes: 2432
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))
ans = 0
o = 1000000
for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < o:
        o = abs(a - (t - h[i] * 0.006))
        ans = i+1
print(ans)


Measured memory_bytes: 9020
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> a(3*n);
    rep(i,3*n) cin>>a[i];
    sort(all(a));
    ll sum=0;
    for(int i=n;i<3*n;i+=2) sum+=a[i];
    cout<<sum;
}

Measured memory_bytes: 5604
#include <iostream>
#include "math.h"
using namespace std;
int X;
int main()
{
   cin>>X;
   int j,res,temp;
   if(X<4) res=1;
   else 
   {
   	res=0;
   for(int i=2;i<=sqrt(X);i++)
   {
   	  j=2;
   	  temp=1;
   	  while(temp<X)
   	  {
   	  	temp=pow(i,j);
   	  	j++;
	  }
   	  if(temp>X) temp=pow(i,j-2);
   	  if(temp>res) res=temp;
   }
}
   cout<<res<<endl;
} 

Measured memory_bytes: 384
#include <stdio.h>
int main ()
{
    int d;
    scanf("%d",&d);
    if(d==25)
    {
        printf("Christmas");
    }
    else
    {
        printf("Christmas");
        while(25-d!=0)
        {
            printf(" Eve");
            d++;
        }
    }
     return 0;
}


Measured memory_bytes: 128
#import numpy as np
a = input()
b = input()
dp = [[0] * (len(b) + 1)  for i in range(len(a) + 1)]

for x in range(len(a)):
	for y in range(len(b)):
		if a[x] == b[y]:
			dp[x + 1][y + 1] = dp[x][y] + 1
		else:
			dp[x + 1][y + 1] = max(dp[x + 1][y], dp[x][y + 1])
		
x, y = len(a) - 1, len(b) - 1
s = ''
while (x >= 0 and y >= 0):
	if a[x] == b[y]:
		s = a[x] + s
		x -= 1
		y -= 1
	elif dp[x][y + 1] > dp[x + 1][y]:
		x -= 1
	else:
		y -= 1
		
print(s)


Measured memory_bytes: 112220