akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

long gcd(long,long);

int main(void){
    long N;
    cin >> N;
    long A[N];
    
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    
    long gcdl[N+1],gcdr[N+1];
    gcdl[0] = A[0],gcdr[0] = A[N-1];
    for(int i=0;i<N;i++){
        gcdl[i+1] = gcd(gcdl[i],A[i]);
        gcdr[i+1] = gcd(gcdr[i],A[N-i-1]);
    }
    
    long res=0,dam;
    for(int i=0;i<N;i++){
        if(i==0){
            dam = gcdr[N-1];
        }else if(i == N-1){
            dam = gcdl[N-1];
        }else{
            dam = gcd(gcdl[i],gcdr[N-1-i]);
        }
        
        if(res<dam){
            res = dam;
        }
    }
    
    cout << res << endl;
    
}

long gcd(long a,long b){
    if(a<b){
        long c = a;
        a = b;
        b = c;
    }
    
    long r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    
    return b;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        while(true){
            String str[] = br.readLine().split(" ");
            int h = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
            if(h==0 && w==0) break;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    sb.append("#");
                }
                sb.append("\n");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 25572
inf = float('inf')

N, Ma, Mb = map(int, input().split())
dp = [[inf] * (400 + 1) for _ in range(400 + 1)]
dp[0][0] = 0

max_a = 0
max_b = 0
for i in range(N):
    a, b, c = map(int, input().split())
    max_a += a
    max_b += b
    for j in reversed(range(max_a + 1 - a)):
        for k in range(max_b + 1 - b):
            if dp[j][k] == inf: continue
            dp[j + a][k + b] = min(dp[j][k] + c, dp[j + a][k + b])

j = Ma
k = Mb
ans = inf
while j < 400 + 1 and k < 400 + 1:
    ans = min(ans, dp[j][k])
    j += Ma
    k += Mb

print(-1 if ans == inf else ans)
# print(dp)


Measured memory_bytes: 4852
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    bool ans = true;
    for(int i = k; i < n; i++){
        if(a[i-k] >= a[i])cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 4840
#!/usr/bin/env python3
import sys
import itertools
import collections

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n = I()
ll = list(MI())

count = collections.Counter(ll)


def check(a, b, c):
    if 2 * max(a, b, c) < (a + b + c):
        return True
    else:
        return False


ans = 0
for a, b, c in itertools.combinations(count.keys(), 3):
    if check(a, b, c):
        ans += count[a] * count[b] * count[c]

print(ans)


Measured memory_bytes: 9464
while True:
   n,x=map(int,input().split())
   a=0
   if x == 0 and n == 0:
      break
   for i in range(1,n+1):
    for j in range(i,n+1):
      for k in range(j,n+1):
        if i < j and j < k:
          s=i+j+k
          if s==x:
            a=a+1
   print(a)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    vector<int> nums(5);

    for (auto _ : irange(0, 3)) {
        int a, b;
        cin >> a >> b;
        ++nums[a];
        ++nums[b];
    }

    int k = 0;
    for (auto m : nums) {
        if (m == 1) {
            ++k;
        }
    }

    cout << (k % 2 == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    int p[5000];
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>p[i];
    }
    int ans=20000;
    for (int i=0; i<=p[0]; i++) {
        int q[5000];
        for (int j=0; j<n; j++) {
            q[j]=p[j];
        }
        int sum=i;
        q[0]-=i;
        for (int j=0; j<n-1; j++) {
            if(q[j]<=0)continue;
            sum+=q[j]*2;
            q[j+1]-=q[j];
        }
        if(q[n-1]>0)sum+=q[n-1];
        ans=min(ans, sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
#define endl '\n'

int n, m, x;
int res;

void rec_solve(int cur, int cost, vector<pair<int, vector<int>>>& books, vector<int> levels) {
    if (cur == books.size()) {
        for (int i = 0; i < m; ++i) {
            if (levels[i] < x) {
                return;
            }
        }
        res = min(res, cost);
        return;
    }
    // don't pick
    rec_solve(cur + 1, cost, books, levels);
    // pick the book
    for (int i = 0; i < m; ++i) {
        levels[i] += books[cur].second[i];
    }
    rec_solve(cur + 1, cost + books[cur].first, books, levels);
}
void solve() {
    cin >> n >> m >> x;

    int c;
    vector<pair<int, vector<int>>> books;
    for (int i = 0; i < n; ++i) {
        cin >> c;
        vector<int> level(m);
        for (auto &l : level) {
            cin >> l;
        }
        books.push_back({c, level});
    }

    res = INT_MAX;
    vector<int> levels(m, 0);
    rec_solve(0, 0, books, levels);
    
    if (res == INT_MAX) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }
}

int main() {
    FAST_IO;

    int t;
    // cin >> t;
    t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
int main(){
	int a,b,k,i,t;	//4 8 3
	scanf("%d%d%d",&a,&b,&k);
	if(a+k-1>=b){
		for(i=a;i<=b;i++)
			printf("%d\n",i);
		return 0;
	}
	else{
		for(i=a;i<=a+k-1;i++)
			printf("%d\n",i);
	}
	t=a+k;
	if(t>b-k+1){
		for(i=t;i<=b;i++)
			printf("%d\n",i);
	}
	else{
		for(i=b-k+1;i<=b;i++)
			printf("%d\n",i);
	}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int n; cin >> n;
	map<ll,int> m;
	rep(i, n)
	{
		ll tmp;cin >> tmp;
		m[tmp]++;
	}
	vector<ll> e4,e2;
	for(auto e:m)
	{
		if(e.second >= 4)e4.push_back(e.first);
		else if(e.second >= 2)e2.push_back(e.first);
	}
	sort(all(e4),greater<ll>());
	sort(all(e2),greater<ll>());
	ll ma4 = 0,ma2=0,ma22=0;
	if(sz(e4))ma4 = e4[0];
	if(sz(e2))ma2 = e2[0];
	if(sz(e2)>1)ma22 = e2[1];
	ll ans = max({ma4*ma4,ma2*ma22,ma2*ma4});
	cout << ans << endl;
	return;
}

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


Measured memory_bytes: 6528
x,n= list(map(int, input().split()))
p = list(map(int, input().split())) 
import numpy as np

if x not in p:
    print(x)
else:
    t = [i for i in range(-101,201)]
    for i in range(n):    
        t.remove(p[i])
#         print(t)

    res = 100
    s = 1000
    for i in range(len(t)):
#         print(t[i])
        if s >= abs (x - t[len(t)-1-i]):
            s = abs (x - t[len(t)-1-i])
            res = t[len(t)-1-i]
    print(res)

Measured memory_bytes: 27136
#include <iostream>
using namespace std;
int e(int n) {
  int r = n;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      r -= r / i;
      while (n % i == 0) n /= i;
    }
  if (n > 1) r -= r / n;
  return r;
}
int main() {
  int n;
  cin >> n;
  cout << e(n) << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string S, T;
  cin >> S >> T;
  int s, t, n;
  s = S.size();
  t = T.size();
  n = s - t + 1; 
  //一番合ってるやつを探す
  //前から後へ
  vector<int>c(n);
  int cmax = 0;
  for(int i = 0; i < n; i++){
  //何個一致してるかをｃで表す 
    for(int j = 0; j < t; j++){
      if(S.at(i+j) == T.at(j)){
        c.at(i)++;
    }
    }
  //最大値を更新していく
  if(c.at(i) > cmax){
     cmax = c.at(i);
   }
  }
  cout << t - cmax << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<limits.h>
using namespace std;

long long int dp[101][100001]={{}};
int N,W;
int w[101];
int v[101];

long long int maxValue(int i, int limit){
    if(i<0 || limit<=0)return 0;
    if(dp[i][limit]!=0)return dp[i][limit];
    if(limit-w[i] < 0)return maxValue(i-1,limit);
    long long int  ret = max(maxValue(i-1,limit), maxValue( i-1, limit-w[i] ) + v[i]);
    dp[i][limit] = ret;
    return ret;
}



int main(){
    cin >> N >> W;
    for(int i = 0; i<N; i++){
        cin>>w[i]>>v[i];
    }
    cout<<maxValue(N-1,W)<<endl;

    // for(int i = 0; i<N; i++){
    //     for(int k = 0; k<=W; k++){
    //         cout<<dp[i][k]<<" ";
    //     }
    //     cout<<endl;
    // }
    return 0;
}

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

#define eps 1e-8
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)

const int N=123;
typedef long long LL;
char s[N][N];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
bool vis[N][N];
int n,m,cnt;

bool check(int x,int y){
    if(x>=1&&x<=n&&y>=1&&y<=m&&s[x][y]=='#'&&!vis[x][y]) return true;
    return false;
}

void DFS(int x,int y){
    cnt++;
    vis[x][y]=1;
    for(int i=0;i<4;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(check(nx,ny)) DFS(nx,ny);
    }
}

int main(){
    FAST_IO;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    cin>>s[i][j];

    int F=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cnt=0;
            if(s[i][j]=='#'&&!vis[i][j]){
                DFS(i,j);
                if(cnt==1) F=0;
            }
        }
    }
    if(!F) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq;
    int a;
    for (int i=0;i<10;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end());
    cout << deq[deq.size()-1] << endl;
    cout << deq[deq.size()-2] << endl;
    cout << deq[deq.size()-3] << endl;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
// #include <sys/types.h> 
// #include <unistd.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e7+5;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n;
      cin>>n;
      cout<<n*n;
}
// I never lose. I either win or I learn

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;

struct Fenwick_tree {
    ll t[MAXN];

    Fenwick_tree() {
        memset(t, 0, sizeof t);
    }

    void upd(int pos, ll val) {
        for (; pos < MAXN; pos = (pos | (pos + 1))) {
            t[pos] = max(t[pos], val);
        }
    }

    ll get(int r) {
        ll res = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1) {
            res = max(res, t[r]);
        }
        return res;
    }
};

