akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <iomanip>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mpi = mp::cpp_int;
using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
//  ll mod(ll val) {
//      ll res = val % MOD;
//      if (res < 0) res += MOD;
//      return res;
//  }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     fac[0] = fac[1] = 1;
//     finv[0] = finv[1] = 1;
//     inv[1] = 1;
//     for (int i = 2; i < MAX; i++){
//         fac[i] = fac[i - 1] * i % MOD;
//         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//         finv[i] = finv[i - 1] * inv[i] % MOD;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


int main() {
    ll x; cin >> x;
    for (ld a = -5000; a <= 5000; a += 1) {
        for (ld b = -5000; b <= 5000; b += 1) {
            if (abs(a * a * a * a * a - b * b * b * b * b - x) < 1e-10) {
                cout << (ll)a << " " << (ll)b << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

int main(){
	//~ double Min=LLONG_MAX;
	//~ vector<int>v;
	//~ for(int i=111111111;i>=1;i--){
		//~ int a=i,c=0;
		//~ while(a)c+=a%10,a/=10;
		//~ double d=i/(double)c;
		//~ if(i<=100000000){
			//~ if(d<=Min)v.push_back(i);
		//~ }
		//~ Min=min(Min,d);
	//~ }
	//~ reverse(v.begin(),v.end());
	//~ for(int i:v){
		//~ cout<<i<<endl;
	//~ }
	vector<ll>v;
	for(int i=1;i<=99;i++)v.push_back(i);
	for(int i=3;i<=16;i++){//桁数
		for(int j=100;j<=999;j++){
			ll d=j+1;rep(k,i-3)d*=10;d--;
			v.push_back(d);
		}
	}
	vector<ll>ans;
	double Min=LLONG_MAX;
	for(int i=v.size()-1;i>=0;i--){
		ll a=v[i],c=0;
		while(a)c+=a%10,a/=10;
		double d=v[i]/(double)c;
		if(d<=Min){
			ans.push_back(v[i]);
		}
		Min=min(Min,d);
	}
	reverse(ans.begin(),ans.end());
	int k;scanf("%d",&k);
	rep(i,k){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main()
{
  int n, T;
  cin >> n >> T;
  vi c(n), t(n);
  rep(i,n){
    cin >> c.at(i) >> t.at(i);
  }
  rep(i,n){
    for (int j = i; j < n;j++){
      int tmp;
      if (c.at(i) > c.at(j))
      {
        tmp = c.at(i);
        c.at(i) = c.at(j);
        c.at(j) = tmp;

        tmp = t.at(i);
        t.at(i) = t.at(j);
        t.at(j) = tmp;
      }
    }
  }
  rep(i,n){
    if(t.at(i)<=T){
      cout << c.at(i) << endl;
      break;
    }
    if(i==n-1){
      cout << "TLE" << endl;
    }
  }
  return 0;
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
bool edge [9] [9];

int main()
{
	scanf("%d%d",&N,&M);
	FOR(i,0,M){
		int a,b;
		scanf("%d%d",&a,&b);
		edge [a] [b] = edge [b] [a] = true;
	}

	vector<int> v(N);
	FOR(i,0,N){
		v [i] = i + 1;
	}

	int ans = 0;
	do{
		bool ok = true;
		FOR(i,0,N - 1){
			ok &= edge [v [i]] [v [i + 1]];
		}
		if(ok && v.front() == 1){
			ans++;
		}
	}while(next_permutation(ALL(v)));

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

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
/* デバッグ */
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"
int main(){
  int N,H;
  cin>>N;
  int ans = 0;
  int move = 0;
  int buf = 0;
  rep(i,N){
    cin>>H;
    if(buf>=H){
      move++;
    }else{
      ans = max(ans, move);
      move = 0;
    }
    buf = H;
  }
  ans = max(ans, move);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    vector<ll> space;
    ll cnt = 0;
    bool exchange = false;
    for(ll i = min(a-1, b-1); i < max(c, d); ++i){
        if(i != n-1 && s[i] == '#' && s[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
        if(i >= b-2 && i <= d && s[i] == '.') cnt++;
        if(s[i] == '#') cnt = 0;
        if(cnt >= 3) exchange = true;
    }
    if(c < d) cout << "Yes" << endl;
    else{
        if(!exchange) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

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

using namespace std;
int main(){
  int heisei = 0;
  string S;cin >> S;
  if (S.substr(5,1) == "0" and S.substr(6,1) <= "4"){
      heisei ++;
  }
  if (heisei == 1){
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" <<endl;
  }
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        if(x%2==0&&x%3!=0&&x%5!=0)
            cout<<"DENIED",exit(0);
    }
    cout<<"APPROVED";
}


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

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[222222];
ll b[222222];
set<ii> S;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; S.insert({-a[i],i});
	}
	ll ans=0;
	while(!S.empty())
	{
		int pos = (*S.begin()).se; S.erase(S.begin());
		if(a[pos]<b[pos])
		{
			cout<<-1<<'\n'; return 0;
		}
		if(a[pos]==b[pos])
		{
			continue;
		}
		ll sum = a[(pos+n-1)%n]+a[(pos+1)%n];
		ll M = max(b[pos],max(a[(pos+n-1)%n],a[(pos+1)%n]));
		ll cnt = max(0LL, (a[pos]-M)/sum);
		a[pos]-=sum*cnt; ans+=cnt;
		if(cnt==0)
		{
			a[pos]-=sum; ans++;
		}
		if(a[pos]<=0)
		{
			cout<<-1<<'\n'; return 0;
		}
		S.insert({-a[pos],pos});
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 17920
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

void solve1() {
	int N, A;
	cin >> N >> A;
	cout << N*N - A << endl;
}

void solve2() {

}

void solve3() {

}

void solve4() {

}

int main() {
	solve1();
	//solve2();
	//solve3();
	//solve4();

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (Math.Abs(A-B) % 2 == 0) {
            WriteLine("Alice");
        } else {
            WriteLine("Borys");
        }
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

using namespace std;

int main(void)
{
  char ch;
  int na = 0, nb = 0;
  for (int i = 0; i < 3; i++)
  {
    cin >> ch;
    if ('A' == ch) na++; else nb++;
  }
  cout << ((na && nb) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
program Exactly_N_points
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,ex,up
    integer(int32), allocatable:: cs(:)

    read*, n
    allocate(cs(n))
    cs(1) = 1
    ex = 0
    up = 1
    do i=2,n
        cs(i) = cs(i-1)+i
        if (cs(i) >= n) then
            ex = cs(i) - n
            up = i
            exit
        end if
    end do

    do i=1,up
        if (i==ex) cycle
        print'(i0)', i
    end do
end program Exactly_N_points

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

int main(void){
    int n,num;
    
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec.at(i);
    }

    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    
    int max = vec.at(0);
    num = 1;
    for(int i=1;i<n;i++){
        if(vec.at(i) < max){
            num++;
            max = vec.at(i);
        }
    }
    cout << num << endl;
}





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

using namespace std;
 int main() {
   long long N;
   cin>> N;
   long long W;
   cin >> W;
  
   
     

   vector<long long> a(N);
   vector<long long> b(N);
   for(long long i=0; i<N;i++) {
     cin >>a.at(i)>>b.at(i);
   }
   
   long long dp[110][100010];
   for (long long w = 0; w <= W; ++w) dp[0][w] = 0;//初期条件

   for (long long i = 0; i < N; ++i) {
    for (long long w = 0; w <= W; ++w) {
      if (w >= a[i]) dp[i+1][w] = max(dp[i][w-a[i]] + b[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

   cout << dp[N][W] << endl;
 }
   
   

Measured memory_bytes: 80896
main2(){
int c,d,_d,x,i,j;
char n[1001],u[51];
for(x=d=-1,i=0;(c=getchar())!=' ';i++){
if(c=='.'){i--;_d=d=i;continue;}
if(x<0&&c!='0')x=i;
n[i]=c;}
if(d==-1)_d=d=i-1;
scanf("%s",u);
if(!strcmp(u,"yotta"))d+=24;
if(!strcmp(u,"zetta"))d+=21;
if(!strcmp(u,"exa"))d+=18;
if(!strcmp(u,"peta"))d+=15;
if(!strcmp(u,"tera"))d+=12;
if(!strcmp(u,"giga"))d+=9;
if(!strcmp(u,"mega"))d+=6;
if(!strcmp(u,"kilo"))d+=3;
if(!strcmp(u,"hecto"))d+=2;
if(!strcmp(u,"deca"))d+=1;
if(!strcmp(u,"yocto"))d+=-24;
if(!strcmp(u,"zepto"))d+=-21;
if(!strcmp(u,"ato"))d+=-18;
if(!strcmp(u,"femto"))d+=-15;
if(!strcmp(u,"pico"))d+=-12;
if(!strcmp(u,"nano"))d+=-9;
if(!strcmp(u,"micro"))d+=-6;
if(!strcmp(u,"milli"))d+=-3;
if(!strcmp(u,"centi"))d+=-2;
if(!strcmp(u,"deci"))d+=-1;
if(d!=_d)scanf("%s",u);
getchar();putchar(n[x]);
if(x+1<i)putchar('.');
for(j=x+1;j<i;j++)
putchar(n[j]);
printf(" * 10^%d %s\n",d-x,u);}
main(n){for(scanf("%d",&n),getchar();n--;)main2();exit(0);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;

        void solve()
        {
          ll n,m,i,j,k,c=0,y=0,ams=0,a,b;
          string s;
         cin>>n;
         vector < ll > v(n);
        rep(i,0,n)
        {
            cin>>v[i];
            y^=v[i];
        }
        rep(i,0,n)
        {
            cout<<(y^v[i])<<" ";
        }



    }

        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


Measured memory_bytes: 4776
#include <stdio.h>

int main(void)
{
  char s[4];

  scanf("%s", s);


  if((s[0]!=s[1])&&(s[1]!=s[2])&&(s[2]!=s[0])) printf("Yes\n");
  else                                         printf("No\n");

  return 0;
} 


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

using namespace std;

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

	int *x;
	x = new int[n];
	for(int i = 0; i < n; i++) cin >> x[i];

	double ans = 0;
	for(int i = 0; i < n; i++) ans += 1.0/(double)x[i];

	cout << 1.0/ans;

	delete[] x;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;
    int ans[200005] = {};
    for(int i = n - 1;i > 0;i --){
      if(s[i] == '.'){
	ans[i] ++;
      }
      ans[i - 1] += ans[i];
    }
    int minv = INF, sum = 0;
    rep(i,n){
      minv = min(minv , ans[i + 1] + sum);
      if(s[i] == '#'){
	sum ++;
      }
    }
    cout << minv << '\n';
    return 0;
}


Measured memory_bytes: 1300
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ABC083_B();
        }

        static void ABC083_B()
        {
            var NAB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = NAB[1];
            var B = NAB[2];
            var list = new List<int>();
            for (int i = 1; i <= NAB[0]; i++)
            {
                var sum = i.ToString().Select(x => x.ToString()).Select(int.Parse).Sum();
                if (sum >= A && sum <= B)
                    list.Add(i);
            }
            Console.WriteLine(list.Sum());
        }

        public static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0)
                throw new Exception("0??");

            if (start > stop || (start == 0 && stop == 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        public static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }
    }
}

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

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

Measured memory_bytes: 256
/*Name:蔡佩璇  StudenID:107033226  Dept:動機22*/ 
#include <stdio.h>
#include <stdlib.h>

int main() {
	
	int a, b, sum, digit = 0;
	
	while(scanf("%d%d",&a ,&b) != EOF){
		
		digit = 0;
		sum = a + b;
		while(sum >= 1){
			
			sum /= 10;
			digit++;
			
		}
		printf("%d\n", digit);
				
	}
	return 0;
}


Measured memory_bytes: 1976
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int Japa , Math;
		
		if(A % C == 0){
			Japa = A / C;
		}else{
			Japa = A / C + 1;
		}
		
		if(B % D == 0){
			Math = B / D;
		}else{
			Math = B / D + 1;
		}
		
		int Bigone = Japa;
		
		if(Japa < Math){
			Bigone = Math;
		}
		
		System.out.println(L - Bigone);
		
	}
	
}

Measured memory_bytes: 26268
#include<iostream>
using namespace std;
main()
{
  int a1,a2,a3;
  cin>>a1;
  cin>>a2;
  cin>>a3;
  a1=a1+a2+a3;
 if(a1>22||a1==22)
   cout<<"bust";
  else
    cout<<"win";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

ll h, w;
ll ans = 1ll << 60ll;

int main() {
    cin >> h >> w;

    for (ll i = 1; i < h; i++) {
        ll s1, s2, s3;

        s1 = i * w;
        s2 = (h - i) * ((w + 1) / 2);
        s3 = (h - i) * (w / 2);

        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));
    }

    for (ll j = 1; j < w; j++) {
        ll s1, s2, s3;

        s1 = j * h;
        s2 = (w - j) * ((h + 1) / 2);
        s3 = (w - j) * (h / 2);
        
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));
    }

    for (ll i = 1; i < h; i++) {
        ll s1, s2, s3;

        s1 = i * w;
        s2 = ((h - i) / 2) * w;
        s3 = ((h - i + 1) / 2) * w;
        
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));
    }

    for (ll j = 1; j < w; j++) {
        ll s1, s2, s3;

        s1 = j * h;
        s2 = ((w - j) / 2) * h;
        s3 = ((w - j + 1) / 2) * h;
        
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));
    }

    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    while( cin >> n ) {
        if ( n == 0 )
            break;

        double diff = 999999999.9;
        int least = -1;
        for( int i=0; i<n; ++i ) {
            int i, h, w;

            cin >> i >> h >> w;

            double const bmi = static_cast<double>( w ) / pow( static_cast<double>( h ) / 100.0, 2 );

            double const d = abs( 22.0 - bmi );
            if ( d < diff ) {
                diff = d;
                least = i;
            }
        }

        cout << least << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  int n;
  cin >> n;
  vi a(n) ;
  rep(i,n) cin >> a[i];
  vi t(100009,0);
  vi s(100009,0);
  rep(i,n){
    if(i%2) t[a[i]]++;
    else s[a[i]]++;
  }
  ll maxi = 0;
  ll maxu = 0;
  ll maxp = 0;
  ll maxq = 0;
  rep(i,100001){
    if(t[i]>maxi){
      maxi = t[i];
      maxp = i;
    }
    if(s[i]>maxu){
      maxu = s[i];
      maxq = i;
    }
  }
  int p = 0;
  int q = 0;
  
  sort(ALL(t),greater<int>());
  sort(ALL(s),greater<int>());
  if(maxp==maxq){
    if(t[0]+s[1]>t[1]+s[0])q++;
    else p++;
  }
  cout << n-t[p]-s[q] << endl;
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<31;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int main() {
    ll a, b, c, d; 
    cin >> a >> b >> c >> d;
    ll ans = max({a*c,a*d,b*c,b*d});
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,k,n=0;
    cin >> a >> b >> c >> k;
    if(k<=a){
        n=k;
    }else if(k<=a+b){
        n=a;
    }else{
        n=2*a-k+b;
    }
    cout << n << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

vector<vector<int>> e;
bool used[5];

int dfs(int k, int d){
	if(used[k]) return false;
	used[k] = true;
	if(d == 4) return true;
	bool res = false;
	for(auto&& i : e[k]){
		res |= dfs(i, d + 1);
	}
	used[k] = false;
	return res;
}

int main(){
	e = vector<vector<int>>(5);
	for(int i = 0; i < 3; i++){
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	bool f = false;
	for(int i = 1; i < 4; i++){
		f |= dfs(i, 1);
	}
	cout << (f? "YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ k, s ] <- readInts
	print $ length $ do
		x <- [ 0 .. k ]
		y <- [ 0 .. k ]
		let
			z = s - x - y
		guard $ 0 <= z && z <= min k s
		return ()

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

using ll = long long;

constexpr int MAX_N = 1e5 + 9;

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

const ll INF = 1LL << 60;

int N;
ll h[MAX_N];

ll dp[MAX_N + 1];

int main() {
  fill_n(dp, MAX_N + 1, INF);
  cin >> N;
  for (int i{}; i < N; ++i) cin >> h[i];

  dp[0] = 0;
  for (int i{0}; i < N - 1; ++i) {
    chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }

  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 5140
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}
ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
}

template<class t>
istream& operator>>(istream& is, vector<t> &x){
    for(auto &i:x)is >> i;
    return is;
}

template<class t, class u>
istream& operator>>(istream& is, pair<t, u> x){
    is >> x.first >> x.second;
    return is;
}


int main(){
    int n = in();
    int r = in();
    cout << r + max(0, 10-n) * 100 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k, n,ans;
    cin >> k >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    ans=a[0]+k-a[n-1];
    for (int i=0; i<n-1; i++)
    {
        ans=max(ans,a[i+1]-a[i]);
    }
    cout<<k-ans<<endl;
    return 0;
}






Measured memory_bytes: 1024
import java.util.*;
    public class Main{
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b= a + (int)Math.pow(a, 2) + (int)Math.pow(a, 3);
          	System.out.println(b);
        }
    }

Measured memory_bytes: 35732
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int f_stamp[103];
int e_stamp[103];
vector<vector<int> > edge;
int t;
void dfs(int v){
	REP(i,edge[v].size()){
		if(not f_stamp[edge[v][i]]){
			f_stamp[edge[v][i]] = ++t;
			dfs(edge[v][i]);
		}
	}
	e_stamp[v] = ++t;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	edge.resize(n,vector<int>());
	REP(i,n){
		int v;cin>>v;v--;int t;cin>>t;
		while(t--){
			int u;cin>>u;u--;
			edge[v].push_back(u);
		}
	}
	REP(i,n){
		if(not f_stamp[i]){
			f_stamp[i] = ++t;
			dfs(i);
		}
	}
	REP(i,n){
		cout << i+1 << ' ' << f_stamp[i] << ' ' << e_stamp[i] << endl;
	}
  return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
 
using namespace std;
 
int main(){
 
    int h,w;
    cin >> h >> w;
 
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
 
    for(int i=0;i<h;i++){
        for(int k=0;k<w;k++){
            int c=0;
            if(s[i][k] == '#'){
            if(i != 0 && s[i-1][k] == '#') c++;
            if(i != h-1 && s[i+1][k] == '#') c++;
            if(k != 0 && s[i][k-1] == '#') c++;
            if(k != w-1 && s[i][k+1] == '#') c++;
            if(c == 0){
                cout << "No";
                return 0;
            }
            }
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
unique_a = {a[0] % m: 1}
for i in range(1, n):
    a[i] += a[i - 1]
    a[i] %= m
    if a[i] in unique_a:
        unique_a[a[i]] += 1
    else:
        unique_a[a[i]] = 1
count = 0
if 0 in unique_a:
    count += unique_a[0]
for k, v in sorted(unique_a.items(), key=lambda x: - x[0]):
    if v == 0:
        break
    count += v * (v - 1) // 2
print(count)

Measured memory_bytes: 17572
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  int n;
  cin>>n;
  vector<int> a(n),l,r;
  for(auto& c:a)cin>>c;
  l=r=a;
  for(int i=1;i<n;++i){
    l[i]=gcd(l[i],l[i-1]);
    r[n-1-i]=gcd(r[n-1-i],r[n-i]);
  }
  int res=1;
  for(int i=0;i<n;++i)res=max(res,gcd(i?l[i-1]:0,i+1<n?r[i+1]:0));
  cout<<res;
  return 0;
}

Measured memory_bytes: 1408
a, b = input().split()  # まず文字列で受け取ります
p = int(a) # aはそのままint型にします
q = int(b[0] + b[2] + b[3])  # b[0] + b[2] + b[3]を整数に変換すれば、bの100倍を正確に得られます

print(p * q // 100)  # 2つを掛けて100で整数の割り算をすれば終わりです

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i,x;
    cin>>n;
    ll sum[n+1]={0};
    
    string s;
    map<string,int>m;
    for(i=0;i<n;i++)
    {
    	cin>>s>>x;
    	m[s]=i;
    	sum[i+1]=sum[i]+x;
    	
	}
	cin>>s;
	cout<<sum[n]-sum[m[s]+1];
    
    

}

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

constexpr auto MOD = (long long)1e9+7;
constexpr auto MAXN = 6000;

long long Pow(long long a,long long b){
    long long ans = 1LL;
    for(;b;b>>=1,(a*=a)%=MOD)
        if(b&1) (ans *= a) %= MOD;
    return ans;
}

long long f[4][MAXN];
long long g[MAXN][2];

signed main(void)
{
    int len,a,b;
    long long ans=0;

    std::cin>>len>>a>>b;
    if(a > b) std::swap(a,b);
    if(b<2) goto OP;

    f[0][1] = 1LL;
    for(int i=2;i<b;++i){
        f[0][i] = 1;
        for(int j=1;j<i;++j) (f[0][i] += f[1][i-j]) %= MOD;
        for(int j=i-a;j>=0;--j) (f[1][i] += f[0][j]) %= MOD;

        for(int j=1;j<i;++j) (f[2][i] += f[3][j]) %= MOD;
        if(i >= a) f[3][i] = 1;
        for(int j=i-a;j>=0;--j) (f[3][i] += f[2][j]) %= MOD;
    }
    for(int i=1;i<=len;++i){
        if(i < b) g[i][1] = f[0][i] + f[2][i];
        for(int j=1; j<b&&i-j>0; ++j)
            (g[i][1] += g[i-j][0]*f[0][j]) %= MOD;

        if(i < a) g[i][0] = 1LL;
        for(int j=1; j<a&&i-j>0; ++j)
            (g[i][0] += g[i-j][1]) %= MOD;
    }

    ans = (g[len][0]+g[len][1]) % MOD;
    for(int i=1;i<len;++i) (ans += g[i][0]*f[1][len-i]) %= MOD;
    
 OP:
    std::cout<< (Pow(2LL,len)-ans+MOD)%MOD <<std::endl;
    
    return 0;
}


Measured memory_bytes: 3848
import sys
import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    a,b,c = map(int,input().split())
    if 4*a*b<(c-a-b)**2 and c-a-b>=0:
        print("Yes")
    else:
        print("No")
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 3060
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():

        n=int(input())
        l=[list(map(int,input().split())) for i in range(n)]
        l.sort(key=lambda x:x[1])
        time=0
        for x,y in l:
            time+=x
            if time>y:
                return 'No'
        return 'Yes'
    print(main())

resolve()

Measured memory_bytes: 83292
use proconio::input;

fn main() {
    input! {
        n: usize,
    }

    let mut a = (n as f64).sqrt() as usize;
    let b = 
        loop {
            if n % a == 0 {
                break n / a;
            }
            a -= 1;
        };

    let mut length = a.to_string().chars().collect::<Vec<_>>().len();
    length = std::cmp::max(length, b.to_string().chars().collect::<Vec<_>>().len());

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


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<algorithm>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;



int main() {
	int a[5];
	int ans =0,k=10,j=0;
	rep0(i,5){
	    cin >> a[i];
	    if(a[i]%10<k&&a[i]%10>0){
	        j=i;
	        k=a[i]%10;
	    }
	}
	rep0(i,5){
	    if(a[i]%10!=0&&i!=j){
	        
	        a[i]=(a[i]/10+1)*10;
	        ans+=a[i];
	    }
	    else{
	        ans+=a[i];
	    }
	}
    cout << ans;
}


Measured memory_bytes: 256
import collections


def solve(N, ts, ps):
    for i in range(N):
        dt = ts[i+1] - ts[i]
        d = abs(ps[i+1].x - ps[i].x) + abs(ps[i+1].y - ps[i].y)

        if d > dt or dt % 2 != d % 2:
            return "No"
    return "Yes"


N = int(input())
point = collections.namedtuple('point', ['x', 'y'])
ts = [0]
ps = [point(0, 0)]
for i in range(N):
    t, x, y = list(map(int, input().split()))
    ts.append(t)
    ps.append(point(x, y))

print(solve(N, ts, ps))

Measured memory_bytes: 18560
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

class dijkstra{
  constructor(n){
    this.graph = Array(n).fill().map(a=>[]);
  }
  add(u,v,cost){
    this.graph[u].push(v,cost);
  }
  add2(u,v,cost){
    this.graph[u].push(v,cost);
    this.graph[v].push(u,cost);
  }
  solve(start){
    const INF = 1e18;
    const g = this.graph;
    var pq = new priorityQueue();
    pq.push([0,start]);
    var dp = Array(g.length).fill(INF);
    dp[start] = 0;
    while(pq.size){
      var [t,v] = pq.pop();
      if(dp[v] < t)continue;
      for(var i = 0; i < g[v].length; i+=2){
        var V = g[v][i], c = g[v][i+1] + t;
        if(dp[V] <= c)continue;
        dp[V] = c;
        pq.push([c,V]);
      }
    }
    return dp;
  }
}

class priorityQueue{
  constructor(){
    this.a=[];
  }
  push(x){
    const a = this.a;
    for(var i = a.length, j; i; i = j){
      j = i - 1 >> 1;
      if(a[j][0] <= x[0])break;
      a[i] = a[j];
    }
    a[i] = x;
  }
  pop(){
    const a = this.a, r = a[0], x = a.pop(), k = a.length >> 1;
    for(var i = 0, j; i < k; i = j){
      j = (i << 1) + 1;
      if(a[j+1] && a[j+1][0] < a[j][0])j++;
      if(x[0] <= a[j][0])break;
      a[i] = a[j];
    }
    if(a.length)a[i] = x;
    return r;
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

const mx = 2500;

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m,s] = nexts(3);
  var g = new dijkstra(mx * n);
  for(var i = 0; i < m; i++){
    var [u,v,a,b] = nexts(4);
    u--,v--;
    u *= mx, v *= mx;
    for(var j = mx; j-- > a;){
      g.add(u+j,v+j-a,b);
      g.add(v+j,u+j-a,b);
    }
  }
  for(var i = 0; i < n; i++){
    var [c,d] = nexts(2);
    var v = i * mx;
    for(var j = 0; j < mx-1; j++)g.add(v+j,v+Math.min(mx-1,j+c),d);
  }
  var dp = g.solve(Math.min(mx-1,s));
  var ans = xArray(1e18,n);
  for(var i = 1; i < n; i++){
    var v = i*mx;
    for(var j = 0; j < mx; j++){
      ans[i] = Math.min(ans[i],dp[v+j]);
    }
  }
  return ans.slice(1).join("\n");
}

Measured memory_bytes: 112484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main(){
    int A, B;
    cin >> A >> B;
    rep(i, 10000) {
        if((int)(i*0.08) == A && (int)(i*0.1) == B){
            out(i);
            return 0;
        }
    }
    out(-1);
}

Measured memory_bytes: 256
# abcde    s=input()    s='abcde'
# abcde    s=list(input())    s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)    a=int(input())    a=5
# 1 2    | x,y = s_inpl()   |    x=1,y=2
# 1 2 3 4 5 ... n 　    li = input().split()    li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　    li = inpl()    li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　    li = input().split('T')    li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

class UnionFind(object):
 
    def __init__(self, N):
        self.parent = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N
 
    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
 
        if self.rank[x] < self.rank[y]:
            x, y = y, x
 
        self.size[x] += self.size[y]
        self.parent[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def count(self, x):
        return self.size[self.find(x)]

N, M = l_inpl()
p = l_inpl()

uf = UnionFind(N)
for _ in range(M):
    xi, yi = l_inpl()
    xi, yi = xi-1, yi-1
    uf.union(xi, yi)

ans = 0
for i, pi in enumerate(p):
    pi = pi - 1
    if uf.same(i, pi):
        ans += 1

print(ans)    


Measured memory_bytes: 99888
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

struct Edge{
        int to,cost;
};
bool operator < (const Edge &e,const Edge &f){	return e.cost>f.cost;	};	//INVERSE!!
typedef vector<vector<Edge>> Graph;

void addEdge(Graph &g,int from,int to,int cost){
    g[from].push_back((Edge){to,cost});
}

int main(void){
    int N,M;
    GI(N);GI(M);
    Graph G(N);
    vector<LL> pos(N,LLMAX);
    REP(i,M){
        int L,R;
        LL D;
        GI(L);GI(R);GLL(D);
        L--;R--;
        addEdge(G,L,R,D);
        addEdge(G,R,L,-D);
    }
    REP(i,N){
        if(pos[i]==LLMAX){
            pos[i]=0;
            queue<pair<LL,LL> > que;
            for(auto e:G[i])
                que.push(MP(e.to, e.cost));
            while(!que.empty()){
                int v = que.front().first;
                int d = que.front().second;
                que.pop();
                if(pos[v]!=LLMAX){
                    if(pos[v] != d){
                        printf("No\n");
                        return 0;
                    }
                }else{
                    pos[v] = d;
                    for(auto e:G[v])
                        que.push(MP(e.to, d + e.cost));
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 14068
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
	string S;
	cin >> S;
	int l = S.size();

	char ch[l];
	for(int i=0;i<l;i++){
		ch[i] = S[i];
	}
	sort(ch, ch+l);

	for(int i=0;i<l-1;i++){
		if(ch[i]==ch[i+1]){
			cout << "no" <<endl;
			return 0;
		}
	}
	cout << "yes" <<endl;
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll     long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll ll,ll ll>
#define all(v) (v).begin(), (v).end()
using namespace std;

void solve()
{
    ll n, ans = 0, maxa = 0;
    cin >> n;
    std::vector<ll> v(n);
    for(ll &i : v) cin >> i;
    for(ll i : v)
    {
        ans += max(maxa - i, 0ll);
        maxa = max(maxa, i);
    }
    cout << ans;
}
int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll TESTS = 1;
    // cin >> TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4776
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using System;

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var p = Console.ReadLine().Trim().Replace(" ", "");
        var q = Console.ReadLine().Trim().Replace(" ", "");
        getAns(n, p, q);
    }
    static void getAns(int n, string p, string q)
    {
        var alist = new List<string>();
        var a = Enumerable.Range(1, n).Perm();
        foreach (var x in a)
        {
            var t = "";
            foreach (var y in x) t += y.ToString();
            alist.Add(t);
        }
        alist.Sort();
        var pc = alist.BinarySearch(p);
        var qc = alist.BinarySearch(q);
        Console.WriteLine(Abs(pc - qc));
    }
}


Measured memory_bytes: 20612
N = int(input())
cost = [0]*5
for i in range(5):
  cost[i] = int(input())
bottleneck = sorted(cost,key = lambda x: N / x,reverse = True)
result = N // bottleneck[0]
if N % bottleneck[0] == 0:
  result -= 1
print(5+result)
    
    
    
    

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
  int N,i,v,j;
  int A[100];
  
  scanf("%d",&N);
  for(i = 0;i < N;i++){
    scanf("%d",&A[i]);
  }

  for(j = 0;j < N;j++){
      printf("%d",A[j]);
      if(j == N - 1) break;
      printf(" ");
    }
    printf("\n");
  
  for(i = 1;i <= N - 1;i++){
    
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    
    for(j = 0;j < N;j++){
      printf("%d",A[j]);
      if(j == N - 1) break;
      printf(" ");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2064
n, k = map(int, input().split())
li=[]
for i in range(n):
    a, b = map(int, input().split())
    li.append([a,b])
li=sorted(li, key=lambda x: x[0])
for i in range(n):
    k -= li[i][1]
    if k <= 0:
        print(li[i][0])
        break




Measured memory_bytes: 22144
#include <iostream>
#include <math.h>
using namespace std;
#define int long long
int a,b;
int ans=1;
int gcd(int a,int b){
	if (a<b) swap(a,b);
	if (b==0) return a;
	else return gcd(b,a%b);
}

signed main()

{
	ios::sync_with_stdio(false);
	cin>>a>>b;
	int c=gcd(a,b);
	int oc=c;
	for (int i=2;i<=sqrt(oc);i++){
		if (c%i==0&&i<=c){
			ans++;
			//cout<<i<<endl;
			while (c%i==0) c/=i;
		}
	}

	for (int i=sqrt(oc);i>=1;i--){
		int ni=oc/i;
		if (c%ni==0){
			if (ni<=1) continue;
			ans++;
			//cout<<ni<<endl;
			while (c%ni==0&&ni<=c) c/=ni;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL))
int main()
{
    ll n;
    cin>>n;
    ll ans = 1e18;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ans = min(ans,i+(n/i));
        }
    }
    ans -= 2;
    cout<<ans;
}

Measured memory_bytes: 256