akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int MAX(int a,int b){return a<b?b:a;}
double f(int a,int b,int c,int d){//printf("%d %d %d %d\n",a,b,c,d);
  int i=abs(c-d);
  double s=(c+d)*i/2.0,m=b;
  a-=i;
  c=MAX(c,d);//printf("%f %d\n",s,c);
  if(c+a/2.0<m)m=c+a/2.0;//printf("%f\n",m);
  m-=c;//printf("%f\n",m);
  s+=m*m+c*(2*m);//printf("s%f\n",s);
  s+=b*(a-m*2);//printf("s%f\n",s);
  return s;
}    
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,a[110],b[110],c[110],i,s=0;
  double ans=0;
  scanf("%d",&n);
  a[0]=b[0]=a[n+1]=b[n+1]=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i+1]);
    s+=a[i+1];
  }
  for(i=0;i<n;i++)scanf("%d",&b[i+1]);
  c[0]=0;
  for(i=1;i<=n;i++)c[i]=MIN(c[i-1]+a[i],MIN(b[i],b[i+1]));
  c[n]=0;
  for(i=n;i--;i)c[i]=MIN(c[i+1]+a[i+1],MIN(b[i],c[i]));
  //for(i=0;i<n;i++)printf("%d %d %d\n",a[i+1],b[i+1],c[i+1]);
  for(i=0;i<n;i++)ans+=f(a[i+1],b[i+1],c[i],c[i+1]);
  printf("%lf\n",ans);
  return 0;
}


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

