akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<class In>
void print_array(In begin, In end) {
  cout << (*begin);
  begin++;
  for (; begin != end; begin++)
  {
    cout << " " << (*begin);
  }
  cout << endl;
}

int main()
{
  ll x, a;
  cin >> x >> a;

  cout << (x < a ? 0 : 10) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
const ll mxn = 405;
const ll inf = 1000000000000000000;
ll dp[mxn][mxn], a[mxn], pre[mxn];

ll get_range(ll l, ll r)
{
	return pre[r]-pre[l-1];
}

ll calc(ll i, ll j)
{
	if(i==j) return 0;
	if(i+1==j) return a[i]+a[j];
	if(dp[i][j]!=0) return dp[i][j];
	ll mn = inf;
	for(ll k = i; k<=j-1; k++)
	{
		ll x = calc(i, k)+calc(k+1, j)+get_range(i, k)+get_range(k+1, j);
		if(x<mn) mn = x;
	}
	return dp[i][j] = mn;
}


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll N; cin>>N;
	for(ll i=1; i<=N ;i++) cin>>a[i], pre[i] = pre[i-1]+a[i];

	cout << calc(1, N) << '\n';
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

	static int[] num = new int[12];

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		for (int i = 0, j = 11; i < 12; i++, j--) {
			if (S.charAt(i) == '?') {
				num[j] = -1;
			} else {
				num[j] = S.charAt(i) - '0';
			}
		}

		int count = 0;
		int ans = 0;

		for (int i = 0; i < 12; i++) {
			if (num[i] == -1) {
				for (int j = 0; j <= 9; j++) {
					num[i] = j;
					if (check()) {
						count++;
						ans = j;
					}
					num[i] = -1;
				}
			}
		}

		if (count > 1) {
			System.out.println("MULTIPLE");
		} else {
			System.out.println(ans);
		}
	}

	static boolean check() {

		int digit = 0;

		for (int i = 11; i >= 1; i--) {
			if (i >= 7) {
				digit += num[i] * (i - 5);
			} else {
				digit += num[i] * (i + 1);
			}
		}

		digit %= 11;

		if (digit <= 1) {
			digit = 0;
		} else {
			digit = 11 - digit;
		}

		return digit == num[0];
	}
}


Measured memory_bytes: 26260
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
#include <array>
#include <unordered_map>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

bool cmpLen(const string &s1, const string &s2) { return s1.size()<s2.size(); }

unordered_map<int64, int> f;
int ch[30];

void gen() {
	srand(time(0));
	int n=1000;
	set<string> ss;
	REP (i,n) {
		int len=1+rand()%2000;
		string s;
		REP (i,len) {
			s+='a'+rand()%20;
		}
		ss.insert(s);
	}
	cout << ss.size() <<endl;
	int total=0;
	for (string s : ss) {
		cout << s << endl;
		total+=s.size();
	}
	cerr << total << endl;
}