typedef vector<vector<ll> > matrix;

ll SQR = 1ll * mod * mod;

void add_sqr(ll &a, ll val) {
    a += val;
    if (a >= SQR)
        a -= SQR;
}

matrix mult(matrix &a, matrix &b) {
    int n = sz(a);
    int m = sz(b[0]);
    int k = sz(a[0]);
    assert(sz(a[0]) == sz(b));
    matrix res(n, vector<ll>(m));
    for (int i = 0; i < n; ++i) {
        for (int e = 0; e < m; ++e) {
            ll val = 0;
            for (int j = 0; j < k; ++j) {
                add_sqr(val, a[i][j] * b[j][e]);
            }
            res[i][e] = val % mod;
        }
    }
    return res;
}

matrix bin_pow(matrix &a, ll n) {
    matrix res(sz(a), vector<ll>(sz(a)));
    for(int i = 0;i<sz(a);++i){
        res[i][i] = 1;
    }

    while (n) {
        if (n & 1) {
            res = mult(res, a);
        }
        a = mult(a, a);
        n>>=1;
    }
    return res;
}


void solve() {
    int n;ll k;
    cin >> n >> k;
    matrix A(n,vector<ll> (n));

    matrix res(n,vector<ll> (1,1));
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            int x;
            cin >> x;
            if(x){
                A[i][j] = 1;
            }
        }
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            dout << A[i][j]<<" ";
        }
        dout << endl;
    }
    dout << endl;

    A = bin_pow(A,k);
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            dout << A[i][j]<<" ";
        }
        dout << endl;
    }

    res = mult(A,res);

    ll sum = 0;
    for(int i =0;i<n;++i)
        sum+=res[i][0];
    sum%=mod;
    cout << sum<<"\n";

}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 384
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int n, a[100009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	bool flag = true;
	for (int i = 0; i < n; i++) {
		if (n % 2 == 1) {
			if (a[i] != (i + 1) / 2 * 2) flag = false;
		}
		else {
			if (a[i] != i / 2 * 2 + 1) flag = false;
		}
	}
	if (!flag) cout << 0 << endl;
	else {
		int ret = 1;
		for (int i = 0; i < n / 2; i++) ret = ret * 2 % 1000000007;
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 768
///In the name of ALLAH

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

#define endl '\n'

const int mx = 1e5+123;
int h[mx], n;
int dp[mx];

int solve ( int i )
{
    if ( i == n ) return 0;
    if ( dp[i] != -1 ) return dp[i];

    int ret1 = 2e9, ret2 = 2e9;

    if ( i+1 <= n ) ret1 = abs ( h[i] - h[i+1] ) + solve ( i+1 );
    if ( i+2 <= n ) ret2 = abs ( h[i] - h[i+2] ) + solve ( i+2 );

    dp[i] = min ( ret1, ret2 );
    return dp[i];
}


int main()
{

    cin >> n;
    for ( int i = 1; i <= n; i++ ) cin >> h[i];

    memset ( dp, -1, sizeof ( dp ) );
    cout << solve ( 1 ) << endl;

    return 0;
}

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

#define ll long long
#define s(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)

int main()
{
    ll t, i, j, n;
    //cout << "Hello" << endl;
    cin >> n;
    cout << ((n*(n+1))/2)-n<< endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

int n, m;
int input[1000 + 5];
int sum;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &input[i]);
		sum += input[i];
	}
	int cnt = 0;
	int border;
	if (sum % (4 * m) == 0) border = sum / (4 * m);
	else border = sum / (4 * m) + 1;

	for (int i = 0; i < n; ++i)
	{
		if (input[i] < border) continue;
		cnt++;
	}
	if (cnt >= m) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;cin>>a>>b;
  if (a.at(0)==b.at(2)&&a.at(1)==b.at(1)&&a.at(2)==b.at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String S = br.readLine();

    List<String> wordPattern = new ArrayList<String>();
    // 文字を読み込んでいく

    char curr = S.charAt(0);
    int cnt = 0;
    int s = 0;

    for (int i = 0; i < S.length(); i++){

      if(s != S.charAt(i) || i == 0){
        s = S.charAt(i);
        cnt++;
      } else if(++i < S.length()){
        s = 0;
        cnt++;
      }

    }

    System.out.println(cnt);

  }
}


