akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;

const int maxn=105;
int cnt[maxn][30];
int acnt[30];
int main()
{
	int n;
	cin>>n;
	for(int j=0;j<30;j++) acnt[j]=INF;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		for(int j=0;j<s.length();j++)
			cnt[i][s[j]-'a']++;
		for(int j=0;j<30;j++)
			acnt[j]=min(acnt[j],cnt[i][j]);
	}
	string ans;
	for(int i=0;i<30;i++)
	{
		for(int j=0;j<acnt[i];j++)
			ans+=(i+'a');
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	int d, t, s;
	cin >> d >> t >> s;
	Yes(d <= t * s);
	return 0;
}

Measured memory_bytes: 3620
import itertools as it

n, m = list(map(int,input().split()))
nodes = [[] for _ in range(n)] 
for i in range(m):
    ai, bi = list(map(int, input().split()))
    nodes[ai-1].append(bi-1)
    nodes[bi-1].append(ai-1)
cnt = 0
for perm in it.permutations(range(1,n),n-1):
    i = 0
    ok = True
    for j in perm:
        if j not in nodes[i]:
            ok = False
            break
        i = j
    if ok:
        cnt += 1
            
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
int mod(int a){
if(a>=0)
    return a;
else return -a;
}



using namespace std;
int main(){
int n;
cin>>n;
vector<int> a;
a.resize(n);
for(int i=0;i<n;i++)
    cin>>a[i];
int b[n];
b[0]=0;
b[1]=mod(a[1]-a[0]);
for(int i=2;i<n;i++){
    b[i]=min(b[i-1]+mod(a[i]-a[i-1]),b[i-2]+mod(a[i]-a[i-2]));
}
cout<<b[n-1];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
	using namespace std;
	#define xxx ios::sync_with_stdio(),cin.tie(0),cout.tie(0)
	#define rep(i,n) for(int i=0;i<n;i++)
	#define int long long
	int powerof(int x, int n){
		int ans=0;
		while(x!=0){
			if(x%n==0) {x/=n;ans++;}
			else{
				return ans;
			}
		}
	}
	
	
	signed main(){
		int test=1;
		//cin>>test;
		while(test--){
			int n;
			cin>>n;
			string s[n];
			rep(i,n) cin>>s[i];
			int arr[4]={0};
			rep(i,n) {
				if(s[i]=="AC") arr[0]++;
				if(s[i]=="WA") arr[1]++;
				if(s[i]=="TLE") arr[2]++;
				if(s[i]=="RE") arr[3]++;
			}
			cout<<"AC x "<<arr[0]<<"\nWA x "<<arr[1]<<"\nTLE x "<<arr[2]<<"\nRE x "<<arr[3]<<endl;
		}
		return 0;
	}

Measured memory_bytes: 6752
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(2*b==a+c)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}
    

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    ll N, M, res;
	cin >> N >> M;
    res = 0;
    
    res += min(N, M/2);
    M -= res * 2;
    res += M / 4;
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
N,M,Q,*as=$<.read.split.map(&:to_i)
abcds = as.each_slice(4)

max = 0
(1..M).to_a.repeated_combination(N) do |arr|
    sum = 0
    abcds.each do |a,b,c,d|
        sum += d if arr[b-1] - arr[a-1] == c
    end
    max = sum if max < sum
end
puts max


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

using namespace std;

using ll = long long;

int a[3][3];
bool f[3][3];