int main() {
	//freopen("test.in","w",stdout); gen(); return 0;
	//freopen("test.in","r",stdin);
	int n;
	cin >> n;
	vector<string> ss(n);
	int64 total=0;
	REP (i,n) {
		cin >> ss[i];
		total+=ss[i].size();
	}
	f.reserve(total);
	sort(ALL(ss),cmpLen);
	int64 r=0;
	for (string s : ss) {
		int64 h=0;
		int64 p=90000000000077LL;
		// query
		INIT(ch,0);
		REP (i,s.size()) ch[s[i]-'a'+1]++;
		h=0;
		for (int i=s.size()-1;i>=0;i--) {
			REP (c,30) if (ch[c]) {
				int64 k=(h*31+c)%p;
				if (f.count(k)) r+=f[k];
			}
			h=(h*31+(s[i]-'a'+1))%p;
			ch[s[i]-'a'+1]--;
		}
		// update
		h=0;
		for (int i=s.size()-1;i>=0;i--) {
			h=(h*31+(s[i]-'a'+1))%p;
		}
        f[h]++;
	}
	cout << r << endl;
	/*int q=0;
	for (int i=0;i<n;i++) {
		//cout << ss[i] << endl;
		for (int j=0;j<n;j++) if (i!=j && ss[i].size()<ss[j].size()) {
			int match=1;
			for (int k=0;k<ss[i].size()-1;k++) {
				if (ss[i][ss[i].size()-1-k]!=ss[j][ss[j].size()-1-k]) match=0;
			}
			int ch=0;
			for (int k=ss[j].size()-ss[i].size();k>=0;k--) {
				if (ss[j][k]==ss[i][0]) ch=1;
			}
			if (match && ch) {
				q++;
			}
		}
	}
	cout << q << endl;*/
	return 0;
}


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

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

    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string op, s, p;
	int q, a, b;
	cin >> s;
	cin >> q;
	for(int i=1; i<=q; i++){
		cin >> op >> a >> b;
		if(op=="replace"){
			cin >> p;
			s.replace(a, b-a+1, p);   // replace(起始位置，长度，替换字符串) 
		}
		if(op=="reverse"){
			for(int j=a; j<=(a+b)/2; j++)  // 反转 
				swap(s[j], s[a+b-j]);
		}
		if(op=="print"){
			for(int j=a; j<=b; j++)
				cout << s[j];
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




int main() {
	ll A, B, C,K;
	cin >> A >> B >> C>>K;
	ll ans = 0;
	int c = 1 - (K % 2) * 2;
	ans = A * c - B * c;
	if (abs(ans) > 1000000000000000000) {
		cout << "Unfair" << endl;
	}
	else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// .Always initialize dp array
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int n, w; cin >> n >> w;
	vi val, wt;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		wt.pb(x);
		val.pb(y);
	}
	vector<vector<int>> dp(n + 1 , vector<int>(w + 1, 0));
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if (j < wt[i - 1])
			{
				dp[i][j] = dp[i - 1][j];
			}
			else dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]] , dp[i - 1][j]);
		}
	}
	cout << dp[n][w];
	return 0;
}

Measured memory_bytes: 83076
n = input().split()
N = []
for i in n :
  N.append(int(i))
t = 0
for i in range(0,N[0]+1) :
  for j in range(0,N[0]+1):
    z = N[1] -i-j
    if 0 <= z <=N[0] :
      t += 1
print(t)
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  int a,b,c; cin>>a>>b>>c;
  Cout(a*b/2);
}












Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}


*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;
 
int main() {
	// 入力
	int N;
    string S;
    cin >> N >> S;
    
    int E[N] = {0};
    int W[N] = {0};
    int sumE = 0;
    int sumW = 0;
    for (int i = 0; i < N; ++i){
    	if (S[i]=='W'){
    		sumE++;
    	}
    	if (S[N-i-1]=='E'){
    		sumW++;
    	}
    	E[i+1] = sumE;
    	W[N-i-2] = sumW;
    }
    int sum[N] = {0};
    for (int i = 0; i < N; ++i){
    	sum[i] = E[i] + W[i];
    	// cout << E[i] << " " << W[i] << endl;
    }
    int ans = N;
    for (int i = 0; i < N; ++i){
    	if (sum[i]<ans) ans = sum[i];
    }
 
	//出力
    cout << ans << endl;
}
 


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int a,b,c;
    Scd3(a,b,c);

    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);

    YesNo( s.size()==2 );

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int aa = sc.nextInt();
		double x[] = new double[aa];
		for(int n = 0; n < aa; n++){
			x[n] = sc.nextInt();
		}
		double a = 1;
		double b = x[0];
		for(int n=1; n < aa; n++){
			a = a*x[n] + b;
			b *= x[n];
			double t = f(Math.max(a, b), Math.min(a, b));
			a = a / t;
			b = b / t;
		}
		System.out.println((double)b/(double)a);
		
		
	}
	
	public static double f(double d, double e){
		double t = d % e;
		if(t == 1)return 1;
		else if(t == 0)return e;
		else return f(e, t);
	}
}

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

