akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
int n,k;
int a[110];
bool dp[100010];
int main()
{
  cin >> n >> k;
  rep(i,n) cin >> a[i];
  
  dp[0] = false;

  rep1(i,k){
    bool f = false;
    rep(j,n){
      if( i-a[j] < 0) break;
      else if( !dp[i-a[j]] ){
	f = true;
	break;
      }
    }
    dp[i] = f;
  }

  cout << (dp[k] ? "First" : "Second") << "\n";
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 500100
//#define NIL -1

int n;
vector<vector<int>> a(200010);
vector<int> parent(200010, MAX);


void bfs(int s){
    queue<int> q;
    q.push(s);
    int u;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(int i=0; i<a[u].size(); i++){
            int v=a[u][i];
            if(parent[v]!=MAX){
                continue;
            }
            parent[v]=u+1;
            //cout << u+1 << " " << v+1 << " " << dist[v] << endl;
            q.push(v);
        }
    }
}


int main() {
    int m;

    cin >> n >> m;



    int tmp_a;
    int tmp_b;
    bool ok=true;

    for(int i=0; i<m; i++){
        cin >> tmp_a >> tmp_b;
        tmp_a--;
        tmp_b--;
        a[tmp_a].push_back(tmp_b);
        a[tmp_b].push_back(tmp_a);
    }
    parent[0]=-1;
    bfs(0);
    for(int i=0; i<n; i++){
        //cout << dist[i] << endl;
        if(parent[i]==MAX){
            ok=false;
            break;
        }
    }
    if(ok==true){
        cout << "Yes" << endl;
        for(int i=1; i<n; i++){
            cout << parent[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 12952
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,s,t;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0){
		    cout<<"DENIED";
		    return 0;
	    }
	}
	cout<<"APPROVED";
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::i32;
use std::char;

fn match_i(s: &Vec<i32>, i: i32) -> bool {
  let mut p = 0;
  for j in 0..3 {
    let d = i / (10 as i32).pow((2-j) as u32) % 10;
    if let Some(q) = s[p..].iter().position(|&x| x == d) {
      p += q + 1;
    } else {
      return false;
    }
  }
  true
}

fn solve(n: usize, s: Vec<i32>) -> i32 {
  (0..1000).filter(|i| match_i(&s, *i)).count() as i32
}

fn main() {
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let mut iter = buf.split_whitespace();
  let n: usize = iter.next().unwrap().parse().unwrap();
  let s: Vec<i32> = iter.next().unwrap().chars().map(|c| c.to_digit(10).unwrap() as i32).collect::<Vec<_>>();

  let ans = solve(n, s);
  println!("{}", ans);
}


Measured memory_bytes: 4352
c,b = gets.split(" ").map{|n|n.to_i}
l = gets.split(" ").map{|n|n.to_i}
l.unshift(0)
cl,sum= 0,0
while cl < c+1 && sum + l[cl]  <= b do
  sum += l[cl]
  cl += 1
end
puts cl

Measured memory_bytes: 1788
from math import gcd
def lcm(a, b):
    return a*b//gcd(a, b) 

A, B, C, D = map(int,input().split())
As = [(A-1)//C, (A-1)//D, (A-1)//lcm(C,D)]
Bs = [B//C, B//D, B//lcm(C,D)]

aa = (A-1) - (As[0]+As[1]-As[2])
bb = B - (Bs[0]+Bs[1]-Bs[2])

print(bb-aa)

Measured memory_bytes: 9152
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();
    	int ans = 0;
	int b = K-A;
    int c = K-A-B;
	if(A==0 && C==0){
		System.out.println("0");
    }else if(K>=A && c<1){
		System.out.println(A);
	}else if(K>=A && c>=1){
		System.out.println(A+(c*-1));
	}else if(K<A){
        System.out.println(K);
      }
}
}

Measured memory_bytes: 35772
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;


int main(void) {
	int n, x, i, a[103];

	scanf("%d%d", &n, &x);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	sort(a, a + n);

	for (i = 0; i < n; i++) {
		if (x < a[i]) break;
		if (i == n - 1 && x > a[i]) break;
		x -= a[i];
	}

	printf("%d\n", i);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double

#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const ll MOD = 1000 * 1000 * 1000 + 7;
using namespace std;



long double dp[4000][4000];


ll N;

long double P[4000];

long double seno(ll idx, ll H)
{



if (idx==1)
{
if (H==0)
return dp[idx][0]=1-P[idx];
else
return dp[idx][1]=P[idx];    
}



if (dp[idx][H]!=4)
return dp[idx][H];    



dp[idx][H]=(long double)(P[idx]*seno(idx-1,H-1))+(long double)((idx-1-H>=0?(1-P[idx])*seno(idx-1,H):0));



return dp[idx][H];
}



int main() 
{ 


fastio();

cin>>N;
   
for(int i=1;i<=N;i++)
cin>>P[i];    


for(int i=1;i<=3000;i++)
{
for(int j=1;j<=3000;j++)
dp[i][j]=0;
}    


dp[1][0]=1-P[1];
dp[1][1]=P[1];


for (int i=2;i<=N;i++)
{
    dp[i][0]=(1-P[i])*dp[i-1][0];
}



for (int i=2;i<=3000;i++)
{
for(int j=1;j<=i;j++)
{
dp[i][j]=(P[i]*dp[i-1][j-1])+(1-P[i])*dp[i-1][j];    
}    
}    


long double sum=0;

for(int i=(N/2)+1;i<=N;i++)
{

sum+=dp[N][i];
}    

cout<<setprecision(9)<<sum;

return 0;
} 




Measured memory_bytes: 188416
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 2e3 + 15;
int n, k, q, a[N];
int len[N];
int ord[N];

main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n >> k >> q;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		ord[i] = i;
	}
	sort(ord + 1, ord + 1 + n, [&](int x, int y) {
		return a[x] > a[y];
	});
	int ans = inf;
	for(int i = 1; i <= n; ++i) {
		int x = a[ord[i]];
		int cur = 0;
		vector <pii> v = {};
		for(int j = 1; j <= n; ++j) {
			if(a[j] < x)
				continue;
			int k = j;
			while(k + 1 <= n && a[k+1] >= x)
				++k;
			for(int t = j; t <= k; ++t)
				v.pb({a[t], j});
			len[j] = k - j + 1;
			j = k;
		}
		sort(v.begin(), v.end());
		int cnt = 0;
		for(pii e : v) {
			if(len[e.se] < k)
				continue;
			--len[e.se], ++cnt;
			if(cnt == q) {
				Min(ans, e.f - x);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
n,k=map(int,input().split())

ans=0
prob=1/n
coins=1/2

for i in range(1,n+1):
    cnt=1
    tmp=i
    if tmp >= k:
        ans+=prob
    else:
        while tmp*2 < k:
            tmp=tmp*2
            cnt+=1
        ans+=prob*(coins**cnt)

print(ans)

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

int main() {
	long long x,y,z=0;
	cin >> x >> y;
	if(x % y == 0)
	{
		z = -1;
	}
	else
	{
		z = (x * y) - x;
	}
	cout << z <<endl;
	return 0;
}


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

using namespace std;

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

    int n;
    cin >> n;

    string query, str;
    set<string> str_set;

    for (int i = 0; i < n; i++) {
        cin >> query >> str;

        if (query == "insert") {
            str_set.insert(str);
        } else if (query == "find") {
            cout << (str_set.find(str) != str_set.end() ? "yes" : "no") << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 29804
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int Y = int.Parse(str[1]);
		int a = Y/10000;
		int b = -1;
		int c = -1;
		while(a >= 0){
			for(var i=0;i<=(Y-a*10000)/5000;i++){
				int n = Y-a*10000-i*5000;
				if(n%1000 == 0){
					if(a+i+n/1000==N){
						b = i;
						c = n/1000;
						break;
					}
				}
			}
			if(b >= 0){
				break;
			}
			a -= 1;
		}
		Console.WriteLine(a + " " + b + " " +c);
	}
}

Measured memory_bytes: 13140
#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;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

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


const ll MOD = 998244353;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    mint ans = 0;
    mint m_minus_1 = m-1;
    mint fact[200001] = {};
    fact[0] = 1;fact[1] = 1;
    rep(i,2,200001) fact[i] = fact[i-1]*i;
    
    rep(i,0,k+1){
        ans += fact[n-1]/fact[i]/fact[n-i-1]*m*m_minus_1.pow(n-i-1);
    }
    cout << ans << endl;

    return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int const INF = INT32_MAX;
struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,INF);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,int val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    int getmin(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return node[k];
        int vl = getmin(a,b,2*k+1,l,(l+r)/2);
        int vr = getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

int main() {
    int h,w;
    cin >> h >> w;
    set<int> st;
    SegmentTree seg(vector<int>(w+10,0));
    for (int i = -1;i < w+1;++i) st.insert({i});
    for (int i = 0;i < h;++i) {
        int a,b;
        cin >> a >> b;a--;
        int r = -1,x = 1e9;
        auto it = st.lower_bound(a);
        while (*it < b) {
            r = *it;
            x = min(x,b-r+seg.getmin(r,r+1));
            seg.update(r,1e9);
            it = st.erase(it);
        }
        if (*it == b) {
            r = *it;
            x = min(x,seg.getmin(r,r+1));
        } else {
            st.insert(b);
        }
        if (r >= 0) seg.update(b,x);
        int ans = seg.getmin(0,w)+i+1;
        if (ans > h+w) ans = -1;
        cout << ans << newl;
        // for (int j = 0;j < w;++j) cout << seg.getmin(j,j+1) << " ";
        // cout << newl;
    }
}

Measured memory_bytes: 14604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();

	    int sheet = N / 2;

	    if(N % 2 == 1) {
	    	sheet++;
	    }

	    System.out.println(sheet);
	}
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    const int MAX = 110000;
    const int MOD = 1000000007;
    static long[] Fac = new long[MAX], Finv = new long[MAX], Inv = new long[MAX];

    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }
    static object Solve() {
        var cin = new Scanner();
        int N = cin.NextInt(), M = cin.NextInt();
        COMini();
        var primeFactors = PrimeFactorization(M);
        long result = 1;
        foreach (var p in primeFactors) {
            var num = p.count;
            long temp = COM(num + N - 1, N - 1);
            result = result * temp % MOD;
        }
        return result;
    }
    static void COMini() {
        Fac[0] = Fac[1] = 1;
        Finv[0] = Finv[1] = 1;
        Inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            Fac[i] = Fac[i - 1] * i % MOD;
            Inv[i] = MOD - Inv[MOD % i] * (MOD / i) % MOD;
            Finv[i] = Finv[i - 1] * Inv[i] % MOD;
        }
    }
    static long COM(int N, int K) {
        if (N < K) return 0;
        if (N < 0 || K < 0) return 0;
        return Fac[N] * (Finv[K] * Finv[N - K] % MOD) % MOD;
    }
    static List<(int prime, int count)> PrimeFactorization(int N) {
        var ret = new List<(int, int)>();
        for (int i = 2; i * i <= N; i++){
            if (N % i != 0) continue;
            var count = 0;
            while (N % i == 0) { 
                count++;
                N /= i;
            }
            ret.Add((i, count));
        }
        if (N != 1) ret.Add((N, 1));
        return ret;
    }
}

class Scanner
{
    string[] s;
    int i;
    char[] cs = {' '};

    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public long NextLong() => long.Parse(Next());
    public double NextDouble() => double.Parse(Next());
    public int[] ArrayInt(int N, int add = 0) {
        var Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = NextInt() + add;
        }
        return Array;
    }
    public long[] ArrayLong(int N, long add = 0) {
        var Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = NextLong() + add;
        }
        return Array;
    }
    public double[] ArrayDouble(int N, double add = 0) {
        var Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 30456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N, M; cin >> N >> M;
  vi K(N);
  vvi A(N,vi(30));
  
  rep(i,N) {
    cin >> K.at(i);
    rep(j,K.at(i)) {
      cin >> A.at(i).at(j);
    }
  }
  
  vi d(M+1,0);
  rep(i,N) {
    rep(j,K.at(i)) {
      d.at(A.at(i).at(j))++;
    }
  }
  
  cout << count(all(d),N) << endl;  
}

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

