akhauriyash/Code-Regression huggingface dataset:
/*
    five_variables.c
    2020/06/14
*/

#include <stdio.h>

int main()
{
    int i;
    int x[5];
    for(i = 0; i < 5; i++ ){
        scanf("%d", &x[i]);
        if(x[i] == 0) 
            break;
    }
    printf("%d\n", i + 1);
}


Measured memory_bytes: 1732
h,w = map(int,input().split())
area =[input() for i in range(h)]

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


for i in range(h):
  for j in range(w):
    if area[i][j] == '#':
      f = 0
      for x, y in xy:
        if 0 <= i + y < h and 0 <= j + x < w and area[i+y][j+x]=="#":
          f=1
      if f == 0:
        print('No')
        exit()

print('Yes')



Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.next());
        String str = sc.next();
        int num2 = Integer.parseInt(sc.next());
        String targetValue = str.substring(num2 -1,num2);

        String tmpValue = "";
        for (int i = 0; i < str.length(); i++) {
            tmpValue = String.valueOf(str.charAt(i));
            if (!targetValue.equals(tmpValue)) {
                str = str.replace(tmpValue,"*");
            }
        }
        System.out.println(str);
    }
}


Measured memory_bytes: 21588
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int x;cin>>x;
    if(x==5||x==3||x==7)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main(){
  int N;
  cin >> N;
  bool a=false;
  while(N){
    if(N%10==7){
      a=true;
    }
    N/=10;
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
    

Measured memory_bytes: 3628
#include <stdio.h>
int main (void){
    int n,m,e,j,i;
    for(;;){
        scanf("%d",&n);
        if(n==0)break;
        for(i=0;i<n;i++){
            scanf("%d%d%d",&m,&e,&j);
            if(m==100||e==100||j==100){
                printf("A\n");
            }
            else if((m+e)/2>=90){
                printf("A\n");
            }
            else if((m+e+j)/3>=80){
                printf("A\n");
            }
            else if((m+e+j)/3>=70){
                printf("B\n");
            }
            else if((m+e+j)/3>=50&&m>=80||e>=80){
                printf("B\n");
            }
            else printf("C\n");
        }
    }
return 0;
}

Measured memory_bytes: 580
import sys


def main():
    N, T, *AB = map(int, sys.stdin.buffer.read().split())
    D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    D.sort()

    dp = [0] * T
    ans = 0

    for i, (a, b) in enumerate(D[:-1]):
        for t in range(T - 1, a - 1, -1):
            if dp[t] < dp[t - a] + b:
                dp[t] = dp[t - a] + b
        if ans < dp[T - 1] + D[i + 1][1]:
            ans = dp[T - 1] + D[i + 1][1]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74036
#include <iostream>
//文字列
#include <string>
//配列操作
#include <algorithm>
using namespace std;

//英語を漢字に翻訳
#define 中心() main()
#define 返 return
#define 入力(a) cin >> a
#define 出力(a) cout << a << endl
#define 如果(a) if(a)
#define 他 else
#define 長(a) a.size()

//再起
#define 再帰(s,t) for(整数 s = 0; s < 整数(t); s += 1)

typedef int 整;
typedef long long 整数;
typedef string 文字;

整数 小(整数 a, 整数 b){返 min(a,b);}

整 中心(){
    文字 m;
    整数 s;
    入力(m);
    入力(s);
    整数 t = 小(長(m), s);
    再帰(a,t){
        如果(m[a] >= '2'){
            出力(m[a]);
            返 0;
        }
    }
    
    出力('1');
    返 0;
}   

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

int main()
{
    int a, b, c; cin>>a>>b>>c;
    for(int i=0; i<1000000; ++i) {
        if (a%2 or b%2 or c%2) return cout<<i<<endl, 0;
        int A=b/2+c/2;
        int B=c/2+a/2;
        int C=a/2+b/2;
        a=A, b=B, c=C;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG


int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,n){
        cin>>a[i];
    }

    ll ng=0;
    ll ok=10000000001;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        ll count=0;
        rep(i,n){
            if(count>k) break;
            count+=(a[i]+mid-1)/mid-1;
        }
        if(count<=k) ok=mid;
        else ng=mid;
    }

    cout<<ok<<endl;
}

Measured memory_bytes: 5124
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	int cnt = 0, abr = 1;
	string s;
	cin >> s;
	rep(i,n){
		if(s[i] == 'a'){
			if(cnt < a+b){
				cout << "Yes" << endl;
				++cnt;
			}
			else cout << "No" << endl;
		}
		else if(s[i] == 'b'){
			if(cnt < a+b && abr <= b){
				cout << "Yes" << endl;
				++cnt;
				++abr;
			}
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3792
D, G = map(int, input().split())
G //= 100
P = []; C = []
for i in range(D):
    p, c = map(int, input().split())
    P.append(p); C.append(c // 100)

P.reverse()
C.reverse()
ans = sum(P)
for i in range(2 ** D):
    cnt = 0
    score = 0
    for j, p in enumerate(P):
        if ((i >> j) & 1):
            score += (D - j) * p + C[j]
            cnt += p
    if score >= G:
        ans = min(ans, cnt)
    else:
        for j, p in enumerate(P):
            if ((i >> j) & 1) == 0:
                for k in range(p - 1):
                    score += (D - j)
                    cnt += 1
                    if score >= G:
                        ans = min(ans, cnt)
                        break

print(ans)


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

int main()
{
  string s, t;
  cin >> s>> t;

  vector<vector<int>> dp((int)s.length()+1, vector<int>((int)t.length()+1, 0));
  vector<vector<int>> dp_ch((int)s.length()+1, vector<int>((int)t.length()+1, 0));

  for(int i=1; i<=(int)s.length(); i++)
  {
    for(int j=1; j<=(int)t.length(); j++)
    {
      if(s[i-1] == t[j-1])
      {
        dp_ch[i][j] = 2;
        dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      }
      else
      {
        if(dp[i-1][j] > dp[i][j-1])
          dp_ch[i][j] = 1;
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
    }
  }

  string ans = "";
  for(int i=(int)s.length(),j=(int)t.length(); i>=0 && j>=0; )
  {
      if(dp_ch[i][j] == 0)
        j--;
      else if(dp_ch[i][j] == 1)
            i--;
          else if(dp_ch[i][j] == 2)
                ans = string(1, s[i-1])+ans, i--, j--;
  }

  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 70784
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	int n; cin >> n;
	cout << fixed << setprecision(12);
	double x = n / 3.0;
	cout << x * x * x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath> 
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <numeric> 
#include <iomanip>
#include <map> 
#include <stack>
#include <sstream>
#define sz(x) ((int)(x).size())
#define full(a) a.begin(), a.end()
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAX = 1e6;
long long max(long long a, long long b) { if (a > b)return a; else return b; }
long long min(long long a, long long b) { if (a < b)return a; else return b; }
const int MAXC = 1e5;
int a[100005];
/*int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}
std::vector<int> fractionSum(std::vector<int> a, std::vector<int> b) {
    vector<int> ne{a[0] * b[1] + b[0] * a[1], a[1] * b[1]};
    int k = gcd(ne[0], ne[1]);
    ne[0] /= k;
    ne[1] /= k;
    return ne;
}
*/
  		     	/*ll n, k;
		std::cin >>  n;
		std::vector <int> v(n);
			for (ll i = 0; i < n; i++)
			{
					std::cin >> v[i];
			}
		std::sort(v.begin(), v.end());*/
/*void sortString(string &str)
{
	sort(str.begin(), str.end());
	cout << str;
}*/


int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<pii> vp(n);
	trav(i, vp)
	{
		cin >> i.first >> i.second;
	}
	for(int i = 0; i < n-2; i++)
	{
		if (vp[i].first == vp[i].second && vp[i + 1].first == vp[i + 1].second && vp[i + 2].first == vp[i + 2].second)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout << "No" << endl;
	 return 0;
					
}

	

  

 

Measured memory_bytes: 3120
#include<iostream>

using namespace std;

int main() {
	int d, x, y, s = 0;
	while (cin >> d) {
		x = 600;
		s = 0;
		for (x -= d; x > 0; x -= d) {
			y = x * x;
			s += y * d;
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).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; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::cout << (1+N)*N/2 << std::endl;
  return 0;
}


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

int n;
string s,t;

int main() {
  cin >> n >> s >> t;
  rep(i,n)
  cout << s[i] << t[i];
  cout << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())

V_max = N // 4
V_min = N // 7

if N % 4 == 0 or N % 7 == 0:
    print('Yes')
    exit()

tmp = N
for i in range(1,V_max):
    tmp = N - i*4
    if tmp % 7 == 0:
        print('Yes')
        exit()

print('No')


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

namespace CS.Solve
{
    class Program
    {
        static void Main(string[] args)
        {
            var givenN = int.Parse(Console.ReadLine());
            var words = new List<string>();
            for(int i = 0; i < givenN; i++)
            {
                var tmp = Console.ReadLine();
                words.Add(tmp);
            }
            if (Shiritori.MatchRule(words))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

    public class Shiritori
    {
        public static bool MatchRule(List<string> words)
        {
            bool rule1 = DifferenceEachOther(words);
            bool rule2 = BeforeAfterRealtionship(words);
            return rule1 && rule2;
        }

        private static bool BeforeAfterRealtionship(List<string> words)
        {
            char x = words.First().Last();
            foreach(var tmp in words.Skip(1))
            {
                if (x != tmp.First())
                {
                    return false;
                }
                x = tmp.Last();
            }
            return true;
        }

        private static bool DifferenceEachOther(List<string> words)
        {
            return words.Count == words.Distinct().Count();
        }
    }
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

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

struct UF {
    vector<int> par, sz;

    UF(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

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

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
};

vector<bool> used;
signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        if (n == 2) {
            rep(i, 2 * n - 1) cout << i + 1 << endl;
        } else {
            used.resize(2 * n, false);
            list<int> ans;
            if (x != 2) {
                ans.push_back(x - 2), used[x - 2] = true;
                ans.push_back(x), used[x] = true;
                ans.push_back(x + 1), used[x + 1] = true;
                ans.push_back(x - 1), used[x - 1] = true;
                int cnt = 0;
                for (int i = 1; i < 2 * n; ++i) {
                    if (used[i] == false) {
                        if (cnt < n - 2) {
                            ans.push_front(i);
                        } else {
                            ans.push_back(i);
                        }
                        ++cnt;
                    }
                }
            } else {
                ans.push_back(x + 2), used[x + 2] = true;
                ans.push_back(x - 1), used[x - 1] = true;
                ans.push_back(x), used[x] = true;
                ans.push_back(x + 1), used[x + 1] = true;
                int cnt = 0;
                for (int i = 1; i < 2 * n; ++i) {
                    if (used[i] == false) {
                        if (cnt < n - 2) {
                            ans.push_back(i);
                        } else {
                            ans.push_front(i);
                        }
                        ++cnt;
                    }
                }
            }

            stl_rep(itr, ans) cout << *itr << endl;
        }
    }

    return 0;
}

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

const int N = 1299800;

bool prime[N];

void makePrime(){
    for(int i = 2; i < N; i++) prime[i] = true;
    for(int i = 2; (i * i) < N; i++){
        if(!prime[i]) continue;
        for(int j = i + i; j < N; j += i){
            prime[j] = false;
        }
    }
}

int main(){
    makePrime();
    int n;
    while(cin >>n){
        if(n == 0) break;
        if(prime[n]){
            cout <<'0' <<endl;
            continue;
        }
        int top = n, tail = n;
        while(!prime[top]) top--;
        while(!prime[tail]) tail++;
        cout <<tail - top <<endl;
    }
    return 0;
}

Measured memory_bytes: 2428
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int hoge[6][5] = {{'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','.','?','!',' '}};
  string s;
  while(cin>>s) {
    string ans;
    int i;
    for(i=0; i<s.length(); i+=2) {
      int a = s[i]-'1';
      int b = s[i+1]-'1';
      if (a<0||6<=a||b<0||5<=b) {
        ans = "NA";
        break;
      }
      ans += hoge[a][b];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N, M;
vector< vector<int> > G;
vector<int> H, color;
int itrNum[100001];
stack<int> S;
 
void dfs(int u){
    S.push(u);
    color[u] = 1;
    H[u] = 0;
 
    while(!S.empty()){
        u = S.top();  // 訪問中の頂点
        auto itr_v = next(G[u].begin(), itrNum[u]);
        itrNum[u]++;
        if(itr_v != G[u].end()){
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
                color[v] = 1-color[u];
            }
        }else{
            S.pop();
            H[u] = 1;
        }
    }
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin >> N >> M;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    color = vector<int>(N, -1);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--; b--;
 
        G[a].pb(b);
        G[b].pb(a);
    }
 
    REP(i, N) if(H[i] == -1) dfs(i);
 
    bool isBiG = true;
    REP(i, N){
        if(!G[i].empty()){
            //cout << i << " " << color[i] << " ";
            for(auto x : G[i]){
                if(color[x] == color[i]){
                    isBiG = false;
                    break;
                }
                //cout << color[x];
            }
            //cout << "\n";
        }
    }
    if(!isBiG) cout << (llint)(N-1)*N/2 - M << "\n";
    else{
        int r = 0, b = 0;
        REP(i, N){
            color[i] ? r++ : b++ ;
        }
        cout << (llint)r*b - M << "\n";
    }
    return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"(";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<")";
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

constexpr ll Ten(int n){
	return n==0?1:Ten(n-1)*10;
}

template<class T>
vector<T> Uniqued(const vector<T>&vv){
	auto v(vv);
	sort(ALL(v));
	v.erase(unique(ALL(v)),v.end());
	return v;
}
template<class T>
void MakeUniqued(vector<T>&v){
	sort(ALL(v));
	v.erase(unique(ALL(v)),v.end());
}

signed main(){
	vi deg(4);
	REP(i,3){
		int a=read()-1,b=read()-1;
		deg[a]++;
		deg[b]++;
	}
	int cnt=0;
	REP(i,4){
		cnt+=deg[i]%2;
	}
	if(cnt==2)
		Yes();
	else
		No();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
Graph G;
vector<int> result;
void dfs(int v, int p, int c) {
    result[v] = c;
    for(Edge e : G[v]) {
        if(e.first == p) {
            continue;
        }
        if(e.second % 2 == 1) {
            dfs(e.first, v, !c);
        } else {
            dfs(e.first, v, c);
        }
    }
}
int main() {
    int N;
    cin >> N;
    G.assign(N, vector<Edge>());
    for(int i = 0; i < N-1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }
    result.assign(N, 0);
    dfs(0, -1, 0);
    for(int i : result) {
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 8192
def resolve():
    n = int(input())
    for i in range(2, int(n ** 0.5) + 1)[::-1]:
        if n % i == 0:
            ans = i + n // i - 2
            print(ans)
            return 0
    print(n - 1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include <iostream>
#include <ostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

const int INF = 1000000;

int main() {
	double a, b, t;
	cin >> a >> b >> t;
	cout << (int)((t + 0.5) / a)*b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a[101][101] = {};
    int r, c;
    int i, j, k, l;
    
    scanf("%d %d", &r, &c);
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &a[i][j]);
        }
    }
    
    for(k = 0; k <= r; k++){
        for(l =0; l <= c; l++){
            if(k != r && l != c){
                a[k][c] += a[k][l];
            }if(k != r){
                a[r][l] += a[k][l];
            }if(k != r && l != c){
                printf("%d ", a[k][l]);
            }else if(l == c){
                printf("%d\n", a[k][c]);
            }else if(r == k && l != c){
                printf("%d ", a[r][l]);
            }
        }
    }return 0;
}


Measured memory_bytes: 2772
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<cctype>
#include<string>
using namespace std;
#define rep(i,a,b) for(i=a;i<=b;i++)
#define INF 2100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F1 second.first
#define F2 second.second
#define ub upper_bound
#define SS stringstream
#define sz(x) ((int)(x).size())
int main(void)
{
	int k,s,sum,cnt=0;
	int i,j;
	cin>>k>>s;
	for(i=0;i<=k;i++) {
		for(j=0;j<=k;j++) {
			if((i+j)+(s-(i+j))==s && (s-(i+j))>=0 && (s-(i+j))<=k) cnt++;
		}
	}
	cout<<cnt<<endl;
}

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

int main() {
    return ([]() {
        std::function<void()> input;
        std::vector <int> list;
        (input = [&input, &list]() {
            int data;
            if ( std::cin >> data ) {
                list.push_back( data );
                input();
            }
        })();
        ([&list]() {
            sort( list.rbegin(), list.rend() );
            for_each( list.begin(), list.begin() + 3, [](int x){ std::cout << x << std::endl; } );
        })();
        return 0;
    })();
}

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

int main(){
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
    return 0;
}


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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       s.find(x) != s.end()

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
//ll b[SZ];



int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
    //    ll a, b, d;
    string s, s1, s2;

    cin2(s, s1);

    for0(i, s.size()) {
        c += (s[i] != s1[i]);
    }

    cot1(c);

    return 0;
}



Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>

using namespace std;

#define ll long long

int main(){
   
   ll N,numE=0,ans;
   string S;
   cin>>N>>S;
   
   for(int i=0;i<N;i++)
       if(S[i]=='E')numE++;
   
   ans=numE;
   if(S[0]=='E')ans--;
   
   ll cntW=0;
   for(int i=1;i<N;i++){
       
       if(S[i-1]=='W')cntW++;
       ll tmp=cntW*2+numE-i;
       if(S[i]=='E')tmp--;
       ans=min(ans,tmp);
       
   }
   
   cout<<ans<<endl;
   
   return 0;
}

Measured memory_bytes: 900
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll mod=998244353;
 
int main(){
    ll n,k;
    cin >> n >> k;
    vector<vector<ll>> a(61,vector<ll>(n));
    
    rep(i,n){
        cin >> a[0][i];
        a[0][i]--;
    }
    vector<ll> b(61);
    ll v=1;
    rep(i,61){
        b[i]=v;
        v*=2;
    }
    for(ll i=1;i<=60;i++){
        rep(j,n){
            a[i][j]=a[i-1][a[i-1][j]];
        }
    }
    ll pos=0;
    for(ll i=60;i>=0;i--){
        if(k>=b[i]){
            pos=a[i][pos];
            k-=b[i];
        }
    }
    cout << pos+1 << endl;
    return 0;
}

Measured memory_bytes: 100148
#include <iostream>
#include <cmath>

using namespace std;

const long long int MOD=1e9+7;

int main() {
    long long int N, M;
    cin >> N >> M;
    
    if(abs(N-M)>1) {
        cout << 0 << endl;
    } else {
        long long int ans=1;
        for(int n=1; n<=N; n++) {
            ans *= n;
            ans %= MOD;
        }
        for(int m=1; m<=M; m++) {
            ans *= m;
            ans %= MOD;
        }
        
        if(N==M) {
            cout << ans*2%MOD << endl;
        } else {
            cout << ans << endl;
        }
    }


    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
#define M(x) memset(x,0,sizeof(x))
#define dalao main
using namespace std;
vector<int>v[200005];
bool vis[200005];
int ans=-1;

int dfs(int s,int num)
{
    for(int i=0;i<v[s].size();i++)
    {
        int nxt=v[s][i];
        if(!vis[nxt])
        {
            vis[nxt]=true;
            num=dfs(nxt,num+1);
        }
    }
    return num;
}

int dalao()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            vis[i]=true;
            //debug(i)
            //debug(dfs(i,1));
            ans=max(ans,dfs(i,1));
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 20896
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int a=0;
  cin >> N;
  for(int i=1;i<=N;i++){
    int j=i;
    int kai=0;
    while(j>0){
      j=j/10;
      kai++;
    }
    if(kai%2==1){
      a++;
    }
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static int r = 998244353;

	public static long mypow(long a, long b) {
		if (a == 1 || b == 0)
			return 1;
		long ans = 1;
		for (int i = 0; i < b; ++i) {
			ans *= a;
			ans %= r;
		}
		return ans;
	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long len[] = new long[n];
		for (int i = 0; i < n; ++i) {
			int tmp = sc.nextInt();
			if(i == 0){
				if(tmp != 0)len[0] = -r;
			}
			len[tmp]++;
		}
		sc.close();
		long num = len[1];
		long pre = num;
		long ans = 0;
		if (len[0] == 1) {
			ans = 1;
			for (int i = 2; i < n; ++i) {
				pre = len[i];
				long tmp = mypow(num, pre);
				ans *= tmp;
				ans %= r;
				num = len[i];
			}
		}
		System.out.println(ans);
	}
}


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

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

  if (K <= A)
    cout << K << endl;
  else if (K <= A + B)
    cout << A << endl;
  else
    cout << A - (K - A - B) << endl;

  return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;	
	ll n;
	cin>>n;
	ll minm=1+n;
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			minm=min(minm,i+n/i);
		}
	}
	cout<<minm-2;
}

Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    sieve();
    int x;
    cin >> x;
    
    while(true) {
        if(prime[x]==1) {
            cout << x;
            break;
        }
        x++;
    }
    
	return 0;
    
}

Measured memory_bytes: 12160
# 配列の各要素は関係ないことに気づく。テストケース1では[3 6 12]や[4 8 16] [5 10 15]もある。
# [X ~~ Y] のうちAを長くするには,Aiができるだけ小さいと嬉しい。
# Ai+1もできるだけ小さいと嬉しい
# なので条件を満たすAi+iはAi*2だと嬉しい

x, y = map(int, input().split())
count = 0
while x <= y:
    count += 1
    x *= 2
print(count)


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

keys = []

M.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  cs = gets.chomp.split.map(&:to_i)
  keys << [a, cs]
end

dp = [987654321] * 2**N
dp[0] = 0

keys.each do |key|
  key_bit = 0 
  key[1].each do |c|
    key_bit += 2**(c - 1)
  end
  dp.size.times do |i|
    dp[i | key_bit] = [dp[i | key_bit], dp[i] + key[0]].min
  end
end

if dp[-1] == 987654321
  puts "-1"
else
  puts dp[-1]
end


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

int B[50];

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  for (int i = 0; i < M; i++) cin >> B[i];
  int res = 0;
  for (int i = 0; i < N; i++) {
    int point = 0;
    for (int j = 0; j < M; j++) {
      int a;
      cin >> a;
      point += a * B[j];
    }
    point += C;
    if (point > 0) res++;
  }
  cout << res << endl;
}


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

int main(){
  char s;
  cin >> s;
  
  switch(s) {
    case 'A':
      cout << 'T' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
    default:
      break;
  }
  
}

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

/**
 * Created by Ayushi on 16 Feb 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();
        st = new StringTokenizer(temp, " ");
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        br.close();

        if (a == b && a != c) System.out.println("Yes");
        else if (a == c && a != b) System.out.println("Yes");
        else if (b == c && b != a) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 21204
a,b,c,d,e,f=map(int,input().split())
wans,sans,Cans=100*a,0,0
for p in range(1+(f//100*a)):
    for q in range(1+(f//100*b)):
        water=100*(a*p+b*q)
        if water>f or water==0:
            pass
        else:
            limit=(a*p+b*q)*e
            for r in range(1+(limit//c)):
                for s in range(1+(limit//d)):
                    suger=r*c+s*d
                    if water+suger>f or c*r+d*s>limit:
                        pass
                    else:
                        C=suger/(water+suger)
                        if C>=Cans:
                            wans,sans,Cans=water,suger,C
print(wans+sans,sans)

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

int main() {
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<long double> res;
    long double ans = 0;
    long double cnt = 0;

    rep(i, n) {
        cin >> x[i];
        cin >> y[i];
    }
    vector<ll> ptn(n);
    rep(i, n) ptn.at(i) = i;

    do {
        // rep(i, ptn.size()) cout << ptn.at(i) << ' ';
        // cout << endl;
        for(size_t i = 0; i < n - 1; i++) {
            res.push_back((long double)sqrt(
                pow(x.at(ptn.at(i)) - x.at(ptn.at(i + 1)), 2) +
                pow(y.at(ptn.at(i)) - y.at(ptn.at(i + 1)), 2)));
        }
        cnt++;

    } while(next_permutation(all(ptn)));

    rep(i, res.size()) {
        ans += res.at(i);
        // cout << res.at(i) << endl;
    }
    // cout << ans / cnt << endl;ac
    ans /= cnt;
    // printf("%f16", (double)ans);
    cout << fixed << setprecision(16) << ans;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n);
  rep(i,n) {
    cin>>a[i];
    a[i]--;
  }
  vi idx(n);
  rep(i,n) idx[a[i]]=i;
  set<int> s;
  ll ans=0;
  rrep(x,n){
    int i = idx[x];
    s.insert(i);
    
    vi l(2,-1), r(2,n);
    
    auto it = s.find(i);
    rep(j,2){
      if(it == s.begin()) break;
      it--;
      l[j] = *it;
    }
    it = s.find(i);
    rep(j,2){
      it++;
      if(it == s.end()) break;
      r[j] = *it;
    }
    vi ls(2), rs(2);
    ls[0]=i-l[0]; ls[1]=l[0]-l[1];
    rs[0]=r[0]-i; rs[1]=r[1]-r[0];
    
    ans+=((ll)ls[0]*rs[1]+ls[1]*rs[0])*(x+1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

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

    int cost = INF, tmp;

    for(int i = -100;i <= 100;i++){
        tmp = 0;
        rep(j,N){
            tmp += (a[j] - i) * (a[j] - i);
        }
        chmin(cost,tmp);
    }

    cout << cost << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(int &a){a=0;int f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
for(;c<='9' && c>='0';a=a*10+c-'0',c=getchar());return a*=f;}
inline void print(int a){int s[20],t=0;if(!a){putchar('0');putchar('\n');return;}
while(a){s[t++]=a%10,a/=10;}for(;t--;putchar(s[t]+'0'));putchar('\n');}
struct pricture{
	int next,y;
} e[200010];
int link[100010],lin;
void add(int a,int b){e[++lin].next=link[a],link[a]=lin,e[lin].y=b;}
int n,m,q;
int v[100010],d[100010],c[100010];
int s[100010],a[100010];

void dfs(int x,int d,int l)
{
	if(!a[x]) a[x]=l;
	if(!d || s[x]>=d) return;
	s[x]=d;
	for(int i=link[x];i;i=e[i].next)
	dfs(e[i].y,d-1,l);
}

int main()
{
	read(n),read(m);
	for(int i=1;i<=m;i++)
	{
		int s,t;
		read(s),read(t);
		add(s,t);
		add(t,s);
	}
	read(q);
	for(int i=1;i<=q;i++) read(v[i]),read(d[i]),read(c[i]);
	for(int i=q;i>=1;i--) dfs(v[i],d[i],c[i]);
	for(int i=1;i<=n;i++) print(a[i]);
	return 0;
}

Measured memory_bytes: 4608