Measured memory_bytes: 26068
def round(points)
  3.times.each_with_object([points]){ |_, obj| obj << obj[-1].map{ |p| [-p[1], p[0]] } }
end

def same(a, b)
  a.size == b.size && a.zip(b).map { |(xa, ya), (xb, yb)| [xb - xa, yb - ya] }.uniq.size == 1
end

while (n = gets.to_i) != 0
  target = gets.to_i.times.map{ gets.split.map(&:to_i) }
  cand = n.times.map{ gets.to_i.times.map{ gets.split.map(&:to_i) } }
  n.times do |i|
    [target, target.reverse].flat_map{ |t| round(t) }
      .uniq.each do |t|
      if same(t, cand[i])
        puts i + 1
        break
      end
    end
  end
  puts '+++++'
end

Measured memory_bytes: 8844
num = list(input().split())
num = sorted([int(num[i]) for i in range(3)])

a = num[2] - num[1]
b = (num[2] - a - num[0]) % 2
c = (num[2] - a - num[0]) // 2

if b == 1:
    print(a + c + 2)
else:
    print(a + c)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;

    cout << "100 100\n";
    REP(i,100){
        REP(j,100) i<50 ? cout << (i%2&&j%2&&--a>0 ? "." : "#") : cout << (i%2&&j%2&&--b>0 ? "#" : ".");
        cout << "\n";
    }
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K = int(input())
A = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      A += gcd(a+1,b+1,c+1)
print(A)
  


