akhauriyash/Code-Regression huggingface dataset:
n, a, b = map( int, input().split() )
mod = 10 ** 9 + 7

N = pow( 2, n, mod ) - 1

def comb( n, r  ):
  c = 1
  m = 1
  r = min( n - r, r )
  for i in range( r ):
    c = c * ( n - i ) % mod
    m = m * ( i + 1 ) % mod
  return c * pow( m, mod - 2, mod ) % mod

A = comb( n, a )
B = comb( n, b )
print( ( N - A - B ) % mod )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  rep(i,c-a){cout<<'R';}
  rep(i,d-b){cout<<'U';}
  rep(i,c-a){cout<<'L';}
  rep(i,d-b){cout<<'D';}
  cout<<'D';
  rep(i,c-a+1){cout<<'R';}
  rep(i,d-b+1){cout<<'U';}
  cout<<'L';
  cout<<'U';
  rep(i,c-a+1){cout<<'L';}
  rep(i,d-b+1){cout<<'D';}
  cout<<'R';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll MOD=1000000007;
int main(){
  ll n,t;
  cin >> n >> t;
  ll i,j,k;
  vector<ll> v;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(),v.end());
  ll ans=1;
  for(i=0;i<n;i++){
    ans*=(i-distance(v.begin(),lower_bound(v.begin(),v.end(),v[i]-t))+1);
    ans%=MOD;
  }
  cout << ans % MOD << endl;
  return 0;
}

Measured memory_bytes: 2068
#include <stdio.h>
int main(void){
   int m,f,r;
   while(1){ 
      scanf("%d %d %d",&m,&f,&r);
       if(m==-1&&f==-1&&r==-1)break;
       if(m==-1||f==-1){
           printf("F\n");
       }else if(m+f>=80){
           printf("A\n");
       }else if(m+f>=65){
           printf("B\n");
       }else if(m+f>=50){
           printf("C\n");
       }else if(m+f>=30&&r<50){
           printf("D\n");
       }else if(m+f>=30&&r>=50){
           printf("C\n");
       }else if(m+f<30){ 
          printf("F\n");
       }
   }
   return 0;
}


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

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;


int main(){
    string S, T;
    cin >> S >> T;
    int N = S.size();
    bool flag = true;

    if(N + 1 != T.size()) flag = false;
    rep(i, N){
        if(S.at(i) != T.at(i)) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int a,b;
   cin>>a>>b;
   if((a*b)%2)cout<<"Odd"<<endl;
   else cout<<"Even"<<endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] L = new int[N];
		Arrays.setAll(L, i -> sc.nextInt());
		int ans = 0;
		for(int i = 0; i < N; i++)
			for(int j = i+1; j < N; j++)
				for(int k = j+1; k < N; k++)
					if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k] && L[i]+L[j]>L[k] && L[i]+L[k]>L[j] &&L[k]+L[j]>L[i])
						ans++;
		System.out.println(ans);
	}

}


Measured memory_bytes: 36916
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int N=200005;

std:: stack <int> stack;
std:: vector <int> vec;

struct edge {int x,y,next;} e[N*2];

int used[N],dep[N],ls[N],p[N],f[N],d,wjp,edCnt=1;

bool vis[N],in[N];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

void add_edge(int x,int y) {
	e[++edCnt]=(edge) {x,y,ls[x]}; ls[x]=edCnt;
}

void dfs1(int x) {
	stack.push(x);
	for (int i=ls[x];i;i=e[i].next) {
		if (!vis[e[i].y]) {
			vis[e[i].y]=1;
			dep[e[i].y]=dep[x]+1;
			dfs1(e[i].y);
		} else {
			int y=0;
			while (y!=e[i].y) {
				y=stack.top(),stack.pop();
				vec.push_back(y);
				in[y]=1;
			}
		}
	}
}

void dfs2(int x,int from) {
	for (int i=ls[x];i;i=e[i].next) {
		if (!in[e[i].y]&&e[i].y!=from) dfs2(e[i].y,x);
	}
	++wjp;
	for (int i=ls[x];i;i=e[i].next) {
		if (!in[e[i].y]&&e[i].y!=from) {
			used[f[e[i].y]]=wjp;
		}
	}
	for (f[x]=0;used[f[x]]==wjp;) f[x]++;
}

