akhauriyash/Code-Regression huggingface dataset:
import sys

INF = float('inf')

def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        #flag = False
        
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                #flag = True
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
    

N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)

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

int main() {
    string S, T;
    cin >> S >> T;
    vector<string> ans;

    for (int i = 0; i < S.size() - T.size() + 1; i++) {
        bool flag = true;
        string tmp = S;
        for (int j = 0; j < T.size(); j++) {
            if (S[i + j] != T[j] && S[i + j] != '?') {
                flag = false;
                break;
            }
            tmp[i + j] = T[j];
        }
        if (flag) {
            for (int k = 0; k < tmp.size(); k++) {
                if (tmp[k] == '?')
                    tmp[k] = 'a';
            }
            ans.push_back(tmp);
        }
    }
    if (ans.empty()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		string S; cin >> S;
		if (S <= "2019/04/30") cout << "Heisei" << endl;
		else cout << "TBD" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
//#include <ext/hash_map>
#include <tr1/unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using namespace tr1;
//using namespace __gnu_cxx;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define DEB 0

#define SZ 885777

/*
real	0m2.093s  --> 
real	0m2.000s
*/
const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];
int hS[25],hx[25],hy[25],edge[25][4][25]; //[src][dir][dest]
//hash_map<int,int> hii(3000000);
unordered_map<int,int> hii(3000000);


inline bool isnotgoal(int s){
  return (((last&s)) == last);
}
inline bool isnot(int s){
  rep(i,home)if( !(s&(1<<i)) ){
    if( (hS[i]&s)==hS[i] ) return true;
  }
  return false;
}
inline bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}

int dfs(int S){
  int src = S&((1<<5)-1);
  int x = hx[src];
  int y = hy[src];
  int s = S>>5;

  if( (1<<home)-1 == s ){ //ツ静「ツ妥篠づ可姪淞づェツづゥ
    return 1;
  }
  if( isnotgoal(s) ){ //ツ仰ウツ嘉ッツづ可姪淞づゥツつスツづ淞づ個嘉づーツ湘氾ッツつオツつスツつゥツづつ、ツつゥ
    return 0;
  }
  //hash_map<int,int>::iterator it = hii.find(S);
  unordered_map<int,int>::iterator it = hii.find(S);
  if( it!=hii.end() ){ //ツ探ツ催オツ催渉づ敖づ個湘ウツ妥板つゥツづつ、ツつゥ
    return it->second;
  }

  // ツプツδ個ゼツδ督トツつェツ置ツつッツづ按つ「ツ嘉づ個有ツ鳴ウ
  if( s>0 && ((s&(s-1))!=0) && isnot(s&~(1<<src)) ){
    return 0;
  }
  
  int ret = 0;
  rep(k,4){
    for(int j=0; edge[src][k][j]!=-1; j++){
      int dest = edge[src][k][j];
      int nx = hx[dest];
      int ny = hy[dest];
      if( field[ny][nx]==1 ){
	field[ny][nx] = 0;
	ret += dfs(((s|(1<<dest))<<5)|dest);
	field[ny][nx] = 1;
	break;
      }
    }
  }
  hii.insert(make_pair(S,ret));
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    hii.clear();
    memset(num,-1,sizeof(num));
    memset(edge,-1,sizeof(edge));
    memset(hS,0,sizeof(hS));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
	if( field[i][j]==1 ){
	  hx[home]=j; hy[home]=i;
	  num[i][j] = home;
	  home++;
	}
      }
    }
    hx[home] = sx;
    hy[home] = sy;

    // other homes
    rep(i,home){
      rep(k,4){
	int sz = 0;
	for(int j=1; j<20; j++){
	  int tx = hx[i] + dx[k]*j;
	  int ty = hy[i] + dy[k]*j;
	  if( inside(tx,ty) ) break;
	  if( field[ty][tx]==1 ){
	    hS[i] |= (1<<num[ty][tx]);
	    edge[i][k][sz++] = num[ty][tx];
	  }
	}
      }
    }

    //last homes
    rep(k,4){
      int sz = 0;
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	  edge[home][k][sz++] = num[ty][tx];
	}
      }
    }
    printf("%d\n",dfs(home));
  }
  

  return 0;
}

Measured memory_bytes: 26000
a, b, c, d = map(int, input().split())

if b <= c or d <= a:
    print(0)
elif a <= c and b <= d:
    print(b - c)
elif a <= c and d <= b:
    print(d - c)
elif c < a and b <= d:
    print(b - a)