Measured memory_bytes: 69416
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
using lint = long long;
using pi = pair<int, int>;
const int mod = 1e9 + 7;

int r, c, n;
vector<pi> seg;

int canon(int x, int y){
	if(1 <= x && x < r && 1 <= y && y < c) return -1;
	if(x == 0) return y;
	else if(y == c) return c + x;
	else if(x == r) return r + c + c - y;
	else return r + c + r + c - x;
}

int main(){
	scanf("%d %d %d",&r,&c,&n);
	for(int i=0; i<n; i++){
		int sx, sy, ex, ey;
		scanf("%d %d %d %d",&sx,&sy,&ex,&ey);
		int px = canon(sx, sy);
		int py = canon(ex, ey);
		if(px == -1 || py == -1) continue;
		if(px > py) swap(px, py);
		seg.emplace_back(px, py);
	}
	sort(seg.begin(), seg.end());
	vector<pi> stk;
	for(auto &i : seg){
		while(!stk.empty() && stk.back().second < i.first){
			stk.pop_back();
		}
		if(!stk.empty() && stk.back().second < i.second){
			puts("NO");
			return 0;
		}
		stk.push_back(i);
	}
	puts("YES");
}


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

int main()
{
    int N;
    cin >> N;
    double a;
    if((N%2) == 1) {
        a = (double)(N/2+1) / N;
    } else {
        a = (double)(N/2) / N;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3708
#! /usr/bin/env python3

s = input()

alphabets = list("abcdefghijklmnopqrstuvwxyz")

res = True

if s[0] != 'A' or s[1] not in alphabets:
    res = False

count = 0
for i in range(2, len(s)-1):
    if s[i] == 'C':
        if count == 0:
            count = 1
        else:
            res = False
    elif s[i] not in alphabets:
        res = False

if count == 0:
    res = False

if s[len(s)-1] not in alphabets:
    res = False

if res == True:
    print('AC')
else:
    print('WA')


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

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 2e5+5;
const int mod = 1e9+7;

int n, ct, ct2;
string s;

int main() {
    fastIO();
    cin >> n >> s;
    ct = count(all(s), 'R');
    for (int i = 0; i < ct; ++i) {
    	ct2 += (s[i] != 'R');
    }
    cout << ct2 << '\n';
    return 0;
}



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

using std::cout;
using std::cin;
using std::endl;

int main(void) {
    int a;
    int b;
    cin >> a >> b;
    int d;
    int r;
    double f;
    double da = (double) a;
    double db = (double) b;

    d = a / b;
    r = a % b;

    f = da / db; 
    cout << std::fixed << std::setprecision(6) << endl;
    cout << d << " " << r << " " << f << endl;

    return 0;
}

Measured memory_bytes: 3288
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    num = 0
    for k in range(d):
      num += (x[i][k]-x[j][k])**2
    if num == int(math.sqrt(num))**2:
      ans += 1
    else:
      continue
print(ans)

Measured memory_bytes: 38512
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000;

int aa[N];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	sort(aa, aa + n, greater<>());
	long long ans = aa[0];
	for (int i = 1; i < (n + 1) / 2; i++)
		ans += aa[i] + aa[i];
	if (n % 2)
		ans -= aa[(n + 1) / 2 - 1];
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4364
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define MOD 1000000007
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int n;
    cin >> n;
    int l, r;
    int ans = 0;
   imfor(i, n) {
       cin >> r >> l;
       ans += (l - r) + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vs;
  int v;
  for(int i = 0; i < N; ++i) {
    cin >> v;
    vs.push_back(v);
  }
  int c;
  for(int i = 0; i < N; ++i) {
    cin >> c;
    vs[i] -= c;
  }
  int ans = 0;
  for(auto v : vs) {
    // cout << v << endl;
    if(v > 0) {
      ans += v;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long ll;

ll N;
ll A, B;
ll h[100000];

bool go(ll t)
{
	ll count = 0;
	for (int i = 0; i < N; i++)
		if (h[i] > B * t)
			count += (h[i] - B*t) / A + ((h[i] - B*t) % A ? 1 : 0);
		
	
	return (count <= t);
}

int main(void)
{
	scanf("%lld %lld %lld", &N, &A, &B);
	for (int i = 0; i < N; i++) 
		scanf("%lld", &h[i]);
	
	ll base = 0;
	ll answer = 0;
	A = A - B;

	ll l = 1, r = 1000000000;
	while (l <= r) {
		ll mid = (l+r) / 2;
		if (go(mid)) 
			r=mid-1;
		
		else 
			l=mid+1;
		
	}
	printf("%lld\n", l);
	return false;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node {
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key) {
	NodePointer x = nil->next;

	while (1) {
		if (x == nil) return NULL ;
		else if (x->key == key) return x;
		x = x->next;
	}

	return NULL ;
}

void init() {
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	NodePointer cur = nil->next;
	int isf = 1;
	while (1) {
		if (cur == nil) break;
		if (isf == 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}

void deleteNode(NodePointer t) {
	t->next->prev = t->prev;
	t->prev->next = t->next;
	free(t);
}

void deleteFirst() {
	NodePointer t = nil->next;
	if (t == nil) return;
	deleteNode(t);
}

void deleteLast() {
	NodePointer t = nil->prev;
	if (t == nil) return;
	deleteNode(t);
}

void delete(int key) {
	NodePointer x;

	x = listSearch(key);

	if (x == NULL ) {
		return;
	}

	x->prev->next = x->next;
	x->next->prev = x->prev;
	free(x);
}

void insert(int key) {
	NodePointer x;
	x = malloc(sizeof(struct node));

	x->key = key;
	x->next = nil->next;
	x->prev = nil;
	nil->next = x;
	x->next->prev = x;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;

	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
			np++;
			size++;
		} else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F')
					deleteFirst();
				else if (com[6] == 'L')
					deleteLast();
			} else {
				delete(key);
				nd++;
			}
			size--;
		}
	}

	printList();
	return 0;
}

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

int main()
{
    int N, flag=0;

    cin >> N;
    vector<string> str(N);
    for (int i = 0; i < N;i++){
        cin >> str.at(i);
    }

    for (int i = 0; i < N-1;i++){

        //cout << "end=" << str.at(i).at(str.at(i).size() - 1) << " first=" << str.at(i + 1).at(0) << endl;

        if(str.at(i).at(str.at(i).size()-1)!=str.at(i+1).at(0)){
            flag = -1;
        }
    }
    for (int i = 0; i < N;i++){
        for (int j = i+1; j < N ; j++)
        {
            if(str.at(i)==str.at(j)){
                flag = -1;
            }
        }

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	char a;
	
	cin >> a;
	
	if(a=='A')cout << 'T' << endl;
	else if(a=='T')cout << 'A' << endl;
	else if(a=='C')cout << 'G' << endl;
	else if(a=='G')cout << 'C' << endl;
	
	return 0;
}

Measured memory_bytes: 256
#!/bin/sh
read a b c
y=0
z=0
[[ a -eq 5 ]] && z=$(( z + 1 ))
[[ b -eq 5 ]] && z=$(( z + 1 ))
[[ c -eq 5 ]] && z=$(( z + 1 ))
[[ a -eq 7 ]] && y=$(( y + 1 ))
[[ b -eq 7 ]] && y=$(( y + 1 ))
[[ c -eq 7 ]] && y=$(( y + 1 ))
[[ y -eq 1 && z -eq 2 ]] && echo YES
[[ y -eq 1 && z -eq 2 ]] || echo NO


Measured memory_bytes: 1904
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using qi = queue<int>;
using Graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

ll dp(int* r, int* c, int n) {
    ll table[n][n];
    REP(i, n) table[i][i] = 0;
    FOR(i, 1, n) {
        REP(j, n-i) {
            table[j][j+i] = table[j][j+i-1] + r[j]*c[j+i-1]*c[j+i];
            FOR(k, j, j+i) {
                table[j][j+i] = min(table[j][k] + r[j]*c[k]*c[j+i] + table[k+1][j+i], table[j][j+i]);
            }
        }
    }
    return table[0][n-1];
}

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

    int n; cin >> n;
    int r[n], c[n];
    REP(i, n) {
        cin >> r[i] >> c[i];
    }

    // a に含まれる n 個の値で k を作ったときの最大値は何か
    int table = dp(r, c, n);

    cout << table << "\n";
}


Measured memory_bytes: 3220
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
vector<P> prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; 
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({ a, ex });
    }
    if (N != 1) res.push_back({ N, 1 });
    return res;
}
int main() {
    ll n;
    cin >> n;
    vector<P>x;
    x = prime_factorize(n);
    ll ans = 0;
    for (auto id : x) {
        ll index = 2;
        while (id.second > 0) {
            id.second -= index;
            index++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int[] S= new int[]{A+(A-1),B+(B-1),A+B};
      
      int max = S[0];
      for (int i = 0; i < S.length; i++) {
        int v = S[i];
        if(v > max){
          max = v;
        }
      }
      System.out.println(max);
    }
}

Measured memory_bytes: 35664
n,m=map(int,input().split())
x=list(map(int,input().split()))
l=[]
ans=0
if n<m:
  x.sort()
  for i in range(m-1):
    l.append(x[i+1]-x[i])
  l.sort()
  for j in range(m-n):
    ans+=l[j]
print(ans)

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

#define int long long
const int mod = 1e9 + 7, N = 1e6 + 5;
int n, dp[N][2][2];

int solve(int idx, int zero, int nine) {
    assert(idx >= 1 and idx <= n + 1 and zero >= 0 and zero <= 1 and nine >= 0 and nine <= 1);

    if (idx == n + 1) {
        if (zero and nine)
            return 1;
        return 0;
    }

    int &ans = dp[idx][zero][nine];

    if (~ans) return ans;

    int res = 0;
    for (int i = 0; i < 10; i++) {
        res = (res + solve(idx + 1, (i == 0) ? 1 : zero, (i == 9) ? 1 : nine) % mod) % mod;
    }

    return ans = ((res % mod) + mod) % mod;
}
int32_t main() {

    cin >> n;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                dp[i][j][k] = -1;
            }
        }
    }
    cout << solve(1, 0, 0) % mod << '\n';
}


