akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 4 * 3;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> c(m), x(n);
        for(int i=0; i<m; ++i)
            cin >> c[i];
        for(int i=0; i<n; ++i)
            cin >> x[i];

        vector<int> dp(256, INF);
        dp[128] = 0;
        for(int i=0; i<n; ++i){
            vector<int> next(256, INF);
            for(int j=0; j<256; ++j){
                for(int k=0; k<m; ++k){
                    int a = max(0, min(255, j + c[k]));
                    next[a] = min(next[a], dp[j] + (x[i] - a) * (x[i] - a));
                }
            }
            dp.swap(next);
        }

        cout << *min_element(dp.begin(), dp.end()) << endl;
    }
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

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

	if (2 > (b - a)) {
		cout << k + 1 << '\n';
	} else {
		if (k < a - 1) {
			cout << k + 1 << '\n';
		} else {
			k -= (a - 1);
			ll x = a;
			x += (k / 2) * (b - a) + k % 2;
			cout << x << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
 
int main(void){
  int x,y;
 
  scanf("%d%d",&x,&y);
  while(x!=0||y!=0){
    printf("%d %d\n",x<y?x:y,x<y?y:x);
    scanf("%d%d",&x,&y);
  }
  return 0;
}

Measured memory_bytes: 1028
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

ln = [0]
for i in range(n):
  ln += [ln[i] + (s[i-1:i+1]=='AC')]

for _ in range(q):
  l, r = f()
  print(ln[r] - ln[l])

Measured memory_bytes: 7948
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            string s = cin.next();

            long ans = 0;
            for (int i = 0; i < 1 << (s.Length - 1); i++)
            {
                string siki = s[0].ToString();
                int p = 1;
                for (int j = 0; j < s.Length - 1; j++)
                {
                    if ((i >> j & 1) == 1)
                    {
                        siki += "+" + s[p];
                    }
                    else
                    {
                        siki += s[p];
                    }
                    p++;
                }
                ans += Calc(siki);
            }

            Console.WriteLine(ans);
        }

        long Calc(string s)
        {
            string[] array = s.Split('+');
            long result = 0;
            for (int i = 0; i < array.Length; i++)
            {
                result += long.Parse(array[i]);
            }

            return result;
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
	private int[] a;
	
	private Scanner sc;

	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		int lim = Integer.parseInt(sc.next());
		
		a = new int[lim];
		for (int i = 0; i < lim; i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		int p = partition(0, lim - 1);
		
		StringBuilder sb = new StringBuilder();
		sb.append(a[0]);
		for (int i = 1; i < lim; i++) {
			if (i == p) sb.append(" [" + a[i] + "]");
			else sb.append(" " + a[i]);	
		}
		System.out.println(sb);
	}
	
	private int partition(int p, int r) {
		int x = a[r];
		int i = p - 1;
		
		int tmp;
		
		for (int j = p; j < r; j++) {
			if (a[j] <= x) {
				i = i + 1;
				
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
		
		tmp = a[i + 1];
		a[i + 1] = a[r];
		a[r] = tmp;
		return (i + 1);
	}
}

Measured memory_bytes: 68084
package main

import "fmt"

func main() {
    var a, b, c int64
    var n, y int64
    fmt.Scan(&n, &y)

    // 10000 * a + 5000 * b + 1000 * c = Y
    // a + b + c = N
    for a = 0; 10000*a <= y; a++ {
        for b = 0; 10000*a + 5000*b <= y; b++ {
            c = n-a-b
            if y - 10000*a - 5000*b == 1000*c {
                fmt.Println(a, b, c)
                return
            }
        }
    }
    fmt.Println(-1, -1, -1)
}

Measured memory_bytes: 512
#include<iostream>

int main() {
	int n, m, cnt = 0;
	std::cin >> n >> m;
	for (int i = 0; i < 2; i++) {
		if (m > n) {
			cnt += m;
			m--;
		}
		else {
			cnt += n;
			n--;
		}
	}
	std::cout << cnt << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w,c=0;
  cin>>h>>w;
  char s[h+1][w+1];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
      if(s[i][j]=='#')
        c++;
    }
  }
  if(s[0][0]!='#'||s[h-1][w-1]!='#'){
    cout<<"Impossible";
    return 0;
  }
  int i=0,j=0,k=1;
  while(i!=h-1||j!=w-1){
    if(s[i+1][j]=='#'){
      i++;
      k++;
    }else if(s[i][j+1]=='#'){
      j++;
      k++;
    }else{
      cout<<"Impossible";
      return 0;
    }
  }
  cout<<(c==k?"Possible":"Impossible");
}


Measured memory_bytes: 256
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8,i8,i8[:],i8[:]), cache=True)
def main(N,K,P,C):
  INF = 1<<30
  ans = -INF
  for i in range(N):
    score = 0
    now = i
    visited = np.full(N,-1,np.int64)
    scores = np.zeros(N,np.int64)
    visited[now] = 0
    for j in range(1,K+1):
      now = P[now]
      score += C[now]
      ans = max(ans, score)
      if visited[now]>=0:
        cyc = j - visited[now]
        up = score - scores[now]
        break
      scores[now] = score
      visited[now] = j
    else:
      continue
    if up<=0:
      continue
    cnt = j+1
    if K-cyc>=j:
      score += (K-cyc-j)//cyc * up
      ans = max(ans, score)
      cnt += (K-cyc-j)//cyc*cyc
    for j in range(cnt,K+1):
      now = P[now]
      score += C[now]
      ans = max(ans, score)
  return ans

