akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define M 100009
using namespace std;
int read(){
	int f=1,re=0;char ch;
	for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
	if(ch=='-'){f=-1,ch=getchar();}
	for(;isdigit(ch);ch=getchar()) re=(re<<3)+(re<<1)+ch-'0';
	return re*f; 
}
int x[M],y[M],z[M],n,m,a,b,c,ans;
bool cmp(const int &a,const int &b){return a>b;}
signed main(){
	n=read(),m=read(),a=read(),b=read(),c=read();
	for(int i=1;i<=a;i++) x[i]=read();
	for(int i=1;i<=b;i++) y[i]=read();
	for(int i=1;i<=c;i++) z[i]=read();
	sort(x+1,x+a+1,cmp);
	sort(y+1,y+b+1,cmp);
	sort(z+1,z+c+1,cmp);
	a=n,b=m;
	for(int i=1;i<=n;i++) ans+=x[i];
	for(int i=1;i<=m;i++) ans+=y[i];
	int cnt1=a,cnt2=b,cnt3=1;
	x[0]=10000000009,y[0]=100000000000;
	while(cnt3<=c){
		if(x[cnt1]<y[cnt2]&&cnt3<=c&&z[cnt3]>x[cnt1]){
			ans+=(z[cnt3]-x[cnt1]),cnt1--,cnt3++;
			continue;
		}
		if(x[cnt1]>=y[cnt2]&&cnt3<=c&&z[cnt3]>y[cnt2]){
			ans+=(z[cnt3]-y[cnt2]),cnt2--,cnt3++;
			continue;
		}break;
	}printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        n: usize,
    }
    let mut o = n % 10;
    // if 10 <= n && n < 100 {
    //     o = n % 10;
    // }
    // else if 100 <= n {
    //     o = n % 10;
    // }
    match o {
        2 | 4 | 5 | 7 | 9 => println!("hon"),
        0 | 1 | 6 | 8 => println!("pon"),
        _ => println!("bon"),
    }
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int a,b;
  cin >> a >> b;
  cout << (b - 1 + a - 1 - 1) / (a - 1) << endl;
  return 0;
}


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

#define X first
#define Y second
#define MP make_pair

using namespace std;

typedef long long ll;

const int N = 1e5 + 12;
const ll mod = 1e9 + 7;

int n, m;
string s[N];

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

	cin >> n >> m;
	for(int i = 1;i <= n;i++)
		cin >> s[i];
	sort(s + 1, s + n + 1);
	for(int i = 1;i <= n;i++)
		cout << s[i];
}


Measured memory_bytes: 6664
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

