akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vi to[MX];
vi ans;
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n=in(), q=in();
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23424
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[200005] = {};
ll B[100005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl[2][100005];
vector <long long>vll[100005];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


/*
struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};



string ss, sss;


int main() {


	cin >> N >> a >> b;

	c = a * (N - 1) + b;
	d = a + b * (N - 1);
	e = d - c + 1;

	if (a > b) {
		e = 0;
	}

	if (a != b && N == 1) {
		e = 0;
	}

	cout << e << endl;
	return 0;

}


Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
const int maxn=1e5+7;

int a[maxn];

int main()
{
//    freopen("input.txt","r",stdin);
    
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=0;i<n;i++) a[i]=k-q;
    for(int i=0;i<q;i++)
    {
    	int x;
    	cin>>x;
    	a[x-1]++;
	}
	for(int i=0;i<n;i++) 
	{
		if(a[i]>0) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
    
    return 0;
}
//想着稍微改一改思路来做这道题也不错 
//考虑一下我为什么会把G题的思路想起来 














Measured memory_bytes: 1024
def com(_x):
    _flg = 1
    mx  = int(_x**0.5)
    for i in range(2, mx+1):
        if _x % i == 0:
            _flg = 0
            break
    return _flg


def main():
    x = int(input())
    flg = 0
    while flg == 0:
        #print("a")
        flg = com(x)
        if flg == 0:
            x+=1
    print(x)



if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    ll N, K; cin >> N >> K;
    vector<ll> x(N);
    rep(i, N) cin >> x[i];

    deque<ll> deqpz, deqm;

    rep(i, N) {
        if (x[i] >= 0) deqpz.push_back(x[i]);
        else deqm.push_back(x[i]);
    }

    reverse(all(deqm));

    deque<ll> dist;

    if (deqpz.size() == 0) {
        cout << abs(deqm[K - 1]) << endl;
    }
    else if (deqm.size() == 0) {
        cout << deqpz[K - 1] << endl;
    }
    else {
        rep(i, K - 1) {
            if (i < deqm.size() && K - i - 2 < deqpz.size()) {
                dist.push_back(abs(deqm[i]) + deqpz[K - i - 2] - deqm[i]);
            }
            if (i < deqpz.size() && K - i - 2 < deqm.size()) {
                dist.push_back(deqpz[i] + deqpz[i] - deqm[K - i - 2]);
            }
        }

        sort(all(dist));
        cout << dist[0] << endl;
    }

}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	inc1(i, 5) {
		IN(int, n);
		if(n == 0) { OUT(i); }
	}
}


Measured memory_bytes: 3592
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

l=[[0 for i in range(W)] for j in range(H)]
count=0

for index,i in enumerate(a):
    for j in range(i):
        aa=count//W
        bb=count%W
        if aa%2==0:
            l[aa][bb]=index+1
        else:
            l[aa][W-bb-1]=index+1
        count+=1
        
for i in l:
    print(" ".join(map(str,i)))
    

Measured memory_bytes: 41456
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (ll)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll n,k,r,S,p,ans;
string s; 
map<char,int> score;
map<char,int> id;
int help(vector<int>& slices) {
	 int ans=0;
	 int preWin=0;
	 rep(i,0,sz(slices)){
	 	if(!preWin){
	 		preWin = 1;
	 		ans+=score[s[slices[i]]];
		 }else{
		 	if(s[slices[i]]!=s[slices[i-1]]){
		 		ans+=score[s[slices[i]]];
			 }else{
			 	preWin = 0;
			 }
		 }
	 }
	 return ans;
} 
void solve(){
	cin>>n>>k>>r>>S>>p>>s;
	score['r'] = p;
	score['s'] = r;
	score['p'] = S;
	id['r'] = 0;
	id['s'] = 1;
	id['p'] = 2;
	rep(i,0,k){
		int j = i;
		VI slices;
		while(j<n){
			slices.pb(j);
			j+=k;
		}
		ans+=help(slices);
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 1020
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
//#define ll long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int 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 mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};
#define double long double
int fun(int a, int b, int c) 
{
    //db3(a, b, c);
    int d = b*b - 4*a*c; 
    double sqrt_val = sqrt(abs(d));
    int ans;
    //deb(d);
    if (d > 0) 
    { 
        ans = (double)(-b + sqrt_val) / (2 * a);
        
    } 
    else if (d == 0) 
    { 
        ans = -(double)b / (2 * a);
    }
    //deb(ans);
    return ans;
} 
  
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    for (int i = 2; i <= sqrt(n);i++){
        if(n%i==0){
            int c = 0;
            while(n%i==0){
                c++;
                n /= i;
            }
            v.pb({i, c});
        }
    }
    if(n>1){
        v.pb({n, 1});
    }
    int ans = 0;
    for(auto it:v){
        ans += fun(1, 1, -2 * it.se);
    }
    cout << ans;

}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,N,C,a,b,cnt=0,ans=0;
  cin>>N>>C;
  pvec v;
  vector<tdata> q(N);
  rep(i,N){
    cin>>a>>b>>q[i].first;
    q[i].second=datas(a,b);
  }
  vsort(q);
  rep(i,N){
    a=q[i].second.first;
    b=q[i].second.second;
    if(i&&q[i].first==q[i-1].first&&a==v[cnt-1].first){
      v[cnt-1].first=b;
    }else{
      v.push_back(datas(a-1,1));
      v.push_back(datas(b,0));
      cnt+=2;
    }
  }
  vsort(v);
  N=cnt;cnt=0;
  rep(i,N){
    if(!v[i].second){
      cnt--;
    }else{
      cnt++;
      ans=max(ans,cnt);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8688
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cmath>
#include<stack>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 200500
#define inf (int)1e9
#define ll long long
#define mm 1000000007
#define eps 1e-9
#define low(x) x&(-x)
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int a[maxn],pos[maxn],ans[maxn],t[2][maxn*4];
int n;
struct data{int x,y,l,r,op;
bool friend operator <(data p,data q){
	return a[p.x]>a[q.x];
}};
void build(int i,int l,int r,int op){
	if (l==r) {
		if ((l%2)!=op) t[op][i]=inf;
		else t[op][i]=a[l];
		return;
	}
	int mid=(l+r)/2;
	build(i*2,l,mid,op); build(i*2+1,mid+1,r,op);	
	t[op][i]=min(t[op][i*2],t[op][i*2+1]);
}
int ask(int i,int l,int r,int tl,int tr,int op){
	if (tl<=l&&r<=tr) {
		return t[op][i]; 
	}
	int mid=(l+r)/2,ans=inf;
	if (tl<=mid) ans=min(ans,ask(i*2,l,mid,tl,tr,op));
	if (tr>mid) ans=min(ans,ask(i*2+1,mid+1,r,tl,tr,op));
	return ans;
}
priority_queue<data> q;
void add(int l,int r,int op){
	if (l>r) return; 
	int x=pos[ask(1,1,n,l,r,1^op)];
	int y=pos[ask(1,1,n,x+1,r,op)];
	q.push((data){x,y,l,r,op});
}
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	n=read();
	rep(i,1,n) a[i]=read(),pos[a[i]]=i;
	build(1,1,n,0);
	build(1,1,n,1);
	int x=pos[ask(1,1,n,1,n,1)];
	int y=pos[ask(1,1,n,x+1,n,0)];
	q.push((data){x,y,1,n,0});
	int cnt=0;
	while (!q.empty()){
		data u=q.top(); q.pop();
		ans[++cnt]=a[u.x],ans[++cnt]=a[u.y];
		int x=u.x,y=u.y,l=u.l,r=u.r,op=u.op;
		add(l,x-1,op);
		add(x+1,y-1,op^1);
		add(y+1,r,op);
	}
	rep(i,1,n) printf("%d ",ans[i]);
	return 0;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template
int mx,mn,n;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    mx = INT_MIN;
    mn = INT_MAX;

    cin>>n;
    for(int i=1;i<=n;i++){
        int temp;cin>>temp;
        mx = max(mx,temp);
        mn = min(mn,temp);
    }
    cout<<mx-mn<<newl;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(0, n-1):
    if A[i] + A[i+1] > x:
        diff = A[i] + A[i+1] - x
        ans += diff
        A[i+1] = max(0, A[i+1]-diff)

print(ans)


Measured memory_bytes: 19908
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
long mod=1e9+7;
int N,M,S,T;
vector<pair<int,int> >G[1<<17];
long a[1<<17],b[1<<17],c[1<<17],d[1<<17];
void calc(int S,long*d,long*w)
{
	for(int i=0;i++<N;)d[i]=-1e18;
	priority_queue<pair<long,int> >P;
	w[S]=1;
	P.emplace(d[S]=0,S);
	while(!P.empty())
	{
		long c=P.top().first;
		int u=P.top().second;
		P.pop();
		if(d[u]>c)continue;
		for(pair<int,int>p:G[u])
		{
			int v=p.first;
			long nxt=c-p.second;
			if(d[v]<nxt)
			{
				w[v]=w[u];
				P.emplace(d[v]=nxt,v);
			}
			else if(d[v]==nxt)(w[v]+=w[u])%=mod;
		}
	}
}
main()
{
	cin>>N>>M>>S>>T;
	for(int i=0;i<M;i++)
	{
		int u,v,d;cin>>u>>v>>d;
		G[u].push_back(make_pair(v,d));
		G[v].push_back(make_pair(u,d));
	}
	calc(S,a,b);
	calc(T,c,d);
	long ans=b[T]*b[T];
	for(int i=0;i++<N;)
	{
		if(2*a[i]==a[T])ans-=b[i]*b[i]%mod*d[i]%mod*d[i]%mod;
		for(pair<int,int>p:G[i])
		{
			int v=p.first;
			if(2*a[i]>a[T]&&2*a[v]<a[T]&&a[i]+c[v]-p.second==a[T])
				ans-=b[i]*b[i]%mod*d[v]%mod*d[v]%mod;
		}
	}
	cout<<(ans+mod)%mod<<endl;
}


Measured memory_bytes: 16340
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;

const int N = 1e5+5;
int A[N];
int k;
vector<int> v;
vector<string> ans;

bool compare(string a,string b){
    int ans1=0;
    for(int i=0;i<a.length();i++)
        ans1 = ans1*10 + (a[i]-'0'); 
    int ans2=0;
    for(int i=0;i<b.length();i++)
        ans2 = ans2*10 + (b[i]-'0');
    return ans1<ans2;
}

void solve(int index,int first,int digit,string s)
{

    if(index==digit){ 
        ans.pb(s);
        //cout<<digit<<endl;
        return;
    }
   // if(ans.size()>k) return; 
   // string s="";
    for(int i=0;i<=9;i++){
        if(index==0 && i==0) continue; 
        if(index==0){
            string s1 = s;
            s+=(i+'0');
            //ans.pb(s);
            solve(index+1, i,digit,s);
            s=s1;

        }
        else{
            if(abs(first-i)<=1){
                string s1 = s;
                s+= (i+'0');
                //ans.pb(s);
                solve(index+1,i,digit,s);
                s=s1;

            }
        }
    }
}
int32_t main()
{
   
   
    crap;
    /*for(int i=1;i<=12;i++) A[i]=i;

    int j = 13;
    for(int i=10;i<N;i++){
        A[j] = A[i]+A[i+1];
        j++;
        if(j==1e5+1) break;
    }*/


int digit;
    cin>>k;
    for(digit=1;digit<=10;digit++){
        solve(0,0,digit,"");
        sort(ans.begin(),ans.end());
        if(ans.size()>k) break;
    }
    sort(ans.begin(),ans.end(),compare);
    cout<<ans[k-1]<<endl;
   //  for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
    //cout<<A[k]<<endl;
   // for(int i=1;i<=9;i++){

        
    //}
    

}

