akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return sums.back();
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate(ll k) {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
        rep(i, sums.size()) sums[i] = sums[i] % k;
    }

};

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

    vector<ll> numbers(n + 1, 0);
    rep(i, n) cin >> numbers[i + 1];
    rep(i, n) numbers[i + 1]--;

    n++;

    CumulativeSum cs(n);
    rep(i, n) cs.set(i, numbers[i]);
    cs.calculate(k);

    ll ans = 0;
    map<ll, ll> m;


    auto pop = [&](ll i) {
        if (i < 0) return;
        m[cs.getSum(i)]--;
    };

    auto push = [&](ll i) {
        if (i < 0) return;
        m[cs.getSum(i)]++;
    };

    rep(i, n) {
        pop((-k) + i);
        push(i - 1);

        ll c = m[cs.getSum(i)];
        ans += c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17408
#include <cstdio>

#define int long long

template<class T>void fr(T &a) {
    T w=0,s=1;char c=getchar();
    while(c<'0'||c>'9') {if(c=='-')s=-1;c=getchar();}
    while(c>='0'&&c<='9') w=w*10+c-'0',c=getchar();
    a=w*s;
}
template<class T>T fr() {T a;fr(a);return a;}
#define R() fr<int>()

int a[55];

signed main() {
    int n=R(),ans=0;
    for(int i=1;i<=n;i++) fr(a[i]);
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
            ans+=(a[i]*a[j]);
    return !printf("%lld\n",ans);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for _ in range(H)]

N = W * H
E = [[0] * N  for _ in range(N)]

dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            for di, dj in dij:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":
                    E[W * i + j][W * ni + nj] = 1

from scipy.sparse.csgraph import floyd_warshall
A = floyd_warshall(E)
INF = float("inf")

print(int(max(max(a if a != INF else 0 for a in a) for a in A)))

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> X(N);
    rep(i, N) cin >> X[i];

    sort(X.begin(), X.end());

    ll ans = INF;
    rep(x, 101) {
        ll res = 0;
        for (int &i : X) res += (i - x) * (i - x);
        ans = min(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#define INF 1000000013
using namespace std;
typedef long long ll;
ll mod=1e9+7;
int dp[100010];

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<a[0];i++) dp[i]=1;
  for(int i=a[0];i<=k;i++){
    bool check=false;
    for(int j=0;j<n;j++){
      if(i-a[j]>=0&&dp[i-a[j]]==1) check=true;
    }
    if(!check) dp[i]=1;
  }
  cout << (dp[k]^1?"First":"Second") << endl;
}

Measured memory_bytes: 640
main=do
 [x,y,v,w]<-map read.words<$>getLine
 let a = abs(x-v)
     b = abs(y-w)
 putStrLn$unwords$map show$if(v-x)*(w-y)>0 then(if x<v||y<w then [v-b,w+a,x-b,y+a]else[v+b,w-a,x+b,y-a])else if x<v||y>w then[v+b,w+a,x+b,y+a]else[v-b,w-a,x-b,y-a]

Measured memory_bytes: 508
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    
    ll w,h,x,y;cin>>w>>h>>x>>y;
    cout<<(double)w*h/2<<" ";
    if((w%2==0&&x==w/2)&&(h%2==0&&y==h/2))cout<<1<<endl;
    else cout<<0<<endl;
}






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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define pb push_back
#define w first
#define d second
typedef pair<int,int> pii;

int main(){
  while(1){
    int n,w,d; cin >> n >> w >> d;
    if(w == 0) break;
    
    vector<pii> cake = {pii(w,d)};
    rep(i,n){
      int p,s; cin >> p >> s; p--;
      pii n1, n2;
      n1 = n2 = cake[p];
      cake.erase(cake.begin() + p);
      s %= n1.w + n1.d;

      // n1 <= n2となるようにする
      if(0 < s and s < n1.w){
	if(s <=  n1.w / 2){
	  n1.w = s;
	  n2.w -= s;
	}else{
	  n2.w = s;
	  n1.w -= s;
	}
      }else{
	s -= n1.w;
	if(s <= n1.d / 2){
	  n1.d = s;
	  n2.d -= s;
	}else{
	  n2.d = s;
	  n1.d -= s;
	}
      }

      cake.pb(n1);
      cake.pb(n2);
    }

    map<int,int> mp;
    rep(i,cake.size()) mp[cake[i].w * cake[i].d]++;

    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
      if(itr == mp.begin())
	rep(i,(*itr).second)
	  if(i == 0)
	    cout << (*itr).first;
	  else
	    cout << " " << (*itr).first;
      else
	rep(i,(*itr).second)
	  cout << " " << (*itr).first;
    }
    cout << endl;
  }
}


