akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 2000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), f(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	rep(i, n) cin >> f[i];
	ll ng = -1, ok = INF;
	while (ok - ng > 1) {
		ll mid = (ng + ok) / 2;
		vector<ll> c(n);
		rep(i, n) c[i] = mid / f[i];
		sort(all(c));
		ll cnt = 0;
		rep(i, n) cnt += max(a[i] - c[i], 0ll);
		if (cnt <= k) ok = mid;
		else ng = mid;
	}
	cout << ok << '\n';
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#define pb push_back
#define fi first
#define se second
#define sz(x)  x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define r(x)  scanf("%d", &x)
#define rr(x , y)  scanf("%d%d" , &x , &y)
#define rst(s)  scanf("%s" , s)
#define rl(x)  scanf("%lld" , &x)
#define rrl(x , y)  scanf("%lld%lld" , &x , &y)
#define w(x)  printf("%d" , x)
#define ww(x , y)  printf("%d %d" , x , y)
#define wl(x)  printf("%lld" , x)
#define wwl(x , y)  printf("%lld %lld" , x , y)
#define sp()  printf(" ")
#define en()  puts("")
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , inf , sizeof(x))
#define mem__inf(x)  memset(x , -inf , sizeof(x))
#define p_queue priority_queue
#define debug(x)  cout << '*' << x << '\n'
#define ddebug(x , y)  cout << '*' << x << ' ' << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
//mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef pair<int , ll> pil ;
typedef pair<ll , int> pli ;
const int inf = 0x3f3f3f3f ;
const int maxn = 2e5 + 5 ;
const int maxm = 30 ;
const double eps = 1e-6 ;
int n ;
char s[maxn] ;
int num[3005] ;
int main()
{
	rst(s + 1) ;
	n = strlen(s + 1) ;
	int now = 0 ;
	int base = 1 ;
	mem0(num) ;
	num[0] ++ ;
	per(i , n , 1)
	{
		now = (now + (s[i] - '0') * base) % 2019 ;
		base *= 10 ;
		base %= 2019 ;
		num[now] ++ ;
	}
	ll ans = 0 ;
	rep(i , 0 , 2018)  ans += ll(num[i]) * (num[i] - 1) / 2 ;
	wl(ans) , en() ;
	return 0 ;
}

Measured memory_bytes: 4016
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

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

const double EPS = 1e-10;
const int INF = 1e7;

vector <int> a;