int main()
{
    string s;
    cin>>s;
    int m=0;
    int c=0;
    for(char d:s){
        if(d=='R'){
             c++;
             m=max(m,c);
        }
        else{
            c=0;
        }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 3624
#![allow(unused_imports)]

mod pcl {

}




fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let k = it.next().unwrap().parse::<i32>().unwrap();
    let n = it.next().unwrap().parse::<i32>().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut a: Vec<_> = s
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    debug_assert_eq!(a.len(), n as usize);

    a.sort();
    let v = a[0];
    a.push(v + k);
    let dist = a.windows(2).map(|v| v[1] - v[0]).max().unwrap();
    println!("{}", k - dist);
}


Measured memory_bytes: 8444
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  int ans = 1000000000;
  for (int p = x[0]; p <= x[n-1]; p++) {
    int tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += pow((x[i]-p), 2);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int c[53] = { 0 };
    for( int i = 0; i < n; i++ ){
        char t;
        int num;
        cin >> t >> num;
        if( t == 'S' ) c[num] = 1;
        else if( t == 'H' ) c[13+num] = 1;
        else if( t == 'C' ) c[13*2+num] = 1;
        else if( t == 'D' ) c[13*3+num] = 1;
    }
    for( int i = 1; i <= 52; i++ ){
        if( c[i] == 0 ){
            if( i <= 13 ) cout << "S " << i << endl;
            else if( 13 < i && i <= 13*2 ) cout << "H " << i-13 << endl;
            else if( 13*2 < i && i <= 13*3 ) cout << "C " << i-(13*2) << endl;
            else if( 13*3 < i ) cout << "D " << i-(13*3) << endl;
        }
    }
}

Measured memory_bytes: 1164
a=input().split()
b=input().split()
t=int(input())
dis=abs(int(a[0])-int(b[0]))
p=-(int(b[1])-int(a[1]))
if p<=0: 
    print("NO")
else:
    if dis/p>t:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 61832
#include <bits/stdc++.h>
using namespace std;
int n;
int s[100];

int main() {
    while(true) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i=0; i<n; i++) scanf("%d", &s[i]);
        sort(s, s+n);
        int sum = 0;
        for (int i=1; i<n-1; i++) sum += s[i];
        printf("%d\n", sum / (n - 2));
    }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;
  string ans;

  rep(i,s.size()){
    if(s[i]=='B'){
      if(ans.size()>0) ans.pop_back();
    } else {
      ans.pb(s[i]);
    }
  }

  prt(ans);
}


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

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

    int wa[100010] = {};
    int ac[100010] = {};
    for(int i = 0;i < m;i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "WA"){
            if(ac[p] == 0) wa[p]++;
        }else{
            ac[p] = 1;
        }
    }

    int ac_ans = 0;
    int wa_ans = 0;

    for(int i = 0;i < n;i++){
        if(ac[i]){
            ac_ans++;
            wa_ans += wa[i];
        }
    }

    cout << ac_ans << " " << wa_ans << endl;

    return 0;
}