Measured memory_bytes: 2992
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h;
ll ans,num;
ll x[500005],y[500005],z[500005];
ll l[500005],r[500005];
bool dame,flag;
bool check[500005];
char s[500005],t[500005];

int main(){
    cin >> n;
	p(2*(n-1));
	num = 0;
	for(i=0;i<n;i++){
		cin >> x[i];
		if(abs(x[i]) > num){
			num = abs(x[i]);
			a = i;
		}
	}
	if(x[a] > 0){
		for(i=0;i<n;i++){
			if(a != i){
				pe(a+1);p(i+1);
			}
		}
		for(i=0;i<n-1;i++){
			pe(i+1);p(i+2);
		}
	}else{
		for(i=0;i<n;i++){
			if(a != i){
				pe(a+1);p(i+1);
			}
		}
		for(i=n-1;i>0;i--){
			pe(i+1);p(i);
		}
	}
	return 0;
}

Measured memory_bytes: 26240
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			// 文字列の入力
			if(a==b && b==c) {
				System.out.println("Yes");
			} else {
			// 出力
  				System.out.println("No");
			}
	}
}

Measured memory_bytes: 23380
/*
  AOJ 1030
  Title:Cubes Without Holes
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
int n,h;
int x[500],y[500],z[500];
char men[3];
int table[6][3]={{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};

int cross_1(int x[],int y[],int z[],int p,int q,int r)
{
  int a[3][3],x1,y1,z1,x2,y2,z02,x3,y3,z3,i;
  a[0][0]=x[p];a[0][1]=y[p];a[0][2]=z[p];
  a[1][0]=x[q];a[1][1]=y[q];a[1][2]=z[q];
  a[2][0]=x[r];a[2][1]=y[r];a[2][2]=z[r];
  for(i=0;i<6;i++)
    {
      x1=a[table[i][0]][0];y1=a[table[i][0]][1];z1=a[table[i][0]][2];
      x2=a[table[i][1]][0];y2=a[table[i][1]][1];z02=a[table[i][1]][2];
      x3=a[table[i][2]][0];y3=a[table[i][2]][1];z3=a[table[i][2]][2];
      if(x1==x2 && x3==0 && y2==y3 && y1 == 0 && z3==z1 && z02 == 0)
	return(1);
    }
  return(0);
}

main()
{
  int i,j,k,ret,a,b;
  int cnt_x,cnt_y,cnt_z,cnt_xyz;

  while(scanf("%d %d",&h,&n)  && (n||h))
    {
      memset(x,0,sizeof(x));
      memset(x,0,sizeof(y));
      memset(x,0,sizeof(z));
      for(i=0;i<n;i++)
	{
	  scanf("%s %d %d",men,&a,&b); 
	  if(men[0]=='x')
	    {
	      x[i]=a;
	      {
		if(men[1]=='y')
		  {
		    y[i]=b;
		    z[i]=0;
		  }
		else
		  {
		    y[i]=0;
		    z[i]=b;
		  }
	      }
	    }
	  else if(men[0]=='y')
	    {
	      x[i]=0;
	      y[i]=a;
	      z[i]=b;
	    }
	}

      cnt_x=cnt_y=cnt_z=cnt_xyz=0;
      for(i=0;i<n-1;i++)
	for(j=i+1;j<n;j++)
	  {
	      if(x[i]==x[j] && y[i]==0 && z[j]==0)
		cnt_x++;
	      if(x[i]==x[j] && z[i]==0 && y[j]==0)
		cnt_x++;
	      if(y[i]==y[j] && z[i]==0 && x[j]==0)
		cnt_y++;
	      if(y[i]==y[j] && x[i]==0 && z[j]==0)
		cnt_y++;
	      if(z[i]==z[j] && x[i]==0 && y[j]==0)
		cnt_z++;
	      if(z[i]==z[j] && y[i]==0 && x[j]==0)
		cnt_z++;
	    }
      
      for(i=0;i<n-2;i++)
	for(j=i+1;j<n-1;j++)
	  for(k=j+1;k<n;k++)
	    cnt_xyz+=cross_1(x,y,z,i,j,k);      

      //printf("%d %d %d %d\n",cnt_x,cnt_y,cnt_z,cnt_xyz);
      printf("%d\n",h*h*h-n*h+cnt_x+cnt_y+cnt_z-cnt_xyz);
    }
  return(0);
}

Measured memory_bytes: 604
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var X = Number(lines[0].split(" ")[1]);

    var x = lines[1].split(" ").map(i => Number(i)); x.push(X);
    x.sort((a, b) => a - b);

    var diff = Array(N);
    for (var i = 0; i < N; i++) { diff[i] = x[i + 1] - x[i]; }

    var ans = diff[0];
    for (var i = 1; i < N; i++) { ans = gcd(ans, diff[i]) }
    
    console.log(ans);

});

function gcd(a, b) {
    var r = a % b;
    if (r === 0) { return (b) }
    else { return (gcd(b, r)); }
}

Measured memory_bytes: 29200
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        return S.chars().reduce(0, (result, ch) -> result + ((ch == '+') ? 1 : -1));
    }
}

Measured memory_bytes: 27088
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

s=SI()
if s=="RRR":ans=3
if s=="SRR":ans=2
if s=="RRS":ans=2
if s=="RSR":ans=1
if s=="RSS":ans=1
if s=="SRS":ans=1
if s=="SSR":ans=1
if s=="SSS":ans=0
print(ans)


Measured memory_bytes: 9148
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        double r = 0;
        double log2 = Math.log(2);
        double perDice = 1.0d/n;
        for(int i=1; i<=n; i++) {
            double score = (double)i;
            double req = Math.ceil(Math.log(k/score)/log2);
            double possibility = Math.min(1.0, Math.pow(0.5, req));
            r += perDice * possibility;
        }
        System.out.println(r);
    }
}


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

int main ()
{
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	
//	freopen ("//specify file name","r",stdin);
//	freopen ("output.txt","w",stdout);
	
	char matrix[3][3];
	
	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			cin>>matrix[i][j];
		}
	}
	
	cout<<matrix[0][0]<<matrix[1][1]<<matrix[2][2];
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define N 15
int p[N];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        int max_p=0;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            cin>>p[i];
            ans+=p[i];
            max_p=max(max_p,p[i]);
        }
        cout<<ans-max_p/2<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define mod 1000000007
int n,m,f[100005];
long long fac[100005],inv[100005],ans;
long long c(int x,int y){return y<=x?fac[x]*inv[y]%mod*inv[x-y]%mod:0;}
long long fp(long long x,long long y){return (y%2?x:1ll)*(y/2?fp(x*x%mod,y/2):1ll)%mod;}
void pre(int n)
{
	fac[0]=inv[0]=1;
	for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	for (int i=1;i<=n;i++) inv[i]=fp(fac[i],mod-2);
}
int main()
{
	scanf("%d%d",&n,&m);
	pre(std::max(n,m));
	for (int i=1;i<=n;i++) scanf("%d",&f[i]);
	std::sort(f+1,f+n+1);
	for (int i=1;i<=n;i++) ans=(ans+f[i]*c(i-1,m-1))%mod;
	for (int i=1;i<=n;i++) ans=(ans-f[i]*c(n-i,m-1)+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

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

int main()
{
	string  n;
	cin >> n;
	long long sum = 0;
	for(long long i = 0; i < n.length(); i++)
	sum += n[i]-'0';
	if(sum % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3724
#include <iostream>
using namespace std;
int main() 
{
    long a, b, c, d, tmp;
    while (std::cin >> a >> b) {
    	d = a * b;
		if(a < b) {
            tmp = a;
            a = b;
            b = tmp;
        }
 
    c = a % b;
    while(c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
    cout << b << " " << d / b << endl;
    }
       return 0;
}


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

void dfs(ll &n,vector<vector<ll>> &f,vector<ll> &group,ll k,ll &g){
  ll i;
  for(i=0;i<f.at(k).size();i++){
    if(group.at(f.at(k).at(i))==10000000){
      group.at(f.at(k).at(i))=g;
      dfs(n,f,group,f.at(k).at(i),g);
    }
  }
}

int main(){
  ll n,m,a,b,i,big=10000000;
  cin >> n >> m;
  vector<vector<ll>> f(n,vector<ll>(0));
  vector<ll> group(n,10000000);
  for(i=0;i<m;i++){
    cin >> a >> b;
    a--;
    b--;
    f.at(a).push_back(b);
    f.at(b).push_back(a);
  }
  
  for(i=0;i<n;i++){
    if(group.at(i)==big){
      group.at(i)=i;
      dfs(n,f,group,i,i);
    }
  }
  
  vector<ll> x(n);
  ll maxx=1;
  for(i=0;i<n;i++){
    x.at(group.at(i))++;
  }
  for(i=0;i<n;i++){
    maxx=max(maxx,x.at(i));
  }
  cout << maxx << endl;
}

Measured memory_bytes: 32660
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;


int main() {
  int n, m;

  while (cin >> n >> m && n != 0) {
    int a[n];
    R(i,0,n) {
      cin >> a[i];
    }
    int ans = 0, sum = 0;
    R(i,0,n-1) {
      R(j,i+1,n) {
        sum = a[i] + a[j];
        if (sum <= m) {
          ans = max(ans, sum);
        }
      }
    }
    if (ans != 0) {
      cout << ans << endl;
    } else {
      cout << "NONE" << endl;
    }
  }
}



Measured memory_bytes: 3084
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw/say/;

my ($H, $W, $N) = split(/ /, <STDIN>);
my %counts;
for (1..$N) {
    my ($i, $j) = split(/ /, <STDIN>);
    --$i;
    --$j;
    for my $di (-1..1) {
        for my $dj (-1..1) {
            my ($ci, $cj) = ($i + $di, $j + $dj);
            next if $ci - 1 < 0 || $ci + 1 >= $H;
            next if $cj - 1 < 0 || $cj + 1 >= $W;
            ++$counts{"$ci:$cj"};
        }
    }
}


my @ret = (0) x 10;
++$ret[$_] for values %counts;
my $sum = 0;
$ret[0] = ($H - 2) * ($W - 2) - scalar(keys(%counts));
say $_ for @ret;


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

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


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    res = 0
    for a in range(N):
        f = True
        for i in range(N):
            for j in range(N):
                if S[(i - a) % N][j] != S[(j - a) % N][i]:
                    f = False
        if f:
            res += N
    print(res)


if __name__ == "__main__":
    main()


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

int ans = 0;
vector<vector<int>> field;
vector<bool> visited;

void dfs(int x, int remain);

int main() {
    int n, m, a, b;
    cin >> n >> m;
    vector<vector<int>> path(n);
    visited.resize(n);
    fill(visited.begin(), visited.end(), false);
    rep(i, m) {
        cin >> a >> b;
        path.at(a - 1).push_back(b - 1);
        path.at(b - 1).push_back(a - 1);
    }
    field = path;
    dfs(0, n - 1);
    cout << ans << endl;
}

void dfs(int x, int remain) {
    if(remain == 0) {
        ans++;
        return;
    }
    visited.at(x) = true;
    rep(i, field.at(x).size()) {
        if(!visited.at(field.at(x).at(i))) dfs(field.at(x).at(i), remain - 1);
    }
    visited.at(x) = 0;
    return;
}



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

const double PI=3.141592653589793;

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  sort(p.begin(), p.end());
  int cnt = 0;
  rep(i, k) cnt += p[i];
  cout << cnt << endl;

  return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int i =0;
  int cnt =0;
  int j = n-1;
  while(i < j){
         if(s[i]!=s[j])
          cnt++;
       i++;
       j--;
  }
  
  cout << cnt;
  return 0;

}












Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    long long t1 = 60 * H1 + M1;
    long long t2 = 60 * H2 + M2;
    cout << t2 - K - t1 << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    map<int,int> amap;
    for(int i=0;i<n;i++){
        int ai;
        cin>>ai;
        amap[ai]++;
    }
    vector<int> asort;
    for(const auto& item:amap){
        asort.push_back(item.second);
    }
    sort(asort.begin(),asort.end());
    int val=amap.size();
    int ans=0;
    int index=0;
    while(val>k){
        ans+=asort[index];
        val--;
        index++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

const int mxN = 1e5;

vector<int> g[mxN + 1];
map<int, int> parent;
int visited[mxN + 1], n, m;

void bfs(int src)
{
    queue<int> q;
    q.push(src), visited[src] = 1;

    while (!q.empty())
    {
        int f = q.front();
        q.pop();
        for (auto ch : g[f])
            if (!visited[ch])
                parent[ch] = f, q.push(ch), visited[ch] = 1;
    }
}
void solve()
{
    cin >> n >> m;
    for (int x, y, i = 0; i < m; i++)
        cin >> x >> y, g[x].push_back(y), g[y].push_back(x);

    bfs(1);

    if (parent.size() != (n - 1))
        cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
        for (auto el : parent)
            cout << el.second << endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  ll h, w;
  cin >> h >> w;

  for (long long i = 0; i < h; i++) {
    vector<char> c(w);
    for (long long j = 0; j < w; j++) {
      cin >> c.at(j);
    }

    for (auto x : c) {
      cout << x;
    }
    cout << endl;
    for (auto x : c) {
      cout << x;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);

			 System.out.println(a>=13?b:a>=6?b/2:0);
		}
	}
}

Measured memory_bytes: 25252
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	map<string,int>mp;
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		mp[s]++;
	}
	int ma=0;
	for(auto u:mp) if(u.second>ma)ma=u.second;
	for(auto u:mp)if(u.second==ma) cout<<u.first<<endl;
    return 0;
}

Measured memory_bytes: 27264
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    
    ll ans=0;
    ll r=0,g=0,b=0;
    for(auto u:s)
    {
        if(u=='R')
            r++;
        else if(u=='G')
            g++;
        else
            b++;
    }
    ans=r*g*b;
    // cout<<ans<<endl;
    ll res=0;
    for(int l=1;l<=(n-1)/2;l++)
    {
        for(int i=0;i<n-2*l;i++)
        {
            if(s[i]!=s[i+l]&&s[i]!=s[i+2*l]&&s[i+l]!=s[i+2*l])
            {
                res++;
            }
        }
    }
    cout<<ans-res<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3664
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let as' = Array.make n 0 in
  Array.iteri (fun i a -> as'.(a - 1) <- i + 1) as_;
  Array.iter (Printf.printf "%d ") as';
  print_newline ()


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

using namespace std;

//#define PRAGMA 448
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#ifdef LUCARIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif

typedef int intt;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define fs first 
#define sd second 
#define mp make_pair    
#define endl "\n"

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define ing(g,u,v)  g[u].pb(v); g[v].pb(u);
#define ingp(g,u,v,c) (g[u].pb({v,c});g[v].pb({u,c});)
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())
#define sfind(s,t) (s.find(t) != string::npos)

#define infll (ll)1e15
#define infi  (int)(1e9+1)
#define PI 3.14159265359 
#define mod (ll)(1e9+7)
#define eps  1e-6

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

int n;
int a[3001];
int dp[3001][3001][2];

int solve(int i, int j, bool b){
    if(i == j)return !b ? a[i] : -a[i];
    int &r = dp[i][j][b];
    if(~r)return r;
    
    if(b){
        return r = min(-a[i]+solve(i+1,j,!b),-a[j]+solve(i,j-1,!b));
    }else{
        return r = max(solve(i+1,j,!b)+a[i],solve(i,j-1,!b)+a[j]);
    }
}


int32_t main(int32_t argc, char const *argv[]){
    FIN;
    mm(dp,-1);
    int n; cin>>n;
    fore(i,0,n)cin>>a[i];
    cout<<solve(0,n-1,false)<<endl;


    return 0;
}



















Measured memory_bytes: 141184
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

# Segment Tree
class SegmentTree:
    def __init__(self, N):
        self.size = 2 ** (N-1).bit_length()# 要素数を超える最小の2べき
        self.dat = [0] * (2*self.size)
    
    def update(self,i,x):# i番目の文字がxになる
        i += self.size
        self.dat[i] = 1 << ord(x)-ord('a')
        while i > 0:# 上まで更新していく
            i >>= 1
            self.dat[i] = self.dat[i*2] | self.dat[i*2+1]

    def fold(self, l, r):
        l += self.size
        r += self.size
        vl = 0
        vr = 0
        while l < r:
            if l & 1:
                vl |= self.dat[l]
                l += 1
            if r & 1:
                r -= 1
                vr |= self.dat[r]
            l >>= 1
            r >>= 1
        # print(bin(vl | vr))
        return bin(vl | vr).count('1')

def main():
    N = int(input())
    S = list(input())
    sg = SegmentTree(N)
    for i in range(N):
        sg.update(i,S[i])
    
    Q = int(input())
    for _ in range(Q):
        Query = input().split()
        if Query[0] == '1':
            sg.update(int(Query[1])-1, Query[2])
        else:
            res = sg.fold(int(Query[1])-1, int(Query[2]))
            print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 110452
#include <iostream>
#include <algorithm>
 
using namespace std;
 
struct Crop{
    double inc;
    string name;
 
    bool operator < (const Crop &c)const{
	if(c.inc != inc){
	    return c.inc < inc;
	}else{
	    return c.name > name;
	}
    }
};
 
int main(){
    int n,P,A,B,C,D,E,F,S,M;
    string L;
 
    while(cin >> n, n){
	Crop data[n];
 
	for(int i = 0 ; i < n ; i++){
	    cin >> L >> P >> A >> B >> C 
		>> D >> E >> F >> S >> M;
 
	    int Time = A + B + C + D + E;
	    Time += (M-1) * (D + E);
	    S = S*M*F;
 
	    data[i].name = L;
	    data[i].inc = (double)(S-P) / Time;
	}
 
	sort(data,data+n);
 
	for(int i = 0 ; i < n ; i++){
	    cout << data[i].name << endl;
	}
	cout << "#" << endl;
    }
    return 0;
}

Measured memory_bytes: 3132
// コッホ曲線
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

typedef struct st
{
    double x;
    double y;
}st_Coordinate;

void Koch_curve(st_Coordinate p1, st_Coordinate p2, int n);

int main(void)
{
    int n;
    st_Coordinate st_start, st_end;

    st_start.x = 0; st_start.y = 0;
    st_end.x = 100; st_end.y = 0;

    scanf("%d", &n);

    if( n > 0 )
    {
        // コッホ曲線の作成
        Koch_curve(st_start, st_end, n);
        // 求めた点の2重表示を防ぐため、最後の点だけ別に表示
        printf("%lf %lf\n", st_end.x, st_end.y);
    }
    else
    {
        printf("%lf %lf\n", st_start.x, st_start.y);
        printf("%lf %lf\n", st_end.x, st_end.y);
    }

    return 0;
}

// コッホ曲線を作成する関数
// p1 : 左端の点の座標
// p2 : 右端の点の座標
// count : 関数のcall回数
void Koch_curve(st_Coordinate p1, st_Coordinate p2, int n)
{
    double split_x, split_y;
    st_Coordinate s, t, u;

    if( n <= 0 )
    {
        // call回数が規定値に到達した
        return;
    }

    split_x = ( p2.x - p1.x ) / 3.0;
    split_y = ( p2.y - p1.y ) / 3.0;

    // 左端の座標
    s.x = p1.x + split_x;
    s.y = p1.y + split_y;
    // 右端の座標
    t.x = p2.x - split_x;
    t.y = p2.y - split_y;

    // 正三角形の頂点の座標 ( t を s の周りに60°だけ回転させる)
    u.x = ( cos( M_PI / 3.0 ) * ( t.x - s.x ) )
            + ( ( -1 ) * sin( M_PI / 3.0 ) * ( t.y - s.y ) ) + s.x;

    u.y = ( sin( M_PI / 3.0 ) * ( t.x - s.x ) )
            + ( cos( M_PI / 3.0 ) * ( t.y - s.y ) ) + s.y;

    // nの減算
    n--;

    if( n > 0 )
    {
        Koch_curve(p1, s, n);
        Koch_curve(s, u, n);
        Koch_curve(u, t, n);
        Koch_curve(t, p2, n);
    }
    else
    {
        // 座標の表示
        printf("%lf %lf\n", p1.x, p1.y);
        printf("%lf %lf\n", s.x, s.y);
        printf("%lf %lf\n", u.x, u.y);
        printf("%lf %lf\n", t.x, t.y);
        //printf("%lf %lf\n", p2.x, p2.y);
    }

    return;
}



Measured memory_bytes: 3220
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    Int K, N; cin >> K >> N;
    vector<Int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    Int ans = 0;
    for (int i = 0; i < N-1; i++) {
        ans = max(A[i+1] - A[i], ans);
    }
    ans = max(A[0] + (K - A[N-1]), ans);
    ans = K - ans;
    cout << ans << endl;


}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return

int main(){
    CIN(N);CIN(A);CIN(B);
    Yes(N+A>=B);
    return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    private void ShowArray(int[] n)
    {
        for (int i = 0; i < n.Length; i++)
            Console.Write(n[i] + "　");
        Console.WriteLine();
    }
    public static void Main()
    {
        //Program prog = new Program();
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int k = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = int.Parse(str[i]);
        Array.Sort(a);
        //prog.ShowArray(a);
        int kinds = 1;
        if (n != 1)
            for (int i = 0; i < a.Length - 1; i++)
                if (a[i] != a[i + 1])
                    kinds++;
        int[] num = new int[kinds];
        if (n == 1)
            num[0] = 1;
        else
        {
            int c = 0;
            int d = -1;
            for (int i = 0; i < a.Length - 1; i++)
            {
                if (a[i] != a[i + 1])
                {
                    num[c] = i - d;
                    d = i;
                    c++;
                }
            }
            num[kinds - 1] = a.Length - 1 - d;
        }
        //prog.ShowArray(num);
        Array.Sort(num);
        //prog.ShowArray(num);
        int sum = 0;
        if (kinds != k)
            for (int i = 0; i < kinds - k; i++)
                sum += num[i];
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 31068
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, h, a[100005], b[100005], ma, sb, ans;
int main() {
	int i;
	scanf("%d%d", &n, &h);
	for(i=0; i<n; i++) {
		scanf("%d%d", &a[i], &b[i]);
		ma = max(ma, a[i]);
	}
	sort(b, b+n);
	for(i=n-1; i>=0; i--) {
		ans++;
		h -= max(b[i], ma);
		if(h<=0) break;
	}
	if(h>0) {
		ans += (h+ma-1)/ma;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
N,M,K=map(int,input().split())
mod=998244353

#階乗と階乗逆元
fact=[0]*220000
invfact=[0]*220000
fact[0]=1
for i in range(1,220000):
    fact[i]=fact[i-1]*i%mod
invfact[220000-1]=pow(fact[220000-1],mod-2,mod)
for i in range(220000-2,-1,-1):
    invfact[i]=invfact[i+1]*(i+1)%mod

#↑を用いたnCk
def nCk(n,k):
    if k<0 or n<k:return 0
    return fact[n]*invfact[k]*invfact[n-k]%mod

ans=0
for i in range(K+1):
    ans+=M*pow(M-1,N-i-1,mod)*nCk(N-1,i)%mod

print(ans%mod)

Measured memory_bytes: 74792
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N, K;
	scanf("%d %d", &N, &K);
	
	int i;
	long long ans = K;
	for (i = 1; i < N; i++) ans *= K - 1;
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N >> M;
	vector<ll> A(N + 1), sum(N + 1,0);
	unordered_map<ll, ll>m;
	m[0]++;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		sum[i] = sum[i - 1] + A[i];
		sum[i] %= M;
		m[sum[i]]++;
	}
	for (auto it = m.begin(); it != m.end(); it++) {
		pair<ll, ll>item = *it;
		ans += item.second*(item.second - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5260
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{
    public void AtCoder()
    {
        string[] s;
        s = Console.ReadLine().Split(' ');

        int h, w, n;
        h = int.Parse(s[0]);
        w = int.Parse(s[1]);
        n = int.Parse(s[2]);

        s = Console.ReadLine().Split(' ');
        int x, y;
        y = int.Parse(s[0]);
        x = int.Parse(s[1]);

        string a = Console.ReadLine();
        string b = Console.ReadLine();

        char[] d1 = new char[n+1];
        char[] d2 = new char[n+1];
        for(int i=0; i<n; i++)
        {
            d1[i + 1] = a[i];
            d2[i + 1] = b[i];
        }

        int[] dpl = new int[n+1];
        int[] dpr = new int[n+1];
        int[] dpu = new int[n+1];
        int[] dpd = new int[n+1];

        dpl[0] = x; dpr[0] = x;
        dpu[0] = y; dpd[0] = y;

        bool f = true;
        for(int i=1; i<=n; i++)
        {
            dpl[i] = dpl[i - 1];
            dpr[i] = dpr[i - 1];
            if (d1[i] == 'L') dpl[i]--;
            if (dpl[i] < 1) f = false;
            if (d1[i] == 'R') dpr[i]++;
            if (dpr[i] > w) f = false;
            if (d2[i] == 'L' && dpr[i] > 1) dpr[i]--;
            if (d2[i] == 'R' && dpl[i] < w) dpl[i]++;
        }
        for (int i = 1; i <= n; i++)
        {
            dpu[i] = dpu[i - 1];
            dpd[i] = dpd[i - 1];
            if (d1[i] == 'U') dpu[i]--;
            if (dpu[i] < 1) f = false;
            if (d1[i] == 'D') dpd[i]++;
            if (dpd[i] > h) f = false;
            if (d2[i] == 'U' && dpd[i] > 1) dpd[i]--;
            if (d2[i] == 'D' && dpu[i] < h) dpu[i]++;
        }

        if (f) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


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

int main() {
    string targetStr;
    cin >> targetStr;

    int counter = 0;
    while (targetStr.size() > counter) {
        if (targetStr[counter] == '?') {
            targetStr[counter] = 'D';
        }
        counter++;
    }

    cout << targetStr << endl;
}

Measured memory_bytes: 3752
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define REP(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> x, std::vector<long long> y){
    vll seq(N);
    ll total = 1;
    REP(i, N){
        seq[i] = i;
        total *= i+1;
    }
    double tmp = 0.0;
    do{
        REP(i, N-1){
            ll j1 = seq[i], j2 = seq[i+1];
            tmp += sqrt( (double) (x[j1]-x[j2])* (double) (x[j1]-x[j2]) + (double)(y[j1]-y[j2])* (double)(y[j1]-y[j2]) );
        }
    }while(next_permutation(seq.begin(), seq.end()));

    cout << setprecision(14) << tmp / (double)total << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
n, m=map(int, input().split())
p=[0]+list(map(int, input().split()))

par=[i for i in range(n+1)]
cnt=0
def root(i):
    if par[i]==i:
        return i
    else:
        par[i]=root(par[i])
        return par[i]


for i in range(m):
    x, y=map(int, input().split())
    if root(x)==root(y):
        0
        #print(par[1:])
    else:
        par[root(y)]=root(x)
        #print(par[1:])

ans=0
for i in range(n):
    n=1+i
    if root(n)==root(p[n]):
        ans=ans+1
print(ans)
'''
print(par[1:])

root_ls=[0]+[root(i+1) for i in range(n)]
print(par[1:])
print(root_ls[1:])
'''


Measured memory_bytes: 129388
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mp make_pair
#define all(a) (a).begin(), (a).end()

int main(){
    int n;
    string s;
    cin >> n >> s;
    int m = s.size();
    rip(i,m,0){
        s[i] = char((s[i] - 'A' + n) % 26 + 'A');
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int s,a,b;
	while(~scanf("%d%d",&a,&b))
	{
		if(b*2<a)
		s=a-b*2;
		else
		s=0;
		printf("%d\n",s);
	}
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  string s;
  while (getline(cin, s), !(s.length() == 1 && s[0] == '.')) {
    int n = s.length();
    vector<int> imos_m(105, 0), imos_k(105, 0);
    REP(i, n) {
      if (s[i] == '(') imos_m[i + 1]++;
      if (s[i] == ')') imos_m[i + 1]--;
      if (s[i] == '[') imos_k[i + 1]++;
      if (s[i] == ']') imos_k[i + 1]--;
    }
    REP(i, 104) {
      imos_m[i + 1] += imos_m[i];
      imos_k[i + 1] += imos_k[i];
    }
    bool ans = true;
    REP(i, 105) {
      if (imos_m[i] < 0) ans = false;
      if (imos_k[i] < 0) ans = false;
    }
    if (imos_m[104] != 0) ans = false;
    if (imos_k[104] != 0) ans = false;
    REP(l, 105) REP(r, 105) {
      if (l >= r) continue;
      if (l - 1 < 0) continue;
      if (105 <= r) continue;
      if (imos_m[l - 1] < imos_m[l] && imos_m[r - 1] > imos_m[r] && imos_m[l] == imos_m[r - 1] && imos_k[l] != imos_k[r - 1]) ans = false;
      if (imos_m[l] > imos_m[r]) break;
    }
    REP(l, 105) REP(r, 105) {
      if (l >= r) continue;
      if (l - 1 < 0) continue;
      if (105 <= r) continue;
      if (imos_k[l - 1] < imos_k[l] && imos_k[r - 1] > imos_k[r] && imos_k[l] == imos_k[r - 1] && imos_m[l] != imos_m[r - 1]) ans = false;
      if (imos_k[l] > imos_k[r]) break;
    }
    cout << ((ans) ? "yes" : "no") << endl;
  }
}



Measured memory_bytes: 3140
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <complex>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
 
#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back
#define ll long long
 
const long long MAXN = 1e7 + 1;
const long long MOD = 1e9 + 7;
using namespace std;
 
typedef pair<int, int> pii;
 
 
long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

#define int ll

int mx = 0;
int ver = 0;

vector <int> g[MAXN];

void dfs(int v, int par, int deg) {
    if (mx < deg) {
        mx = deg;
        ver = v;
    }
    for (int i : g[v]) {
        if (i == par) continue;
        dfs(i, v, deg + 1);
    }
}

 main(){
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 1; i < n; i++) {
        int u = readInt(), v = readInt();
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1,0,0);
    mx = 0;
    int kek = ver;
    ver = 0;
    dfs(kek,0,0);
    cout << (mx % 3 == 1 ? "Second" : "First");
    return 0; 
}


Measured memory_bytes: 250240
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(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)]

N = I()
d = LI()
d = sorted(d)

left = d[len(d)//2 - 1]
right = d[len(d)//2]

print(right - left)


Measured memory_bytes: 53008