N, K = map(int, input().split())
P = np.array(list(map(lambda x:int(x)-1, input().split())))
C = np.array(list(map(int, input().split())))

print(main(N,K,P,C))

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll T1,T2; cin >> T1 >> T2;
    ll A1, A2; cin >> A1 >> A2;
    ll B1, B2; cin >> B1 >> B2;
    if(A1 < B1 && A1*T1+A2*T2 < B1*T1+B2*T2){
        cout << 0 << endl;
        return 0;
    }
    if(A1 > B1 && A1*T1+A2*T2 > B1*T1+B2*T2){
        cout << 0 << endl;
        return 0;
    }
    if(A1*T1+A2*T2 == B1*T1+B2*T2){
        cout << "infinity" << endl;
        return 0;
    }

    if(B1 > A1){
        swap(A1,B1);
        swap(A2,B2);
    }
    ll s = (B1-A1)*T1 + (B2-A2)*T2;
    ll ans = (A1-B1)*T1/s + (B2-A2)*T2/s;
    if((B2-A2)*T2%s == 0) ans--;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10;
const ll inf = 1ll<<60;
struct Seg{
    ll mn[N<<2] , add[N<<2];
    void Add(int c,int l,int r,int L,int R,ll d){
        if(L<=l&&r<=R) mn[c]+=d,add[c]+=d;
        else {
            int m=(l+r)>>1;
            if(L<=m) Add(c<<1,l,m,L,R,d);
            if(R>m) Add(c<<1|1,m+1,r,L,R,d);
            mn[c]=min(mn[c<<1],mn[c<<1|1])+add[c];
        }
    }
    ll query(int c,int l,int r,int L,int R){
        if(L<=l&&r<=R) return mn[c];
        else {
            int m=(l+r)>>1;
            ll res=inf<<2;
            if(L<=m) res=min(res,query(c<<1,l,m,L,R));
            if(R>m) res=min(res,query(c<<1|1,m+1,r,L,R));
            return res+add[c];
        }
    }
};
Seg f1 , f2;
int n,Q,A,B;

int main(){
    scanf("%d%d%d%d",&n,&Q,&A,&B);
    rep(i,1,n+1) {
        if(i == A) f1.Add(1,1,n,i,i,i);
        else f1.Add(1,1,n,i,i,inf+i);
        if(i == A) f2.Add(1,1,n,i,i,-i);
        else f2.Add(1,1,n,i,i,inf-i);
    }
    rep(i,0,Q){
        int x;
        scanf("%d",&x);
        ll bestr = f1.query(1,1,n,x,n)-x;
        ll bestl = f2.query(1,1,n,1,x)+x;
        ll best = min(bestl , bestr);
        int costB = abs(x - B);
        f1.Add(1,1,n,1,n,costB);
        f2.Add(1,1,n,1,n,costB);
        ll past = f1.query(1,1,n,B,B)-B;
        if(best < past) {
            f1.Add(1,1,n,B,B,-past+best);
            f2.Add(1,1,n,B,B,-past+best);
        }
        B = x;
    }
    ll ans = inf;
    rep(i,1,n+1) ans=min(ans,f1.query(1,1,n,i,i)-i);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){

     //GO BACK AND UNDERSTAND THE PROBLEM!!
      int n,a,b;
      cin>>n>>a>>b;
      if(a==0){
          cout<<0<<"\n";
          return 0;
      }
      int ans=0;
      ans+=(n/(a+b))*a;
      ans+=min((n%(a+b)),a);
      cout<<ans<<"\n";
      
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 3612
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int fir[100010],dis[200010],nxt[200010],id;
int qd[100010],qx[100010],qc[100010],ans[100010];
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
int f[100010][11];
void dfs(int x,int y,int c){
	f[x][y]=c;for(int i=y-1;~i&&!f[x][i];--i)f[x][i]=c;if(!y)return;
	for(int i=fir[x];i;i=nxt[i])if(!f[dis[i]][y-1])dfs(dis[i],y-1,c);
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),a,b;
	for(int i=1;i<=m;++i)a=gi(),b=gi(),link(a,b),link(b,a);
	int q=gi();
	for(int i=1;i<=q;++i)qx[i]=gi(),qd[i]=gi(),qc[i]=gi();
	for(int i=q;i;--i)if(!f[qx[i]][qd[i]])dfs(qx[i],qd[i],qc[i]);
	for(int i=1;i<=n;++i){
		int res=0;
		for(int j=0;j<=10;++j)if(f[i][j]){res=f[i][j];break;}
		printf("%d\n",res);
	}
	return 0;
}


