akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

inline void read() {}
template <class S>
inline void read(S &arg) {
  cin >> arg;
}
template <class S>
inline void read(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    read(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void read(S &arg, T &... rest) {
  read(arg);
  read(rest...);
}

inline void write() {}
template <class S>
inline void write(S arg) {
  cout << arg;
}
template <class S>
inline void weite(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    write(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void write(S arg, T... rest) {
  write(arg);
  write(rest...);
}

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

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

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 998244353;
constexpr int N = 2e5 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}
ll po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

int n;
ll a[N], b[N];

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

  read(n);
  read(a, a + n);
  read(b, b + n);

  if (accumulate(a, a + n, 0ll) < accumulate(b, b + n, 0ll))
    return write(-1, '\n'), 0;

  ll cnt = 0, res = 0;
  vi vec;
  rep(i, 0, n) {
    if (a[i] < b[i]) {
      cnt++;
      res += b[i] - a[i];
    } else
      vec.pb(a[i] - b[i]);
  }

  sort(all(vec), greater<int>());
  for (auto e : vec)
    if (res > 0) {
      res -= e;
      cnt++;
    }

  write(cnt, '\n');

  return 0;
}

// b[ptr] - b[r] + b[l] + (r - l) - (b[r] - b[l])
// b[ptr] - 2b[r] + r + 2b[l] - l


Measured memory_bytes: 2428
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let mut ans: usize = 0;
    let mut set = HashSet::new();
    for i in 1..n {
        let m = n - i;
        if i < m {
            set.insert((i, m));
        } else if m < i {
            set.insert((m, i));
        }
    }

    ans = set.len();
    println!("{}", ans);
}


Measured memory_bytes: 40984
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int a;
			int b,t;
			int n,m;
			String result;
			a = sc.nextInt();
			b = sc.nextInt();
			t = sc.nextInt();
			n=t/a;
			m=n*b;
			// 出力

			System.out.println(m);
	}
}

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


int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif
		int n;
		cin>>n;
		int h[n];
		for(int i=0;i<n;i++)
			cin>>h[i];
		if(n==2)
		{
			cout<<abs(h[1]-h[0])<<'\n';
			return 0;
		}
		int dp[n];
		memset(dp,0,n);
		int INF=INT_MAX;
		for(int i=1;i<n;i++)
		{
			dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(i-2)>=0?(dp[i-2]+abs(h[i]-h[i-2])):INF);
		}
		cout<<dp[n-1]<<'\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <list>
#include <cmath>
#include <iomanip>

int main()
{
    long double a,b,C;
    std::cin >> a >> b >> C;

    long double height = b * std::sin(C/180.0*M_PI);
    long double area = 1.0 / 2.0 *a * height;
    long double length = a + b +std::sqrt(std::pow(a - b * std::cos(C/180.0*M_PI),2) + std::pow(height, 2));

    std::cout << std::setprecision(8) << area << std::endl;
    std::cout << std::setprecision(8) << length << std::endl;
    std::cout << std::setprecision(8) << height << std::endl;

    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = (N / (A + B)) * A;
    ans += min(A, N % (A + B));
    cout << ans << endl;
}

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

