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

using namespace std;

int64_t N, M;
vector<int64_t> a;

int64_t solve_brute() {
  vector<int64_t> a2;
  a2.reserve(N * N);
  for (int64_t n1 : a) {
    for (int64_t n2 : a) {
      a2.push_back(n1 + n2);
    }
  }
  sort(a2.rbegin(), a2.rend());
  return accumulate(a2.begin(), a2.begin() + M, 0LL);
}

int64_t solve() {
  vector<int64_t> integral(N + 1);
  for (int i = 0; i < N; ++i) {
    integral[i + 1] = integral[i] + a[i];
  }

  int64_t left = 0;
  int64_t right = a.back() * 2 + 1;
  int64_t cnt;
  while (left + 1 < right) {
    cnt = 0;
    auto mid = (left + right) / 2;
    for (int i = 0; i < N; ++i) {
      auto diff = mid - a[i];
      auto it = lower_bound(a.begin(), a.end(), diff);
      cnt += a.end() - it;
      if (M < cnt)
        break;
    }
    if (M <= cnt) {
      left = mid;
    } else {
      right = mid;
    }
  }

  cnt = 0;
  int64_t score = 0;
  for (int i = 0; i < N; ++i) {
    auto diff = left - a[i];
    auto it = lower_bound(a.begin(), a.end(), diff);
    cnt += a.end() - it;
    score += a[i] * (a.end() - it);
    score += integral.back() - integral[it - a.begin()];
  }

  score -= (cnt - M) * left;

  return score;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N >> M;
  a.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  // cerr << solve_brute() << endl;
  cout << solve() << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<stack>
using namespace std;
char s[100];
char ans[100];

char change(char c, int plus, int minas) {
  int t = (int)c - (int)'A' + plus - minas + ((int)'Z' - (int)'A' + 1) * 100;
  t %= ((int)'Z' - (int)'A' + 1);
  return 'A' + (char)t;
}

void reverse(int b, int g) {
  ans[b++] = '!';
  ans[g--] = '!';
  for (; b < g; b++, g--) swap(ans[b], ans[g]);
}

int main() {
  while (1) {
    scanf("%s", s);
    if (s[0] == '.') break;
    int cNum = 0;
    int plus = 0;
    int minas = 0;
    stack<int> stc;
    for (int i = 0; s[i] != 0; i++) {
      if (s[i] == '+') {
        plus++;
      } else if (s[i] == '-') {
        minas++;
      } else {
        if ('A' <= s[i] && s[i] <= 'Z') {
          ans[cNum++] = change(s[i], plus, minas);
        } else {
          ans[cNum++] = s[i];
          if (s[i] == '[') stc.push(cNum - 1);
          if (s[i] == ']') {
            reverse(stc.top(), cNum - 1);
            stc.pop();
          }
        }
        plus = minas = 0;
      }
    }
    for (int i = 0; i < cNum; i++) {
      if ('A' <= ans[i] && ans[i] <= 'Z') printf("%c", ans[i]);
      if (ans[i] == '?') printf("A");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2592
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string S;
int N;

int main(){
    cin>>S;
    N=S.size();

    int g=0, p=0;
    rep(i,N){
        if(S[i]=='g') g++;
        if(S[i]=='p') p++;
    }

    int ans=g-p;
    if(ans>0) ans/=2;
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.min(n * a, b));
		sc.close();
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // Input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        // Calc
        int x = 800 * n;		// Payment
        int y = 200 * (n/15);	// Kickback
        int z = x-y;			// Result

        // Output
        System.out.println(z);

        sc.close();

    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define   ll   long long int
#define   sz   200010

using namespace std;


ll num[sz];

int main()
{


   ll n;

   ll a,i,b;

   for(i=1;i<=3;i++)
   {
       cin>>num[i];
   }

   swap(num[1],num[2]);
   swap(num[1],num[3]);

   cout<<num[1]<<" "<<num[2]<<" "<<num[3]<<endl;


   return 0;
}


Measured memory_bytes: 256
N, C = map(int, input().split())
X = []
V = []
for i in range(N):
  x, v = map(int, input().split())
  X.append(x)
  V.append(v)

frontS = []
# 前i個の中での累計MAX
frontMaxS = []
prevX = 0
v = 0
tmpMax = float('-inf')
for i in range(N):
  v = v + V[i] - (X[i] - prevX)
  frontS.append(v)
  tmpMax = max(tmpMax, v)
  frontMaxS.append(tmpMax)
  prevX= X[i]
frontMaxS.reverse()
frontMaxS.append(0)

backS = []
# 後ろi個の中での累計MAX
backMaxS = []
prevX = C
v = 0
tmpMax = float('-inf')
for i in range(N-1, -1, -1):
  v = v + V[i] - (prevX - X[i])
  backS.append(v)
  tmpMax = max(tmpMax, v)
  backMaxS.append(tmpMax)
  prevX = X[i]
backMaxS.reverse()
backMaxS.append(0)

ans = max(0, backMaxS[0], frontMaxS[0])
for i in range(N):
  # X個まで食べて、退出 or 引き返す
  ans = max(
    ans,
    frontS[i],
    frontS[i] - X[i] + backMaxS[i+1],
    backS[i],
    backS[i] - (C-X[-i-1]) + frontMaxS[i+1]
  )

print(ans)

Measured memory_bytes: 21676
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)
	//sc.Buffer(nil, 100000000)
	n := nextInt()

	as := make([]int, n+1)
	nums := make(map[int][]int)
	for i := 2; i <= n; i++ {
		as[i] = nextInt()

		if _, ok := nums[as[i]]; !ok {
			nums[as[i]] = make([]int, 0)
		}
		if _, ok := nums[i]; !ok {
			nums[i] = make([]int, 0)
		}
		nums[as[i]] = append(nums[as[i]], i)
	}

	for i := 1; i <= n; i++ {
		fmt.Println(len(nums[i]))
	}
}


Measured memory_bytes: 27540
#include "bits/stdc++.h"
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
      cin >> a.at(i);
  }
    int z =1;
    int ans =0;
    int check =0;
    for (int i=0;i<n-1;i++){
      ans++;
        int b = z-1;
      if(a.at(b)==2){
          
          cout << ans << endl;
          check++;
          break;
}
      else {
          z = a.at(b);
      }
  }
  if (check ==0){
      cout << -1 << endl;
  }
}

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