Measured memory_bytes: 8448
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, T;
vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> T;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int ans = 0;
  int max_diff = 0;
  int min_v = A[0];
  int max_v = 0;
  for (int i = 1; i < N; i++) {
    if (A[i] < min_v) {
      min_v = A[i];
      max_v = 0;
    } else if (A[i] > max_v) {
      max_v = A[i];
      int diff = max_v - min_v;
      if (max_diff == diff) {
        ans++;
      } else if (diff > max_diff) {
        ans = 1;
        max_diff = diff;
      }
    }
  }

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

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

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

const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, l[N], r[N], deg[N], vis[N], tree[N], par[N], d[N];

void dfs(int u) {
  vis[u] = 1;
  for (int i : adj[u]) {
    int v = u ^ l[i] ^ r[i];
    if (!vis[v]) {
      par[v] = i;
      tree[i] = 1;
      d[v] = d[u] + 1;
      dfs(v);
    }
  }
}

int main() {
  scanf("%d %d", &n, &m);
  if(m & 1) {
    puts("-1");
    exit(0); 
  }

  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &l[i], &r[i]);
    adj[l[i]].push_back(i);
    adj[r[i]].push_back(i);
  }

  dfs(1);

  for (int i = 1; i <= m; ++i) {
    if (!tree[i]) deg[l[i]] ^= 1;
  }

  vector<int> id(n - 1);
  iota(id.begin(), id.end(), 2);
  sort(id.begin(), id.end(), [](int i, int j) { return d[i] > d[j]; });

  for (int u : id) {
    int e = par[u];
    if(deg[u] ^ (l[e] == u)) swap(l[e], r[e]); 
    deg[l[e]] ^= 1;
  }

  for (int i = 1; i <= m; ++i) {
    printf("%d %d\n", l[i], r[i]);
  }
}


Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;

  ll sum = 0;

  rep(i,k) {
    if(a > 0) {
      sum++;
      a--;
    }
    else if(b > 0) {
      b--;
    }
    else if(c > 0) {
      sum--;
      c--;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		/*
		 * Nは参加者数、Kは初期ポイント、Qはクイズの数
		 * A(i)は正解した人の名前
		 * 出力は1行ごとにその人の合否判定
		 *正解の人はポイント増えなくてその他だけ減るが、
		 *全員全問不正解、正答者のみ+1と考える
		 */
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		int[] mens = new int[n];

		for(int i = 0; i < n; i++) {
			mens[i] = k - q;
		}
		
		
		for(int i = 0; i < q; i++) {
			int j = sc.nextInt() - 1;
			mens[j]++;
			
		}
		for(int man: mens) {
			if(man > 0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

}


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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  string s;
  double ans = 0;

  int n;
  cin >> n;
  rep(i, 0, n - 1) {
    int a;
    cin >> a;
    ans += double(1) / a;
  }

  cout << setprecision(10) << double(1) / ans << endl;

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>){
	How_Many_Divisors()
}

fun How_Many_Divisors(){
	val d = readLine()!!.split(" ").map(String::toInt)
	val a = d[0]; val b = d[1]; val c = d[2]
	val divisors: MutableList<Int> = mutableListOf()
	var divisor_num = 0
	for(i in 1..c){
		if(c%i==0){
			divisors.add(i)
		}
	}
	for(i in a..b){
		for(j in divisors){
			if(i==j){
				divisor_num++
			}
		}
	}
	println(divisor_num)
}


Measured memory_bytes: 32692
n, w = map(int, input().split())
IN = []
for _ in range(n):
    IN.append(list(map(int, input().split())))

DP = [[0] * (w + 1) for _ in range(n + 1)]

for i in range(n):
    cv, cw = IN[i]
    for j in range(w + 1):
        if j - cw >= 0:
            DP[i + 1][j] = max(DP[i][j - cw] + cv, DP[i][j])            
        else:
            DP[i + 1][j] = DP[i][j]
print(max(sum(DP, [])))



Measured memory_bytes: 57664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

ll a[200001],b[200001];
int main(){
    int n;
    cin>>n;
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    ll cur1=a[n/2-1],cur2=a[n/2];
    rep(i,n){
        if(b[i]>cur1){
            cout<<cur1<<endl;
        }
        else{
            cout<<cur2<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

struct TP{
	double time;
	int vel, prev, cur;
	TP(double time, int vel, int cur, int prev) : time(time), vel(vel), cur(cur), prev(prev){}

	bool operator< (const TP& a) const{
		return time > a.time;
	}
};

int acc[3] = {-1, 0, 1};

struct Edge{
	int to, cost, limit;
	Edge(int to, int cost, int limit) : to(to), cost(cost), limit(limit) {}
};

vector<vector<Edge>> graph;

double tm[35][35][35];

void dijkstra(int s){
	fill((double*)tm, (double*)tm + sizeof(tm) / sizeof(double), INF);
	tm[s][0][s] = 0;
	priority_queue<TP> que;
	que.emplace(tm[s][0][s], 0, s, s);
	while(!que.empty()){
		auto v = que.top();
		que.pop();
		int cur = v.cur;
		double t = v.time;
		int cur_vel = v.vel;
		int prev = v.prev;
		if(t > tm[cur][cur_vel][prev])continue;

		for(auto nv : graph[cur]){
			if(nv.to == prev)continue;

			for(int i = 0; i < 3; ++i){
				int nxt_vel = cur_vel + acc[i];
				if(nxt_vel <= 0 || nv.limit < nxt_vel)continue;

				double nt = (double)nv.cost / (double)nxt_vel;
				if(tm[cur][cur_vel][prev] + nt < tm[nv.to][nxt_vel][cur]){
					tm[nv.to][nxt_vel][cur] = tm[cur][cur_vel][prev] + nt;
					que.emplace(tm[nv.to][nxt_vel][cur], nxt_vel, nv.to, cur);
				}
			}
			
		}
	}
}

int main(){
  while(true){
  	int n, m, s, g;
  	cin >> n >> m;
  	if(n == 0)return 0;
  	cin >> s >> g;
  	--s;
  	--g;
  	graph.clear();
  	graph.resize(n);
  	for(int i = 0; i < m; ++i){
  		int x, y, d, c;
  		cin >> x >> y >> d >> c;
  		--x;
  		--y;
  		graph[x].emplace_back(y, d, c);
  		graph[y].emplace_back(x, d, c);
  	}

  	dijkstra(s);

  	double ans = INF;
  	for(int i = 0; i < n; ++i){
  		ans = min(ans, tm[g][1][i]);
  	}

  	if(ans == INF)cout << "unreachable" << endl;
  	else printf("%.5lf\n", ans);
  }
  return 0;
}



Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a) cout << "delicious" << endl;
  if (b > a && b <= a + x) cout << "safe" << endl;
  if (b > a + x) cout << "dangerous" << endl;
}

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

using namespace std;

const int N=2e5+10;
int n,m,k;
int a[N];
int solve(){
    int ans=0;
    for(int st=1;st<=n;){
        ans++;
        int en=st;
        while (en-st<m&&a[en]-a[st]<=k) en++;
        st=en;
    }
    return ans;
}
int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    sort(a+1,a+n+1);
    cout<<solve()<<'\n';
}


Measured memory_bytes: 640
package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	K := nextInt()

	anser := N % K
	if anser == 0 {
		fmt.Println(anser)
	} else {
		anserA := anser
		anserB := anser - K
		if anserB < 0 {
			anserB *= -1
		}
		if anserA > anserB {
			fmt.Println(anserB)
		} else {
			fmt.Println(anserA)
		}
	}
}


Measured memory_bytes: 1756
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
P = LIST()
Q = LIST()
 
def Numth(R, N):
  ORDER = [1]*N
  c = 0
  for i in range(N-1):
    c += (ORDER[:R[i]].count(1) - 1) *factorial(N-i-1)
    ORDER[R[i]-1] = 0 
  return c+1

print(abs(Numth(P, N)-Numth(Q, N)))

Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto x : v) cerr << x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int i = 0; i < (n); ++i) cerr << a[i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
char S[45];
const int MAXN = 45;
const ll P1 = 998244353;
const ll Q1 = 107;
const ll P2 = 1000000007;
const ll Q2 = 103;
ll p1[MAXN];
ll p2[MAXN];
int main() {
	p1[0] = 1;
	p2[0] = 1;
	for (int i = 1; i < MAXN; ++i) {
		p1[i] = p1[i - 1] * Q1 % P1;
		p2[i] = p2[i - 1] * Q2 % P2;
	}
	map<pair<int, pair<ll, ll>>, int> H;
	int N;
	scanf("%d%s", &N, S);
	for (int i = 0; i < (1 << N); ++i) {
		ll x1 = 0, y1 = 0;
		ll x2 = 0, y2 = 0;
		for (int j = 0; j < N; ++j) {
			if (i & (1 << j)) {
				x1 = x1 * Q1 + (S[j] - 'a');
				x1 %= P1;
				x2 = x2 * Q2 + (S[j] - 'a');
				x2 %= P2;
			}
		}
		for (int j = N - 1; j >= 0; --j) {
			if (!(i & (1 << j))) {
				y1 = y1 * Q1 + (S[j] - 'a');
				y1 %= P1;
				y2 = y2 * Q2 + (S[j] - 'a');
				y2 %= P2;
			}
		}
		int xlen = __builtin_popcount(i);
		ll h = (x1 * p1[N - xlen] - y1) % P1;
		if (h < 0) h += P1;
		ll h2 = (x2 * p2[N - xlen] - y2) % P2;
		if (h2 < 0) h2 += P2;
		++H[{xlen, {h, h2}}];
	}
	ll ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		ll x1 = 0, y1 = 0;
		ll x2 = 0, y2 = 0;
		for (int j = 0; j < N; ++j) {
			if (i & (1 << j)) {
				x1 = x1 * Q1 + (S[N + j] - 'a');
				x1 %= P1;
				x2 = x2 * Q2 + (S[N + j] - 'a');
				x2 %= P2;
			}
		}
		for (int j = N - 1; j >= 0; --j) {
			if (!(i & (1 << j))) {
				y1 = y1 * Q1 + (S[N + j] - 'a');
				y1 %= P1;
				y2 = y2 * Q2 + (S[N + j] - 'a');
				y2 %= P2;
			}
		}
		int xlen = __builtin_popcount(i);
		int rem = N - xlen;
		ll h = (y1 * p1[xlen] - x1) % P1;
		if (h < 0) h += P1;
		ll h2 = (y2 * p2[xlen] - x2) % P2;
		if (h2 < 0) h2 += P2;
		auto it = H.find({rem, {h, h2}});
		if (it != H.end()) ans += it->second;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 20736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll h, w;
    cin >> h >> w;

    if (h > w) swap(h, w);

    if (h == 1) {
        cout << 1 << endl;
    } else {
        cout << (h * w + 1) / 2 << endl;
    }

    return 0;
}

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

    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if( r > x || r > y ){
        printf("No\n");
    }
    else if( x+r > W || y+r > H ){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    return 0;
}

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

int main() {
	// your code goes here
	int n;int k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
// 	int dp[n]={INT_MAX};
    int dp[n];
	dp[0]=0;dp[1]=dp[0]+abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
	    int rem=INT_MAX;
	    for(int j=1;j<=k;j++){
	        if(j<=i){
	            rem=min(rem,(dp[i-j]+abs(arr[i]-arr[i-j])));    
	        }
	        else{
	            break;
	        }
	    }
	    dp[i]=rem;
	}
	cout<<dp[n-1];
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;
 
int main() {
    ios_base::sync_with_stdio(false);
    ll x; cin >> x;
    x = (x*(x-1)) >> 1;
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string n;
    cin >> n;

    bool isgood = false;
    if (n[0] == n[1] && n[1] == n[2]) isgood = true;
    if (n[1] == n[2] && n[2] == n[3]) isgood = true;
    
    if (isgood)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sun Dec 30 18:56:23 2018
//
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	if N == 1 && M == 1 {
		fmt.Println(1)
	} else if N == 1 || M == 1 {
		fmt.Println(N*M - 2)
	} else if N == 2 || M == 2 {
		fmt.Println(0)
	} else {
		fmt.Println((N - 2) * (M - 2))
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int const INF = 1e9;

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

    int n,d,ans=0; cin>>n>>d; float x[n][d];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < d; j++){
            cin>>x[i][j];
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            float key=0;
            for (int k = 0; k < d; k++){
                key+=pow(x[i][k]-x[j][k],2);
            }
            key=sqrt(key);
            if(ceil(key)==floor(key))ans++;
        }
    }
    cout<<ans<<'\n';
}

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