int main(){
    int N, K;  cin >> N >> K;
    string S;  cin >> S;
    vector<int> a;
    a.push_back(0);
    for(int i=0; i<N;){
        int cnt = 0;
        if(S[i]=='0'){
            while(i<N && S[i]=='0'){
                i++;
                cnt--;
            }
        }else if(S[i]=='1'){
            while(i<N && S[i]=='1'){
                i++;
                cnt++;
            }
        }
        a.push_back(cnt);
    }
    int n = a.size();

    vector<int> nNeg(n,0);
    for(int i=0; i<n; i++){
        if(a[i]<0) nNeg[i]++;
        if(i>0) nNeg[i] += nNeg[i-1];
    }
    nNeg.push_back(1e9);
    vector<int> suma(n,0);
    for(int i=0; i<n; i++){
        suma[i] = abs(a[i]);
        suma[i] += suma[i-1];
    }
    // for(int i=0; i<n; i++){
    //     cout << a[i] << " ";
    // }cout << endl;
    // for(int i=0; i<n; i++){
    //     cout << nNeg[i] << " ";
    // }cout << endl;

    int ans = 0;
    for(int start=1; start<n; start++){
        int end = upper_bound(nNeg.begin(), nNeg.end(), K + nNeg[start-1]) - nNeg.begin() - 1;
        ans = max(ans, suma[end]-suma[start-1]);
        // cout << start << " " << end << " " << suma[end]-suma[start-1] << endl;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1660
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, H;
  cin >> N >> H;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  int64_t max_a = INT64_MIN;
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
    if (A[i] > max_a) {
      max_a = A[i];
    }
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  int64_t sum_b = 0;
  for (int64_t i = 0; i < N; ++i) {
    if (B[i] > max_a) {
      sum_b += B[i];
    } else {
      break;
    }
  }
  int64_t result = 0;
  if (H > sum_b) {
    const int64_t count_a = (H - sum_b + (max_a - 1)) / max_a;
    result += count_a;
    H -= count_a * max_a;
  }
  for (int64_t i = 0; i < N; ++i) {
    if (H <= 0) {
      break;
    }
    H -= B[i];
    ++result;
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
#define ll long long int


int main() {
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int a_x = x2 - x1;
  int a_y = y2 - y1;

  cout << x2 - a_y << " " << y2 + a_x << " ";
  cout << x1 - a_y << " " << y1 + a_x << endl;  
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

vector<int> V,C;
int dp[1007][5000];

int main(){
    int N,M,a,b,c,j;
    cin >> N >> M;
    rep(i,M){
        cin >> a >> b;
        ll key=0;
        rep(j,b){
            cin >> c ;
            key+=pow(2,c-1);
        }
        C.pb(a);
        V.pb(key);
    }
    rep(i,M+1){
        rep(j,1<<N){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    rep(i,M){
        rep(bit,1<<N){
            if(dp[i][bit]!=INF){
                dp[i+1][bit]=min(dp[i][bit],dp[i+1][bit]);
                j=V[i]|bit;
                dp[i+1][j]=min(dp[i+1][j],dp[i][bit]+C[i]);
            }
        }
    }
    if(dp[M][(1<<N)-1]==INF){
        cout << -1 << endl;
    }
    else{
        cout << dp[M][(1<<N)-1] << endl;
    }
}

Measured memory_bytes: 19840
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{
int n,W; 
cin>>n>>W;
vector<int>v(n),w(n);
vector<long long int> first(W+1,0);
for(int i=0; i<n; i++) cin>>w[i]>>v[i];
for(int i=0; i<n; i++){ for(int k=W; k>=w[i]; k--) first[k]=max(first[k-w[i]]+v[i],first[k]); 
                      }//DEBUG: for(int i=0; i<=n; i++){ for(int k=0; k<=W; k++) cout<<dp[i][k]<<" "; cout<<endl; }
cout<<first[W];
return 0; 
} 


Measured memory_bytes: 1024
# include <stdio.h>


int y[100], m[100], d[100], out[100]={0,};


void input(int n){
	scanf("%d%d%d", &y[n], &m[n], &d[n]);
}

void output(int n){
	printf("%d\n", out[n]);
}

int main(void){

	int n, i, num;
	int year, month, day;

	scanf("%d", &n);

	for(i=0; i<n; i++){
		input(i);
	}

	for(i=0; i<n; i++){

		if(y[i] % 3 == 0){
			num = 20;
		}
		else if(m[i] % 2 == 0){
			num = 19;
		}else{
			num = 20;
		}
		out[i] += (num - d[i] + 1);
		m[i] += 1;
		for(year=y[i]; year<1000; year++){
			if(year == y[i])
				month = m[i];
			else
				month = 1;
			for(; month<=10; month++){
				if(year % 3 == 0){
					num = 20;
				}else if(month % 2 == 0){
					num = 19;
				}else{
					num = 20;
				}
				out[i] += num;
			}
		}
	}




	for(i=0; i<n; i++){
		output(i);
	}

	return 0;
}

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

int solve_testcase() {
    int N, M; cin >> N >> M;
    if(N == 0 and M == 0) return 1;

    vector<int> D(N), V(N);
    vector<int> ma(M + 1);
    for(int i=0; i<N; i++) {
        cin >> D[i] >> V[i];
        ma[ D[i] ] = max(ma[ D[i] ], V[i]);
    }

    cout << accumulate(ma.begin(), ma.end(), 0) << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3080
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        l: f64
    }

    let mut ans = 0;

    println!("{}", (l / 3.0).powf(3.0));
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
def find_match(a):
    for i in range(len(a) - 1):
        if a[i] == a[-1]:
            return len(a)
    return None


s = int(input())
a = [s]
i = 1
ans = 1000000
while(True):
    if a[-1] % 2 == 0:
        a.append(a[-1] // 2)
    else:
        a.append(3 * a[-1] + 1)
    x = find_match(a)
    if x is not None:
        if ans < x:
            break
        ans = x
print(ans)


Measured memory_bytes: 3064
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll mod = 1e9 + 7;
ll cnt[(ll)1e5 + 10] = { 3 };

int main() {
    ll N;
    cin >> N;
    V<ll> A(N);
    for(auto &&ele : A) cin >> ele;
    ll ans = 1;
    for(ll i = 0; i < N; i++) {
        ll tmp = cnt[A[i]];
        (ans *= tmp) %= mod;
        cnt[A[i]]--;
        cnt[A[i] + 1]++;
    }

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


Measured memory_bytes: 1792
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
s = 0
for a in A:
    s ^= a
B = [s^a for a in A]
print(*B)


Measured memory_bytes: 119128
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n,t;
  cin>>n>>t;
  if((n-t)>0){
  cout<<(n-t);
  }else{
    cout<<'0';
  }
    return 0;
}


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

int main() {
  
  // 調理時間の配列を作る
  vector<int> cook(5);
  for (int i = 0; i < 5; i++) {
    cin >> cook.at(i);
  }
  
  // 料理が届いてから注文するまでの時間の配列を作る
  vector<int> interval(5);
  for (int i = 0; i < 5; i++) {
    if (cook.at(i) % 10 == 0) {
      interval.at(i) = 0;
    }
    else {
      interval.at(i) = 10 - cook.at(i) % 10;
    }
  }
  
  // 最後の料理を決める
  int last = 0; // 最後の料理
  for (int i = 1; i < 5; i++) {
    if (interval.at(last) < interval.at(i)) {
      last = i;
    }
  }
  
  // 最後の料理のintervalを0にする
  interval.at(last) = 0;
  
  // 最後の料理が届く時刻を求める
  int time; // 最後の料理が届く時刻
  for (int i = 0; i < 5; i++) {
    time += cook.at(i) + interval.at(i);
  }
  
  cout << time << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> P(M);
  vector<string> S(M);
  vector<bool> done(N);
  vector<int> penalty(N);
  int ac = 0, pena = 0;
  rep(i, M) {
    cin >> P[i] >> S[i]; P[i]--;
    if(S[i] == "WA" && !done[P[i]]) penalty[P[i]]++;
    else if(S[i] == "AC" && !done[P[i]]) {
      ac++;
      done[P[i]] = true;
    }
  }
  rep(i, N) if(done[i]) pena += penalty[i];
  cout << ac << ' ' << pena << "\n";
  return 0;
}


Measured memory_bytes: 7080
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)
    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)
    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x


N,Q = MI()
UF = UnionFind(N)
for _ in range(Q):
    t,u,v = MI()
    if t == 0:
        UF.unite(u,v)
    else:
        print(1 if UF.same_check(u,v) else 0)


Measured memory_bytes: 82260
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn read_int_tuple() -> (i32, i32) {
    let v = read_vec();
    (v[0], v[1])
}

fn main() {
    let (mut L, mut R) = read_int_tuple();
    if L / 2019 != R / 2019 {
        println!("0");
        return;
    }
    L %= 2019;
    R %= 2019;
    let mut ans = 2019;
    for i in L..R {
        for j in i+1..R+1 {
            ans = std::cmp::min(ans, (i*j)%2019);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
  	vector<int> B(N-1);
//    cout << N << endl;
    for (int i = 0; i < N -1; i++) {
        cin >> B[i];
//      	cout << B[i]; cout << ' ';
    }
//    cout << endl;
    int ans = B[0];
    for (int i = 1; i < N-1; i++) {
        ans += min(B[i-1],B[i]);
//        cout << ans; cout << ' ';
    }
//    cout << endl;
    ans+=B[(N-1)-1];
    cout << ans;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
#define p 1000000007
using namespace std;
inline ll read(){
    ll x = 0; char zf = 1; char ch = getchar();
    while (ch != '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int i,j,k,m,n,x,y,z,cnt,sum;
int a[1000010],f[1000010],la[1001000],s[1000010];
int main(){
	n=r;for(rt i=1;i<=n;i++){
		a[i]=r;
		if(a[i]==a[i-1])n--,i--;
	}
	f[0]=s[0]=1;
	for(rt i=1;i<=n;i++){
		if(la[a[i]])f[i]=s[la[a[i]]];
		la[a[i]]=i;s[i]=(s[i-1]+f[i])%p;
	}
	cout<<s[n];
    return 0;
}








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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin>>n>>s;
    int red[4010]{}; int green[4010]{}; int blue[4010]{};
    long long int sum =0;
    for(int i=0;i<n;i++)

    {
        if(s[i]=='R')
        {
            red[i]++;
        }
        if(s[i]=='G')
        {
            green[i]++;
        }
        if(s[i]=='B')
        {
            blue[i]++;
        }
        if(i>0)
        {
            red[i]=red[i]+red[i-1];
            green[i]=green[i]+green[i-1];
            blue[i]=blue[i]+blue[i-1];
        }
    }

        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(s[i]=='R'&&s[j]=='G' || s[i]=='G'&&s[j]=='R')
                {
                    long long int x = blue[n-1]-blue[j-1];
                    sum = sum + x;
                    if(j+j-i<n && s[j+j-i]=='B')
                    {
                        sum--;
                    }
                }
            if(s[i]=='R'&&s[j]=='B' || s[i]=='B'&&s[j]=='R')
                {
                    long long int x = green[n-1]-green[j-1];
                    sum = sum + x;
                    if(j+j-i<n && s[j+j-i]=='G')
                    {
                        sum--;
                    }
                }
                if(s[i]=='B'&&s[j]=='G' || s[i]=='G'&&s[j]=='B')
                {
                    long long int x = red[n-1]-red[j-1];
                    sum = sum + x;
                    if(j+j-i<n && s[j+j-i]=='R')
                    {
                        sum--;
                    }
                }
            }
        }
        cout<<sum<<endl;

    }


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

using namespace std;

int main()
{
    long long int a,b,c,d,c1=0,c2=0;
    cin>>a>>b>>c>>d;
    while(a>0)
    {
        a=a-d;
        c1++;
    }
    while(c>0)
    {
        c=c-b;
        c2++;
    }
    if(c1>=c2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10**9)

def neighbor(a):
    if a == 0:
        return [0,1]
    if a == 9:
        return [8,9]
    return [a-1,a,a+1]

def make_lunlun(digit, start):
    if digit == 1:
        return [start]
    res = []
    for start_neighbor in neighbor(start):
        b = make_lunlun(digit-1, start_neighbor)
        c = list(map(lambda x:x+(start*(10**(digit-1))), b))
        res.extend(c)
    return res
lunlun = []
for i in range(1,11):
    for j in range(1,10):
        lunlun.extend(make_lunlun(i, j))

k = int(input())
print(lunlun[k-1])


Measured memory_bytes: 79068
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
      int n = sc.nextInt();
      int[] x = new int[n];
      int[] y = new int[n];
      IntStream.range(0, n).forEachOrdered(num -> x[num] = sc.nextInt());
      IntStream.range(0, n).forEachOrdered(num -> y[num] = sc.nextInt());

      IntStream.rangeClosed(1, 3)
          .forEachOrdered(num -> System.out.println(calcDistance(x, y, num)));
      System.out.println(calcDistance(x, y, Integer.MAX_VALUE));
      
    }
  }
 
  public static double calcDistance(int[] x, int[] y, int p) {
    double tmp = 0.0;
    for (int i = 0; i < x.length; i++) {
      double abs = Math.abs(x[i] - y[i]);
      tmp = (p == Integer.MAX_VALUE) ? Math.max(abs, tmp) : tmp + Math.pow(abs, p);
    }
    return (p == Integer.MAX_VALUE) ? tmp : Math.pow(tmp, 1.0 / (double) p);
  }

}


Measured memory_bytes: 32392
import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
        for (int i = Math.min(a, b), count = 0; i >= 1 ; i--) {
            if (a % i == 0 && b % i == 0) count++;
            if (count == k) {
                System.out.println(i);
                break;
            }
        }
    }
}


Measured memory_bytes: 22996
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
int n,k;
int max_p( vector<int> const & v){

  int product = 1;
  for(int i = 0;i < k;i++){
    product *= v[i];
  }
  int max_product = product;
  for(int i = k,tail = 0;i < n;i++,tail++){
    product /= v[tail];
    product *= v[i];
    max_product = max(max_product,product);
  }
  return max_product;
}

int main(){
  ios::sync_with_stdio(false);
  while(cin >> n >> k && n + k > 0){
    vector<int> input;    
    for(int i = 0;i < n; ++i){
      int x;
      cin >> x;
      input.push_back(x);
    }
    int sensei = max_p(input);
    int maxi = 0;
    for(int i = 0;i < n;i++){
      for(int j = i+1;j < n;j++){
	swap(input[i],input[j]);
	maxi = max(maxi,max_p(input));
	swap(input[i],input[j]);
      }
    }
    if(maxi - sensei >= 0)cout << maxi - sensei << endl;
    else cout << "NO GAME" << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

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)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main(){
	ll N;
	cin >>  N;
	vector<ll> a(N);
	vector<ll> b(N);
	rep(i,N) scanf("%d",&a[i]);
	rep(i,N) scanf("%d",&b[i]);
	ll tmp=0;
	rep(i,N){
		if(a[i]>b[i]){
			tmp += a[i]-b[i];
		}
		else{
			tmp -= (b[i]-a[i])/2;
		}
	}
	if(tmp<=0) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int MOD = 1000000007;
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        for (int i = 1; i <= k; i++) {
            if (n-k+1 < i) {
                System.out.println(0);
                continue;
            }
            System.out.println(nCkMOD(n-k+1, i, MOD) * nCkMOD(k-1, i-1, MOD) % MOD);
        }
    }
    
    public static long nCkMOD(long n, long k, long mod) {
        if (k > n - k) return nCkMOD(n, n - k, mod);
    
        long res = 1;
        for (int i = 0; i < k; i++) {
            res = (res * (n - i)) % mod;
        }
        for (int i = 1; i <= k; i++) {
            res = (res * inverse(i, mod)) % mod;
        }
    
        return res % mod;
    }
    
    private static long inverse(long a, long mod) {
        return modpow(a, mod - 2, mod);
    }
    
    private static long modpow(long a, long n, long mod) {
        long res = 1;
    
        while (n > 0) {
            if (n % 2 == 1) res = (res * a) % mod;
            a = (a * a) % mod;
            n >>= 1;
        }
    
        return res % mod;
    }
}


Measured memory_bytes: 23764
use whiteread::parse_line;

fn main() {
    let _n: usize = parse_line().unwrap();
    let t: Vec<isize> = parse_line().unwrap();
    let m: usize = parse_line().unwrap();

    let sum: isize = t.iter().sum();
    for _ in 0..m {
        let (p, x): (usize, isize) = parse_line().unwrap();
        let diff = t[p - 1] - x;
        println!("{}", sum - diff);
    }
}


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

const int INF = 1e8;

int main(){
  int N,T;
  cin >> N >> T;
  int res = INF;
  for(int i = 0 ; i < N ; i++){
    int c,t;
    cin >> c >> t;
    if(t > T){
      continue;
    }
    res = min(res,c);
  }
  if(res == INF){
    cout << "TLE" << endl;
  }
  else {
    cout << res << endl;
  }
  return 0;
}


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

int main () {
  int N;
  cin >> N;
  
  vector<int>a(N);
  vector<int>b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  
  if (N == 2){
    cout << max(a.at(0),a.at(1)) << ' ' << min(a.at(0),a.at(1)) << endl;
    return 0;
  }
  
  sort(a.begin(), a.end());
  for (int i = 0; i < N-1; i++) {
    a.at(i) = min(a.at(N-1)-a.at(i),a.at(i));
  }
  cout << a.at(N-1) << ' ';
  int A = a.at(N-1);
  a.at(N-1) = 0;
  sort(a.begin(), a.end());
  
  for (int i = 0; i < N; i++) {
    if (a.at(N-1) == b.at(i) || a.at(N-1) + b.at(i) == A){
      cout << b.at(i) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 4052
x1, y1, x2, y2 = map(int, input().split())

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx

x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4)

Measured memory_bytes: 9084
#include<bits/stdc++.h> 
using namespace std;
 int main() { 
   string s, t; 
   cin >> s >> t; 
   int ans = 0; 
   if(s[0] == t[0]) ans++; 
   if(s[1] == t[1]) ans++; 
   if(s[2] == t[2]) ans++; 
   cout << ans << endl; 
   return 0; 
 }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        int lenB = 0;
        long copyB = b;
        while (copyB > 0) {
            lenB++;
            copyB /= 2;
        }
        int [] resB = new int[lenB];
        int [] resA = new int[lenB];
        check(a - 1, resA, lenB);
        check(b, resB, lenB);
        int [] res = new int[lenB];
        for (int i = 0; i < lenB; ++i) {
            res[i] = (resA[i] == resB[i]) ? 0 : 1;
        }
        long answer = 0;
        for (int i = 0; i < lenB; ++i) {
          // System.out.println("res[" + i + "]: " + res[i]);
            answer += Math.pow(2, i) * res[i];
        }
        System.out.println(answer);

    }

    // 0 ... xor value
    public static void check(long value, int[] res, int lenB) {
        long num = value + 1L;
        for (int i = 0; i < lenB; ++i) {
            long len = (long) Math.pow(2, i);
            long t1 = num / len;
            long mod = num % len;
            long zeroPack =
                    (t1 % 2 == 0) ? t1 / 2 : (t1 / 2 + 1);
            long onePack = t1 / 2;
            long oneNum = onePack * len;
            if (t1 % 2 == 1) {
                oneNum += mod;
            }
         //   System.out.println("t1: "+ t1);
            if (oneNum % 2 == 1) {
                res[i] = 1;
            } else {
                res[i] = 0;
            }
         //   System.out.println("bit: " + i + " oneNum: " + oneNum);
        }
//        System.out.println("value: " + value);
//        for (int i = lenB - 1; i >= 0; --i) {
//            System.out.print(res[i]);
//        }
//        System.out.println();

    }
    }


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	int p[n],q[m];
	for(int i=0;i<n;i++) cin>>p[i];
	for(int i=0;i<m;i++) cin>>q[i];
	sort(p,p+n);sort(q,q+m);
	if(max(p[n-1],a)<min(q[0],b)) cout<<"No War";
	else cout<<"War";
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
lis = []
for i in p:
    lis.append((i+1)/2)
sum = [0]
for l in lis:
    sum.append(sum[-1] + l)
ans = 0
for i in range(n-k+1):
    ans = max(sum[k+i] - sum[i], ans)
print(ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	string s;
	cin>>s;
	bool f=false;
	if(s[0]=='o' && s[s.size()-1]=='o') f=true;
	int cnt=0;
	rep(i,1,s.size()){
		if(s[i]!=s[i-1]) cnt++;
	}
	if((cnt%2 && !f) || (cnt%2==0 && f)) cout<<'o'<<endl;
	else cout<<'x'<<endl;
}

Measured memory_bytes: 1172
c=[]
for _ in range(3):
  c.append( list(map(int,input().split())))
 
ans = "Yes"
a=[c[0][0],c[1][0],c[2][0]]
b=[c[0][0]-a[0],c[0][1]-a[0],c[0][2]-a[0]]
for i in range(3):
    for j in range(3):
        if c[i][j] != a[i]+b[j]:
            ans = "No"
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N, M; cin >> N >> M;
  vector<int> pena(N, 0);
  vector<bool> isPassed(N, false);
  const string AC = "AC";
  const string WA = "WA";
  for (int i = 0; i < M; ++i) {
    int p; cin >> p;
    --p;
    string s; cin >> s;
    if (s == AC) {
      isPassed[p] = true;
    }
    if (s == WA) {
      if (!isPassed[p]) {
        pena[p] += 1;
      }
    }
  }
  int sumPass{};
  int sumPena{};
  for (int i = 0; i < N; ++i) {
    if (isPassed[i]) {
      ++sumPass;
      sumPena += pena[i];
    }
  }
  cout << sumPass << SPACE << sumPena << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#define INF 2100000000
#define ll long long
#define clr(x) memset(x,0,sizeof(x))


using namespace std;

const int maxn = 100005;
int R,C,N;

struct point {
	int x,y,num;
	void read() { scanf("%d%d",&x,&y); }
	bool onedge() {
		if(!x || !y || x == R || y == C) return true;
		else return false;
	}
	int typ() const {
		if(x == 0) return 1;
		else if(y == 0) return 2;
		else if(x == R) return 3;
		else return 4;
	}
	bool operator < (const point &B) const {
		int t1 = typ(), t2 = B.typ();
		if(t1 != t2) return t1<t2;
		else if(t1 == 1) return y > B.y;
		else if(t1 == 2) return x < B.x;
		else if(t1 == 3) return y < B.y;
		else return x > B.x;
	}
}P[maxn][2];
point P2[maxn<<1];
int tot,top;
int stk[maxn<<1];

int main() {
	scanf("%d%d%d",&R,&C,&N);
	for(register int i = 1; i <= N; i++) {
		P[i][0].read(); P[i][1].read(); P[i][0].num = P[i][1].num = i;
		if((P[i][0].onedge()) && (P[i][1].onedge()))
			P2[++tot] = P[i][0], P2[++tot] = P[i][1];
	}
	sort(P2+1, P2+tot+1);
	for(register int i = 1; i <= tot; i++) {
		if(top && stk[top-1] == P2[i].num) top--;
		else stk[top++] = P2[i].num;
	}
	printf(top ? "NO\n" : "YES\n");
	return 0;
}



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  string s = to_string(n);

  function<void(set<string>&, ll, string, vector<bool>)> solve;
  solve = [&](set<string> &ans, ll i, string v, vector<bool> seen){
    if (seen[0] && seen[1] && seen[2]) {
      if (atoi(v.c_str()) <= n) ans.insert(v);
    }
    if (i == s.size()) return;

    for (ll j = 3; j <= 7; j+=2) {
      auto next_seen = seen;
      if (j == 3) next_seen[0] = true;
      if (j == 5) next_seen[1] = true;
      if (j == 7) next_seen[2] = true;
      solve(ans, i+1, to_string(j)+v, next_seen);
    }
  };

  set<string> ans;
  vector<bool> seen(3);
  solve(ans, 0, "", seen);

  cout << ans.size() << endl;

  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    int a = t%10;
    if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
        cout<<"hon\n";
    else if (a == 0 || a==1 || a==6||a==8)
        cout << "pon\n";
    else  cout << "bon\n";
}


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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back

const int N = 1e5+5;
int a[N],dp[N];

int32_t main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	dp[1] = 0;
	dp[2] = abs(a[2]-a[1]);

	for(int i=3;i<=n;i++)
	{
		dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout<<dp[n]<<endl;


	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;

int main(){
 int m1,d1,m2,d2;
 cin>>m1>>d1>>m2>>d2;
 if(d2-d1!=1){
   cout << 1 << endl;
 }else{
   cout << 0 <<endl;
 }
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>

using namespace std;

class Stack {
    int top = 0;
    int S[1000];

public: void push(int x) {
        top++;
        S[top] = x;
    }

public: int pop() {
        top--;
        return S[top+1];
    }
};

int main() {
    int o1, o2;
    Stack stack;

    char s[100];
    while (scanf("%s", s) != EOF) {
        if (s[0] == '+') {
            o2 = stack.pop();
            o1 = stack.pop();
            stack.push(o1 + o2);
        } else if (s[0] == '-') {
            o2 = stack.pop();
            o1 = stack.pop();
            stack.push(o1 - o2);
        } else if (s[0] == '*') {
            o2 = stack.pop();
            o1 = stack.pop();
            stack.push(o1 * o2);
        } else {
            stack.push(atoi(s));
        }
    }

    printf("%d\n", stack.pop());

    return 0;
}

Measured memory_bytes: 2764
K=int(input())
A=input().split(' ')
min=2
max=2
flag=0
while K>0:
  K=K-1
  i=int(A[K])
  if max<i:
    print('-1')
    flag=1
    break
  elif i<min:
    if min%i!=0:min=min+i-(min%i)
    else:min=min+(min%i)
    max=max+i-(max%i)-1
    if min>max:
      print('-1')
      flag=1
      break
  else:
    min=i
    max=max+i-(max%i)-1
if flag==0:
  print('{0} {1}'.format(min,max))

Measured memory_bytes: 13100
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 2e3+10;
int n,ans;
int v[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) 
		cin>>v[i];
	sort(v+1,v+1+n);
	for(int j=1;j<=n;j++)
		for(int k=j+1;k<=n;k++)
			for(int l=k+1;l<=n;l++)
				if(v[l]<v[j]+v[k])
					ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-09-01
**/

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

int mult(int a, int b) {
    return (int) ((long long) a * b % MOD);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<long long> suff(n);
    suff[n-1] = a[n-1];
    for (int i = n-2; i >= 0; i--) {
        suff[i] = suff[i+1] + a[i];
        suff[i] %= MOD;
    }
    
    long long ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += mult(a[i], suff[i+1]);
        ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MOD = 1e9 + 7;
const int MAX = 2e6 + 5;
int fat[MAX];

inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}

inline int sub(int a, int b) {
    a -= b;
    if (a < 0) a += MOD;
    return a;
}

inline int mult(int a, int b) {
    return (1LL * a * b) % MOD;
}

int f_exp(int x, int e) {
    if (e == 0) return 1;
    if (e & 1) return mult(x, f_exp(x, e - 1));
    return f_exp(mult(x, x), e / 2);
}

inline int inv(int x) {
    return f_exp(x, MOD - 2);
}

inline int comb(int n, int k) {
    if (k > n) return 0;
    return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k])));
}

