akhauriyash/Code-Regression huggingface dataset:
import sys

def solve():
    input = sys.stdin.readline
    A = [[int(i) for i in input().split()] for _ in range(3)]
    O = [[False] * 3 for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == b: O[i][j] = True

    for i in range(3):
        if False in O[i]: continue
        else:
            print("Yes")
            break
    else:
        for i in range(3):
            if O[0][i] == O[1][i] == O[2][i] == True:
                print("Yes")
                break
        else:
            if O[0][0] == O[1][1] == O[2][2] == True: print("Yes")
            elif O[0][2] == O[1][1] == O[2][0] == True: print("Yes")
            else: print("No")

    return 0

if __name__ =="__main__":
    solve()

Measured memory_bytes: 38484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  char a[h+2][w+2];
  for(int i = 0;i < h+2;i++){
    for(int j = 0;j < w+2;j++){
      if(i == 0 || j == 0) a[i][j] = '#';
      else if (i == h+1 || j == w+1) a[i][j] = '#';
      else cin >> a[i][j];
      
      cout << a[i][j];
	  if (j == w+1) cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, cnt = 0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < 1000; i++)
    {
        int c[3] = {i / 100, (i/10) % 10, i % 10};
        int f = 0;
        for (int j = 0; j < N; j++)
        {
            if(S[j] == ('0' + c[f])) f++;
            if(f == 3) break;
        }
        if(f == 3) cnt++;
    }
    cout << cnt << endl;
}

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

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = scanner.nextInt();

			int ans = n;
			for (int i = 0; i < n; i++) {
				for (int j = 1; j < 4; j++) {
					if (a[i] == j)
						continue;
					int tmp = a[i];
					a[i] = j;
					int l = i;
					int r = i;
					int cnt = 0;
					while (0 <= l) {
						int cc = a[l];
						while (l > 0 && cc == a[l - 1])
							l--;
						while (r < n - 1 && cc == a[r + 1])
							r++;
						if (r - l - cnt < 3)
							break;
						cnt = r - l + 1;
						l--;
					}
					a[i] = tmp;
					ans = Math.min(ans, n - cnt);
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 42420
W, H = map(int, input().split())
P = []
Q = []
for i in range(W):
    P.append(int(input()))
for i in range(H):
    Q.append(int(input()))

edges = []
for p in P:
    edges.append((p, 0))
for q in Q:
    edges.append((q, 1))
edges.sort()

def r(xy):
    if xy == 0:
        return 1
    return 0

WH = (W + 1, H + 1)
C = [0, 0]
answer = 0
for w, xy in edges:
    C[xy] += 1
    n = WH[r(xy)] - C[r(xy)]
    answer += n * w
print(answer)


Measured memory_bytes: 26204
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[27],b[27],c[27];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    for(int i=1;i<=n;++i)
        cin>>b[i];
    for(int i=1;i<n;++i)
        cin>>c[i];
    int sum=0;
    for(int i=1;i<=n;++i){
        sum+=b[a[i]];
        if(a[i-1]==a[i]-1&&i>1)
            sum+=c[a[i-1]];
    }
    cout<<sum;
    return 0;
}


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

int main() {
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if (u == s) {
        cout << a-1 << " " << b << endl;
    }
    else {
        cout << a << " " << b-1 << endl;
    }
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int diff(string &s, string &t, int i , int j){
    int dif = 0;
    for(int k = i ; k <= j; k++){
        if(s[k] != t[k-i]) dif++;
    }
    return dif;
}
int main(){
    string s, t;
    cin>>s>>t;
    int mind = t.size();
    for(int i  = 0 , j = t.size()-1; j < s.size(); i++,j++){
        mind = min(mind, diff(s, t, i , j));
    }
    cout<<mind;
    return 0;
}

Measured memory_bytes: 3580
from itertools import accumulate
from bisect import *
n = int(input())
a = list(map(int, input().split()))

a = [0]+list(accumulate(a))
#print(a)
ans = 10**18
for i in range(2, n):
    b = []
    m = a[i]
    l = bisect_right(a, m/2)
    if abs(a[l]-m/2) <= abs(a[l-1]-m/2):
        b.append(a[l])
        b.append(m-a[l])
    else:
        b.append(a[l-1])
        b.append(m-a[l-1])
    r = bisect_left(a, (a[-1]+m)/2)
    if abs(a[r]-(a[-1]+m)/2) <= abs(a[r-1]-(a[-1]+m)/2):
        b.append(a[r]-m)
        b.append(a[-1]-a[r])
    else:
        b.append(a[r-1]-m)
        b.append(a[-1]-a[r-1])

    #print(b)
    ans = min(ans, max(b)-min(b))

print(ans)


Measured memory_bytes: 25544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,m;
  cin >> n >> m;
  priority_queue<ll> que;
  rep(i,n){
    ll a;
    cin >> a;
    que.push(a);
  }
  ll ans=0;
  rep(i,m){
    ll cp=que.top();
    que.pop();
    cp/=2;
    que.push(cp);
  }
  while(!que.empty()){
    ll cp=que.top();
    que.pop();
    ans+=cp;
  }
  cout << ans;
}

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

int main() {
  int N;
  cin >> N;
  int a = N/1000;
  int b = N%1000/100;
  int c = N%100/10;
  int d = N%10;

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

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// 0 1 2 3 n-1
//  0 1 2 n-2

signed main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n-1);
  rep(i, n-1)
    cin >> b[i];
  a[0] = b[0];
  a[n-1] = b[n-2];
  for (int i = 1; i <= n-2; i++) {
    a[i] = min(b[i-1], b[i]);
  }

  ll ans = 0;
  rep(i,n)
    ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n,p,d;

ll power(ll a, ll b)
{
    if (b==0ll) return 1ll;
    if (b%2ll==0ll) return power(a,b/2)*power(a,b/2);
    else return a*power(a,b/2)*power(a,b/2);
}

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> p;
    if (n==1) rc(p);
    if (n>log2(p)) rc(1);
    for (ll i = 1ll; i <= p; ++i)
    {
        if (power(i,n)<=p)
        {
            if (p%power(i,n)==0) d=i;
        }
        else break;
    }
    cout << d;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int k;
	cin>>k>>s;
	int t=s.length();
	if(t<=k)cout<<s;
	else{
		for(int i=0;i<k;i++){
			cout<<s[i];
		}
		s[k]=s[k+1]=s[k+2]='.';
		cout<<s[k]<<s[k+1]<<s[k+2];
		}
	return 0;
}

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

struct edge {
    ll to, cost;
    ll rev;
    edge(int to, int cost) : to(to), cost(cost), rev(-1) {}
    edge(int rev) : to(-1), cost(-1), rev(rev) {}
};
vector<edge> G[3000];

struct UnionFind {
    static const int MAX = 3030;
    int par[MAX];
    void init(int N) {
        for (int i=0; i<N; ++i) {
            par[i] = -1;
        }
    }
    void init() {
        for (int i=0; i<MAX; ++i) {
            par[i] = -1;
        }
    }
    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) {
            int tmp = x;
            x = y;
            y = tmp;
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    // そのグループの木の大きさを返す
    int size(int x) {
        return -par[find(x)];
    }
};


int N, M;
UnionFind uf;
bitset<3030> visited;

void dfs(int v) {
    visited[v] = true;
    for (auto u : G[v]) {
        if (u.rev == -1) continue;
        if (visited[u.rev]) continue;
        uf.unite(N-1, u.rev);
        dfs(u.rev);
    }
}

ll d[3030];
const ll INF = 1e13;

// falseなら負の閉路がある
bool shortest_path(int s) {
    for (int i = 0; i < N; ++i) d[i] = INF;
    d[s] = 0;
    int num = 0;
    while (true) {
        bool update = false;
        for (int i=0; i<N; ++i) {
            for (auto e : G[i]) {

                if (e.to == -1) continue;
                if (!uf.same(i, N-1)) continue;

                if (d[i] != INF and d[e.to] > d[i] + e.cost) {
                    d[e.to] = d[i] + e.cost;
                    update = true;
                }
            }
        }
        if (update) {
            num++;
	     // V回以上更新があったら負の閉路がある
            if (num >= N) {
                return false;
            }
        }
        if (!update) break;
    }
    return true;
}

int main() {
    ll P;
    cin >> N >> M >> P;

    uf.init();

    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].emplace_back(b, -c + P);
        G[b].emplace_back(a);
    }

    dfs(N-1);
    bool negative = shortest_path(0);

    if (!negative) {
        cout << -1 << endl;
    }
    else {
        cout << max(0LL, -d[N-1]) << endl;
    }


}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string b = "";
    for (; n != 0; n /= -2)
    {
        if (n % 2 == 0)
        {
            b = "0" + b;
        }
        else
        {
            b = "1" + b;
            n -= 1;
        }
    }
    if (b.size() == 0)
    {
        b = "0";
    }
    cout << b << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int a[101010];

