akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <bitset>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif

int rint();char rch();long long rlong();
const int mn=1e5+2;
int va[mn];
void fail(int t) {
  printf("-1\n"); exit(0);
}
int n;
ll getres(ll x) {
  for (int i=0;i<n;i++) {
    int a=va[i];
    x=(x/a)*a;
  }
  return x;
}
ll getmin() {
  ll x=2;
  for (int i=n-1;i>=0;i--) {
    int a=va[i];
    x=((x+a-1)/a)*a;
  }
  return x;
}
ll gethi() {
  ll x=2;
  for (int i=n-1;i>=0;i--) {
    int a=va[i];
    x=(((x)/a)*a)+a-1;
  }
  return x;
}
int main()
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  n=rint();
  for (int i=0;i<n;i++) va[i]=rint();
  if (va[n-1]!=2) fail(1);
  ll lo=getmin();
  if (getres(lo)!=2) fail(2);
  ll hi=gethi();
  printf("%lld %lld\n",lo,hi);
}

int rint()
{
  int xx;scanf("%d",&xx); return xx;
}

Measured memory_bytes: 640
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, A = map(int, input().split())
    X = list(map(int, input().split()))
    X = [x-A for x in X]

    ret={0: 1}
    for xi in X:
        for y, cnt in list(ret.items()):
            ret[xi+y] = ret.get(xi+y, 0) + cnt
    print(ret[0]-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
n,k = map(int, input().split())
kk = 2*k
if k % 2:
    tmp = (n//k)**3
    print(tmp)
    exit()
kk = 0
k2 = 0
kkk = 0
for i in range(k//2,n+1):
    if i % k == 0:
        kk += 1
    if i % k == k//2:
        k2 += 1
    if i % k == 0 and i % k == k//2:
        kkk += 1
    # print(i, kk, k2, kkk)

print(kk**3 + k2**3 - kkk**3)


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
map<P,int> m;
P m2[1000001];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int d[1000001],u[1000001];

vector<int> sieve(int n) {
  vector<int> p(n);
  for(int i=2; i<n; i++) p[i]=i;
  for(int i=2; i*i<n; i++) {
    if(p[i]) {
      for(int j=i*i; j<n; j+=i) p[j]=0;
    }
  }
  return p;
}

vector<int> p=sieve(1000001);

int main() {
  int ma=0;
  {
    int x=0,y=0,k=0;
    for(int i=1; i<=1000000; i++) {
      m[P(x,y)]=i;
      m2[i]=P(x,y);
      int xx=x+dx[(k+1)%4],yy=y+dy[(k+1)%4];
      if(!m.count(P(xx,yy))) k=(k+1)%4;
      x=x+dx[k],y=y+dy[k];
      ma=max(ma,x);
    }
  }  int n,z;
  while(cin >> n >> z && n) {
    memset(d,-1,sizeof(d));
    memset(u,0,sizeof(d));
    if(p[z]) d[z]=1;
    else d[z]=0;
    P s=m2[z];
    for(int ii=0; ii<1000; ii++) {
      for(int jj=-ii; jj<=ii; jj++) {
        P now=P(s.first+ii,s.second+jj);
        if(now.first>ma) goto end;
        if(!m.count(now)) continue;
        int x=m[now];
        int c=d[x];
        for(int i=-1; i<2; i++) {
          P next=P(now.first+1,now.second+i);
          if(!m.count(next)||m[next]>n) continue;
          int y=m[next],cc=c;
          if(p[y]) cc++;
          d[y]=max(d[y],cc);
        }
      }
    }
  end:;
    int M=0,x=0;
    for(int i=1; i<=n; i++) {
      if(p[i]) {
        if(M<=d[i]) {
          M=d[i];
          x=i;
        }
      }
    }
    if(M==0) cout << 0 << " " << 0 << endl;
    else cout << M << " " << x << endl;
  }
  return 0;
}


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

ll modpow(ll a, ll b){
    ll x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) ; // multiplying with base
        }
        y = (y*y) ; // squaring the base
        b /= 2;
    }
    return x;
}
 
 
int main(){
 
	
	
	int n ; cin>>n;int d ; cin>>d;
	int q = 0; int c=0;

	while(q<n){
		q=q+d*2+1;
		c++;
	}
	cout<<c;
	int l ; cin>>l;
	
	
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 52;
const int MAX_H = 52;
const int MAX_WH = MAX_W * MAX_H;

/* typedef */

struct Stat {
  int lpos, rpos;
  Stat() {};
  Stat(int _lp, int _rp): lpos(_lp), rpos(_rp) {}
};

/* global variables */

bool lflds[MAX_WH], rflds[MAX_WH], used[MAX_WH][MAX_WH];

/* subroutines */

/* main */

int main() {
  int w, h, w2;
  int lspos, rspos, lgpos, rgpos;
  
  for (;;) {
    cin >> w >> h;
    if (w == 0) break;

    w2 = w + 2;
    memset(lflds, false, sizeof(lflds));
    memset(rflds, false, sizeof(rflds));

    for (int y = 1; y <= h; y++) {
      string lline, rline;
      cin >> lline >> rline;

      for (int x = 1; x <= w; x++) {
	int pos = y * w2 + x;

	switch (lline[x - 1]) {
	case '.': lflds[pos] = true; break;
	case 'L': lspos = pos; lflds[pos] = true; break;
	case '%': lgpos = pos; lflds[pos] = true; break;
	}

      	switch (rline[x - 1]) {
	case '.': rflds[pos] = true; break;
	case 'R': rspos = pos; rflds[pos] = true; break;
	case '%': rgpos = pos; rflds[pos] = true; break;
	}
      }
    }
    //printf("lspos(%d,%d), rspos(%d,%d)\n",
    //lspos % w2, lspos / w2, rspos % w2, rspos / w2);
    //printf("lgpos(%d,%d), rgpos(%d,%d)\n",
    //lgpos % w2, lgpos / w2, rgpos % w2, rgpos / w2);

    int ldpos[] = { 1, -w2, -1, w2};
    int rdpos[] = {-1, -w2,  1, w2};

    queue<Stat> q;
    q.push(Stat(lspos, rspos));

    memset(used, false, sizeof(used));
    used[lspos][rspos] = true;

    bool ok = false;
    
    while (! q.empty()) {
      Stat u = q.front(); q.pop();
      //printf("L(%d,%d), R(%d,%d)\n",
      //u.lpos % w2, u.lpos / w2, u.rpos % w2, u.rpos / w2);
      
      if (u.lpos == lgpos && u.rpos == rgpos) {
	ok = true;
	break;
      }
      if (u.lpos == lgpos || u.rpos == rgpos) continue;

      for (int di = 0; di < 4; di++) {
	int vlpos = u.lpos + ldpos[di];
	if (! lflds[vlpos]) vlpos = u.lpos;

	int vrpos = u.rpos + rdpos[di];
	if (! rflds[vrpos]) vrpos = u.rpos;

	if (! used[vlpos][vrpos]) {
	  used[vlpos][vrpos] = true;
	  q.push(Stat(vlpos, vrpos));
	}
      }
    }

    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}

Measured memory_bytes: 8832
n = int(input())
lis = list(map(int,input().split()))
dp = [10**10 for i in range(n+3)]
dp[0] = 0
for i in range(n-1):
  dp[i+1] = min(dp[i+1],dp[i] + abs(lis[i+1]-lis[i]))
  if i != n-2:
    dp[i+2] = min(dp[i+2],dp[i] + abs(lis[i+2]-lis[i]))
print(dp[n-1])

Measured memory_bytes: 13924
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
    
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, q, com, s, t, x, i;

const int INF = (1LL << 31) - 1;
const int sqrtN = 512;
struct SqrtDecomposition {
	int N, K;
	vector<int> data;
	vector<bool> lazyFlag;
	vector<int> lazyUpdate;
	SqrtDecomposition(int n) : N(n) {
		K = (N + sqrtN - 1) / sqrtN;
		data.assign(K * sqrtN, INF);
		lazyFlag.assign(K, false);
		lazyUpdate.assign(K, 0);
	}
	void eval(int k) {
		if (lazyFlag[k]) {
			lazyFlag[k] = false;
			for (int i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
				data[i] = lazyUpdate[k];
			}
		}
	}
	// [s, t)
	void update(int s, int t, int x) {
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= s || t <= l)
				continue;
			if (s <= l && r <= t) {
				lazyFlag[k] = true;
				lazyUpdate[k] = x;
			}
			else {
				eval(k);
				for (int i = max(s, l); i < min(t, r); ++i) {
					data[i] = x;
				}
			}
		}
	}
	int find(int i) {
		int k = i / sqrtN;
		eval(k);
		return data[i];
	}
};

