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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;

int n, m, c[11];
int ans;

void rec(int i, int mm, int sum) {
	if (i == n) {
		ans = min(ans, sum);
		return;
	}
	
	for_(j,0,10) {
		if (mm - c[j] >= 0) rec(i + 1, mm - c[j], 10 * sum + j);
	}
}

void solve() {
	ans = (int)1e9;
	rec(0, m, 0);
	if (ans == (int)1e9) cout << "NA" << endl;
	else {
		vector<int> outs;
		for_(i,0,n) {
			outs.push_back(ans % 10);
			ans /= 10;
		}
		for_(i,0,n) {
			if (i < n - 1) cout << outs[n - i - 1];
			else cout << outs[n - i - 1] << endl;
		}
	}
}

int main() {
	cin >> n >> m;
	for_(i,0,10) cin >> c[i];
	solve();
	return 0;
}


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

const int N = 200005;
map<int,int> mp;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	long long ans = 0;
	for(int i=1;i<=n;i++){
		int h;
		cin>>h;
		ans += mp[i-h];
		mp[i+h]++;
	}
	cout<<ans;
	
	return 0;
}


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

namespace ConsoleApp11
{
    class Class68
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int count4 = a.Count(x => x % 4 == 0);
            int count2 = a.Where(x => x % 4 != 0).Count(y => y % 2 == 0);
            int test = count4 + count2 / 2;
            Console.WriteLine(test >= N /2? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 21728
using System;
using System.Linq;

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var count = 0;
            var lastindex = n-1;

            while (lastindex > 0)
            {
                for (int i = 0; i < lastindex; i++)
                {
                    if (inputs[i] > inputs[i + 1])
                    {
                        var t = inputs[i];
                        inputs[i] = inputs[i + 1];
                        inputs[i + 1] = t;

                        count++;
                    }
                }

                lastindex--;
            }

            Console.WriteLine(string.Join(" ", inputs.Select(s => s.ToString()).ToArray<string>()));
            Console.WriteLine(count);
        }
    }
}

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

int main(){
  int N, K, sum = 0;
  cin >> N >> K;
  for(int i = 0;i < N;i++){
    int x;
    cin >> x;
    if((K - x) < x)
      sum += (K - x);
    else
      sum += x;
  }
  cout << (sum * 2) << endl;
}

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

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

	string s; cin >> s;
	int n = s.size();
	int k; cin >> k;

	set<string> sub;
	REP(i, n) for (int j = 1; j <= k; j++) {
		sub.insert(s.substr(i, j));
	}

	int i = 0;
	for (auto x : sub) {
		i++;
		if (i == k) {
			cout << x << '\n';
			return 0;
		}
	}
    return 0;
}


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

