akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
long long mod = 1e9 + 7;
const int N = 3e5 + 500;

long long n, m, u, v, k, t, q, a, h;

pair <string, int> rest[N];

int val[N];

int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n >> k;
   for (int i = 1; i <= n; ++i) cin >> val[i];
   
   
   int best = 0;
   for (int i = 0; i <= n; ++i) {
      for (int j = n + 1; j > i; --j) {
         
         if (i + (n + 1 - j) > k) break;
         int cur = 0;
         vector <int> neg;
         for (int k = 1; k <= i; ++k) {
            cur += val[k];
            if (val[k] < 0) neg.push_back(val[k]);
         }
         for (int k = n; k >= j; --k) {
            cur += val[k];
            if (val[k] < 0) neg.push_back(val[k]);
         }
         sort(neg.begin(), neg.end());
         int rem = k - i - (n + 1 - j);
         //cout << i << " " << j << " " << rem << " " << cur << endl;
         for (int k = 0; k < min((int)neg.size(), rem); ++k) cur -= neg[k];
         best = max(best, cur);
      }
   }
   
   cout << best << endl;
}






Measured memory_bytes: 4992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            for (int i = 0; i < s.length() - 1; ++i) {
                if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }
}



Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using uint1024_t = mp::uint1024_t;
using namespace std;
void plus2(deque<int>&num,int i) {
		num[i] = 0;
		if (i == 0) {
			num.push_front(1);
			num.push_front(1);
		}
		else if (i == 1) {
			num[0] += 1;
			num.push_front(1);
		}
		else {
			num[i - 1] += 1;
			num[i - 2] += 1;
		}
}
void minus1(deque<int>&num, int i) {
		num[i] = 1;
		if (i == 0) {
			num.push_front(1);
		}
		else {
			num[i - 1] += 1;
		}
}
void plus3(deque<int>&num, int i) {
	if (i == 0) {
		num[i] = 1;
		num.push_front(1);
		num.push_front(1);
	}
	else if (i == 1) {
		num[i] = 1;
		num[0]+=1;
		num.push_front(1);
	}
	else {
		num[i] = 1;
		num[i - 1] += 1;
		num[i - 2] += 1;
	}
}
void plus22(deque<int>&num, int i) {
	num[i] = 1;
	num[i + 1] = 0;
}

int main() {
	int n;
	cin >> n;
	deque<int>num;
	if (n == 0) {
		num.push_back(0);
	}
	while (n != 0) {
		num.push_back(n % (-2));
		n /= -2;
	}
	
	reverse(all(num));
	rep(i, num.size()) {
		if (num[i] == -1) {
			minus1(num, i);
		}
	}
	bool flag = true;
	int j = 0;
	while(j<9) {
		flag = true;
		while (flag) {
			int count = 0;
			rep(i, num.size()) {
				if (num[i] == 2) {
					count++;
					plus2(num, i);
				}

			}
			if (count == 0 or 1) {
				flag = false;
			}
		}
		flag = true;
		while (flag) {
			int count = 0;
			rep(i, num.size()) {
				if (num[i] == 3) {
					count++;
					plus3(num, i);
				}
				else if (num[i] == 2 && num[i + 1] == 2) {
					plus22(num, i);
				}
			}
			if (count == 0 or 1) {
				flag = false;
			}
		}
		j++;
	}

	rep(i, num.size()) {
		cout << num[i];
	}
	cout << endl;
	
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    vector<int> s(N,0);
    int sum = 0;
    
    for(int i=0;i<N;i++){
        cin >> s[i];
        sum += s[i];}
    
    int x=sum%10;
    
    if (!x){
        int min =sum;
        
        for(int i=0;i<N;i++){
            if (s[i]%10 != 0 && s[i]< min)
                min = s[i]; }
        
        cout << (sum - min);
    }
    else
        cout << sum;
}




  
  
  

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

using namespace std;

