akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
 
using namespace std;
 
typedef long long int ll;
typedef vector<long long int> VL;
typedef vector<VL> VVL;
 
int main() {
    string s, p;
    
    cin >> s >> p;
    
    int n_match = 0;
    int idx = 0;
    bool is_second = false;
    while(1) {
        if(s[idx] == p[n_match]) {
            n_match++;
        } else {
            if(is_second) {
                cout << "No" << endl;
                break;
            }
        }
        if(n_match == p.length()) {
            cout << "Yes" << endl;
            break;
        }
        
        idx++;
        if(idx >= s.length()) {
            idx = 0;
            is_second = true;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int n, maxw;
int w[111], v[111];
ll f[111111];
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),	cout.tie(0);
	cin >> n >> maxw;
	for(int i = 1; i <= n; ++i) cin >> w[i] >> v[i];
	for(int i = 1; i <= n; ++i){
		for(int j = maxw; j >= w[i]; --j){
			f[j] = max(f[j], f[j-w[i]] + v[i]);
		}
	}
	cout << f[maxw];
}

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

using namespace std;

int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    if(k + l - n >= 0)
        cout << min(k,l) << " " << abs(k + l - n);
    else
        cout << min(k,l) << " " << 0;

    return 0;
}


Measured memory_bytes: 256
a=int(input())
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        res=[]
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
        if res!=[]:
            divisors.append(res)
    return divisors
 
res=make_divisors(a)
my_min=0
for i in range(len(res)):
    if i==0:
        if len(res[i])==2:
            my_min=res[i][0]+res[i][1]
        else:
            my_min=(res[i][0]*2)
    else:
        if len(res[i])==2:
            my_min=min(my_min,res[i][0]+res[i][1])
        else:
            my_min=min(my_min,res[i][0]*2)
 
print(my_min-2)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 1e5+3;
const int MOD = 1e9+7;

int N;
int P[MAXN];
set<int> S;
LL ans;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    fori(i,N) {
        int x; cin >> x;
        P[x] = i;
    }

    for (int i = N; i; i--) {
        int x = P[i];
        int l1=-1,l2=-1,r1=N,r2=N;
        
        auto it = S.upper_bound(x);
        auto it1 = it;
        if (it != S.end()) {
            r1 = *it;
            it++;
            if (it != S.end()) {
                r2 = *it;
            }
        }

        if (it1 != S.begin()) {
            --it1;
            l1 = *it1;
            if (it1 != S.begin()) {
                --it1;
                l2 = *it1;
            }
        }

        if (l1 != -1) {
            int dl = l1-l2;
            int dr = r1-x;
            ans += 1LL*dl*dr*i;
        }

        if (r1 != N) {
            int dl = x-l1;
            int dr = r2-r1;
            ans += 1LL*dl*dr*i;
        }

        //cout << i << ' ' << x << ' ' << ans << endl;
        S.insert(x);
    }

    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int l[2020];
    static int memo[2020][2020] = {};
    for(int i = 0; i < n; i++) cin >> l[i];
    for(int i = 0; i < n; i++) memo[i][l[i]]++;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j+1 < 2020; j++) memo[i][j+1] += memo[i][j];
    }
    
    for(int j = 0; j < 2020; j++){
        for(int i = 0; i+1 < n; i++) memo[i+1][j] += memo[i][j];
    }
    
    int res = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int index_lmax = l[i]+l[j]-1;
            int index_lmin = max(0, max(l[i]-l[j], l[j]-l[i]));
            int count = memo[n-1][index_lmax] - memo[n-1][index_lmin] - memo[j][index_lmax] + memo[j][index_lmin];
            if(count > 0) res += count;
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 16000
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
//#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

signed main (){
    string s;cin>>s;
    int k;cin>>k;
    rep(i,0,s.size()){
        if(s[i]=='a')continue;
        int act='z'-s[i]+1;
        if(k>=act){
            s[i]='a';
            k-=act;
        }
    }
    k%=26;
    int t=s[s.size()-1];
    rep(i,0,k){
        t++;
        if(t=='z'+1)t='a';
    }
    s[s.size()-1]=t;
    cout<<s<<endl;

    
}
/*
1-21-2
*/


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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