int main(){
    int S, h, m, s;
    cin >> S;
    h = S / 3600 ;
    m = (S - 3600*h) / 60;
    s = S - 3600*h - 60*m ;

    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3096
/*
 *
 */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
  int n;

  cin >> n;

  long long pro = 1;

  long long limit = 1e18;
  
  long long a;

  int is_zero = 0;
  int is_exceed = 0;
  
  while (n--) {
    scanf("%lld", &a);

    if (is_zero)
      continue;

    if (a == 0)
      is_zero = 1;
    else if (pro > (limit / a))
      is_exceed = 1;
    else
      pro *= a;
  }

  if (is_zero)
    cout << 0 << endl;
  else if (is_exceed)
    cout << -1 << endl;
  else
    cout << pro << endl;
  
  return 0;
}


Measured memory_bytes: 3768
n,a,b = gets.split.map(&:to_i)
s = gets.strip

passed = 0
abroad = b

s.chars.each do |char|
  if char == 'a'
    if passed < a + b
      puts 'Yes'
      passed += 1
    else
      puts 'No'
    end
  elsif char == 'b'
    if passed < a + b && abroad > 0
      puts 'Yes'
      abroad -= 1
      passed += 1
    else
      puts 'No'
    end
  else
    puts 'No'
  end
end

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=2e5 + 5;

