akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int con = int.Parse(Console.ReadLine());
            if(con == 3 || con == 5 || con == 7)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


Measured memory_bytes: 11092
import math
K=int(input())
ans=0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      gcd=math.gcd(a,b)
      gcd=math.gcd(gcd,c)
      ans+=gcd
print(ans)

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    string s,t;

    cin >> s >> t;

    lint cnt = 0;

    rep0(i,s.length())
    {
        if(s[i] != t[i])cnt ++;
    }


    cout << cnt << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  cout<<min(B/A,C)<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n, m;
    cin >> n >> m;
    int arr[n][m];
    int dp[n][m];
    for(int i=0;n>i;i++){
        string str;
        cin >> str;
        for(int j=0;m>j;j++){
            if(str[j] == '#'){
                arr[i][j] = 1;//blocked
            }else{
                arr[i][j] = 0;
            }
        }
    }
    dp[0][0] = 1;
    for(int j=1;m>j;j++){
        dp[0][j] = dp[0][j-1];
        if(arr[0][j] == 1){
            dp[0][j] = 0;
        }
    }
    for(int i=1;n>i;i++){
        dp[i][0] = dp[i-1][0];
        if(arr[i][0] == 1){
            dp[i][0] = 0;
        }
    }
    for(int i=1;n>i;i++){
        for(int j=1;m>j;j++){
            dp[i][j] = dp[i-1][j]%MOD + dp[i][j-1]%MOD;
            dp[i][j] %= MOD;
            if(arr[i][j] == 1){
                dp[i][j] = 0;
            }
        }
    }
    cout << dp[n-1][m-1]%MOD << endl;
}










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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    int N = next<int>();
    int cards[200], _cards[200];
    times(N * 2, i) cards[i] = i + 1;

    times(next<int>(), _) {
        times(N * 2, i) _cards[i] = cards[i];
        int K = next<int>();
        if(K){
            times(K, i) cards[N * 2 - K + i] = _cards[i];
            times(N * 2 - K, i) cards[i] = _cards[K + i];
        }else{
            times(N, i) cards[i * 2] = _cards[i];
            times(N, i) cards[i * 2 + 1] = _cards[N + i];
        }
    }

    times(N * 2, i) cout << cards[i] ln;

    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
const int MAXN=200017;
using namespace std;

int n, a[MAXN];

long long num(long long cnt)
{
	long long c1=cnt;
	//bool fl=0;
	//if(c1==5) fl=1;
	for(int i=0; i<n; i++)
	{
		c1=c1-c1%a[i];
		//if(fl) cout<<c1<<" ";
	}
	
	//cout<<endl;
	
	return c1;
}
void mainp()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("***.in", "r", stdin);
//	freopen("***.out", "w", stdout);

	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	
	long long l=0ll, r=(long long)1e18, ans1=0ll, ans2=0ll;
	
	while(l<=r)
	{
		long long mid=(l+r)/2ll;
		//cout<<mid<<" "<<num(mid)<<endl;
		if(num(mid)>=2ll)
		{
			ans1=mid;
			r=mid-1;
		}
		else
		{
			l=mid+1;
		}
	}
	
	l=0ll, r=(long long)1e18;
	while(l<=r)
	{
		long long mid=(l+r)/2ll;
		if(num(mid)>2ll)
		{
			r=mid-1;
		}
		else
		{
			ans2=mid;
			l=mid+1;
		}
	}
	
	
	//cout<<ans1<<" "<<ans2<<endl;
	if(num(ans1)==2&&num(ans2)==2) cout<<ans1<<" "<<ans2<<endl;
	else cout<<-1<<endl;
}

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


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int x, y,z;
		Scanner sc = new Scanner(System.in);
		while (true) {
			x = sc.nextInt();
			y = sc.nextInt();
			if(x > y){
				z=x;
				x=y;
				y=z;
						
			}
			if (x == 0 && y == 0) break;
			System.out.println(x + " " + y);
		}
		sc.close();
	}
}


Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
//ノート　isupperで大文字の判定　islowerで小文字の判定
int main(){
   string s,t,u;
   std::cin >>s>>t ;
   int a,b;
   std::cin >> a>>b;
   std::cin >> u;
   if(s==u)std::cout << a-1<<" "<<b << std::endl;
   else std::cout << a<<" "<<b-1 << std::endl;
}

