akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;
#define M 1000000007

typedef long long int ll;

int main() {

	IOS

	int n, k;
	cin >> n >> k;

	ll max_sum, min_sum, count = 0;

	for (ll num_el = k; num_el <= n+1; num_el++) {
		min_sum = ((double)num_el * (num_el-1)) / 2;
		// max_sum = n/2 * (2a + n-1 d);
		max_sum = (ll) (((double)num_el/2) * (2*(n-num_el+1) + (num_el-1)));

		// deb((n-num_el+1));
		// deb(num_el);
		// deb(min_sum);
		// deb(max_sum);

		count = (count + (max_sum - min_sum + 1)) % M;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3620
package main

import (
	"fmt"
	"strings"
)

func main() {
	var num int
	fmt.Scanf("%d", &num)

	var str string
	fmt.Scanf("%s", &str)

	fmt.Println(calc(num, str))
}

func calc(num int, s string) int {
	ret := strings.Count(s, "R") * strings.Count(s, "G") * strings.Count(s, "B")

	for i := 0; i < num-2; i++ {
		for j := i; j < num-1; j++ {
			for _, k := range pattern(i, j) {
				if k < num && k >= 0 {
					if s[i] != s[j] && s[j] != s[k] && s[i] != s[k] {
						ret--
					}
				}
			}
		}
	}

	return ret
}

func pattern(i, j int) []int {
	var ret []int
	if i > j {
		ret = append(ret, i-j+i)
	} else {
		ret = append(ret, j-i+j)
	}
	return ret
}


Measured memory_bytes: 6464
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll n;
    cin >> n;
    if(n%2 == 0){
        cout << n/2 -1 << endl;
    }else{
        cout << n/2 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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(){
    cin.tie(0);
   	ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int tmp = 0;
    int ans = 100000;
    for(int i = 0; i < S.length()-2; i++){
        tmp = stoi(S.substr(i, 3));
        chmin(ans, abs(753-tmp));
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
/*
 * 17-08-26_AGC019_B.cpp
 *
 *  Created on: 2017/08/26
 *      Author: ryoma
 */

#include<iostream>
#include<string>

using namespace std;

string A;
long long a[30];
long long ans;
int main() {
	cin >> A;
	for (int i = 0; i < A.length(); i++) {
		a[A[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		ans += a[i]*(A.length()-a[i]);
	}
	ans /= 2;
	ans++;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 640
//SILENT KILLER
              //HARD WORK BEATS TALENT WHEN TALENT DOESNOT WORK HARD
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
  {ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d});
  }














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

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<string> s(h);
  for (string &i : s) cin >> i;
  vector<vector<int>> l(h, vector<int>(w, -1));
  deque<tuple<int,int,int>> q;
  q.push_back({ch, cw, 0});
  while (!q.empty()) {
    auto [gh, gw, gl] = q.front();
    q.pop_front();
    if (l[gh][gw] != -1) continue;
    l[gh][gw] = gl;
    if (gh + 1 < h and s[gh + 1][gw] == '.') q.push_front({gh + 1, gw, gl});
    if (gh - 1 >= 0 and s[gh - 1][gw] == '.') q.push_front({gh - 1, gw, gl});
    if (gw + 1 < w and s[gh][gw + 1] == '.') q.push_front({gh, gw + 1, gl});
    if (gw - 1 >= 0 and s[gh][gw - 1] == '.') q.push_front({gh, gw - 1, gl});
    FOR(i, -2, 3) FOR(j, -2, 3) {
      int nh = gh + i, nw = gw + j;
      if (0 <= nh and nh < h and 0 <= nw and nw < w and s[nh][nw] == '.') q.push_back({nh, nw, gl + 1});
    }
  }
  cout << l[dh][dw] << endl;
  return 0;
}

Measured memory_bytes: 10688
N = int(input())
S = [input() for _ in range(N)]

cnt = {}
for Si in S:
    cnt[Si] = cnt.setdefault(Si, 0) + 1

result = sorted(cnt.items(), key=lambda x: -x[-1])

ans_list = []
for i, (key, value) in enumerate(result):
    if i == 0:
        ans_cnt = value
    #
    if value >= ans_cnt:
        ans_list.append(key)
    else:
        break

for key in sorted(ans_list):
    print(key)

Measured memory_bytes: 48908
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main()
{
	double n;
	cin >> n;
	if ((int)n % 2 == 0) cout << 0.5;
	else cout << ((int)n / 2 + 1) / n;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;

double dist[1010][1010];
double d[1010];
int N;
void dijkstra(int start){
	priority_queue<pdi, vector<pdi>,greater<pdi> > que;
	for(int i=0;i<N+2;i++)d[i]=10000000000.0;
	d[start] = 0.0;
	que.push( mp(0.0,start) );//cost,ver
	
	while(!que.empty()){
		pdi p=que.top();
		que.pop();
		
		int v=p.second;
		if(d[v]<p.first)continue;
		
		for(int i=0;i<N+2;i++){
			double e=dist[v][i];
			if(d[i]>d[v]+e){
				d[i]=d[v]+e;
				que.push(mp(d[i],i));
			}
		}
	}
	
}
int main(){
	double x,y,r;
	vector<pair<pair<double,double>,double> > data;
	cin>>x>>y;
	data.pb( mp(mp(x,y),0.0) );
	cin>>x>>y;
	data.pb( mp(mp(x,y),0.0) );
	cin>>N;
	
	for(int i=0;i<N;i++){
		cin>>x>>y>>r;
		data.pb( mp(mp(x,y),r) );
	}
	for(int i=0;i<N+2;i++){
		double x1=data[i].first.first,y1=data[i].first.second,r1=data[i].second;
		for(int j=i;j<N+2;j++){
			double x2=data[j].first.first,y2=data[j].first.second,r2=data[j].second;
			dist[i][j]=max(0.0,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))-r1-r2);
			dist[j][i]=dist[i][j];
		}
	}
	dijkstra(0);
	printf("%.10f\n",d[1]);
}


Measured memory_bytes: 12420
#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#define ll long long int
using namespace std;

int main(){
	string s;
	int g_cnt = 0, p_cnt = 0, point = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'g') {
			if (p_cnt < g_cnt) {
				p_cnt += 1;
				point += 1;
			}
			else {
				g_cnt += 1;
			}
		}
		if (s[i] == 'p') {
			if (p_cnt < g_cnt) {
				p_cnt += 1;
			}
			else {
				g_cnt += 1;
				point -= 1;
			}
		}

	}
	cout << point << endl;
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
const int maxn = 101;
typedef long long ll;
typedef std::pair<int,ll> pr;
int n;
std::vector<int> to[maxn];
int mx[maxn], a[maxn], b[maxn];
inline void up(int & x,int y){ if(x < y) x = y; }
inline void dfs(int x,int f = 0,int d = 1){
	up(mx[d], to[x].size());
	for(int i : to[x]) if(i != f) dfs(i, x, d + 1);
}
int main()
{
	std::ios::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for(int i = 1;i < n;++i) std::cin >> a[i] >> b[i],to[a[i]].push_back(b[i]),to[b[i]].push_back(a[i]);
	pr ans(1e9, 1e18), o;
	for(int i = 1;i < n;++i) {
		memset(mx, 0, sizeof mx), dfs(a[i],b[i]), dfs(b[i],a[i]), o.second = 2;
		for(int&i = o.first = 1;mx[i];++i) o.second *= std::max(mx[i] - 1,1);
		ans = std::min(ans, o);
	}
	for(int i = 1;i <= n;++i) {
		memset(mx, 0, sizeof mx), dfs(i), o.second = mx[1];
		for(int&i = o.first = 2;mx[i];++i) o.second *= std::max(mx[i] - 1,1);
		ans = std::min(ans, o);
	}
	std::cout << ans.first - 1 << ' ' << ans.second << '\n';
}


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

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

using std::min;
using std::max;
using std::swap;

using std::string;

using std::vector;


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

    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }

    int cnt = 0;
    bool update = true;
    while(update){
        update = false;
        for(int i = 0; i < n-1; i++){
            if(p[i] == i){
                swap(p[i], p[i+1]);
                cnt++;
                update = true;
            }
        }
        for(int i = n-1; i > 0; i--){
            if(p[i] == i){
                swap(p[i], p[i-1]);
                cnt++;
                update = true;
            }
        }
    }

    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;







int main() {

    ld a,b;
    cin>>a>>b;
    fin(ll(a*b));

}




Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define int long long 
using namespace std;

int32_t main(){

    string s;   cin >> s;
    int k;  cin >> k;
    int n = s.size();
    vector<string> f;

    for(int x=0;x<n;x++){
        for(int j = 1; j <= 5; j++){
            if(x + j <= n){
                string tmp = s.substr(x,j);
                f.push_back(tmp);
            }
        }
    }

    sort(all(f));
    unique(all(f));

    cout << f[k-1] << endl;

    return 0;
}

Measured memory_bytes: 1660
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(n+1)]

for i in a:
  l[i]+=1
cmb1=[0 for i in range(n+1)]
cmb2=[0 for i in range(n+1)]

for i in range(1,n+1):
  cmb1[i]=(l[i]*(l[i]-1))//2
  cmb2[i]=((l[i]-1)*(l[i]-2))//2

kei1=0
for i in range(1,n+1):
  kei1+=cmb1[i]

for i in range(1,n+1):
  print(kei1-cmb1[a[i-1]]+cmb2[a[i-1]])


Measured memory_bytes: 26140
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

BSUM = sum([i[1] for i in AB])

AplsB = [i + j for i, j in AB]

AplsB.sort(reverse=True)

ans = 0
for i, v in enumerate(AplsB):
  if i % 2 == 0:
    ans += v

print(ans - BSUM)

Measured memory_bytes: 31948
import sys
a,v = map(int, sys.stdin.readline().rstrip("\n").split())
b,w = map(int, sys.stdin.readline().rstrip("\n").split())
t = int(sys.stdin.readline().rstrip("\n"))
between = abs(b - a)
speed = v-w
if between <= speed*t:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9180
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

int solve()
{
    string s;
    cin >> s;

    cout << string(s.length(), 'x') << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


int main()
{
    vector<ll> a;
    for (ll i = 0; i < 3; i++)
    {
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(all(a));

    println(a[0] + a[1]);
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

struct UnionFind {
    vector<int> par;

    void init(int n) {
        for (int i = 0; i < n; i++) {
            par.push_back(i);
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    // source
    UnionFind uni;

    int n, m;
    cin >> n >> m;
    int x[m], y[m];
    int z[m];
    uni.init(n);
    rep(i, m) { cin >> x[i] >> y[i] >> z[i]; }

    rep(i, m) { uni.unite(x[i], y[i]); }

    int ans = 0;
    rep(i, n + 1) {
        if (uni.root(i) == i) {
            ans++;
        }
    }

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

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


Measured memory_bytes: 2424
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
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 d = sc.nextInt();
        System.out.println(Math.min(a , b) + Math.min(c , d));
    }
}

Measured memory_bytes: 35748
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int A, B, C;
  std::cin >> A >> B >> C;
  int X, Y; std::cin >> X >> Y;
  X *= 2;
  Y *= 2;
  int Z = std::max(X,Y);

  lint inf = std::numeric_limits<lint>::max();
  lint ans = inf;
  rep(c,0,Z+1) {
    lint x = (std::max(0ll, X - c) + 1) / 2 * A;
    lint y = (std::max(0ll, Y - c) + 1) / 2 * B;
    lint z = c * C;
    lint now = x + y + z;
    debug(c,x,y,z,now);
    cmn(ans,now);
  }
  std::cout << ans << std::endl;
  return 0;
}

/*
AB ピザの枚数を全探索です。
*/

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

typedef long long ll;
typedef unsigned long long ull;

// 最大公約数
ll gcd(ll a, ll b)
{
    if (a < 0)
        a = -a;
    if (b < 0)
        b = -b;
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

int main()
{
    ull x;
    cin >> x;
    double r = 1.01;
    ull cu = 100;
    for (ull i = 1; i < 1000000000000000000; i++)
    {
        cu *= r;
        if (cu >= x)
        {
            cout << i << endl;
          	return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
from collections import deque


def bfs(n, adj, source):
	dist = [-1] * n
	dist[source] = 0
	q = deque([source])
	mx = 0
	idx = 0
	while q:
		cur = q.popleft()
		for nxt, d in adj[cur]:
			if dist[nxt] < 0:
				dist[nxt] = dist[cur] + d
				if dist[nxt] > mx:
					mx = dist[nxt]
					idx = nxt
				q.append(nxt)
	return idx, mx


def main():
	n, *L = map(int, open(0).read().split())
	adj = [[] for _ in range(n)]
	for a, b, c in zip(*[iter(L)] * 3):
		adj[a].append((b, c))
		adj[b].append((a, c))
	idx1, _, = bfs(n, adj, 0)
	_, ans, = bfs(n, adj, idx1)
	print(ans)


if __name__ == '__main__':
	main()



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

using namespace std;
typedef long long ll;

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

  vector<ll> p(w), q(h + 1, 0);
  ll ans = 0;
  for (int i = 0; i < w; i++) {
    cin >> p[i];
    ans += p[i];
  }
  for (int i = 0; i < h; i++) {
    cin >> q[i];
    ans += q[i];
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());

  vector<ll> cump = p, cumq = q;
  for (int i = 1; i < w; i++) {
    cump[i] += cump[i - 1];
  }
  for (int i = 1; i <= h; i++) {
    cumq[i] += cumq[i - 1];
  }
  q[0] = -1;

  for (int i = 0; i < w; i++) {
    ll r = lower_bound(q.begin(), q.end(), p[i]) - q.begin() - 1;
    ans += p[i] * (h - r);
    if (!r) continue;
    ans += cumq[r];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string ss;
  cin>>n>>ss;
  int a=ss.size();
  int s[30000];
  rep(i,a)s[i]=ss[i]-'0';
  int tot=0;
  for(int i=0;i<1000;i++){
    int p[3];
    p[0]=i/100;
    p[1]=(i-p[0]*100)/10;
    p[2]=i%10;
    int tmp=-1;
    int k=0;
    for(int j=0;j<3;j++){
      for(int i=tmp+1;i<a;i++){
        if(s[i]==p[j]){
          tmp=i;
          k++;
          break;
        }
      }
      if(k!=j)continue;
    }
    if(k==3)tot++;
  }
  cout<<tot<<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N; cin >> N;
	map<int,bool> mp;
	int cnt = 0;

	for (int i = 0;i < N;i++){
		int A; cin >> A;
		if(mp[A]){ mp[A] = false; cnt--;}
		else {mp[A] = true; cnt++;}
	}

	cout << cnt << endl;

	return 0;

}


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

int main() {

    int n, m;
    cin >> n >> m;
    if(m / n == 1) {
    cout << "Yes" << endl;
    } else {
    cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
        "sort"
)

func main() {
        var n, x int
        fmt.Scan(&n, &x)
        as := make([]int, n)
        for i := range as {
                fmt.Scan(&as[i])
        }
        sort.Sort(sort.IntSlice(as))
        var distributed, i int
        for true {
                if i == len(as) {
                        i--
                        break
                }
                if distributed+as[i] > x {
                        break
                }
                distributed += as[i]
                i++
                if distributed == x {
                        break
                }
        }
        fmt.Printf("%d\n", i)
}

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

const int N = 2e5 + 5 ;

int n , m , t[ N ][ 64 ] ;

signed main() {
	cin >> n >> m ;
	for( int i = 1 ; i <= n ; ++i )
		cin >> t[ i ][ 0 ] ;
	for( int j = 1 ; j <= 63 ; ++j )
		for( int i = 1 ; i <= n ; ++i ) 
			t[ i ][ j ] = t[ t[ i ][ j - 1 ] ][ j - 1 ] ;
	int ans = 1;
	for( int i = 63 ; ~i ; --i ) {
		if( m & (1ll << i) )
			ans = t[ans][i];
	}
	cout << ans << '\n';
	return 0 ;
}

Measured memory_bytes: 103636
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

#define mid ((l+r)>>1)
const int N=1e4+9;
const int Inf=1e9+7;

struct node
{
	int x,y;
}p[N];

struct pts
{
	int x,id;
	bool operator < (pts o)const
	{
		return x<o.x;
	}
}pt[N<<1];

int n,ans=0;
vector<int> g[N<<3];
int low[N<<1],pre[N<<1],scc[N<<1],scccnt,dfn;
int rp[N<<1],stk[N<<1],top,ptop;

inline void chkmin(int &a,int b){if(a>b)a=b;}
inline void chkmax(int &a,int b){if(a<b)a=b;}

inline void add(int u,int v)
{
	g[u].push_back(v);
}

inline void dfs(int u)
{
	low[u]=pre[u]=++dfn;
	stk[++top]=u;
	for(int i=0,e=g[u].size(),v;i<e;i++)
		if(!low[(v=g[u][i])])
		{
			dfs(v);
			chkmin(low[u],low[v]);
		}
		else if(!scc[v])
			chkmin(low[u],pre[v]);
	if(low[u]==pre[u])
	{
		scccnt++;
		do
			scc[stk[top]]=scccnt;
		while(stk[top--]!=u);
	}
}	

inline void build(int x,int l,int r)
{
	if(l==r)
		return;
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	add((x<<1)+ptop,x+ptop);
	add((x<<1|1)+ptop,x+ptop);
}

inline void adds(int x,int l,int r,int dl,int dr,int id)
{
	if(dl==l && r==dr)
	{
		add(id,x+ptop);
		return;
	}
	if(dr<=mid)
		adds(x<<1,l,mid,dl,dr,id);
	else if(mid<dl)
		adds(x<<1|1,mid+1,r,dl,dr,id);
	else
	{
		adds(x<<1,l,mid,dl,mid,id);
		adds(x<<1|1,mid+1,r,mid+1,dr,id);
	}
}

inline bool judge(int k)
{
	dfn=scccnt=0;
	for(int i=0;i<ptop;i++)
		g[i].clear();
	memset(low,0,sizeof(low));
	memset(scc,0,sizeof(scc));

	//build(1,1,ptop);
	//for(int i=0;i<ptop;i++)
	//	adds(1,1,ptop,pt[i].x-k,pt[i].x,pt[i].id);

	
	for(int i=0;i<ptop;i++)
	{
		for(int j=i-1,cnt=1;~j && pt[j].x+k>pt[i].x && cnt<=12;j--,cnt++)
		{
			add(pt[i].id,pt[j].id^1);
			add(pt[j].id,pt[i].id^1);
		}
	}
	

	for(int i=0;i<ptop;i++)
		if(!low[i])
			dfs(i);
	for(int i=0;i<n;i++)
		if(scc[i<<1]==scc[i<<1|1])
			return false;
	return true;
}

int main()
{
	n=read();
	int l=0,r=0,mids,ans=0;
	for(int i=0;i<n;i++)
	{
		p[i].x=read();
		p[i].y=read();
		if(p[i].x>p[i].y)swap(p[i].x,p[i].y);
		chkmax(r,p[i].y);
		pt[i<<1].x=p[i].x;pt[i<<1].id=i<<1;
		pt[i<<1|1].x=p[i].y;pt[i<<1|1].id=i<<1|1;
	}
	ptop=n*2;
	sort(pt,pt+ptop);
	while(l<=r)
	{
		mids=l+r>>1;
		if(judge(mids))
			ans=mids,l=mids+1;
		else
			r=mids-1;
	}

	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6272
import sys
import numpy as np
input = sys.stdin.readline

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))
c = np.cumsum(p)

ans = c[K-1]

for i in range(N - K):
    tmp = c[i+K] - c[i]
    ans = max(ans, tmp)

print((ans + K) / 2)


Measured memory_bytes: 34048
// #include C {
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<cmath>
// }

// #include C++ {
#include<functional>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<map>
#include<set>
// }

using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 100005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
//  WF("output.txt");
	DF("err.txt");

	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	printf("%d\n", A^B^C);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> sumr(n + 1);
	vector<int> sumg(n + 1);
	vector<int> sumb(n + 1);
	rep(i, n) {
		if (s[i] == 'R') sumr[i]++;
		if (s[i] == 'G') sumg[i]++;
		if (s[i] == 'B') sumb[i]++;
		sumr[i + 1] += sumr[i];
		sumg[i + 1] += sumg[i];
		sumb[i + 1] += sumb[i];
	}
	ll ans = 0;
	rep(i, n - 1) {
		for (int j = i + 1; j < n; ++j) {
			if (s[i] == 'R' && s[j] == 'G') {
				int tmp = sumb[n] - sumb[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'B') ans--;
			}
			if (s[i] == 'G' && s[j] == 'R') {
				int tmp = sumb[n] - sumb[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'B') ans--;
			}
			if (s[i] == 'R' && s[j] == 'B') {
				int tmp = sumg[n] - sumg[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'G') ans--;
			}
			if (s[i] == 'B' && s[j] == 'R') {
				int tmp = sumg[n] - sumg[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'G') ans--;
			}
			if (s[i] == 'G' && s[j] == 'B') {
				int tmp = sumr[n] - sumr[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'R') ans--;
			}
			if (s[i] == 'B' && s[j] == 'G') {
				int tmp = sumr[n] - sumr[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'R') ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3692
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let k:usize = read!();
    let n:usize = read!();
    let mut a:usize = read!();
    let mut b:usize = 0;
    let mut c:usize = a;
    for i in 1..n-1 {
        let mut x:usize = read!();
        if b < x-a {
            b=x-a;
        }
        a = x;
    }
    let mut zz:usize = read!();
    if b < zz-a {
        b=zz-a;
    }
    if b<k-zz+c {
        b=k-zz+c;
    }
    println!("{}",k-b);
}

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

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; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    vector<ll> A(2),B(2);
    cin>>A[0]>>A[1]>>B[0]>>B[1];
    vector<ll> res;
    rep(i,2){
        rep(j,2){
            res.push_back(A[i]*B[j]);
        }
    }
    sort(res.rbegin(),res.rend());
    cout<<res[0]<<endl;
}


Measured memory_bytes: 3628
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &x : a) {
        cin >> x;
    }
    map<int, int> cnt;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += cnt[a[i] - i];
        ++cnt[-a[i] - i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 27412
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <set>

#include <stdio.h>
#include <string.h>

using namespace std;


typedef long long ll;

int par[100000];
int ran[100000];
int n;

void init(int k) {
	for (int i = 0; i < k; i++) {
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y]) ran[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int main(int argc, char* argv[])
{
	int n; cin >> n;
	init(n);
	vector< pair<int, int> > vx, vy;
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		vx.push_back(pair<int, int>(x, i));
		vy.push_back(pair<int, int>(y, i));
	}
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	vector< pair<int, pair<int, int> > > v;
	for (int i = 0; i < n - 1; i++) {
		pair< int, pair<int, int> > p;
		p.first = vx[i + 1].first - vx[i].first;
		p.second = pair<int, int>(vx[i + 1].second, vx[i].second);
		v.push_back(p);
		p.first = vy[i + 1].first - vy[i].first;
		p.second = pair<int, int>(vy[i + 1].second, vy[i].second);
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < v.size(); i++) {
		if (!same(v[i].second.first, v[i].second.second)) {
			unite(v[i].second.first, v[i].second.second);
			ans += v[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
  int n, m;
  vector<string> id;
  bool close = true;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    id.push_back(s);
  }

  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    if (find(id.begin(), id.end(), s) != id.end()) {
      if (close) {
        cout << "Opened by " << s << endl;
        close = false;
      } else {
        cout << "Closed by " << s << endl;
        close = true;
      }
    } else {
      cout << "Unknown " << s << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;

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

        int n = inScanner.nextInt();

        for (int i = 0; i < n; i++) {
            int y = inScanner.nextInt();
            int m = inScanner.nextInt();
            int d = inScanner.nextInt();

            int ans = 0;
            while(true) {
                if (y == 1000) {
                    break;
                }

                ans++;

                // day
                d++;
                if (d == 20 && m%2 == 0 && y%3 != 0) {
                    d = 1;
                    m++;
                }
                else if (d == 21) {
                    d = 1;
                    m++;
                }

                // month
                if (m == 11) {
                    m = 1;
                    y++;
                }
            }

            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 27364
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
	int s[200010], i, j,n;
	long long int step=0, num = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &s[i]);
		if (step < s[i])
		{
			step = s[i];
		}
		else
		{
			num += (step - s[i]);
		}
	}
	printf("%lld", num);
	return 0;
}

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

int32_t main() {
  int n, k;
  cin >> n >> k;
  k = min(k, n);
  vector<int> h(n);
  for(int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  cout << accumulate(h.begin(), h.begin() + n - k, 0ll) << '\n';
}

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

using namespace std;

map <int64_t, int64_t> m1;
int64_t res = 0;




int main(){
    int n; cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++) cin >> arr[i];
    int sum  = 0;
    for(int i = 0; i < n; i++) sum += arr[i];   
    if(sum%n > n/2) sum = sum/n+1;
    else sum = sum/n;
    int res = 0;
    for(int i = 0; i < n; i++) res += (sum-arr[i])*(sum-arr[i]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
string S;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>S;
	ll c=0;
	for(auto ch:S){
		if(ch=='o'){
			c++;
		}
	}
	cout<<(c+(15-S.length())>=8 ? "YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int answer=0;
bool dfs(int origin, int number, int N){
    if(N<number*origin){
        false;
    }else{
        answer = max(answer,number*origin);
        if(origin != 1) dfs(origin,number*origin,N);
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    for(int i=1; i<33; i++){
        dfs(i,i,N);
    }
    cout << answer <<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int ans = 0;
        if (S.equals("SUN")) {
            ans = 7;
        } else if (S.equals("MON")) {
            ans = 6;
        } else if (S.equals("TUE")) {
            ans = 5;
        } else if (S.equals("WED")) {
            ans = 4;
        } else if (S.equals("THU")) {
            ans = 3;
        } else if (S.equals("FRI")) {
            ans = 2;
        } else if (S.equals("SAT")) {
            ans = 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#coding: utf-8

r, c = map(int, input().split())
mtx = list()
sor = [0 for i in range(c + 1)]
for i in range(r):
    temp = list(map(int, input().split()))
    temp.append(sum(temp))
    for j in range(c + 1):
        sor[j] += temp[j]
    mtx.append(temp)
mtx.append(sor)
for i in range(r + 1):
    for j in range(c + 1):
        mtx[i][j] = str(mtx[i][j])
    print(' '.join(mtx[i]))


Measured memory_bytes: 6116
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,d;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 256
import math

def isinteger(n):
    if isinstance(n, int):
        return True
    elif isinstance(n,float):
        return n.is_integer()
    return False

n = int(input())
A = list(map(int,input().split()))
for i in range(1,n+1):
    A[i-1] = A[i-1]-i
A.sort()
if n % 2 == 1:
    b = A[(n-1)//2]
else:
    b = (A[n//2]+A[n//2]-1)/2
if isinteger(b):
    ans = 0
    for i in A:
        ans += abs(i-b)
    print(ans)
else:
    ans1=0
    ans2=0
    b1= math.floor(b)
    b2=b1+1
    for i in A:
        ans1 += abs(i-b1)
        ans2 += abs(i-b2)
    print(min(ans1,ans2))

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

int main(){
    int K;
    cin >> K;
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[K-1] << endl;
    return 0;
}

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

#define REP(i, a, b)  for(int i = a, _b = b; i < _b; ++i)
#define FOR(i, a, b)  for(int i = a, _b = b; i <= b; ++i)
#define FORD(i, a, b) for(int i = a, _b = b; i >= b; --i)

#define endl "\n"
#define newline	cout << "\n"
#define puts(x)	cout << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef long long llong;


const int MN = 2e5+5;

#define two(x)	(1 << (x))
#define pc(x)	__builtin_popcount(x)

int h[MN], dp[two(26) + 10];
string s;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef Home
   freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	cin >> s;
	int n = s.length();

	h[0] = two(s[0] - 'a');
	REP(i, 1, n) {
		h[i] = h[i-1]^(two(s[i] - 'a'));
	}
	
	memset(dp, 0x3F, sizeof dp); 
	REP(i, 0, n) {
		if(pc(h[i]) <= 1) dp[h[i]] = 1;
		else {
			REP(j, 0, 26) {
				dp[h[i]] = min(dp[h[i]], dp[h[i]^two(j)]+1);
			}
		}
	}
	puts(dp[h[n-1]]);	
   return 0;
}

Measured memory_bytes: 263572
N = int(input())
X = []
max_ = -1

for i in input().split(" "):
    tmp = int(i)
    if tmp > max_:
        max_ = tmp
    X.append(tmp)

ans = 1e9
for i in range(100):
    tmp = 0
    for j in X:
        tmp += ((j - i) ** 2)
    if ans > tmp:
        ans = tmp

print(ans)

Measured memory_bytes: 3064
/*
mdzz不好好读题目还想做题，。。
题目中说“联通块内的任意点都只有一条路径可达”，不难推断出这是一棵树
因此 联通块个数 = 蓝点的数量 - 蓝点间边的数量
考虑用前缀和维护，点的数量好处理，但是这个边的数量有点麻烦
反正我用一个数组是搞不出来，因为无法判断左右的方向。。
那就行列分别记录一下就可以了。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#define LL long long 
using namespace std;
const int MAXN = 2001;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, M, Q;
char s[MAXN][MAXN];
int P[MAXN][MAXN], R[MAXN][MAXN], L[MAXN][MAXN];
int GetP(int x, int y) {
	if(x == 0 || y == 0) return 0;
	return P[x - 1][y] + P[x][y - 1] - P[x - 1][y - 1];
}
int GetR(int x, int y) {
	if(x == 0 || y == 0) return 0;
	return R[x - 1][y] + R[x][y - 1] - R[x - 1][y - 1];
}
int GetL(int x, int y) {
	if(x == 0 || y == 0) return 0;
	return L[x - 1][y] + L[x][y - 1] - L[x - 1][y - 1];
}
main() {
	N = read(); M = read(); Q = read();
	for(int i = 1; i <= N; i++) {
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= M; j++) {
			P[i][j] = GetP(i, j);
			R[i][j] = GetR(i, j);
			L[i][j] = GetL(i, j);
			if(s[i][j] == '1') L[i][j] += (s[i - 1][j] == '1'),
							   R[i][j] += (s[i][j - 1] == '1'), 
							   P[i][j]++;
		}
	}
	/*for(int i = 1; i <= N; i++, puts(""))
		for(int j = 1; j <= M; j++)
			printf("%d ", L[i][j]);*/
	while(Q--) {
		int x1 = read(), y1 = read(), x2 = read(), y2 = read();
		// printf("%d %d %d %d\n", GetP(x2, y2), GetP(x1 - 1, y2), GetP(x2, y1 - 1), GetP(x1 - 1, y1 - 1));
		int ans1 = P[x2][y2] - P[x1 - 1][y2] - P[x2][y1 - 1] + P[x1 - 1][y1 - 1];
		int ans2 = R[x2][y2] - R[x1 - 1][y2] - R[x2][y1] + R[x1 - 1][y1];
		int ans3 = L[x2][y2] - L[x2][y1 - 1] - L[x1][y2] + L[x1][y1 - 1];
		cout << ans1 - ans2 - ans3 << endl;
	}
    return 0;
}
/*
*/


Measured memory_bytes: 52608