typedef long long ll;
//{
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define sd pop_back
//}

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}
//}

int a,b,c,d;
string s,t;
int coin[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int dp[100001];

int main(){
    cin>>a;
    
    for(int i=1;i<=100000;i++){
        dp[i]=100001;
    }
    for(int i=0;i<=100000;i++){
        for(int j=0;j<12;j++){
            if(i+coin[j]<=a)dp[i + coin[j]]=min(dp[i+coin[j]],dp[i]+1);
        }
    }
    dump(dp[a]);
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	int a, b;
	cin >> a >> b;
	cout << __gcd(a, b) << endl;
}

Measured memory_bytes: 0
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 300005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

int seg[4*MAX];

void construct(int node,int st,int end) {
	if(st == end) {
		seg[node] = 0;
		return;
	}
	
	int mid = (st+end)>>1;
	construct(node<<1, st, mid);
	construct(1+(node<<1), mid+1, end);
	int l = node<<1;
	int r = l+1; 
	seg[node] = max(seg[l], seg[r]);
}

void update(int node, int st, int end, int idx, int val) {
	if(st==end && st==idx) {
		seg[node] = max(val, seg[node]);
		return ;
	}
	
	int mid=(st+end)>>1;
	if(idx <= mid) update(node<<1,st,mid,idx,val);
	else if(idx > mid) update(1+(node<<1),mid+1,end,idx,val);
	
	int l=node<<1,r=l+1;
	
	seg[node] = max(seg[node], max(seg[l], seg[r]));
}

int query(int node, int st, int end, int qs, int qe) {
	if(st>end||qs>end||qe<st) {
		return 0;
	}
	
	if(st>=qs&&qe>=end) {
		return seg[node];
	}
	
	int mid=(st+end)>>1;
	int l = query(node<<1,st,mid,qs,qe);
	int r = query(1+(node<<1),mid+1,end,qs,qe);
	
	return max(l, r);
}

void solve() {
	int n, k;
	in2(n, k);
	
	int a[n];
	for(int i=0;i<n;i++) in(a[i]);
	
	int maxi = -1;
	for(int i=0;i<n;i++) {
		int qs = max(0, a[i]-k);
		int qe = min(a[i]+k, MAX);
		int max_now = query(1, 0, MAX, qs, qe);
		maxi = max(maxi, max_now+1);
		update(1, 0, MAX, a[i], max_now+1);
	}
	cout<<maxi<<en;
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



string s;
void solve(){
	cin >> s;
	int n = s.size();
	
	i64 ans = 0, cnt = 0, cnt2 = 0;
	bool b = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == '>'){
			if(b){
				ans += cnt2*(cnt2-1)/2;
			}
			cnt++;
			b = 0;
		}
		else{
			if(!b){
				ans += max(cnt,cnt2);
				ans += cnt*(cnt-1)/2;
				cnt = cnt2 = 0;
			}
			cnt2++;
			b = 1;
		}
	}
	if(!b){
		ans += max(cnt,cnt2);
		ans += cnt*(cnt-1)/2;
	}
	else ans += cnt2*(cnt2+1)/2;
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

using namespace std;

typedef long long int ll;

ll wt[105] , Val[105];

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

    ll sum =0;
    for(int i=1; i<=N; i++)
    {
        cin >> wt[i] >> Val[i];
        sum += Val[i];
    } 

    ll dp[sum+1][N+1];

    for(ll i =0; i<=sum; i++)
    {
        for(int j=0; j<=N;j++)
        {
            if(i==0) dp[i][j] = 0;
            else
            {
                dp[i][j] = 1000000000000LL;
            }
        }
    }

    dp[Val[1]][1] = wt[1];

    for(ll s=1; s<=sum ; s++)
    {
        for(int j=1; j<=N; j++)
        {
            if(s >=Val[j])
            {
                dp[s][j] = min(dp[s][j-1], dp[s-Val[j]][j-1]+wt[j]);
            }
            else
            {
                dp[s][j] = dp[s][j-1];
            }
            // cout<< dp[s][j]<< endl;
        }
        
    }
    // ll result;
    for(ll s=sum; s>0; s--){
        if(dp[s][N] <=W){
            cout << s <<endl;
            break;
        }
    }
    // cout << INT64_MAX;
    return 0;
}


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

