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

using namespace std;

inline void read() {}
template <class S>
inline void read(S &arg) {
  cin >> arg;
}
template <class S>
inline void readA(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    read(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void read(S &arg, T &... rest) {
  read(arg);
  read(rest...);
}

inline void write() {}
template <class S>
inline void write(S arg) {
  cout << arg;
}
template <class S>
inline void writeA(S Lptr, S Rptr) {
  if (Lptr != Rptr) {
    write(*Lptr);
    Lptr++;
  }
  while (Lptr != Rptr) {
    write(' ');
    write(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void write(S arg, T... rest) {
  write(arg);
  write(' ');
  write(rest...);
}

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 1e9 + 7;
constexpr int N = 1e6 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

ll po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

int n, m, S[2];
vector<pii> adj[N];
ll dist[2][N], w[2][N];

inline void dijk(int id) {
  int so = S[id];
  memset(dist[id], 63, sizeof(dist[id]));
  dist[id][so] = 0;
  w[id][so] = 1;
  set<pair<ll, int>> st;
  st.insert({0, so});
  while (!st.empty()) {
    int v = st.begin()->second;
    st.erase(st.begin());
    for (auto e : adj[v]) {
      ll exp = dist[id][v] + e.second;
      if (exp < dist[id][e.first]) {
        st.erase({dist[id][e.first], e.first});
        dist[id][e.first] = exp;
        w[id][e.first] = w[id][v];
        st.insert({dist[id][e.first], e.first});
      } else if (exp == dist[id][e.first])
        add(w[id][e.first], w[id][v]);
    }
  }
}

int a[N], b[N], d[N];

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

  read(n, m);
  readA(S, S + 2);
  rep(i, 0, m) {
    read(a[i], b[i], d[i]);
    adj[a[i]].pb({b[i], d[i]});
    adj[b[i]].pb({a[i], d[i]});
  }

  dijk(0);
  dijk(1);

  ll res = po(w[0][S[1]], 2);

  rep(i, 1,
      n + 1) if (dist[0][i] == dist[1][i] && dist[0][i] * 2 == dist[0][S[1]])
      add(res, -po(w[0][i] * w[1][i] % MOD, 2));
  rep(i, 0, m) {
    if (dist[0][a[i]] + d[i] == dist[0][b[i]] &&
        dist[0][b[i]] + dist[1][b[i]] == dist[0][S[1]] &&
        dist[0][b[i]] > dist[1][b[i]] && dist[1][a[i]] > dist[0][a[i]]) {
      add(res, -po(w[0][a[i]] * w[1][b[i]] % MOD, 2));
    }
    swap(a[i], b[i]);
    if (dist[0][a[i]] + d[i] == dist[0][b[i]] &&
        dist[0][b[i]] + dist[1][b[i]] == dist[0][S[1]] &&
        dist[0][b[i]] > dist[1][b[i]] && dist[1][a[i]] > dist[0][a[i]]) {
      add(res, -po(w[0][a[i]] * w[1][b[i]] % MOD, 2));
    }
  }

  write(res);

  return 0;
}


Measured memory_bytes: 67188
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;

int main(){

  int c[3][3], a[3], b[3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> c[i][j];
    }
  }

  a[0]=0;

  for(int i=0; i<3; i++){
    b[i]=c[0][i]-a[0];
  }

  for(int i=1; i<3; i++){
    a[i]=c[i][0]-b[0];
  }

  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(c[i][j]!=a[i]+b[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
	struct node*oya,*ko[2];
	char key[30];
	int val,p;
}node;

void rot(node*v,int d){
	node*nnn=v->ko[d];
	
	v->ko[d]=nnn->ko[d^1];
	if(v->ko[d])v->ko[d]->oya=v;
	
	v->oya->ko[v->oya->ko[1]==v]=nnn;
	nnn->oya=v->oya;
	
	nnn->ko[d^1]=v;
	v->oya=nnn;  
}
void ins(node*v,node*oya,int dir,node*n){
	if(!v){
		n->oya=oya;
		oya->ko[dir]=n;
	}else{
		int d=strcmp(v->key,n->key)<0;
		ins(v->ko[d],v,d,n);
		if(v->ko[d]->p > v->p)rot(v,d);
	}
}
node*find(node*v,char*s){
	if(!v)return 0;
	int flag=strcmp(v->key,s);
	if(!flag)return v;
	return find(v->ko[flag<0],s);
}
void del(node*v){
	while(v){
		if(v->ko[0]){
			if(v->ko[1])rot(v,v->ko[1]->p > v->ko[0]->p);
			else rot(v,0);
		}else{
			if(v->ko[1])rot(v,1);
			else v=v->oya->ko[v->oya->ko[1]==v]=0;
		}
	}
}

node root;
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		int t;
		char s[30];
		scanf("%d%s",&t,s);
		if(t==0){
			int x;
			scanf("%d",&x);
			node*crr=find(root.ko[0],s);
			if(crr){
				crr->val=x;
			}else{
				node*v=calloc(1,sizeof(node));
				memcpy(v->key,s,20);
				v->val=x;
				v->p=rand();
				ins(root.ko[0],&root,0,v);
			}
		}else{
			printf("%d\n",find(root.ko[0],s)->val);
		}
	}
}


Measured memory_bytes: 17484
# -*- coding: utf-8 -*-
import bisect
import sys

sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap





@mt
def slv(N, A, UV):
    A.insert(0, -1)
    g = [list() for _ in range(0, N+1)]
    for u, v in UV:
        g[u].append(v)
        g[v].append(u)

    ans = [-1] * (N+1)
    ans[1] = 1
    dp = [INF] * (N+1)
    dp[0] = A[1]

    def dfs(u, p):
        for v in g[u]:
            if v == p:
                continue

            i = bisect.bisect_left(dp, A[v])
            b = dp[i]
            dp[i] = A[v]
            ans[v] = bisect.bisect_left(dp, INF)
            dfs(v, u)
            dp[i] = b

    dfs(1, 0)

    for i in range(1, N+1):
        print(ans[i])


def main():
    N = read_int()
    A = read_int_n()
    UV = [read_int_n() for _ in range(N-1)]
    slv(N, A, UV)


if __name__ == '__main__':
    main()


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

ll N;
ll ans=0;

int main()
{
cin >> N;
 ll A[N]={};
  ll B[N]={};
  ll C[N-1]={};
  
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
 for(int i=0;i<N;i++){
    cin >> B[i];
  } 
  for(int i=0;i<N-1;i++){
    cin >> C[i];
  } 
  
  for(int k=0;k<N;k++){
    ans += B[A[k]-1];
    if(A[k-1]==A[k]-1 && k>=1) ans+=C[A[k-1]-1];
  }

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

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

int main(){
double d,t,s;
cin>>d>>t>>s;
if(d/s <=t){
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3716
#include<stdio.h>
#include<math.h>
#include<stdlib.h>


int main(){
    int a, b;
    scanf("%d %d", &a, &b);

    if( a > 0 ) 
        puts( "Positive");
    else if( a < 0 && b > 0 )
        puts( "Zero" );
    else{


        if ((b - a + 1) % 2 == 0)
            printf("Positive\n");
        else
            printf("Negative\n");
    }
    return 0;

}

	





Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int,int>> edge[100005];
int c[100005];
void dfs(int u,int fa,int k){
	c[u]=k;
	for(int i=0;i<edge[u].size();i++){
		int v=edge[u][i].first,x=edge[u][i].second;
		if(v==fa) continue;
		if(x%2==0) dfs(v,u,k);
		else dfs(v,u,k^1);
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v,w;
		cin>>u>>v>>w;
		edge[u].push_back({v,w});
		edge[v].push_back({u,w});
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++){
		cout<<c[i]<<endl;
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    string S; cin >> S;
    REP(i, S.length()) {
        if (S[i] == '?') S[i] = 'D';
    }
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 3732
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
map<int,int> M;
int n;
void init(){
  cin >> n;
  while( n -- )
    M[ getint() ] ++;
}
void solve(){
  int ans = 0;
  for( auto i : M )
    if( i.second > i.first )
      ans += i.second - i.first;
    else if( i.second < i.first )
      ans += i.second;
  printf( "%d\n" , ans );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	int ret = 700;
	if (topping.at(0) == 'o') ret += 100;
	if (topping.at(1) == 'o') ret += 100;
	if (topping.at(2) == 'o') ret += 100;

	cout << ret << endl;
}


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

int main() {
	vector<int> a(4), b(4);
	while( cin >> a[0] >> a[1] >> a[2] >> a[3] ){
		for( int i=0; i<4; ++i ) cin >> b[i];
		
		int hit = 0, blow = 0;
		for( int i=0; i<4; ++i ){
			for( int j=0; j<4; ++j ){
				if( a[i] == b[j] ){
					( i==j ? hit : blow ) += 1;	
				}
			}
		}
		cout << hit << ' ' << blow << endl;
	}
}

Measured memory_bytes: 3076
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int main() {
	ll a, b;
	cin >> a >> b;

	ll A = 0;
	ll B = 0;
	for (int i = 0; i < b;++i) {
		B += a * pow(10 , i);
	}
	for (int i = 0; i < a; ++i) {
		A += b * pow(10, i);
	}

	ll ans;
	if (a < b)ans = B;
	else if (b < a)ans = A;
	else ans = A;
	cout << ans << endl;
}

Measured memory_bytes: 2816
#include <stdio.h>
#include <math.h>
int main (void){
        long long int N,ans=0;
        scanf("%lld",&N);
for (int i = 1; i < N; i++) {
  if (((N-i)/i)<=i) {
    break;
  }
  if ((N-i)%i==0) {
    ans+=(N-i)/i;
    //printf("=%lld,%d\n",ans ,i);
  }
}
        printf("%lld\n",ans );
        return 0;

}


Measured memory_bytes: 128
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define in inline
#define reg register
#define MAX 200308
using namespace std;
namespace qwq{
	in void read(int &o) {
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9') {
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9') {
			o=(o<<3)+(o<<1)+(c^48);c=getchar();
		}
		o*=w;
	}
	void write(int x){
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
		putchar(x%10+48);
	}
	void Write(int x) {
		write(x);putchar('\n');
	}
	in int max(int x,int y){return x>y?x:y;}
	in int min(int x,int y){return x<y?x:y;}
}
using namespace qwq;
#define double long double
const double pi=acos(-1.0);
double a,b,x,h,alpha;
signed main()
{
	scanf("%Lf%Lf%Lf",&a,&b,&x);
	h=2.0*x/(a*b*1.0);
	//cout<<h<<endl;
	if(h>a)
	{
		double k=1.0*(2.0*x/(a*a*1.0))-b;
		//cout<<k<<endl;
		alpha=90.0-atan(1.0*a/(b*1.0-k*1.0))/pi*180;
		printf("%.10Lf",alpha);
	}
	else 
	{
		alpha=90.0-atan((1.0*h)/(b*1.0))/pi*180;
		printf("%.10Lf",alpha);
	}
	return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  map<ll, ll> cnt;
  rep(i, n) {
    int a; std::cin >> a;
    cnt[a]++;
  }
  ll ma1 = 0, ma2 = 0;
  for (auto &p : cnt) {
    if (p.se < 2) continue;
    if (p.fi > ma1) {
      ma2 = ma1;
      ma1 = p.fi;
      if (p.se >= 4) ma2 = p.fi;
    } else if (p.fi > ma2) {
      ma2 = p.fi;
    }
  }
  if (ma1 == 0 || ma2 == 0)
    std::cout << 0 << "\n";
  else
    std::cout << ma1 * ma2 << "\n";
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (998244353ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

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

ll rwpw(ll x, ll p){
	ll ret = 1ll;
	while(p){
		if(p%(2ll)){
			mul_mod(ret,x);
		}
		mul_mod(x,x);
		p /= (2ll);
	}
	return ret;
}

ll fc[334334], nv[334334];

ll comb(ll n, ll k){
	ll ret = 1ll;
	mul_mod(ret,fc[n]);
	mul_mod(ret,nv[k]);
	mul_mod(ret,nv[n-k]);
	return ret;
}

int main(void){
	ll n,a,b,k,i,j,tmp,ans=0ll;
	fc[0] = 1ll; nv[0] = 1ll;
	for(i=1ll; i<333333ll; ++i){
		fc[i] = i;
		mul_mod(fc[i],fc[i-1]);
		nv[i] = rwpw(i,MOD-2);
		mul_mod(nv[i],nv[i-1]);
	}
	cin >> n >> a >> b >> k;
	for(i=0ll; i<=n; ++i){
		j = k - (a*i);
		if(j<0ll || (j%b)){
			continue;
		}
		j /= b;
		if(j > n){
			continue;
		}
		tmp = 1ll;
		mul_mod(tmp,comb(n,i));
		mul_mod(tmp,comb(n,j));
		add_mod(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5504
v[50],p,n,k,X;main(s){for(;n=atoi(gets(v));printf("%d\n",s)){for(p=s=0;p<n;v[++p]=strlen(gets(v+n)));for(;n;)for(n=0,p=++s,k=261096;k/=8;n+=X)for(X=k&7;X>0;X-=v[p++]);}}

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

using namespace std;

struct Node{
    int key;
    Node *parent;
    Node *left;
    Node *right;
};

Node *nil, *root;

void find(int a){
    Node *x = root;
    bool flag = false;
    while(x != nil){
        if(x->key == a)flag = true;
        if(a < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    if(flag){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
}

void insert(int a){
    Node *x = root;
    Node *y = nil; //xの親
    Node *z = (Node*)malloc(sizeof(Node));
    z->key = a;
    z->left = nil;
    z->right = nil;

    //zの親に適切なNodeを指定する
    while(x != nil){
        y = x;
        //根の値より大きいかどうかで根の位置をずらしていく。小さければ左。
        if(z->key < x->key){
            x = x->left; 
        }else if(x->key < z->key){
            x = x->right;
        }
    }
    z->parent = y;

    if(y == nil){
        root = z;
    }else if(z->key < y->key){
        y->left = z;
    }else{
        y->right = z;
    }
}

vector<int> in;
void inorder(Node *n){
    if(n == nil)return;
    inorder(n->left);
    in.push_back(n->key);
    inorder(n->right);
}

vector<int> pre;
void preorder(Node *n){
    if(n == nil)return;
    pre.push_back(n->key);
    preorder(n->left);
    preorder(n->right);
}

void print(){
    inorder(root);
    for(int i = 0; i < in.size(); i++){
        cout << " " << in[i];
    }
    cout << endl;
    preorder(root);
    for(int i = 0; i < pre.size(); i++){
        cout << " " << pre[i];
    }
    cout << endl;
    pre.clear();
    in.clear();
}

int main(void){
    int n;
    cin >> n;
    while(n--){
        string command;
        cin >> command;
        if(command == "insert"){
            int a;
            cin >> a;
            insert(a);
        }else if(command == "find"){
            int a;
            cin >> a;
            find(a);
        }else{
            print();
        }
    }
}


Measured memory_bytes: 26256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int N = sc.nextInt();
		while (N-- > 0) {
			String input = sc.next();
			System.out.println(dfs(input));
		}
	}

	int dfs(String seg) {
		if (Character.isDigit(seg.charAt(0))) {
			return Integer.valueOf(seg) / 2 + 1;
		}
		int left = 0;
		int start = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < seg.length(); i++) {
			if (seg.charAt(i) == '[') {
				left++;
			}
			if (seg.charAt(i) == ']') {
				left--;
			}
			if (left == 0) {
				list.add(dfs(seg.substring(start + 1, i)));
				start = i + 1;
			}
		}
		int sum = 0;
		Collections.sort(list);
		for (int i = 0; i < list.size() / 2 + 1; i++) {
			sum += list.get(i);
		}
		return sum;
	}

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

Measured memory_bytes: 40820
#include <iostream>
#include <string>
using namespace std;
string s;
int a=700;

int main(){
	cin>>s;
  	for(int i=0;i<3;i++){
		if(s[i]=='o'){
			a+=100;
        }
    }
  	cout<<a<<endl;
  	return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import qualified Data.Array.IO         as IO
import qualified Data.Array.Unboxed    as A
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt

  f <- replicateM n getIntList

  p' <- IO.newArray ((1,0),(n,10)) (0::Int) :: IO (IO.IOUArray (Int, Int) Int)
  forM_ [1..n] $ \i -> do
    ps <- getIntList
    forM_ [0..10] $ \j -> IO.writeArray p' (i, j) $ ps !! j
  p <- IO.freeze p' ::  IO (A.UArray (Int, Int) Int)

  let b2a   :: Int -> [Int]
      b2a b = fmap (\i -> 1 .&. (b `shiftR` i)) [0..9]

      calc b = let a = b2a b
                   c i = sum $ zipWith (.&.) (f !! (i-1)) a
               in
                 sum $ fmap (\i -> p A.! (i, c i)) [1..n]

      solve b m | b == 0 = m
                | otherwise =
                  let m' = max m (calc b)
                  in
                    solve (b-1) m'

  print $ solve 1023 (-1000000001)

Measured memory_bytes: 1020
def calc(x,y):
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    return dp1[-1]

q = int(input())
for i in range(q):
    x = input()
    y = input()
    print(calc(x,y))


Measured memory_bytes: 5632
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;
	REP(i, S.size()) {
		S[i] = 'x';
	}
    cout << S <<  endl;
    return 0;
}


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

int main() {
   int n;
   cin >> n;
   int ans=1;
   while((ans+1)*(ans+1)<=n)
   ans++;
   cout << ans*ans << endl;
}

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

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(v,a,b) for(int v=(a); v<=(b); v++)
#define fr(v,a,b) for(int v=(a); v>=(b); v--)
#define rng(v,a,b) for(int v=(a); v<(b); v++)

using namespace std;
typedef long long ll;
template<typename T> T& chmax(T& a, T b) { a = a > b ? a : b; return a;}
template<typename T> T& chmin(T& a, T b) { a = a < b ? a : b; return a;}
//const int maxn;
int main()
{
	boost;
	int n,a,b; cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
	return 0;
}


Measured memory_bytes: 384
while 1:
    t,n = map(int,raw_input().split())
    if t == n == 0: break
    block = []
    for loop in range(n):
        x,y = map(int,raw_input().split())
        block.append((x+100,y+100))
    sx,sy = map(int,raw_input().split())
    sx += 100; sy += 100
    visited = [[False]*200 for _ in range(200)]
    visited[sy][sx] = True
    que = [[sx,sy,t]]
    ans = 1
    while que:
        x,y,tt = que.pop(0)
        if tt == 0: continue
        for dx,dy in zip([1,1,0,-1,-1,0],[0,1,1,0,-1,-1]):
            nx,ny = x+dx,y+dy
            if not visited[ny][nx] and (nx,ny) not in block:
                que.append([nx,ny,tt-1])
                visited[ny][nx] = True
                ans += 1
    print ans

Measured memory_bytes: 4768
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
vector<int> L[101010];

int uf[303030];

int root(int p)
{
	return uf[p] < 0 ? p : (uf[p] = root(uf[p]));
}
void join(int p, int q)
{
	p = root(p);
	q = root(q);
	if (p == q) return;
	uf[p] += uf[q];
	uf[q] = p;
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) {
		int k;
		scanf("%d", &k);
		for (; k--;) {
			int v;
			scanf("%d", &v);
			--v;
			L[i].push_back(v);
		}
	}
	for (int i = 0; i < N + M; ++i) uf[i] = -1;
	for (int i = 0; i < N; ++i) {
		for (int l : L[i]) {
			join(i, l + N);
		}
	}
	int rt = root(0);
	for (int i = 1; i < N; ++i) {
		if (rt != root(i)) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 8064
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main()
{
    int  x , y;
    cin >> x >> y;
    
    for (int i = 0; i < y + 2; i++) {
        cout << "#";
    }
    cout << "\n";
    for (int i = 0; i < x ; i++) {
        string z;
        cin >> z;
        cout << "#" << z << "#\n";
    }
    for (int i = 0; i < y + 2; i++) {
        cout << "#";
    }
	

    return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)

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

    int n;
    cin >> n;

    int i = 0;
    int ts, tx, ty;
    int cs, cx, cy;
    cs = 1;
    cx = 0;
    cy = 0;
    while (i < n && cin >> ts >> tx >> ty)
    {
        // printf("ts: %d, cs: %d, tx: %d, ty: %d\n", ts, cs, tx, ty);

        while (cs <= ts)
        {
            if (tx > cx)
            {
                cx += 1;
            }
            else if (tx < cx)
            {
                cx -= 1;
            }
            else if (ty > cy)
            {
                cy += 1;
            }
            else if (ty < cy)
            {
                cy -= 1;
            }
            else
            { // (cx,cy) == (tx, ty)
                cx++;
            }

            // printf("cx: %d, cy: %d\n", cx, cy);
            ++cs;
        }

        if (cx == tx && cy == ty)
        {
            ++i;
        }
        else
        {
            // printf("cx: %d, cy: %d\n", cx, cy);
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 888
n, m = map(int, input().split())
ls = []
for i in range(m):
    ls.append(list(map(int, input().split())))

ans = [-1 for i in range(n)]

for i in range(m):
    if ans[ls[i][0]-1] < 0:
        ans[ls[i][0]-1] = ls[i][1]
    elif ans[ls[i][0]-1] != ls[i][1]:
        ans = []
        break

if len(ans) == 0:
    print(-1)
elif n == 1:
    if ans[0] == -1:
        print(0)
    else:
        print(ans[0])
else:
    if ans[0] == 0:
        print(-1)
    else:
        if ans[0] == -1:
            ans[0] = 1

        for j in range(1, n):
            if ans[j] == -1:
                ans[j] = 0
        print("".join(list(map(str, ans))))


Measured memory_bytes: 3064
const f:array[1..11,1..5] of longint=((4,2,0,9,7),
                           (1,10,8,6,4),
                           (9,7,5,3,1),
                           (6,4,2,0,9),
                           (3,1,10,8,6),
                           (0,9,7,5,3),
                           (8,6,4,2,0),
                           (5,3,1,10,8),
                           (2,0,9,7,5),
                           (10,8,6,4,2),
                           (7,5,3,1,10));
var n,k,ans,p,i,j:longint;
begin
        readln(n,k);
        n:=n-2;
        p:=n mod 11;
        n:=n div 11;
        ans:=n*5;
        if n<=2 then
                for i:=1 to p do
                        for j:=1 to 5 do
                                if f[i,j]=k then inc(ans) else begin end
        else
        for i:=1 to p do
                for j:=1 to 5 do
                        if f[i,j]=k then inc(ans);
        writeln(ans);
end.

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

using int64 = long long;

int64 gcd(int64 a, int64 b) {
  int64 c = a % b;
  while (int64 c = a % b) {
    a = b;
    b = c;
  }
  return b;
}

const char* solve(int64 n, int64 k, const vector<int64>& as) {
  int64 max = *max_element(as.begin(), as.end());
  int64 g = as[0];
  for (int64 i = 1; i < n; ++i)
    g = gcd(as[i], g);
  if (k % g)
    return "IMPOSSIBLE";
  if (k > max)
    return "IMPOSSIBLE";
  return "POSSIBLE";
}

int main() {
  int64 n, k;
  cin >> n >> k;
  vector<int64> as(n);
  for (int64 i = 0; i < n; ++i)
    cin >> as[i];
  cout << solve(n, k, as) << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,p;
    scanf("%lld%lld",&n,&p);
    ll ans = 1ll;
    if(n==1){
        printf("%lld\n",p);
        return 0;
    }
    for(ll i=2ll; i*i<=p; i++){
        int tmp=0;
        while(p%i==0ll){
            tmp++;
            p/=i;
        }
        tmp/=n;
        while(tmp--)ans*=i;
    }
    printf("%lld\n",ans);
}


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

int main(){
  string s;cin>>s;
  int n=s.size();
  if(s[n-1]=='s')cout<<s<<"es"<<endl;
  else cout<<s<<"s"<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define INF 2e8
#define all(a) a.begin(), a.end()
#define maxel max_element
#define minel min_element
#define Bit(i) pow(2, i)

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a ? b - a : a + b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N = 1e5 + 10;  
ll Lft[3*N], Rit[3*N];
int num[3*N];
int main()  
{  
  // freopen("in.txt", "r", stdin);
    int n;
    while (~scanf("%d", &n))
    {
        for (int i = 1; i <= 3*n; i++)
            scanf("%d", num + i);
        priority_queue<int, vector<int>, greater<int> >qmin; 
        priority_queue<int> qmax;
        ll sum = 0;
        // qmin.push(num[0]);
 
        for (int i = 1; i <= n; i++)
        {
            sum += num[i];
            qmin.push(num[i]);
        }
        int m = n<<1;
        Lft[n] = sum;
        for (int i = n + 1; i <= m; i++)
        {
            if (qmin.top() < num[i])
            {
                sum += num[i];
                sum -= qmin.top();
                qmin.pop();
                qmin.push(num[i]);
            }
             
            Lft[i] = sum;
        }
 
        sum = 0;
        for (int i = 3*n; i >= m + 1; i--)
        {
            sum += num[i];
            qmax.push(num[i]);
        }
        Rit[m+1] = sum;
        for (int i = m; i >= n + 1; i--)
        {
            if (num[i] < qmax.top())
            {
                sum += num[i];
                sum -= qmax.top();
                qmax.pop();
                qmax.push(num[i]);
            }
            Rit[i] = sum;
        }
        ll ans = Lft[n] - Rit[n + 1];
        for (int i = n; i <= m; i++)
        {
            ans = max(Lft[i] - Rit[i+1], ans);
        }
        cout<<ans<<endl;
    }
 
   return 0;  
}  

Measured memory_bytes: 5240
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//ワーシャルフロイト法のテンプレ.graphに最短経路が格納される.
//負の重みがある場合inf + const = inf に気を付けること.
//graphは隣接行列.
void WF(vector<vector<int>> &graph){
	int n = graph.size();
	for (int k = 0; k < n; k++){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
			}
		}
	}
}

//素因数分解をする関数.
map<long long int, int> prime_factorization(long long int a)
{
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

int main()
{
	string s;
	cin >> s;
	int a_ = -1, z_;
	rep(i, s.size())
	{
		if(s[i] =='A' && a_ == -1)
			a_ = i;
		if (s[i] == 'Z')
			z_ = i;
	}
	cout << z_ - a_ + 1 << endl;

	return 0;
	
}

Measured memory_bytes: 3708
import java.util.*;
public class Main{
   public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        
        int temp1 = A+B+C;
        int max = Math.max(A, Math.max(B,C));
        
        if ((temp1 % 2 == 0 && max % 2 == 0) || (temp1 % 2 != 0 && max % 2 != 0) ) {
            System.out.println((3 * max - temp1) / 2);
        } else  {
            int temp2 = (3 * (max+1) - temp1)/2;
            System.out.println(temp2);
        }
        
        
    }

}


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

void solve()
{
    int n,m,k,i,j,count=0,sum=0,maxi=0,mini=1e18,flag=0;
    
    
    int x,y;
    cin>>x>>y;
    
    for(i=0;i<=x;i++)
    {
        int a=i;
        int b=x-i;
        
        if(a*2+b*4==y)
        {
            cout<<"Yes";
            return;
        }
    }
    cout<<"No";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rg register
typedef long long LL;
const int maxn = 1000010;
const int inf = 1 << 30;

inline LL read() {
	register char ch;
	while(!isdigit(ch = getchar()));
	register LL x = ch ^ '0';
	while(isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ '0');
	return x;
}

LL n;
LL ans1 = 0, ans2 = 0;
LL a[maxn], b[maxn], c[maxn << 1], pre[maxn];

int main() {
	n = read();
	ans1 = 0, ans2 = 0;
	for(rg int i = 1; i <= n; ++i) a[i] = read(), b[i] = read();
	for(rg int i = 1; i <= n; ++i) ans1 += a[i], ans2 += b[i];
	ans1 = std::min(ans1, ans2);
	for(rg int i = 1; i <= n; ++i) c[i * 2] = a[i], c[i * 2 - 1] = b[i];
	std::sort(c + 1, c + 2 * n + 1);
	for(rg int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + c[i];
	for(rg int i = 1; i <= n; ++i) {
		ans2 = 0;
		int now = n;
		if(a[i] >= c[now]) ans2 += a[i], now--;
		if(b[i] >= c[now]) ans2 += b[i], now--;
		ans1 = std::min(ans1, ans2 + pre[now]);
	}
	printf("%lld\n", ans1);
	return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  cin >> b;
  vector<int> a(n);
  a[n - 1] = b[n - 2];
  rep3(i, 1, n - 1) a[i] = min(b[i], b[i - 1]);
  a[0] = b[0];
  cout << accumulate(all(a), 0) << endl;
}


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

int main()
{

    long long n,m,i,j,k,a,b,c,sz,az,st,x,y,z;
    vector<long long>v,ans;

    vector<long long>::iterator it;

    string str;

    scanf("%lld %lld",&n,&m);

    cin>>str;

    for(i=0;i<n+1;i++)
    {
        if(str[i]=='0')
        {
            v.push_back(i);
        }
    }

    st=n;

    while(1)
    {

        y=max(0LL,st-m);

        it=lower_bound(v.begin(),v.end(),y); x=it-v.begin(); z=v[x];

        if(z==st)break;
        else
        {
            ans.push_back(st-z); st=z;   if(st==0)break;

        }


    }

    if(st!=0)printf("-1\n");
    else
    {
        sz=ans.size();

        for(i=sz-1;i>=0;i--)
        {
            printf("%d ",ans[i]);
        }

    }



    return 0;
}


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

using namespace std ;
#define   ll long long
#define   null NULL
#define   double dll
#define   endl "\n"
#define   mp make_pair
#define   pb push_back
#define   ff first
#define   ss second

ll mod = (ll)(1e9 + 7);
ll inf = (ll)(1e17 + 17);

int main () {
	int a[5] ,k = 0;
	for (int i = 0;i<5;i++){
		cin >> a[i] ;
		if (a[i] == 0){
			k = i+1 ;
		}
	}
	cout << k ;
	return 0 ;
}

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

int main() {
int N=0;
  cin >> N;
	vector<int> vec(N);
			for (int i = 0; i < N-1; i++) {
  				cin >> vec.at(i);
         	}
	vector<int> count(N);
  		for (int i=0;i<N-1;i++){
          int j = vec.at(i)-1;
          count.at(j)++;
        }
  		for (int i =0;i<N;i++){
        	cout << count.at(i) << endl;
        }
}

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

int map[9][9] , f[9][9] = {} ;

int main(){
	
	int n ;
	cin >> n ;
	for( int m=1 ; m<=n ; m++ ){
		
		for( int i=0 ; i<9 ; i++ ){
			for( int j=0 ; j<9 ; j++ ){
				cin >> map[i][j] ;
			}
		}
		
		for( int i=0 ; i<9 ; i++ ){
			for( int j=0 ; j<9 ; j++ ){
				for( int k=0 ; k<9 ; k++ ){
					if( j!=k ){
						if( map[i][j] == map[i][k] ) f[i][j] = m ;
						if( map[j][i] == map[k][i] ) f[j][i] = m ;
					}
					if( i != i/3*3+k/3 && j != j/3*3+k%3 ){
						if( map[i][j] == map[i/3*3+k/3][j/3*3+k%3] ){
							f[i][j] = m ;
						}
					}
				}
			}
		}
		
		for( int i=0 ; i<9 ; i++ ){
			for( int j=0 ; j<9 ; j++ ){
				if( f[i][j] == m ) cout << '*' ;
				else  cout << ' ' ;
				
				cout << map[i][j] ;
			}
			cout << endl ;
		}
		if( m!=n )cout << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	rep(snip_i, n) cin >> d.at(snip_i);
	sort(d.begin(), d.end());
	if(n % 2 == 1){
		cout << 0 << endl;
	}else{
		cout << d.at(n/2) - d.at(n/2-1) << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n) upper_bound(v.begin(),v.end(),n)-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a);
		}
		b>>=1;
		a=(a*a);
	}
	return ans;
}//prefixsums
void frooty()
{
	l le,ri,d;
	cin>>le>>ri>>d;
	l ans=0;
	for(l i=le;i<=ri;i++)
	{
		if(i%d==0)
			ans++;
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
	//cin>>q;
	while(q--)
	{
		frooty();
	}
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {

	int k, n,y;
	cin >> k >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		cin >> y;
		a.push_back(y);
	}
	sort(a.begin(), a.end());
	int x = 0;
	x = (k - a[n - 1]) + a[0];
	for (int i = 0; i < n; i++) {
		if ((a[i + 1] - a[i]) > x)x = (a[i + 1] - a[i]);
	}
	cout << k - x << endl;

	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    double r;
    std::cin >> r;

    std::cout << std::fixed << std::setprecision(5) << M_PI * r * r << " " << 2 * M_PI * r << std::endl;
    return 0;
}


Measured memory_bytes: 3276
def main():
    N = input()
    if N[-1] == "2" or N[-1] == "4" or N[-1] == "5" or N[-1] == "7" or N[-1] == "9":
        print("hon")
    elif N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
        print("pon")
    elif N[-1] == "3":
        print("bon")
if __name__ == "__main__":
    main()

Measured memory_bytes: 9064
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M, Q = mi()
abcd = li2(Q)

'''
a = '0' * N
m = str(M-1)
l = [a]

while True:
    i = N-1
    while i >= 0 and a[i] == m:
        i -= 1
    if i == -1:
        break
    a = list(a)
    num = str(int(a[i]) + 1)
    a[i] = num
    if i != N-1:
        for j in range(i+1, N):
            a[j] = num
    tmp = ''.join(a)
    l.append(tmp)
'''

def dfs(num, length):
    if length == N:
        l.append(num)
        return
    last = int(num[-1])
    for i in range(last, M):
        dfs(num + str(i), length+1)

l = []
dfs('0', 1)

ans = 0
for num in l:
    cnt = 0
    num = list(map(int, list(num)))
    for i in range(Q):
        if num[abcd[i][1]-1] - num[abcd[i][0]-1] == abcd[i][2]:
            cnt += abcd[i][3]
    ans = max(ans, cnt)

print(ans)

Measured memory_bytes: 12504