akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;
        int Q = cin.nextint;
        var dp = new int[N, N];
        for (int i = 0; i < M; i++)
        {
            dp[cin.nextint - 1, cin.nextint - 1]++;
        }
        for (int i = 1; i < N; i++)
        {
            for (int j = 0; j + i < N; j++)
            {
                if (i == 1) dp[j, j + 1] += dp[j, j] + dp[j + 1, j + 1];
                else dp[j, j + i] += dp[j, j + i - 1] + dp[j + 1, j + i] - dp[j + 1, j + i - 1];
            }
        }

        for (int i = 0; i < Q; i++)
        {
            WriteLine(dp[cin.nextint - 1, cin.nextint - 1]);
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 16548
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  rep(i, N-1) {
    if(H[i] < H[i+1])
      H[i+1]--;
    else if(H[i] > H[i+1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
using namespace std;

signed main() {
	int n,mu=0;
	vector<int> ta;
	map<int,int> mp;
	mp[0]=1;
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		mu+=a;
		ta.push_back(mu);
	}
	int ans=0;
	vsort(ta);
	rep(i,n){
		ans+=mp[ta[i]];
		mp[ta[i]]++;
	}
	cout<<ans<<endl;
}

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

string A[9];
int H, W;
bool ok = false;

void go(int x, int y, int num, int total_s) {
    if (num == total_s) ok = true;
    else if (!ok) {
        if (x < W-1 && A[y][x+1] == '#') {
            go(x+1, y, num+1, total_s);
        }
        if (y < H-1 && A[y+1][x] == '#') {
            go(x, y+1, num+1, total_s);
        }
    }
}

int main() {
    cin >> H >> W;
    rep(i, H) cin >> A[i];

    int total_s = 0;
    rep(i, H) rep(j, W) if (A[i][j] == '#') total_s++;

    go(0, 0, 1, total_s);

    if (ok) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = 0;
		int x = 0;
		int y = 0;
		for(int i=0;i<n;i++) {
			int nextt = sc.nextInt();
			int nextx = sc.nextInt();
			int nexty = sc.nextInt();
			
			int dt = nextt - t;
			int dist = Math.abs(nextx-x) + Math.abs(nexty-y);
			if(dt<dist || ((dist-dt)%2 != 0)) {
				System.out.println("No");
				return;
			}
			t = nextt;
			x = nextx;
			y = nexty;
		}
		System.out.println("Yes");
	}

}

Measured memory_bytes: 87168
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int p[100005], q[100005];
long long sum[100005];
int main() {
    int w, h;
    long long ans = 0;
    scanf("%d%d", &w, &h);
    for (int i = 0; i < w; ++i) {
        scanf("%d", &p[i]);
        ans += p[i];
    }
    for (int i = 0; i < h; ++i) {
        scanf("%d", &q[i]);
    }
    sort(p, p + w);
    sum[0] = p[0];
    for (int i = 1; i < w; ++i) {
        sum[i] = sum[i - 1] + p[i];
    }
    for (int i = 0; i < h; ++i) {
        int u = lower_bound(p, p + w, q[i]) - p;
        if (u > 0) {
            ans += sum[u - 1];
        }
        ans += ((long long)(w - u + 1)) * q[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())

AB = sorted([list(map(int, input().split())) for _ in range(N)])

ans = 0
honsu = 0

for a, b in AB:
    if M - honsu > b:
        ans += a * b
        honsu += b
    else:
        ans += a * (M - honsu)
        honsu += M - honsu
    if M == honsu:
        break

print(ans)


Measured memory_bytes: 28656
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    h_list = list(map(int, input().split()))

    dp = [0]

    for i in range(n):
        dp.append(9999999999)
        if i > 0:
            dp[i] = min(dp[i], dp[i - 1] + abs(h_list[i] - h_list[i - 1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i - 2] + abs(h_list[i] - h_list[i - 2]))

    print(dp[-2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 13976
//  Created by Sengxian on 2017/6/18.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline int readInt() {
	int n = 0, ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
	return n;
}

const int MAX_N = 100000 + 3;
int n, a[MAX_N];

int main() {
	n = readInt();
	for (int i = 0; i < n; ++i) a[i] = readInt();
	bool same = true;
	for (int i = 0; i < n - 1; ++i) if (a[i] != a[i + 1]) same = false;
	
	if (same) puts((a[0] == n - 1) || a[0] <= n / 2 ? "Yes" : "No");
	else {
		int mx = INT_MIN, mn = INT_MAX;
		for (int i = 0; i < n; ++i) {
			mx = max(mx, a[i]);
			mn = min(mn, a[i]);
		}
		if (abs(mx - mn) > 1) return puts("No"), 0;
		int cnt1 = 0, cnt2 = 0;
		for (int i = 0; i < n; ++i) if (a[i] == mn) ++cnt1;
		cnt2 = n - cnt1;
		// [cnt1 + 1, cnt1 + cnt2 / 2];
		if (mx >= cnt1 + 1 && mx <= cnt1 + cnt2 / 2) puts("Yes");
		else puts("No");
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
//#include <tr1/unordered_set>
//#include <tr1/unordered_map>
#include <bitset>
#include <cassert>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define inf 1e9
#define debug(a) cout << #a" = " << (a) << endl;
#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }
#define clr(x, y) memset(x, y, sizeof x)
#define LL long long
#define uLL unsigned LL

using namespace std;
struct FFF
{
    LL n,d;
}f[10];
bool cmp(FFF a,FFF b)
{
    return a.n*b.d<b.n*a.d;
}
bool equ(FFF a,FFF b)
{
    return a.n*b.d==b.n*a.d;
}
void norm(FFF &a)
{
    if(a.n<=0&&a.d<=0)
    {
        a.n*=-1;
        a.d*=-1;
    }
    int g=__gcd(a.n,a.d);
    a.n/=g;
    a.d/=g;
}
bool check(FFF a)
{
    return a.n>=0&&a.d>0&&a.n<a.d*60;
}
int solve(LL H,LL h,LL m)
{
    int cnt=0;
    FFF s,ns,nn;
    ns.n=3600*h+60*m-60*m*H;
    ns.d=H-1;
    norm(ns);

    s.d=119*H-1;
    s.n=3600*h+60*m+60*m*H;
    norm(s);
  //  print(s);
    if(check(s)&&!equ(ns,s))
        f[cnt++]=s;

    s.d=119*H-1;
    s.n=3600*h+60*m+60*m*H-3600*H;
    norm(s);
  //  print(s);
    if(check(s)&&!equ(ns,s)&&s.n<s.d*30)
        f[cnt++]=s;

    s.d=119*H-1;
    s.n=3600*h+60*m+60*m*H+3600*H;
    norm(s);
  //  print(s);
    if(check(s)&&!equ(ns,s)&&s.n>=s.d*30)
        f[cnt++]=s;
    sort(f,f+cnt,cmp);
   // printf("#####\n");
    return cnt;
}
void inc(LL &H,LL &h,LL &m)
{
    m++;
    if(m>=60)
    {
        m%=60;
        h++;
        if(h>=H)
        {
            h%=H;
        }
    }
}
int main()
{
    LL H,h,m,s;
   // freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
    while(scanf("%lld%lld%lld%lld",&H,&h,&m,&s)&&(H||h||m||s))
    {
        int cnt=solve(H,h,m);
        FFF in;
        in.n=s; in.d=1;
        int flag=0;
      //  printf("cnt = %d\n",cnt);
        for(int i=0;i<cnt;i++)
        {
          //  print(f[i]);
            if(!cmp(f[i],in))
            {
                flag=1;
                printf("%lld %lld %lld %lld\n",h,m,f[i].n,f[i].d);
                break;
            }
        }
        while(!flag)
        {
            inc(H,h,m);
            int cnt=solve(H,h,m);
            if(cnt!=0)
            {
                printf("%lld %lld %lld %lld\n",h,m,f[0].n,f[0].d);
                flag=1;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1208
import java.io.IOException;
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			d = new int[n][n];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					d[i][j] = scanner.nextInt();
			int max = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					d[i][j] = Math.max(d[i][j], d[j][i]);
					max = Math.max(max, d[i][j]);
				}
			ans = INF;
			pos = new int[n];
			bitSet = new BitSet();
			dfs(0);
			System.out.println(ans);
		}
	}

	private void dfs(int right) {
		if (ans <= right)
			return;

		if (bitSet.cardinality() == n) {
			ans = right;
			return;
		}
		for (int i = 0; i < n; i++) {
			if(bitSet.get(i))
				continue;
			bitSet.set(i);
			for (int j = 0; j < n; j++) {
				if (bitSet.get(j))
					pos[i] = Math.max(pos[i], pos[j] + d[j][i]);
			}
			dfs(pos[i]);
			bitSet.clear(i);
			pos[i] = 0;
		}
	}

	int n, ans;
	int[] pos;
	int[][] d;
	int INF = 1 << 30;
	BitSet bitSet;
}

Measured memory_bytes: 30316
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n;
int t[16][17];
int x[1 << 16];

int dfs(int i){
	if(x[i] != -1){
		return x[i];
	}
	int p = 2e6;
	rep(j, n){
		if((i >> j) & 1){
			int s = i - (1 << j);
			int q = t[j][0];
			rep(k, n){
				if((s >> k) & 1){
					q = min(t[j][k + 1], q);
				}
			}
			p = min(q + dfs(s), p);
		}
	}
	return x[i] = p;
}

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		}
		rep(i, n){
			rep(j, n + 1){
				scanf("%d", &t[i][j]);
			}
		}
		fill_n(x, 1 << n, -1);
		x[0] = 0;
		printf("%d\n", dfs((1 << n) - 1));
	}
	return 0;
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

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

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

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

	int cost[n];
	cost[0] = 0;

	for(int i = 1; i < n; i++){
		cost[i] = INT_MAX;
		for(int j = 1; j <= k and i-j >= 0; j++){
			cost[i] = min(cost[i-j] + abs(h[i] - h[i-j]), cost[i]);	
		}
	}

	cout << cost[n-1] << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		VI as( n );
		FOR( a, as )
		{
			cin >> a;
		}

		sort( ALL( as ) );
		cout << accumulate( as.begin() + 1, as.end() -1, 0 ) / ( n - 2 ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
long long int inf = 1e18;

int main() {

  int n, m; cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  vector<bool> c(n+1, false);
  vector<bool> d(n+1, false);
  for(int i=0; i<m; i++){
    cin >> a[i] >> b[i];
    if( a[i] == 1 ){
      c[ b[i] ] = true;
    }else if( b[i] == 1 ){
      c[ a[i] ] = true;
    }else if( a[i] == n ){
      d[ b[i] ] = true;
    }else if( b[i] == n ){
      d[ a[i] ] = true;
    }
  }

  bool f = false;
  for(int i=1; i<=n; i++){
    if( c[i] && d[i] ) f = true;
  }

  cout << (f ? "POSSIBLE" : "IMPOSSIBLE") << endl;


  return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,x;
    scanf("%d",&n);
 
    for(int i = 1; i<= n; i++)
    {
        if(i%3 == 0){
            printf(" %d",i);
        }else{
            x = i;
            do{
                if(x%10 == 3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }while(x);
        }
    }
    printf("\n");
}


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

const int N = 100 * 1000 + 20, mod = 1e9 + 7;
int a[N], n, k, fact[N], factRev[N], ans;

int sum(int a, int b) {
  	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int a, int b) {
  	return ((1LL * a * b) % mod + mod) % mod;
}

int pw(int a, int b) {
	int res = 1, tmp = a;
  	while (b) {
      	if (b & 1)
          	res = mul(res, tmp);
      	tmp = mul(tmp, tmp);
      	b >>= 1;
    }
  	return res;
}

int c(int a, int b) {
	return a >= b? mul(fact[a], mul(factRev[b], factRev[a - b])): 0;
}

void prepros() {
	fact[0] = 1;
  	for (int i = 1; i < N; i++)
      	fact[i] = mul(fact[i - 1], i);
 	factRev[N - 1] = pw(fact[N - 1], mod - 2);
  	for (int i = N - 2; ~i; i--)
      	factRev[i] = mul(factRev[i + 1], i + 1);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  	cin >> n >> k;
  	for (int i = 0; i < n; i++)
      	cin >> a[i];
 	prepros();
  	sort(a, a + n);
  	for (int i = k - 1; i < n; i++)
    	ans = sum(ans, mul(c(i, k - 1), a[i]));
    reverse(a, a + n);
    for (int i = k - 1; i < n; i++)
    	ans = sum(ans, mul(c(i, k - 1), -a[i]));
  	cout << ans << "\n";
}

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

/*两个点必定有一条通路，如果后面没有相连的，那么肯定和前面的某个点相同
而我要找的是走过点最多的通路，所以先拓扑排好序，按照各点出现先后顺序dp*/
//证明：https://blog.csdn.net/jk_chen_acmer/article/details/104533994?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-4 

int dp[100005],in[100005];
queue<int> que;
vector<int>edge[100005];
	
signed main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		in[y]++,edge[x].push_back(y);
	}
	
	for(int i=1;i<=n;i++)
	if(in[i]==0)que.push(i);
	
	while(!que.empty()){
		int now=que.front();
		que.pop();
		for(int i=0;i<edge[now].size();i++){//先后滚动 
			dp[edge[now][i]]=max(dp[edge[now][i]],dp[now]+1);//最长路要么有他，要么没有他是其他点组成的 
			in[edge[now][i]]--;
			if(in[edge[now][i]]==0)
			que.push(edge[now][i]);
		}
	}
	
	int ans=0;
	for(int i=1;i<=n;i++)
	ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 9644
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) (v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int MAXN = 100001;

int prime[MAXN];

void sieve(){
    prime[1] = 1;
    for (int i=2; i<MAXN; i++)
        prime[i] = i;

    for (int i=4; i<MAXN; i+=2)
        prime[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (prime[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
                if (prime[j]==j)
                    prime[j] = i;
        }
    }
}

vector<int> getFactorization(ll x){
    vector<int> ret;
    while (x != 1)
    {
        ret.push_back(prime[x]);
        x = x / prime[x];
    }
    return ret;
}

vector<ll> primeFactors(ll n)  {
	vector<ll> res;
    while (n % 2 == 0)  {
    	res.push_back(2);
        n = n/2;
    }
    for (ll i = 3; i * i <= n; i = i + 2)  {
        while (n % i == 0)  {
            res.push_back(i);
            n = n/i;
        }
    }
    if (n > 2)
        res.push_back(n);
    return res;
}


int main(){
        _
        ll n; cin >> n;
        vll fac = primeFactors(n);
        sort(all(fac));
        int m = fac.size();
        int i=0;
        int res = 0;
        while (i < m) {
            ll cur = fac[i];
            int ct = 0;
            while (i < m && cur == fac[i]) {
                ct++;
                i++;
            }
            int sum = 0, c = 0;
            while (true) {
                sum += c;
                if (sum  > ct) {
                    c--;
                    break;
                }
                c++;
            }
            res += c;
        }
        cout << res;




return 0;
}



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

int modu(int k){
  if (k<0)
    return -1*k;
  return k;
}

int mini(int a, int b){
  if (a<b)
    return a;
  return b;
}

int main(){
  int n,h[100001], arr[3];
  cin>>n;
  
  for (int i=0;i<n;i++){
    cin>>h[i];
  }
  
  arr[0]=0; 
  arr[1]=modu(h[0]-h[1]);
  
  for (int i=2;i<n;i++){
    arr[2] = mini(arr[0]+modu(h[i-2]-h[i]), arr[1]+modu(h[i-1]-h[i]));
    arr[0] = arr[1];
    arr[1] = arr[2];
  }
  cout<<arr[1];
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  string str;
  cin>>str;
  if(str[0] == str[2])
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
[A, B, C, K] = [int(i) for i in input().split()]

j1 = A - K
j2 = A + B - K
if j2 >0: # K < A + B
    if j1 < 0: #A > K
        print(A)
    else:
        print(K)
else:
    print(A + j2)

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

using namespace std;

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

int main() {
    int N;
    int ans;

    cin >> N;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (i==0) {
            ans = a;
        } else {
            ans = gcd(ans, a);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <string>
#include <set>
#include <iostream>
using namespace std;

int M;
string S;

int main( void ) {
	
	cin >> M;
	
	while ( M-- ) {
		
		cin >> S;
		
		typedef set<string> set_t;
		set_t all;
		all.insert( S );
		
		for ( size_t i = 1; i < S.size(); i++ ) {
			
			string L = S;
			L.resize( i );
			string R = S.substr( i );
			
			string L2 = L, R2 = R;
			reverse( L2.begin(), L2.end() );
			reverse( R2.begin(), R2.end() );
			
			all.insert( R + L );
			all.insert( R + L2 );
			all.insert( R2 + L );
			all.insert( R2 + L2 );
			all.insert( L + R );
			all.insert( L + R2 );
			all.insert( L2 + R );
			all.insert( L2 + R2 );
			
		}
		
		cout << all.size() << endl;
		
	}
	
	return 0;
	
}

Measured memory_bytes: 1292
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    int x; scanf("%d", &x);

    x-=400;
    x/=200;
    ll ans = 8-x;
    printf("%lld", ans);
}


Measured memory_bytes: 1720
#include <iostream>

using namespace std;

int main(){
        int a,b,c,d; cin>>a>>b>>c>>d;
        string ans = "No";
        if(abs(c-a)<=d || (abs(b-a)<=d&&abs(c-b)<=d)) ans = "Yes";
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
*/

main:-
    get_string(S),
    string_code(1, S, C),
    C2 is C + 1,
    char_code(A, C2),
    writeln(A).


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  string A, B;
  cin >> A >> B;
  ll ans = 0;
  REP(i, 3) if (A[i] == B[i]) ans++;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

void fnInput(int& rnMember, int& rnScore, vector<int>& rvnAnsMem)
{
  int nMemSiz, nAnsSiz;
  cin >> rnMember >> rnScore >> nAnsSiz;

  rvnAnsMem.resize(nAnsSiz);
  for (int& rnAnsMem : rvnAnsMem)
    cin >> rnAnsMem;
}

void fnScoreCheck(int nMember, int nScore, const vector<int>& cnrvnAnsMem)
{
  vector<int> vnMemScore(nMember + 1, nScore - cnrvnAnsMem.size());

  for (int nAnsMem : cnrvnAnsMem)
    vnMemScore[ nAnsMem ]++;

  for (int i = 1; i <vnMemScore.size(); i++)
    if (vnMemScore[i] > 0) cout << "Yes" << endl;
    else                   cout << "No"  << endl;
}

int main()
{
  int nMember, nScore;
  vector<int> vnAnsMem;

  fnInput(nMember, nScore, vnAnsMem);
  fnScoreCheck(nMember, nScore, vnAnsMem);

  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {

  int i, j;
  int h, w;

  while(1) {
    scanf("%d %d", &h, &w);

    if (h == 0 && w == 0) {
      break;
    } else {
      for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
          if ((i + j) % 2 == 0) {
            putchar('#');
          } else {
            putchar('.');
          }
        }
        putchar('\n');
      }
      putchar('\n');
    }
  }

  return 0;
}



Measured memory_bytes: 2124
using System;
using System.Collections.Generic;
using System.Linq;

//AGC004-A-Divide a Cuboid
//http://agc004.contest.atcoder.jp/tasks/agc004_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 3 3");
            //9
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 2 4");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 3 5");
            //15
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray();
        long A = wkArr[0];
        long B = wkArr[1];
        long C = wkArr[2];

        //偶数の軸がある場合
        if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
            Console.WriteLine(0);
            return;
        }

        //Aで分割する場合
        long wkProd1 = B * C;

        //Bで分割する場合
        long wkProd2 = A * C;

        //Cで分割する場合
        long wkProd3 = A * B;

        long Answer = Math.Min(wkProd1, wkProd2);
        Answer = Math.Min(Answer, wkProd3);
        Console.WriteLine(Answer);
    }
}


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

int main(){
    string s;
    cin >> s;
    ll c = 0;
    rep(i, 0, 3){
        if(s[i] == 'A') c++;
    }
    if(c == 0 || c == 3) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]

INF = int(10e8 + 1)
dp = [INF] * (1 << n)
dp[0] = 0

for j in range(m):
    cost = int(input().split()[0])

    boxes = [int(x)-1 for x in input().split()]
    mask = 0

    mask = sum(1 << box for box in boxes)
    
    for i in range(1 << n):
        if dp[i] + cost < dp[i | mask]:
            dp[i | mask] = dp[i] + cost

res = dp[-1] if dp[-1] != INF else -1
print(res)


Measured memory_bytes: 3188
from collections import deque
h, w = map(int, input().split())

grid = []
for _ in range(h):
    row = list(input())
    grid.append(row)

def bfs(grid, sy, sx, gy, gx, h, w):
    visited = [[float('inf')] * w for _ in range(h)]
    visited[sy][sx] = 1
    que = deque([(sy, sx)])
    # up, right, down, left
    dy = [-1, 0, 1, 0]
    dx = [0, 1, 0, -1]
    while que:
        y, x = que.popleft()
        for i in range(4):
            next_y = y + dy[i]
            next_x = x + dx[i]
            if 0 <= next_y < h and 0 <= next_x < w and grid[next_y][next_x] == '.' and visited[next_y][next_x] == float('inf'):
                visited[next_y][next_x] = visited[y][x] + 1
                que.append([next_y, next_x])
                if next_y == gy and next_x == gx:
                    return visited[gy][gx]
    return -1

r = bfs(grid, 0, 0, h - 1, w - 1, h, w)
if r == -1:
    print(r)
else:
    white = 0
    for i in range(h):
        for j in range(w):
            if grid[i][j] == '.':
                white += 1
    print(white - r)

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}

void solve_A() {
  int n,r;
  cin>>n>>r;
  if(n<10) out(r+100*(10-n));
  else out(r);
}
void solve_B() {
  int n,k,ans=0;
  cin>>n>>k;
  while(n>0){
    n/=k;
    ans++;
  }
  out(ans);
}
void solve_C() {
  int n,ans=INF;
  cin>>n;
  vi x(n);
  rep(i,n) cin>>x[i];
  sort(all(x));
  REP(a,x[0],x[n-1]+1){
    int p=0;
    rep(i,n) p+=(a-x[i])*(a-x[i]);
    chmin(ans,p);
  }
  out(ans);
}

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


Measured memory_bytes: 256
N,_=gets.chomp.split(' ').map{|n| n.to_i}
A = Array.new(N)
h = {}
0.upto(N-1){|d|
	tmph = {}
	gets.chomp.split('').map{|n| n}.each{|a|
		tmph[a].nil? ? tmph[a]=1 : tmph[a]+=1
	}
	if(d==0)
		h = tmph
	else
		h.each{|k,v|
			if(tmph[k].nil?)
				h.delete(k)
			else
				h[k] = tmph[k] if h[k] > tmph[k]
			end
		}
	end
}
s = ""
h.keys.sort.each{|k|
	s += k * h[k]
}
puts s

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


int main(){
    int H,W;
    cin >> H >> W;
    
    int h,w;
    cin >> h  >> w;
    
    int x,y;
    x = H - h;
    y = W - w;
    
    cout << x*y << endl;
}


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

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

	map<int, int> mp;
	for (int i = 0; i < N - 1; ++i) {
		int a;
		cin >> a;
		mp[a]++;
	}

	for (int i = 1; i <= N; ++i) {
		cout << mp[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 13008
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    string ans="YES";
    set<long long> hoge;
    
    for(int i=0;i<n;i++){
        long long tmp;
        cin>>tmp;
        int kazu=hoge.size();
        hoge.insert(tmp);
        if(kazu==hoge.size()) ans="NO";
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 9600
N,M=map(int,input().split())
List=[list(map(int,input().split())) for i in range(M)]
flag=True
for i in range(M):
    for j in range(i,M):
        if List[i][0]==List[j][0] and List[i][1]!=List[j][1]:
            print(-1)
            flag=False
            break
    if not flag:
        break

if N!=1 and [1,0] in List:
    print(-1)
    flag=False

if flag:
    ans=[0 for i in range(N)]
    for i in range(M):
        ans[List[i][0]-1]=List[i][1]
    if ans[0]==0 and N!=1:
        ans[0]=1

    print(sum(ans[j]*(10**(N-j-1)) for j in range(N)))

Measured memory_bytes: 3064
def solve():
    from sys import stdin
    f_i = stdin
    
    n = f_i.readline()
    A = f_i.readline().split()
    
    ans = (a1 for a1, a2 in zip(A, A[1:] + [None]) if a1 != a2)
    print(' '.join(ans))

solve()


Measured memory_bytes: 14896
package main

import "fmt"

func main() {
	var M, D int
	fmt.Scan(&M, &D)
	c := 0
	for m := 1; m <= M; m++ {
		for d := 2; d <= D; d++ {
			d1 := d % 10
			d10 := d / 10
			if m == d1*d10 && d1 >= 2 && d10 >= 2 {
				c++
			}
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    int count1 = 0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
            count1++;
        
    }
    cout << count1<< endl;
    return 0;
}

Measured memory_bytes: 3860
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 14:38:46 2020

@author: shinba
"""

x = int(input())

while True:
    for i in range(2,int(x**(0.5))):
        if x % i == 0:
            x += 1
            break
    else:
        break

print(x)

Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>A(N);
	map<int, int>m;
	rep(i, N) {
		cin >> A[i];
		m[A[i]]++;
	}
	if (m.size() == N) {
		rep(i, N)cout << 0 << endl;
		return 0;
	}
	int sum = 0;
	for (auto j : m) {
		int num = j.second;
		sum += num * (num - 1) / 2;
	}
	rep(i, N) {
		int ans = sum - m[A[i]] + 1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read() 
{
    register int x = 0 , ch = getchar(); 
    while( !isdigit( ch ) ) ch = getchar(); 
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();     
    return x; 
}
ll quick_power(ll a,ll b,ll modn)
{
    ll ans=1;
    while(b)
    {
        if(b%2)
            ans=ans*a%modn;
        a=a*a%modn;
        b=(b>>1);
    }
    return ans;
}
ll turtle_muti(ll ain,ll bin,ll modn)
{
    ll res=0;
    for(;bin;bin>>=1) 
    {
        if(bin&1)
            res=(res+ain)%modn;
        ain=(ain<<1)%modn;
    }
    return res;
}
/*------------------Coding Area------------------*/


int ans,n,a;
signed main()
{
    n=read();
    for(int i=1;i<=n;++i)
    {
        a=read();
        ans+=a-1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
using System;

class MyClass
{
    static void Main(string[] args)
    {
        string str = "";
        while ((str = Console.ReadLine()) != null)
        {
            int length = str.Length;
            int count1 = 0;
            int count2 = 0;
            for (int i = 0; i < length - 2; i++)
            {
                string sub = str.Substring(i, 3);
                if (sub == "JOI")
                {
                    count1++;
                }
                else if (sub == "IOI")
                {
                    count2++;
                }
            }
            Console.WriteLine(count1);
            Console.WriteLine(count2);
        }
    }
}


Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<endl;
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  string s; 
  int l=0,r=n,x,y;
  pr(0);
  R s;
  if(s[0]=='M') y=0;
  else if(s[0]=='F') y=1;
  else return;
  while(l+1<r) {
    ll m=(l+r)/2;
    ll t=m%2;
    pr(m);
    R s;
    if(s[0]=='M') x=0;
    else if(s[0]=='F') x=1;
    else return;
    if(t==(x+y)%2) l=m;
    else r=m;
  }
}

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


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>

using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmax(T &a, T b)
{
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  int N;
  vector<int> X;

  cin >> N;

  X.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }

  int sum_X;

  sum_X = accumulate(X.begin(), X.end(), 0);

  double P_zero = sum_X / (double)N;

  double integral_part = 0;
  float fractional_part = modf(P_zero, &integral_part);

  int integral_P_zero;

  if (fractional_part <= 0.5) {
    integral_P_zero = (int)integral_part;
  }
  else {
    integral_P_zero = (int)integral_part + 1;
  }

  int minimum = 0;
  for (int i = 0; i < N; i++) {
    minimum += pow(X[i] - integral_P_zero, 2);
  }

  cout << minimum;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

ll N,M,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<ll> P,Q,R;
vector<pair<int,int>> PP,QQ;
bool CAN=true;


int main(){
  cin>>A>>B>>C;
  if(A*B*C%2==0) cout<<0<<endl;
  else cout<<min(A*B,min(B*C,C*A))<<endl;
}

Measured memory_bytes: 256
n = int(input())
al = list(map(int, input().split())) 

res = 1
from collections import Counter
count = Counter(al)
cc = count[0]

if cc >=1:
    print(0)
    exit()

for i in range(n):
    res *= al[i]    
    if res > 10**18:
        print(-1)
        exit()

else:        
    print(res)

Measured memory_bytes: 23968
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int x=a[0];
  for(Int i=0;i<n;i++) x=__gcd(x,a[i]);
  Int ans=0;
  while(x%2==0) x/=2,ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int N = 100;

int main(){

   int M[N][N];
   int a, b, i, j, n, k;

   cin >> n;

   for(i = 0; i < n; i++) {
      for(j = 0; j < n; j++) {
         M[i][j] = 0;
      }
   }

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

   for(i = 0; i < n; i++) {
      for(j = 0; j < n; j++) {
         if (j) cout << " ";
         cout << M[i][j];
      }
      cout << endl;
   }
   return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b;

int main()
{
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	long long int a, b, c, d, e, f;
	//for(int i=)
	a = 1000000000;
	b = 1;
	c = 0;
	long long int box, bag;
	box = N / 1000000000;
	bag = N % 1000000000;
	if (abs(box + bag) <= 1000000000) {
		e = 1000000000;
		f = e - box;
		d = f - bag;
	//	cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
		cout << a << " " << d << " " << b << " " << e << " " << c << " " << f << endl;
		cerr << abs(a*(e - f) + b * (f - d) + c * (d - e)) << endl;
	}
	else {
		box++;
		bag = 1000000000 - (N % 1000000000);
		cerr << box << " " << bag << endl;
		if (abs(box - bag) <= 1000000000) {
			f = 0;
			e = box;
			d = bag;
			cerr << "ohge" << endl;
			//cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
			cout << a << " " << d << " " << b << " " << e << " " << c << " " << f << endl;
			cerr << abs(a*(e - f) + b * (f - d) + c * (d - e)) << endl;
		}
	}
}

Measured memory_bytes: 256
n=int(input())
K=int(input())
n_list=[]
while n>=10:
    n_list.append(n%10)
    n=(n-n%10)//10
n_list.append(n)
n_list.reverse()
x=len(n_list)
dp=[[[0]*100,[0]*100] for i in range(x+1)]
dp[0][1][0]=1
for i in range(x):
    for k in range(99):
        dp[i+1][0][k]+=dp[i][0][k]
        dp[i+1][0][k+1]+=dp[i][0][k]*9
    if n_list[i]==0:
        for k in range(99):
            dp[i+1][1][k]+=dp[i][1][k]
    else:
        n=n_list[i]
        for k in range(99):
            dp[i+1][1][k+1]+=dp[i][1][k]
            dp[i+1][0][k]+=dp[i][1][k]
            dp[i+1][0][k+1]+=dp[i][1][k]*(n-1)
ans=dp[x][0][K]+dp[x][1][K]
print(ans)


Measured memory_bytes: 39920
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int k,val=7,i=1;
	cin>>k;
	unordered_set<int> st; 
	while(1){
		val=val%k;
		if(st.find(val)!=st.end()){
			cout<<-1<<'\n';
			return 0;
		}
		st.insert(val);
		if(val==0){
			break;
		}
		val=val*10+7;
		i++;
	}
	cout<<i<<'\n';
	return 0;
}

Measured memory_bytes: 42696
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long

using namespace std;

int main(void) {
    ll n, k;
    cin >> n >> k;
    if(n%k < abs(k - (n%k))) cout << n%k << endl;
    else cout << k - (n%k) << endl;
}



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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n;
  double res = 0;
  cin >> n;
  for (int i=0; i<n; i++){
      double num;
      cin >> num;
      res += 1/num;
  }
  cout << 1/res;
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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 ll INF = 1LL << 60;

int main() {
    int A, B, C ,K; cin >> A >> B >> C >> K;
    int rem = 0; int sum = 0;
    if (K < A) {
        sum += 1 * K;
    } else {
        sum += A;
        rem = K - A;
        if (rem > B) {
            rem -= B;
            sum += -1 * rem;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
string str_arr[100];
int main()
{
  	int N,L,i,j;
  	string temp;
  	cin >> N >> L;
  	for(i = 0;i<N;i++)
        cin>>str_arr[i];
    for(i=0;i<N-1;i++)
        for(j=0;j<N-1;j++){
            if(str_arr[j]>str_arr[j+1])
            {
                temp = str_arr[j];
                str_arr[j] = str_arr[j+1];
                str_arr[j+1] = temp;
            }
        }
      for(i = 0;i<N;i++)
        cout << str_arr[i];
}


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

int main(){
    int n, m;
    while(cin >> n >> m){
        vector<int> a(m+1, 0), b(m+1, 0), c(m+1, 0);
        while(n-- > 0){
            string s;
            int w, x, y, z;
            getline(cin, s);
            getline(cin, s);
            cin >> w >> x >> y >> z;
            for(int i = 0; i <= m-w; i++){
                a[i+w] = max(a[i+w], a[i]+x);
                b[i+w] = max(b[i+w], b[i]+y);
                c[i+w] = max(c[i+w], c[i]+z);
            }
        }
        cout << max( {*max_element(a.begin(), a.end()), 
                      *max_element(b.begin(), b.end()),
                      *max_element(c.begin(), c.end())} ) << endl;
    }
    return 0;
}


Measured memory_bytes: 3164