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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 100005;

int N, A, B;
vi tree[MX];
map<pi, int> edges;
vpi orderOfEdges, degrees(MX);
set<int> treeEdgeColors[MX];
int minColors;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> N;
	FOR(i, 1, N + 1) degrees[i] = mp(0, i);
	F0R(i, N - 1) {
		cin >> A >> B;
		tree[A].pb(B);
		tree[B].pb(A);
		degrees[A].f++; degrees[B].f++;
		if (B < A) swap(A, B);
		edges[mp(A, B)] = 0;
		orderOfEdges.pb(mp(A, B));
	}
	
	sort(all(degrees), greater<pi>());
	minColors = degrees[0].f;
	 
	F0R(i, N) {
		int v = degrees[i].s, color = 1;
		trav(u, tree[v]) {
			// Check to make sure there's no color
			if (u < v && edges[mp(u, v)]) continue;
			if (v < u && edges[mp(v, u)]) continue;
			
			while(treeEdgeColors[u].count(color) || treeEdgeColors[v].count(color)) color++;
			treeEdgeColors[u].insert(color);
			treeEdgeColors[v].insert(color);
			if (u < v) edges[mp(u, v)] = color;
			else edges[mp(v, u)] = color;
		}
	}
	
	cout << minColors << "\n";
	F0R(i, N - 1) {
		cout << edges[orderOfEdges[i]] << "\n";
	}
	
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 27892
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		for(int i = 0;i < n ; i++){
			String[] tmpStr = br.readLine().split(" ");

			double[] input = new double[6];
			for(int j = 0; j < tmpStr.length ; j++){
				input[j] = Double.parseDouble(tmpStr[j]);
			}

			//?????????2?????????
			Point2D.Double p1 = new Point2D.Double((input[0] + input[2])/2, (input[1] + input[3])/2);
			Point2D.Double p2 = new Point2D.Double((input[2] + input[4])/2, (input[3] + input[5])/2);
			//?????????2?????????
			double a1 = -1/((input[1]-input[3])/(input[0]-input[2]));
			double a2 = -1/((input[3]-input[5])/(input[2]-input[4]));


			Equation e1 = new Equation(a1, -1, (a1*p1.x - p1.y));
			if(input[1] == input[3]){
				e1 = new Equation(1, 0, p1.x);
			}
			Equation e2 = new Equation(a2, -1, (a2*p2.x - p2.y));
			if(input[3] == input[5]){
				e2 = new Equation(1, 0, p2.x);
			}

			Point2D.Double center = Calc.solveEquation(e1, e2);

			System.out.printf("%.3f %.3f %.3f\n",Calc.round(center.getX()), Calc.round(center.getY()), Calc.round(center.distance(input[0], input[1])));
		}
	}

}

class Equation {
	double a;
	double b;
	double c;

	public Equation(double a, double b, double c){
		this.a = a;
		this.b = b;
		this.c = c;
	}
}
//??£???????¨??????¨
class Calc {

	public static Point2D.Double solveEquation (Equation e1, Equation e2) {
		// TODO ?????????????????????????????????????????????
		double[] input = new double[6];
		double[] reverse = new double[6];

		input[0] = reverse[3] = e1.a;
		input[1] = reverse[4] = e1.b;
		input[2] = reverse[5] = e1.c;
		input[3] = reverse[0] = e2.a;
		input[4] = reverse[1] = e2.b;
		input[5] = reverse[2] = e2.c;

		//System.out.println(input[0]+" "+input[1]+" "+input[2]);
		//System.out.println(input[3]+" "+input[4]+" "+input[5]);

		//??????a = 0???????????????????????\????????????
		if(input[0] == 0){
			for(int i = 0; i < 6; i++){
				input[i] = reverse[i];
			}
		}

		//????????§??????????????¬?????¢?????????????????¨?????????
		double k = input[3]/input[0];
		input[3] = 0;
		input[4] -= input[1]*k;
		input[5] -= input[2]*k;

		double k2 = input[4];
		input[4] = 1;
		input[5] /= k2;

		double k3 = input[1];
		input[1] = 0;
		input[2] -= input[5]*k3;

		input[2] /= input[0];
		input[0] = 1;

		//System.out.printf("%.3f %.3f\n", input[2], input[5]);
		return new Point2D.Double(input[2], input[5]);
	}