int n,q;
vector<int> g[N];
int val[N]={0};
int ans[N] = {0};
int vis[N] = {0};

void dfs(int i)
{
	vis[i]=1;
	ans[i] += val[i];
	for(auto it:g[i])
	{
		if(vis[it]==0)
		{
			ans[it] += ans[i];
			dfs(it); 
		}
	}
}

int32_t main()
{
	IOS;
	cin >> n >> q;
	rep(i,1,n-1)
	{
		int x,y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);	
	}	
	rep(i,1,q)
	{
		int x,y;
		cin >> x >> y;
		val[x] += y;
	}	
	dfs(1);
	rep(i,1,n)
	{
		cout << ans[i] << " ";
	}
	cout << endl;
}


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

struct Activity{
    int a,b,c;
};

int solve(vector< Activity > vec, int n){
    vector < Activity > dp(n);

    dp[0].a = vec[0].a;
    dp[0].b = vec[0].b;
    dp[0].c = vec[0].c;

    for (int i=1 ; i<n ; i++ ){
        dp[i].a = vec[i].a + max ( dp[i-1].c, dp[i-1].b );
        dp[i].b = vec[i].b + max ( dp[i-1].a, dp[i-1].c );
        dp[i].c = vec[i].c + max ( dp[i-1].b, dp[i-1].a );
    }

    return max( dp[n-1].a, max(dp[n-1].b, dp[n-1].c));
}