Measured memory_bytes: 13936
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <tuple>
#include <cmath>
#include <cassert>
#include <string>

using namespace std;

typedef long long ll;

int N;
int x[100010];
int L, Q;
int a[100010];
int b[100010];

int memo[100010][18];

void init() {
  int l = 0;
  int r = 1;
  while (r < N) {
    if (x[r] - x[l] > L) {
      r--;
      memo[l][0] = r;
      //cerr << "memo[" << l << "][0] = " << memo[l][0] << endl;
      l++;
    } else {
      r++;
    }
  }
  while (l < N) {
    memo[l][0] = N-1;
    //cerr << "memo[" << l << "][0] = " << memo[l][0] << endl;
    l++;
  }
}

int g(int a, int r) {
  // cerr << "g(" << a << ", " << r << ") is called." << endl;
  if (memo[a][r] != -1) return memo[a][r];
  int ans = 0;
  if (a == N-1) {
    ans = N-1;
  } else if (r == 0) {
    int now = a;
    // cerr << "now = " << a << endl;
    // cerr << "x[" << a << "] = " << x[a] << endl;
    // cerr << "x[" << now+1 << "] = " << x[now+1] << endl;
    // cerr << "N = " << N << endl;
    // cerr << "L = " << L << endl;
    while (now+1 < N && x[now+1] - x[a] <= L) {
      // // cerr << "hello" << endl;
      now++;
    }
    ans = now;
  } else {
    ans = g(g(a, r-1), r-1);
  }
  // cerr << "memo[" << a << "][" << r << "] = " << ans << endl;
  return memo[a][r] = ans;
}