int main(){
    int x,a;
    cin >> x >> a;
    if(x<a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
int main() {
   string A, B, C;
   cin >> A >> B >> C;
   if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]){
       cout << "YES" << endl;
   }else{
       cout << "NO" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main(){
        int a,b,c,x,y;
        cin>>a>>b>>c>>x>>y;
        long long ans;
        if((a+b)>=c*2){
            if(x<y){
                if(b>2*c) ans=2*c*y;
                else ans=2*c*x+(y-x)*b;
            }
            else {
                if(a>2*c) ans=2*c*x;
                else ans=2*y*c+(x-y)*a;
            }
        }
        else ans=x*a+y*b;
        cout<<ans;
    }

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

int main() {
    ll M;
    cin >> M;
    vector<ll> d(M), c(M);
    rep(i, M) cin >> d[i] >> c[i];
    ll num = 0;
    ll ans = 0;
    rep(i, M) {
        ans += c[i];
        num += c[i] * d[i];
    }
    --ans;

    ll tmp = num;
    while (tmp > 9) {
        ans += max(0LL, tmp / 10 - 1);
        tmp /= 10;
    }

    while (num > 9) {
        ll tmp = num;

        num = 0;
        while (tmp > 0) {
            num += tmp % 10;
            tmp /= 10;
            ++ans;
        }
        --ans;

        tmp = num;
        while (tmp > 9) {
            ans += max(0LL, tmp / 10 - 1);
            tmp /= 10;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6332
N = int(input())
h = list(map(int, input().split()))
INF = 10 ** 9
dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    if i == N - 2:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    else:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))

print(dp[-1])

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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 ); }


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

    int W, H, N;
    cin >> W >> H >> N;
    int x1 = 0, x2 = W, y1 = 0, y2 = H;
    rep(i, N) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            x1 = max(x1, x);
        } else if (a == 2) {
            x2 = min(x2, x);
        } else if (a == 3) {
            y1 = max(y1, y);
        } else {
            y2 = min(y2, y);
        }
    }
    if ((x2 - x1 < 0) || (y2 - y1 < 0)) cout << 0 << endl;
    else cout << (x2 - x1) * (y2 - y1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char s[1000001];
int a[1000000];

int calc(int n, int m) {
    int x = 0, y = 0, i;
    
    for (i = 0; i < n; i++) {
        if (s[i] == '1' || (s[i] == '?' && x + 1 + a[i] <= m)) {
            x++;
        } else {
            x--;
        }
        
        y = min(y, x);
    }
    
    return m - y;
}

int main() {
    int n, m = 0, x = 0, y = 0, i;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    for (i = 0; i < n; i++) {
        if (s[i] == '1') {
            x++;
        } else {
            x--;
        }
        
        m = max(m, x);
    }
    
    x = 0;
    
    for (i = n - 1; i >= 0; i--) {
        a[i] = y - x;
        
        if (s[i] == '1') {
            x--;
        } else {
            x++;
        }
        
        y = max(y, x);
    }
    
    printf("%d\n", min(calc(n, m), calc(n, m + 1)));
    
    return 0;
}


Measured memory_bytes: 6612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll a[200100];
vector<ll> b;

int main() {
	cin >> n;
	b.resize(n);
	rep(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(ALL(b));
	rep(i, n) {
		auto it = lower_bound(ALL(b), a[i]);
		if (it - b.begin() < n / 2)cout << b[n / 2] << endl;
		else cout << b[n / 2 - 1] << endl;
	}
}

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

int main() {
  string S, T; cin >> S >> T;
  vector<int> ss(S.length() + 1, 0);
  for (int i = 1; i < S.length() + 1; ++i) ss[i] = ss[i - 1] + ( (S[i - 1] == 'A') ? 1 : 2 );
  vector<int> st(T.length() + 1, 0);
  for (int i = 1; i < T.length() + 1; ++i) st[i] = st[i - 1] + ( (T[i - 1] == 'A') ? 1 : 2 );
  int q; cin >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int i = 0; i < q; ++i) {
    int ns = (ss[b[i]] - ss[a[i] - 1]) % 3;
    int nt = (st[d[i]] - st[c[i] - 1]) % 3;
    cout << ( (ns == nt) ? "YES" : "NO" ) << endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  int n, d;
  cin >> n >> d;
  cout << (n - 1) / (2 * d + 1) + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args)
    {
        Map<List<Integer>,Integer> dataBase = new HashMap<>();
        List<Integer> first = new ArrayList<>();
        Integer[] firstData = {0,1,2,3,4,5,6,7,0};
        first.addAll(Arrays.asList(firstData));
        dataBase.put(first,0);
        Queue<List<Integer>> q = new LinkedList<>();
        q.add(first);
        while(!q.isEmpty())
        {
            List<Integer> tmp = q.remove();
            List<List<Integer>> next = getNext(tmp);
            for(List<Integer> item : next)
            {
                if(!dataBase.containsKey(item))
                {
                    dataBase.put(item,dataBase.get(tmp)+1);
                    q.add(item);
                }
            }
        }

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext())
        {
            List<Integer> input = new ArrayList<>();
            int indexofzero = 0;
            for(int i=0;i<8;i++)
            {
                input.add(sc.nextInt());
                if(input.get(i)==0)indexofzero = i;
            }
            input.add(indexofzero);
            System.out.println(dataBase.get(input));
        }
    }

    static List<List<Integer>> getNext( List<Integer> prev)
    {
        List<List<Integer>> ret = new ArrayList<>();
        int point = prev.get(8);
        if(point%4!=0)
        {
            List<Integer> cur  =new ArrayList<>();
            cur.addAll(prev);
            int p = cur.get(point);
            cur.set(point,cur.get(point-1));
            cur.set(point-1,p);
            cur.set(8,point-1);
            ret.add(cur);
        }
        if(point%4!=3)
        {
            List<Integer> cur  =new ArrayList<>();
            cur.addAll(prev);
            int p = cur.get(point);
            cur.set(point,cur.get(point+1));
            cur.set(point+1,p);
            cur.set(8,point+1);
            ret.add(cur);
        }

        if(point>3)
        {
            List<Integer> cur  =new ArrayList<>();
            cur.addAll(prev);
            int p = cur.get(point);
            cur.set(point,cur.get(point-4));
            cur.set(point-4,p);
            cur.set(8,point-4);
            ret.add(cur);
        }
        else
        {
            List<Integer> cur  =new ArrayList<>();
            cur.addAll(prev);
            int p = cur.get(point);
            cur.set(point,cur.get(point+4));
            cur.set(point+4,p);
            cur.set(8,point+4);
            ret.add(cur);
        }
        return ret;
    }


}

