akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;

const int MAX_N = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

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

int par[MAX_N];
int ran[MAX_N];

void init(int n) {
	for(int i = 0; i < n; i++) {
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x) {
	if(par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int N;
int AA[MAX_N];
int BB[MAX_N];
int A[MAX_N], B[MAX_N];

int C[MAX_N];
vector<int> vec;

int fd(int a) {
	return lower_bound(all(vec), a) - vec.begin();
}

void solve() {
	cin >> N;
	int a = 0;
	rep(i, 0, N) {
		cin >> AA[i];
		a ^= AA[i];
	}
	rep(i, 0, N) cin >> BB[i];
	int at = 0;
	rep(i, 0, N) {
		if(AA[i] != BB[i]) {
			A[at] = AA[i];
			B[at] = BB[i];
			at++;
		}
	}
	N = at;
	A[N] = a;
	/*
	debug(vector<int>(A, A + at + 1));
	debug(vector<int>(B, B + at));
	*/

	rep(i, 0, N) vec.push_back(B[i]);

	sort(all(vec));
	vec.erase(unique(all(vec)), vec.end());
	int n = (int)vec.size();
	rep(i, 0, N) {
		int a = fd(B[i]);
		C[a]++;
	}

	bool ok = true;
	rep(i, 0, N + 1) {
		int a = fd(A[i]);
		if(a >= n) continue;
		if(vec[a] == A[i]) C[a]--;
	}
	rep(i, 0, n) {
		if(C[i] > 0) {
			ok = false;
			break;
		}
	}
	if(!ok) cout << "-1\n";
	else {
		init(n);
		rep(i, 0, N) unite(fd(A[i]), fd(B[i]));
		set<int> s;
		rep(i, 0, n) s.insert(find(i));
		if(fd(A[N]) < n && vec[fd(A[N])] == A[N]) cout << N + (int)s.size() - 1 << "\n";
		else cout << N + (int)s.size() << "\n";
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 5752
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n, ans;
    ans = 1;
    cin >> n;
    rep(i,3) ans *= n;
    cout << ans << endl;
}

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

int main( void ) {
    int m, f, r;
    while( cin >> m >> f >> r && m + f + r != -3 ) {
        if( m == -1 || f == -1 || m + f < 30 ) cout << 'F' << '\n';
        else if( m + f >= 80 ) cout << 'A' << '\n';
        else if( m + f >= 65 ) cout << 'B' << '\n';
        else if( m + f >= 50 ) cout << 'C' << '\n';
        else cout << (r >= 50 ? 'C' : 'D' ) << '\n';
    }
    return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int n,m;
	int tunnel,in,out,ch=0,max;
	
	scanf("%d",&n);
	scanf("%d",&m);
	tunnel=m;
	max=m;
	for(int i=0;i<n;i++){
		scanf("%d %d",&in,&out);
		tunnel+=in;
		tunnel-=out;
		if(max<tunnel)
		max=tunnel;
		if(tunnel<0){
			ch=1;
			break;
		}
	}
	if(ch==1)
	printf("0\n");
	else
	printf("%d\n",max);
}

Measured memory_bytes: 3200
/*s1190073  Rina Sato
  File name: prog5a.c
  This is a Burte Force approach program.*/

#include <stdio.h>

int solve(int,int);
int n;
int A[21];

int main(void){
  int q,i,j;
  int M[201];
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&M[i]);
  }
  for(i = 0 ; i < q ; i++){  
    if(solve(0,M[i])){
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
  }
  return 0;
}

int solve(int p,int t)
{
  int r,s;

  if(t < 0) return 0;
  if(t == 0) return 1; 
  if(p == n)return 0;
  r=solve(p+1,t);
  s=solve(p+1,t-A[p]);
  if(r==1 || s==1) return 1;
  else return 0;
}

Measured memory_bytes: 376
from collections import deque

N = int(input())
A = list(map(int,input().split()))
A_deq = deque(A)

max_A = 0
ans = 0
while A_deq:
    anum = A_deq.popleft()
    if max_A <= anum:
        max_A = anum
    else:
        ans += max_A - anum

print(ans)


Measured memory_bytes: 96336
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

long long gcd(long long a, long long b)
{
    long long c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(){

    long T;
    cin >> T;
    long long* A = new long long[T];
    long long* B = new long long[T];
    long long* C = new long long[T];
    long long* D = new long long[T];
    bool* result = new bool[T];
    for(int i = 0; i < T; i ++){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    
        //cout << "input:" << A[i] << B[i] << C[i] << D[i] << endl;

        long long firstA = A[i];
        vector<long long> history;
        long long x = gcd(B[i], D[i]);

        //cout << A[i]%B[i] + ((B[i] - A[i]%B[i] - 1) / x) * x << endl;
        //cout << ((B[i] - A[i]%B[i] - 1) / x) * x << endl;
        //cout << x << endl;

        if (A[i] < B[i]){
            result[i] = false;
            cout << "No" << endl;
            continue;
        }

        if (D[i] < B[i]){
            result[i] = false;
            cout << "No" << endl;
            continue;
        }

        if(A[i]%B[i] + ((B[i] - A[i]%B[i] - 1) / x) * x > C[i]){
            result[i] = false;
            cout << "No" << endl;
        }
        else{
            result[i] = true;
            cout << "Yes" << endl;
        }

        /*while(true){
            //cout << "first:" << A[i] << endl;
            /*if(A[i] % B[i] > C[i]){
                result[i] = false;
                cout << "No" << endl;
                break;
            }
            auto itr = std::find(history.begin(), history.end(), A[i]);
            size_t index = std::distance( history.begin(), itr );
            if (index != history.size()) { // 発見できたとき
                result[i] = true;
                cout << "Yes" << endl;
                break;
            }
            history.push_back(A[i]);

            A[i] = (A[i] + D[i]) % B[i];
        }*/
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[233333];
int n,k;
int vis[30];
int val[30];
int main()
{
	cin>>n;
	memset(val,127,sizeof(val));
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		memset(vis,0,sizeof(vis));
		for(int j=0;j<s.size();j++)
		{
			 vis[s[j]-'a']++;
		}
		for(int j=0;j<26;j++)
		{
			val[j]=min(val[j],vis[j]);
		}
	}
	for(int i=0;i<26;i++)
	{
		for(int j=0;j<val[i];j++)
		{
			cout<<(char)('a'+i);
		}
	}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________

	ll n;
	cin >> n;
	cout << (n / 500) * 1000 + ((n % 500) / 5) * 5 << en;


	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define NUM 1000000007

/*
int koyaku(int a,int b){
  if(a>b){
    if(a%b==0) return b;
    return koyaku(b,a-b);}
  else{
    if(b%a==0) return a;
    return koyaku(a,b-a);}
    }
*/

int koyaku(int a,int b){
  if(b==0) return a;
  return koyaku(b,a%b);
}

/*
long int power(int a){ //2**a%NUM
  if(a<30) return (long int)pow(2,a);
  long int tmp=(long int)pow(2,30)%NUM;
  return ((int)pow(tmp,a/30)%NUM)*(int)pow(2,a%30);}
*/

long int power2(int a,long int b){
  if(b==1) return (long int)a;
  if(b%2==0){
    long int tmp=power2(a,b/2)%NUM;
    return (tmp*tmp)%NUM;}
  else{
    return (power2(a,b-1)*a)%NUM;}
}
  

long int disco(int h,int w,int t){
  if(t==1){
    long int sum=0;
    sum+=power2(2,h);
    //printf("%ld\n",sum);
    sum+=power2(2,w);
    //printf("%d\n",NUM);
    sum+=power2(2,koyaku(h,w));
    //printf("%ld\n",sum);
    return (sum-3)%NUM;}

  else{
    long int koyaht=koyaku(h,t);
    long int koyawt=koyaku(w,t);
    return (long int)power2(disco(h/koyaht,w/koyawt,1),koyaht*koyawt)%NUM;}
}

int main(){
  int h,w,t;
  scanf("%d%d%d",&h,&w,&t);
  long int sum=disco(h,w,t);
  printf("%ld\n",sum);
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll a[n];
    rp(i,n) cin >> a[i];
    sort(a,a+n);
    ll curNumb = -1;
    ll sum = 0;
    bool used = false;
    rp(i,n){
      if(curNumb == -1) {
        curNumb = a[i];
        sum++;
        used = true;
        continue;
      }
      if(a[i] != curNumb){
        curNumb = a[i];
        sum++;
        used = true;
        continue;
      }
      if(a[i] == curNumb){
        if(used){
          sum--;
          used = false;
          continue;
        } else {
          sum++;
          used = true;
          continue;
        }
      }
    }
    cout << sum << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

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

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

int main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0) {
		int ans = (a + b) / 2;
		cout << ans << endl;
		return 0;
	} else {
		string ans = "IMPOSSIBLE";
		cout << ans << endl;
		return 0;
	}
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    long double a,b;
    cin >> a >> b;
    ll ans = a * b;
    cout << ans << endl;
}

Measured memory_bytes: 3732
/**
 *    author:  [itmo] enot.1.10
 *    created: 25.02.2017 14:58:10       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 2e5 + 10;
const int mod = 1e9 + 7;


int a[N];


int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n;
    scanf("%d", &n);
    forn(i, n) scanf("%d", &a[i]);

    int bad = 0;
    int ok = 0;
    int res = 1;

    for (int i = 0; i < n; ++i)
    {
        int want = 2 * (i - bad) + 1;
        if (a[i] >= want)
        {
            ok++;
            continue;
        }
        bad++;
        res = (res * (ll)(ok + 1)) % mod;
    }
    for (int i = 1; i <= ok; ++i) res = (res * (ll)i) % mod;
    printf("%d\n", res);
        
            

    
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int table[365][26];
int main()
{	
	int D;
	cin >> D;
	vec(C);
	vec(Las);
	fx(26) {
		vecp(C);
		Las.push_back(0);
	}

	fx(D) {
		fy(26) {
			cin >> table[x][y];
		}
	}
	vector<int> T(D);
	int k = 0;
	fx(26) {
		if (k < table[0][x]) {
			T[0] = x+1;
			k = table[0][x];
		}
	}
	fx(D-1) {
		ll res = -LLONG_MAX;
		int las = 0;
		fy(26) {
			ll sum = 0;
			sum += table[x + 1][y];
			fz(26){
				if (y == z) { continue; }
				sum -= C[z] * (x + 1 - Las[z]);
			}

			if (res<sum) {
				res = sum;
				T[x + 1] = y+1;
				las = y;
			}
		}
		Las[las] = x + 1;
	}

	ll sum = -INT_MAX,sumPre=-INT_MAX;
	srand(time(NULL));
	fx(200000) {
		int d, q;
		d = rand() % D + 1;
		q = rand() % 26 + 1;
		if (sum==sumPre) {
			int d3 = rand() % 20;
			while (d3==0) {
				d3 = rand() % 20;
			}
			int sign = rand() % 2;
			int d2;
			if (sign==0) {
				d2 = min(d + d3,D);
			}
			else {
				d2 = max(d - d3,1);
			}
			T[d - 1] ^= T[d2 - 1];
			T[d2 - 1] ^= T[d - 1];
			T[d - 1] ^= T[d2 - 1];
		}
		int pre = T[d - 1];

		T[d - 1] = q;
		ll ans = 0;

		fy(26) {
			Las[y] = 0;
		}
		fw(D) {

			ans += table[w][T[w] - 1];
			Las[T[w] - 1] = w + 1;
			fz(26) {
				ans -= C[z] * (w + 1 - Las[z]);
			}

		}
		if (ans > sum) {
			sum = ans;
		}
		else {
			T[d - 1] = pre;
		}
	}


	fx(D) {
		ce(T[x])
	}
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int b;
    cin>>b;
    if (b==0)
      break;
    int bottom=1,top=1;
    int sum=1;
    while(true) {
      ++top;
      sum += top;
      if (sum==b) {
        cout<<bottom<<" "<<top-bottom+1<<endl;
        break;
      }
      if (sum>b) {
        while(sum>b) {
          sum-=bottom;
          ++bottom;
        }
        if (sum==b){
          cout<<bottom<<" "<<top-bottom+1<<endl;
          break;
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3116
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    left = 1
    right = N if N%2 == 0 else N-1
    count = 0
    if N%2 == 0:
        p = set()
        while count < M:
            if right-left == N//2 or N-(right-left) in p:
                left += 1
                continue
            print(left,right)
            p.add(right-left)
            left += 1
            right -= 1
            count += 1
    else:
        while count < M:
            print(left,right)
            left += 1
            right -= 1
            count += 1
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13376
import math
a, b, x = map(int, input().split())

if a ** 2 * b <= 2 * x:
    y = (a ** 2 * b - x) * 2 / a ** 3

    atany = math.degrees(math.atan(y))
    print(atany)
    
else:
    y = (a * b ** 2) / (2 * x)
    atany = math.degrees(math.atan(y))
    print(atany)
    


 

 


                                        




    




        


    







        



Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
int A,B;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int main(){
	cin >> A >> B;
	if(B == 1){
		printf("0\n");return 0;	
	}
	for(int i = 1;i <= 1000;++i){
		if(A + (i - 1) * (A - 1) >= B){
			return printf("%d\n",i) * 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char number[1001];
  while(1) {
    scanf("%s", number);
    if (number[0] == '0') {
      break;
    }
    
    int total = 0;
    for(int i = 0; number[i] != '\0'; i++) {
      total += number[i] - '0';
    }
    printf("%d\n", total);
  }
  return 0;
}


Measured memory_bytes: 2700
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	int N;
	cin >> N;
	vector <ll> a(N);

	// マイナスが偶数個のときは、全部プラスにできます。
	// マイナスが奇数個のときは、ゼロがあれば、全部プラスにできます。
	//                           ゼロがなければ、マイナスが1個残ります。一番小さいマイナスを残しましょう。

	ll sumAbs = 0;
	int numMinus = 0;
	ll minAbsMinus = BIGLL;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (a[i] <= 0)
		{
			numMinus++;
		}
		amin(minAbsMinus, abs(a[i]));

		sumAbs += abs(a[i]);
	}

	ll ret = 0;
	if (numMinus % 2 == 0)
	{
		ret = sumAbs;
	}
	else
	{
		ret = sumAbs - 2 * minAbsMinus;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    int a[N];

    int c[9] = {0};

    for(int i = 0; i < N; i++){
        scanf("%d", &a[i]);
        if(a[i] < 400){
            c[0]++;
        }else if(a[i] < 800){
            c[1]++;
        }else if(a[i] < 1200){
            c[2]++;
        }else if(a[i] < 1600){
            c[3]++;
        }else if(a[i] < 2000){
            c[4]++;
        }else if(a[i] < 2400){
            c[5]++;
        }else if(a[i] < 2800){
            c[6]++;
        }else if(a[i] < 3200){
            c[7]++;
        }else{
            c[8]++;
        }
    }

    int t = 0;

    for(int i = 0; i < 8; i++){
        if(c[i] > 0){
            t++;
        }
    }

    if(t == 0){
        printf("1 %d\n", c[8]);
    }else{
        printf("%d %d\n", t, t + c[8]);
    }

    return 0;
}

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

int main()
{
    int n; cin >> n;
    int cnt[n];
    for(int i=0; i<n; i++) cnt[i] = 0;
    int a;
    for(int i=0; i<n-1; i++){
        cin >> a;
        cnt[a-1]++;
    }

    for(int i=0; i<n; i++)
        cout << cnt[i] << endl;

    return 0;

}

Measured memory_bytes: 3948
// https://atcoder.jp/contests/abc065/tasks/abc065_d
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

struct UnionFind {
    vector<int> par; // 親の番号
    UnionFind(int size) : par(size, -1) {}
    // xとyの木を併合
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (par[y] < par[x])
                swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return true;
        } else {
            return false;
        }
    }
    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) { return root(x) == root(y); }
    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    // 頂点 v が属するグループと同じグループに属する頂点数を得る
    int size(int x) { return -par[root(x)]; }
};

struct edge {
    int from, to, cost;
    bool operator<(const edge &t) const { return cost < t.cost; };
};

int kruskal(int v, vector<edge> es) {
    sort(ALL(es));

    UnionFind uf(v);

    int res = 0;
    for (auto &e : es) {
        if (uf.unite(e.from, e.to)) {
            res += e.cost;
        }
    }

    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, y;
    cin >> n;
    vector<P> vx(n), vy(n);
    REP(i, n) {
        cin >> x >> y;
        vx[i] = {x - 1, i};
        vy[i] = {y - 1, i};
    }
    sort(ALL(vx));
    sort(ALL(vy));
    vector<edge> e;
    FOR(i, 1, n) {
        e.push_back(
            {vx[i].second, vx[i - 1].second, vx[i].first - vx[i - 1].first});
        e.push_back(
            {vy[i].second, vy[i - 1].second, vy[i].first - vy[i - 1].first});
    }
    cout << kruskal(n, e) << endl;
    return 0;
}

Measured memory_bytes: 7536
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
using namespace std;
int n,m;
int dp[100001],h[100001];
int cal(int i)
{
	if(dp[i]!=-1)
		return dp[i];
int p;
p=min(abs(h[i]-h[i+1])+cal(i+1),abs(h[i]-h[i+2])+cal(i+2));
dp[i]=p;
return p;
}
int main() 
{
	for(int i=0;i<100001;i++)
		dp[i]=-1;
	cin>>n;
	for0(i,n)cin>>h[i];
	dp[n-1]=0;
	dp[n-2]=abs(h[n-2]-h[n-1]);
	m=cal(0);
	cout<<m;
}


Measured memory_bytes: 3328
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[1000001];//動的計画法
int prime[1000001];
int main(){
    int hand[5];
    int gcnt,ccnt,pcnt;
    int ans[5];
    while(cin>>hand[0],hand[0]){
        gcnt=ccnt=pcnt=0;
        for(int i=1;i<5;i++){
            cin>>hand[i];
        }
        for(int i=0;i<5;i++){
            if(hand[i]==1) gcnt++;
            else if(hand[i]==2) ccnt++;
            else pcnt++;
        }
        if(gcnt>0&&ccnt>0&&pcnt>0){
            for(int i=0;i<5;i++){
                ans[i]=3;
                cout<<ans[i]<<endl;
            }
            continue;
        }else if(gcnt==5||ccnt==5||pcnt==5){
             for(int i=0;i<5;i++){
                ans[i]=3;
                cout<<ans[i]<<endl;
            }
            continue;
        }else{
            if(pcnt==0){
                for(int i=0;i<5;i++){
                    if(hand[i]==1) ans[i]=1;
                    else ans[i]=2;
                }
            }else if(gcnt==0){
                for(int i=0;i<5;i++){
                    if(hand[i]==2) ans[i]=1;
                    else ans[i]=2;
                }
            }else{
                for(int i=0;i<5;i++){
                    if(hand[i]==3) ans[i]=1;
                    else ans[i]=2;
                }
            }
            for(int i=0;i<5;i++){
                cout<<ans[i]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    vector<vector<int>> c(H, vector<int>(W));

    int k = 1;
    int count = 0;
    REP(i, H) REP(j, W){
        c[i][j] = k;
        count++;
        if (count >= a[k-1]) {
            k++;
            count = 0;
        }
    }
    REP(i, H){
        if (i % 2 == 0){
            REP(j, W) cout << c[i][j] << " ";
        }
        else for(int j = W-1; j >= 0; j--) cout << c[i][j] << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i) cin >> vec[i];
    sort(vec.begin(), vec.end());
 
    int ans = 0;
 
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                if (vec[k] != vec[j] and vec[i] != vec[j] and vec[k]!=vec[i] and
                    vec[k] + vec[j] > vec[i]) {
                    ans++;
                }
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		b,c,d,w,h,i,j,k,l,m,n,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> n;
	vector<ll>	a(n);
	for(i=0;i<n;i++) cin >> a[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	m = a[0];
	for(i=1;i<n;i++) {
		if (m<a[i]) m = a[i];
		else ans += m - a[i];
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int n;
	int a,b,c,d;

	cin >> n;

	a = n/1000;
	b = (n/100)%10;
	c = (n/10)%10;
	d = n%10;

	if( (a==b && b==c) || (b==c && c==d) ){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<string.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define INF 1000000007
#define ull unsigned long long
#define PI 3.141592653589793238
#define pb push_back
#define max3(x, y, z) Max(x, Max(y, z))
#define min3(x, y, z) Min(x, Min(y, z))
#define mp make_pair
#define pre(a,b) cout << fixed << setprecision(a) << b  //a for precision b for answer
#define MAX 1e18
#define all(x) (x).begin(), (x).end()
#define lb lower_bound //lower_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘x’.
#define ub upper_bound //upper_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘x’.
#define maxe *max_element
#define mine *min_element
#define acc(x) accumulate(x.begin(), x.end(), 0)
#define dst distance
#define sz(x) (int)x.size()

template <typename T>
inline T const& Max (T const& a, T const& b)
{ 
	return a < b ? b:a; 
}

template <typename T>
inline T const& Min (T const& a, T const& b) { 
   return a < b ? a:b; 
}

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}

ll SieveOfEratosthenes(int n) 
{  
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    {  
        if (prime[p] == true) 
        {   
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    /*for (int p=2; p<=n; p++) 
       if (prime[p]) 
          cout << p << " "; */
    return prime[n + 1];
}

int main()
{
	IOS;
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }	
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using graph = vector<vector<int>>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    ll ls, lt, m, tmp;
    m = 0;
    cin >> s >> t;
    ls = s.length();
    lt = t.length();
    
    FOR(i, 0, ls - lt){
        tmp = 0;
        REP(j, lt){
            if(s[i+j] == t[j]){
                tmp ++;
            }
        }
        m = max(m, tmp);
    }
    

    cout << lt - m <<"\n";
	return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h+2, vector<char>(w+2));
    rep(i, h){
        rep(j, w){
            cin >> s.at(i+1).at(j+1);
        }
    }
    string ans = "Yes";
    rep(i, h){
        rep(j, w){
            if(s.at(i+1).at(j+1) == '.') continue;
            if(!(s.at(i).at(j+1) == '#'||s.at(i+2).at(j+1) == '#'||
                s.at(i+1).at(j) == '#'||s.at(i+1).at(j+2) == '#')){
                ans = "No";
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n,a,b,c,d;
      cin >> n;
      a=n-n%1000;
      b=n-a-n%100;
      c=n-a-b-n%10;
      d=n-a-b-c;
      bool flug=false;
      if(a/1000==b/100 && b/100==c/10)flug=true;
      if(b/100==c/10&&c/10==d)flug=true;
      if(flug){
        cout << "Yes"<<endl;
      }else{
        cout << "No" << endl;
      }
    }

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	/**
	 * @param args
	 */
	static int sum_A, sum_B, infomation, math, science, English;
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		read();
		slove();
	}
	static boolean read(){
		infomation = sc.nextInt();
		math = sc.nextInt();
		science = sc.nextInt();
		English = sc.nextInt();
		
		sum_A = infomation+math+science+English;

		infomation = sc.nextInt();
		math = sc.nextInt();
		science = sc.nextInt();
		English = sc.nextInt();

		sum_B = infomation+math+science+English;
		
		return true;
	}
	static void slove(){
		int max = Math.max(sum_A, sum_B);
		System.out.println(max);
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <regex>
using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    
    if(regex_match(S, regex("(dream|dreamer|erase|eraser)*"))) cout << "YES" <<endl;
    else cout<<"NO"<<endl;

}



Measured memory_bytes: 39808
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    while(cin>>n&&n){
        vector<int> a(n);
        rep(i,n)cin>>a[i];
        
        map<int,int> mp;
        rep(i,a.size()){
            mp[a[i]]++;
        }
        
        int color = -1;
        for(auto e:mp){
            if(2*e.second>n){
                color = e.first;
            }
        }
        if(color==-1)cout<<"NO COLOR"<<endl;
        else cout<<color<<endl;
    }
}

Measured memory_bytes: 9452
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b+c >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}

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


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

    if (a >= 1 && a <= 9 && b >= 1 && b <= 9){
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }

}



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


int cnt;

void dfs(string S,long long N)
{

    if(S.find('3')!=string::npos && S.find('5')!=string::npos && S.find('7')!=string::npos && stoll(S)<=N){
      cnt++;
    }

    if(S.size()!=0){
    if(stoll(S)>N)
    {
        return;
    }}

    for(char c='3';c<='7';c+=2){
      dfs(S+c,N);
    }
    return;
}
int main()
{
    long long N;
    cin >> N;
    dfs("",N);
    cout<<cnt<<endl;

    return 0;
}


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

int main()
{
  ll n,ans=1,m=1e7;
  cin>>n;
  ll a;
  for(ll i=0;i<n;i++){
  cin>>a;
    if(i)if(a<m)ans++;
    m=min(a,m);
  }
  cout<<ans;
  
 
  
  
  
  
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
A = sorted(LI(), reverse=True)
max_num = 10 ** 5 * 2 + 1
D = [0] * max_num
acc = [0] + A
for i in range(1, n):
    acc[i + 1] += acc[i]

for i in A:
    D[i] += 1

for i in range(max_num - 1, 0, -1):
    D[i - 1] += D[i]

ok = 1
ng = max(A) * 2 + 1
while ng > ok + 1:
    mid = (ng + ok) // 2
    ret = 0
    happiness = 0
    for i in range(n):
        d = D[max(mid - A[i], 0)]
        ret += d
    if ret >= m:
        ok = mid
    else:
        ng = mid


ret2 = 0
ans = 0
for i in range(n):
    d2 = D[max(ng - A[i], 0)]
    ret2 += d2
    ans = ans + d2 * A[i] + acc[d2]

ans += (m - ret2) * ok
print(ans)





Measured memory_bytes: 55640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int Max = 0;
  int Min = 1000;
  int a;
  for (int i = 0; i < N; i++){
    cin >> a;
    Max = max(Max,a);
    Min = min(Min,a);
  }
  cout << Max - Min;
}

Measured memory_bytes: 256
(let ((lst (loop :for a :from 1 :upto (read) :collect (parse-integer (format nil "~B" a))))
      (ans -1))
  (mapcar (lambda (n)
            (if (= 0 (mod n (expt 2 ans)))
                (incf ans))) lst)
  (princ (expt 2 ans)))

Measured memory_bytes: 6504
N, *rest = $stdin.read.split.map(&:to_i)
class Section < Struct.new(:start, :len, :velo)
  def end
    start + len
  end
end
start = 0
SECTIONS = rest.first(N).zip(rest.last(N)).map{|t, v|
  Section.new(start, t, v).tap{ start += t }
}
SECTIONS.unshift(Section.new(0, 0, 0))
total_time = SECTIONS.map(&:len).inject(:+)
SECTIONS.push(Section.new(total_time, 0, 0))

def min_v(t)
  SECTIONS.map{|s|
    case
    when t <= s.start
      s.velo + (s.start - t)
    when s.start < t && t <= s.end
      s.velo
    else
      s.velo + (t - s.end)
    end
  }.min
end

ans = 0
prev_min_v = min_v(0)
0.step(total_time-0.5, 0.5) do |t|
  curr_min_v = min_v(t+0.5)
  ans += 0.25 * (prev_min_v + curr_min_v)
  prev_min_v = curr_min_v
end
p ans



Measured memory_bytes: 5016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main(){
  int N;cin>>N;
  vi C, V;
  for (int i=0;i<N;++i){
    int v;cin >>v;
    V.push_back(v);
  }
  for (int i=0;i<N;++i){
    int c;cin >>c;
    C.push_back(c);
  }

  int ans=0;

  for (int i=0;i<N;++i){
    if(V[i]-C[i]>0){ans+=V[i]-C[i];}
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<ll, int>> a(n);
  rep(i, n) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  vector<vector<ll>> dp(n+1, vector<ll>(n+1));
  for (int len = n; len > 0; len--) {
    for (int l = 0; l+len <= n; l++) {
      int r = l+len;
      int i = n-len;
      chmax(dp[l+1][r], dp[l][r]+a[i].first*abs(a[i].second-l));
      chmax(dp[l][r-1], dp[l][r]+a[i].first*abs(a[i].second-(r-1)));
    }
  }
  ll ans = 0;
  rep(i, n+1)
    chmax(ans, dp[i][i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 34608
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;

bitset<40> f(long long x){
	bitset<40> bt(0);
	if(x%4==0){bt^=x;}
	if(x%4==1){bt^=x;bt^=x-1;}
	if(x%4==2){bt^=x;bt^=x-1;bt^=x-2;}
	if(x%4==3){bt^=x;bt^=x-1;bt^=x-2;bt^=x-3;}

	return bt;
}

int main(){
	long long a,b;cin>>a>>b;
	int A,B;
	bitset<40> bt;
	if(a==0)bt=f(b);
	else bt= f(b)^f(a-1);
	cout<<bt.to_ullong()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)

int main(void){
    ll X, Y, K;
    cin >> X >> Y >> K;
    modint res = 0;
    rep(dx,X){
        res += modint(dx) * modint(X-dx) * modint(Y*Y);
    }
    rep(dy,Y){
        res += modint(dy) * modint(Y-dy) * modint(X*X);
    }
    cout << res * modint::C(X*Y-2, K-2) << endl;
    return 0;
}


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

const int N = 2005;

int n, head[N], tot, ret, dp[N];
int size[N], sum[N], ans = 0x3f3f3f3f;

std::string s;

struct edge { int to, nxt; } e[N << 1];
void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}

void dfs(int x, int f = 0) {
	int M = 0;
	size[x] = s[x] == '1', sum[x] = 0, dp[x] = 0;
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f) {
		dfs(e[i].to, x);
		sum[x] += sum[e[i].to] += size[e[i].to];
		size[x] += size[e[i].to];
		dp[e[i].to] += size[e[i].to];
		if (dp[e[i].to] > dp[M]) M = e[i].to;
	}
	if (dp[M] <= sum[x] - sum[M]) dp[x] = sum[x] & 1;
	else dp[x] = dp[M] - (sum[x] - sum[M]);
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> s, s = '#' + s;
	for (int i = 1, x, y; i < n; ++i)
		std::cin >> x >> y, link(x, y);
	for (int i = 1; i <= n; ++i) {
		ret = 0, dfs(i);
		if (!dp[i]) ans = std::min(ans, sum[i] / 2);
	}
	if (ans == 0x3f3f3f3f)
		std::cout << -1 << '\n';
	else
		std::cout << ans << '\n'; 
	return 0;
}

Measured memory_bytes: 384