using namespace std;

const int N = 1e5 + 5;

int dp[N][2];
bool kosong[N];
vector<int> g[N];

void dfs(int v, int par = -1) {
  dp[v][1] = 0;
  dp[v][0] = 0;
  kosong[v] = 1;
  int child = 0;
  for (int u : g[v]) if (u != par) {
    dfs(u, v);
    int one = dp[v][1] + dp[u][1], zero = dp[v][0] + dp[u][1];
    if (kosong[u])
      one = min(one, dp[v][0]);
    else
      kosong[v] = 0;
    dp[v][1] = one;
    dp[v][0] = zero;
    ++child;
  }
  if (child > 1)
    kosong[v] = 0;
  dp[v][1] = max(dp[v][1], 1);
  dp[v][0] = max(dp[v][0], 1);
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int banyak = g[0].size(), root = 0;
  for (int i = 0; i < n; ++i) {
    if (banyak < g[i].size())
      root = i, banyak = g[i].size();
  }
  if (banyak <= 2) {
    puts("1");
    return 0;
  }
  dfs(root);
  printf("%d\n", dp[root][1]);
  return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define dd double
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int i,j,k;
	if(s.compare("RRR")==0)
	cout<<"3";
	else if(s.compare("SSS")==0)
	cout<<"0\n";
	else if(s.compare("RSR")==0)
	cout<<"1\n";
	else if(s.compare("SRS")==0)
	cout<<"1\n";
	else if(s.compare("RSS")==0)
	cout<<"1";
	else if(s.compare("SSR")==0)
	cout<<"1";
	else if(s.compare("RRS")==0)
	cout<<"2";
	else if(s.compare("SRR")==0)
	cout<<"2";
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>   
using namespace std;
#define N 1000000   
#define REP(i, n) for(int i=0; i<n; i++)
int n;
int l[N] ;
int main(void){
    cin>>n;
    REP(i,n)cin>>l[i];
    int now=0;int c=0;

    while(c<=n){
        if(now==1){
            break;
        }
        c++;
        now=l[now]-1;
    }
    if(c>n)c=-1;
    printf("%d",c);    
}


Measured memory_bytes: 640
import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int max = Math.max(a, c);
        int min = Math.min(b, d);
        if(min >= max){
            System.out.println(min - max);
        }else{
            System.out.println(0);
        }


    }
}