int minimum(int a, int b) {
  if (b <= a) return 0;
  int x = 1;
  while (g(a, x) < b) {
    x++;
  }
  x -= 1;
  return (1 << x) + minimum(g(a, x), b);
}

int main() {
  cin >> N;
  for (auto i = 0; i < N; i++) {
    cin >> x[i];
  }
  cin >> L >> Q;
  for (auto i = 0; i < Q; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    if (a[i] > b[i]) swap(a[i], b[i]);
  }
  // assert(N <= 1000 && Q <= 1000);
  fill(&memo[0][0], &memo[0][0]+100010*18, -1);
  init();
  for (auto i = 0; i < Q; i++) {
    cout << minimum(a[i], b[i]) << endl;
  }
}


Measured memory_bytes: 9088
#include <stdio.h>

int main()
{
    int k, a, b;
    scanf("%d",&k);
    scanf("%d%d", &a, &b);
    for (int i=a; i<=b; i++){
        if(i % k== 0){
            printf("OK\n");
            return 0;
        } else {
            continue;
        }
    }
    printf("NG\n");
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

ll BASE_NUM = 1000000007;
int main()
{
  // 整数の入力
  string S;
  cin >> S;
  vector<vector<ll>> DP(2,vector<ll>(2019,0));
  ll total = 0;
  for(int i = 0 ;i < S.size();i++){
    ll a = S[i] - '0';
    DP[(i+1)% 2] = vector<ll>(2019,0);
    for(int j = 0;j < 2019;j++){
      DP[(i+1) % 2][(j * 10 + a) % 2019] += DP[i % 2][j];
    }
    DP[(i+1) % 2][a] += 1;
    // cout << DP[(i+1) % 2][0] << endl;
    total += DP[(i+1) % 2][0];
  }
  // cout << endl;
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;
const LL INF = 1e18;

LL a[300][300];

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

    int n;
    cin >> n;
    rep(i, n) rep(j, n) {
        cin >> a[i][j];
    }

    //! check if a is optimised or not
    rep(k, n) rep(i, n) rep(j, n)
        if (a[i][k] + a[k][j] < a[i][j]) {
            //! a can be improved => a is not optimised
            cout << -1 << endl;
            return 0;
        }

    //! revert
    bool done = false;
    while (!done) {
        done = true;
        rep(k, n) rep(i, n) rep(j, n)
            if (i != k && k != j && i != j && a[i][k] + a[k][j] == a[i][j] && 0 < a[i][j]) {
                a[i][j] = INF;
                done = false;
            }
    }

    LL ans = 0;
    rep(i, n) rep(j, n) {
        if (i < j && a[i][j] != INF) {
            ans += a[i][j];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4304
import java.util.Scanner;

public class Main {
	static int time = 0;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		Tree a = new Tree(n);

		for (int y = 0; y < n; y++)
			for (int x = 0; x < n; x++)
				a.setLeng(x, y, scan.nextInt());

		System.out.println(a.MinTree());

		scan.close();
		System.exit(0);
	}
}

class Tree {
	int[][] leng;
	int[] reach;

	public Tree(int n) {
		leng = new int[n][n];
		reach = new int[n];
		for (int i = 0; i < n; i++)
			reach[i] = -1;
	}

	public int MinTree() {
		int min = Integer.MAX_VALUE;
		int xx = 0, yy = 0;
		for (int x = 0; x < leng.length; x++)
			for (int y = x + 1; y < leng[x].length; y++)
				if (leng[x][y] !=-1 && leng[x][y] < min) {
					xx = x;
					yy = y;
					min = leng[x][y];
				}
		reach[xx] = 0;
		reach[yy] = min;
		for (int i = 2; i < reach.length; i++)
			nextMin();

		int total = 0;
		for (int i = 0; i < reach.length; i++)
			total += reach[i];
		return total;
	}

	private void nextMin() {
		int min = Integer.MAX_VALUE;
		int xx = 0, yy = 0;
		for (int x = 0; x < leng.length; x++) {
			if (reach[x] == -1)
				continue;
			for (int y = 0; y < leng[x].length; y++) {
				if (reach[y] != -1||leng[x][y]==-1)
					continue;
				if (leng[x][y] < min) {
					xx = x;
					yy = y;
					min = leng[x][y];
				}
			}
		}
		reach[yy] = min;
	}

	public void setLeng(int x, int y, int length) {
		leng[x][y] = length;
	}

}



Measured memory_bytes: 40444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    ll l;cin >>l;
    ll t=1,cnt=0;while(t*2<=l){
        t*=2;cnt++;
    }
    ll n=cnt+1;
    vector<vector<ll>> edge(0,vl(3));
    rep(i,n-1)edge.pb({i+1,i+2,(ll)pow(2,i)});
    rep(i,n-1)edge.pb({i+1,i+2,0LL});
    l-=t;
    while(l){
        ll z=1;cnt=0;
        while(z*2<=l){
            z*=2;cnt++;
        }
        edge.pb({cnt+1,n,t});
        t+=z;
        l-=z;
    }
    cout << n <<" " << edge.size() <<endl;
    for(auto p:edge){
        rep(i,3)cout << p[i] <<" ";
        cout << endl;
    }
}

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

int main(){
 int a,b;
  cin>>a>>b;
  if(a<=2*b){
    cout<<0<<endl;
    return 0;
  }
  cout<<a-2*b<<endl;
}

Measured memory_bytes: 256
n,q = gets.chomp.split.map(&:to_i)
que = []
time = 0
n.times do
  k,v = gets.chomp.split
  que.push([k, v.to_i])
end

until que == []
  if que[0][1] > q
    time += q
    que[0][1] -= q
    que.rotate!
  else
    time += que[0][1]
    puts "#{que.shift[0]} #{time}"
  end
end

Measured memory_bytes: 19176
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

int main() {
    string S, T;
    cin >> S >> T;
    if (S.length() + 1 == T.length()) {
        rep(i, S.length()) {
            if (S[i] != T[i]) break;
            if (i == S.length() - 1) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int k;
	vector<int>vec(5);
	vecin(vec);
	cin >> k;
	sort(all(vec));
	if (max(vec[0] - vec[4], vec[4] - vec[0]) > k) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
}





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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if ((v - w) * t >= abs(a - b)) cout << "YES" << '\n';
    else cout << "NO" << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    int sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    int dx = tx - sx, dy = ty - sy;
    rep(i,dx) cout<<'R';
    rep(i,dy) cout<<'U';
    rep(i,dx) cout<<'L';
    rep(i,dy + 1) cout<<'D';
    rep(i,dx + 1) cout<<'R';
    rep(i, dy + 1) cout<<'U';
    cout<<"LU";
    rep(i, dx + 1) cout<<'L';
    rep(i, dy + 1) cout<<'D';
    cout<<'R'<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 
double eps = 1e-5;

double get(double a, double b) {
  if (a + b < eps) return 0;
  return (a * a + b * b) / (2.0 * (a + b));
}
signed main() {
  int n; cin >> n;
  vector<double> h(n); REP (i, n) cin >> h[i];
  const int K = 301;
  vector<vector<double>> dp(n + 1, vector<double>(K, 1e18));
  dp[0][1] = 0;
  REP (i, n) {
    REPI (k1, 1, K) {
      REPI (k2, 1, K) {
        double ad = dp[i][k1];
        if ((k1 < h[i] && k2 < h[i]) || (k1 > h[i] && k2 > h[i])) {
          ad += (abs(h[i] - (double)k1) + abs(h[i] - (double)k2)) / 2.0;
        } else {
          ad += get(abs(h[i] - (double)k1), abs(h[i] - (double)k2));
        }
        chmin(dp[i + 1][k2], ad);
      }
    }
  }
  double ans = 1e18;
  REPI (k, 1, K) {
    chmin(ans, dp[n][k]);
  }
  cout << setprecision(10) << ans << endl;
}



Measured memory_bytes: 3412
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = min(A); b=min(B)
mans = a+b
for _ in range(m):
  x,y,c = map(int,input().split())
  x-=1;y-=1
  tmp = A[x] + B[y] - c
  mans = min(mans,tmp)
print(mans)

Measured memory_bytes: 71924
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


bool walk(const string& S, int pos_init, int pos_end)
{
    int delta = 2;
    for(int i = pos_init; i <= pos_end; i+=delta) {
        if(pos_end <= i) {
            // pass
            return true;
        }
        if(S[i-1] == '.') {
            delta = 2;
        } else {// S[i] == '#'
            if(delta == 1) {
                return false;
            } else { // delta == 2
                delta = 1;
                i -= 2;// 二つ戻る
            }
        }
    }
    return true;
}

int main(int argc, const char * argv[]) {
    int N = 0; // num of total cell
    int A = 0; // Sunuke-kun init pos
    int B = 0; // Funuke-kun init pos
    int C = 0; // Sunuke-kun's final pos
    int D = 0; // Funuke-kun's final pos
    cin >> N >> A >> B >> C >> D;

    string S;
    cin >> S;

    bool need_pass = false; // whether if Sunuke-kun need to pass Funuke-kun
    bool gap_found = false; // (3連続の'.') があるか
    if(D < C) { // sunuke kun needs to pass funuke kun
        need_pass = true;
        // B-1 ~ D+1 の間に gap があるか
        for(int i = B; i <= D; i++) {
            if(S[i-2] ==  '.' && S[i-1] == '.' && S[i] == '.') {
                gap_found = true;
            }
        }
    }

    if(need_pass && !gap_found) {
        cout << "No" << endl;
        return 0;
    }

    // ふぬけくんから
    if(!walk(S, B, D)) {
        cout << "No" << endl;
        return 0;
    }

    // すぬけくん
    if(!walk(S, A, C)) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>

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

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

long long dp[100100][3];
long long a[100100][3];

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

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            std::cin >> a[i][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for(int i = 0; i < 3; i++){
        chmax(res, dp[n][i]);
    }
    std::cout << res << std::endl;
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

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

	cout<<6-a-b<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long  int
#define N 10000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;


ll h,n;
ll a[1001],b[1001];
ll dp[1002][2*N+1];

ll rec(ll i,ll w)
{
    //cout << i << " " << w << endl;
    if(i>n&&w<h)
    return INT_MAX;
   
    if(w>=h)
    return 0;

    if(dp[i][w]!=-1)
    return dp[i][w];
    ll ans=0;
    
    ans=min({b[i]+rec(i,w+a[i]),b[i]+rec(i+1,w+a[i]),rec(i+1,w)});
     
     return dp[i][w]=ans;
      

}
int main()
{
   // freopen("input.txt","r",stdin);
    cin >> h >> n;
    
    memset(dp,-1,sizeof(dp));
     f(i,1,n)
     {
         cin >> a[i] >>  b[i];
     }

     cout <<rec(1,0);

}


Measured memory_bytes: 157568
I,O,T,J,L,S,Z=map(int,raw_input().split())
ans=0
ans1=0
ans+=2*O
ans1+=2*O
ans+=4*(I/2)
ans+=4*(J/2)
ans+=4*(L/2)
JL=min(J,L)
if JL>=1 and I>=1:
    ans1+=6
    J-=1
    L-=1
    I-=1
ans1+=4*(I/2)
ans1+=4*(J/2)
ans1+=4*(L/2)
print(max(ans/2,ans1/2))


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

int main() {
  int N;
  int dan=1;
  cin>>N;
  vector<int>d(N);
  for(int i=0; i<N; i++){
    cin>>d.at(i);
  }
  //昇順に並び替える
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      if(d.at(i)>d.at(j)){
        swap(d.at(i),d.at(j));
      }
    }
  }
  //並び替え終了
  for(int i=0; i<N-1; i++){
    if(d.at(i)==d.at(i+1)){
      continue;
    }
    dan++;
  } 
  cout<<dan<<endl;
}


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

using namespace std;

#define for_(i,a,b) for(int i=a;i<b;i++)

int m, a, b;
int MAX_I = 50001;

vector<int> prime;
void make_prime() {
	vector<bool> isprime(MAX_I, true);
	for_(i, 2, MAX_I) {
		if (isprime[i]) {
			prime.push_back(i);
			for (int j = 2 * i; j < MAX_I; j += i) isprime[j] = false;
		}
	}
}

void solve() {
	double rate = (double)a / (double)b;
	
	int maxS = 0;
	int ansp = -1, ansq = -1;
	
	int psize = (int)prime.size();
	
	for_(i, 0, psize) {
		int p = prime[i];
		int t = min(m / p, p * b / a);
		
		for_(j, 0, psize) {
			int q = prime[j];
			if (q > t) break;
			double fruc = (double)p / (double)q;
			
			if (rate <= fruc && fruc <= 1.0) {
				int S = p * q;
				if (S <= m && maxS < S) {
					maxS = S;
					ansp = p; ansq = q;
				}
			}
		}
	}
	
	cout << ansp << " " << ansq << endl;
}

int main() {
	make_prime();
	
	while (cin >> m >> a >> b, m) {
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1280
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>
//#include<bits/stdc++.h>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int dp[200000][10];
int main() {
	int N;
	cin >> N;
	
	int minValue = INT_MAX;
	int count = 0;

	for (int i = 0; i < N; ++i) {
		int p;
		cin >> p;
		
		if (p <= minValue) {
			++count;
			minValue = p;
		}
	}

	
	cout << count << endl;

	return 0;
}



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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<ll> A(n), B(n);

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

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    if (n & 1) {
        cout << B[n / 2] - A[n / 2] + 1 << endl;
    } else {
        auto Min = A[n / 2 - 1] + A[n / 2];
        auto Max = B[n / 2 - 1] + B[n / 2];
        cout << Max - Min + 1 << endl;
    }

}

Measured memory_bytes: 6420