inline int comb_sum(int up, int down) {
    return comb(up + 1, down + 1);
}

void preprocess() {
    fat[0] = 1;
    fori (i, 1, MAX) {
        fat[i] = mult(fat[i - 1], i);
    }
}

void solve() {
    preprocess();
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = 0;
    fori (i, r1, r2 + 1) {
        ans = add(ans, sub(comb_sum(i + c2, i), comb_sum(i + c1 - 1, i)));
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



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

int main(){
  int N;
  cin >> N;
  char S;
  int red = 0;
  int blue = 0;
  
  
  for(int i = 0; i < N; i++){
    cin >> S;
    if(S == 'R'){
      red++;
    }
    else{
      blue++;
    }
  }
  if(red > blue){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
acc = [0] + list(accumulate(aaa))
dp = [[0] * (n + 1) for _ in range(n)]
for l, aa in enumerate(zip(aaa, aaa[1:])):
    dp[l][l + 2] = sum(aa)
for w in range(3, n + 1):
    for l in range(n - w + 1):
        r = l + w
        dp[l][r] = min(dp[l][m] + dp[m][r] for m in range(l + 1, r)) + acc[r] - acc[l]
print(dp[0][n])


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

using namespace std;

#define sz(s) ((int)s.size())

typedef long long ll;

const double eps = 0.00001;
const int MOD = 1000000007; //998244353
const int INF = 1000055555;
const long long LLINF = 1223372000000000555;
const int N = 2250555;
const int M = 5222;

int a[N];
int cnt[N];

struct query{
    int left;
    int right;
    int index;
};

query q[N];
ll ans = 0;

vector<query> block[M];

void del(int idx){
    ll val = a[idx];
    cnt[val]--;
    if (cnt[val] == 0) ans--;
}
void add(int idx){
    ll val = a[idx];
    cnt[val]++;
    if (cnt[val] == 1) ans++;
}

ll ANS[N];

void solve() {
    int n, m;
    cin >> n >> m;

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

    int k = sqrt(n) + 1;

    for (int i = 1; i <= m; i++){
        int l, r;
        cin >> l >> r;
        q[i] = {l, r, i};
        block[l / k].push_back(q[i]);
    }

    for (int i = 0; i < k; i++){
        sort(block[i].begin(), block[i].end(), [](auto a, auto b){return a.right < b.right; });
    }

    int l = 1, r = 0;

    for (int i = 0; i < k; i++){
        for (auto now : block[i]){
            int L = now.left, R = now.right;
            while (l > L) add(--l);
            while (l < L) del(l++);
            while (r < R) add(++r);
            while (r > R) del(r--);
            ANS[now.index] = ans;
        }
    }

    for (int i = 1; i <= m; i++){
        cout << ANS[i] << "\n";
    }

}


int main() {
    ios_base::sync_with_stdio(false);
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 26400
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;

	int a = 1;
	for(int i=-1000;i<1000;i++){
		for(int j=-1000;j<1000;j++){
			if(x==pow(i,5) - pow(j,5)){
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 4040
#include<stdio.h>
int main(){
int dp[101010],n,i,a[101010],max,min,mid;
for(i=0;i<100010;i++){
dp[i]=1000000010;
}
scanf("%d\n",&n);
for(i=0;i<n;i++){
scanf("%d\n",&a[i]);
}
for(i=0;i<n;i++){
max=100005,min=0;
mid=(max+min)/2;
while(min<max){
if(dp[mid]==a[i]){
break;
}
else if(dp[mid]>a[i]){
max=mid;
}
else{
min=mid+1;
}
mid=(max+min)/2;
}
dp[mid]=a[i];
}
for(i=0;i<100005;i++){
if(dp[i]==1000000010){
printf("%d\n",i);
break;
}
}
return 0;
}


Measured memory_bytes: 2628
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  ll n,m,v,p;
  cin >> n;
  cin >> m;
  cin >> v;
  cin >> p;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll vv = v-(p-1);
  sort(a.begin(), a.end());
  vector<ll> b;
  rep(i,n-p+1){
    b.push_back(a[i]);
  }
  reverse(b.begin(), b.end());
  int nn = b.size();
  vector<ll> sum(nn);
  sum[0] = 0;
  rep1(i,nn-1){
    sum[i] = sum[i-1] + b[i-1];
  }
  // rep(i,nn){
  //   cout << b[i] << " ";
  // }
  //  cout << "\n";
  int res = (int)p;
  rep1(i,nn-1){
    if(b[0]-b[i]>m) continue;
    ll d = sum[i] - i*b[i];
    ll vvv = max(0LL,vv-(nn-i));
    // cout << i << " ";
    // cout << vvv << " ";
    // cout << d << " ";
    // cout << m << "\n";
    if(m*vvv<=m*i-d) res++;
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 2676
a = str(input())
s = len(a)
x = ""
while True:
    if s == 0:
        break
    elif a[0] == "0":
        x += "0"
    elif a[0] == "1":
        x += "1"
    elif a[0] == "B":
        x = x[:-1]
    s = s - 1
    a = a[1:]
print(x)

Measured memory_bytes: 2940
#include<stdio.h>

#define HEAP_SIZE 250

int main()
{
	int heap[HEAP_SIZE+1];
	int i, n;

	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d", &heap[i]);
	}

	for(i = 1; i <= n; i++){
		printf("node %d: key = %d, ", i, heap[i]);
		if(0 < (i / 2)){
			printf("parent key = %d, ", heap[i / 2]);
		}
		if((2 * i) <= n){
			printf("left key = %d, ", heap[2 * i]);
		}
		if((2 * i + 1) <= n){
			printf("right key = %d, ", heap[2 * i + 1]);
		}
		printf("\n");
	}

	return(0);
}

Measured memory_bytes: 600
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn minkowski_distance(p: i32, n: usize, x: &Vec<f64>, y: &Vec<f64>) -> f64 {
  let mut ans = 0.0;
  for i in 0..n {
    ans += (x[i] - y[i]).abs().powi(p);
  }
  ans.powf(1.0 / p as f64)
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let n = scan!(sc; usize);
  sc.new_line();
  let x: Vec<f64> = sc.get_as_vec();
  sc.new_line();
  let y: Vec<f64> = sc.get_as_vec();
  for i in 1..4 {
    println!("{}", minkowski_distance(i, n, &x, &y));
  }
  let d: f64 = {
    let mut ans = 0.0;
    for i in 0..n {
      ans = f64::max(ans, (x[i] - y[i]).abs());
    }
    ans
  };
  println!("{}", d);
}



Measured memory_bytes: 5188