Measured memory_bytes: 52572
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//--GLOBAL---------------------------------

ll dp[3001][2][3001]; //番目,こえた,時間 = 満足
//--MAIN-----------------------------------
void Main() {
    int N,T;
    cin >>N>>T;

    vector<P> AA(N);
    ll A[N],B[N];

    rep(i,N){
        cin>>A[i]>>B[i];
        AA[i]={A[i],B[i]};
    }

    SORT(AA);

    rep(i,N){
        A[i]=AA[i].first;
        B[i]=AA[i].second;
    }
    /*

    rep(i,3001){
        rep(j,2){
            rep(k,3001){
                dp[i][j][k]=INF;
            }
        }
    }

    dp[0][0][0]=0;
    */

    rep(i,N){
        rep(j,T){
            // 注文しない
            maxi(dp[i+1][0][j],dp[i][0][j]);

            //注文する
            ll Tx=j+A[i];
            if(Tx<T){
                maxi(dp[i+1][0][Tx],dp[i][0][j]+B[i]);
            }
            else{
                maxi(dp[i+1][1][0],dp[i][0][j]+B[i]);
            }
            

        }
        maxi(dp[i+1][1][0],dp[i][1][0]);
    }

    ll ans=0;

    rep(i,T){
        maxi(ans,dp[N][0][i]);
    }
    maxi(ans,dp[N][1][0]);

    cout<< ans<<"\n";




}

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


Measured memory_bytes: 139648
def main():
    s = input()

    ans = 0
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            ok = True
            ss = s[i:j]
            for k in ss:
                if k not in {"A", "C", "G", "T"}:
                    ok = False

            if ok:
                ans = max(ans, j-i)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9+7;

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

    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];


    ll dp[n]={0};
    dp[1] = abs(arr[1]-arr[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i] = min( dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]) );
    }
    cout<<dp[n-1];
}



Measured memory_bytes: 1920
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

using SyrupBeans.Competitive.Integer;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        var a = ab[0];
        var b = ab[1];

        var commonDivisors = new HashSet<long>(Divisibility.EnumerateDivisors(a));
        commonDivisors.IntersectWith(new HashSet<long>(Divisibility.EnumerateDivisors(b)));

        var candidates = new SortedSet<long>(commonDivisors);
        var d = 1L;
        while (d + 1 <= candidates.Max)
        {
            d = candidates.GetViewBetween(d + 1, candidates.Max).Min;
            var t = d + 1;
            while (t <= candidates.Max)
            {
                var s = candidates.GetViewBetween(t, candidates.Max).Min;
                t = s + 1;
                if (s % d != 0)
                {
                    continue;
                }
                candidates.Remove(s);
            }
        }

        Console.WriteLine(candidates.Count);
    }
}

namespace SyrupBeans.Competitive.Integer
{
    using Integer = System.Int64;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public static class Divisibility
    {
        /// <summary>O(log min(<paramref name="x" />, <paramref name="y" />))</summary>
        public static Integer Gcd(Integer x, Integer y) => x < 1 ? y : Gcd(y % x, x);

        /// <summary>O(sqrt(<paramref name="x" />))</summary>
        public static IEnumerable<Integer> EnumerateDivisors(Integer x)
        {
            var cache = new Stack<Integer>();
            for (Integer i = 1; i * i <= x; ++i)
            {
                Integer r, d = Math.DivRem(x, i, out r);
                if (r != 0)
                {
                    continue;
                }
                yield return i;
                cache.Push(d);
            }
            if (cache.Any() && cache.Peek() * cache.Peek() == x)
            {
                cache.Pop();
            }
            while (cache.Any())
            {
                yield return cache.Pop();
            }
        }
    }
}