int main(){
    int N,K; cin >> N >> K;
    vector<int> h(N+100,0); for(int i = 0; i < N; i++) cin >> h.at(i);
    
    vector<int> dp(N+110,INF);
    dp.at(0) = 0;
    for(int i = 0; i < N; i++){
        for(int j = 1; j <= K; j++){
            int dc = dp.at(i) + abs(h.at(i+j) - h.at(i));
            dp.at(i+j) = min(dp.at(i+j), dc);
        }
    }
    cout << dp.at(N-1) << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<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 N;
    cin >> N;

    vl A(N);
    rep(i, N) cin >> A[i];

    ll st = 0;
    ll mo = 1000;
    ll min_v, max_v;
    rep(i, N) {
        // cout << "i: " << i << endl;
        min_v = A[i];
        max_v = A[i];
        FOR(j, i+1, N) {
            if (min_v >= A[j]) {
                min_v = A[j];
            }
            if (((j+1 < N && A[j+1] < A[j]) || j+1 == N) && A[j] > min_v) {
                max_v = A[j];
                st = mo / min_v;
                mo += ((max_v - min_v) * st);
                i = j;
                break;
            }
        }
    }

    cout << mo << endl;

    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(){
  int i,j;
  int n,d[100000],p[100000],f,s,b,t;
  for(n=0;;n++){
    scanf("%d,%d",&d[n],&p[n]);
    if(d[n]==0&&p[n]==0)
      break;
  }
  do{
    f=0;
    for(i=1;i<n;i++){
      if(p[i-1]<p[i]){
	s=p[i-1];
	p[i-1]=p[i];
	p[i]=s;
	s=d[i-1];
	d[i-1]=d[i];
	d[i]=s;
	f=1;
      }
    }
  }while(f);
  while(scanf("%d",&b)!=-1){
    for(i=0;i<n;i++){
      if(d[i]==b){
	t=p[i];
	break;
      }
    }
    j=1;
    for(i=0;i<n;i++){
      if(i)
	if(p[i-1]>p[i])
	  j++;
      if(p[i]==t){
	printf("%d\n",j);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

ans = []
for r in range(H):
    for c in range(W - 1):
        if a[r][c] % 2 == 1:
            a[r][c + 1] += 1
            ans.append((r, c, r, c + 1))

for r in range(H - 1):
    if a[r][W - 1] % 2 == 1:
        a[r + 1][W - 1] += 1
        ans.append((r, W - 1, r + 1, W - 1))
print(len(ans))
for aa in ans:
    print(*map(lambda x: x + 1, aa))


Measured memory_bytes: 22956
// #includes {{{
#include <bits/stdc++.h>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

Int X;

int main(){
	Int s = 0;
	cin>>X;
	for(Int i=1;;i++){
		s+=i;
		if(X<=s){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; string s;
	cin >>n >>s;
	
	string s1=s.substr(0,n), s2=s.substr(n,n);
	//dbg(s,s1,s2);
	
	unordered_map<string, int> mp; mp.reserve((1<<n)+100);
	rep(i,1<<n){
		string ky,vl;
		rep(j,n) (i>>j&1? ky: vl ) +=s1[j];
		mp[ky+":"+vl]++;
	}
	//for(auto x :mp) printf("%s:%d, ",x.first.c_str(),x.second); puts("");
	ll ans =0;
	reverse(all(s2));
	rep(i,1<<n){
		string ky,vl;
		rep(j,n) (i>>j&1? ky: vl ) +=s2[j];
		ans += mp[ky+":"+vl];
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 63368
import math
n = int(input())

class point:
    x = 0
    y = 0

def kock(k, p1, p2):
    s = point()
    t = point()
    u = point()
    if k == 0:
        return
    s.x = (2*p1.x+p2.x)/3
    s.y = (2*p1.y+p2.y)/3
    t.x = (p1.x+2*p2.x)/3
    t.y = (p1.y+2*p2.y)/3
    u.x = (t.x-s.x)*math.cos(math.radians(60))-(t.y-s.y)*math.sin(math.radians(60))+s.x
    u.y = (t.x-s.x)*math.sin(math.radians(60))+(t.y-s.y)*math.cos(math.radians(60))+s.y
    kock(k-1, p1, s)
    print(s.x, s.y)
    kock(k-1, s, u)
    print(u.x, u.y)
    kock(k-1, u, t)
    print(t.x, t.y)
    kock(k-1, t, p2)


a = point()
b = point()
b.x = 100
print(a.x, a.y)
kock(n, a, b)
print(b.x, b.y)


Measured memory_bytes: 5776
import re
S = input()

if re.search(r'^k.*eyence$', S) or \
   re.search(r'^ke.*yence$', S) or \
  re.search(r'^key.*ence$', S) or \
  re.search(r'^keye.*nce$', S) or \
  re.search(r'^keyen.*ce$', S) or \
  re.search(r'^keyenc.*e$', S) or \
  re.search(r'^.*keyence$', S) or \
  re.search(r'^keyence.*', S) or \
  S == 'keyence':
    print('YES')
else:
  print('NO')

Measured memory_bytes: 3188
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int K;
    cin >> K;
    ll ans = 0;
    REP(i, 1, K + 1) {
        REP(j, 1, K + 1) {
            REP(k, 1, K + 1) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int l0=2;
int l2=1;

int pl(int p,int q){
 return p+q; 
}
 
int main() {
  int64_t x;
  int a;
  cin >> a;
  int64_t p= 2;int64_t q=1;
  x = q ;
  for(int i=0;i<a-1;i++){
    x = p+q;
    p = q;
    q = x;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int D;
vector<int> c(26);
vector<vector<int>> s;

int scoring(const vector<int>& t) {
    int v = 0;
    vector<int> last(26, -1);
    rep(i, D) {
        v += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) {
            v -= c[j] * (i - last[j]);
        }
    }
    return v;
}

// int diff_scoring(const vector<int>&t, int v, int to_d, int to_t) {
//     int last = -1;
//     rep(i, D) {
//         if (t[i] == to_t) v -= s[i][t[i]], last = i;
//         v += c[to_t] * (i - last)
//     }
//     last = -1;
//     rep(i, D) {
//         if (i == to_d || t[i] == to_d) {
//             v += s[i][t[i]], last = i;
//         }
//         v -= c[to_t] * (i - last);
//     }
//     return v;
// }

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

    auto start = chrono::system_clock::now();
    
    cin >> D;
    rep(i, 26) cin >> c[i];
    s.resize(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> t(D);

    rep(i, D) {
        t[i] = max_element(all(s[i])) - s[i].begin();
    }
    
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand_d(0, D-1);
    uniform_int_distribution<> rand_t(0, 25);
    
    int v = scoring(t);
    int x = 0;
    while (true) {
        int to_d = rand_d(mt);
        int to_t = rand_t(mt);
        if (t[to_d] == to_t) continue;
        int old = t[to_d];
        t[to_d] = to_t;
        if (!chmax(v, scoring(t))) {
            t[to_d] = old;
        }
        x++;
        if (x % 1000 == 0) {
            auto end = chrono::system_clock::now();
            auto dur = end - start;
            auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
            if (msec >= 1980) break;
        }
    }
    
    rep(i, D) cout << t[i] + 1 << '\n';
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int H, W;
	cin >> H >> W;
	string S[2000];
	rep(i, H) cin >> S[i];

	int L[2000][2000] = {};
	int R[2000][2000] = {};
	int U[2000][2000] = {};
	int D[2000][2000] = {};

	rep(i, H) {
		rep(j, W) {
			if (j == 0 && S[i][j] == '.') L[i][j] = 1;
			else {
				if (S[i][j] == '.') L[i][j] = L[i][j - 1] + 1;
			}
		}
		for (int j = W - 1; j >= 0; j--) {
			if (j == W - 1 && S[i][j] == '.') R[i][j] = 1;
			else {
				if (S[i][j] == '.') R[i][j] = R[i][j + 1] + 1;
			}
		}
	}
	rep(j, W) {
		rep(i, H) {
			if (i == 0 && S[i][j] == '.') U[i][j] = 1;
			else {
				if (S[i][j] == '.') U[i][j] = U[i - 1][j] + 1;
			}
		}
		for (int i = H - 1; i >= 0; i--) {
			if (i == H - 1 && S[i][j] == '.') D[i][j] = 1;
			else {
				if (S[i][j] == '.') D[i][j] = D[i + 1][j] + 1;
			}
		}
	}

	int kotae = 0;
	rep(i, H) {
		rep(j, W) {
			int k = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
			kotae = max(kotae, k);
		}
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 67072
import sys
input = sys.stdin.readline
sys.setrecursionlimit(11000)

n = int(input())
ab = [[ (int(i)-1) for i in input().split()] for i in range(n-1)]
c = sorted([int(i) for i in input().split()], reverse=True)

if n==1:
    print(0)
    print(c[0])
    exit()

dic = {}
for i in range(n):
    dic[i] = []

cnt = [0]*n
for a,b in ab:
    dic[a].append(b)
    dic[b].append(a)
    cnt[a] += 1
    cnt[b] += 1

c_idx = 0
res = 0
res_arr = [""]*n
used = [0]*n
def f(idx):
    global c_idx, res, used
    used[idx] = 1
    res_arr[idx] = str(c[c_idx])
    for x in dic[idx]:
        if used[x] == 0:
            c_idx += 1
            res += c[c_idx]
            f(x)

f(cnt.index(1))
print(res)
print(" ".join(res_arr))

Measured memory_bytes: 55644
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    double rev_sum = 0;
    for(int i = 0; i < n; i++){
        double a;
        cin >> a;
        rev_sum += 1 / a;
    }

    cout << 1 / rev_sum << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
set_a = set(a)
ans = 0
i = -1
c = Counter(a).most_common() # (出現回数の最も少ない数字,出現回数)
while len(set_a) > k:
    set_a.remove(c[i][0])
    ans += c[i][1]
    i-=1
print(ans)


Measured memory_bytes: 50576
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
inline bool chmin(T &a, T b) { return a > b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<vector<int>> d(N, vector<int>(N, INF));
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		d[a][b] = 1;
	}
	DMP(d);

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (d[i][k] == INF || d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	DMP(d);

	int mincyc = INF;
	vector<int> ans;
	for (int i = 0; i < N; i++) chmin(mincyc, d[i][i]);
	if (mincyc == INF) cout << -1 << "\n";
	else {

		int st = -1;
		for (int i = 0; i < N; i++) {
			if (d[i][i] == mincyc) {
				st = i;
				break;
			}
		}

		while (ans.size() < mincyc) {

			for (int i = 0; i < N; i++) {
				if (d[i][i] == mincyc && d[st][i] == 1) {
					ans.emplace_back(i);
					st = i;
					break;
				}
			}

		}

		cout << ans.size() << "\n";
		for (const auto &e : ans) cout << e + 1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
LL A[100000 + 10];
int n, k;
//模拟装货过程
bool check(LL P) {
    int cnt = k;
    for (int i = 0; i < n; ) {
        LL t = P;
        cnt--;
        // 卡车已经用完，证明卡车当前最大装载量不能装完货物
        if (cnt < 0)
            return false;
        while (i < n && t >= 0) {
            // 剩余重量可以装上当前货物
            if (t >= A[i])
                t -= A[i],i++;
            //装不下则用下一辆卡车去装
            if (t < A[i])
                break;
        }
    }
    return true;
}
// 二分找出P的最小值
LL BinarySearch(LL sum) {
    LL left = 0, right = sum;
    LL mid;
    while (left + 1 < right) {
        mid = (left + right) / 2;
        //可以装好货物
        if (check(mid))
            right = mid;
        else
            left = mid;
    }

    return right;
}
int main() {
    LL sum = 0;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &A[i]);
        sum += A[i];
    }
    LL P = BinarySearch(sum);
    printf("%lld\n", P);
    return 0;
}


Measured memory_bytes: 3960
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 5e5 + 5, mod = (int) 0;
int a[N], dp[N], nxt[N], prv[N];;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int j = 0; j < n; ++j) a[j] = s[j] - '0';
	nxt[n] = n;
	for (int j = n - 1; j >= 0; --j) {
		nxt[j] = nxt[j + 1];	
		if (a[j] == 0) nxt[j] = j;
	}
	for (int j = 0; j < n; ++j) {
		prv[j] = (j == 0 ? -1 : prv[j - 1]);
		if (a[j] == 0) prv[j] = j;
	}
	dp[0] = 0;
	for (int j = 0; j < n; ++j) {
		if (a[j] == 1) {
			{
			int pos = nxt[j];
			if (pos + 1 < n && a[pos + 1] == 1) {
				dp[pos + 2] = max(dp[pos + 2], dp[j] + (pos - j));
			}
			}
			{
			int pos = prv[j];
			if (pos - 1 >= 0 && a[pos - 1] == 1) {
				dp[j + 1] = max(dp[j + 1], dp[pos - 1] + (j - pos));	
			}
			}
		}
		dp[j + 1] = max(dp[j + 1], dp[j]);
	}
	cout << dp[n] << endl;
}





Measured memory_bytes: 8708
N = int(input())
As = list(map(int, input().split()))

sum = 0
for i in range(N):
    sum += As[i]
    sum %= 10**9+7

ans = 0
for i in range(N):
    sum -= As[i]
    ans += As[i]*sum
    ans %= 10**9+7

print(ans)


Measured memory_bytes: 31584
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
        int A,B,C;
        cin>>A>>B>>C;
        if(A>B)
                printf("0");
        else if(B/A<=C)
                printf("%d",B/A);
        else
                printf("%d",C);
        return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();

  vector<vector<int>> sPos(26);
  rep(i, n) {
    int c = s.at(i) - 'a';
    sPos.at(c).push_back(i);
  }
  rep(i, n) {
    int c = s.at(i) - 'a';
    sPos.at(c).push_back(i + n);
  }

  ll ans = 0;
  int pos = 0;
  rep(i, m) {
    int c = t.at(i) - 'a';
    if (sPos.at(c).empty()) {
      cout << -1 << endl;
      return 0;
    } else {
      pos = *lower_bound(sPos.at(c).begin(), sPos.at(c).end(), pos) + 1;
      if (pos >= n) {
        ans += n;
        pos -= n;
      }
    }
  }
  ans += pos;
  cout << ans << endl;
  return 0;
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/************************************************************************************************************************************************/
void solve(){
    /*
    LL N;
    cin >> N;
    LL num = 0;
    while(N >= pow(26,num)){
        N-=pow(26,num);
        num++;
    }
    cout << "num = " << num << endl;
    vector<LL> name (num);
    for(LL i = 0;i < num;i++){
        name[i] = N%27;
        N /= 27;
    }
    REV(name);
    for(LL i = 0;i < num;i++){
        cout << char('a'+name[i]);
    }
    cout << endl;
    */
    char a;
    cin >> a;
    if('a' <= a && a <= 'z'){
        cout << 'a' << endl;
    }
    else{
        cout << 'A' << endl;
    }
}



Measured memory_bytes: 3648
s = input()
N = int(input())
Q = [input().split() for _ in range(N)]

head = ''
tail = ''
reverse = 0

for q in Q:
    if int(q[0]) == 1:
        reverse = 1 - reverse
    elif int(q[1]) == 1:
        if reverse:
            tail += q[2]
        else:
            head += q[2]
    else:
        if reverse:
            head += q[2]
        else:
            tail += q[2]

if reverse:
    print(tail[::-1] + s[::-1] + head)
else:
    print(head[::-1] + s + tail)

Measured memory_bytes: 41460
// C - To Infinity

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

int main() {
	string S;
	cin >> S;

	ll K;
	cin >> K;

	int seq_one = 0;
	char first_num;
	for (int i=0; i<S.size(); i++) {
		if (S[i] == '1') seq_one++;
		else {
			first_num = S[i];
			break;
		};
	}

	if (K <= seq_one) {
		cout << 1 << endl;
	} else {
		cout << first_num << endl;
	}

	return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N; cin >> N;
	while (N--) {
		int a, b, c; cin >> a >> b >> c;
		if (a > b)swap(a, b);
		if (b > c)swap(c, b);
		if (a*a + b*b ==c* c)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int n, l, absmin = MOD, temp, ans = 0;
	cin >> n >> l;
	vector<int> taste(n+1);
	for (int i = 1; i <= n; i++){
		taste[i] = l + i - 1;
		if (absmin >= abs(taste[i])){
			absmin = abs(taste[i]);
			temp = i;
		}
	}
	for (int i = 1; i <= n; i++){
		if (i == temp) continue;
		ans += taste[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

Answer_dict = {}
used_i = list()
used_j = [[] for j in range(10)]

for i in range(N-2):
  if S[i] in used_i:
    continue

  for j in range(i+1,N-1):
    if S[j] in used_j[int(S[i])]:
      continue

    for k in range(j+1,N):
      Answer_dict[S[i]+S[j]+S[k]] = 1

    used_j[int(S[i])].append(S[j])
  used_i.append(S[i])

print(len(Answer_dict))

Measured memory_bytes: 3188
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	if strings.Index(s,"a") >= 0 && strings.Index(s,"b") >= 0 && strings.Index(s,"c") >= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if (h == 0 && w == 0) break;
			draw(h, w);
			System.out.println();
		}

	}

	public static void draw(int h, int w) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if(i == 0 || i == h-1)System.out.print("#");
				else if(j == 0 || j == w-1)System.out.print("#");
				else System.out.print(".");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 24828
#include<iostream>
#define N 100001
#define INF 10000
using namespace std;


struct Node{
  int p,l,r,sib;
};
Node t[N];

int sibling(int x){
  return t[x].sib;
}

int dep(int x){
  int cnt=0;
  if(t[x].p>=0) cnt=dep(t[x].p)+1;
  return cnt;
}

int height(int x){
  int cntl=0,cntr=0;
  if(t[x].l>=0)cntl=height(t[x].l)+1;
  if(t[x].r>=0) cntr=height(t[x].r)+1;
  if(cntl<cntr)return cntr;
  else  return cntl;
}

int degree(int x){
  int cnt=0;
  if(t[x].l>=0)cnt++;
  if(t[x].r>=0)cnt++;
  return cnt;
}

int main(){
  int n,id,c;
  cin>>n;
  for(int i=0;i<n;i++)t[i].l=-1,t[i].p=-1,t[i].r=-1,t[i].sib=-1;

  for(int i=0;i<n;i++){
    cin>>id;
    for(int j=0;j<2;j++){
      int befc=c;
      cin>>c;
      if(c>=0)t[c].p=id;
      if(j>0 && c>=0 && befc>=0) t[c].sib=befc,t[befc].sib=c;
      if(j==0) t[id].l=c;
      else t[id].r=c;
    }
  }

  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<t[i].p<<", sibling = "<<sibling(i)<<", degree = "<<degree(i) <<", depth = ";
    cout<<dep(i)<<", ";
    cout<<"height = "<<height(i)<<", ";
    if((t[i].l>=0 || t[i].r>=0) && t[i].p>=0) cout<<"internal node";
    else if(t[i].p==-1) cout<<"root";
    else cout<<"leaf";
    cout<<endl;
  }


  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    int n;
    cin >> n;
    map<string, int> s;
    for(int i=0; i<n; i++) {
        string a;
        cin >> a;
        s[a]++;
    }
    int m;
    cin >> m;
    map<string, int> t;
    for(int i=0; i<m; i++) {
        string a;
        cin >> a;
        t[a]++;
    }
    int max = 0;
    for(auto x : s) {
        int count = x.second - t[x.first];
        if(max < count) max = count;
    }
    cout << max << endl;
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

h,a = map(int, input().split())
# n = int(input())
# a = list(map(int,input().split()))
if h % a ==0: ans = h // a
else: ans = h // a + 1

print(ans)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N;

int main()
{
    cin >> N;

    if (N % 2 == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    ll nn = N / 2;
    ll ans = 0;
    for (ll i = 5; i <= nn; i *= 5)
    {
        ans += nn / i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc171/tasks/abc171_a

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 

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

    char x;
    cin >> x;

    if(isupper(x)) {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>

  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
  typedef string str;
  typedef unsigned long long ull;
  ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;



// void solve(){

// string s;
// cin>>s;


// }
 


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0;i<n;i++){int k; cin>> k; a[i] = k; cin>>k; b[i] = k;}
  sort(a.begin(), a.end());
sort(b.begin(), b.end());

if (n%2==1){
  int amed = a[n/2];
  int bmed = b[n/2];
  cout<< max(abs(bmed-amed)+1, 0) <<"\n";
}else{
  lld amed = (a[n/2]+(lld)a[n/2-1])/2;
  lld bmed = (b[n/2]+(lld)b[n/2-1])/2;
  cout<< max(int(abs(bmed-amed)*2+1), 0)<<"\n";
}
  
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

int main()
{
    ll X, A;
    cin >> X >> A;
    cout << ((X < A) ? 0 : 10) << endl;
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb emplace_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int h, w;
    cin >> h >> w;
    vstr s = in(h);

    vint dx{1, 0, -1, 0};
    vint dy{0, 1, 0, -1};

    int ans = 0;
    rep(i, h) rep(j, w)
    {
        if (s[i][j] == '#')
            continue;
        int dist[h][w];
        rep(k, h) rep(l, w) dist[k][l] = -1;
        dist[i][j] = 0;
        qpint q;
        q.emplace(i, j);
        while (!q.empty())
        {
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            rep(k, 4)
            {
                int ny = y + dy[k];
                int nx = x + dx[k];
                if (nx >= 0 && ny >= 0 && nx < w && ny < h && dist[ny][nx] == -1 && s[ny][nx] != '#')
                {
                    dist[ny][nx] = dist[y][x] + 1;
                    q.emplace(ny, nx);
                }
            }
        }

        rep(k, h) rep(l, w)
        {
            ans = max(ans, dist[k][l]);
        }
    }
    cout << ans << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector< PII >
#define VVI vector< VI >
#define PB push_back
#define F first
#define S second
const int INF=1e9;
const int MOD=1e9+7;
int n,freq[26],mask[200000],dp[200001];
map<int,int> m;
string s;
int main(){
    cin>>s;
    n=s.size();
    memset((freq),0,sizeof(freq));
    for(int i=0;i<n;i++){
        freq[s[i]-'a']++;
        mask[i]=0;
        for(int j=0;j<26;j++){
            if(freq[j]%2!=0)mask[i]=mask[i]|(1<<j);
        }
    }
    dp[n]=0;
    for(int i=n-1;i>=0;i--){
        int cur_mask=(i>0)?mask[i-1]:0;
        dp[i]=dp[i+1]+1;
        for(int j=0;j<27;j++){
            int new_mask=0;
            for(int k=0;k<26;k++){
                if(j==k){
                    if((cur_mask&(1<<k))==0)new_mask=new_mask|(1<<k);
                }
                else{
                    if(cur_mask&(1<<k))new_mask=new_mask|(1<<k);
                }
            }
            if(m.count(new_mask)!=0){
                dp[i]=min(dp[i],m[new_mask]+1);
            }
        }
        if(m.count(mask[i])==0)m[mask[i]]=dp[i+1];
        else m[mask[i]]=min(m[mask[i]],dp[i+1]);
    }
    cout<<dp[0]<<"\n";
    return 0;
}

Measured memory_bytes: 11396
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-05-17(Sun)
   note   
**********************************************************************/

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int ans = n % 10;
  if (ans == 3) {
      cout << "bon" << endl;
  }
  else if (ans == 0 || ans == 1 || ans == 6 || ans == 8) {
      cout << "pon" << endl;
  }
  else {
      cout << "hon" << endl;
  }
  return 0; 
}

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

int r[200000],c[200000];
int x[200000];
int pos[200000];

int main(){
	int n;cin>>n;
	set<int>R,C;
	rep(i,n){
		scanf("%d%d",&r[i],&c[i]);r[i]--;c[i]--;
		R.insert(r[i]);
		C.insert(c[i]);
		x[c[i]]=r[i];
		pos[r[i]]=c[i];
	}
	if(R.size()!=n||C.size()!=n){
		puts("-1");return 0;
	}
	int cnt=0;
	rep(i,n){
		if(pos[i]==i)continue;
		cnt++;
		int j=pos[i];
		swap(pos[x[i]],pos[x[j]]);
		swap(x[i],x[j]);
	}
	cout<<cnt<<endl;
}


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

int main()
{
  int n,m;
  
  cin >> n;
  string s[n];
  for(int i = 0; i < n; i++)
    cin >> s[i];
  
  cin >> m;
  string t[m];
  for(int i = 0; i < m; i++)
    cin >> t[i];
  
  int p[n];
  for (int i =0; i < n; i++)
    p[i] = 0;
  
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (s[i] == s[j])
         p[i] += 1;
    }
    for (int j = 0; j < m; j++)
    {
       if (s[i] == t[j])
         p[i] -= 1;
    } 
  }
  sort(p, p + n,greater<int>());
  
  if(p[0] < 0)
  {
    cout << 0 << endl;
    return (0);
  }
  
  cout << p[0] << endl;

}

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

// #define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod (ll) (1e9 + 7)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(), v.end()
#define dvec(v) for(auto i: v) cout<< i<< " "; cout<< '\n';
#define gcd(a,b) __gcd(a, b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define darr(a,n) for(int i=0; i<n;i++) cout<< a[i]<< " "; cout<< '\n';
#define what_is(x) cerr<< #x<< " : "<< x<< '\n';


int32_t main() {
	fast;
	int a, b;
	cin >> a >> b;
	if (a + b > 9) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int D[] = new int[5];

        D[0] = sc.nextInt();
        D[1] = sc.nextInt();
        D[2] = sc.nextInt();
        D[3] = sc.nextInt();
        D[4] = sc.nextInt();
        int minMod = 10;
        int time = 0;

        for(int i=0;i<5;i++){
            int mod = D[i] % 10;
            if(mod < minMod && mod != 0){
                minMod = mod;
            }

            if(mod != 0){
                time += D[i] - mod + 10;
            } else {
                time += D[i];
            }

        }


        System.out.println(time + minMod - 10);

    }

}


Measured memory_bytes: 21460
let readInt _ = stdin.ReadLine() |> int

let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

let rec solve count list =
    match (count, list) with
    | (3, _) -> "Yes"
    | (c, [| a; b |] :: xx) -> if a = b then solve (c + 1) xx else solve 0 xx
    | (_, []) -> "No"

()
|> readInt
|> fun x ->
    [ 1 .. x ]
    |> List.map readIntArray
    |> solve 0
    |> printfn "%s"


Measured memory_bytes: 29840
#include <iostream>

using namespace std;

int main(){
	int n, a[101];
	cin >> n;
	
	for(int i = 0; i <  n; i++){
		cin >> a[i];
	}
	
	for(int i = n - 1; i >= 0; i--){
		cout << a[i];
		if(i != 0) cout <<" ";
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define in insert
#define bs binary_search   

int main()
{
    ll n,w;
    cin>>n>>w;
    ll arr[n],var[n];
    for(int i=0;i<n;i++){
        cin>>arr[i]>>var[i];
    }
    ll dp[n+1][w+1];
    for(int i=0;i<=n;i++)
        for(int j=0;j<=w;j++)
        {
            if(j==0 || i==0)
            dp[i][j]=0;
            else if(arr[i-1]>j)
            dp[i][j]=dp[i-1][j];
            else
            dp[i][j]=max(dp[i-1][j-arr[i-1]]+var[i-1],dp[i-1][j]); 
        }
    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 79104
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
def solve():
  ans = -float('inf')
  N = int(input())
  A = list(map(int, input().split()))
  before = A[:N]
  after = list(map(lambda x:-x,A[-N:]))
  heapify(before)
  heapify(after)
  b = [sum(before)]*(3*N)
  a = [sum(after)]*(3*N)
  for i in range(N,2*N):
    p = heappop(before)
    if p<A[i]:
      b[i] = b[i-1]-p+A[i]
      heappush(before,A[i])
    else:
      b[i] = b[i-1]
      heappush(before,p)
  for i in range(2*N-1,N-1,-1):
    p = heappop(after)
    if p<-A[i]:
      a[i] = a[i+1]-p-A[i]
      heappush(after,-A[i])
    else:
      a[i] = a[i+1]
      heappush(after,p)
  for i in range(N,2*N+1):
    ans = max(ans,b[i-1]+a[i])
  return ans
print(solve())

Measured memory_bytes: 117188
#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;


main(){
	stack<int> s;
	int a,b;
	string st;
	while(cin >> st){
		if(st[0]=='+'){
			a=s.top();s.pop();
			b=s.top();s.pop();
			s.push(a+b);
		}
		else if(st[0]=='-'){
			b=s.top();s.pop();
			a=s.top();s.pop();
			s.push(a-b);
		}
		else if(st[0]=='*'){
			a=s.top();s.pop();
			b=s.top();s.pop();
			s.push(a*b);
		}
		else{
			s.push(atoi(st.c_str()));
		}
	}
		printf("%d\n",s.top());
	
	return 0;
}


Measured memory_bytes: 3284