akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << 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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main(){
	int n;
	cin >> n;
	V a(n);
	V b(n);
	rep(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(all(b));
	int mid1 = b[n / 2 - 1];
	int mid2 = b[n / 2];
	if (mid1 == mid2) {
		rep(i, n) {
			cout << mid1 << endl;
		}
		return 0;
	}
	else {
		rep(i, n) {
			int tmp = (mid1 < a[i]) ? mid1 : mid2;
			cout << tmp << endl;
		}
		return 0;
	}
	return 0;
}

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

int main () {
    int f;
    f = 0;
    int s;
    s = 0;
    int t;
    t = 0;
    for (int i=0;i<10;++i){
        int a;
        cin >> a;
        if (a > t){
            t = a;
        }
        if (t > s) {
            int tmp;
            tmp = s;
            s = t;
            t = tmp;
        }
        if (s > f){
            int tmpo;
            tmpo = f;
            f = s;
            s = tmpo;
        }
    }
    cout << f << endl;
    cout << s << endl;
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int ll

int n;
int a, b;
int32_t main()
{
    cin >> n;
    for (int i = 1; i*i<=n; i++)
    {
        if (n%i==0)
        {
            a = i, b = n/i;
        }
    }
    cout << a + b -2 << '\n';
}

Measured memory_bytes: 256
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
    ll a, b, c, k;
    cin>>a>>b>>c>>k;
    if(k<a){
        cout<<k<<endl;
        return 0;
    }
    else{
        if(k<b){
            k-=a;
            ll ans = a;
            cout<<ans<<endl;
            return 0;
        }
        else{
            ll ans = a;
            k-=a;
            k-=b;
            cout<<a-(k)<<endl;
        }
    }
}





Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
using namespace std;
 

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
#define int long long

 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
 
const int MAXN = 1e5 + 5;
const ll MOD = 998244353;
const ll INF = 1e18;


random_device rd;
mt19937 rnd(rd());


int gcd(int a, int b) {
	return (!a ? b : gcd(b % a, a));
}


ll pw(ll a, ll x) {
	ll res = 1;
	while (x > 0) {
		if (x & 1) {
			res = (res * a) % MOD;
		}
		a = (a * a) % MOD;
		x >>= 1;
	}
	return res;
}


signed main() {
	FAST_IO;
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n + 1);
	forn(i, n + 1) {
		cin >> a[i];
	}
	if (a[0] > 1) {
		cout << "-1\n";
		return 0;
	}
	b[0] = 1;
	for (int i = 1; i <= n; i++) {
		b[i] = (b[i - 1] - a[i - 1]) * 2;
		b[i] = min(b[i], INF);
		if (b[i] < a[i]) {
			cout << "-1\n";
			return 0;
		}
	}
	int ans = 0, v = 0;
	for (int i = n; i >= 0; i--) {
		v += a[i];
		ans += min(v, b[i]);
	}
	cout << ans << "\n";
 	return 0;
}

Measured memory_bytes: 4744
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int[] a = na(3);
    int[] b = na(3);

    long ret1 = f(n, a, b);
    long ret2 = f((int)ret1, b, a);

    System.out.println(ret2);   
  }
  
  private static long f(int n, int[] from, int[] to) {
    int m = 3;
    int k = n;
    long[] dp = new long[k + Arrays.stream(from).max().getAsInt() + 1];
    Arrays.fill(dp, Long.MIN_VALUE / 2);
    dp[n] = n;
    
    long ret = n;
    for (int i = 0; i < m; i ++) {
      for (int j = k; j >= 0; j --) {
        dp[j] = Math.max(dp[j], dp[j + from[i]] - from[i] + to[i]);
        
        ret = Math.max(ret, dp[j]);
      }
    }
    return ret;
  }


  
  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 223700
import java.util.*;
// . >
class Main{
	static Scanner in = new Scanner(System.in);

	public static void main(String args[]){	
		// String a = in.nextLine();
		int n = scInt(), k = scInt();
		long res = k;
		for(int i = 1; i < n; i++){
			res *= k - 1;
			if(res > Math.pow(2, 31) - 1){
				pl((long)Math.pow(2, 31) - 1 + "");
				return;
			}
		}
		pl( res + "");
		
	}

	public static int scInt(){return in.nextInt();}
	public static double scDbl(){return in.nextDouble();}
	public static String scStr(){return in.next();}
	public static String scLne(){return in.nextLine();}

	public static void pl(String s){System.out.println(s);}	

}


Measured memory_bytes: 38652
#include <iostream>
using namespace std;
using ll = long long;

ll n;
int cnt;

void dfs(ll cur,bool three, bool five, bool seven) {
    if (cur > n) return;
    if (cur <= n) if (three && five && seven) cnt++;

    dfs(cur * 10 + 3, true,  five, seven);
    dfs(cur * 10 + 5, three, true, seven);
    dfs(cur * 10 + 7, three, five, true );
}