Measured memory_bytes: 112904
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  int p=a-'0',q=b-'0',r=c-'0',s=d-'0';
  if(p+q+r+s==7)
cout<<p<<'+'<<q<<'+'<<r<<'+'<<s;
  else if(p+q+r-s==7)
cout<<p<<'+'<<q<<'+'<<r<<'-'<<s;
  else if(p+q-r+s==7)
cout<<p<<'+'<<q<<'-'<<r<<'+'<<s;
  else if(p-q+r+s==7)
cout<<p<<'-'<<q<<'+'<<r<<'+'<<s;
  else if(p+q-r-s==7)
cout<<p<<'+'<<q<<'-'<<r<<'-'<<s;
  else if(p-q+r-s==7)
cout<<p<<'-'<<q<<'+'<<r<<'-'<<s;
  else if(p-q-r+s==7)
cout<<p<<'-'<<q<<'-'<<r<<'+'<<s;
  else
cout<<p<<'-'<<q<<'-'<<r<<'-'<<s;
cout<<"=7";
}


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

long long dp[409][409]; long long N, A[409], V[409][409];

long long dfs(long long L, long long R) {
	if (L > R) return 0;
	if (L == R) return A[L];
	if (dp[L][R] != 0) return dp[L][R];

	long long minx = (1LL << 60);
	for (int i = L + 1; i <= R; i++) {
		minx = min(minx, V[L][R] + dfs(L, i - 1) + dfs(i, R));
	}
	dp[L][R] = minx;
	return minx;
}

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

	for (int i = 1; i <= N; i++) {
		long long sum = 0;
		for (int j = i; j <= N; j++) {
			sum += A[j]; V[i][j] = sum;
		}
	}
	cout << dfs(1, N) - V[1][N] << endl;
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,d,ans{};
    cin>>n>>d;
    fr(i,n){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d) ++ans;
    }
    cout<<ans<<'\n';
}

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

