akhauriyash/Code-Regression huggingface dataset:
def solve(placed, w1, w2):
  global weight, D
  n = len(N) - len(placed)
  x = list(set(N) - set(placed))
  if x == []:
    if weight > w1:
      D = placed
      weight = w1
    return
   
  for e in x:
    w = Food[0][e]
    if w2 > Food[1][e]: return
    a = w1 + w * n
    if a > weight: return
    b = w2 + w
    solve(placed+[e], a, b)
  return
 
while 1:
  n = input()
  if n==0: break
  Food = {}
  weight = 1e9
  N = range(n)
  x = []
  for i in N:
    a = raw_input().split()
    x.append(map(int, a[1:])+[a[0]])
  Food = zip(*sorted(x))
  solve([], 0, 0)
  for e in D[::-1]:
    print Food[2][e]

Measured memory_bytes: 4288
#include <iostream>

using namespace std;

int main(void) {
	int N,M,K;
	cin >> N >> M >> K;
	bool find = false;
	for (int i = 0; !find && i < N+1; ++i) {
		for (int j = 0; !find && j < M+1; ++j) {
			int count = (i*(M-j)) + (j*(N-i));
			if (count == K) {
				find = true;
			}
		}
	}

	if (find) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

long long pt[100005] = {0};
int step[100005] = { 0 };
int main()
{
	int n,m;
	cin >> n>>m;
	for (int i = 1; i <= m; i++) {
		int k;
		cin >> k;
		step[k] = 1;
	}
	pt[0] = 1;
	for (int i = 0; i <= n-1; i++) {
		if (step[i + 1] == 0)pt[i + 1] += pt[i];
		if (step[i + 2] == 0)pt[i + 2] += pt[i];
		pt[i + 1] %= 1000000007;
		pt[i + 2] %= 1000000007;
	}
	cout << pt[n]<<endl;
}

Measured memory_bytes: 1408
class SegTree:
    def __init__(self, a, func):
        self.n = 2**(len(a) - 1).bit_length()
        self.f = func
        self.d = [0] * (2 * self.n - 1)
        self.d[self.n - 1:self.n - 1 + len(a)] = a
        for i in reversed(range(self.n - 1)):
            self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])

    def update(self, i, v):
        i += self.n - 1
        self.d[i] = v
        while i:
            i = (i - 1) // 2
            self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])

    def query(self, l, r):
        assert l <= r
        l += self.n
        r += self.n
        s = self.d[l - 1]
        while l < r:
            if l & 1:
                s = self.f(s, self.d[l - 1])
                l += 1
            if r & 1:
                r -= 1
                s = self.f(s, self.d[r - 1])
            l //= 2
            r //= 2
        return s

def main():
    N = int(input())
    H = list(map(int, input().split()))
    A = list(map(int, input().split()))
    S = SegTree([0] * N, max)

    for h, a in zip(H, A):
        S.update(h - 1, S.query(0, h - 1) + a)
    return S.query(0, N)

print(main())


Measured memory_bytes: 119872
#include <iostream>
 using namespace std;
 int main(){ 
char a,b; 
cin>>a>>b; 
if((a=='H')&&(b=='H')) { 
cout<<"H"; 
} 
if((a=='D')&&(b=='D')){ 
cout<<"H"; 
}
 if(((a=='H')&&(b=='D'))|| ((a=='D')&&(b=='H'))){
 cout<<"D"; 
} }

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ff(i,a,b) for(int i = a; i < b; i++)
#define fb(i,a,b) for(int i = a; i > b; i--)
#define MOD 1000000007


ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}



/*void solve(){
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	int x[3];
	x[0]=a; x[1]=b; x[2]=c;
	sort(x,x+3);
	//cout<<x[0]<<" "<<x[1]<<" "<<x[2];
	int m=n/x[0];
	fb(i,m,-1){
		ff(j,0,n/x[1]+1){
			ff(k,0,n/x[2]+1){
				//cout<<x[0]*i+x[1]*j+x[3]*k<<"\n";
				if(((x[0])*i+(x[1])*j+(x[3])*k)==n){
					cout<<(i+j+k)<<"\n";
					return;
				}
			}
		}
	}
}*/

