akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  if (N >= 1000) cout << "ABD" << endl;
  else cout << "ABC" << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

int a[105];
int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int j;
        cin >> j;
        a[j]++;
        if(a[j] == 1)
            ans++;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
import sys


def preorder(u):
    PRE.append(u)
    if TREE[u][1] != NIL:
        preorder(TREE[u][1])
    if TREE[u][2] != NIL:
        preorder(TREE[u][2])
        
        
def inorder(u):
    if TREE[u][1] != NIL:
        inorder(TREE[u][1])
    IN.append(u)
    if TREE[u][2] != NIL:
        inorder(TREE[u][2])


def postorder(u):
    if TREE[u][1] != NIL:
        postorder(TREE[u][1])
    if TREE[u][2] != NIL:
        postorder(TREE[u][2])
    POST.append(u)
        
        
if __name__=="__main__":
    NIL = -1
    n = int(sys.stdin.readline())
    TREE = [[NIL, NIL, NIL] for i in range(n)]
    root = set(range(n))
    PRE = []
    IN = []
    POST = []
    for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        if inp[1] != NIL:
            TREE[inp[0]][1] = inp[1]
            TREE[inp[1]][0] = inp[1]
        if inp[2] != NIL:
            TREE[inp[0]][2] = inp[2]
            TREE[inp[2]][0] = inp[2]
        root -= set([inp[1], inp[2]])
    a = root.pop()
    preorder(a)
    inorder(a)
    postorder(a)
    print("Preorder")
    print(" " + " ".join(map(str, PRE)))
    print("Inorder")
    print(" " + " ".join(map(str, IN)))
    print("Postorder")
    print(" " + " ".join(map(str, POST)))

Measured memory_bytes: 7800
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,d;
    cin>>n>>d;
    d=2*d+1;
    cout<<ll(ceil(1.0*n/d));
}


Measured memory_bytes: 256
// AOJ ALDS1_12_A Minimum Spanning Tree
// 2018.5.2 bal4u

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

#define MAX_V 105

/* UNION-FIND library */
int id[MAX_V], size[MAX_V];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q)
{
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

typedef struct { int s, t, w; } EDGE;
EDGE edge[5100];

int cmp(EDGE *a, EDGE *b) { return a->w - b->w; }

int kruskal(int V, int E)
{
	int ans;
	EDGE *ep;

	qsort(edge, E, sizeof(EDGE), cmp);
	init(V); 
	ans = 0;
	ep = edge; while (E--) {
		if (!connected(ep->s, ep->t)) { 
			unite(ep->s, ep->t);
			ans += ep->w;
		}
		ep++;
	}
	return ans;
}

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	while (c <= ' ') c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int main()
{
	int n, a, i, j;
	EDGE *ep;

	n = in();
	ep = edge;
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
		a = in();
		if (j > i && a >= 0) {
			ep->s = i, ep->t = j, ep->w = a;
			ep++;
		}
	}
	printf("%d\n", kruskal(n, ep-edge));
	return 0;
}



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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;
const ll com_max = 510000;

ll fac[com_max], inv[com_max], finv[com_max];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (ll i = 2; i < com_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;
    }
}

ll com(ll n, ll k) {
    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

ll permu(ll n, ll k) {
    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }
    return fac[n] * finv[n - k] % mod;
}

int main() {
    ll n, m;
    cin >> n >> m;
    com_init();
    ll all = permu(m, n);
    repd(x, 1, n + 1) {
        ll temp = com(n, x) * permu(m - x, n - x) % mod;
        if (x % 2 == 1) {
            all -= temp;
            all += mod;
            all %= mod;
        } else {
            all += temp;
            all %= mod;
        }
    }
    all *= permu(m, n);
    all %= mod;
    cout << all << endl;
    return 0;
}