int main() {
    cin >> n;

    dfs(0, false, false, false);
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> sum1,sum2;
void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(ll i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}
ll query(ll i,ll j,vector<ll> &s){//区間[i,j]の和
    return (s[j]-s[i]);
}

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

    pre_process(v,sum1);
    reverse(v.begin(),v.end());
    pre_process(v,sum2);
    reverse(v.begin(),v.end());


    ll ans=0,sum=0;

    /*rep(i,sum1.size()) cout<<sum1[i]<<" ";
    cout<<endl;
    rep(i,sum2.size()) cout<<sum2[i]<<" ";
    cout<<endl;*/
    

    rep(left,min(n,k)+1){
        rep(right,min(n,k)+1-left){
            priority_queue<ll> que;

            sum=(sum1[left]+sum2[right]);
            rep(i,left+1){
                if(i==0) continue;
                que.push(-1*v[i-1]);
            }
            reverse(v.begin(),v.end());
            rep(i,right+1){
                if(i==0) continue;
                que.push(-1*v[i-1]);
            }
            reverse(v.begin(),v.end());

            rep(i,k-left-right){
                if(que.size()==0) continue;
                ll now=que.top();
                que.pop();
                if(now>0){
                    sum+=now;
                }else{
                    break;
                }
            }

            chmax(ans,sum);
        }
    }

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

Measured memory_bytes: 3608
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stdint.h>
#include<limits.h>
#include<sstream>
#include<iomanip>
#include<cmath>
using namespace std;


int main() {
	int n,a[21],b[51],c[51];
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	for (int i = 1;i <= n;i++)
		cin >> b[i];
	for (int i = 1;i < n;i++)
		cin >> c[i];
	int sum = 0,fir=-1;
	for (int i = 1;i <= n;i++) {
		if (a[i] == fir + 1)
		{
			sum = sum + b[a[i]] + c[a[i-1]];
		}
		else {
			sum = sum + b[a[i]];
		}
		fir = a[i];
	}
	cout << sum;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

ll x,y,n;
int main()
{
	
	scanf("%lld%lld%lld",&x,&y,&n);
	ll t = min(y-1,n);
	ll ans = (x*t)/y - x * (t/y);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int n,k;
    cin >> n >>k;
    bool ok[n];
    rep(i,n){
        ok[i]=false;
    }

    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        int a[d];
        rep(i,d){
            cin >> a[i];
            ok[a[i]-1]=true;
        }
    }

    int ans=0;
    rep(i,n){
        if(!ok[i])ans++;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

vector<pair<ll, ll>> a;

struct HashPair {
    template<class T1, class T2>
    size_t operator()(const pair<T1, T2> &p) const {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        size_t seed = 0;
        seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};

unordered_map<pair<ll, ll>, ll, HashPair> cache;

ll solve(ll left, ll right){
    const ll cur = a.size() - (right - left);
    if(cur >= a.size()){
        return 0;
    }

    if(cache.count({left, right})){
        return cache[{left, right}];
    }

    ll tmp_l = solve(left + 1, right) + a.at(cur).first * abs(a.at(cur).second - left);
    ll tmp_r = solve(left, right - 1) + a.at(cur).first * abs(a.at(cur).second - (right - 1));
    const ll ret = max(tmp_l, tmp_r);
    cache[{left, right}] = ret;
    return ret;
}

int main(){
    ll n;
    cin >> n;
    REP(i, n){
        ll ai;
        cin >> ai;
        a.emplace_back(ai, i);
    }
    sort(a.rbegin(), a.rend());
    const ll ans = solve(0, n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 113992
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#include <utility>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  string str;
  string tmp="a",tmp2="a";
  map<string,string>mp;
  cin >> mp["a"] >> mp["b"] >> mp["c"];
  while(mp[tmp2][0]!='\0'){
    tmp=mp[tmp][0];
    mp[tmp2]=mp[tmp2].substr(1);
    tmp2=tmp;
  }
  char ans = tmp2[0];
  ans=toupper(ans);
  cout << ans<<endl;
  return 0;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    
    vector <unsigned long long> v1(3);
    vector <unsigned long long> v2(3);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (a+v1[1] > a+v1[2]) {
            v2[0] = a+v1[1];
        } else {
            v2[0] = a+v1[2];
        }
        if (b+v1[0] > b+v1[2]) {
            v2[1] = b+v1[0];
        } else {
            v2[1] = b+v1[2];
        }
        if (c+v1[0] > c+v1[1]) {
            v2[2] = c+v1[0];
        } else {
            v2[2] = c+v1[1];
        }
        v1[0] = v2[0];
        v1[1] = v2[1];
        v1[2] = v2[2];
    }
    cout << *max_element(v2.begin(), v2.end());
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INF=(1<<21);
static const int WH=0;
static const int GRY=1;
static const int BL=2;

int n, MA[MAX][MAX];

int prim(){
  int  u, minV;
  int d[MAX], p[MAX], color[MAX];

  for(int i=0; i<n; i++)
  {
    d[i]=INF;
    p[i] = -1;
    color[i]=WH;
  }

  d[0]=0;

  while(1)
  {
    minV=INF;
    u = -1;
    for(int i=0; i<n; i++)
    {
      if(minV > d[i] && color[i] != BL)
      {
        u=i;
        minV=d[i];
      }
    }
    if(u == -1) break;
    color[u]=BL;
    for(int v=0; v<n; v++)
    {
      if(color[v] != BL && MA[u][v] != INF)
      {
        if(d[v] > MA[u][v])
        {
          d[v]=MA[u][v];
          p[v]=u;
          color[v]=GRY;
        }
      }
    }
  }
  int sum=0;
  for(int i=0; i<n; i++)
  {
    if(p[i] != -1) sum += MA[i][p[i]];
  }

  return sum;
}

int main(){
  cin >> n;

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++)
    {
      int e;
      cin >> e;
      MA[i][j] = (e == -1) ? INF : e;
    }
  }

  cout << prim() << endl;

  return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main () {
  int n, a; cin >> n >> a;
  cout << ((n%500) > a ? "No" : "Yes") << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX_N 41

using namespace std;

typedef unsigned long long ull;

struct Country{
  int index,power;
  Country(int index=IINF,int power=IINF):index(index),power(power){}
  bool operator < (const Country& c)const{ return power > c.power; }
};

int N,answer,V,sum[MAX_N];
ull adj_bitmask[MAX_N];
Country c_list[MAX_N];

inline void input(){
  V = 0;
  int dex = 0,i_tmp;
  map<string,int> getIndex;
  set<string> ban;
  string s_tmp;
  rep(i,N){
    cin >> s_tmp >> i_tmp;
    if( ban.find(s_tmp) != ban.end() ){
      cin >> i_tmp;
      rep(i,i_tmp)cin>>s_tmp;
      continue;
    }
    if( getIndex.find(s_tmp) == getIndex.end() ) getIndex[s_tmp] = dex++;
    int from = getIndex[s_tmp];
    if( from == 0 ) answer = i_tmp;
    c_list[from] = Country(from,i_tmp);
    adj_bitmask[from] = 0ULL;
    cin >> i_tmp;
    rep(j,i_tmp){
      cin >> s_tmp;
      if( from == 0 ){
	ban.insert(s_tmp);
	continue;
      }
      if( ban.find(s_tmp) != ban.end() ) continue;
      if( getIndex.find(s_tmp) == getIndex.end() ) getIndex[s_tmp] = dex++;
      int to = getIndex[s_tmp];
      adj_bitmask[from] |= (1ULL<<to);
    }
  }
  V = dex;
}

void dfs(int sp,int power,ull friend_bitmask,ull enemy_bitmask){
  if( power + sum[sp] <= answer )return;
  answer = max(answer,power);
  if( sp >= V ) return;
   
  REP(i,sp,V){
    if( ((friend_bitmask|enemy_bitmask)>>(ull)(c_list[i].index)) & 1ULL ) continue;
    if( friend_bitmask & adj_bitmask[c_list[i].index] ) continue;
    dfs(i+1,power+c_list[i].power,friend_bitmask|(1ULL<<c_list[i].index),enemy_bitmask|adj_bitmask[c_list[i].index]);
    dfs(i+1,power,friend_bitmask,enemy_bitmask);
    break;
  }

}

int main(){
  while(cin>>N,N){
    input();
    sort(c_list,c_list+V);
    rep(i,V)sum[i] = 0;
    sum[V-1] = c_list[V-1].power;
    for(int i=V-2;i>=0;i--) sum[i] = sum[i+1] + ((c_list[i].index==0)?0:c_list[i].power);
    dfs(0,answer,1,0);
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for i in range(N):
  a = list(map(int,input().split()))
  P = C  
  for j in range(M):
    P += B[j]*a[j]
  if P>0:
    count+=1
print(count)

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

int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> v(N);
  for(int i=0;i<M;i++){
    cin >> v.at(i);
  }
  
  int cost1 =0;
  for(int i=0;i<X;i++){
    for(int j=0;j<M;j++){
      if(i == v.at(j)) cost1++;
    }
  }
  
  int cost2 = 0;
  for(int i=X+1;i<N;i++){
    for(int j=0;j<M;j++){
      if(i == v.at(j)) cost2++;
    }
  }
  cout << min(cost1,cost2) << endl;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll pass = p, fail = n+1;
  while (fail-pass > 1) {
    ll mid = pass+fail>>1;

    ll t = a[mid-1]+m;
    ll sum = (p-1)*m;
    for (int i = p-1; i < n; i++) {
      sum += min(m, t-a[i]);
    }
    if (sum >= m*v && t >= a[p-1]) pass = mid;
    else fail = mid;
  }
  cout << pass << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int b[15];
int count(int n)
{
	int k, k5, m;
	for (k = 0, k5 = 1; (long long)k5*5 <= n; k ++, k5 *= 5);
	if (k) {
		m = n - k5;
		return b[k] + count(m);
	} else {
		return 0;
	}
}
int main()
{
	int i, n, k5;
	b[0] = 0;
	for (i = 1, k5 = 1; i < 15; i ++, k5 *= 5)
		b[i] = b[i-1] + k5;
	while (scanf("%d", &n), n) {
		printf("%d\n", count(n));
	}
	return 0;
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n,a,b,c,d;

void yes(){
  cout << "YES" << endl;
  exit(0);
}

void no(){
  cout << "NO" << endl;
  exit(0);
}

int main(){
  cin >> n >> a >> b >> c >> d;
  for(lli i = 0;i < n;i++){
    if(a-b <= i*d-(n-1-i)*c && a-b >= i*c-(n-1-i)*d) yes();
  }
  no();
  return 0;
}


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

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

	char c[100][100];

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

	for (int j = 0; j < W + 2; j++)
	{
		cout << '#';
	}
	cout << endl;
	for (int i = 0; i < H; i++)
	{
		if (i == 0)
		{
		}
		for (int j = 0; j < W; j++)
		{
			if (j == 0) {
				cout << '#';
			}
			cout << c[i][j];
			if (j == W - 1) {
				cout << '#';
			}
		}
		cout << endl;
	}
	for (int j = 0; j < W + 2; j++)
	{
		cout << '#';
	}
	cout << endl;

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int arr[n],dp[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    dp[1] = abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < w + 2; i++)cout << "#";
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << "#";
		string str;
		cin >> str;
		cout << str << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++)cout << "#";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    from collections import Counter as ct
    n = int(input())
    s = ct([input() for _ in [0]*n])
    for i in ["AC", "WA", "TLE", "RE"]:
        if i not in s:
            a = 0
        else:
            a = s[i]
        print(i, "x", a)


main()


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

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned long long uInt;
typedef unsigned uint;

string S;

int main(void) {
    cin >> S;

    for (int i = 0; i < S.size(); i++) {
        if (i == 4) cout << " ";
        cout << S[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;

public class Main{

    static int A,B,C,n;
    static int l[];
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[n];
        for(int i=0; i<n; i++){
            l[i] = sc.nextInt();
        }
        System.out.println(dfs(0,0,0,0));
    }

    static int dfs(int i, int a, int b, int c){
        if(i==n){
            return (min(min(a,b),c) > 0) ? abs(A-a) + abs(B-b) + abs(C-c) -30 : 9999999;
        }

        int mp0 = dfs(i+1, a, b, c);
        int mp1 = dfs(i+1, a+l[i], b, c) + 10;
        int mp2 = dfs(i+1, a, b+l[i], c) + 10;
        int mp3 = dfs(i+1, a, b, c+l[i]) + 10;

        return min(min(mp0,mp1),min(mp2,mp3));
    }
}

Measured memory_bytes: 23892
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		int ans = solve();
		System.out.println(ans);
	}
	
	private static int solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Integer, Integer> map = new TreeMap<>();
		
		for (int i = 0; i < n; i++) {
			int rank = sc.nextInt();
			int score = sc.nextInt();
			map.put(rank, score);
		}
		sc.close();
		
		List<Integer> ranks = new ArrayList<>();
		for (Integer key : map.keySet()) {
			ranks.add(key);
		}
		Collections.sort(ranks);
		
		int tempFirst = ranks.get(0);
		int tempLast = ranks.get(ranks.size() - 1);
		
		int tempLastScore = map.get(tempLast);
		
		return (tempLast - tempFirst + 1 + (tempFirst - 1) + tempLastScore);
	}
}

Measured memory_bytes: 99032
import sys,math
input = sys.stdin.readline

N = int(input())
CSF = [[0,0,0]]
for i in range(1,N):
    CSF.append(list(map(int,input().split())))
for i in range(1,N+1):
    nowtime = 0
    for j in range(i,N):
        if nowtime <=CSF[j][1]:
            depT =CSF[j][1]
        else:
            depT =CSF[j][1] + math.ceil((nowtime-CSF[j][1])/CSF[j][2])*CSF[j][2]

        nowtime = depT+CSF[j][0]
        #print(nowtime,depT)
    print(nowtime)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll a,b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD

    ll n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  k--;
  for(int i=0;i<s.size();i++)
  {
    if(i==k)
      s[i]=s[i]-'A'+97;
  }
  cout<<s<<endl;
}
    
    
    







Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
fn main() {
    input! {
        n:usize,
        S:Chars
    }
    let mut ans = 0;
    for a in 0..10u8 {
        // 文字aの最初の出現位置
        let mut ai = getFirstPoint(&S, n, a, 0);
        //println!("a={},ai={}", a, ai);
        if ai == n {
            // 見つからなかったケース。
            continue;
        }
        for b in 0..10u8 {
            let mut bi = getFirstPoint(&S, n, b, ai + 1);
            if bi == n {
                // 見つからなかったケース。
                continue;
            }
            for c in 0..10u8 {
                let mut ci = getFirstPoint(&S, n, c, bi + 1);
                if ci < n {
                    // 見つかった場合、そのPINは有効。
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}
// 文字xの、index i以降で最初に出現する位置
fn getFirstPoint(s: &Vec<char>, n: usize, c_u8: u8, i: usize) -> usize {
    let c = ('0' as u8 + c_u8) as char;
    for j in i..n {
        //println!("s[j]={}, c={}", s[j], c);
        if s[j] == c {
            return j;
        }
    }
    return n;
}


Measured memory_bytes: 2308
#include <iostream>
using namespace std;
int main() {
    short t,n,count = 0;
    cin>>t;
    for (int i = 1; i <= t; i++) {
        cin >> n;
        if (i % 2 == 1 && n % 2 == 1)
            count++;
    }
    cout<<count;
    return 0;
}

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


int main () 
{
      int a, b, c, x;
  cin >>a>>b>>c>>x;
  
  int sum =0, ans;
  for (int i=0; i<=a; i++) {
    for (int j=0; j<=b; j++) {
      for (int k=0; k<=c; k++) {
        sum = i*500 + j*100 + k*50;
          if (sum == x)
            ans++;
      }
    }
  }

  cout << ans << endl;
}

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

#define ll long long
#define p_b push_back
#define pl pair<ll,ll>

ll modo = 1000000007;
ll MOD = modo;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t = 1;
	//cin >> t;
	while(t--)
	{
		ll n,m;
		cin >> n >> m;
		ll mp[4];
		mp[1] = 300000;
		mp[2] = 200000;
		mp[3] = 100000;
		mp[0] = 0;
		if(n>3)
		{
			n = 0;
		}
		if(m>3)
		{
			m = 0;
		}
		
		ll ans = mp[n] + mp[m];
		if(n==1 && n==m)
		{
			ans += mp[1]+mp[3];
		}
		cout << ans << endl;


	}	
	
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long h,w,n,maxi=0,rem=0,ans=0;
    cin>>h>>w>>n;
    
    if(h>=w)
        maxi = h;
    else
        maxi = w;
    
    ans = n/maxi;
    rem = n%maxi;
    
    if(rem>0)
        ans = ans + 1;
    
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

const vector<string> p3 = {
    ".aa",
    "a..",
    "a.."
};
const vector<string> p4 = {
    "aacd",
    "bbcd",
    "dcbb",
    "dcaa"
};
const vector<string> p5 = {
    "aabaa",
    "b.bcc",
    "bac..",
    ".ac.b",
    "bbaab"
};
//const vector<string> p5 = {
//    "aabba",
//    "b.cca",
//    "bc..b",
//    "ac..b",
//    "abbaa"
//};
//const vector<string> p7 = {
//    "aabb..a",
//    ".cc.cca",
//    "a...abb",
//    "a..ba  ",
//    ".aab.aa",
//    "a..ab..",
//    "a..ab.."
//};
const vector<string> p7 = {
    ".aabbcc",
    "a.dd.dd",
    "ad..d..",
    "bd..d..",
    "b.dd.dd",
    "cd..d..",
    "cd..d.."
};

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

    if (N == 2) {
        write(-1);
        return 0;
    }

    vector<string> ans(N);
    rep(i, N) ans[i] = string(N, '.');

    if (N == 3) ans = p3;
    else if (N == 4) ans = p4;
    else if (N == 5) ans = p5;
    else if (N == 6) {
        rep(i, 3) rep(j, 3) {
            ans[i][j] = ans[3 + i][3 + j] = p3[i][j];
        }
    }
    else if (N == 7) ans = p7;
    else {
        int k4 = (N - 8) / 4;
        rep(k, k4) {
            rep(i, 4) rep(j, 4) {
                ans[4 * k + i][4 * k + j] = p4[i][j];
            }
        }
        int M = 4 * k4;

        if (N - M == 8) {
            rep(i, 4) rep(j, 4) {
                ans[M + i][M + j] = p4[i][j];
            }
            M += 4;
            rep(i, 4) rep(j, 4) {
                ans[M + i][M + j] = p4[i][j];
            }
        }
        else if (N - M == 9) {
            rep(i, 9) rep(j, 9) {
                ans[M + i][M + j] = p3[i % 3][j % 3];
            }
        }
        else if (N - M == 10) {
            rep(i, 5) rep(j, 5) {
                ans[M + i][M + j] = p5[i][j];
            }
            M += 5;
            rep(i, 5) rep(j, 5) {
                ans[M + i][M + j] = p5[i][j];
            }
        }
        else if (N - M == 11) {
            rep(i, 4) rep(j, 4) {
                ans[M + i][M + j] = p4[i][j];
            }
            M += 4;
            rep(i, 7) rep(j, 7) {
                ans[M + i][M + j] = p7[i][j];
            }
        }
    }

    rep(i, N) write(ans[i]);
}

Measured memory_bytes: 2304
n, k = map(int,input().split())
mod = 10 ** 9 + 7

cnt = 0
for i in range(k, n + 2):
    temp = i * (2 * n - i + 1) // 2 - i * (i - 1) // 2 + 1
    cnt = (cnt + temp) % mod
    #print(i, cnt, temp)
print(cnt)

Measured memory_bytes: 9116
/**
 * C - Triangular Relationship
 * https://atcoder.jp/contests/abc108/tasks/arc102_a
 **/
#include<iostream>

#define ll long long

using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    if(k%2==0) {
        ll one=n/k;
        ll half=2*n/k-one;
        cout << one*one*one+half*half*half << endl;
    } else {
        ll one=n/k;
        cout << one*one*one << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

n = int(input())
ans = n
divisor_num = divisor(n)

for i in divisor_num:
    j = n // i
    tmp = i + j - 2
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 66708
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
const ll N=1e5+5;
ll bexpo(ll x,ll n){
    if(n==0)return 1;
    else if(n%2==0)return bexpo(x*x,n/2);
    else return x*bexpo(x*x,(n-1)/2);
}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);} 
int Arr[N];
void initialize()
{
    for(int i = 0;i<N;i++)
    Arr[ i ] = i ;
}
int root(int i)
{
    while(Arr[ i ] != i)       
    {
     i = Arr[ i ];
    }
    return i;
}

void unio(int A ,int B)
{
    int root_A = root(A);       
    int root_B = root(B);  
    if(root_A<root_B)
        Arr[ root_A ] = root_B ;    
    else
        Arr[root_B]=root_A;
}
bool find(int A,int B)
{
    if( root(A)==root(B) )    
    return true;
    else
    return false;
}
ll w[N],v[N];
ll dp[N][102];
ll knapsack(ll wt,ll i)
{ 
  if(wt==0 || i==0)
    return 0;
  if(dp[wt][i]!=-1)
    return dp[wt][i];
  if(w[i]>wt)
    return knapsack(wt,i-1);
  return dp[wt][i]=max(knapsack(wt-w[i],i-1)+v[i],knapsack(wt,i-1));
   
}
int main() {
FIO;
  ll n,wt;
  cin>>n>>wt;
 memset(dp,-1,sizeof(dp));
  ll i;
  for(i=1;i<=n;i++)
    cin>>w[i]>>v[i];
  cout<<knapsack(wt,n);
}

Measured memory_bytes: 83288
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int W = stdIn.nextInt(); int H = stdIn.nextInt(); int x = stdIn.nextInt(); int y = stdIn.nextInt(); int r = stdIn.nextInt(); if(x - r < 0 || y - r < 0 || W < x + r || H < y + r) { System.out.println("No"); } else { System.out.println("Yes"); } } } 


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


int main() {
    string s,t;
    cin >> s >> t;
    t=t.erase(s.size());
    if(s==t) cout << "Yes"; 
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<int> min = new List<int>();
        for (int i = 0; i < s[0]; i ++) {
            int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (c[1]<=s[1]) min.Add(c[0]);
        }
        if (min.Count()==0) Console.WriteLine("TLE");
        else Console.WriteLine(min.Min());
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "/Users/swad/Desktop/CP/debug.h"
#endif

const int N = int(2e5) + 10;

typedef pair<ll, ll> pll;
struct CHT { // Finds maximum
private:
	vector<pll> lines;
public:
	CHT() {}
	void addLine(pll line) {
		insert(line);
	}
	ll query(ll x) {
		if (lines.empty()) return LLONG_MIN;

		int L = 0, R = lines.size() - 1;
		while (L != R) {
			int mid1 = L + (R - L) / 3;
			int mid2 = R - (R - L) / 3;
			if (lines[mid1].x * 1LL * x + lines[mid1].y
				>= lines[mid2].x * 1LL * x + lines[mid2].y) R = mid2 - 1;
			else L = mid1 + 1;
		}
		return lines[L].x * 1LL * x + lines[L].y;
	}
private:
	bool bad(pll line1, pll line2, pll line3) {
		return (line3.y - line1.y) * 1LL * (line1.x - line2.x)
			   <= (line2.y - line1.y) * 1LL * (line1.x - line3.x);
	}
	void insert(pll line) {
		while (lines.size() > 0 && lines.back().x == line.x) lines.pop_back();
		lines.push_back(line);
		int sz = lines.size();
		while (sz >= 3 && bad(lines[sz - 3], lines[sz - 2], lines[sz - 1])) {
			lines.erase(lines.end() - 2);
			sz--;
		}
	}
};

int n;
ll h[N];
ll C;
ll dp[N];

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	scanf("%d %lld", &n, &C);
	for (int i = 1; i <= n; i++) scanf("%lld", &h[i]);

	CHT cht;
	dp[1] = 0;

	for (int i = 2; i <= n; i++) {
		cht.addLine({2LL * h[i - 1], - dp[i - 1] - C - h[i - 1] * h[i - 1]});
		dp[i] = h[i] * h[i] - cht.query(h[i]);
	}

	printf("%lld\n", dp[n]);

	return 0;
}

Measured memory_bytes: 9456
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int ans;
int n;
string s[303];
int main() {
  cin >> n;
  for(int i = 0; i < n; i++) cin >> s[i];

  for(int k = 0; k < n; k++) {
    bool exist = true;
    for(int i = 0; i < n; i++) {
      rotate(s[i].begin(),s[i].begin() + n - 1,s[i].end());
    }
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	if(s[i][j] != s[j][i]) {
	  exist = false;
	  break;
	}
      }
    }
    if(exist) ans++;
  }

  cout << ans * n << endl;
}


Measured memory_bytes: 384
def 解():
    iN = int(input())
    iD = 10**9 + 7

    if iN < 3:
        print(iN)
        exit()

    aS = [1]*(iN+1)
    dP={}
    for i in range(2,iN+1):
        if aS[i]:
            dP[i] = 1
            for j in range(i*2,iN+1,i):
                aS[j] = 0

    for i in range(2,iN+1):
        for iP in dP:
            while i % iP == 0:
                dP[iP]+=1
                i //= iP
    iAns = 1
    for iP in dP:
        iAns *= dP[iP]
        iAns %= iD
    print(iAns)
解()


Measured memory_bytes: 3064
def bubble_sort(A, N):
    flag = 1
    cnt = 0
    while flag:
        flag = 0
        for j in range(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                A[j], A[j -1] = A[j - 1], A[j]
                flag = 1
                cnt += 1
    print(' '.join(list(map(str, A))))
    print(cnt)
                

N = int(input())
A = list(map(int, input().split()))
bubble_sort(A, N)



Measured memory_bytes: 5604
#include<stdio.h>

int main(void){
  int N,M,L,R,Lmax,Rmin,i,c;
  scanf("%d %d",&N,&M);
  Rmin=N;
  Lmax=1;
  for(i=0;i<M;i++){
    scanf("%d %d",&L,&R);
    if(Lmax<L){Lmax=L;}
    if(Rmin>R){Rmin=R;}
  }
  if(Rmin>=Lmax){
    printf("%d\n",Rmin-Lmax+1);
  }else{
    printf("0\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=605;

int n,m,dx[MAXN*4],dy[MAXN*4];
void work(int d)
{
	m=0;
	for(int i=-n;i<=n;++i)
		for(int j=-n;j<=n;++j)
			if(i*i+j*j==d)dx[++m]=i,dy[m]=j;
}
int c1[MAXN][MAXN],c2[MAXN][MAXN];
void dfs(int x,int y,int c[MAXN][MAXN])
{
	int tx,ty;
	for(int i=1;i<=m;++i)
	{
		tx=x+dx[i],ty=y+dy[i];
		if(tx<0 || ty<0 || tx>=n || ty>=n || c[tx][ty])continue;
		c[tx][ty]=3-c[x][y];
		dfs(tx,ty,c);
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int d;
	readint(n);n*=2;
	readint(d);work(d);
	for(int x=0;x<n;++x)
		for(int y=0;y<n;++y)
		{
			if(c1[x][y])continue;
			c1[x][y]=1;
			dfs(x,y,c1);
		}
	readint(d);work(d);
	for(int x=0;x<n;++x)
		for(int y=0;y<n;++y)
		{
			if(c2[x][y])continue;
			c2[x][y]=1;
			dfs(x,y,c2);
		}
	for(int i=1;i<=2;++i)
		for(int j=1;j<=2;++j)
		{
			int ans=0;
			for(int x=0;x<n;++x)
				for(int y=0;y<n;++y)
					if(c1[x][y]==i && c2[x][y]==j)++ans;
			if(ans*4>=n*n)
			{
				ans=n*n/4;
				for(int x=0;x<n;++x)
					for(int y=0;y<n;++y)
						if(c1[x][y]==i && c2[x][y]==j)
						{
							printf("%d %d\n",x,y);
							--ans;
							if(!ans)return 0;
						}
			}
		}
	return 0;
}

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

using ll = long long;

int main() {
    ll n; cin >> n;
    vector<ll> a(5);
    for(int i = 0; i < 5; ++i) {
        cin >> a[i];
    }
    const ll mi = *min_element(begin(a), end(a));
    cout << (n + mi - 1) / mi + 4 << endl;
}

Measured memory_bytes: 256
import heapq
n,m = map(int,input().split())
j = []
for i in range(n):
    j1 = list(map(int,input().split()))
    j.append(j1)
j.sort(key=lambda x:x[1],reverse=True)
j.sort(key=lambda x:x[0])
day = 1
i = 0
q = []
ans = 0
count = 0
while day <= m and i < n:
    if day == j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        i = i + 1
    elif day > j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        i = i + 1
        count = count + 1
    else:
        day = day + 1
        if count > 0:
            ans = ans + heapq.heappop(q)*(-1)
            count = count - 1
while day <= m and count > 0:
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        count = count - 1
print(ans)

Measured memory_bytes: 31972
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pii;

bool compa(Pii a, Pii b) 
{
    if (a.first < b.first) return true;
    if ((a.first == b.first) && (a.second > b.second)) return true;
    return false;
}

bool compb(Pii a, Pii b)
{
    if (a.second == 0 && b.second == 0) return a.first > b.first;
    if (a.second == 0) return false;
    if (b.second == 0) return true;
    int da = a.second - a.first;
    int db = b.second - b.first;
    if (da > db) return true;
    if (da == db) return a.first > b.first;
    return false;
}

int main() {
    int N; cin >> N;
    vector<Pii> bra(N);
    for (int i = 0; i < N; i++) {
        bra[i].first = 0;
        bra[i].second = 0;
        string S; cin >> S;
        for (char x : S) {
            if (x == '(') {
                bra[i].second++;
            } else {
                if (bra[i].second > 0) {
                    bra[i].second--;
                } else {
                    bra[i].first++;
                }
            }
        }
    }

    sort(bra.begin(), bra.end(), compa);
    vector<Pii> amari;
    int k = 0;
    for (int i = 0; i < N; i++) {
        if (bra[i].first - bra[i].second < 0) {
            k -= bra[i].first;
            if (k < 0) {
                cout << "No" << endl;
                return 0;
            }
            k += bra[i].second;
        } else {
            amari.push_back(bra[i]);
        }
    }

    sort(amari.begin(), amari.end(), compb);
    for (auto x : amari) {
        k -= x.first;
        if (k < 0) {
            cout << "No" << endl;
            return 0;
        }
        k += x.second;
    }

    if (k != 0) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

int main() {
    long long int n;
    cin>>n;
    long long int a[n];
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long int ans=0;
    for(long int i=0;i<n;i++)
    for(long int j=i+1;j<n;j++)
    for(long int k=j+1;k<n;k++)
    {
        if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[k]+a[j]>a[i] && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
        ans++;
    }
    cout<<ans<<endl;
	// your code goes here
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include <array>
#include <vector>
#include <algorithm>
#include "math.h"
using namespace std;


int main() {
  std::array<int, 3> n;
  cin >> n[0] >> n[1] >> n[2];
  std::sort(n.begin(), n.end());

  int diff = 2 * n[2] - n[1] - n[0];
  if (diff % 2 == 0) {
    std::cout << diff / 2 << std::endl;
  } else {
    std::cout << diff / 2 + 2 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner


object Main {

  def solve(n: Long, capaList: IndexedSeq[Long]): Long = {
    val minCapa = capaList.min
    capaList.length + (n-1)/minCapa
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextLong()
    val capaList = for (_ <- 0 until 5) yield sc.nextLong()
    println(solve(n, capaList))
  }
}

Measured memory_bytes: 27208
N, K = map(int, input().split())
H = list(map(int, input().split()))
INF = 10 ** 9
dp = [INF]*N
dp[0] = 0
for i in range(N):
    for j in range(K):
        target=i+j+1
        if target < N:
            tmp = dp[i] + abs(H[i]-H[target])
            dp[target] = min(dp[target], tmp)
print(dp[N-1])

Measured memory_bytes: 52592
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string s; cin >> s;
  cout << s.substr(0, 4) << ' ' << s.substr(4, 8) << '\n';
}

Measured memory_bytes: 256