Measured memory_bytes: 256
n = int(input())
stairs = list(map(int,input().split()))
min = stairs[0]
#左のマスと同じか大きい値にできればおっけー

if n == 1:
    print('Yes')
    exit()

for i in range(n-1,0,-1):
    if stairs[i] < stairs[i-1]:
        stairs[i-1] -= 1
        if stairs[i] < stairs[i-1]:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 14396
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std;
 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.in","w",stdout);
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   	ll i,j,k,t,a,b,c,d;
   	cin>>a>>b>>c>>d;
   	cout<<max({a*c,a*d,b*c,b*d});
	
	
 
 
 
 
 
 
 
	return 0;
}

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

int main(){
	int color[9],N,tmp,max=0,min=0;
	for(int i=0;i<9;i++){
		color[i]=0;
	}
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> tmp;
		if(tmp<=399){color[0]++;}else
		if(tmp<=799){color[1]++;}else
		if(tmp<=1199){color[2]++;}else
		if(tmp<=1599){color[3]++;}else
		if(tmp<=1999){color[4]++;}else
		if(tmp<=2399){color[5]++;}else
		if(tmp<=2799){color[6]++;}else
		if(tmp<=3199){color[7]++;}else
		{color[8]++;}
	}
	for(int i=0;i<8;i++){
		if(color[i]>0){
			max++;min++;
		}

	}
	max+=color[8];
	if(min==0)min=1;
	cout << min << " " << max << endl;


	return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}


double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll x, k, d;
	scanf("%lld%lld%lld", &x, &k, &d);
	x = abs(x);
	if (x / d > k) {
		printf("%lld\n", x - k * d);
	}
	else if ((x / d) % 2 == k % 2) {
		printf("%lld\n", x % d);
	}
	else {
		printf("%lld\n", abs((x % d) - d));
	}

	Please AC;
}


Measured memory_bytes: 3804
#include <stdio.h>
#include <string.h>

int main (void)
{
    char s[1005];
    char t[1005];
    int lens;
    int lent;
    int cnt=0;
    int ans;
    int i;
    int j;

    scanf("%s",s);
    lens = strlen(s);
    scanf("%s",t);
    lent = strlen(t);
    ans = lent;

    // printf("%d, %d", lens, lent);

    for(i=0;i<(lens-lent+1);i++){
        for(j=0;j<lent;j++){
            if(s[i+j]!=t[j]){
                cnt++;
            }
        }
        if(cnt < ans){
            ans = cnt;
        }
        cnt = 0;
    }

    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

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

    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            ans[0] += a[i];
        } else {
            ans[0] -= a[i];
        }
    }

    for (int i = 1; i < n; i++) ans[i] = 2 * a[i - 1] - ans[i - 1];

    for (int i = 0; i < n; i++) cout << ans[i] << " ";
    cout << endl;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	long long N;
	long long A[100000+2] = {0};

	cin >> N;

	long long tot = 0;
	for(int i=1; i<=N; i++){
		cin >> A[i];
		tot += abs(A[i] - A[i-1]);
	}
	tot += abs(A[N]);

	for(int i=1; i<=N; i++){
		long long d = 0;
		d -= abs(A[i + 1 ] - A[i]);
		d -= abs(A[i] - A[i - 1]);
		d += abs(A[i + 1] - A[i - 1]);
		printf("%lld\n", tot+d);
	}
	return 0;
}

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

using namespace std;

