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

typedef long long int ll;

#define mod 1000000007
#define pb push_back
#define prt1(a) cout<<a<<" ";
#define prt2(a,b) cout<<a<<" "<<b<<" ";
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" ";
#define rep(i,st,end) for(int i=st;i<(int)end;i++)
#define repv(i,st,end) for(int i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int fact(int n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}

int main()
{ 
    std::cout << std::fixed;
    std::cout << std::setprecision(10);
    int n;
    cin>>n;
    ll fac=fact(n);
    int a[n][2];
    char count='0';
    string s="";
    for(int i=0;i<n;i++){
    cin>>a[i][0];
    cin>>a[i][1];
    s+=count;
    count++;
    }
    count=0;
    long double res=0;
    do { 
        long double dis=0;
        for(int i=1;i<n;i++){
            int a1=s[i]-48,b=s[i-1]-48;
            dis+=sqrt(pow(a[b][0]-a[a1][0],2)+pow(a[b][1]-a[a1][1],2));
        }
        dis=dis/fac;
        res+=dis;
        count++;
    } while(std::next_permutation(s.begin(), s.end())); 
    cout<<res;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define db double
#define ld long double
#define pp printf
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
using namespace std;

const int N = 1e5 + 5;

char s[N];
int n, bz[27];

const int mo = 1e9 + 7;

ll ans;

void dg(int x, ll s) {
	if(x > 25) {
		ans += s;
		return;
	}
	dg(x + 1, s * bz[x] % mo);
	dg(x + 1, s);
}
int main() {
//	freopen("a.in", "r", stdin);
	scanf("%d", &n);
	scanf("%s", s + 1);
	fo(i, 1, n) bz[s[i] - 'a'] ++;
	dg(0, 1);
	pp("%lld", (ans - 1 + mo) % mo);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[50], b[50], c[50];
int dp[405][405];
const int inf=1e9;
int n,x,y;
int main()
{
	//dp[i][j] miinimum cost of mixture i j
	cin>>n>>x>>y;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];

	}
	
	for(int i=0;i<=400;i++ )
	for(int j=0;j<=400;j++)
	dp[i][j]=inf;
	
	dp[0][0]=0;
	
	for(int cur=0;cur<n;cur++)
	{
		for(int i=400;i>=a[cur];i--)
		for(int j=400;j>=b[cur];j--)
		dp[i][j]=min(dp[i][j], dp[i-a[cur]][j-b[cur]]+c[cur]);
	}
	
	int ans=inf;
	for(int i=1;max(x,y)*i<=400;i++)
	ans=min(ans, dp[i*x][i*y]);
	
	if(ans>1e8)cout<<-1;
	else cout<<ans;
	
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {
	
	ll n, m;
	cin >> n >> m;
	vector<edge> e(2*m + 1);

	repn(i, m) {
		ll u, v, s;
		cin >> u >> v >> s;
		e[i] = { i,u,v,s };
		e[m + i] = { i,v,u,s };
	}

	vector<vector<edge>> g(n+1);
	repn(i, 2 * m) {
		g[e[i].fr].push_back(e[i]);
	}

	vector<ll> dis(n + 1, -1);
	vector<ll> val(n + 1, -1);
	queue<ll> q;

	dis[1] = 0;
	val[1] = 0;
	q.push(1);

	while (!q.empty()) {
		ll v = q.front();

		q.pop();
		for (edge e : g[v]) {
			ll w = e.to;
			if (dis[w] != -1) { continue; }
			dis[w] = dis[v] + 1;
			val[w] = e.d - val[v];
			q.push(w);
		}
	}

	ll mn = -INF;
	ll mx = INF;

	repn(v, n) {

		//cout <<v<< dis[v] << val[v] << endl;
		if (dis[v] % 2 == 0) {
			mn = max(mn, -val[v]+1);
		}

		else { mx = min(mx, val[v]-1); }
	}

	ll t = -1;
	
	repn(i, m) {
		if (mx <= mn) { t = 0; break; }

		ll v = e[i].fr;
		ll w = e[i].to;

		ll gosa = e[i].d - val[v] - val[w];

		if (gosa % 2 == 1) { t = 0; break; }

		if (dis[v]%2 != dis[w]%2) {
			if (gosa!=0) { t = 0; break; }
		}

		else if (dis[v] % 2 == 0) {
			if (t == -1) {
				t = gosa / 2;
				if (t<mn || t>mx) { t = 0; break; }
			}

			else { if (gosa != t * 2) { t = 0; break; } }
		}

		else{
			if (t == -1) {
				t = -gosa / 2;
				if (t<mn || t>mx) { t = 0; break; }
			}

			else { if (gosa != -t * 2) { t = 0; break; } }
		}
	}

	if (t == 0) { cout << 0; }
	else if (t == -1) { cout << mx - mn + 1; }
	else { cout << 1; }
	

	system("PAUSE");
}


Measured memory_bytes: 19956
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define debug(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define TAU PI * 2
using ll = long long;
using ull = unsigned long long;
ll MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 1);
    a[0] = 0;
    FOR(i, 1, n + 1){
        cin >> a[i];
    }
    a.pb(0);

    int all = 0;
    for(int i = 0; i < n + 1; ++i){
        all += abs(a[i] - a[i + 1]);
    }

    for(int i = 1; i < n + 1; ++i){
        int tmp = abs(a[i - 1] - a[i + 1]);
        int cost = all - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + tmp;
        println(cost);
    }
}

