akhauriyash/Code-Regression huggingface dataset:
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	for {
		ans, ok := solve()
		if !ok {
			break
		}
		println(ans)
	}

}

func solve() (int, bool) {
	w := readInt()
	h := readInt()
	if w == 0 && h == 0 {
		return 0, false
	}

	c := make([][]int, h+2)
	c[0] = make([]int, w+2)
	c[h+1] = make([]int, w+2)
	for i := 1; i-1 < h; i++ {
		c[i] = make([]int, w+2)
		for j := 1; j-1 < w; j++ {
			c[i][j] = readInt()
		}
	}

	var ans int
	for i := 1; i-1 < h; i++ {
		for j := 1; j-1 < w; j++ {
			if 0 < c[i][j] {
				ans++
				dfs(c, i, j)
			}
		}
	}
	return ans, true
}

func dfs(c [][]int, y, x int) {
	c[y][x] = 0
	dx := []int{-1, 0, 1, -1, 1, -1, 0, 1}
	dy := []int{-1, -1, -1, 0, 0, 1, 1, 1}
	for i := range dx {
		nx := x + dx[i]
		ny := y + dy[i]
		if 0 < c[ny][nx] {
			dfs(c, ny, nx)
		}
	}
}

// -----------------------------------------------------------------------------



Measured memory_bytes: 2216
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int s[N-1],sum=0;
    for(int i=0; i<N; i++){
        cin >> s[i];
        sum = sum + s[i];
    }
    if(sum%10 != 0) {
        cout << sum << endl;
    }else{
        int min=100;
        for(int j=0; j<N; j++){
            if(s[j]%10 != 0){
                if(s[j] <= min){
                    min = s[j];
                }
            }
        }
        if((sum-min)%10 != 0 or (min-sum)%10 != 0){
            cout << sum-min << endl;
        }else{
            cout << 0 << endl;
        }
    }


    return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<pair<string, int> > S(N);

    for(int i = 0; i < N; i++){
        string a;
        int b;
        cin >> a >> b;
        ostringstream sout;
        sout << setfill('0') << setw(3) << (100-b);
        S[i].first = a + sout.str();
        S[i].second = i+1;
    }

    sort(S.begin(), S.end());
    for(int i = 0; i < N; i++){
        cout << S[i].second << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        long a = long.Parse(input[0]);
        long b = long.Parse(input[1]);
        long c = long.Parse(input[2]);
        long d = long.Parse(input[3]);*/
//        string temp = ReadLine();
        int a = int.Parse(ReadLine());
//        int b = int.Parse(ReadLine());
//        int c = int.Parse(ReadLine());
//        int d = int.Parse(ReadLine());
//        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
//        string[] input = ReadLine().Split(' ');
//        string ko = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int max = 0;
        if(a >= 1 && a <= 3){ WriteLine(1); }
        else{
        for(int i=2;i<33;i++){
            if(i < a){
                int k = i;
                while(k <= a){
                    k *= i;
                    if(k<=a){
                        max = Max(k,max);
                    }
                }
            }
        }
        WriteLine(max);
        }
    }
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int x,t;
	cin >> x >> t;
	cout << max(x-t, 0) << "\n";	
	return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> x(n, -1);	
	for (int i = 0; i < m; i++) {
		int s, c;
		cin >> s >> c;
		s--;
		if (x[s] != -1 && x[s] != c) {
			cout << -1 << endl;
			return 0;
		}
		x[s] = c;
	}
	if (n > 1 && x[0] == 0) {
		cout << -1 << endl;
		return 0;
	}
	if (n > 1 && x[0] == -1) x[0] = 1;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans *= 10;
		ans += max(0, x[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/

    ll n;
    cin>>n;
    ll a[n+1];
    loop(i,1,n+1) cin>>a[i];
    ll ps[n+1];
    ps[0] = 0;
    loop(i,1,n+1){
        ps[i] = ps[i-1] + a[i];
    }
    ll dp[n+1][n+1];
    loop(i,1,n+1) dp[i][i] = 0;
    for(ll i=n-1; i>=1; i--){
        loop(j,i+1,n+1){
            ll res=inf;
            loop(k,i,j){
                res=min(res, dp[i][k] + dp[k+1][j] + ps[j] - ps[i-1]);
            }
            dp[i][j] = res;
        } 
    }
        
    print(dp[1][n]);

    /*#ifndef ONLINE_JUDGE
        end_routine();
    #endif*/
}



Measured memory_bytes: 1536
package main

import (
  "fmt"
)

func main() {
  var (
    a,b int
  )
  fmt.Scan(&a)
  fmt.Scan(&b)

  fmt.Println(check(a,b))
}

func check(a,b int) int {
  for i:=8; i<10000; i++ {
    if (i*8)/100 == a && i/10 == b{
      return i
    }
  }
  return -1
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map { it.toLong() }
    val r = n / (a + b)
    val m = n % (a + b)
    var ans = r * a
    ans += if (m > a) a else m
    println(ans)
}

Measured memory_bytes: 37948
N = int(input())
H = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * N

dp[0] = 0

for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(H[i] - H[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(H[i] - H[i-2]))

print(dp[N-1])

Measured memory_bytes: 13924
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

ll dfs(set<ll> &s,mtl &vec,vl &Vec, int x)
{
	ll ans=0;
	if(s.count(x)){
		ans=Vec.size();
		return ans;
	}
	
	for(int c:vec.at(x)){
		s.insert(c);
		Vec.push_back(c);
		ans=dfs(s,vec,Vec,c);
	}	
	return ans;
}



int main(){
	set<ll> s;
	ll K,N,v,sum,cnt;
	cin>>N>>K;
	ll x=0;
	vl Vec(1,0);
	map<ll,ll> mp;
	rep(i,0,N){
		ll a; cin>>a;
		mp[i]=(a-1);
	}
	while(true){
		ll y=mp[x];
		if(s.count(y)){
			sum=y;
			v=Vec.size();
			break;
		}
		else{
			Vec.push_back(y);
			s.insert(y);
			x=y;
		}
	}
	rep(i,0,Vec.size()){
		if(Vec[i]==sum){
			cnt=i;
			break;
		}
	}
	if(K<cnt) cout<<Vec[K]+1;
	else{
		ll ans=(K-cnt)%(v-cnt);
		ll f=Vec.at(cnt+ans);
		print(f+1)
	}
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  ll x;
  cin >> x;
  ll ans;
  ll cnt = x / 500;
  ans = cnt * 1000;
  ll left = x % 500;
  ans += (left / 5) * 5;
  ANS(ans);

  return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

string itob(int a) {
  string ret;
  for(int i=16; i>0; i/=2) {
    if (a>=i) {
      ret+='1';
      a-=i;
    } else
      ret+='0';
  }
  return ret;
}

int main() {
  string hoge = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  map<string, string> m;
  REP(i,hoge.length()) {
    string hage;
    hage = hoge[i];
    m.insert(make_pair(itob(i),hage));
  }
  hoge = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string hoge2[] = {"101","000000","000011","10010001","010001","000001","100101","10011010"
                 ,"0101","0001","110","01001","10011011","010000","0111","10011000"
                 ,"0110","00100","10011001","10011110","00101","111","10011111","1000"
                 ,"00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
  map<char,string> m2;
  REP(i,hoge.length())
    m2.insert(make_pair(hoge[i],hoge2[i]));
  string line;
  while(!cin.eof()) {
    getline(cin,line);
    if (cin.eof()) break;
    string a;
    REP(i,line.length())
      a += m2[line[i]];
    int aa = a.length()%5;
    if(aa)
      a+=string(5-aa,'0');
    string ans;
    for (int i=0; i<a.length(); i+=5) {
      ans += m[a.substr(i,5)];
    }
    //cout << a << endl;
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }



int main()
{
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int H,W;
    cin >> H >> W;
    char s[H][W];
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cin >> s[i][j];
        }
    }
    bool flag = false;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            flag = false;
            if(s[i][j] == '#')
            {
                for(int k = 0; k < 4; k++)
                {
                    if(i + dx[k] <= H - 1 && i + dx[k] >= 0 && j + dy[k] <= W - 1 && j + dy[k] >= 0)
                    {
                        if(s[i + dx[k]][j + dy[k]] == '#')
                        {
                            flag = true;
                        }

                    }
                }
                if(flag == false)
                {
                    cout << "No" << endl;
                    return(0);
                }
            }
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=200005;
int n,m,i,j,k,l,x,a[105][105],b[105][105],c[105][105],head[N],adj[N],nxt[N],flow[N],cap[N],cur[N],d[N],q[N],bg,ed;
bool v[105][105];
void addedge(int u,int v,int w)
{
	adj[++l]=v;
	nxt[l]=head[u];
	head[u]=l;
	flow[l]=0;
	cap[l]=w;
	adj[++l]=u;
	nxt[l]=head[v];
	head[v]=l;
	flow[l]=0;
	cap[l]=0;
}
bool bfs()
{
	int i;
	for(i=1;i<=2*n+2;++i)
		d[i]=1<<30;
	d[2*n+1]=0;
	q[bg=ed=1]=2*n+1;
	while(bg<=ed)
	{
		for(i=head[q[bg]];i;i=nxt[i])
			if(flow[i]<cap[i]&&d[adj[i]]==(1<<30))
			{
				d[adj[i]]=d[q[bg]]+1;
				q[++ed]=adj[i];
			}
		++bg;
	}
	return d[2*n+2]<(1<<30);
}
int dfs(int x,int a)
{
	if(x==2*n+2||a<=0)
		return a;
	int g,h=0;
	for(;cur[x];cur[x]=nxt[cur[x]])
		if(d[adj[cur[x]]]==d[x]+1&&(g=dfs(adj[cur[x]],min(cap[cur[x]]-flow[cur[x]],a)))>0)
		{
			flow[cur[x]]+=g;
			flow[cur[x]&1?cur[x]+1:cur[x]-1]-=g;
			a-=g;
			h+=g;
			if(a<=0)
				break;
		}
	return h;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			scanf("%d",a[i]+j);
	for(i=1;i<=m;++i)
	{
		for(j=1;j<=2*n+2;++j)
			head[j]=0;
		l=0;
		for(j=1;j<=n;++j)
		{
			addedge(2*n+1,j,1);
			addedge(n+j,2*n+2,1);
		}
		for(j=1;j<=n;++j)
			for(k=1;k<=m;++k)
				if(!v[j][k])
					addedge(j,n+(a[j][k]-1)/m+1,1);
		while(bfs())
		{
			for(j=1;j<=2*n+2;++j)
				cur[j]=head[j];
			dfs(2*n+1,1<<30);
		}
		for(j=1;j<=n;++j)
		{
			for(k=head[j];k;k=nxt[k])
				if(adj[k]!=2*n+1&&flow[k]==1)
				{
					k=adj[k]-n;
					break;
				}
			for(x=1;x<=m;++x)
				if(!v[j][x]&&(a[j][x]-1)/m+1==k)
				{
					v[j][x]=true;
					b[j][i]=a[j][x];
					break;
				}
		}
	}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			c[(b[i][j]-1)/m+1][j]=b[i][j];
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=m;++j)
			printf("%d ",b[i][j]);
		puts("");
	}
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=m;++j)
			printf("%d ",c[i][j]);
		puts("");
	}
	return 0;
}


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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll A, B, C, K; cin >> A >> B >> C >> K;
	
	ll ans = 0;
	ans += min(A, K);
	K -= min(A, K);
	K -= min(B, K);
	ans -= min(C, K);
	print(ans);
}