int main(){
    int x;
    cin >> x;
    int count = 0;
    int rad = 0;
    for (int i = 0; i < 1000000; i++){
        rad += x;
        count++;
        
        if (rad == 360) {
            cout << count << "\n";
            return 0;
        }

        if (rad > 360) {
            rad -= 360;
        }
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll d;
    cin >> d;
    vll c(26);
    rep(i, 26) cin >> c[i];
    vvll s(d,vll(26));
    rep(i,d){
        rep(j,26) cin>>s[i][j];
    }
    ll v=0;
    vector<set<int>>set(26);
    vll ans(d);
    rep(i,26) set[i].insert(0);
    rep(i,d){
        ll ma=0;
        ll key=0;;
        rep(j,26){
            if(ma<c[j]*(i+1-(*--set[j].end()))+s[i][j]){
                key=j;
                ma=c[j]*(i+1-(*--set[j].end()))+s[i][j];
            }
            v-=c[j]*(i+1-(*(--set[j].end())));
        }
        set[key].insert(i+1);
        ans[i]=key;
    }
    bool flag=true;
    if(flag){
        rep(i,100000){
            ll day=rand()%d;
            ll cont=rand()%26;
            if(ans[day]==cont)continue;
            auto itr=set[ans[day]].find(day+1);
            ll prev=*--itr;ll next=*++itr;
            if(itr==set[ans[day]].end()) next=d+1;
            else next=*++itr;
            if(itr==set[ans[day]].begin()) prev=0;
            else prev=*--itr;
            ll lost=((next-prev-1)*(next-prev)/2-(next-day)*(next-day+1)/2-(day-prev)*(day-prev+1)/2)*c[ans[day]]+s[day][ans[day]];
            auto itr2=upper_bound(all(set[cont]),day+1);
            if(itr2==set[cont].end()) next=d+1;
            else next=*itr2;
            if(itr2==set[cont].begin()) prev=0;
            else prev=*--itr2;
            ll prof=((next-prev-1)*(next-prev)/2-(next-day+1)*(next-day)/2-(day-prev+1)*(day-prev)/2)*c[cont]+s[day][cont];
            if(prof>=lost){
                set[ans[day]].erase(day+1);
                ans[day]=cont;
                set[cont].insert(day+1);
            }
        }
    }
    rep(i,d){
        cout<<ans[i]+1<<endl;
    }
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << '\n';
 	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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


		    String str1 = scanner.next();

            int A = Integer.parseInt(str1);


            if(A % 2 == 0)
            {
            	System.out.println(A);
            }
            else
            {
            	System.out.println(A * 2);
            }
        	scanner.close();}
		  }


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

void bubblesort(char a[][3],int c[],int n){
  int i=0,j,s = 0,flag = 1,k,m;
  char x[3];
  while(flag != 0){
    flag = 0;
    for(j = n-1;j > i;j--){
      if(c[j-1] > c[j]){
	k = c[j];
	c[j] = c[j-1];
	c[j-1] = k;
	strcpy(x,a[j]);
	strcpy(a[j],a[j-1]);
	strcpy(a[j-1],x);
	flag = 1;
      }
    }
    i++;
  }
}

void selectsort(char b[][3],int e[],int n){
  int i,min,j,k,m;
   char x[3];

  for(i = 0;i < n-1; i++){
    min = i;
   for(j = i;j < n; j++){
    if(e[j] < e[min]){
      min = j;
     }
    }
   if(e[i] > e[min]){
      k = e[i];
      e[i] = e[min];
      e[min] = k;
      strcpy(x,b[i]);
      strcpy(b[i],b[min]);
      strcpy(b[min],x);
   }
  }
}