Measured memory_bytes: 17248
N, M = map(int, input().split())
num = [None]*N
res = 0
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if N > 1 and s == 0 and c == 0:
        res = -1
        break    
    if num[s] == None:
        num[s] = c
    elif num[s] != c:
        res = -1
        break

print(res) if res == -1 else print(*[e if e!=None else 0 if i != 0 or N == 1 else 1 for i, e in enumerate(num)], sep="")


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

char atcg[4] = {'A', 'T', 'C', 'G'};

ll dp[101][5][5][5];

int main() {
    int n;
    cin >> n;
    
    fill(dp[0][0][0], dp[100][4][4]+5, 0LL);
    dp[0][0][0][0] = 1;

    for(int i=0;i<n;++i) {
        for(int j1=0;j1<5;++j1) {
            for(int j2=0;j2<5;++j2) {
                for(int j3=0;j3<5;++j3) {
                    if(!dp[i][j1][j2][j3]) continue;
                    for(int j4=1;j4<5;++j4) {
                        if(j4 == 3) {
                            if(j2 == 1 && j3 == 4) continue;
                            if(j1 == 1 && j3 == 4) continue;
                            if(j1 == 1 && j2 == 4) continue;
                            if(j2 == 4 && j3 == 1) continue;
                        } else if(j2 == 1 && j3 == 3 && j4 == 4) {
                            continue;
                        }
                        dp[i+1][j2][j3][j4] += dp[i][j1][j2][j3];
                        dp[i+1][j2][j3][j4] %= MOD;
                    }
                }
            } 
        }
    }

    ll ans = 0LL;
    for(int j1=1;j1<5;++j1) {
        for(int j2=1;j2<5;++j2) {
            for(int j3=1;j3<5;++j3) {
                ans += dp[n][j1][j2][j3];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;

}


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

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

    static class BGreatOceanView {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();
            int max = Integer.MIN_VALUE;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] >= max) {
                    max = a[i];
                    count++;
                }
            }
            out.println(count);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22484
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
LL rev[N];
void init()
{
	rev[0] = rev[1] = 1;
	for (int i = 2; i < N; i++) rev[i] = (INF - INF / i) * rev[INF % i] % INF;
}
LL C(LL n, int m)
{
	LL ans = 1;
	while (m)
	{
		ans = ans * n % INF * rev[m] % INF;
		n--, m--;
	}
	return ans;
}
LL solve(vector<int>& v)
{
	sort(v.begin(), v.end());
	LL ans = 0;
	LL sum = 0;
	for (int i = 0; i < v.size(); i++)
	{
		ans = (ans + 1LL * v[i] * i - sum) % INF;
		sum += v[i];
		if (sum >= INF)
			sum -= INF;
	}
	return ans;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init();
	vector<int> v1, v2;
	int n, m;
	cin >> n >> m;
	int k;
	cin >> k;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			v1.push_back(i);
			v2.push_back(j);
		}
	}
	LL ans = (solve(v1) + solve(v2)) * C(1LL * n * m - 2, k - 2) % INF;
	if (ans < 0) ans += INF;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
import bisect
def inpl(): return list(map(int, input().split()))
N = int(input())
a, b, c = sorted(inpl()), sorted(inpl()), sorted(inpl())

ans = 0
for j in b:
    ans += bisect.bisect_left(a, j)*(N-bisect.bisect_right(c, j))
print(ans)


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

// A function to print all prime
// factors of a given number n
long long int  primeFactors(long long int n,long long int arr[])
{      long long int l=0;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        arr[l]=2;
        l++;
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (long long int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
           arr[l]=i;
           l++;
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)  {
        arr[l]=n;
        l++;
    }
    return l;
}

