akhauriyash/Code-Regression huggingface dataset:
import sys
from math import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, X = in_nn()
    x = in_nl()
    x += [X]
    x.sort()

    diff = [0] * N
    for i in range(N):
        diff[i] = x[i + 1] - x[i]

    ans = diff[0]
    for i in range(1, N):
        ans = gcd(ans, diff[i])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18836
#include<iostream>
using namespace std;
#define N 100005
#define NIL -1

struct Node {int p,l,r;};

Node TW[N];
int n, DT[N];

void print(int u){
    int i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << TW[u].p << ", ";
    cout << "depth = " << DT[u] << ", ";

    if (TW[u].p == NIL) cout << "root, ";
    else if (TW[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for(i = 0, c =TW[u].l; c != NIL; i++, c=TW[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void recdepth(int u,int p){
    DT[u] = p;
    if(TW[u].r != NIL) recdepth(TW[u].r ,p);
    if(TW[u].l != NIL) recdepth(TW[u].l,p+1);
}

int main(){
    int i,j,d,v,c,l,r;
    cin >> n;
    for(i=0;i<n;i++)TW[i].p = TW[i].l = TW[i].r = NIL;

    for(i=0;i<n;i++){
        cin >> v >> d;
        for(j=0;j<d;j++){
            cin >> c;
            if (j==0)TW[v].l = c;
            else TW[l].r =c;
            l = c;
            TW[c].p = v; 
        }
    }
    for(i=0;i<n;i++){
        if(TW[i].p == NIL)r=i;  
    }

    recdepth(r,0);

    for(i=0;i<n;i++)print(i);

    return 0;
}



Measured memory_bytes: 7768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define ll long long
using namespace std;

int main(){
  //cout<<123<<endl;
  int K,S;
  cin>>K>>S;
  int cnt=0;
  for (int x=0; x<=K; x++) {
    for (int y=0; y<=K; y++) {
      int z=S-x-y;
      cnt += (z>=0 and z<=K) ? 1:0;
    }
  }
  cout<<cnt<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <ctime>
#include <set>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <sstream>
#include <cstdio>
#include <bitset>
#include <iomanip>

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector <long long> h(n + 10);

    for (int i = 1; i <= n; ++i)
        cin >> h[i];

    vector <long long> dp(n + 10);

    for (int i = 0; i <= n; ++i)
        dp[i] = (1<<60);

    dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    for (int i = 3; i <= n; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	long long n,teama,teamb,score[1001]={0},c,d,number[1001],kari[1001];
	cin>>n;
	for(int i=0;i<n*(n-1)/2;++i){
		cin>>teama>>teamb;
		cin>>c>>d;
		if(c>d){
			score[teama]+=3;
		}
		else if(c<d){
			score[teamb]+=3;
		}
		else{
			score[teama]+=1;
			score[teamb]+=1;
		}

	}
	int max=-1,memo,count=0;
	for(int j=1;j<=n;++j){
		for(int i=1;i<=n;++i){
			if(max<score[i]){
				max=score[i];
				memo=i;
			}
		}
		number[memo]=j;
		for(int k=1;k<=n;++k){
			if(memo==k){
				continue;
			}
			if(score[memo]==score[k]&&score[memo]!=-1&&score[k]!=-1){
				number[k]=j;
				score[k]=-1;
				count++;
			}
		}
		j+=count;
		count=0;
		score[memo]=-1;
		max=-1;
	}
	
	for(int i=1;i<=n;++i){
		cout<<number[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import deque

def solve():
    n = II()
    V = LI()

    V = deque(sorted(V))

    vi = V.popleft()
    while 1:
        vj = V.popleft()
        avg = (vi + vj) / 2
        V.append(avg)
        V = deque(sorted(V))

        vi = V.popleft()
        if len(V) == 0:
            break
    print(vi)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b + c || b == a + c || c == a + b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, Q;
  string S;
  int l, r;
  cin >> N >> Q;
  cin >> S;
  
  vector<int> v_int = vector<int>(N+1, 0);
  int count_ac = 0;
  for (int i=0; i<N; i++) {
    if (S[i]=='A' && S[i+1]=='C'){
      count_ac++;
    }
    v_int[i+1] = count_ac;
  }

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

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int x, y;
	cin >> x>>y;
	if (y < 2 * x) {
		cout << "No"; return 0;
	}
	if (y > 4 * x) {
		cout << "No"; return 0;
	}

	if (y % 2 == 1) {
		cout << "No"; return 0;
	}

	cout << "Yes";
	return 0;
}

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

ll cn[100010];

int main(){
    ll n;cin>>n;
    ll an=1;
    rep(i,0,n){
        ll a;
        cin>>a;
        if(a!=0){
            an=(an*(cn[a-1]-cn[a]))%1000000007;
        }
        cn[a]++;
    }
    if(cn[0]==1){
        an=(an*3)%1000000007;
    }
    else if(cn[0]>3){
        cout<<0<<endl;
        return 0;
    }
    else an=(an*6)%1000000007;
    cout<<an<<endl;
}







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

int main(){
    int n;
    string str;
    cin>>n;
    int s[4]={};
    for(int i=0;i<n;i++){
        cin>>str;
        if(str=="AC")s[0]++;
        else if(str=="WA")s[1]++;
        else if(str=="TLE")s[2]++;
        else if(str=="RE")s[3]++;
    }
    cout<<"AC x "<<s[0]<<endl;
    cout<<"WA x "<<s[1]<<endl;
    cout<<"TLE x "<<s[2]<<endl;
    cout<<"RE x "<<s[3]<<endl;
}


Measured memory_bytes: 3592
def main():
	N = int(input())
	L = [int(l) for l in input().split(" ")]
	L.sort()
	m = len(L)
	cnt = 0
	for i in range(m):
		k = m - 1
		for j in range(i + 1, m):
			while m + i - j < k:
				if L[m + i - j] + L[i] <= L[k]:
					k -= 1
				else:
					cnt += k - m - i + j
					break
	print(cnt)

main()

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	string s;
	cin >> s;
	ll cnt=0,sum=0;
	repp(i, 0, s.size()-1) {
		if (s[i] == 'A')++cnt;
		else {
			if (s[i] == 'B') {
				if (s[i + 1] == 'C') {
					sum += cnt;
					i++;
				}
				else cnt = 0;
			}
			else cnt = 0;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
std::pair<int, long long int> remove_count(int d, long long int c) {
	if (c == 1) return std::make_pair(d, 0);
	if (c % 2 == 0) {
		if (d * 2 < 10) {
			auto next = remove_count(d * 2, c / 2);
			next.second += c / 2;
			return next;
		}
		else {
			auto next = remove_count(d * 2 - 9, c / 2);
			next.second += c;
			return next;
		}
	}
	else {
		if (d * 2 < 10) {
			auto next = remove_count(d * 2, c / 2);
			next.first += d;
			next.second += 1;
			if (next.first >= 10) {
				next.first -= 9;
				next.second += 1;
			}
			next.second += c / 2;
			return next;
		}
		else {
			auto next = remove_count(d * 2 - 9, c / 2);
			next.first += d;
			next.second += 1;
			if (next.first >= 10) {
				next.first -= 9;
				next.second += 1;
			}
			next.second += c / 2 * 2;
			return next;
		}
	}
}
long long int remove_count(std::vector<int> digits) {
	long long int count = 0;
	while (digits.size() > 1) {
		++count;
		auto back = digits.back(); digits.pop_back();
		digits.back() += back;
		if (digits.back() >= 10) {
			++count;
			digits.back() -= 9;
		}
	}
	return count;
}
int main() {
	int m; std::cin >> m;
	std::vector<int> digits; digits.reserve(m);
	long long int sum = 0;
	for (auto i = 0; i < m; ++i) {
		int d; long long int c; std::cin >> d >> c;
		auto result = remove_count(d, c);
		digits.push_back(result.first);
		sum += result.second;
	}
	std::cout << sum + remove_count(std::move(digits)) << '\n';
}

Measured memory_bytes: 1024
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int a=sc.nextInt(),b=sc.nextInt();
        int q=sc.nextInt();
        long[] s=new long[a];
        long[] t=new long[b];
        for (int i = 0; i < a; i++) {
            s[i]=sc.nextLong();
        }
        for (int i = 0; i < b; i++) {
            t[i]=sc.nextLong();
        }
        for (int i = 0; i < q; i++) {
            long x=sc.nextLong();
            int S=Arrays.binarySearch(s,x);
            int T=Arrays.binarySearch(t,x);
            if(S<0)S=~S;
            if(T<0)T=~T;
            long s1=0<=S&&S<a?s[S]:-1;
            long s2=0<=S-1&&S-1<a?s[S-1]:-1;
            long t1=0<=T&&T<b?t[T]:-1;
            long t2=0<=T-1&&T-1<b?t[T-1]:-1;
            long d1=s1!=-1&&t1!=-1?min(abs(s1-x)+abs(t1-s1),abs(t1-x)+abs(s1-t1)):Long.MAX_VALUE;
            long d2=s1!=-1&&t2!=-1?min(abs(s1-x)+abs(t2-s1),abs(t2-x)+abs(s1-t2)):Long.MAX_VALUE;
            long d3=s2!=-1&&t1!=-1?min(abs(s2-x)+abs(t1-s2),abs(t1-x)+abs(s2-t1)):Long.MAX_VALUE;
            long d4=s2!=-1&&t2!=-1?min(abs(s2-x)+abs(t2-s2),abs(t2-x)+abs(s2-t2)):Long.MAX_VALUE;
            out.println(min(min(d1,d2),min(d3,d4)));
        }
    }
}

Measured memory_bytes: 96120
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  int ans = 1e9 + 7;
  int N = max(X, Y) * 2;
  for(int i = N; i >= 0; i -= 2){
    int a = max(X-i/2, 0);
    int b = max(Y-i/2, 0);
    ans = min(ans, A*a+B*b+C*i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;
void solve(){
    string s;
    cin >> s;
    string t1 = "", t2 = "";
    
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            t1 += "0";
            t2 += "1";
        }
        else{
            t1 += "1";
            t2 += "0";
        }
    }
    int cnt1 = 0, cnt2 = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t1[i]) cnt1++;
        if(s[i] != t2[i]) cnt2++;
    }
    cout << min(cnt2, cnt1);
}


int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


Measured memory_bytes: 768
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>

using namespace std;


int main() {

    int K, X;
    cin >> K >> X;
    if (500 * K >= X) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e3 + 100, INF = 1e9 * 1e4 + 10, MOD = 1e9 + 7;

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

ll n, a, b, c, d, dp[SIZE];
vector<vector<ll>> gr;
vector<ll> vals;

void input() {
    cin >> n;

    gr.resize(n);

    for (int i = 1; i < n; i++) {
        ll pr;
        cin >> pr;
        pr--;
        gr[pr].push_back(i);
    }

    vals.resize(n);

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

ll pw(ll a, ll b, ll md) { ll res = 1; while (b) { if (b & 1) { res = (a*res) % md; }a = (a*a) % md; b >>= 1; }return(res); }

bitset<5010> bck[SIZE];

void dfs(int v) {
    dp[v] = INF;
    
    bck[v][0] = 1;
    ll s = 0;
    for (auto to : gr[v]) {
        dfs(to);
        s += vals[to] + dp[to];
        bck[v] = (bck[v] << vals[to]) | (bck[v] << dp[to]);
    }

    bool flag = true;

    ll mn = INF;
    for (int i = vals[v]; i >= 0; i--) {
        if (bck[v][i]) {
            flag = false;
            mn = s - i;
            break;
        }
    }
    dp[v] = mn;

    if (flag) {
        cout << "IMPOSSIBLE";
        exit(0);
    }
}

void sol() {
    dfs(0);
}

int main()
{
    fastInp;

    ll t = 1;

    while (t--) {
        input();
        sol();

        cout << "POSSIBLE";
    }

    return 0;
}

Measured memory_bytes: 5060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
 
int main(){
    double a,b; int h,m;
    cin >> a >> b >> h >> m;
    
    double kaku = min(abs(h * 30 + 0.5 * m - 6 * m),360 - abs(h * 30 + 0.5 * m - 6 * m)); //cout << kaku << endl;
    
    double p = 180;
    double sita = (kaku / p) * 3.141592653589; //cout << cos(sita) << endl;

    double ans2 = a * a + b * b - 2 * a * b * cos(sita); //cout << ans2 << endl;
    //double ans1 = pow(ans2,0.5);

    cout << fixed <<  setprecision(15) << sqrt(ans2) << endl;
}

Measured memory_bytes: 4188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;
ll A[200005];

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> A[i];
	}

	if (A[0] != 0)
	{
		cout << -1 << endl;
		return 0;
	}

	ll ans = 0;
	ll a = 0;
	ll m = 0;
	IREP(i, N - 1)
	{
		if (m > a)
		{
			cout << -1 << endl;
			return 0;
		}
		if (a < A[i])
		{
			ans += A[i];
			a = A[i];
			m = std::max(m, a);
		}
		else if (a > A[i])
		{
			if (i < a || A[i] == 0)
			{
				cout << -1 << endl;
				return 0;
			}
			a = A[i];
			ans += A[i];
			m = std::max(m, a);
		}
		a--;
		m--;
	}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    int cnt = 0;
    rep(k, N+1) {
        rep(l, M+1) {
            cnt = k*(M-l) + (N-k)*l;
            if (cnt == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-13
#define INF 1e9
#define LINF 1e18

int const MaxSize = 1e5 + 10;
LL N, K;

LL cgcd(LL a, LL b) {
	if (a == b) {
		return a;
	} else if (a < b) {
		return cgcd(b, a);
	} else {
		if (a % b) {
			return cgcd(b, a % b);

		} else {
			return b;
		}
	}
}

LL k1Good(vector<LL>& sorted) {
	LL gcd = sorted[0];

	LP(i, 1, sorted.size())
	{
		gcd = cgcd(gcd, sorted[i]);
	}

	return gcd;
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);

	cin >> N >> K;

	vector<LL> noDup;
	set<LL> seen;
	LP(i, 0, N)
	{
		LL Ai;
		cin >> Ai;

		if (seen.count(Ai)) {

		} else {
			seen.insert(Ai);
			noDup.push_back(Ai);
		}
	}

	sort(noDup.begin(), noDup.end());
	int nds = noDup.size();

	if (noDup[nds - 1] < K) {
		cout << "IMPOSSIBLE";
	} else if (seen.count(K)) {
		cout << "POSSIBLE";
	} else if (nds == 1) {
		cout << "IMPOSSIBLE";
	} else {
		LL allGCD = k1Good(noDup);

		if (allGCD == 1 || K % allGCD == 0) {
			cout << "POSSIBLE";
		} else {
			cout << "IMPOSSIBLE";
		}
	}

	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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 comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

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

    }

    if( n == 1 ) {
        cout << v[0] << endl;
        return 0;

    }

    int res = 0;
    bool flg = false;
    while( !flg ) {
        for( int i = 0; i < n; ++i ) {
            if( v[i] == 0 ) {
                continue;

            }
            if( i == 0 ) {
                if( v[i + 1] == 0 ) {
                    ++res;

                }

            } else if( i == n - 1 ) {
                ++res;

            } else {
                if( v[i + 1] == 0 ) {
                    ++res;

                }
            }
            --v[i];

        }
        int cnt = 0;
        for( int i = 0; i < n; ++i ) {
            if( v[i] == 0 ) ++cnt;

        }
        if( cnt == n ) flg = true;

    }
    cout << res << endl;
    return 0;
}



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


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set; */
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define N 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef ONLINE_JUDGE
#define cerr if(true)cerr
#endif

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
	}
};

ll power(ll x, ll y,ll p)
{
    ll res = 1;     // Initialize result
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;  // Change x to x^2
    }
    return res;
}
// int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a,ll p){return power(a,p-2,p);}

/*
 
REMOVE DEBUG STATEMENTS
CHECK FOR DUPLICATES (SET -> MULTISET)
CLEAR EVERYTHING BEFORE EVERY TESTCASE
ceil(x/2.0)
floor(x/2.0)
 
*/
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

void solve(){
    ll n,k;
    cin>>n>>k;
    vll a(n);
    f(i,0,n){
        cin>>a[i];
    }
    sort(all(a));
    ll sm = 0;
    f(i,0,k){
        sm+=a[i];
    }
    cout<<sm<<nl;
    return ;
}
int main()
{
    IO;
    int T=1;
	// cin >> T;
	f(c,0,T){
		solve();
	}
    return 0;
}//multiset m make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first false erase double priority_queue


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  int h,a;
  cin>>h>>a;
  if(h==a){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

void solve(long long N, std::vector<std::string> S){
    int num[4] ={};
    for(int i=0;i<N;i++){
        if(S[i] == "AC"){
            num[0]++;
        }
        if(S[i] == "WA"){
            num[1]++;
        }
        if(S[i] == "TLE"){
            num[2]++;
        }
        if(S[i] =="RE"){
            num[3]++;
        }
    }
    cout <<"AC x " <<num[0] <<endl;
    cout <<"WA x " <<num[1] <<endl;
    cout <<"TLE x " <<num[2] <<endl;
    cout <<"RE x " <<num[3] <<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 N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

struct line{
    int to,costt,costm;
};

struct dpnode{
    ll from,money,time;
};

int main() {

    int N,M,S;
    Scd3(N,M,S);
    if( S > 5000 ) S = 5000;

    int u,v,a,b;
    vi c(N),d(N);
    vector<vector<line>> e(N);

    Rep(i,M){
        Scd2(u,v); Scd2(a,b);
        u--,v--;
        e[u].push_back({v,b,a});
        e[v].push_back({u,b,a});
    }
    Rep(i,N){
        Scd2(c[i],d[i]);
    }


    auto comp = []( const dpnode& a, const dpnode& b ){
        return a.time > b.time;
    };
    priority_queue<dpnode,vector<dpnode>, decltype(comp) > q(comp);

    q.push({0,S,0});
    vector<vl> dp(N, vl(5001,1e16));
    dp[0][S] = 0;

    while( q.size() ){
        int from = q.top().from;
        ll money = q.top().money;
        ll time = q.top().time;
        // printf ("%d %d -- %lld\n", from, money, time);
        // Scd(a);
        q.pop();
        if( time > dp[from][money] ) continue;
        // idou
        for( line tol : e[from] ){
            int to = tol.to;
            ll toMoney = money-tol.costm;
            ll toTime = time+tol.costt;
            if( toMoney < 0 ) continue;
            if( toTime < dp[to][toMoney] ){
                q.push({to,toMoney,toTime});
                dp[to][toMoney] = toTime;
            }
        }
        // kinnka to ginka
        int to = from;
        ll toMoney = money+c[from];
        ll toTime = time+d[from];
        if( toMoney > 5000 ) toMoney = 5000;
        if( toTime < dp[to][toMoney] ){
            q.push({to,toMoney,toTime});
            dp[to][toMoney] = toTime;
        }
    }

    vl ans(N,1e16);
    Repe(i,N,1){
        Rep(j,5001) ans[i] = min( ans[i], dp[i][j] );
        printf ("%lld\n", ans[i] );
    }

    return 0;
}



Measured memory_bytes: 11424
#include <iostream>
#include <algorithm>

using namespace std;

#define MY_LIMITS 1000000007	

int main(){
	int n=0;
	int m=0;
	cin >> n >> m;
	if(abs(n-m)>1){
		cout << "0" << endl;
	}else if(n==m){
		long long int ans=1;
		for(int i=2;i<=n;i++){
			ans*=i;
			if(ans>MY_LIMITS){
				ans%=MY_LIMITS;
			}
			ans*=i;
			if(ans>MY_LIMITS){
				ans%=MY_LIMITS;
			}
		}
		ans*=2;
		if(ans>MY_LIMITS){
			ans%=MY_LIMITS;
		}
		cout << ans << endl;
	}else{
		long long int ans=1;
		for(int i=2;i<=min(n,m);i++){
			ans*=i;
			if(ans>MY_LIMITS){
				ans%=MY_LIMITS;
			}
			ans*=i;
			if(ans>MY_LIMITS){
				ans%=MY_LIMITS;
			}
		}
		ans*=max(n,m);
		if(ans>MY_LIMITS){
				ans%=MY_LIMITS;
		}
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef double keytype;

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int main(){
    int n;
    double a[1005];

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

    double sum = 0.0;
    for(int i = 0; i < n; ++i){
        sum += (1.0 / a[i]);
    }

    printf("%f\n", 1.0 / sum);

    return 0;
}


Measured memory_bytes: 1744
//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
using namespace std;
typedef long long ll;


int main() {
	int N,tmp;
	cin >> N;
	int A[N] = { 0 };
	FOR(N-1) {
		cin >> tmp;
		A[tmp-1]++;
	}
	FOR(N) {
		cout << A[i] << endl;
	}
}


Measured memory_bytes: 4424
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
//slower
/*
const int maxn = 1e7+5;
int prime[maxn]={0};
int temp[maxn]={0};
void getprim(int n){
    prime[1]=1;
    long long num = 0;
    for(long long i=2;i<=n;i++){
        if(!prime[i]){
            num = i;
            while(num<=n){
                for(long long j=num;j<=n;j+=num){
                    ++temp[j];
                    //cout << j <<endl;
                }
                num = num*i;
            }
            for(long long j=i;j<=n;j+=i){
                if(prime[j]==0)
                    prime[j]=temp[j]+1;
                else
                    prime[j]*=(temp[j]+1);
                temp[j]=0;
            }

        }
    }
}
int main()
{
    int n;
    cin >> n;
    getprim(n);
    long long sum = 0 ;
    for(int i=1;i<=n;++i)
        sum = sum + 1ll*i*(prime[i]);
    cout << sum <<endl;
    return 0;
}
*/
//faster
int main(){
    int n=10000000;
    cin >> n;
    long long ans = 0 ;
    for(int i=1;i<=n;++i){
        int div_i = n/i;
        ans += 1ll*i*(div_i+1)*div_i/2 ;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n,k,i,j;
    int a;
    int d[200000]={};
    cin >> n >> k;
    for (i=0;i<n;++i){
        cin >> a;
        d[a]+=1;
    }
    int len = sizeof(d)/sizeof(d[0]);
    sort(d,d+len);
    int num=0;
    for(i=0;i<len;++i){
        if(d[i])num+=1;
    }
    j=0;
    if (num<=k)cout << 0;
    else{
        int ret=0;
        for(i=0;i<len;++i){
            if(d[i]){
                ret+=d[i];
                ++j;
                if(j>=num-k){
                    cout << ret;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string S;
  cin >> S;

  int ret = 0;
  stack<char> s;
  for (int i=0; i<S.length(); i++) {
    char c = S[i];
    if (!s.empty() && c != s.top()) {
      s.pop();
      ret += 2;
    } else {
      s.push(c);
    }
  }
  cout << ret << endl;
}


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


int main(){
    int N; cin >> N;
    vector<int> X(N), Y(N);
    for(int i=0; i<N; i++){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(Y.begin(),Y.end());
    
    int mid1=Y[Y.size()/2-1], mid2=Y[Y.size()/2];
    
    for(int i=0; i<N; i++){
        if(X[i]<=mid1){
            cout << mid2 << endl;
        }
        else {
            cout << mid1 << endl;
        }
    }
}


Measured memory_bytes: 3712
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

class Tree
{
    Tree[26] children;
    long[26] counts;
    char c;

    this(char c) {
        this.c = c;
    }

    void add(string s) {
        assert(this.c == '\n');

        auto last = s[$-1];
        if (children[last - 'a'] is null) {
            children[last - 'a'] = new Tree(last);
        }
        long[26] cs;
        children[last - 'a'].add(s[0..$-1], cs);
        foreach (i, c; cs) this.counts[i] += c;
    }

    void add(string s, ref long[26] cs) {
        if (s.empty) {
            ++cs[this.c - 'a'];
            return;
        }

        auto last = s[$-1];
        if (children[last - 'a'] is null) {
            children[last - 'a'] = new Tree(last);
        }
        children[last - 'a'].add(s[0..$-1], cs);

        foreach (i, c; cs) this.counts[i] += c;
        cs[this.c - 'a'] = 1;
    }

    long count(string s) {
        if (s[$-1] == '\n') s = s[0..$-1];

        auto c = s[$-1];
        if (s.length == 1) {
            return this.counts[c - 'a'] - 1;
        } else {
            return this.children[c - 'a'].count(s[0..$-1]);
        }
    }
}

void main()
{
    auto N = readln.chomp.to!int;
    auto tree = new Tree('\n');
    string[] ss;
    foreach (_; 0..N) {
        auto s = readln.chomp;
        tree.add(s);
        ss ~= s;
    }
    long r;
    foreach (s; ss) r += tree.count(s);
    writeln(r);
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VI> dt(101000);
	rep(i, n){
		int a, b; cin >>a >>b;
		dt[a].push_back(b);
	}
	ll ans =0;
	priority_queue<int> pq;
	rep(i, m+1){
		for(auto x: dt[i]) pq.emplace(x);
		if(!pq.empty()){
			ans += pq.top(); pq.pop();
		}
	}
	cout <<ans <<"\n";
	return 0;
	
}


Measured memory_bytes: 5632
import collections

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

S = [0]
for i in range(N):
  S.append(S[i] + A[i])
S = S[1::]
#print("S:", S)

S = list(map(lambda x: x % M, S))
S = collections.Counter(S).items()
#print("S:", S)

answer = 0
for k, v in S:
  if k == 0:
    answer += v * (v + 1) //2
  else:
    answer += v * (v - 1) //2
print(answer)

Measured memory_bytes: 64664
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r: u32 = read();
    let g: u32 = read();
    let b: u32 = read();

    let ans = {
        (100*r+10*g+b) % 4 == 0
    };

    println!("{}", if ans {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

long long int A, B;

int main() {
	cin >> A >> B;

	long long int range = B - A + 1;
	if (A % 2 == 0) {
		A = 0;
	}
	else {
		range--;
	}

	if (B % 2 == 1) {
		B = 0;
	}
	else {
		range--;
	}

	long long int ans = 0;
	if ((range / 2) % 2 == 1) {
		ans = 1;
	}

	cout << (ans ^ A ^ B) << endl;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int N;
    cin >> N;
    cout << N*N*N << endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
count = 0
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j] and L[i] != L[k] and L[j] != L[k] and L[i] != L[j]:
                count += 1
print(count)

Measured memory_bytes: 9204
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int , input().split()))
m = sum(x)/n
m = round(m)
ans = sum((num-m)**2 for num in x)
print(ans)

Measured memory_bytes: 61348
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    long long h, w;
    cin >> h >> w;
    if(h % 3 == 0 || w % 3 == 0){
        cout << 0 << "\n";
        return 0;
    }
    long long score = min(w, h);
    for(int i = 1; i < h; i++){
        long long a = i * w;
        long long b = (h - i) * (w / 2);
        long long c = (h - i) * (w / 2 + w % 2);
        score = min(score, max({a, b, c}) - min({a, b, c}));
    }
    for(int i = 1; i < w; i++){
        long long a = i * h;
        long long b = (w - i) * (h / 2);
        long long c = (w - i) * (h / 2 + h % 2);
        score = min(score, max({a, b, c}) - min({a, b, c}));
    }
    cout << score << "\n";
}

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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long

const int upper = 3e5 + 20;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e17;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n; cin >> n;
	int sum = 0;
	int mx = -inf;

	for (int i = 0; i < n; i += 1) {
		int lol; cin >> lol;
		mx = max(mx, lol);

		sum += lol;
	}

	sum -= mx / 2;

	cout << sum;
 	end_routine();	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
int n,m,a[510][510],b[510][510];char ch;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n) rep(j,1,m) scanf(" %c",&ch),a[i][j]=b[i][j]=(ch=='#');
	rep(i,2,n-1) rep(j,2,m-1) (j&1)?(a[i][j]=1):(b[i][j]=1);
	rep(i,1,m) a[1][i]=b[n][i]=1;
	rep(i,1,n){rep(j,1,m) putchar(a[i][j]?'#':'.');puts("");}puts("");
	rep(i,1,n){rep(j,1,m) putchar(b[i][j]?'#':'.');puts("");}
	return 0;
}

Measured memory_bytes: 2816
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
using namespace std;
const long long N=1e5+10,M=3e5+30,LEN=50;
const int Mod=10007;
const long double EPS=1e-7;
const long long MAX=1e18;
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n,a;
long long f[N][5];
int main(){
    //freopen("problem.in","r",stdin);
    //freopen("problem.ans","w",stdout);
    scanf("%d",&n);
    f[0][0]=0;
    f[0][1]=f[0][2]=-MAX;
    for(int i=1;i<=n;i++){
    	a=read();
    	f[i][0]=max(f[i-1][0],f[i-1][1]);
    	f[i][1]=max(f[i-1][1],f[i-1][2]);
    	f[i][2]=f[i-1][2];
    	f[i][0]+=a;
    	f[i][1]-=a;
    	f[i][2]+=a;
    	if(a<0){
    		f[i][2]=max(f[i][2],f[i][1]);
    		f[i][1]=max(f[i][1],f[i][0]);
    	}
    }
    printf("%lld\n",max(f[n][0],max(f[n][1],f[n][2])));
    return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
int main(){
	long long int n;
	long long int total=0;
	scanf("%lld",&n);
	for(int i=0;i<=n;i++){
		if(i%3==0||i%5==0){
			continue;
		}
		else{
		total=total+i;
		}
	}
	printf("%lld",total);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,l;
	cin>>n>>l;
	string s[n];
	for(i=0;i<n;i++)
	{
		cin>>s[i];
	}
	sort(s,s+n);
	for(i=0;i<n;i++)
	{
		cout<<s[i];
	}
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
const int N=2e5;

int main(){
int n;
cin>>n;
int a[n];
rep(i,n) scanf("%d",&a[i]);
if(n%2==0){
ll dp[n];
dp[0]=a[0];
dp[1]=a[1];
    for(int i=2;i<n;i++){
    if(i%2==0)
        dp[i]=dp[i-2]+a[i];
    else
        dp[i]=max(dp[i-3],dp[i-2])+a[i];
    }
    printf("%lld\n",max(dp[n-1],dp[n-2]));
}
else{
    vector<ll>l(n/2),m(n/2),r(n/2);
    l[0]=a[0];
    m[0]=a[1];
    r[0]=a[2];
    for(int i=1;i<n/2;i++){
        l[i]=l[i-1]+a[2*i];
        m[i]=max(l[i-1],m[i-1])+a[2*i+1];
        r[i]=max(l[i-1],max(m[i-1],r[i-1]))+a[2*i+2];
    }
    printf("%lld\n",max(l[n/2-1],max(m[n/2-1],r[n/2-1])));
}

return 0;
}


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

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

  vector<int> list;
  for (int i = 0; i < n; i++)
  {
    int input;
    cin >> input;
    list.push_back(input);
  }

  int before = list.size();
  sort(list.begin(), list.end());
  list.erase(unique(list.begin(), list.end()), list.end());
  int after = list.size();

  if (before == after) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll y;
    cin>>y;
    ll x = (y+999)/1000;
    cout<<(x*1000 - y)<<nl;

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";


}


Measured memory_bytes: 3804
n = gets.to_i
b = gets.split.map { |s| s.to_i }
a = []
a[0] = b[0]
a[n - 1] = b[n - 2]
(1...n - 1).each { |i|
  a[i] = b[i - 1..i].min
}
puts a.reduce(:+)


Measured memory_bytes: 3836