int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] == a[i]) {
			ans++;
			i++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define _ 0
#define M 5000000
#define N 5000000
#define int long long
#define drep(k ,l ,r) for(register int k = (r) ; k >= (l) ; -- k)
#define rep(k ,l ,r) for(register int k = l ; k <= r ; ++ k)
#define re register
using namespace std;
int h ,w ,n ,ans;
int read() {
	char cc = getchar() ; int cn = 0 ,flus = 1;
	while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus ; cc = getchar();}
	while(cc >= '0') cn = cn * 10 + cc - '0' ,cc = getchar();
	return flus * cn;
}
signed main() {
    h = read() ,w = read() ,n = read();
    ans = ceil((double)n / (double)(max(h ,w)));
    printf("%d" ,ans);
    return ~~(0^_^0);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N;
    string S;
    int A[300010] = {1};
    cin >> N;
    cin >> S;

    if(S[0] == 'E') A[0] = 1;
    else A[0] = 0;

    for(int i = 1; i< N; i++){
        if(S[i] == 'E') A[i]+=A[i-1]+1;
        else A[i] = A[i-1];
    }

    int change = 0;
    int min = 99999999;//N;
    for(int i = 0; i < N; i++) {
        if(i == 0) {
            change = A[N-1] - A[0];
        } else if(i >= N-1) {
            change = N-1 - (A[N-2]);
        } else {
            change = i - (A[i-1]) +  (A[N-1] - A[i]);
        }

        if(change <= min) {
            min = change;
        }
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 2052
using System;
using System.Linq;

namespace abc085_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = input[0];
            int Y = input[1];
            for(int i = 0; i <= N; i++)
            {
                for(int j = 0;j <= N - i; j++)
                {
                    if(i * 1000 + j * 5000 + 10000 * (N - i - j) == Y)
                    {
                        Console.WriteLine($"{N - i - j} {j} {i}");
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <stdio.h>

using namespace std;

const int N = 200010;

double q[N];

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

    double x;
    for (int i = 1; i <= n; i ++ )
    {
        cin >> x;
        q[i] = (x*(x+1)/2)/x;
    }

    double sum = 0;
    for (int i = 1; i <= k ; i ++ )
    {
        sum += q[i];
    }

    double maxs = sum;

    for (int i = k+1; i <= n; i ++ )
    {
        sum = sum+q[i]-q[i-k];
        maxs = max(sum,maxs);
    }

    printf("%.12f\n",maxs);

    return 0;
}


Measured memory_bytes: 1792
a=input()
a1=list(a)
c=""
j=0
list1=[]



for i in a1:
    if i=="0":
        list1.append("0")
        j=j+1
    elif i=="1":
        list1.append("1")
        j=j+1
    elif i!="0" and i!="1" and j>=1:
        list1.pop()
        j=j-1
for j in range(len(list1)):
    c=c+list1[j]
print(c)
	


Measured memory_bytes: 38256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int n, x, y;
    std::cin >> n >> x >> y;

    std::vector<std::vector<int>> min_dist(n + 1, std::vector<int>(n + 1));
    std::vector<int> min_count(n, 0);
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            min_count[std::min(std::abs(i - j), std::abs(i - x) + 1 + std::abs(y - j))]++;
        }
    }

    for (int i = 1; i < n; i++) {
        std::cout << min_count[i] << std::endl;
    }
}


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

int main(){
	int K,S;
	cin>>K>>S;
	
	int ans=0;
	for(int i=0;i<=K;i++){
		for(int j=0;j<=K;j++){
			if(S-i-j>=0&&S-i-j<=K)
				ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string s{}; cin >> s;
  auto res = boost::accumulate(s, 0U, [](auto r, char c){ return r + (c == 'x'); });

  cout << (res > 7 ? "NO" : "YES") << CRLF;

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>

using namespace std;

typedef long long ll;

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





signed main() {
	

	int n;
	cin >> n;


	for (int i = 1; i <= 9; i++) {
		int a;
		if (n % i != 0) {
			continue;
		}
		else {
			a = n / i;
			if (a < 10) {
				cout << "Yes";
				return 0;
			}
		}
	}

	cout << "No";
	return 0;
}


Measured memory_bytes: 256
import math
import itertools
import statistics

N = int(input())

x = []
y = []

for i in range(N):
    x_buf, y_buf = map(int, input().split())
    x.append(x_buf)
    y.append(y_buf)

dist_list = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    for j in range(i+1,N):
        distance = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        dist_list[i][j] = distance


l = [i for i in range(N)]
#print(l)
dist_sum = 0
dist_sum_list = []

for v in itertools.permutations(l, N):
    for i in range(N-1):
        if v[i] < v[i+1]:
            dist_sum += dist_list[v[i]][v[i+1]]
        else:
            dist_sum += dist_list[v[i+1]][v[i]]
    dist_sum_list.append(dist_sum)
    dist_sum = 0
    
mean = statistics.mean(dist_sum_list)
print(mean)

Measured memory_bytes: 6684
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	as := scanInts(n)

	all, bad := 1, 1
	for _, a := range as {
		all *= 3
		if a%2 == 0 {
			bad *= 2
		}
	}

	fmt.Println(all - bad)
}


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

using Graph=vector<vector<int>>;
vector<bool> seen(200010,false);
void dfs(Graph &G,vector<int> &count,int x){
  seen[x]=true;  
  for (auto y :G[x]){
    if (seen[y]){
      continue;
    }
    count[y]+=count[x];
    dfs(G,count,y);
  }
}
int main() {
  int N,Q;
  cin >> N >> Q;
  vector<vector<int>> G(N);
  for (int i=0;i<N-1;i++){
    int a,b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  vector<int> count(N);
  for (int i=0;i<Q;i++){
    int p,x;
    cin >> p >> x;
    count[p-1]+=x;
  }
  dfs(G,count,0);
  for (int i=0;i<N;i++){
    cout << count[i];
    if (i!=N-1){
      cout << ' ';
    }
    else {
      cout << endl;
    }
  }
}

Measured memory_bytes: 26624
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  char board[H][W];
  for (int i = 0; i < H; i++) {
	  for (int j = 0; j < W; j++) {
	    cin >> board[i][j];
      }
  }

  for (int i = 0; i < H; i++){
    int count = 0;
      for(int j = 0; j < W; j++){
        if(board[i][j] == '.' || board[i][j] == 'X') count++;
      }
       if(count == W){
          for(int j = 0; j < W; j++){
              board[i][j] = 'X';
          }
      }
  }

 for (int i = 0; i < W; i++){
    int count = 0;
      for(int j = 0; j < H; j++){
        if(board[j][i] == '.' || board[j][i] == 'X') count++;
      }
       if(count == H){
          for(int j = 0; j < H; j++){
              board[j][i] = 'X';
          }
      }
  }

  for (int i = 0; i < H; i++){
    int count2 = 0;
      for(int j = 0; j < W; j++){
        if(board[i][j] != 'X'){
          cout << board[i][j];
        }
        else count2++;
        if(j == W - 1 && count2 != W){
          cout << endl;
        }
      }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int a, b;
  cin >> a >> b;
  kek(6 - a - b);
  
}


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


int main() {

  int key, n;
  char com[20];
  list<int> L;
  scanf ("%d", &n);
  rep(i, n) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      L.push_front(key);
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') L.pop_front();
        else if (com[6] == 'L') L.pop_back();
      } else {
        for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
          if (*it == key) {
            L.erase(it);
            break;
          }
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
    if (i++) printf(" ");
    printf("%d", *it);
  }
  printf("\n");
  

  return 0;
}


Measured memory_bytes: 34480
#include <stdio.h>
#include <stdlib.h>


void bubbleSort(int numbers[], int array_size)
{
  int i, j, temp;

  for (i = 0; i < (array_size - 1); i++) {
    for (j = (array_size - 1); j > i; j--) {
      if (numbers[j-1] > numbers[j]) {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}

int main(void){
  int N;
  int *a;
  int i, j, temp;
  int sum_A=0, sum_B=0;
  int flg = 0;
  
  scanf("%d", &N);
  a = malloc(N*(sizeof(int)));
  for(i=0;i<N;i++){
    scanf("%d", &a[i]);
  }
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(a[j-1]>a[j]){
	temp = a[j-1];
	a[j-1] = a[j];
	a[j] = temp;
      }
    }
  }

  for(i=N-1;i>=0;i--){
    if(flg==0){
      sum_A += a[i];
      flg = 1;
    }else{
      sum_B += a[i];
      flg = 0;
    }
  }
  printf("%d", sum_A - sum_B);

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
 
int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	int max = a+b;
	if(max < a-b) max = a-b;
	if(max < a*b) max = a*b;
	
	printf("%d", max);
	
	return 0;
}

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (s); i <= (t); ++i)
#define repD(i,t,s) for(int i = (t); i >= (s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1) / (d) + 1)
#define parity(a,b) (((a)^(b)) & 1 ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = (1 << 30) - 1;
const ll INF_64 = (1LL << 62) - 1;
const int MOD = 1e9 + 7;

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

	ll n; cin >> n;
	const bitset<64> b(n);
	ll dp[64][3] = {{}};
	dp[63][2] = 1;
	repD(i,62,0){
		dp[i][0] += dp[i + 1][0] * 3 + dp[i + 1][1];
		if(b[i]){
			dp[i][0] += dp[i + 1][1];
			dp[i][1] += dp[i + 1][2] + dp[i + 1][1];
			dp[i][2] = dp[i + 1][2];
		}else{
			dp[i][2] += dp[i + 1][2] + dp[i + 1][1];
			dp[i][1] = dp[i + 1][1];
		}
		dp[i][0] %= MOD;
		dp[i][1] %= MOD;
		dp[i][2] %= MOD;
	}
	cout << (dp[0][0] + dp[0][1] + dp[0][2]) % MOD << endl;
}





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

int main(){
  int N,T,goAl,answer;
  float mini=1000;
  cin>>N>>T>>goAl;
  int altitude[N];
  for(int i=0;i<N;i++){
    cin>>altitude[i];
    float temp=T-0.006*altitude[i];
    if(abs(temp-goAl)<mini){
      mini=abs(temp-goAl);
      answer=i;
    }
  }
  cout<<answer+1<<endl;
  return 0;
}


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

int main() {
  
  int N ;
  string S,T ;
  cin >> N >> S >> T ;
  
  int i ;
  i = 0 ;
  
  while (i < N) {  
    cout << S.at(i) << T.at(i) ;
        i++ ;
  }
  
  cout << endl ;
  
}

Measured memory_bytes: 256
#include <iostream>

#include <math.h>
#include <algorithm>
using namespace std;
const int MAX = 100001;

int main()
{
	int N;
	int h[MAX];
	int dp[MAX];
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> h[i];

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

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

int main(void){
  string s;
  int N;
  cin>>N;
  cin>>s;
  int red = 0;
  int blue = 0;
  for(int i = 0; i<N; i++){
      if(s[i]=='R'){
          red++;
      }
      else{
          blue++;
      }
  }
  cout<<((red>blue)?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self, x):
        return -self.par[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

n, m = map(int, input().split())
uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.unite(a - 1, b - 1)

cnt = 0
for pa in uf.par:
    cnt = min(pa, cnt)
print(-cnt)


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

int main()
{
	int n, k, m, s;
	int h[100000];
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	sort(h, h + n);
	m = (1 << 30);
	for (int i = 0; i < n - k+1; i++) {
		s = h[i+k-1]-h[i];
		m = min(m, s);
	}
	cout << m << endl;
}

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

int main(){
	// おまじない
	cin.tie(0);
   	ios::sync_with_stdio(false);

	ll N,A,B;
    ll ans;
	cin >> N >> A >> B;
    if((B-A)%2 == 0){
        ans = (B-A)/2;
    }
    else{
        ans = (A-1 + B-1 + 1)/2;
        ans = min(ans,(N-B+N-A+1)/2);
    }
	cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      int count=0;
      Scanner scan = new Scanner(System.in);
      String s =  scan.nextLine();
      for(int i=0; i < s.length();i++){
        char a = s.charAt(i);
      if(a=='1')
      count++;
      }
      System.out.println(count);
      scan.close();
  }
}



Measured memory_bytes: 21844
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

S = input()
K = int(input())

for i, s in enu(S):
    if s != '1':
        print(s)
        exit()
    if i == K-1:
        print(s)
        exit()


Measured memory_bytes: 65616
#include<iostream>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
	char str[20000];
	scanf("%s",str);
	stack<int> S;
	stack< pair<int,int> > S2;
	vector<int> L;
	int sum=0,k=0;
	for(int i=0;i<strlen(str);i++){
		char t = str[i];
		if(t == '\\'){
			S.push(i);
		}else if(t == '/'){
			if(!S.empty()){
			int tmpArea = i - S.top();
			sum += tmpArea;
			//?????????????????????S2??¨first?????????????????????first????°????????????°??????????????????
			while(!S2.empty()){
				if(S2.top().first > S.top()){
					tmpArea += S2.top().second;
					S2.pop();
				}else if(S2.top().first < S.top()){
					break;
				}
			}
			S2.push(make_pair(S.top(),tmpArea));
			S.pop();
			}
		}
	}
	stack<int> ans;
	int size = S2.size();
	for(int i=0;i<size;i++){
		ans.push(S2.top().second);
		S2.pop();
	}
	
	cout<<sum<<endl;
	cout<<size;
	size = ans.size();
	for(int i=0;i<size;i++){
		cout<<" ";
		cout<<ans.top();
		ans.pop();
	}
	cout<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int n, k; cin >> n >> k;
    vector<int> w(n);
    int P = -1; int total = 0;
    rep(i,n){
        cin >> w[i];
        P = max(P,w[i]);
        total += w[i];
    }
    P = max(P,total/k)-1;
    int k_temp, w_temp;
    do{
        P++;
        k_temp = 1; w_temp = 0;
        rep(i,n){
            w_temp += w[i];
            if(w_temp > P){
                k_temp++;
                w_temp = w[i];
            }
        }
    }while(k_temp > k);
    
    cout << P << endl;
    return 0;
}


Measured memory_bytes: 3112
N,M=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(M)]
L=LR[0][0]
R=LR[0][1]
for i in range(1,M):
    if L<LR[i][0]:
        L=LR[i][0]
    if R>LR[i][1]:
        R=LR[i][1]
print(max(0,R-L+1))

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

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

//A[i] = A[i-1]^A[i+1], A[i+1] = A[i]^A[i+2]ならばA[i+2] = A[i-1]
//A[i+3] = A[i]において上記の仮定が成り立たないのはいつかな -> 任意のA[i] = k (k > 0)

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    sort(A, A+N);
    if(N % 3 == 0){
        int first = A[0];
        int second = A[N/3];
        int third = A[2*(N/3)];

        if(first != A[N/3 - 1] || second != A[2*(N/3) - 1] || third != A[N-1]){
            cout << "No" << endl;
            return 0;
        }

        for(int i = 0; i < N; i+=3){
            A[i] = first; A[i+1] = second; A[i+2] = third;
        }

        if((A[N-1]^A[1]) != A[0] || (A[N-2]^A[0]) != A[N-1]) cout << "No" << endl;    
        else{
            for(int i = 1; i <= N-2; i++){
                if((A[i-1]^A[i+1]) != A[i]){
                    cout << "No" << endl;
                    return 0;
                }
            }
            cout << "Yes" << endl;
        }
    }
    else{
        if(A[N-1] == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n = s.size();
    int flag = 1;
    for (int i = 0; i<n; i++) {
        if (i+1<n && s[i]==s[i+1]) {
            flag = 0;
            printf("%d %d\n", i+1, i+2);
            break;
        }
        if (i+2<n && s[i]==s[i+2]) {
            flag = 0;
            printf("%d %d\n", i+1, i+3);
            break;
        }
    }
    if (flag) {
        printf("-1 -1\n");
    }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;
LL n, k;

int main() {
	cin >> s >> k;
	n = s.size();
	
	int ans = 1;
	inc(i, min(n, k)) { if(s[i] != '1') { ans = s[i] - '0'; break; } }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[10];
int main () {
	cin >> s;
	bool f = false;
	for (int i = 0; i < 4; i++)
		if (s[i] == 'A' && s[i + 1] == 'C')
			f = true;
	if (f) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
m,n = map(int,input().split())
MOD = 1000000007

def power(m,n):
    if n == 1:
        return m
    else:
        if n % 2 == 0:
            return (power(m,n//2)**2)%MOD
        else:
            return ((power(m,n//2)**2)*m)%MOD

print(power(m,n))


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

const int MAX_NM = 100010;
int kyori_sum = 0;
int move(int now, int go, int kyori[], int type, int n);

int main(){
	int n, m;
	cin >>n >>m;
	int kyori[MAX_NM];
	for(int i = 0; i < (n - 1); i++){
		cin >>kyori[i];
		kyori_sum += kyori[i];
	}
	
	int idou, sum = 0, now = 0;
	for(int i = 0; i < m; i++){
		cin >>idou;
		int go = now + idou;
		int type;
		if(idou < (MAX_NM / 2)){
			type = 0;
		} else{
			type = 1;
		}
		sum += move(now, go, kyori, type, n);
		sum %= 100000;
		now = go;
	}
	cout <<sum <<endl;
	return 0;
}

int move(int now, int go, int kyori[], int type, int n){
	int ans = 0;
	int start = now, goal = go;
	if(start > goal) swap(start, goal);
	
	if(type == 0){
		for(int i = start; i < goal; i++){
			ans += kyori[i];
		}
	} else{
		int tmpans = 0;
		for(int i = 0; i < start; i++){
			tmpans += kyori[i];
		}
		for(int i = goal; i < (n - 1); i++){
			tmpans += kyori[i];
		}
		ans = kyori_sum - tmpans;
	}
	return ans;
}

Measured memory_bytes: 0
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n,m;cin >> n >> m;
    vector<int>a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    
    vector<int>ans(n,0);
    for(int i=0;i<m;i++){
        ans[a[i]-1]++;
        ans[b[i]-1]++;
    }
    rep(i,n)out(ans[i]);
    return 0;
}


Measured memory_bytes: 256
from math import floor
t1, t2 = map(int,input().split())
a1, a2 = map(int,input().split())
b1, b2 = map(int,input().split())

v1 = a1-b1
v2 = a2-b2

m1 = v1*t1
m2 = v2*t2

if m1>0:
    m1 *= -1
    m2 *= -1

if m1 == -m2:
    print('infinity')
elif m1+m2>0:
    ans = floor(-m1/(m2+m1)) * 2
    if m1%(m2+m1) != 0:
        ans += 1
    print(ans)
else:
    print(0)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n;
	cin >> n;
	v1 a(n);
	int s = 0;
	rep(i, n){
		int x;
		cin >> x;
		a[i] = x;
		s += x;
	}
	int p1 = s/n;
	int p2 = s/n + 1;
	int s1 = 0;
	int s2 = 0;
	rep(i, n){
		s1 += (p1-a[i])*(p1-a[i]);
		s2 += (p2-a[i])*(p2-a[i]);
	}
	cout << min(s1, s2) << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a<=c&&c<=b){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []


    while True:
        n,m,p,s,t = LI()
        if m == 0:
            break
        ta = LI()
        e = collections.defaultdict(list)
        for _ in range(p):
            a,b,c = LI()
            e[a].append((b,c))
            e[b].append((a,c))

        def search(s):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                if u[0] == t:
                    return d
                v[u] = True
                if len(u[1]) == 0:
                    continue

                for uu, ud in e[u[0]]:
                    for i in range(len(u[1])):
                        uv = (uu, tuple(u[1][:i] + u[1][i+1:]))
                        if v[uv]:
                            continue
                        vd = k + ud / u[1][i]
                        if d[uv] > vd:
                            d[uv] = vd
                            heapq.heappush(q, (vd, uv))

            return d

        d = search((s,tuple(ta)))
        r = inf
        for k,v in d.items():
            if k[0] == t and r > v:
                r = v

        if r == inf:
            r = 'Impossible'
        else:
            r = '{:0.99999f}'.format(r)
        rr.append(r)

    return '\n'.join(map(str, rr))



print(main())



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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう
int main(){
    int a,b,c,k;
    std::cin >> a>>b>>c>>k;
    int ans=0;
    ans+=min(a,k);
    k-=a;
    if(k<0)k=0;
    k-=b;
    if(k<0)k=0;
    ans-=min(c,k);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		if(a == b){
			System.out.println(c);
		}else if(b == c){
			System.out.println(a);
		}else{
			System.out.println(b);
		}

	}
}

Measured memory_bytes: 23636
def ge(x):
    return int(x) - 1


(n, m) = tuple(map(int, input().split()))
inp = list(map(ge, input().split()))
arr = [i for i in range(n)]


def root(a):
    global arr
    if arr[a] == a:
        return a
    else:
        tmp = root(arr[a])
        arr[a] = tmp
        return tmp


def sameroot(x, y):
    return root(x) == root(y)


def merge(x, y):
    global arr
    if not sameroot(x, y):
        arr[root(y)] = root(x)


for i in range(m):
    merge(*tuple(map(ge, input().split())))

res = 0
for i in range(n):
    if sameroot(i, inp[i]):
        res += 1
print(res)


Measured memory_bytes: 13812
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
  ll m;
  cin>>n>>m;
  ll p=(n*(n-1))/2 + (m*(m-1))/2;
  cout<<p;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3640