akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;

void solve()
{
	int V, E;
	cin >> V >> E;
	vector< vector<long long int> > D(V + 1, vector<long long int>(V + 1));
	for (int i = 0; i < V; ++i)
	{
		for (int j = 0; j < V; ++j)
		{
			if (i == j)
			{
				D[i][j] = 0;
			}
			else
			{
				D[i][j] = 1e18;
			}
		}
	}
	for (int i = 0; i < E; ++i)
	{
		int s, t, d;
		cin >> s >> t >> d;
		D[s][t] = d;
	}

	for (int k = 0; k < V; ++k)
	{
		for (int i = 0; i < V; ++i)
		{
			if (D[i][k] == 1e18)
			{
				continue;
			}
			for (int j = 0; j < V; ++j)
			{
				if (D[k][j] == 1e18)
				{
					continue;
				}
				D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}
	for (int i = 0; i < V; ++i)
	{
		if (D[i][i] < 0)
		{
			cout << "NEGATIVE CYCLE" << endl;
			return;
		}
	}
	for (int i = 0; i < V; ++i)
	{
		for (int j = 0; j < V; ++j)
		{
			if (j)
			{
				cout << " ";
			}
			if (D[i][j] == 1e18)
			{
				cout << "INF";
			}
			else
			{
				cout << D[i][j];
			}
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}


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

#define INT_MAX 2147483647

int main(void){
    char S[101];
    char T[101];

    scanf("%s", S);
    scanf("%s", T);
    char SS[202];
    sprintf(SS, "%s%s", S, S);
    int i, j;
    int lenT = strlen(T);
    int lenSS = strlen(SS);

    for(i=0; i <= lenSS - lenT; i++) {
        char temp[101];
        strncpy(temp, SS+i, lenT);
        temp[lenT] = '\0';
        if(strcmp(T, temp) == 0) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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


public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        String s= scanner.next();
        boolean coffeeLike=true;
        if (s.charAt(2)!=s.charAt(3)){
            coffeeLike=false;
        }
        if (s.charAt(4)!=s.charAt(5)){
            coffeeLike=false;
        }
        System.out.println(coffeeLike? "Yes" : "No");
    }
}


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


const ll mod7 = 1000000000LL + 7;

int main(void) {
  ll n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }

  if (n == m) {
    ll sum = 1;
    for (int i = 1; i <= n; ++i) {
      sum *= i;
      sum %= mod7;
    }
    sum *= sum;
    sum %= mod7;
    sum *= 2;
    sum %= mod7;
    cout << sum << endl;
    return 0;
  }

  if (n < m) swap(n, m);
  ll sum_n = 1;
  for (int i = 1; i <= n; ++i) {
    sum_n *= i;
    sum_n %= mod7;
  }
  ll sum_m = 1;
  for (int i = 1; i <= m; ++i) {
    sum_m *= i;
    sum_m %= mod7;
  }

  ll ans = sum_n * sum_m % mod7;
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  
  if(max(X, A) - min(X, A) < max(X, B) - min(X, B)) cout << "A";
  else if(max(X, A) - min(X, A) > max(X, B) - min(X, B)) cout << "B";
}


Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
const int N = 65;
const double EPS = 1e-9;
int n, k;
double xx[N], yy[N], c[N], r[N];

typedef pair<double, double> PDD;
typedef vector<PDD> VPDD;
typedef double DB;
#define x first
#define y second

DB distance(PDD a, PDD b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

VPDD cal(DB x1, DB y1, DB r1, DB x2, DB y2, DB r2) {
	x1 -= x2, y1 -= y2;
	DB S = x1 * x1 + y1 * y1;
	DB a = (S + r2 * r2 - r1 * r1) / 2;
	DB D = S * r2*r2 - a * a;
	if (D < 0) return {};
	DB A1 = a * x1, B1 = y1 * sqrt(D);
	DB A2 = a * y1, B2 = x1 * sqrt(D);
	return { {(A1 + B1) / S + x2,(A2 - B2) / S + y2},{(A1 - B1) / S + x2,(A2 + B2) / S + y2} };
}

bool check(DB t) {
	for (int i = 0; i < n; i++)
		r[i] = t / c[i];
	VPDD vec;
	for (int i = 0; i < n; i++) {
		vec.push_back({ xx[i],yy[i] });
		for (int j = i + 1; j < n; j++) {
			VPDD v = cal(xx[i], yy[i], r[i], xx[j], yy[j], r[j]);
			for (auto it : v)
				vec.push_back(it);
		}
	}
	for (auto it : vec) {
		int cnt = 0;
		for (int i = 0; i < n; i++)
			if (r[i] + EPS >= distance(it, { xx[i],yy[i] }))
				cnt++;
		if (cnt >= k)
			return true;
	}
	return false;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> xx[i] >> yy[i] >> c[i];
	
	DB left = 0, right = 1e9;
	for (int i = 0; i < 100; i++) {
		DB mid = (left + right) / 2;
		if (check(mid)) right = mid;
		else left = mid;
	}

	printf("%.12f\n", right);

	return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut dp: Vec<usize> = vec![0; 100];
    let ans: usize = fibonacci(n, &mut dp);

    return format!("{}", ans);
}

fn fibonacci(n: usize, dp: &mut Vec<usize>) -> usize {
    dp[0] = 1;
    dp[1] = 1;
    for i in 2..(n + 1) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    return dp[n];
}



Measured memory_bytes: 5028
n,m,l=map(int,input().split())
a,b=[],[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(m):
    b.append(list(map(int,input().split())))
for i in range(n):
    c=[]
    for k in range(l):
        x=0
        for j in range(m):
            x+=a[i][j]*b[j][k]
        c.append(x)
    print(*c)

Measured memory_bytes: 8676
n, m = map(int, input().split())

ans = ["#"]*n

for i in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == "#" or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if n >= 2:
    if ans[0] == "#":
        ans[0] = 1
    elif ans[0] == 0:
        print(-1)
        exit()
else:
    if ans[0] == "#":
        ans[0] = 0

print("".join(map(str, ans)).replace("#", "0"))

Measured memory_bytes: 61904
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define cins(s,n) rep(i,n)cin>>s.at[i];
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;



ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}


int main()
{
    int n;cin>>n;vi p(n);cin_pl(n,p);sort(rall(p));
    int x=0,y=0;
    rep(i,n)
    {
        if(i%2==0)x+=p[i];
        else y+=p[i];
    }
    cout<<x-y;
}

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

int main() {
  float t, x;
  cin >> t >> x;
  printf("%.04f\n", t / x);
  return 0;
}

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

int main() {
    string s, p;
    cin >> s;
    int q;
    cin >> q;
    int counter = 0;
    for(int i = 0; i < q; ++i){
        int t;
        cin >> t;
        if(t==1){
            ++counter;
        }else if(t==2){
            int f;
            string c;
            cin >> f >> c;
            if(f==1){
                if(counter%2==0){
                    p += c;
                }else{
                    s += c;
                }
            }else{
                if(counter%2==0){
                    s += c;
                }else{
                    p += c;
                }
            }
        }
    }
    reverse(p.begin(),p.end());
    p += s;
    if(counter%2==1){
        reverse(p.begin(),p.end());
        cout << p << "\n";
    }else{
        cout << p << "\n";
    }
    return 0;
}


Measured memory_bytes: 1128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;

 
int main() {
    int N; cin >> N;
    vector<int> V(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    map<int, int> MO, ME;
    for(int i = 0; i < N; i+=2) ME[V[i]]++;
    for(int i = 1; i < N; i+=2) MO[V[i]]++;
    int MAXME=0, MAXMO=0, ide, ido;
    for(auto M : ME) {
        MAXME = max(MAXME, M.second); 
        if(MAXME == M.second) ide = M.first;
    }
    for(auto M : MO) { 
        MAXMO = max(MAXMO, M.second);
        if(MAXMO == M.second) ido = M.first;
    }
    int ans = 1e9;

    for(auto M : MO){
        if(ide == M.first) continue;
        ans = min(ans, N - MAXME - M.second);
    }

    for(auto M : ME){
        if(ido == M.first) continue;
        ans = min(ans, N - MAXMO - M.second);
    }

    /*for(auto me : ME){
        for(auto mo : MO){
            if(me.first == mo.first) continue;
            ans = min(ans, N - me.second - mo.second);
            //cout << mo.first << " " << me.first << " " << N - me.second - mo.second << endl;
        }
    }*/
    if(ans == 1e9) cout << N/2 << endl;
    else cout << ans << endl;

    
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false), cin.tie(0)
typedef long long ll;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
ll a[maxn];
ll dp[maxn];

int main()
{
    IO;
    int n, k=2;
    cin >> n ;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    memset(dp, inf, sizeof(dp));
    dp[1] = 0;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 1; j <= k; ++j)
        {
            dp[i] = min(dp[i], dp[max(i - j, 1)] + abs(a[i] - a[max(i - j, 1)]));
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 10496
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,t,a[12],b[12],s[12];

int main(){
	while(cin>>n){
		if(n==0)return 0;
		for(int i=0;i<n;i++)cin>>a[i];
		t=0;
		while(1){
			for(int i=0;i<n;i++){b[i]=a[i];s[i]=0;}
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(a[j]==a[i])s[i]++;
			for(int i=0;i<n;i++)a[i]=s[i];
			bool same=true;
			for(int i=0;i<n;i++)if(a[i]!=b[i])same=false;
			if(same){
				cout<<t<<endl;
				for(int i=0;i<n;i++){cout<<a[i];if(i!=n-1)cout<<" ";}
				cout<<endl;
				break;
			}
			t++;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
//==============================================================================================


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int r = n % 10;
	if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9  )printf("hon");
	else if (r == 0 || r == 1 || r == 6 || r == 8)printf("pon");
	else printf("bon");
	return 0;
}

Measured memory_bytes: 3784
N = int(input())
import sys
input = sys.stdin.readline
a = []
for i in range(1,N+1):
    a.append(int(input()))
ans = 1
check = a[0]
pre_index = 1
while True:
    if N < ans:
        print(-1)
        exit()
    if check == 2:
        print(ans)
        exit()
    if pre_index == a[check-1]:
        print(-1)
        exit()
    pre_index = check
    check = a[check-1]
    ans += 1

Measured memory_bytes: 7084
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main() {
    int N, M, s, c, ans = 0;
    map<int, int> m;
    cin >> N >> M;
    while (M--) {
        cin >> s >> c;
        if (m.count(s)) {
            if (m[s] != c) {
                cout << "-1" << endl;
                return 0;
            } else {
                continue;
            }
        }
        m.insert(make_pair(s, c));
        ans += c * (int) (pow(10, N - s) + 0.5);
    }

    if (N > 1 && m.count(1) && m[1] == 0) {
        cout << "-1" << endl;
        return 0;
    }
    if (N > 1 && !m.count(1)) {
        ans += 1 * (int) (pow(10, N - 1) + 0.5);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int i=0;i<T;i++){
            solve(sc);
        }
    }

    public static void solve(Scanner sc){
        int N = sc.nextInt();
        List<Place> v = new ArrayList<>();
        long base=0;
        for(int i=0;i<N;i++){
            int k,l,r;
            k = sc.nextInt();
            l = sc.nextInt();
            r = sc.nextInt();
            base += (long)(Math.min(l,r));
            v.add(new Place(k,l,r,N));
        }
        Map<Integer, List<Place>> lmp = new HashMap<>();
        Map<Integer, List<Place>> rmp = new HashMap<>();
        for(Place t:v){
            if(t.isLeft()){
                lmp.putIfAbsent(t.K, new ArrayList<>());
                lmp.get(t.K).add(t);
            }else if(t.isRight()){
                rmp.putIfAbsent(t.K, new ArrayList<>());
                rmp.get(t.K).add(t);
            }
        }
        base += getGain(N, lmp);
        base += getGain(N, rmp);
        System.out.println(base);
    }

    private static long getGain(int n, Map<Integer, List<Place>> lmp) {
        long gain=0;
        PriorityQueue<Place> lpq=new PriorityQueue<>(Comparator.comparingLong(p->p.gain));
        for(int i = 1; i<= n; i++) {
            if (lmp.containsKey(i)) {
                lpq.addAll(lmp.get(i));
                while(lpq.size() > i){
                    lpq.poll();
                }
            }
        }
        while(!lpq.isEmpty()){
            Place t = lpq.poll();
            gain += t.gain;
        }
        return gain;
    }

    public static class Place{
        long gain;
        private int lr;
        int K;
        public Place(int k, int l, int r, int N){
            if(l-r > 0){
                gain = l-r;
                lr=-1;//left of K
                K=k;
            }else if(l-r < 0){
                gain = r-l;
                lr=1;//right of K
                K=N-k;
            }else{
                gain = 0;
                lr=0;
                K=k;
            }
        }
        public String toString(){
            return gain + " - " + K;
        }
        public boolean isLeft(){
            return lr == -1;
        }

        public boolean isRight() {
            return lr == 1;
        }
    }
}


Measured memory_bytes: 87712
#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
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int 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]);
}
int h,w;
vs field;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vvi d(50,vi(50));


int bfs(int sx,int sy,int gx,int gy){
  queue<P> que;
  for (int i = 0; i < 50; i++){
    for (int j = 0; j < 50; j++) d[i][j] = 100000000;
  }
  que.push(P(sx, sy));
  d[sx][sy] = 0;
  
// キューが空になるまでループ
  while (que.size()){
//キューの先頭を取り出す
    pair<int,int> p = que.front(); que.pop();
//取り出してきた状態がゴールなら探索をやめる
    if (p.first == gx && p.second == gy) break;
//移動4方向をループ
    for (int i = 0; i < 4; i++) {
//移動した後の点を(nx, ny)とする
      int nx = p.first + dx[i], ny = p.second + dy[i];
//移動が可能かの判定とすでに訪れたことがあるかの判定(d[nx][ny] != INFなら訪れたことがある)
      if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] != '#' &&d[nx][ny] ==100000000) {
//移動できるならキューに入れ、その点の距離をpからの距離+1で確定する
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
return d[gx][gy];
}
     
int main(){
  cin>>h>>w;
  rep(i,h){
    string f;
    cin>>f;
    field.push_back(f);
  }
  int res =bfs(0,0,h-1,w-1);
  
  int count=0;
  rep(i,h){
   rep(j,w){
     if(field[i][j]=='.')count++;
   }
    
  }
  if(res==100000000)cout<<-1<<endl;
  else cout<<count-1-res<<endl;

  
  
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	for(;;)
	{
		int n,a[4],b,c,d,f=0,l,s;
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		else if(n%1111==0)
		{
			printf("NA\n");
		}
		else
		{
			for(;;)
			{
				if(n==6174)
				{
					break;
				}
				a[0]=n/1000;
				a[1]=n/100-a[0]*10;
				a[2]=n%100/10;
				a[3]=n%10;
				for(b=0;b<4;b++)
				{
					for(c=b+1;c<4;c++)
					{
						if(a[b]<a[c])
						{
							d=a[b];
							a[b]=a[c];
							a[c]=d;
						}
					}
				}
				l=(a[0]*1000+a[1]*100+a[2]*10+a[3]);
				s=(a[0]+a[1]*10+a[2]*100+a[3]*1000);
				n=l-s;
				f++;
			}
			printf("%d\n",f);
		}
	}
	return 0;
}

Measured memory_bytes: 2604
//DEEPANSHU RAWAT
//BTECH/10530/18
//INFORMATION TECHNOLOGY

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
 */
/*************************************************************************************************************************/
#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 1000000007
#define modd 20000
using namespace std ;
lld v[100005];
/**************************************************************************************************************************/

/**************************************************************************************************************************/
int main()
    {
        ios_base::sync_with_stdio(false);//FOR FAST INPUT OUTPUT METHOD
        cin.tie(NULL);
        cout.tie(NULL);
        
        lld n;
        cin>>n; 
        cout<<((n)*(n-1))/2;
        
}
       
/**************************************************************************************************************************/                            


Measured memory_bytes: 256
from math import factorial

n, m = map(int, input().split())


def f(n):
    if n == 1:
        return 1
    else:
        return n * f(n-1)


if abs(n - m) >= 2:
    print(0)

elif abs(n - m) == 1:
    print((factorial(min(n, m)) ** 2 * max(n, m)) % (10 ** 9 + 7))

else:
    print((2 * factorial(n) ** 2) % (10 ** 9 + 7))


Measured memory_bytes: 4740
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,n,i;
	cin>>k>>n;
	int a[n+2];
	a[n+1]=k;
	a[0]=0;
	for(i=1;i<n+1;i++)
	cin>>a[i];
	int sum=0,mx=0,j=1,kk=0,l,h;
	mx=a[1]-a[0]+a[n+1]-a[n];
	for(i=1;i<n;i++)
	{
		
		mx=max(mx,a[i+1]-a[i]);
	}

	
	cout<<(k-mx);
}


Measured memory_bytes: 4384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
using ll = long long;

ll modpow(ll a, ll n, ll mod) {
	ll res = 1;
	while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; }
	return res;
}

int main() {
	ll a = 1000000007;
	ll N,K;
	cin >> N >> K;
	vector<ll> di(K+1);
	di[0] = 0;
	for (ll i = K; i > 0; --i) {
		//di[i] = pow(ll(K / i), N);
		di[i] = modpow(ll(K / i), N, a);
		for (ll j = 2; i * j <= K; ++j) {
			di[i] -= di[j * i];
		}
	}
	ll ans = 0;
	for (ll i = 1; i <= K; ++i) {
		ans += di[i] * i % a;
		ans %= a;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3964
#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 510000
#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()
#define uni(q) unique(all(q)),q.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;

ll h,w;
ll dy[4] = {1,0,-1,0};
ll dx[4] = {0,1,0,-1};

bool in(ll y, ll x){
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
    cin >> h >> w;
    vvl a(h,vl(w,-1));
    queue<P> q;
    ll sum = 0;
    rep(i,h){
        rep(j,w){
            char c; cin >> c;
            if(c=='#'){
                q.emplace(i,j);
                a[i][j]=0;
                sum++;
            }
        }
    }
    while(!q.empty()){
        P p = q.front(); q.pop();
        ll y = p.first;
        ll x = p.second;
        rep(i,4){
            ll ny = y + dy[i];
            ll nx = x + dx[i];
            if(in(ny,nx)&&a[ny][nx]==-1){
                a[ny][nx] = a[y][x]+1;
                q.emplace(ny,nx);
                //cout << ny << nx << endl;
            }
        }
    }
    ll ans = 0;
    rep(i,h){
        rep(j,w) ans = max(ans,a[i][j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 24500
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string str[100002];
ll n;
string ans;
bool dfs(ll cu,int a,int b,int c)
{
    if(cu==n)
        return true;
    if(str[cu]=="AB")
    {
        if(a==0 && b==0)
            return false;
        if(a>0 && dfs(cu+1,a-1,b+1,c))
        {
            ans+="B";
            return true;
        }
        if(b>0 && dfs(cu+1,a+1,b-1,c))
        {
            ans+="A";
            return true;
        }
        return false;
    }
    if(str[cu]=="AC")
    {
        if(a==0 && c==0)
            return false;
        if(a>0 && dfs(cu+1,a-1,b,c+1))
        {
            ans+="C";
            return true;
        }
        if(c>0 && dfs(cu+1,a+1,b,c-1))
        {
            ans+="A";
            return true;
        }
        return false;
    }
    if(str[cu]=="BC")
    {
        if(c==0 && b==0)
            return false;
        if(b>0 && dfs(cu+1,a,b-1,c+1))
        {
            ans+="C";
            return true;
        }
        if(c>0 && dfs(cu+1,a,b+1,c-1))
        {
            ans+="B";
            return true;
        }
        return false;
    }
}
int main()
{
    ll i,j,k,l,m,a,b,c,x;
    cin>>n>>a>>b>>c;
    for(i=0;i<n;i++)
        cin>>str[i];
    if(dfs(0,a,b,c))
    {
        cout<<"Yes"<<endl;
        for(i=ans.length()-1;i>=0;i--)
            cout<<ans[i]<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 11544
#include<iostream>
#include<map>
using namespace std;
 
int main()
{
 map< int,int, greater<int> > m;
 int n,i,p,d1,d2;
 while(cin>>n,n){
  m.clear();
  for(i=0;i<n;i++){
   cin>>p>>d1>>d2;
   m[d1+d2] = p;
  }
  cout<<(*m.begin()).second<<" "<<(*m.begin()).first<<endl;
 }
 return 0;
}

Measured memory_bytes: 1228
def main():
    N = int(input())

    ans = 1
    dp = [1] * (N+1)
    for i in range(2, N+1):
        for j in range(i, N+1, i):
            dp[j] = dp[j] + 1
        ans = ans + i*dp[i]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 145820
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
static const LL INF = 1LL << 60;

void solve(long long N, std::vector<long long> &a) {
	LL ans = 0;
	for (LL i = 0; i < N; ++i) {
		LL x = max(0LL, a[i] / (N + 1) - N);
		a[i] -= x * (N + 1);
		ans += x * (N + 1);
	}
	int index;
	while (index = max_element(a.begin(), a.end()) - a.begin(), a[index] >= N) {
		++ans;
		for (LL i = 0; i < N; ++i) {
			a[i] += i == index ? -N : 1;
		}
	}
	cout << ans << endl;
}

int main() {
    long long N;
	std::cin >> N;
	std::vector<long long> a(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
	}
	solve(N, a);
	return 0;
}


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

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    map<long long, int> cnt;
    cnt[0] = 1;
    long long acc = 0, ans = 0;
    for (int ai: a) acc += ai, ans += cnt[acc % m]++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int k = Integer.parseInt(sc.nextLine());

		int totalMove = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			totalMove += Math.min(x, k - x) * 2;
		}

		System.out.println(totalMove);

		sc.close();
	}
}

Measured memory_bytes: 22996
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}


const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  if(n==3 || n==5 || n==7) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, s, p[N]; i64 c[N];
i64 solve(int x, int l, int r)
{
    if(s < p[l]) return p[r]-s; if(s > p[r]) return s-p[l];
    if(c[l] >= c[r]) return c[l] += c[r], solve(l, l, r-1)+(r==x?p[r]-p[l]:0);
    else return c[r] += c[l], solve(r, l+1, r)+(l==x?p[r]-p[l]:0);
}
int main()
{
    n = read(), s = read(); for(int i = 1; i <= n; ++i) p[i] = read(), c[i] = read();
    printf("%lld\n", solve(c[1]<c[n]?1:n, 1, n));
    return 0;
}

Measured memory_bytes: 5248
//void __(){
//    _(string,s);
//    int n = s.size()/2;
//    string tmp;
//    rep(i,n)
//        tmp += "hi";
//    if(tmp == s)
//        print "Yes";
//    else
//        print "No";
//}
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_ZERO_INT(i,r) for(int i = 0; i < r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
void __(){
    _(string,s);
    int n = s.size()/2;
    string tmp;
    rep(i,n)
        tmp += "hi";
    if(tmp == s)
        print "Yes";
    else
        print "No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}


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

using namespace std;


int main()
{
int N,M;
cin>>N;
cin>>M;
int array[100000];

for(int i=0;i<M;i++){
  cin>>array[i];
}
std::sort(array, array + M);
int r[100000];
for(int i=0;i<M-1;i++){r[i]=abs(array[i+1]-array[i]);}
int a=0;
std::sort(r, r + M-1);
for(int i=0;i<M-N;i++)a=a+r[i];
cout<<a<<endl;
return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b > c+d)
    cout << "Left" << endl;
  else if(a+b < c+d)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
  return 0;
}

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

int main()
{
  int N;
  cin >> N;
  unsigned long long power = 1;
  
  for (int i = 1; i <= N; ++i) {
    power *= i;
    if (power >= 1000000007)
      power %= 1000000007;
  }
  
  cout << power << endl;
  return 0;
}


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

using namespace std;

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

    if (s == "ARC")
    {
        cout << "ABC" << endl;
    }
    else
    { 
        cout << "ARC" << endl;
    }
    return 0;
}


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

int i,N;
int A[210];
#define for() for(i=0;i<N;i++)

int main() {
  cin>>N;
  for() cin>>A[i];
  int f=1,c=0;
  while(1){
    for(){
      f=A[i]%2==1?0:f;
    }
    if(!f) break;
    for(){
      A[i]/=2;
    }
    c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def EulerTour(graph, root=1):
    N = len(graph) - 1
    parent = [0] * (N + 1)
    stack = [-root, root]
    tour = []
    ind_L = [0] * (N + 1)
    ind_R = [0] * (N + 1)
    i = -1
    while stack:
        v = stack.pop()
        tour.append(v)
        i += 1
        if v > 0:
            ind_L[v] = i
            p = parent[v]
            for w in graph[v]:
                if w == p:
                    continue
                parent[w] = v
                stack.append(-w)
                stack.append(w)
        else:
            ind_R[-v] = i
    return tour, ind_L, ind_R, parent


N = int(readline())
graph = [[] for _ in range(N + 1)]
C = (0,) + tuple(map(int, readline().split()))
m = map(int, read().split())
for a, b in zip(m, m):
    graph[a].append(b)
    graph[b].append(a)

tour, ind_L, ind_R, parent = EulerTour(graph)
removed = [0] * (N + 1)
answer = [N * (N + 1) // 2] * (N + 1)
memo = [0] * (N + 1)

for v in tour:
    if v > 0:
        memo[v] = removed[C[parent[v]]]
    else:
        v = -v
        removed[C[v]] += 1
        p = parent[v]
        x = (ind_R[v] - ind_L[v]) // 2 + 1  # subtree size
        x -= removed[C[p]] - memo[v]
        answer[C[p]] -= x * (x + 1) // 2
        removed[C[p]] += x

for i, x in enumerate(removed):
    x = N - x
    answer[i] -= x * (x + 1) // 2
print('\n'.join(map(str, answer[1:])))


Measured memory_bytes: 105740
#include<stdio.h>

int main() {
   int A,B,sum;
   scanf("%d %d",&A, &B);
   if(A > B) {
      sum = A + (A-1);
   } else if(A < B) {
      sum = B + (B-1);
   } else {
      sum = 2*A;
   }
   printf("%d\n", sum);
}


Measured memory_bytes: 128
"""
X以下の数をL枚以上取り出せるか？という二分探索を行う。
L枚以上取り出せるか？のテストは尺取法を用いる
"""
N,K,L = map(int,input().split())
A = list(map(int,input().split()))

def is_ok(X):
    r = 0
    cnt1 = 0
    cnt2 = 0
    for i in range(N):
        for j in range(r,N):
            if cnt2 == K-1 and A[j]<=X:
                r = j
                cnt1 += N-j
                if A[i]<=X:
                    cnt2 -= 1
                break
            elif A[j]<=X:
                cnt2 += 1
        else:
            break
    if cnt1 >= L:
        return True
    else:
        return False

def bisearch(high,low):
    while high-low>1:
        mid = (high+low)//2
        if is_ok(mid):
            high = mid
        else:
            low = mid
    return high

print(bisearch(200000,-1))



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

typedef long long ll;

const int mod = 1000000007;

int n, m, k;
int res;

int Get3(int k)
{
    int a = k - 1, b = k, c = k + 1;
    if (a % 3 == 0) a /= 3;
    else if (b % 3 == 0) b /= 3;
    else c /= 3;
    return ll(a) * b % mod * c % mod;
}

int Get2(int k)
{
    int a = k, b = k + 1;
    if (a % 2 == 0) a /= 2;
    else b /= 2;
    return ll(a) * b % mod;
}

int main()
{
    scanf("%d %d %d", &n, &m, &k);
    int mult = 1;
    for (int i = n + m - k + 1; i <= n + m - 2; i++)
        mult = ll(mult) * i % mod;
    if (k >= 2) {
        res = ll(mult) * n % mod * m % mod * Get3(k) % mod;
    }
    for (int i = max(n + m - k + 1, n + m - 1); i <= n + m - 1; i++)
        mult = ll(mult) * i % mod;
    res = (res + ll(mult) * (n + m) % mod * Get2(k)) % mod;
    mult = ll(mult) * (n + m) % mod;
    res = (res + ll(mult) * k) % mod;
    printf("%d\n", res);
    return 0;
}


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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int n, a, b, ans = 0;
  string s;
  cin >> n >> s;
  //vector<int> v(n), c(n);
  for(int i = 0; i < n - 2; i++) {
    if(s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      ans++;
      i += 2;
    }
  }
  cout << ans << endl;
}

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

int main()
{
  int n,i,j,k,b,f,r,v;
  int res[4][3][10]={0}; 

  cin>>n;
  for(i=0;i<n;i++){
    cin>>b>>f>>r>>v;
    res[b-1][f-1][r-1]+=v;
  }

  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
        if(k<9) cout<<" "<<res[i][j][k];
        if(k==9) cout<<" "<<res[i][j][k]<<endl;
      }
    }
    if(i<3) cout<<"####################"<<endl;
  }
}


Measured memory_bytes: 1168
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n, x;
long thick[55];
long pate[55];

long cnt(long x, long cl){//0 < x <= thick[class]
    if(x == 0){
        return 0;
    }
    long res = 0;
    if(x == thick[cl]){
        return pate[cl];
    }
    x -= 1;
    if(x > thick[cl-1]){
        res += pate[cl-1];
        x -= thick[cl-1];
        if(x > 0){
            res += 1;
            x -= 1;
        }
    }
    res += cnt(x, cl-1);
    return res;
}

int main(){
    scanf("%ld%ld", &n, &x);
    thick[0] = 1;
    pate[0] = 1;
    for(int i = 1; i <= 50; i++){
        thick[i] = 2 * thick[i-1] + 3;
        pate[i] = 2 * pate[i-1] + 1;
        //printf("(%ld %ld %ld)\n", i, thick[i], pate[i]);
    }
    printf("%ld\n", cnt(x, n));
}


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

int main () {
  int n;
  cin >> n;
  vector<int>x(n); 
  vector<int>y(n); 
  vector<int>index(n); 
  rep(i, n) cin >> x[i] >> y[i], index[i] = i;
  double ans = 0;
  int count = 0;
  do{
    for(int i = 1; i < n;i++) {
      ans += sqrt(pow(x[index[i - 1]] - x[index[i]], 2) + pow(y[index[i - 1]] - y[index[i]], 2));
    }
    count ++;
  }while(next_permutation(index.begin(), index.end()));
  cout << setprecision(12) << ans / count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    string S;
    cin >> S;
    int s_size = S.size();
    if (S[s_size-1] == 's') {
        cout << S << "es" << endl;
    } else {
        cout << S << "s" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    ll x=N;
    ll ans=0;
    for (ll i = 2; i*i <= N; i++)
    {
        ll cnt=0;
        while (x%i==0)
        {
            x=x/i;
            cnt++;
        }
        ll lo=0,hi=100;
        while (lo<hi)
        {
            ll mid=(lo+hi)/2;
            if((mid*(mid+1)/2)<=cnt)
            {
                lo=mid+1;
            }
            else
            {
                hi=mid;
            }
        }
        ans+=lo-1;
    }
    if(x>1)
    {
        ans++;
    }
    cout<<ans<<endl;
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3792
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

const MOD: i64 = 1e9 as i64 + 7;

fn solve(x: i64, y: i64, _k: i64, comb: i64) -> i64 {
  let mut ans = 0;
  for d in 1 .. x {
    ans = (ans + d * (x - d) % MOD * y * y) % MOD;
  }
  ans * comb % MOD
}

fn factor(x: i64) -> i64 {
  (1 .. x + 1).fold(1, |f, a| f * a % MOD)
}

fn pow(x: i64, e: i64) -> i64 {
  if e == 1 {
    x
  } else if e % 2 == 0 {
    let y = pow(x, e / 2);
    y * y % MOD
  } else {
    pow(x, e - 1) * x % MOD
  }
}

fn main() {
  input! {
    n: i64,
    m: i64,
    k: i64,
  }
  let div = factor(k - 2) * factor(n * m - k) % MOD;
  let comb = factor(n * m - 2) * pow(div, MOD - 2) % MOD;
  let ans = (solve(n, m, k, comb) + solve(m, n, k, comb)) % MOD;
  println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val X, Y = in.next().toInt


  val b = ((2.0 / 3) * Y - (1.0 / 3) * X).round.toInt
  val w = ((2.0 / 3) * X - (1.0 / 3) * Y).round.toInt


  val MOD = 1e9.toInt + 7

  if (b >= 0 && w >= 0 && b + 2*w == X && 2*b + w == Y) {
    val mc = new ModComb(w+b, MOD)

    var ans: Long = mc.fact(w+b)
    ans *= mc.factInv(w)
    ans %= MOD
    ans *= mc.factInv(b)
    ans %= MOD

    println(ans)
  }
  else {
    println(0)
  }
}

class ModComb(maxNum: Int, mod: Long) {

  private def repeatSquares(x: Long, n: Long): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % mod, n/2)
    else
      (x * repeatSquares(x*x % mod, n/2)) % mod
  }

  val fact = new Array[Long](maxNum + 1)

  fact(0) = 1
  for (i <- 1 to maxNum)
    fact(i) = (i * fact(i-1)) % mod

  val factInv = new Array[Long](maxNum + 1)

  factInv(maxNum) = repeatSquares(fact(maxNum), mod-2)
  for (i <- (1 to maxNum).reverse)
    factInv(i-1) = (i * factInv(i)) % mod


  // nCk
  def comb(n: Int, k: Int): Long = {
    val numer = fact(n)
    val denom = (factInv(n-k) * factInv(k)) % mod

    (numer * denom) % mod
  }

}


object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 38088