else:
    print(d - a)

Measured memory_bytes: 3060
REGEX = /(.AGC|A.GC|AG.C|.ACG|.GAC)/
DIVISOR = 10**9 + 7

def calc(n)
  return { "A" => 1, "C" => 1, "G" => 1, "T" => 1 } if n == 1
  res = calc(n-1)
  new_res = {}
  res.each do |k, v|
    "AGCT".each_char do |ch|
      cand = k + ch
      cand = cand.slice(1, 5) if cand.size > 4
      if cand.size < 4
        if cand != "AGC" && cand != "ACG" && cand != "GAC"
          # p cand
          new_res[cand] = 1
        end
      else
        if !REGEX.match(cand)
          new_res[cand] ||= 0
          new_res[cand] += v
        end
      end
    end
  end
  new_res
end

puts((calc gets.to_i).map{ |_, v| v }.inject(&:+) % DIVISOR)


Measured memory_bytes: 2172
def f(n):
  res = 1
  if n <= 1:
    return 1
  while n>1:
    res *= n
    n-=1
  return res
 
def h(n,m):
  return f(n+m-1)//f(n)//f(m-1)
 
s=int(input())
 
res = 0
 
pair = s//3
 
for i in range(1,pair+1):
  res += h(s-3*i,i)
print(res%(10**9+7))

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;
ll x, k, d;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> x >> k >> d;
	x = abs(x);
	ll a = x / d;
	if(a > k){
		cout << (x - k * d);
		return 0;
	}
	else{
		k -= a;
		x %= d;
		if(k > 0){
			if(d - x < x){
				x = d - x;
				k--;
			}
			if(k % 2 == 0)
				cout << x;
			else
				cout << abs(d - x);
			return 0;
		}
		else{
			cout << x;
			return 0;
		}

	}


	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

using Graph = Vvec<int>;
const ll infty = 1e18;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

void dfs(Graph& graph, vector<ll>& a, vector<ll>& dp, vector<ll>& ans, int tmp, int from, int sz)
{
    auto itr = lower_bound(dp.begin(), dp.end(), a[tmp]);
    int d = distance(dp.begin(), itr);

    ll a0 = dp[d];
    if(d>sz) sz++; 
    ans[tmp] = sz;
    dp[d] = a[tmp];

    for(auto& to: graph[tmp]){
        if(to != from) dfs(graph, a, dp, ans, to, tmp, sz);
    }
    dp[d] = a0;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    for(auto& x: a) cin >> x;
    Graph graph(N);
    for(int i=0; i<N-1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<ll> dp(N, infty);
    dp[0] = 0;
    vector<ll> ans(N);
    dfs(graph, a, dp, ans, 0, -1, 0);

    for(auto& x: ans) cout << x << "\n";
}

Measured memory_bytes: 38904
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	cout << N - 1 - M << endl;
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
int main(void)
{
	fastio
	ld x;
	cin>>x;
	x /= 3;
	x = x*x*x;
	printf("%0.7Lf\n",x);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();

    if(a<b && b<c && a<c) System.out.println("Yes");
    else System.out.println("No");



  }
}



Measured memory_bytes: 26240
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	 
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n,w;
		cin>>n>>w;
		vll weights(n),values(n);
		forn(i,n)cin>>weights[i]>>values[i];
		ll sum_values=0;
		forn(i,n)sum_values+=values[i];
		vll dp(sum_values+1,1e18+4);
		dp[0]=0;
		forn(i,n)
		{
			for(ll already_value=sum_values-values[i]; already_value>=0; already_value--)
			{
				dp[already_value+values[i]]=min(dp[already_value]+weights[i],dp[already_value+values[i]]);
			}
		}
		ll ans=0;
		for(ll i=0;i<=sum_values;i++)
		{
			if(dp[i]<=w)
			ans=max(ans,i);
		}
		cout<<ans<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}

	
	

Measured memory_bytes: 3976
def BTCtoJPY(BTC):
    return BTC*380000.0

def main():
    accum = 0
    X = []
    N = int(input())
    for i in range(N):
        X.append(input().split())
    for i in X:
        if i[1] == "BTC":
            accum += BTCtoJPY(float(i[0]))
        else:
            accum += float(i[0])
    print(accum)

main()


Measured memory_bytes: 3060
/*  ex4_1
    Graku   */
#include <stdio.h>