Measured memory_bytes: 15512
N,A,B=map(int,input().split())
H=[int(input()) for _ in [0]*N]
l,r=0,10**10
while l+1 < r:
    k=(l+r)//2
    if sum([max(0,(h-B*k-1)//(A-B)+1) for h in H]) > k:l=k
    else:r=k
print(r)

Measured memory_bytes: 10932
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, a[114514], ans;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i <= 100000; i++) {
		int ko = lower_bound(a, a + n, i) - a;
		if (ko == n / 2)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int l, r, d;

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

	cin >> l >> r >> d;
	int ans = 0;
	for(int i = l; i<=r; i++)
		if(i%d == 0) ans++;

	cout << ans << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n;
vector<lli> a;

int error(){
    cout << 0 << endl;
    return 0;
}
lli lli_pow(lli a,lli n,lli mod){
	lli ret = 1;
	for(;n!=0;n=n>>1){
		if(n&1) ret = (ret * a) % mod;
		a = (a * a) % mod;
	}
	return ret;
}
int main(int argc, char const *argv[]) {
    cin >> n;
    a = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    if(n%2 == 0){
        for(lli i = 1,j = 0;j < n;i+=2){
            if(a[j++] != i) return error();
            if(a[j++] != i) return error();
        }
    }else{
        if(a[0] != 0) return error();
        for(lli i = 2,j = 1;j < n;i += 2){
            if(a[j++] != i) return error();
            if(a[j++] != i) return error();
        }
    }
    cout << lli_pow(2,n/2,1000000007) << endl;
    return 0;
}


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

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
  int n1 = mid-left;
  int n2 = right-mid;
  for ( int i = 0; i < n1; i++ ) L[i] = A[left+i];
  for ( int i = 0; i < n2; i++ ) R[i] = A[mid+i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for ( int k = left; k < right; k++ ) {
    cnt++;
    if ( L[i] <= R[j] ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];      
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  if ( left+1 < right ) {
    int mid = (left+right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> A[i];

  mergeSort(A, n, 0, n);

  for ( int i = 0; i < n; i++ ) {
    if ( i ) cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;
  
  return 0;
}



Measured memory_bytes: 6944
N, K = map(int, input().split())
S = input()

happy = 0
for i in range(1,N):
    if S[i] == S[i-1]:
        happy += 1

turn = N - happy - 1

for i in range(K):
    if turn <= 0:
        break
    elif turn == 1:
        happy += 1
        turn -= 1
    else:
        happy += 2
        turn -= 2

print(happy)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define INFTY (1<<30)

int n;
vector<vector<int>> M(101,vector<int>(101,0));
vector<int> color(101,0),d(101,INFTY);
queue<int> Q;

void bfs(){
    color[1]=1;
    d[1]=0;
    Q.push(1);
    while(!Q.empty()){
        int u=Q.front();
        Q.pop();
        for(int v=1;v<n+1;v++){
            if(M[u][v]&&color[v]==0){
                color[v]=1;
                d[v]=d[u]+1;
                Q.push(v);
            }
        }
        color[u]=2;
    }
}


int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,k;
        cin>>a>>k;
        for(int j=0;j<k;j++){
            cin>>b;
            M[a][b]=1;
        }
    }

    bfs();

    for(int i=1;i<n+1;i++){
        cout<<i<<' ';
        if(d[i]==INFTY) cout<<-1<<endl;
        else cout<<d[i]<<endl;
    }
}


Measured memory_bytes: 3196
s = input()

cnt=0
if s[0]!="C":
    cnt+=1
if s[1] != "O":
    cnt += 1
if s[2] != "D":
    cnt += 1
if s[3] != "E":
    cnt += 1
if s[4]!="F":
    cnt+=1
if s[5]!="E":
    cnt+=1
if s[6]!="S":
    cnt+=1
if s[7]!="T":
    cnt+=1
if s[8]!="I":
    cnt+=1
if s[9]!="V":
    cnt+=1
if s[10] != "A":
    cnt += 1
if s[11] != "L":
    cnt += 1
if s[12] != "2":
    cnt += 1
if s[13] != "0":
    cnt += 1
if s[14] != "1":
    cnt += 1
if s[15] != "6":
    cnt += 1

print(cnt)


Measured memory_bytes: 3064
//DSL_1A
#include <iostream>
#include <vector>
using namespace std;
 
class DisjointSet{
 public:
  vector<int> rank,p;
  
  DisjointSet(){}
  
  DisjointSet(int size){
   rank.resize(size,0);
   p.resize(size,0);
   for(int i=0;i<size;i++) makeSet(i);
  }

  void makeSet(int x){
   p[x]=x;
   rank[x]=0;
  }

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

  void unite(int x,int y){
   link(findSet(x),findSet(y));
  }

  void link(int x,int y){
   if(rank[x]>rank[y]){
    p[y]=x;
   }else{
    p[x]=y;
    if(rank[x]==rank[y]){
     rank[y]++;
    }
   }
  }


  int findSet(int x){
   if(x!=p[x]){
    p[x]=findSet(p[x]);
   }
   return p[x];
  }
};

int main(){
 int n,a,b,q;
 int t;
 cin>>n>>q;
 DisjointSet ds=DisjointSet(n);
 for(int i=0;i<q;i++){
  cin>>t>>a>>b;
  if(t==0) ds.unite(a,b);
  else if(t==1){
   if(ds.same(a,b)) cout<<1<<endl;
   else cout<<0<<endl;
  }
 }
 return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
	int n,m;
	char tmp;
	while (cin >> n) {
		if (n == 0) break;
		pair<char, char> key[n];
		for (int i=0; i<n; i++) {
			cin >> key[i].first >> key[i].second;
		}
		cin >> m;
		string ans = "";
		for (int i=0; i<m; i++) {
			cin >> tmp;
			for (int j=0; j<n; j++) {
				if (tmp == key[j].first) {
					tmp = key[j].second;
					break;
				}
			}
			ans += tmp;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long V, long long B, long long W, long long T){
    if(W>=V){
        cout<< NO << endl;
        return;
    }
    ll distance = abs(A-B);
    ll t = (distance + V-W-1)/(V-W);
    if(t <=T){
        cout <<YES << endl;
        return;
    } 
    cout << NO << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long V;
    scanf("%lld",&V);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    long long T;
    scanf("%lld",&T);
    solve(A, V, B, W, T);
    return 0;
}


Measured memory_bytes: 3768
#include "iostream"
#include "algorithm"

using namespace std;

int main(){
    int n, c; cin>>n>>c;
    int a[n]; 
    for(auto &i: a) cin>>i;

    sort(a, a+n);

    int cost = 0;
    for(int i=0; i<c; i++){
        cost += a[i];
    }
    cout<<cost<<"\n";
}

Measured memory_bytes: 3604
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (std::decay_t<decltype(k)> i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    char c; std::cin >> c;
    std::cout << (std::islower(c) ? 'a' : 'A') << '\n';
}


Measured memory_bytes: 3660
S = input()
N = len(S)
a = 0
ans = 0
f = 0
for i in range(N-1):
    if S[i] == 'A':
        a += 1
    elif S[i] == 'B':
        if S[i+1] == 'C':
            ans += a
            f = 1
        else:
            a = 0
    else:
        if f != 1:
            a = 0
        else:
            f = 0
print(ans)

Measured memory_bytes: 3500
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#define mem(a, b) memset(a, (b), sizeof(a))

using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int Max = 1e9 + 10;

ll dp[110];

int main(){
	int l, k;
	while(~scanf("%d%d", &l, &k)){
		mem(dp, 0);
		for(int i = 0; i <= l; i++){
			if(i == 1 || i == k) dp[i] = 1;
			if(i - 2 >= 0) dp[i] += dp[i - 2];
			if(i - k -  1 >= 0) dp[i] += dp[i - k - 1];
		}
		ll sum = 0;
		for(int i = 0; i <= l; i++)
			sum += dp[i];
		printf("%lld\n", sum);
	}
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
  return 0;
}

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

const long long mod = 1000000007;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m;
	cin >> n >> m;
	vector < int > a(n), b(m);
	for (int i = 0; i < n; ++i) 
		cin >> a[i];
	for (int i = 0; i < m; ++i)
		cin >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	bool ok = 1;
	for (int i = 1; i < n; ++i) 
		ok = ok && (a[i] != a[i - 1]);
	for (int i = 1; i < m; ++i)
		ok = ok && (b[i] != b[i - 1]);
	if (!ok)
		cout << "0\n";
	else {
		long long ans = 1;
		for (int i = n * m; i; --i) {
			int ja = lower_bound(a.begin(), a.end(), i) - a.begin();
			int jb = lower_bound(b.begin(), b.end(), i) - b.begin();
			if (ja == n || jb == m)
				ans = 0LL;
			else if (a[ja] == i && b[jb] == i)
				ans *= 1LL;
			else if (a[ja] == i)
				(ans *= ((long long) (m - jb))) %= mod;
			else if (b[jb] == i)
				(ans *= ((long long) (n - ja))) %= mod;
			else
				(ans *= (((long long) (n - ja)) * ((long long) (m - jb))) - ((long long) (n * m - i))) %= mod;
		}
		cout << ans << '\n';
	}
} 


Measured memory_bytes: 3616
function main()
	n = parse(readline())
	w = ["" for i in 1:n]
	flag = 0
	w[1] = readline()
	for i in 1:n-1
		x = split(w[i], "")
		l = length(x)
		w[i+1] = readline()
		y = split(w[i+1], "")
		for j in 1:i
			if w[j] == w[i+1]
				flag = 1
				break
			elseif x[l-1] != y[1]
				flag = 1
				break
			end
		end
	end
	if flag == 0
		print("Yes")
	else
		print("No")
	end
end


main()


Measured memory_bytes: 112884
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;
int n; long double x[100], y[100], p[100];
long double dst(long double X1, long double Y1, long double X2, long double Y2) {
	return sqrtl((X1 - X2)*(X1 - X2) + (Y1 - Y2)*(Y1 - Y2));
}
long double solve2(long double X, long double Y) {
	long double __minx = 0.0l;
	for (int i = 0; i < n; i++) {
		__minx = max(dst(X, Y, x[i], y[i]) / p[i], __minx);
	}
	return __minx;
}
long double solve(long double X) {
	long double _a = 0.0l, _b = 100.0l, _c1, _c2, _minx = 100000.0l;
	for (int i = 0; i < 160; i++) {
		_c1 = _a + 1.0l*(_b - _a) / 3.0l;
		_c2 = _a + 2.0l*(_b - _a) / 3.0l;
		long double _d1 = solve2(X, _c1);
		long double _d2 = solve2(X, _c2);
		_minx = min(_minx, min(_d1, _d2));
		if (_d1 >= _d2)_a = _c1; if (_d1 < _d2)_b = _c2;
	}
	return _minx;
}
int main() {
	while (true) {
		cin >> n; if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> x[i] >> y[i] >> p[i];
		}
		long double a = 0.0l, b = 100.0l, c1, c2, minx = 100000.0l;
		for (int i = 0; i < 160; i++) {
			c1 = a + 1.0l*(b - a) / 3.0l;
			c2 = a + 2.0l*(b - a) / 3.0l;
			long double d1 = solve(c1), d2 = solve(c2);
			if (d1 >= d2)a = c1; if (d1 < d2)b = c2;
			minx = min(minx, min(d1, d2));
		}
		cout << fixed << setprecision(20) << minx << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
/////////////////////////////////////////////////
/////             Give me AC!!!!            /////
/////////////////////////////////////////////////
//↑これじゃ気合いが足りない！
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////             お願いしますACをくださいそうじゃないと僕泣きますお願いしますACをくださいJudge様....            /////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const int MOD = 1000000007;
const int MAX = 100000;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
ld rad(ld a) {return a * 180 / PI;}
const int dx[4] = {1, 0, -1, 0};//2次元グリッド上のx軸方向
const int dy[4] = {0, 1, 0, -1};//2次元グリッド上のy軸方向

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

map<ll,ll> factorize_list;

void prime_factorize(ll N) {
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        factorize_list[a] = ex;
    }

    // 最後に残った数について
    if (N != 1) factorize_list[N] = 1;
    return ;
}

//dpTable
vector<ll> dp(100,MAX);

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

long long fac[MAX], finv[MAX], inv[MAX];

char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}

const ll INF = 10000000000;
struct edge{ll to, cost;};

int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    for (int i = A; i <= B; i++) {
        int ic = i;
        vector<int> list;
        while(ic != 0) {
            list.push_back(ic % 10);
            ic /= 10;
        }
        bool hoge = true;
        for (int i = 0; i < 5; i++) {
            if (list.at(i) != list.at(4 - i)) hoge = false;
        }
        if (hoge) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    
    
    int n;
    cin >> n;
    int i,d[n+1];
    for(i=0;i<n;++i) cin >> d[i];
    
    sort(d,d+n);
    
    int ans=0;
    
    for(i=0;i<n;++i){
        if(d[i]==d[i+1]) ans--;
        ans++;
    }
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iomanip> 
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
int main()
{
//	freopen("A.in","r",stdin);
//	freopen(".out","w",stdout);
	char s[100];
	cin>>s;
	Rep(i,4) cout<<s[i];
	cout<<' ';
	Fork(i,4,11) cout<<s[i];cout<<endl;
	 
	
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    register long i,j;
    long n;
    scanf("%ld",&n);
    register unsigned long long ans = 0;
    static int dbnc[10000000];
    dbnc[0] = 1;
    for(i = 1;i < n;i++){
        dbnc[i] += 2;
        for(j = 2;(i+1)*j <= n;j++)dbnc[(i+1)*j-1]++;
    }
    for(i = 0;i < n;i++)ans += dbnc[i] * (i+1);
    printf("%lld",ans);
}

Measured memory_bytes: 40792
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]-=i+1
a.sort()
ans=0
ans2=0
if n%2:
  for i in range(n):
    ans+=abs(a[i]-a[n//2])
  print(ans)
else:
  for i in range(n):
    ans+=abs(a[i]-a[n//2])
    ans2+=abs(a[i]-a[n//2+1])
  print(min(ans,ans2))

Measured memory_bytes: 26020
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>

using namespace std;

typedef long long ll;

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


Measured memory_bytes: 256
# cf16-finalC - Interpretation
# bipartite graph
def dfs() -> None:
    stack = [(1, 1)]
    seen_m[1] = 1
    while stack:
        v, flg = stack.pop()
        if flg:
            for u in men[v]:
                if not seen_l[u]:
                    stack.append((u, 0))
                    seen_l[u] = 1
        else:
            for u in langs[v]:
                if not seen_m[u]:
                    stack.append((u, 1))
                    seen_m[u] = 1


def main():
    global men, langs, seen_m, seen_l
    N, M = tuple(map(int, input().split()))
    A = tuple(tuple(map(int, input().split())) for _ in range(N))
    men, langs = [[] for _ in range(N + 1)], [[] for _ in range(M + 1)]
    for person, lang in enumerate(A, 1):  # construct a bipartite graph
        for l in lang[1:]:
            men[person].append(l), langs[l].append(person)
    seen_m, seen_l = [0] * (N + 1), [0] * (M + 1)
    dfs()
    flg = all(i for i in seen_m[1:])
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 44996
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX / 10000;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

struct edge { ll to, cost; };

int main()
{
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;

	vector<vector<edge> > E(n), S(n);
	rep(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		E[u].push_back({ v,a });
		S[u].push_back({ v,b });
		E[v].push_back({ u,a });
		S[v].push_back({ u,b });
	}
	Vl distE(n, LINF);
	Vl distS(n, LINF);
	
	//スタートからダイクストラ
	rep(i, n) distE[s] = 0;  //スタート地点
	priority_queue<Pl, vector<Pl>, greater<Pl> > Q1;
	Q1.push({ 0,s });
	while (!Q1.empty()) {
		Pl P = Q1.top();
		Q1.pop();
		ll v = P.second; //頂点番号
		if (distE[v] < P.first)  continue;
		for (int j = 0; j < E[v].size(); j++) {
			edge e = E[v][j];
			if (distE[e.to] > distE[v] + e.cost) {
				distE[e.to] = distE[v] + e.cost;
				Q1.push({ distE[e.to],e.to });
			}
		}
	}
	
	//ゴールからダイクストラ
	rep(i, n) distS[t] = 0;  //スタート地点
	priority_queue<Pl, vector<Pl>, greater<Pl> > Q2;
	Q2.push({ 0,t });
	while (!Q2.empty()) {
		Pl P = Q2.top();
		Q2.pop();
		ll v = P.second; //頂点番号
		if (distS[v] < P.first)  continue;
		for (int j = 0; j < S[v].size(); j++) {
			edge e = S[v][j];
			if (distS[e.to] > distS[v] + e.cost) {
				distS[e.to] = distS[v] + e.cost;
				Q2.push({ distS[e.to],e.to });
			}
		}
	}

	vector<Pl> dist(n);
	rep(i, n) dist[i] = { distE[i] + distS[i],i + 1 };
	sort(dist.begin(), dist.end());

	ll X = 1e15;
	int ansnum = 0;
	rep(i, n) {
		while(dist[ansnum].second <= i) {
			ansnum++;
		}
		cout << X - dist[ansnum].first << endl;
	}
}


Measured memory_bytes: 22516
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

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

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef pair<long long, long long>pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 100050;
const double pi = acos(-1); constexpr double EPS = 1e-12;
constexpr ll INF = 1e16;
void yes(bool c) { if (c)print("Yes"); else print("No"); };

int C[110];
int A[101][101];
void solve() {
	int N, M; cin >> N >> M;
	int X; cin >> X;
	REP(i, N) {
		cin >> C[i];
		REP(j, M) {
			cin >> A[i][j];
		}
	}
	int ans = 1e9;
	REP(bit, 1 << N) {
		vector<int>x(M);
		int res = 0;
		REP(i, N) {
			if (bit&(1 << i)) {
				res += C[i];
				REP(j, M) {
					x[j] += A[i][j];
				}
			}
		}
		bool ok = true;
		REP(j, M) {
			if (x[j] < X)ok = false;
		}
		if (ok)chmin(ans, res);
	}
	if (ans >= 1e9)print(-1);
	else print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

int main (void){
    int N;
    cin >> N;
    int a = N % 10;
    if(a == 3) cout << "bon" <<endl;
    else if(a ==0 || a == 1 || a== 6 || a== 8){
        cout << "pon" << endl;
    }
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3628
/// Code by Leonardo16
///   “It is not the strength of the body, but the strength of the spirit.”   —  J.R.R. Tolkien
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
/// Macros
#define int long long
#define ll long long
#define sz size
#define ull unsigned long long
#define ld long double
#define ii pair<int,int>
#define fst first
#define scd second
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
#define pf push_front
#define fl '\n'
#define el endl
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
/// Functions
#define db(x) cerr << #x << ": " << (x) << '\n';
#define random() __builtin_ia32_rdtsc()
#define lg2(x) 31-__builtin_clz(x)
#define lg2ll(x) 63-__builtin_clzll(x)
#define pi acos(-1)
#define YN(x) cout<<((x)?("YES"):("NO"))<<fl;
#define yn(x) cout<<((x)?("Yes"):("No"))<<fl;
/// Red-Black Tree Template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
//#define less_than(n) order_of_key(n)
//#define en_pos(n) find_by_order(n)
/// Prime numbers  173,179,311,331,737,1009,2011,2027,3079,4001,100003
///=====================================================================


main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,k;
    cin>>n>>k;
    vi v;

    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        v.pb(x);
    }
    sort(all(v));
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=v[i];
    }
    cout<<ans;

return 0;}







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


fn main(){
    input!{
        n: u32,
        m: u32,
    }
    let a = ((n-1)*n)/2;
    let b = ((m-1)*m)/2;
    println!("{}", (a+b));
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#define MAX 10000
#define NIL -1


typedef struct Node
{
	int number;
	int parent;
	int left, right;
	int depth;
	int height; // 自分と自分から一番深い子の距離
};

void setDepth(Node node[], int index, int depth)
{
	if (index == NIL) return;
	node[index].depth = depth;
	setDepth(node, node[index].left, depth + 1);
	setDepth(node, node[index].right, depth + 1);
}

int setHeight(Node node[], int index, int height)
{
	int h1 = 0, h2 = 0;
	if (node[index].left != NIL)
		h1 = setHeight(node, node[index].left, node[node[index].left].height) + 1;
	if (node[index].right != NIL)
		h2 = setHeight(node, node[index].right, node[node[index].right].height) + 1;
	return node[index].height = h1 > h2 ? h1 : h2;
}

int getSibling(Node node[], int index)
{
	if (node[index].parent == NIL) return NIL;
	if (node[node[index].parent].left != index && node[node[index].left].number != NIL)
		return node[node[index].parent].left;
	if (node[node[index].parent].right != index && node[node[index].right].number != NIL)
		return node[node[index].parent].right;
	return NIL;
}

int getDegree(Node node)
{
	int deg = 0;
	if (node.left != NIL) deg++;
	if (node.right != NIL) deg++;
	return deg;
}

void print(Node node[], int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << "node " << node[i].number << ": ";
		cout << "parent = " << node[i].parent << ", ";
		cout << "sibling = " << getSibling(node, i) << ", ";
		cout << "degree = " << getDegree(node[i]) << ", ";
		cout << "depth = " << node[i].depth << ", ";
		cout << "height = " << node[i].height << ", ";
		if (node[i].parent == NIL)
			cout << "root";
		else if (node[i].left == NIL && node[i].right == NIL)
			cout << "leaf";
		else
			cout << "internal node";
		cout << endl;
	}
}

int main()
{
	Node node[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		node[i].number = node[i].parent = NIL;
		node[i].left = node[i].right = NIL;
		node[i].depth = node[i].height = 0;
	}
	for (int i = 0; i < n; i++)
	{
		int number;
		cin >> number;
		node[number].number = number;
		cin >> node[number].left >> node[number].right;
		if (node[number].left != NIL) node[node[number].left].parent = node[number].number;
		if (node[number].right != NIL) node[node[number].right].parent = node[number].number;
	}

	int idxRoot;
	for (int i = 0; i < n; i++) if (node[i].parent == NIL) { idxRoot = i; break; }

	setDepth(node, idxRoot, 0);
	setHeight(node, idxRoot, 0);

	print(node, n);
}


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

//解説参考.
int main(){
	llong n;
	cin>>n;
	
	string ans="";
	while(n>0){
		n--;
		ans+=char('a'+n%26);
		n/=26;
	}
	reverse(ALL(ans));
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#define INF 999999
#define NIL -1

int main()
{
  int i,j;
  int n;
  int u,min=0,sum=0;
  int g[100][100],a[100],b[100],c[100];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      a[i]=INF;
      b[i]=NIL;
      c[i]=1;
    }
  a[0]=0;

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

  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  if(g[i][j]==-1) g[i][j]=INF;
	}
    }

  

  while(1)
    {
      min=INF;
      for(i=0;i<n;i++)
	{
	  if(c[i]!=2 && a[i]<min)
	    {
	      min = a[i];
	      u = i;
	    }
	}

    if(min == INF) break;

    c[u] = 2;
    for(i = 0; i < n; i++){
      if(c[i] != 2 && g[u][i] < a[i]){
  	b[i] = u;
  	a[i] = g[u][i];
      }
    }
  }

  for(i = 0; i < n; i++){
    if(b[i] != NIL) sum += g[i][b[i]];
  }

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

  return 0;
}



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

int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    int x1=0,x2=0;
    for(int i=0;i<n;i++){
        cin>>x[i];
        x1+=x[i];
        x2+=pow(x[i],2);
    }
    int pmin=*min_element(x.begin(),x.end()),pmax=*max_element(x.begin(),x.end()),emin;
    emin=n*pow(pmin,2)-2*pmin*x1+x2;
    for(int i=pmin+1;i<=pmax;i++){
        emin=min(emin,n*(int)pow(i,2)-2*i*x1+x2);
    }
    cout<<emin;
    return 0;
}


Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll minv;
    ll minn;
    ll maxv;
    ll maxn;
    if(x <= y) {
        minv = a;
        minn = x;
        maxv = b;
        maxn = y;
    }else {
        minv = b;
        minn = y;
        maxv = a;
        maxn = x;

    }

    ll ans = min(x*a+y*b, 2 * maxn * c);
    ans = min(ans, 2 * minn * c + (maxn- minn) * maxv);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M;
int G[10][10] = { 0 };
int ans = 0;
bool vis[10] = {false};


void dfs(int s) {
	vis[s] = true;
	
	REP(i, N) {
		bool F = true;

		if (G[s][i] && !vis[i]) {
			vis[i] = true;
			REP(i, N) {
				if (!vis[i])F = false;
			}
			if (F) {
				ans++;
				vis[i] = false;
				//cout << "K" << s << " " << i << endl;
			}
			else {
			//	cout << s << " " << i << endl;
				dfs(i);
			}
		}
	}
	vis[s] = false;
	return;
}






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

	cin >> N >> M;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a][b]=1;
		G[b][a] = 1;
	}
	dfs(0);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		if((a.equals("H") && b.equals("H"))||(a.equals("D") && b.equals("D")))System.out.println("H");
		else System.out.println("D");
		
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int n=0;
    if(S.at(0)=='o')    n++;
    if(S.at(1)=='o')    n++;
    if(S.at(2)=='o')    n++;
    
    cout << 700+n*100 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[10];
void f(int x,int chk)
{
    if(x==n)
    {
        for(int i=0;i<n;i++)
        {
            printf("%c",a[i]);
        }
        printf("\n");
        return;
    }
    for(int i=0;i<10;i++)
    {
        if(i==0||(chk&(1<<(i-1))))
        {
            a[x]='a'+i;
            f(x+1,chk|(1<<i));
        }
    }
}
int main()
{
    scanf("%d",&n);
    f(0,0);
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,n,a) for(int i=n;i>=a;i++)
#define ll long long int
#define p(a,b) pair<a,b>
#define mp(a,b) make_pair(a,b)
#define hpq(a) priority_queue<a>
#define lpq(a) priority_queue<a, vector<a>, greater<a>>
#define nl endl
#define pb(x) push_back(x);
#define ft(x,a) for(auto &it : a)
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
/*

   *                          (                            (
 (  `          )   )          )\ )            )            )\ )        (      )    *   )              )                                                  (
 )\))(      ( /(( /(   (  (  (()/(  (      ( /(   (  (    (()/(        )\  ( /(  ` )  /((   (      ( /(                   (         )    (               )\ )  (
((_)()\  (  )\())\()) ))\ )(  /(_))))\  (  )\()) ))\ )(    /(_))  (   ((_) )\())  ( )(_))(  )\ )   )\())(     (  (  `  )  )\ )     (     )\ )    (  (   (()/( ))\
(_()((_) )\(_))((_)\ /((_|()\(_))_/((_) )\((_)\ /((_|()\  (_))_   )\  )\ )(_))/  (_(_()|()\(()/(  (_))/ )\    )\ )\ /(/( (()/(     )\  '(()/(    )\ )\   ((_))((_)
|  \/  |((_) |_| |(_|_))  ((_) |_(_))( ((_) |(_|_))  ((_)  |   \ ((_)_(_/(| |_   |_   _|((_))(_)) | |_ ((_)  ((_|(_|(_)_\ )(_))  _((_))  )(_))  ((_|(_)  _| (_))
| |\/| / _ \  _| ' \/ -_)| '_| __| || / _|| / // -_)| '_|  | |) / _ \ ' \))  _|    | | | '_| || | |  _/ _ \ / _/ _ \ '_ \) || | | '  \()| || | / _/ _ \/ _` / -_)
|_|  |_\___/\__|_||_\___||_| |_|  \_,_\__||_\_\\___||_|    |___/\___/_||_| \__|    |_| |_|  \_, |  \__\___/ \__\___/ .__/ \_, | |_|_|_|  \_, | \__\___/\__,_\___|
                                                                                            |__/                   |_|    |__/           |__/

*/
int main()
{
    int n;
    cin>>n;
    int m=0;
    int c=0;
    for(int i=0;i<n;i++)
    {
        int z;
        cin>>z;
        if(z%2==0)
        {
            c++;
            if(z%3==0||z%5==0)
                m++;
        }
    }
    if(m==c)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"
#include "map"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const ll mod = 1e9 + 7;

int main()
{
  int a[5][5];
  int n;
  int b[20];
  bool cl[5][5];
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cl[i][j] = false;
    }
  }
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> a[i][j];
    }
  }
  cin >> n;
  for (int k = 0; k < n; k++)
  {
    cin >> b[k];
    for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < 3; j++)
      {
        if (b[k] == a[i][j])
        {
          cl[i][j] = true;
        }
      }
    }
  }
  bool ans = (cl[0][0] && cl[0][1] && cl[0][2]) || (cl[1][0] && cl[1][1] && cl[1][2]) || (cl[2][0] && cl[2][1] && cl[2][2]) || (cl[0][0] && cl[1][0] && cl[2][0]) || (cl[0][1] && cl[1][1] && cl[2][1]) || (cl[0][2] && cl[1][2] && cl[2][2]) || (cl[0][0] && cl[1][1] && cl[2][2]) || (cl[0][2] && cl[1][1] && cl[2][0]);
  cout << (ans ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 101010;

int main(){
    int sqt = ceil(sqrt(INF) + 0.1);
    vector<int> a(INF, 1);
  	a[0] = 0; a[1] = 0;
    for(int i=0; i<sqt; ++i){
        if(!a[i]){continue;}
        for(int j=i*2; j<INF; j+=i){a[j] = 0;}
    }

    vector<int> like(INF, 0);
    for(int i=0; i<INF; ++i){
        if(i%2==0){continue;}
        if(a[i] && a[(i+1)/2]){like[i] = 1;}
    }
    vector<int> s(INF, 0);
    for(int i=0; i<INF; ++i){
        s[i+1] = s[i] + like[i];  	
    }

  	int q; cin >> q;
    for(int i=0; i<q; ++i){
        int l, r; cin >> l >> r;
        cout << s[r+1] - s[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 4512
#include<bits/stdc++.h>
	using namespace std;
	vector<long long int>primes, v;
	void s(long long int n)
	{
		long long int i;
		for(i=2;i<=sqrt(n);i++)
		{
			if(n%i == 0)
			{
				primes.push_back(i);
				while(n%i==0)
				n/=i;
			}
		}
		if(n>1)
		primes.push_back(n);
	}
	void ispuni(long long int n)
	{
		for(long long int i=0;i<primes.size();i++)
		{
			long long int broj = primes[i];
			while(broj <= n)
			{
				v.push_back(broj);
				broj*=primes[i];
			}
		}
	}
	main()
	{
		long long int n, ans=0;
		cin >> n;
		long long int i;
		//long long int   ans = 0;
		if(n == 1)
		{
			cout <<0 << endl;
			return 0;
		}
	 	s(n);	
	 	 ispuni(n);
	 	sort(v.begin(), v.end());
		for(i=0;i<v.size();i++)
		{
			if(n%v[i] == 0)
			n/=v[i], ans++;
		}
		cout << ans << endl;
		return 0 ;
	}

Measured memory_bytes: 3676