int main(){
    Activity A;
    int n;
    cin>>n;
    vector< Activity > vec(n);

    for (int i=0; i<n ; i++){
        cin >> vec[i].a;
        cin >> vec[i].b;
        cin >> vec[i].c;
    } 

    cout<<solve(vec, n);
}

Measured memory_bytes: 6696
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    cout << T + S << endl;
}

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

typedef long long i64 ;
typedef pair<i64,i64> P;

int n;
int k;

vector<i64> x,y;

i64 INF = (1LL << 62);

i64 ans = (1LL << 62);

#define MIN(a,b) a = min(a,b)
#define MAX(a,b) a = max(a,b)

void rec(vector<int>& vec)
{

	if(vec.size() == 4)
	{
		i64 mi_x = INF;
		i64 ma_x = -INF;
		i64 mi_y = INF;
		i64 ma_y = -INF;

		for(int i : vec)
		{
			MIN(mi_x,x[i]);
			MAX(ma_x,x[i]);
			MIN(mi_y,y[i]);
			MAX(ma_y,y[i]);
		}

		int cou = 0;

		for(int i = 0;i < n;i++)
		{
			if(mi_x <= x[i] && x[i] <= ma_x && mi_y <= y[i] && y[i] <= ma_y)
			{
				cou++;
			}
		}

		if(cou >= k)
		{
			ans = min(ans , (ma_x - mi_x) * (ma_y - mi_y));
		}
		return;
	}

	for(int i = 0;i < n;i++)
	{
		vec.push_back(i);
		rec(vec);
		vec.pop_back();
	}
}