using namespace std;

#define loop(i,a,b) for(int i = a; i < b ; i ++)
#define rep(i,a) loop(i,0,a)

int main(void){
  string s;
  cin>>s;
  for(int i = s.size() - 1 ; i >= 0 ; i --){
    cout<<s[i];
  }
  cout<<endl;

}

Measured memory_bytes: 1172
#include <stdio.h> 
int main()
{
    int c[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int b;
    scanf("%d",&b);
    printf("%d",c[b-1]);
    return 0;
}

Measured memory_bytes: 128
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
const int N=2e5 + 5;
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    //vector<PI> vec;
    ll fir[n],sec[n];
    forn(i,n){
        cin>>fir[i]>>sec[i];
    }
    sort(fir,fir+n);
    sort(sec,sec+n);
    if(n&1){
        ll ans=sec[n/2]-fir[n/2]+1;
        cout<<ans;
    }
    else{
        int in=n/2;in-=1;
        ll n1=sec[in]+sec[in+1]-fir[in]-fir[in+1]+1;
        cout<<n1<<endl;
    }


    return 0;
}


Measured memory_bytes: 6788
#include <iostream>

using namespace std;

int main(){
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 10; j <= d; j++){
            ans += (j % 10 >= 2) && (j / 10 >= 2) && ((j / 10) * (j % 10) == i);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int main() {
    int n, k;
    std::cin >> n >> k;
    long double p = 0.0;
    for (int i = 1; i <= n; i++) {
        long double t;
        if (k - i <=0) {
            p += 1;
            continue;
        }
        long double r = log2(k) - log2(i);

        int rr = ceil(r);
        t = std::pow(0.5, rr);
        p += t;

    }
    std::cout << std::setprecision(12) << p/n << std::endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "sort"
)

type Player struct {
    Name int
    Score  int
}

type Place []Player

func (p Place) Len() int {
    return len(p)
}

func (p Place) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}

func (p Place) Less(i, j int) bool {

	if p[i].Score == p[j].Score {
		return p[i].Name < p[j].Name
	} else {
		return p[i].Score > p[j].Score
	}
   
}

func DataEntry(n int) Place {
	var id, sc int
	var ranking Place
	var adding Player

	for i := 0; i < n; i++ {

		fmt.Scan(&id, &sc)

		adding.Name = id
		adding.Score = sc

		ranking = append(ranking, adding)
	}

	return ranking
}

func main() {
	var ranking Place
	var num int

		fmt.Scan(&num)
		ranking = DataEntry(num)
	
	sort.Sort(Place(ranking))
	fmt.Println(ranking[0].Name ,ranking[0].Score)
}


Measured memory_bytes: 1132
#include <iostream>

using namespace std;