	public static double round(double a){
		double result = (double)Math.round(a*1000)/1000;
		return result;
	}
}

Measured memory_bytes: 24908
def enum_divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
    return res


def F(A, B):
    return max(len(str(A)), len(str(B)))


N = int(input())
ans = float("inf")
for n in enum_divisors(N):
    ans = min(ans, F(n, N // n))
print(ans)


Measured memory_bytes: 3060
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX=10000;

int V;
vector<int> G[MAX];
vector<int> rG[MAX];
vector<int> vs;
bool used[MAX];
int cmp[MAX];

void add_edge(int from,int to)
{
	G[from].push_back(to);
	rG[to].push_back(from);
	return;
}

void dfs(int v)
{
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		if(!used[G[v][i]])dfs(G[v][i]);
	}
	vs.push_back(v);
	return;
}

void rdfs(int v,int k)
{
	used[v]=true;
	cmp[v]=k;
	for(int i=0;i<rG[v].size();i++)
	{
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
	return;
}

int ssc()//Strongly Connected Component
{
	memset(used,0,sizeof(used));
	vs.clear();
	for(int v=0;v<V;v++)
	{
		if(!used[v])dfs(v);
	}
	memset(used,0,sizeof(used));
	int k=0;
	for(int i=vs.size()-1;i>=0;i--)
	{
		if(!used[vs[i]])rdfs(vs[i],k++);
	}
	return k;
}

int main()
{
	int E;
	cin>>V>>E;
	for(int i=0;i<E;i++)
	{
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
	}
	int k=ssc();
	int Q;cin>>Q;
	for(int i=0;i<Q;i++)
	{
		int u,v;
		cin>>u>>v;
		cout<<(cmp[u]==cmp[v])<<endl;
	}
	return 0;
}

Measured memory_bytes: 4716
from math import gcd
def preprocess(n):
    """
    n以下の自然数の高速素因数分解の前処理

    Parameters
    ----------
    n: int
        自然数

    Returns
    -------
    MinFactor:list
      高速素因数分解用のMinFactorテーブル
    """
    f = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    # MinFactor[x]:xに含まれる最小の素因子
    MinFactor = [-1]*(n+1)
    MinFactor[0] = 0
    MinFactor[1] = 1

    for i in range(2, n+1):
        if is_prime[i]:
            MinFactor[i] = i
            f.append(i)
            for j in range(i*2, n+1, i):
                is_prime[j] = False
                if MinFactor[j] == -1:
                    MinFactor[j] = i
    """
    return値
     1.素数か否かの判定結果:is_prime
     2.素数のリスト:f
     3.高速素因数分解用のMinFactorテーブル
    """
    return MinFactor

def prime_factorize(n,MinFactor):
    # res = []
    while n != 1:
        prime = MinFactor[n]
        # exp = 0
        while MinFactor[n] == prime:
            # exp += 1
            n //= prime
        cnt[prime] += 1
        # res.append((prime,exp))
    # return res

n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
g = a[0]
for aa in a:
    g = gcd(g,aa)

mf = preprocess(a_max)
cnt = [0]*(a_max+1)
for aa in a:
    prime_factorize(aa,mf)

if g != 1:
    print("not coprime")
elif max(cnt) <= 1:
    print("pairwise coprime")
else:
    print("setwise coprime")

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

int main() {
    int L, R; cin >> L >> R;
    if (R - L > 2019) {
        cout << 0 << endl;
        return 0;
    }
    long long ans = 2019;
    for (int i = L; i < R; i++) for (int j = i + 1; j <= R; j++) {
        ans = min(ans, 1LL * i * j % 2019);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
char s[N];
int n,m,ans,b[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	m=read();
	if(n==1)
	{
		cout<<m/2;
		return 0;
	}
	for(int i=2;i<=n;i++)
		if(s[i]==s[i-1]&&!b[i-1])
		{
			ans++;
			b[i]=1;
		}
	ans=ans*m;
	if(s[1]==s[n]&&!b[n])
	{
		if(s[1]!=s[2])ans=ans+m-1;
		else{
			ans=ans/m;
			memset(b,0,sizeof(b));
			b[1]=1;
			int res=1;
			for(int i=2;i<=n;i++)
				if(s[i]==s[i-1]&&!b[i-1])
				{
					res++;
					b[i]=1;
				}
			if(!b[n])ans+=res*(m-1);
			else{
				if(res<ans)swap(res,ans);
				cout<<res*(m/2)+ans*(m/2+m%2)<<endl;
				return 0;
			}
		}
	}
	cout<<ans;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];


    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 21728
#include "bits/stdc++.h"

using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const vector<pair<T, U>> p) {
	os << "P(" << p.first << ", " << p.second << endl;
}

/*
template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << P << " ";
	return os << "}";
}
*/

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Insert from here! */
/* Cut from here! */
struct data { int x, y, b, p; };

void Main() {
	int N; cin >> N;
	vector<struct data> IN(N);
	rep(i, N) {
		cin >> IN[i].x >> IN[i].y >> IN[i].b >> IN[i].p;
	}
	vector<int> ans(N);
	rep(i, N) {
		int tmp1 = IN[i].x * IN[i].b + IN[i].y * IN[i].p;
		int tmp2 = (IN[i].x * max(5, IN[i].b) + IN[i].y * max(2, IN[i].p)) * 0.8;
		ans[i] = min(tmp1, tmp2);
	}
	rep(i, N) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3188
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

print(dp[-1])


Measured memory_bytes: 58336
#include<stdio.h>
int main(void)
{
    int a,b,c,d,e,kaito,atu,sum;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
    if(a<0){
        kaito=-a*c;
        atu=b*e;
        sum=kaito+atu+d;
    }
    else if(a==0){
        atu=b*e;
        sum=atu+d;
    }
    else if(a>0){
        atu=b-a;
        sum=atu*e;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 1e2 + 10;
char s[MAXN];
int main() {
	while (scanf("%s", &s) != EOF) {
		int num = 0;
		for (int i = 0; s[i]; i++) {
			num++;
		}
		cout << s[0] << num-2 << s[num-1] << endl;
	}
}

Measured memory_bytes: 256
import math

def main():
        index=0
        a=[]
        b=[]
        N = int(input())
        for i in range(N):
            A,B=input().split()
            a.append(int(A))
            b.append(int(B))
        for i in range(N):
            for j in range(N-1-i):
                index+=calc_length(a[i],a[j+1+i],b[i],b[j+1+i])

        print(index*2/N)

def calc_length(x1,x2,y1,y2):
    return math.sqrt(((x1-x2)**2)+((y1-y2)**2))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
object Main extends App{
  import scala.io.StdIn._
  val n: Int = readLine.trim.toInt
  val pointsSortByX = Array.tabulate(n){_ ⇒ val Array(x, y) = readLine.trim.split(' ').map(_.toInt); Point(x, y)}.sortBy{_.x}
  val pointsSortByY = pointsSortByX.sortBy(_.y)
  pointsSortByX.zipWithIndex.foreach{case (p, i) ⇒ p.rankX = i}
  println(minDistanceSquare(pointsSortByX, pointsSortByY))
  def minDistanceSquare(pointsSortByX: Array[Point], pointsSortByY: Array[Point]): Long = {
    pointsSortByX.length match{
      case 0 ⇒ Int.MaxValue
      case 1 ⇒ Int.MaxValue
      case 2 ⇒ pointsSortByX(0).distanceSquare(pointsSortByX(1))
      case n ⇒
        val mid = pointsSortByX(n / 2)
        val leftX = Array.tabulate(n / 2){i ⇒ pointsSortByX(i)}
        val leftY = pointsSortByY.filter{_.rankX < n / 2}
        val leftMin = minDistanceSquare(leftX, leftY)
        val rightX = Array.tabulate(n - n / 2 - 1){i ⇒ pointsSortByX(n / 2 + 1 + i)}
        val rightY = pointsSortByY.filter{_.rankX > n / 2}
        val rightMin = minDistanceSquare(rightX, rightY)
        val minHalf = if (leftMin < rightMin) leftMin else rightMin
        val suspectLeft = leftX.filter{p ⇒ mid.x - minHalf <= p.x && mid.x + minHalf >= p.x && mid.y - minHalf <= p.y && mid.y + minHalf >= p.y}
        val suspectRight = rightX.filter{p ⇒ mid.x - minHalf <= p.x && mid.x + minHalf >= p.x && mid.y - minHalf <= p.y && mid.y + minHalf >= p.y}
        val minAcross = if (suspectLeft.isEmpty || suspectRight.isEmpty) Int.MaxValue else suspectLeft.map{l ⇒ suspectRight.map{r ⇒ l.distanceSquare(r)}.min}.min
        val minMid = if (suspectLeft.isEmpty && suspectRight.isEmpty) Int.MaxValue else List(suspectLeft, suspectRight).filterNot{_.isEmpty}.flatMap{_.map{p ⇒ p.distanceSquare(mid)}}.min
        List(minMid, minAcross, minHalf).min
    }
  }
}
case class Point(x: Long, y: Long) {
  var rankX: Int = 0
  var rankY: Int = 0
  def distanceSquare(that: Point): Long = (x - that.x) * (x - that.x) + (y - that.y) * (y - that.y)

}


Measured memory_bytes: 609956
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)cin >> v[i];
    vector<int> tmp = v;
    sort(tmp.begin(), tmp.end());
    int change = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] != tmp[i])change++;
    }
    cout << (change <= 2 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,t,a;
  cin >> n >> t >> a;
  vl h(n,0);
  rep(i,n){
    cin >> h[i];
  }
  double H=(t-a)*1000/6;
  ll MIN=INF;
  ll ans;
  rep(i,n){
    if(abs(H-h[i])<abs(MIN-H)){
      MIN=h[i];
      ans=i+1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def ans():
  N, M, X, Y = map(int,input().split())
  x = sorted(list(map(int,input().split())))
  y = sorted(list(map(int,input().split())))
  for i in range(X+1, Y+1):
    if(x[-1] < i <= y[0]):
      print("No War")
      break
  else:
    print("War")
ans()

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int MAX_N = 1005, MOD = 1000000007;
typedef long long i64;
typedef pair<int, int> pii;

class Edge {
public:
  int nxt, to;
} e[MAX_N << 1];

int head[MAX_N], cnt, C[MAX_N][MAX_N];
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}

int N, M, K, dfn[MAX_N], low[MAX_N], dfs_clock;
int st[MAX_N], top, bcc_cnt;

vector<int> block[MAX_N];

pii edge[MAX_N];

void find_bcc(int u, int v) {
  dfn[u] = ++dfs_clock, low[u] = dfn[u];

  int temp;
  
  for (int i = head[u]; i; i = e[i].nxt) 
    if (!dfn[e[i].to]) {
      temp = top, st[++top] = (i + 1) / 2;
      find_bcc(e[i].to, u), low[u] = min(low[u], low[e[i].to]);

      if (low[e[i].to] >= dfn[u]) {
	++bcc_cnt;
	while (top > temp) block[bcc_cnt].push_back(st[top--]);
      }
      
    } else if (e[i].to != v && dfn[e[i].to] < dfn[u]) {
      low[u] = min(low[u], dfn[e[i].to]);
      st[++top] = (i + 1) / 2;
    }
}

int fa[MAX_N];
int find(int x) {
  return fa[x] == x ? x : fa[x] = find(fa[x]);
}

i64 fpm(i64 x, i64 y) {
  i64 res = 1;
  while (y) {
    if (y & 1) res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return res;
}

i64 work(vector<int> &v) {
  for (int i = 1; i <= N; ++i) fa[i] = i;

  int num = 0, n = v.size();
  for (int x : v) {
    int u = find(edge[x].first), v = find(edge[x].second);
    if (u == v) num++;
    else fa[u] = v;
  }

  if (num == 0) return K;
  else if (num == 1) {
    i64 res = 0;
    for (int i = 1; i <= n; ++i)
      res = (res + fpm(K, __gcd(i, n))) % MOD;
    res = res * fpm(n, MOD - 2) % MOD;
    return res;
  } else {
    return C[n + K - 1][K - 1];
  }
  
}

int main() {

  scanf("%d%d%d", &N, &M, &K);

  for (int i = 0; i < MAX_N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  
  for (int i = 1, u, v; i <= M; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
    edge[i] = make_pair(u, v);
  }

  for (int i = 1; i <= N; ++i)
    if (!dfn[i]) find_bcc(i, 0);

  i64 res = 1;
  for (int i = 1; i <= bcc_cnt; ++i)
    res = res * work(block[i]) % MOD;

  printf("%lld\n", res);
  
  return 0;
}


Measured memory_bytes: 4224
n = int(input())
a = [[0],[0]]
a[0] = list(map(int,input().split()))
a[1] = list(map(int,input().split()))
c = 0
for i in range(n):
    c = max(c,sum(a[0][0:i+1] + a[1][i:]))
print(c)

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            final int N = (int) 1e5 + 10;
            boolean[] primes = new boolean[N];
            Arrays.fill(primes, true);
            primes[0] = primes[1] = false;
            for (int i = 2; i < primes.length; ++i) {
                if (!primes[i]) continue;
                for (int j = i + i; j < primes.length; j += i) {
                    primes[j] = false;
                }
            }
            int[] oddNums = new int[N];
            for (int i = 1; i < oddNums.length; i += 2) {
                int cur = i == 1 ? 0 : oddNums[i - 2];
                if (primes[i] && primes[(i + 1) / 2]) {
                    ++cur;
                }
                oddNums[i] = cur;
            }
            int q = in.nextInt();
            for (int qq = 0; qq < q; ++qq) {
                int l = in.nextInt();
                int r = in.nextInt();
                int rr = oddNums[r];
                int ll = l == 1 ? 0 : oddNums[l - 2];
                out.println(rr - ll);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<str> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

#define forr(i, a, b, s) for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define f0(i, n) forr(i, 0, (n), 1)
#define f1(i, n) forr(i, 1, ((n) + 1), 1)
#define fo(i, b, e) forr(i, (b), (e), 1)
#define trav(a, x) for (auto &a : x)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define sll unordered_set<ll>
#define sii unordered_set<int>
#define mll unordered_map<ll, ll>
#define mii unordered_map<int, int>
#define pqb priority_queue<ll>
#define pqs priority_queue<ll, vll, greater<ll>>

#define zerobits(x) __builtin_ctzll(x)
#define setbits(x) __builtin_popcountll(x)
#define ps(x, y) fixed << setprecision(y) << x
#define mem(arr, x) memset(arr, x, sizeof(arr))
#define endl '\n'

const ll INF = 9e18;
ll mod = 1000000007;

template <typename T>
ostream &operator<<(ostream &stream, vector<T> &v)
{
    for (T &x : v)
        stream << x << " ";
    return stream;
}

template <typename T>
istream &operator>>(istream &stream, vector<T> &v)
{
    for (T &x : v)
        stream >> x;
    return stream;
}

template <typename T>
void sort(vector<T> &v)
{
    std::sort(v.begin(), v.end());
    return;
}

template <typename T>
T max(vector<T> &v)
{
    return *(max_element(v.begin(), v.end()));
}

template <typename T>
T min(vector<T> &v)
{
    return *(min_element(v.begin(), v.end()));
}

// =============== !!! ~ ~ ~ code starts here ~ ~ ~ !!! ===============

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef RAGHAV
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    clock_t t1, t2;
    t1 = clock();
    int tc = 1;
    // cin >> tc;
    while (tc--)
    {

        int n;
        cin >> n;
        vi a(n), b(n), c(n);
        f0(i, n) cin >> a[i] >> b[i] >> c[i];
        vector<vi> dp(n + 1, vi(3, 0));
        f1(i, n)
        {
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i - 1];
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i - 1];
            dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i - 1];
        }
        cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
    }
#ifdef RAGHAV
    t2 = clock();
    cout << "\n\ntime taken: " << (t2 - t1) / (long double)CLOCKS_PER_SEC;
#endif
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      int black = i * (M - j) + j * (N - i);
      if (black == K) {
        cout << "Yes" << '\n';
        return 0;
      }
    }
  }
  cout << "No" << '\n';
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> C(N, vector<int>(N));
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            cin >> C[i][j];
        }
    }
    long long cost = 0;
    for (int i=0; i<N; ++i) {
        for (int j=i+1; j<N; ++j) {
            cost += min(C[i][j], C[j][i]);
        }
    }
    cout << cost << endl;
    return 0;
}


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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