int N; 
double ans = 0;

int main() {
  cin >> N;  
  for (int i = 0; i < N; i++) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") ans += x;
    else ans += x * 380000.0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            if (A <= 8 && B <= 8) {
                out.println("Yay!");
            } else {
                out.println(":(");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

Measured memory_bytes: 20052
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;
#define lli long ling int;

int main()
{
    long long int N, sum = 0;
    scanf("%lld", &N);

    for (long long int i = 1; i <= N; i++) {
        if (i % 3 == 0)
            continue;
        
        if (i % 5 == 0)
            continue;

        sum += i;
    }

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

    return 0;
}

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

int main(){
	int N;
	scanf("%d", &N);
	int a[1<<N];
	for(int i=0;i<(1<<N);i++)scanf("%d", &a[i]);
	int ans = 0;
	for(int i=1;i<(1<<N);i++){
		if(a[i]==0){
			for(int k=0;k<N;k++){
				if((i^(1<<k))<i && a[i^(1<<k)]==1){
					//printf("%d %d\n", i, i^(1<<k));
					printf("-1\n");
					return 0;
				}
			}
		}
		else{
			int flag = 1;
			for(int k=0;k<N;k++){
				if((i^(1<<k)) < i && a[i^(1<<k)]==1)flag=0;
			}
			if(flag==1)ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

int main(void) {

  long h,w,m;
  scanf("%ld %ld %ld", &h, &w, &m);
  long *check_h,*check_w,**bomb;
  check_h = (long*)malloc(sizeof(long)*(h+1));
  for (long i = 1; i <= h; i++) {
    check_h[i] = 0;
  }
  check_w = (long*)malloc(sizeof(long)*(w+1));
  for (long i = 1; i <= w; i++) {
    check_w[i] = 0;
  }
  bomb = (long**)malloc(sizeof(long*)*m);
  for (long i = 0; i < m; i++) {
    bomb[i] = (long*)malloc(sizeof(long)*2);
    scanf("%ld %ld", &bomb[i][0], &bomb[i][1]);
    check_h[bomb[i][0]]++;
    check_w[bomb[i][1]]++;
  }
  long max_h = check_h[1],count_h = 0,max_w = check_w[1],count_w = 0;
  for (long i = 2; i <= h; i++) {
    if (check_h[i] > max_h) {
      max_h = check_h[i];
    }
  }
  for (long i = 1; i <= h; i++) {
    if (check_h[i] == max_h) {
      count_h++;
    }
  }
  for (long i = 2; i <= w; i++) {
    if (check_w[i] > max_w) {
      max_w = check_w[i];
    }
  }
  for (long i = 1; i <= w; i++) {
    if (check_w[i] == max_w) {
      count_w++;
    }
  }
  long ans = max_h+max_w,count_all = count_h*count_w,count_bomb = 0;
  for (long i = 0; i < m; i++) {
    if (check_h[bomb[i][0]]+check_w[bomb[i][1]] == ans) {
      count_bomb++;
    }
  }
  if (count_bomb == count_all) {
    ans--;
  }
  printf("%ld\n", ans);

  return 0;
}

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

int main(){

  int N,L;
  cin >> N >> L;

  vector<string> vec(N);
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(),vec.end());
  
  for (int i=0; i<N; i++){
    cout << vec.at(i);
  }

  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	long long int a[100005], b[100005], c[100005];
	long long int dpa[100005], dpb[100005], dpc[100005];
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	dpa[0] = a[0];
	dpb[0] = b[0];
	dpc[0] = c[0];
	for(int i=0;i<n;i++){
		dpa[i+1] = a[i+1]+max(dpb[i],dpc[i]);
		dpb[i+1] = b[i+1]+max(dpa[i],dpc[i]);
		dpc[i+1] = c[i+1]+max(dpa[i],dpb[i]);
	}
	cout << max(dpa[n-1],(max(dpb[n-1],dpc[n-1]))) << endl;
	return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public class Prc
    {
        public string Name;
        public int Time;
        public Prc(string name, int time)
        {
            this.Name = name;
            this.Time = time;
        }
    }
    public void Proc()
    {
        string[] inpt = Console.ReadLine().Split(' ');
        int itemCount = int.Parse(inpt[0]);
        int q = int.Parse(inpt[1]);

        List<Prc> que = new List<Prc>();
        for(int i=0; i<itemCount; i++)
        {
            inpt = Console.ReadLine().Split(' ');
            Prc p = new Prc(inpt[0], int.Parse(inpt[1]));
            que.Add(p);
        }

        // ??????
        int time = 0;
        List<string> ans = new List<string>();

        while(que.Count > 0)
        {
            int tmAdd = Math.Min(que[0].Time, q);
            time += tmAdd;
            if(que[0].Time == tmAdd)
            {
                ans.Add(que[0].Name + " " + time);
                que.RemoveAt(0);
            } else
            {
                que[0].Time -= tmAdd;
                que.Add(que[0]);
                que.RemoveAt(0);
            }
        }
        foreach(string line in ans)
        {
            Console.WriteLine(line);
        }
    }

    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

const int MOD=1000000007;
const int MAX=2e5+9;

ll c[MAX];

ll fastPow(ll a, ll b) {
    if (!b) {
        return 1;
    }

    ll sq=fastPow(a, (b>>1LL));
    sq*=sq;

    if (b&1LL) {
        sq%=MOD;
        sq*=a;
    }

    return sq%MOD;
}

ll inv(ll a) {
    return fastPow(a, MOD-2);
}
/*
ll C(int n , int k){
    vector<int> a, b;
    int mx=max(k, n-k);
    for(int i=n; i>mx; --i) {
        a.push_back(i);
    }

    int mn=min(k, n-k);
    for(int i=2; i<=mn; ++i) {
        b.push_back(i);
    }

    for(int i=0; i<(int)a.size(); ++i){
        for(int j=0; j<(int)b.size(); ++j){
            int d=__gcd(a[i] , b[j]);
                a[i]/=d;
                b[j]/=d;
        }
    }

    ll res1=1;
    for(auto it : a) {
        res1*=(ll)it;
        res1%=MOD;
    }

    ll res2=1;
    for(auto it : b) {
        res2*=(ll)it;
        res2%=MOD;
    }

    return (res1*inv(res2))%MOD;;
}*/

ll C(ll n, ll k) {
    ll res=1;
    for (int i = 1; i <= k; ++i) {
        res=((res*(ll)(n - k + i)%MOD)*inv(i))%MOD;
    }

    return res;
}

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

    ll n, a, b;
    cin >> n >> a >> b;

    ll ans=(((fastPow(2, n)-C(n, a)+MOD)%MOD)-1+MOD)%MOD;
    if (a!=b) {
        ans=(ans-C(n, b)+MOD)%MOD;
    }

    cout << ans;

    return 0;
}


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

int main() {
  int x, t;
  cin >> x >> t;

  if(x>t) {
    cout << x-t << endl;
  }
  else {
    cout << 0 << endl;
  }
  return 0;
}

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

vector<int> g[2100];
bool check[2100] = {};
int num = 0,n,m;

int dfs(int x,int k)
{
	if (k < 0) return 0;
	num++;
	if (g[x].size() == 0)	return 1;
	int maxdeep = 0;
	for (int i = 0;i<g[x].size();i++)
	if (check[g[x][i]] == 0)
	{
		check[g[x][i]] = 1;
		maxdeep = max(maxdeep,dfs(g[x][i],min(k - 1,m - maxdeep - 1)));
	}
	return maxdeep + 1;	
}

int main()
{
	cin>>n>>m;
	for (int i = 1,u,v;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = 2147483647;
	for (int i = 1;i<=n;i++) 
	{
		check[i] = 1;
		dfs(i,m);
		if (ans > n - num) ans = n - num;
		num = 0;
		memset(check,0,sizeof(check));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9+7;
int N, M;
int dp[303][303][303];
vector<pair<int, int> > lx[303];
int main()
{
  scanf("%d%d", &N, &M);
  for(int i=1; i<=N; ++i) lx[i].clear();
  for(int i=0; i<M; ++i)
  {
    int l, r, x; scanf("%d%d%d", &l, &r, &x);
    lx[r].emplace_back(l, x);
  }
  int ans = 0;
  memset(dp, 0, sizeof dp);
  dp[0][0][0] = 1;
  for(int i=0; i<=N; ++i)
    for(int j=0; j<=N; ++j)
      for(int k=0; k<=N; ++k)
      {
        if(dp[i][j][k] == 0) continue;
        int V = max(i, max(j, k));
        for(auto t: lx[V])
        {
          int l, x; tie(l, x) = t;
          if(l <= i && i <= V) --x;
          if(l <= j && j <= V) --x;
          if(l <= k && k <= V) --x;
          if(x != 0){ dp[i][j][k] = 0; break;}
        }
        if(V==N)
        {
          ans += dp[i][j][k]; ans %= MOD;
        }
        else
        {
          dp[V+1][j][k] += dp[i][j][k]; dp[V+1][j][k] %= MOD;
          dp[i][V+1][k] += dp[i][j][k]; dp[i][V+1][k] %= MOD;
          dp[i][j][V+1] += dp[i][j][k]; dp[i][j][V+1] %= MOD;
        }
      }
  printf("%d\n", ans);
}

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i) cin >> vec[i];
    sort(vec.begin(), vec.end());

    int ans = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                if (vec[k] != vec[j] and vec[i] != vec[j] and
                    vec[k] + vec[j] > vec[i]) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}

int main(){
	ll N; cin>>N;
	vector<ll>A(N);
	vector<ll>B(N);
	vector<ll>C(N);

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

	ll dp[100000][3];//dp[i][j]:i日目(0-origin)までの最大値(i日目はj)
	memset(dp,0,sizeof(dp));

	//初期化
	dp[0][0]=A[0];
	dp[0][1]=B[0];
	dp[0][2]=C[0];

	rep1(i,N-1){
		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][1]+C[i]);
		chmax(dp[i][2],dp[i-1][0]+C[i]);
	}
	cout<<maxx(dp[N-1][0],dp[N-1][1],dp[N-1][2]);
}

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

#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

  vi a(n);
  rep(i, n) cin >> a[i];

  map<int, int> cnt;
  rep(i, n) cnt[a[i]]++;
  
  int ans = 0;
  for(int b = 31; b >= 0; b--){
    int tmp = 1<<b;
    for(auto& p : cnt){
      if(p.first > 0){
        if(cnt.count(tmp-p.first)> 0){
          if(tmp == p.first*2){
            ans += p.second/2;
            p.second = 0;
          }else{
            int res = min(p.second, cnt[tmp-p.first]);
            ans += res;
            p.second -= res;
            cnt[tmp-p.first] -= res;
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14336
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()

ai = a[-1]
j = bisect.bisect(a, ai/2)
if abs(ai/2 - a[j]) < abs(ai/2 - a[j-1]):
    aj = a[j]
else:
    aj = a[j-1]

print(ai, aj)


Measured memory_bytes: 14052
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


def main():
    S = input().strip("\n")
    if len(set(S))==2 and S.count(S[0])==2:
        return "Yes"
    return "No"


print(main())


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  double r; cin >>r;
  cout << 2*r*PI << endl;

  return 0;
}


Measured memory_bytes: 3768
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define LONGMAX 1e18
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
	ll N,M;
	cin>>N>>M;
	ll j=500*N;
	if(j>=M)
	    cout<<"Yes"<<endl;
	  else
	    cout<<"No"<<endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 256
#include<stdio.h>

/*構造体の定義*/
typedef struct {
	char suit;
	int value;
} Card ;


void swap_Card(Card *x, Card *y)
{
	Card temp = *x;
	*x = *y;
	*y = temp;
}


//バブルソート
void BubbleSort(Card A[], int N) {
	int i, j;
	Card temp;

	for (i = 0; i < N-1; i++) {
		for (j = N - 1; j > i ; j--) {
			if (A[j].value < A[j - 1].value) {
				temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
			}
		}
	}
}

//選択ソート
void SelectionSort(Card A[], int N) {
	int i, j;
	int minj;
	Card temp;

	for (i = 0; i < N-1; i++) {
		minj = i;
		for (j = i+1; j < N; j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		temp = A[i];
		A[i] = A[minj];
		A[minj] = temp;
	}
}

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

	int i,j;
	Card BC[36];
	Card SC[36];

	for (i = 0; i < N; i++) {
		Card c;
		scanf("%c", &c.suit);
		scanf("%d ", &c.value);
		BC[i] = c;
		SC[i] = c;
	}

    
	/* 
    for (i = 0; i < N - 1; i++) {
        for (j = N - 1; j > i; j--) {
            if (BC[j].value < BC[j - 1].value)
                swap_Card(&BC[j], &BC[j - 1]);
        }
    }
	
	
    for (i = 0; i < N - 1; i++) {
        int minj = i;
        for (j = i + 1; j < N; j++) {
            if (SC[j].value < SC[minj].value)
                minj = j;
        }
        swap_Card(&SC[i], &SC[minj]);
    }
    */
    
    BubbleSort(BC,N);
    SelectionSort(SC,N);
	
	/* Output */
	for (i = 0; i < N - 1; i++) {
		printf("%c%d ", BC[i].suit, BC[i].value);
	}
	printf("%c%d\n", BC[N - 1].suit, BC[N - 1].value);
	puts("Stable");

	for (i = 0; i < N - 1; i++) {
		printf("%c%d ", SC[i].suit, SC[i].value);
	}
	printf("%c%d\n", SC[N - 1].suit, SC[N - 1].value);

	for (i = 0; i < N; i++) {
		if (BC[i].suit != SC[i].suit) {
			puts("Not stable");
			return 0;
		}
	}
	puts("Stable");

	return 0;
}


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

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int min_cost = A * X + B * Y;
    for (int Z = 0; Z <= 2 * max(X, Y); ++Z) {
        int cost = A * max(0, X - Z / 2) + B * max(0, Y - Z / 2) + C * Z;
        if (min_cost > cost)
            min_cost = cost;
    }
    cout << min_cost << endl;
}


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

using namespace std;

signed main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for (int& x : a) {
        scanf("%d", &x);
    }
    vector<bool> dp(k + 1);
    // dp[i] - TRUE if the first player wins if there are i stones remaining
    for (int stones = 0; stones <= k; stones++) {
        for (int x : a) {
            if (stones >= x && !dp[stones - x]) {
                dp[stones] = true;
            }
        }
    }
    puts(dp[k] ? "First" : "Second");
    return false;
}

Measured memory_bytes: 256
s = input()
q = int(input())
revFlag = False
head, tail = [], []

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    revFlag = not revFlag
  else:
    if int(query[1]) == 1:
      if not revFlag:
        head.append(query[2])
      else:
        tail.append(query[2])
    else:
      if not revFlag:
        tail.append(query[2])
      else:
        head.append(query[2])

if not revFlag:
  h = "".join(reversed(head))
  t = "".join(tail)
  print("".join([h, s, t]))
else:
  h = "".join(head)
  t = "".join(reversed(tail))
  print("".join([t, s[::-1], h]))

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

#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define endl "\n"
#define int long long

int32_t main()
{
    IOS;

    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        cout << "x";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    N = input()
    if N == 0:
        break
    data = [map(int,raw_input().split()) for _ in xrange(N)]
    data.sort(key = lambda x:-x[0])
    R,W = zip(*data)
    empty = max(0,R[0]-sum(R[1:]))
    #print "empty",empty
    dp = [False]*(empty+1)
    dp[0] = True
    ma = 0
    for w in W[-1:0:-1]:
        if empty < w:
            break
        for i in xrange(empty,-1,-1):
            if dp[i] and i+w <= empty:
                ma = max(ma, i+w)
                dp[i+w] = True
    #print filter(lambda x: dp[x], xrange(empty+1))
    print sum(R)+sum(W)+(empty-ma)

Measured memory_bytes: 4484
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll n;cin >> n;
	if(n%2==1)
	{
		cout<<0<<endl;
		return 0;
	}
	ll ans =0;

	ans += n/10;
	for(ll i =  50;i<=n;i*=5)
	{
		//cout<<ans+n/i<<endl;
		ans += n/i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
  	long long x;
  	cin >> n >> x;
  	long long a[n];
  	for (int i = 0; i < n; ++i)
      	cin >> a[i];
  	long long ans = abs(x - a[0]);
  	for (int i = 1; i < n; ++i)
    	ans = __gcd(ans, abs(x - a[i]));
  	cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 1005;
const int M = 301;
int n,m;
int a,b,c,d;
int main()
{
    while (~scanf("%d",&n))
    {
        LL ans = 1;
        for (int i=0;i<n;i++)
        {
            LL a;
            scanf("%lld",&a);
            LL tmp = __gcd(a,ans);
            ans = ans/tmp*a;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

/*

*/

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 25.12.2019 00:26:56       
**/
#include <bits/stdc++.h>

using namespace std;

struct Line {
  long long k;
  long long b;
};

inline long long BetterFrom(const Line& p, const Line& q) {
  long long num = p.b - q.b;
  long long den = q.k - p.k;
  if (den < 0) {
    num = -num;
    den = -den;
  }
  long long r = num % den;
  if (r < 0) {
    r += den;
  }
  return (num - r) / den + 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long c;
  cin >> n >> c;
  vector<long long> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<long long> dp(n);
  dp[0] = 0;
  vector<Line> st;
  vector<long long> sx;
  int ptr = 0;
  for (int i = 0; i < n - 1; i++) {
    Line me = {-2 * h[i], dp[i] + h[i] * h[i] + c};
    if (st.empty()) {
      st.push_back(me);
    } else {
      long long at = BetterFrom(me, st.back());
      while (st.size() >= 2 && at <= sx.back()) {
        st.pop_back();
        sx.pop_back();
        at = BetterFrom(me, st.back());
      }
      st.push_back(me);
      sx.push_back(at);
    }
    ptr = min(ptr, (int) st.size() - 1);
    while (ptr < (int) st.size() - 1 && h[i + 1] >= sx[ptr]) {
      ++ptr;
    }
    dp[i + 1] = h[i + 1] * h[i + 1] + st[ptr].k * h[i + 1] + st[ptr].b;
  }
  cout << dp.back() << '\n';
  return 0;
}


Measured memory_bytes: 11504
use v5.26; # strict say state

chomp (my ($n, $k) = split / /, <STDIN>);
my $MOD = 1e9 + 7;
my $sum = 0;
for my $i ($k..$n+1) {
  my $fst = $i * ($i - 1) / 2;
  my $end = (2 * $n - ($i - 1)) * $i / 2;
  $sum += $end - $fst + 1;
  $sum %= $MOD;
}
say $sum;

Measured memory_bytes: 4840
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
#include <string>

using namespace std; using ll=long long; const int INF=1e9; using P=pair<int,int>;

int main() {
  int n,x; cin>>n>>x; int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n); int i;
  for(i=0;i<n;i++) {
    x-=a[i];
    if (x<0) break;
  }
  if (x!=0 && i==n) cout<<n-1<<endl;
  else cout<<i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);
 
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;
 
constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;
 
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	string S; cin >> S;
	ll N = S.size();
	ll K; cin >> K;
	S = "0" + S;
	auto dp = multivector(N+1,2,5,0LL);
	dp[0][0][0] = 1;
	for(int i = 1; i <= N; ++i) {
		ll c = S[i]-'0';
		for(int j = 0; j < 4; ++j) {
			if(c==0) dp[i][0][j] += dp[i-1][0][j];
			else dp[i][0][j+1] += dp[i-1][0][j];
		}

		for(int j = 0; j < 4; ++j) {
			if(c) dp[i][1][j+1] += (c-1)*dp[i-1][0][j];
			if(c) dp[i][1][j] += dp[i-1][0][j];
		}

		for(int j = 0; j < 4; ++j) {
			dp[i][1][j+1] += 9LL*dp[i-1][1][j];
			dp[i][1][j] += dp[i-1][1][j];
		}
	}
	cout << dp[N][0][K] + dp[N][1][K] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c){
    cout<<b+c<<endl;
  }
  else{
    cout<<2*b+a+1<<endl;
  }
  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 vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    ll ans=0;
    rep(i,s.size()){
        int x = stoi(s.substr(i,1));
        ans+=x;
    }
    if(ans%9==0){
        cout << "Yes" << "\n";
        return 0;
    }else{
        cout << "No" << "\n";
        return 0;
    }
}   

Measured memory_bytes: 3772
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tokenizer = null;
    int totalCases, testNum;

    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    void solve() throws IOException {

    }

    void execute() throws IOException {
        int n = ni();
        int w = ni();
        int[][] k = new int[n][2];
        for (int i = 0; i < n; i++) {
            k[i][0] = ni();
            k[i][1] = ni();
        }
        long[][] dp = new long[n + 1][w + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= w; j++) {
                int weight = k[i - 1][0];
                int value = k[i - 1][1];
                if (j >= weight) {
                    dp[i][j] = Math.max(value + dp[i - 1][j - weight], dp[i-1][j]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        out.print(dp[n][w]);

        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().execute();
    }

    void debug(Object... os) {
        System.out.println(Arrays.deepToString(os));
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String ns() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(br.readLine());
        }
        return tokenizer.nextToken();
    }

    String nline() throws IOException {
        tokenizer = null;
        return br.readLine();
    }

    boolean input() throws IOException {
        return true;
    }

}


Measured memory_bytes: 129108
N = int(input())
cnt_a = [0] * 200000
A = [int(n) for n in input().split()]

for a in A:
  if a != 0:
    cnt_a[a-1] += 1
  cnt_a[a] += 1
  cnt_a[a+1] += 1

print(max(cnt_a))

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

int main() {
int N;
  cin>>N;
  vector<int>a(100010), all(100010);
  for(int i=0; i<N; i++){
   cin>>a[i];
   all[a[i]+1]++;
   if(a[i]>0){all[a[i]-1]++;}
   all[a[i]]++; 
  }
  
  int ans=0;
  for(int i=0; i<=100000; i++){
    if(all[i]){ans=max(ans, all[i]);}
  }
  
  cout<<ans;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll ;

int main(){
  int n,m;
  cin >> n >> m;
  int p[m],y[m];
  vector<int>yd[n+1];
  for(int i=0;i<m;i++){
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }
  for(int i=0;i<n;i++){
    sort(yd[i+1].begin(),yd[i+1].end());
  }
  for(int i=0;i<m;i++){
  long long ans;
  ans = ll(p[i])*1000000 + lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin()+1;
  printf("%012lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, S;
    cin >> N >> K >> S;
    vector<ll> ans(N);
    REP(i,N){
        if(K > 0){
            ans[i] = S;
            K--;
        }
        else{
            if(S != INF) ans[i] = INF;
            else ans[i] = INF - 1;
        }
    }
    REP(i,N) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 2176