int main(void) {
	int n=read(),rec=-1;
	rep(i,1,n) p[i]=read();
	rep(i,1,n) add_edge(i,p[i]);
	dep[1]=vis[1]=1;
	dfs1(1);
	rep(i,1,n) add_edge(p[i],i);
	bool flag=false;
	for (int x:vec) {
		dfs2(x,0);
		if (rec==-1) rec=f[x];
		else if (rec!=f[x]) flag=true;
	}
	if ((vec.size()&1)&&(!flag)) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 20896
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N; int a; bool can = true;
  rep(i, N){
    cin >> a;
    if(a%2==0){
      if(a%3 && a%5) can = false;
    }
  }
  if(can) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

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

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

void Main(){
  ll N; cin >> N;
  cout << (N * (N - 1)) / 2 << endl;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> v;
    v.pb(0);
    while(n--){
        ll k;
        cin>>k;
        v.pb(k);
    }
    sort(v.begin(),v.end());
    ll ans=0;
    for(ll i=1;i<v.size();i++){
        if(v[i]!=v[i-1]){
            ans+=1;
        }
    }
    cout<<ans-!(ans&1);
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 
 
int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
 
    int num = 0;
    rep(i,M){
        cin >> A[i];
        num += A[i];
    }
 
    int ans;
    ans = N - num;
    if(ans < 0) ans = -1;
 
    cout << ans << endl;
 
    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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


int main() {
    int x = 0,n;
    string s;
    cin>>n;
    cin>>s;
    int a[102];
    a[0] = 0;
    for(int i = 1; i <= s.length();i++){
        if(s[i-1] == 'I'){
            x++;
            
        }
        else{
            x--;
        }
        a[i] = x;
    }

    cout<<*max_element(a,a+n+1);
    return 0;
}

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

int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		S[i] = 'x';
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
    return 0;
};


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
  double a,b,C;
  double S,L,h;
  scanf("%lf %lf %lf\n",&a,&b,&C);
  C=M_PI*C/180;
  S=a*b*0.5*sin(C);
  L=a+b+sqrt(a*a+b*b-2*a*b*cos(C));
  h=b*sin(C);
  printf("%.8lf\n%.8lf\n%.8lf\n", S,L,h);
  return 0;
}

Measured memory_bytes: 680
def main():
    N,M = map(int,input().split())
    store_l = []
    for i in range(N):
        store_l.append(tuple(map(int,input().split())))

    store_l = sorted(store_l,key=lambda x:x[0])
    ans = 0
    buynum = 0
    for price,maxnum in store_l:
        if(buynum+maxnum<=M):
            buynum += maxnum
            ans += maxnum*price
        else:
            ans += (M-buynum)*price
            break
    print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 18864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long double a, b;
	cin >> a >> b;
	long double z = a * b;
	long long int r = z;
	cout <<  r << endl;
}

Measured memory_bytes: 3808
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
    
        long answer = n / (a + b) * a;
        answer += Math.min(a, n % (a + b));
    
        System.out.println(answer);
    }

}

Measured memory_bytes: 35628
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n,q;
  cin>>n>>q;

  string s;
  cin>>s;

  vector<ll> l(q);
  vector<ll> r(q);
  rep(i,q){
    cin>>l[i];
    cin>>r[i];
  }
  
  

  ll dp[100001];
  
  dp[0]=0;
  //dp[1]=0;

  rep(i,n){
    if(i==0) continue;

    if(s[i]=='C' && s[i-1] == 'A'){
      dp[i]=dp[i-1]+1;
    }
    else{
      dp[i]=dp[i-1];
    }
    //cout << dp[i] << endl;
  }

  rep(i,q){
    //cout << l[i] << "," << r[i] << endl;
    cout << dp[ r[i]-1 ] - dp[ l[i]-1 ] << endl;
  }

  return 0;

}


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

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

    int m = std::max({A, B, C});
    if (m == A) {
        cout << A*10+B+C << endl;
    } else if (m == B) {
        cout << B*10+A+C << endl;
    } else {
        cout << C*10+A+B;
    }
}