int main(){
int N,K;
map<int,int> A;
cin>>N>>K;
int tmp;

for(int i=0;i<N;i++){
    cin>>tmp;
    A[tmp]+=1;
}

vector<int> value;
for(auto it :A){
    value.push_back(it.second);
}
sort(value.begin(),value.end());

//exchange key for value
if(K>=A.size()){
    cout<<0;
}
else{
    int cnt=0;
for(int i=0;i<A.size()-K;i++){
    cnt+=value[i];
}
cout<<cnt;
}

//system("pause");
return 0;
}

Measured memory_bytes: 10748
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  }

  private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  }
}


Measured memory_bytes: 21844
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	cout<<fixed<<setprecision(9);
	dl dp[n+1][n+1],a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		dp[i][0]=(1.0-a[i]);
		dp[i][1]=a[i];
	}
	for(int i=2;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(j==0)dp[i][0]=dp[i-1][0]*(1-a[i]);
			else dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
		}
	}
	dl ans=0.0;
	for(int i=n/2+1;i<=n;i++){
		ans+=dp[n][i];
	}
	cout<<ans<<endl;
}

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

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

ll a[maxn];

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

ll qt[70];


int main()
{

  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for(int i = 0; i < n ; i++)
  {
    ll x;
    cin >> x;
    for(int j = 0; j < 61; j++)
    {
      qt[j] += bool(x & (1LL << j));
    } 
  }

  ll ans = 0;


  for(int i = 0; i < 61; i++)
  {
    // debug(i);
    // debug(qt[i]);
    // cout << "\n\n\n";
    ll x = (1LL << i) % mod;
    ll y = (qt[i] * (n - qt[i])) % mod;
    ans += ( x * y) % mod;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int V, LOG_V, ROOT;
vector<vi> g;		//bidirectional graph
vector<vi> parent;
vi depth;

void dfs(int v, int p, int d)
{
	parent[0][v] = p;
	depth[v] = d;
	REP(i, g[v].size()) if (g[v][i] != p) dfs(g[v][i], v, d + 1);
}

void init(int root)
{
	ROOT = root;
	V = g.size(); LOG_V = log2(V) + 1;
	parent.resize(LOG_V, vi(V));
	depth.resize(V);
	dfs(ROOT, -1, 0);
	REP(k, LOG_V - 1)REP(v, V)
	{
		if (parent[k][v] < 0) parent[k + 1][v] = -1;
		else parent[k + 1][v] = parent[k][parent[k][v]];
	}
}

int lca(int u, int v)
{
	if (depth[u] > depth[v]) swap(u, v);
	REP(k, LOG_V)
	{
		if (((depth[v] - depth[u]) >> k) & 1) v = parent[k][v];
	}
	if (u == v) return u;
	for (int k = LOG_V - 1; k >= 0; k--)
	{
		if (parent[k][u] != parent[k][v])
		{
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}

int main()
{
	cin >> V;
	g.resize(V);
	FOR(i, 1, V)
	{
		int t; cin >> t;
		t--;
		g[i].push_back(t);
		g[t].push_back(i);
	}
	init(0);
	vi visit;
	queue<int> que; set<int> st;
	que.push(0);
	visit.push_back(0);
	st.insert(0);
	while (que.size())
	{
		int t = que.front();
		que.pop();
		REP(i, g[t].size())
		{
			int nx = g[t][i];
			if (st.count(nx)) continue;
			st.insert(nx);
			visit.push_back(nx);
			que.push(nx);
		}
	}
	ll ans = 0;
	REP(i, visit.size() - 1)
	{
		int node = lca(visit[i], visit[i + 1]);
		int d = depth[node];
		ans += depth[visit[i]] + depth[visit[i + 1]] - d * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 25224
#include <queue>
#include <vector>
#include <iostream>

#define INF (1 << 29)

using namespace std;

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

int main()
{
	int H, W, T; vector<vector<vector<bool> > > M;

	while (true)
	{
		scanf("%d", &W);
		scanf("%d", &H);

		if (W == 0 && H == 0) { break; }

		M = vector<vector<vector<bool> > >(H, vector<vector<bool> >(W, vector<bool>(4, false)));

		for (int i = 0; i < W; i++)
		{
			M[0][i][0] = true;
		}

		for (int i = 0; i < H; i++)
		{
			M[i][W - 1][1] = true;
		}

		for (int i = 0; i < W; i++)
		{
			M[H - 1][i][2] = true;
		}
		
		for (int i = 0; i < H; i++)
		{
			M[i][0][3] = true;
		}

		for (int i = 0; i < 2 * H - 1; i++)
		{
			for (int j = 0; j < (i % 2 == 0 ? W - 1 : W); j++)
			{
				scanf("%d", &T);

				if (T == 1)
				{
					if (i % 2 == 0)
					{
						M[i / 2][j][1] = true;
						M[i / 2][j + 1][3] = true;
					}
					else
					{
						M[i / 2][j][2] = true;
						M[i / 2 + 1][j][0] = true;
					}
				}
			}
		}

		vector<vector<int> > dp(H, vector<int>(W, INF)); dp[0][0] = 1;

		queue<pair<int, int> > que; que.push(make_pair(0, 0));

		while (!que.empty())
		{
			pair<int, int> p1 = que.front(); que.pop();

			int x = p1.first;
			int y = p1.second;

			for (int dir = 0; dir < 4; dir++)
			{
				if (M[y][x][dir] == false)
				{
					if (dp[y + dy[dir]][x + dx[dir]] == INF)
					{
						dp[y + dy[dir]][x + dx[dir]] = dp[y][x] + 1;

						que.push(make_pair(x + dx[dir], y + dy[dir]));
					}
				}
			}
		}

		if (dp[H - 1][W - 1] == INF)
		{
			printf("0\n");
		}
		else
		{
			printf("%d\n", dp[H - 1][W - 1]);
		}
	}

	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <numeric>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vec>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int func(vecvec& v,int h1,int w1,int h2,int w2){
    return v[h2][w2]-v[h2][w1]-v[h1][w2]+v[h1][w1];
}

int main(){
    int h=in(),w=in(),k=in();
    vecvec v(h+1,vec(w+1,0));
    rep(i,h){
        string s=stin();
        rep(j,w)v[i+1][j+1]=s[j]=='0'?v[i][j+1]+v[i+1][j]-v[i][j]:v[i][j+1]+v[i+1][j]-v[i][j]+1;
    }
    int ans=2000;
    rep(x,1<<(h-1)){
        int tmp=0;
        rep(i,h-1)if(x&(1<<i))tmp++;
        int end=0;
        rep(j,w){
            int ceil=0;
            bool flag=false;
            rep(i,h){
                if(func(v,i+1,j+1,ceil,end) > k)flag=true;
                if(x&(1<<i))ceil=i+1;
            }
            if(flag){
                tmp++;
                if(j==0){
                    tmp=2000;
                    break;
                }
                end=j;
            }
        }
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3752
N = int(input())
S = list(input())

ans = 0

Rc = S.count("R")
Gc = S.count("G")
Bc = S.count("B")

Rp = 0
Gp = 0

for i in range(Rc):
  while S[Rp] != "R":
    Rp += 1
  for j in range(Gc):
    ad = 0

    while S[Gp] != "G":
      Gp += 1
    
    if  min(Rp,Gp)-abs(Rp-Gp) >= 0 :
      if S[min(Rp,Gp)-abs(Rp-Gp)] == "B":
        ad += 1
    if max(Rp,Gp)+abs(Rp-Gp) < N :
      if S[max(Rp,Gp)+abs(Rp-Gp)] == "B":
        ad += 1
    if (Rp + Gp)//2 == (Rp + Gp)/2:
      if S[(Rp + Gp)//2] == "B":
        ad += 1

    
    ans += Bc - ad

    Gp += 1

  Rp += 1
  Gp = 0


print(ans)    

Measured memory_bytes: 73976
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, x = sc.nextInt
    val list = List.fill(n)(sc.nextInt)

    def bound(dx: List[Int], bounce: List[Int]): List[Int] =
      dx.isEmpty match {
        case true => bounce
        case _    => bound(dx.tail, bounce :+ bounce.last + dx.head)
      }
    println(bound(list, List(0)).count(_ <= x))
  }
}

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

int main(){
    int a[3000],b[3000],index=0,num,num2;
    while(true){
        cin >> num >> num2;
        if(num == 0 && num2 == 0) break;
        if(num < num2) {
            a[index] = num;
            b[index] = num2;
        }else{
            b[index] = num;
            a[index] = num2;
        }
        index++;
    }
    for(int i=0;i<index;i++){
        cout << a[i] << " " << b[i] << endl;
    }
}


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


def dfs(numbers, appeared):
    global count
    if int(numbers) <= N:
        if appeared[0] and appeared[1] and appeared[2]:
            count += 1

        tmp1 = appeared.copy()
        tmp1[0] = True
        dfs(numbers + "3", tmp1)
        tmp2 = appeared.copy()
        tmp2[1] = True
        dfs(numbers + "5", tmp2)
        tmp3 = appeared.copy()
        tmp3[2] = True
        dfs(numbers + "7", tmp3)


count = 0
dfs("3", [True, False, False])
dfs("5", [False, True, False])
dfs("7", [False, False, True])

print(count)


Measured memory_bytes: 3064
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int[] aa = new int[n + 1];
		for (int i = 1; i <= n; i++)
			aa[i] = sc.nextInt();
		Integer[] ii = new Integer[n + 1];
		for (int i = 0; i <= n; i++)
			ii[i] = i;
		Arrays.sort(ii, (i, j) -> aa[j] - aa[i]);
		long[] kk = new long[n + 1];
		for (int h = 0, h_, i = n, i_; h < n; h = h_) {
			int a = aa[ii[h]];
			h_ = h;
			while (aa[i_ = ii[h_]] == a) {
				i = Math.min(i, i_);
				h_++;
			}
			int b = aa[ii[h_]];
			kk[i] += (long) (a - b) * h_;
		}
		for (int i = 1; i <= n; i++)
			println(kk[i]);
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  string s;
  cin >> s;
  ll n = s.length();
  for (ll i = 0; i < n; i++) {
    if (s[i] != s[n - 1 - i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range, std.algorithm;

void main() {
	string[] n = [];
	foreach (string l; lines(stdin)) n ~= l.chomp;
	foreach (s; ["S", "H", "C", "D"])
		foreach (i; 1..14) {
			auto t = "%s %d".format(s, i);
			if (!n[1..$].canFind(t)) t.writeln;
		}
}

Measured memory_bytes: 2496
N, Y = [int(i) for i in input().split()]
x, y, z = -1, -1, -1
for a in range(N + 1):
    for b in range(N + 1):
        c = N - a - b
        if 0 <= c and c <= N and a * 10000 + b * 5000 + c * 1000 == Y:
            x, y, z = a, b, c
            break
    else:
        continue
    break
print(x, y, z)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i< int (n); i++)
int main(){
int n, m;
cin >> n >> m;
int a[110];
int sum=0;
rep(i,n) {
    cin >> a[i];
    sum+=a[i];
}
double e;
e=(sum+(4*m-1))/(4*m);
int cnt=0;
rep(i,n) {
    if(a[i]>=e) cnt++;
}

if(cnt>=m) cout << "Yes" <<  endl;
else cout << "No" <<  endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;
  cin>>n;
  vector<ll> a(3*n);
  rep(i,3*n){
   cin>>a[i];cerr<<a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll ans=0;
  rep(j,n){
    ans+=a[j*2+1];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
def main():
    INF = 10 ** 10
    N, M = list(map(int, input().split(' ')))
    key_list = list()
    for _ in range(M):
        A, _ = list(map(int, input().split(' ')))
        C = list(map(lambda x: int(x) - 1, input().split(' ')))
        boxes = 0
        for c in C:
            boxes |= (1 << c)
        key_list.append((A, boxes))
    # bit DP
    # dp[m][S]: m個目までのカギでSに含まれる宝箱を開けるための最小費用
    dp = [[INF for _ in range(1 << N)] for _ in range(M + 1)]
    for m in range(M + 1):
        dp[m][0] = 0
    for m in range(1, M + 1):
        cost, box = key_list[m - 1]
        for S in range(1 << N):
            dp[m][S] = min(dp[m][S], dp[m - 1][S])
            if box | S != S:
                dp[m][box | S] = min(dp[m][box | S], dp[m - 1][S] + cost)
    ans = dp[M][(1 << N) - 1]
    if ans >= INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 109564
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    ll N, K;
    cin >> N >> K;
    
    vector<ll> A(N), F(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> F[i];
    }
    std::sort(A.begin(), A.end());
    std::sort(F.rbegin(), F.rend());
    ll lt = -1;
    ll rt = 1e18 + 100;
    while(rt - lt > 1) {
        ll ct = lt + (rt - lt) / 2;
        ll req = 0;
        for (int i = 0; i < N; i++) {
            req += std::max(0LL, A[i] - ct / F[i]);
        }
        if (req > K) {
            lt = ct;
        } else {
            rt = ct;
        }
    }
    cout << rt << endl;
    
    return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	string s;

	cin >> s;

	bool flag = true;

	REP(i, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				flag = false;
				break;
			}
		}
		else {
			if (s[i] == 'R') {
				flag = false;
				break;
			}
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

const string Weathers[] = {"Sunny", "Cloudy", "Rainy"};
int main() {
  string S;
  cin >> S;
  for(int i = 0; i < 3; ++i) {
    if(S == Weathers[i]) {
      auto next = (i + 1) % 3;
      cout << Weathers[next] << endl;
      return 0;
    }
  }
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
  int paSize = printArray.size();
  for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
  if (between != '\n') {cerr << endl;}
}

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

int Len[55], Pat[55];

int rec(int level, int layer) {
  if (level <= 0) return 1;

  if (layer <= 1) { // 1
    return 0;
  } else if (layer <= Len[level-1]+1) { // 2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1] + 2) {  // 3
    return Pat[level-1] + 1;
  } else if (layer <= 2*Len[level-1]+2) { // 4
    return Pat[level-1] + 1 + rec(level-1, layer-Len[level-1]-2);
  } else { // 5
    return 2*Pat[level-1] + 1;
  }
}

signed main() {
  int N, X;
  cin >> N >> X;

  Len[0] = Pat[0] = 1;
  for (int i = 1; i <= N; i++) {
    Len[i] = Len[i-1] * 2 + 3;
    Pat[i] = Pat[i-1] * 2 + 1;
  }

  cout << rec(N, X) << endl;

  return 0;
}

Measured memory_bytes: 256
s = input()
N = len(s)
if s[-1] == "1" or s[0] == "0" or s[:N-1] != s[:N-1][::-1]:
    print("-1")
else:
    v = 1
    for i in range(N-1):
        print("{} {}".format(v, i+2))
        if s[i] == "1" and i+1 <= N//2:
            v = i + 2
        else:
            pass

Measured memory_bytes: 4500
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
vector<int> next(vector<int>v) {
	
	vector<int>res;
	rep(i, 0, v.size()) {
		res.push_back(count(all(v), v[i]));
	}
	return res;
}
signed main() {
	int n; 
	while (cin >> n, n) {
		vector<int>w, v(n); rep(i, 0, n)cin >> v[i];
		int cnt(0);
		while (1) {
			w = v;
			v = next(v);
			if (v == w)break;
			cnt++;
		}
		cout << cnt << endl;
		rep(i, 0, v.size()) cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');
	}
	return 0;
}

Measured memory_bytes: 3108
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
min = float("INF")
for i in range(n - k + 1):
    if min > h[i + k - 1] - h[i]:
        min = h[i + k - 1] - h[i]
print(min)

Measured memory_bytes: 7384
#include<cstring>
#include<cstdio>
#include<cmath>
int main()
{
    int n;
    int a[1000];
    int i = 0;
    scanf("%d", &n);
    if(n==0)
    {
        printf("0\n" );
        return 0;
    }
    while (n != 0 )    //短除法
         {
 
             a [ ++ i ] = n % (- 2 );
 
             n /= (- 2 );
 
             if (a [ i ] == - 1 )        //将余数为-1的改为1
             {
                a [ i ] = 1 ;
                n ++ ;            //(商)*(-2)-1 == (商+1)*(-2)+1
             }
 
        }
    for(int j = i; j >= 1;j--)printf("%d", a[j]);
    return 0;
}

Measured memory_bytes: 128
w, h, n = gets.split.map(&:to_i)
l = 0
b = 0
n.times do
	x, y, a = gets.split.map(&:to_i)
	case a
	when 1
		l = [l,x].max
	when 2
		w = [w,x].min
	when 3
		b = [b,y].max
	when 4
		h = [h,y].min
	end
end
puts [(w - l),0].max * [(h - b),0].max



Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int MAXN = 1e5;
int n,m;
int a[MAXN+5], fa[MAXN+5];
int rpos[MAXN+5];
//int p[100050],x[100050],y[100050];

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

void Init(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		fa[i] = i;
		rpos[a[i]] = i;
	}
	for(int i = 1; i <= m; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		fa[find(u)] = find(v);
	}
	//for(int i = 1;  i<= n; i++) printf("%d ", find(i));
}

int main(){
	Init();
	int res = 0;
	for(int i = 1; i <= n; i++){
		if(find(i) == find(rpos[i])) res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1408
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, k) = (v[0] as usize, v[1]);
    let a = read_vec::<i64>();
    let mut sum_a = vec![0; n + 1];
    for i in 0..n {
        sum_a[i + 1] = (sum_a[i] + a[i]) % k;
    }
    //minus
    for i in 0..n + 1 {
        sum_a[i] = (sum_a[i] - i as i64) % k;
        sum_a[i] = (sum_a[i] + k) % k;
    }
    // debug!(sum_a);

    let mut poses = HashMap::new();
    for i in 0..n + 1 {
        poses.entry(sum_a[i]).or_insert(vec![]).push(i);
    }

    let mut ans = 0;
    let k_limit = min(k, n as i64 + 1) as usize;
    for i in 0..n + 1 {
        let key = sum_a[i];
        if !poses.contains_key(&key) {
            continue;
        }
        let idx = poses[&key].upper_bound(&i);
        let limit_idx = poses[&key].lower_bound(&(i + k_limit));
        ans += limit_idx - idx;
    }
    println!("{}", ans);
}

use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 26408
fun main(args: Array<String>) {
    readLine()!!
    val a = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }
    val c = readLine()!!.split(" ").map { it.toInt() }

    val result = a.withIndex().map {
        b[it.value - 1] +
            if (it.index > 0)
                if (it.value - a[it.index - 1] == 1) c[it.value - 2]
                else 0
            else 0
        }.sum()
    println(result)
}

Measured memory_bytes: 37816
#include<stdio.h>
#include<string.h>


int begin( char *base ,char *old ,int oldLen ,int now )
{
	int i ;
	for( i = now ; i < oldLen ; ++i )
	{
		if( base[ 0 ] == old[ i ] )
		{
			return i ;
		}
	}

	return oldLen ;
}

int pair( char *base ,int baseLen ,char *old ,int oldLen ,int start )
{
	int baseP ;

	int i ,j ,k ;
	while( start < oldLen )
	{
		for( i = 1 ; ( i * ( baseLen - 1 ) ) <= oldLen ; ++i )
		{
			baseP = 0 ;
			for( j = start ; baseP < baseLen && j < oldLen ; j += i )
			{
				if( base[ baseP ] != old[ j ] )
				{
					break ;
				}

				++baseP ;
			}

			if( baseP == baseLen )
			{
				return 1 ;
			}
		}

		start = begin( base ,old ,start + 1 ,oldLen ) ;
	}

	return 0 ;
}


int main( void )
{
	int N ;
	scanf( "%d" ,&N ) ;

	char base[ 128 ] ;
	scanf( "%s" ,base ) ;

	int baseLen = strlen( base ) ;

	int baseP ;
	int ans = 0 ;

	int i ,j ,k ,t ;
	for( i = 0 ; i < N ; ++i )
	{
		char old[ 128 ] ;
		scanf( "%s" ,old ) ;

		int oldLen = strlen( old ) ;

		if( oldLen >= baseLen && pair( base ,baseLen ,old ,oldLen ,begin( base ,old ,oldLen ,0 ) ) == 1 )
		{
			++ans ;
		}
	}

	printf( "%d\n" ,ans ) ;


	return 0 ;
}

Measured memory_bytes: 2756
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
 
int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
 
    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;
 
    if ((K-min(K,X/D)) % 2 == 0) {
        cout << X-min(X/D,K)*D << endl;
    } else {
        cout << D - (X-X/D*D) << endl;
    }
 
    return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
    if (n == 0)return 1;
    if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
    return (x * modexp((x * x) % md, n / 2, md)) % md;
}

const int MAX = 1000001;
struct Query{
    int l, r, idx;
};

bool cmp(Query x, Query y){
    return x.r < y.r;
}

void update(int idx, int val, int bit[], int n){
    for (; idx <= n; idx += idx&-idx)
        bit[idx] += val;
}

int query(int idx, int bit[], int n){
    int sum = 0;
    for (; idx>0; idx-=idx&-idx)
        sum += bit[idx];
    return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q){
    // initialising bit array
    int bit[n+1];
    memset(bit, 0, sizeof(bit));

    // holds the rightmost index of any number
    // as numbers of a[i] are less than or equal to 10^6
    int last_visit[MAX];
    memset(last_visit, -1, sizeof(last_visit));

    // answer for each query
    int ans[q];
    int query_counter = 0;
    for (int i=0; i<n; i++)
    {
        // If last visit is not -1 update -1 at the
        // idx equal to last_visit[arr[i]]
        if (last_visit[arr[i]] !=-1)
            update (last_visit[arr[i]] + 1, -1, bit, n);

        // Setting last_visit[arr[i]] as i and updating
        // the bit array accordingly
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);

        // If i is equal to r of any query  store answer
        // for that query in ans[]
        while (query_counter < q && queries[query_counter].r == i)
        {
            ans[queries[query_counter].idx] =
                    query(queries[query_counter].r + 1, bit, n)-
                    query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }

    // print answer for each query
    for (int i=0; i<q; i++)
        cout << ans[i] << endl;
}
int main(){
    fastio;
    //clock_t tm = clock();
    int n,m;
    cin>>n>>m;
    int a[n];
    f(i,0,n)cin>>a[i];
    Query q[m];
    f(i,0,m){
        cin>>q[i].l>>q[i].r;
        --q[i].l;--q[i].r;
        q[i].idx=i;
    }
    sort(q,q+m,cmp);
    answeringQueries(a,n,q,m);
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 19312
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}


Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
vector<vector<int> > v(201, vector<int>(201,-1));
ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(v.at(a).at(b) != -1 ) return v.at(a).at(b);
    ll aa = a;
    ll bb = b;
    while(b>0){
        ll p= a%b;
        a = b;
        b=p;
    }
    v.at(aa).at(bb) =a;
    return a;
}
int main(){
    int k;
    cin>>k;
    ll sum =0;
    for(int i=1; i<=k; i++){
        for(int j=1; j<=k; j++){
            for(int l =1; l<=k; l++){
                sum  += gcd(i, gcd(j,l));
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3800
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count=0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      ans = 500*i + 100*j + 50*k
      if ans==int(x):
        count+=1
      
print(count)

Measured memory_bytes: 3060