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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
string s;
int n,a,b,c,d;
bool ok(int p,int q){
    if(p>=n)return false;
    if(s[p]=='#')return false;
    if(p==q)return true;
    if(s[p+1]=='.')return ok(p+1,q);
    return ok(p+2,q);
}

int main(){

    cin >> n >> a >> b >> c >> d;
    cin >> s;
    a--;b--;c--;d--;
    bool flag = 0;
    if(c<d){
        if(ok(a,c)&&ok(b,d)){
            flag = 1;
        }
    }else{
        int cnt = 0;
        int mx = 0;
        for(int i=b-1;i<=d+1;i++){
            if(s[i]=='.'){
                cnt++;
            }else{
                mx = max(mx,cnt);
                cnt = 0;
            }
        }
        mx = max(mx,cnt);
        if(mx>=3){
            if(ok(a,c)&&ok(b,d)){
                flag = 1;
            }
        }
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll dp[3010][3010];

int main() {
    ll N;
    cin >> N;
    ll a[N];
    REP(i, 0, N) {
        cin >> a[i];
    }
    REP(i, 0, N + 1) {
        dp[0][i] = 0;
    }
    REP(i, 1, N + 1) {
        REP(j, 0, N + 1 - i) {
            if ((N - i) % 2 == 0) {
                dp[i][j] = max(dp[i - 1][j + 1] + a[j], dp[i - 1][j] + a[j + i - 1]);
            } else {
                dp[i][j] = min(dp[i - 1][j + 1] - a[j], dp[i - 1][j] - a[j + i - 1]);
            }
        }
    }
    // REP(i, 0, N + 1) {
    //     REP(j, 0, N + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = dp[N][0];
    cout << ans << endl;
}


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

int main(){
    string N;
    cin>>N;
    if(N.at(0)=='7'){
        cout<<"Yes"<<endl;
    }
    else if(N.at(1)=='7'){
        cout<<"Yes"<<endl;
    }
    else if(N.at(2)=='7'){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll H, W; cin >> H >> W;
    ll ans = 0;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    REP(i, 0, H) {
        if (i % 2 == 0) {
            ans += (W + 1) / 2;
        } else {
            ans += W / 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
struct card{
  int num;
  char c;
  bool operator <(const card &a)const{
    if(c == a.c){
      return num < a.num;
    }
    return c < a.c;
  }
};

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    card c[9];
    for(int i = 0; i < 9; i++){
      cin >> c[i].num;
    }
    for(int i = 0; i < 9; i++){
      cin >> c[i].c;
    }
    sort(c, c + 9);
    // for(int i = 0; i < 9; i++){
    //   cout << c[i].num << " ";
    // }
    // cout << endl;
    // for(int i = 0; i < 9; i++){
    //   cout << c[i].c << " ";
    // }
    // cout << endl;
    
    bool flag = 0;
    do{
    for(int i = 0; i < 9; i += 3){
      // cout << "i:" << i << endl;
      // cout << c[i].c << " " << c[i + 1].c << endl;
      if(!(c[i].c   == c[i + 1].c   && c[i + 1].c   == c[i + 2].c))break;
      if(!(c[i].num == c[i + 1].num && c[i + 1].num == c[i + 2].num) &&
	 !(c[i].num + 1 == c[i + 1].num && c[i + 1].num + 1 == c[i + 2].num)){
	break;
      }
      if(i == 6){
	flag = 1;
      }
    }
    }while(next_permutation(c, c + 9));
    if(flag)cout << 1 << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 1180
#define rep(i,n) for (int i=0; i<(int)(n); ++i)

#include<bits/stdc++.h>
using namespace std;

int gcd(int a, int b){
    int tmp = 0;
    if(a < b){
        tmp = b;
        b = a;
        a = tmp;
    }

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

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

    int sum = 0;

    for(int a=1; a<=K; ++a){
        for(int b=1; b<=K; ++b){
            for(int c=1; c<=K; ++c){
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args) {

		int n = scanner.nextInt();
		int m = scanner.nextInt();
		long[][] totalValue = new long[8][n];
		for(int i=0; i<n; i++) {
			long x = scanner.nextLong();
			long y = scanner.nextLong();
			long z = scanner.nextLong();
			for(int j=0; j<8; j++) {
//				System.out.println((4&j) + "," + (2&j)+ "," + (1&j));
				if((4 & j) == 4)
					totalValue[j][i] += -x;
				else
					totalValue[j][i] += x;
				if((2 & j) == 2)
					totalValue[j][i] += -y;
				else
					totalValue[j][i] += y;
				if((1 & j) == 1)
					totalValue[j][i] += -z;
				else
					totalValue[j][i] += z;
			}
		}
		long max = Long.MIN_VALUE; 
		for(int i=0; i<8; i++) {
//			System.out.println(Arrays.toString(totalValue[i]));
			Arrays.sort(totalValue[i]);
//			System.out.println(Arrays.toString(totalValue[i]));
			long sum = 0l;
			for(int j=n-m; j<n; j++) {
				sum += totalValue[i][j];
			}
//			System.out.println(sum);
			if(sum > max)
				max = sum;
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 27656
<?php
fscanf(STDIN, "%d", $N);

$ans = 0;
for ($j = 1; $j <= $N; $j++) {

    $Y = floor($N / $j);
    $tmp = $Y * ($Y + 1) * $j / 2;

    $ans += $tmp;
}

printf("%d", $ans);


Measured memory_bytes: 16220
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    string s, t;
    cin >> s;
    cin >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if ( s<t ) {
        printf("Yes\n");

    } else {
        printf("No\n");
    }
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;
    int x = n * 800;
    int y = 200 * (n / 15);

    cout << x - y << endl;

    return 0;
}

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

int main(){
	int N;
	int A, B;
	int min_place, min_point;

	cin >> N;
	min_place = 0;
	for(int i = 1; i <= N; i++){
		cin >> A >> B;
		if(A > min_place){
			min_place = A;
			min_point = B;
		}
	}

	cout << min_place + min_point << endl;

	return 0;
}


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

int main(){
int n;
int a=100000;
cin>>n;
while (n--){
	a*=1.05;
	int l=a%1000;
	if(l>0)a+=1000-l;
	
}
cout<<a<<endl;
return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

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


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){


 // }
     int n,k;
     cin >> n >> k;
     vi v(n+1);
     while(k--){
     	int m;
     	cin >> m;
     	fo(i,0,m){
     		int a;
     		cin >> a;
     		v[a]++;
     	}
     }
     int count = 0;
     fo(i,1,n+1){
     	if(v[i] == 0)count++;
     }
     cout << count << endl;

return 0;
	
	}




Measured memory_bytes: 3576
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

/////////////////////////////////////////////////////////////////

int main(){
    ll n,k;cin>>n>>k;
    ll x[n];rep(i,0,n-1)cin>>x[i];
    ll init=lower_bound(x, x+n, 0)-x;
    ll ans=inf;
    if(init+k-1<=n-1)ans=min(ans,x[init+k-1]);
    if(x[init]!=0){
        if(init-k>=0)ans=min(ans,-x[init-k]);
    }else{
        if(init-k+1>=0)ans=min(ans,-x[init-k+1]);
    }
    rep(i,0,init-1){
        int j=i+k-1;
        if(0<=j&&j<=n-1)ans=min(ans,-x[i]+(x[j]-x[i]));
    }
    rep(j,init+1,n-1){
        int i=j-k+1;
        if(0<=i&&i<=n-1)ans=min(ans,x[j]+(x[j]-x[i]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  2 11:20:26 2020
//
package main

import (
	"fmt"
	"math/big"
)

const MOD = 1e9 + 7

var N int
var A []int

func gcd(n, m *big.Int) *big.Int {
	if m.Cmp(big.NewInt(0)) == 0 {
		return n
	} else if n.Cmp(m) == 1 {
		return gcd(m, n.Mod(n, m))
	} else {
		return gcd(n, m.Mod(m, n))
	}
}

func solve() int64 {
	mod := big.NewInt(MOD)

	lcm := big.NewInt(int64(A[0]))
	for i := range A {
		a := big.NewInt(int64(A[i]))
		g := big.NewInt(0)
		g.GCD(nil, nil, lcm, a)
		lcm.Mul(lcm, a)
		lcm.Div(lcm, g)
	}

	ans := big.NewInt(0)
	for i := range A {
		a := big.NewInt(int64(A[i]))
		x := big.NewInt(0)
		x.Div(lcm, a)
		ans.Add(ans, x)
	}
	return ans.Mod(ans, mod).Int64()
}

func main() {
	fmt.Scan(&N)
	A = make([]int, N)
	for i := range A {
		fmt.Scan(&A[i])
	}

	fmt.Println(solve())
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll N,A,B;
    cin >> N >> A >> B;
    if(N == 1){
        if(A == B) cout << 1 << endl;
        else cout << 0 << endl;;
    }else{
        if(A > B) cout << 0 << endl;
        else cout << (B-A)*(N-2)+1 << endl;
    }

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int h = in.nextInt();

            out.println((a + b) * h / 2);
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;

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

	cin >> a >> b;
	cout << ((a<=9 && b<=9) ? (a*b) : -1) << endl;
	return 0;
}



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

int main() {
  char c;
  cin >> c;
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
      cout <<"vowel" << endl;
    }
    else{
      cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int64_t INFL = 0x3F3F3F3F3F3F3F3FLL;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        ll a = INFL, z = 0;
        for (ll i = 0; i < s.size(); i++) {
            if (s[i] == 'A') {
                a = min(a, i);
            }
            if (s[i] == 'Z') {
                z = max(z, i);
            }
        }
        out << z - a + 1 << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
 
using namespace std;
 
int n, i, res;
char a[1000], b[1000], c[1000];
 
int main()
{
    cin >> n;
    scanf("%s", &a);
    scanf("%s", &b);
    scanf("%s", &c);
    for(i = 0; i < n; i++) 
    {
        if(a[i] == b[i])
            if(a[i] != c[i]) res++;
        if(a[i] != b[i])
        {
             if(b[i] == c[i]) res++;
             if(b[i] != c[i])
             {
                 if(c[i] == a[i]) res++;
                 if(c[i] != a[i]) res += 2;
             }
         }
    }
    cout << res << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> m;
  rep(l,m){
    ll u = 0,d = 0,a,b;
    cin >> n ;
    cin >> b;
    rep(i,n-1){
      cin >> a;
      if(a - b>0)
        u = max(u,a - b);
      else{
        d = max(d,b-a);
      }
      b = a;
    }
    cout << u << " " << d << endl;
  }
  return 0;
}

Measured memory_bytes: 3044
#include<stdio.h>

int main(){
  int i, n, q, ans=0;
  int Y[10001], key[10001];

  scanf("%d", &n);
  for(i=0 ; i<n ; i++){
    scanf("%d", &Y[i]);
  }
  scanf("%d", &q);
  for(i=0 ; i<q ; i++){
    scanf("%d", &key[i]);
  }
    for(i=0 ; i<q ; i++){
    if(LS(Y, n, key[i])==1)ans++;
  }
  printf("%d\n",ans);
  return 0;
}

int LS(int X[], int n, int key){
  int i=0;
  while(i<n){
    if(X[i]==key)return 1;
    i++;
  }
  return 0;
}


Measured memory_bytes: 2144
h,w = map(int,input().split())
t = "."*(w+2)
b = [t]
for i in range(h):
  s = str(input())
  s = "."+ s + "."
  b.append(s)
b.append(t)
for i in range(1,h+1):
  for j in range(1,w+1):
    if b[i][j] == "#":
      if all([b[i-1][j]==".",b[i+1][j]==".",b[i][j-1]==".",b[i][j+1]=="."]):
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include<cmath>
using namespace std;
void arraycout(int *arrayy,int n){
    for(int u=0;u<n;u++){//出力
        if(u==n-1){
            cout<<arrayy[u]<<endl;
        }else{
            cout<<arrayy[u]<<' ';
        }
    }
    
}


void insertionSort(int* sou,int n){//挿入ソート
    for(int i=0;i<n;i++){

        int v=sou[i];
        int j=i-1;
        while(j>=0&&v<sou[j]){
            sou[j+1]=sou[j];
            j--;
        }
        sou[j+1]=v;
                arraycout(sou,n);
        
    }
}
int Bubble1(int* sou,int n){
    int flag=1;
    int ans=0;
    while(flag){
        flag=0;
        for(int i=n-1;i>0;i--){
            if(sou[i]<sou[i-1]){
                flag=1;
                swap(sou[i],sou[i-1]);
                ans++;
            }
        }
    }
    return ans;
    
}
int Bubble(int* sou,int n){
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i+1;j--){
            if(sou[j]<sou[j-1]){
                ans++;
                swap(sou[j],sou[j-1]);
            }
        }
    }
    return ans;
}
int main(){
    
    int n;
    cin>>n;
    int sou[n];
    for(int i=0;i<n;i++){
        cin>>sou[i];
    }
    int ans=Bubble(sou,n);
    arraycout(sou,n);
    cout<<ans<<endl;
   // insertionSort(sou,n);
   // arraycout(sou,n);
    
    return 0;
}



Measured memory_bytes: 3140
import sys

def Grouping(F):
    n = len(F)
    G = [None for i in range(n)]
    for u in range(n):
        if G[u] is None:
            G[u] = u
            S = [u]
            while(len(S) > 0):
                u1 = S.pop()
                for u2 in F[u1]:
                    if G[u2] is None:
                        G[u2] = u
                        S.append(u2)
    return G

def main():
    istr = sys.stdin.read()
    ilist = istr.splitlines()
    unum, fnum = list(map(int,ilist[0].split()))

    F = [[]  for i in range(unum)]
    fnum += 1
    for n in range(1, fnum):
        uid, fid = map(int,ilist[n].split())
        F[uid].append(fid)
        F[fid].append(uid)
    
    G = Grouping(F)

    qnum = int(ilist[fnum])
    fnum += 1
    for q in range(fnum, (fnum + qnum)):
        id1, id2 = map(int,ilist[q].split())
        if G[id1] == G[id2]:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Measured memory_bytes: 36044
#include<stdio.h>
#define NUM 999
int main(){
   int x ;
   scanf("%d",&x);
   if(x%10==2||x%10==4||x%10==5||x%10==7||x%10==9){
      printf("hon");
   }else if(x%10==0||x%10==1||x%10==6||x%10==8){
      printf("pon");
   }else if(x%10==3){
      printf("bon");
   }
     

   
   return 0;
}


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

void solve() {
	int n; cin >> n;
	vector<ld> dp(n + 1, 0), prob(n);
	for (int i = 0; i < n; ++i) {
		cin >> prob[i];
	}
	dp[0] = 1;
	for (auto p : prob) {
		for (int i = n; i >= 0; --i) {
			dp[i] = dp[i] * (1 - p) + (i == 0? 0 : dp[i - 1] * p);
		}
	}
	ld res = 0;
	for (int i = n/2 + 1; i <= n; ++i) {
		res += dp[i];
	}
	cout << res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>


using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;

//abc104
//基本的には、一番むずかしい問題を解いたほうがよい
//全問といたときの効果
int main() {

    ll D,G;
    cin >> D >> G;

    ll p[D];
    ll c[D];

    ll tmp;

    REP(i,D)
    {
        cin >> p[i] >> c[i];
    }

    ll res = 10000000000;

    //2^D通り 全完の組み合わせ
    for(ll bit = 0; bit < (1<<D); bit++)
    {
        ll sum = 0;
        ll num = 0;
        for(ll i = 0; i < D; ++i)
        {
            if(bit & (1 << i))
            {
                //i*100点*問題数 + ボーナス点
                sum += (i + 1) * 100 * p[i]  + c[i];
                //問題数
                num += p[i];
            }
        }
        if(G <= sum)
        {
            res = min(res,num);
        }
        else
        {
            //高得点から解いていく
            for(ll i = D - 1; i  >= 0; --i)
            {
                //すでに解いている場合は行わない
                if(bit & (1 << i))continue;

                for(ll j = 0; j < p[i]; ++j)
                {
                    if(sum >= G)break;
                    sum += (i+1)*100;
                    ++num;
                }
            }
            res = min(res,num);
        }
    }

    cout << res << endl;

    return 0;

}

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

const int max_n = 100005;

int arr[max_n + 1];

int main(void)
{
	int n;
	int i;
	int nb_perm = 0;
	scanf("%d\n", &n);
	for(i = 0; i < n; ++i)
		scanf("%d", &arr[i]);

	for(i = 0; i < n; ++i) {
		if(arr[i] == (i + 1)) {
			nb_perm++;
			if((i + 1) < n && arr[i + 1] == (i + 2))
				++i;
		}
	}

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

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
inline int max(const int a, const int b){return a>b?a:b;}
//fast(?) Input
#define buf_sz 1<<24
char buf[buf_sz];
unsigned int nextint(){
	static int id = 0;
	if(id == 0)read(0, buf, buf_sz);
	unsigned int res = 0;
	while(id<buf_sz && buf[id]<'0' || '9'<buf[id])id++;
	while(id<buf_sz && '0'<=buf[id] && buf[id]<='9'){
		res *= 10;
		res += buf[id++] - '0';
	}if(id>=buf_sz)exit(1);
	return res;
}
#undef buf_sz

int d[] = {[0 ... 1<<18] -1};
int find(int x){
	if(d[x] < 0) return x;
	return d[x] = find(d[x]);
}
bool unite(int x, int y){
	x = find(x); y = find(y);
	if(x == y)return false;
	if(d[x] > d[y]){
		int tmp = x;
		x = y;
		y = tmp;
	}
	d[x] += d[y];
	d[y] = x;
	return true;
}
bool same(int x, int y){return find(x) == find(y);}
int size(int x){return -d[find(x)];}

int ans;
int main(){
	int N = nextint(), M = nextint();
	while(M--)unite(nextint(), nextint());
	for(int i=1; i<=N; i++)ans = max(ans, size(i));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4928
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int sum = 0;
    int ichi = 0;
    int jyu = 0;
    int jyu_2 = 0;
    int jyu_3 = 0;
    int jyu_4 = 0;

    for(int i=1;i<=n;i++){  
      //1桁目
      ichi = i%10;
      //2から5桁目
      jyu = (i/10)%10;
      jyu_2 = (i/100)%10;
      jyu_3 = (i/1000)%10;
      jyu_4 = (i/10000)%10;
      
      if ((a <= (ichi + jyu + jyu_2 + jyu_3 + jyu_4)) && 
          ((ichi + jyu + jyu_2 + jyu_3 + jyu_4) <= b)){
        sum += i;
      }
    }
    
    System.out.println(sum);

  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
using lli = long long int;

lli nc2(lli l) {
	if (l < 2)return 0;
	lli ret = l;
	return (l * (l - 1)) / 2;
}

int main() {
	string s,t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		rotate(s.begin(), s.begin() + 1, s.end());
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int max = -1, min = 1001;
			int sum = 0;
			int n = in.nextInt();
			if (n == 0) break;
			for (int i = 0; i < n; i++) {
				int x = in.nextInt();
				sum += x;
				if (max < x) max = x;
				if (min > x) min = x;
			}
			System.out.println((sum - max - min) / (n - 2));
		}
	}
}

Measured memory_bytes: 21008
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;
    int N, M, X;
    vector<int> As;

    cin >> N >> M >> X;
    copy_n(istream_iterator<int>(cin), M, back_inserter(As));

    auto left = count_if(As.begin(), As.end(), [X](int a) { return a < X; });
    auto right = count_if(As.begin(), As.end(), [X](int a) { return a > X; });

    cout << min(left, right) << endl;
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int ans=0;
    for (int i=0 ; i<S.size()/2 ; i++){
        if (S.at(i)!=S.at(S.size()-i-1))
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define mod (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}



template<typename T>
struct BIT {
    vector<T> array;
    const int n;
public:
    BIT(int _n) : array(_n + 1, 0), n(_n) {}
    
    // 1番目からi番目までの累積和
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += array[i];
            i -= i & -i;
        }
        return s;
    }
    
    // [i, j]の要素の総和
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);
        return ret_j - ret_i;
    }
    
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

void solve() {
    int n;
    cin >> n;
    vector<pii> p(n);
    rep(i, n) { cin >> p[i].F; p[i].S = i; }
    sort(all(p), greater<pii>());
    
    BIT<int> bit(n);
    int ans = 0;
    rep(i, n) {
        bit.add(p[i].S + 1, 1);
        int sum = bit.sum(p[i].S + 1);
        if (sum == p[i].S + 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b,i;
    cin>>k;
    cin>>a>>b;
    int flag=0;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"OK"<<"\n";
    else
    cout<<"NG"<<"\n";
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
int c(const void *v1,const void *v2){
    return *(int *)v1-*(int *)v2;
}
int main(void){
    int n1,n2,i,line[20000],line1[20000],max;
    for(;scanf("%d %d",&n1,&n2),(n1+n2)!=0;){
        for(i=0;scanf("%d",&line[i++]),i!=(n1+n2););
        qsort(line,n1+n2,4,c);
        line1[0]=line[0];
        for(i=1;i<n1+n2;i++)
            line1[i]=line[i]-line[i-1];
        for(i=1,max=line1[0];i<n1+n2;i++)
            if(max<line1[i])
                max=line1[i];
        printf("%d\n",max);
    }
    return 0;
}

Measured memory_bytes: 880
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;
bool cmp(PII a,PII b)
{
    return(a.s>b.s);
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>m)
    {
        ll ara[n];
        for(i=0;i<n;i++) cin>>ara[i];
        PII pr[m];
        
        for(i=0;i<m;i++) cin>>pr[i].f>>pr[i].s;
        sort(ara,ara+n);
        i=0,j=0;
        ll sum=0;
        sort(pr,pr+m,cmp);
        while(j<m && i<n){
            k=0;
            while(i<n && ara[i]<pr[j].s && k<pr[j].f){
                sum+=pr[j].s;
                ++i,++k;
            }
            ++j;
        }
 
        while(i<n){
            sum+=ara[i];
            ++i;
        }
 
        cout<<sum<<endl;
    }
 
 
 
 
}

Measured memory_bytes: 2560
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,M,X,Y=get_i
x=get_i
y=get_i
if x.max>=y.min
    puts "War"
else
    (x.max+1).upto(y.min) do|i|
      if X<i and i<=Y
          puts "No War"
          exit()
      end
    end
    puts "War"
end

Measured memory_bytes: 1916
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

ll dp[100010][11];

ll f(int d, int b)
{
  if (dp[d][b] != -1)
    return dp[d][b];
  if (d == 0)
    return 1;

  ll res = 0;

  if (b == 10)
  {
    for (int i = 1; i <= 9; i++)
    {
      res += f(d - 1, i);
    }
  }
  else
  {
    for (int i = max(0, b - 1); i <= min(9, b + 1); i++)
    {
      res += f(d - 1, i);
    }
  }

  return dp[d][b] = res;
}

string ans;
ll k;

void calc(int di, int b)
{
  if (di == 0)
    return;
  ll val;


  if (b == 10)
  {
    for (int i = 1; i <= 9; i++)
    {
      val = f(di - 1, i);
      if (k <= val)
      {
        ans.push_back((char)(i + '0'));
        calc(di - 1, i);
        return;
      }
      k -= val;
    }
  }
  else
  {
    for (int i = max(0, b - 1); i <= min(9, b + 1); i++)
    {
      val = f(di - 1, i);
      if (k <= val)
      {
        ans.push_back((char)(i + '0'));
        calc(di - 1, i);
        return;
      }
      k -= val;
    }
  }
  assert(false);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  cin >> k;
  rep(i, 100010) rep(j, 11) dp[i][j] = -1;

  for (int d = 1; d <= 100010; d++)
  {
    ll val = f(d, 10);
    if (k <= val)
    {
      calc(d, 10);
      cout << ans << endl;
      return 0;
    }
    k -= val;
  }
  assert(false);
  return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> que;
    rep(i, (int)(s.size())) {
        que.push_back(s[i]);
    }
    bool rev_flg = false;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            rev_flg = !rev_flg;
        }
        else if (t == 2) {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (!rev_flg && f == 1 || rev_flg && f == 2) {
                que.push_front(c);
            }
            else {
                que.push_back(c);
            }
        }
    }
    while(!que.empty()) {
        if (rev_flg) {
            cout << que.back();
            que.pop_back();
        }
        else {
            cout << que.front();
            que.pop_front();
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4016
import math
a, b, x = map(float, input().split())
if x < a * a * b / 2:
    print(math.atan(a * b * b / (2 * x)) * 180 / math.pi)
else:
    print(math.atan((b - x / (a * a)) * 2 / a) * 180 / math.pi)

Measured memory_bytes: 2940
slime_number = int(input())
slime_colors = list(input())

last_slime = 'ほげ'
result = 0

for i in range(slime_number):
  if last_slime != slime_colors[i]:
    last_slime = slime_colors[i]
    result += 1

print(max(result, 1))


Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n;
  cin>>n;

  vector<ll> x(n);
  vector<ll> y(n);

  if(n==1){
    cout << 1 << endl;
    return 0;
  }

  rep(i,n){
    cin>>x[i];
    cin>>y[i];
  }

  vector< vector< pair<ll,ll> > > graph( n,vector<pair<ll,ll>>(n) );

  auto pp=[](const pair<ll,ll> x){ cout << x.first << "," << x.second << endl; };

  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      graph[i][j]=make_pair( x[j]-x[i] ,y[j]-y[i]);
      //pp(graph[i][j]);
      //cout << graph[i][j].first << "," << graph[i][j].second << endl;
    }
  }

  ll ans=0;

  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      ll tmp=0;
      for(ll k=0;k<n;k++){
        for(ll l=k+1;l<n;l++){
          if( (i==k&&j==l)  )  continue;
          else{
            if( (graph[i][j] == graph[k][l]) || ( graph[i][j].first == -graph[k][l].first && graph[i][j].second == -graph[k][l].second ) ) tmp++;
          }
        }
      }
      ans=max(ans,tmp);
    }
  }
  //cout << ans << endl;
  cout << n-ans-1 << endl;

  return 0;

}


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

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

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1111;
int a[N],c[N];
int n;
int main(){
	char ch;
	scanf("%c",&ch);
	if ('a'<=ch&&ch<='z')	printf("a\n");
	if ('A'<=ch&&ch<='Z')	printf("A\n");
    return 0;
}

Measured memory_bytes: 1596
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N = read_int()
    X = read_int_list()
    # p = sum(X) // N
    p = round(sum(X) / N)
    res = 0
    for i in range(N):
      res += (X[i] - p) ** 2
    print(res)


main()


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#define nmax 200010
using namespace std;

int n,m;
bool onr[nmax];
int poz[nmax];
vector< pair<int,int>> g[nmax];

int l[nmax];
int r[nmax];
int d[nmax];

bool viz[nmax];

void solve(int nod)
{
    viz[nod]=1;
    for( pair<int,int> p:g[nod])
    {
        poz[p.first]=poz[nod]+p.second;
        if(!viz[p.first])
            solve(p.first);
    }
}

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


    for(i=1;i<=m;i++)
    {
        cin>>l[i]>>r[i]>>d[i];
        onr[r[i]]=1;
        g[l[i]].push_back( make_pair(r[i],d[i]));
    }

    for(i=1;i<=n;i++)
        if(!onr[i])
            solve(i);

  //  for(i=1;i<=n;i++) cout<<poz[i]<<' '; cout<<'\n';

    for(i=1;i<=n;i++)
        if( poz[r[i]]-poz[l[i]]!=d[i])
        {
            cout<<"No\n";
            return 0;
        }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 13824
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		char[][] c = new char[h][w];
		for (int i = 0; i < h; i++) {
			String s = scan.next();
			for (int j = 0; j < w; j++) {
				c[i][j] = s.charAt(j);
			}
		}
		String[] sr = new String[h];
		for (int i = 0; i < h; i++) {
			sr[i] = "";
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				sr[i] = sr[i]+c[i][j];
			}
		}
		int a = 0;
		boolean f = false;
		while (a<h) {
			System.out.println(sr[a]);
			if (f == true) {
				a++;
				f = false;
			} else {
				f = true;
			}
		}
	}
}


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

const int maxn = 1e5 + 10;

int data[maxn], n, sum;

inline int IN() {
	int x = 0;
	bool flag = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
	    flag |= (ch == '-');
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return flag ? -x : x;
}

inline void write_int(int x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write_int(x / 10);
    putchar(x % 10 + '0');
}

int main() {
	n = IN();
	for (register int i = 1; i <= n; i++) {
		data[i] = IN();
		sum += abs(data[i] - data[i - 1]);
	}
	data[n + 1] = 0;
	sum += abs(data[n]);
	for (register int i = 1; i <= n; i++) {
		write_int(sum + abs(data[i - 1] - data[i + 1]) - abs(data[i - 1] - data[i]) - abs(data[i + 1] - data[i]));
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
const LL N = 2005;
const LL M = 400005;

vector <LL> G[N];
LL vis[2][N][N],p[2][N],vi[N];
LL eu[M],ev[M],n,m;

void dfs_vis(LL u,LL rt){
	vis[0][rt][u] = 1;
	vi[u] = 1;
	for(LL i = 0;i < G[u].size();i ++){
		LL v = ev[G[u][i]];
		if(vi[v]) continue;
		dfs_vis(v,rt);
	}
}

void get_vis(){
	for(LL i = 1;i <= n;i ++){
		memset(vi,0,sizeof(vi));
		dfs_vis(i,i);
	}
}

void dfs_sol(LL u,LL col,LL pid,LL rt){
	p[pid][u] = col;
	vi[u] = 1;
	for(LL i = 0;i < G[u].size();i ++){
		LL v = ev[G[u][i]];
		if(vi[v]) continue;
		dfs_sol(v,col,pid,rt);
	}
}

void solve(LL u){
	memset(p,0,sizeof(p));
	memset(vi,0,sizeof(vi)); vi[u] = 1;
	for(LL i = 0;i < G[u].size();i ++) if(!vi[ev[G[u][i]]]) dfs_sol(ev[G[u][i]],i + 1,0,u);
	memset(vi,0,sizeof(vi)); vi[u] = 1;
	for(LL i = (LL)(G[u].size()) - 1;i >= 0;i --) if(!vi[ev[G[u][i]]]) dfs_sol(ev[G[u][i]],i + 1,1,u);
	for(LL i = 1;i <= n;i ++) if(vi[i] && p[0][i] != p[1][i]) vis[1][u][i] = 1;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(LL i = 1;i <= m;i ++){
		cin >> eu[i] >> ev[i];
		G[eu[i]].push_back(i);
	}
	get_vis();
	for(LL i = 1;i <= n;i ++) solve(i);
//	for(LL i = 1;i <= m;i ++) cout << ans[0][i] << ' ' << ans[1][i] << endl;
	for(LL i = 1;i <= m;i ++) cout << ((vis[0][ev[i]][eu[i]] ^ vis[1][eu[i]][ev[i]]) ? "diff" : "same") << '\n';
	return 0;
}

Measured memory_bytes: 44928
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
ll a,b,c,d;
ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
ll min_c(ll x,ll y){
    if(x%y==0) return x;
    else return y*(x/y+1); 
}
ll max_c(ll x,ll y){
    if(x%y==0) return x;
    else return y*(x/y);
}
int main(){
    cin>>a>>b>>c>>d;
    //最小公倍数e
    ll e=c*d/gcd(max(c,d),min(c,d));
    //cout<<e<<endl;
    ll cnt1=0,cnt2=0,cnt3=0;
    ll left=min_c(a,c), right=max_c(b,c);//a以上の最小,b以下の最大
    if(left<=b && right>=a){
        if(left==right) cnt1=1;
        else cnt1=(right-left)/c+1;
    }
    left=min_c(a,d), right=max_c(b,d);//a以上の最小,b以下の最大
    if(left<=b && right>=a){
        if(left==right) cnt2=1;
        else cnt2=(right-left)/d+1;
    }
    left=min_c(a,e), right=max_c(b,e);//a以上の最小,b以下の最大
    if(left<=b && right>=a){
        if(left==right) cnt3=1;
        else cnt3=(right-left)/e+1;
    }
    cout<<b-a+1-cnt1-cnt2+cnt3<<endl;
    return 0;
}


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

#define INF (1LL<<60)

long long cnt[200001];
long long sum[200001];
long long A[100000];

long long n,m;

long long Check(long long num){
	long long ret=0;

	for(int i=0;i<n;i++){
		ret+=cnt[ max(num-A[i],0LL) ];
	}
	return ret;
}

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

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

	// 左手を先に決めた時の、右手握手できる人数を求める用
	for(int i=100000;i>=0;i--){
		cnt[i]+=cnt[i+1];
		sum[i]+=sum[i+1];
	}

	long long OK=0, NG=200001;
	while(NG-OK>1){
		long long mid=(OK+NG)/2, tmp=0;

		if(Check(mid)>=m)OK=mid;
		else NG=mid;
	}
	//cout<<OK<<endl;

	long long ans=0;
	for(int i=0;i<n;i++){
		ans+=sum[ max(OK-A[i],0LL) ] + A[i]*cnt[ max(OK-A[i],0LL) ];
	}
	//cout<<ans<<endl;

	long long tmp=Check(OK);
	//cout<<tmp<<endl;

	ans-=(tmp-m)*OK;
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod =  998244353;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

ll dp[10010] = {-1, -1, -1, -1, -1, -1, -1, -1};

signed main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  ll b[] = {0,2,5,5,4,5,6,3,7,6};
  ll a[10] = {};
  REP(i, m) {
    int tmp;
    cin >> tmp;
    a[tmp] = 1;
  }
  dp[0] = 0;
  REP(j, 10) {
    if(a[j] == 0) continue;
    dp[b[j]] = 1;
  }
  REP(i, n) {
    if(dp[i] <= 0) continue;
    REP(j, 10) {
      if(a[j] == 0) continue;
      dp[i+b[j]] = max(dp[i+b[j]], dp[i]+1);
    }
  }
  vector<int> hoge;
  while(n > 0) {
    REP(i, 9) {
      if(a[9-i] == 0 || n-b[9-i] < 0) continue;
      if(dp[n] - dp[n-b[9-i]] == 1) {
        cout << 9-i;
        n -= b[9-i];
        break;
      }
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384