int main(){
  
  int i,n,result = 0,c[36],e[36];
  char a[36][3],b[36][3],*d;
  
   scanf("%d",&n);
  
  for(i = 0;i<n;i++){
    scanf("%s",a[i]);
    strcpy(b[i],a[i]);
    c[i] = (int)strtol(&b[i][1],&d,0);
    e[i] = c[i];
  }
  bubblesort(a,c,n);
  selectsort(b,e,n);
  for(i = 0;i<n;i++){
    if(i > 0)printf(" ");
    printf("%s",a[i]);
  }
  printf("\nStable\n");

   for(i = 0;i<n;i++){
    if(i > 0)printf(" ");
    printf("%s",b[i]);
    if(strcmp(a[i],b[i])==0)result++;
  }
   
   if(result == n)printf("\nStable\n");
   else printf("\nNot stable\n");
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 

ll fct[100005];
ll rfct[100005];

ll ncr(ll n,ll r){
    if(n==0&&r==0) return 1;
    return (fct[n]*((rfct[n-r]*rfct[r])%mod))%mod;
}
ll ns(ll n, ll s){
    s-=3*n;
    if(s<0) return 0;
    return ncr(s+n-1,s);
}
void solve(ll ts){
    //ll n; cin>>n; vector<ll>arr(n,0); rep(n) cin>>arr[i];
    ll s; cin>>s;
    //cout<<(pw(10,n)-pw(9,n)-pw(9,n)+pw(8,n)+mod+mod+mod+mod)%mod<<endl;
    ll tot=0;
    for(ll l=1;l<1000;l++) tot=(tot+ns(l,s))%mod;
    cout<<tot%mod<<endl;
}

//
int main(){
    fct[0]=1;
    rep(100005) if(i) fct[i]=(fct[i-1]*i)%mod;
    rep(100005) rfct[i]=pw(fct[i],mod-2);
//    rep(20) cout<<i<<":"<<fct[i]<<"*"<<rfct[i]<<" = "<<(fct[i]*rfct[i])%mod<<endl;
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define int long long
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n;
string s;
int cntj[100005],cnti[100005];
int dp[100005][4];
int ans;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    rep(i,n){
        char c=s[i];
        if (c=='J') cntj[i]=1;
        else if (c=='I') cnti[i]=1;
    }
    rep(i,n-1){
        cntj[i+1]+=cntj[i];
        cnti[n-2-i]+=cnti[n-1-i];
    }
    int idx=-1;
    int cnt=0;
    rep(i,n-1){
        if (cnt<cntj[i]*cnti[i+1]){
            cnt=cntj[i]*cnti[i+1];
            idx=i+1;
        }
    }
    int ans=0;
    rep(k,3){
        string tmps=s;
        if (k==0) tmps='J'+tmps;
        else if (k==1) tmps=tmps+'I';
        else {
            if (idx==-1) break;
            tmps.insert(tmps.begin()+idx,'O');
        }
        fill(dp[0],dp[n+2],0);
        dp[0][0]=1;
        rep(i,n+1)rep(j,4){
            char c=tmps[i];
            dp[i+1][j]+=dp[i][j];
            if (c=='J'){
                if (j==1) dp[i+1][j]+=dp[i][j-1];
            }
            else if (c=='O'){
                if (j==2) dp[i+1][j]+=dp[i][j-1];
            }
            else{
                if (j==3) dp[i+1][j]+=dp[i][j-1];
            }
        }
        ans=max(ans,dp[n+1][3]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if((a-b) % 2 == 0){
		printf("Alice\n");
	}
	else{
		printf("Borys\n");
	}
	return 0; 
} 

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

N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]

L.sort(key = lambda x:x[1])

c = 0
for i in range(N):
    x, y = L[i]
    
    c += x
    if c > y:
        print("No")
        exit()
      
print("Yes")

Measured memory_bytes: 53632
#include <math.h>
#include <stdio.h>
#include <string.h>
void swap_int(int* x, int* y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void swap_char(char* x, char* y) {
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

void asc_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] > array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

void dec_sort(int* array, int n) {
    int i, j;
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (array[i] < array[j]) {
                swap_int(&array[i], &array[j]);
            }
        }
    }
}

int max(int x, int y) {
    if (x > y) {
        return x;
    } else {
        return y;
    }
}

int min(int x, int y) {
    if (x > y) {
        return y;
    } else {
        return x;
    }
}

int main(void) {
    int n, a, b, c, d;
    static char str[400000];
    int flg = 0;
    int flg1 = 0;
    int i, j, k, x, cnt = 0;
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    scanf("%s", str);

    for (i = a - 1; i < max(c, d) - 2; i++) {
        if (str[i] == '#' && str[i + 1] == '#') {
            flg = 1;
            break;
        }
    }
    if (flg) {
        printf("No\n");
        return 0;
    }

    if (c < d) {
        if (!flg) {
            printf("Yes\n");
        }
    } else {
        for (i = b - 1; i < d; i++) {
            if (str[i - 1] == '.' && str[i] == '.' && str[i + 1] == '.') {
                printf("Yes\n");
                return 0;
            }
        }
        printf("No\n");
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int countR = 0;

  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') {
      countR++;
    }
  }
  
  if (countR > (N - countR)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  int n,m,q;
  cin>>n>>m>>q;
  V<ll> a(n),b(m),c(n),d(m);
  for(int i=0;i<n;i++){cin>>a[i];c[i]=a[i];}
  for(int i=0;i<m;i++){cin>>b[i];d[i]=b[i];}
  sort(all(a));sort(all(b));
  ll ans=a[0]+b[0];
  for(int i=0;i<q;i++){
      ll e,f,g;
      cin>>e>>f>>g;
      chmin(ans,c[e-1]+d[f-1]-g);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3456
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll k;
int a[200100];

int solve() {
    int dist[n];
    memset(dist, -1, sizeof(dist));
    ll p = 0, d = 0;
    while (true) {
        if (dist[p] >= 0) break;
        dist[p] = d;
        d++;
        p = a[p];
    }
    if (k < d) {
        for (int i = 0; i < n; i++) {
            if (dist[i] == k)
                return i+1;
        }
    } else {
        ll r = d - dist[p];
        k -= dist[p];
        k %= r;
        for (int i = 0; i < k; i++) {
            p = a[p];
        }
        return p+1;
    }
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
}

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

    input();
    cout << solve() << endl;
}


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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll ans = 0;
    ll N,K;
    cin>>N>>K;
    v V(N);
    rep(i,0,N)cin>>V[i];

    rep(i,0,N+1)rep(j,i,N+1){
        if(N-(j-i) > K)continue;
        ll max_V = 0;
        priority_queue<ll> q;
        rep(k,0,i){
            q.push(-V[k]);
            max_V += V[k];
        }
        rep(k,j,N){
            q.push(-V[k]);
            max_V += V[k];
        }

        rep(k,0,K-(N-(j-i))){
            if(q.empty())break;
            if(q.top() <= 0)break;
            max_V += q.top();
            q.pop();
        }
        ans = max(ans, max_V);
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int n{};
    int buf[20]{};
    std::cin >> n;
    for(int i = 0; i < n; ++i)
        std::cin >> buf[i];
    int c = 0;
    for(int i = 1; i < n - 1; ++i){
        if(buf[i - 1] < buf[i] && buf [i] < buf[i + 1])
            ++c;
        if(buf[i + 1] < buf[i] && buf[i] < buf[i - 1])
            ++c;
    }
    std::cout << c << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (a > 0 && c > 0)
  {
    a -= d;
    c -= b;
  }

  cout << ((a <= 0 && c > 0) ?  "No" : "Yes") << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
vector<vector<int>> vv;
vector<int>v;
int N, M, Q;
void dfs(int depth) {
    if (depth >= N) {
        //cout << vv.size() << endl;
        vv.push_back(v); return;
    }
    for(int i = 1; i <= M; i++) {
        if(v.size() == 0) {
            v.push_back(i);
            dfs(depth + 1);
            v.pop_back();
        }
        else if(v.back() >= i) {
            v.push_back(i);
            dfs(depth + 1);
            v.pop_back();
        }
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    
   
    int a[51], b[51], c[51], d[51];
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    rep(i, Q) {a[i]--; b[i]--; }
    vector<int> A(N);
    int ans = 0;
    dfs(0);
    //cout << "*" << vv.size() << endl;

    for(vector<int> A: vv) {
        //sort(A.begin(), A.end())

        int tmp = 0;
        rep(i, Q) {
            if (-A[b[i]] + A[a[i]] == c[i]) tmp += d[i];
        }
        ans = max(ans, tmp);
        //cout << "->" <<  tmp << endl;
    }
    cout << ans << endl;
    
    return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

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

// make vector of divisor O(sqrt(n))
vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}
bool is_prime(long long n) {
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1; // exclude 1
}

// factorization O(sqrt(n))
map<long long, long long> prime_factor(long long n) {
    map<long long, long long> res;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    vl condi;
    sort(all(a));
    ll cur = a[0];
    int size = 0;
    auto clear = [&](int idx) {
        if (size >= 2) condi.push_back(cur);
        if (size >= 4) condi.push_back(cur);
        size = 1;
        cur = a[idx];
    };
    rep(i, n) {
        if (cur != a[i]) {
            clear(i);
        } else {
            size++;
        }

        if (i == n - 1) clear(i);
    }

    if (condi.size() < 2) {
        out(0);
    } else {
        ll ans = condi.back() * *(condi.end() - 2);
        out(ans);
    }
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int A, B, K; cin >> A >> B >> K;
  
  int cnt = 0;
  for (int i=min(A,B);i>=1;i--){
    if (A%i==0 && B%i==0) cnt++;

    if (cnt==K) {
      cout << i << endl;
      break;
    }
  }





  return 0;
}

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

#define Bye return 0
#define ll long long
const ll MAX = 1e2;

void solve(){
    int n, m; cin>>n>>m;
    ll a[n+1], b[n+1], c[m+1], d[m+1];

    for (int i=1; i<=n; i++) cin>>a[i]>>b[i];
    for (int i=1; i<=m; i++) cin>>c[i]>>d[i];

    for (int i=1; i<=n; i++){
        ll min = LONG_MAX; ll res;
        for (int j=1; j<=m; j++){
            ll x = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(x<min){ min = x; res = j;}
        }
        cout<<res<<endl;
    }
}

int main(){
    solve();
    Bye;
}

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

using namespace std;

int main() {
 long long int a,b,c,d,ans1,ans2,ans3,ans4,mx;
 cin>>a>>b>>c>>d;
 
 ans1=b*d;
 ans2=a*d;
 ans3=b*c;
 ans4=a*c;
 mx=max(ans1,ans2);
 mx=max(mx,ans3);
  mx=max(mx,ans4);
 cout<<mx<<endl;
}

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

typedef long long ll;

const ll INF = 1e18;
const int prime[] = {2, 3, 5};

ll N;
int cost[4];
unordered_map <ll, ll> dp;

ll solve(ll n) {
	if (dp.find(n) != dp.end())
		return dp[n];
	ll &ref = dp[n];
	ref = n <= INF / cost[3] ? n * cost[3] : INF;
	if (n <= 1)
		return ref;
	for (int i = 0; i < 3; i++) 
		for (auto nxt : {n / prime[i], (n - 1) / prime[i] + 1})
			ref = min(ref, solve(nxt) + cost[i] + abs(nxt * prime[i] - n) * cost[3]);
	return ref;
}

int main() {
	int tc;
	scanf("%d", &tc);
	while (tc--) {
		scanf("%lld", &N);
		for (int i = 0; i < 4; i++)
			scanf("%d", cost + i);
		dp.clear();
		printf("%lld\n", solve(N));
	}
	return 0;
}

Measured memory_bytes: 4168
#include <iostream>
using namespace std;
main(){
int s,t;
while(cin>>s>>t){
if((s|t)==0) break;
int m=s+t,mi=0;
for(int i=1;i<5;i++){
cin>>s>>t;
if(m<s+t){
m=s+t;
mi=i;
}
}
cout<<(char)('A'+mi)<<" "<<m<<endl; 
}
}

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

int main(){
    int N;
    cin>>N;
    vector<long long> D(N);
    for(int i=0;i<N;++i)cin>>D[i];
    sort(D.begin(),D.end());
    long long left = D[N/2-1];
    long long right = D[N/2];
    cout<<right - left<<endl;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main(){

    int K,N,maxD=0,A[200010]={};

    cin>>K>>N;

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

    maxD = A[1] + (K-A[N]);

    for(int i=2;i<=N;i++){
        int temp = A[i]-A[i-1];
        if(temp>maxD)maxD=temp;
    }

    cout << K - maxD<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

bool ng[10];

bool chack(int n){
	while(n > 0){
		if(ng[n%10]) return false;
		n /= 10;
	}
	return true;
}

int main(){
	int n, k;
	cin>>n>>k;
	vi d(k);
	rep(i, k){
		cin>>d[k];
		ng[d[k]] = true;
	}
	for(int i = n; ; i++){
		if(chack(i)){
			cout<<i<<endl;
			return 0;
		}
	}

}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc090/tasks/arc091_a

import itertools
import collections
import bisect

def main():
    N, M = map(int, input().split())
    if N > 1 and M > 1:
        print((N-2)*(M-2))
    else:
        if N == 1 and M == 1:
            print(1)
        else:
            print(max(N, M) - 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    t1, t2 = mi()
    a1, a2 = mi()
    b1, b2 = mi()
    aoki = 0
    taka = 0
    meetF = False
    meetS = False
    # a の方が速くなるようにスワップ
    if t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2:
        x1, x2 = a1, a2
        a1, a2 = b1, b2
        b1, b2 = x1, x2
    # print(a1, a2, b1, b2)
    if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
        exit("infinity")
    if a1 > b1:
        meetF = False
    else:
        meetF = True
    # 1区間目も2区間目もaの法が速いなら合うことはない
    if not meetF:
        exit(0)
    sa = t1 * a1 + t2 * a2 - t1 * b1 - t2 * b2  # 1区切りごとにＡが速く，付いてしまう差
    # print(sa)
    # 何区切りすると追いつけない差になってしまうか
    ng = 10**18
    ok = 1
    while(ng - ok > 1):
        mid = (ng + ok) // 2
        # シミュレーション（mid区切りのあと追いつけるか）
        a = 0
        b = -mid * sa
        if(a + t1 * a1 <= b + t1 * b1):
            ok = mid
        else:
            ng = mid
    # シミュレーション(ok*2回は確実に会う)
    cnt = 2 * (ok - 1) - 1
    a = 0
    b = -(ok - 1) * sa
    for i in range(ok - 1, ok + 10):
        a += t1 * a1
        b += t1 * b1
        if a < b:
            cnt += 2
        if a == b:
            cnt += 1
        a += t2 * a2
        b += t2 * b2
    print(cnt)
    # exit(2 * ok + 1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 40528
import java.util.Scanner;
 
public class Main{
	public static void main(String[] args){
      
    	Scanner sc = new Scanner(System.in);
        	int a = sc.nextInt();
       		int b = sc.nextInt();
    	if(a < 10){
    		if(b < 10){
        		System.out.println(a * b);
            
        	}else{
        		System.out.println(-1);
        	
            }
    	}else{
            	System.out.println(-1);
        }
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long double k=0.0,ans=0.0;
  cin >> N;
  
  for(int i=0; i<N; i++){ 
    cin >> k;
    ans += 1/k;
  }
  cout << fixed << setprecision(10) << 1.0/ans << endl; 
  return 0;
} 

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

using namespace std;

void solve(){
    int s, w;
    cin >> s >> w;
    if(s > w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
#else
	#define de(x)
	#define rff
#endif

#define full_auto(x) for(auto it=x.begin();it!=x.end();it++)
#define pdd pair<double,double>
#define pii pair<int,int>
#define PQ priority_queue
#define setp setprecision
#define sqr(a) ((a)*(a))
#define el cout<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define ins insert
#define re return
#define se second
#define fi first
const int INF=(int)INFINITY;

ll ans;
int n,fa[100003],r[100003];
pii a[100003],x[100003],y[100003];
PQ <pair<int,pii>> q;

int find_fa(int x){
	if (fa[x]==x) return x;
	return fa[x]=find_fa(fa[x]);
}

void uni(int x,int y){
	x=find_fa(x);
	y=find_fa(y);
	if (r[x]<r[y]){
		fa[x]=y;
	}else{
		fa[y]=x;
		if (r[x]==r[y]) r[x]++;
	}
}

int main(){
//	rff;
	cin>>n;
	for (int i=0;i<n;i++){
		fa[i]=i;
	}
	for (int i=0;i<n;i++){
		cin>>a[i].fi>>a[i].se;
		x[i]={a[i].fi,i};
		y[i]={a[i].se,i};
	}
	sort(x,x+n);
	sort(y,y+n);
	for (int i=0;i<n-1;i++){
		q.push({-(x[i+1].fi-x[i].fi),{x[i].se,x[i+1].se}});
		q.push({-(y[i+1].fi-y[i].fi),{y[i].se,y[i+1].se}});
	}
	while (q.size()){
		int c=-q.top().fi,p1=q.top().se.fi,p2=q.top().se.se;
		if (find_fa(p1)!=find_fa(p2)){
			uni(p1,p2);
			ans+=c;
		}
		q.pop();
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 7668
#include <iostream>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
const int INF=1e9;

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans=INF;
  rep(i,X+1){
    int sum=A*i;
    int N=(X-i)*2, res=Y-N/2;
    sum+=N*C;
    if(res>0) sum+=res*min(B,C*2);
    ans=min(ans,sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> P;
    rep(i, n){
        ll a;
        cin >> a;
        P.push(a);
    }
    pair<int, int> b[m];
    rep(i, m) cin >> b[i].second >> b[i].first;
    sort(b, b + m);
    reverse(b, b + m);
    int j = 0;
    while(true){
        ll k = P.top();
        if(b[j].first > k && b[j].second > 0){
            P.pop();
            P.push(b[j].first);
            b[j].second --;
            if(b[j].second == 0) j ++;
        }else break;
    }
    ll ans = 0;
    while(!P.empty()){
        ll h = (ll)P.top();
        ans += h;
        //cout << h << endl;
        P.pop();
    }
    cout << ans << endl;

}

Measured memory_bytes: 1528
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

A, B, C, X = [int(input()) for _ in range(4)]


cnt = sum(0 <= X-500*a-100*b <= 50*C for a in range(A+1) if X - 500*a>=0 for b in range(B+1))
print(cnt)

Measured memory_bytes: 2940
import bisect
#2分探索の際に用いる
N = int(input())
L_a = [int(s) for s in input().rstrip().split(" ")]
L_b = [int(s) for s in input().rstrip().split(" ")]
L_c = [int(s) for s in input().rstrip().split(" ")]
L_a.sort()
L_b.sort()
L_c.sort()
k = 0
for i in range(N):
  s_l = bisect.bisect_left(L_a, L_b[i]) #L_b[i]よりも真に小さい配列の要素の数
  s_r = bisect.bisect_right(L_c, L_b[i])
  k += s_l*(N-s_r)
print(k)

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

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

    sort(A, A+N);
    for(int i=0; i<M; i++){
        if(A[N-i-1] < count/(4.0*M)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct _node{
    int key;
    struct _node *parent;
    struct _node *left;
    struct _node *right;
}NODE;
NODE* makeNode(int x,NODE* p){
    NODE *n=(NODE*)malloc(sizeof(NODE));
    n->key=x;
    n->parent=p;
    n->left=NULL;
    n->right=NULL;
    
    return n;
}
NODE* insert(NODE *t,int x,NODE *p){
    if(t==NULL)return makeNode(x,p);

    if(t->key<x)t->right=insert(t->right,x,t);
    else t->left=insert(t->left,x,t);
    
    return t;
}
void inorder(NODE *t){
    if(t==NULL)return;
    
    if(t->left!=NULL)inorder(t->left);
    printf(" %d",t->key);
    if(t->right!=NULL)inorder(t->right);
    
    return;
}
void preorder(NODE *t){
    if(t==NULL)return;
    
    printf(" %d",t->key);
    if(t->left!=NULL)preorder(t->left);
    if(t->right!=NULL)preorder(t->right);
    
    return;
}
NODE* find(NODE *t,int x){
    if(t==NULL)return NULL;
    
    if(t->key==x)return t;
    else if(t->key<x)return find(t->right,x);
    else return find(t->left,x);
}
NODE* delete(NODE *t,NODE *d){
    if(t==NULL)return t;
    
    NODE *p,*c;
    if(d->left==NULL&&d->right==NULL){
        p=d->parent;
        if(p->left==d)p->left=NULL;
        else p->right=NULL;
        free(d);
        return t;
    }else if(d->left==NULL||d->right==NULL){
        p=d->parent;
        if(p->left==d){
            if(d->left!=NULL)c=d->left;
            else c=d->right;
            p->left=c;
        }else{
            if(d->left!=NULL)c=d->left;
            else c=d->right;
            p->right=c;
        }
        c->parent=p;
        free(d);
        return t;
    }else{
        c=d->right;
        while(c->left!=NULL)c=c->left;
        d->key=c->key;
        return delete(t,c);
    }
}
int main(void){
    NODE *root;
    root=NULL;
    
    int n;
    scanf("%d\n",&n);
    
    NODE *d;
    char com[6+1];
    int x;
    while(n--){
        scanf("%s",com);
        switch(com[0]){
            case 'i':
                //insert
                scanf("%d\n",&x);
                root=insert(root,x,NULL);
                break;
            case 'p':
                //print
                inorder(root);
                printf("\n");
                preorder(root);
                printf("\n");
                break;
            case 'f':
                scanf("%d\n",&x);
                if(find(root,x)==NULL)printf("no\n");
                else printf("yes\n");
                break;
            case 'd':
                scanf("%d\n",&x);
                d=find(root,x);
                if(d!=NULL)delete(root,d);
                break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 20484
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	ll n,k;
	double ans = 0;
	ll memo = 0;
	cin >> n >> k;
	
	rep(i,1,n+1){
		memo = max((ll)0,(ll)ceil(log2((double)k/i)));
		ans += pow(0.5,memo)/n;
	}
	
	cout << setprecision(10);
	cout << ans << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main(){
  int n,k;
  cin>>n>>k;
  
  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  rep(i,k){
    bool alln=true;
    vector<ll> q(n+1);
    rep(j,n){
      if(p[j]<n) alln=false;
      if(j+1-p[j]<0) q[0]++;
      else q[j+1-p[j]]++;
      if(j+2+p[j]<n+1) q[j+2+p[j]]--;
    }
    if(alln){
      rep(j,n){
        cout << n;
        if(i!=n) cout << " ";
        else cout << endl;
      }
      return 0;
    }
    repo(j,n+1){
      q[j]+=q[j-1];
      p[j-1]=q[j];
    }
  }

  rep(i,n){
    cout << p[i];
    if(i!=n) cout << " ";
    else cout << endl;
  }

}


Measured memory_bytes: 6428
import sys
n,m,v,p=map(int,sys.stdin.readline().split())
a=list(map(int, sys.stdin.readline().split()))
#a=[int(i) for i in sys.stdin.readline().split()]
a.sort(reverse=True)
a=a[p-1:]
l,r=0,n-p

def adopt(x):
    global a,n,m,v
    b=a[x]+m
    if b<a[0]:
        return False
    al=(v-(n-x))*m
    s=x*b-sum(a[:x])
    return al<=s

while l+1<r:
    k=(l+r)//2
    if adopt(k):
        l=k
    else:
        r=k

if adopt(r):
    print(p+r)
else:
    print(p+l)


Measured memory_bytes: 14296
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll N;
ll M;
ll Q;
ll a[100];
ll b[100];
ll c[100];
ll d[100];


ll maxV=0;

void getMax(int index,ll min,ll AA[]){
    if(index==N){
        for( int mi = min ; mi <=M ; mi++ ){
            AA[index]=mi;
            ll score = 0;
            rep(qi,Q){
                int index1=b[qi];
                int index2=a[qi];
                if(AA[index1]-AA[index2]==c[qi]) score+=d[qi];
            }
            if(score>maxV) maxV = score;
        }
    }else{
        for( int mi = min ; mi <=M ; mi++ ){
            AA[index]=mi;
            getMax(index+1,mi,AA);
        }
    }

}


int main(){

    cin >> N;
    cin >> M;
    cin >> Q;

    rep(qi,Q){
        cin >> a[qi];
        cin >> b[qi];
        cin >> c[qi];
        cin >> d[qi];
    }

    ll AA[N+1];
    getMax(1,1,AA);
    cout << maxV << endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <bitset>
#include <vector>
#include <queue>
#include <limits.h>
using namespace std;

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

struct Bridge {
	int a, b, cost;
};

bool operator <(const Bridge& b1, const Bridge& b2) {
	return b1.cost < b2.cost;
}

bool operator >(const Bridge& b1, const Bridge& b2) {
	return b1.cost > b2.cost;
}

int n, m, a, b, cost;
const int MAX_N = 100;
int T[MAX_N][MAX_N];
priority_queue<Bridge, vector<Bridge>, greater<Bridge> > q;

int main() {
	while(cin >> n >> m, n | m) {
		fill(&T[0][0], &T[0][0]+MAX_N*MAX_N, INT_MAX);
		rep(i,m) {
			cin >> a >> b >> cost;
			T[a][b] = T[b][a] = cost;
		}

		q = priority_queue<Bridge, vector<Bridge>, greater<Bridge> >();
		rep(i,n) {
			if(T[0][i] != INT_MAX) {
				Bridge bdg;
				bdg.a = 0;
				bdg.b = i;
				bdg.cost = T[0][i];
				q.push(bdg);
			}
		}

		int total = 0;
		bitset<MAX_N> visited;
		visited.set(0);
		while(!q.empty()) {
			Bridge bdg = q.top();
			q.pop();
			if(visited[bdg.b]) continue;

			total += bdg.cost;
			visited.set(bdg.b);
			rep(i,n) {
				if(!visited[i] && T[bdg.b][i] != INT_MAX) {
					Bridge new_bdg;
					new_bdg.a = bdg.b;
					new_bdg.b = i;
					new_bdg.cost = T[bdg.b][i];
					q.push(new_bdg);
				}
			}
			
			if(visited.count() == n) break;
		}

		cout << total << endl;
	}
}

Measured memory_bytes: 1260