int main(){
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  if (fabs(c - a) <= d) {
    std::cout << "Yes\n";
  } else if (fabs(b - a) <= d && fabs(c - b) <= d) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int x, y, n;

  cin >> x >> y;

  if (x < y) {
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
  }

  while (1) {
    n = x % y;
    if (n == 0) break;
    x = y;
    y = n;
  }

  cout << y << endl;
  return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define int ll

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

    //a[i] or a[i]-1，すべてのxorをとって0にできればok
    //桁ごと上位からみる
    int n;cin>>n;
    int x=0;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
        x^=a[i];
    }
    vector<int> b(n);
    rep(i,n) b[i]=__builtin_ffsll(a[i])-1;
    //1引いて揃えれるならどれ引いて揃えても変わらない
    int ans=0;
    for(int bit=32;bit>=0;bit--){
        int cnt=0;
        rep(i,n){
            if((1ll<<bit)&a[i]) cnt++;
        }
        cnt+=ans;
        if(cnt%2==0) continue;
        bool f=false;
        rep(i,n){
            if(bit==b[i]){
                ans++;
                f=true;
                break;
            }
        }
        if(!f){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<string.h>

typedef long long int ll;
using namespace std;

int main(void)
{
	while (1)
	{
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)
		{
			break;
		}
		
		if (x < y)
		{
			cout << x << ' ' << y << endl;
		}
		else
		{
			cout << y << ' ' << x << endl;
		}
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<P>num(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    num.at(i) = {a,i+1};
  }
  sort(num.begin(),num.end());
  for (int i = 0; i < n; i++) {
    cout << num.at(i).second << " ";
  }
}  

Measured memory_bytes: 1536
X = int(input())
a = 0
b = 0

if X >= 500:
    a = X // 500 * 1000
    X = X % 500
    if X >= 5:
        b = X // 5 * 5
        print(a + b)
    else:
        print(a)
elif X >= 5:
    b = X // 5 * 5
    print(b)
else:
    print('0')

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

int main() {
    ll a,b;
    char op;
    cin>>a>>op>>b;
    if (op=='+') cout<<a+b<<endl;
    else cout<<a-b<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>



int main(void){
    
    char s[100];
    char p[100];
    char ring[200];
    
    scanf("%s",s);
    scanf("%s",p);
    strcpy(ring,s);
    strcat(ring,s);
    
   // printf("%s\n",ring);
    
    if(strstr(ring, p)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	private void solve() throws IOException {
		int n = ni();

		int cnt = 0;
		int k;
		for (int i = 0; i < n; i++) {
			k = ni();
			while (k % 2 == 0) {
				k /= 2;
				cnt++;
			}
		}

		out.println(cnt);
		out.close();

	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	private int[][] na(int n) throws IOException {
		int[][] a = new int[n][2];
		for (int i = 0; i < n; i++) {
			a[i][0] = ni();
			a[i][1] = i;
		}
		return a;
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

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

int main()
{
    bool flag = true;
    int cnt1, cnt2;
    int H, W;
    char mas[105][105];
    cin >> H >> W; 
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> mas[i][j];
        }
    }
    if(H % 2 == 0 && W % 2 == 0) {
        cnt1 = 0, cnt2 = 0;
    } else if(H % 2 == 0 && W % 2 == 1) {
        cnt1 = 0, cnt2 = H / 2;
    } else if(H % 2 == 1 && W % 2 == 0) {
        cnt1 = 0, cnt2 = W / 2;
    } else {
        cnt1 = 1, cnt2 = (H + W) / 2 - 1;
    }
    for(int p = 0; p < 26; p++) {
        int cnt = 0;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(mas[i][j] == 'a' + p) cnt++;
            }
        }
        if(cnt % 2) cnt1--, cnt--;
        if(cnt % 4) cnt2--;
    }
    if(cnt1 >= 0 && cnt2 >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[2][n];
	for(int i=0; i<2; i++){
		for(int j=0; j<n; j++){
			cin >> a[i][j];
		}
	}
	int max=0;
	for(int i=0; i<n; i++){
		int sum=0;
		for(int j=0; j<=i; j++){
			sum+=a[0][j];
		}
		for(int j=i; j<n; j++){
			sum+=a[1][j];
		}
		if(max<sum) max=sum;
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N = input()

A1 = map(int, raw_input().split())
A2 = map(int, raw_input().split())

for i in range(1, N):
    A1[i] += A1[i - 1]

for i in range(0, N - 1)[::-1]:
    A2[i] += A2[i + 1]

ans = 0

for i in range(N):
    ans = max(ans, A1[i] + A2[i])

print ans

Measured memory_bytes: 2812
// g++ -std=c++11 a.cpp
#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(ll 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;
//kaewasuretyuui
typedef long long ll;
//#define int 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;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
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;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
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 idx(vi a,int c){
	return lower_bound(all(a),c)-a.begin();
}
int main(){
	int n;
	while(cin>>n,n){
		vi x(n+4),y(n+4);
		rep(i,n+4)cin>>x[i]>>y[i];
		vi X,Y;
		rep(i,n+4)X.pb(x[i]),X.pb(x[i]+1);
		rep(i,n+4)Y.pb(y[i]),Y.pb(y[i]+1);
		sort(all(X));X.erase(unique(all(X)),X.end());
		sort(all(Y));Y.erase(unique(all(Y)),Y.end());
		int N=X.size(),M=Y.size();
		vvi dp(N,vi(M));
		int t=1;
		rep(i,n){
			int a=idx(X,x[i]),b=idx(Y,y[i]);
			dp[a][b]=t;
			t*=-1;
		}
		rep(i,N-1)rep(j,M)dp[i+1][j]+=dp[i][j];
		rep(i,N)rep(j,M-1)dp[i][j+1]+=dp[i][j];
		int a=min(min(x[n],x[n+1]),min(x[n+2],x[n+3]));
		int b=max(max(x[n],x[n+1]),max(x[n+2],x[n+3]));
		int c=min(min(y[n],y[n+1]),min(y[n+2],y[n+3]));
		int d=max(max(y[n],y[n+1]),max(y[n+2],y[n+3]));
		a=idx(X,a);b=idx(X,b);c=idx(Y,c);d=idx(Y,d);
		loop(i,a,b)loop(j,c,d)dp[i][j]=0;
		
		ll sum=0;
		rep(i,N)rep(j,M)if(dp[i][j])sum+=(ll)(X[i+1]-X[i])*(Y[j+1]-Y[j]);
		cout<<sum<<endl;
	}
}









Measured memory_bytes: 3156
//author : Yogi79

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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   long n;
   cin>>n;
   vector<pair<long,long>>v;
   pair<long,long>x;

   for(int i=1;i<n+1;i++)
   {
    cin>>x.first;
    x.second = i;
    v.emplace_back(x);
   }   
   
   sort(v.begin(),v.end());
   for(auto x : v)
    cout<<x.second<<" ";
}

Measured memory_bytes: 2544
#include <iostream>


int main(){
    int x,y;
    std::cin >> x >> y;
    bool key=false;
    
    for (int i=0;i<=x;i++){
        if(2*i + 4*(x-i)==y){
            std::cout << "Yes" <<std::endl;
                return 0;
        }
    }

    if (key==false){
        std::cout << "No" <<std::endl;
    }


}


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

using namespace std;
int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c;
    x=b-a;
    y=c-b;
    if(x==y){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
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;}



signed main(){
	int N;
	cin>>N;
	cout<<N*(N-1)/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
int a[maxn] , res;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a , a + n);
    for(int i = 1; i < n; i++)
        res += a[i] - a[i - 1];
    cout << res;
}


Measured memory_bytes: 256
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

// using long doubles saves you from corner cases but is very time consuming
#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
// just comment the line below in case of interactive problems
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

struct cmp 
{
		bool operator()(pair<int,int>& t1, pair<int,int>& t2) 
		{
	    	return t1.S < t2.S;
		}
};

void showpq(priority_queue<pair<int,int>, vector<pair<int,int>>, cmp> gq) 
{ 
    priority_queue<pair<int,int>, vector<pair<int,int>>, cmp> g = gq; 
    while (!g.empty()) 
    { 
        pii p = g.top();
	g.pop();
	cout << p.F << " " << p.S << endl; 
    } 
} 
	
int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		int a[n+5];
		int b[n+5];
		rep(i,1,n)
			cin >> a[i];
		rep(i,1,n)
			cin >> b[i];
		reverse(b+1,b+n+1);
		int c = -1;
		int  l = 0;
		rep(i,1,n)
		{
			if(a[i]==b[i])
			{
				c = a[i];
				l = i;
				break;
			}
		}
		int r = -1;
		brep(i,n,1)
		{
			if(a[i]==b[i])
			{
				r = i;
				break;
			}
		}
		rep(i,1,n)
		{
			if(a[i]!=c && b[i]!=c && l<=r){
				swap(b[i],b[l]);
				l++;
			}	
		}
		if(l<=r)
		{
			cout << "No";
			return 0;
		}
		cout << "Yes" << endl;
		rep(i,1,n)
			cout << b[i] << " ";
	}
}


Measured memory_bytes: 6780
class dsu:
    def __init__(self, n=0):
        self._n = n
        self.parent_or_size = [-1] * n
    
    def merge(self, a: int, b: int) -> int:
        x = self.leader(a)
        y = self.leader(b)
        if x == y:
            return x
        if self.parent_or_size[x] > self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x
    
    def same(self, a: int, b: int) -> bool:
        return self.leader(a) == self.leader(b)
    
    def leader(self, a: int) -> int:
        x = a
        while self.parent_or_size[x] >= 0:
            x = self.parent_or_size[x]
        while a != x:
            self.parent_or_size[a], a = x, self.parent_or_size[a]
        return x
    
    def size(self, a: int) -> int:
        return -self.parent_or_size[self.leader(a)]
    
    def groups(self):
        g = [[] for _ in range(self._n)]
        for i in range(self._n):
            g[self.leader(i)].append(i)
        return list(c for c in g if c)

n, m = map(int, input().split())
vdata = [] # (required, gain)
for _ in range(n):
    a, b = map(int, input().split())
    vdata.append((max(a - b, 0), b))
to = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    to[u].append(v)
    to[v].append(u)
s = dsu(n)
dp = vdata.copy() # (extra, tot_gain)
visited = [False] * n
for u in sorted(range(n), key=lambda i: vdata[i][0]):
    req, gain = vdata[u]
    frm = {u}
    for v in to[u]:
        if visited[v]:
            frm.add(s.leader(v))
    mnextra = 10 ** 18
    for v in frm:
        e, g = dp[v]
        e += max(req - (e + g), 0)
        if e < mnextra:
            mnextra, mni = e, v
    extra, tot_gain = mnextra, sum(dp[v][1] for v in frm)
    for v in frm:
        s.merge(u, v)
    dp[s.leader(u)] = extra, tot_gain
    visited[u] = True
ans = sum(dp[s.leader(0)])
print(ans)


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

vector<vector<int>> graph;
vector<bool> visited;
vector<int> ans;
multiset<int> c;

void DFS(int v, int parent_v = -1){
    if(visited[v] == true) return;
    visited[v] = true;
    ans[v] = *prev(c.end());
    c.erase(prev(c.end()));

    bool leaf = true;
    for(int child_v : graph[v]){
        if(child_v == parent_v) continue;

        leaf = false;
        DFS(child_v, v);
    }
    return;
}

int main(){
    int n;
    cin >> n;
    graph.resize(n);
    visited.resize(n);
    ans.resize(n);

    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int score = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        c.insert(x);
        score += x;
    }

    DFS(0);
    cout << score - ans[0] << endl;
    for(int i=0; i<n; i++){
        cout << ans[i];
        if(i == n-1) break;
        cout << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
	long long n, p, ans = 1;
	scanf("%lld%lld", &n, &p);
	if(n == 1) printf("%lld\n", p);
	else{
		for(long long i = 2; i*i <= p; i += 2){
			int j = 0;
			for(; p%i == 0; p/=i, j++);
			for(int k = 0; k < (j/n); k++) ans *= i;
			if(i == 2) i--;
		}
		printf("%lld\n", ans);
	}
}


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


typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

struct QItem{
    complex<int> p;
    ll step;
};

bool isIn(complex<int> p, vec2<int> field){
    int r = p.real();
    int c = p.imag();
    int H = field.size();
    int W = field[0].size();

    if(!(0 <= r && r < H)){
        return false;
    }
    if(!(0 <= c && c < W)){
        return false;
    }
    return true;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format
    int H, W;
    cin >> H >> W;

    vec2<int> field(H, vec<int>(W, 0));
    ll whites = 0;
    for(int i=0; i < H; i++){
        for(int j=0; j < W; j++){
            while(true){
                char temp;
                cin >> temp;
                if(temp == '#'){
                    field[i][j] = 1;
                }else if(temp == '.'){
                    field[i][j] = 0;
                    whites++;
                }else if(temp == ' ' || temp == '\n'){
                    continue;
                }else{
                    assert(0);
                }
                break;
            }
        }
    }


    // solve
    complex<int> goal(H-1, W-1);
    vector<vector<bool>> visited(H, vector<bool>(W, false));
    queue<QItem> que;
    que.push(QItem{complex<int>(0, 0), 0});
    ll minStep = -1;
    while(!que.empty()){
        auto popped = que.front();
        que.pop();
    
        // ここ来ちゃいけないならやめる
        if(!isIn(popped.p, field) || visited[popped.p.real()][popped.p.imag()] || field[popped.p.real()][popped.p.imag()] == 1){
            continue;
        }
    
        // visitedをつける
        visited[popped.p.real()][popped.p.imag()] = true;
    
        // もしゴールならゴール
        if(popped.p == goal){
            minStep = popped.step;
            break;
        }
    
        // 次にいく
        vector<complex<int>> ds{complex<int>(1, 0), complex<int>(-1, 0), complex<int>(0, 1), complex<int>(0, -1)};
        for(auto d: ds){
            que.push(QItem{popped.p + d, popped.step + 1});
        }
    }

    if(minStep == -1){
        cout << -1 << endl;
    }else{
        cout << whites - minStep - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,x,y,z;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b){
		x = a;
		a = b;
		b = x;
	}if(b > c){
		y = b;
		b = c;
		c = y;
	}if(a >b){
		z = a;
		a = b;
		b = z;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;

    int num = s.size();
    vvi dp(num+1, vi(k+1));
    vi dp_(num+1);
    rep(i, num) {
        dp_[i+1] = dp_[i];
        int now = s[i] - '0';
        if(s[i] != '0') {
            dp_[i+1]++;
            if(dp_[i] < k) {
                dp[i+1][dp_[i]+1] = now-1;
            }
            if(dp_[i] <= k) {
                dp[i+1][dp_[i]]++;
            }
        } 
        rep(j, k) {
            dp[i+1][j+1] += dp[i][j] * 9;
        }
        rep(j, k+1) {
            dp[i+1][j] += dp[i][j];
        }
    }

    if(dp_[num] == k) {
        dp[num][k]++;
    }
    cout << dp[num][k] << endl;
}

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

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

fn main() {
    let m = (read::<usize>(), read::<usize>(), read::<usize>());
    if m.0 + m.1 + m.2 >= 22 {
        println!("bust");
    } else {
        println!("win");
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	string s;
	int k;
	cin >> s >> k;

	if (s.size() == 1) {
		cout << floor(k / 2.0) << endl;
		return 0;
	}

	// if (set<char>(all(s)).size() == 1) {
	//	cout << floor(s.size() * k / 2.0) << endl;
	//	return 0;
	//}

	string t = s + s, u = s + s + s;
	int sum = 0, dsum = 0, ksum = 0;
	;
	{
		int cnt = 0;
		rep(i, s.size() - 1) {
			if (s[i] == s[i + 1]) {
				cnt++;
			} else {
				sum += floor((cnt + 1) / 2.0);
				cnt = 0;
			}
		}
		sum += floor((cnt + 1) / 2.0);
	}
	{
		int cnt = 0;
		rep(i, t.size() - 1) {
			if (t[i] == t[i + 1]) {
				cnt++;
			} else {
				dsum += floor((cnt + 1) / 2.0);
				cnt = 0;
			}
		}
		dsum += floor((cnt + 1) / 2.0);
	}
	{
		int cnt = 0;
		rep(i, u.size() - 1) {
			if (u[i] == u[i + 1]) {
				cnt++;
			} else {
				ksum += floor((cnt + 1) / 2.0);
				cnt = 0;
			}
		}
		ksum += floor((cnt + 1) / 2.0);
	}
	int ddif = ksum - sum;
	int dif  = dsum - sum;
	cout << sum + ddif * (k - 1) / 2 + dif * (k - 1) % 2 << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	public static final long MOD = 1000000007;
	
	public static class State implements Comparable<State> {
		long limit;
		long cnt;
		
		public State(long limit, long cnt) {
			this.limit = limit;
			this.cnt = cnt;
		}

		@Override
		public int compareTo(State o) {
			return Long.compare(o.limit, this.limit);
		}
	}
	
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final char[] as = sc.next().toCharArray();
			final char[] bs = sc.next().toCharArray();
			final char[] cs = sc.next().toCharArray();
			
			int answer = 0;
			for(int i = 0; i < N; i++) {
				if(as[i] == bs[i] && bs[i] == cs[i]) {
					answer += 0;
				}else if(as[i] == bs[i]) {
					answer += 1;
				}else if(as[i] == cs[i]) {
					answer += 1;
				}else if(bs[i] == cs[i]) {
					answer += 1;
				}else {
					answer += 2;
				}
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

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

  int s[M];
  int c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }

  // 2桁以上の場合、先頭に 0 をつけた表記は認めない
  if (N > 1) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  int start;
  int end;
  if (N == 1) {
    start = 0;
    end = 9;
  } else if (N == 2) {
    start = 10;
    end = 99;
  } else {
    start = 100;
    end = 999;
  }

  for (int count = start; count <= end; count ++) {
    string strCount = to_string(count);
    bool hit = true;
    for (int i = 0; i < M; i++) {
      if (!(ctoi(strCount.at(s[i] - 1)) == c[i])) {
        hit = false;
      }
    }
    if (hit == true) {
      cout << count << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int num, taste;
    cin >> num >> taste;

    int ans =0;

    if(taste>0){
        for(int i=2;i<=num;i++){
            ans  += taste + i -1;
        }
    }else if(taste+num-1<0){
        for(int i=1;i<=num-1;i++){
            ans += taste + i -1;
        }
    }else{
        for(int i=1;i<=num;i++){
            ans += taste + i - 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
package main

import "fmt"

func isKai(s string) bool {
	//fmt.Println(s)
	n := len(s)
	for i:=0 ; i<n/2 ;i++ {
		if s[i:i+1] != s[n-1-i:n-i] {
			return false
		}
	}
	return true
}

func main(){
	var s string
	fmt.Scan(&s)
	n := len(s)
	if isKai(s) && isKai(s[0:(n-1)/2]) && isKai(s[(n+3)/2-1:n]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N);

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

    int64_t ret = 0x7FFFFFFFFFFFFFFF;
    rep(i, N-K+1) {
        int64_t l = x[i];
        int64_t r = x[i+K-1];

        int64_t time1 = abs(l) + abs(r-l);
        int64_t time2 = abs(r) + abs(r-l);
        ret = min(ret, min(time1, time2));
    }
    cout <<ret << endl;

    return 0;
}



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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

const ll N = 2e6+5;
ll fact[N];
ll ifact[N];
ll p25[N];

void pre(){

    fact[0] = 1;
    ifact[0] = 1;
    p25[0] = 1;
    for(ll i=1;i<N;i++){
        fact[i] = fact[i-1]*i%mod;
        ifact[i] = inv(fact[i]);
        p25[i] = p25[i-1]*25%mod; 
    }

}

ll ncr(ll n,ll r){
    ll tmp = fact[n]*ifact[r]%mod;
    tmp = tmp*ifact[n-r]%mod;
    return tmp;
}

void solve(){

    ll k;
    cin >> k;
    string s;
    cin >> s;
    ll n = s.size();
    ll sz = n+k;
    // ll ans = 0;
    // for(ll i=n;i<=sz;i++){
    //     ans += ncr(sz,i)*p25[sz-i]%mod;
    //     ans %= mod;
    // }
    ll ans = fast(26,sz);
    for(ll i=0;i<n;i++){
        ll extra = ncr(sz,i)*p25[sz-i]%mod;
        ans -= extra;
        ans %= mod;
        ans += mod;
        ans %= mod;
    }
    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 51132
#include <iostream>

using namespace std;

int main()
{
        string s;
        cin >> s;
        int count = 0;

        for (int i = 0; i < (int)s.size(); ++i)
        {
                if (s == "RSR")
                {
                        count = 1;
                        break;
                }
                else if (s[i] == 'R')
                {
                        count++;
                }
        }
        cout << count << endl;
}


Measured memory_bytes: 3200
<?php

  $stdin = fopen('php://stdin', "r");
  
  while(true) {
      fscanf($stdin, "%d", $num);
      if($num === 0) {
          break;
      }
      
      echo isPerfectNumber($num) . PHP_EOL;
  }
  
  function isPerfectNumber($num) {
      $mean = floor(sqrt($num));
      $divPlus = 1;
      if($num === 1) {
          return "deficient number";
      }
      for($i = 2; $i <= $mean; $i++) {
          $tmp = $num/$i;
          if(is_int($tmp)) {
              if($tmp === $i){
                $divPlus = $divPlus + $tmp;
              } else {
                $divPlus = $divPlus + $tmp + $i;
              }
          }
      }
      
      if($divPlus === $num) {
          return "perfect number";
      } else if($divPlus > $num) {
                  return "abundant number";
      }
      else {
          return "deficient number";
      }
  }
  

?>

Measured memory_bytes: 6620
S = list(input())
T = list(input())
lenS = len(S)
lenT = len(T)
if lenS < lenT:
    print("UNRESTORABLE")
else:
    end = False
    for i in range(lenS - lenT, -1, -1):
        cnt = 0
        for j in range(lenT):
            if S[i + j] == T[j] or S[i + j] == "?":
                cnt += 1
            else:
                break
            if cnt == lenT:
                for k in range(lenT):
                    S[i + k] = T[k]
                end = True
        if end:
            ans = ""
            for k in range(lenS):
                if S[k] == "?":
                    S[k] = "a"
                ans = ans + S[k]
            print(ans)
            break
        if i == 0 and not end:
            print("UNRESTORABLE")

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

class Solution {
  bool test(string s) {
    deque<char> dq(s.begin(), s.end());
    string key = "keyence";
    int l = 0, r = 0;
    while (l < min(s.size(), key.size()) and s[l] == key[l]) ++l;
    reverse(key.begin(), key.end());
    reverse(s.begin(), s.end());
    while (r < min(s.size(), key.size()) and s[r] == key[r]) ++r;
    return l + r >= key.size();
  }
public:
  void run(istream &in, ostream &out) {
    string s; in >> s;
    out << (test(s) ? "YES" : "NO") << '\n';
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solution().run(cin, cout);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
//条件式 ? 真の場合の文 : 偽の場合の文
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換
//binary_search(all(p),x) bool型




int main(){

    int x,y,nx,ny;
    cin >> x >> y >> nx >> ny;
    int dx = nx - x;
    int dy = ny - y;

    rep(i,dy) cout << 'U';
    rep(i,dx) cout << 'R';
    rep(i,dy) cout << 'D';
    rep(i,dx) cout << 'L';
    cout << 'L';
    rep(i,dy+1) cout << 'U';
    rep(i,dx+1) cout << 'R';
    cout << 'D' << 'R';
    rep(i,dy+1) cout << 'D';
    rep(i,dx+1) cout << 'L';
    cout << 'U'<< endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int d = cin.nextInt();
        int x = cin.nextInt();
        int a = 0;
        for (int i = 0; i < n; i++) {
            a = cin.nextInt();
            for (int day = 1; day <= d; day += a) {
                x++;
            }
        }
        System.out.println(x);
    }

}


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

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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  int x[n];
  int sum = 0;
  rep (i, n) {
    cin >> x[i];
    sum += x[i];
  }
  int ave = round((double)sum / n);
  int ans = 0;
  rep (i, n) {
    ans += pow(x[i] - ave, 2);
  }
  // cout << sum << " - " << ave << endl;
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
    char s[99];
    int judge = 0,i;
    scanf("%s",s);
    int n = strlen(s);
    if(n < 3){
        judge = 1;
    }

    if(judge == 0){
        for(i = 0; i < n/2; i++){
            if(s[i] != s[n-i-1]){
                judge = 1;
            }
        }
    }

    if(judge == 0){
        for(i = 0; i < (n-1)/2/2; i++){
            if(s[i] != s[(n-1)/2-1-i]){
                judge = 1;
            }
        }
    }

    if(judge == 0){
        for(i = (n+3)/2; i< n; i++){
            if(s[i] != s[n-1-i]){
                judge = 1;
            }
        }
    }

    if(judge == 0){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans
 
N = int(input())
a = map(int, input().split())
ans = min(map(how_many_times_divisible, a))
 
print(ans)

Measured memory_bytes: 2940
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
        ll n;
        cin>>n;
        if(n==0 || n==1)
        cout<<"0"<<endl;
        else if(n%2==0)
        {
            ll p1 = n/2;
            ll ans =0;
            ll r1 = 5;
            for (ll i = 5; p1 / i >= 1; i *= 5) 
        ans += p1 / i;
        cout<<ans;
        }
        else
        {
            ll p1 =(n+1)/2;
            ll ans =0;
            ll ans1=0;
            for (ll i = 5; p1 / i >= 1; i *= 5) 
            ans += p1 / i;
           ll k1 = p1;
           p1*=2;
        for (ll i = 5; p1 / i >= 1; i *= 5) 
        ans1 += p1 / i;
        cout<<max(ans1-ans-k1,0LL)<<endl;
        }
         

      }
      






}












Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    S = list(map(int, input().split()))

    q = int(input())
    T = list(map(int, input().split()))

    cnt = 0
    for i in T:
        for j in S:
            if i == j:
                cnt += 1
                break
    print(cnt)


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

using namespace std;
typedef long long LL;

int main() {
	int K;
	string S;
	cin >> K >> S;
	if (S.length() <= K) cout << S << "\n";
	else {
		cout << S.substr(0, K) << "...\n";
	}
}

Measured memory_bytes: 3632
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

m = inn()
cnt = 0
a = []
for i in range(m):
    d,c = inm()
    while c>1:
        if c%2 == 1:
            a.append(d)
            c -= 1
        if d<5:
            d = 2*d
            cnt += c//2
        else:
            d = 2*d-9
            cnt += c
        c //= 2
    a.append(d)

ddprint("cnt {}  a:".format(cnt))
ddprint(a)

x = a.pop()
while len(a)>0 or x>9:
    if x>9:
        x = (x//10)+(x%10)
        cnt += 1
    else:
        y = a.pop()
        x += y
        cnt += 1
print(cnt)


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

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

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

int lcm(int a, int b)
{
	return (a / gcd(a, b)) * b;
}

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int n;
	cin>>n;
	vector<int>v(1000005);
	for(int i=0;i<n;i++){
		int h;
		cin>>h;
		v[h]++;
	}
	int ans=0;
	vector<int>d(1000005,0);
	for(int i=1;i<=1000000;i++){
		if(v[i]==0 || d[i]){
			continue;
		}
		if(v[i]==1 && !d[i])
		ans++;
		for(int j=i;j<=1000000;j+=i)
			d[j]=1;
	}
	cout<<ans;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


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

left = 0
for i in range(N - 1, -1, -1):
    if S[i] == ")":
        left += 1
    else:
        left = max(0, left - 1)

right = 0
for i in range(N):
    if S[i] == "(":
        right += 1
    else:
        right = max(0, right - 1)

print("(" * left + S + ")" * right)

Measured memory_bytes: 3064