Measured memory_bytes: 3656
import numpy as np
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.csgraph import shortest_path

n,m,limit=map(int,input().split())
G=np.zeros((n,n),dtype=np.int64)
for i in range(m):
    a,b,cost=map(int,input().split())
    G[a-1,b-1]=cost
    G[b-1,a-1]=cost
G=shortest_path(G,method='FW')
for c in range(n):
    for l in range(n):
        if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0
G=shortest_path(G,method='FW')
q=int(input())
Q=[map(int,input().split())for i in range(q)]
for a,b in Q:
    print(int(G[a-1][b-1])-1 if G[a-1][b-1]<10**18 else -1)

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

vector<P> Search(map<ll,ll> &mp){
  vector<P> v;
  for(P p:mp){
    swap(p.first,p.second);
    v.push_back(p);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  return v;
}

ll n;
ll ans=(1LL<<60);
ll a[100005];
 
int main(){
  
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  map<ll,ll> mp;
  ll ca=0;
  for(int i=0;i<n;i+=2){
    mp[ a[i] ]++;
    ca++;
  }

  vector<P> A=Search(mp);
  
  ll cb=0;
  mp.clear();
  for(int i=1;i<n;i+=2){
    mp[ a[i] ]++;
    cb++;
  }

  vector<P> B=Search(mp);
  A.push_back(P(0,-1));
  B.push_back(P(0,-2));

  for(int i=0;i<A.size();i++){
    if(i>3)break;
    for(int j=0;j<B.size();j++){
      if(j>3)break;
      if(A[i].second==B[j].second)continue;
      ans = min(ans, ca+cb-A[i].first-B[j].first);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

class Program {
  static void Main() {
    int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    int c = arr[2];
    Console.WriteLine(b - a == c - b ? "YES" : "NO");
  }
}

Measured memory_bytes: 13396
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class UF:
    def __init__(self, N):
        self.state = [-1] * N
        self.rank = [0] * N
        self.num_group = N
    
    def get_parent(self, a):
        p = self.state[a]
        if p < 0:
            return a
        
        q = self.get_parent(p)
        self.state[a] = q
        return q

    def make_pair(self, a, b):
        pa = self.get_parent(a)
        pb = self.get_parent(b)
        if pa == pb:
            return

        if self.rank[pa] > self.rank[pb]:
            pa, pb = pb, pa
            a, b = b, a
        elif self.rank[pa] == self.rank[pb]:
            self.rank[pb] += 1

        self.state[pb] += self.state[pa]
        self.state[pa] = pb
        self.state[a] = pb
        self.num_group -= 1
    
    def is_pair(self, a, b):
        return self.get_parent(a) == self.get_parent(b)

    def get_size(self, a):
        return -self.state[self.get_parent(a)]


def main():
    N, M = read_values()
    uf = UF(N)
    for _ in range(M):
        A, B = read_index()
        uf.make_pair(A, B)

    res = 0
    for n in range(N):
        res = max(res, uf.get_size(n))

    print(res)


if __name__ == "__main__":
    main()



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

int main(){
  int N;
  cin >> N;
  vector<int> x(N),y(N),v(N);
  for(int i=0;i<N;i++){
    cin >> x.at(i) >> y.at(i);
    v.at(i)=i;
  }
  int count=0;
  double sum=0;
  do{
    for(int i=0;i<N-1;i++){
      sum+=sqrt(pow(x.at(v.at(i))-x.at(v.at(i+1)),2)+pow(y.at(v.at(i))-y.at(v.at(i+1)),2));
      // if(v.at(i)!=N-1){
      //   sum+=sqrt(pow(x.at(v.at(i))-x.at(v.at(i)+1),2)+pow(y.at(v.at(i))-y.at(v.at(i)+1),2));
      // }else{
      //   sum+=sqrt(pow(x.at(v.at(i))-x.at(0),2)+pow(y.at(v.at(i))-y.at(0),2));
      // }
    }
    count++;
  }while(next_permutation(v.begin(),v.end()));
  double ans=sum/count;
  cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

bool is_prime (long n) {
  if (n == 1) return false;
  if (n == 2) return true;

  long sqrtn = ceil(sqrt(n));

  for (long i = 2; i <= sqrtn; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

int main () {
  int N;
  cin >> N;
  mp::cpp_int answer = 1;
  for (int p = 1; p <= N; p++) {
    if (!is_prime(p)) continue;
    int s = 0;
    for (int j = 1; pow(p, j) <= N; j++) s += floor(N / pow(p, j));
    answer *= mp::cpp_int(1 + s);
  }
  cout << (answer % mp::cpp_int(1'000'000'007)) << "\n";
}


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

constexpr int MOD = 1000000007;

int main() {
  // if T1*(A1-B1) + T2*(A2-B2) = 0
  // A1>B1
  // A2<B2
  ll T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  ll D = T1*(A1-B1) + T2*(A2-B2);
  if (D == 0) {
    cout << "infinity" << endl;
    return 0;
  }
  if (D < 0) {
    swap(A1, B1);
    swap(A2, B2);
    D *= -1;
  }
  if (A1 > B1) {
    cout << 0 << endl;
    return 0;
  }
  // k*D + (A1-B1)*T1 >= 0
  // k >= (B1-A1)T1 / D
  ll k = ((B1-A1)*T1 + D - 1) / D;
  ll ans = k*2-1;
  if (k*D + (A1-B1)*T1 == 0) {
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
A.insert(0,0)
hist = [0 for _ in range(N+1)]
a = 1
cnt = 0
hist[a] = 1
while True:
    cnt += 1
    a = A[a]
    if hist[a]==1:
        cnt = -1
        break
    hist[a] = 1
    if a==2:
        break
print(cnt)

Measured memory_bytes: 85700
#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

ll solve(const ll K, const vector<ll> A) {
  vector<vector<ll>> dp(50, vector<ll>(2, -1));

  ll ans = 0;
  for (int i = 45; i >= 0; i--) {
    ll n = (1LL << i);
    if (n > K) {
      ll sum = 0;
      for (auto &&e : A) {
        if (bitset<64>(e)[i]) {
          sum += n;
        }
      }
      ans += sum;
    }
  }

  for (int i = 45; i >= 0; i--) {
    ll n = (1LL << i);
    if (n > K) {
      continue;
    }

    ll sum1 = 0;
    ll sum2 = 0;
    for (auto &&e : A) {
      if (bitset<64>(e)[i] ^ 1) {
        sum1 += n;
      } else {
        sum2 += n;
      }
    }

    if (dp[i + 1][0] == (-1) && dp[i + 1][1] == (-1)) {
      dp[i][0] = sum1;
      dp[i][1] = sum2;
      continue;
    }

    // 0 -> 0
    if (bitset<64>(K)[i]) {
      dp[i][0] = max(dp[i][0], dp[i + 1][0] + sum1);
    } else {
      dp[i][0] = max(dp[i][0], dp[i + 1][0] + sum2);
    }

    // 1 -> 1
    dp[i][1] = max(dp[i][1], max(dp[i + 1][1] + sum1, dp[i + 1][1] + sum2));

    // 0 -> 1
    if (bitset<64>(K)[i]) {
      dp[i][1] = max(dp[i][1], dp[i + 1][0] + sum2);
    }
  }

  return ans + max(0LL, max(dp[0][0], dp[0][1]));
}

int main() {
  ll n, K;
  cin >> n >> K;

  vector<ll> A(n);
  for (size_t i = 0; i < n; i++) {
    cin >> A[i];
    // cout << (bitset<64>(A[i])[0] ^ 0) << endl;
  }

  ll ans = max(ans, solve(K, A));
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n;
    ll aa[100007];
    memset(aa,0,sizeof(aa));
    for0(n)
    {
        cin>>x;
        aa[x]++;
        c+=x;
    }
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        x=aa[a];
        aa[a]=0;
        aa[b]+=x;
        c-=a*x;c+=b*x;
        cout<<c<<endl;
    }
}



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

bool g(ll a,ll b){
    return a>b;
}
int main(){
    string S;
    cin>>S;
    vector<ll> cnt(3,0);
    for(ll i=0;i<S.length();++i){
        switch(S[i]){
            case 'a':
            cnt[0]++;
            break;
            case 'b':
            cnt[1]++;
            break;
            case 'c':
            cnt[2]++;
            break;
        }
    }
    for(ll i=0;i<3;++i){
        if(cnt[i]>(S.length()+2)/3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

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

int main()
{
    int a,b,t,i,sum;
    float c;
    sum = 0;
    cin >> a >> b >> t;
    c = (t+0.5)/a;

    for(i=1; i <= c; i++){
        sum = sum + b;
    }

    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  map<int,int,greater<int>> a;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a[x]++;
  }
  vector<int> r;
  vector<int> s;
  for(auto x:a){
    if(x.second>=2)
      r.push_back(x.first);
    if(x.second>=4)
      s.push_back(x.first);
  }
  if(s.size()>=1){
    if(r.size()>=2)
      cout<<max((int64_t)s.at(0)*s.at(0),(int64_t)r.at(0)*r.at(1))<<endl;
    else
      cout<<(int64_t)s.at(0)*s.at(0)<<endl;
  }else{
    if(r.size()>=2)
      cout<<(int64_t)r.at(0)*r.at(1)<<endl;
    else
      cout<<0<<endl;
  }
}

Measured memory_bytes: 4992
n = gets.to_i
num = 0
if n / 1000 == 2
  num += 1
end
n %= 1000
if n / 100 == 2
  num += 1
end
n %= 100
if n /10 == 2
  num += 1
end 
n %= 10
if n == 2
  num += 1
end

puts num

Measured memory_bytes: 3836
N = int(input())
S = input()
LR = [0,0]
l = "("
r = ")"

for i in range(N):
  if S[i] == r:
    if LR[1] == 0:
      LR[0] += 1
    else:
      LR[1] -= 1
  elif S[i] == l:
    LR[1] += 1

S = l * LR[0] + S + r * LR[1]

print(S)



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

using namespace std;
#define Vi vector<int>
#define FOR(i,n) for(int i=0;i<n;i++)

int main(){
  int n,sum=0,ans;
  cin>>n;
  Vi s(n);
  for(int i=0;i<n;i++)
    cin>>s[i];
  for(int i=0;i<n;i++)
    sum+=s[i];
  if(sum%10){
    ans=sum;
  }else{
    ans=0;
    for(int i=0;i<n;i++){
      if((sum-s[i])%10){ans=max(ans,sum-s[i]);}
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll fn(ll n) {
  if(n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

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

  ll s; cin>>s;
  ll keep = s;
  ll cnt = 1;
  if(keep == 4 || keep == 2 || keep == 1) {
    cout << 4 << endl;
    exit(0);
  }
  while(keep != 8) {
    cnt++;
    if(cnt == 1) {
      cout << "hoge" << endl;
    } else {
      keep = fn(keep);
    }
  }
  // for(int i = 1;;i++) {
  //   int a;
  //   if(i == 1) {
  //     a = s;
  //   } else {
  //     a = fn(keep);
  //   }

  //   if(a == 8) {
  //     cnt = i;
  //     break;
  //   }

  //   keep = a;
  // }

  cout << cnt + 4 << endl;
}


Measured memory_bytes: 256
from sys import stdin

n, l = [int(x) for x in stdin.readline().rstrip().split()]
apples = [l+i for i in range(n)]

apple_sum = (apples[0] + apples[n-1]) * n / 2
rm = 0

for i, apple in enumerate(apples):
    if abs(apple) < abs(apples[rm]):
        rm = i

apples.pop(rm)
print(sum(apples))


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

const MOD: usize = 1_000_000_007;

fn check(v: [char; 4]) -> bool {
    if func(&v[0..3]) || func(&v[1..4]) {
        return true;
    }
    for i in 0..3 {
        let mut v = v.clone();
        let mut a1 = v[i];
        let mut a2 = v[i+1];
        std::mem::swap(&mut a1, &mut a2);
        v[i] = a1;
        v[i+1] = a2;
        if func(&v[0..3]) || func(&v[1..4]) {
            return true;
        }
    }
    return false;
}

fn func(v: &[char]) -> bool {
    let po = ['A', 'G', 'C'];
    for k in 0..3 {
        if v[k] != po[k] {
            return false;
        }
    }
    return true;
}

fn main() {
    let n: usize = read();
    
    let po = ['A', 'C', 'G', 'T'];
    let mut dp = vec![[[[0; 4]; 4]; 4]; n];

    for i in 0..4 { for j in 0..4 { for k in 0..4 {
        dp[0][i][j][k] += 
            if check([po[i], po[j], po[k], 'X']){0}
            else {1};
    }}}

    for i in 0..n-3 {
        for j in 0..4 { for k in 0..4 { for l in 0..4 { for m in 0..4 {
            if !check([po[j], po[k], po[l], po[m]]) {
                dp[i+1][k][l][m] += dp[i][j][k][l];
                dp[i+1][k][l][m] %= MOD;
            }
        }}}}
    }

    let mut ans = 0;
    for j in 0..4 { for k in 0..4 { for l in 0..4 {
        ans += dp[n-3][j][k][l];
        ans %= MOD;
    }}}
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
// 23:53-00::06
#include <iostream>
#include <vector>

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

int main() {
  int k, n;
  std::cin >> k >> n;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];
  a.push_back(a[0] + k);

  int max = 0;
  rep(i, n) {
    // int d;
    // if (i == n - 1)
    //   d = std::abs(a[0] - a[i]);
    // else
    //   d = a[i + 1] - a[i];
    // d = std::min(d, k - d);

    // if (d > max) max = d;
    max = std::max(max, a[i + 1] - a[i]);
  }

  std::cout << k - max << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define FF first.first
#define FS first.second
#define S second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16;
 
ll n, q=1, m, a[N], b[N], f[N], o, k, t, x, y, z, u, h, mx, mn, ans, Ans;
pair<ll,ll> p[N];
string s;
vector<int> v[N];
 
main(){ios_base::sync_with_stdio(false), cin.tie(0);
   	
	cin>>n>>q;
   	
   	while(q--){ans=o=0,u=100;
   		cin>>x;
		
		for (int i=1; i<=x; i++){
			cin>>y;
			f[y]=1;
		}
	}
	for (int i=1; i<=n; i++)if(!f[i])ans++;
	cout<<ans;
	
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    bool flag = true;
    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0) {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                flag = false;
            }
            
        } else if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
            flag = false;
        }
    }
    
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int[] A = new int[N];
		for(int i = 0;i < N;i++) {
			A[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		Map<Integer,Integer> map = new HashMap<>();
		for(int i=0;i < N;i++) {
			if(map.containsKey(A[i])) {
				map.put(A[i], map.get(A[i])+1);
			}else {
				map.put(A[i], 1);
			}
		}
		int j = 0;
		Integer[] cnt = new Integer[map.size()];
		for(Map.Entry<Integer, Integer> bar: map.entrySet()) {
			cnt[j] = bar.getValue();
			j++;
		}
		Arrays.sort(cnt);
		List<Integer> list = Arrays.asList(cnt);
		Collections.reverse(list);
		Integer[] cnt2 = (Integer[])list.toArray(new Integer[map.size()]);
		int sum = 0;

		for(int i = 0;i < (K > cnt2.length ? cnt2.length : K);i++) {
			sum += cnt2[i];
		}
		System.out.println(N - sum);
	}
}

Measured memory_bytes: 55496
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;

typedef long long int ll;
 
//typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 10005;
const ll mod = 998244353;
const long long int inf = 10e17;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


int main()
{
	ll n,m;
	cin>>n>>m;
	ll a[n];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	ll sum = 0;
	rep(i,n) sum+=a[i];
	ll cnt = 0;
	rep(i,n){
		if(a[i]*4*m>=sum) cnt++;
	}
	if(cnt>=m) cout<<"Yes\n";
	else cout<<"No\n";

}

	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

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

int main(){
  ll N, M, i, ans;
  cin >> N >> M;

  
  ans = N*(N - 1)/2 + M*(M - 1)/2;
  cout << ans << endl;
  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<VI> jc(n, VI(3));
	rep(i, n){
		cin >>jc[i][0] >>jc[i][1]; jc[i][2] =i;
	}
	
	vector<VI> r;
	UF uf(n);
	sort(all(jc));
	rep(i, n-1){
		auto z1=jc[i] , z2=jc[i+1];
		r.push_back({z1[2], z2[2], abs(z2[0] - z1[0])});
	}
	sort(all(jc), [](auto& l, auto& r){return l[1] < r[1];});
	rep(i, n-1){
		auto z1=jc[i] , z2=jc[i+1];
		r.push_back({z1[2], z2[2], abs(z2[1] - z1[1])});
	}
	sort(all(r), [](auto& l, auto& r){return l[2] < r[2];});
	//for(auto x :r) printf("%d:%d:%d  ",x[0],x[1],x[2]); puts("");
	
	ll ans =0;
	for(auto& z: r){
		if(!uf.same(z[0], z[1])){
			ans += z[2];
			uf.unite(z[0], z[1]);
		}
		
	}
	cout << ans <<"\n";

	return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n;
int main(){
	cin >> n;
	vector<int>v(n);
	for(int i = 0; i < n; i++)cin >> v[i];
	int ans = INTMAX;
	for(int i = 1; i < 101; i++){
		int tmp = 0;
		for(int j = 0; j < n; j++){
			tmp += pow(v[j] - i, 2);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, i;
	cin >> n;
	ll a[n];
	fr(i,0,n)
		cin >> a[i];
	ll tmp = a[0];
	fr(i,1,n)
	{
		if(i%2 == 1)
			tmp -= a[i];
		else
			tmp += a[i];
//		trace2(i, tmp);
	}
	ll ans[n];
	ans[0] = tmp;
	fr(i,1,n)
	{
		ans[i] = 2*(a[i-1] - ans[i-1]/2);
	}
	fr(i,0,n)
		cout << ans[i] << " ";
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 201; // number of vertex
static const ll INF = mop;
static const ll whi = 0;
static const ll gra = 1;
static const ll bla = 2;

ll n, adj[MAX][MAX]; // adjacency matrix
ll d[MAX][MAX];

void dijkstra(ll k){
    ll minv;
    ll color[MAX];

    for (ll i=1;i<=n;i++){
        d[k][i] = INF;
        color[i] = whi;
    }

    d[k][k] = 0; // starting point distance
    color[k] = gra;
    while(true){
        minv = INF;
        ll u = -1;
        for (ll i=1;i<=n;i++){
            if(minv > d[k][i] and color[i] != bla){
                u = i;
                minv = d[k][i];
            }
        }
        if(u == -1){
            break;
        }
        color[u] = bla;
        for (ll v=1;v<=n;v++){
            if(color[v] != bla and adj[u][v] != INF){
                if(d[k][v] > d[k][u] + adj[u][v]){
                    d[k][v] = d[k][u] + adj[u][v];
                    color[v] = gra;
                }
            }
        }
    }
}


int main() {
   
    ll m,r;
    cin >> n >> m >> r;
    vector <ll> des;
    for (ll i=0;i<r;i++){
        ll x;
        cin >> x;
        des.push_back(x);
    }
    for (ll i=1;i<=n;i++){
        for (ll j=1;j<=n;j++){
            adj[i][j] = INF;
        }
    }
    for(ll i=0;i<m;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        adj[a][b] = c;
        adj[b][a] = c;
    }
//    for (ll i=1;i<=n;i++){
//        if(i-1){
//            cout << endl;
//        }
//        for(ll j=1;j<=n;j++){
//            cout << adj[i][j] << " ";
//        }
//    }
//    cout << endl;
    for (ll i=1;i<=n;i++){
        dijkstra(i);
    }

    ll ans = INF;
  	sort(des.begin(), des.end());
    do{
        ll pre = 0;
        for (ll i=0;i<r-1;i++){
            pre += d[des[i]][des[i+1]];
        }
        if(ans > pre){
            ans = pre;
        }
    }while(next_permutation(des.begin(), des.end()));

    cout << ans << endl;
//    for (ll i=1;i<=n;i++){
//        for (ll j=1;j<=n;j++){
//            cout << i << " " << j << " " << d[i][j] << endl;
//        }
//    }



}




Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std; 
const int N=1510;
typedef long long ll;

int main(){
    ll n , m;
    while (~scanf("%lld%lld", &n, &m)){
    	if (n%m == 0)  puts("-1");
    	else {
    		ll  x = n;
    		while(true){
    			x += n;
    			if (x % m != 0){
    				printf("%lld\n", x);
    				break;
				}
			}	
		}
	}
    return 0;
}

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

int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    for(size_t i = 0; i < n; i++)
    {
        if(i < k){
            ans += x;
        }
        else{
            ans += y;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, K;
    cin >> A >> B >> K;
    int m = min(A, B);
    for(int i = m; i >= 1; i--){
        if(A % i == 0 && B % i == 0){
            K--;
            if(K == 0){
                cout << i << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a,b) << " " << ((n-(a+b)>0) ? 0 : abs(n-(a+b))) << endl;
  return 0;
}


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

int main() {
 int N = 0;

 cin >> N;

 double num;

 if(N == 1) {
	num = 1;
 } else if(N % 2 == 0) {
	num = (double)N/2/N;
 } else {
	num = (double)(N/2+1)/N;
 }
 cout << fixed << setprecision(10) << num << endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int checksum(int n){
	int sumi=0;
  while(n!=0){
  	sumi+=n%10;
    n/=10;
  }
  return sumi;
}
int main(){
	int n,a,b;cin>>n>>a>>b;
  int sum=0;
  for(int i=1;i<=n;i++){
  	if(checksum(i)>=a && checksum(i)<=b)sum+=i;
  }
  cout<<sum;
}

Measured memory_bytes: 3592
K = int(input())
A, B = map(int, input().split())


if B // K - A // K > 0:
    print('OK')
elif B // K - A // K == 0:
    if A % K == 0 or B % K == 0:
        print('OK')
    else:
        print('NG')
else:
    print('NG')


Measured memory_bytes: 9100
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
	int k=0;
	double n, *a, n1=0, n2=0;
	scanf("%lf", &n);
	a=(double *)malloc(sizeof(double)*n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%lf", &a[i]);
	}
	for (int i = 0; i < n; ++i)
	{
		n1+=a[i];
	}
	n1/=n;
	n2=fabs(a[0]-n1);
	for (int i = 1; i < n; ++i)
	{
		if (n2>fabs(a[i]-n1))
		{
			n2=fabs(a[i]-n1);
			k=i;
		}
	}
	printf("%d\n", k);
	return 0;
}

Measured memory_bytes: 128
// agrawal117
// chahatagrawal117

#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
#define MAX 100004
void solve(string s ,int p)
{
    ll ans=0;
    for(int i=0;i<s.size();i++){
        if((s[i]-'0') % p ==0 )  ans+=(i+1);
    }
    cout<<ans<<endl;
    exit(0);
}
int main()
{
    ll n,p;
     cin>>n>>p;
     string s; cin>>s;
     if(p==2 || p==5) solve(s,p);
     ll arr[n+2];
     ll val=1LL;
     map<ll,ll> mp;
     ll ans=0;
     for(int i=0;i<s.size();i++){
         arr[i]=s[s.size()-i-1]-'0';
         arr[i]%=p; arr[i]*=val;
         arr[i]%=p;
         val*=10;
         val%=p;
         ans+=arr[i];
        //  cout<<arr[i]<<" ";
         ans%=p;
         mp[ans]++;
     }
     cout<<endl;
     mp[0]++;
     ans=0;
     for(auto i : mp) 
     {
         ll val= i.second;
         ans+=(val*(val-1))/2;
     }
     cout<<ans<<endl;
     
}

Measured memory_bytes: 2564