/* Driver code */
int main()
{  long long int n1;
  cin>>n1;
 int y=sqrt(n1);
 long long  int arr1[1000];
  long long int l1=primeFactors(n1,arr1);
// cout<<l1<<endl;
  long long int arr2[1000];
  arr2[0]=arr1[0];
   for(long long int i=1;i<l1;i++){
    if(arr1[i]==arr1[i-1]){
        arr2[i]=arr2[i-1]*arr1[i];
    }
    else{
        arr2[i]=arr1[i];
    }
 }
 long long int sum=0;
 for(long long int i=0;i<l1;i++){

    if(n1%arr2[i]==0){
        sum++;
        n1=n1/arr2[i];
    }


 }

 cout<<sum;


    return 0;
}

Measured memory_bytes: 3720
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	unordered_map<int, int> cnt;
	vi a(n); 
	rep(i, n) {
		cin >> a[i];
		++cnt[a[i]];
	}

	vii pairs;
	for (auto i : cnt) {
		pairs.push_back(i);
	}

	sort(DESC(pairs));

	bool check1 = false, check2 = false;
	ll r = 0, l = 0;
	ll tmp = 0;
	rep(i, pairs.size()) {
		if (pairs[i].second >= 4) {
			tmp = max(tmp, (ll)pairs[i].first * pairs[i].first);
		}

		if (pairs[i].second >= 2 && check1 == false) {
			r = pairs[i].first;
			check1 = true;
		}
		else if (pairs[i].second >= 2 && check2 == false) {
			l = pairs[i].first;
			check2 = true;
		}
		else if (check1 == true && check2 == true) break;

	}
	cout << max(tmp, r * l) << endl;

}


