akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0;i<n;i++)

int main() {
  int n,sum=0,r=0; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  ll ans=0;
  REP(l,n) {
    while(r < n) {
      if ((sum^a[r]) != (sum+a[r])) break;
      sum += a[r];
      r++;
    }
    ans += r-l;

    if (r == l) r++;
    sum -= a[l];
  }

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

Measured memory_bytes: 4052
# -*- coding: utf-8 -*-
import sys
import math


n = int(input())
#tmp = input().split()
#n,m,k = list(map(lambda a: int(a), tmp))

if(n%10==7):
	print("Yes")
	sys.exit()
n-=n%10
n/=10
if(n%10==7):
	print("Yes")
	sys.exit()
n-=n%10
n/=10
if(n==7):
	print("Yes")
	sys.exit()
print("No")

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

int main() {
    ll n,k,a[200010],now=0,hoge=0,r[200010],rlen=0,rend=0,clen=0,rstart=0;
    bool f[200010]={false};
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> hoge;
        hoge--;
        a[i] = hoge;
    }
    if(k<=n){
        ll piyo=0;
        for(ll i=0;i<k;i++){
            piyo = a[piyo];
        }
        cout << piyo + 1 << endl;
        return 0;
    }
    f[now]=true;
    r[clen]=now;
    clen++;
    while(1){
        now = a[now];
        r[clen] = now;
        clen++;
        if(f[now]){
            //ループ発見
            rend=now;
            break;
        }
        f[now] = true;
    }
    for(int i=0;i<clen;i++){
        if(r[i] == rend){
            rstart=i;
            break;
        }
    }
    rlen = clen - rstart - 1;
    k -= rstart;
    k %= rlen;
    cout << r[rstart+k] + 1 << endl;
    return 0;
}

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



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
   
    int k, a[3], ans = -987654321, index = -9;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    
    
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < 3; j++) {
            a[j] *= 2;
            int sum = 0;
            for (int k = 0; k < 3; k++) {
                    sum += a[k];
            }
            if (sum > ans) {
                ans = sum;
                index = j;
            }
            a[j] /= 2;
        }
        
        a[index] *= 2;
    }
    cout << ans << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    if wv[i][0]==w0:
        k=wv[i][1]+x[0][-1]
        l=len(x[0])
        if l*w0<=w:x[0].append(k)
    elif wv[i][0]==w0+1:
        k=wv[i][1]+x[1][-1]
        l=len(x[1])
        if l*(w0+1)<=w:x[1].append(k)
    elif wv[i][0]==w0+2:
        k=wv[i][1]+x[2][-1]
        l=len(x[2])
        if l*(w0+2)<=w:x[2].append(k)
    else:
        k=wv[i][1]+x[3][-1]
        l=len(x[3])
        if l*(w0+3)<=w:x[3].append(k)
#print(x)
ma=0
for i in range(len(x[3])):
    for j in range(len(x[2])):
        for k in range(len(x[1])):
            #for l in range(len(x[0])):
            d=w-(i*(w0+3)+j*(w0+2)+k*(w0+1))
            if d>=0:
                ma_sub=x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,len(x[0])-1)]
            ma=max(ma,ma_sub)