Measured memory_bytes: 1656
#include <iostream>

#define ll long long
#define MOD 1000000007

ll power_mod(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  else if (n % 2)
    return x * power_mod(x, n - 1, mod) % mod;
  else
    return power_mod(x * x % mod, n / 2, mod);
}

ll facts[1000001];
ll rfacts[1000001];

ll comb(ll n, ll k) {
  if (n == 0 || k == 0 || n - k == 0) return 1;
  return (facts[n] * rfacts[k] % MOD) * rfacts[n - k] % MOD;
}

int main() {
  int upper = 1000000;

  ll f = 1;
  facts[0] = 1;
  for (int i = 1; i <= upper; i++) {
    f = f * i % MOD;
    facts[i] = f;
    rfacts[i] = power_mod(f, MOD - 2, MOD);
  }

  //ここでcomb()使った処理
  int n;
  std::cin >> n;

  ll res = 0;
  ll pre = 0;
  for (int k = (n - 1) / 2 + 1; k < n; k++) {
    ll cnt = (comb(k - 1, n - k - 1) * facts[k] % MOD) * facts[n - k - 1] % MOD;

    res = ((res + k * (cnt - pre)) % MOD + MOD) % MOD;
    pre = cnt;
  }

  std::cout << res << std::endl;

  return 0;
}

Measured memory_bytes: 16000
from itertools import accumulate

N = int(input())
L, R = [0], [0]
for i in range(N):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

L.sort(reverse=True)
R.sort()

L = list(accumulate(L))
R = list(accumulate(R))

ans = 0
for k in range(N+1):
    ans = max(ans, 2*(L[k]-R[k]))

print(ans)