void solve(){
	int n;
	cin>>n;
	int a[n];
	ff(i,0,n) cin>>a[i];
	sort(a,a+n);
	int sum;
	ll count=0;
	ff(i,0,n){
		ff(j,i+1,n){
			sum=a[i]+a[j];
			if(a[i]!=a[j])
			ff(k,j+1,n){
				if(sum>a[k]&&a[i]!=a[k]&&a[j]!=a[k]) count++;
				if(sum<=a[k]) break;
			}
		}
		//cout<<"x";
	}
	cout<<count;
}


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

	//int t;
    //cin>>t;
	//while(t--)
		solve();
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3784
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;


int main(void){
  
  int N,M,ans=0;
  vector<int> A;

  
  
  cin >> N >> M;

  for(int i = 0; i < M ;i++){
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }

  ans = N;

  for(int i = 0; i < M ;i++){
    ans = ans - A.at(i);
  }

  if(ans <0){
    ans =-1;
  }

  cout << ans << endl;
  

  return 0;
}




Measured memory_bytes: 3704
#include<iostream>
using namespace std;
int main(){
    int N;
    string S,T;
    cin >> N;
    cin >> S >> T;
    string ans;
    for(int i=0;i<N;i++){
        ans += S.at(i);
        ans += T.at(i);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  string S;
  cin >> S;
  string s1 = "", s2;
  for (int i = 0; i < S.size(); i++)
  {
    if (S.at(i) != 'x')
      s1 = s1 + S.at(i);
  }
  s2 = s1;
  reverse(s1.begin(), s1.end());
  if (s1 != s2)
  {
    cout << -1 << endl;
    return 0;
  }
  int64_t l = 0, r = S.size() - 1, cnt = 0;
  while (l < r)
  {
    if (S.at(l) == S.at(r))
    {
      l++;
      r--;
    }
    else
    {
      if (S.at(l) == 'x')
        l++;
      else
        r--;
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

const int mod = 998244353;

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) { return po(x, mod - 2); }
int fact[10002], invf[10002];

int comb(int n, int k) {
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}

string A, B;
int m, e;
int dp[10002][10002];

int main() {
    fact[0] = 1;
    for(int i = 1; i < 10002; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < 10002; i++) {
        invf[i] = inv(fact[i]);
    }

    cin >> A >> B;

    m = 0, e = 0;
    for(int i = 0; i < A.size(); i++) {
        if(A[i] == '1' && B[i] == '1') m++;
        else if(A[i] == '1') e++;
    }

    for(int i = 0; i <= m; i++) {
        for(int j = 0; j <= e; j++) {
            if(i == 0 && j == 0) {
                dp[i][j] = 1;
                continue;
            }
            if(i && j) {
                dp[i][j] += 1LL * i * j % mod * dp[i - 1][j] % mod;
                dp[i][j] %= mod;
            }
            if(j) {
                dp[i][j] += 1LL * j * j % mod * dp[i][j - 1] % mod;
                dp[i][j] %= mod;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= m; i++) {
        ans += 1LL * comb(m, i) * comb(m + e, i) % mod * fact[i] % mod * fact[i] % mod * dp[m - i][e] % mod;
        ans %= mod;
    }
    cout << ans;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<int> k(m);
    vector<vector<int> > S(m);
    vector<int> p(m);
    for(int i = 0; i < m; i++) {
        cin >> k[i];
        S[i].resize(k[i]);
        for(int j = 0; j < k[i]; j++) {
            cin >> S[i][j];
            S[i][j]--;
        }
    }
    for(int i = 0; i < m; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++) {
        int cnt = 0;
        for(int i = 0; i < m; i++) {
            int c = 0;
            for(auto j : S[i]) {
                if(bit & (1 << j)) c++; 
            }
            int judge = c % 2;
            if(p[i] == judge) cnt++;
        }
        if(cnt == m) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

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

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

int main(){
    ll n;
    cin >> n;
    ll x,y;
    rep(i,n){
        ll t,a;
        cin >> t >> a;
        if(i==0){
            x=t; y=a;
        }
        else{
            ll p=1,q=1;
            if(t<x) p=(x-1)/t+1;
            if(a<y) q=(y-1)/a+1;
            ll k=max(p,q);
            x=k*t;
            y=k*a;
        }
    }
    cout << x+y << endl;
    return 0;
}

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

int main() {
  char C;
  cin >> C;
  if (C=='a') cout << 'b' << endl;
  if (C=='b') cout << 'c' << endl;
  if (C=='c') cout << 'd' << endl;
  if (C=='d') cout << 'e' << endl;
  if (C=='e') cout << 'f' << endl;
  if (C=='f') cout << 'g' << endl;
  if (C=='g') cout << 'h' << endl;
  if (C=='h') cout << 'i' << endl;
  if (C=='i') cout << 'j' << endl;
  if (C=='j') cout << 'k' << endl;
  if (C=='k') cout << 'l' << endl;
  if (C=='l') cout << 'm' << endl;
  if (C=='m') cout << 'n' << endl;
  if (C=='n') cout << 'o' << endl;
  if (C=='o') cout << 'p' << endl;
  if (C=='p') cout << 'q' << endl;
  if (C=='q') cout << 'r' << endl;
  if (C=='r') cout << 's' << endl;
  if (C=='s') cout << 't' << endl;
  if (C=='t') cout << 'u' << endl;
  if (C=='u') cout << 'v' << endl;
  if (C=='v') cout << 'w' << endl;
  if (C=='w') cout << 'x' << endl;
  if (C=='x') cout << 'y' << endl;
  if (C=='y') cout << 'z' << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
deque < l > ans;
l ans2=0;
int num[100005],a,b,c;
int main()
{
	int n,k;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		num[a]++;
		ans2+=a;
	}
	cin>>k;
	for(int i=0;i<k;i++)
	{
		cin>>b>>c;
		l o=num[b]*(c-b);
		ans2+=o;
		ans.push_back(ans2);
		num[c]+=num[b];
		num[b]=0;
	}
	for(int i=0;i<k;i++)
		cout<<ans[i]<<endl;
	return 0;
}

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

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int c = Integer.parseInt(in.next());
            int d = Integer.parseInt(in.next());
            int ans = Math.max(0, Math.min(b, d) - Math.max(a, c));

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 5001;

int n, A, B, cnt[N];
ll dp[N][N];
vector <int> a;

ll solve(int idx, int j){
    if(idx == n) return 0;
    ll &ret = dp[idx][j];
    if(ret != -1) return ret;
    if(a[idx] == j) return solve(idx + 1, j + 1);
    if(a[idx] < j) return solve(idx + 1, j);
    if(cnt[j]) return solve(idx, j + 1);
    ret = solve(idx, j + 1) + B;
    cnt[a[idx]]++;
    ret = min(ret, solve(idx + 1, j) + A);
    cnt[a[idx]]--;
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n >> A >> B;
    a.resize(n);
    for(auto &i : a) cin >> i;
    cout << solve(0, 1) << endl;
}


Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
#define vi vector<int>
#define vvi vector<vector<int>>
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    int ans = 0,r=0,g=0,b=0;
    rep(i,0,n){
        if(s[i]=='R'){r++;}
        else if(s[i]=='G'){g++;}
        else{b++;}
    }
    ans+=r*b*g;
    rep(i,0,n){
        rep(j,1,n/2+1){
            if(i+2*j<n){
                if(s[i]!=s[i+j]&&s[i+j]!=s[i+2*j]&&s[i+2*j]!=s[i]){ans--;}
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3660
import sys
sys.setrecursionlimit(10**9)

def solve():
    N = int(input())
    adjL = [[] for _ in range(N)]
    edges = []
    for _ in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        adjL[a].append(b)
        adjL[b].append(a)
        if a > b:
            a, b = b, a
        edges.append((a, b))
    M = int(input())
    uvs = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(M)]

    def getPath(vSt, vEn):
        def dfs(vNow, vPar):
            if vNow == vEn:
                path.append(vNow)
                return True
            for v2 in adjL[vNow]:
                if v2 != vPar:
                    if dfs(v2, vNow):
                        path.append(vNow)
                        return True
        path = []
        dfs(vSt, -1)
        return path

    edgeConstraints = []
    for u, v in uvs:
        path = getPath(u, v)
        setEdge = set()
        for j in range(len(path)-1):
            a, b = path[j], path[j+1]
            if a > b:
                a, b = b, a
            setEdge.add((a, b))
        edge = 0
        for j, (a, b) in enumerate(edges):
            if (a, b) in setEdge:
                edge |= 1<<j
        edgeConstraints.append(edge)

    numEs = []
    for S in range(1<<M):
        edge = 0
        for i, edgeConstraint in enumerate(edgeConstraints):
            if (S>>i) & 1:
                edge |= edgeConstraint
        numE = bin(edge).count('1')
        numEs.append(numE)

    pow2s = [1]
    for i in range(N):
        pow2s.append(pow2s[-1]*2)

    ans = 0
    for S, numE in enumerate(numEs[1:], 1):
        num1 = bin(S).count('1')
        if num1 % 2:
            ans += pow2s[N-1-numE]
        else:
            ans -= pow2s[N-1-numE]

    print(pow2s[N-1] - ans)


solve()


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

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	string s = read_item();
	if(*s.rbegin() == 's') {
		s = s + "es";
	} else {
		s = s + "s";
	}

	printf("%s\n", s.c_str());

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 3632
import itertools
N,M=map(int,input().split())
edges=set()
for _ in range(M):
  a,b=map(int,input().split())
  edges.add((a,b))
  edges.add((b,a))
  
  
answer=0


for p in itertools.permutations(range(1,N+1)):
  if p[0] !=1:
    continue
  bl=True
  for i in range(N-1):
    if (p[i],p[i+1]) not in edges:
      bl =False
      
  if bl:
    answer +=1
    
    
print(answer)

Measured memory_bytes: 3064
/**
*    created: 20.06.2020 02:55:43
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.rbegin(),p.rend());
    int sum = 0;
    rep(i,n) {
        if (i == 0) sum += p[i] / 2;
        else sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

#define MAX_DEPTH  (50000)

long long leaf[MAX_DEPTH];

// テヲツ慊ィテ」ツつ津・ツ?催・ツクツーテァツ堋?」ツ?ォテァツ板淌ヲツ按静」ツ?凖」ツつ凝」ツつ、テ」ツδ。テ」ツδシテ」ツつクテ」ツつ津」ツ?療」ツ?ヲテ」ツ??」ツ?敕」ツ?ョテ」ツ?ィテ」ツ?催ヲツウツィテァツ崢ョテ」ツ?凖」ツつ凝ィツ堕嘉」ツ?ョテヲツキツアテ」ツ?陛」ツつ津ィツィツ佚ゥツ個イ
// テ・ツ青古」ツ?佚ヲツキツアテ」ツ?陛」ツ?ァテ」ツ?づ」ツつ古」ツ?ーテァツコツ湘」ツつ?」ツつ嘉」ツつ古」ツつ凝」ツ?ョテ」ツ?ァテ」ツ??ヲツキツアテ」ツ?陛ヲツッツ偲」ツ?ォ nC2 テ」ツつ津ァツョツ療・ツ?コテ」ツ?療」ツ?淌ァツキツ湘・ツ陳古」ツつ津ヲツアツづ」ツつ?」ツつ古」ツ?ーテ」ツつ暗」ツ??
int main() {
  
  string s;
  int size;
  
  cin >> s; size = s.size();
  
  int depth = -1;
  
  for(int i=0; i<size; i++) {
    if(s[i] == '(') leaf[++depth] ++;
    else {
      leaf[--depth] ++;
    }
  }
  
  long long ans = 0;
  for(int i=0; leaf[i]>0; i++) {
    ans += (leaf[i]*(leaf[i]-1))/2;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

const int maxn = 200005;
int n, m, a[maxn], x[maxn], id[maxn], ans[maxn], sum[maxn];
vector<int> v;

bool cmp(int p, int q)
{
	return x[p] < x[q];
}

int main()
{
	int fst, sec;
	scanf("%d%d%d", &n, &fst, &sec);
	int base = fst - sec, ma = 0;
	n -= 2;
	for (int i = 1; i < n; i++)
		scanf("%d", a + i), sum[i] = sum[i - 1] + a[i], ma = max(ma, a[i]);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++)
		scanf("%d", x + i), id[i] = i;
	sort(id + 1, id + 1 + m, cmp);
	for (int i = ma; i >= 0; i--)
		v.push_back(i);
	for (int i = 1, j = 1; i <= m; i++)
	{
		if (x[id[i]] >= sum[n - 1])
			ans[id[i]] = x[id[i]] - sum[n - 1];
		else
		{
			while (sum[n - 1] - sum[j - 1] > x[id[i]])
			{
				int s = (int)v.size();
				for (int k = 1; k <= a[j]; k++)
					v.push_back(v[s - 1 - k]);
				j++;
			}
			ans[id[i]] = v[v.size() - 1 - (x[id[i]] - (sum[n - 1] - sum[j - 1]))];
		}
	}
	for (int i = 1; i <= m; i++)
		printf("%d\n", base + ans[i]);
	return 0;
}


Measured memory_bytes: 13544
#include<iostream>
#include<string.h>
using namespace std;

int main(){
    int n,m,b,d,i;
    while(cin>>n>>m,n){
        bool a[1001]={0};
        b=n-1;
        for(i=n;i>1;i--){
            d=m;
            while(d>0){
                b=(b+1)%n;
                if(!a[b])d--;
            }
            a[b]=1;
        }
        for(i=0;i<n;i++)
            if(!a[i]){
                cout<<i+1<<endl;
                break;
            }
    }
}

Measured memory_bytes: 1160
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

import bisect

ans = 0
for b in B:
  k = bisect.bisect_left(A, b)
  l = bisect.bisect_right(C, b)
  ans += k * (N -l)
print(ans)
  
  
  
  

Measured memory_bytes: 107108
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)


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

int N;
int p[110];
int ans[110] = {};

int main()
{
	cin >> N;
	REP(i, N) {
		cin >> p[i];
		for (int j = 0; j <= p[i]; j++) {
			ans[j]++;
		}
	}
	for (int i = 100; i >= 0; i--) {
		if (ans[i] >= i) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,k;
	cin>>n>>k;

	if(k==1)cout<<"0"<<endl;
	else cout<<n-k<<endl;
	return 0;

}


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

using namespace std;

int main() {
  string N;
  cin >> N;
  char c = N.back();
  if (c == '2' || c == '4' || c == '5' || c == '7' || c == '9') {
    cout << "hon" << endl;
  } else if (c == '3') {
    cout << "bon" << endl;
  } else {
    cout << "pon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let N:usize = read_line().parse::<usize>().unwrap();
    let mut A:Vec<i64> = read_line().split_whitespace().map(|x|x.parse::<i64>().unwrap()).collect::<Vec<i64>>();
    A.sort();
    A.reverse();
    let mut alice = 0;
    let mut bob = 0;
    for i in 0..N {
        if i % 2 == 0 {
            alice+=A[i];
        }else{
            bob+=A[i];
        }
    }
    println!("{}",alice-bob);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



int main(){

  int h,w;
  cin >> h >> w;
  int a[h][w];
  rep(i,h){
    rep(j,w) cin>>a[i][j];
  }
  vector<pair<int, int> > a_from;
  vector<pair<int, int> > a_to;
  rep(i,w-1){
    rep(j,h){
      if(a[j][i]%2==0) continue;
      else{
	a[j][i+1]++;
	a_from.pb(mp(j,i));
	a_to.pb(mp(j,i+1));
      }
    }
  }
  rep(j,h-1){
    if(a[j][w-1]%2==0) continue;
    else{
      a[j+1][w-1]++;
      a_from.pb(mp(j,w-1));
      a_to.pb(mp(j+1,w-1));
    }
  }
  cout << a_to.size() << endl;
  rep(i,a_to.size()){
    cout << a_from[i].first+1 << " " << a_from[i].second+1 << " " << a_to[i].first+1 << " " <<a_to[i].second+1 << endl;
  }
  
  
  
  
  return 0;

}


Measured memory_bytes: 5228
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n, m;
  scan(n, m);
  string s;
  if (n == m) {
    s = "Yes\n";
  } else {
    s = "No\n";
  }
  cout << s;
  return 0;
}


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

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

    vector<string> vc;

    int sl = s.length();
    for (int i = 0; i < sl; i++) {
        for (int j = 1; j <= min(k, sl - i); j++) {
            vc.push_back(s.substr(i, j));
        }
    }

    sort(vc.begin(), vc.end());
    vc.erase(unique(vc.begin(), vc.end()), vc.end());
    cout << vc[k-1] << "\n";
    
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;
    public class Main {// Main
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int[] a = new int[3];
            for(int i=0;i<3;i++) a[i] = sc.nextInt();
            Arrays.sort(a);
            int ans = a[0] + a[1];
            System.out.println(ans);
        }
    }							

Measured memory_bytes: 22868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int m = int.Parse(Console.ReadLine());
            char[] str = Console.ReadLine().ToCharArray();
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] != str[n-1]) str[i] = '*';
            }

            Console.WriteLine(new string(str.ToArray()));


        }
        
    }
}


Measured memory_bytes: 13268
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;
import java.lang.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		if (a.charAt(a.length() - 1) == b.charAt(0) && b.charAt(b.length() - 1) == c.charAt(0)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a == b && b == c ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[9],t[9];
int main(){
	scanf("%s%s",s,t);
	puts(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]?"YES":"NO");
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class Main {

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	TreeSet<String> ts;
	
	public void run() throws Exception {
		FastIO file = new FastIO();
		ts = new TreeSet<>();
		permute("ABCDE".toCharArray(), 0);
		int[] a = new int[5];
		for(int i = 0; i < 5; i++) {
			a[i] = file.nextInt();
		}
		int ans = Integer.MAX_VALUE;
		for (String s : ts) {
			int time = 0;
			for (char c : s.toCharArray()) {
				if (time % 10 != 0) {
					time += 10 - time % 10;
				}
				time += a[c - 'A'];
			}
			ans = Math.min(ans, time);
		}
		System.out.println(ans);
	}

	void permute(char[] c, int x) {
		if (x == 5) {
			ts.add(String.valueOf(c));
		}
		else {
			for (int i = 0; i < 5; i++) {
				if (i != x) {
					char temp = c[i];
					c[i] = c[x];
					c[x] = temp;
					permute(c.clone(), x + 1);
					temp = c[i];
					c[i] = c[x];
					c[x] = temp;
				}
			}
		}
	}
	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

		public FastIO() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, p / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, p / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}


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

ll dsum(ll n){
ll k =0;
while(n>0){
    k+=n%10;
    n/=10;
}
return k;
}
int main() {

    ll n;
    cin>>n;
    ll k =dsum(n);
    if(n%k==0)cout<<"Yes";
    else cout<<"No";

 return 0;
}


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

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

    static class ANumberOfMultiples {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int l = in.readInt(), r = in.readInt(), d = in.readInt();
            int ans = 0;
            for (int i = l; i <= r; i++)
                if (i % d == 0)
                    ans++;

            System.out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 32272
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    ca,sa,fa = list(map(int,input().split()))
    C[i] = ca
    S[i] = sa
    F[i] = fa
time = [0] * N
for i in range(N-1):
    t = C[i]+S[i]
    for j in range(i+1,N-1):
        if t<= S[j]:
            t = S[j]
        else:
            d = t - S[j]
            k = d // F[j]
            m = d % F[j]
            if m != 0:
                t = S[j] + (k+1) * F[j]
        t += C[j]
    time[i] = t
for i in range(N):
    print(time[i])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll cnt = 2;
    while(true) {
        if(a <= 0) {
            cout << "No";
            return 0;
        } else if(c <= 0) {
            cout << "Yes";
            return 0;
        }
        if(cnt % 2 == 0)
            c -= b;
        else
            a -= d;
        cnt++;
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, w, x, y, sum, pos, k, h[ohara];
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n;
    rep(i, n)
    {
        cin >> h[i];
    }
    while (1)
    {
        int ok = 1;
        rep(i, n)
        {
            if (h[i] != 0)
                ok = 0;
        }
        if (ok)
            break;
        int st = 0, en = n;
        while (1)
        {
            int judge = 1;
            rrep(i, st, n)
            {
                if (h[i] != 0)
                    judge = 0;
            }
            if (judge)
                break;
            rrep(i, st, en)
            {
                if (h[i] == 0)
                {
                    en = i;
                    break;
                }
            }
            ll mi = LINF;
            int tuuka = 0;
            rrep(i, st, en)
            {
                mi = min(mi, h[i]);
                tuuka = 1;
            }
            if (!tuuka)
                mi = 0;
            rrep(i, st, en)
            {
                h[i] -= mi;
            }
            //rep(i, n) cout << h[i] << " ";
            //cout << "\n";
            st = en + 1;
            en = n;
            ans += mi;
        }
        //Cout("aa");
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int MX = 1000000;
const long long mod = 1000000007;
long long mp(long long b, long long e) {
	long long a = 1;
	while (e) {
		if (e & 1) a = a * b % mod;
		b = b * b % mod;
		e >>= 1;
	}
	return a;
}
int main() {
	long long fac[2 * MX], inv[2 * MX], p25[MX + 1], p26[MX + 1];
	fac[0] = p25[0] = p26[0] = 1;
	for (int i = 1; i < 2 * MX; ++i) fac[i] = fac[i - 1] * i % mod;
	for (int i = 0; i < 2 * MX; ++i) inv[i] = mp(fac[i], mod - 2);
	for (int i = 1; i <= MX; ++i) p25[i] = p25[i - 1] * 25 % mod;
	for (int i = 1; i <= MX; ++i) p26[i] = p26[i - 1] * 26 % mod;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int K;
	string S;
	cin >> K >> S;
	long long ans = 0;
	for (int i = 0; i <= K; ++i) ans = (ans + fac[S.size() - 1 + i] * inv[S.size() - 1] % mod * inv[i] % mod * p25[i] % mod * p26[K - i] % mod) % mod;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 51048
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll M = 900000;
const ld X = 0.6;
const ld Y = 0.9999;
ll n;
ll x[55], y[55];
ld cx, cy;
ld now = X;

void f(ld p)
{
    ld mx = 0;
    ll mi = 0;
    for(ll i = 0; i < n; i++)
    {
        ld r = (cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]);
        if(mx < r) mx = r, mi = i;
    }
    cx += (x[mi] - cx) * p;
    cy += (y[mi] - cy) * p;
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &x[i], &y[i]);
        cx += x[i];
        cy += y[i];
    }
    cx /= n;
    cy /= n;
    for(ll i = 0; i < M; i++)
    {
        f(now);
        now *= Y;
    }
    ld ans = 0;
    for(ll i = 0; i < n; i++)
    {
        ld r = (cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]);
        ans = max(ans, r);
    }
    printf("%.12Lf", sqrt(ans));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
  string s;
  std::cin >> s;
  rep(i,s.length())std::cout << 'x' ;
  std::cout  << '\n';

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();

		char ch[] = new char[S.length()];

		int count = 0;

		for (int i = 0; i < S.length(); i++) {
			ch[i] = S.charAt(i);
		}

		for (int i = 0; i < S.length(); i++) {
			for (int j = i + 1; j < S.length(); j++) {
				if (ch[i] == ch[j]) {
					count++;
				}
			}
		}
		System.out.print(count == 2 ? "Yes" : "No");
	}
}


Measured memory_bytes: 21332
n = int(input())
s = input()
a = s[1:].count('E')
inf = float('inf')
ans = [inf]*n
ans[0] = a
for i in range(1,n):

    if s[i] == 'E':
        ans[i] = ans[i-1] - 1
    else:
        ans[i] = ans[i-1]

    if s[i-1] == 'W':
        ans[i] += 1
    else:
        continue

print(min(ans))



Measured memory_bytes: 15436
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    H, W = LI()
    maze = SR(H)

    ans = 0
    for h in range(H):
        for w in range(W):
            if maze[h][w] == '#':
                continue

            q = deque()
            q.append((0, h, w))

            visited = [[False] * W for _ in range(H)]
            visited[h][w] = True

            while q:
                dist, y, x = q.popleft()

                for dy, dx in dire:
                    if y + dy >= 0 and y + dy < H and x + dx >= 0 and x + dx < W:
                        if maze[y + dy][x + dx] == '.' and not visited[y + dy][x + dx]:
                            q.append((dist + 1, y + dy, x + dx))
                            visited[y + dy][x + dx] = True

            ans = max(ans, dist)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 79296
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const V = arg[1].split(" ").map(n=>~~n);
    const C = arg[2].split(" ").map(n=>~~n);
    
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        if(V[i] - C[i] < 0) {
            
        } else {
            answer += V[i] - C[i];
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 4e6+10;
const ll inf = 1e18;

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

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

int n,k;
ll dp[2010][2010],F[N], inv[N];

ll nCk(int n,int k){
	if(k>n)	return 0;
	return F[n]*inv[k]%mod*inv[n-k]%mod;
}

ll f(int i,int j){
	if(i==n && j==n)	return 1;
	ll &ret = dp[i][j];
	if(ret!=-1) return ret;
	ret = 0;
	if(i!=n){
		ret = f(i+1,j);
	}
	if(i>j){
		ret = (ret+ (n-j)*f(i,j+1)%mod*nCk(n*k-i-j*(k-1)-1,k-2))%mod;
		// printf("%d %d %lld\n",n*k-i-j*(k-1)-1,k-2,nCk(n*k-i-j*(k-1)-1,k-2));
	}
	return ret;
}


int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	scanf("%d %d",&n,&k);
	if(k==1){
		printf("1\n");return 0;
	}
	FILL(dp,-1);
	F[0] = inv[0] = 1;
	REPP(i,1,N) F[i] = F[i-1]*i%mod;
	inv[N-1] = power(F[N-1],mod-2);
	for(int i=N-2;i>=1;i--){
		inv[i] = inv[i+1]*(i+1)%mod;
		assert(inv[i]*F[i]%mod==1);
	}
	printf("%lld\n",f(0,0));
	return 0;
}




Measured memory_bytes: 94592
s = list(input())
without_x = []
notx_index = []
for i in range(len(s)):
	if s[i] != "x":
		without_x.append(s[i])
		notx_index.append(i)
if not without_x:
	print(0)
elif without_x != without_x[::-1]:
	print(-1)
else:
	n = len(notx_index)
	#center_ind = (n-1) // 2
	x_num = [notx_index[0]]
	for i in range(n-1):
		x_num.append(notx_index[i+1] - notx_index[i] - 1)
	x_num.append(len(s)-1 - notx_index[n-1])
	#print(x_num)
	ans = 0
	for i in range(n // 2 + 1):
		ans += abs(x_num[i] - x_num[n-i])

	print(ans)

Measured memory_bytes: 9428
function Main(input) {
    input = input.split("\n");
    var N =Number(input[0]);
    var inputA = input[1].split(' ').map(Number);
    var inputB = input[2].split(' ').map(Number);
    var inputC = input[3].split(' ').map(Number);
    var count = 0;
    for(var i=0; i < N;i++){
        count +=  inputB[ inputA[i] - 1 ] ;
            //if( inputA[i-1] === inputA[i] -1  ){
        if( inputA[i] === inputA[i-1]+1  ){
            //count += inputC[  inputA[i-1] -1 ];
            count += inputC[inputA[i] -2];
        }
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))
//Main(require("fs").readFileSync("data.txt", "utf8"))

Measured memory_bytes: 9420
#include<iostream>

using namespace std;

int main(void){
    int N, M;
    int L[100000];
    int R[100000];

    cin>>N;
    cin>>M;

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

    int max = R[0];
    int min = L[0];

    for(int i=1;i<M;i++){
        if(L[i]>min){
            min=L[i];
        }
        if(R[i]<max){
            max=R[i];
        }
    }

    int ans = max-min+1;
    if(ans<0){
        ans = 0;
    }

    

    cout<<ans<<endl;



}


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

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> cnt(N, 0);
	for(int i=0; i<Q; ++i){
	    int a;
	    cin >> a;
	    ++cnt[a-1];
	}
	for(int i=0; i<N; ++i){
	    if(Q-cnt[i]<K) cout << "Yes" << endl;
	    else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024