Measured memory_bytes: 22996
use proconio::input;
fn main() {
    input! {
        a: usize,
        b: usize
    }
    let c = format!("{}{}", a, b);
    let c = c.parse::<usize>().unwrap();
    if check(c) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn check(n: usize) -> bool {
    let sqrt = (n as f64).sqrt();
    if sqrt == ((sqrt + 1e-9) as usize) as f64 {
        true
    } else {
        false
    }
}


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

using namespace std;
int main()
{
	vector<int> h1;
	vector<int> h2;
	vector<pair<int,int> > m;
	int N,M;
	
	cin>>N;
	for(int i=0;i<N;i++){
		h1.push_back(0);
		h2.push_back(0);
		m.push_back(make_pair(0,0));
		cin>>h1[i]>>h2[i];
		m[i]=make_pair(h1[i],h2[i]);
	}
	cin>>M;
	for(int i=0;i<M;i++){
		h1.push_back(0);
		h2.push_back(0);
		m.push_back(make_pair(0,0));
		cin>>h1[i]>>h2[i];
		m[i+N]=make_pair(h1[i],h2[i]);
	}
	
	sort(m.begin(),m.end());
	
	for(int i=0;i<M+N-1;i++){
		if(m[i].first==m[1+i].first&&m[i].second==m[1+i].second)
		continue;
		else
		cout<<m[i].first<<":";
		if(m[i].second<10)
		cout<<"0"<<m[i].second<<" ";
		else
		cout<<m[i].second<<" ";
	}
	cout<<m[M+N-1].first<<":";
	if(m[M+N-1].second<10)
	cout<<"0"<<m[M+N-1].second<<endl;
	else
	cout<<m[M+N-1].second<<endl;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;
typedef long long ll;
const int N=2*100009;
int ar[N];
int main()
{
	fastio;
	int k,n,i,id1,id2,mx=-1,d,flag=0;
    cin>>k>>n;
    for(i=1; i<=n; i++)
    {
    	cin>>ar[i];
    }

    for(i=2; i<=n; i++)
    {
       d=ar[i]-ar[i-1];
       if(d>mx)
       {
       	 mx=d;
       	 id1=i-1;
       	 id2=i;
       }
    }
    d=k-ar[n]+ar[1];
    if(d>mx)
    {
    	mx=d;
    	flag=1;
    	id1=1; 

    }
    ll sum=0;
    if(flag)
    {
      for(i=1; i<n; i++)
      {
      	 sum+=(ar[i+1]-ar[i]);
      }
    }
    else
    {
    	for(i=id1; i>1; i--)
    	{
    		sum+=(ar[i]-ar[i-1]);
    	}
    	for(i=id2; i<n; i++)
    	{
    		sum+=(ar[i+1]-ar[i]);
    	}
    	sum+=(k-ar[n]+ar[1]);
    }
    cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}
void dfs(string s,int depth,int n,char alp[],int& ans,int b){
    if(depth <= n){
        if(s.find('3') <= 100 && s.find('5') <= 100 && s.find('7') <= 100){
            if(b >= stoi(s)) {
                ans++;
            }
        }
        for(int i = 0;i < 3;i++){
            s += alp[i];
            depth++;
            dfs(s,depth,n,alp,ans,b);
            s.erase(s.size()-1);
            depth--;
        }
    }
}



int main(){
    string a; cin >> a;
    string s = "";
    vector<int>v;
    int ans = 0;
    char alp[3] = {'3','5','7'};
    int depth = 0;
    dfs(s,depth,(int)a.length(),alp,ans,stoi(a));
    cout << ans;
}



Measured memory_bytes: 3600
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 18;
char C[CM + CL], * ci = C + CL, * owa = C + CM, c;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;

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


	fread(ci, 1, CM, stdin);
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';
	int D[10];
	int d = 1;
	rep(i, 10) {
		D[i] = d;
		d *= 10;
	}

	ll p[20][20] = {};
	rep(i, N) {
		if (ci - owa > 0) {
			memcpy(C, owa, CL);
			ci -= CM;
			fread(C + CL, 1, CM, stdin);
		}

		ll kari = 0;
		while ((c = *ci++) >= '0') kari = kari * 10 + c - '0';
		int d = 9;
		if (*(ci - 1) == '.') {
			ll tmp = *(ll*)ci;
			if ((tmp & ma0) ^ ma0) {
				int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
				tmp = tmp << dig & ma1;
				tmp = tmp * 10 + (tmp >> 8) & ma2;
				tmp = tmp * 100 + (tmp >> 16) & ma3;
				tmp = tmp * 10000 + (tmp >> 32) & ma4;
				ci += (72 - dig >> 3);
				d -= (64 - dig >> 3);
				kari = kari * D[(64 - dig >> 3)] + tmp;
			}
			else {
				tmp = tmp & ma1;
				tmp = tmp * 10 + (tmp >> 8) & ma2;
				tmp = tmp * 100 + (tmp >> 16) & ma3;
				tmp = tmp * 10000 + (tmp >> 32) & ma4;
				ci += 8;
				d -= 8;
				kari = kari * 100000000 + tmp;
				if (*ci >= '0') {
					kari = kari * 10 + *ci++ - '0';
					d--;
				}
				ci++;
			}
		}
		int a = __builtin_ctzll(kari) + d;
		if (a > 18) a = 18;
		int b = d;
		while (kari % 5 == 0) {
			b++;
			kari /= 5;
		}
		p[a][b]++;
	}
	ll kotae = 0;
	rep(a, 19) rep(b, 19) if (p[a][b]) {
		ll P = p[a][b];
		for (int x = max(a, 18 - a); x <= 18; x++) {
			if (x == a) {
				for (int y = max(b, 18 - b); y <= 18; y++) {
					if (y == b) kotae += P * (P - 1) / 2;
					else kotae += P * p[x][y];
				}
			}
			else {
				for (int y = 18 - b; y <= 18; y++) {
					kotae += P * p[x][y];
				}
			}
		}
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define BLOCK 750
#define mxn 5000001
using namespace std;
struct query{
	int l;
	int r;
	int i;
};
query Q[mxn];
int ar[mxn] , ans[mxn];
int fre[mxn];
int cnt = 0;
bool comp(query a , query b)
{
	if(a.l / BLOCK != b.l/BLOCK)
	return a.l/BLOCK < b.l/BLOCK;
 
	return a.r < b.r;
}
 
void add(int pos)
{
	fre[ar[pos]]++;
	if(fre[ar[pos]] == 1)
	cnt++;
}
 
void remove(int pos)
{
	fre[ar[pos]]--;
	if(fre[ar[pos]] == 0)
	cnt--;
}
 
int main()
{
	 ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
 
 
 
	int n , q; 
	cin>>n >> q;
	for(int i=0;i<n;i++)
	cin>>ar[i];
 
	
	for(int i=0;i<q;i++){
		cin>>Q[i].l>>Q[i].r;
		Q[i].i = i , Q[i].l-- , Q[i].r--;
	}
 
	sort(Q , Q+q , comp);
 
	int ML = 0 , MR = -1;
	for(int i=0;i<q;i++)
	{
		int L = Q[i].l;
		int R = Q[i].r;
 
		while(ML > L)
		ML-- , add(ML);
 
		while(MR < R)
		MR++ , add(MR);
 
		while(ML < L)
		remove(ML) , ML++;
 
		while(MR > R)
		remove(MR) , MR--;
 
		ans[Q[i].i] = cnt;
	}
 
	for(int i=0;i<q;i++)
	cout<<ans[i]<<'\n';
}

Measured memory_bytes: 15432
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a;
    double z = 0;
    cin >> n;
    while (n--) cin >> a, z += 1.0 / a;
    cout << 1 / z;
}


Measured memory_bytes: 3700
#38 ABC129D
h,w=map(int,input().split())
s=[input() for _ in range(h)]

x=[[0 for _ in range(w)] for _ in range(h)]
y=[[0 for _ in range(w)] for _ in range(h)]

t=0
for i in range(h):
	t=0
	for j in range(w):
		if s[i][j]==".":
			t+=1
		else:
			t=0
		x[i][j]=t
for i in range(h):
	for j in range(1,w):
		if x[i][w-j-1]==0:
			continue
		elif x[i][w-j]==0:
			continue
		else:
			x[i][w-j-1]=x[i][w-j]

t=0
for j in range(w):
	t=0
	for i in range(h):
		if s[i][j]==".":
			t+=1
		else:
			t=0
		y[i][j]=t
for j in range(w):
	for i in range(1,h):
		if y[h-i-1][j]==0:
			continue
		elif y[h-i][j]==0:
			continue
		else:
			y[h-i-1][j]=y[h-i][j]

z=[[x[i][j]+y[i][j] for j in range(w)] for i in range(h)]
res=0
for t in z:
	res=max(res,max(t))
print(max(0,res-1))

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;

    mp ms1;
    rep(i, n){
        string s;
        cin >> s;
        ms1[s]++;
    }
    int m;
    cin >> m;
    mp ms2;
    rep(i, m){
        string s;
        cin >> s;
        ms2[s]++;
    }

    int ans = 0;
    for (auto& p : ms1) {
        if(p.second > ms2[p.first]){
            ans = max(ans, p.second - ms2[p.first]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import fractions
def lcm(a,b):
    return a*b/fractions.gcd(a,b)

while True:
    n=input()
    if n==0:break
    D,T=[],[]
    for i in range(n):
        d,t=map(int,raw_input().split())
        D.append(d)
        T.append(t)
    dn=reduce(lcm,D)
    nm=[T[i]*dn/D[i] for i in range(n)]
    g=reduce(fractions.gcd,nm)
    for i in range(n):
        print nm[i]/g

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int N = S.size();
    if (S[N-1]=='s'){
        cout<<S<<"es"<<endl;
    }else{
        cout<<S<<"s"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3656
s = input()
k = int(input())

if len(set(s)) == 1:
    ans = len(s) * k //2
else:
    if s[0] != s[-1]:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        ans = cnt * k
    else:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        tmp = cnt * k

        cnt_s = 0
        i = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt_s += 1
                i += 2
            else:
                i += 1
        
        s_2 = s * 2
        cnt_s_2 = 0
        i = 0
        while i < len(s_2) - 1:
            if s_2[i] == s_2[i+1]:
                cnt_s_2 += 1
                i += 2
            else:
                i += 1

        diff = cnt_s_2 - 2 * cnt_s
        ans = tmp + diff * (k-1)



print(ans)

Measured memory_bytes: 39732
#include<stdio.h>
#define swap(X, Y) {int Z; Z = Y; Y = X; X= Z; }
int main(void)
{
	int  a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b)
	{
		swap(a, b);
	}
	
	if(a > c)
    {
    	swap(a, c);
	}
	
	if(b > c)
	{
		swap(b, c);
	}	
	printf("%d %d %d\n", a, b, c);
	return 0;
} 


Measured memory_bytes: 2748
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
int f(int a, int b) {
	if (b > a)swap(a, b);
	if (a%b == 0)return b;
	return f(a%b, b);
}
signed main() {
	int n; cin >> n;
	int a; cin >> a;
	for (int i = 1; i < n; i++) {
		int b; cin >> b;
		a = f(a, b);
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

int main(){
	int h,a;
	cin>>h>>a;
	cout<<h/a+bool(h%a)<<endl;




}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }


int main(){
  li n;cin >>n;
  li s=0;
  rep(i,n){
    s+=(i+1)*(n-i);
  }
  if(df)print(s);
  
  li mn=0;
  rep(i,n-1){
    int u,v; cin >>u >>v;
    if(u>v)swap(u,v);
    mn+=u*(n-v+1);
  }
  print(s-mn);
  if(s-mn<0){
    while(1) print(1);
  }
}


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

int dp[100010][2];
int a[100010];

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	memset(dp, -1, sizeof(dp));
	dp[0][0] = dp[0][1] = 0;
	for (int i = 1; i <= k; i++){
		for (int p = 0; p < 2; p++){
			for (int j = 0; j < n; j++){
				int last = i - a[j];
				if (last < 0) continue;
				if (dp[last][p ^ 1] == -1) dp[i][p] = 1;
				else if (dp[last][p ^ 1] == 1 && dp[i][p] == -1) dp[i][p] = 0;
				else if (dp[last][p ^ 1] == 0) dp[i][p] = 1;
			}
//			cout << "  " << i << " " << p << " " << dp[i][p] << endl;
		}
	}
	printf(dp[k][0] == 1 ? "First\n" : "Second\n");
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int a[10], b[10];

int main(){
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1];
	sort(a, a + 4, greater<int>());
	sort(b, b + 4, greater<int>());
	cout << a[0] + a[1] + a[2] + b[0] << endl;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n,m; cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 256
use proconio::input;
// use num::*;

fn main() {
    input! {
        n: String,
    };
    let last_s = n.chars().last().unwrap();
    let res = if last_s == '2' || last_s == '4' || last_s == '5' || last_s == '7' || last_s == '9' {
        "hon"
    } else if last_s == '0' || last_s == '1' || last_s == '6' || last_s == '8' {
        "pon"
    } else {
        "bon"
    };
    println!("{}", res);
}


Measured memory_bytes: 2092
#include<algorithm>
#include<stack>
#include<ctime>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<queue>
using namespace std;
inline int read(){
	int num=0,f=1;char x=getchar();
	while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}
	while(x>='0'&&x<='9'){num=num*10+x-'0';x=getchar();}
	return num*f;
}
int n;
int main(){
	n=read();int ans=0;
	for(int i=1,a;i<=n;++i){
		a=read();
		ans+=((i&1)&&(a&1));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

int n, m;

vector<int> mem[110][110];

vector<int> e[110];

int a[110][110];

int vis[110], ts;
int mat[110];
int rev[110];

bool dfs(int x) {
	if(vis[x] == ts) return false;
	vis[x] = ts;
	for(int y:e[x]) if(!rev[y] || dfs(rev[y])) {
		mat[x] = y;
		rev[y] = x;
		return true;
	}

	return false;
}

int main()
{
	cppio(); cin >> n >> m;
	rrep(i, n) {
		rrep(j, m) {
			int t; cin >> t;
			mem[i][(t+m-1)/m].pb(t);
		}
	}

	rrep(j, m) {
		rrep(i, n) {
			e[i].clear();
			e[i].reserve(m);
			rrep(k, n) {
				int c = sz(mem[i][k]);
				for(;c--;) {
					e[i].pb(k);
				}
			}
		}

		++ts;
		fill(mat+1, mat+n+1, 0);
		fill(rev+1, rev+n+1, 0);

		bool upd = 1;
		while(upd) {
			upd = 0;
			rrep(i, n) if(!mat[i] && dfs(i)) { upd = 1; }
			if(upd) ++ts;
		}

		rrep(i, n) {
			auto &v = mem[i][mat[i]];
			a[i][j] = v.back();
			v.pop_back();
		}
	}

	rrep(i, n) {
		rrep(j, m) cout << a[i][j] << ' ';
		cout << '\n';
	}

	vector<int> v;
	rrep(j, m) {
		v.clear(); rrep(i, n) v.pb(a[i][j]);
		sort(all(v));
		rrep(i, n) a[i][j] = v[i-1];
	}

	rrep(i, n) {
		rrep(j, m) cout << a[i][j] << ' ';
		cout << '\n';
	}

	return 0;
}


Measured memory_bytes: 1024
n=int(input())
ans=2148483647
for i in range(1,n):
    a,b=i,n-i
    t=0
    for j in range(len(str(a))):
        t+=int(str(a)[j])
    for j in range(len(str(b))):
        t+=int(str(b)[j])
    if t<ans:
        ans=t
print(ans)

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}
main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n;
  cin>>n;

  ll a=1,b=0;
  rep(i,n){
    ll q,x;
    cin>>q>>x;
    if(q==1){
      a*=x;
      b*=x;
    }
    if(q==2)b+=x;
    if(q==3)b-=x;
  }
  cout<<-b<<" "<<a<<endl;


}



Measured memory_bytes: 3212
# AOJ 1043: Selecting Teams Advanced to Regional
# Python3 2018.7.6 bal4u

def pr(i, u):
    global total
    print(team[i][0])
    total, affi[u] = total + 1, affi[u] + 1


while True:
    n = int(input())
    if n == 0: break
    team = [list(map(int, input().split())) for i in range(n)]
    team.sort(key=lambda x: (-x[2], x[3], x[0]))
    total, affi = 0, [0] * 1002
    for i in range(n):
        u = team[i][1]
        if   total < 10 and affi[u] < 3: pr(i, u)
        elif total < 20 and affi[u] < 2: pr(i, u)
        elif total < 26 and affi[u] < 1: pr(i, u)



Measured memory_bytes: 5624
# -*- coding: utf-8 -*-
import sys
import math
#import fractions

n = int(input())
#tmp = input().split()
#n,m,k = list(map(lambda a: int(a), tmp))

total=0
for i in range(1,n+1):
	for j in range(1,n+1):
		tmp=math.gcd(i,j)
		for k in range(1,n+1):
			total+=math.gcd(tmp,k)
print(total)

Measured memory_bytes: 9184
#include <stdio.h>

using namespace std;

int main() {
	int a, b;
	double a_d, b_d;
	scanf("%d %d", &a, &b);
	a_d = static_cast<double>(a);
	b_d = static_cast<double>(b);
	printf("%d %d %.5f\n", a / b, a % b, a_d / b_d);
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  string s, res = "";
  cin >> s;

  REP(i, s.length()) {
    if(s[i] == '0') {
      res += '0';
    } else if(s[i] == '1') {
      res += '1';
    } else {
      if(res.length() != 0) {
        res.erase(res.length() - 1);
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y = list(map(int,input().split()))
out = 10**9
L = []
L.append(A*X+B*Y)
L.append(C*2*max(X,Y))
if X<Y:
    L.append(C*2*X+B*(Y-X))
if X>Y:
    L.append(C*2*Y+A*(X-Y))
print(min(L))


Measured memory_bytes: 61844
k, _ = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
a.push(a[0] + k)
res = k
a.each_cons(2) do |i, j|
  res = k - (j - i) if k - (j - i) < res
end
puts res

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

const ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

int x, y, e;

vector<vector<int>>G;//グラフの隣接リスト表現

vector<int>match;//マッチングのペア

vector<bool>used;//同一頂点を始点としたDFSを行わないようにする

				 //uとvを結ぶ辺をグラフに追加する

void add_edge(int u, int v) {

	G[u].push_back(v);

	G[v].push_back(u);

}

//増加パスをDFSで探す

bool bi_dfs(int v) {

	used[v] = true;

	for (int i = 0; i<G[v].size(); i++) {

		int u = G[v][i], w = match[u];

		if (w < 0) {

			match[v] = u;

			match[u] = v;

			return true;

		}

		else if (used[w] == false) {

			if (bi_dfs(w)) {

				match[v] = u;

				match[u] = v;

				return true;

			}

		}

	}

	return false;

}

//二部グラフの最大マッチングを求める

int bipartitea_matching() {

	int res = 0;

	fill(match.begin(), match.end(), -1);

	for (int v = 0; v<x + y; v++) {

		if (match[v]<0) {//頂点vのマッチングのペアが現時点でない場合

			fill(used.begin(), used.end(), false);

			if (bi_dfs(v)) {

				res++;

			}

		}

	}

	return res;

}



signed main() {
	ll n;
	vector<pair<ll, ll>> v1, v2;

	cin >> n;

	x = n;
	y = n;

	G.resize(x + y);

	match.resize(x + y);

	used.resize(x + y);

	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		v1.push_back(make_pair(a, b));
	}

	REP(i, n) {
		ll c, d;
		cin >> c >> d;
		v2.push_back(make_pair(c, d));
	}

	REP(i, n) {
		REP(j, n) {
			if (v1[i].first < v2[j].first && v1[i].second < v2[j].second) {
				add_edge(i, j + n);
			}
		}
	}

	cout << bipartitea_matching() << endl;

	return 0;

}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  int a, b;
  vector<int> bridge(n, 0);
  for(int i=0; i<m; i++){
    cin >> a >> b;
    a--; b--;
    bridge.at(a) += 1;
    bridge.at(b) += 1;
  }

  for(int i=0; i<n; i++){
    cout << bridge.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ll ans = 0;
		for (int j = 1; j <= 100; j++) {
			if (j * j + 2 * j + 3 > i)break;
			for (int k = 1; k <= 100; k++) {
				if (j * j + k * k + j * k + j + k + 1 > i)break;
				for (int l = 1; l <= 100; l++) {
					if (j * j + k * k + l * l + j * k + k * l + l * j > i)break;
					if (j * j + k * k + l * l + j * k + k * l + l * j == i)ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3560
use std::cmp::min;

macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: i32,
    x: [i32; n],
  }
  let mut ans = 1_000_000_000;
  for p in 1..101 {
    let mut sum = 0;
    for x in x.iter() {
      sum += (x - p) * (x - p);
    }
    ans = min(ans, sum);
  }
  println!("{}", ans);
}


Measured memory_bytes: 2068
N, M = gets.chomp.split.map(&:to_i)
H  = gets.chomp.split

dropOutList = Hash.new

M.times do
  A, B = gets.chomp.split.map(&:to_i)
  if (H[A-1].to_i >= H[B-1].to_i)
  	dropOutList[B] = true
  end	
  if (H[A-1].to_i <= H[B-1].to_i)
  	dropOutList[A] = true
  end
end

print N - dropOutList.length

Measured memory_bytes: 44896
NUM=int(input())

for sect in range(NUM):
    n,k=list(map(int,input().strip().split()))
    x=list(map(int,input().strip().split()))
    x.sort()
    diff=[]
    
    for i in range(1,len(x)):
        diff.append(x[i]-x[i-1])
    diff.sort(reverse=True)

    s=sum(diff[:k-1])

    print(max(x)-min(x)-s)


Measured memory_bytes: 21304
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;

	char s[100];

	while (scanf("%s", s) != EOF) {
		if ( s[0] == '+' ) {
			a = pop();
			b = pop();

			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();

			push(a - b);
		}
		else if ( s[0] == '*' ) {
			a = pop();
			b = pop();

			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}

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

	return 0;
}


Measured memory_bytes: 2732
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf = 1e14;

class min_cost_flow{
private:
    int N;
    struct edge{int to; ll cap,cost; int rev;};
    vector<vector<edge>> G;
    vector<ll> h,dist,prevv,preve;
public:
    min_cost_flow(int n){
        N = n;
        G = vector<vector<edge>>(N);
        h = dist = prevv = preve = vector<ll>(N,0);
    }
    void add_edge(int from,int to,ll cap,ll cost){
        G[from].push_back((edge){to,cap,cost,(int) G[to].size()});
        G[to].push_back((edge){from,0,-cost,(int) G[from].size()-1});
    }
    ll answer(int s,int t,ll f){
        ll res = 0;
        fill(h.begin(),h.end(),0);
        while(f>0){
            priority_queue<P,vector<P>,greater<P>> Q;
            fill(dist.begin(),dist.end(),inf);
            dist[s] = 0;
            Q.push(P(0,s));
            while(!Q.empty()){
                P p = Q.top(); Q.pop();
                int v = p.second;
                if(dist[v]<p.first) continue;
                for(int i=0;i<G[v].size();i++){
                    edge &e = G[v][i];
                    if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                        dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        Q.push(P(dist[e.to],e.to));
                    }
                }
            }
            if(dist[t]==inf) return -1;
            for(int v=0;v<N;v++) h[v] += dist[v];
            ll d = f;
            for(int v=t;v!=s; v=prevv[v]){
                d = min(d,G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d*h[t];
            for(int v=t;v!=s;v=prevv[v]){
                edge &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

struct edge{
    ll a,b,d,c;
};

int main(){
    int N,M,S,T;
    cin >> N >> M >> S >> T;
    S--; T--;
    vector<vector<ll>> g(N,vector<ll>(N,inf));
    vector<edge> edges(M);
    for(int i=0;i<M;i++){
        ll a,b,c,d;
        cin >> a >> b >> d >> c;
        a--; b--;
        edges[i] = {a,b,d,c};
        g[a][b] = d;
    }
    for(int k=0;k<N;k++) for(int i=0;i<N;i++) for(int j=0;j<N;j++){
        g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
    }
    ll D = g[S][T];
    min_cost_flow flow(N+2);
    vector<ll> b(N,0);
    ll uinf = 10000;
    ll ans = -uinf*(D+1);
    b[S] += uinf;
    b[T] -= uinf;
    flow.add_edge(S,T,uinf,D+1);
    for(auto& e:edges){
        flow.add_edge(e.a,e.b,e.c,e.d);
/*        b[e.b] -= uinf;
        b[e.a] += uinf;
        ans += -e.d*uinf;
        flow.add_edge(e.a,e.b,uinf-e.c,e.d);*/
    }
    ll sum = 0;
    for(int i=0;i<N;i++){
        //cerr << i << " " << b[i] << endl;
        if(b[i]>0) flow.add_edge(N,i,b[i],0);
        if(b[i]<0) flow.add_edge(i,N+1,-b[i],0);
        sum += max(b[i],0LL);
    }
    cout << -ans-flow.answer(N,N+1,sum) << endl;
}


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

typedef pair<int,int> P;

int main(){
  int data[3][3];
  bool A[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data[i][j];
      A[i][j]=false;
    }
  }
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if(data[i][j]==a) A[i][j]=true;
      }
    }
  }
  string ans="No";
  for(int i=0; i<3; i++){
    if(A[i][0]&&A[i][1]&&A[i][2]) ans = "Yes";
    if(A[0][i]&&A[1][i]&&A[2][i]) ans = "Yes";
  }
  if(A[0][0]&&A[1][1]&&A[2][2]) ans = "Yes";
  if(A[0][2]&&A[1][1]&&A[2][0]) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  int i,j = 0,k,reset = 0;
  char s[11];
  
  scanf("%s",s);
  
  for(i = 0;i < strlen(s);i++){
    if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
      j++;
    }else
      reset = 1;
    if(j > k)
      k = j;
    if(reset){
      j = 0;
      reset = 0;
    }
  }
 
  printf("%d",k);
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
*p,=map(int,input().split())
p=[z-1 for z in p]
es=[[] for _ in range(n)]
for _ in range(m):
    x,y=map(int,input().split())
    es[x-1].append(y-1)
    es[y-1].append(x-1)

group=[-1]*n
last=-1
for i in range(n):
    if group[i]==-1:
        last+=1
        group[i]=last
        stack=[i]
        while stack:
            j=stack.pop()
            for e in es[j]:
                if group[e]==-1:
                    stack.append(e)
                    group[e]=last
groupset=set(group)
group1=[[] for g in groupset]
group2=[[] for g in groupset]

for i in range(n):
    group1[group[i]].append(i)
    group2[group[i]].append(p[i])

ans=0
for g in groupset:
    ans+=len(set(group1[g])&set(group2[g]))
print(ans)

Measured memory_bytes: 139092
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int ka[2145140],inv[2145140];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
int calc( int x, int y ){
	int ans = comb(x+y+2,y+1) - 1 + inf;
	return ans%inf;
}
signed main(){
	setkaijo(2100000);
	setinv(2100000);
	int r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	int ans = calc(r2,c2) - calc(r2,c1-1) - calc(r1-1,c2) + calc(r1-1,c1-1) + inf + inf;
	ans %= inf;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 33408
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
    long long n;
    cin >> n;
    long long min = (long long)1e15+5;
    for(int i = 0; i < 5; i++){
        long long x;
        cin >> x;
        if(min > x) min = x;
    }
    cout << (n-1)/min + 5 << endl;
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<P> task(n);
  rep(i,n)  cin >> task[i].second >> task[i].first;
  
  sort(task.begin(),task.end());
  
  ll time = 0;
  rep(i,n){
    time += task[i].second;
    if(time>task[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
char s[20];
int main() {
//	freopen("1.txt","r",stdin);
	scanf("%s",s);
	int n=strlen(s),cnt=0;
	int ans=1;
	if (s[0]!='A') ans=0;
	for (int i=1;i<n;i++)
		if (s[i]=='C'&&i!=n-1&&i!=1) cnt++;
		else if ('a'<=s[i]&&s[i]<='z'); else ans=0;
	if (cnt!=1) ans=0;
	if (ans) printf("AC\n"); else printf("WA\n");
	return 0;
}

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

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

int main() {
  int K;
  int count = 0;
  cin >> K;
  for (int i = 1; i < K + 1; i++) {
    for (int j = 1; j < K + 1; j++) {
      for (int q = 1; q < K + 1; q++) {
        count += gcd(gcd(i, j), q);
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3592