bool check() {
    if (f[0][0] && f[1][1] && f[2][2]) return true;
    if (f[0][2] && f[1][1] && f[2][0]) return true;

    for (int i = 0; i < 3; ++i) {
        if (f[i][0] && f[i][1] && f[i][2]) return true;
        if (f[0][i] && f[1][i] && f[2][i]) return true;
    }

    return false;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (a[j][k] == b) {
                    f[j][k] = true;
                }
            }
        }
    }

    cout << (check() ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
input = input()
split = input.split()
pliceA = int(split[0])
pliceB = int(split[1])
pliceC = int(split[2])
neededA = int(split[3])
neededB = int(split[4])

maxC = neededA * 2 if neededA > neededB else neededB * 2
minPlice = 10 ** 10
for c in range(0, maxC + 1, 1):
    leftA = neededA - int(c / 2) if neededA - int(c / 2) > 0 else 0
    leftB = neededB - int(c / 2) if neededB - int(c / 2) > 0 else 0
    plice = leftA * pliceA + leftB * pliceB + pliceC * c
    minPlice = plice if plice < minPlice else minPlice

print(minPlice)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String str = sc.nextLine();
			str = str.replaceAll("apple", "1");
			str = str.replaceAll("peach", "2");
			str = str.replaceAll("1", "peach");
			str = str.replaceAll("2", "apple");
			System.out.println(str);
		}
	}
}


Measured memory_bytes: 26164
sa = input()
sb = input()
sc = input()

sa = sa.upper()
sb = sb.upper()
sc = sc.upper()

sa = list(sa)
sb = list(sb)
sc = list(sc)


#最初のターンはAから
turn = "A"
flag = False

while(not flag):
  if turn == "A":
    if len(sa) == 0:
      flag = True
    else:
      turn = sa[0]
      del sa[0]
  elif turn == "B":
    if len(sb) == 0:
      flag = True
    else:
      turn = sb[0]
      del sb[0]
  else :
    if len(sc) == 0:
      flag =True
    else:
      turn = sc[0]
      del sc[0]

