akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 998244353;
const int Maxn = 1e6 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

vector<pll> E[2];
ll par[Maxn];

ll get_par(ll u){
	if(par[u] == u) return u;
	return par[u] = get_par(par[u]);
}
void merge(ll u, ll v){
	u = get_par(u);
	v = get_par(v);
	par[u] = v;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	iota(par, par + Maxn, 0);
	ll n, m;
	cin >> n >> m;
	ll q;
	cin >> q;
	ll u, v, c;
	for(int i = 0; i < q; i++){
		cin >> u >> v >> c;
		E[c].pb({u, v});
	}
	if(m == n - 1) return cout << (E[1].size() == 0 ? "Yes" : "No"), 0;
	for(auto x : E[0]) merge(x.F, x.S);
	for(auto x : E[1]) if(get_par(x.S) == get_par(x.F)) return cout << "No", 0;
	
	ll s = 0;
	for(int i = 0; i < n; i++) if(get_par(i) == i) s++;
	ll mx = (s * (s - 1) / 2LL) + (n - s);
	if(m > mx) return cout << "No", 0;
	cout << "Yes\n";
	
	return 0; 
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 10996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr double INF{1e9};
constexpr int MAGIC_PRIME{1000000000 + 7};
constexpr array<int, 4> dy{-1, 1, 0, 0};
constexpr array<int, 4> dx{0, 0, -1, 1};
constexpr int div_ru(int a, int b)
{
    return (a - b + 1) / b;
}
ll pow_mod(ll b, ll e, ll m)
{ // https://atcoder.jp/contests/atc002/tasks/atc002_b
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
int coin_times(int a, int b)
{
    int n = 0;
    while (a*pow(2, n) <b)
    {
        n++;
    }

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

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

    double p = 0;

    for (int i = 0; i < n; i++) // i+1が最初のサイコロで出た目
    {
        if (i + 1 >= k)
        {
            p += 1.0 / n;
            continue;
        }
        else
        {
            p += 1.0 / n * pow(0.5, coin_times(i + 1, k));
        }
    }

    cout <<setprecision(12)<< p << endl;
}
// 　　　　　　_......_
// 　　　　 , ´　 <＊y　♪
// 　　　　 i,（i ﾉﾉﾊ）_）
// 　　　　ﾉ_iﾊﾟ ヮﾟﾉﾊ
// 　　　 　 ,´i'_ｿﾉj,〈つ　))
// 　　　　〈_,ﾉ＾＾＾ヽ.´
// 　　　　 .＾＾i_ｿ_ｿ^´
// 　　　　 ￣￣ ￣　
// vector<vector<int>> mm(h, vector<int>(w, -1));


Measured memory_bytes: 256
/*
高橋君は 2 で割れる数が好きです。
正整数 N が与えられるので、
1 以上 N 以下の整数のうち、
最も 2 で割れる回数が多いものを求めてください。答えは必ず 
1 つに定まります。
なお、2 で割っていき、何回あまりが出ずに割れるかを、
2 で割れる回数と呼ぶことにします。
例えば6 ならば、6 -> 3で、1 回 2 で割れます。
8 ならば、8 -> 4 -> 2 -> 1で、3 回 2 で割れます。
3 ならば、0 回 2 で割れます。
制約
1≦N≦100
*/

#include <iostream>
using namespace std;

int N;
int A[110];         // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) A[i] = i+1;

    int res = 0;

    // 操作が行える限り操作を繰り返す
    int waru = 2;
    int max = 1;
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
        	// cout << i;
            if (A[i] % waru == 0){
                //cout << waru << ' ' << A[i] << endl;
                exist_odd = true;  // 奇数があったらフラグを立てる
                max = A[i];
            }
        }
        //cout << 1;
        if (exist_odd==false) break;  // 奇数があったら break
        
        waru = waru*2;
        if (waru > N) break;
    }
 
    cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using P = pair<int, int>;
typedef long long 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 dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MAX = (1LL << 60);

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main() {
  ll n;
  cin >> n;
  ll ans = MAX;
  vector<ll> res = divisor(2 * n);
  rep(i, res.size()){
    ll num = (2 * n) / res[i];
    vector<ll> r(2), m(2);
    r[0] = 0, m[0] = res[i];
    r[1] = -1, m[1] = num;
    auto p = atcoder::crt(r, m);
    if (p.first != 0 && p.second != 0) chmin(ans, p.first);
  }
  cout << ans << endl;
}

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

constexpr int INF = 1<<30;