int cnt(ll x) {
	int ret = 0;
	while (x % 2 == 0) {
		ret++;
		x /= 2;
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	int ans = 100;
	rep(i, n) {
		ll k;
		cin >> k;
		ans = min(ans, cnt(k));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func check(e error) {
	if e != nil {
		log.Fatalf("error: %v", e)
	}
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	_, err := strconv.Atoi(stdin.Text())
	check(err)

	var count int
	stdin.Scan()
	arr := strings.Split(stdin.Text(), " ")

LOOP:
	for divisor := 2; ; divisor *= 2 {
		for _, element := range arr {
			a, err := strconv.Atoi(element)
			check(err)
			if a%divisor != 0 {
				break LOOP
			}
		}
		count++
	}
	fmt.Println(count)
}


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

int euc(int a, int b) {
  if(a < b) {
    return euc(b, a);
  }
  
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int N;
  cin >> N;
  set<int> A, B;
  
  for(int i=0; i<N; i++) {
    int tmp;
    cin >> tmp;
    A.insert(tmp);
  }
  
  int gcd = *A.begin();
  for(auto a:A) {
    gcd = euc(a, gcd);
  }
  
  cout << gcd << endl;
  
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
using namespace std;
int N,W;

int v[1005],w[1005];
int dp[105][10005];


void solve(void){
	for(int i=0;i< N ;i++){
		for(int j=0;j<=W  ;j++){
			if(j<w[i+1]){
				dp[i+1][j]=dp[i][j];
			}else{
				dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i+1]]+v[i+1]);
			}
		}
	}
}

int main(void){
	cin>>N>>W;
	for(int i=1;i<= N ;i++){
		cin>>v[i]>>w[i];
	}
	
	solve();
	cout<<dp[N][W]<<endl;
}


Measured memory_bytes: 7012
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;

using namespace std;

int main() {
    ll N,M;
    cin >> N >> M;
    vector<ll> x(N);
    vector<ll> y(N);
    vector<ll> z(N);
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll maxVal = 0;
    for(unsigned int i = 0; i < 8; i++){
        vector<ll> tmpVec(N);
        for(int j = 0; j < N; j++){
            ll tmp = 0;
            if(i & (1 << 0)){
                tmp += x[j];
            }else{
                tmp -= x[j];
            }
            if(i & (1 << 1)){
                tmp += y[j];
            }else{
                tmp -= y[j];
            }
            if(i & (1 << 2)){
                tmp += z[j];
            }else{
                tmp -= z[j];
            }
            tmpVec[j] = tmp;
        }
        sort(tmpVec.begin(),tmpVec.end(),greater<ll>());
        ll tmpVal = 0;
        for(int k = 0; k < M; k++){
            tmpVal += tmpVec[k];
        }
        maxVal = max(maxVal,tmpVal);
    }
    cout << maxVal << endl;
}


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

const int N = 2e5+10;

const double PI = 3.141592653;


int n,q;
int x,y;

vector<int> nums[N];
long long val[N];
bool vis[N];

void dfs(int idx)
{
    vis[idx] = true;
    for(int i = 0; i < nums[idx].size(); i++)
    {
        if(!vis[nums[idx][i]])
        {
            val[nums[idx][i]]+=val[idx];
            dfs(nums[idx][i]);
        }
    }
}


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

    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    scanf("%d%d",&n,&q);
    for(int i = 0; i < n-1; i++)
    {
        scanf("%d%d",&x,&y);
        nums[x].push_back(y);
        nums[y].push_back(x);
    }

    for(int i = 0; i < q; i++)
    {
        scanf("%d%d",&x,&y);
        val[x]+=y;
    }
    dfs(1);
    for(int i = 1;i<= n; i++)
        printf("%I64d ",val[i]);
    return 0;
}