Measured memory_bytes: 256
t=input()
now=len(t)-1
kekka=t
ket=[]
for i in range(len(t)):
    ket.append(kekka[i])
if ket[now]=="?":
    ket[now]="D"
    now-=1
while 0<now:
    if ket[now]=="?":
        if ket[now+1]=="P":
            ket[now]="D"
        else:
            if ket[now-1]=="P":
                ket[now]="D"
            else:
                ket[now]="P"
    now=now-1
if ket[0]=="?"and len(t)>1:
    if ket[1]=="P":
        ket[0]="D"
    else:
        ket[0]="P"

print(*ket,sep="")


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

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

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;

char f(char a, char b) {
  if (a == 'T' && b == 'F') return 'F';
  return 'T';
}
signed main() {
  int n; cin >> n;
  vector<char> a(n); REP (i, n) cin >> a[i];
  char ans = f(a[0], a[1]);
  REPI (i, 2, n) {
    ans = f(ans, a[i]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3204
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>

int main(){
  while(true){
    std::string red, green, bottom, right;
    std::cin >> red;
    if (red.compare("-") == 0) return EXIT_SUCCESS;
    std::cin >> green;
    std::cin >> bottom;
    right.clear();
    auto c_red = red.begin();
    auto c_green = green.begin()+1;
    auto center = *(green.begin());
    for(auto i=bottom.begin(); i!=bottom.end(); i++){
      while(center!=*i){
        right.push_back(center);
        center = *c_green;
        c_green++;
      }
      center = *c_red;
      c_red++;
    }
    while(c_green!=green.end()){
      right.push_back(center);
      center = *c_green;
      c_green++;
    }
    right.push_back(center);
    std::cout << right << std::endl;
  }
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[200005];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    if (N % 2 == 1)
    {
        for (int i = N - 1; i >= 0; i -= 2)
        {
            cout << A[i] << " ";
        }
        for (int i = 1; i < N; i += 2)
        {
            cout << A[i] << " ";
        }
    }
    else
    {
        for (int i = N - 1; i >= 0; i -= 2)
        {
            cout << A[i] << " ";
        }
        for (int i = 0; i < N; i += 2)
        {
            cout << A[i] << " ";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1

using namespace std;

int main() {
  int n, count;
  while (cin >> n, n) {
    count = 0;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < i; j++) {
        if (i*(i+1) - j*(j+1) == 2*n) count++;
      }
    }
    cout << count << el;
  }
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> pos(n);
    rep(i,n){
        ll p;
        cin >> p;
        --p;
        pos.at(p) = i;
    }
    ll ans = 0;
    multiset<ll> ms;
    ms.insert(-1),ms.insert(-1),ms.insert(n),ms.insert(n);
    for(i = n-1;i >= 0;--i){
        ll now = pos.at(i);
        auto it = ms.lower_bound(now);
        ll r = *it;
        ll rr = *(++it);
        --it;   --it;
        ll l = *it;
        ll ll = *(--it);
        ans += (i+1)*(r - now)*(l - ll);
        ans += (i+1)*(rr - r)*(now - l);

        ms.insert(now);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8580
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

int main() {
  int row, column;
  cin >> row >> column;
  int ans[row + 1][column + 1];
  std::memset(ans, 0, sizeof ans);

  for (int i = 0; i < row; i++) {
    for (int j = 0; j < column; j++) {
      cin >> ans[i][j];
      ans[i][column] += ans[i][j];
      ans[row][j] += ans[i][j];
      ans[row][column] += ans[i][j];
    }
  }

  for (int i = 0; i <= row; i++) {
    for (int j = 0; j <= column; j++) {
      cout << ans[i][j];
      if (j != column) {
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
const int MAXN = 100005;

struct edge{
  int from, to;
  ll cost;
};


struct pts{
  ll x,y;
  int id;
};

bool xcmp(pts a, pts b) { return a.x < b.x; }
bool ycmp(pts a, pts b) { return a.y < b.y; }
bool ecmp(edge a, edge b) { return a.cost < b.cost; }

int par[MAXN];

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

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

int main(){
  int N; cin >> N;
  //vector<pts> v(N);
  pts v[MAXN];
  for(int i=1;i<=N;i++){
    cin >> v[i].x >> v[i].y;
    v[i].id = i;
  }
  vector<edge> e_arr;
  sort(v+1,v+N+1,xcmp);
  for(int i=1;i<N;i++){
    edge e;
    e.from = v[i].id; e.to = v[i+1].id;
    e.cost = v[i+1].x - v[i].x;
    e_arr.push_back(e);
  }
  sort(v+1,v+N+1,ycmp);
  for(int i=1;i<N;i++){
    edge e;
    e.from = v[i].id; e.to = v[i+1].id;
    e.cost = v[i+1].y - v[i].y;
    e_arr.push_back(e);
  }

  sort(e_arr.begin(), e_arr.end(), ecmp);
  // init
  for(int i=0;i<N;i++) par[i] = i;
  ll ans = 0;
  for(auto e : e_arr){
      if(find(e.from) != find(e.to)){
        ans += e.cost;
        unite(e.from, e.to);
      }
  }
  cout << ans << endl;
  //int a[MAXN];
  return 0;
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int x[52];
ll dp[52][52][2555];

int main()
{
	memset(x, 0, sizeof(x));
	memset(dp, 0LL, sizeof(dp));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N, A; cin >> N >> A;
	rep (i, N) cin >> x[i];

	dp[0][0][0] = 1LL;
	rep (i, N){
		for (int j = 0; j <= i; ++j){
			for (int k = 0; k < 2501; ++k){
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			} // end for
		} // end rep
	} // end rep

	ll res = 0LL;
	for (int j = 1; j <= N; ++j){
		res += dp[N][j][j*A];
	} // end for
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 54272
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int n;
cin >> n;
vector<int> b(n-1);
rep(i,n-1) cin >>b[i];

vector<int> a(n);
a[0] = b[0];
a[n-1] = b[n-2];

int ans = 0;

rep(i,n) {
    if(i!=0 && i!= n-1) a[i] = min(b[i-1],b[i]);
    ans += a[i];
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n-2; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    ll n,ans=INF;
    string s;
    cin >> n >> s;
    int k = s.size();
    
    vector<ll>lb(n,0);
    vector<ll>rw(n,0);
    
    rep2(i,1,n){
        if(s[i-1]=='#')lb[i]=lb[i-1]+1;
        else lb[i]=lb[i-1];
    }
    for(int i=n-2;i>=0;i--){
        if(s[i+1]=='.')rw[i]=rw[i+1]+1;
        else rw[i]=rw[i+1];
    }
    
    rep(i,n)ans=min(ans,(rw[i]+lb[i]));
    
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 6768
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
using namespace std;

int main() {
    int n,a,b;
    cin >> n >> a>> b;
    if (n*a<=b)
    {
        cout  << n*a << endl;
    }else{
        cout  << b << endl;
    }
    

}


Measured memory_bytes: 3608
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n;
	cin>>n;
	ll t = 0, a = 0, b = 0;
	rep(i, n){
		ll x, y, r;
		cin>>r>>x>>y;
		ll d1 = r-t, d2 = abs(x-a)+abs(y-b);
		if(d1<d2||(d1%2!=d2%2)){
			cout<<"No"<<endl;
			return 0;
		}
		t = r;
		a = x;
		b = y;
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

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

	string ret;
	if(C >= A && C <= B)
		ret = "Yes";
	else
		ret = "No";

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.List

main :: IO ()
main = do
  { [n] <- getInts
  ; cards <- loop n
  ; putCards (allcards \\ cards)
  }

putCards :: [(Suit, Int)] ->IO ()
putCards = putStr . unlines . map showCard

loop :: Int -> IO [(Suit, Int)]
loop 0 = return []
loop n = do
  { c  <- getCard
  ; cs <- loop (n-1)
  ; return (c:cs)
  }

showCard :: (Suit, Int) -> String
showCard (s, n) = show s ++ " " ++ show n

--

data Suit = S | H | C | D deriving (Eq, Ord, Show, Read)

allcards :: [(Suit, Int)]
allcards = [ (s, r) | s <- [S, H, C, D], r <- [1..13]]

getCard :: IO (Suit, Int)
getCard = do
  { [s, r] <- words <$> getLine
  ; return (read s , read r)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine




Measured memory_bytes: 4172
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    multiset<LLONG> prices;
    for (int i = 0; i < N; ++i)
    {
        int price;
        cin >> price;
        prices.insert(price);
    }
    // 常に値段が最大のものに割引券を使う
    for (int ticket = 0; ticket < M; ++ticket)
    {
        auto maxItr = --prices.end();
        const LLONG newPrice = *maxItr / 2;
        prices.erase(maxItr);
        prices.insert(newPrice);
    }
    cout << accumulate(prices.begin(), prices.end(), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  REP(i, 2) REP(j, N) cin >> A[i][j];
  ll mx = 0;
  for (int i = 0; i < N; i++) {
    ll num = 0;
    int tmp = 0;
    REP(j, N) {
      num += A[tmp][j];
      if (j == i) {
        tmp++;
        num += A[tmp][j];
      }
    }
    mx = max(mx, num);
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
M, D = map(int, input().split())
ans = 0
for i in range(1, M+1):
  for j in range(10, D+1):
    d1 = j%10
    d10 = j//10
    if d1 >= 2 and d10 >= 2:
      if i == d1 * d10:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    ns <- sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    print . head . sort . map f $ permutations ns
    
f [a, b, c] = abs (b - a) + abs (c - b)


Measured memory_bytes: 380
/**
 *
 * AtCoder Beginner Contest 104 - Problema B: We Love ABC (https://abc104.contest.atcoder.jp/tasks/abc104_d)
 *
 * Find all occurrences of the subsequence ABC on given string S, replacing all ? symbols with
 * A, B and C.
 *
 * DP solution: use a if-else chain to find the corresponding contest according to the rules.
 */
#include <iostream>


#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : vec) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

using namespace std;
using ll = long long;

const int MAX { 100010 };
const ll MOD { 1000000007 };

ll abc[MAX], bc[MAX], cs[MAX], qm[MAX];

ll mod_pow(ll a, ll n)
{
    ll res = 1, base = a;

    while (n)
    {
        if (n & 1)
            res = (res * base) % MOD;

        base = (base * base) % MOD;
        n >>= 1;
    }

    return res;
}
 
void solve(const string& S)
{
    int N = S.size();

    for (int i = N - 1; i >= 0; --i)
    {
        auto c = S[i];
        auto strings_so_far = mod_pow(3, qm[i + 1]);

        cs[i] = (c == '?' ? 3*cs[i + 1] +  strings_so_far : cs[i + 1]);
        cs[i] += (c == 'C' ? strings_so_far : 0);
        cs[i] %= MOD;

        qm[i] = qm[i + 1] + (c == '?' ? 1 : 0);

        bc[i] += (c == '?' ? 3*bc[i + 1] + cs[i + 1]: bc[i + 1]);
        bc[i] += (c == 'B' ? cs[i + 1] : 0);
        bc[i] %= MOD;

        abc[i] += (c == '?' ? 3*abc[i + 1] + bc[i+1] : abc[i + 1]);
        abc[i] += (c == 'A' ? bc[i + 1] : 0);
        abc[i] %= MOD;

//LOGM("==> "); LOG(i, '\n');
//LOGA(cs, N, '\n');
//LOGA(qm, N, '\n');
//LOGA(bc, N, '\n');
//LOGA(abc, N, '\n');
//LOG(ans, '\n');
    }

    cout << abc[0] << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    solve(S);

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    long long int n,k;
    cin>>n>>k;
    long long int d[100001]={0};//個数
    long long int s[100001]={0};//累積和
    long int a[n];
    long int b[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        d[a[i]]+=b[i];
    }
    for(int i=1;i<100001;i++){
        s[i]=s[i-1]+d[i];
        if(k<=s[i]){
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;

}


Measured memory_bytes: 3328
N,M=map(int,input().split())
A=[[] for i in range(N)]
for i in range(0,N):
    A[i]=list(map(int,input().split()))

pointer={i:0 for i in range(0,N)}
cancel=set([])
ans=N
while True:
    dic={i:0 for i in range(1,M+1)}
    for i in range(0,N):
        dic[A[i][pointer[i]]]+=1
    most=max(dic[i] for i in range(1,M+1))
    ans=min(ans,most)
    for i in range(1,M+1):
        if dic[i]==most:
            cancel.add(i)

    for i in range(0,N):
        while A[i][pointer[i]] in cancel:
            pointer[i]+=1
            if pointer[i]==M:
                print(ans)
                exit()

Measured memory_bytes: 44124
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef double db;
const int N = 2005, mod = 924844033;
int n, m;
ll fac[N], f[N][N][2][2], ans, res;
int main()
{
	scanf ("%d%d", &n, &m);
	fac[0] = 1;
	Rep(i, 1, n) fac[i] = fac[i - 1] * i % mod;
	int i = 1;
	f[0][0][0][0] = 1;
	Rep(r, 1, n) {
		bool f1, f2;
		if (r > 1) {
			if (i + m > n) i = i % m + 1, f1 = 0;
			else i = i + m, f1 = 1;
		} else f1 = 0;
		// cout << i<<endl;
		f2 = (i + m <= n);
		Rep(j, 0, r) Rep(p1, 0, 1) Rep(p2, 0, 1) {
			Rep(q1, 0, f1) Rep(q2, 0, f2) if (!(p1 & q1) && !(q1 & q2)) {
				(f[r][j + (q1 | q2)][p2][q2] += f[r - 1][j][p1][p2]) %= mod;
			}
		}
	}
	int k = 1;
	Rep(i, 0, n) {
		res = 0;
		Rep(p1, 0, 1) Rep(p2, 0, 1) (res += f[n][i][p1][p2]) %= mod;
		(ans += res * fac[n - i] * k) %= mod;
		k *= -1;
	}
	printf("%lld\n", (ans + mod) % mod);

	return 0;
}

Measured memory_bytes: 123776
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# どれかの軸で切る

A,B,C = map(int,read().split())

INF = 10 ** 18
answer = INF
for _ in range(3):
    A,B,C = B,C,A
    # A 方向で切る
    if A & 1:
        x = B * C
    else:
        x = 0
    if answer > x:
        answer = x

print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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; }

int main(){
  ll n,k; cin >> n >> k;
  vi a(n); rep(i,n){ cin >> a[i]; a[i]--; }
  set<int> st;
  vi trace;
  int now = 0;
  rep(i,n){
    if(st.count(now)) break;
    st.insert(now);
    trace.push_back(now);
    now = a[now];
  }
  int i = 0;
  for(; trace[i] != now; i++){
    if(k == 0){
      cout << trace[i]+1;
      return 0;
    }
    k--;
  }
  int cnt = (int)trace.size()-i;
  cout << trace[i+k%cnt]+1;
  cout << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const ll mod = 1e9 + 7;
typedef pair<ll,ll>P;

int main(){

  int n;cin>>n;
  string s;cin>>s;

  vector<int>e(n+1,0);
  rep(i,0,n)e[i+1]=e[i]+(s[i]=='E');

  int mi=1000000;
  rep(i,0,n){
    int wnm=i-e[i],enm=e[n]-e[i+1];
    mi=min(wnm+enm,mi);
  }

  out(mi);

  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int c=0, d=0, e=1, f=1;
  
  if (a<b){
    for (int i = 0; i < b; i++){
      c += a * e;
      e *=10;
    }
    cout << c << endl;
  }
  else {
    for (int i = 0; i<a; i++){
      d += b * f;
      f *=10;
    }
    cout << d << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
                first = false;
            }
            cout << x;
        }
    }
};

int main()
{
    input in;
    output out;

    int A, B;
    in >> A, B;

    if (A < 10 && B < 10) {
        out << A * B;
    } else {
        out << -1;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s,ans="No";
    cin >> s;
    if(s[0]==s[1] and s[2]==s[3]){
        ans="Yes";
    }
    if(s[0]==s[2] and s[1]==s[3]){
        ans="Yes";
    }
    if(s[0]==s[3] and s[1]==s[2]){
        ans="Yes";
    }
    if(s[0]==s[1] and s[1]==s[2] and s[2]==s[3]){
        ans="No";
    }
    
    cout << ans << endl;
}

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

int main(){
  while(1){
    int N, i, j;
    scanf("%d", &N);
    if(N == 0){
      return 0;
    }
    vector<pair<int, int>> rw(N);
    int rsum = 0, wsum = 0;
    for(i = 0; i < N; i++){
      scanf("%d %d", &rw[i].first, &rw[i].second);
      rsum += rw[i].first;
      wsum += rw[i].second;
    }
    sort(rw.begin(), rw.end());
    if(rsum >= 2 * rw[N - 1].first){
      printf("%d\n", rsum + wsum);
      continue;
    }
    int d = rw[N - 1].first - (rsum - rw[N - 1].first);
    vector<int> dp(d + 1, 0);
    dp[0] = 1;
    for(i = 0; i < N - 1; i++){
      int w = rw[i].second;
      for(j = d; j >= w; j--){
        dp[j] |= dp[j - w];
      }
    }
    int m = 0;
    for(i = 0; i <= d; i++){
      if(dp[i] == 1){
        m = max(m, i);
      }
    }
//    printf("(rsum, wsum) = (%d, %d)\n", rsum, wsum);
//    printf("d = %d\n", d);
//    printf("m = %d\n", m);
    printf("%d\n", rsum + wsum + (d - m));
  }
}



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

int main(){
	vector<int> a(5), b(5);
	rep(i,5){
		cin >> a[i];
		b[i] =  a[i]%10;
	}
	int min=10;
	rep(i,5){
		if(b[i] != 0 && b[i] < min) min = b[i];
	}
	int res=0;
	rep(i,5){
		if(b[i]!=0){
			res += (a[i]/10 + 1)*10;
		}else res += a[i];
	}
	if(min != 10){
		res -= (10-min);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(a, b, c, d) = sc.nextLine.split(" ").map(_.toInt)
    if (Math.abs(c - a) <= d) println("Yes")
    else if (Math.abs(b - a) <= d & Math.abs(c - b) <= d) println("Yes")
    else println("No")
  }

}


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

int main(){
	int n,K;cin>>n>>K;
	int lim=(n-1)*(n-2)/2;
	if(K>lim){
		puts("-1");return 0;
	}
	vector<P>v;
	rep(i,n){
		for(int j=i+1;j<n;j++)v.push_back(P(i,j));
	}
	rep(i,K)v.pop_back();
	cout<<v.size()<<endl;
	for(auto p:v){
		cout<<p.first+1<<' '<<p.second+1<<endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main(){
  ll n;cin>>n;
  map<ll,ll> m;
  rep(i,0,n){
    ll d;cin>>d;
    m[d]++;
  }
  ll k;cin>>k;
  rep(i,0,k){
    ll t;cin>>t;
    if(m[t]==0){cout<<"NO"<<endl;return 0;}
    m[t]--;
  }
  cout<<"YES"<<endl;
}







Measured memory_bytes: 16048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();

            int ans = Math.min(b, d) - Math.max(a, c);
            out.println(ans < 0 ? 0 : ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



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

struct Heap {
    int *heapTable;
    int length;
    int curr;

    Heap () {
        this->heapTable = new int[20000001];
        this->length = 0;
        this->curr = 1;
    }

    void add (int valor) {
        this->heapTable[this->curr] = valor;
        this->curr++;
        this->length++;
    }

    void bottomUp() {
        if (this->length > 1) {
            int k = this->length;
            int v = this->heapTable[k];
            bool heapConfirm = false;
            while (!heapConfirm && k > 1) {
                int j = k / 2;
                if (v <= this->heapTable[j]) {
                    heapConfirm = true;
                } else {
                   this->heapTable[k] = this->heapTable[j];
                   this->heapTable[j] = v;
                   k = j;
                }
            }
        }
    }
    void upDown() {
            int k = 1;
            int v = this->heapTable[k];
            bool heapConfirm = false;
            while (!heapConfirm) {
                int j = 2 * k;
                if (j < this->curr) {
                    if (this->heapTable[j] < this->heapTable[j+1]) {
                        j = j + 1;
                    }
                } if (v >= this->heapTable[j]) {
                    heapConfirm = true;
                } else {
                    this->heapTable[k] = this->heapTable[j];
                    k = j;
                }
            }
            this->heapTable[k] = v;
        }


    void extract () {
        int aux = this->heapTable[1];
        this-> heapTable[1] = this->heapTable[length];
        this->heapTable[length] = 0;
        this->curr--;
        this->length--;
        cout << aux << endl;
    }

    void printArray() {
        for (int i = 0; i < this->length+1; i++) {
            cout << this->heapTable[i] << " ";
        }
    cout << "\n";
    }
};

int main () {
    Heap *heap = new Heap();
    bool stop = false;
    while (!stop) {
        string action = "";
        int valor = 0;
        cin >> action;
        if (action == "end") {
            stop = true;
        }
        else if (action == "insert") {
            cin >> valor;
            heap->add(valor);
            heap->bottomUp();
           // heap->printArray();
        } else {
            heap->extract();
            heap->upDown();
            //heap->printArray();
        }
    }
}



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

int main() {
	int n; cin >> n;
	int	ans = 1e10;

	auto check = [](int x){
		int num = 0;
		while (x) {
			num += x % 10;
			x /= 10;
		}
		return num;
	};

	for (int i = 1; i < n; i++) {
		int a = check(i), b = check(n - i);
		if (ans > a + b)ans = a + b;	
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int[] num = new int[3];
                num[0] = sc.nextInt();
                num[1] = sc.nextInt();
                num[2] = sc.nextInt();
                int K = sc.nextInt();
                int max=0;
                int maxN=0;
                for(int i=0; i<3; i++){
                        if(max<num[i]){
                                max = num[i];
                                maxN = i;
                        }
                }

                for(int i=0; i<K; i++)num[maxN] = num[maxN] * 2;
                System.out.println(num[0]+num[1]+num[2]);
        }
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0;
  cin >> n;

  cout << n + n * n + n * n * n << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){

	int n;

	cin>>n;

	if(n==0){
		cout<<1<<endl;
	}
	else if(n==1){
		cout<<2<<endl;
	}
	else if(n==2){
		cout<<1<<endl;
	}
	else{
		cout<<0<<endl;
	}

	return 0;
}

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

using namespace std;

int n, k, cnt[12345], ans = 0;
//set<string>a;
int init()
{
	int alpa = 26;
	//char s[123456];
	string s;
	scanf("%d", &n);
	scanf("%d", &k);
	for (int i = 0; i < n; ++i)
		{
			cin >> s;
			//a.insert(s)
			cnt[s[0] - 'A']++;
			//scanf("%s", s[i]);
		}
	//for (int i = 0; i < n; ++i)
	//{
		//cnt[i[0] - 'A']++;
	//}
	while(true)
	{
		sort(cnt , cnt + alpa);
		reverse(cnt, cnt + alpa)	;
		int check = 1;
		if(!cnt[k - 1]) break;
		//{
			//check = 0;break;
		//if(cnt[k - 1]) {
		for (int i = 0; i < k; ++i)
		{
			cnt[i]--;
			//ans++;
		}
		ans++;
	}
		//}
		//if(check == 1) ans++;
		//else break;
	//}
	printf("%d\n", ans);
}

int main()
{
/*
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
*/
	init();

	return 0;
}

Measured memory_bytes: 256