akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi sosuu(ll n){   //n以下の素数列挙
    vector<bool> b(n-1,true);
    for(ll i=2;i<=sqrt(n);i++){
        if(!b[i-2])continue;
        for(ll j=2;i*j<=n;j++)b[i*j-2]=false;
    }
    vi res;
    rep(i,n-1)if(b[i])res.pb(i+2);
    return res;
}
bool is_prime(ll n){
    if(n<=1)return false;
    REP(i,2,sqrt(n)+1)if(n%i==0)return false;
    return true;
}
vp bunkai(ll n){
    vp res;
    if(n<=1)return res;
    vi x=sosuu(sqrt(n)+1);
    for(ll i:x){
        if(n%i!=0)continue;
        ll k=0;
        while(n%i==0){
            k++;
            n/=i;
        }
        res.eb(i,k);
    }
    if(n!=1)res.eb(n,1);
    return res;
}
int main(){
    long double a,b;cin>>a>>b;
    out((ll)(a*b));
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define ll long long

ll n,ans=0;
void dfs(ll x, ll a, ll b, ll c) {
  if (x > n) return;
  if (a&b&c) ans++;
  dfs(x*10+3,1,b,c);
  dfs(x*10+5,a,1,c);
  dfs(x*10+7,a,b,1);
}

int main() {
  cin>>n;
  dfs(0,0,0,0);
  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
# マスの左側から順に隣接するマスを比較する。
# 隣り合う右のマスより高いマスがある場合、高さを1低くする。
a[0]=a[0]-1
for i in range(1,n):
    if i+1<n and a[i-1]<a[i]:
        a[i]-=1
# 再び隣接するマスの比較を行う。
# 隣り合う右のマスより高いマスがある場合は"No"を表示する。
for i in range(n):
    if i+1<n and a[i]>a[i+1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14396
a = gets.chomp
b = gets.chomp
M = gets.to_i

# k: 桁（n桁の数字について調べているときは n-1 は1の位を表す）
# f: 上限と等しい場合 0 そうでない場合 1
# u: 1（より大きい数字を探す）or 0（より小さい数字を探す）
# pre: 一桁左の数字
# mod: m での mod
# zero: 調べている位より上が全部0の場合 true そうでない場合 false
def get(k, f, u, pre, mod, zero)
    if k == @n
        return zero ? 0
         : mod==0 ? 1
         : 0
    end
    res = 0
    if zero
        res += get(k+1,1,0,0,0,true);
        (1..9).each do |i|
            res += get(k+1,1,0,i, i % M,false);
            if k+1 != @n
                res += get(k+1,1,1,i,i % M,false);
            end
        end
        return res % 10000
    end
    if @dp[k][f][u][pre][mod] != nil
        return @dp[k][f][u][pre][mod]
    end
    if f == 1
        if u == 1
            ((pre+1)..9).each do |i|
                res += get(k+1,1,0,i,(mod*10+i) % M,false)
            end
        else
            (0..(pre-1)).each do |i|
                # puts "#{k+1},#{1},#{1},#{p},(mod*10+i) % M"
                res += get(k+1,1,1,i,(mod*10+i) % M,false)
            end
        end
    else
        if u == 1
            ((pre+1)..@s[k]).each do |i|
                if i == @s[k]
                    res += get(k+1,0,0,i,(mod*10+i) % M,false)
                else
                    res += get(k+1,1,0,i,(mod*10+i) % M,false)
                end
            end
        else
            (0..[pre-1, @s[k]].min).each do |i|
                if i == @s[k]
                    res += get(k+1,0,1,i,(mod*10+i) % M,false)
                else
                    res += get(k+1,1,1,i,(mod*10+i) % M,false)
                end
            end
        end
    end
    res = res % 10000
    @dp[k][f][u][pre][mod] = res
    return res
end

def calc(r)
    @n = r.length
    @s = r.split("").map(&:to_i)
    @dp = Array.new(@n+1)
    (0..@n).each do |i|
        @dp[i] = Array.new(2)
        (0..1).each do |j|
            @dp[i][j] = Array.new(2)
            (0..1).each do |k|
                @dp[i][j][k] = Array.new(10)
                (0..9).each do |l|
                    @dp[i][j][k][l] = Array.new(M)
                end
            end
        end
    end
    res = 0
    res += get(1, 1, 0, 0, 0, true)
    (1..@s[0]).each do |i|
        if i == @s[0]
            res += get(1,0,0,i,i % M,false)
            if @n != 1
                res += get(1,0,1,i,i % M,false)
            end
        else
            res += get(1,1,0,i,i % M,false)
            if @n != 1
                res += get(1,1,1,i,i % M,false)
            end
        end
    end
    return res % 10000
end

def judge(r)
    array = r.split("").map(&:to_i)
    pre_diff = nil
    (0..(array.length-2)).each do |i|
        diff = array[i] - array[i+1]
        return false if diff == 0
        if pre_diff == nil
            pre_diff = diff
            next
        end

        if pre_diff * diff < 0
            pre_diff = diff
        else
            return false
        end
    end
end

puts (calc(b) - calc(a) + 10000 + (judge(a) ? 1 : 0)) % 10000 



Measured memory_bytes: 133984
def check(P):
    for i in range(len(P)-1):
        if P[i] != P[i+1]:
            return i
    return "Non"
def min_2(a,b):
    if a < b:
        return a
    else:
        return b
P = list(input())
c0 = P.count("0")
c1 = P.count("1")
print(min_2(c0,c1)*2)
#t = check(P)
#pop = 0
#while t != "Non":
#    P.pop(t)
#    P.pop(t)
#    pop+=1
#    t = check(P)
#print(pop*2)


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

using ll = long long;

int main() {
	int n;
	cin >> n;
	map<string, int> cnt;
	for(int i=0;i<n;i++) {
		string s;
		cin >> s;
		cnt[s]++;
	}
	for(string s: {"AC", "WA", "TLE","RE"}) {
		cout << s << " x " << cnt[s] << endl;
	}
}

Measured memory_bytes: 3632
/*
author: diradon
25-Sep-19
21:35:25
*/

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

ll solve(vector<ll> w, vector<ll> v, ll space_avail, ll n)
{
    if (n == 0 or space_avail == 0)
        return 0;
    if (w[n-1] > space_avail)
        return solve(w, v, space_avail, n-1);

    return max(v[n-1] + solve(w,v,space_avail-w[n-1], n-1),  solve(w, v, space_avail, n-1));
}

ll ksolve(vector<ll> w, vector<ll> v, ll space_avail, ll n)
{
    ll cost[n+1][space_avail+1];
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = 0; j <= space_avail; j++)
        {
            if (i == 0 or j == 0)
                cost[i][j] = 0;
            else if (w[i-1] <= j)
                cost[i][j] = max(v[i-1] + cost[i-1][j-w[i-1]], cost[i-1][j]);
            else
                cost[i][j] = cost[i-1][j];
        }
    }
    return cost[n][space_avail];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, wmax;
    cin >> n >> wmax;
    vector<ll> w(n), v(n);
    for (int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    
    //cout << solve(w, v, wmax, n) << endl;
    cout << ksolve(w, v, wmax, n) << "\n";
    

}

Measured memory_bytes: 79232
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector <int> n;

int main(){
	long long n,k,ans;
	cin>>n>>k;
	ans=n;
	if(n>k){
		n=n-n/k*k;
	}
	cout<<min(n,k-n)<<endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll a[3*n];
  rep(i, 3*n) cin >> a[i];
  ll suml[n+1], sumr[n+1];
  suml[0] = 0, sumr[0] = 0;
  priority_queue<ll, vector<ll>, greater<ll>> sl;
  priority_queue<ll> sr;
  rep(i, n){
    sl.push(a[i]); suml[0] += a[i];
    sr.push(a[3*n-1-i]); sumr[0] += a[3*n-i-1];
  }
  rep(i, n){
    sl.push(a[n+i]);
    suml[i+1] = suml[i] + a[n+i] - sl.top();
    sl.pop();
    sr.push(a[2*n-1-i]);
    sumr[i+1] = sumr[i] + a[2*n-1-i] - sr.top();
    sr.pop();
  }
  ll ans = -INF;
  rep(i, n+1) ans = max(ans, suml[i]-sumr[n-i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5996
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    while(b<=a&&k!=0)
    {
        b=b*2;
        k--;
    }
    while(k!=0)
    {
        c*=2;
        k--;
    }
    if(b>a&&c>b)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
}

Measured memory_bytes: 3644
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;




//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
    }
    let h = "hon";
    let p = "pon";
    let b = "bon";
    let v = vec![p,p,h,b,h,h,p,h,p,h];

    println!("{}", v[n%10]);
}



Measured memory_bytes: 2112
/**
 * Square Route
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line.substring(0, line.indexOf(' ')));
			int m = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((n | m) == 0) break;

			//
			int[] ns = new int[n + 1];
			int[] ms = new int[m + 1];

			for (int i = 1; i < n + 1; i++) {
				ns[i] = parseInt(br.readLine()) + ns[i - 1];
			}
			for (int i = 1; i < m + 1; i++) {
				ms[i] = parseInt(br.readLine()) + ms[i - 1];
			}

			//
			int[][] nm = new int[Math.max(ns[n], ms[m]) + 1][2];

			for (int i = 0; i < n; i++) {
				for (int j = i; j < n + 1; j++) {
					nm[ns[j] - ns[i]][0]++;
				}
			}
			for (int i = 0; i < m; i++) {
				for (int j = i; j < m + 1; j++) {
					nm[ms[j] - ms[i]][1]++;
				}
			}

			int sum = 0;
			for (int i = 1; i < nm.length; i++) {
				sum += nm[i][0] * nm[i][1];
			}
			System.out.println(sum);
		} //end while
	} //end main
}

Measured memory_bytes: 90852
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;


vector<vector<int>> grid_bfs(int h,int w,int x,int y,vector<string> &maze,char obstacle='#') {
  const int dx[] = { 1,0,-1,0}, dy[] = { 0,1,0,-1};//4方向移動
  const int init=1e7;
  vector<vector<int>>d(h,vector<int>(w,init));
  d[x][y]=0;
  deque<pair<int, int>>q;
	pair<int, int>p;
  q.emplace_back(x,y);
	while (!q.empty()) {
		p = q.front();
		q.pop_front();
		for (int i = 0; i < 4;++i) {
			int nx = p.first+dx[i]; int ny = p.second+dy[i];
			if (0 <= nx && nx < h && 0 <= ny && ny < w &&chmin(d[nx][ny],d[p.first][p.second])&&maze[nx][ny]!=obstacle) {
				q.emplace_front(nx,ny);
			}
			for(int a=-2;a<=2;++a){
				for(int b=-2;b<=2;++b){
					if(0<=p.first+a&&p.first+a<h&&0<=p.second+b&&p.second+b<w&&chmin(d[p.first+a][p.second+b],d[p.first][p.second]+1)&&maze[p.first+a][p.second+b]!=obstacle){
						q.emplace_back(p.first+a,p.second+b);
					}
				}
			}
		}
	}
  return d;//initを含むことに注意
}
 
using P=pair<int,int>;
void solve(){
  int h,w;
  cin>>h>>w;
  vector<string>s(h);
  P start,goal;
	cin>>start.first>>start.second;
	start.first--;
	start.second--;
	cin>>goal.first>>goal.second;
	goal.first--;
	goal.second--;
  rep(i,h){
    cin>>s[i];
  }
  auto x=grid_bfs(h,w,start.first,start.second,s);
  if(x[goal.first][goal.second]==1e7)cout<<-1;
  else cout<<x[goal.first][goal.second];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

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

int main(){
  string s; cin >> s;
  rep(i,s.size()-1){
    if(s[i]==s[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
  	$num = fgets(STDIN);
 	$arr = str_split(fgets(STDIN));
	$ans = 0;


	for($i=0; $i< $num; $i++){
    	if ($arr[$i] == $arr[$i+1]){
          
        }else{
          $ans++;
        }
    }
	echo $ans;

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

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
priority_queue<long long int> PQ1;

int main(){
  int N;
  cin >>N;
  vector<int> list;
  for(int i  = 0;i<N;i++){
      int w;
      cin >>w;
      list.push_back(w);
  }

  int ans = 999999999;

  for(int i = 1; i< N;i++){
    int l = 0;
    int r = 0;
    for(int j = 0;j<i;j++){
       l += list[j];
    }
    for(int j = i;j<N;j++){
       r += list[j];
    }
    if(ans > abs(l-r))ans =abs(l-r);
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
#define vi vector<int>
#define vl vector<long long>
#define vd vector<double>
#define vp vector<pair<int,int> >
#define ll long long
#define pi pair<int,int>
#define popcnt(x) __builtin_popcountll(x)
#define LSOne(x) ((x) & (-(x)))
#define xx first
#define yy second
#define PQ priority_queue
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prp(p) cerr << "(" << (p).first << " ," << (p).second << ")";
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
using namespace std;

string s1,s2;
int n;

const int MAXN = 52,mod = 1e9 + 7;
int dp[MAXN][4][4];

int add(int a,int b){
	a += b;
	if(a >= mod) a -= mod;
	return a;
}

int solve(int cur,int top,int bottom){
	if(cur == n) return 1;
	if(dp[cur][top][bottom] != -1) return dp[cur][top][bottom];
	int & ret = dp[cur][top][bottom];
	ret = 0;
	if(s1[cur] == s2[cur]) {
		for(int c = 1;c <= 3;c++)
			if(c != top && c != bottom) {
				ret = add(ret,solve(cur+1,c,c));
			}
		return ret;
	}
	if(!cur) {
		for(int c1 = 1;c1 <= 3;c1++)
			for(int c2 = 1;c2 <= 3;c2++)
				if(c1 != c2)
					ret = add(ret,solve(cur + 1,c1,c2));
		return ret;
	}
	bool t = s1[cur] == s1[cur - 1];
	bool b = s2[cur] == s2[cur - 1];
	vi T,B;
	if(t) T = vi{top};
	else {
		range(c,1,3) if(c != top) T.pb(c);
	}
	if(b) B = vi{bottom};
	else {
		range(c,1,3) if(c != bottom) B.pb(c);
	}
	for(int c1 : T) for(int c2 : B) if(c1 != c2) ret = add(ret,solve(cur+1,c1,c2));
	return ret;
}

int main(){
	#ifdef HOME
		freopen("in.in", "r", stdin);
	#endif
	cin >> n >> s1 >> s2;
	memset(dp,-1,sizeof dp);
	cout << solve(0,0,0) << endl;
	return 0;
}


Measured memory_bytes: 256
class UnionFindVerSize():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N)]
        # グループのサイズ（個数）
        self._size = [1] * N

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属するグループを併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        """ xが属するグループのサイズ（個数）を返す """
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        """ グループ数を計算して返す """
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans


N,K,L=map(int,input().split())
ufload=UnionFindVerSize(N)
for i in range(0,K):
    p,q=map(int,input().split())
    ufload.unite(p-1,q-1)
ufrail=UnionFindVerSize(N)
for i in range(0,L):
    r,s=map(int,input().split())
    ufrail.unite(r-1,s-1)

data=[]
for i in range(0,N):
    data.append([ufload.find_root(i),ufrail.find_root(i),i])

data.sort()
ans=[0 for i in range(0,N)]
start=0
end=0
count=1
for i in range(0,N-1):
    if data[i][0]==data[i+1][0] and data[i][1]==data[i+1][1]:
        count+=1
    else:
        end=start+count-1
        for j in range(start,end+1):
            ans[data[j][2]]=count
        start=end+1
        count=1

end=start+count-1
for j in range(start,end+1):
    ans[data[j][2]]=count
start=end+1
count=1

print(*ans)

Measured memory_bytes: 114948
#include <iostream>
#include <cstring>
#define MAXK 1000005
#define BIG_NUM 1000000007

using namespace std;

int N;					//Number of children
int K;					//Number of candies
long long ways[MAXK];//Number of ways in which we can distribute the candies
int a;					//Maximum number of candies current child can recieve
long long sum;					//Sum of other ways for current update

int main(){
	cin>>N>>K;
	
	memset(ways,0,sizeof(ways));
	ways[K]=1;

	for(int i=0;i<N;i++){
		cin>>a;

		sum=0;
		for(int j=1;j<=min(a,K);j++){
			sum += ways[j];
			sum %= BIG_NUM;
		}

		for(int j=0;j<=K;j++){
			ways[j] = (ways[j]+sum)%BIG_NUM ;
			sum -= ways[j+1];
			if(j+a+1<=K)
				sum += ways[j+a+1];
			sum = (sum+BIG_NUM)%BIG_NUM;
		}

	}
	cout<<ways[0]<<endl;
}



Measured memory_bytes: 8064
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	bitset<4000010>dp(1);
	int n;
	cin>>n;
	int sum=0;
	rep(i,n){
		int a;cin>>a;
		sum+=a;
		dp|=dp<<a;
	}
	loop(i,(sum+1)/2,1000000000)if(dp[i]){
		cout<<i<<endl;
		return 0;
	}
}









Measured memory_bytes: 1664
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main(){
	int K=0, U=0, P=0, C=0;
	string input;

	cin >> input;

	for(int i=0; i < input.length(); i++){
		switch(input[i]){
			case 'K':
				K++;
				break;
			case 'U':
				U++;
				break;
			case 'P':
				P++;
				break;
			case 'C':
				C++;
				break;
		}
	}
	cout << min(K, min(U, min(P, C))) << endl;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main(){
    int P, Q, R;
    cin>>P>>Q>>R;
    int a=max(P, Q);
    a=max(a, R);
    cout<<P+Q+R-a<<endl;
}

Measured memory_bytes: 256
n, a, b = gets.to_s.split.map{|t| t.to_i }

if n == 1 && a != b
  puts 0
  exit
end

if a > b
  puts 0
  exit
end

if n <= 2
  puts 1
  exit
end

puts b * (n-2) - a * (n-2) + 1

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int X;
    cin >> X;
    int res = 1;
    for(int i = 2;i < 33; ++i){
        int a = i;
        REP(j,10){
            a *= i;
            if(X < a){
                if(j == 0){
                    a = 1;
                    break;
                }
                else a /= i;
                break;
            }
        }
        res = max(res, a);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n,k,s;
		cin>>n>>k>>s;
		vi v;
		for(int i=1;i<=k;i++) v.pb(s);
		while(v.size()!=n)
		{
			if(s==1e9) v.pb(1);
			else v.pb(1e9);
		}
		for(auto i:v) cout<<i<<" ";
	}
	return 0;
}

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

int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int count=0;
  while(A>=B){
    B=B*2;
    count+=1;
  }
  while(B>=C){
    C=C*2;
    count+=1;
  }
  if(count<=K)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}

Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
class Simple {
    private string s;
    void Solve() {
        //input
        s = io.String;
        //cal
        var win = 0;
        var los = 0;
        var pNum = 0;
        var gNum = 0;
        Func <bool> availableP=()=>pNum + 1 <= gNum;
        Func <int, bool> drawableWithG = (index) => s[index] == 'g'; 
        Func <int, bool> drawableWithP = (index) => s[index] == 'p' && availableP(); 
        Func <int, bool> winable = (index) => availableP() && s[index] == 'g';
        for(int i = 0; i < s.Length; ++i) {
            if(winable(i)) {
                win++;
                pNum++;
            } else if(drawableWithG(i)) {
                gNum++;
            }else if(drawableWithP(i)) {
                pNum++;
            }
            else {
                los++;
                gNum++;
            }
        }
        //ret
        Console.WriteLine(win-los);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] {' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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 main(){
    long long R;
    scanf("%lld",&R);
    // long long M;
    // scanf("%lld",&M);
    // std::vector<long long> A(M);
    // for(int i = 0 ; i < M ; i++){
    //     scanf("%lld",&A[i]);
    // }
    //solve(N, M, std::move(A));
    cout << 2*R*PI << endl;
    return 0;
}


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

using namespace std;

using uint = unsigned int;

int main (void){
  uint h, w;
  cin >> h >> w;
  cin.ignore();
  char a[h][w];

  for (uint i = 0; i < h; i++){
    for (uint j = 0; j < w; j++){
      cin >> a[i][j];
    }
    cin.ignore();
  }

  for (uint i = 0; i < w+2; i++){
    cout << "#" << flush;
  }
  cout << endl;
  for(uint i = 0; i < h; i++){

    cout << '#' << flush;
    for (uint j = 0; j < w; j++){
      cout << a[i][j] << flush;
    }
    cout << '#' << endl;
  }
  for (uint i = 0; i < w+2; i++){
    cout << "#" << flush;
  }
  cout << flush;
  

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    long a, b, c, d;
    scan(n, a, b, c, d);

    b = b - a;
    a = 0;

    auto s = - (n - 1) * d;
    auto t = - (n - 1) * c;

    foreach (i ; 0 .. n) {
        if (s <= b && b <= t) {
            writeln("YES");
            return;
        }
        s += c + d;
        t += c + d;
    }

    writeln("NO");
}










void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
N, M, X, Y = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
x.append(X)
y.append(Y)
if max(x) < min(y):
  print("No War")
else:
  print("War")

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

int main() {
  
  long long A, B, K;
  cin >> A >> B >> K;
  
  if (A >= K) {
    A = A - K;
  }
  else if (B >= K - A) {
    B = B - (K - A);
    A = 0;
  }
  else {
    A = 0;
    B = 0;
  }
  
  cout << A << " " << B << endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
	ll  n, k;
	cin >> n >> k;
	ll ans = 0;
	for (ll i = k; i <= n + 1; i++) { 
		ll c = (i * (n - i + 1)) + 1;
		ans += c;
		ans = ans % 1000000007;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3600
// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba-064a5016a 

#include <bits/stdc++.h>
using namespace std;
#define int     long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
signed main()
{
	fast_io
	int n;
	cin >> n;
	vector < long double > p(n);
	for(int i = 0; i < n; i++)
		cin >> p[i];
	long double dp[n + 1][n + 1];
	dp[0][0] = 1.000000;
	for(int i = 1; i <= n; i++)
		dp[0][i] = 0.0000;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 0; j<= n; j++)
		{
			if(i < j)
			{
				dp[i][j] = 0.0000;
				continue;
			}
			dp[i][j] = dp[i - 1][j]*(1.0000 - p[i - 1]);
			if(j - 1 >= 0)
				dp[i][j] += (dp[i - 1][j - 1]*p[i - 1]);
		}
	}
	long double ans = 0.00000000000;
	for(int i = n/2 + 1; i <= n; i++)
		ans += dp[n][i];
	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
const int N=85;
typedef long long ll;
ll a[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	int left=1,right=1;
	bool flag=0,flag2=1;
	ll money=1000,stock=0;
	for(int i=2;i<=n;i++){
		if(a[i]>a[i-1]){
			if(flag==0){
				stock+=money/a[i-1];
				money%=a[i-1];
			}
			flag=1;
			right=i;
		}
		else if(a[i]<a[i-1]){
			if(flag==1){
				money+=stock*a[i-1];
				stock=0;
			}
			flag=0;
			left=i;
		}
		if(i==n) money+=stock*a[i],stock=0;
	}
	printf("%lld",money);
	return 0;
}


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

using namespace std;

typedef long long LL;
#define N 220000

LL n,m,k,a[N],vis[N],q[N],f[N][62],lst[N],g[N][62];

int main(){
	srand((unsigned long long)new char+time(NULL));
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=n;++i) scanf("%lld",a+i);
	for (int i=n;i;--i){
		f[i][0]=lst[a[i]]; g[i][0]=0;
		lst[a[i]]=i;
	}
	for (int i=n;i;--i)
		if (!f[i][0]){f[i][0]=lst[a[i]]; g[i][0]=1;}
	for (int i=1;i<=n;++i)
		if (f[i][0]<n) ++f[i][0];
		else{f[i][0]=1; ++g[i][0];}
	for (int j=1;j<=60;++j){
		for (int i=1;i<=n;++i){
			f[i][j]=f[f[i][j-1]][j-1];
			g[i][j]=g[i][j-1]+g[f[i][j-1]][j-1];
		}
	}
	LL x=1,y=1;
	for (int k=60;~k;--k)
		if (y+g[x][k]<=m){
			y+=g[x][k];
			x=f[x][k];
		}
	int xb=0;
	for (int i=x;i<=n;++i){
		if (!vis[a[i]]){vis[a[i]]=++xb; q[xb]=a[i];}
		else{
			for (;xb>vis[a[i]];--xb){vis[q[xb]]=0; q[xb]=0;}
			vis[q[xb]]=0; q[xb]=0; --xb;
		}
	}
	for (int i=1;i<=xb;++i) printf("%lld ",q[i]);
	puts("");
	
	return 0;
}
			

Measured memory_bytes: 206976
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    char c;
    string ans;
    cin >> c;
    ans = "consonant";
    if(
        c == 'a' ||
        c == 'i' ||
        c == 'u' ||
        c == 'e' ||
        c == 'o'
    ) {
        ans = "vowel";
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 512
# -*- coding: utf-8 -*-
 
n = int(input())
w=[]
for i in range(n):
    w.append(str(input()))

i=int(0)
z=str(w[0][:1])
x=int(0)
k=int(0)

while i < n:
    a=str(w[i][:1])
    if z != a:
        x=1
    z=str(w[i][-1:])
    k=int(0)
    while k < i:
        if w[i]==w[k]:
            x=1
        k +=1
    if x==1:
        break
    i+=1
    

if x==1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3064
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    read!(usize);
    let S = rl().chars().collect::<Vec<_>>();

    let R = S.iter().filter(|&&c| c == 'R').count();
    let B = S.iter().filter(|&&c| c == 'B').count();

    println!("{}", if R > B { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    let ans = if a <= b { a } else { a - 1 };
    println!("{}", ans);
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
14min 05sec
"""
# 実験したら規則性が見えた。

#import itertools
#
#def test():
#    for i in range(1, ):
#        N = i
#        #N = int(input())
#        N_list = list(range(1, N+1))
#
#        answer = 0
#        for P_list in itertools.permutations(N_list):
#            answer = max(
#                answer,
#                sum([N_list[i] % P_list[i] for i in range(N)])
#            )
#        print(i, answer)

def main():
    N = int(input())
    print(N*(N-1)//2)
    return

if __name__ == "__main__":
    main()




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

int main()
{
  ll N,K;cin>>N>>K;
  
  double sum=0;
  for (int i=1;i<=N;i++)
  {
    //サイコロの目がiだった時、勝てる確率を求める
    int count=0;
    int point=i;
    while (point<=K-1)
    {
      point *= 2;
      count++;
    }
    //cout<<i<<": "<<count<<endl;
    sum += pow(0.50000000000000,count);
    //cout << fixed << setprecision(15) << sum<< endl;
  }
  //cout << fixed << setprecision(15) << sum << endl;
  sum /= N;
  cout << fixed << setprecision(15) << sum << endl;
}

Measured memory_bytes: 256
# 組み合わせ計算
# 約分してから計算するアルゴリズム
# 10^9 + 7 で割ったあまりを返すバージョン
MOD = 1000000007

def combination(n, r):
    # n >= 0, r >= 0, r <= n を仮定
    if n < 0 or r < 0 or n < r:
        return -1

    # r <= n - r を仮定
    if n - r < r:
        r = n - r

    # r < 2 の場合
    if r == 0:
        return 1
    if r == 1:
        return n

    # nCr の分子
    # [n - r + 1, n - r + 2, ... , n - 1, n]
    numerator = [n - r + 1 + i for i in range(r)]


    # nCr の分母
    # [1, 2, ... , r - 1, r]
    denominator = [i + 1 for i in range(r)]

    # nCr を約分する
    for i in range(r):
        # i番目の分母で約分する
        # 0番目は1なので省略

        # 元の（今までの約分を行う前の）i番目の分母の値
        original_denominator = i + 1

        # 今までの約分を行った後の、i番目の分母の値
        # 今回の約分で割る数
        divisor = denominator[i]

        # divisorが1（全て約分済み）の場合は無視する
        if divisor == 1:
            continue

        # 約分する相手の分子を決める
        # 0～i番目の分子（約分前）の中で、
        # original_denominatorで割り切れる数
        # （一つしかない）を選ぶ
        # remainder = i番目の分子 % original_denominator
        # とするとき、
        # (i - remainder)番目の分子 = i番目の分子 - remainder
        # (i - remainder)番目の分子 % original_denominator
        #  = (i番目の分子 - remainder) % original_denominator
        #  = 0
        # なので、(i - remainder)番目の分子を選べばよい。

        # remainder = i番目の分子 % original_denominator
        #           = (n - r + i + 1) % (i + 1)
        #           = (n - r) % (i + 1)
        remainder = (n - r) % original_denominator

        # divisor で約分できるペアをすべて約分する
        for j in range(i, r, original_denominator):
            numerator[j - remainder] = numerator[j - remainder] // divisor
            denominator[j] = denominator[j] // divisor

    ans = 1
    for i in numerator:
        ans = (ans * i) % MOD
    return ans

X, Y = map(int, input().split())
if X < Y:
    d = Y - X
    n = X
else:
    d = X - Y
    n = Y

# (n, n + d)
if (n - d) % 3 != 0 or n < d:
    print(0)
else:
    print(combination((2*n + d) // 3, (n - d) // 3))

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

int main() {
    int N;
    cin >> N;
    vector<int> B(N-1), A(N,0);
    for (int i = 0; i < N-1; i++){
        cin >> B[i];
    }
    
    A[0] = B[0];
    for (int i = 0; i < N-1; i++){
        A[i+1] = B[i];
        if (i > 0 && A[i] > B[i]){
            A[i] = B[i];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
        ans += A[i];
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {

	long n;
	cin >> n;

	vector<string> s(n);
	for (long i = 0; i < n; i++) {
		cin >> s[i];
	}

	vector<vector<long>> ab(n,vector<long> (26,0));

	for (long i = 0; i < n; i++) {
		for (long j = 0; j < s[i].size(); j++) {
			ab[i][s[i][j]-97]++;
		}
	}

	long counter ;
	for (long j = 0; j < 26; j++) {
		counter = 100;
		for (long i = 0; i < n; i++) {
			counter = min(counter, ab[i][j]);
		}
		for (long k = 0; k < counter; k++) {
			cout << (char)(j + 97);
		}
	}
	cout << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int main() {
    cin>>A>>B>>K;
    cout<<(A + B) * K / 2<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  
  if(a >= b && a >= c){
    printf("%d\n", b*c/2);
  } else if(b >= a && b >= c){
    printf("%d\n", a*c/2);
  } else {
    printf("%d\n", a*b/2);
  }
  
  return 0;
  
}

Measured memory_bytes: 128
using System;
using System.Linq;

class Program{
    static void Main(string[] args){
        int[] nums=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        if(nums[0]==nums[1]){
            Console.WriteLine("a == b");
        }else if(nums[0]>nums[1]){
            Console.WriteLine("a > b");   
        }else{
            Console.WriteLine("a < b");
        }
    }
}


Measured memory_bytes: 18384
import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int d[] = new int[num];
        int ans = 0;
        for(int i = 0; i<num; i++){
            d[i] =  sc.nextInt();
        }
        for(int i = 0; i<num; i++){
            for(int j = i + 1; j<num; j++){
                //System.out.println("i"+d[i]);
                //System.out.println("j"+d[j]);
                ans = ans + d[i] * d[j];
                //System.out.println("ans"+ans);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <algorithm>

bool isPrimenumber(const int n);

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> numbers(n);

	int numPrimeNumber = 0;
	int inputNumber = 0;

	for (int i = 0; i < n; i++)
	{
		std::cin >> inputNumber;
		if (isPrimenumber(inputNumber))
		{
			numPrimeNumber++;
		}
	}
	std::cout << numPrimeNumber << std::endl;
	return 0;
}

bool isPrimenumber(const int n)
{
	int loopLimit = (int)std::sqrt(n);
	for (int i = 2; i <= loopLimit; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    if (m == 0) {
        cout << 0 << ' ' << 0 << endl;
        return 0;
    }
    map<int, int> p_wa;   // 問題pのWA回数
    map<int, bool> p_ac;  // 問題pがAC済みか
    for (int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s;
        if (p_wa.count(p) == 0) {  // 初めての問題p
            p_wa[p] = (s == "AC") ? 0 : 1;
            p_ac[p] = (s == "AC") ? true : false;
        } else {  // 既知の問題p
            if (s == "AC") {
                p_ac[p] = true;
            } else {
                // 一度もACしていない場合のみWA数える
                if (!p_ac[p]) {
                    p_wa[p]++;
                }
            }
        }
    }

    int ac_cnt = 0;
    int wa_cnt = 0;
    for (auto pp : p_ac) {
        if (pp.second) ac_cnt++, wa_cnt += p_wa[pp.first];
    }

    printf("%d %d\n", ac_cnt, wa_cnt);
}

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

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int ans = abs(a[n - 1] - y);
    if (n > 1) {
        ans = max(ans, abs(a[n - 2] - a[n - 1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256