signed main(){
	int h,a;
	cin>>h>>a;
	cout<<(h+a-1)/a<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    elif S[i] == 'B':
        B.append(i+1)

lenb = len(B)

cnt = 0
for r in R:
    for g in G:
        up = max(r, g)
        down = min(r, g)
        diff = up - down
        
        chk = 0
        if up + diff <= N:
            if S[up+diff-1] == 'B':
                chk += 1
        if down-diff >= 1:
            if S[down-diff-1] == 'B':
                chk += 1
        if diff%2 == 0:
            if S[int(up-diff/2-1)] == 'B':
                chk += 1
        cnt += lenb - chk

print(cnt)


Measured memory_bytes: 9308
#include <bits/stdc++.h>
using namespace std;
char a[6][6]={"aacd","bbcd","cdaa","cdbb"};
char b[8][8]={"aabba","bcc.a","b..cb","a..cb","abbaa"};
char c[8][8]={"bbacc.","a.a..c","abb..c","cc.bba","..ca.a","..cabb"};
char d[9][9]={"eeffee.","aa.aa.e","..a..ae","..a..af","aa.aa.f","..a..ae","..a..ae"};
char ans[1002][1002];
void f(int n,int k){
    if(n==1)return;
    int i,j;
    char q='a';
    char w='b';
    if(k%2)q='c',w='d';
    char c=q;
    for(i=1 ; i<n ; i+=2){
        a[k][i-1+k]=a[k][i+k]=c;
        if(c==q)c=w;
        else c=q;
    }
    for(i=1 ; i<n ; i+=2){
        a[i+k][n-1+k]=a[i-1+k][n-1+k]=c;
        if(c==q)c=w;
        else c=q;
    }
    for(i=n-1 ; i>=1 ; i-=2){
        a[n-1+k][i+k]=a[n-1+k][i+k-1]=c;
        if(c==q)c=w;
        else c=q;
    }
    for(i=n-1 ; i>=1 ; i-=2){
        a[i+k][k]=a[i-1+k][k]=c;
        if(c==q)c=w;
        else c=q;
    }
    f(n-2,k+1);
}
void check(int n){
    int i,j;
    int s=0;
    for(i=0 ; i<n ; i++){
        if(a[0][i]!='.' && a[0][i]!=a[0][i+1])s++;
    }
    for(i=0 ; i<n ; i++){
        int cnt=0;
        for(j=0 ; j<n ; j++){
            if(a[i][j]!='.' && a[i][j]!=a[i][j+1])cnt++;
        }
        if(cnt!=s)cout<<"!";
    }
    for(i=0 ; i<n ; i++){
        int cnt=0;
        for(j=0 ; j<n ; j++){
            if(a[j][i]!='.' && a[j+1][i]!=a[j][i])cnt++;
        }
        if(cnt!=s)cout<<"!";
    }
}
int main(){
    cin.tie(0);
    int n;
    ios_base::sync_with_stdio(0);
    cin>>n;
    int i,j;
    int k=0;
    int m=n;
    if(n==2 ){
        cout<<-1;
        return 0;
    }
    if(n==7){
        for(i=0 ; i<7 ; i++)cout<<d[i]<<endl;
        return 0;
    }
    if(n==3){
        cout<<"aa."<<endl<<"..a"<<endl<<"..a";
        return 0;
    }
    while(n){
        if(n==11){
            n-=5;
            for(i=0 ; i<5 ; i++){
                for(j=0 ; j<5 ; j++){
                    ans[n+i][n+j]=b[i][j];
                }
            }
            n-=6;
            for(i=0 ; i<6 ; i++){
                for(j=0 ; j<6 ; j++)
                    ans[i][j]=c[i][j];
            }
            break;
        }
        if(n==5){
            n-=5;
            for(i=0 ; i<5 ; i++){
                for(j=0 ; j<5 ; j++){
                    ans[i][j]=b[i][j];
                }
            }
            break;
        }
        if(n==6){
            n-=6;
            for(i=0 ; i<6 ; i++){
                for(j=0 ; j<6 ; j++)
                    ans[i][j]=c[i][j];
            }
            break;
        }
        n-=4;
        for(i=0 ; i<4 ; i++){
            for(j=0 ; j<4 ; j++){
                ans[n+i][n+j]=a[i][j];
            }
        }
    }

    for(i=0 ; i<m ; i++){
        for(j=0 ; j<m ; j++){
            if(ans[i][j]==0)cout<<'.';
            else cout<<ans[i][j];
        }
        cout<<"\n";
    }
    return 0;
}


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

int A[20], n, q, k;
int dp[21][2001];

void init(int k){
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= k; j++){
      dp[i][j] = -200;
    }
  }
}