int main()
{
	cin >> n >> k;
	x.assign(n,0);
	y.assign(n,0);

	

	for(int i = 0;i < n;i++)
	{
		cin >> x[i] >> y[i];

	}

	vector<int> vec;
	rec(vec);

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


Measured memory_bytes: 256
"use strict";

main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.split("\n");

  const slimes_num = parseInt(input[0]);
  let slimes_color = input[1].split("");

  for (let i = 0; i < slimes_color.length - 1; i++) {
    if (slimes_color[i] === slimes_color[i + 1]) {
      slimes_color[i] = "";
    }
  }

  let result = slimes_color.filter(c => c !== "");
  console.log(result.length);
}


Measured memory_bytes: 22088
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B;
	cin >> A >> B;
	if (B<0&&A>=0){
		cout << A - B << endl;
	}else{
		cout << (A+B<A*B?A*B:A+B) << endl;
	}
}


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

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define mod 1000000007
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int main(){
    int n,h=0,ans=0;
    cin>>n;
    for (int i=1;i<=n;i++){
        int x;cin>>x;
        if (x>=h)ans++;
        h=max(h,x);
    }
    cout<<ans;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--){
		ll w, h;
		cin >> w >> h;
		if(w % 2 + h % 2 == 1){
			cout << "1 1" << endl;
			continue;
		}
		const ll g = __gcd(w, h);
		const ll d = (w / g) * (h / g);
		const ll x = ((d + 1) / 2);
		const ll y = (d / 2);
		const ll z = __gcd(x, y);
		cout << x / z << " " << y / z << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
//
//#include <iostream>
//#include<cmath>
//
//using namespace std;
//
//int main()
//{
//    long long a;
//    double b;
//
//    cin >> a >> b;
//
//    double ans = floor((a * b));
//   // cout << ans << endl;
//   // long long x = (long long)ans;
//
//    printf("%.0f", ans);
//
//}

#include<stdio.h>
#include<iostream>
using namespace std;
long long a[100010];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];

	int zero = 0;

	for (int i = 0; i < n; i++)if (a[i] == 0)zero++;

	if (zero > 0) {
		printf("0\n");
		return 0;
	}

	long long prod = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] <= 1000000000000000000 / prod) {
			prod *= a[i];
		}
		else {
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", prod);
}