print(turn)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	a = getchar();
	if (a == 'a' || a == 'e' || a == 'i' || a == 'o'|| a == 'u')
	{
		printf("vowel\n");
	}
	else
	{
		printf("consonant\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 100000000
#define inf 1e18 
 
using namespace std;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,k,i;
    cin>>n>>k;
    vi v(n+1);
    for(i=1;i<=n;i++) cin>>v[i];
    for(i=k+1;i<=n;i++)
    {
        if(v[i]>v[i-k]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4780
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

int main()
{
    LLONG N; cin >> N;
    if (N % 2 == 1)
    {
        cout << 0 << endl;
    }
    else
    {
        LLONG ans = 0;
        for (LLONG d = 10; d <= N; d *= 5)
        {
            ans += N / d;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,k,i,min;
  scanf("%d%d%d",&a,&b,&k);
  if(a<b){
    min=a;
  }else{
    min=b;
  }
  for(i=min;i>0;i--){
    if(a%i==0&&b%i==0){
      k--;
    }
    if(k==0){
      break;
    }
  }
  printf("%d",i);
  return 0;
}
    

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  char b;
  cin >> b;
  char ans;
  if (b == 'A')
    ans = 'T';
  else if (b == 'C')
    ans = 'G';
  else if (b == 'G')
    ans = 'C';
  else
    ans = 'A';
  cout << "" << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = 205, MOD = 998244353;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, x[MX], y[MX],u;
ll ans=1;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d%d", x+i, y+i);
	u = 1+n;
	rep(i,n) for(int j=i+1; j<n; j++){
		ll t=1, tx = x[j]-x[i], ty = y[j]-y[i];
		for(int k=j+1; k<n; k++) if(tx*(y[k]-y[i])-ty*(x[k]-x[i])==0) t = t*2%MOD;
		u = (u+t) % MOD;
	}
	for(ll b=2; n; n/=2, (b*=b)%=MOD) if(n&1) (ans *= b) %= MOD;
	printf("%lld\n", (ans+MOD-u)%MOD);
}

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

using namespace std;


void solve(){
    int n;
    cin >> n;
    int bad = 0;
    vector<int>test(n);
    for(int i = 0; i < n; ++i){
        cin >> test[i];
    }
    for(int i =0; i < test.size(); ++i){
        if(test[i] != (i+1)){
            ++bad;
        }
        if(bad > 2){
            cout << "NO" << endl;
            return;
        }
    }
    if(bad <= 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" <<endl;
    }
}

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


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] x = in.nextIntArray(n);

        long minCost = Long.MAX_VALUE / 10;
        for (int i = 1; i <= 100; i++) {
            long cost = calcCost(x, i);
            minCost = Math.min(minCost, cost);
        }

        out.println(minCost);
    }

    private static long calcCost(int[] x, int target) {
        long ret = 0;
        for (int i : x) {
            int dist = target - i;
            ret += dist * dist;
        }
        return ret;
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

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

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        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: 21716
#include <bits/stdc++.h>
using namespace std;

string D = "UDLR";
void fail(){
    cout << "NO" << endl;
    exit(0);
}

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    sr--; sc--;
    string Ss, Ts;
    cin >> Ss >> Ts;
    int S[200000], T[200000];
    for(int i=0; i<N; i++){
        S[i] = D.find(Ss[i]);
        T[i] = D.find(Ts[i]);
    }

    for(int t=0; t<2; t++){
        int add = 2*t+1, sub = 2*t;
        int start = (t==0 ? sr : sc);
        int X = (t==0 ? H : W);
        int mx = X-1, mn = 0;
        for(int i=N-1; i>=0; i--){
            if(T[i] == sub){
                mx = min(X-1, mx+1);
            }else if(T[i] == add){
                mn = max(0, mn-1);
            }
            if(S[i] == add){
                mx--;
            }else if(S[i] == sub){
                mn++;
            }
            if(mn > mx) fail();
        }
        if(!(mn <= start && start <= mx)) fail();
    }
    cout << "YES" << endl;
    return 0;
}


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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(const char* s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int64 s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    cout << "(";
    print(p.first, false);
    cout << ", ";
    print(p.second, false);
    cout << ")";

    if (endline) print();
}

template <typename T>
void print(T& t, bool endline = true) {
    cout << "[";
    for (auto it = t.begin(); it != t.end(); ++it) {
        if (it != t.begin()) cout << ", ";
        print(*it, false);
    }
    cout << "]";

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

bool c(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.first + a.second > b.first + b.second); 
} 

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    int64 n, k;
    cin >> n >> k;

    string s;

    cin >> s;

    vector<pair<int, bool>> arr;

    int cur = 1;

    for(size_t i = 1; i < s.size(); ++i) {
        if (s[i - 1] == s[i]) {
            cur += 1;
        } else {
            arr.push_back({cur, s[i - 1] == '1'});
            cur = 1;
        }
    }

    arr.push_back({cur, s[s.size() - 1] == '1'});

    vector<int> r_sum(arr.size(), 0);
    for(size_t i = 0; i < arr.size(); ++i) {
        if(i != 0) {
            r_sum[i] = r_sum[i-1] + arr[i].first;
        } else {
            r_sum[i] = arr[i].first;
        }
    }

    size_t i = 0, j = 0;
    int count = 0;
    int best = 0;
    int tmp = 0;

    while(j < arr.size()) {
        if(arr[j].second == 0) {
            count++;
        }

        if (count > k) {
            if(arr[i].second == 1) {
                i += 2;
            } else {
                i++;
            }
            count--;
        }

        if(i == 0) {
            tmp = r_sum[j];
        } else {
            tmp = r_sum[j] - r_sum[i - 1];
        }

        j++;

        best = max(tmp, best);
    }

    print(best);


    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int N;
int A[MAX], B[MAX];

int solve() {
    A[0] = B[0];
    FOR (i, 1, N-1) A[i] = min(B[i-1], B[i]);
    A[N-1] = B[N-2];
    int ans = 0;
    REP (i, N) ans += A[i];
    return ans;
}

int main() {
    cin >> N;
    REP (i, N-1) cin >> B[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;
#define MAXN 1002
int main(){
    int N;
    int T,A;
    int H[MAXN+1];
    cin >> N >> T >> A;
    for(int i=1;i<=N;i++){
        cin >> H[i];
        H[i] = abs(A*1000 - (T*1000-H[i]*6));
    }
    int num = 1;
    for(int i=2;i<=N;i++){
        if(H[num]>H[i]){
            num = i;
        }
    }
    cout << num << endl;
    return 0;

}

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

int main() {
  int a, b, c, k;
    cin >> a >> b >> c >> k;
    int xa = min(a, k);
    k -= xa;
    int xb = min(b, k);
    k -= xb;
    int xc = k;
    int ans = xa - xc;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
main = do
  n <- readLn :: IO Int
  [t, a] <- map read . words <$> getLine :: IO [Int]
  h <- map read . words <$> getLine :: IO [Int]
  let temperature x = 1000 * t - x * 6 :: Int
  let diff x = abs $ 1000 * a - temperature x :: Int
  let diff_indx = zip (map diff h) [1..n] :: [(Int, Int)]
  print $ snd (foldl min (head diff_indx) (tail diff_indx))

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int h = scan.nextInt();
		int m = scan.nextInt();

		// 時針 - 分針
		// 角度
		double rad = Math.PI * 2 * ((double)h / 12.0 + ((double)m / 60.0) / 12.0 - (double)m / 60.0);

		double rsq = (double)(a * a + b * b) - (double)(2 * a * b) * Math.cos(rad);


		System.out.println(Math.sqrt(rsq));
	}
}

Measured memory_bytes: 35832
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k; cin >> k;
	cout << a[k-1] << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<ll> v(N),u;
    rep(i,N){
        v[i] = S[i] - '0';
    }
    ll now = 1;
    ll cnt = 0;
    rep(i,N){
        if(v[i] == now){
            cnt++;
        }else{
            u.push_back(cnt);
            i--;
            cnt = 0;
            now = (now?0:1);
        }
    }
    if(now == 1){
        u.push_back(cnt);
    }else{
        u.push_back(cnt);
        u.push_back(0);
    }
    ll M = u.size();
    //PR(u,M);
    vector<ll> us(M+1,0);
    rep(i,M){
        us[i+1] = us[i] + u[i]; 
    }
    if(M <= K*2){
        cout << us[M] << endl;
        return 0;
    }
    ll ans = 0;
    rep(i,M-K*2){
        cmax(ans,us[i+K*2+1] - us[i]);
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5656
#!/usr/bin/env python3
import sys
INF = 1<<32

def solve(N: int, K: int, h: "List[int]"):
    dp = [INF] * (N+2)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])

    for i in range(N):
        for j in range(1, K+1):
            if(i+j < N):
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))

    print(dp[N-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53404
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
int main(){
	int W, H, N;
	cin >> W >> H >> N;
	int min_x = 0;
	int max_x = W;
	int min_y = 0;
	int max_y = H;
	rep(i, N){
		int x, y, a;
		cin >> x >> y >> a;
		if(a==1){
			min_x = max(min_x, x);
		}else if(a==2){
			max_x = min(max_x, x);
		}else if(a==3){
			min_y = max(min_y, y);
		}else if(a==4){
			max_y = min(max_y, y);
		}
	}
	if(min_x >= max_x || min_y >= max_y){
		cout << 0 << endl;
	}else{
		cout << (max_x - min_x) * (max_y - min_y) << endl;
	}
}

Measured memory_bytes: 256
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var max = 0;
  var add = 0;
  input.shift();
  for(var i = 0; i < N; i++){
    var tmp = myconv(input[i],4);
    if(max < tmp[0]){
       max = tmp[0];
       add = tmp[1];
    }
  }
  myout(max + add);
}
Main(myin());

Measured memory_bytes: 30336
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();

        StringBuilder sb = new StringBuilder();
        sb.append(S);
        if(S.charAt(S.length() - 1) != 's') {
            sb.append("s");
        } else {
            sb.append("es");
        }
        System.out.print(new String(sb));
    }
}



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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int MOD = 998244353, N = 305;
int dp[N][N][N][2], mn_suf[N], zero_on_suf[N];
bool dp2[N][N][N];