int main(){
    int n, k;
    while(cin >> n >> k, n){
        vector<int> v;
        int m = 0;
        for(int i=0;i<k;i++){
            int a;
            cin >> a;
            if(a != 0) v.push_back(a);
            else m++;
        }
        n = v.size();
        sort(v.begin(),v.end());
        v.push_back(INF);
        int ans = 0;
        for(int l=0,r=0,c=0;r<n;){
            while(c<=m && r<n){
                c += v[r+1]-v[r]-1;
                r++;
                if(c<=m) ans = max(ans, v[r]-v[l]+1);
            }
            while(c>m && l<=r){
                c -= v[l+1]-v[l]-1;
                l++;
                if(c<=m) ans = max(ans, v[r]-v[l]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3476
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int) 1e9 + 9;
const int maxn = (int) 1e6 + 6;
//const mod = (int) 1e9 + 7;
using namespace std;

signed main() {
      int n, k;
      cin >> n >> k;
      vector<int> v(n);
      for(int i = 0; i < n; i++){
            cin >> v[i];
      }
      sort(v.begin(), v.end());

      int ans = 0;
      for(int i = 0; i < n-k; i++){
            ans += v[i];
      }

      cout << ans;



return 0;

}

Measured memory_bytes: 1792
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>

#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int k;
  cin >> k;
  int h[n];
  for (int i = 0; i < n; i++) {
    int cur;
    cin >> cur;
    h[i] = cur;
  }
  int minCosts[n];
  minCosts[0] = 0;
  minCosts[1] = abs(h[1]-h[0]);
  for (int i = 2; i < n; i++) {
    int cur = abs(h[i]-h[i-1])+minCosts[i-1];
    for (int j = 2; j < min(i, k)+1; j++) {
      cur = min(cur, abs(h[i]-h[i-j])+minCosts[i-j]);
    }
    minCosts[i] = cur;
  }
  cout << minCosts[n-1] << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
int main(int argc, char **argv){
  int N;
  ll C;
  std::cin >> N >> C;

  std::vector<ll> posx(N,0),negx(N,0),v(N,0),posco(N,0),negco(N,0);

  for(int i = 0; i < N; i++){
    std::cin >> posx[i] >> v[i];
    negx[N-1-i]=C-posx[i];
  }

  posco[0]=v[0]-posx[0];
  negco[0]=v[N-1]-negx[0];

  ll posmax=(posco[0]>0)?posco[0]:0;
  ll negmax=(negco[0]>0)?negco[0]:0;

  for(int i = 1; i < N; i++){
    posco[i]+=posco[i-1]+v[i]-posx[i]+posx[i-1];
    negco[i]+=negco[i-1]+v[N-1-i]-negx[i]+negx[i-1];
    posmax=std::max(posmax,posco[i]);
    negmax=std::max(negmax,negco[i]);
  }
  //ここまでok

  ll maxcal=std::max(posmax, negmax);
  ll bufcos=0;
  ll revmax=0;
  //p>>0>>n
  for(int i = 0; i < N; i++){
    bufcos=posco[N-2-i]-posx[N-2-i];
    revmax=std::max(revmax, negco[i]);
    maxcal=std::max(maxcal, revmax+bufcos);
  }
  revmax=0;
  //n>>0>>p
  for(int i = 0; i < N; i++){
    bufcos=negco[N-2-i]-negx[N-2-i];
    revmax=std::max(revmax, posco[i]);
    maxcal=std::max(maxcal, revmax+bufcos);
  }

  std::cout << maxcal << std::endl;

  return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>

int main()
{
	int a, b, c, i;
	
	scanf("%d %d %d", &a, &b, &c);
	
	for(i=1;i<=b;i++){
		if((a*i)%b == c) break;
	}
	
	if(i <= b) printf("YES");
	else printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int H,W;
std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

ll N;


int main()
{
	cin>>N;
  vector<ll> r=enum_div(N);
  r.push_back(N);
  ll ans=0;
  for(auto i:r){

    if(N/i<i-1){
      ans+=i-1;
    }
  }

  cout<<ans<<endl;
  


  return 0;
}

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

int main(){
    int N, i;
    string S;

    cin >> N >> S;
    if(N % 2 == 1){
        cout << "No" << endl;
    }else{
        N /= 2;
        for(i = 0; i < N; i++){
            if(S[i] != S[N + i])break;
        }
        if(i == N)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  int n; cin >> n;
  vector <ll> a(n);
  vector <int> cnt(100001, 0);
  for(auto &x : a) {
    cin >> x;
    cnt[x]++;
  }
  int q; cin >> q;
  ll sum = accumulate(all(a), 0ll);
  while(q--) {
    ll b, c; cin >> b >> c;
    sum -= b * cnt[b];
    sum += c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    print(sum);
  }
}

int main() {
  int t; t = 1;
  while(t--) solve();
}




Measured memory_bytes: 4556
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



inline double sq(double a) { return a*a; }

int n, k;
double a[25], b[25], c[25];

int main() {
    while (cin >> n >> k) {
        double res = 0.0;
        for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
        if (k > 0) {
        for (int bit = (1<<k)-1, BX, BY; bit < (1<<n); BX = bit&-bit, BY = bit+BX, bit = ((bit&~BY)/BX>>1)|BY) {
            double tmp = 0.0;
            for (int i = 0; i < n; ++i) if (bit & (1<<i)) 
                for (int j = i+1; j < n; ++j) if (bit & (1<<j))
                    tmp += sq(a[i]-a[j]) + sq(b[i]-b[j]) + sq(c[i]-c[j]);
            chmax(res, tmp);
        }
        }
        cout << fixed << setprecision(9) << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1288
/**
 * Created by ysh on 2017/10/31.
 */
import java.util.Scanner;

public class Main{
    public static int[] dx = {-1,0,1,0};
    public static int[] dy = {0, 1, 0, -1};
    public static void solve(char[][] maze, int x, int y)
    {
        char temp = maze[x][y];
        maze[x][y] = '.';
        for (int i=0;i<4;i++)
        {
            int new_x = x+dx[i];
            int new_y = y+dy[i];
            if (new_x < 0 || new_x >= maze.length || new_y < 0 || new_y >= maze[0].length)
                continue;
            if(maze[new_x][new_y] == temp)
            {
                solve(maze, new_x, new_y);
            }
        }

    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int x,y;
        while(true)
        {
            String l = sc.nextLine();
            String[] nums = l.split("\\s+");
            if(nums.length == 2 && nums[0].equals("0") && nums[1].equals("0"))
                return;
            int h = Integer.parseInt(nums[0]);
            int w = Integer.parseInt(nums[1]);
            char[][] maze = new char[h][w];
            for(int i = 0;i< h;i++)
            {
                String s = sc.nextLine();
                for(int j=0;j<w;j++)
                {
                    maze[i][j] = s.charAt(j);
                }
            }
            int res =0;
            for(int i=0;i<h;i++) {
                for (int j = 0; j < w; j++) {
                    if (maze[i][j] != '.')
                    {
                        solve(maze, i,j);
                        res++;
                    }
                }
            }
            System.out.println(res);
        }
    }
}

Measured memory_bytes: 28348
#include <iostream>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>

using namespace std;
using namespace boost;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

int main() {
    int n;
    cin >> n;
    adjacency_list<listS, vecS, directedS, no_property,
                   property<edge_weight_t, long long>>
        graph1(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        add_edge(a, b, c, graph1);
        add_edge(b, a, c, graph1);
    }

    int q, k;
    cin >> q >> k;
    --k;
    vector<PII> v(q);

    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        v[i] = {x - 1, y - 1};
    }

    // k からの最短距離を求める
    vector<long long> distances1(n);
    vector<int> parents1(n);
    dijkstra_shortest_paths(
        graph1, k,
        distance_map(distances1.data()).predecessor_map(parents1.data()));
    for (auto a : v) {
        cout << distances1[a.first] + distances1[a.second] << endl;
    }
    return 0;
}

Measured memory_bytes: 22136
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  random_device rd;
  mt19937 mt(rd());
  uniform_int_distribution<ll> a(1,26);
  vector<ll> day(26);
  vector<pair<ll,ll>> c(26);
  ll d;
  cin >> d;
  rep(i,26) {
    ll t;
    cin >> t;
    c[i] = pair(t,i);
  }
  Sort(c);
  ll p = 0;
  rep(i,26) {
    if (c[i].first < 90) {
      p = i;
      break;
    }
  }
  ll cnt = 0;
  while (1) {
    rep(i,p) {
      cout << c[i].second +1 << '\n';
      ++cnt;
      if (cnt >= 365) {
        return 0;
      }
    }
    rep(i,(26-p)/2) {
      cout << c[i+p].second +1 << '\n';
      ++cnt;
      if (cnt >= 365) {
        return 0;
      }
    }
    rep(i,p) {
      cout << c[i].second +1 << '\n';
      ++cnt;
      if (cnt >= 365) {
        return 0;
      }
    }
    rep(i,((26-p)+1)/2) {
      cout << c[i+p+(26-p)/2].second +1 << '\n';
      ++cnt;
      if (cnt >= 365) {
        return 0;
      }
    }
  }  
}

Measured memory_bytes: 3680
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 終了後に自力AC 
#
# カードを「Aより小さい」「Aに等しい」「Aより大きい」に分ける。
#
# 「Aより小さい」カードで「和がSになる組み合わせの数」は容易に計算できる。
# 「Aより大きい」カードで「和がTになる組み合わせの数」も計算できる。
#
# あとはこれらを組み合わせるだけ

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

lower = []
same = 0
upper = []
for x in Xs:
    if x < A:
        lower.append(A - x)
    elif x == A:
        same += 1
    else:
        upper.append(x - A)

def make_counter(nums):
    counter = Counter({0: 1})
    for n in nums:
        new_counter = Counter()
        for k, v in counter.items():
            # 使う場合、使わない場合それぞれの場合の数を増やす
            new_counter[k] += v
            new_counter[k + n] += v
        counter = new_counter
    return counter

lower_counter = make_counter(lower)
upper_counter = make_counter(upper)

ans = 0
for lk, lv in lower_counter.items():
    # (i) Aに等しい数だけ使う
    if lk == 0:
        # ひとつも選ばれない場合を除くために-1
        ans += 2 ** same - 1
    # (ii) それ以外
    else:
        # Aより小さい数たちと、Aより大きい数たちとの集合の平均がちょうどA
        if lk in upper_counter:
            ans += (2 ** same) * lv * upper_counter[lk]

print(ans)


Measured memory_bytes: 5680
#include <iostream>

using namespace std;
int bubbleSort(int A[],int N)
{
    int sw=0;
    bool flag=1;
    for(int i=0;flag;i++)
    {
        flag=0;
        for(int j=N-1;j>=i+1;j--)
        {
            if(A[j]<A[j-1])
            {
                swap(A[j],A[j-1]);
                flag=1;
                sw++;
            }
        }
    }
    return sw;
}

int main()
{
    int A[100],N,sw;
    cin >>N;
    for(int i=0;i<N;i++) cin>>A[i];

    sw=bubbleSort(A,N);

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

    return 0;
}



Measured memory_bytes: 3096
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;


int main() {
  int A, B, T;

  cin >> A >> B >> T;
  cout << (T / A) * B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double


int32_t main()
{
	
	IOS
	int n,ans=LLONG_MIN;cin>>n;
	vector<pair<float,pair<int,int>>>A(n);
	for(int i=0;i<n;i++)cin>>A[i].second.first;
	for(int i=0;i<n;i++)cin>>A[i].second.second;
	for(int i=0;i<n;i++)
	{
		A[i].first=(float)A[i].second.first/(float)A[i].second.second;
	}
	
	sort(A.rbegin(),A.rend());
	for(int i=0;i<n;i++)
	{
		int v=0,c=0;
		for(int j=0;j<n;j++)
		{
			v+=A[j].second.first;
			c+=A[j].second.second;
			ans=max(ans,v-c);
		}
		
	}
	cout<<max(ans,0LL)<<endl;
			

	
	
			
	
		
			
	
		
	
	
}			
	
	
	
	
	

	

	

	
		


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

int main() {
int h,w;
cin >> h >> w;
vector<string> a(h);
vector<int> dx = {1,1,0,-1,-1,-1,0,1};
vector<int> dy = {0,1,1,1,0,-1,-1,-1};
rep(i,h) cin >> a.at(i);
rep(i,h)rep(j,w)if(a.at(i).at(j) == '.'){
    int cnt = 0;
    rep(k,8){
      int x = i +dx.at(k);
      int y = j +dy.at(k);
      if(x >= 0 && x < h && y >= 0 && y < w && a.at(x).at(y) == '#') cnt++;     
      }
      a.at(i).at(j) = '0' + cnt;
    }

rep(i,h) cout << a.at(i) << endl;
 }


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
    int n;
    int maxnum=0;
    int sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        int tmp;
        cin>>tmp;
        maxnum=max(maxnum,tmp);
        sum+=tmp;
    }
    if(sum-maxnum>maxnum) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

int main(){
    int N; cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++){
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int res = 0;
    for (int i = 0; i < N-2; i++){
        for (int j = i+1; j < N-1; j++){
            int sum = L[i]+L[j];
            int now = lower_bound(L.begin()+j, L.end(), sum) - L.begin();
            res += max(now-j-1, 0);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

//図形sと図形cの数がそれぞれ与えられる(1≦s,c≦10^12)
//cを2つ組み合わせてsを作ることができる
// "scc"がいくつ作れるかを出力する

int main(void){

    long long s,c;
    cin >> s >> c;

    //sの数だけsccが作れるだけのcの数(理想のc)
    long long idealC = s*2;
    //足りないcの数
    long long lackC = idealC - c;

    long long ans = 0;

    if(idealC <= c){  //cの数が理想のcより多い時
        c -= idealC;
        ans = s;
    }else{            //cが足りない時
        c = 0;
        ans = s;
        //足し過ぎた分引く
        ans -= (lackC+1)/2;
    }
    
    //cが余っている場合4つで"scc"が作れる
    ans += c / 4;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
l=[]
for _ in range(N):
  L=list(map(int,input().split()))
  l.append(L)
dp=[[0 for i in range(W+1)] for i in range(N+1)]
for i in range(1,N+1):
  for j in range(W+1):
    if j>=l[i-1][0]:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
    else:dp[i][j]=dp[i-1][j]
print(dp[N][W])


Measured memory_bytes: 171784
# -*- coding: utf-8 -*-
#ABC112C
import sys

n = int(input())

x = []
y = []
h = []
for i in range(0,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	x.append(hoge[0])
	y.append(hoge[1])
	h.append(hoge[2])

distance=0
height=0

m=0
while(h[m]==0):
	m+=1
for i in range(0,101):
	for j in range(0,101):
		distance=abs(i-x[m])
		distance+=abs(j-y[m])
		height=distance+h[m]
		for k in range(0,n):
			distance=abs(i-x[k])
			distance+=abs(j-y[k])
			if(max(height-distance,0)!=h[k]):
				break
			if(k==n-1):
				print(i,j,height)
				sys.exit()

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a >= b && a >= c){
    cout << a * 10 + b + c << endl;
  }else if(b >= a && b >= c){
    cout << a + b * 10 + c << endl;
  }else{
    cout << a + b + c * 10 << endl;
  }
}


Measured memory_bytes: 256
s = gets.chomp
ans = 'No'
if s == s.reverse
  if s[0..(s.size-1)/2-1] == s[0..(s.size-1)/2-1].reverse
    if s[(s.size+1)/2..-1] == s[(s.size+1)/2..-1].reverse
      ans = 'Yes'
    end
  end
end

puts ans

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

int main() {
   
  int n, ans = 0;
  string s, s2 = "ABC";
  
  cin >> n;
  cin >> s;
  
  int cnt = 0;
    
  for(int i=0; i< n-2; i++) {
    
        if(s.substr(i, 3) == s2) {
          
          ans++;
        
        }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
;
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PI 3.14159265358979323846
using namespace std;

void debugV(vector<int>& deV) {
    for (int i = 0; i < (signed)deV.size(); i++) {
        cout << "[" << i << "]= " << deV[i] << ",";
    }
    cout  <<endl ;
}

void debugVV(vector<vector<int> >& deV) {
    for (int i = 0; i < (signed)deV.size(); i++) {
        cout << i << " ";
        for (int j = 0; j < (signed)deV[i].size(); j++) {
            cout << "[" << j << "]= " << deV[i][j] << ",";
        }
        cout << endl;
    }
}

// typedef tuple<int, int, int, int> mytuple;

// bool mycompare( const mytuple &lhs, const mytuple &rhs )
// {
//     if ( get<3>(lhs) !=  get<3>(rhs)) return  get<3>(lhs) <  get<3>(rhs);
//     if ( get<2>(lhs) !=  get<2>(rhs)) return  get<2>(lhs) <  get<2>(rhs);
//     return  get<1>(lhs) <  get<1>(rhs);
// }
int n, m, q;
vector<int> SSS;

int saiki(const vector<vector<int> >& S, int d, int bf) {
    int mx = 0;
    if (d == n) {
   //     debugV(SSS);
        int d = 0;
        REP(ii, q) {
            if (SSS[S[1][ii] - 1] - SSS[S[0][ii] - 1] == S[2][ii]) {
                d += S[3][ii];
            }
        }
 //       cout << " Score = " << d << endl;
        return d;
    }
    for (int i = bf; i <= m; i++) {
        SSS[d] = i;
        mx = max(mx, saiki(S, d + 1, i));
    }
    return mx;
}

signed main() {
    cin >> n >> m >> q;
    // n = 4;
    // m = 5;
    // q = 5;
    int ans = 0;
    vector<int> A(n);
    vector<vector<int> > S(4, vector<int>(q));
    REP(i, q) {
        REP(j, 4) { cin >> S[j][i]; }
    }
    SSS.resize(n);

    cout << saiki(S, 0, 1) << endl;

    // REP(j, n) {
    //     int bf = 1;
    //     for (int i = bf; i <= m; i++) {
    //         SSS[i] = i;
    //     }
    // }

    // REP(i, q){
    //     int aa,bb,cc,dd ;
    //     S.push_back(make_tuple(aa,bb,cc,dd));
    // }

    // sort(ALL(S),mycompare);

    // REP(i, q) {
    //   if ((get<1>(S[i]) - get<0>(S[i])) == get<3>(S[i])) {
    //     ans += get<3>(S[i]);
    //   }
    // }

    return 0;
}

Measured memory_bytes: 3576
//
//  ABC116B.cpp
//  programing
//
//  Created by 毛利源 on 2019/02/02.
//

#include<iostream>
using namespace std;


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

  int N_MAX =100000;
  int a[N_MAX];
	
  for (int i;i<N_MAX;i++){
  a[i] = 0;
  }
  int ans = 0;
  while(true){
   ans++;
   if (s%2 == 0){
     if(a[s] ==0 ){
       a[s] = 1;
   		s /= 2;
     }else{break;}
  }else{
        if(a[s] ==0 ){
       a[s] = 1;
   		 s = 3*s +1;
     }else{break;}
   }
  }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1n(i,n) for(int i=1; i<=(n); ++i)
#define repxn(i,x,n) for(int i=x; i<=(n); ++i)
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define INF 1001001001  // 浮動小数点型
#define INF_L 1001001001001001001  // 浮動小数点型
#define bit(n,m)(((n)>>(m))&1)  // nのmビット目が1
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
#define yn2 {puts("YES");}else{puts("NO");}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}

ll digit_sum(ll n) {
    ll res = 0;
    while(n > 0) {
        // res += n%10; //桁和
        res++; //桁数
        n /= 10;
    }
    return res;
}

int main() {
    ll n; cin>>n;
    ll ans = INF_L;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            mins(ans, max(digit_sum(i), digit_sum(n/i)));
        }
    }
    cout<<ans<<endl;
}

/*
g++ c.cpp
./a.out
./problem.exe
oj d
oj t

debug:ctrl+shift+B problemin

*/


Measured memory_bytes: 3568
N = int(input())

def func():
    for h in range(1, 3501):
        for n in range(1, 3501):
            temp1 = N * n * h
            temp2 = 4 * h * n - N * (n + h)
            if temp2 != 0:
                w = temp1 // temp2
                if w * temp2 == temp1 and w >= 1:
                    print(h, n, w)
                    return None
func()

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 2 * a << endl;
  }
  else if (a > b) {
    cout << 2 * a - 1 << endl;
  }
  else {
    cout << 2 * b - 1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[][] m = new int[n][2];
		int[][] dp = new int[n][n];
		for(int i=0;i<n;i++){
			Arrays.fill(dp[i], Integer.MAX_VALUE);
			dp[i][i] = 0;
			m[i][0] = sc.nextInt();
			m[i][1] = sc.nextInt();
		}
		
		for(int w=1;w<n;w++){
			for(int i=w;i<n;i++){
				for(int j=i-w;j<i;j++){
					int c = m[i-w][0]*m[j][1]*m[j+1][0]*m[i][1];
					dp[i-w][i] = Math.min(dp[i-w][i], dp[i-w][j]+dp[j+1][i]+c);
				}
			}
		}
		System.out.println(dp[0][n-1]);
	}
}

Measured memory_bytes: 21276
#include <bits/stdc++.h>
using namespace std;
int main() {
    int L,R;
    cin >> L >> R;
    int min=99999;

    for(int i=L; i<=R-1 && i<L+2050; i++){
        for(int j=i+1; j<=R && j<i+2050; j++){
            int a = i % 2019;
            int b = j % 2019;
            if((a*b)%2019 < min) min = (a*b)%2019;
        }
    }
    
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	void solve() {
		int n = nextInt();
		int[] v = new int[n];
		int[] c = new int[n];
		for(int i=0;i<n;i++)v[i]= nextInt();
		for(int i=0;i<n;i++)c[i]= nextInt();

		int res = 0;
		for(int i=0;i<n;i++)res += v[i]>c[i]?v[i]-c[i]:0;
		System.out.println(res);
	}

	private int nextInt() {
		return Integer.parseInt(sc.next());
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    int n;
    cin >> n;
    int a[3 * n + 5];
    rep(i, 3 * n){
      cin >> a[i];
    }
    sort(a, a +(3 * n),greater<int> ());
    lol sum = 0;
    rep(i, n){
      sum += a[i * 2 + 1];
    }
    cout << sum << '\n';
    return 0;
} 


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll m,k;cin >> m >>k;
    if(m==1){
        if(k==0)cout << 0 <<" " <<0 <<" " << 1 <<" " << 1<<endl;
        else cout << -1 <<endl;
    }
    else{
        if(k>=(1LL<<m))cout << -1 <<endl;
        else{
            rep(i,1LL<<m){
                if(i==k)continue;
                cout << i <<" ";
            }
            cout << k <<" ";
            per(i,(1LL<<m)){
                if(i==k)continue;
                cout << i <<" ";
            }
            cout << k <<endl;
        }
    }
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        A,B=map(int,input().split())
        for i in range(1,4):
            if (A*B*i)%2==1:
                return 'Yes'
        return 'No'
    print(main())

resolve()

Measured memory_bytes: 38256
def p(x,n,s):
    return int(n*((x-s/n)**2)-(s**2)/n)

n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ds=0
for num in l:
    ds+=num**2
ans=ds+min(p(s//n,n,s),p(s//n+1,n,s))
print(ans)

Measured memory_bytes: 3064
N = int(input())
L = list(map(int, input().split()))

cnt = 0

for i in range(N-2):
    for j in range(i+1, N):
        if(L[i] == L[j]):
            continue
        for k in range(j+1, N):
            if(L[j] == L[k] or L[k] == L[i]):
                continue
            
            if(L[i]+L[j] > L[k] and L[j]+L[k] > L[i] and L[k]+L[i] > L[j]):
                cnt += 1
                
print(cnt)

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

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int flag = 0;
  for(int i=n-1;i>0;i--){
    if(a[i] < a[i-1])
      a[i-1]--;
    if(a[i-1] > a[i]){
      flag = 1;
      break;
    }
  }
  if(flag == 1)
    cout<<"No";
  else{
    for(int i=0;i<n-1;i++){
      if(a[i]>a[i+1]){
        flag = 1;
        break;
      }
    }
    if(flag)
      cout<<"No";
    else
      cout<<"Yes";
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


int b[30];
int a[30][30];
int N, M, C;
int main(){
  cin >> N >> M >> C;
  rep(i,M) cin >> b[i];
  rep(i,N){
    rep(j,M) cin >> a[i][j];
  }
  
  int ans = 0;
  rep(i,N){
    int val = C;
    rep(j,M){
      val += a[i][j] * b[j];
    }
    if(val > 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i=0; i<(int) (n);i++)
using ll = long long;
using P = pair<int, int>;

void solve_1() {//14m
	int a, b;
	cin >> a >> b;
	int total;
	int n = 0;
	while (!((a-1)*n + 1 >= b)) {
		n++;
	}
	cout << n << endl;

}

void solve_2() {//30m
	int n;
	cin >> n;
	vector<int> x;
	int total = 0;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		x.push_back(tmp);
		total += tmp;
	}
	int p1 = (double(total)/double(n)*2 - 1.0) / 2;
	int p2 = (double(total)/double(n)*2 - 1.0) / 2 + 1;
	int point_sum1 = 0, point_sum2= 0;
	rep(i, n) {
		point_sum1 += pow(x[i] - p1, 2);
		point_sum2 += pow(x[i] - p2, 2);
	}
	cout << min(point_sum1, point_sum2) << endl;

}

void solve_2re() {
	int n;
	cin >> n;
	vector<int> x(n);
	int total = 0;
	rep(i, n) {
		cin >> x[i];
		total += x[i];
	}
	int p1 = total / n;
	int p2 = total / n + 1;
	int point_sum1 = 0, point_sum2 = 0;
	rep(i, n) {
		point_sum1 += pow(x[i] - p1, 2);
		point_sum2 += pow(x[i] - p2, 2);
	}
	cout << min(point_sum1, point_sum2) << endl;
}

void solve_3() {

}

void solve_4() {

}

void solve_5() {

}

void solve_6() {

}

int main() {
	//solve_1();
	//solve_2();
	solve_2re();
	//solve_3();
	//solve_4();
	//solve_5();
	//solve_6();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cmath>

int main() {
	int64_t n;
	std::cin >> n;

	for (int64_t i = static_cast<int64_t>(std::sqrt(n)); i > 0; --i) {
		if (n % i == 0) {
			std::cout << static_cast<int64_t>(std::log10(n / i) + 1) << std::endl;
			break;
		}
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n,c,k,a[111111],cnt,last,ans;
int main()
{
	cin>>n>>c>>k;
	for(ll i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(ll i=1;i<=n;i++)
	{
		if(cnt==0||a[i]-last>k)
			cnt=c,last=a[i],ans++;
		cnt--;
	}
	cout<<ans;
}

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

int main(){
  int n;
  double answer;
  cin >> n;
  vector<int> data(n);
  for(int i=0; i<n; i++){
    cin >> data.at(i);
  }
  
  sort(data.begin(),data.end());
  answer = data.at(0);
  
  for(int i=1; i<n; i++){
    answer = (answer + data.at(i))/2.0;
  }
  
  cout << answer << endl;
}

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

int main() {
    vector<int> a(9);
    vector<bool> ab(9);

    for(int i = 0; i < 9; i++){
        cin >> a.at(i);
        ab.at(i) = false;
    }


    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int b;
        cin >> b;
        for(int j = 0; j < 9; j++){
            if (b == a.at(j)){
                ab.at(j) = true;
            }
        }
    }

bool ret = false;
    if (ab.at(0) && ab.at(1) && ab.at(2)){
        ret=true;
    }
    if (ab.at(3) && ab.at(4) && ab.at(5)){
        ret=true;
    }
    if (ab.at(6) && ab.at(7) && ab.at(8)){
        ret=true;
    }
    if (ab.at(0) && ab.at(3) && ab.at(6)){
        ret=true;
    }
    if (ab.at(1) && ab.at(4) && ab.at(7)){
        ret=true;
    }
    if (ab.at(2) && ab.at(5) && ab.at(8)){
        ret=true;
    }
    if (ab.at(0) && ab.at(4) && ab.at(8)){
        ret=true;
    }
    if (ab.at(2) && ab.at(4) && ab.at(6)){
        ret=true;
    }

    cout << (ret ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#ABC173-B
N = int(input())
S = list()
for i in range(N):
 S.append(str(input()))
A = S.count("AC")
W = S.count("WA")
T = S.count("TLE")
R = S.count("RE")
print("AC x {}\nWA x {}\nTLE x {}\nRE x {}".format(A,W,T,R))

Measured memory_bytes: 16284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> drinks(n+10);
    rep(i, n) {
        cin >> drinks[i].first >> drinks[i].second;
    }
    sort(drinks.begin(), drinks.end());

    ll cost = 0, bottles = 0;
    ll i = 0;
    while(true) {
        cost += drinks[i].first * drinks[i].second;
        bottles += drinks[i].second;
        if (bottles > m) break;
        i++;       
    }
    ll yobun = bottles - m;
    cost -= drinks[i].first * yobun;
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[100100];
vector<pii> candidates;

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    rep(i, N) {
        int x = A[i];
        int y1 = *l_b(A, A + N, x / 2);
        int y2 = *(l_b(A, A + N, x / 2) - 1);
        int y;
        if (x == y1)y = y2;
        else if (x == y2)y = y1;
        else if (y1 - 1. * x / 2 <= 1. * x / 2 - y2)y = y1;
        else y = y2;
        candidates.emplace_back(x, y);
    }
    sort(candidates.begin(), candidates.end());
    cout << candidates[candidates.size() - 1].first << " " << candidates[candidates.size() - 1].second << endl;
    return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <array>

using namespace std;

#define ll long long
#define all(v) v.begin(),v.end()
#define bootstrap ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// custom hash can be a standalone function object:
struct MyHash
{
    std::size_t operator()(pair<long, long> const& p) const noexcept
    {
        std::size_t h1 = std::hash<long>{}(p.first);
        std::size_t h2 = std::hash<long>{}(p.second);
        return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion)
    }
};

struct MyComp
{
    template<typename T>
    std::size_t operator()(T &l, T &r) const noexcept
    {
        return l < r;
    }
};

void solve() {
    string s;
    cin >> s;
    if(s.at(s.size()-1) == 's') {
        cout << s << "es"<< endl;
    } else {
        cout << s << "s" << endl;
    }
}

int main() {
    bootstrap
    solve();
}


Measured memory_bytes: 3060
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        mut s: String,
    }

    println!("{}", &s[0..3]);
}


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

using namespace std;


int main() {

    int R, G, B, N;
    cin >> R >> G >> B >> N;
    long long ans = 0;
    int MAX = N + 1;
    for (int i = 0; i < MAX; ++i) {
        for (int j = 0; j < MAX; ++j) {
            long long balls = i * R + j * G;
            if ((N - balls) % B == 0 && (N - balls) / B >= 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int a,b;
    cin >> a >> b;

    int plug=1;
    int tap=0;
    while(plug<b){
        tap++;
        plug=plug-1+a;
    }

    cout << tap << endl;

    return 0;
}


Measured memory_bytes: 3552
N = int(input())
h = [0] + list(map(int, input().split())) + [0]
counter = 0
fin = [0 for _ in range(N+2)]

while not h == fin:
    for i in range(1, N+2):
        if h[i] == 0 and not h[i-1] == 0:
            counter += 1
    for i in range(1, N+1):
        if not h[i] == 0:
            h[i] -= 1


print(counter)


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b&&a>c)
	{
		if(b>c)
		printf("%d %d %d",c,b,a);
		else
		printf("%d %d %d",b,c,a);	
	}
	else if(b>a&&b>c)
	{
		if(a>c)
		printf("%d %d %d",c,a,b);
		else		
		printf("%d %d %d",a,c,b);		
	}
	else if(c>a&&c>b)
	{
		if(a>b)
		printf("%d %d %d",b,a,c);
		else
		printf("%d %d %d",a,b,c);
	}
	printf("\n");
	return 0;
} 


Measured memory_bytes: 2072