int main() {
	cin >> n >> q;
	SqrtDecomposition ruq(n);
	rep(j, q) {
		cin >> com;
		if (com == 0) {
			cin >> s >> t >> x;
			ruq.update(s, t + 1, x);
		}
		else {
			cin >> i;
			cout << ruq.find(i) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;


int main(){

    int n;
    cin >> n;

    vector<int> a;
    vector<int> b;

    a.pback(0);

    rep(i,n - 1){
        int tmp;
        cin >> tmp;
        b.pback(tmp);
        a.pback(0);
    }

    for(int i = 1; i <= n - 2; i++){
        a[i] = min(b[i - 1], b[i]);
    }

    a[0] = b[0];
    a[n - 1] = b[n - 2];

    int ans = 0;

    rep(i,n){
        ans += a[i];
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 256
//#pragma warning(disable:4996)
#include <stdio.h>

int main() {
	int r, d, x;
	scanf("%d %d %d", &r, &d, &x);

	for (int i = 1; i <= 10; i++) {
		x = x * r - d;
		printf("%d\n", x);
	}
	//while (1);
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    ll ans = a[0] / 2;
    if (a[0] % 2 == 0) {
        a[0] = 0;
    } else {
        a[0] = 1;
    }
    for (int i = 1; i < N; i++) {
        if (a[i] == 0) {
            continue;
        }
        if (a[i - 1] == 1) {
            a[i]--;
            ans++;
        }
        ans += a[i] / 2;
        if (a[i] % 2 == 0) {
            a[i] = 0;
        } else {
            a[i] = 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;

int main(){
	cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	ll sum = pow(3,n);
	ll m = 1;
	rep(i,n){
		if(a[i]%2 == 0)m *= 2;
	}
	cout << sum - m << endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define upper(n,m) (n+m-1)/m
#define rounding(n) (int)((double)n+0.5)

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define ALL(a) a.begin(),a.end()

#define coutALL(i,a) {int i=0;for(int e:a) cout<<(i++?" ":"")<<e; cout<<endl;}
#define coutYN(a) cout<<(a?"Yes":"No")<<endl;
#define coutyn(a) cout<<(a?"yes":"no")<<endl;

#define deb cout<<"debug"<<endl
#define debn(n) cout<<"debug: "<<n<<endl

const int INF=INT_MAX;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
//const int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using namespace std;

typedef pair<int,int> P;
typedef long long LL;

signed main(){

  ios::sync_with_stdio(false);

  int n;
  cin>>n;

  int flag[1000]={};
  int where[10010]={};
  vector <int> a(n),sorted_a;
  REP(i,n) cin>>a[i],where[a[i]]=i;

  sorted_a=a;
  sort(ALL(sorted_a));

  vector<vector<int>> cost_list;

  REP(i,n){

    if(flag[i]) continue;

    int now=i;
    vector <int> cost;

    for(;!flag[now];){

      cost.pb(a[now]);
      flag[now]=1;
      now=where[sorted_a[now]];

    }

    cost_list.pb(cost);

  }

  int ans=0,min_a=sorted_a[0];

  for(auto e:cost_list){

    int r1=accumulate(ALL(e),0)+(e.size()-2)**min_element(ALL(e));
    int r2=accumulate(ALL(e),0)+*min_element(ALL(e))+(e.size()+1)*min_a;

    ans+=min(r1,r2);

  }

  cout<<ans<<endl;

  return 0;

}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll a,b,m;cin>>a>>b>>m;
  vector<ll>as(a), bs(b);

  rep(i, a)cin>>as[i];
  rep(i, b)cin>>bs[i];
  ll result=INF;
  rep(i, m){
    int x,y,c;cin>>x>>y>>c;
    x--;y--;
    result = min<ll>(result, as[x]+bs[y]-c);
  }
  ll mina=INF;
  ll minb=INF;
  rep(i, a)mina = min<ll>(mina, as[i]);
  rep(i, b)minb = min<ll>(minb, bs[i]);

  result = min<ll>(result, mina+minb);

  cout<<result<<endl;

  return 0;
}

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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T> ostream & operator<<(ostream& os, vector<T> const& v){
        for(auto it=v.begin(); it!=v.end(); ++it){
            os << *it << (it+1==v.end() ? "" : ",");
        }
        return os;
    }
}

//clear memory
#define clr(a) memset((a), 0 ,sizeof(a))

int gcd(int a, int b){
   int tmp;
   while(a%b!=0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}
 
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
 
bool prime_number(int n){
   if(n==0||n==1) return false;
   vb a(n+1);
   fill(all(a),true);
   loop(i,2,n/2+1){
      if(!a[i]) continue;
      for(int j=2;i*j<=n;j++){
         a[i*j]=false;
      }
   }
   return a[n];
}

int main(){
   int a,ans=0,tmp;
   
   while(cin>>a){
      vi b;
      ans=0;
      rep(i,a){
         cin >> tmp;
         b.pb(tmp);
      }
      sort(all(b));
      rep(i,a){
         ans+= (a-i)*b[i];
      }
      cout << ans << endl;
   }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } else return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } else return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;

int N, M, Q;
int cnt[500];
vector<int> pinfo[500];
vector<pii> v[500];
int ans[112345];

int main() {
	cin >> N >> M >> Q;
	REP(i, M) {
		int l, r;
		scanf("%d %d", &l, &r);
		l--; r--;
		cnt[r]++;
		pinfo[l].push_back(r);
	}
	
	REP(i, Q) {
		int p, q;
		scanf("%d %d", &p, &q);
		p--; q--;
		v[p].push_back(pii(q, i));
	}
	
	REP(i, N) {
		int sum[500] = {};
		sum[i] = cnt[i];
		FOR(j, i + 1, N) sum[j] = sum[j - 1] + cnt[j];;
		
		REP(j, v[i].size()) {
			ans[v[i][j].se] = sum[v[i][j].fi];
		}
		
		REP(j, pinfo[i].size()) {
			cnt[pinfo[i][j]]--;
		}
	}
	
	REP(i, Q) printf("%d\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int k,n,a[200000],m=0;
    scanf("%d%d%d",&k,&n,a);
    long long ans=0;
    for(int i=1;i<n;i++){
        scanf("%d",a+i);
        ans+=a[i]-a[i-1];
        if(a[i]-a[i-1]>m)m=a[i]-a[i-1];
    }
    ans+=k-a[n-1]+a[0];
    if(k-a[n-1]+a[0]>m)m=k-a[n-1]+a[0];
    printf("%lld\n",ans-m);
}

Measured memory_bytes: 896
M, N, X, Y = map(int, input().split())
X_city = list(map(int, input().split()))
Y_city = list(map(int, input().split()))

X_city.append(X)
Y_city.append(Y)

if max(X_city) < min(Y_city) :
  print("No War")
else :
  print("War")

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

using namespace std;
int H,W,K;
int S[11][1010];

int ffunc(int mode, bool cut_place[]){
	int re = 0;
	int i = 0;
	while(mode != 0){
		if(mode%2 == 1){
			cut_place[i] = true;
			re++;
		}
		else cut_place[i] = false;
		i++;
		mode = mode/2;
	}
	return re;
}



int func(int mode){
	bool cut_place[H];
	for(int i = 0; i < H; i++) cut_place[i] = false;
	int re = ffunc(mode,cut_place);
	
	/*
	cout<<"mode = "<<mode<<", re = "<<re<<endl;
	for(int i = 0; i < H; i++){
		if(cut_place[i] == true) cout<<"1 ";
		else cout<<"0 ";
	}
	cout<<endl;
	*/
	
	int k[H]; for(int i = 0; i < H; i++) k[i] = 0;
	int k_num = 0;
	int haba = 0;
	for(int i = 0; i < W; i++){
		k_num = 0;
		for(int j = 0; j < H; j++){
			if(S[j][i] == 1) k[k_num]++;
			if(cut_place[j] == true){
				k_num++;
			}
		}
		for(int j = 0; j < H; j++){
			if(k[j] > K){
				i--;
				for(int q = 0; q < H; q++){
					k[q] = 0;
				}
				re++;
				if(haba == 0) return 2000;
				haba = 0;
			}
		}
		haba++;
	}
	
	return re;
}
int main(void)
{
	cin>>H>>W>>K;
	for(int i = 0; i < H; i++){
		char a1[W];
		cin>>a1;
		for(int j = 0; j < W; j++){
			S[i][j] = ((int)a1[j])-48;
		}
	}
	
	int mode = pow(2,H-1);
	//cout<<"mode = "<<mode<<endl;
	int p,ans = 2000;
	for(int i = 0; i < mode; i++){
		p = func(i);
		if(p < ans) ans = p;
	}
	/*
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cout<<S[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"ans = "<<ans<<endl;
	*/
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [None]*(k+1)
ind = 0
while ind<a[0]:
    dp[ind] = False
    ind += 1
for i in range(ind, k+1):
    for j in a:
        if i-j<0:
            dp[i] = False
            break
        if not dp[i-j]:
            dp[i] = True
            break
    else:
        dp[i] = False
print('First' if dp[k] else 'Second')


Measured memory_bytes: 42860
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var ans = 0, mn = 1;
  for(var i = 0; i < n; i++){
    var t = next()-1;
    if(t < mn){
      mn = Math.max(mn,t+2);
    }else{
      ans += t/mn|0;
      mn = Math.max(2,mn);
    }
  }
  return ans;
}

Measured memory_bytes: 41608
#include <iostream>

using namespace std;

int main()
{
    int S;
    int h, m, s;

    cin >> S;

    h = S / 3600;
    m = S / 60 % 60;
    s = S % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}

Measured memory_bytes: 3108
n, k = map(int, input().split())

def calc_next_x(n,k):
    if n > k:
        return x % k
    else:
        return abs(n-k)

x_prev = 10 ** 18 + 1
x = n
while x < x_prev:
    x_prev = x
    
    x = calc_next_x(x, k)

print(min(x, x_prev))

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  int a[n]; rep(i, n) cin >> a[i];
  int l = a[0], r = a[n-1];
  int ans = 1e9;
  for(int i = 1, j = n-2; i <= j; ) {
    if(abs(l+a[i] - r) < ans) {
      l += a[i];
      ++i;
    } else if(abs(l - r+a[j]) < ans) {
	r += a[j];
	--j;
    } else {
      if(l < r) l += a[i++];
      else r += a[j--];
    }
    ans = abs(l-r);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    double n,k;
    cin>>n>>k;
    ll arr[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576};
    double ans=0;
    for(ll i=1;i<=(ll)n;i++)
    {
        ll cnt=0;
        double val = i;
        while(val<k)
        {
            val = i;
            val = i * arr[cnt];
            cnt++;
        }
        if(cnt>0) cnt--;
        ans+=((1/n)*((double)1/arr[cnt]));
    }
    cout<<setprecision(10)<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
def acinput():
    return list(map(int,input().split(" ")))


n=int(input())
p=acinput()

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


print(count)

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char a = in.next().charAt(0);
        if (a >= 'a' && a <= 'z') {
            System.out.println("a");
        } else {
            System.out.println("A");
        }
    }
}

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

int main()
{
	while(true){
		int M, T, P, R;
		cin >> M >> T >> P >> R;

		if(M==0 && T==0 && P==0 && R==0)
			break;

		int CP[50], TT[50], PT[50][10];		// 正解数，時間計，ペナルティ
		for(int i=0; i<T; i++){
			CP[i] = TT[i] = 0;
			for(int j=0; j<P; j++)
				PT[i][j] = 0;
		}

		for(int i=0; i<R; i++){				// 各チームの正解数，時間計を求める
			int m, t, p, j;
			cin >> m >> t >> p >> j;

			if(j==0){
				CP[t-1]++;
				TT[t-1] += (m+PT[t-1][p-1]);
			}
			else{
				PT[t-1][p-1] += 20;
			}
		}

		int tnow, tpre = -1;				// 今のチーム，1つ前のチーム
		bool flg[50];					// 処理済フラグ
		for(int i=0; i<T; i++)
			flg[i] = false;

		for(int i=0; i<T; i++){
			tnow = -1;
			for(int j=0; j<T; j++){				// 今のチームを求める
				if(flg[j])
					continue;

				if(tnow==-1){
					tnow = j;
				}
				else{
					if(CP[j]>CP[tnow] || (CP[j]==CP[tnow] && TT[j]<=TT[tnow])){
						tnow = j;
					}
				}
			}

			if(tpre!=-1){							// 出力
				if(CP[tnow]==CP[tpre] && TT[tnow]==TT[tpre])
					cout << '=';
				else
					cout << ',';
			}
			cout << tnow+1;

			flg[tnow] = true;
			tpre = tnow;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,K;
    cin >> N >> K;
    ll h[N+K];
    ll i,j;
    ll tmp;
    for (i=K;i<N+K;i++){
      cin >> h[i];
    }
    for(i=0;i<K;i++){
      h[i]=h[K];
    }
    h[0]=h[1];
    ll dp[N+K];
    for(i=0;i<K;i++){
      dp[i]=0;
    }
    for(i=K;i<N+K;i++){
        dp[i]=dp[i-K]+abs(h[i]-h[i-K]);
      for(j=K-1;j>0;j--){
        tmp=dp[i-j]+abs(h[i]-h[i-j]);
        if(tmp<dp[i])dp[i]=tmp;
    }
  }
    cout << dp[N+K-1];
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define cent 100
#define INF 100000000

int Graph[cent+1][cent+1], care[cent+1], size[cent+1];

void depthFirstSearch(int pi, int time);

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

    for(int i = 1; i <= n; ++i)
    {
        care[i] = INF;
        scanf("%d", &x);
        scanf("%d", &size[x]);
        for(int j = 1; j <= size[x]; ++j) scanf("%d", &Graph[x][j]);
    }

    depthFirstSearch(1, 0);

    for (int i = 1; i <= n; ++i) printf("%d %d\n", i, (care[i] == INF) ? -1 : care[i]);

    return 0;
}

void depthFirstSearch(int pi, int time)
{
    care[pi] = time;
    for(int i = 1; i <= size[pi] ; ++i) if(time+1 < care[Graph[pi][i]]) depthFirstSearch(Graph[pi][i], time+1);
}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

vector<int> part[100010];

int main() {
    int n,m;cin>>n>>m;
    rep(i,n) {
        int a,b;cin>>a>>b;
        part[a].push_back(b); 
    }
    rep(i,m+1) sort(part[i].begin(),part[i].end());
    int ma=0;
    priority_queue<P> qu;
    ll ans = 0;
    for (int i = 1;i<=m;i++) {
        int sz = part[i].size();
        if(sz) {
            qu.push(P(part[i][sz-1],i));
            part[i].erase(part[i].end()-1);
        }
        if(qu.size()) {
            int sara = qu.top().first,day = qu.top().second;
            qu.pop();
            ans += sara;
            int pre_sz = part[day].size();
            if(pre_sz) {
                qu.push(P(part[day][pre_sz-1],day));
                part[day].erase(part[day].end()-1);
            }
        }
    }
    cout<<ans<<endl;
}

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

int main(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int tot=0;
    for(int i=0;i<=(n);i++){
	for(int j=0;j<=(n);j++){
	    int k = (n-(i*r+j*g));
	    if(k%b==0){
	    	if(k/b>=0)
		    ++tot;
	    }
	}
    }
    cout<<tot<<endl;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

bool DP[3005][3005];
double ans = 0;
int I = 0, J = 0;

int main(){
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  DP[0][0] = true;
  for (int i = 0; i <= F; i++){
    for (int j = 0; j <= F; j++){
      if (!DP[i][j]) continue;

      if (i > 0 && ans < (double) j / (double) i) {
        ans = (double)j / (double)i;
        I = i; J = j;
      }

      if (i + 100 * A <= F) DP[i + 100 * A][j] = true;
      if (i + 100 * B <= F) DP[i + 100 * B][j] = true;

      int Water = i - j;
      if (j + C <= Water * E / 100 && j + C <= F){
        DP[i + C][j + C] = true;
      }
      if (j + D <= Water * E / 100 && j + D <= F){
        DP[i + D][j + D] = true;
      }
    }
  }

  if (I == 0 && J == 0) I += 100* A;

  cout << I << " " << J << endl;


  return 0;
}


Measured memory_bytes: 9220
#include<stdio.h>
int main()
{
int i,j,ten[11],sum,w,n,sum2;
for(i=0;i<10;i++)
{
	scanf("%d",&ten[i]);
}
for(n=10;n>0;n--)
{
        for( i=0; i<9; i++ )
          {
            if ( ten[i]>ten[i+1] ) 
              {
                w=ten[i];
                ten[i]=ten[i+1];
                ten[i+1]=w;
              }
          }
	}
          sum=0;
          for(i=9;i>6;i--)
          {
          	sum+=ten[i];
          }
for(i=0;i<10;i++)
{
	scanf("%d",&ten[i]);
}
for(n=10;n>1;n--)
{
        for( i=0; i<9; i++ )
          {
            if ( ten[i]>ten[i+1] ) 
              {
                w=ten[i];
                ten[i]=ten[i+1];
                ten[i+1]=w;
              }
          }
 }
          sum2=0;
          for(i=9;i>6;i--)
          {
          	sum2+=ten[i];
          }
printf("%d %d\n",sum,sum2);
return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#define N 10000

int main(void){
  int i,num,j;
  int n,hit,sumhit[N];
  
  for(i=0;;i++){
    scanf("%d",&n);
    if(n==0)
      break;
    sumhit[i]=0;
    for(j=0;j<n/4;j++){
      scanf("%d",&hit);
      sumhit[i]+=hit;
    }
  }
  num=i;
  for(i=0;i<num;i++){
    printf("%d\n",sumhit[i]);
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace ABC110
{
    class B
    {
        static void Main(string[] args)
        {
            var NMXY = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var xmax = Console.ReadLine().Split().Select(int.Parse).ToArray().Max();
            var ymin = Console.ReadLine().Split().Select(int.Parse).ToArray().Min();

            if (NMXY[2] < NMXY[3] && Math.Max(NMXY[2], xmax) < Math.Min(NMXY[3], ymin)) Console.WriteLine("No War");
            else Console.WriteLine("War");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    
    string ans;
    if (a < b) {
        a += v*t;
        b += w*t;
        if (a >= b) ans = "YES";
        else ans = "NO";
    }
    else {
        a -= v*t;
        b -= w*t;
        if (a <= b) ans = "YES";
        else ans = "NO";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
s = gets.chomp.to_s
t = gets.chomp.to_s

end_point = s.size - t.size
replace_point = nil
0.upto(end_point) do |start|
  successive_num = 0
  t.size.times do |order|
    if s[start + order] == "?" or s[start + order] == t[order]
      successive_num += 1
      if successive_num == t.size
        replace_point = start
      end
    else
      break
    end
  end
end

if replace_point
  s[replace_point, t.size] = t
  s.gsub!("?", "a")
  puts s
else
  puts "UNRESTORABLE"
end


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

struct player {
    int id;
    double t;
};

bool cmp(player const &lhs, player const &rhs) {
    return lhs.t < rhs.t;
}
void print(player const &p) {
    std::cout << p.id << " " << std::fixed << std::setprecision(2) << p.t << std::endl;
}

int main(void)
{
    std::vector<player> g[3];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 8; j++) {
            player p;
            std::cin >> p.id >> p.t;
            g[i].emplace_back(p);
        }
    }

    for (int i = 0; i < 3; i++) {
        std::sort(g[i].begin(), g[i].end(), cmp);
    }

    std::vector<player> rest;

    for (int i = 0; i < 3; i++) {
        print(g[i][0]);
        print(g[i][1]);
        std::copy(g[i].begin() + 2, g[i].end(), std::back_inserter(rest));
    }

    std::sort(rest.begin(), rest.end(), cmp);

    print(rest[0]);
    print(rest[1]);

    return 0;
}

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

using namespace std;

long long a[55], s;
int n;

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	for(int i = 1; i <= n; ++i) scanf("%lld",&a[i]), s += a[i];
	for(long long k = max(0ll, s - n * (n - 1)); k <= s; ++k){
		long long op = 0;
		for(int i = 1; i <= n; ++i){
			op += (a[i] + k + 1) / (n + 1); 
		}
		if (op == k){
			printf("%lld",k);
			return 0;
		}
	}
	return 0; 
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < n; i++) {
            y[i] = Integer.parseInt(sc.next());
        }

        // p = 1
        double D = 0.0;
        for (int i = 0; i < n; i++) {
            D += Math.abs(x[i] - y[i]);
        }
        out.printf("%.10f\n", D);

        // p = 2
        D = 0.0;
        for (int i = 0; i < n; i++) {
            D += Math.pow(x[i] - y[i], 2);
        }
        out.printf("%.10f\n", Math.sqrt(D));

        // p = 3
        D = 0.0;
        for (int i = 0; i < n; i++) {
            D += Math.pow(Math.abs(x[i] - y[i]), 3);
        }
        out.printf("%.10f\n", Math.cbrt(D));

        // p = unlimited
        D = 0.0;
        for (int i = 0; i < n; i++) {
            double temp = D;
            D = Math.max(Math.abs(x[i] - y[i]), temp);
        }
        out.printf("%.10f\n", D);
        out.flush();
    }
}


Measured memory_bytes: 26612
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <utility>
#define ll long long
using namespace std;

int main() {
    int n,r;
    vector<int> a;
    cin>>n;
    if(n==0)
        a.push_back(0);
    r=-2;
    while(n!=0){
        if(n<0){
            a.push_back(abs(n%2));
            n=n/r+(abs(n%2)==1);
        }else{
            a.push_back(n%2);
            n=n/r;
        }
        //cout<<n<<'\n';
    }
    for(int i=a.size()-1;i>=0;i--)
        cout<<a[i];
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B,C,D; cin >> A >> B >> C >> D;
    int l=A+B;
    int r=C+D;
    if(l>r){
        cout << "Left" << endl;
    }else if(l==r){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long a[100];
long long s[100];
long long t[100];
long long x[100];
long long y[100];
int main(){
	int T=0;
	int n;
	while(scanf("%d",&n),n){
		n*=2;
		int p=(int)(sqrt((double)n+0.00000005));
		if(p*p==n){
			printf("Case %d: %d %d\n",++T,p,1);
			continue;
		}
		long double now=sqrt((long double)n);
		a[0]=(long long)now;
		s[0]=0;t[0]=1;
		x[0]=1;y[0]=0;
		x[1]=a[0];y[1]=1;
		for(int i=0;i<50;i++){
			s[i+1]=a[i]*t[i]-s[i];
			t[i+1]=((long long)n-s[i+1]*s[i+1])/t[i];
			a[i+1]=(a[0]+s[i+1])/t[i+1];
			x[i+2]=a[i+1]*x[i+1]+x[i];
			y[i+2]=a[i+1]*y[i+1]+y[i];
	//		printf("%lld %lld %lld %lld %lld\n",s[i+1],t[i+1],a[i+1],x[i+2],y[i+2]);
			if(t[i+1]==1&&x[i+1]*x[i+1]-y[i+1]*y[i+1]*n==1){
				printf("Case %d: %lld %lld\n",++T,x[i+1],y[i+1]);
				break;
			}
		}
	}
}

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, pair<long long, long long>>;

long long N;
pair<long long, long long> z[100000];
pair<long long, long long> x[100000], y[100000];

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  cin >> N;
  rep(i, N) {
    long long a, b;
    cin >> a >> b;
    x[i] = make_pair(a, i);
    y[i] = make_pair(b, i);
  }
  sort(x, x+N);
  sort(y, y+N);

  priority_queue<P, vector<P>, greater<P>> quex;
  for(long long i = 0; i < N - 1; i++) {
    long long dist = x[i+1].first - x[i].first;
    quex.push(make_pair(dist, make_pair(x[i].second, x[i+1].second)));
  }
  priority_queue<P, vector<P>, greater<P>> quey;
  for(long long i = 0; i < N - 1; i++) {
    long long dist = y[i+1].first - y[i].first;
    quey.push(make_pair(dist, make_pair(y[i].second, y[i+1].second)));
  }

  priority_queue<P, vector<P>, greater<P>> que;
  for(long long i = 0; i < N - 1; i++) {
    P nx = quex.top();
    quex.pop();
    que.push(nx);
    P ny = quey.top();
    quey.pop();
    que.push(ny);
  }

  UnionFind tree(N);
  long long ans = 0;
  
  while(que.size()) {
    P p = que.top();
    que.pop();
    long long cost = p.first;
    long long s = p.second.first;
    long long t = p.second.second;
    if(tree.same(s, t)) {
      continue;
    } else {
      tree.unite(s, t);
      ans += cost;
      // cout << cost << " " << s << " " << t << endl;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int N, K, num = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    if(num * 2 > num + K) num += K;
    else num *= 2;
  }
  cout << num << endl;
  return 0;
}


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

using namespace std;





int main() {
	int n;

	cin >> n;
	int ans = 0;

	int v[n], c[n];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < n; i++) {
		if (v[i] > c[i]) {
			ans += v[i] - c[i];
		}

	}
	
	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;

const ll N = 3e3 + 5, MOD = 1e9 + 7;
const double C = 1;

int n;
double a[N];
double dp[N][N];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for (int i = 1; i <= n; i++)
        cin>>a[i];
    dp[0][0] = C;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= i; j++){
            dp[i][j] = (C - a[i]) * dp[i - 1][j];
            if (j)
                dp[i][j] += a[i] * dp[i - 1][j - 1];
        }
    double ans = 0;
    for (int i = 1; i <= n; i++)
        if (i * 2 > n)
            ans += dp[n][i];
    printf ("%.10f\n", ans);
    return 0;
}


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

void rotate_side(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }

  for (int i = 0; i < n; i++) {
    int tmp = si[0]; 
    si[0] = si[2];
    si[2] = si[5];
    si[5] = si[4];
    si[4] = tmp;
  }
}
void rotate_front(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }

  for (int i = 0; i < n; i++) {
      int tmp = si[0];
      si[0] = si[1];
      si[1] = si[5];
      si[5] = si[3];
      si[3] = tmp;
  }
}

void rotate_top(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }
  for (int i = 0; i < n; i++) {
    int tmp = si.at(1);
    si[1] = si[2];
    si[2] = si[3];
    si[3] = si[4];
    si[4] = tmp;
  }
}
 
void init_dice(vector<int> &si) {
  cin >> si[0];
  cin >> si[2];
  cin >> si[3];
  cin >> si[1];
  cin >> si[4];
  cin >> si[5];
}

int findLabel(vector<int> &si, int num) {
  return distance(si.begin(), find(si.begin(), si.end(), num));
}

int main() {
  vector<int> si1(6);
  vector<int> si2(6);
  init_dice(si1);
  init_dice(si2);
  int top = si1[0];
  int front = si1[2];
  
      set<int> s(si1.begin(), si1.end());
      set<int> s2(si2.begin(), si2.end());
      if (s.size() != s2.size()) {
          cout << "No" << endl;
          return 0;
      } else if(s.size() < 3) {
          cout << "Yes" << endl;
          return 0;
      }

    // find top
    int d = findLabel(si2, top);
    // cout << "DEBUG: " << d << endl;
    switch (d) {
    case 0:
      // do nothing
      break;
    case 1:
      rotate_front(si2, 1);
      break;
    case 2:
      rotate_side(si2, 1);
      break;
    case 3:
      rotate_front(si2, 3);
      break;
    case 4:
      rotate_side(si2, -1);
      break;
    case 5:
      rotate_front(si2, 2);
      break;
    }

    // find front
    d = findLabel(si2, front);
    // cout << "DEBUG: " << d << endl;
    // cout << "DEBUG: ";
    // for (int k = 0; k < 6; k++) cout << si.at(k) << " ";
    // cout << endl;
    switch (d) {
    case 1:
      rotate_top(si2, 3);
      break;
    case 2:
      // do nothing
      break;
    case 3:
      rotate_top(si2, 1);
      break;
    case 4:
      rotate_top(si2, 2);
      break;
    default:
      cout << "ERR: " << d << endl;
      return 0;
    }
    // cout << "DEBUG: ";
    // for (int k = 0; k < 6; k++) cout << si.at(k) << " ";
    // cout << endl;
    cout << ((si1 == si2) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3112
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } }
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void) {
	LL A, B, C;
	cin >> A >> B >> C;

	cout << max(C - (A - B), 0LL) << endl;

	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
    i *= 500
    for j in range(b+1):
        j *= 100
        for k in range(c+1):
            k *= 50
            sum = i + k + j
            if sum == x:
                ans += 1

print(ans)
            


Measured memory_bytes: 9084