int main(){

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

  for ( int i = a; i <= b; i++ ){
    
    if ( i / 10000 == i % 10 && ( i % 10000 ) / 1000 == ( i / 10 ) % 10 ){
      c++;
    }
  }
  cout << c << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
arr = [0]*(n+1)
ans = 0
mod = 10**9+7
for i in range(n):
  arr[i+1] += arr[i]+a[i]
  
for i in range(n):
  ans += (a[i]*(arr[n]-arr[i+1]))%mod
print(ans%mod)

Measured memory_bytes: 31440
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int N;
vector<int> A;

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> N;
    rep(i, 0, N) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }


    int L[N + 2], R[N + 2];
    L[0] = R[N + 1] = 0;

    rep(i, 0, N + 1) {
        L[i + 1] = gcd(L[i], A[i]);
    }

    for(int i = N; i >= 0; i--) {
        R[i] = gcd(R[i + 1], A[i]);
    }

    vector<int> m;
    rep(i, 0, N + 1) {
        m.push_back(gcd(L[i], R[i + 1]));
    }

    vsort_r(m);
    cout << m[0] << endl;




}


Measured memory_bytes: 2168
while True:
    H,W = [int(x) for x in input().split()]
    if (H,W)==(0,0): 
        break
    for i in range(H):
        if  i==0 or i==H-1:
            print("#"*W)
        else:
            print("#" + "."*(W-2) + "#")
    print("")


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


int main(){
	double x1, y1, x2, y2;
	double length;

	cin >> x1 >> y1 >> x2 >> y2;

	length = ((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1));
	length = sqrt(length);

	printf("%.5f\n", length);
	return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,c=0,d=0;
  cin>>n;
  vector<ll> a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
    if(a[i]>b[i]){
      c+=a[i]-b[i];
    }else if(a[i]+1<b[i]){
      d+=(b[i]-a[i])/2;
    }
  }
  cout<<(c>d?"No":"Yes")<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1l << 60;
static const ll MOD = 1e9 + 7;
typedef pair<int, int> P;

int N;