Measured memory_bytes: 6308
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string str;
    int ab[26]={};
    int i;
    while(getline(cin,str)){
        for(i=0;i<str.size();i++){
            if(str[i]>='a'&&str[i]<='z') ab[str[i]-'a']++;
            else if(str[i]>='A'&&str[i]<='Z') ab[str[i]-'A']++;
        }
    }
    for(i=0;i<26;i++){
        cout << (char)('a'+i) << " : " << ab[i] << endl;
    }
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b,ll c){if(a==b)out(c);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
int main(){
    ll n;cin>>n;
    if(n==3)cout<<2<<' '<<5<<' '<<63<<endl;
    else {
        vi ans(n);
        vi v={2,3,4,6,8,9,10,12},x={2,4,3,9,8,10};
        ll k=n/8;
        rep(i,k)rep(j,8)ans[i*8+j]=i*12+v[j];
        if(n&1)ans[n-1]=6+k*12;
        rep(i,n%8)if(ans[i+k*8]==0)ans[i+k*8]=x[i]+k*12;
        outv(ans);
    }
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
ll total, n, A[MAXN], q, ans[MAXN], mx, mi, mxval;
vector<spi> Q;
int main(){
	FAST
	cin>>total>>n;
	FOR(i,1,n)cin>>A[i];
	cin>>q;
	FOR(i,0,q-1){
		ll t,a;
		cin>>t>>a;
		Q.eb(t,pi(a,i));
	}
	sort(all(Q));
	ll co = 1;bool top = 1, same = 0;
	mi = 0, mx = total, mxval = total;
	for(auto i:Q){
		while(co <= n && A[co] <= i.f){
			ll d=A[co]-A[co-1];
			if(same) {
				mxval += d * (top ? -1 : 1);
				mxval = max(mxval, 0ll);
				mxval = min(mxval, total);
			}else{
				if(top){// minus
					ll mival = mxval - (mx - mi);
					if(mival < d){
						mi += d - mival;
					}
					mxval -= d;
					if(mxval <= 0){
						same = 1, mxval = 0;
					}
				}else{// add
					if(total - mxval < d){
						mx-=d-(total-mxval), mxval=total;
					}else{
						mxval += d;
					}
					if(mx <= mi){
						same=1;
					}
				}
			}
			++ co, top ^= 1;
		}
		ll a = i.s.f;
		if(same){
			ans[i.s.s]=mxval;
		}else{
			if(a <= mi){
				ans[i.s.s]=mxval - (mx-mi);
			}else if(a >= mx){
				ans[i.s.s]=mxval;
			}else{
				ans[i.s.s]=mxval-(mx-a);
			}
		}
		ans[i.s.s] += (i.f - A[co-1]) * (top ? -1 : 1);
		ans[i.s.s]=max(ans[i.s.s],0ll);
		ans[i.s.s]=min(ans[i.s.s],total);
	}
	FOR(i,0,q-1)cout<<ans[i]<<'\n';
}


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

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

using ll = long long;
using namespace std;

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

    vector<int> a(n);
    int sum = 0;
    rep(n, i) {
      cin >> a[i];
      sum += a[i];
    }

    int count = 0;
    for (auto e : a) {
      if ( 4 * m * e  < sum)
        continue;
      count++;
    }

    cout << (m <= count ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
N=gets.to_i
ss=$<.read.split.map(&:chomp)

a = 0
b=0
ab=0
ret = 0
ss.each do |s|
  i = -1
  ret += 1 while i = s.index('AB',i+1)
  if s[0]=='B' && s[-1]=='A'
    ab+=1
  elsif s[0]=='B'
    b+=1
  elsif s[-1]=='A'
    a+=1
  end
end

if 0 < ab
  ret += ab-1
  if 0 < a
    a -= 1
    ret += 1
  end
  if 0 < b
    b -= 1
    ret += 1
  end
end

ret += [a,b].min
puts ret


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

int main() {
  string s;
  cin >> s;
  int start = 0;
  long long int length1 = 0;
  long long int length2 = 0;
  long long int ans = 0;

  if(s[s.size()-1] == '>') s += '<';
  else s += '>';

  for(int i = 0; i < s.size() - 1; i++) {

    if(s[i] == s[i+1]) continue;
    else {
      if(s[i+1] == '>') {
        length1 = i + 1 - start;
        start = i + 1;
        if(i == s.size() - 2) {
          ans += length1 * (length1 + 1) / 2;
          break;
        }
      } else {
        length2 = i + 1 - start;
        start = i + 1;
        if(length1 > length2) ans += length1 * (length1 + 1) / 2 + length2 * (length2 - 1) / 2;
        else ans += length1 * (length1 - 1) / 2 + length2 * (length2 + 1) / 2;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int main(){
    bool c=0,f=0;
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='C') c=1;
        if(s[i]=='F'&&c) f=1;
    }
    if(c&&f) puts("Yes"); else puts("No");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main(){
    int64_t n, a, b;
    cin >> n >> a >> b;
    int64_t ans = (n - 1) * b + a - ((n - 1) * a + b) + 1;
    cout << max(0L, ans) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else if(a==b){
		printf("a == b\n");
	}
	 return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long B[100000];
long C[100000];
long Diff[100000];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		C[i] = rei();
	}
	for(int i=0;i<N;i++){
		B[i] = rei();
	}
	int ans = 0;
	long sum = 0;
	for(int i=0;i<N;i++){
		if(B[i] > C[i]){
			ans++;
			sum += B[i] - C[i];
		}
		else{
			Diff[i] = C[i] - B[i];
		}
	}
	sort(Diff,Diff+N);
	int p = N-1;
	while(sum > 0){
		if(p == -1){
			cout << "-1" << endl;
			return;
		}
		ans++;
		sum -= Diff[p--];
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 2560
using System;

class ABC_135_B
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int[] p = new int[N];
        for (int i = 0; i < N; i++)
        {
            p[i] = int.Parse(input[i]);
        }

        int count = 0;
        for (int i = 0; i < N; i++)
        {
            if (p[i] != (i + 1)) count++;
        }

        if (count <= 2)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);


int main() {
    ll N; cin >> N;
    vi A(N); rep(i,N) cin >> A[i];
    sort(A.begin(), A.end());

    ll sum = 0;
    rep(i,N) sum += A[i];
    ll ans = 1;
    rep(i,N-1){
        sum -= A[N-1-i];
        if(sum*2 < A[N-1-i]) break;
        ans++;
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3728
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include<bits/stdc++.h>

using namespace std; 

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void cook()
{
    // start with your recipe
    int a[5];
    for(int i=0;i<5;++i)    cin>>a[i];
    for(int i=0;i<5;++i)
    {
        if(a[i] == 0)
        {
            cout<<i+1;
            exit(0);
        }
    }
}

start_cooking
{
    main_ingredient_added
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1; 
    //cin>>t;
    while(t--)
        cook();
    food_is_ready
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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


Measured memory_bytes: 256
def main():
    n,a,b = map(int,input().split())
    MOD = 10**9 +7
    s = pow(2,n,MOD)-1
    P_ni = 1
    F_i = 1


    for i in range(1,b + 1):
        P_ni=P_ni*(n-i+1)%MOD
        F_i=F_i* i % MOD
        if i == a or i == b:
            s-=P_ni*pow(F_i,MOD-2,MOD)



    print(s%MOD)

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    cout << ((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class BIT:
    def __init__(self, n):
        self.array = [0] * (n + 1)
        self.size = n

    def sum(self, i):
        s = 0
        tmp = i
        while tmp > 0:
            s += self.array[tmp]
            tmp -= tmp & -tmp
        return s

    def add(self, i, x):
        tmp = i + 1
        while tmp <= self.size:
            self.array[tmp] += x
            tmp += tmp & -tmp


n, q = map(int, input().split())
*C, = map(lambda x: int(x) - 1, input().split())
P = [0] * n
N = [None] * n
for i in range(n)[::-1]:
    if P[C[i]]:
        N[i] = P[C[i]]
    P[C[i]] = i
F = [0] * n
B = BIT(n)
for i in range(n):
    if F[C[i]] == 0:
        B.add(i, 1)
        F[C[i]] = 1
XY = [tuple(map(int, input().split())) for j in range(q)]
ids = list(range(q))
ids.sort(key=lambda j: XY[j][0])
a = 0
lst = [0] * q
for j in ids:
    x, y = XY[j]
    for i in range(a, x - 1):
        if N[i]:
            B.add(N[i], 1)
    a = x - 1
    lst[j] = B.sum(y) - B.sum(x - 1)
print(*lst, sep="\n")


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

#define int long long
#define REP(i,n) for(int i=1;i<=n;i++)
struct S {int p,q,r,b;};
int n;
S a[102];
bool is_top[102];

int gcd(int a,int b){
  while(a%=b)swap(a,b);
  return b;
}

int lcm(int a,int b){
  return a/gcd(a,b)*b;
}

int w(int i){
  if(i==0)return 1;
  int p=a[i].p, q=a[i].q,
      r=a[i].r, b=a[i].b;
  int l=lcm(w(r)*p,w(b)*q);
  return l/p+l/q;
}

signed main(){
  while(cin>>n,n){
    int p,q,r,b;
    REP(i,n)is_top[i]=1;
    REP(i,n){
      cin>>p>>q>>r>>b;
      a[i]={p,q,r,b};
      is_top[r]=0;
      is_top[b]=0;
    }
    int top=1;
    while(!is_top[top])top++;
    cout<<w(top)<<endl;
  }
  return 0;
}

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

string s;
long long n,br;

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

    cin>>s;
    n=s.size();
    int ind;
    if(s[0]=='W')
        ind=0;
    else
        ind=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            br++;
    }

    cout<<br<<endl;

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;

#define pb push_back

void slove()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int i = 1;
	while(true) {
		if(a <= 0) {
			cout << "No" << endl;
			break;
		}
		if(c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		if(i % 2 == 1) {
			c -= b;
		}
		if(i % 2 == 0) {
			a -= d;
		}
		i++;
	}
}

int main() 
{
	int t;
	t = 1;
	while(t--) {
		slove();
	}
	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n, W;
    cin >> n >> W;

    ll w[n], v[n];
    rep(i, n) {
        cin >> w[i] >> v[i];
    }

    ll dp[n+1][W+1];
    rep(i, n+1) {
        rep(j, W+1) {
            dp[i][j] = 0;
        }
    }

    rep(i, n) {
        rep(j, W+1) {
            if(j < w[i]) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max( dp[i][j], dp[i][j-w[i]] + v[i] );
            }
        }
    }

    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 79104
<?php
while(fscanf(STDIN, "%d %d", $a, $b)) {
    $gcd = $a > $b ? euclid($a, $b) : euclid($b, $a);
    echo $gcd, " ", $a / $gcd * $b, PHP_EOL;
}
 
function euclid($a, $b) {
    return $a % $b ? euclid($b, $a % $b) : $b;
}

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

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 n; cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    ll ans = gcd(x[0],x[1]);
    rep(i,n-1){
        ans = gcd(ans, x[i+1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024