bool Comb(int i, int m){
  if(dp[i][m] >= 0) return dp[i][m];
  if(m == 0) return true;
  if(i == n) return false;
  return dp[i][m] = Comb(i + 1, m - A[i]) || Comb(i + 1, m);
}

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

  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> k;
    init(k);
    if(Comb(0, k)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1320
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
t = STR()
ans = len(s)
for i, j in zip(s, t):
    if i == j:
        ans -= 1
print(ans)

Measured memory_bytes: 73804
from collections import Counter

N = int(input())
words = [input() for _ in range(N)]
counts = Counter(words)

if max(counts.values()) > 1:
    print('No')
else:
    for i in range(1, len(words)):
        if words[i][0] != words[i - 1][-1]:
            print('No')
            break
    else:
        print('Yes')


Measured memory_bytes: 3316
from bisect import bisect_left
N = int(input())
L = list(map(int,input().split()))
L_1 = sorted(L)

ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
      ans +=bisect_left(L_1,L_1[i]+L_1[j])-j-1
print(ans)

Measured memory_bytes: 3188
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let x = read::<i64>();
    let mut cur = 0;
    let mut ans = 0;
    loop {
        ans += 1;
        cur += ans;
        if cur >= x {
            println!("{}", ans);
            return;
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;


int main() {
	ll a;
	cin >> a;
	long double b;
	cin >> b;
	string ans = to_string((ll)floor(a * b));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#define ffor(a, b, c) for (int a=b; a<=c; a++)
using namespace std;

int n, h[100007], dp[100007];

int main() {
	cin>>n;
	ffor (i, 1, n) cin>>h[i];
	dp[1]=0, dp[2]=abs(h[2]-h[1]);
	ffor (i, 3, n) dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SYOU(x) fixed<<setprecision(x) //小数点桁数を指定する
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    INT(N);
    ll ans = 0LL;
    for(int i = 1; i <=N; ++i){
        if(i % 3 == 0 || i % 5 == 0){

        } else {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define M 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define m_p make_pair
#define pb push_back
#define vi vector<int>
#define F first 
#define S second 

void solve()
{
	int n; cin>>n;
	int a[n];
	
	rep(i,0,n) cin>>a[i];
	
	int sum=0;
	rep(i,0,n) sum+=a[i];
	
	float x=(float)sum/n;
	int p;
	if(x-floor(x)>0.5) p=floor(x)+1;
	else p=floor(x);
	
	//cout<<x<<endl;
	
	int ans=0;
	
	rep(i,0,n)
	{
		ans+=pow((a[i]-p),2);
	}
	cout<<ans<<endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b) {
	int r;
	while (b > 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(void) {
	char str[32];
	int zero_left, zero_right, one_left, one_right;
	int phase = 0;
	int i;
	int bunsi, bunbo, g;
	if (scanf("%s", str) != 1) return 1;
	zero_left = one_left = 1;
	zero_right = one_right = 0;
	for (i = 0; str[i] != '\0'; i++) {
		if (str[i] == '.') {
			phase = 1;
		} else if (str[i] == '(') {
			phase = 2;
		} else if (str[i] == ')') {
			phase = 3;
		} else {
			switch (phase) {
			case 0:
				zero_right = zero_right * 10 + (str[i] - '0');
				one_right = one_right * 10 + (str[i] - '0');
				break;
			case 1:
				zero_right = zero_right * 10 + (str[i] - '0');
				one_right = one_right * 10 + (str[i] - '0');
				zero_left *= 10;
				one_left *= 10;
				break;
			case 2:
				one_right = one_right * 10 + (str[i] - '0');
				one_left *= 10;
				break;
			case 3:
				break;
			}
		}
	}
	if (phase >= 2) {
		bunsi = one_right - zero_right;
		bunbo = one_left - zero_left;
	} else {
		bunsi = zero_right;
		bunbo = zero_left;
	}
	g = gcd(bunsi, bunbo);
	printf("%d/%d\n", bunsi / g, bunbo / g);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  double tax = 1.08;
  int ans = 0;
  for (int i=1; i<=N; i++) {
    if (N <= (i * tax) && (i * tax) < (N + 1)) {
      ans = i;
      break;
    }
  }
  
  if (ans) {
    cout << ans << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
string a,b,c;
cin >> a>>b>>c;
int d=(int)a.at(0)-32;
int e=(int)b.at(0)-32;
int f=(int)c.at(0)-32;
cout << (char)d<<(char)e<<(char)f<<endl;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  scan(h);
  sort(all(h));

  ll ans = LL_INF;
  rep(i, k - 1, n) chmin(ans, abs(h[i] - h[i - (k - 1)]));

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 1024
number=input().split()
n=int(number[0])
q=int(number[1])
answer=[]
time=0
head=0

Que=[input().split() for i in range(n)]
for i in range(n):
    Que[i][1]=int(Que[i][1])
    Que[i].append(0)
    
while Que!=[]:
    l=len(Que)
    if head==l:
        head=0
        
    else:
        if Que[head][1]<=q:
            time+=Que[head][1]
            Que[head][2]+=time
            tmp=Que.pop(head)
            answer.append(tmp)
            
        else:
            time+=q
            Que[head][1]-=q
            head+=1
            
for i in range(n):
    print(answer[i][0],answer[i][2])


Measured memory_bytes: 17120
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n)
	{
		int ans = 1;
		for(int i = 1; i <= n; ++i)
		{
			ans += i;
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include<set>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

//136B
int main(void) {
	ll k, x;
	cin >> k >> x;
	rep(i, x - k + 1, x + k) {
		if (i < -1000000 || i > 1000000) continue;
		cout << i;
		if (i != x + k - 1)cout << " ";
		else cout << endl;
	}
}


Measured memory_bytes: 256