Measured memory_bytes: 35072
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    char x;
    cin >> x;
    if(x<='Z' && x>='A'){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        pq.push(make_pair(b, a));
    }
    ll cur = 0;
    while(!pq.empty()) {
        auto p = pq.top(); pq.pop();
        if ((cur + p.second) > p.first) {
            cout << "No" << endl;
            return 0;
        }
        cur += p.second;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 6128
#include <iostream>
using namespace std;
int a[200005],n;
bool b[200005];
bool pd(int x){for(int i=1;i<=n*2-1;i++) b[i]=(a[i]>=x);b[0]=b[1];
	for(int i=n;i<=n+n;i++){if(b[i]==b[i+1])return b[i];if(b[n+n-i]==b[n+n-i-1])return b[n+n-i];}
}
int main(){
cin>>n;
for(int i=1;i<=n*2-1;i++)cin>>a[i];
int l=1,r=n*2,A=0,md;
while(l<=r){md=(l+r)/2;if(pd(md))l=md+1,A=md;else r=md-1;}cout<<A;}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
const int N = 2e5;
long h[N];                                                                                                              
int main() {
        long n, k;                                                                                                              std::cin >> n >> k;                                                                                                     for (int i = 0; i < n; ++i) {                                                                                                   std::cin >> h[i];
        }

        std::sort(h, h+n);                                                                                                      long sum = 0;
        for (int i = n - k - 1; i >= 0; --i) {                                                                                          sum += h[i];
        }                                                                                                               
        std::cout << sum << '\n';                                                                                       
        return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<math.h>
#include<deque>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    vector<int> ans;
    int sz = n;
    while(!b.empty()) {
        int best = -1;
        rep(i, sz) {
            if ( b[i] == i + 1 ) {
                best = i;
            }
        }
        if ( best == -1 ) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(best+1);
        b.erase(b.begin()+best);
        --sz;
    }

    reverse(ans.begin(), ans.end());
    for ( int v : ans ) {
        cout << v << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = input()

s = s[::-1]
s += "0"
l = len(s)

dp = [[float("inf")] * 2 for _ in range(l + 1)]
dp[0][0] = 0

for i, e in enumerate(s):
    for j in range(2):
        x = int(e)
        x += j
        for a in range(10):
            ni = i + 1
            nj = 0
            b = a - x
            if b < 0:
                nj = 1
                b += 10

            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)

ans = dp[l][0]
print(ans)


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{


    vector<pll> v;
    ll m, n;
    cin >> n >> m;
    for(ll i = 0; i < n; i++)
    {

        ll x,y;
        cin >> x >> y;
        v.pb(mp(x,y));
    }
    ll ans = 0;
    sort(v.begin(), v.end());
    for(ll i = 0; i < v.size(); i++)
    {

        if(m >= v[i].ss)
        {

            ans+=v[i].ss*v[i].ff;
            m-=v[i].ss;
        }
        else
        {

            ans+=m*v[i].ff;
            m = 0;
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 2420
$field
$visited
$cnt
$b_flg
$w_flg
$w
$h
$dy = Array[0, -1, 0, 1]
$dx = Array[1, 0, -1, 0]

def search(i, j)
  $cnt += 1
  $visited[i][j] = true

  for k in 0...4
    y = i + $dy[k]
    x = j + $dx[k]
    if y < 0 || $h <= y
      next
    end
    if x < 0 || $w <= x
      next
    end
    if $visited[y][x]
      next
    end
    if $field[y][x] == 'B'
      $b_flg = true
    elsif $field[y][x] == 'W'
      $w_flg = true
    else
      search(y, x)
    end
  end
end

loop do
  $w, $h = gets.chomp.split.map(&:to_i)

  if $w == 0 && $h == 0
    break;
  end

  $field = Array.new($h)
  $visited = Array.new($h)

  for i in 0...$h
    $field[i] = gets.chomp.split(//).map(&:to_s)
    $visited[i] = Array.new($w, false)
  end

  ans_b = ans_w = 0

  for i in 0...$h
    for j in 0...$w
      if $field[i][j] == '.' && !$visited[i][j]
        $b_flg = $w_flg = false
        $cnt = 0
        search(i, j)
        if $b_flg && !$w_flg
          ans_b += $cnt
        elsif !$b_flg && $w_flg
          ans_w += $cnt
        end
      end
    end
  end

  puts "#{ans_b} #{ans_w}"
end

Measured memory_bytes: 10096
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm>   //sort,二分探索,など
#include <bitset>      //固定長bit集合
#include <chrono>      //実行時間計測
#include <cmath>       //pow,logなど
#include <complex>     //複素数
#include <deque>       //両端アクセスのキュー
#include <functional>  //sortのgreater
#include <iomanip>     //setprecision(浮動小数点の出力の誤差)
#include <iostream>    //入出力
#include <iterator>    //集合演算(積集合,和集合,差集合など)
#include <map>         //map(辞書)
#include <numeric>     //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>       //キュー
#include <set>         //集合（順序保持）
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>  //可変長配列
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, n) for (int i = 0; i < ll(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < ll(b); i++)
#define FORD(i, a, b) for (int i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
const long long INF = 1e12;
const int MOD = 1e9 + 7;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
#define int long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
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;
}

signed main() {

    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    REP(i, n) { cin >> A.at(i); }
    sort(ALL(A));
    reverse(ALL(A));
    int cnt = 0;

    FOR(i, k, n) { cnt += A[i]; }
    print(cnt);
}


Measured memory_bytes: 4800