akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
       if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
    int f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline ll readll() {
    ll f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void fl(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
          dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define MAXN 110
ll n,a[MAXN];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);ll ans=0;
    rp(i,1,n){
        rp(j,i+1,n){
            rp(k,j+1,n){
                if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]){
                    ans++;
                    //cout<<i<<' '<<j<<' '<<k<<endl;
                }
            }
        }
    }cout<<ans<<endl;
    return 0;
}
/* stuff to remember
    * int overflow, array bounds
    * special cases (n=1? n=0?)
    * do something instead of nothing and stay organized
    * USE STATIC ARRAYS
    * DEFINING ARRAYS BEFORE main()
    * DO NOT DEFINE ARRAYS IN main()
    * USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
string s;
vector<llint> vec;
llint dp[500005][3];

llint calc()
{
	if(vec.size() <= 1) return 0;
	llint m = vec.size();
	
	//for(int i = 0; i < m; i++) cout << vec[i] << " "; cout << endl;
	
	for(int i = 0; i <= m; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = -inf;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < m; i++){
		for(int j = 0; j < 3; j++){
			llint rem = vec[i]-j;
			if(j == 2) rem = 1;
			if(rem < 0) continue;
			chmax(dp[i+1][0], dp[i][j]);
			if(i+2 <= m && vec[i+1] >= 1) chmax(dp[i+1][1], dp[i][j]+rem);
			if(i+2 <= m && rem >= 1) chmax(dp[i+2][0], dp[i][j]+vec[i+1]);
			if(i+2 <= m && rem >= 1 && vec[i+1] >= 1) chmax(dp[i+1][2], dp[i][j]+vec[i+1]-1);
		}
	}
	return max(dp[m][0], max(dp[m][2], dp[m][1]));
}

int main(void)
{
	cin >> n;
	cin >> s;
	s += "00";
	
	for(int i = 0; i+2 < (int)s.size(); i++){
		if(s.substr(i, 3) == "101") s[i+1] = '#';
	}
	llint ans = 0, cnt = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '1') cnt++;
		if(s[i] == '0'){
			if(cnt > 0) vec.push_back(cnt);
			cnt = 0;
			ans += calc();
			vec.clear();
		}
		if(s[i] == '#'){
			vec.push_back(cnt);
			cnt = 0;
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

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

	double e = 0;

	int i = 1;
	double p = pow(0.5,  m);
	while (1) {
		double add = 1.0;
		add *= pow(1 - p, i - 1) * p * (19 * m + (n - m)) * i * 100;
		e += add;
		i++;

		if (add < 1e-9) {
			break;
		}
	}

	int ans = e + 0.5;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
import math
a,b,h,m = map(int,input().split())

time = h * 60 + m


angle1 = time * (1/30 - 1/360)%2

angle2 = min(angle1,2 - angle1)

angle3 = math.pi * angle2


d = math.sqrt(a**2 + b**2 -2*a*b*math.cos(angle3))
print(d)


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


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    lcm = 1
    ans = 0

    for ai in a:
        lcm = lcm * ai // gcd(lcm, ai)

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6200
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

int main(){
    ll a,b; cin >> a >> b;
    ll keta;
    ll ans;
    if(a%2 == 1 && b%2==0){
        keta = (b-a+1-2)/2;//a,b使う
        if(keta%2==0){
            ans=(a^b);
        }else{
            ans=(a^b^1);
        }
    }
    if(a%2==1 && b%2 == 1){
        keta = (b-a+1-1)/2;//aのみ使う
         if(keta%2==0){
            ans=(a);
        }else{
            ans=(a^1);
        }
    }
    if(a%2==0 && b%2==0){
        keta=(b-a+1-1)/2;//ｂのみ使う
         if(keta%2==0){
            ans=(b);
        }else{
            ans=(b^1);
        }
    }
    if(a%2==0 && b%2 == 1){
        keta=(b-a+1)/2;//何も使わない
         if(keta%2==0){
            ans=0;
        }else{
            ans=1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func bs(x int, a []int) int {
	l,r := -1,len(a)
	c := (l+r)/2
	for l < r-1 {
		if x < a[c] {
			r = c
		} else {
			l = c
		}

		c = (l+r)/2

	}

	return r
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}

	b := make([]int, 0)

	b = append(b,a[n-1])
	ans := 1

	for i := n-2; i >= 0; i-- {
		c := bs(a[i],b)
		if c == len(b) {
			b = append(b,a[i])
			ans++
		} else {
			b[c] = a[i]
		}
		// fmt.Println(b)
	}

	fmt.Println(ans)

}


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

int main()
{
	int h, w;
	char a[] = { '#', '.' };
	while (cin >> h >> w && h != 0) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i % 2 == 0) cout << a[j % 2];
				else cout << a[!(j % 2)];
			}
			cout << "\n";
		}
		cout << "\n";
	}
}


Measured memory_bytes: 3076
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<int>a;//入力
	int x=0,n;
	int i = 0, j = 0,in; //内部で使用;
	int ans = 0,d; //出力

	cin >> n>>x;
	while (cin >> in) {
		a.push_back(in);
	}
	a.push_back(INT_MAX);
	sort(a.begin(),a.end());
	
	while (a[i] <= x) {
		if (i!=a.size()-2) {
			x = x - a[i];
			ans++;
			i++;
		}
		else
		{
			if (a[i] == x) {
				x = x - a[i];
				ans++;
				i++;
			}
			else x = 0;
		}
	}
	cout << ans << "\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll x;
    cin >> x;
    ll a = 100;
    ll ans = 0;
    while(true) {
        ans++;
        a *= 1.01;
        ll b = a;
        if(b >= x) {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
vector<bool>visited1(2600,0);
vector<bool>visited2(2600,0);
//Bellman_Ford(O(V*E)
ll V,E;
vector<vector<pll> >G(2600);
vector<vector<ll> >g(2600);
vector<ll>d(2600);
bool Bellman_Ford(ll s){
    bool f=1;
    rep(i,V)d[i]=inf*inf;
    d[s]=0;
    ll cnt=0;
    while(true){
        if(cnt==V){
            f=0;break;
        }
        cnt++;
        bool update=0;
        rep(i,V){
            if((!visited1[i])||(!visited2[i]))continue;
            for(auto e:G[i]){
                if((!visited1[e.first])||(!visited2[e.first]))continue;
                if(d[i]!=inf*inf&&d[e.first]>d[i]+e.second){
                    d[e.first]=d[i]+e.second;
                    update=true;
                }
            }
        }
        if(!update)break;
    }
    return f;
}
void dfs(ll i){
    visited1[i]=1;
    for(auto e:G[i]){
        if(visited1[e.first])continue;
        dfs(e.first);
    }
    return;
}
void dfs2(ll i){
    visited2[i]=1;
    for(auto e:g[i]){
        if(visited2[e])continue;
        dfs2(e);
    }
    return;
}
int main(){
    cin>>V>>E;
    ll p;cin>>p;
    rep(i,E){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].pb(mp(b,p-c));
        g[b].pb(a);
    }
    dfs(0);
    dfs2(V-1);
    bool f=Bellman_Ford(0);
    if(f){
        if(d[V-1]>0)cout<<0<<endl;
        else cout<<-d[V-1]<<endl;
    }else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cassert>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REPEAT(i, n) FOR(i, 0, n)
#define DECFOR(i, a, b) for (int i = (a); (b) < i; --i)

using namespace std;

void c_3_3() {
	int n;
	bool flag;
	int count;

	cin >> n;
	// int price[n];
	vector<int> a(n);
	REPEAT(i, n) {
		cin >> a[i];
	}

	flag = true;
	count = 0;
	while (flag) {
		flag = false;
		DECFOR(j, n - 1, 0) {
			if (a[j] >= a[j - 1]) {
				continue;
			}
			const auto v = a[j];
			a[j] = a[j - 1];
			a[j - 1] = v;
			flag = true;
			++count;
		}
	}
	REPEAT(k, a.size())
	{
		cout << (k ? " " : "") << a[k];
	}
	cout << endl;
	cout << count << endl;
}

void c_3_2() {
	int n;

	cin >> n;
	// int price[n];
	vector<int> a(n);
	REPEAT(i, n) {
		cin >> a[i];
	}
	REPEAT(k, a.size()) {
		cout << (k ? " " : "") << a[k];
	}
	cout << endl;
	FOR(i, 1, n) {
		int j;

		const auto v = a[i];
		j = i - 1;
		while (j >= 0 and a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		REPEAT(k, a.size()) {
			cout << (k ? " " : "") << a[k];
		}
		cout << endl;
	}
	//正解との違い: 特になし
}

void c_2_5() {
	//string s;
	int n;
	cin >> n;
	// int price[n];
	vector<int> price(n);
	REPEAT(i, n) {
		cin >> price[i];
	}
	int maxPrice[n];
	int currentMaxPrice;
	currentMaxPrice = 0;	// or -infinite
	for (int i = n - 1; i >= 0; i--) {
		if (price[i] > currentMaxPrice) {
			currentMaxPrice = price[i];
		}
		maxPrice[i] = currentMaxPrice;
	}
	int maxUp = maxPrice[1] - price[0];
	for (int i = 1; i < n - 1; i++) {
		const int diff = maxPrice[i + 1] - price[i];
		if (diff > maxUp) {
			maxUp = diff;
		}
	}
	cout << maxUp << "\n";
	// 正解との違い: 最大ではなく最小を保持するようにすれば先頭から処理でき、配列を使う必要すらない
	// 競技プログラミングとしてのアドバイス: FOR, REPEATマクロを使いタイプミスをする可能性を減らす
	//   配列の変わりにvectorを用いて宣言以上の領域へのアクセスを検知したりsegmentation faultで落ちるようにする
}

int main() {
	ios::sync_with_stdio(false);
	c_3_3();
	return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll x[1001],y[1001],z[1001];
ll dp1[1001][1001];
int main(){
    int n,m;
    cin>>n>>m;
    rep(i,n) cin>>x[i]>>y[i]>>z[i];
    ll mx=0;
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]+x[i]+y[i]+z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]-x[i]+y[i]+z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]+x[i]-y[i]+z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]+x[i]+y[i]-z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]-x[i]-y[i]+z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]-x[i]+y[i]-z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]+x[i]-y[i]-z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    rep(i,1001)rep(j,1001) dp1[i][j]=-100010001000100010;
    dp1[0][0]=0;
    rep(i,n)rep(j,m+1)if(dp1[i][j]!=-1){
        if(j<m){
            dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]-x[i]-y[i]-z[i]);
        }
        dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
    }
    mx=max(mx,dp1[n][m]);
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    cin>>v[i];

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

    int pos=n/2;

    if(v[pos-1]==v[pos])
    {
        cout<<0;
        return 0;
    }

    int x=v[pos]-v[pos-1];
    cout<<x;
    return 0;
}


Measured memory_bytes: 640
function Main(input){
	input = input.split("\n");
	input.shift();
	for(var i=0;i<input.length;i++){
	    input[i] = input[i].split(" ").map(Number);
	}
	var flag = true;
	input.unshift([0,0,0])
	for(var i=1;i<input.length;i++){
	    if((Math.abs(input[i-1][1]-input[i][1])+Math.abs(input[i-1][2]-input[i][2]))%2!=(input[i][0]-input[i-1][0])%2||(Math.abs(input[i-1][1]-input[i][1])+Math.abs(input[i-1][2]-input[i][2]))>(input[i][0]-input[i-1][0])){
	      //  console.log((Math.abs(input[i-1][1]-input[i][1])+Math.abs(input[i-1][2]-input[i][2])),(input[i]-input[i-1]))
	        flag = false;
	    }
	}
	console.log(flag?"Yes":"No")
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 51540
N = int(input())

sum = 0

for Ai in range(1, N + 1, 1):
  if Ai % 3 == 0 and Ai % 5 == 0:
    # print('FizzBuzz')
    pass
  elif Ai % 3 == 0:
    pass
    # print('Fizz')
  elif Ai % 5 == 0:
    pass
      # print('Buzz')
  else:
    sum += Ai

print(sum)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int n,t;
   cin >> n >> t;

   int cmin,tmin;
   cin >> cmin >> tmin;

   int ctmp, ttmp;
   for(int i=1; i<n; i++){
     cin >> ctmp >> ttmp;
     if (ctmp < cmin && ttmp <= t){
       cmin = ctmp;
       tmin = ttmp;
     }
   }

   if (tmin <= t)
     cout << cmin << endl;
   else
     cout << "TLE" << endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
int zm[26];
int main(){

	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		zm[s[i]-'a']++;
	} 
	for(int i=0;i<26;i++){
		if(zm[i]%2==1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

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

  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int alice = 0;
  int bob = 0;
  
  for(int i=0; i<N; i+=2){
    alice += vec.at(i);
    //cout << alice << endl;
  }
  
  for(int i=1; i<N; i+=2){
    bob += vec.at(i);
    //cout << bob << endl;
  }
  
  cout << alice -bob << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <utility>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m;
  set< pair<ll, ll> > s;
  scanf("%lld%lld", &n, &m);
  ll a[m], b[m], uf[n], ans[m], now = n * (n - 1) / 2;
  for(i = 0; i < n; ++i) uf[i] = i, s.insert({i, 1});
  for(i = 0; i < m; ++i) scanf("%lld%lld", &a[i], &b[i]), a[i]--, b[i]--;
  ans[m - 1] = now;
  for(i = m - 1; i; --i) {
    ll na = a[i], nb = b[i], ra = 0, rb = 0;
    while(uf[na] != na) ra++, na = uf[na];
    while(uf[nb] != nb) rb++, nb = uf[nb];
    if(na == nb) {
      ans[i - 1] = now;
      continue;
    }
    uf[a[i]] = na, uf[b[i]] = nb;
    now -= (*s.lower_bound({na, 0})).second * (*s.lower_bound({nb, 0})).second;
    ans[i - 1] = now;
    if(ra < rb) {
      ll tmp = (*s.lower_bound({na, 0})).second;
      s.erase(s.lower_bound({na, 0}));
      pair<ll, ll> p = *s.lower_bound({nb, 0});
      s.erase(s.lower_bound({nb, 0}));
      p.second += tmp;
      s.insert(p);
      uf[na] = nb;
    } else {
      ll tmp = (*s.lower_bound({nb, 0})).second;
      s.erase(s.lower_bound({nb, 0}));
      pair<ll, ll> p = *s.lower_bound({na, 0});
      s.erase(s.lower_bound({na, 0}));
      p.second += tmp;
      s.insert(p);
      uf[nb] = na;
    }
  }
  for(i = 0; i < m; ++i) printf("%lld\n", ans[i]);
  return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int r,d,x;
	cin>>r>>d>>x;
	for (int i = 0; i < 10; i++){
		x = r*x-d;
		cout<<x<< " ";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;
int main()
 {
	long long int n,i,j,k=0,l=1,m=0;
	string s;
	cin>>s;
	for(i=0;i<s.size();i+=2)
	   cout<<s[i];
	cout<<'\n';   
	return 0;
}

Measured memory_bytes: 512
//Patwari26
//#include template<t> as mine
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=500005;
// We will represent each query as three numbers: L, R, idx. Idx is 
// the position (in original order) of this query.
pair< pair<int, int>, int> queries[500500];
int BLOCK_SIZE;
int arr[500005];
long long cnt[500005];
// Essential part of Mo's algorithm: comparator, which we will
// use with std::sort. It is a function, which must return True
// if query x must come earlier than query y, and False otherwise.
inline bool mo_cmp(const pair< pair<int, int>, int> &x,
        const pair< pair<int, int>, int> &y)
{
    int block_x = x.first.first / BLOCK_SIZE;
    int block_y = y.first.first / BLOCK_SIZE;
    if(block_x != block_y)
        return block_x < block_y;
    return x.first.second < y.first.second;
}
ll val[N];
void solve(){
    ll n,q;
    cin>>n;
    cin>>q;
    BLOCK_SIZE = static_cast<int>(sqrt(n));
    rep(i,0,n-1) cin>>arr[i];
    rep(i,0,q-1){
        cin >> queries[i].first.first >> queries[i].first.second;
        queries[i].second = i;
    }
    sort(queries, queries + q, mo_cmp);
    int mo_left=0,mo_right=-1;
    ll cc=0;
    ll ans[q];
    for(int i = 0; i < q; i++) {
        // [left, right] is what query we must answer now.
        int left = queries[i].first.first-1;    // -1 for zero based indexing
        int right = queries[i].first.second-1;  // -1 for zero based indexing

        // Usual part of applying Mo's algorithm: moving mo_left
        // and mo_right.
        while(mo_right < right) {
            mo_right++;
            cnt[arr[mo_right]]++;
            if(cnt[arr[mo_right]]==1) cc++;
        }
        while(mo_right > right) {
            if(cnt[arr[mo_right]]==1) cc--;
            cnt[arr[mo_right]]--;
            mo_right--;
        }

        while(mo_left < left) {
            if(cnt[arr[mo_left]]==1) cc--;
            cnt[arr[mo_left]]--;
            mo_left++;
        }
        while(mo_left > left) {
            mo_left--;
            cnt[arr[mo_left]]++;
            if(cnt[arr[mo_left]]==1) cc++;
        }
        ans[queries[i].second]=cc;
    }
    rep(i,0,q-1){
        cout<<ans[i]<<endl;
    }
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    // time
    return 0;
}

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

int main(){
    int n, m;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++) {
        cin >> s[i];
    }
    cin >> m;
    vector<string> t(m);
    for(int i=0; i<m; i++) {
        cin >> t[i];
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    vector<string> u;
    set_union(s.begin(), s.end(), t.begin(), t.end(), back_inserter(u));
    set<string> su(u.begin(), u.end());
    int point = 0, mx_point = 0;
    
    for(auto itr=su.begin(); itr!=su.end(); itr++)
    {
        point = 0;
        point += std::count(s.begin(), s.end(), *itr);
        point -= std::count(t.begin(), t.end(), *itr);
        mx_point = max(point, mx_point);
    }

    std::cout << mx_point << std::endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func isPower(num int) bool {
	if num == 1 {
		return true
	}
	for n := 2; true; n++ {
		nThRoot := math.Pow(float64(num), 1/float64(n))
		if math.Abs(nThRoot-math.Ceil(nThRoot)) < 0.00000001 {
			return true
		}
		if nThRoot < 2.0 {
			break
		}
	}
	return false
}

func main() {
	var x int
	fmt.Scan(&x)
	for i := x; i >= 1; i-- {
		if isPower(i) {
			fmt.Println(i)
			return
		}
	}
}


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

#define ll long long

map<string,int>m;
vector<string>v;
vector<string>ans;
string s;
int main()
{

    int n,maxi=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        v.push_back(s);
        m[s]+=1;
        int t=m[s];
        maxi=max(t,maxi);
    }
    for(auto it=m.begin();it!=m.end();it++){
        if(it->second==maxi)
            ans.push_back(it->first);
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 29168
# -*- coding: utf-8 -*-
import heapq
import math
import sys

tmp = input()
N, M, K = [int(a) for a in tmp.split()]

for i in range(N+1):
    for j in range(M+1):
        val = i * (M - j) + j * (N - i)
        if val > K:
            break
        if val == K:
            print('Yes')
            sys.exit()

print('No')


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define RI register int
typedef long long LL;
LL read() {
	LL q=0,w=1;char ch=' ';
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') w=-1,ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+(LL)(ch-'0'),ch=getchar();
	return q*w;
}
const int N=100005;
int n,m,to[60][N];LL K,bin[60],p[N],d[N],a[N],b[N];
int work(int x) {
	for(RI i=59;i>=0;--i) if(K&bin[i]) x=to[i][x];
	return x;
}
int main()
{
	n=read();
	for(RI i=1;i<=n;++i) p[i]=read(),d[i]=p[i]-p[i-1];
	m=read(),K=read();
	for(RI i=1;i<=n;++i) a[i]=i;
	for(RI i=1;i<=m;++i) {int x=read();swap(a[x],a[x+1]);}
	for(RI i=1;i<=n;++i) to[0][a[i]]=i;
	bin[0]=1;for(RI i=1;i<=59;++i) bin[i]=bin[i-1]<<1;
	for(RI j=1;j<=59;++j)
		for(RI i=1;i<=n;++i) to[j][i]=to[j-1][to[j-1][i]];
	for(RI i=1;i<=n;++i) a[i]=work(i);
	for(RI i=1;i<=n;++i) b[a[i]]=i;
	for(RI i=1;i<=n;++i)
		p[i]=p[i-1]+d[b[i]],printf("%lld.0\n",p[i]);
	return 0;
}

Measured memory_bytes: 28032
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int r;cin >> r;
    cout << 3 * (r * r) <<endl; 
    return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n,m = inp
ans = [-1] * n
m.times do
  s,c = inp
  if(ans[s-1] == -1 or ans[s-1] == c)
    ans[s-1] = c
  else
    p -1
    exit
  end
end


if ans[0] == 0 and ans.size > 1
  p -1
  exit
end
if ans[0] == -1 and ans.size > 1
  ans[0] = 1
end
ans.size.times do |i|
  if ans[i] == -1
    ans[i] = 0
  end
end
puts ans.join


Measured memory_bytes: 3964
import itertools
n = int(input())
f = []
p = []
res = -10**100
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
l = [0,1]
q = list(itertools.product(l,repeat=10))
del q[0]
for i in q:
    r = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if i[k] and f[j][k]:
                c += 1
        r += p[j][c]
    res = r if res<r else res
print(res)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) rep2(i,0,n)

using namespace std;


main(){
    int n;
    cin>>n;
    int a[n];
    int b[n];
    rep(i,n) cin>>a[i];
    rep(i,n) b[i]=a[i];
    sort(a,a+n);
    int min=a[n/2-1]; int max=a[n/2];
    rep(i,n){
        if(b[i]<=min) cout<<max;
    else cout<<min;
      cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3712
s=input()
S=list(s)
L=len(s)
s=0

if S[0]=='1':
    for i in range(0,L):
        if i%2==1:
            if S[i]=='1':
                s=s+1
            else:
                continue
        else:
            if S[i]=='0':
                s=s+1
            else:
                continue

else:
    for i in range(0,L):
        if i%2==1:
            if S[i]=='0':
                s=s+1
            else:
                continue
        else:
            if S[i]=='1':
                s=s+1
            else:
                continue

m=1
if S[0]=='1':
    for i in range(0,L):
        if i%2==1:
            if S[i]=='0':
                m=m+1
            else:
                continue
        else:
            if S[i]=='1':
                m=m+1
            else:
                continue

else:
    for i in range(0,L):
        if i%2==1:
            if S[i]=='1':
                m=m+1
            else:
                continue
        else:
            if S[i]=='0':
                m=m+1
            else:
                continue
if m>s:
    print(s)
else:
    print(m)



Measured memory_bytes: 49392
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n + 1];
        double max = Math.sqrt(n);

        for (int i = 1; i < max; i++) {
            for (int j = 1; j < max; j++) {
                for (int k = 1; k < max; k++) {
                    int v = i * i + j * j + k * k + i * j + j * k + k * i;
                    if (v > n) {
                        break;
                    }
                    array[v]++;
                }
            }
        }

        for (int i = 1; i <= n; i++) {
            System.out.println(array[i]);
        }
    }
}

Measured memory_bytes: 39040
from collections import deque


def main():
    n = int(input())
    tree = AdjacentListGraph([Vertex() for _ in range(n)])
    for _ in range(n - 1):
        a, b, c = map(int, input().split())
        tree.add_edge(a - 1, b - 1, c)
        tree.add_edge(b - 1, a - 1, c)
    q, k = map(int, input().split())
    distances = distances_from(tree, k - 1)
    # print(distances)
    answers = []
    for _ in range(q):
        x, y = map(int, input().split())
        answers.append(distances[x - 1] + distances[y - 1])
    print("\n".join(map(str, answers)))


def distances_from(
    graph: "Graph", from_: int, break_if=lambda node: False
) -> "List[int]":
    distances = [None for _ in range(graph.size)]
    distances[from_] = 0
    queue = deque([from_])
    while queue:
        node = queue.popleft()
        if break_if(node):
            break
        curDist = distances[node]
        for edge in graph.edges_from(node):
            if distances[edge.to] is not None:
                continue
            delta = edge.weight if edge.weight else 0
            distances[edge.to] = curDist + delta
            queue.append(edge.to)
    return distances


class Vertex:
    __slots__ = ("data", "edges")

    def __init__(self, data=None):
        self.data = data
        self.edges = []

    def add_edge(self, to, weight=None):
        self.edges.append(Edge(to, weight))

    def remove_edge(self, to: int) -> bool:
        for i, edge in enumerate(self.edges):
            if edge.to == to:
                del self.edges[i]
                return True
        return False


class Edge:
    __slots__ = ("to", "weight")

    def __init__(self, to, weight=None):
        self.to = to
        self.weight = weight


class AdjacentListGraph:
    def __init__(self, vertices):
        self.vertices = vertices
        self.size = len(vertices)

    def get_weight(self, from_: int, to: int):
        for edge in self.vertices[from_].edges:
            if edge.to == to:
                return edge.weight
        return None

    def edges_from(self, from_: int):
        return self.vertices[from_].edges

    def add_edge(self, from_: int, to: int, weight=None) -> bool:
        return self.vertices[from_].add_edge(to, weight)

    def remove_edge(self, from_: int, to: int) -> bool:
        return self.vertices[from_].remove_edge(to)

    def is_adjacent(self, from_: int, to: int) -> bool:
        return to in {edge.to for edge in self.edges_from(from_)}


if __name__ == "__main__":
    main()


Measured memory_bytes: 122656
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 1005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int dp[ARRAY_MAX][ARRAY_MAX];


int main() {

	int n;
	cin >> n;
	for (int tm = 0; tm < n; tm++)
	{
		string s, t;
		cin >> s >> t;
		int s_siz = s.size();
		int t_siz = t.size();

		for (int i = 0; i < s_siz; i++) {
			for (int j = 0; j < t_siz; j++) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else {
					dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				}
			}
		}
		cout << dp[s_siz][t_siz] << endl;

	}

	return 0;
}


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

using namespace std;
using ll = long long;
int n;
string s;

bool p(int len) {
    for (int j = 0; j + len - 1 < n; j++) {
        string tmp = s.substr(j, len);
        size_t pos = s.find(tmp, j + len);
        if (pos != string::npos) {
            return 1;
        }
    }
    return 0;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n;
    cin >> s;
    int lo = 0, hi = n;
    int ans = -1;
    while(lo <= hi) {
        int mid = (lo + hi + 1) / 2;
        if (p(mid)) {
            lo = mid + 1;
            ans = mid;
        } else {
            hi = mid - 1;
        }
    }
    assert(ans != -1);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
# C - Many Requirements
import sys
sys.setrecursionlimit(10000)

N,M,Q = map(int,input().split())
q = []
for _ in range(Q):
    q.append(list(map(int,input().split())))
A_list = []

def make(a):
    global A_list,N,M
    if len(a)==N:
        A_list.append(a)
    else:
        for i in range(a[len(a)-1],M+1):
            make(a+[i])
make([1])

ans = 0
for A in A_list:
    tmp = 0
    for a,b,c,d in q:
        if A[b-1]-A[a-1]==c:
            tmp += d
    ans = max(ans,tmp)

print(ans)

Measured memory_bytes: 16228
#include <iostream>
using namespace std;
int main(void)
{
  long long N,h=0,h1,cnt=0,maxc=0,i;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> h1;
    if(h1<=h) {
      h=h1;
      cnt++;
    } else {
      cnt=0;
      h=h1;
    }
    maxc=cnt>maxc?cnt:maxc;
  }
  cout << maxc << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

map<pair<int, int>, int> reserved;
set<pair<int, int> > open;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    reserved.clear();
    open.clear();
    open.insert(make_pair(0, 1000000000));
    REP(iter, n) {
      char c;
      scanf(" %c ", &c);
      if (c == 'W') {
        int id, s;
        scanf("%d %d", &id, &s);
        set<pair<int, int> >::iterator it = open.begin();
        while (s > 0) {
          int u = min(s, it->second);
          reserved[make_pair(it->first, u)] = id;
          s -= u;
          if (u < it->second) {
            int nstart = it->first + u;
            int width = it->second - u;
            open.erase(it++);
            open.insert(make_pair(nstart, width));
          } else {
            open.erase(it++);
          }
        }
      } else if (c == 'D') {
        int id;
        scanf("%d", &id);
        map<pair<int, int>, int>::iterator it = reserved.begin();
        while (it!= reserved.end()) {
          if (it->second == id) {
            open.insert(make_pair(it->first.first, it->first.second));
            reserved.erase(it++);
          } else {
            it++;
          }
        }
      } else {
        int p;
        scanf("%d", &p);
        FORIT(it, reserved) {
          int s = it->first.first;
          int l = it->first.second;
          if (s <= p && p < s + l) {
            printf("%d\n", it->second);
            goto next;
          }
        }
        puts("-1");
next:;
      }
    }
    puts("");
  }
}

Measured memory_bytes: 1080
#coding: utf-8
from collections import deque

H, W = (int(x) for x in input().split())
A = []

curMove = []
moves = []
hasOdd = False
pi = -1
pj = -1
for i in range(H):
    row = [int(x) for x in input().split()]
    if i % 2 == 0:
        start, end, diff = 0, W, 1
    else:
        start, end, diff = W-1, 0-1, -1

    for j in range(start, end, diff):
        if row[j] % 2 == 1:
            if hasOdd:
                curMove.append((pi,pj, i, j))
                moves += curMove
                curMove = []
                hasOdd = False
            else:
                hasOdd = True
        else:
            if hasOdd:
                curMove.append((pi,pj, i, j))
        pi = i
        pj = j

print(len(moves))
for m in moves:
    print(" ".join((str(i+1) for i in m)))


Measured memory_bytes: 24136
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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

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

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


int N;
double x[10];
double y[10];


int main () {
  cin >> N;
  rep(i, N) {
    cin >> x[i] >> y[i];
  }
  vector<int> v(N);
  iota(v.begin(), v.end(), 1);

  double ans = 0;

  do { 
    for (int i=1;i<=N-1;++i) {
      //cout << v[i-1] << " " << v[i] << "\n";
      ans += sqrt(pow((x[v[i-1]] - x[v[i]]), 2) + pow((y[v[i-1]] - y[v[i]]), 2));
    }
  } while (next_permutation(v.begin(), v.end()));

  ans /= fact(N);
  printf("%.10f\n", ans);
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, x;
    int m[100];
    cin >> n >> x;
    for (int i = 0; i < n; i++)
        cin >> m[i];

    sort(m, m + n);
    /*
    for (int i = 0; i < n; i++)
        cout << m[i] << " ";
    cout << endl;
*/
    for (int i = 0; i < n; i++)
        x -= m[i];

    int cnt = n;
    while (x - m[0] >= 0)
    {
        x -= m[0];
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    int n; cin >> n;
    vector<int> a(n+2);
    rep(i,n) cin >> a[i+1];

    ll sum = abs(a[1]),ans;
    rep(i,n-1){
        sum += abs(a[i+2] - a[i+1]);
    }
  	sum += abs(a[n]);
      
    for(int i=1;i<n+1;i++){
        ans = sum + abs(a[i+1] - a[i-1]) - (abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]));
        cout << ans << endl;
    }
}

    
    

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	string a, b, c; cin >> a >> b >> c;
	deque<char>A, B, C;
	rep(i, 0, a.size()) {
		A.push_back(a[i]);
	}
	rep(i, 0, b.size()) {
		B.push_back(b[i]);
	}
	rep(i, 0, c.size()) {
		C.push_back(c[i]);
	}
	char ch = 'a';
	while (1) {
		if (ch == 'a') {
			if (A.empty()) {
				puts("A");
				break;
			}
			ch = A.front();
			A.pop_front();
		}
		else if (ch == 'b') {
			if (B.empty()) {
				puts("B");
				break;
			}
			ch = B.front();
			B.pop_front();
		}
		else {
			if (C.empty()) {
				puts("C");
				break;
			}
			ch = C.front();
			C.pop_front();
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,n,k,m=1000000000,a;
string s,t;
char tmp;
int main()
{
  for(cin>>s>>t;i<s.size();i++){
    if(s.compare(t)==0)return cout<<"Yes", 0;
    tmp=s[s.size()-1];
    s=tmp+s.substr(0,s.size()-1);
  }
  cout<<"No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <vector>

// constexpr std::int64_t INF = 1ull << 50;
constexpr int INF = 1 << 20;

auto main() -> int {
  std::uint64_t r, D, x;
  std::cin >> r >> D >> x;

  for (auto i = 0u; i < 10; ++i) {
    x = r * x - D;
    std::cout << x << '\n';
  }
}


Measured memory_bytes: 384
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long i; long long j;
};


ll const MAX = 200005;
string s;
ll memo[MAX][30] = {};

int main() {
	ll n;
	cin >> s;
	n = s.size();
	REP(i, 1, n) {
		char cur = s[i - 1];
		REP(j, 0, 25) {
			memo[i][j] = memo[i - 1][j];
		}
		memo[i][cur - 'a']++;
	}
	ll ans = 0;
	REP(i, 1, n) {
		ll cur = s[i - 1] - 'a';
		ans += i - 1 - memo[i - 1][cur];
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 47492
#include<iostream>
#include<cstring>
#define MAX_N 103
using namespace std;
void solve();
void dfs(int,int,char);
char field[MAX_N][MAX_N];
int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
int W,H;
void print();
int main(){
  while(cin>>H>>W,W){
    memset(field,-1,sizeof(field));
    for(int i=1;i<H+1;i++){
      for(int j=1;j<W+1;j++){
	cin>>field[i][j];
      }
    }
     solve();
  }
  return 0;
}
void dfs(int x,int y,char c){
  if(field[y][x]!=c)return;
  field[y][x]=-1;
  dfs(x+dx[0],y+dy[0],c);
  dfs(x+dx[1],y+dy[1],c);
  dfs(x+dx[2],y+dy[2],c);
  dfs(x+dx[3],y+dy[3],c);
  return ;
}
void solve(){
  int a=0;
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      if(field[i][j]!=-1){
	a++;
	dfs(j,i,field[i][j]);
      }
    }
  }
  cout<<a<<endl;
}
void print()
{
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout<<field[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
 
using namespace std;
 
#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif
 
#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair
 
#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];
 
//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif
 
typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;
 
void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}
 
signed main(void)
{
  ll i;
  in(ll,k);
  if(k==0)
    {
      printf("4\n3 3 3 3\n");
      return 0;
    }
  if(k==1)
    {
      cout<<2<<endl;
      cout<<2<<" "<<0<<endl;
      return 0;
    }
  if(k<50)
    {
      cout<<k<<endl;
      for(i=0;i<k;i++)
	cout<<i+1<<" ";
      cout<<endl;
      return 0;
    }
  ll ama=k%50;
  ll sho=k/50;
  ll base=50-ama;
  ll a[50]={};
  rep(i,50)
    {
      ll sum=(i>=base);//base+i+1;
      //if(sum>49)sum-=51;
      a[i]=sum+sho+i;
    }
 
  cout<<50<<endl;
  rep(i,50)
    cout<<a[i]<<" ";
  cout<<endl;  
 
  return 0;
}

Measured memory_bytes: 256