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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;cin>>n;
  std::vector<int> v(n);for (int i = 0; i < n; ++i)cin>>v[i];
  sort(All(v),greater<int>());
  int ans=0,x=v[0];
  for (int i = 1; i < n; ++i){
  	ans+=x-v[i];
  	x=v[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX_N = 100000;

void _main()
{
    vector<int> ks(MAX_N + 1, -1);
    for (int k = 2; k * (k - 1) / 2 <= MAX_N; ++k)
    {
        ks[k * (k - 1) / 2] = k;
    }

    int N;
    cin >> N;

    if (ks[N] == -1)
    {
        cout << "No" << endl;
        return;
    }

    const int k = ks[N];
    const int elementNum = k - 1;
    vector<vector<int>> a(elementNum, vector<int>(elementNum, -1));
    int num = 1;
    rep(i, 0, elementNum)
    {
        rep(j, 0, i + 1)
        {
            a[i][j] = num++;
        }
    }
    assert(num == N + 1);

    cout << "Yes" << endl;
    cout << k << endl;

    cout << elementNum << " ";
    rep(i, 0, elementNum) cout << a[i][i] << " ";
    cout << endl;

    cout << elementNum << " ";
    rep(i, 0, elementNum) cout << a[i][0] << " ";
    cout << endl;

    rep(i, 1, elementNum)
    {
        cout << elementNum << " ";
        rep(j, 0, i + 1)
        {
            cout << a[i][j] << " ";
        }
        rep(j, i + 1, elementNum)
        {
            cout << a[j][i] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 2560
def d_even_relation(N, Nodes):
    from collections import deque
    graph = [{} for _ in range(N)]
    for u, v, w in Nodes:
        graph[u - 1][v - 1] = w
        graph[v - 1][u - 1] = w

    distance_from_root = [0] * N  # 頂点1を根としたときの、各頂点への距離
    queue = deque([(-1, 0, 0)])  # 親の頂点番号、子の頂点番号、根から親までの距離
    while queue:
        parent, child, distance = queue.pop()
        if parent != -1:  # 今調べている頂点が根でない
            distance += (graph[parent][child] % 2)  # 偶奇だけわかればいい
            distance_from_root[child] = distance
        for k in graph[child].keys():
            if parent != k:  # 木を「逆戻り」しない頂点だけ調べる
                queue.appendleft((child, k, distance))
    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root)
    return '\n'.join(map(str, ans))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print(d_even_relation(N, Nodes))

Measured memory_bytes: 69364
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
long long INF = (long long)1E17;
#define i_7 (long long)(1E9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE = 200'010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
  invinit();
  using namespace std;
  long long n, a, b;
  cin>>n>>a>>b;
  long long ans = mod(po(2LL, n) - 1);
  long long ca = invkai[a];
  long long cb = invkai[b];
  for(long long i = 0; i < a; i++){
    ca *= (n - i);
    ca = mod(ca);
  }
  ans -= ca;
  ans = mod(ans);
  for(long long i = 0; i < b; i++){
    cb *= (n - i);
    cb = mod(cb);
  }
  ans -= cb;
  ans = mod(ans);
  cout<<ans<<endl;
  return 0;
}



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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n){
        if(a[i] == 1){
            ll cnt = 0;
            ll rem = i;
            while(0 < rem){
                rem -= k-1;
                cnt++;
            }
            rem += n-i-1;
            while(0 < rem){
                rem -= k-1;
                cnt++;
            }
            cout << cnt << endl;
            return 0;
        }
    }

    
    
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int p[N]; rep(i,N) cin >> p[i];
  string result = "YES";
  int count = 0;
  rep(i,N-1) {
    if (p[i]!=i+1) {
      if (count>=2||p[p[i]-1]!=i+1) result = "NO";
      count++;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string A;
    string B;
    string C;
    cin >> A >> B >> C;
    if(A.back() == B.front() && B.back() == C.front()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

front, back = [0], [0]
for a in A:
    front.append(gcd(front[-1], a))
front.append(0)
for a in A[::-1]:
    back.append(gcd(back[-1], a))
back = [0] + back[::-1]


ans = 0
for i in range(1, N + 1):
    ans = max(ans, gcd(front[i - 1], back[i + 1]))
print(ans)


Measured memory_bytes: 16700
import sys

def main():
    # res = []
    inps = map(lambda s: s.strip(), sys.stdin.readlines())
    iid = 0
    r, c, n = map(int, inps[iid].split())
    iid += 1

    def boundary(x,y):
        if x==0 or y==0 or x==r or y==c:
            return True
        return False

    def downright(x, y):
        if x==0 or y==c:
            return True
        return False


    points = []
    dr = []
    ul = []
    for i in xrange(1,n+1):
        x1, y1, x2, y2 = map(int, inps[iid].split())
        iid += 1
        if boundary(x1, y1) and boundary(x2, y2):
            if downright(x1,y1):
                dr.append((x1,y1,i))
            else:
                ul.append((x1,y1,i))
            if downright(x2,y2):
                dr.append((x2,y2,i))
            else:
                ul.append((x2,y2,i))
    dr.sort()
    ul.sort(reverse=True)
    dr.extend(ul)
    # print dr
    stack = []
    for elem in dr:
        if len(stack)!=0 and stack[-1]==elem[2]:
            stack.pop()
        else:
            stack.append(elem[2])
    if len(stack)==0:
        print "YES"
    else:
        print "NO"

    # print '\n'.join(res)
if __name__ == '__main__':
    main()

Measured memory_bytes: 111596
let () =
  let n, p = Scanf.scanf "%d %d\n" (fun n p -> n, p) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.fold_left (fun (odd, even) a ->
    if a mod 2 = 0 then (2 * odd, 2 * even)
    else (odd + even, odd + even)) (0, 1) as_
  |> (if p = 1 then fst else snd)
  |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define M 1000000007
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

using namespace std;
ll fac[200005];
ll power(ll x,ll y){
    ll t=1;
    while(y){
        if(y&1) t=(t*x)%M;
        y>>=1;
        x=(x*x)%M;
    }
    return t;
}
ll per(ll n,ll r){
    return (fac[n]*((power(fac[r],M-2)*power(fac[n-r],M-2))%M)%M);
}
void pre(){
    fac[0]=fac[1]=1;
    ll i=2;
    while(i<200003){
        fac[i]=(fac[i-1]*i)%M;
        i++;
    }
}
int main(){
    cs;
    pre();
    ll n,k,ans=0;
    cin>>n>>k;
    if(k>n-1) k=n-1;
    for(ll i=0;i<=k;i++) ans=(ans+per(n,i)*per(n-1,i))%M; 
    while(ans<0) ans+=M;
    cout<<ans;
}

Measured memory_bytes: 1792
N=int(input())
V=input().split()
C=input().split()
V=[int(i) for i in V]
C=[int(i) for i in C]
sum=0

for i in range(N):
    if 0<V[i]-C[i]:
        sum+=V[i]-C[i]
        
if sum<0:
    print(0)
else:
    print(sum)

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, h;
    int a[100000], b[100000];
    cin >> n >> h;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }

    vector<pair<int, int>> v, v2;
    for (int i = 0; i < n; i++)
    {
        v.push_back(make_pair(a[i], b[i]));
        v2.push_back(make_pair(b[i], a[i]));
    }
    sort(all(v));
    sort(all(v2));

    // for (int i = 0; i < n; i++)
    // cout << v2[i].first << "," << v2[i].second << endl;
    int fmx = v[n - 1].first;
    int smx = v[n - 1].second;
    bool use = false;
    int sum = 0;
    int cnt = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (v2[i].first > fmx && sum < h)
        {
            sum += v2[i].first;
            cnt++;
            /*
            if (v2[i].first != smx || use)
            {
                sum += v2[i].first;
                cnt++;
            }
            else
            {
                use = true;
            }
            */
            // cout << "*";
        }
        // cout << v2[i].first << endl;
    }

    // cout << "cnt=" << cnt << "," << sum << endl;

    if (h - sum > 0)
    {
        int sub = h - sum;
        int psub = sub - smx;
        // cout << sub << "," << smx << "," << fmx << "," << max(0LL, (sub - smx + fmx - 1) / fmx) << endl;
        // cout << ((sub + fmx - 1) / fmx) << endl;
        if (sub > 0)
            cnt += ((sub + fmx - 1) / fmx);
        // cnt += max(0LL, (max(0LL, sub - smx) + fmx - 1) / fmx);
        // cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    int cnt[n + 1][n + 1] = {};
    rep(i, 0, m) {
        int l, r;
        cin >> l >> r;
        cnt[l][r]++;
    }

    rep(i, 1, n + 1) {
        rep(j, 1, n + 1) {
            cnt[i][j] += cnt[i][j - 1];
        }
    }

    rep(i, 1, n + 1) {
        rep(j, 1, n + 1) {
            cnt[i][j] += cnt[i - 1][j];
        }
    }

    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        cout << cnt[r][r] - cnt[r][l - 1] - cnt[l - 1][r] + cnt[l - 1][l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1920
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author __shangu__
 */
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);
        CSyntheticKadomatsu solver = new CSyntheticKadomatsu();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSyntheticKadomatsu {
        private int c;
        private int N;
        private int a;
        private int b;
        private int[] arr;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            arr = new int[N];
            for (int i = 0; i < N; ++i) arr[i] = in.nextInt();

            out.println(sol(0, 0, 0, 0));
        }

        private int sol(int n, int x, int y, int z) {
            if (N == n) {
                if (x == 0 || y == 0 || z == 0) return 0x3f3f3f3f;
                return Math.abs(x - a) + Math.abs(y - b) + Math.abs(z - c);
            }

            int v1 = sol(n + 1, x + arr[n], y, z) + (x == 0 ? 0 : 10),
                    v2 = sol(n + 1, x, y + arr[n], z) + (y == 0 ? 0 : 10),
                    v3 = sol(n + 1, x, y, z + arr[n]) + (z == 0 ? 0 : 10),
                    v4 = sol(n + 1, x, y, z);
            return Math.min(v1, Math.min(v2, Math.min(v3, v4)));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 23892
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 1000
int LCSLength(char*,char*);
int max(int,int);
int main(void)
{
  int i;//counter
  int n;//the number of dataset
  char str[2][LEN+1];//2 input strings
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s %s",str[0],str[1]);
      printf("%d\n",LCSLength(str[0],str[1]));
    }
  return 0;
}
int LCSLength(char *str0,char *str1)
{
  int i,j;//counter
  int len[2];//length of each string
  len[0]=strlen(str0);
  len[1]=strlen(str1);
  int **arr;//array to calculate LCS length
  arr=(int**)malloc(sizeof(int*)*(len[0]+1));
  for(i=0;i<=len[0];i++) arr[i]=(int*)malloc(sizeof(int)*(len[1]+1));
  for(i=0;i<=len[0];i++)
    {
      for(j=0;j<=len[1];j++)
        {
          if(i==0||j==0) arr[i][j]=0;
          else if(str0[i-1]==str1[j-1]) arr[i][j]=arr[i-1][j-1]+1;
          else arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
        }
    }
  return arr[len[0]][len[1]];
}
int max(int x,int y)
{
  return x>y?x:y;
}


Measured memory_bytes: 80456
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h(n+5);
  for(int i=0;i<n;i++){
    cin>>h[i+1];
  }
  vector<int> dp(n+5,INF);

  dp[1]=0;
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
      if(i-j<0){
        break;
      }
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
  }
  cout<<dp[n]<<'\n';
  return(0);
}

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

long long a[200010], b[200010];
long long t_a[200010], t_b[200010];

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

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}

	int ans = 0;
	for (int bit = 0; bit < 30; bit++) {
		long long t = 1 << bit;

		for (int i = 1; i <= n; i++) {
			t_a[i] = a[i] % (2 * t);
			t_b[i] = b[i] % (2 * t);
		}

		sort(t_b + 1, t_b + n + 1);

		long long cnt = 0;
		for (int i = 1; i <= n; i++) {
			cnt += lower_bound(t_b + 1, t_b + n + 1, 4 * t - t_a[i]) - lower_bound(t_b + 1, t_b + n + 1, 3 * t - t_a[i]);
			cnt += lower_bound(t_b + 1, t_b + n + 1, 2 * t - t_a[i]) - lower_bound(t_b + 1, t_b + n + 1, t - t_a[i]);
		}

		if (cnt % 2 == 1) {
			ans += t;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>

using namespace std;


int main()
{
  long long int n;
  long long int ans = 0;

  cin >> n;

  for (long long int i = 1; i <= n; i++) {
    if ((i % 3) != 0 && (i % 5) != 0) {
      ans+=i;
    }
  }
  cout << ans;

  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a*b%2!=0 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
D - Triangles
https://atcoder.jp/contests/abc143/tasks/abc143_d

"""
import sys

from bisect import bisect_right

def solve(N, lines):
    ans = 0
    for c in range(N-1, -1, -1):
        for b in range(c-1, -1, -1):
            i = bisect_right(lines[:b], lines[c] - lines[b])
            ans += b-i
    return ans


def main(args):
    N = int(input())
    lines = map(int, input().split())
    ans = solve(N, sorted(lines))
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

#define ll long long
#define mod 1000000007

void solve(){
    int n;
    cin>>n;
    if(360 % n == 0){
        cout<<360 / n;
    }else{
        for(int i = 1;i>0;i++){
            if((n * i) % 360 == 0){
                cout<<i;
                return;
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int t = 1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
    ll q,h,s,d,n,m,a=0;
    cin>>q>>h>>s>>d>>n;
    m=min(min(q*4, h*2), s);
    if(n%2==1){
        a+=m;
    }
    a+=(n/2)*min(d, m*2);
    cout<<a<<endl;
}


Measured memory_bytes: 256
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int N,K,eval;
    char S[100000];
    cin >> N >> K >> S;
    
    eval = 0;
    REP(i,N){
        if(S[i] == S[i+1]){
            eval++;
        }
    }

    cout << min(N-1, eval+2*K) << endl;


    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

double dist(double x1, double y1, double x2, double y2) {  // (x1, y1) と (x2, y2) のユークリッド距離
    return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}
 
int main() {
    ll n;
    cin >> n;

    vector<double> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    
    vl perm(n);
    rep(i, n) {
        perm[i] = i;
    }

    double ans = 0.0;
    do {
        // {0, 1, … , n-1} の全順列を昇順に出力
        rep(i, n-1) {
            ans += dist(x[perm[i]], y[perm[i]], x[perm[i+1]], y[perm[i+1]]);
        }
        
    } while(next_permutation(all(perm)));

    ll p = 1;
    exrep(i, 1, n) {
        p *= i;
    }

    ans /= (double)p;
    
    exout(ans);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;i++)
ll n,m;
ll v[10000];
ll w[10000];
ll d[101][100000];
int main()
{
    cin>>n>>m;
    F(i,1,n)cin>>w[i]>>v[i];
    F(i,1,n)F(j,1,m)
    {
        if(w[i]<=j)d[i][j]=max(d[i-1][j],d[i-1][j-w[i]]+v[i]);
        else d[i][j]=d[i-1][j];
    }
    cout<<d[n][m];
}


Measured memory_bytes: 78336
n=int(input())
a=list(map(int,input().split()))
ans=0
right=0
np=a[0]
nx=a[0]
for left in range(n):
    while np==nx:
        right+=1
        if right==n:
            break
        np+=a[right]
        nx^=a[right]
    else:
        np-=a[right]
        nx^=a[right]
    right-=1
    ans+=(right-left+1)
    np-=a[left]
    nx^=a[left]
print(ans)

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

ll Smax(ll S1, ll S2, ll S3) {
  ll ans = S1;
  ans = std::max(ans, S2);
  ans = std::max(ans, S3);
  return ans;
}
ll Smin(ll S1, ll S2, ll S3) {
  ll ans = S1;
  ans = std::min(ans, S2);
  ans = std::min(ans, S3);
  return ans;
}

ll solve(ll H, ll W) {
  ll ans = 1LL << 31;
  for(ll h = 1; h < H; ++h) {
    ll S1, S2, S3;
    S1 = h * W;
    if(H - h >= 2) {
      S2 = ((H - h) / 2 * W);
      S3 = H * W - S1 - S2;
      ans = std::min(ans, Smax(S1, S2, S3) - Smin(S1, S2, S3));
    }
    S2 = (H - h) * (W / 2);
    S3 = H * W - S1 - S2;
    ans = std::min(ans, Smax(S1, S2, S3) - Smin(S1, S2, S3));
  }

  return ans;
}

int main() {
  ll H, W;
  std::cin >> H >> W;

  ll ans;
  ans = std::min(solve(H, W), solve(W, H));

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
n = int(input())

a1 = 26**1
a2 = 26**2
a3 = 26**3
a4 = 26**4
a5 = 26**5
a6 = 26**6
a7 = 26**7
a8 = 26**8
a9 = 26**9
a10 = 26**10
a11 = 26**11
a12 = 26**12

b1 = a1
b2 = a1+a2
b3 = a1+a2+a3
b4 = a1+a2+a3+a4
b5 = a1+a2+a3+a4+a5
b6 = a1+a2+a3+a4+a5+a6
b7 = a1+a2+a3+a4+a5+a6+a7
b8 = a1+a2+a3+a4+a5+a6+a7+a8
b9 = a1+a2+a3+a4+a5+a6+a7+a8+a9
b10 = a1+a2+a3+a4+a5+a6+a7+a8+a9+a10
b11 = a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11
b12 = a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12

b = [b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12]
c = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
s = ''
e = []
     
if n <= b1:
    i = 1
elif b1 < n <= b2:
    i = 2
elif b2 < n <= b3:
    i = 3
elif b3 < n <= b4:
    i = 4
elif b4 < n <= b5:
    i = 5
elif b5 < n <= b6:
    i = 6
elif b6 < n <= b7:
    i = 7
elif b7 < n <= b8:
    i = 8
elif b8 < n <= b9:
    i = 9
elif b9 < n <= b10:
    i = 10
elif b10 < n <= b11:
    i = 11
elif b11 < n:
    i = 12


for j in range (i):
    if n % 26 == 0:
        f = n % 26
        e.append(f)
        n = n // 26 -1
    elif n % 26 != 0:
        f = n % 26
        e.append(f)
        n = n // 26

for  k in range(i,0,-1):
    s = s + c[e[k-1]-1]

print(s)


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

int N;
int64 a[50];

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

	cin >> N;
	int64 m = 0, mi = -1;
	REP(i, 0, N) {
		cin >> a[i];
		if(m < abs(a[i])) {
			m = abs(a[i]);
			mi = i;
		}
	}
	if(mi == -1) {
		cout << 0 << endl;
	} else {
		cout << (N*2 - 2) << endl;
		REP(i, 0, N)
			if(i != mi)					cout << (mi+1) << " " << (i+1) << endl;
		if(a[mi] > 0) {
			REP(i, 0, N-1)				cout << (i+1) << " " << (i+2) << endl;
		} else {
			for(int i=N-1; i > 0; i--)	cout << (i+1) << " " << (i) << endl;
		}
	}
	
	return 0;
}


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

char len1[1001], len2[1001];

LCS(int x, int y){
  int i,j,c[1001][1001];

   for(i=0;i<=x;i++){
      c[i][0]=0;
  }

  for(j=0;j<=y;j++){
    c[0][j]=0;
  }

  for(i=1;i<=x;i++){
    for(j=1;j<=y;j++){
      if(len1[i-1]==len2[j-1]){
	c[i][j]=c[i-1][j-1]+1;
      }else if(c[i-1][j-1]>=c[i][j-1]){
	c[i][j] = c[i-1][j];
      }else{
	c[i][j] = c[i][j-1];
      }
    }
  }

  if(i==0 || j==0){
    return 0;
  }else if(i>0 && j>0 && x == y){
    return c[i-1][j-1];
  }else if(i>0 && j>0 && x!=y){
    return c[x][y];
  }
}

main(){
  int n,i,l1,l2,result;

  scanf("%d", &n);
  
  for(i=0;i<n;i++){
    scanf("%s",len1);
    scanf("%s",len2);
    l1=strlen(len1);
    l2=strlen(len2);
   
    result=LCS(l1,l2);
    printf("%d\n",result);
  }
  return 0;
}

Measured memory_bytes: 4512
from math import sqrt
n = int(input())
cnt = 0
for i in range(n):
    b = True
    x = int(input())
    xroot = int(sqrt(x))
    for i in range(xroot+1):
        if i >= 2 and x%i == 0:
            b = False
            break
    if b == True:
        cnt += 1

print(cnt)


Measured memory_bytes: 5668
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;
int main() {
	string s;
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++)
		for (char j = 'A'; j < 'A' + w; j++) {
			cin >> s;
			if (s == "snuke") {
				cout << j << i << endl;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<int>())
using namespace std;
int main()
{
  speed_up;
  ll a, b, x;
  cin>>a>>b>>x;
  a = a - 1;
  if(a>=0) a = a/x + 1;
  else a = 0;

   b = b/x + 1;
   
  cout<<b - a<<endl;

  return 0;
}



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

#define INF 1000000001
using namespace std;

int counter = 0;

void merge(vector<int> &A,const int left,const int mid,const int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L(n1+1,0),R(n2+1,0);
    for(int i = 0;i < n1;i++) L[i] = A[left + i];
    for(int i = 0;i < n2;i++) R[i] = A[mid  + i];
    L[n1] = INF;R[n2] = INF;
    int j = 0,k = 0;
    for(int i = left;i < right;i++){
        if(L[j] <= R[k]){
            counter++;
            A[i] = L[j];
            j++; 
        }else if(L[j] > R[k]){
            counter++;
            A[i] = R[k];
            k++;
        }
    }
}

void mergeSort(vector<int> &A,int left,int right){
    if(left + 1 < right){
        int mid = (left + right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);

    }
}


int main(){
    int flag = 0;
    int len_array;
    int temp;
    scanf("%d",&len_array);
    
    vector<int> int_array(len_array,0);
    for(int i = 0;i < len_array;i++){
        scanf("%d",&temp);
        int_array[i] = temp;
    } 
    
    mergeSort(int_array,0,len_array);
    
    for(int i = 0;i < len_array;i++){
        printf("%d",int_array[i]);
        if(i < len_array-1) printf(" ");
        else printf("\n");
    }
    printf("%d\n",counter);
    return 0;   
}



Measured memory_bytes: 6908
MOD = 2019
p = 673
l,r = map(int,input().split())
r += 1

if (r-1)//p - (l-1)//p >= 1:
    print(0)
    exit()


def it():
    for dx in range(r-l):
        x = (l+dx)%MOD
        for dy in range(dx+1,r-l):
            y = (l+dy)%MOD
            yield x*y%MOD

print(min(it()))


Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      Deque<Integer> stack = new ArrayDeque<>();
      int tmpA = 0, tmpB = 0;
      String[] str = sc.nextLine().split("\\s");

      for (String s : str) {
        if (s.equals("+")) {
          tmpA = stack.pop();
          tmpB = stack.pop();
          stack.push(tmpA + tmpB);
        } else if (s.equals("-")) {
          tmpA = stack.pop();
          tmpB = stack.pop();
          stack.push(tmpB - tmpA);
        } else if (s.equals("*")) {
          tmpA = stack.pop();
          tmpB = stack.pop();
          stack.push(tmpA * tmpB);
        } else {
          stack.push(Integer.valueOf(s));
        }
      }

      System.out.println(stack.pop());
    }
  }
}



Measured memory_bytes: 26308
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , m;
ll a , b , c; 
int A[MAXN] , B[MAXN];

void solve() {
	cin >> n;
	rep( i , 1 , n ) scanf("%lld%lld",A+i,B+i);
	sort( A + 1 , A + 1 + n );
	sort( B + 1 , B + 1 + n );
	if( n & 1 ) {
		int t = A[( n + 1 ) / 2] , r = B[( n + 1 ) / 2];
		cout << r - t + 1;
	} else {
		int t = ( A[n / 2] + A[n / 2 + 1] ) , r = B[n / 2] + B[n / 2 + 1];
		cout << r - t + 1;
	}
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}



Measured memory_bytes: 6788
#include <iostream>
    #include <map>
    #include <algorithm>
    using namespace std;
    int n, m, s[100], t[100];
    typedef map<string, int> mp;
    int main(void){
        // Your code here!
        mp blue, red;
        string str;
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> str;
            blue[str]++;
        }
        cin >> m;
        for (int i = 0; i < m; i++) {
            cin >> str;
            blue[str]--;
        }
        int res = 0;
        for (auto it = blue.begin(); it != blue.end(); it++) {
            res = max(res, it->second);
        }
        cout << res << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int N = 100000; 
    vector<bool> isPrime(N, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i*i < N; i++) {
        if (!isPrime[i]) continue;
        for (int j = i*i; j < N; j += i) isPrime[j] = false;
    }
    vector<int> ps;
    loop (N, i) if (isPrime[i]) ps.push_back(i);

    while (1) {
        int m, a, b; cin >> m >> a >> b;
        if (!a) break;
        int M = 0, p, q;
        for (int i = 0; ps[i] * ps[i] <= m; i++) {
            int j = i;
            while (ps[i] * ps[j] <= m && ps[j] * a <= ps[i] * b) j++;
            j--;
            if (M < ps[i] * ps[j]) {
                M = ps[i] * ps[j];
                p = ps[i];
                q = ps[j];
            }
        }
        cout << p << " " << q << endl;
    }
    return 0;
}

Measured memory_bytes: 3244
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main(){
	int x, y, z;
	int s, ans;
	scanf("%d %d %d", &x, &y, &z);
	y /= x;
	ans = min(y, z);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define maxn 500000
#define int long long
#define INF 99999999999LL
int n, sum, S, T, lev[maxn];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

struct edge
{
	int cnp, to[maxn], f[maxn], last[maxn], head[maxn], cur[maxn];
	edge() { cnp = 2; }
	void add(int u, int v, int fl)
	{
		to[cnp] = v, f[cnp] = fl, last[cnp] = head[u], head[u] = cnp ++;
		to[cnp] = u, f[cnp] = 0, last[cnp] = head[v], head[v] = cnp ++;
	}
}E1;

bool bfs()
{
	memset(lev, 0, sizeof(lev));
	queue <int> q; q.push(S); lev[S] = 1;
	while(!q.empty())
	{
		int u = q.front(); q.pop();
		for(int i = E1.head[u]; i; i = E1.last[i])
		{
			int v = E1.to[i];
			if(!lev[v] && E1.f[i])
			{ lev[v] = lev[u] + 1; q.push(v); }
		}
		if(lev[T]) return 1;
	}
	return 0;
}

int dfs(int u, int nf)
{
	if(u == T) return nf;
	int tf = 0;
	for(int i = E1.cur[u]; i; i = E1.last[i])
	{
		int v = E1.to[i];
		if(lev[v] == lev[u] + 1 && E1.f[i])
		{
			int af = dfs(v, min(nf, E1.f[i]));
			tf += af, nf -= af;
			E1.f[i] -= af, E1.f[i ^ 1] += af;
			if(!nf) return tf;
			E1.cur[u] = i;
		}
	}
	return tf;
}

int Dinic()
{
	int ret = 0;
	while(bfs())
	{
		memcpy(E1.cur, E1.head, sizeof(E1.head));
		ret += dfs(S, INF);
		//exit(0);
	}
	return ret;
}

signed main()
{
	n = read(); S = 0, T = n + 3;
	for(int i = 1; i <= n; i ++) 
	{
		int x = read();
		if(x > 0) sum += x, E1.add(i, T, x); 
		else if(x <= 0) E1.add(S, i, -x);
	}
	for(int i = 1; i <= n; i ++)
		for(int j = 2; i * j <= n; j ++)
			if(i * j <= n) E1.add(i, i * j, INF);
	printf("%lld\n", sum - Dinic());
	return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll sm = TEN(17);
    for (int x = -200; x < 200; x++) {
        ll nw = 0;
        for (int i = 0; i < n; i++) {
            nw += (x-a[i])*(x-a[i]);
        }
        sm = min(sm, nw);
    }
    cout << sm << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}

ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


    
     int solve()
     {  
        int n;cin>>n;
        map<pii,int> m;
        for(int i=1;i<=n;i++){
            int z=i;
            vi a;
            while(z){
                a.pb(z%10);
                z/=10;
            }
            int st=a[0],en=a[a.size()-1];
            m[{st,en}]+=1;
        }
        int ans=0;
        for(auto i:m){
            auto st=i.ff.ff,en=i.ff.ss,cnt=i.ss;
            ans+=cnt*m[{en,st}];
        }
        // ans-=n;
        cout<<ans<<endl;

        r0   
     }
    signed main()
    {   
        asdf
        
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

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



signed main(){
	ll n,ans = 0;
	cin >> n;
	ll t[n];
	string s[n],x;
	bool flag = false;
	
	rep(i,0,n){
		cin >> s[i] >> t[i];
	}
	cin >> x;
	
	
	rep(i,0,n){
		if(flag) ans += t[i];
		if(x == s[i]) flag = true;
	}
	
	cout << ans << endl;
	
    return 0;
}

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    vector<int> t;
    int i = 0;
    int a = A;
    int b = B;
    while (i<K) {
        if (a > B) break;
        t.push_back(a);
        a++;
        i++;
    }
    int j = 0;
    while (j < K) {
        if (b < A) break;
        t.push_back(b);
        b--;
        j++;
    }

    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    for (int i=0; i<t.size(); i++) {
        cout << t[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;
int x[10], y[10];

double dist(int i, int j)
{
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    
    return sqrt(dx * dx + dy * dy);
}


int main(int argc, const char * argv[]) {

    int n, count = 1;
    float ans = 0;
    cin >> n;
    
    double sum = 0;
    
    vector<int> v(n);
    
    for(int i=1; i<=n; i++)
    {
        cin >> x[i] >> y[i];
    }
    
    for(int i=1; i<=n; i++)
    {
        count *= i;
    }
    
    for(int i=0; i<n; i++) v[i] = i + 1;
    
    do{
        for(int i=0; i<n-1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    
    
    
    
    cout << fixed << setprecision(10) << sum / count << endl;
    
    return 0;
}


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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << ':' << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) <<  ':'  << arg1 << '|' ;
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
int main(){
	ll n, m; cin >> n >> m;
	ll a[n], sum = 0;
	for(ll i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	ll tar = 0;
	for(auto v: a){
		if (v >= ((1.0)/(4*m*1.0) * 1.0 * sum)) {
			tar++;
		}
	}
	if(tar >= m){
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

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

int pcnt(int x) { return __builtin_popcount(x); }

int f(int x) {
  if (x == 0) return 0;
  return f(x % pcnt(x)) + 1;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> x(n);
  rep(i, n) x[i] = s[i] - '0';
  int pc = 0;
  rep(i, n) pc += x[i];
  vector<int> ans(n, 0);
  rep(b, 2) {
    int npc = pc;
    if (b == 0)
      npc++;
    else
      npc--;
    if (npc <= 0) continue;
    int r0 = 0;
    rep(i, n) {
      r0 = (r0 * 2) % npc;
      r0 += x[i];
    }
    int k = 1;
    for (int i = n - 1; i >= 0; --i) {
      if (x[i] == b) {
        int r = r0;
        if (b == 0)
          r = (r + k) % npc;
        else
          r = (r - k + npc) % npc;
        ans[i] = f(r) + 1;
      }
      k = (k * 2) % npc;
    }
  }

  rep(i, n) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 5248
from itertools import groupby

n,k = map(int,input().split())
s = input()


grouped = groupby (s)
res = []

if s[0] == '0':
	res.append((1,0))

for l,v in grouped:
	res.append( (l,len(list(v))) )

if s[len(s)-1] == '0':
	res.append((1,0))

#for d in res:
	#print(d)

if len(res) <= 2*k + 1:
	ans = 0;
	for d in res:
		ans += d[1];

	print(ans)
	exit()

now = 0
ans = 0
for i in range(2*k+1):
	now += res[i][1]

ans = max(ans,now)

for i in range(2*k+1,len(res),2):
	now -= res[i-2*k-1][1]
	now -= res[i-2*k][1]

	now += res[i][1]
	now += res[i+1][1]

	ans = max(ans,now)

print(ans)



Measured memory_bytes: 16448
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll s[100010],f[100010];
int b[100010],L[100010],R[100010],v[200010],tr[800010];
void pushdown(int x){
	if(tr[x]){
		tr[x<<1]=tr[x<<1|1]=tr[x];
		tr[x]=0;
	}
}
void modify(int L,int R,int v,int l,int r,int x){
	if(L<=l&&r<=R){
		tr[x]=v;
		return;
	}
	pushdown(x);
	int mid=(l+r)>>1;
	if(L<=mid)modify(L,R,v,l,mid,x<<1);
	if(mid<R)modify(L,R,v,mid+1,r,x<<1|1);
}
int query(int p,int l,int r,int x){
	if(l==r)return tr[x];
	pushdown(x);
	int mid=(l+r)>>1;
	if(p<=mid)
		return query(p,l,mid,x<<1);
	else
		return query(p,mid+1,r,x<<1|1);
}
int M,k;
ll calc(int x){
	int y=query(x,1,M,1);
	if(y==0)return 0;
	return f[y]+((v[L[y]]-v[x])%k+k)%k;
}
int main(){
	int n,i,a;
	ll ans;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d%d",&a,b+i);
		if(b[i]==1&&a*2>k){
			puts("-1");
			return 0;
		}
		s[i]=s[i-1]+a;
	}
	for(i=1;i<=n;i++){
		if(b[i]==1){
			L[i]=((-2*s[i-1]%k)+k)%k;
			R[i]=((-2*s[i]%k)+k)%k;
		}else{
			L[i]=0;
			R[i]=k-1;
		}
	}
	for(i=1;i<=n;i++){
		v[++M]=L[i];
		v[++M]=R[i];
	}
	sort(v+1,v+M+1);
	M=unique(v+1,v+M+1)-v-1;
	for(i=n;i>0;i--){
		L[i]=lower_bound(v+1,v+M+1,L[i])-v;
		R[i]=lower_bound(v+1,v+M+1,R[i])-v;
		f[i]=calc(L[i]);
		if(L[i]<=R[i]){
			if(L[i]>1)modify(1,L[i]-1,i,1,M,1);
			if(R[i]<M)modify(R[i]+1,M,i,1,M,1);
		}else if(R[i]+1<=L[i]-1)
			modify(R[i]+1,L[i]-1,i,1,M,1);
	}
	ans=f[1];
	for(i=1;i<=M;i++)ans=min(ans,calc(i));
	printf("%lld",ans+2*s[n]);
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
intt lcm(intt a, intt b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("o.txt","w",stdout);
  #endif
}
///////////U L R D
int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};

template <typename T1, typename T2>
struct less_second {
    typedef pair<T1, T2> type;
    bool operator ()(type const& a, type const& b) const {
        return a.second > b.second;
    }
};

int solve(vi v)
{
  vi ans(v.size(),INT_MAX);
  ans[0]=0;
  
  for(int i=0;i<v.size();i++)
  {
    for(int j : {i+1,i+2})
    {
      if(j<v.size())
      {
        ans[j]=min(ans[j],ans[i]+abs(v[i]-v[j]));
      }
    }
  }
  return ans[v.size()-1];
}

int main()
{
  go();
  fast_io
  int n;cin>>n;
  vi v(n);
  for0(i,n)
  {
    cin>>v[i];
  }
  int ans=0;
  ans=solve(v);
  cout << ans <<"\n";
}



/*

arr : 0 20 min(30,50)

*/










Measured memory_bytes: 4496
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF 1e9
#define INFL 1e18
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll n, a, b;

ll power(ll x, ll p) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        ll t = power(x, p/2);
        return t*t % MOD;
    }
    return (x * power(x, p-1)) % MOD;
}

class DBouquet {
public:
	void solve(std::istream& in, std::ostream& out) {
	    in >> n >> a >> b;
	    ll com[200005];
        com[0] = 1;
        for (int i = 1; i < 200005; i++) {
            com[i] = com[i-1] * (((n-i+1) * (power(i, MOD-2) % MOD)) % MOD);
            com[i] %= MOD;
        }
	    ll ans = (power(2, n) - 1) % MOD;
	    ll A = 0, B = 0;
	    if (n >= a) {
	        A = com[a] % MOD;
	    }
	    if (n >= b) {
	        B = com[b] % MOD;
	    }
	    ans += (MOD - A) + (MOD - B);
	    ans %= MOD;
	    out << ans << '\n';
	}
};


int main() {
	DBouquet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<int> T(N, 0);
    int total = 0;
    for (int i = 0; i < N; ++i) {
        cin >> T[i];
        total += T[i];
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; ++i) {
        int p, x;
        cin >> p >> x;
        --p;
        cout << total - T[p] + x << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3604