akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    long double a, b, c;
    cin >> a >> b >> c;
    long double res = 2 * sqrt(a) * sqrt(b);
    if(a+b+res < c) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end



int main(){
    int n; scanf("%d",&n);
    vector<int> a(n);
    rep(i,0,n)scanf("%d",&a[i]);
    int rui[2010]={};
    rep(i,0,n)rui[a[i]]++;
    rep(i,0,2005)rui[i+1]+=rui[i];
    ll ans=0;
    rep(i,0,n)rep(j,i+1,n){
        int ma=max(a[i],a[j]),mi=min(a[i],a[j]);
        int lb=max(ma-mi,0),rb=ma+mi;
        int add=rui[rb-1]-rui[lb];
        if(lb<a[i]&&a[i]<rb)add--;
        if(lb<a[j]&&a[j]<rb)add--;
        ans+=add;
    }
    printf("%lld\n",ans/3);
    return 0;
}

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


int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n)
    cin >> s[i];
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  cout << s.size() << endl;
  return 0;
}

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

int n, k;
int x[51], y[51];
void solve()
{
    int n, k;
    cin >> n >> k;
    int x[n], y[n];
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
        a[i] = x[i];
        b[i] = y[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans = LLONG_MAX;
    for(int h = 0; h < n; h++){
        for(int low = n-1; low >= 0; low--){
            if(b[h] <= b[low]) continue;
            for(int r = n-1; r >= 0; r--){
                for(int l = 0; l < n; l++){
                    if(a[l] >= a[r]) continue;
                    int in = 0;
                    for(int i = 0; i < n; i++){
                        if(a[l] <= x[i] && x[i] <= a[r] && b[low] <= y[i] && y[i] <= b[h]) in++;
                    }
                    if(in >= k) ans = min(ans, (ll)(a[r] - a[l])*(ll)(b[h] - b[low]));
                }
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	std::int64_t N, A, B;
	std::cin >> N >> A >> B;
	auto c = N / (A + B);
	auto a = c * A;
	auto r = N - c * (A + B);
	std::cout << (a + std::min(A, r)) << std::endl;
}

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

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;

int n;
int f[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        f[i] = f[i - 1] + 1;
        int k = 6, t = k;
        while(i >= t)
        {
            f[i] = min(f[i], f[i - t] + 1);
            t = t * k;
        }

        k = 9, t = k;
        while(i >= t)
        {
            f[i] = min(f[i], f[i - t] + 1);
            t = t * k;
        }
    }

    cout << f[n] << endl;
    return 0;
}


Measured memory_bytes: 640
/*
                                                                                                                                               
8b        d8                           888888888888                                             88b           d88                  ad88888ba   
 Y8,    ,8P                                 88                                        ,d        888b         d888                 d8"     "8b  
  Y8,  ,8P                                  88                                        88        88`8b       d8'88                 ""      a8P  
   "8aa8"  ,adPPYba,   88       88          88  8b,dPPYba,  88       88  ,adPPYba,  MM88MMM     88 `8b     d8' 88   ,adPPYba,          ,a8P"   
    `88'  a8"     "8a  88       88          88  88P'   "Y8  88       88  I8[    ""    88        88  `8b   d8'  88  a8P_____88         d8"      
     88   8b       d8  88       88          88  88          88       88   `"Y8ba,     88        88   `8b d8'   88  8PP"""""""         ""       
     88   "8a,   ,a8"  "8a,   ,a88          88  88          "8a,   ,a88  aa    ]8I    88,       88    `888'    88  "8b,   ,aa         aa       
     88    `"YbbdP"'    `"YbbdP'Y8          88  88           `"YbbdP'Y8  `"YbbdP"'    "Y888     88     `8'     88   `"Ybbd8"'         88       
                                                                                                                                               
*/
#include <bits/stdc++.h>
using namespace std;

long long l, r;

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> l >> r;
	if ((r - l >= 2019) || ((l % 2019) > (r % 2019))) cout << 0 << '\n';
	else {
		l %= 2019;
		r %= 2019;

		long long ans = 1e18;
		for (long long i = l; i <= r; i++) {
			for (long long j = i + 1; j <= r; j++) {
				ans = min(ans, (i * j) % 2019);
			}
		}

		cout << ans << '\n';
	}

	return 0;
} 

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

using namespace std;
typedef long long ll;

#define MAX_N 10000
int a[MAX_N];

int main() {

  // -----------------------------
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  // input
  int H, N;
  cin >> H >> N;

  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  // -----------------------------

  for (int i = 0; i < N; i++) {
    H = H - A[i];
    if (H <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }  

  cout << "No" << endl;
  
  return 0;
  
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1e6+10,mo=998244353;
int cnt[N],miu[N],n,fr[N],pr[N],x,M=1e6;
ll sum[N],inv[N],jc[N],ny[N];
ll power(ll a,ll b=mo-2){
	ll ans=1;
	while (b){
		if (b&1)ans=ans*a%mo;
		a=a*a%mo;
		b>>=1;
	}return ans;
}
void prep(int n=1e6){
	miu[1]=jc[1]=jc[0]=1;
	for (int i=2;i<=n;i++){
		jc[i]=jc[i-1]*i%mo;
		if (!pr[i]){
			miu[i]=-1;
			for (int j=i;j<=n;j+=i)pr[j]=1,fr[j]=fr[j]?fr[j]:i;
		}
		else{
			if (fr[i]==fr[i/fr[i]])miu[i]=0;
			else miu[i]=-miu[i/fr[i]];
		}
	}
	ny[n]=power(jc[n])%mo;
	for (int i=n;i;i--)ny[i-1]=ny[i]*i%mo,inv[i]=ny[i]*jc[i-1]%mo;
}
int main(){
	prep();
	cin>>n;
	ll ans=0;
	for (int i=1;i<=n;i++)scanf("%lld",&x),cnt[x]++,ans-=x;
	for (int i=1;i<=M;i++){
		for (ll j=i;j<=M;j+=i)sum[i]+=j*cnt[j];
		sum[i]%=mo;
		sum[i]=sum[i]*sum[i]%mo;
	}
	for (int i=1;i<=M;i++){
		for (int j=2;i*j<=M;j++)sum[i]+=miu[j]*sum[i*j];
		ans=(ans+sum[i]%mo*inv[i])%mo;
	}
	cout<<(ans+mo)*inv[2]%mo<<endl;
}


Measured memory_bytes: 47104
n = gets.to_i
string = gets
arr = []
mod = n % 26
string.each_char do |st|
  val = st.ord + mod
  if val > 90
    arr.push(('A'.ord + val - 90 - 1).chr)
  else
    arr.push((st.ord + mod).chr)
  end
end

arr.pop

print arr.join('')

Measured memory_bytes: 2428
/*input
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define INF 0x3f3f3f3f
#define mod 1000000007LL

int n;
string a , b;
int32_t main(){
    IOS;
    cin >> n >> a >> b;

    int ans , pos , type;
    if(a[0] == b[0]) ans = 3 , pos = 1 , type = 1;
    if(a[0] != b[0]) ans = 6 , pos = 2 , type = 2;

    while(pos < a.size()){
        if(a[pos] == b[pos]){
            if(type == 1) ans = (ans * 2) % mod;
            if(type == 2) ;
            type = 1 , pos ++;
        }
        else {
            if(type == 1) ans = (ans * 2) % mod;
            if(type == 2) ans = (ans * 3) % mod;
            type = 2 , pos += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

using ll = long long;

int main()
{
    int N;
    scanf("%d\n", &N);
    vector<int> A(N);
    for (int i = 0; i < N; ++i){
        int Ai;
        scanf("%d", &Ai); getchar();
        A[i] = Ai;
    }
    vector<unordered_set<int>> edges(N);
    for (int i = 0; i < N - 1; ++i){
        int ai, bi;
        scanf("%d %d\n", &ai, &bi); --ai; --bi;
        edges[ai].emplace(bi);
        edges[bi].emplace(ai);
    }
    int root = 0;
    while (root < N && edges[root].size() == 1) ++root;
    if (root == N){
        if (N == 2){
            if (A[0] == A[1]){
                puts("YES");
            }else{
                puts("NO");
            }
        }
        return 0;
    }
    bool contradict_flag = false;
    function<ll(int, int)> check = [&](int node, int parent) -> ll {
        if (edges[node].size() == 1) return A[node];
        ll leaf_sum = 0;
        vector<ll> children;
        for (auto& edge : edges[node]){
            if (edge == parent) continue;
            children.emplace_back(check(edge, node));
            leaf_sum += children.back();
            if (contradict_flag) return 0;
        }
        if (!(A[node] <= leaf_sum && leaf_sum <= A[node] * 2)){
            contradict_flag = true;
            return 0;
        }
        ll inner_count = 0;
        for (auto& child : children){
            inner_count += min(child, leaf_sum - child);
        }
        if (inner_count < (leaf_sum - A[node]) * 2) contradict_flag = true;
        return A[node] * 2 - leaf_sum;
    };
    if (check(root, root) == 0 && !contradict_flag){
        puts("YES");
    }else{
        puts("NO");
    }
}


Measured memory_bytes: 26368
S=input()
T=input()

for i in range(-1,len(T)-len(S)-2,-1):
  f=1
  for j in range(-1,-1*len(T)-1,-1):
    if S[i+j+1]==T[j] or S[i+j+1]=="?":pass
    else:f=0
  if f==1:
    S=list(S)
    for j in range(-1,-1*len(T)-1,-1):
      S[i+j+1]=T[j]
    for k in range(len(S)):
      if S[k]=="?":S[k]="a"
    print("".join(S))
    exit(0)
print("UNRESTORABLE")

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n;
	ll a, b;
	cin >> n >> a >> b;
	vector<int> x(n);
	for(int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	
	ll cost = 0;
	for(int i = 0; i < n - 1; i++) {
		cost += min(b, (x[i + 1] - x[i]) * a);
	}
	
	cout << cost << "\n";
	return 0;
}


Measured memory_bytes: 640
/**
*    created: 09.07.2020 00:36:04
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#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++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    string a, s, d; cin >> a >> s >> d;
    cout << char(toupper(a[0])) << char(toupper(s[0])) << char(toupper(d[0])) << endl;
    return 0;
}

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

constexpr const int N = 2e5 + 10;

using ll = long long;

int n;
ll a[N];
map<ll, ll> ms;

int main() {
    cin >> n;

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

    ll res = 0;

    for (auto it : ms) {
        ll cnt = it.second;

        if (cnt >= 2) {
            res += cnt * (cnt - 1LL) / 2LL;
        }
    }

    for (int i = 0; i < n; ++i) {
        ll ans = 0;

        if (ms[a[i]] >= 2) {
            ans = res - ms[a[i]] * (ms[a[i]] - 1LL) / 2LL;
            ans += (ms[a[i]] - 1LL) * (ms[a[i]] - 2LL) / 2LL;
        }
        else {
            ans = res;
        }

        printf("%lld\n", ans);
    }

    return 0;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    vector<int> v(5);
    rep(i,5) cin>>v[i];
    sort(v.begin(),v.end());
    int ans = inf;
    do{
        int now = 0;
        for(int i = 0;i<5;i++){
            now += v[i];
            if(i==4) break;
            while(now%10!=0){
                now++;
            }
        }
        ans = min(ans,now);
    }while(next_permutation(v.begin(),v.end()));
    cout<< ans << endl;
    return 0;
}


Measured memory_bytes: 256
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 2e5 + 5;

int n;
int arr[N];
pair<int, int> st[N << 2];

void build(int cur, int s, int e) {
  if(s == e) {
    st[cur] = { arr[s], s };
    return;
  }
  int mid = (s + e) / 2;
  int l = 2 * cur + 1;
  int r = 2 * cur + 2;
  build(l, s, mid);
  build(r, mid + 1, e);
  st[cur] = min(st[l], st[r]);
}

pair<int, int> query(int cur, int s, int e, int i, int j) {
  if(s > j || e < i) return {n + 1, 0};
  if(s >= i && e <= j) return st[cur];
  int mid = (s + e) / 2;
  int l = 2 * cur + 1;
  int r = 2 * cur + 2;
  return min(query(l, s, mid, i, j), query(r, mid + 1, e, i, j));
}

long long solve(int s, int e) {
  if(s > e) return 0;
  pair<int, int> q = query(0, 0, n - 1, s, e);
  int idx = q.second;
  int val = q.first;
  return 1LL * (idx - s + 1) * (e - idx + 1) * val + solve(s, idx - 1) + solve(idx + 1, e);
}

int main()
{
  cin >> n;
  for(int i = 0 ; i < n ; i++)
    cin >> arr[i];
  build(0, 0, n - 1);
  cout << solve(0, n- 1) << endl;
  return 0;
}


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

int main(){

    int n,k;
    cin>>n>>k;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l.begin(),l.end(),greater<int>());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=l[i];
    }
    cout<<ans<<endl;




    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long A[2<<17],B[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	long ans=0;
	for(int t=0;t<400;t++)
	{
		for(int i=t&1;i<N;i+=2)
		{
			long s=B[(i+N-1)%N]+B[(i+1)%N];
			long t=(B[i]-A[i])/s;
			ans+=t;
			B[i]-=t*s;
		}
	}
	for(int i=0;i<N;i++)
	{
		if(A[i]!=B[i])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define N 300001
typedef long long ll;
typedef long double ld;
 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

#define eps 1e-9

int main()
{
	fastIO;
	
	int n, ans = 0;
	double d, x, y;

	cin >> n >> d;
	for(int i = 0; i < n; i++) 
	{
		cin >> x >> y;
		if(sqrt(x*x + y*y) <= d)
			ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3860
#include<iostream>
#include<vector>
//#include<string>
//#include<queue>
//#include<set>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef double db;
const int MOD = 1e9 + 7;
vector<int> f, inv;
int pow_bin(int a, int b)
{
	int t = 1;
	while (b > 0)
	{
		if (b & 1)
			t = 1ll * t * a % MOD;
		a = 1ll * a * a % MOD;
		b >>= 1;
	}
	return t;
}
int nPk(int n, int k)
{
	return 1ll * f[n] * inv[n - k] % MOD;
}
int nCk(int n, int k)
{
	return 1ll * f[n] * inv[k] % MOD * inv[n - k] % MOD;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	f.resize(m + 1);
	inv.resize(m + 1);
	f[0] = 1;
	for (int i = 1; i <= m; ++i)
		f[i] = 1ll * f[i - 1] * i % MOD;
	inv[m] = pow_bin(f[m], MOD - 2);
	for (int i = m - 1; i >= 0; --i)
		inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
	int total = nPk(m, n);
	int remain = total;
	for (int i = 1; i <= n; ++i)
	{
		int sub = 1ll * nCk(n, i) * nPk(m - i, n - i) % MOD;
		if (i & 1)
			remain = (1ll * remain + MOD - sub) % MOD;
		else
			remain = (1ll * remain + sub) % MOD;
	}
	cout << 1ll * total * remain % MOD;
	return 0;
}

Measured memory_bytes: 7072
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
//x,yがax+by=gcd(a,b)の解になる
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
//aのmod mでの逆元を求める
ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}
const int N_MAX = 1 << 20;
ll p[N_MAX];
void init() {
	p[0] = 1;
	rep1(i, N_MAX - 1) {
		p[i] = p[i - 1] * i%mod;
	}
}
//xCyを求める
ll comb(ll x, ll y, ll m) {
	if (x < y)return 0;
	ll res = p[x];
	(res *= mod_inverse(p[y], m)) %= mod;
	(res *= mod_inverse(p[x - y], m)) %= mod;
	return res;
}
ll comb2(ll x, ll y) {
	if (x < y)return 0;
	ll res = comb(x, y, mod);
	res = res * p[y] % mod;
	return res;
}
vector<P> v;
int a[1000], b[1000];
int c[2];
int main() {
	init();
	int n, m; cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		v.push_back({ a[i],0 });
	}
	rep(i, m) {
		cin >> b[i];
		v.push_back({ b[i],1 });
	}
	bool valid = true;
	sort(a, a + n);
	sort(b, b + m);
	rep(i, n - 1) {
		if (a[i] == a[i + 1])valid = false;
	}
	rep(i, m - 1) {
		if (b[i] == b[i + 1])valid = false;
	}
	if (!valid) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	sort(v.begin(), v.end());
	int sum = 0;
	rep(i, n+m-1) {
		if (v[i].first == v[i + 1].first) {
			int rest = m - c[1] - 1 + n - c[0] - 1;
			int num = v[i].first;
			c[0]++; c[1]++;
			ans = ans * comb2(num - 1 - sum, rest) % mod;
			sum += rest + 1;

			i++;
		}
		else {
			int id = v[i].second;
			int num = v[i].first;
			int rest = 0;
			if (id == 0) {
				rest = m - c[1];
			}
			else {
				rest = n - c[0];
			}
			c[id]++;
			ans = ans * rest%mod; rest--;
			ans = ans * comb2(num -1- sum, rest) % mod;
			sum += rest+1;
		}
	}
	cout << ans << endl;
	//stop
		return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
#include <string.h>

int main(){

  int n,i,x=0,max=0;
  char s[110];

  scanf("%d",&n);

  scanf("%s",&s);

  for(i=0;i<n;i++){
    if(s[i]=='I') x++;
    if(s[i]=='D') x--;
    if(max<x) max=x;
    }
  printf("%d\n",max);
  return 0;
}


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

typedef long long ll;

int main()
{
   int n,i,a[1005]={0},sum=0;
   cin>>n;
   for(i=0;i<n;i++)
   {
      cin>>a[i];
      sum+=a[i];
   }
   sort(a,a+n);
   if(sum%10!=0)
   {
       cout<<sum;
   }
   else
   {
       for(i=0;i<n;i++)
       {
           if((sum-a[i])%10!=0)
           {
               cout<<sum-a[i];
               return 0;
           }
       }
       cout<<"0";
   }
   return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))

dp =[0]*n
dp[1] = abs(h[1] -h[0])
for i in range(2,n):
    #print(dp)
    if dp[i-1] + abs(h[i]-h[i-1]) > dp[i-2] + abs(h[i]-h[i-2]):
        dp[i] = dp[i-2] + abs(h[i]-h[i-2])
    else:
        dp[i] = dp[i-1] + abs(h[i]-h[i-1])
#print(dp)
print(dp[-1])

Measured memory_bytes: 20440
#135 ABC
N = int(input()) # sを取得し、strに値を入れる
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum=0


for i in range(0, N):
	if (A[i] >= B[i]): sum += B[i]
	else:
		if(A[i+1] >= B[i]-A[i]):
			sum += B[i]
			A[i+1] = A[i+1] - (B[i]-A[i])
		else:
			sum += A[i]+A[i+1]
			A[i+1] = 0

print(sum)

Measured memory_bytes: 18476
using System;

class Program {
    private static int Main() {
        do {
            var input = Console.ReadLine();
            var values = input.Split( ' ' );

            int x = int.Parse( values[ 0 ] );
            int y = int.Parse( values[ 1 ] );

            if( x == 0 && y == 0 ) { break; }

            if( x > y ) {
                var tmp = x;
                x = y;
                y = tmp;
            }

            var output = string.Format( "{0} {1}", x, y );
            Console.WriteLine( output );
        } while( true );

        return 0;
    }
}

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

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

    int ans = 0;
    for (char i = 0; i < 10; i++)
    {
        for (char j = 0; j < 10; j++)
        {
            for (char k = 0; k < 10; k++)
            {
                vector<char> target = vector<char>{(char)('0' + i), (char)('0' + j), (char)('0' + k)};
                int current = 0;
                for (char s : S)
                {
                    if (s == target[current])
                    {
                        current++;
                        if (current == 3)
                        {
                            ans++;
                            break;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[] coins = new int[18]; // do not use [0].
    int pattern;

    void run(){
	for(int i=0; i<coins.length; i++)
	    coins[i] = i*i;

	while(sc.hasNext()){
	    int n = sc.nextInt();
	    if(n!=0){
		int level = coins.length-1;
	        pattern = 0;
		while(coins[level]>n) level--;
		solve(n, level);
		System.out.println(pattern);
	    }
	}
    }

    void solve(int n, int level){
	//System.out.println("*"+n+" "+level);
	if(level==0) return;	

	// 使わずに次へ
	solve(n, level-1);

	// 使ってから、もう一枚!or次へ
	n -= coins[level];
	if(n==0) {
	    pattern++;
	    return;
	}
	if(n>=coins[level]) solve(n, level);
	else solve(n, level-1);
    }
}

Measured memory_bytes: 19656
/*-------------------------*/
/*      D-SavePostman      */
/*       by darsein        */
/* AC: O(k^2*3^k + kmlogn) */
/*-------------------------*/

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> edge;
typedef vector< vector<edge> > graph;

const ll INF = 1e15;

int main(){
  int n,m,k,p;
  cin >> n >> m >> k >> p; p--;
  
  graph g(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin >> a >> b >> c; a--; b--;
    g[a].push_back(edge(c,b));
    g[b].push_back(edge(c,a));
  }

  vector<int> v_list;
  v_list.push_back(p);

  vector<int> drop(k), goal(k);
  for(int i=0;i<k;i++){
    cin >> drop[i] >> goal[i];
    drop[i]--; goal[i]--;

    v_list.push_back(drop[i]);
    v_list.push_back(goal[i]);
  }

  int kn = 2*k+1;
  vector< vector<ll> > adj(kn, vector<ll>(kn,INF));

  for(int i=0;i<kn;i++){
    int v = v_list[i];

    vector<ll> d(n,INF);
    d[v] = 0;
    priority_queue< edge,vector<edge>,greater<edge> > q;
    q.push(edge(0,v));
    
    while(q.size()){
      ll dis = q.top().first, cur = q.top().second; q.pop();
      if(d[cur] < dis)continue;
      
      for(edge e : g[cur]){
	ll ndis = dis + e.first, nxt = e.second;
	if(d[nxt] > ndis){
	  d[nxt] = ndis;
	  q.push(edge(ndis,nxt));
	}
      }
    }
    for(int j=0;j<kn;j++){
      adj[i][j] = d[v_list[j]];
    }
  }

  vector<ll> pow3(k+1);
  pow3[0] = 1;
  for(int i=0;i<k;i++)pow3[i+1] = pow3[i] * 3;

  vector< vector<ll> > dp(kn, vector<ll>(pow3[k],INF) );
  dp[0][0] = 0;

  for(int bit=0;bit<pow3[k];bit++){
    for(int i=0;i<kn;i++){
      for(int j=0;j<kn;j++){
	if(adj[i][j] == INF)continue;

	int nbit = bit, x = (j-1)/2;
	if( j!=0 && j%2==1 ){
	  if( (bit/pow3[x])%3 == 0 ){
	    nbit += pow3[x];
	  }
	}
	if( j!=0 && j%2==0 ){
	  if( (bit/pow3[x])%3 == 1 ){
	    nbit += pow3[x];
	  }
	}

	dp[j][nbit] = min(dp[j][nbit], dp[i][bit] + adj[i][j]);
      }
    } 
  }

  ll ans = INF;
  for(int i=0;i<kn;i++)ans = min(ans, dp[i][pow3[k]-1]);
  if(ans == INF)cout << "Cannot deliver" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 1436
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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() {
  ll l, r;
  cin >> l >> r;
  ll ans = INF;
  for (ll i = l; i < r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      ans = min(ans, i * j % 2019);
      if (ans == 0) {
        P(ans);
        return 0;
      }
    }
  }
  P(ans);

  return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n,m,x,s[1001],d[1000];
int main()
{
while(1){
	cin>>n>>m;
	if(!n&&!m) return 0;
	x=1;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	for(int i=0;i<m;i++) cin>>d[i];
	for(int i=0;;i++){
		x+=d[i];
		if(x>=n) {cout<<i+1<<endl; break;}
		x+=s[x];
		if(x>=n) {cout<<i+1<<endl; break;}
	}
}

}

Measured memory_bytes: 1168
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 1e5 + 5;

bool vis[N];
vector <int> adj[N];

void dfs(int r) {
  vis[r] = 1;
  for(auto i : adj[r]) {
    if(!vis[i]) dfs(i);
  }
}

void solve() {
  int n, m;

  cin >> n >> m;

  for(int i = 1; i <= m; i++) {
       int x, y; cin >> x >> y;
       adj[x].pb(y);
       adj[y].pb(x);
  } 
  
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(!vis[i]) {
      dfs(i);
      ans++;
    }
  }
  
  ans--;

  cout << ans << '\n';
}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; // cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/

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

int main(){
    ll N;
    cin >> N;
    ll c0;
    cin >> c0;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    if (c0 == 1){
        if (N != 0) cout << -1 << endl;
        else cout << 1 << endl;
    }
    else if (c0 != 0){
        cout << -1 << endl;
    }
    else{
        ll bunki_max = 0;
        bool possible = true;
        rep(i,N){
            bunki_max += vec[i];
        }
        bunki_max -= 1;
        ll dankai = 1;
        ll bunki_kaisuu = 0;
        ll ans = 1;
        rep(i,N){
            if (i == N - 1 && vec[i] == 0){
                possible = false;
            }
            else if (vec[i] > dankai * 2){
                possible = false;
                break;
            }
            else{
                if (bunki_max - bunki_kaisuu >= dankai){
                    bunki_kaisuu += dankai;
                    dankai *= 2;
                }
                else if (bunki_max - bunki_kaisuu < dankai){
                    dankai += (bunki_max - bunki_kaisuu);
                    bunki_kaisuu = bunki_max;
                }
                
                ans += dankai;
                dankai -= vec[i];
            }
        }
        if (possible) cout << ans << endl;
        else cout << -1 << endl;
    }
}

Measured memory_bytes: 4060
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [a, b, c] <- getLine
    [e, f, g] <- getLine
    let ps = [ a == g
            , b == f
            , c == e
            ]
    if and ps
        then putStrLn "YES"
        else putStrLn "NO"

Measured memory_bytes: 380
#include<stdio.h>
int main()
{
	int x, y, temp;
	while (1)
	{
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0)break;
		else if (x > y)
		{
			temp = x;
			x = y;
			y = temp;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}


Measured memory_bytes: 2604
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
arr=list(map(int,input().split()))
lgcd=[arr[0]]
rgcd=[arr[-1]]

if n==2:
  print(max(arr[0],arr[1]))
elif n==3:
  print(max(gcd(arr[0],arr[1]),gcd(arr[1],arr[2]),gcd(arr[2],arr[0])))
else:
  tmp=arr[0]
  for i in range(1,n-1):
    lgcd.append(gcd(tmp,arr[i]))
    tmp=gcd(tmp,arr[i])
  tmp=arr[-1]
  for i in range(n-2,0,-1):
    rgcd.append(gcd(tmp,arr[i]))
    tmp=gcd(tmp,arr[i])
  rgcd=rgcd[::-1]
  ans=0
  for i in range(n):
    if i==0:
      tmp=rgcd[0]
    elif i==n-1:
      tmp=lgcd[-1]
    else:
      tmp=gcd(rgcd[i],lgcd[i-1])
    if tmp>ans:
      ans=tmp
  print(ans)

Measured memory_bytes: 14400
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int res = 0;
    FOR(i, 1, n-1) {
        string a = s.substr(0, i);
        string b = s.substr(i, s.size()-i);
        set<char> a_set;
        set<char> b_set;
        for(char c:a){a_set.insert(c);}
        for(char c:b){b_set.insert(c);}
        int tmp = 0;
        for(char c:b_set) {
            if (a_set.find(c) != a_set.end()) {
                tmp++;
            }
        }
        res = max(res, tmp);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

def solve2(x,y):
    if x==n:
        S[y] = 1
    else:
        solve2(x+1,y)
        if y+A[x] < 2001:
            solve2(x+1,y+A[x])
            
S = [0 for i in range(2001)]

solve2(0,0)

def solve(x,y):
    if y<0:
        return False
    elif y==0:
        return True
    elif x==n:
        return False
    else:
        return solve(x+1,y) or solve(x+1,y-A[x])
    
for i in range(m):
    if (i>50 and (S[B[i]] == 1)):
        print("yes")
    elif (i>50 and (S[B[i]] == 0)):
        print("no")
    else:
        if solve(0,B[i]):
            print("yes")
        else:
            print("no")


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

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		String word=in.nextLine(),str = in.nextLine()+" ";
		while(true) {
			String tstr=in.nextLine();
			if(tstr.equals("END_OF_TEXT"))break;
			str+=tstr+" ";
		}
		word=word.toUpperCase(); str=str.toUpperCase();
		
		String words[]=str.split(" ");
		//for(int i=0;i<words.length;i++)out.println(words[i]);
		int cnt=0;
		
		for(int i=0;i<words.length;i++) {
			if(words[i].equals(word))cnt++;
		}
		out.println(cnt);
		out.flush();
	}

}



Measured memory_bytes: 26220
#include <iostream>

using namespace std;

int n = 0, heap[2000001];

void maxHeapify(int i) {
    int l = i * 2;
    int r = i * 2 + 1;
    int maxi = i;
    if (l <= n && heap[l] > heap[maxi])
        maxi = l;
    if (r <= n && heap[r] > heap[maxi])
        maxi = r;
    if (i != maxi) {
        swap(heap[i], heap[maxi]);
        maxHeapify(maxi);
    }
}

void insert(int v) {
    int i = ++n;
    heap[i] = v;
    while (i > 1 && heap[i] > heap[i / 2]) {
        swap(heap[i], heap[i / 2]);
        i /= 2;
    }
}

int extract() {
    int ret = heap[1];
    swap(heap[1], heap[n--]);
    maxHeapify(1);
    return ret;
}

int main() {
    int v;
    string s;
    while (1) {
        cin >> s;
        if (s == "insert") {
            cin >> v;
            insert(v);
        }
        if (s == "extract") {
            cout << extract() << endl;
        }
        if (s == "end") {
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 7024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  int x;
  x = 0;
  for(int i=0;i<3;i++){
    if(a.at(i)==b.at(i)){
      ++x;
    }
  }
  cout << x << endl;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x,  k;
string s, t;

// <------------- Implement Functions Here ----------> //

queue<ll> q[2000];
ll m[2000][2000] = {};
queue<ll> q1,q2;

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n ;
	vll a(n);
	for(ll i=0;i<n;i++) cin>>a[i];
	sort(all(a));
	reverse(all(a));

	ll sum = accumulate(all(a),0) - a[0];
	if(a[0] >= sum) {
		cout<<"No\n";
	}
	else {
		cout<<"Yes\n";
	}
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 4896
# -*- coding: utf-8 -*-

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#-----

a_even_list=[]
for v in a_list:
    if v%2 == 0 and v != 0:
        a_even_list.append(v)

cnt=0
for v in a_list:
    while v%2 == 0 and v != 0:
        v /= 2
        cnt += 1

print(cnt)


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

int main()
{
    for (int n, count; cin >> n; cout << count << endl) {
        count=0;
        if (n<=36) {
            for (int a=0; a<10; a++) {
                for (int b=0; b<10; b++) {
                    for (int c=0; c<10; c++) {
                        for (int d=0; d<10; d++) {
                            if (a+b+c+d>n) {
                                break;
                            }
                            else if (a+b+c+d==n) {
                                count++;
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b  = MAP()
a_a = str(a)
b_b = str(b)
c = [a_a] * b
d = [b_b] * a
c = "".join(c)
d = "".join(d)
print(min(c, d))

Measured memory_bytes: 5140
n = input()
flag = False
while flag == False:
    # print(n)
    for i in range(len(n)-1):
        # print(i,n,n[i],n[i+1])
        if n[i] != n[i+1]:
            n = str(int(n) + 1)
            break
        # print('clear')

        if i == len(n)-2:
            # print(n)
            flag = True

print(int(n))

Measured memory_bytes: 2940
def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end
#####

n = gi
hs = gim

dp = Array.new(n, Float::INFINITY)
dp[0] = 0

dp[1] = dp[0]+(hs[1]-hs[0]).abs

(2..n-1).each do |i|
  dp[i] = [dp[i],dp[i-1]+(hs[i]-hs[i-1]).abs].min
  dp[i] = [dp[i],dp[i-2]+(hs[i]-hs[i-2]).abs].min
end
puts dp[-1]

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 2e5 + 5;
const LL maxm = LL(1e18)+5;

LL A[maxn];
vector<LL> minu;
vector<LL> plu;
vector<LL> num;
LL K,N;

LL les_than_mid(LL mid){
    LL cnt = 0;
    //数组下标的二分查找法
    _for(i,0,num.size()){
        if(num[i] < 0){
            int l = -1;
            int r = N-1;
            while(r > l){
                //printf("%lld %lld\n",l,r);
                LL m = ceil((l + r)/(double)2);
                if(num[m] * num[i] < mid){
                    r = m - 1;
                }else{
                    l = m;
                }
            }
            cnt += N - 1 - r;
            if(i > r) cnt--;
        }
        else if(num[i] == 0){
            if(mid > 0) cnt += N - 1;
        }
        else{
            int l = 0;
            int r = N;
            while(r > l ){
                LL m = (l + r)/2;
                if(num[m] * num[i] < mid){
                    l = m + 1;
                }
                else{
                    r = m;
                }
            }

            cnt += l;
            if(i < l) cnt--;

        }

    }


    //cout <<mid <<" "<< cnt/2 << endl;

    return cnt/2;

}

int main()
{
    cin >> N >> K;
    int mnum = 0;
    int pnum;
    _for(i,0,N){
        cin >> A[i];
        num.PB(A[i]);
    }


    sort(ALL(num));

    LL l =  -maxm;
    LL r =  maxm;
    while(r  > l){
        //printf("%lld %lld\n",l,r);
        LL mid = l + (r - l)/2;
        LL cnt = les_than_mid(mid);
        if(cnt < K){
            l = mid + 1;
        }else
        {
            r = mid;
        }
    }
    cout << l-1 <<endl;


    return 0;
}


Measured memory_bytes: 3444
package main

import (
	"fmt"
)

func solution(n, k int) int {
	var i int
	for n > 0 {
		n /= k
		i++
	}
	return i
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	fmt.Println(solution(n, k))
}


Measured memory_bytes: 512
import numpy
import re
import math
from collections import deque, defaultdict
import itertools

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	連結を隣接行列で管理 + DFS
	"""
	n, m = map(int, input().split())
	table = [[0] * n for _ in range(n)] #隣接行列
	for _ in range(m):
		a, b = map(int, input().split())
		table[a - 1][b - 1] = 1
		table[b - 1][a - 1] = 1
	cnt = 0
	for pattern in itertools.permutations(range(n)): #全ての点が繋がっている状態は順列の積で記述
		if pattern[0] != 0: #スタートがゼロ(頂点1)でなかった場合
			break
		factor = 1
		for i in range(n - 1):
			factor *= table[pattern[i]][pattern[i + 1]] #0なら頂点1から繋がっておらず、1なら頂点1から全ての点へ繋がっている
		cnt += factor #頂点1から繋がっていれば加算

	print(cnt)

if __name__ == '__main__':
	main()


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> p(N); rep(i, N){cin >> p.at(i);}
    sort(p.begin(), p.end());
    ll ans = p.at(N - 1) / 2;
    rep(i, N - 1){ans += p.at(i);}
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3596