akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

ll rep_power_modM(ll a, ll n, ll M){
    if(n == 0)return 1;
    if(n%2 == 0){ll tmp = rep_power_modM(a,n/2,M); return tmp*tmp%M;}
    return a*rep_power_modM(a,n-1,M)%M;
}

int main(){
    int n,a,b; cin>>n>>a>>b;
    ll ans = rep_power_modM(2,n,MOD)-1;
    ll comb_a = 1; rep(i,a){comb_a *= (n-i)%MOD; comb_a%=MOD;}
    ll comb_b = 1; rep(i,b){comb_b *= (n-i)%MOD; comb_b%=MOD;}

    ll divisor_a = 1; rep(i,a){divisor_a *= (i+1)%MOD; divisor_a %=MOD;}
    ll divisor_b = 1; rep(i,b){divisor_b *= (i+1)%MOD; divisor_b %=MOD;}

    comb_a = comb_a * rep_power_modM(divisor_a,MOD-2,MOD)%MOD;
    comb_b = comb_b * rep_power_modM(divisor_b,MOD-2,MOD)%MOD;
    ans -= comb_a; if(ans<0)ans+=MOD;
    ans -= comb_b; if(ans<0)ans+=MOD;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

vs generate_cand(int l){
  vs res;
  if(l==0){
    res.eb(""); return res;
  }
  vs tmp = generate_cand(l-1);
  for(string x : tmp){
    rep(i,26){
      res.eb( x + (char)('a'+i));
    }
  }
  return res;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int n; cin >> n;
  vs s(n);
  rep(i,n) cin >> s[i];

  set<string> ng;
  for(int l=1;l<=4;l++){
    for(string x : s){
      if(x.size()<l) continue;
      rep(i,x.size()-l+1){
        ng.em( x.substr(i,l) );
      }
    }
  }

  for(int l=1;l<=4;l++){
    vs cand = generate_cand(l);
    for(string x : cand){
      if(ng.count(x) == 0) {
        cout << x << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 68336
#include<bits/stdc++.h>
#define LL long long
#define N 111111
using namespace std;
const int debug=0;
int n,i,x,y,z,an,tot,a[N],fir[N],la[N*2],ne[N*2],va[N*2],sz[N],mv[N],q[N],E[N];
bool vis[N];
LL V[N*3];
void ins(int x,int y,int z){la[++tot]=y;ne[tot]=fir[x];fir[x]=tot;va[tot]=z;}
void bd(int k,int l,int r){
	V[k]=-1e18;
	if(l==r)return;
	int md=l+r>>1;
	bd(k<<1,l,md);bd(k<<1|1,md+1,r);
}
void add(int k,int l,int r,int x,LL z){
	V[k]=max(V[k],z);
	if(l==r)return;
	int md=l+r>>1;
	if(x<=md)add(k<<1,l,md,x,z);else add(k<<1|1,md+1,r,x,z);
}
int qu(int k,int l,int r,LL z){
	if(V[k]<z)return -1e9;
	if(l==r)return l;
	int md=l+r>>1;
	if(V[k<<1|1]>=z)return qu(k<<1|1,md+1,r,z);else return qu(k<<1,l,md,z);
}
void dsz(int x,int fa,int dis,int&mx){
	mx=max(mx,dis);
	sz[x]=1;mv[x]=0;
	for(int i=fir[x],y;i;i=ne[i])
		if(!vis[y=la[i]]&&y!=fa)
			dsz(y,x,dis+1,mx),sz[x]+=sz[y],mv[x]=max(mv[x],sz[y]);
}
void drt(int zs,int x,int fa,int&rt){
	mv[x]=max(mv[x],sz[zs]-sz[x]);
	if(mv[x]<mv[rt]||!rt)rt=x;
	for(int i=fir[x],y;i;i=ne[i])
		if(!vis[y=la[i]]&&y!=fa)drt(zs,y,x,rt);
}
void getup(int x,int fa,LL z,LL mi,int dis,int mx){
//	printf("%d %lld \n",x,mi);
	if(mi>=0)add(1,1,mx,dis,z);//,printf("ADD %d %d %lld\n",x,dis,z);
	for(int i=fir[x],y;i;i=ne[i])
		if(!vis[y=la[i]]&&y!=fa)getup(y,x,z-va[i]+a[y],min(mi,0ll)-va[i]+a[y],dis+1,mx);
}
void getdown(int x,int fa,LL z,LL mi,int dis,int mx){
//	printf("%d %lld   %d\n",x,mi,dis);	
	z+=a[x];
	an=max(an,qu(1,1,mx,-mi)+dis+1);//>=-mi de zuidadeshu
	if(mi>=0)an=max(an,dis+1);
	for(int i=fir[x],y;i;i=ne[i])
		if(!vis[y=la[i]]&&y!=fa)getdown(y,x,z-va[i],min(mi,z-va[i]),dis+1,mx);
}
void fz(int x){
	int i,p,y,rt=0,mx=0,t=0;
	dsz(x,0,0,mx);
mx ++;
	drt(x,x,0,rt);
	vis[rt]=1;
//	printf("------%d------\n",rt);
	if(mx){
		bd(1,1,mx);
		for(i=fir[rt];i;i=ne[i])if(!vis[la[i]])q[++t]=la[i],E[t]=va[i];
		for(i=1;i<=t;i++)y=q[i],getdown(y,rt,a[rt]-E[i],a[rt]-E[i],1,mx),getup(y,rt,a[q[i]]-E[i],a[q[i]]-E[i],1,mx);
		an=max(an,qu(1,1,mx,0)+1);
		bd(1,1,mx);
		for(i=t;i;i--)y=q[i],getdown(y,rt,a[rt]-E[i],a[rt]-E[i],1,mx),getup(y,rt,a[q[i]]-E[i],a[q[i]]-E[i],1,mx);
//		printf("%d\n",an);
	}
	for(i=fir[rt];i;i=ne[i])if(!vis[y=la[i]])fz(y);
}
void dfs(int x,int fa,LL z,int w){
	//if(mi>=0){
		an=max(an,w);
	
	//}
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa)
		if(z-va[i]>=0)dfs(la[i],x,z-va[i]+a[la[i]],w+1);
}
int main(){
	//srand(time(0));
	an=1;
	if(debug)n=1000;else scanf("%d",&n);
	for(i=1;i<=n;i++)if(debug)a[i]=rand()%20+1,printf("%d ",a[i]);else scanf("%d",&a[i]);
	//puts("");
	for(i=1;i<n;i++){
		if(debug){
			x=rand()%i+1;
			y=i+1;
			z=rand()%20+1;
			printf("%d %d %d\n",x,y,z);
		}else scanf("%d%d%d",&x,&y,&z);
		ins(x,y,z),ins(y,x,z);
	}
/*	for(i=1;i<=n;i++){
		dfs(i,0,a[i],1);
		memset(vis,0,sizeof vis);
	}
	printf("%d\n",an);
	an=0;*/
	fz(1);
	printf("%d\n",an);
}

Measured memory_bytes: 17104
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <utility>
using namespace std;

int cnt;

void trace(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i > 0)
            printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
}

void insertionSort(int a[], int n, int g)
{
    int v;
    for (int i = 0; i < n; i++)
    {
        v = a[i];
        int j;
        for (j = i - g; j >= 0 && a[j] > v; j = j - g)
        {
            a[j + g] = a[j];
            cnt++;
        }
        a[j + g] = v;
    }
}

void shellSort(int a[], int n)
{
    cnt = 0;
    int m = log2(n)+1;
    int g[m];
    g[0] = n/2+1;
    for(int i = 1; i < m; i++)
        g[i] =  g[i-1]/2;
    for (int i = 0; i < m; i++)
        insertionSort(a, n, g[i]);
    printf("%d\n", m);
    trace(g, m);
    printf("%d\n", cnt);
    for (int i = 0; i < n; i++)
        printf("%d\n", a[i]);
}

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

    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    shellSort(a, n);

    return 0;
}



Measured memory_bytes: 7236
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define to_bin(b, n) bitset<b>(n) 
#define setBits(n) __builtin_popcountll(n) 
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int n, cnt = 0;
    cin >> n;
    vi in(n);
    UMO<int, int> ans;
    for(auto &i : in) cin >> i, ans[i]++, cnt += i;
    int q;
	cin >> q;
	while(q--) {
		int a, b;
		cin >> a >> b;
		debug_out(ans[a] * a, ans[a] * b);
		cnt -= (ans[a] * a);
		cnt += (ans[a] * b);
		ans[b] += ans[a];
		ans[a] = 0;
		cout << cnt << endl; 
	}
}
  
int32_t main() {
 
    FAST;

   
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 7884
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

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

	ll ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
(let* ((n (read))
    (s (make-array n))
    (ans 0)
    (herasu 0))
    (loop for i below n do
        (progn
            (setf (aref s i) (read))
            (incf ans (aref s i))
        )
    )
    (setf s (sort s #'<))
    (loop for i below n do
        (if (not (zerop (rem (aref s i) 10)))
            (progn
                (setf herasu (aref s i))
                (return)
            )
        )
    )
    (if (zerop (rem ans 10))
        (if (zerop herasu)
            (setq ans 0)
            (decf ans herasu)
        )
    )
    (format t "~D~%" ans)
)

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

signed main() {

    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int Max = max({A, B, C});
    for (int i = 1; i <= K; i++) {
        Max = Max*2;
    }
    cout << Max + (A + B + C) - max({A, B, C}) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++){
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	cout << d[(N / 2)] - d[(N / 2)-1] << endl;
	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 200;
string s[N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  set<int> rows, cols;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < m; ++j) {
      sum += s[i][j] == '.';
    }
    if (sum == m) rows.insert(i);
  }
  for (int j = 0; j < m; ++j) {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += s[i][j] == '.';
    }
    if (sum == n) cols.insert(j);
  }
  for (int i = 0; i < n; ++i) {
    if (rows.count(i)) continue;
    string cur = "";
    for (int j = 0; j < m; ++j) {
      if (cols.count(j)) continue;
      cur += s[i][j];
    }
    cout << cur << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  REP(i, n) cin >> s[i];
  sort(ALL(s));
  string ans;
  REP(i, n) ans += s[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int l=1;
  for(int i=1;i<s.length();i++){
    if(s[i]!=s[i-1])
      l=l+1;
  }
  cout<<l<<"\n";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
    //cin.sync_with_stdio(0); cin.tie(0);
    //cin.exceptions(cin.failbit);
    int n, ans = 0;
    cin >> n;
    rep(i, 1, n+1)
        if (i&1)
            ans++;
    printf("%.9f\n", (double)ans/n);
    //cout << ((double)ans/n) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int A,B,K;
  cin>>A>>B>>K;
  cout<<max(0LL,A-K)<<" "<<max(0LL,min((A+B-K),B))<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
void chmax(T &a, T b) {
    if (b > a) a = b;
}

constexpr int M = 26, D = 365;

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

    int r[D];
    int c[M];
    int s[D][M];

    for (int j = 0; j < M; j++) {
        cin >> c[j];
    }
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < M; j++) {
            cin >> s[i][j];
        }
    }

    int l[M];
    for (int j = 0; j < M; j++) {
        l[j] = -1;
    }

    for (int i = 0; i < D; i++) {
        pair<int, int> p = { -1, -1 };
        for (int j = 0; j < M; j++) {
            int d = i - l[j];
            //int t = 0;
            //if (i < D - 5) {
            //    t = 0;
            //    for (int k = 1; k <= 5; k++) {
            //        t += s[i + k][j] - c[j] * k;
            //    }
            //    t /= 900;
            //}
            int v = min(5, D - i) * c[j] * d + s[i][j];
            if (i < D - 1) {
                int t = l[j];
                l[j] = i;
                int u = 0;
                for (int k = 0; k < M; k++) {
                    chmax(u, min(5, D - (i + 1)) * c[k] * ((i + 1) - l[k]) + s[i + 1][k]);
                }
                v += u * (i == D - 2 ? 1.0 : 0.8);
                l[j] = t;
            }
            chmax(p, { v, j });
        }
        r[i] = p.second;
        l[r[i]] = i;
    }

    {
        ll sc = 0;
        int l[M];
        for (int j = 0; j < M; j++) {
            l[j] = -1;
        }
        for (int i = 0; i < D; i++) {
            sc += s[i][r[i]];
            l[r[i]] = i;

            for (int j = 0; j < M; j++) {
                sc -= c[j] * (i - l[j]);
            }
        }
        cerr << "satisfaction  " << sc << '\n';
    }

    for (int i = 0; i < D; i++) {
        cout << r[i] + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 3684
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long lli;
const int maxn = 1e5 + 5;
const int MOD = 998244353;
int n;
int d[maxn];
int cnt[maxn];

void ReadInput()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> d[i];
        ++cnt[d[i]];
    }
    //sort(d + 1, d + n + 1);
}

void Solve()
{
    if(cnt[0] == 0 || cnt[0] > 1 || d[1] != 0)
    {
        cout << "0\n";
        return;
    }
    lli ans = 1;
    for(int i = 1; i <= n; ++i)
        if(d[i] > 0) ans = ans * (lli)cnt[d[i] - 1] % MOD;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


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

int main() {
        ios_base:: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n, m;
        cin >> n >> m;
        if(m == n) {
                cout << "Yes";
        } else {
                cout << "No";
        }
        return 0;
}

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

int main(){

  int n;cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n-1; i++) cout << a[n-i-1] << " ";
  cout << a[0] << endl;


}

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

int main() {
	ios::sync_with_stdio(false);
	int N;
	vector<int> a;
	cin >> N;
	int i;
	int x;
	for (i = 0; i < 3 * N; i++) {
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	ll sum = 0;
	for (i = N; i < 3 * N; i += 2) {
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
long long n,a[N],b[N],ans=0;
int main()
{
	cin>>n;
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++){
		if(a[i]>=b[i])a[i]-=b[i],ans+=b[i],b[i]=0;
		else ans+=a[i],b[i]-=a[i],a[i]=0;
		if(b[i]!=0&&a[i+1]>=b[i]) a[i+1]-=b[i],ans+=b[i];
		else if(b[i]!=0&&a[i+1]<b[i]) ans+=a[i+1],a[i+1]=0;
	}
	cout<<ans;
	return 0;
}

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

const int mod = 1000000007;

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

    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll ans = 0;
    
    for(int i = 0; i < 60; i++){
        ll x = 0;
        for(int j = 0; j < n; j++){
            if(a[j]>>i&1) x++;
        }
        ll add = x * (n - x) % mod;
        for(int j = 0; j < i; j++){
            add = add * 2 % mod;
        }
        ans += add;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

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

int main()
{
    fsscan();
    string s1,s2;
    cin>>s1;
    cin>>s2;
    int c=0;
    for(int i=0;i<sz(s1);i++){
        if(s1[i]==s2[i])
        c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
int main(){
  int x,ans=0;
  cin>>x;
  for(int i=2; i<=9; i++){
    for(int j=1; j<=sqrt(x); j++){
      if(ans<(int)pow(j,i) && (int)pow(j,i)<=x){
        ans = (int)pow(j,i);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

main = do
  [n, k] <- map (read::String -> Int) . words <$> getLine
  arr <- listArray (1, n) . sort <$> forM [1..n] (\i -> (read::String -> Int) <$> getLine)
  print $ foldl (\acc i -> min acc (arr ! (i + k - 1) - arr ! i)) (maxBound::Int) [1..(n - k + 1)]

Measured memory_bytes: 67964
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int v[100001];
	int count[100001]={0};
	int countmod[2][100001]={0};
	int maxnum[2]={0};
	int maxyouso[2];
	vpint kazu[2];
	vint vs;
	vint vsmod[2];
	scan(N);
	rep(i,N){
		scan(v[i]);
		if(count[v[i]]==0) vs.push_back(v[i]);
		count[v[i]]++;
		if(countmod[i%2][v[i]]==0) vsmod[i%2].push_back(v[i]);
		countmod[i%2][v[i]]++;
	}
	if(vs.size()==1) prin(N/2);
	else{
		rep(mod,2){
			rep(i,vsmod[mod].size()){
				kazu[mod].push_back(mp(countmod[mod][vsmod[mod][i]],vsmod[mod][i]));
			}
			sort(kazu[mod].rbegin(),kazu[mod].rend());
		}
		if(kazu[0][0].second==kazu[1][0].second){
			prin(min(N-kazu[0][0].first-kazu[1][1].first,N-kazu[0][1].first-kazu[1][0].first));
		}
		else{
			prin(N-kazu[0][0].first-kazu[1][0].first);
		}
	}
	return 0;
}


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

void Main() {
    // input
    u_int32_t N, K;
    cin >> N >> K;
    vector<u_int32_t> frutes(N);

    for (u_int32_t i = 0; i < N; i++) {
        cin >> frutes[i];
    }

    // translate
    sort(frutes.begin(), frutes.end());
    u_int32_t ans = 0;
    for (u_int32_t i = 0; i < K; i++) {
        ans += frutes[i];
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
vector<int> a[200500];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	bool ok = false;
	for (auto f : a[1]) {
		if (f == n) {
			ok = true;
		}
		for (auto ff : a[f]) {
			if (ff == n) {
				ok = true;
			}
		}
	}
	if (ok)
		cout << "POSSIBLE";
	else
		cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 14980
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define P pair<ll,ll>
const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

void dijkstra(int s,vector<vector<ll>> &to,vector<vector<ll>> &cost,vector<ll> &d){
    d[s] = 0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push({0,s});
    while(!q.empty()){
        P now = q.top();q.pop();
        for(int i=0;i<to[now.second].size();i++){
            int next = to[now.second][i];
            if(d[next]>now.first+cost[now.second][i]){
                d[next] = now.first+cost[now.second][i];
                q.push({d[next],next});
            }
        }
    }
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M;
    cin >> N >> M;
    vector<ll> L(M),R(M),C(M);
    vector<vector<ll>> to(N+1),cost(N+1);
    vector<ll> d(N+1,2e14);
    rep(i,M){
        cin >> L[i] >> R[i] >> C[i];
        to[L[i]].push_back(R[i]);
        cost[L[i]].push_back(C[i]);
        to[R[i]].push_back(L[i]);
        cost[R[i]].push_back(C[i]);
    }
    rep(i,N){
        to[i+1].push_back(i);
        cost[i+1].push_back(0);
    }
    dijkstra(1,to,cost,d);
    cout << (d[N]!=2e14?d[N]:-1) << endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<P> tmp(n);
    REP(i, n) {
        cin >> a[i];
        tmp[i].first = a[i], tmp[i].second = i;
    }
    sort(ALL(tmp));
    REP(i, n) a[tmp[i].second] = i+1;

    int ans = 0;
    REP(i, n) if(i % 2 == 0) if(a[i] % 2 != 1) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int N,A[101010];

ll solve(){
    if(N==0){
        if(A[0]==1) return 1;
        else return -1;
    }

    if(A[0]!=0) return -1;

    ll tot=0;
    rep(i,N+1) tot+=A[i];

    ll cur=1;
    ll ans=1;
    for(int i=1;i<N+1;i++){
        cur*=2;
        if(cur<A[i]) return -1;
        ans+=min(cur,tot);
        cur=min(cur,tot)-A[i];
        tot-=A[i];
    }

    return ans;
}

int main(){
    cin>>N;
    rep(i,N+1) cin>>A[i];
    cout<<solve()<<endl;
}


 

Measured memory_bytes: 4012
#include <stdio.h>
int a[1000001];
int main(){
    int K;
    scanf("%d",&K);
    a[1]=7%K;
    for(int i=2;i<=K;i++)a[i]=(a[i-1]*10+7)%K;

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

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

int main() { 
  int n, ans;
  cin >> n;
  ans = n % 1000;
  if (ans != 0){
    ans = 1000 - ans;
  }
  cout << ans << endl;
  return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#include <vector>
using namespace std;

vector<int> primes;
vector<int> smallest_prime_factor;

int sieve(int nmax){
    primes.clear();
    smallest_prime_factor.assign(nmax+1, 0);

    // ここではあえて愚直な書き方
    for (int n=2; n<=nmax; ++n) {
        if (!smallest_prime_factor[n]) {
            primes.push_back(n);
            for (int kn=n; kn<=nmax; kn+=n) {
                if (!smallest_prime_factor[kn]) {  // ←このチェックをせずに上書きを続けると largest_prime_factor[] が出来上がる
                    smallest_prime_factor[kn] = n;
                }
            }
        }
    }
    return primes.size();
}

// xを素因数分解
vector<int> factorize(int x) {
    vector<int> prime_factors;
    while (x > 1) {
        int s = smallest_prime_factor[x];
        if (!s) break;
        prime_factors.push_back(s);
        x /= s;
    }
    return prime_factors;
}

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll M=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % M; }
ll SUB(ll x, ll y) { return (x-y+M) % M; }
ll MUL(ll x, ll y) { return x*y % M; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { assert(y%M!=0); return MUL(x, POW(y, M-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }


ll solve(int N) {
    // 1-1e3
    map<int,int> st;
    rep1(i,N){
        vi f = factorize(i);
        for (int fi : f){
            ++st[fi];
        }
    }
    // cerr << st << endl;
    ll ans = 1LL;
    for(auto p:st){
        ans = MUL(ans, p.second+1);
    }
    return ans;
}

int main() {
    sieve(1000);
    int N; cin >> N;
    cout << solve(N) << endl;
    return 0;
}


Measured memory_bytes: 256
s = gets.to_i

list = []
list[s] = 1

(2..1000000).each do |i|
  if s.even?
    s /= 2
  else
    s = 3 * s + 1
  end

  if list[s]
    puts i
    break
  else
    list[s] = 1
  end
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define all(x)              (x).begin(), (x).end()
#define inf                 1e18

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	int n;
	cin >> n;
	vector <ll> v(n);
	for (auto &i : v) cin >> i;

	sort(all(v));
	if (v[0] == 0) {
		cout << 0;
		return;
	}

	ld res = 1;
	for (int i = 0; i < n; ++i) {
		if (res * v[i] > inf) {
			cout << -1;
			return;
		}
		res *= v[i];
	}
	if (res > inf) {
		cout << -1;
		return;
	}
	cout << (unsigned ll)res;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	ifstream cin("input.txt");
//	ofstream cout("output.txt");
	int q = 1; // cin >> q;
	while (q--) {
		solve();
	}
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& e : a) cin >> e;
    auto f = [&](int x) { return k <= x; };
    cout << count_if(a.begin(), a.end(), f) << endl;
    return 0;
}

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

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

   for(int i=0; i<s.size(); i++) {
      if(i % 2 == 1) {
         if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
            cout << "No" << endl;
            return 0;
         }
      }
      else if(i % 2 == 0) {
         if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
            cout << "No" << endl;
            return 0;
         }
      }
   }
   cout << "Yes" << endl;
}

Measured memory_bytes: 3580
// implement 15min
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Rect {
  int x1, y1, x2, y2;
  Rect() {;}
  Rect(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {;}
};

int n, m;
Rect rect[100];
bool visit[1010][1010];
void PrintVisit() {
  REP(y, m) {
    REP(x, m) {
      putchar(visit[y][x] ? '#' : '.');
    }
    puts("");
  }
}

int main() {
  while (scanf("%d", &n) > 0 && n) {
    {
      // read
      MEMSET(visit, false);
      map<int, int> mapto;
      REP(i, n) {
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        x1 *= 2; y1 *= 2; x2 *= 2; y2 *= 2;
        FOREQ(j, -1, 1) {
          mapto[x1 + j] = mapto[x2 + j] = -1;
          mapto[y1 + j] = mapto[y2 + j] = -1;
        }
        rect[i] = Rect(x1, y2, x2, y1);
      }
      int cnt = 2;
      FORIT(it, mapto) { it->second = cnt++; }
      m = cnt;

      // compress & make border
      REP(i, n) {
        rect[i].x1 = mapto[rect[i].x1];
        rect[i].y1 = mapto[rect[i].y1];
        rect[i].x2 = mapto[rect[i].x2];
        rect[i].y2 = mapto[rect[i].y2];
        FOREQ(x, rect[i].x1, rect[i].x2) {
          visit[rect[i].y1][x] = true;
          visit[rect[i].y2][x] = true;
        }
        FOREQ(y, rect[i].y1, rect[i].y2) {
          visit[y][rect[i].x1] = true;
          visit[y][rect[i].x2] = true;
        }
      }
      // PrintVisit();

      // calc region
      int ans = 0;
      REP(sy, m) {
        REP(sx, m) {
          if (visit[sy][sx]) { continue; }
          ans++;
          queue<pair<int, int> > que;
          que.push(make_pair(sx, sy));
          while (!que.empty()) {
            int x = que.front().first;
            int y = que.front().second;
            que.pop();
            const int dx[4] = { 1, 0, -1, 0 };
            const int dy[4] = { 0, 1, 0, -1 };
            REP(dir, 4) {
              int nx = x + dx[dir];
              int ny = y + dy[dir];
              if (nx < 0 || m < nx || ny < 0 || m < ny || visit[ny][nx]) { continue; }
              visit[ny][nx] = true;
              que.push(make_pair(nx, ny));
            }
          }
        }
      }
      printf("%d\n", ans);
    }
  }
}

Measured memory_bytes: 2244
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <math.h>
#include <complex>
using ll = long long;
using namespace std;
int const MOD = 1e9 + 7;
ll const INF = (1LL << 62) - 1;
#define rep(i, n) for (int i = 0; i < (n); i++)

using P = pair<ll, ll>;
bool operator<(const P &a, const P &b)
{
    if (a.first == b.first)
        return a.second < b.second;
    return a.first < b.first;
}

ll arr[200010];
int main(void)
{
    int N;
    cin >> N;
    map<ll, ll> mp;
    ll t = 0;
    mp[t]++;
    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
        t += arr[i];
        mp[t]++;
    }
    ll ans = 0;
    for (auto e : mp)
    {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14336
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static ArrayList<Integer>[] e = null;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		e = new ArrayList[N];
		for (int i = 0; i < N; i++) {
			e[i] = new ArrayList<>(8);
		}

		for (int i = 0; i < M; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			e[u].add(v);
			e[v].add(u);
		}
		sc.close();

		int[] chk = new int[N];
		int evenCnt = 0;
		long singleCnt = 0;
		ArrayList<Integer> a = new ArrayList<>();
		Arrays.fill(chk, -1);
		for (int i = 0; i < N; i++) {
			if (chk[i] == -1) {
				if (e[i].size() == 0) {
					chk[i] = 0;
					singleCnt++;
				} else {
					int c = count(chk, i, 0, false) ? 1 : 2;
					a.add(c);
					evenCnt += (c == 2) ? 1 : 0;
				}
			}
		}
		long cnt = 0;
		for (int x : a) {
			if (x == 2) {
				cnt += 2 * evenCnt + (a.size() - evenCnt);
			} else {
				cnt += a.size();
			}
		}
		cnt += ((long) N) * ((long) N) - (N - singleCnt) * (N - singleCnt);
		System.out.println(cnt);
	}

	public static boolean count(int[] chk, int pos, int parity, boolean odd) {
		if (chk[pos] != -1) {
			if (chk[pos] == parity) {
				return odd;
			} else {
				return true;
			}
		}
		chk[pos] = parity;
		for (int next : e[pos]) {
			odd |= count(chk, next, 1 - parity, odd);
		}
		return odd;
	}
}


Measured memory_bytes: 135204
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin

constexpr int mod = int(1e9) + 7;

int add(int a, int b) {
	return ((a + b) % mod + mod) % mod;
}

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

	int n, K;
	cin >> n >> K;
	vector<int> a(n);
	for(int &ai : a)
		cin >> ai;

	vector<vector<int>> dp(n + 1, vector<int>(K + 1)); // answer if we have childs [1, i] if they use k candies
	dp[0][0] = 1;
	for(int i = 1; i <= n; ++i) {
		int sum = 0;
		for(int k = 0; k <= K; ++k) {
			sum = add(sum, dp[i - 1][k]);
			if(k > a[i - 1])
				sum = add(sum, -dp[i - 1][k - a[i - 1] - 1]);
			dp[i][k] = sum;
		}
	}
	cout << dp[n][K] << '\n';
}



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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n + 1], b[n + 1], c[n + 1];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[n + 1][3];
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = max(a[i] + dp[i - 1][1], a[i] + dp[i - 1][2]);
        dp[i][1] = max(b[i] + dp[i - 1][0], b[i] + dp[i - 1][2]);
        dp[i][2] = max(c[i] + dp[i - 1][0], c[i] + dp[i - 1][1]);
    }
    int maxpoints = max(dp[n][0], dp[n][1]);
    maxpoints = max(maxpoints, dp[n][2]);
    cout << maxpoints << "\n";

    return 0;
}

Measured memory_bytes: 2560
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    ts=LIST()
    m=INT()
    xs=[0]*m
    for i in range(m):
        p,x=INTM()
        xs[i]=ts[p-1]-x
    tst=sum(ts)
    for i in range(m):
        #print(xs[i])
        print(tst-xs[i])
    #print(ts)
if __name__ == '__main__':
    do()

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

#define int long long

const int INF = LLONG_MAX/2;
const int MAX_K = 10000;

int N, K, D[MAX_K];
bool exists[10];
int ans;

void DFS(int dep, int n)
{
	if (dep >= 7) return;
	if (n >= N)
	{
		ans = min(ans, n);
		return;
	}
	for (int i = 0; i < 10; i++)
	{
		if (!exists[i]) continue;
		DFS(dep + 1, n*10 + i);
	}
}

signed main()
{
	ans = INF;
	fill(exists, exists + 10, true);
	cin >> N >> K;
	for (int i = 0; i < K; i++)
	{
		cin >> D[i];
		exists[D[i]] = false;
	}

	DFS(0, 0);
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    string a, b, c;
    int cnt_a = 0, cnt_b = -1, cnt_c = -1;
    char check = 'a';
    cin >> a >> b >> c;
    while (true)
    {
        if (check == 'a') {
            if (a[cnt_a] == 'a') {
                cnt_a++;
                check = 'a';
            } else if(a[cnt_a] == 'b') {
                cnt_b++;
                check = 'b';
            } else if(a[cnt_a] == 'c') {
                cnt_c++;
                check = 'c';
            }
        } else if (check == 'b') {
            if (b[cnt_b] == 'a') {
                cnt_a++;
                check = 'a';
            } else if (b[cnt_b] == 'b') {
                cnt_b++;
                check = 'b';
            } else if (b[cnt_b] == 'c') {
                cnt_c++;
                check = 'c';
            }
        } else if (check == 'c') {
            if (c[cnt_c] == 'a') {
                cnt_a++;
                check = 'a';
            } else if (c[cnt_c] == 'b') {
                cnt_b++;
                check = 'b';
            } else if (c[cnt_c] == 'c') {
                cnt_c++;
                check = 'c';
            }
        }

        if (cnt_a == a.size()) {
            cout << 'A' << endl;
            break;
        } else if (cnt_b == b.size()) {
            cout << 'B' << endl;
            break;
        } else if (cnt_c == c.size()) {
            cout << 'C' << endl;
            break;
        }
    }
    
    return 0;
}

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

int main() {
  int N,K;
  cin >> N>> K;
  vector<ll> h(N);
  for(int i = 0;i<N;i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  ll ans = 1000000000000;
  for(int i = 0;i<=N-K;i++){
      ans = min(ans,h[i+K-1]-h[i]);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)

dist = []
for i in range(n+1):
    dist.append(abs(a[i+1]-a[i]))

tot = sum(dist)
for i in range(1, n+1):
    print(tot - dist[i-1] - dist[i] + abs(a[i+1]-a[i-1]))

Measured memory_bytes: 20568
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
using namespace std;
ll mod = 1000000007;
ll INF = 1000000000000000000;
ll n, k;
ll a[101];
bool dp[100001];
bool vis[100001];

bool foo(ll sum)
{


	if (vis[sum]) return dp[sum];

	bool res = false;

	for (int i = 0; i < n; i++)
	{
		if (sum + a[i] <= k)
			res |= !foo(sum + a[i]);
	}

	vis[sum] = true;
	dp[sum] = res;
	return res;
}

void solve(int t)
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	memset(vis, false, sizeof(vis));
	if (foo(0))
	{
		cout << "First" << endl;
		return;
	}
	cout << "Second" << endl;


}

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


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

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}
}


Measured memory_bytes: 3584
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 


#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(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;
}





int main() {
    
    fastio;
    
    int n, l;
    cin >> n >> l;
    int min = abs(l);
    int ans = 1;
    fr(i, 1, n)
    {
        int x = abs(l+i-1);
        if(x < min)
        {
            min = x;
            ans = i;
        }
    }
    int sum = 0;
    fr(i, 1, n)
    {
        if(i != ans)
            sum += (l+i-1);
    }
    cout << sum;

    return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int i,j,h,w;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0) break;
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				if((i>=2&&i<=h-1)&&(j>=2&&j<=w-1)){
					putchar('.');
				}else{
					putchar('#');
				}
			}
			putchar('\n');
		}
		putchar('\n');
	}

return(0);
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int t = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        t = t ^ a[i];
    }
    for (int i = 0; i < n; i++)
    {
        int temp = t ^ a[i];
        cout << temp << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int r=n%10;
  if(r==2||r==4||r==5||r==7||r==9)
  {
    cout<<"hon";
  }
  if(r==0||r==1||r==6||r==8)
  {
    cout<<"pon";
  }
  if(r==3)
  {
    cout<<"bon";
  }
  return 0;
}

Measured memory_bytes: 3596
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

alias P = Tuple!(int, "a", int, "b");

void main()
{
    auto hwn = readln.split.to!(int[]);
    long H = hwn[0];
    long W = hwn[1];
    auto N = hwn[2];
    int[P] ps;
    foreach (_; 0..N) {
        auto ab = readln.split.to!(int[]);
        auto a = ab[0];
        auto b = ab[1];
        static foreach (ad; [-1, 0, 1])
        static foreach (bd; [-1, 0, 1]) {{
            auto h = ad+a;
            auto w = bd+b;
            if (1 < h && h < H && 1 < w && w < W) ++ps[P(h, w)];
        }}
    }
    long[10] res;
    res[0] = (H-2) * (W-2);
    foreach (_, v; ps) {
        --res[0];
        ++res[v];
    }
    static foreach (i; 0..10) writeln(res[i]);
}

Measured memory_bytes: 68584
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    while (1)
    {
        if (s.find(s[0], 1) <= s.size())
        {
            s.erase(s.begin() + s.find(s[0], 1));
            s.erase(s.begin());
        }
        else if (s.size() == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        else{
            cout << "No" <<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import numpy as np
H,W = map(int,input().split())
l = []
for i in range(H):
    tmp = input()
    if tmp.count('.') != W:
        l.append(list(tmp))
    else:
      	H-=1
l = np.array(l).T.tolist()
ans = []
for i in l:
  if i.count('.') != H:
    ans.append(i)
for i in np.array(ans).T:
  print(''.join(i))
  

Measured memory_bytes: 12508
n=int(input())
P=map(int,input().split())
p=list(P)
s=0

for i in range(0,n-2):
    if p[i]<=p[i+1]:
        if p[i+1]<p[i+2]:
            s=s+1
    
    elif p[i]>p[i+1]:
        if p[i+1]>=p[i+2]:
            s=s+1

print(s)



Measured memory_bytes: 38384