int main(void) {
    int n, d;
    scanf("%d %d", &n, &d);

    //a man can check (2*d + 1) trees. (a + b -1) / b == (int)ceil((double)a/(double)b)
    int ans = (n + (2*d + 1) - 1) / (2*d + 1);
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int x[15][15];

int main(void){
	int n,d,i,j,k,s,ans=0;
	cin >> n >> d;
	for(i=0; i<n; ++i){
		for(k=0; k<d; ++k){
			cin >> x[i][k];
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<i; ++j){
			s = 0;
			for(k=0; k<d; ++k){
				s += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			for(k=0; k<1024; ++k){
				if(s == k*k){
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll a; cin >> a;
	vl q(a);
	for (int i = 0; i < a; i++) {
		cin >> q[i];//お腹すいたなぁ
	}
	sort(q.begin(), q.end());//そうだ、ラーメンにしよ
	if (q[a / 2] == q[a / 2 - 1]) {
		cout << 0 << endl;
	}
	else {
		cout << q[a / 2] - q[a / 2 - 1] << endl;
	}
}

Measured memory_bytes: 4116
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    long long int ans = 0;
    int n;

    scanf("%d", &n);
    long long int a[n + 1];
    long long int b[n];
    for (int i = 0; i < n + 1; i++)
        scanf("%lld", &a[i]);
    for (int i = 0; i < n; i++)
        scanf("%lld", &b[i]);

    for (int i = 0; i < n; i++)
    {
        if (a[i] < b[i])
            ans += a[i];
        else
            ans += b[i];

        if (a[i] < b[i])
            if (a[i + 1] > b[i] - a[i])
            {
                a[i + 1] -= (b[i] - a[i]);
                ans += (b[i] - a[i]);
            }
            else
            {
                ans += a[i + 1];
                a[i + 1] = 0;
            }
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1664
#include<cstdio>
using namespace std;
int main(void)
{	
	int dp[5][4001];
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF)	{
		for(i=0;i<=4;i++)	{
			for(j=0;j<=n;j++)	dp[i][j]=0;
		}
		for(i=0;i<=1000;i++)	{
			if(i>n)	break;
			dp[0][i]=1;
		}
		for(i=0;i<4-1;i++)	{
			for(j=0;j<=n;j++)	{
				for(k=0;k<=1000;k++)	{
					if(j+k>n)	break;
					dp[i+1][j+k]+=dp[i][j];
				}
			}
		}
		printf("%d\n",dp[3][n]);
	}
	return 0;
}


Measured memory_bytes: 1100
/*
	Created by Faisal Ahmed
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	int h, a;
	int arr[100010];
	ll sum = 0;
	
	cin >> h >> a;
	for(int i = 0; i < a; i++){
		cin >> arr[i];
		sum += arr[i];
	}
	
	if(sum >= h){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
 
	return 0;
}

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

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

  int A[N];
  for(int i = 0; i < N; i++) cin >> A[i];

  int j, i, v;
  for( i = 1; i < N; i++ ) {
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v ) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
  cout << A[N-1] - A[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<map>
#include<stack>
#include<algorithm>
using namespace std;
const int N = 300000;

int main()
{
    int n,ch[N];
    long long int ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&ch[i]);
    if(ch[0]!=0) {printf("-1\n");return 0;}
    for(int i=1;i<n;i++)
    {
        if(ch[i]-ch[i-1]>=2) {printf("-1\n");return 0;}
        else if(ch[i]-ch[i-1]==1) ans++;
        else ans+=ch[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<cmath>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;

map<char,char> m={{'A','T'},{'C','G'},{'T','A'},{'G','C'}};
set<char> se={'A','T','C','G'};

char s[20];

int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int ans=0;

    for(int i=0;i<len;++i)
    {
        int cur=i;

        while(cur<len&&se.count(s[cur]))
            ++cur;
        ans=max(cur-i,ans);
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, x, y, z ; cin >> n;
    ll sum = 0;
    for(x=1; x<=n; ++x){
        for(y=1; y<=n; ++y)
        {
            for(z=1; z<=n; ++z)
            {
           sum += __gcd(__gcd(x,y),z);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main(){
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	int dx =  x2 - x1, dy = y2 - y1;
	int x3 = x2 - dy, y3 = y2 + dx;
	int x4 = x3 - dx, y4 = y3 - dy;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))

def ruiseki(ans):
    retval = 0
    for i in ans:
        retval += i
    return retval

max = 0
for i in range(N):
    ans = []
    for j in range(i+1):
        ans.append(a[0][j])
    for j in range(i,N):
        ans.append(a[1][j])
    if ruiseki(ans) > max:
        max = ruiseki(ans)
print(max)


Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 25
int parent[MAX],left[MAX],right[MAX];
int depth(int);
int height(int);
int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)  parent[i] = -1;
    for(int i=0; i<n; i++){
        int id, l, r;
        scanf("%d%d%d",&id,&l,&r);
        left[id] = l;
        if(l != -1) parent[l] = id;
        right[id] = r;
        if(r != -1) parent[r] = id;
    }
    for(int i=0; i<n; i++){
        int sibling,degree=0;
        sibling =(left[parent[i]] == i ? right[parent[i]] : left[parent[i]]);
        if(parent[i] == -1) sibling = -1;
        if(left[i] != -1) degree++;
        if(right[i] != -1) degree++;
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i, parent[i], sibling, degree, depth(i), height(i));
        if(parent[i] == -1) printf("root\n");
        else if(degree == 0) printf("leaf\n");
        else printf("internal node\n");
    }
}
int depth(int node){
    return (parent[node] == -1 ?  0 : depth(parent[node]) + 1);
} 
int height(int n){
    return ((left[n] == -1 ? -1 : height(left[n]) )< (right[n] == -1 ? -1 : height(right[n]) )?(right[n] == -1 ? -1 : height(right[n]) ): (left[n] == -1 ? -1 : height(left[n]) )) + 1;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define maxn 200001
#define maxa 2000005
#define MOD  1000000007
#define INF 1000000000000000000

using namespace std;

#define int int64_t
#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(v) v.begin(), v.end()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout << setprecision(10) << fixed;
}
ll ceil(ll a, ll b){ return (a+ b-1)/b; }
void flaged(bool flag){
    if(flag) cout << "Yes\n";
    else cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf(){
    fact[0] = finv[0] = 1;
    for(ll i = 1; i < maxa; i++){fact[i] = (fact[i-1]*i) %MOD;finv[i] = (finv[i-1]*power(i))%MOD;}
}
// nCr
ll ncr(ll N, ll R){ if(R > N) return 0; return (fact[N]*((finv[R]*finv[N-R])%MOD))%MOD;}



void solve(){
    ll n, k;
    cin >> n >> k;

    ll a1[n+5];
    memset(a1, 0, sizeof(a1));

    ll s = 0;
    for(ll i = 0; i <= n; i++){
         a1[i+1] = a1[i]+i; s+= i;
    }

    ll ans = 0;
    for(ll i = k; i <= n+1; i++){
        ans += (s - a1[n+1-i] - a1[i])+1; //cout << s-a1[n+1-i] << " " << a1[i] << endl;

    }
    cout << ans%MOD;

}

main(){
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 5152
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
/***********MAIN**************/
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    if(s == "Sunny"){
        cout<<"Cloudy";
    }
    if(s=="Cloudy"){
        cout<<"Rainy";
    }
    if(s=="Rainy"){
        cout<<"Sunny";
    }
    return 0;
}
//.........

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

int main(void){
    // Your code here!
    string s;
    long long x, y;
    int count_T = 0;
    int count_F = 0;
    bool dp[2][16001] = {{}};
    dp[0][8000] = true; dp[1][8000] = true;
    
    cin >> s;
    cin >> x >> y;
    
    s += 'T';
    for(auto c:s){
        if(c == 'F')
            count_F += 1;
        else{
            bool buf[16001] = {};
            for(int i = 0; i < 16001; i++){
                if(dp[count_T%2][i]){
                    if(count_T > 0)
                        if(i - count_F >= 0)
                            buf[i - count_F] = true;
                    if(i + count_F <= 16000){
                        buf[i + count_F] = true;
                    }
                }
            }
            memcpy(dp[count_T % 2], buf, 16001);
            count_T++;
            count_F = 0;
        }
    }
    
    if(dp[0][8000+x] && dp[1][8000+y])
        cout << "Yes";
    else
        cout << "No";
        
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool cmp1(T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
}

bool cmp2(T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
 ///return a.top - a.mn > b.top - b.mn;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 11316
# include <iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int n,k,i=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;(i+k)<n;i++)
    {
        if(a[i]>=a[k+i])
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 4412
n = int(input())
ans = []
start = "a"
stack = []
stack.append(start)
num = ord("a")
while stack:
    v = stack.pop()
    if len(v) == n:
        ans.append(v)
        continue
    s = list(v[::])
    s.sort()
    nex_num = ord(s[-1])
    for i in range(num, nex_num + 2):
        tuika = chr(i)
        stack.append(v + tuika)
ans.sort()
print(*ans, sep="\n")


Measured memory_bytes: 14504
def main():
    n = int(input())
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())

    mi = min(a, b, c, d, e)

    ans = n//mi + (4 if n%mi == 0 else 5)
    print(ans)

if __name__ == "__main__":
    main()


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

int main(){
	char s[60], *next;
	int n, c = 0;
	next = s;
	scanf("%d %s", &n, s);
	while((next = strstr(next, "ABC")) != NULL){
		c++;
		next++;
	}
	printf("%d\n", c);
}

Measured memory_bytes: 256
#include <stdio.h>

#define LEN 1000000
 
int head = 0, tail = 0;
int que[LEN];

int next[100][100];
int d[100] = {0};
int rank = 0;

int isempty() {
  return head == tail;
}
   
void enqueue(int x) {
  que[tail] = x;
  if ((tail + 1) == LEN)
    tail = 0;
  else
    tail++;
}
 
int dequeue() {
  int x;
  x = que[head];
  if ((head + 1) == LEN)
    head = 0;
  else
    head++;
  return x;
}

int next_enqueue(int u, int n) {
  for (int j = 0; j < n; j++) {
    if (next[u - 1][j] == 1 && d[j] == -1) {
      enqueue(j + 1);
      d[j] = d[u - 1] + 1;
    }
  }
  return isempty();
}

int main(void) {
  int n;
  int u, k, v;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &u);
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &v);
      next[u - 1][v - 1] = 1;
    }
  }

  for (int i = 0; i < n; i++)
    d[i] = -1;

  u = 1;
  d[0] = 0;
  while (1) {
    if (next_enqueue(u, n) == 1)
      break;
    u = dequeue();
  }

  for (int i = 1; i < n; i++) 
    if (d[i] == 0) 
      d[i] = -1;
 
  for (int i = 0; i < n; i++) {
    printf("%d %d\n", i + 1, d[i]);
  }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int i = 1; i < n + 1; i++){
    string s = to_string(i) + "0000";
    if(i % 3 == 0){
      cout << " " << i;
    }
    else if(s.at(0) == '3' || s.at(1) == '3' || s.at(2) == '3' || s.at(3) == '3'|| s.at(4) == '3'){
      cout << " " << i;
    }

    if(i == n){
      cout <<  endl;
    }
  } 
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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



#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if(b == 0) return a;
    if(a % b == 0) return b;
    return gcd(b, a % b);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    int x[105000];
    cin >> x[1];
    int ans = abs(x[1] - X);
    for(int i = 2; i <= N; i++) {
        cin >> x[i];
        ans = gcd(ans, abs(x[i] - X));
    }
    cout << ans << endl;
    return 0;
}


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

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

int main(void){

    char a; cin >> a;
    if('a' <= a && a <= 'z') cout << "a\n";
    else cout << "A\n";

    return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    int k, n; cin >> k >> n;
    ll a[n]; 
    rep(i,n) cin >> a[i];

    ll mx = k - a[n-1] + a[0];
    rep(i,n-1) {
        mx = max(mx, a[i+1] - a[i]);
    }

    out(k - mx);



    return 0;
}










Measured memory_bytes: 2424
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>v(N);
	vector<int>w(N);
	for (auto &i : v)cin >> i;
	for (int i = N - 2; i >= 0; i--) {
		if (v[i] >= v[i + 1])w[i] = w[i + 1] + 1;
		else w[i] = 0;
	}
	cout << *max_element(w.begin(), w.end()) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<string>
#include<cmath>
#include <iomanip>

using namespace std;


int main(){
    long long a = 0;
    cin >> a;
    long long ans = 0;
    if(a % 2 == 0){
        a /= 2;
        while(a > 4){
            a = a - (a % 5);
            a /= 5;
            ans += a;
        }
        cout << ans;
    }
    else cout << 0;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt(); // 1点
        int b = sc.nextInt(); // 0点
        int c = sc.nextInt(); // -1点
        int k = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < k; i++) {
            if (a > 0) {
                sum++;
                a--;
                continue;
            }
            if (b > 0) {
                b--;
                continue;
            }
            if (c > 0) {
                sum--;
                continue;
            }
        }
        System.out.println(sum);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

Measured memory_bytes: 32700
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  string S; cin>>S;
  int K; cin>>K;

  int N = S.length();

  set<string> st;

  rep(i,N){
    reps(j,i,min(N,i+5)){
      st.insert(S.substr(i,j-i+1));
    }
  }

  cout<< *next(st.begin(),K-1) <<"\n";
}

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


Measured memory_bytes: 1664
N=int(input())
A=[int(x)-1 for x in input().split()]
B=[int(x) for x in input().split()]
C=[int(x) for x in input().split()]

ans=0
before=-100
for i in range(N):
    k=A[i]
    ans+=B[k]
    if k-before==1:
        ans+=C[k-1]
    before=k
print(ans)

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll X,Y;
	cin >> X>>Y;
	if(Y%2 == 0)
	{
		if(X*4 >= Y && X*2 <= Y)
		{
			cout <<"Yes\n";
		}
		else
		{
			cout <<"No\n";
		}
	}
	else
	{
		cout <<"No\n";
	}
	


}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int A, B, col[109][109];
int main() {
	cin >> A >> B;
	swap(A, B);
	for (int i = 50; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			col[i][j] = 1;
		}
	}
	A--; B--;
	for (int i = 1; i <= 47; i += 2) {
		for (int j = 1; j <= 97; j += 2) {
			if (A > 0) { col[i][j] = 1; A--; }
		}
	}
	for (int i = 51; i <= 97; i += 2) {
		for (int j = 1; j <= 97; j += 2) {
			if (B > 0) { col[i][j] = 0; B--; }
		}
	}
	cout << 100 << " " << 100 << endl;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (col[i][j] == 0) {
				cout << ".";
			}
			else {
				cout << "#";
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){
    int n,m;
    cin >> n;
    int r1,r2,r3;
    for(int i=0; i<999;i++){
        m = n;
       r1 = (n%10);
       n-=r1;
       n/=10;
       r2 = (n%10);
       n-=r2;
       n/=10;
       r3 = (n%10);
       n-=r2;
       if( r1 == r2 && r1 == r3){
           break;
       }
       m++;
       n=m;
    }
    cout << r1 << r2 << r3 << endl;
}