signed main() {
  cin >> N;
  vector<P> v(N);
  rep(i, N) {
    ll a, l;
    cin >> a >> l;
    v[i] = {a - l, a + l};
  }
  sort(all(v), [](P a, P b) { return a.second < b.second; });

  int res = 0;
  ll cur = -INF; // 現在選んでいる区間の中で最も右
  rep(i, N) {
    if (cur > v[i].first) continue; // 被るのは飛ばす
    ++res;
    cur = v[i].second;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main()
{
    ll s;
    cin >> s;
    ll ans=1;
    map<ll,ll> m;
    m[s]++;
    while(true){
        ans++;
        if(s%2==0){
            s/=2;
        }
        else{
            s=3*s+1;
        }
        if(m.count(s)){
            break;
        }
        else{
            m[s]++;
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
import sys
N = int(input())
A = list(map(int,input().split()))

A_lis = []
for a in A:
    if a%2 == 0:
        A_lis.append(a)
flag = 0
for a in A_lis:
    if (a%3==0 or a%5==0):
        flag += 1
if flag == len(A_lis):
    print('APPROVED')
    sys.stdout.flush 
else:
    print('DENIED')
    sys.stdout.flush 

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

using namespace std;

int dp[100009], *visited;

vector<vector<int>> G;

void dfs(int v){
	visited[v] = 1;
	for(auto u: G[v]){
		//cout<<"First: v = "<<v<<" u = "<<u<<" "<<dp[v]<<" "<<dp[u]<<"\n";
		if(!visited[u]) dfs(u);
		//cout<<"Return: v = "<<v<<" u = "<<u<<" "<<dp[v]<<" "<<dp[u]<<"\n";
		dp[v] = max(dp[v], 1+dp[u]);
	}
}

int main(){
	int n ,m, i, u, v;
	scanf("%d%d",&n,&m);

	for(i=0;i<=n;i++) dp[i] = 0;
	for(i=0;i<=n;i++) G.push_back(vector<int> ());

	visited = new int[n+1]{0};

	for(i=0;i<m;i++){
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
	}
	for(i = 1; i <= n; i++) {
		if(!visited[i])
		dfs(i);
	}
	int ans = 0;
	for(i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<s.size()/2;i++)
    {
        if(s[i]!=s[s.size()-1-i])
            cnt++;
    }
    cout<<cnt;

}


Measured memory_bytes: 3652
<?php
list($n, $k, $q) = explode(' ', trim(fgets(STDIN)));

$status = range(1, $n);
$status = array_flip($status);

$allLoser = 0;
foreach ($status as $key => $item) {
    $status[$key] = 0;
}
for($i = 0; $i < (int) $q; $i++){
    $winIndex = trim(fgets(STDIN));
//    foreach ($status as $loserIndex => $val) {
//        if ($loserIndex !== (int) $winIndex) {
//            $status[$loserIndex] --;
//        }
//    }
    $status[(int)$winIndex] ++;
    $allLoser --;
}

//echo $allLoser;
foreach ($status as $statusIndex => $value) {
//    echo $value;
    if(($value + ($k + $allLoser)) > 0) {
        echo 'Yes' . PHP_EOL;
    } else {
        echo 'No' . PHP_EOL;
    }
}

Measured memory_bytes: 12920
#include<stdio.h>
int m[]={2189,89,1232,866,1796,2603},a,b,c,d,r;char s[99];int main(){for(s[87]=1,s[78]=4,s[69]=3,s[83]=2;~scanf("%s",s);r+=a%3?b%3?(b+6-a)%6<3?2:5:3+!b:a?6:1)d=s[*s],*s<65?printf(r?"%d\n":0,r),a=c=r=0,b=1:d?d=d+c&3,a=m[a]>>3*d&7,b=m[b]>>3*d&7:c+=*s-76?1:3;}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

#define pb push_back
#define mp make_pair

#define mod 1000000007

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define vin(v, n) for (int i = 0; i < (int)(n); i++) cin >> (v)[i];
#define vout_sp(v, n) for (int i = 0; i < (int)(n); i++) cout << (v)[i] << " ";
#define vout_nl(v, n) for (int i = 0; i < (int)(n); i++) cout << (v)[i] << endl;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x, y;
    cin >> x >> y;
    ll mi = x*2;
    ll ma = x*4;
    if(y >= mi && y <= ma && y%2==0)
        cout << "Yes" << endl;
    else
        cout <<"No" << endl;
    }


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

struct LazySegTree {
    int B = 1;
    // check and change these for sure
    using S = int;
    vector<S> s;
    LazySegTree(int n) {
        while (B < n) B *= 2;
        // init tree
        s.resize(B * 2, INT_MAX);
    }
    void apply(int u, int x) {
        s[u] = min(s[u], x);
    }
    // *probably* dont need to change these
    template<class... T>
    void update(int u, int L, int R, int ql, int qr, T... x) {
        if (R <= ql || qr <= L) 
            return;
        if (ql <= L && R <= qr) {
            apply(u, x...);
            return;
        }
        int M = (L + R) / 2, lc = u << 1, rc = lc | 1;
        update(lc, L, M, ql, qr, x...);
        update(rc, M, R, ql, qr, x...);
    }
    template<class... T>
    void update(int l, int r, T... x) {
        update(1, 0, B, l, r, x...);
    }
    S query(int u, int L, int R, int i) {
        if (R - L == 1)
            return s[u];
        int M = (L + R) / 2, lc = u << 1, rc = lc | 1;
        if (i < M)
            return min(s[u], query(lc, L, M, i));
        else
            return min(s[u], query(rc, M, R, i));
    }
    S query(int i) {
        return query(1, 0, B, i);
    }
};

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    LazySegTree x(n), y(n);
    x.update(1, n - 1, n - 2);
    y.update(1, n - 1, n - 2);
    int64_t res = 0;
    while (q--) {
        int a, b;
        cin >> a >> b;
        if (a == 1) {
            int r = x.query(b - 1); 
            // cout << r << '\n';
            y.update(1, r + 1, b - 2);
            res += r;
        } else {
            int r = y.query(b - 1);
            // cout << r << '\n';
            x.update(1, r + 1, b - 2);
            res += r;
        }
    }
    int64_t N = n - 2;
    cout << N * N - res << '\n';
    return 0;
}

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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	
	static char s[], t[];
	static int dp[][];
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		s = fs.next().toCharArray(); t = fs.next().toCharArray();
		dp = new int[s.length+1][t.length+1];
		for(int i=1;i<s.length+1;i++) {
			for(int j=1;j<t.length+1;j++) {
				if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
				else {
					dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
		
		//復元
		String ans = dfs(s.length,t.length,"");
		StringBuffer sb = new StringBuffer(ans);
		System.out.println(sb.reverse());
	}
	static String dfs(int x,int y,String res) {
		if(x==0&&y==0)return res;
		else if(x==0) {
			return dfs(x,y-1,res);
		}
		else if(y==0) {
			return dfs(x-1,y,res);			
		}
		else{
			if(dp[x-1][y-1] + 1 == dp[x][y] && s[x-1]==t[y-1]) {
				return dfs(x-1,y-1,res+s[x-1]);
			}
			else {
				if(dp[x-1][y]>=dp[x][y-1]) return dfs(x-1,y,res);
				else  return dfs(x,y-1,res);
			}
		}
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 106452
n = int(input())
even = 0
if n % 2 == 0:
    even = 1

el = []
ol = []
#n偶数のとき逆順奇数列＋普通の偶数列
s = list(map(int,(input().split())))
for i in range(n):
    if i%2 ==0:#guusuu
        el.append(s[i])
    else:
        ol.append(s[i])
if even == 1:#偶数のとき
    ol.reverse()
    ol.extend(el)
    print(" ".join(map(str,ol)))
else:
    el.reverse()
    el.extend(ol)
    print(" ".join(map(str,el)))


Measured memory_bytes: 31120
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define dloop(i,a,b) for(ll i=a;i>=b;--i)
#define all(a) a.begin(),a.end()
#define lar 1000000007
#define pq priority_queue
#define pll pair<ll,ll>
#define ss second
#define ff first
#define pb push_back
#define ppb pop_back
#define umap unordered_map
#define ub upper_bound
#define lb lower_bound
#define br "\n"
#define sp " "

void solve(){
   ll a,b,c,d;
   cin>>a>>b>>c>>d;
   ll ans = -1e18;
   //cout<<ans;
    ans = max(ans,b*d);
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    ans = max(ans,a*c);
    cout<<ans<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}



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

int N, A[5000];
vector<int> edges[5000];

const int64_t INF = 1e18;
int64_t dp[5000][5001][2], sub[5001][2];
int num[5000];
void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}

void dfs(int i, int par){
    vector<pair<int, int>> children;
    for(int j : edges[i]) if(j != par){
        dfs(j, i);
        children.push_back({num[j], j});
    }
    sort(children.begin(), children.end());

    int sum = 1;
    dp[i][0][A[i] < 0] = A[i];
    for(auto& pr : children){
        int n = pr.first, j = pr.second;

        for(int n1=0; n1<sum; n1++){
            for(int n2=0; n2<n; n2++){
                for(int k1=0; k1<2; k1++){
                    for(int k2=0; k2<2; k2++){
                        chmin(sub[n1+n2][k1|k2], dp[i][n1][k1] + dp[j][n2][k2]);
                        if((k2==0 && dp[j][n2][k2] < INF) || dp[j][n2][k2] < 0) chmin(sub[n1+n2+1][k1], dp[i][n1][k1]);
                    }
                }
            }
        }

        sum += n;
        for(int n1=0; n1<sum; n1++) for(int k=0; k<2; k++){
            dp[i][n1][k] = sub[n1][k];
            sub[n1][k] = INF;
        }
    }

    num[i] = sum;
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    for(int j=0; j<N; j++) for(int k=0; k<2; k++){
        for(int i=0; i<N; i++) dp[i][j][k] = INF;
        sub[j][k] = INF;
    }

    dfs(0, -1);

    int ans = N-1;
    for(int n=0; n<N; n++){
        //for(int i=0; i<N; i++) cout << i << " " << n << " " << dp[i][n][0] << " " << dp[i][n][1] << endl;
        if(dp[0][n][0] < INF) ans = min(ans, n);
        if(dp[0][n][1] < 0) ans = min(ans, n);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 392192
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  ll ans = 0;
  ll req = a[0];
  for (int i = 1; i < n; i++) {
    if (req > a[i]) ans += req - a[i];
    else req = a[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4748
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	string h;
	cin >> h;
	int mon = h.length() - 7;
	if (h.length() == 7) {
		if (h == "keyence") {
			cout << "YES" << endl;
		}
		else { cout << "NO" << endl; }
		return 0;
	}
	for (int i = 0; i <= h.length() - mon; ++i) {
		if (h.substr(0, i) + h.substr(i + mon, h.length() - i - mon) == "keyence") {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

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

int main(){
    int n;
    string s;
    cin>>n>>s;
    ll rsum=0,gsum=0,bsum=0;

    rep(i,n){
        if(s[i]=='R'){
            rsum++;
        }else if(s[i]=='G'){
            gsum++;
        }else{
            bsum++;
        }
    }
    ll ans = rsum*gsum*bsum;

    ll mt=0;

    for(int i=1;i<n-1;i++){
        int mergin = min(i,n-1-i);
        for(int j=1;j<=mergin;j++){
            if(s[i-j]!=s[i]&&s[i]!=s[i+j]&&s[i-j]!=s[i+j]){
                mt++;     
            }
        }
    }
    cout<<ans-mt<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

vector<int> v;
vector<int> dp;

int f(int n,int k){

	if(n<=1) return 0;

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

	int a = INT_MAX;
	for(int i=1; i<=k; i++) {
		if(n-k>=1){
			a = min(a,f(n-i,k)+abs(v[n]-v[n-i]));
		}
		else{
			a = abs(v[n]-v[1]);
		}
	}
	return dp[n]=a;
}

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

    int n,k;
    cin>>n>>k;
    v.resize(n+1,0);
    dp.resize(n+1,-1);

    int ans = INT_MAX;
    for(int i=1; i<=n; i++) {
        cin>>v[i];
    }
    // dp[1]=v[1];
    // if(n>=2) dp[2]=abs(v[2]-v[1]);
	ans = min(ans,f(n,k));

	cout<<ans<<'\n';
    // for(auto i:dp){
    // 	cout<<i<<' ';
    // }
    return 0;
}

Measured memory_bytes: 8064
n = int(input())
h = list(map(int, input().split()))

c = []
c.append(0)
c.append(abs(h[0]-h[1]))
for i in range(2, n):
  c.append(min(abs(h[i]-h[i-1])+c[i-1], abs(h[i]-h[i-2])+c[i-2]))

print(c[-1])


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

int main(){
  int n, m;
  cin >> n >> m;
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(m);
  rep(i, m) cin >> x.at(i);
  sort(x.begin(), x.end());
  vector<int> dif(m-1);
  rep(i, m-1) dif.at(i) = abs(x.at(i+1) - x.at(i));
  sort(dif.begin(), dif.end());
  int ans = 0;
  rep(i, m-n) ans += dif.at(i);
  cout << ans << endl;
  
  
}

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

int main()
{
	vector<long long > DP(100000+5,INT_MAX);
	int n,k; cin>>n>>k;
	vector <long long> h(n+5);
	for (int i=0; i<n ;i++) cin>>h[i];
	DP[0] = 0;
	for(int i=1; i<n; i++)
	{
		for(int j=i-1; j>=max(i-k,0); j--)
		{
			DP[i]=min(DP[i],DP[j]+abs(h[i]-h[j]));
		}
		//cout<<DP[i]<<endl;
	}
	
	cout<<DP[n-1]<<endl;
	return 0;
}
	


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; ++i) cin >> s[i];
  vector<int> oz(n, -1);
  oz[0] = 0;
  queue<int> que;
  que.push(0);
  while(!que.empty()){
    int x = que.front();
    que.pop();
    for(int i=0; i<n; ++i){
      if(s[x][i] == '0') continue;
      if(oz[i] == -1){
        oz[i] = (oz[x] ? 0:1);
        que.push(i);
      }
      else if(oz[i] == oz[x]){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  vector<vector<int>> wf(n,vector<int>(n,INF));
  for(int i=0; i<n; ++i) for(int j=0; j<n; ++j){
    if(i == j) wf[i][j] = 0;
    else if(s[i][j] == '1') wf[i][j] = 1;
  }
  for(int k=0; k<n; ++k) for(int i=0; i<n; ++i) for(int j=0; j<n; ++j){
    wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
  }
  int ans = 0;
  for(int i=0; i<n; ++i) for(int j=0; j<n; ++j){
    ans = max(ans,wf[i][j]);
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 3856
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int n;
  cin >> n ;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  vector<int> c(n + 1);
  vector<vector <int> > dp(n + 1,vector<int> (3,0));

  for( int i = 1 ; i <= n ; i++ ){
    int ai,bi,ci;
    cin >> ai >> bi >> ci;
    a[i] = ai;
    b[i] = bi;
    c[i] = ci;
  }
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  for( int i = 1 ; i <= n ; i++ ){
    dp[i][0] = a[i] + max( dp[i-1][1] , dp[i-1][2] );
    dp[i][1] = b[i] + max( dp[i-1][0] , dp[i-1][2] );
    dp[i][2] = c[i] + max( dp[i-1][0] , dp[i-1][1] );
  }
  int ret01 = max( dp[n][0] , dp[n][1] );
  int ret = max( ret01 , dp[n][2] );
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  int n;  cin >> n;
  vector<ll> a(n),b(n),c(n);
  rep(i,0,n){
    cin >> a[i];
  }
  rep(i,0,n){
    cin >> b[i];
  }
  rep(i,0,n){
    cin >> c[i];
  }
  sort(all(a)); sort(all(b)); sort(all(c));
  ll ans = 0;
  rep(i,0,n){
    auto ite = lower_bound(all(a), b[i]) - a.begin();
    auto ite2 = upper_bound(all(c), b[i]) - c.begin();

    ans += (ite) * (n-ite2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228

#define tm tm228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll INF = 1e18, inf = 1e15;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, m; 
int deg[maxn]; 
vector<pii> tet; 

void solve() {
    cin >> n >> m; 
    for (int i = 0; i < n; ++i) deg[i] = 1;
    set<int> tet; 
    tet.insert(0); 
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b, --a, --b; 
        deg[b]++; 
        deg[a]--; 
        if (tet.count(a)) tet.insert(b); 
        if (deg[a] == 0) {
            if (tet.count(a)) tet.erase(a); 
        }
    }  
    cout << tet.size(); 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
} 

Measured memory_bytes: 9060
# 明日の天気を予測してください
S = input()

if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
elif S == 'Rainy':
    print('Sunny')
else:
    print('明日の天気を予測できませんでした。')

Measured memory_bytes: 9036
PROGRAM ATCODER

implicit none
integer :: i,n,k,s,t
real(8) :: ans=0.d0

read*, n,k

do i = 1, n, 1
  s = i
  t = 0
  do
    if ( s >= k ) exit
    s = s*2
    t = t + 1
  end do
  ans = ans + 0.5d0**t/real(n,8)
end do

write(*,'(i0,f0.10)') 0,ans

END PROGRAM ATCODER

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; 
	int S[10], C[10]; 
	cin >> N >> M;
	for(int i = 0; i < M; i++) cin >> S[i] >> C[i]; 
	if(N == 1){
		for(int i = 0; i <= 9; i++){
			bool ok = true; 
			for(int j = 0; j < M; j++){
				if(i != C[j]) ok = false; 
			}
			if(ok){
				cout << i << endl; return 0; 
			}
		}
	}
	if(N == 2){
		for(int i = 10; i <= 99; i++){
			bool ok = true; 
			for(int j = 0; j < M; j++){
				int a; 
				if(S[j] == 1) a = i / 10; 
				if(S[j] == 2) a = i % 10; 
				if(a != C[j]) ok = false; 
			}
			if(ok){
				cout << i << endl; return 0; 
			}
		}
	}
	if(N == 3){
		for(int i = 100; i <= 999; i++){
			bool ok = true; 
			for(int j = 0; j < M; j++){
				int a; 
				if(S[j] == 1) a = i / 100; 
				if(S[j] == 2) a = (i / 10) % 10; 
				if(S[j] == 3) a = i % 10; 
				if(a != C[j]) ok = false; 
			}
			if(ok){
				cout << i << endl; return 0; 
			}
		}
	}
	cout << -1 << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(void)
{
    using namespace std;
    
    string W, T;
    int i, cnt;

    cin >> W;
    for (i = 0; i < W.size(); ++i) {
        if (isupper(W[i])) {
            W[i] = tolower(W[i]);
        }
    }

    while (cin >> T) {
        if (T == "END_OF_TEXT") break;
        
        for (i = 0; i < T.size(); ++i) {
            if (isupper(T[i])) {
                T[i] = tolower(T[i]);
            }
        }
        
        if (T == W) {
            cnt++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1192
x = gets.chomp.to_i
y = Math.sqrt(x).to_i + 1
if x == 1 then
  puts 1
  exit
end

ans = 1
2.upto(y) do |i|
  a = i
  10.times do |j|
    a *= i
    if a > x then
      break
    elsif a > ans then
      ans = a
    end
  end
end
puts ans

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

int main(){
    vector<string> weather{"Sunny","Cloudy","Rainy"};
    string S;
    cin>>S;

    if(S=="Sunny"){
        cout<<weather[1]<<endl;
    }else if(S=="Cloudy"){
        cout<<weather[2]<<endl;
    }else{
        cout<<weather[0]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
let (n, k) = Scanf.scanf "%d %d\n" (fun n k -> (n, k))

let repeat f =
  let rec loop acc = function
    | 0 -> List.rev acc
    | n -> loop (f () :: acc) (n - 1) in
  loop []

let edges = repeat (fun () -> Scanf.scanf "%d %d\n" (fun a b -> (a-1, b-1))) (n-1)

let al = Array.make n []

let maxarea r =
  let rec area i j = function
    | 0 -> 1
    | r -> List.fold_left (fun a k -> a + (if k = i then 0 else area j k (r-1))) 1 al.(j) in
  let rec aux accu = function
    | 0 -> accu
    | k -> aux (max (area (k-1) (k-1) (r/2)) accu) (k-1) in
  if r mod 2 = 0 then aux 0 n
  else List.fold_left (fun a (i,j) -> max a ((area i j (r/2)) + (area j i (r/2)))) 0 edges

let () =
  List.iter (fun (a,b) -> al.(a) <- b :: al.(a); al.(b) <- a :: al.(b)) edges;
  print_int (n-(maxarea k))

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int a, b, c;
    cin >> a >> b >> c;

    // 処理
    // 出力
    if (a + b >= c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


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

#define F first
#define S second
#define ll long long
#define int long long
#define pb push_back
#define ld long double

using namespace std ; 

const int N = 1001 * 1001  , MOD = 1e9 + 7 ; 

int32_t main()
{
	ios::sync_with_stdio(0) ;cin.tie(0) ; 
	int x , y ; 
	cin >> x >> y ; 
	if(x%y==0) return cout << -1 << endl , 0 ; 
	cout << x << endl ; 
}	

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int D, T, S;
    cin >> D >> T >> S;

    int q = D / S;
    int r = D % S;
    int _ans = (r==0)? q : q+1;
    if(_ans <= T){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
	int i,g=0, n[5];
	for (i = 0; i < 5; i++)
	{
		cin >> n[i];
		if (n[i] >= 40)
			g = g + n[i];
		else
		{
			n[i] = 40;
			g = g + n[i];
		}
	}
	g /= 5;
	cout << g << endl;
	return 0;
}

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

int main () {
  int N;
  cin >> N;
  int A[N], B[N], C[N-1];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N-1; i++) {
    cin >> C[i];
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B[A[i]-1];
    if (A[i]-A[i-1] == 1 && A[i] != 1) {
      ans += C[A[i]-2];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n; cin >> n;
    vector<ll> v(100010, 0);
    REP(i, n){
        ll a; cin >> a;
        v[a]++;
    }
    ll res = -1;
    REP(i, 100005){
        ll tmp = v[i] + v[i+1] + v[i+2];
        res = max(res, tmp);
    }
    cout << res << endl;
}

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

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

#define ll long long
#define forr(i,n) for(ll i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

ll power(ll a,ll b){ll r=1;while(b--)r*=a;return r;}
const ll INF=1e17L+5;

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

    string s1,s2,s="";cin>>s1>>s2;
    int n1=s1.size(),n2=s2.size();
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,0));
    
    f(i,0,n1+1){
        f(j,0,n2+1){
            if(i==0 || j==0)dp[i][j]=0;
            else if(s1[i-1]==s2[j-1]){dp[i][j]=dp[i-1][j-1]+1;}
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }int i=n1,j=n2;
    while(i>0 && j>0){
        if(s1[i-1]==s2[j-1]){s+=s1[i-1];i--;j--;}
        else if(dp[i-1][j]>dp[i][j-1])i--;
        else j--;

    }
    rev(s);
    cs(s);

  }


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

int main(){
  string S;
  cin>>S;
  int n=S.size(),c=0,d=0;
  vector<string>v(n);
  vector<string>a(n);
  vector<string>b(n);
  for (int i=0;i<n;i++){
    v.at(i)=S.at(i);
    if (i%2==0){
      a.at(i)="0";
      b.at(i)="1";
    }
    else {
      b.at(i)="0";
      a.at(i)="1";
    }
  }
  for (int i=0;i<n;i++){
    if (v.at(i)!=a.at(i)){
      c++;
    }
    if (v.at(i)!=b.at(i)){
      d++;
    }
  }
  if (c>d){
    cout<<d<<endl;
  }
  else {
    cout<<c<<endl;
  }
}


Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int cnt[101010],par[101010];
vector<vector<int>> G(101010);


int main(){
  int N,M; cin>>N>>M;
  rep(i,N-1+M){
    int A,B; cin>>A>>B; A--,B--;
    cnt[B]++;
    G[A].push_back(B);
  }

  stack<int> st;
  rep(i,N) if(cnt[i]==0){
    par[i]=0;
    st.push(i);
  }
  while(st.size()){
    int i=st.top(); st.pop();
    for(int u:G[i]){
      cnt[u]--;
      par[u]=i+1;
      if(cnt[u]==0) st.push(u);
    }
  }
  rep(i,N) cout<<par[i]<<endl;
  return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}

ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int n;
    ll ans=0;
    cin >> n;
    vector<ll>a(n);
    vector<ll>left(n);
    vector<ll>right(n);
    rep(i,n) cin >> a[i];
    left[0]=a[0];
    right[n-1]=a[n-1];
    for(int i=1;i<n;i++){
        left[i]=gcd(left[i-1],a[i]);
    }
    for(int j=n-2;j>=0;j--){
        right[j]=gcd(right[j+1],a[j]);
    }
    rep(i,n){
        if(i==0){
            ll x=right[1];
            ans=max(ans,x);
        }
        else if(i==n-1){
            ll x=left[n-2];
            ans=max(ans,x);
        }
        else{
            ll left_gd=left[i-1];
            ll right_gd=right[i+1];
            ans=max(ans,gcd(left_gd,right_gd));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> K >> Q;
	UnionFind road(N);
	UnionFind train(N);
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		road.Unite(a, b);
	}
	for (int i = 0; i < Q; i++) {
		int a, b;
		cin >> a >> b;
		train.Unite(a, b);
	}
	map<pair<int, int>,int>m;
	for (int i = 1; i <= N; i++) {
		m[{road.Find(i), train.Find(i)}]++;
	}
	for (int i = 1; i <= N; i++) {
		if (i > 1)cout << " ";
		cout << m[{road.Find(i), train.Find(i)}] ;
	}
	cout << endl;
	return 0;
}




Measured memory_bytes: 15104
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll t[100001]={};

int main() {

	int n;
	ll x[100001];
	ll a,b;
	cin>>n>>a>>b;
	cin>>x[0];

	ll ans=0;
	for(int i=1; i<n; i++){
		cin>>x[i];
		t[i]=(x[i]-x[i-1])*a;
		t[i]=min(t[i],b);
		ans+=t[i];
	}
	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
/*cout<<setprecision(5)<<ret<<endl;で、数字部分を計5桁表示かつゼロ埋め無*/
/*cout<<fixed<<setprecision(5)<<ret<<endlで、小数部のみ5桁表示かつゼロ埋め有*/
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
/* [Shift+Command+b]（コンパイル）ー＞[Ctrl+Shift+`]（ターミナル起動）ー＞[./a.out] */

//////////////////
//  A
/*int main(void){
    int a,b;cin>>a>>b;
    double c=(double)(a+b)/2.0;
    if(c==(a+b)/2) cout<<(int)c<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

    return 0;
}*/
//////////////////
//  B
/*int main(void){
    int n;cin>>n;
    vector<int> v(n),w(n);
    rep(i,n){ cin>>v[i]; w[i]=v[i];}

    sort(v.begin(),v.end());
    int cnt=0;
    rep(i,n){
        if(v[i]!=w[i]){
            cnt++;
        }
    }
    if(cnt==0 || cnt==2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}*/
//////////////////
//  C 
int main(void){
    ll n;cin>>n;
    vector<ll> a(n+1);
    rep(i,n+1)cin>>a[i];

    ll ret=0LL;
    rep(i,n){
        ll b;cin>>b;
        if(a[i]>=b){
            ret+=b;
        }else{
            ll tmp=a[i+1];
            a[i+1]-=b-a[i];
            if(a[i+1]>=0LL){
                ret+=b;
            }else{
                ret+=a[i]+tmp;
                a[i+1]=0LL;
            }
        }
    }
    cout<<ret<<endl;
    return 0;
}
//////////////////
//  D
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3984
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    int a[4],b[4];
    int d[10];
    int n,m;
    while(scanf("%d",&a[0])!=EOF)
    {
        n=m=0;
        memset(d,0,sizeof(d));
        d[a[0]]++;
        for(int i=1; i<4; i++)
        {
            scanf("%d",&a[i]);
            d[a[i]]++;
        }
        for(int i=0; i<4; i++)
        {
            scanf("%d",&b[i]);
            if(a[i]==b[i])
                n++;
            else
            {
                d[b[i]]++;
                if(d[b[i]]==2)
                    m++;
            }
        }
        printf("%d %d\n",n,m);
    }
    return 0;
}

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

int main(){
    int r,g,b;
    cin >> r >> g >> b;
    int a;
    a = r*100 + g*10 + b;

    if(a%4 ==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256