int w, h;
int c[50][50];
int ax[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
int ay[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
int cnt=0;

void solve(int y, int x){
	if(y<0 || h<=y || x<0 || w<=x) return;
	if(c[y][x] == 1){
		c[y][x] = 0;
		for(int i=0; i<8; i++){
			for(int j=0; j<8; j++){
				solve(y+ay[i], x+ax[j]);
			}
		}
	}
}

int main(){
	while(1){
		cin >> w >> h;
		if(!w && !h) break;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cin >> c[i][j];
			}
		}

		cnt = 0;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(c[i][j] == 1){
					solve(i, j);
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
int r,g,b,n,counter=0;
cin>>r>>g>>b>>n;
for(int i=0;i<n+1;i++){
for(int j=0;j<n+1;j++){
if((n-(i*r+j*g))%b==0&&n>=(i*r+j*g)){
counter++;
}
}
}
cout<<counter<<endl;
}


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

void solve(long long K, long long N, std::vector<long long> A)
{
    long long max_dis = 0;
    for (int i = 0; i < N; i++)
    {
        long long dis = 0;
        if (i != N - 1)
        {
            dis = A[i + 1] - A[i];
            max_dis = max(dis, max_dis);
        }
        else
        {
            dis = K - A[N - 1] + A[0];
            max_dis = max(dis, max_dis);
        }
    }
    cout << K - max_dis << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int small[200001];
int bit[1 << 26];

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


  int curr = 0;

  fill_n(small, 200001, INF);
  fill_n(bit, 1 << 26, INF);
  small[0] = 0;
  bit[0] = 0;

  for(int i = 1; i <= S.size(); i++) {
    curr ^= 1 << (S[i - 1] - 'a');
    for(int j = 0; j < 26; j++) {
      small[i] = min(bit[curr ^ (1 << j)] + 1, small[i]);
    }
    small[i] = min(bit[curr] + 1, small[i]);
    bit[curr] = min(bit[curr], small[i]);
    /*
    for(int j = i - 1; j >= 0; j--) {
      bit ^= 1 << (S[j] - 'a');
      if(__builtin_popcount(bit) <= 1) {
        small[i] = min(small[i], small[j] + 1);
      }
    }
     */
  }

  cout << small[S.size()] << endl;
}

Measured memory_bytes: 263556
#include <iostream>

#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;

int
main()
{
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (U == S)
  {
    A--;
  }
  else
  {
    B--;
  }
  cout << A << ' ' << B << endl;
  return 0;
}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 146 (https://atcoder.jp/contests/abc146)
// Problem: D: Coloring Edges on Tree (https://atcoder.jp/contests/abc146/tasks/abc146_d)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

vector<vpi> adj;
int mxd;
vi col;

void dfs(int v, int p, int ec) {
    int c = 0;
    for (auto pa : adj[v]) {
        if (pa.first == p)
            continue;
        if (c == ec)
            ++c;
        col[pa.second] = c;
        dfs(pa.first, v, c);
        ++c;
    }
}

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

    int n, a, b; cin >> n;
    adj.resize(n), col.resize(n-1);
    rep(i, n-1)
        cin >> a >> b, --a, --b, adj[a].emplace_back(b, i), adj[b].emplace_back(a, i);
    rep(i, n)
        mxd = max(mxd, sz(adj[i]));
    dfs(0, -1, -1);

    cout << mxd << '\n';
    trav(ec, col)
        cout << (ec+1) << '\n';

    return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll count(ll m){
  if(m == 1){
    return 1;
  } else{
    return 1 + 2*count(m/2);
  }
}

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

  cout << count(H) << "\n";
  
  
  return 0;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"

using namespace std;

int dp(int curr, int W, const vector<int>& v, const vector<int>& w, vector<vector<int>>& memo) {
    if (curr == v.size()) {
        return 0;
    }
    if (memo[curr][W] >= 0) {
        return memo[curr][W];
    }

    int ret = dp(curr + 1, W, v, w, memo);
    if (w[curr] <= W) {
        int takeThisAndStay = dp(curr, W - w[curr], v, w, memo) + v[curr];
        int taksThisAndNext = dp(curr + 1, W - w[curr], v, w, memo) + v[curr];
        ret = max(ret, max(takeThisAndStay, takeThisAndStay));
    }
    memo[curr][W] = ret;
    return ret;
}

void solve1(int N, int W, const vector<int>& v, const vector<int>& w) {
    vector<vector<int>> memo(N + 10, vector<int>(W + 10, -1));
    int ans = dp(0, W, v, w, memo);
    cout << ans << endl;
}

void Main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N, 0), w(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> v[i] >> w[i];
    }

    solve1(N, W, v, w);
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 8080
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/
#define int lld
const int N=2050,P=1e9+7,i2=5e8+4;

int n,k;
int a[N],ans,tot;

signed main(){
    scanf("%lld%lld",&n,&k);
    FOR(i,1,n)scanf("%lld",&a[i]);
    FOR(i,1,n){
        FOR(j,i+1,n){
            if(a[i]>a[j]){
                ans++;
            }else if(a[i]<a[j])tot++;
        }
    }
    int t=k*(k+1ll)%P*i2%P;
    int x=k*(k-1ll)%P*i2%P;
    k%=P,x%=P;
    printf("%lld",(tot*x%P+ans*t%P)%P);
    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int mod = 1000000007;

int pow(int a, int b) {
    if(b == 0) return 1;
    if(b%2) return a*pow(a, b-1)%mod;
    return pow(a*a%mod, b/2)%mod;
}

map<int, int> res;

int fact(int n) {
    if(res.count(n)) return res[n];
    
    int ret = 1;
    for(int i = 2; i <= n; ++i) {
        ret = (ret*i)%mod;
    }

    res[n] = ret;
    return ret;
}

int divin(int a) {
    return pow(a, mod-2);
}

int nck(int n, int k) {
    if(k > n) return 0;
    return fact(n)*divin(fact(k)*fact(n-k)%mod)%mod;
}

int32_t main() {

    int n, k; cin >> n >> k;

    int red = n-k, blue = k;

    for(int i = 1; i <= blue; ++i) {
        int pars = nck(red+1, i);
        int poss = nck(blue-1, i-1);
        int ans = (pars*poss)%mod;
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    gusu = N * (N-1) // 2
    kisu = M * (M-1) // 2
    print(gusu + kisu)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    ll check = 0;
    for(ll i = 0; i < n-1; i++){
        for(ll j = i+1; j < n; j++){
            if(a[i]>a[j]) check++;
        }
    }
    ll f = 0;
    for(ll i = 0; i < n; i++)
        for(ll j = 0; j < n; j++)
        if(a[i] > a[j]) f++;
    //cout << check << " " << f << endl;
    ll INF = 1e+9+7;
    ll ans;
    ans = (check*k%INF+((k-1)*k/2)%INF*f%INF)%INF;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
S = input().split(" ")
N = int(S[0])
Y = int(S[1])


def calculate(n, Y):
    # 9000x + 4000y = Y - 1000n

    xmax = (Y - 1000*n) // 9000

    hasValue = False

    for i in range(0,xmax+1):
        y = ((Y - 1000*n) - 9000*i) / 4000

        if i + y > n:
            continue

        if float.is_integer(y):
            y = int(y)
            print(i,y,(n-i-y))
            hasValue = True
            break

    if hasValue == False:
        print("-1 -1 -1")



calculate(N, Y)


Measured memory_bytes: 3064
import scala.io.StdIn._
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = (n - 3) / 2 + 1
    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    private[this] val sqrtLmtNdx = (Math.sqrt(n).toInt - 3) / 2

    def isCmpst(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) != 0
    def setCmpst(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    private def cull(cmpstId: Int, p: Int): Unit = {
      if(cmpstId <= top){
        setCmpst(cmpstId)
        cull(cmpstId + p, p)
      }
    }

    private def rec(cndId: Int): Unit = {
      if(cndId <= sqrtLmtNdx){
        if(!isCmpst(cndId)){
          val p = 2 * cndId + 3
          cull((p * p - 3) >>> 1, p)
        }
        rec(cndId + 1)
      }
    }

    private def next(cndId: Int): Int =
      if ((cndId > top) || !isCmpst(cndId)) 2 * cndId + 3 else next(cndId + 1)

    def exec: Iterator[Int] = {
      rec(0)
      Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) >>> 1)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 65372
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		PriorityQueue<Integer> que = new PriorityQueue<>((o1, o2) -> o2 - o1);
		for (int i = 0; i < n; i++) {
			que.add(Integer.parseInt(sa[i]));
		}
		br.close();

		for (int i = 0; i < m; i++) {
			int o = que.poll();
			que.add(o / 2);
		}

		long ans = 0;
		for (int o : que) {
			ans += o;
		}
		System.out.println(ans);
	}
}


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

ll keta(ll a){
    string s = to_string(a);
    return s.size();
}

vector<ll> keta_bunkai(ll a){
    string s = to_string(a);
    vector<ll> ret;
    for(auto p : s){
        ret.push_back((ll)(p - '0'));
    }
    return ret;
}

int main(){
    ll N, K;
    cin >> N >> K;
    map<ll,ll> D;
    rep(i, 0, N){
        ll d; cin >> d;
        D[d]++;
    }

    vector<ll> e;
    rep(i, 0, 10){
        if(D.count(i) == 0) e.push_back(i);
    }
    
    ll MX = 0;
    rep(i, 0, keta(N)+1){
        MX *= 10;
        MX += e[e.size()-1];
    }

    rep(i, N, MX+1){
        auto t = keta_bunkai(i);
        bool f = false;
        for(auto tt : t){
            if(D.count(tt) > 0){
                f = true;
                break;
            }
        }
        if(!f){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

// 素数判定
template<typename T>
bool is_prime(T n)
{
	if (n == 2)
	{
		return true;
	}
	else if ((n == 1) || (n % 2 == 0))
	{
		return false;
	}

	T p = (T)sqrt(n);
	for (T i = 3; i <= p; i += 2)
	{
		if (n % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	vector<int> prime;

	for (int i = 2; i <= 60000; i++)
	{
		if (is_prime(i))
		{
			prime.push_back(i);
		}
	}

	int n;
	for (; cin >> n;)
	{
		int priv, next;
		for (int i = 0; i < prime.size(); i++)
		{
			if (n == prime.at(i))
			{
				priv = prime.at(i - 1);
				next = prime.at(i + 1);
				break;
			}
			else if (n < prime.at(i))
			{
				priv = prime.at(i - 1);
				next = prime.at(i);
				break;
			}
		}

		cout << priv << " " << next << endl;
	}
}



Measured memory_bytes: 3136
#include<iostream>
#include<cstring>
int main (){
    int n,ans=0,k=0;
    scanf("%d",&n);
    int h[n+1];
    for(int i=1;i<=n;i++){
        scanf("%d",&h[i]);
    }
    for(int i=1;i<=n-1;i++){
        if(h[i]>=h[i+1]){k++;}
        else{if(k>=ans){ans=k;}k=0;}
    }
    if(k>=ans){ans=k;}
    printf("%d",ans);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
char in[1100];
int c[40][40];
string t[40];
int v[40];
int n;
int sz;
int ret;
int ans[40];
int UF[40];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
void solve(int a,int b){
	if(ret==a)return ;
	bool ok=true;
	for(int i=0;i<sz;i++)UF[i]=-1;
	for(int i=0;i<sz;i++){
		for(int j=i+1;j<sz;j++){
			bool OK=false;
			for(int k=0;k<a;k++)if(c[i][v[k]]&&c[j][v[k]])OK=true;
			if(OK)UNION(i,j);
		}
	}
	if(UF[FIND(0)]==-sz){
		ret=a;
		for(int i=0;i<a;i++)ans[i]=v[i];
		return;
	}
	for(int i=b;i<n;i++){
		v[a]=i;
		solve(a+1,i+1);
	}
}
int main(){
	int a,b;
	bool se=false;
	while(scanf("%d%d",&a,&b),a){
		if(se)printf("\n");
		se=true;
		map<string,int>m;
		n=a;
		sz=b;
		ret=6;
		for(int i=0;i<a;i++){
			scanf("%s",in);
			string tmp=in;
			t[i]=tmp;
			m[tmp]=i;
		}
		for(int i=0;i<40;i++)for(int j=0;j<40;j++)c[i][j]=0;
		for(int i=0;i<b;i++){
			int d;scanf("%d",&d);
			for(int j=0;j<d;j++){
				scanf("%s",in);
				string tmp=in;
				c[i][m[tmp]]=1;
			}
		}
		
		for(int i=0;i<a;i++)v[i]=0;
		solve(0,0);
		if(ret==6){
			printf("Impossible\n");
		}else{
			printf("%d\n",ret);
			for(int i=0;i<ret;i++)printf("%s\n",t[ans[i]].c_str());
		}
	}
}

Measured memory_bytes: 1100
#include <bits/stdc++.h>
#include <cmath>
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) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

#define mp make_pair


int main() {
  string s,t;cin>>s>>t;
  cout << t << s << endl;
}


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

int n, m;
int p[114514],parent[114514];

int find(int x){
    if(parent[x]==x)
        return x;
    else
        parent[x] = find(parent[x]);
    return parent[x];
}

void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x!=y)
        parent[x] = y;
    return;
}

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

    int ans = 0;
    cin >> n >> m;
    forx(i,1, 1+n) cin >> p[i];
    rep(i, 114514) parent[i] = i;
    
    rep(i,m){
        int s,t;
        cin >> s >> t;
        unite(p[s], p[t]);
    }
    
    forx(i,1,n+1){
        if(find(p[i])==find(i))
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int x,y;
    cin>>x>>y;
    bool ok=false;
    for(int i=0;i<=x;i++){
        int j=x-i;
        if(i*2+j*4==y)ok=true;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    ll N,D;
    cin >> N >> D;
    D *= D;
    int cnt = 0;
    REP(_,N) {
        ll X,Y;
        cin >> X >> Y;
        ll dist = (X*X)+(Y*Y);
        if(D >= dist) cnt++;
    }
    cout << cnt << endl;
}

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define INF 1000000000000 //10^12:∞
#define MOD 998244353//10^9+7:合同式の法

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
int n,m;
cin>>n>>m;
UnionFind tree(n);
int a,b;
rep(i,0,m){
    cin>>a>>b;
    tree.unite(a-1, b-1);
}
set<int> ans;

rep(i,0,n){
    //db(tree.root(i));
    ans.insert(tree.root(i));
}

cout<<ans.size()-1;

return 0;
}

Measured memory_bytes: 7584
#include <bits/stdc++.h>
using namespace std;
long long i,n,a[100001],x[100001];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
		cin>>a[i];
	x[1]=0;
	for(i=1;i<=n;i++)
		if(i%2==0)
			x[1]=x[1]-2*a[i];
		else
			x[1]=x[1]+2*a[i];
		x[1]=x[1]/2;
	for(i=2;i<=n;i++)
		x[i]=2*a[i-1]-x[i-1];
	for(i=1;i<=n;i++)
		cout<<x[i]<<" ";
}


Measured memory_bytes: 2816
from itertools import permutations
N,M,R = map(int,input().split())
RList = list(map(int,input().split()))
dp = [[float("INF")]*(N+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][i] = 0
for _ in range(M):
    a,b,c = map(int,input().split())
    dp[a][b] = c
    dp[b][a] = c

for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            dp[j][k] = min(dp[j][i]+dp[i][k],dp[j][k])

ans = float("INF")
RList = list(permutations(RList))
for Rs in RList:
    tmp = 0
    for i in range(1,R):
        a = Rs[i-1]
        b = Rs[i]
        tmp += dp[a][b]
    ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 80792
#include<bits/stdc++.h>
using namespace std;
int n,i,j,a[4040404],k=1;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
	{
		if(a[i]==k)
			k++;
	}
	if(k>1)
	cout<<n-k+1;
	else
	cout<<-1;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b;
	c=b;
	int cnt=0;
	while(c){
		cnt++;
		c/=10;
	}
	for(int i=1;i<=cnt;i++)
		a*=10;
	a+=b;
	if(int(sqrt(a))*int(sqrt(a))==a) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		prepareFact();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = m * 3;
		long ans = combi(n - 1 + sum, n - 1);
		for(int i = m * 2 + 1; i <= sum; i ++) {
			long tmp = combi(n - 2 + (sum - i), n - 2);
			tmp = mod(tmp * (long)n);
			ans = mod(ans - tmp);
		}

		long minus = 0;
		for(int i = m + 2; i <= n; i += 2) {
			long tmp = perm(n - 1 + (sum - i) / 2, n - 1);
			tmp = mod(tmp * combi(n, i));
			minus = mod(minus + tmp);
		}
		minus = mod(minus * inv(fact[n - 1]));
		ans = mod(ans - minus);
		System.out.println(ans);
	}

	static long MOD = 998244353;
	public static long mod(long i) {
		return i % MOD + ((i % MOD) < 0 ? MOD : 0);
	}
	
	static long pow(long x, long y) {
		if (y == 0) {
			return 1;
		} else if (y == 1) {
			return x;
		} else if (y % 2 == 0) {
			long tmp = pow(x, y / 2);
			return mod(tmp * tmp);
		} else {
			long tmp = pow(x, y / 2);
			return mod(mod(tmp * tmp) * x);
		}
	}
	
	static long inv(long x) {
		return pow(x, MOD - 2);
	}
	
	static int MAX_FACT = 2_500_100;
	static long fact[] = new long[MAX_FACT];
	static void prepareFact() {
		fact[0] = 1;
		for(int i = 1; i < MAX_FACT; i ++) {
			fact[i] = mod(fact[i - 1] * i);
		}
	}
	
	static long combi(int n, int r) {
		if(n < 0 || n < r) { return 0; }
		return mod(perm(n, r) * inv(fact[r]));
	}

	static long perm(int n, int r) {
		if(n < 0 || n < r) { return 0; }
		return mod(fact[n] * inv(fact[n - r]));
	}
}

Measured memory_bytes: 43620
#include <stdio.h>
int main(void){
    // Your code here!
    int n,m;
    int min = 2000000001;
    int x,set;
    int count = 0;
    int i = 0;
    scanf("%d",&n);
    for (i = 0; i < n; i++){
        scanf("%d",&x);
        if (i == 0){
            set = x;
        }
        
        
        
        
        if (set >= x && min > x){
            count++;
            if (min > x){
                min = x;
            }
        }
      //  printf("%d %d\n",i,set);

    }
    printf("%d",count);
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] + a[i-1] > x) {
            ans += (a[i] + a[i-1] - x);
            a[i] -= (a[i] + a[i-1] - x);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
ll a,b,c,n,s;
str s1,s2;

int main() {
    fast();
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt","w",stdout);
    // #endif
    cin >> n;
    f(i,1,n+1){
        if(n%i==0 and n/i<=9 and i<=9){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";

    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
    string s;
    cin>>s;
    int a=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1]){
            a++;
        }
    }
    cout<<a<<endl;
}

Measured memory_bytes: 512
#098b
import collections
N = int(input())
S = str(input())
ans = 0
for i in range(1,N):
    Sa = S[0:i]
    Sb = S[i::]
    #print(Sa,Sb)
    Sa_counted = collections.Counter(Sa)
    Sb_counted = collections.Counter(Sb)
    common_char = set(Sa_counted.keys()) & set(Sb_counted.keys())
    #print(common_char)
    if len(common_char) > ans:
        ans = len(common_char)
        
print(ans)

Measured memory_bytes: 3444
import math
def main():
  n = int(input())
  p = [int(input()) for i in range(n)]
  ans=p[0]
  max=p[0]
  for i in range(1,n):
    ans+=p[i]
    if max<p[i]:
      max=p[i]
  ans-=int(max/2)
  print(ans)
main()

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

int a, b, c;

void solve() {
    cin >> a >> b >> c;
    cout << (c - (a - b) <= 0 ? 0 : c - (a - b)) << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3612