Measured memory_bytes: 3560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      if(p[i] != i+1)
        count++;
    }
    System.out.println(count<=2?"YES":"NO");
  }
}

Measured memory_bytes: 23252
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
s = list(readline().rstrip().decode())
ans = 1
mod = 10 ** 9 + 7
for v in Counter(s).values():
    ans *= v + 1
    ans %= mod
print((ans - 1) % mod)


Measured memory_bytes: 4656
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;

int num = 2;
int num2;
  
  while(true){
    if(num > N){
      num = num / 2;
      break;
    }
    else if(num == N){
      break;
    }
    num = num * 2;
  }
  cout << num << endl;
}



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

int main(){
  int i;
  int tmp,buf;
  vector<int> li(3);
  rep(i,3,0) cin >> li[i];
  sort(li.begin(),li.end());
  tmp = li[2] * 3;
  buf = accumulate(li.begin(),li.end(),0);

  if(tmp%2 != buf%2) cout << ((li[2] + 1) * 3 - buf)/2 << endl;
  else cout << (int)(li[2] * 3 - buf)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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 int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int dp[100010][3];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	VE a(n), b(n), c(n); rep(i, n)cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
	rep(i, n) {
		if (i == 0)continue;
		chmax(dp[i][0], dp[i - 1][1] + a[i]);
		chmax(dp[i][0], dp[i - 1][2] + a[i]);
		chmax(dp[i][1], dp[i - 1][0] + b[i]);
		chmax(dp[i][1], dp[i - 1][2] + b[i]);
		chmax(dp[i][2], dp[i - 1][0] + c[i]);
		chmax(dp[i][2], dp[i - 1][1] + c[i]);
	}
	int ans = 0;
	rep(i, 3)chmax(ans, dp[n - 1][i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,A,O=0,E=0;
    cin >> N;
    REP(i,N){
        cin >> A;
        if(A%2==1){O++;}else{E++;}
    }
    YES(O%2==0);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int n;
bool e[8][8];
bool used[8];
int ans=0;

void dfs(int s){
    bool able=0;
    rep(g,8){
        if(e[s][g]&&!used[g]){
            able=1;
            used[g]=1;
            dfs(g);
            used[g]=0;
        }
    }
    if(!able){
        bool flg=1;
        rep(i,n){
            if(!used[i]) flg=0;
        }
        if(flg) ans++;
    }
}

int main(){
    int m; cin>>n>>m;
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        e[a][b]=e[b][a]=1;
    }
    used[0]=1;
    dfs(0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256