print(ma)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		StringBuilder output = new StringBuilder();

		while (true) {

			int number1 = input();
			int number2 = input();

			if (number1 < number2) {

				output.append(number1 + " " + number2);

			} else if (number2 < number1) {

				output.append(number2 + " " + number1);

			} else if (number1 ==0 && number2 == 0) {

				output.delete(output.length() -1, output.length());
				break;

			} else if (number1 == number2){

				output.append(number1 + " " + number2);

			}

			output.append("\n");

		}

		System.out.println(output);

		close();

	}

	public static int input() {

		return Integer.parseInt(scanner.next());

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 33428
// JOI13-quest1.cpp : Defines the entry point for the console application.
//

#include <stdio.h>


int main(void)
{
	int temp, sum = 0;
	for (int i = 0; i < 5; i++) {
		scanf("%d", &temp);

		if (temp >= 40) {
			sum += temp;
		}
		else {
			sum += 40;
		}
	}

	printf("%d\n", sum / 5);

	return 0;
}

Measured memory_bytes: 1028
S = input()
test = int(S[0])
count = 0

for i in range(len(S)):
    if int(S[i]) == test:
        if test == 0:
            test += 1
        elif test == 1:
            test -= 1
    else:
        count += 1
        if test == 0:
            test += 1
        elif test == 1:
            test -= 1

print(count)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

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

int main() {
  double L;
  cin >> L;
  double ans = L * L * L;
  ans /= 27;
  cout << std::setprecision(8) << std::fixed << ans << endl;
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int N;
  cin >> N;

  int count = 0;
  for (size_t i = 0; i < 4; i++) {
    if (N % 10 == 2) {
      count++;
    }
    N /= 10;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

//const int mod = 1000000007;
const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

int solve(string S){
    int N = SZ(S);
    S += '@';
    int ans = 0, cnt = 1;
    REP(i, N){
        if(S[i] != S[i + 1]){
            ans += cnt / 2;
            cnt = 1;
        }else cnt++;
    }
    return ans;
}

signed main(){

    string S; cin >> S;
    int K; cin >> K;

    bool same = true;
    for(char c: S) if(c != S[0]) same = false;

    if(same){
        cout << (S.size() * K) / 2 << endl;
    }else{
        int a1 = solve(S), a2 = solve(S + S);
        cout << a1 + (a2 - a1) * (K - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	for(ll i=0;i<=999;i++){
		ll now=i;
		ll now3=now%10;
		now/=10;
		ll now2=now%10;
		now/=10;
		ll now1=now%10;
		bool ch1=false,ch2=false,ch3=false;
		for(ll j=0;j<s.size();j++){
			ll next=s[j]-'0';
			//cout <<next<<endl;
			if(ch1==false){
				if(next==now1){
					ch1=true;
					continue;
				}
			}
			else if(ch2==false){
				if(next==now2){
					ch2=true;
					continue;
				}
			}
			else if(ch3==false){
				if(next==now3){
					ch3=true;
					ans++;
					//cout << now1<<now2<<now3<<endl;
					break;
				}
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

using namespace std;

#define ll long long

int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << W*H/2 << " " << ((W/2 == x) && (H/2 == y)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

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

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, M;
    cin >> N >> M;
    // vector<ll> A(N,0LL);
    // for (int i=0;i<N;i++) cin >> A[i];

    // while (M) {
    //     auto itr = max_element(A.begin(), A.end());
    //     *itr /= 2;
    //     M--;
    // }
    // cout << accumulate(A.begin(), A.end(), 0LL) << endl;
    multiset<ll,greater<ll>> A;
    for (int i=0;i<N;i++) {
        ll X;
        cin >> X;
        A.insert(X);
    }
    while (M) {
        auto itr = A.begin();
        ll X = *itr/2;
        A.erase(itr);
        A.insert(X);
        M--;
    }
    ll ans = 0LL;
    for (auto itr: A) {
        ans += itr;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int l = 1;
  int r = N;

  int ans = 1;

  for (int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    if (L > r || R < l) {
      ans = 0;
      break;
    }
    if (L >= l && R <= r) {
      r = min(R, r);
      l = max(L, l);
    } else if (L <= l && R >= r) {
      r = min(R, r);
      l = max(L, l);
    } else if (L <= r && R >= r) {
      r = min(R, r);
      l = max(L, l);
    } else {
      r = min(r, R);
      l = max(L, l);
    }
  }

  if (ans == 0) {
    cout << ans << endl;
    return 0;
  }

  ans = r - l + 1;
  cout << ans << endl;

};


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

int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int x_length = tx - sx, y_length = ty - sy;
	for (int y = 0; y < y_length; ++y){
		cout << "U";
	}
	for (int x = 0; x < x_length; ++x){
		cout << "R";
	}
	for (int y = 0; y < y_length; ++y){
		cout << "D";
	}
	for (int x = 0; x < x_length; ++x){
		cout << "L";
	}
	cout << "L";
	for (int y = 0; y < y_length+1; ++y){
		cout << "U";
	}
	for (int x = 0; x < x_length+1; ++x){
		cout << "R";
	}
	cout << "D";
	cout << "R";
	for (int y = 0; y < y_length+1; ++y){
		cout << "D";
	}
	for (int x = 0; x < x_length+1; ++x){
		cout << "L";
	}
	cout << "U" << endl;
	return 0;

}

Measured memory_bytes: 256
H, W = map(int,input().split())

if H == 1 or W == 1:
    print(1)
    exit()

if H % 2 == 0:
    print((H//2)*W)
else:
    if W % 2 == 0:
        print(((H-1)//2)*W + (W//2))
    else:
        print(((H-1)//2)*W + (W//2) + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    vector<int> v(3,0);
    for(int i=0;i<3;i++){
        cin>>v[i];
    }
    cout<<v[2]<<" "<<v[0]<<" "<<v[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

#N = 10000
#A = [i*2+1 for i in range(1,N+1)]

MOD = 10**9+7

sm = 0
for x in A:
  sm += pow(x,MOD-2,MOD)
  sm %= MOD

def gcd(x: int, y: int):
  while(y!=0):
    tmp = x%y
    x = y
    y = tmp
  return x

g = 1
for i in range(N):
  g = g * A[i] // gcd(g, A[i]) #pow(gcd(g, A[i]), MOD-2, MOD)
  #print(g)

an = g * sm % MOD

'''
for x in A:
  #print(g,g//x)
  an += g*pow(x,MOD-2,MOD)
  an %= MOD
  print(g,g//x,an)
'''

print(an)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi()-1,a=gi(),b=gi(),c=gi(),d=gi();
	for(int i=0;i<=n;++i){
		ll L=1ll*c*i-1ll*d*(n-i),R=1ll*d*i-1ll*c*(n-i);
		if(a+L<=b&&b<=a+R)return puts("YES"),0;
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
  
struct BIT{
    int size;
    vector<ll> dat;
    void init(int n){
        size=n;
        dat.clear();
        dat.resize(n+1);
    }
    void add(int i,ll x){
        while(i<=size){
        dat[i]+=x;
        i +=i&-i;
        }
    }
    ll sum(int i){
        ll s=0;
        while(0<i){
            s +=dat[i];
            i -=i&-i;
        }
    return s;
    }
};
int a[200001],a2[200001];
int main(){
    int n,ai;
    cin>>n;
    BIT b;
    b.init(n+1);
    ll cnt=0;
    rep(i,n){
        cin>>ai;
        a[i]=a2[i]=ai;
    }
    sort(a2,a2+n);
    rep(i,n){
        a[i]=lower_bound(a2,a2+n,a[i])-a2+1;
    }
    rep(i,n){
        cnt+=i-b.sum(a[i]);
        b.add(a[i],1);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 6024
#include<stdio.h>

int main(){
   int h,n,i;
   scanf("%d %d",&h,&n);
   int a[n];
   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
   }
   for(i=0;i<n;i++){
      h=h-a[i];
   }
   if(h<=0){
      printf("Yes");
   }else{
      printf("No");
   }
   return 0;
}

Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  string s;
  cin>>s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

R, G, B, N = [int(x) for x in stdin.readline().rstrip().split()]

cnt = 0
R, G, B = sorted([R, G, B])
RN = N // R + 1
GN = N // G + 1
BN = N // B + 1

cnt = 0
for i in range(RN):
    tmpN = N - R*i
    if tmpN % G == 0:
        cnt += 1
    for j in range(GN):
        tmpN2 = tmpN - G*j
        if tmpN2 > 0 and tmpN2 % B == 0:
            cnt += 1
    

print(cnt)

Measured memory_bytes: 66536
#include<iostream>
#include<list>
using namespace std;
#define df 0

int main(){
  if(df) printf("*debug mode*\n");
  int n,q; cin >> n >> q;
  string str; cin >> str;
  pair<char,char> query[q];
  for(auto& qr: query){
    cin >> qr.first >> qr.second;
  }
  int l=0,r=n;
  for(int i=q-1;i>=0;i--){
    char a=query[i].first,dir=query[i].second;
    if(dir=='R'){
      if(str[r-1]==a)r--;
      if(l>0 && str[l-1]==a)l--;
    }
    else{
      if(r<n && str[r]==a)r++;
      if(str[l]==a)l++;
    }
    if(df)printf("%d %d\n",l,r);
  }
  cout << r-l;
  
}

/// confirm df==0 ///


Measured memory_bytes: 900
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> ns(n);
    vector<int> xs(n), ys(n);
    for (int i = 0; i < n; i++) {
        cin >> xs[i] >> ys[i];
        ns[i] = i;
    }
    double a = 0;
    double c = 0;
    do {
        c += 1.0;
        double total = 0.0;
        for (int i = 0; i < (int)ns.size() - 1; i++) {
            double xl = (xs[ns[i]] - xs[ns[i+1]]);
            double yl = (ys[ns[i]] - ys[ns[i+1]]);
            total += sqrt(xl * xl + yl * yl);
        }
        a += total;
    } while(next_permutation(ns.begin(), ns.end()));
    printf("%.10lf\n", a / c);
    return 0;
}

Measured memory_bytes: 256
words = lambda t : list(map(t, input().split()))
s = input()

if (s[0] == s[1] and s[2] == s[3] and not(s[0] == s[2])) or (s[0] == s[2] and s[1] == s[3] and not (s[0] == s[1])) or (s[0] == s[3] and s[1] == s[2] and not (s[0] == s[1])):
   print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
X = []
while True:
    x = raw_input()
    if x == "0":
        break
    else:
        X.append(x)

ans = []
for i in range(len(X)):
    tmp = 0
    for j in range(len(X[i])):
        tmp+=int(X[i][j])
    ans.append(tmp)

for char in ans:
    print char


Measured memory_bytes: 4660
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#define maxn 1000003
using namespace std;
struct A{
	char color[maxn];
	int num;
};
int num[maxn];
int main(){
	int i, n;
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> num[i];
	}
	sort(num,num+n);
	for(i = 0; i < n-1; i++){
		if(num[i]==num[i+1]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
} 

Measured memory_bytes: 1024
using System;

namespace StudyCsharp
{
    static class Program
    {
        /// <summary>
        /// アプリケーションのメイン エントリ ポイントです。
        /// </summary>
        [STAThread]
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            Array.Sort(s);

            if (s[0] != "5")
            {
                Console.WriteLine("NO");
                return;
            }
            if (s[1] != "5")
            {
                Console.WriteLine("NO");
                return;
            }
            if (s[2] != "7")
            {
                Console.WriteLine("NO");
                return;
            }
            Console.WriteLine("YES");

        }
    }
}


Measured memory_bytes: 3032
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

void prob138() {
	int N; cin >> N;
	priority_queue<double,vector<double>,greater<double>> pq;
	for (int i = 0; i < N; i++) {
		double x;
		cin >> x;
		pq.push(x);
	}

	for (int i = 0; i < N - 1; i++) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		double z = (x + y) / 2;
		pq.push(z);
	}

	printf("%.10lf\n", pq.top());
}

void prob136() {
	int N; cin >> N;
	int max = 0, min = int_INF;
	bool flag = false;
	rep(i, N) {
		int x; cin >> x;
		if (x > max) {
			max = x; min = int_INF;
		}
		x <= min ? min = x : 1;
		if (max - min > 1) {
			flag = true;
			break;
		}
	}

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

void prob140() {
	int N; cin >> N;

}
int main() {
	prob136();
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const int N = 1e5 + 5;

long long inv[N], fact[N], ifact[N];
void pre()
{
	inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
	for (int i = 2; i < N; i++)
	{
		inv[i] = mul(MOD - MOD / i, inv[MOD % i], MOD);
		fact[i] = mul(i * 1ll, fact[i - 1], MOD);
		ifact[i] = mul(inv[i], ifact[i - 1], MOD);
	}
	return;
}

long long nCr(long long n, long long r)
{
	if (n >= 0 && r >= 0 && n >= r)
		return mul(fact[n], mul(ifact[r], ifact[n - r], MOD), MOD);
	return 0;
}
void solve(int tc)
{
	ll s;
	cin >> s;
	ll ans = 0;
	pre();
	for (int i = 1; i * 3 <= s; i++)
	{
		ll tmp = nCr(s - 2 * i - 1, i - 1);
		ans = add(ans, tmp, MOD);
	}
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 5980
N = int(input())
SP = {}
for i in range(N):
    line = input().split()
    SP[i] = [line[0], int(line[1])]
    
ans = []
for i, index in enumerate(sorted(SP.items(), key= lambda x: (x[1][0], -x[1][1]))):
    ans.append([index, i])

for ls in ans:
    print(ls[0][0] + 1)

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

#define int long long

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define len(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

string smart(vector<string> strs_) {
    vector<pii> pos, neg;
    for (auto s : strs_) {
        int bal = 0, mn = 0;
        for (auto ch : s) {
            if (ch == '(') bal++; else bal--;
            mn = min(mn, bal);
        }
        if (bal >= 0) pos.eb(bal, -mn); else neg.eb(bal, -mn);
    }
    vector<pii> kek;
    sort(all(pos), [&] (const pii &a, const pii &b) {
        return a.y < b.y;
    });
    for (auto elem : pos) kek.pb(elem);
    for (auto &elem : neg) elem.y = max(elem.y, -elem.x);
    sort(all(neg), [&] (const pii &a, const pii &b) {
        return a.x + a.y > b.x + b.y;
    });
    for (auto elem : neg) kek.pb(elem);
    int bal = 0;
    for (auto elem : kek) {
        if (bal < elem.y) return "No\n";
        bal += elem.x;
    }
    return bal == 0 ? "Yes\n" : "No\n";
}

string stupid(vector<string> strs) {
    int n = len(strs);
    vector<int> p(n);
    iota(all(p), 0);
    do {
        string s = "";
        for (int i = 0; i < len(strs); i++) s += strs[p[i]];
        int bal = 0;
        bool good = 1;
        for (auto ch : s) {
            if (ch == '(') bal++; else bal--;
            if (bal < 0) {
                good = 0;
                break;
            }
        }
        good &= bal == 0;
        if (good) return "Yes\n";
    } while (next_permutation(all(p)));
    return "No\n";
}

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

bool check(int t) {
    while (t--) {
        int n = rnd() % 3 + 1;
        vector<string> strs(n);
        for (int i = 0; i < n; i++) {
            int sz = rnd() % 4 + 1;
            string str = "";
            for (int j = 0; j < sz; j++) str.pb((rnd() & 1) ? '(' : ')');
            strs[i] = str;
        }
        auto stupid_ans = stupid(strs);
        auto smart_ans = smart(strs);
        if (stupid_ans != smart_ans) {
            cout << stupid_ans << smart_ans;
            for (auto elem : strs) cout << elem << endl;
            return 0;
        }
    }
    return 1;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> strs(n);
    for (auto &elem : strs) cin >> elem;
    cout << smart(strs);
    return 0;
}


Measured memory_bytes: 97864
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    string S;
    cin>>S;
    int N=S.length();
    string subr1,subr2;
    subr1=S.substr(0,(N-1)/2);
    subr2=S.substr((N+1)/2,(N+1)/2);
    if(subr1==subr2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	ll n, k;
	cin >> n >> k;
	if ((n-1)*(n-2)/2 >= k){
		int temp = (n-1)*(n-2)/2;
		cout << n-1 + temp - k << endl;
		for (int i = 1; i < n; i++){
			cout << n << " " << i << endl;
		}
		int coun = 0;
		if (temp - k == 0) return 0;
		for (int i = 1; i < n; i++){
			for (int j = i+1; j < n; j++){
				cout << i << " " << j << endl;
				coun++;
				if (coun == temp - k){
					return 0;
				}
			}
		}
	}else{
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;

public class Main {


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

        String temp = sc.nextLine();

        String[] tempArr = temp.split(" ");
        int A = Integer.parseInt(tempArr[0]);
        int B = Integer.parseInt(tempArr[1]);

        if (B % A == 0) {
            System.out.println(A + B);
        } else {
            System.out.println(B - A);

        }


    }

}


Measured memory_bytes: 21844
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1e17;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll ans=MOD,tmp=0,sum=Svec(v);
  rep(i,n){
    chmin(ans,abs(tmp-sum));
    tmp+=v[i];
    sum-=v[i];
  }
  chmin(ans,abs(tmp-sum));
  cout<<ans<<endl;
}


Measured memory_bytes: 3328
import java.math.*;import java.util.*;class Main{public static void main(String[]a){Scanner s=new Scanner(System.in);for(int t=s.nextInt();t-->0;){BigDecimal x;System.out.println((""+(x=s.nextBigDecimal().add(s.nextBigDecimal()))).length()>80?"overflow":x);}}}

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

typedef struct node_{
    int key;
    struct node_* left;
    struct node_* right;
}node;

node* insert(node* nd, int key){
    if(nd==NULL){
        nd = (node*)malloc(sizeof(node));
        nd->key = key;
        nd->left = NULL;
        nd->right = NULL;
    }else{
        if(key < nd->key)nd->left = insert(nd->left,key);
        else if(key > nd->key)nd->right = insert(nd->right,key);
    }
    return nd;
}

void preorder(node* nd){
    if(nd==NULL)return;
    printf(" %d",nd->key);
    preorder(nd->left);
    preorder(nd->right);
}

void inorder(node* nd){
    if(nd==NULL)return;
    inorder(nd->left);
    printf(" %d",nd->key);
    inorder(nd->right);
}

int main(){
    int i, m, key;
    char command[7];
    node* root = NULL;
    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%s",command);
        switch(command[0]){
        case 'i':
            scanf("%d",&key);
            root = insert(root,key);
            break;
        case 'p':
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
            break;
        default:
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 18252
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();
		long res = 0;
		long[] M = new long[5];
		for(int i = 0;i<5;i++) {
			M[i] = sc.nextLong();
		}
		long min = M[0];
		int num = 0;
		for(int i = 1;i<5;i++) {
			if(min>M[i]) {
				min = M[i];
				num = i;
			}
		}

		if(N%min==0) {
			res = N/min + 4;
		}else {
			res = N/min +5;
		}


		System.out.println(res);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    insert(node(x));
  }
  return 0;
}


Measured memory_bytes: 26624
/*input
2
1 1
1 1
*/

// Nihesh Anderson - knandy

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 1000000000;

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n; cin >> n;
	vector<ll> v[4];
	for(ll i = 0; i < n; i++) {
		ll x, y; cin >> x >> y;
		v[0].push_back(y - 1 + x - 1);
		v[1].push_back(x - 1 + MX - y);
		v[2].push_back(MX - x + y - 1);
		v[3].push_back(MX - x + MX - y);
	}
	for(ll i = 0; i < 4; i++) {
		sort(v[i].begin(), v[i].end());
	}
	ll ans = 0;
	for(ll i = 0; i < 4; i++) {
		ans = max(ans, v[i][n - 1] - v[i][0]);
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 9724
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

vector<int>v[100004];

vector<int> dp(100004,-1);

void dfs(int start){
	if(dp[start]!=-1) return;
	int res = 0;
	for(auto i:v[start]){
		if(dp[i]!=-1){
			res = max(res,1+dp[i]);
		}
		else{
			dfs(i);
			res = max(res,1+dp[i]);
		}
	}
	dp[start] = max(dp[start],res);
}


int main(){
	fastio();
	int n,m;
	cin>>n>>m;

	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
	}

	int ans=0;

	for(int i=1;i<=n;i++){
			dfs(i);
	}

	for(int i=1;i<=n;i++) ans = max(ans,dp[i]);

		cout<<ans;

}

Measured memory_bytes: 8832
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

vector<int> l;

int Binary_search(int n,int i,int j){
	int ok = j,ng = n;
	while(ng - ok > 1){
		int mid = (ok + ng) / 2;
		if(l[mid] + l[j] > l[i]) ok = mid;
		else ng = mid;
	}
	return ok;
}
	
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	l.resize(n);
	rep(i,n){
		cin >> l[i];
	}
	sort(all(l),greater<int>());
	int cnt = 0;
	for(int i = 0;i < n-2;++i){
		for(int j = i+1;j < n-1;++j){
			cnt += Binary_search(n,i,j) - j;
		}
	}
	cout << cnt << '\n';
	return 0;
}


Measured memory_bytes: 256
import itertools
import copy
from collections import deque
import heapq
h,w,k = map(int,input().split())
c = [list(input()) for i in range(h)]
#print(c)
ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        ans_check = 0
        h_c = {}
        w_c = {}
        for check in range(h):
            if ((i >> check) & 1):
                h_c[check] = 0
        for check in range(w):
            if ((j >> check) & 1):
                w_c[check] = 0
        #print(h_c,w_c)
        for hc,n in enumerate(c):
            if not hc in h_c:
                continue
            for wc,m in enumerate(n):
                if not wc in w_c:
                    continue
                if m == "#":
                    ans_check += 1
        #print(ans_check)
        if ans_check == k:
            ans += 1
print(ans)

Measured memory_bytes: 9628
def dfs(u, color):
    global c
    global g
    s = [u]
    c[u] = color
    while 0 < len(s):
        ch = s.pop()
        for ch in g[ch]:
            u_c = c[ch]
            if u_c is None:
                c[ch] = color
                s.append(ch)

def colorize():
    global g
    global c
    global n
    color = 1
    for i in range(n):
        if c[i] == None:
            dfs(i, color)
            color += 1

n, m = list(map(int, input().split()))

g = [[] for i in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    g[s].append(t)
    g[t].append(s)

c = [None for i in range(n)]

colorize()

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    if c[s] == c[t]:
        print("yes")
    else:
        print("no")

Measured memory_bytes: 32792
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
	int H, W;

	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;

		for (int i = 0; i < H; i++) {
			if (i == 0 || i == H - 1) {
				for (int j = 0; j < W; j++) {
					cout << "#";
				}
			}
			else {
				cout << "#";
				for (int j = 0; j < W - 2; j++) {
					cout << ".";
				}
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) {
        cout << k << endl;
        return 0;
    } else if (k <= a + b) {
        cout << a << endl;
        return 0;
    } else {
        cout << a - (k - a - b) << endl;
        return 0;
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

typedef pair<ll, ll> P;


bool solve() {

  int N = nextInt();
  vector<P> p(N);
  REP(i, N) {
    ll A = nextInt();
    ll B = nextInt();
    p[i] = {B, A};
  }
  sort(ALL(p));

  ll t = 0;
  REP(i, p.size()) {
    t += p[i].second;
    if (t > p[i].first) return false;
  }
  return true;
}

int main2() {

  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, double> P;

int main() {
  int n;
  cin >> n;
  vector<P> xy(n);
  for (int i = 0; i < n; ++i) cin >> xy[i].first >> xy[i].second;

  vector<int> indices(n);
  iota(indices.begin(), indices.end(), 0);

  int cnt = 0;
  double sum = 0;
  do {
    cnt++;
    for (int i = 0; i < n - 1; ++i) {
      double x = xy[indices[i]].first - xy[indices[i + 1]].first;
      double y = xy[indices[i]].second - xy[indices[i + 1]].second;
      sum += sqrt(x * x + y * y);
    }
  } while (next_permutation(indices.begin(), indices.end()));
  double ans = sum / cnt;
  cout << fixed << setprecision(10) << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>){
  
  val (a,op,b) = readLine()!!.split(" ")
  val ans = when(op){
              "+" -> { a.toInt() + b.toInt() }
              "-" -> { a.toInt() - b.toInt() }
             else -> { 0 }
            }
  
  println(ans)
      
}

Measured memory_bytes: 37876
#include <stdio.h>
int main(void)
{
  int a,b,ans=0;
  char c;
  scanf("%d",&a);
  scanf("%c",&c);
  if(c!=('+' || '-'))
  {
    scanf("%c",&c);
  }
  scanf("%d",&b);
  if(c=='+')
  {
    ans=a+b;
  }
  else if(c=='-')
  {
    ans=a-b;
  }
  printf("%d\n",ans);
  return 0;
}


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

typedef long long ll;
ll n,k;
ll cnt[1919191];

int main()
{
	ll ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cnt[i%k]++;
	for(int i=1;i<=n;i++)
	{
		ll num1=(k-(i%k))%k;
		ll num2=(k-(num1%k))%k;
		if(num1==num2) ans+=cnt[num1]*cnt[num2];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	while(cin>>a){
		int l=0,o=0;
		for(int i=0;i<a.length();i++){
			if(a[i]=='0')o++;
			else l++;
		}
		cout<<min(l,o)*2<<endl;
	}
} 

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
bool sameDigit(string n){
	return (n[0]==n[1] and n[1] ==n[2]);
}
int main(){
	int n;
	cin>>n;
	while(!sameDigit(to_string(n))){
		n++;
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    y = [0]*(n+1)
    res = 0
    for i in range(1,n+1):
        j = 1
        while True:
            if i*j > n:
                break
            y[i*j] += 1
            j += 1
        res += i*y[i]
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 151384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

char s[N];
int n;

int main(){
	scanf("%s", s); n = strlen(s);
	int uk = 0;
	for(int i = 0;i < n;i++){
		if(s[i] == 'D' || s[i] == '?') 
			printf("D");
		else
			printf("P");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 3808
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
struct Main {}

#[allow(dead_code)]
impl Main {}

fn main() {
    let s: String = read();
    let q: usize = read();
    let mut res: VecDeque<String> = VecDeque::new();
    for s_one in s.chars() {
        res.push_back(s_one.to_string());
    }
    let mut rvs = false;
    for _ in 0..q {
        let q1: u32 = read();
        if q1 == 1 {
            rvs = !rvs;
        } else {
            let q2: u32 = read();
            let q3: String = read();
            if q2 == 1 {
                if !rvs {
                    res.push_front(q3);
                } else {
                    res.push_back(q3);
                }
            } else {
                if !rvs {
                    res.push_back(q3);
                } else {
                    res.push_front(q3);
                }
            }
        }
    }
    // println!("{:?}", res);
    let mut res_str = "".to_string();
    if !rvs {
        for s in res.iter() {
            res_str.push_str(s.as_str());
        }
    } else {
        for s in res.iter().rev() {
            res_str.push_str(s.as_str());
        }
    }
    println!("{}", res_str);
}


Measured memory_bytes: 17144
p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * W[l] % p

def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j+d] *= u
                f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * iW[l] % p

def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print(*convolve(A, B))


Measured memory_bytes: 197164
#include<stdio.h>
int main(void)
{
int W,H,x,y,r,f;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

f=0;
if(x+r>W)f=1;
if(y+r>H)f=1;
if(r>x)f=1;
if(r>y)f=1;

if(f==0)
printf("Yes\n");
else
printf("No\n");

return 0;
}




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

using namespace std;



int main() {
  int a, b;
  cin >> a >> b;
  for (int c = 1; c <= 3; ++c) {
    if (a*b*c%2) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256