Measured memory_bytes: 1024
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 5 + 100)

def rec(v, dp, E):
    if dp[v] != -1:
        return dp[v]
    x = 0
    for w in E[v]:
        x = max(x, rec(w, dp, E) + 1)
    dp[v] = x
    return x

n, m = map(int, input().split())
E = defaultdict(list)
for i in range(m):
    x, y = map(int, input().split())
    E[x - 1].append(y - 1)

dp = [-1 for _ in range(n)]
ans = 0
for i in range(n):
    ans = max(ans, rec(i, dp, E))
print(ans)


Measured memory_bytes: 67784
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;


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

	const double PI = 3.14159265358979323846;

	double A, B, H, M;
	cin >> A >> B >> H >> M;

	long double thete = (M * PI / 30) - ((H * PI / 6) + ( M * PI / 360));

	if (thete < 0) {
		thete *= -1;
	}

	if (thete >= PI) {
		thete = 2 * PI - thete;
	}

	double c2 = A * A + B * B - 2 * A * B * cos(thete);

	printf("%.11lf\n", sqrt(c2));

	return 0;
}

Measured memory_bytes: 4188
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const char letters[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int diff[62];char pw[129],query[129];
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int ask(void){printf("? %s\n",query);fflush(stdout);return IN();}
int main(void)
{
  int l=0,len=0,mid=0,r=0,total=0;
  rep(i,62){rep(j,128){query[j]=letters[i];}query[128]=0;diff[i]=128-ask();total+=diff[i];}
  rep(i,62)
  {
    if(len==0){len=diff[i];rep(j,diff[i])pw[j]=letters[i];}
    else
    {
      l=0;
      rep(k,diff[i])
      {
        r=len;
        while(l<r)
        {
          mid=(l+r+1)/2;
          rep(j,mid)query[j]=pw[j];
          rep(j,diff[i]-k)query[mid+j]=letters[i];
          query[mid+diff[i]-k]=0;
          if(ask()==total-mid-diff[i]+k)l=mid;else r=mid-1;
        }
        len++;rep(j,len-l){pw[len-j]=pw[len-j-1];}pw[l]=letters[i];
      }
    }
  }
  pw[len]=0;return printf("! %s\n",pw),0;
}

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

unordered_set<string> okWord;

string Extract(string &str, int s, int e) {
  string res;
  if (s<0) {return res;}
  for (int i=s; i<e; i++) {res+=str.at(i);}
  return res;
}
int NextStartIndex(string &str, int p) {
  for (int i=7; i>=5; i--) {
    if (okWord.count(Extract(str, p-i, p))) {return p-i;}
  }
  return -1;
}
int main() {
  okWord.insert("dream");
  okWord.insert("dreamer");
  okWord.insert("erase");
  okWord.insert("eraser");
  
  string S;
  cin >> S;
  int idx=S.size();
  while(idx > 0) {
    idx=NextStartIndex(S, idx);
  }
  if (idx == 0) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}


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

ll mod = 1e9+7;

ll modpower(ll a, ll m) {
    ll res = 1;
    ll n = m;
    ll b = a;
    while (n > 0) {
        if (n % 2 == 1) {
            res *= b;
            res %= mod;
        }
        n /= 2;
        b = (b * b) % mod;
    }
    return res;    
}
 
ll modinv(ll a){
    return modpower(a, mod-2);
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> fact(N+K+1, 1);
    for (int i = 2; i <= N+K; i++) {
        fact[i] = (fact[i-1] * i) % mod;
    }
    for (int i = 1; i <= K; i++) {
        if (i > N-K+1) {
            cout << 0 << endl;
            continue;
        }
        ll t, u;
        t = (fact[N-K+1] * modinv(fact[i]) % mod ) * modinv(fact[N-K+1-i]) % mod;
        u = (fact[K-1] * modinv(fact[i-1]) % mod ) * modinv(fact[K-i]) % mod;
        cout << (t*u)%mod << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int x, y, a, b;
  cin >> x >> y;
  REP(i, 100) {
    REP(j, 100) {
      if(2 * i + 4 * j == y && i + j == x) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < array.length; i++)
			array[i] = sc.nextInt();
		
		int count = 1;
		for(int i = 1; i < array.length; i++) {
			boolean flag = true;
			for(int j = 0; j < i; j++)
				if(array[j] > array[i])
					flag = false;
			count += flag ? 1 : 0;
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
    fast;
	ll n;
	cin>>n;
	ll a=floor(sqrt(n));
	cout<<a*a;
    return 0;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  vector<long> a(3);
  rep(i,3) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

move_x = tx - sx
move_y = ty - sy

move1 = 'R'*move_x + 'U'*move_y
move2 = 'L'*move_x + 'D'*move_y
move3 = 'D' + 'R'*(move_x+1) + 'U'*(move_y+1) + 'L'
move4 = 'U' + 'L'*(move_x+1) + 'D'*(move_y+1) + 'R'

print(move1 + move2 + move3 + move4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int L, R, D;
	cin >> L >> R >> D;
	int c = 0;
	for (int i = L; i <= R; i++) {
		c += (i % D == 0);
	}
	cout << c << endl;
}



Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
using namespace std;
int a[200000],b[200000],lf[200001];
int main(void){
	int n,m,i,flg;
	cin>>n>>m;
	for(i=0;i<n;i++) lf[i]=0;
	for(i=0;i<m;i++) cin>>a[i]>>b[i];
	for(i=0;i<m;i++){
		if(a[i]==1) lf[b[i]]=1;
	}
	flg=0;
	for(i=0;i<m;i++){
		if(lf[a[i]]==1&&b[i]==n){
			flg=1;
			break;
		}
	}
	if(flg==1) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cctype>
#include <string>
#include <cassert>
using namespace std;
string S;
int PQR[3];
int cur = 0;
int formula();
int kakko();
int formula(){
  char c = S[cur];
  cur++;
  if(isdigit(c)){
    return c -'0';
  }else if(isupper(c)){
    return PQR[c-'P'];
  }else if(c == '-'){
    int tmp = formula();
    if(tmp == 2)return 0;
    else if(tmp == 1)return 1;
    else return 2;
  }else{
    int tmp = kakko();
    return tmp;
  }
  return -1;
}
int kakko(){
  int f = formula();
  char op = S[cur];
  cur++;
  int s = formula();
  assert(S[cur] == ')');
  cur++;
  if(op == '*'){
    //cout << f << " " << s << endl;
    return min(f,s);
  }else if(op == '+'){
    return max(f,s);
  }
  return -1;
}
int main(){
  while(cin >> S,S != "."){
    int cnt = 0;
    for(int i = 0;i < 3;i++){
      for(int j = 0;j < 3;j++){
	for(int k = 0;k < 3;k++){
	  cur = 0;
	  PQR[0] = i;
	  PQR[1] = j;
	  PQR[2] = k;
	  if(formula() == 2)cnt++;
	}
      }
    }
      
    
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1188
#include<atcoder/all>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
using namespace atcoder;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second



int main(){
    ll n,q;
    cin >> n >>q;
    dsu d(n);
    for(ll i=0;i<q;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        if(a==1){
            cout << d.same(b,c) << endl;
        }else{
            d.merge(b,c);
        }
    }
}

Measured memory_bytes: 3836
n,w=map(int,input().split())
W=[]
V=[]
for i in range(n):
    a,b=map(int,input().split())
    W.append(a)
    V.append(b)

dp=[0 for i in range(w+1)]
for q in range(n):
    bq=q
    for i in range(w):
        bi=w-i-1
        if bi+W[bq]<=w:
            dp[bi+W[bq]]=max(dp[bi]+V[bq],dp[bi+W[bq]])
    #print(dp)

print(dp[-1])

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

#define ll long long int
ll const mod = 1e9 + 7;

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll p[a], q[b], r[c];
    for(ll i=0;i<a;i++)
    cin>>p[i];
    for(ll i=0;i<b;i++)
    cin>>q[i];
    for(ll i=0;i<c;i++)
    cin>>r[i];
    
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    
    vector<ll> v;
    for(ll i=0;i<x;i++)
    v.push_back(p[a-1-i]);
    for(ll i=0;i<y;i++)
    v.push_back(q[b-1-i]);
    
    sort(v.begin(), v.end());
    
    ll k=0;
    for(ll i=c-1;i>=0;i--)
    {
        if(k>v.size()-1)
        break;
        
        if(v[k]<r[i])
        {
            v[k] = r[i];
            k++;
        }
        else
        break;
    }
    
    ll sum=0;
    for(auto i=v.begin();i!=v.end();++i)
    sum+=*i;
    
    cout<<sum;
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 4852
# -*- coding: utf-8 -*-
import sys

def main():
	X, A, B = map(int, input().split(" "))
	
	if A >= B:
		print("delicious")
		sys.exit()
	if B <= A + X:
		print("safe")
	else:
		print("dangerous")
		
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 2940
import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


# ------------------------------


def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    for i in range(2,n):
        # dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        for j in range(max(0,i-k),i):
            dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])

    print (dp[-1])

if __name__ == "__main__":
    main()



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,p;
  while(1){
    cin >> n >> p;
    int initialp=p;
    if(n==0) return 0;
    vector<int> s(n,0);
    for(int i=0;true;i++){
      if(p==0){
        if(s[i%n]!=initialp){
          p=s[i%n];
          s[i%n]=0;
        }else{
          cout << i%n << endl;
          break;
        }
      }else{
        s[i%n]++;
        p--;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3016
// 2011/03/29 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool spc = false;

	while(true){
		int a, b;
		cin >> a >> b;
		if(a==0&&b==0)
			break;

		if(spc)
			cout << endl;
		else
			spc = true;

		bool flg = false;
		for(int i=a; i<=b; i++){
			if(i%400==0){
				cout << i << endl;
				flg = true;
			}
			else if(i%100==0){
				continue;
			}
			else if(i%4==0){
				cout << i << endl;
				flg = true;
			}
		}
		if(!flg)
			cout << "NA" << endl;
	}

	return 0;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll sum = a + b;
  ll w = n / sum;
  ll m = n % sum;
  cout << w * a + min(a, m) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define debug(x) cout << "debug: " << x << endl
#define MOD 1e9 + 7
#define INF 1e9

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

int main(){
    int n, w; cin >> n >> w;
    vector<vector<int>> v(n, vector<int>(2));
    rep(i, n) rep(j, 2) cin >> v[i][j];
    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
    rep(i, n){
        rep(j, w + 1){
            if (j - v[i][0] >= 0)
                chmax(dp[i + 1][j], dp[i][j - v[i][0]] + v[i][1]);
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[n][w] << endl;
}

Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;

i64 h[40404];
i64 a[40404];
i64 d[40404];
i64 s[40404];
i64 A[40404];
i64 B[40404];

i64 ceil(i64 A,i64 B){
    return A / B + min(1LL,A % B);
}

int main(){
    cin >> n;
    vector<int> vec;
    rep(i,0,n){
        cin >> h[i] >> a[i] >> d[i] >> s[i];
        if(i == 0) continue;

        //cant
        if(a[0] <= d[i] && a[i] > d[0]){
            cout << -1 << endl;
            return 0;
        }
        if(a[0] > d[i]){
            vec.push_back(i);
            A[i] = (ceil(h[i],a[0] - d[i]));
            B[i] = (max(0LL,a[i] - d[0]));
        }
    }

    auto ope = [&](int i,int j){
        return A[i] * B[j] < A[j] * B[i];
    };

    sort(vec.begin(),vec.end(),ope);

    i64 HP = 0;
    i64 cou = 0;

    rep(i,0,(int)vec.size() - 1){
        int index = vec[i];
        cou += A[index];
        HP += cou * B[index];
        if(s[index] < s[0]) HP -= B[index];
        if(h[0] <= HP){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << HP << endl;
    return 0;
}



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

using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(long long i = 0;i < n;i++)
long long H,W,K,N,D,X,T;


int main()
{
  int A[1000000];
  cin>>N;
  REP(i,N){
    cin>>A[i];
  }
  long long count=0;
  long long w=0;
  for(int i=0;i<N;i++){
    if(w<A[i]){
      w=A[i];
    }
    count+=w-A[i];
  }
  cout<<count;
  return 0;
}




Measured memory_bytes: 4404
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    REP(i, L, R) {
        if(i % d == 0) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
const ll INF = LLONG_MAX / 2;

signed main() {
    string S;
    cin >> S;
    if(S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    if(S.length() < 26) {
        bool used[26] = {};
        for(int i = 0; i < S.length(); i++) {
            used[S[i] - 'a'] = true;
        }
        string ans = S;
        for(int i = 0; i < 26; i++)
            if(!used[i]) {
                ans += (char)(i + 'a');
                cout << ans << endl;
                return 0;
            }
    }
    int prev = -1;
    for(int i = 25; i >= 0; i--) {
        if(S[i] > prev) {
            prev = S[i];
            continue;
        }
        string ans = S.substr(0, i);
        for(int j = 25; j > i; j--)
            if(S[j] > S[i]) {
                ans += S[j];
                cout << ans << endl;
                return 0;
            }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	string ans;
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++) {
		ans += s[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	string b;
	cin>>a;
	cin>>b;
	int ans=0;
	for(int i=0;i<3;i++){
		if(a[i]==b[i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define FOR0(i, a, b, s) for (int i = a; s > 0 ? i < b : i > b; i += s)
#define FOR1(n) FOR0(i, 0, n, 1)
#define FOR2(i, n) FOR0(i, 0, n, 1)
#define FOR3(i, a, b) FOR0(i, a, b, 1)
#define FOR4(i, a, b, s) FOR0(i, a, b, s)
#define GET5(_1, _2, _3, _4, _5, ...) _5
#define FOR(...) GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int cnt = 0;
  while (a >= b) {
    b *= 2;
    cnt++;
    if (cnt > k) {
      cout << "No" << '\n';
      return 0;
    }
  }
  while (b >= c) {
    c *= 2;
    cnt++;
    if (cnt > k) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}

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

// - - - - - - Data Types - - - - - - //

typedef long long int LLI;
typedef long int LI;
typedef long long LL;

// - - - - - - Vectors - - - - - - //
typedef vector<int> VI;
typedef vector<LLI> VLLI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef vector<VI> VVI;

#define scanVI(v, n)        for(int i=0; i<n; i++){ int x; SF("%d", &x); v.PB(x); }
#define scanVLLI(v, n)      for(int i=0; i<n; i++){ LLI x; SF("%lld", &x); v.PB(x); }
#define scanVS(v, n)        for(int i=0; i<n; i++){ string x; cin >> x; v.PB(x); }
#define scanVD(v, n)        for(int i=0; i<n; i++){ double x; SF("%lf", &x); v.PB(x); }

// - - - - - - Maps - - - - - - //
typedef map<int, int> MII;
typedef map<int, string> MIS;
typedef map<int, char> MIC;
typedef map<string, int> MSI;
typedef map<char, int> MCI;
typedef map<int, VI> MIVI;

// - - - - - - Pairs - - - - - - //
typedef pair<int, int> PII;
typedef pair<string, string> PSS;
typedef pair<char, char> PCC;
typedef pair<int, string> PIS;
typedef pair<int, char> PIC;
typedef pair<string, char> PSC;

// - - - - - - Sets - - - - - - //
typedef set<int> SI;
typedef set<LLI> SLLI;
typedef set<string> SS;
typedef set<char> SC;
// - - - - - - - - - - - - - - - - - - //

#define PF                  printf
#define SF                  scanf
#define PB                  push_back
#define POP                 pop_back()
#define PP                  prev_permutation
#define NP                  next_permutation
#define MP                  make_pair
#define CLRN(a, b)          memset(a, b, sizeof(a))
#define CLR(a)              memset(a, 0, sizeof(a))
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define BSRCN(a, n, x)      binary_search(ALLN(a, n), x)
#define BSRC(a, z)          binary_search(ALL(a), z)
#define MAX                 10000007
#define MIN                 -10000007
#define PI                  acos(-1)
#define BR                  PF("\n")
#define FastIO              ios_base::sync_with_stdio(false)
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
/*----------------------Graph Moves----------------*/
int ROW[]={+1,-1,+0,+0};
int COL[]={+0,+0,+1,-1};

int X[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
int Y[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

int KX[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
int KY[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
int LCM(int a, int b) { return a * (b/GCD(a, b)); }
bool CMP(int a, int b) { return a>b; }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - END - - - - - - - - - - - - - - - - - - - - - - - - - //



int main()
{
    int n; cin >> n;
    cout << ((n*(n+1))/2) << endl;

    return 0;
}



Measured memory_bytes: 256