void add(int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

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

	string s;
	cin >> s;

	int n = s.size();

	for (int i = n - 1; i >= 0; i--) {
		zero_on_suf[i] = zero_on_suf[i + 1];
		if (s[i] == '0')
			zero_on_suf[i]++;
	}

	dp[0][0][0][0] = 1;
    dp[0][0][0][1] = 1;

	for (int i = 0; i < n; i++) {
		char c = s[n - 1 - i];

		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				for (int h = 0; h < 2; h++) {
					if (dp[i][j][k][h]) {

						if (c == '0' && h == 0) {
							add(dp[i + 1][j][k][h], dp[i][j][k][h]);
                            add(dp[i + 1][j][k][1], dp[i][j][k][h]);
						}
						else if (j < n) {
							add(dp[i][j + 1][k][h], dp[i][j][k][h]);
						}

						if (c == '1' && h == 0) {
							add(dp[i + 1][j][k][h], dp[i][j][k][h]);
                            add(dp[i + 1][j][k][1], dp[i][j][k][h]);
						}
						else if (k < n) {
							add(dp[i][j][k + 1][h], dp[i][j][k][h]);
						}
					}
				}
			}
		}
	}

	dp2[0][0][0] = true;

	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				if (dp2[i][j][k]) {
					int rem = n - i - j - k;
					for (int x = 0; x <= min(rem, 2); x++) {
						for (int p = 0; p <= min(2 - x, j); p++) {
							int q = 2 - x - p;

							if (q > k)
								continue;

							int nj = j - p, nk = k - q, z = 0;

							char oper[2];

							if (x > 0)
								oper[z++] = s[n - rem];
							if (x > 1)
								oper[z++] = s[n - rem + 1];

							if (p > 0)
								oper[z++] = '0';
							if (p > 1)
								oper[z++] = '0';

							if (q > 0)
								oper[z++] = '1';
							if (q > 1)
								oper[z++] = '1';

							for (int h = 0; h < 2; h++) {
								if (oper[h] == '0')
									dp2[i + 1][nj + 1][nk] = true;
								if (oper[h] == '1')
									dp2[i + 1][nj][nk + 1] = true;
							}
							
						}
					}
				}
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n; j++) {
			mn_suf[j] = N;
		}

		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				if (dp2[i][j][k]) {
					int suf = n - i - j - k;
					mn_suf[j + zero_on_suf[n - suf]] = 
						min(mn_suf[j + zero_on_suf[n - suf]], suf);
				}
			}
		}

        for (int j = 0; j <= n; j++) {
            if (mn_suf[j] != N) {
                int x = j - zero_on_suf[n - mn_suf[j]],
                    y = n - i - x - mn_suf[j];
                // cout << mn_suf[j] << " " << x << " " << y << " " << dp[mn_suf[j]][x][y][1] << "\n";
                add(ans, dp[mn_suf[j]][x][y][1]);
            }
        }
	}

	cout << ans << "\n";

	return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int maxA = *max_element(all(a));
  
  int ng = 0;
  int ok = maxA;
  
  while(abs(ok-ng) > 1 && ok > 2){
    int mid = (ok + ng)/2;
    int tmp = 0;
    rep(i,n){
      tmp += (a[i]+mid-1)/mid - 1;
    }
    if(tmp <= k) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 4036
#include <iostream>


using namespace std;

int main()
{
    int a,b,c,j=0,k=0;
    cin>>a>>b>>c;
    j=b-a;
    k=c-b;
    if(j==k)
    {
        cout<<"YES";
    }
    else
        {
            cout<<"NO";
        }
        return 0;
}


Measured memory_bytes: 256
N = int(input())
A = 0
Xmin = Ymin = 3e9 + 5
Xmax = Ymax = -3e9 - 5
for _ in range(N):
    x, y = map(int, input().split())
    X = x + y
    Y = x - y
    Xmin = min(Xmin, X)
    Xmax = max(Xmax, X)
    Ymin = min(Ymin, Y)
    Ymax = max(Ymax, Y)
if Xmin == 3e9 + 5:
    Xmin = Xmax
if Ymin == 3e9 + 5:
    Ymin = Ymax
if Xmax == -3e9 - 5:
    Xmax = Xmin
if Ymax == -3e9 -5:
    Ymax = Ymin
Z = max(Xmax - Xmin, Ymax - Ymin)
print(Z)

Measured memory_bytes: 70992
/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 22 August 2020 05:35:44 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;


void solve(){
    string s;
    cin>>s;
    int sum=0;
    for(int i=0; i<(int)s.length(); ++i){
        sum += (s[i]-'0');
    }
    if(sum%9 == 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

int32_t main(){
    IOS;
    //int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> a >> b;
       if(a+b>=24){
          Cout(a+b-24);
       }
       else{
           Cout(a+b);
       }
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define INT 1000000005 
#define vlli vector<lli>
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
lli dist[100005];
vector< pair<int,lli> > adj[100005];
 
void dfs(int node,int par,lli cost){
    dist[node]=cost;
    
    for(auto i:adj[node]){
        if(i.F==par) continue;
        dfs(i.F,node,cost+i.S);
    }
}
 
int main() 
{
    int n,x,y;
    lli cost;
    si(n);
    
    for(int i=0;i<n-1;i++){
        si(x);si(y);sli(cost);
        adj[x].pb(mp(y,cost));
        adj[y].pb(mp(x,cost));
    }
    
    int q,k;
    si(q);si(k);
    
    dfs(k,-1,0);
    
    while(q--){
        si(x);si(y);
        cout<<dist[x]+dist[y]<<endl;
    }
	return 0;
}

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

int main(void){

	int a,b;
	cin >> a >> b;
	if(a*b%2==0){
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}




	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  for(int i=0; i<a+b+1; i++){
    if(s[i] == '-' && i != a){
      cout << "No" << endl;
      return 0;
    }
    if(s[a] != '-'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;

vector<int> g[maxn];
int val[maxn];
int visited[maxn];

void dfs(int u) {
    visited[u] = true;
    for (auto x : g[u]) {
        if (!visited[x]) {
            val[x] += val[u];
            dfs(x);
        }
    }
}

void solve() {
    int n, q;
    cin >> n >> q;

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;

        val[a] += b;
    }
    dfs(1);
    for (int i = 1; i <= n; i++)cout << val[i] << " ";
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 22784
#include<cstdio>
#include<cstring>

int n, m;
char s[111];
int len;

bool chk() {
	if (len != n+m+1) return false;
	for(int i=0;i<n+m+1;i++) {
		if (i==n) {
			if (s[i] != '-') return false;
		} else {
			if (s[i]<'0' || s[i]>'9') return false;
		}
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	scanf("%s", s);
	len = strlen(s);
	
	puts(chk() ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	s := readString()
	S := s

	pop := func(i int) {
		s = s[0:i] + s[i+1:]
	}

	i := 1
	for {
		if i == len(s) {
			break
		}
		if i > 0 && s[i-1] != s[i] {
			pop(i)
			pop(i - 1)
			i = i - 1
			continue
		}
		if i < len(s)-1 && s[i] != s[i+1] {
			pop(i + 1)
			pop(i)
			continue
		}
		i++
	}

	fmt.Println(len(S) - len(s))
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func comb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 12160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			string s1 = "", s2 = "";
			while (((s1 = Console.ReadLine()) != null) && ((s2 = Console.ReadLine()) != null))
			{
				string[] la = s1.Split(' '), lb = s2.Split(' ');
				var a = new int[4];
				var b = new int[4];
				for (int i = 0; i < 4; i++)
				{
					a[i] = int.Parse(la[i]);
					b[i] = int.Parse(lb[i]);
				}
				int hit = 0, blow = 0;
				for (int i = 0; i < 4; i++)
				{
					if (a[i] == b[i])
					{
						hit++;
						continue;
					}
					for (int j = 0; j < 4; j++)
					{
						if (a[i] == b[j])
						{
							blow++;
						}
					}
				}
				Console.WriteLine("{0} {1}", hit, blow);
			}
		}
	}
}

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

int main()
{
    long long i, n, mx=0;
    map <string, long long> m;
    string s;

    cin>>n;

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

    for(auto p : m)
    {
        mx = max(mx, p.second);
    }

    for(auto p : m)
    {
        if(mx==p.second)
        {
            cout<<p.first<<endl;
        }
    }
    //cout<<mx<<endl;

    return 0;
}


Measured memory_bytes: 25216
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;<n;i++)
#define int64 long long 
using namespace std;

int main(){
  int64 a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k%2==0){
    cout<<a-b<<endl;
  }else{
    cout<<b-a<<endl;
  }
}

Measured memory_bytes: 256
// atcoder/abc163/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

const int N = 2000 + 5;
lli memo[N][N];
vec<pair<lli, int>> v;
int n;
lli rec(int i, int j)
{
  lli& ret = memo[i][j];
  if (ret != -1) return ret;
  unless (i <= j) return 0;

  const int k = i + (v.size() - j - 1);

  lli a = rec(i + 1, j) + v[k].first * abs(v[k].second - i);
  lli b = rec(i, j - 1) + v[k].first * abs(v[k].second - j);

  return ret = max(a, b);
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  while (cin >> n) {
    vec<lli> a(n);
    cin >> a;

    v.clear();
    for (int i = 0; i < a.size(); ++i) {
      v.push_back(make_pair(a[i], i));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    fill(&memo[0][0], &memo[N - 1][N - 1] + 1, -1);
    cout << rec(0, a.size() - 1) << endl;
  }

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = 0;
  ans += min(a, k);
  k -= a;
  chmax(k, 0ll);

  k -= b;
  chmax(k, 0ll);

  ans -= k;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
n = int(input())

a = []
ans = 0
for i in range(2,int(n**0.5)+1):
    count = 0
    while n%i==0:
        n/=i
        count+=1
    if count!=0:
        for j in range(1,count+10):
            if j*(j+1)/2>count:
                ans+=j-1
                break
if n!=1:
    ans+=1
print(ans)

Measured memory_bytes: 63692
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

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 long long INF = 1LL << 60;

int N;
long long h[100060];
long long dp[100060];

int main () {
    long N; cin >> N;

    long sub26 = N / 26;

    char col[17];

    long i = 0;
    while(N>0) {
        N-=1;
        col[i]=('a'+ N % 26);
        N = N/26;
        i++;
    }
    /*
    for (int i = 0; i <= sub26; i++)
    {
        int mod26 = N % 26;
        col[i] = 'a'+mod26-1;28
        N-=pow((float)N, 26.0);
    }
    */
    reverse(col,col+i);
    for (long j = 0; j < i; j++)
    {
        cout << col[j];
    }

    cout << endl;

    return 0;

}

Measured memory_bytes: 3592
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    mut a:[usize; 3]
    }
    a.sort();
    let ans = a[0] * a[1] / 2;
    println!("{}", ans);

}


Measured memory_bytes: 2132
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n;
	cin>>n;
	int a[n+1],b[n+1],c[n+1];
	rep(i,n)cin>>a[i+1];
	rep(i,n)cin>>b[i+1];
	rep(i,n-1)cin>>c[i+1];
	int ans=0;
	a[0]=-2;
	for(int i=1;i<=n;i++){
		ans+=b[a[i]];
		if(a[i]==a[i-1]+1)ans+=c[a[i-1]];
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int INF=1e9;
struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
};
struct data{
    int At,cost,cnt;
    data(int a,int b,int c):At(a),cost(b),cnt(c){}
    bool operator>(const data &d)const{
        return (cost>d.cost);
    }
};
int main(){
    int c,n,m,s,d;
    while(cin>>c>>n>>m>>s>>d){
        if(!(c||n||m||s||d))break;
        s--;d--;
        vector<vector<edge> >V(n);
        vector<vector<int> >D(n,vector<int>(c+1,INF));
        for(int i=0;i<m;i++){
            int a,b,f;
            cin>>a>>b>>f;
            a--;b--;
            V[a].push_back(edge(b,f));
            V[b].push_back(edge(a,f));
        }

        priority_queue<data,vector<data>,greater<data> >Q;
        Q.push(data(s,0,0));

        while(!Q.empty()){
            data latte=Q.top();Q.pop();
            int At=latte.At,cost=latte.cost,cnt=latte.cnt;
            if(cnt>c)continue;
            if(D[At][cnt]<cost)continue;
            D[At][cnt]=cost;
            for(int i=0;i<V[At].size();i++){
                edge e=V[At][i];
                Q.push(data(e.to,cost+e.cost,cnt));
                Q.push(data(e.to,cost+e.cost/2,cnt+1));
            }
        }
        cout<<*min_element(D[d].begin(),D[d].end())<<endl;
    }
    return 0;
}

Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string t;
    cin >> n;
    set<string> s;
    for(int i=0;i<n;i++){
    	cin >> t;
    	s.insert(t);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 19200
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
 
n = int(input())
g = [[]for i in range(n)]
for i in range(n-1):
        a,b=map(int,input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)
c = list(map(int,input().split()))
kyo = [float("inf")] * n
def dfs(x,y,z):
  kyo[x] = y
  for i in g[x]:
    if i == z:
            continue
    dfs(i,y+1,x)
dfs(0,0,-1)
kyo2 = []
for i in range(n):
        kyo2.append([kyo[i],i])
ans = [0]*n
kyo2.sort()
kyo2 = kyo2[::-1]
c.sort()
for i in range(n):
        ans[kyo2[i][1]] = c[i]
print(sum(c)-c[-1])
print(*ans)

Measured memory_bytes: 15896
K, N = map(int, input().split())
A = list(map(int, input().split()))
max_dist = 0

for i in range(N):
  if i == N - 1:
    dist = A[0] + K - A[i]
  else:
    dist = A[i+1] - A[i]
  
  if dist > max_dist:
    max_dist = dist
    
print(K - max_dist)

Measured memory_bytes: 26060
import random
d=int(input())
c=list(map(int,input().split()))
num=[0]*26
ans=[]
numans=0
s=[]
for i in range(1,d+1):
    num1=1
    num2=-(10**100)
    num3=[0]*26
    for j in range(26):
        num3[j]=-1*((i-num[j])*c[j])
    s.append(list(map(int,input().split())))
    for j in range(26):
        num5=s[i-1][j]-num3[j]
        if num5>num2:
            num1=j+1
            num2=num5
    ans.append(num1)
    numans+=num2+s[i-1][num1-1]
    num[num1-1]=i
def sco(n1,n2,n3):
    n0=0
    n01=[0]*26
    old=ans[n1]
    ans[n1]=n2
    for k in range(n3):
        n0+=s[k][ans[k]-1]
        n01[ans[k]-1]=k+1
        for l in range(26):
            n0-=(k+1-n01[l])*c[l]
    return n0
for i in range(1540):
    num6=random.randint(1,26)
    num7=random.randint(2,364)
    num100=sco(num7-1,num6,d)
    if num100>numans:
        ans[num7-1]=num6
for i in range(d):
    print(ans[i])


Measured memory_bytes: 9740
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int N, W;
struct Item {
	int v;
	int w;
};
int C[10005];
Item items[102];
int main() {
	int v,w;
	
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &v, &w);
		items[i].v = v;
		items[i].w = w;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = W; j >= 1; j--) {
			if (j - items[i].w >= 0) {
				C[j] = max(C[j], C[j - items[i].w] + items[i].v);
			}
		}
	}
	cout << C[W] << endl;
	return 0;
}


Measured memory_bytes: 3276