Measured memory_bytes: 18624
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define _D(p) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p)<<std::endl;
#define _D2(p,q) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p) << ", " #q " = "<<(q)<<std::endl;
#define _DN(v) std::cout<<"L"<<__LINE__<<" : " #v " = ["; rep(i,(v).size()) {std::cout<<v[i]<<(i==v.size()-1?"":", ");}std::cout<<"]"<<std::endl;
#define _DNN(v) std::cout<<"L"<<__LINE__<<" : " #v " = [" << std::endl; rep(i,(v).size()) {std::cout<<"    [";rep(j,(v)[0].size()){std::cout<<v[i][j]<<(j==v[0].size()-1?"":", ");}std::cout<<"],"<<std::endl;}std::cout<<"]"<<std::endl;
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(int argc, char const *argv[]) {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> V;
    for (int i = 0; i < R; ++i) {
        int v;
        cin >> v;
        v--;
        V.push_back(v);
    }
    vector<vector<ll>> dist(N, vector<ll>(N, 1LL << 60));
    for (int i = 0; i < N; ++i) {
        dist[i][i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = dist[b][a] = c;
    }

    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    sort(all(V));
    ll ans = 1LL << 60;
    do {
        ll d = 0;
        for (int i = 0; i < R - 1; ++i) {
            d += dist[V[i]][V[i + 1]];
        }
        ans = min(ans, d);
    } while(next_permutation(all(V)));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
def isprime(n)
  return true if n==2
  return false if n==1 || n.even?

  3.step(Math.sqrt(n), 2).each{|i|
    return false if n % i == 0
  }
  return true
end

gets
n=0
isprime($_.to_i)&&n+=1 while gets
p n



Measured memory_bytes: 6944
N, A, B = map(int, input().split())

if A > B:
    print(0)
    exit()
if N==1:
    if A !=B:
        print(0)
        exit()
    else:
        print(1)
        exit()

print(A + B * (N - 1) - A * (N - 1) - B + 1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    rep(i, N - M + 1) rep(j, N - M + 1) {
        bool flag = true;
        rep(k, M) rep(l, M) {
            if (A[i + k][j + l] != B[k][l]) flag = false;
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;
int N;
int j[110000];
int kotae;

int main(){
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> j[i];
	}
	for(int i=1;i<=N;i++){
		if(i==j[i]){
			kotae ++;
			j[i+1] = 0;
		}
	}
	cout << kotae << endl;
	return 0;
}

Measured memory_bytes: 640
s = input() 
ans = 0
flag = False
s += "|"
if s[0] == ">": 
    cntl = 1
    flag = True
    need = 0
else:
    cntr = 1
for i in range(1,len(s)):
    if flag:
        if s[i] == ">":
            ans += cntl
            cntl += 1
        else:
            ans += cntl if cntl >= need else need
            flag = False
            cntr = 1
    else:
        if s[i] == "<":
            ans += cntr
            cntr += 1
        else:
            need = cntr
            flag = True
            cntl = 1
            if i == len(s)-1:
                ans += need
print(ans)
    

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define P pair <int, int>

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int H, W;
int cnt = 0;
void calc( vector <vector <bool> >& vec, int i, int j, vector <vector <int> >& dist, int n ){
	if (i == H || i == -1 || j == -1 || j == W)
		return;
	cnt++;
	if (vec[ i ][ j ] && ( dist[ i ][ j ] > n || dist[ i ][ j ] < 0 )){
		dist[ i ][ j ] = n;
		n++;
		calc( vec, i + 1, j, dist, n );
		calc( vec, i, j + 1, dist, n );
		calc( vec, i - 1, j, dist, n );
		calc( vec, i, j - 1, dist, n );
	}
}

int main( void ){
	cin >> H >> W;
	vector <vector <bool> > vec( H, vector <bool>( W ));
	rep( i, 0, H ){
		rep( j, 0, W ){
			char str;
			cin >> str;
			if (str == '.')
				vec[ i ][ j ] = true;
			else
				vec[ i ][ j ] = false;
		}
	}

	int maximum = 0;
	vector <vector <int> > dist( H, vector <int>( W ));
	queue <P> q;
	int v[ 4 ][ 2 ] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
	rep( i, 0, H ){
		rep( j, 0, W ){
			if (!vec[ i ][ j ])
				continue;
			rep( k, 0, H )
			rep( l, 0, W )
			dist[ k ][ l ] = -1;
			dist[ i ][ j ] = 0;
			q.push( P( i, j ));
			int route = 0;
			while(!q.empty()){
				P now = q.front(); q.pop();
				int d = dist[ now.first ][ now.second ] + 1;
				rep( i, 0, 4 ){
					int x = now.first + v[ i ][ 0 ], y = now.second + v[ i ][ 1 ];
					if (x == H || x == -1 || y == -1 || y == W)
						continue;
					if (vec[x][y] && dist[ x ][ y ] == -1){
						dist[ x ][ y ] = d;
						route = max( route, d );
						q.push( P( x, y ));
					}
				}
			}
			maximum  = max( maximum, route );
		}
	}
	cout << maximum << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int a, b, ans = 0;
	cin >> a >> b;
	if (a < b) {
		ans += b;
		b--;
	}
	else {
		ans += a;
		a--;
	}
	if (a < b) {
		ans += b;
		b--;
	}
	else {
		ans += a;
		a--;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]

AB.sort(key=lambda x:(x[1],x[0]))
time=0
for a,b in AB:
  if time+a>b:
    print('No')
    exit()
  time+=a
print('Yes')

Measured memory_bytes: 66876
#include <bits/stdc++.h>
using namespace std;
main()
{
  int a,b;
  cin >> a>>b;
  int s = 0;
  string h;
  for (int i = a;i<=b;i++){
    h = to_string(i);
    if(h[0]==h[4]&&h[1]==h[3])
      s++;
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
char c[1010][1010];
long long f[1010][1010];
long long mod=1e9+7;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>c[i][j];
		}
	}
	f[0][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(c[i][j]!='#')
			{
				f[i][j]=f[i][j-1]+f[i-1][j];
				f[i][j]%=mod;
			}
		}
	}
	printf("%d",f[n][m]);
	return 0;
}

Measured memory_bytes: 9216
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var n = +lines.shift();

while (n--) {
    var X = lines.shift().split('');
    var Y = lines.shift().split('');

    var dp = [];
    for (var i = 0; i <= X.length; i++) {
        dp.push([]);
        for (var j = 0; j <= Y.length; j++) {
            dp[i][j] = 0;
        }
    }

    for (var i = 0; i < X.length; i++) {
        for (var j = 0; j < Y.length; j++) {
            if (X[i] == Y[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = Math.max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    console.log(dp[X.length][Y.length]);
}

Measured memory_bytes: 62764
import java.io.*;
import java.util.*;

public class Main{
    static public void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        int X = sc.nextInt(), ans = -1;
        int maxN = Math.min(20*X,1000000);
        boolean[] visited = new boolean[maxN+1];
        for(int i=2;i<=maxN;++i){
            if(visited[i]) continue;
            if(i>=X) {
                ans = i;
                break;
            }
            for(int j=2*i; j<=maxN; j+=i) visited[j] = true;
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 25300
<?php
// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
// fscanf(STDIN, "%d %d", $N, $K);
// $a = explode(" ", trim(fgets(STDIN)));

$rest = $N % 28;
$bool = false;
for ($i = 0; $i <= $rest; $i += 4) {
	if (($rest - $i) % 7 === 0) {
		$bool = true;
	}
	if (DEBUG) {
		echo "{$i} {$bool}\n";
	}

}
echo $bool ? "Yes" : "No";

Measured memory_bytes: 4728
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
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;}
// clang-format on

ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; }

void solve(long long N, std::vector<long long> x, std::vector<long long> y) {
  vector<int> idx(N);
  rep(i, N) { idx[i] = i; }

  long double distance = 0.L;
  do {
    rep(i, N - 1) {
      ll from = idx[i];
      ll to = idx[i + 1];
      long double dx = x[from] - x[to];
      long double dy = y[from] - y[to];
      long double d = pow((dx * dx) + (dy * dy), 0.5L);
      distance += d;
    }
  } while (next_permutation(all(idx)));
  ll facn = factorial(N);
  cout << fixed << ((long double)distance / facn) << 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: 512
#include <iostream>
#include <set>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    cout << st.size() << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string w;
        cin >> w;
        map<char, ll> cnt;
        rep(i, 0, len(w)) cnt[w[i]]++;

        bool flg = true;
        for (auto x : cnt) {
                if (odd(x.second)) flg = false;
        }
        if (flg) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

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

  vector<int> a(10010);
  for (ll x=1; x*x<=n; x++) {
    for (ll y=1; x*x+y*y<=n; y++) {
      for (ll z=1; x*x+y*y+z*z+x*y+y*z+z*x<=n; z++) {
        ll t = x*x+y*y+z*z+x*y+y*z+z*x;
        a[t]++;
      }
    }
  }

  for (int i=1; i<=n; i++) {
    cout << a[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 5100
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    vl a(n);
    map<ll,ll> mp;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a.rbegin(),a.rend());
    bool flag = false;
    ll ans = 1;
    ll t = -1;
    rep(i,n){
        if(a[i] == t) continue;
        if(mp[a[i]] >= 4 && !flag){
            cout << a[i]*a[i] << endl;
            return 0;
        }else if(mp[a[i]] >= 2){
            if(flag) {
                cout << ans * a[i] << endl;
                return 0;
            }
            else{
                flag = true;
                ans *= a[i];
                t = a[i];
            }
        }
    }
    if(flag) cout << ans << endl;
    else cout << 0 << endl;
}

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

long long hoge(long long v) {
    long long ret = 0;
    if (v % 2 == 0) {
        ret ^= v;
    }
    // 0101x = 0 x
    // 01010x 1
    // 01x = 1 x
    // 010x = 0
    if (v % 4 == 1 || v % 4 == 2) {
        ret ^= 1;
    }
    return ret;
}

int main() {
    long long a, b; cin >> a >> b;
    long long ret = 0;
    if (a == b) {
        cout << a << endl;
        return 0;
    }
    ret ^= hoge(a - 1);
    ret ^= hoge(b);
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e6+50;
const ll mod=998244353;
using namespace std;
ll i,n,j,nr[nmax],x,cur,tot,sm,f[nmax],rs;
void ad(ll &x,ll y)
{
	x+=y;
	if(x>=mod)x-=mod;
	if(x<0)x+=mod;
}
ll pw(ll x,ll p)
{
	ll ans=1LL;
	while(p)
	{
		if(p&1LL)ans=(ans*x)%mod;
		x=(x*x)%mod;
		p>>=1LL;
	}
	return ans;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		nr[x]++;
	}
	for(i=1000000;i>=1;i--)
	{
		cur=tot=sm=0;
		for(j=i;j<=1000000;j+=i)
		{
			if(j>i)ad(cur,f[j]);
			x=nr[j];
			ad(sm,(((j*j)%mod)*((x*(x-1LL)/2LL)%mod))%mod);
			ad(sm,((j*x)%mod*tot)%mod);
			ad(tot,j*nr[j]%mod);
		}
		ad(sm,-1LL*cur);
		f[i]=sm;
		if(i>1)sm=sm*pw(i,mod-2LL)%mod;
		ad(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 15872
import math
import sys

n, a, b = map(int, sys.stdin.readline().rstrip().split())

if (n - 1) * b + a - (n - 1) * a - b + 1 < 0:
    print(0)
else:
    print((n - 1) * b + a - (n - 1) * a - b + 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
vector<int> G[100010];
int depth[100010];
bool check[100010];
int fen=0;
int snu=0;
 
void dfs(int p,int v){
 
  if(p<0) depth[v]=0; 
  else depth[v]=depth[p]+1;
 
  for(auto nv:G[v]){
    if(nv!=p){
      dfs(v,nv);
    }
  }
 
}
 
void black(int p,int v){
 
  ++fen;
 
  for(auto nv:G[v]){
    if(nv!=p && check[nv]==false){
      black(v,nv);
    }
  }
  
}
 
 
int main(){
 
  int N;
  cin>>N;
  for(int i=0;i<N-1;++i){
    int a,b;
    cin>>a>>b;
    --a,--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
 
  dfs(-1,0);
 
  int v=N-1;
  int d=depth[v]/2;
 
  memset(check,false,sizeof(check));
  
  while(depth[v]>d){
    bool rep=false;
    check[v]=true;
    for(auto nv:G[v]){
      if(depth[nv]<depth[v]){
        v=nv;
        rep=true;
      }
    }
    if(!rep) break;
  }
  
  black(-1,0);
  snu=N-fen;
 
  if(fen>snu) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
 
}

Measured memory_bytes: 10880
#include <stdio.h>

#define N 101
  
int A[N][N];
int f[N],d[N];
int n,t = 0,k;
int color[N];
  
 
void DFSV(int u){
  int v;
   
  color[u] = 0;
  d[u] = ++t;
   
  for(v = 1;v <= n;v++){
    if((color[v] == -1) && (A[u][v] == 1)){
      DFSV(v);
    }
  }
  color[u] = 1;
  f[u] = ++t;
}
 
void DFS(void){
  int u;
      
  for(u = 1;u <= n;u++){
    color[u] = -1;
    t = 0;
  }
      
  for(u = 1;u <= n;u++){
    if(color[u] == -1)DFSV(u);
  }      
}
 
int main(void){
  int ts,u,i,j;
      
  scanf("%d",&n);
      
  for(i = 1;j <= n;i++){
    for(j = 1;j <= n;j++){
      A[i][j] = 0;
    }
  }
  
  for(i = 1;i <= n;i++){
    scanf("%d%d",&u,&k);
    for(j = 1;j <= k;j++){
      scanf("%d",&ts);
      A[i][ts] = 1;
    }
  }

  DFS();
  for(i = 1;i <= n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include <vector>
using namespace std;
int main() {
	int n, a, ans = 0; cin >> n;
	int test[123456] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> a; test[a]++;
	}
	for (int h = 0; h < 100000; h++) {
		ans = max(ans, test[h] + test[h + 1] + test[h + 2]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
s = input()
list = [[0 for i in range(len(s) - 1)] for j in range(2**(len(s) - 1))]
for i in range(2**(len(s) - 1)):
    for j in range(len(s) - 1):
        if ((i >> j) & 1):
            list[i][j] = 1
ans = 0
for x in list:
    temp = 0
    for id in range(len(s)):
        if id == len(s) - 1 or x[id] == 1:
            temp += int(s[id]) 
            ans += temp
            temp = 0
        else:
            temp += int(s[id])
            temp *= 10
print(ans)


Measured memory_bytes: 3064
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = [0] + list(map(int, readline().split()))
    A = np.array(A)
    C = np.zeros(N + 1, dtype=np.int32)

    if A[-1] == 1:
        C[-1] == 1

    for j in range(N, 0, -1):
        cnt = np.count_nonzero(C[j::j])
        C[j] = (cnt % 2) ^ A[j]

    ans = np.sum(C)
    print(ans)
    if ans != 0:
        B = np.arange(N + 1)
        li = B[C == 1]
        print(*li, sep='\n')


main()


Measured memory_bytes: 24088
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'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'};
//cout<<""<<endl;
int main(){
  int N,K;cin>>N>>K;vi x(N);rep(i,N)cin>>x[i];
  int ans=0;
  rep(i,N){
    ans+= min(x[i],K-x[i])*2;
  }
  cout<<ans<<endl;
}







Measured memory_bytes: 256
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main(input) {
  input = myconv(input,6);
  var s = 0;
  var output = input.length;
  for(var i = 0; i < input.length; i++){
    if(input[i] == "S"){
       s++;
    }
    if(input[i] == "T"){
       if(s > 0){
          s--;
         output -= 2;
        }
    }
  }
  myout(output);
}

Measured memory_bytes: 9548
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int ans = 0;
    REP1(i,N){
        int sum = 0;
        int num = i;
        while(num > 0){
            sum += num%10;
            num /= 10;
        }
        if(sum >= A && sum <= B){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
data class Card(val suit: Char, val value: Char) {
    override fun toString(): String {
        return "$suit$value"
    }
}

fun bubbleSort(a: Array<Card>) {
    (0 until (a.size)).forEach { i ->
        ((a.size - 1) downTo (i + 1)).forEach{ j ->
            if (a[j].value < a[j - 1].value) {
                run { val t = a[j]; a[j] = a[j - 1]; a[j - 1] = t }
            }
        }
    }
}

fun selectionSort(a: Array<Card>) {
    (0 until a.size).forEach { i ->
        val minIdx = (i until a.size).minBy { a[it].value }
        minIdx?.let { val t = a[i]; a[i] = a[minIdx]; a[minIdx] = t }
    }
}

fun isStable(a: Array<Card>, b: Array<Card>) =
    (0 until a.size).all { a[it].suit == b[it].suit }

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map {
        val char = it.toCharArray()
        Card(char[0], char[1])
    }.toTypedArray()
    if (n != a.size) return

    val b = a.copyOf()

    bubbleSort(a)
    selectionSort(b)

    println(a.joinToString(" "))
    println("Stable")
    println(b.joinToString(" "))
    println(if (isStable(a, b)) "Stable" else "Not stable")
}


Measured memory_bytes: 32112
#include<iostream>
#define INF 1000000007
using namespace std;
const double pai = 3.141592653589;

int main(void){
    int a, b;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op == '?') break;
        else if(op == '+') cout << a + b << endl;
        else if(op == '-') cout << a - b << endl;
        else if(op == '*') cout << a * b << endl;
        else cout << a / b << endl;
    }
    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)

int N;

int main() {
	while (cin >> N, N) {		
		int ans = 0, f = 0;
		
		for_(i,0,N) {
			int k; cin >> k;
			if (k >= 1) ++ans;
			if (k > 1) f = 1;
		}
		
		if (f) cout << ans + 1 << endl;
		else cout << "NA" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int ans=m*(m-1)/2+n*(n-1)/2;
cout<<ans<<endl;
}



/*
 * ||||


 */

Measured memory_bytes: 3608
//
// Created by 12243 on 2017/10/28.
//

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n;
    double t[1000],v[1000],h[1000];
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>t[i];
    }t[0]=0;t[n+1]=0;
    for (int i=1;i<=n;i++){
        cin>>v[i];
        h[i]=v[i];
    }v[0]=0;v[n+1]=0;
    h[0]=0;v[n+1]=0;

    for (int i=n+1;i>=2;i--){
        if (v[i-1]>v[i])
            v[i-1]=min(v[i-1],v[i]+t[i-1]);

    }
    for (int i=0;i<=n-1;i++) {
        if (v[i + 1] > v[i])
            v[i + 1] = min(v[i + 1], v[i] + t[i + 1]);

    }
    //for (int i=1;i<=n;i++) cout<<v[i]<<" ";cout<<endl;

    double left,right,ans=0;

    for (int i=1;i<=n;i++){
        left=min(v[i-1],v[i]);
        right=min(v[i],v[i+1]);

        if (right>left) {
            double x = (t[i] + abs(right - left)) / 2.0;
            double y = (t[i] - abs(right - left)) / 2.0;
//            if (x<0||y<0)
//                cout<<left<<" "<<right<<" "<<t[i]<<endl;
//            double temp=x * x / 2.0 + y * y / 2.0 + y * (right - left) + t[i] * left;
//            cout<<temp<<"    ";
            //cout<<100.5*100.5<<" ";
            ans += x * x / 2.0 + y * y / 2.0 + y * (right - left) + t[i] * left;
            if (h[i] < left + x) {
                double l = x + left - h[i];
                ans -= l * l;
            }
        }else{

            double y = (t[i] + abs(right - left)) / 2.0;
            double x = (t[i] - abs(right - left)) / 2.0;
//            if (x<0||y<0)
//                cout<<left<<" "<<right<<" "<<t[i]<<endl;
//            double temp=x * x / 2.0 + y * y / 2.0 + y * (right - left) + t[i] * left;
//            cout<<temp<<"";
            //cout<<x<<" ";

            ans += x * x / 2.0 + y * y / 2.0 + x * (left - right) + t[i] * right;
            if (h[i] < left + x ){
                double l=x+left-h[i];
                ans-=l*l;
            }
        }
        //cout<<ans<<endl;
    }

    //cout<<ans;
    printf("%lf",ans);
}

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

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

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

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

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

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>A(M);
	vector<int>B(M);
	for (int n = 0; n < M; ++n) {
		cin >> A[n] >> B[n];
		--A[n];
		--B[n];
	}
	int count = 0;
	{
		UnionFind uf(N);
		for (int n = 0; n < M; ++n) {
			uf.merge(A[n], B[n]);
		}
		set<int>st;
		for (int n = 0; n < N; ++n) {
			st.insert(uf.root(n));
		}
		count = st.size();
	}
	int ans = 0;
	for (int i = 0;i<M;++i) {
		UnionFind uf(N);
		for (int n = 0; n < M; ++n) {
			if (n==i) {
				continue;
			}
			uf.merge(A[n], B[n]);
		}
		set<int>st;
		for (int n = 0; n < N; ++n) {
			st.insert(uf.root(n));
		}
		if (count != st.size()) {
			ans++;
		}
	}
	cout << ans <<endl;
}


Measured memory_bytes: 3604
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        Map<Integer,Integer> map = new HashMap<>();
        int a = s;
        int idx = 1;
        while(a<=1000000){
            if(!map.containsKey(a)){
                map.put(a,idx);
            }else{
                System.out.println(idx);
                return;
            }
            idx++;
            if(a%2==0){
                a/=2;
            }else{
                a = 3*a+1;
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 23124
/**/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,ans=-1;cin>>n;
	std::vector<set<ll> > a(n+1);
	for (int i = 0; i < n; ++i)
	{
		ll x;cin>>x;
		a[x].insert(i+1);
	}
	ll z=0,f=0;
	//cout<<a[1].size();
	for (int i = 1; i < n+1; ++i)
	{
		if(a[i].size()==0){
			f=i-1;
			break;
		}
		else {
			set<ll>::iterator it=a[i].upper_bound(z);
		//	cout<<*it<<" its\n";
			if(it==a[i].end()){
				f=i-1;
				break;
			}
			else {
				z=*it;
				//cout<<"abc";
			}
		}
		if(i==n)f=n;
	}
	if(f==0)cout<<-1;
	else
	cout<<n-f;
}

Measured memory_bytes: 19072
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	int stmp = 0;

	for (int i = 0; i < n - 1; i++)
	{
		string tmp2 = s.substr(i, ans);
		for (int j = i + 1; j < n - ans; j++)
		{
			string tmp = s.substr(j, ans);

			if (tmp == tmp2)
			{
				for (int k = ans; k < j - i; k++)
				{
					if (i + k < j && s[i + k] == s[j + k] && j + k < n)
					{
						stmp++;
						tmp2.push_back(s[i + k]);
					}
					else
					{
						break;
					}
				}
			}
			ans += stmp;
			stmp = 0;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 1011;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::wlnn;
using IO::read;

namespace Cesare {
	
	ll n, k, A, m;
	
	vector <ll> E[N];
	
	int main() {
		n = read(), k = read();
		A = (n - 1) * (n - 2) >> 1;
		if (A < k) return puts("-1"), 0;
		For ( i, 2, n ) E[i].push_back(1), ++m;
		ll I = 2, J = 3;
		while (A > k) {
			--A, ++m;
			E[I].push_back(J++);
			if (J == n + 1) ++I, J = I + 1;
		} 
		wln(m);
		For ( u, 1, n ) For ( i, 1, E[u].size() ) 
			wlnn(u, E[u][i - 1]);
		return 0;
	}
	
}

int main()
{
	return Cesare::main();
}

/*
6 10
*/






Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int n,k;
double qp(double x,int m)
{
    double re=1.;
    while(m)
    {
        if(m&1) re*=x;
        x*=x;
        m>>=1;
    }
    return re;
}
int main()
{
    cin>>n>>k;
    double ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i>=k)
        {
            ans+=1.;
            continue;
        }
        int xx=(int)ceil(log2(ceil(1.*k/i)));
        ans+=1./(qp(2.,xx));
    }
    printf("%.10f\n",ans/n);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int nowx,nowy;
bool houseki[25][25];
int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		REP(i,25) REP(j,25) houseki[i][j] = false;
		REP(i,n){
			int tx,ty;
			cin >> tx >> ty;
			houseki[tx][ty] = true;
		}
		int m;
		cin >> m;
		int get = 0;
		nowx = 10; nowy = 10;
		if(houseki[nowx][nowy]) {
			get++;
			houseki[nowx][nowy] = false;
		}
		REP(i,m){
			char vec; int dis;
			cin >> vec >> dis;
			int oldx = nowx; int oldy = nowy;
			if(vec=='N') nowy+=dis;
			if(vec=='S') nowy-=dis;
			if(vec=='W') nowx-=dis;
			if(vec=='E') nowx+=dis;
			if(nowy == oldy){
				if(nowx<oldx){
					FOR(j,nowx,oldx+1){
						if(houseki[j][nowy]) {
							houseki[j][nowy] = false;
							get++;
						}
					}
				}else{

					FOR(j,oldx,nowx+1){
						if(houseki[j][nowy]) {
							get++;
							houseki[j][nowy] = false;
						}
					}
				}
			}else{
				if(nowy<oldy){
					FOR(j,nowy,oldy+1){
						if(houseki[nowx][j]) {
							get++;
							houseki[nowx][j] = false;
						}
					}
				}else{
					FOR(j,oldy,nowy+1){
						if(houseki[nowx][j]) {
							get++;
							houseki[nowx][j] = false;
						}
					}
				}
			}
			//cout << nowx << " " << nowy<<endl;
		}
		if(get==n) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 1152
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const N = nextInt()
    let x = []
    let y = []
    while(hasNext()){
        let tmp = nextIntArray()
        x.push(tmp[0])
        y.push(tmp[1])
    }
    let pat = []
    const gen = function(sub, used){
        if(sub.length == N){
            pat.push([...sub])
        }
        for(let i = 0;i<N; i++){
            if(used.has(i)) continue
            used.add(i)
            gen([...sub, i], used)
            used.delete(i)
        }
    }
    gen([], new Set())
    let ans = 0
    for(let el of pat){
        let tmp = 0
        for(let i = 1; i<el.length; i++){
            let curr = el[i]
            let prev = el[i-1]
            tmp += Math.sqrt( (x[curr]-x[prev])**2 + (y[curr]-y[prev])**2)
        }
        ans += tmp
    }
    console.log(ans / pat.length)
}
Main()


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int num = 1;
    vector<int> b;
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == num)
        {
            b.push_back(a[i]);
            num++;
        }
    }
    int ans = n - b.size();
    if (b.size() > 0)
        cout << ans << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 5100