Measured memory_bytes: 4424
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int n,a,b;cin>>n>>a>>b;
  string s;cin>>s;
  int bno=1;int now=0;
  rep(i,n){
    if(s[i]=='c')cout<<"No";
    if(s[i]=='a'){
      if(now<a+b){
        cout<<"Yes";
        now++;
      }
      else cout<<"No";
    }
    if(s[i]=='b'){
      if(now<a+b){
        if(bno<=b){
          cout<<"Yes";
          now++;
        }
        else{
          cout<<"No";
        }
      }
      else{
        cout<<"No";
      }
      bno++;
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 896
sd = input()
t = input()
ans = []
if len(sd) < len(t):
    print('UNRESTORABLE')
    exit(0)
for i in range(len(sd)-len(t)+1):
    s = sd
    for j in range(len(t)):
        if sd[i+j] == t[j] or sd[i+j] == '?':
            s = s[:i+j] + t[j] + s[i+j+1:]
        else:
            break
    else:
        ans.append(s.replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(ans)[0])

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a == b)
		cout << "a == b"<< endl;//aとbが等しければa == bを出力
	else if (a > b)
		cout << "a > b" << endl;//aがbよりも大きければa > bを出力
	else
		cout << "a < b" << endl;//aがbよりも小さければa < bを出力
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> task(N);
  for (auto &p : task) cin >> p.second >> p.first;
  sort(task.begin(),task.end());
  
  int T = 0;
  for (int i = 0; i < N; i++) {
    T += task[i].second;
    if (T > task[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

vector<pair<Int,Int> > BA;
int N;

int main(void) {
    cin>>N;
    for(int i = 0;i < N;i++) {
        Int a,b;
        cin>>a>>b;
        BA.push_back(make_pair(b,a));
    }

    sort(BA.begin(),BA.end());

    Int t = 0;
    for(int i = 0;i < N;i++) {
        if(t+BA[i].second <= BA[i].first) {
            t += BA[i].second;
        } else {
            cout<<"No"<<endl;

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

    return 0;
}




Measured memory_bytes: 6384
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;

inline int getBlockStart(int npos, int bakPos) {
    int nextBlock = (bakPos+1-2)/3 * 3 + 2;
    return npos < 0 ? nextBlock : max(nextBlock, (npos-2)/3*3 + 2);
}

inline int checkEqual(VI& A, int i, int j, int k){
    return A[i] == A[k] && A[i] == A[j];
}

inline void solve(VVI& dp, VI& A, int i, int j, int s) {
    if (s <= j && s+3 > j) {
        s += 3;
    }

    if (s <= j || j <= i) {
        return ;
    }

    int plus = s < A.size() ? checkEqual(A, i, j, s) : 0;
    dp[A.size()][A.size()] = max(dp[A.size()][A.size()], dp[i][j] + plus);

    if (s+2 < A.size()) {
        dp[i][s+0] = max(dp[i][s+0], dp[i][j] + checkEqual(A, j, s+1, s+2));
        dp[i][s+1] = max(dp[i][s+1], dp[i][j] + checkEqual(A, j, s+0, s+2));
        dp[i][s+2] = max(dp[i][s+2], dp[i][j] + checkEqual(A, j, s+0, s+1));

        dp[j][s+0] = max(dp[j][s+0], dp[i][j] + checkEqual(A, i, s+1, s+2));
        dp[j][s+1] = max(dp[j][s+1], dp[i][j] + checkEqual(A, i, s+0, s+2));
        dp[j][s+2] = max(dp[j][s+2], dp[i][j] + checkEqual(A, i, s+0, s+1));

        dp[s+0][s+1] = max(dp[s+0][s+1], dp[i][j] + checkEqual(A, i, j, s+2));
        dp[s+0][s+2] = max(dp[s+0][s+2], dp[i][j] + checkEqual(A, i, j, s+1));
        dp[s+1][s+2] = max(dp[s+1][s+2], dp[i][j] + checkEqual(A, i, j, s+0));
    }
}

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

    VI A;
    int ans = 0;

    for (int i = 0; i <= N; ++i) {
        // pattern: 2, 3, 3 .... , 1
        int upper = 2 + (i > 0) - 2*(i == N);
        for (int j = 0; j < upper; ++j) {
            int v;
            cin >> v;
            A.push_back(v);
        }

        while (A.size() >= 3) {
            int aSize = A.size();
            // cout << "GO " << aSize << endl;

            if (A[aSize-1] == A[aSize-2] && A[aSize-1] == A[aSize-3]) {
                A.pop_back();
                A.pop_back();
                A.pop_back();
                ++ans;
            } else {
                break;
            }
        }
    }

    VVI dp(A.size()+5, VI(A.size()+5, -1));
    VI curPos(N+5, -1);
    VI nextPos(A.size() + 1);

    for (int p = A.size()-1; p >= 0; --p) {
        nextPos[p] = curPos[A[p]];
        curPos[A[p]] = p;
    }

    dp[0][1] = 0;

    for (int i= 0; i < A.size(); ++i) {
       for (int j = i+1; j < A.size(); ++j) {
            if (dp[i][j] == -1) {
                continue;
            }

            solve(dp, A, i, j, getBlockStart(j+1, j));

            // match i
            solve(dp, A, i, j, getBlockStart(nextPos[i], j));

            // match j
            solve(dp, A, i, j, getBlockStart(nextPos[j], j));
       }
    }

    if (!A.empty()) {
        cout << ans + dp[A.size()][A.size()] << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 144572
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	
	int ans=0;
	REP(i,n-2)FOR(j,i+1,n-2)FOR(k,j+1,n-1){
		if(a[i]==a[j] or a[j]==a[k] or a[k]==a[i]) continue;
		vi tmp={a[i],a[j],a[k]};
		sort(ALL(tmp));
		if(tmp[0]+tmp[1]>tmp[2]) ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3628
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}


fn main() {
   input! {
      n: usize,
      a: [usize; n],
   }
   let mut set = std::collections::BTreeSet::new();
   for a in a.iter() {
      if set.contains(a) {
         set.remove(a);
      } else {
         set.insert(*a);
      }
   }
   println!("{}", set.len());
}


Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
ll x;
int A[2000];
int temp[2000];

int main() {
	cin >> N >> x;
	rep(i, N){cin >> A[i];}

	ll ans = INT64_MAX;

	rep(m, N){

		if(m != 0){

			rep(i, N){
				int j = i==0 ? N-1 : i-1;
				temp[i] = min(A[i], A[j]);
			}
			rep(i, N){
				A[i] = temp[i];
			}
		}

		ll temp = m * x;
		rep(i, N) temp+=A[i];
		ans = min(ans, temp);
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

auto main() -> int{
    int N;
    vector<int> A;
    cin >> N;
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    for(auto a: A){
        if(a % 2 == 0){
            if(a%3==0 || a%5==0){
            }
            else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256