akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val a = long()
    val b = long()
    val c = long()
    val k = long()
    if (k % 2 == 0L) println(a - b) else println(b - a)
}


class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 29476
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

map<int,int,greater<int>> M;
int main()
{
	int N;
	ll res=-1,a=-1,b=-1;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		int p;
		cin>>p;
		M[p]++;
	}
	for(auto it=M.begin();it!=M.end();it++)
	{
		if(it->second>=2)
		{
			a=it->first;
			it->second-=2;
			break;
		}
	}
	for(auto it=M.begin();it!=M.end();it++)
	{
		if(it->second>=2)
		{
			b=it->first;
			it->second-=2;
			break;
		}
	}
	if(a==-1||b==-1)puts("0");
	else cout<<a*b<<endl;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  char[] c = s.toCharArray();
  String[] alp = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  String[] d = new String[c.length];
  Set<String> hs = new HashSet<String>();
  for(int i = 0;i < s.length();i++){
	  d[i] = String.valueOf(c[i]);
	  hs.add(d[i]);
  }
  if(hs.size() == 26)System.out.println("None");
  else {
    for(int i = 0;;i++){
      if(!(hs.contains(alp[i]))){
        System.out.println(alp[i]);
        break;
      }
    }
  }
}}
  

Measured memory_bytes: 30576
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        200005
#define mod         1000000007
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll q,flag=0,t,f;
    char ch;
    deque<char> qe;
    cin>>q;
    for(auto x:s){
        qe.push_back(x);
    }
    while(q--){
        cin>>t;
        if(t==1){
            if(flag==0){
                flag=1;
            }
            else{
                flag=0;
            }
        }
        else{
            cin>>f>>ch;
            if(flag==0){
                if(f==1){
                    qe.push_front(ch);
                }
                else{
                    qe.push_back(ch);
                }
            }
            else{
                if(f==1){
                    qe.push_back(ch);
                }
                else{
                    qe.push_front(ch);
                }
            }
        }
    }
    if(flag==0){
        while(!qe.empty()){
            cout<<qe.front();
            qe.pop_front();
        }
    }
    else{
        while(!qe.empty()){
            cout<<qe.back();
            qe.pop_back();
        }
    }
}

Measured memory_bytes: 976
def smaller(x, y):
	if x < y: return x
	else: return y

N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
left = 0
right = 0
for i in range(0, M):
	if A[i] < X: left = left + 1
	if A[i] > X: right = right + 1

print smaller(left, right)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;

signed main() {
	int n;
	cin >> n;
	map <string, int> cnt;
	rep (i, n) {
		int w;
		cin >> w;
		string num = "123";
		rep (j, w) {
			int a;
			cin >> a;
			if (a) swap(num[1], num[2]);
			else swap(num[0], num[1]);
		}
		cnt[num]++;
	}
	if (cnt["123"] >= 1 || cnt["132"] >= 2 || cnt["213"] >= 2 || cnt["231"] >= 3
	 || cnt["312"] >= 3 || cnt["321"] >= 2 || cnt["231"] >= 1 && cnt["312"] >= 1
	 || (cnt["231"] >= 1 || cnt["312"] >= 2) && cnt["213"] >= 1 && cnt["321"] >= 1
	 || (cnt["312"] >= 1 || cnt["231"] >= 2) && cnt["132"] >= 1 && cnt["321"] >= 1
	 || cnt["231"] >= 1 && cnt["132"] >= 1 && cnt["213"] >= 1
	 || cnt["312"] >= 1 && cnt["132"] >= 1 && cnt["213"] >= 1 ) {
		cout << "yes" << endl;
	} else {
		cout << "no" << endl;
	}
	return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int a,b,c;
	for(int i; ;i++){
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)
			break;
		else if(a<=b)
			cout<<a<<" "<<b<<endl;
		else
			cout<<b<<" "<<a<<endl;
	}
	return 0;
} 


Measured memory_bytes: 3244
N, Y = map(int, input().split())
a = 0
b = 0
c = 0
total = 0
flag = 0

for a in range(N+1):
    for b in range(N+1-a):
#        for c in range(N):
            total = a*10000 + b*5000 + (N-a-b)*1000
            if Y == total:
                print(a, b, N-a-b)
                flag = 1
                break
    else:
        continue
    break
    
if flag == 0:
    print(-1, -1, -1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  FOR(i,0,1989000000){
    if(i%2==0){
      n*=3;
    }
    else{
      n/=3;
    }
  }
  co(3*n*n)
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        String today = scan.nextLine();

        String tomorrow = "";
        switch (today){
            case "Sunny":
                tomorrow = "Cloudy";
                break;
            case "Cloudy":
                tomorrow = "Rainy";
                break;
            case "Rainy":
                tomorrow = "Sunny";
                break;
        }

        System.out.println(tomorrow);
    }
}


Measured memory_bytes: 21460
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: [usize;5],
        k: usize,
    };
    let ret = if a.iter().max().unwrap()-a.iter().min().unwrap() > k {":("} else {"Yay!"};


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


Measured memory_bytes: 4352
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
//#define MOD (1000000007)
#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int n;cin>>n;
    int b=(n/500)*1000;
    int c= (n%500)/5*5;
    cout<<b+c;
}

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

#define IS_DEBUG true

#define DEBUG_OUTPUT(X) if (IS_DEBUG) cout << X << endl
#define RESULT_OUTPUT(X) cout << X << endl

void sortIncrease(vector<int> &array);
void sortDecrease(vector<int> &array);

int main()
{
	int A, B, C, X;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> X;
	int n = 0;
	for (int a = 0; a <= A; a++)
	{
		for (int b = 0; b <= B; b++)
		{
			for (int c = 0; c <= C; c++)
			{
				if (a * 500 + b * 100 + c * 50 == X)
					n++;
			}
		}
	}
	RESULT_OUTPUT(n);


	if (IS_DEBUG)
	{
		int end;
		cin >> end;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

int n, m, k;
char s[MAXN][MAXN];
void run(){
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) cin >> s[i];
    int cnt, ans = 0;
    for(int r = 0; r < (1 << n); r++){
        for(int c = 0; c < (1 << m); c++){
            cnt = 0;
            for(int i = 0; i < n; i++)
                for(int j = 0; j < m; j++)
                    if(!(r & (1 << i)) && !(c & (1 << j)) && s[i][j] == '#') cnt++;
            ans += cnt == k;
        }
    }
    cout << ans;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    run(); return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
using namespace std;
/*(^(^(^(^(^o^)^)^)^)^) &#9602;&#9605;&#9607;&#9608;&#9619;&#9618;&#9617;('ω')&#9617;&#9618;&#9619;&#9608;&#9607;&#9605;&#9602; */
int main(){
	int n,m=0;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		while(n!=0){
			n /= 5;
            m+=n;
		}
		printf("%d\n",m);
		m=0;
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

map<string, int> ans;
bool used[10] = {};
int n;

void dfs(string s, ll mx){
    if(s.size() == n)ans[s] = 1;
    else {
        rep(i, mx+2){
            dfs(s+char('a'+i), max(mx, i));
        }
    }
}

int main(){
    cin >> n;

    dfs("a", 0);

    for(auto itr = ans.begin(); itr != ans.end();itr++){
        cout << itr->first << endl;
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/04/27  Problem: ABC 125 B / Link: http://abc125.contest.atcoder.jp/tasks/abc125_b  ----- */


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

	LL N; cin >> N;
	vector<LL> v(N);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}
	vector<LL> c(N);
	for (int i = 0; i < N; ++i) {
		cin >> c[i];
	}
	LL ans = 0LL;
	FOR(i, 0, N) {
		ans += max(0LL, v[i] - c[i]);
	}

	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
public class Hello{
    public static void Main()
    {
        // Your code here!
        
        int X = int.Parse(Console.ReadLine());
        int save = 1;
        
        if(X == 1) 
        {
            Console.WriteLine(1);
            return;
            
        }
        
        
        for(int i = 2; i <= Math.Sqrt(X); i++)
        {
            int a = i * i;
            
            while(a <= X)
            {
                
                if(a == X)
                {
                    Console.WriteLine(a);
                    return;
                }
                else if(a < X)
                {
                    a = a * i;
                }
                
               
            }
                a = a / i; //超えたとき
               
                if(a > save)
                {
                    save = a;
                    
                    
                }
               
            
        }
        
        Console.WriteLine(save);
        
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		int[][] a = new int[n][n];
		String[] str; 
		for(int i = 0; i < n; ++i){
			str = br.readLine().split(" ");
			for(int j = 0; j < n; ++j) {
				int u = Integer.parseInt(str[j+1]);
				a[i][j] = (u < 0) ? Integer.MAX_VALUE : u;
			}
		}

		int sum = 0;
		HashSet<Integer> s = new HashSet<Integer>(n);
		s.add(0); // first node
		while(s.size() != n){
			int min = Integer.MAX_VALUE;
			int newNode = 0;
			for(int node : s){
				for(int i = 0; i < n; ++i){
					if(s.contains(i)){
						continue;
					}
					if(min > a[node][i]){
						min = a[node][i];
						newNode = i;
					}
				}
			}
			sum += min;
			s.add(newNode);
		}
		System.out.println(sum);
		
	}

}

Measured memory_bytes: 28100
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll a,b;
    cin>>a>>b;
    
    ld t;
    if(b/10<1){
        t=10*a+b;
    }else if(b/10<10){
        t=100*a+b;
    }else{
        t=1000*a+b;
    }
    ld tt=sqrt(t);
    ll ttt=tt;
    cout<<(tt-ttt==0?"Yes":"No");
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3688
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.List (sort)
import qualified Data.Sequence as S
import Text.Printf
import Debug.Trace

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

hd s = s `S.index` 0
tl s = S.drop 1 s
lst s = s `S.index` (S.length s - 1)
ini s = S.take (S.length s - 1) s

solve (s,acc)
  | S.length s <= 1 = acc
  | otherwise = solve $ eat $ (dropb $ dropf s, acc)
  where
    dropf s
      | S.length s <= 1 = s
      | hd s == (hd . tl) s = s
      | otherwise = dropf $ S.drop 1 s
    dropb s
      | S.length s <= 1 = s
      | lst s == (lst . ini) s = s
      | otherwise = dropb $ ini s
    eat (s,acc)
      | S.length s <= 1 = (s,acc)
      | otherwise = ((ini . tl) s, acc+2)

main = do
  [n] <-getInts
  s <- S.fromList . sort <$> getInts
  print $ n - solve (s,0)
  


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

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    for(int i = 0; i < s1.size(); i++)
    {
        if(s1 == s2) return cout << "Yes\n", 0;
        s1.insert(s1.begin(), s1.back());
        s1.pop_back();
    }
    cout << "No\n";
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>

int prime(int x){
  int flag=1;
  for(int i=2;i<sqrt(x);i++){
      if(x%i==0) flag=0;
  }
  return flag;
}

int main(void){
  int x,ans;
  scanf("%d", &x);
  
  int j = x;
  while(prime(j)==0) j++;
  /*
  for(int j=x;;j++){
    if(prime(x,j)==1){
  	ans =j;
      break;
    }
  }
  */
  ans = j;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 2152
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}
int main()
{
    int n, c, k;
    scanf("%d %d %d", &n, &c, &k);
    int i;
    int t[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &t[i]);
    qsort(t, n, sizeof(int), asc);
    int ans = 0;
    int time = t[0];
    int count = 1;
    for (i = 1; i < n; i++)
    {
        if (count == c || t[i] - time > k)
        {
            ans++;
            count = 1;
            time = t[i];
        }
        else
        {
            count++;
        }
    }
    ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#define sc(n) scanf("%d",&n)
#define sc2(x,y) scanf("%d %d",&x,&y)
#define fornt(i,n) for(i=0; i<n; ++i)
using namespace std;


int main ()
{
    int i,n;
    string s;
    map<string,int>mp;
    sc(n);
    fornt(i,n)
    {
        cin>>s;
        ++mp[s];
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 3304
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = reader.nextInt();
        }
        System.out.println(solve(a));
    }

    private static int solve(int[] a) {
        int[] dp = new int[a.length];
        Arrays.fill(dp, Integer.MAX_VALUE);
//        return findMin(a.length - 1, a.length - 1, a, dp);
//        return findMin2(0, 0, a, dp);
        return findMinIt(a);
    }

    private static int findMin(int curPos, int prevPos, int[] a, int[] dp) {
        if (curPos < 0)
            return Integer.MAX_VALUE;
        if (dp[curPos] > 0)
            return dp[curPos];
        int score = Math.abs(a[curPos] - a[prevPos]);
        if (curPos == 0) {
            return score;
        }
        int min = Math.min(
                findMin(curPos - 1, curPos, a, dp),
                findMin(curPos - 2, curPos, a, dp));
        dp[curPos] = min;

        return min + score;
    }

    private static int findMin2(int curPos, int prevPos, int[] a, int[] dp) {
        if (curPos >= dp.length)
            return Integer.MAX_VALUE;
        int score = Math.abs(a[curPos] - a[prevPos]);
        if (curPos == a.length - 1)
            return score;
        int min;
        if (dp[curPos] != Integer.MAX_VALUE) {
            min = dp[curPos];
        } else {
            min = Math.min(findMin2(curPos + 1, curPos, a, dp), findMin2(curPos + 2, curPos, a, dp));
            dp[curPos] = min;
        }
        return min + score;
    }

    private static int findMinIt(int[] a) {
        int[] dp = new int[a.length];
        for (int i = a.length - 2; i >= 0; --i) {
            if (i == a.length - 2) {
                dp[i] = Math.abs(a[i] - a[i + 1]);
            } else {
                dp[i] = Math.min(dp[i + 1] + Math.abs(a[i] - a[i + 1]), dp[i + 2] + Math.abs(a[i] - a[i + 2]));
            }
        }
        return dp[0];
    }
}


Measured memory_bytes: 49632
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
int main() {
    int n;
    cin >> n;

    vector<int> v(3*n);
    for (auto &&i : v) scanf("%d", &i), i--;
    auto dp = make_v(n, n, -1);
    stack<tuple<int, int, int>> Q;
    dp[v[0]][v[1]] = 0;
    int aans = 0, vval = 0;
    vector<int> dpp(n, -1);
    dpp[v[0]] = 0;
    dpp[v[1]] = 0;
    for (int w = 0; w < n - 1; ++w) {
        int a = v[3*w+2], b = v[3*w+3], c = v[3*w+4];
        if(a == b && b == c) aans++;
        else {
            if (a == b) {
                for (int i = 0; i < n; ++i) {
                    if (dp[i][a] >= 0) Q.emplace(c, i, dp[i][a] + 1);
                    if (dp[a][i] >= 0) Q.emplace(c, i, dp[a][i] + 1);
                }
            } else if (a == c) {
                for (int i = 0; i < n; ++i) {
                    if (dp[i][a] >= 0) Q.emplace(b, i, dp[i][a] + 1);
                    if (dp[a][i] >= 0) Q.emplace(b, i, dp[a][i] + 1);
                }
            } else if (b == c) {
                for (int i = 0; i < n; ++i) {
                    if (dp[i][c] >= 0) Q.emplace(a, i, dp[i][c] + 1);
                    if (dp[c][i] >= 0) Q.emplace(a, i, dp[c][i] + 1);
                }
            }
            if (dp[a][a] >= 0) Q.emplace(b, c, dp[a][a] + 1);
            if (dp[b][b] >= 0) Q.emplace(a, c, dp[b][b] + 1);
            if (dp[c][c] >= 0) Q.emplace(a, b, dp[c][c] + 1);
            Q.emplace(a, b, vval);
            Q.emplace(a, c, vval);
            Q.emplace(b, c, vval);
            for (int i = 0; i < n; ++i) {
                if (dpp[i] >= 0) {
                    Q.emplace(a, i, dpp[i]);
                    Q.emplace(b, i, dpp[i]);
                    Q.emplace(c, i, dpp[i]);
                }
            }
            while (!Q.empty()) {
                auto[p, q, r] = Q.top();
                Q.pop();
                chmax(dp[p][q], r);
                chmax(dpp[p], r);
                chmax(dpp[q], r);
                chmax(vval, r);
            }
        }
    }
    cout << max(vval, dp[v.back()][v.back()]+1)+aans << "\n";
    return 0;
}

Measured memory_bytes: 19528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = (int)((double)iN / 1.08D);
            int iTp1 = 0, iTp2 = 0, iTp3 = 0;
            iTp1 = (int)((double)(iOut - 1) * 1.08D);
            iTp2 = (int)((double)(iOut + 0) * 1.08D);
            iTp3 = (int)((double)(iOut + 1) * 1.08D);
            string sOut = ":(";
            if (iTp1 == iN || iTp2 == iN || iTp3 == iN)
            {
                if      (iTp1 == iN) { sOut = (iOut - 1).ToString(); }
                else if (iTp2 == iN) { sOut = (iOut + 0).ToString(); }
                else if (iTp3 == iN) { sOut = (iOut + 1).ToString(); }
            }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
num = int(input())

info = list()
buildings = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for i in range(num):
    info = input().split()
    buildings[int(info[0])-1][int(info[1])-1][int(info[2])-1] += int(info[3])

for i, b in enumerate(buildings):
    for f in b:
        print(' ', end='')
        print(' '.join(map(str, f)))
    if not i == (len(buildings) - 1):
        print('#'*20)

Measured memory_bytes: 7716
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	int[] sosuu = new int[1000000];
	public void run() {
		calcSosuu();
		while(sc.hasNext()){
			int n = sc.nextInt();
			int p = sc.nextInt();
			if(n == -1 && p == -1) break;
			calc(n, p);
		}
	}
	public void calc(int n , int p){
		LinkedList<Integer> list = new LinkedList<Integer>();
		int t = 0;
		int t2 = 0;
		for(int i = n+1; i < 1000000; i++){
			if(sosuu[i] == 1){
				for(int j = i; j < 1000000; j++){
					if(sosuu[j] == 1){
						list.add(i + j);
						t2++;
					}
					if(t2 == p) {
						t2 = 0;
						break;
					}
				}
				t++;
			}
			if(t == p) break;
		}
		Collections.sort(list);
		System.out.println(list.get(p-1));
	}
	
	public void calcSosuu(){
		for(int i = 2; i < 1000000; i++){
			if(sosuu[i] == 0){
				sosuu[i] = 1;
				for(int j = i * 2; j < 1000000; j = j + i){
					sosuu[j] = -1;
				}
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 110040
n=1<<18;L[1<<18],p;F[1<<18],X[1<<18];i;long D[1<<20],Z[1<<20],A[1<<18],x,z;
//long f(a,k,l,r,b){return a<=l&r<i+2?D[k]+(Z[k]+=x):l<=i&a<r?(D[k]=fmax(f(a,2*k,l,b),f(a,2*k+1,b=l+r>>1,r)))+Z[k]:D[k]+Z[k];}
//long f(a,k,l,r,b,q){q=a<=l&r<i+2;return(D[k]=l<=i&a<r&!q?fmax(f(a,2*k,l,b),f(a,2*k+1,b=l+r>>1,r)):D[k])+(Z[k]+=q?x:0);}
long f(a,k,l,r,b){return(Z[k]+=(b=a<=l&r<i+2)?x:0)+(D[k]=l<=i&a<r&!b?fmax(f(a,2*k,l,b),f(a,2*k+1,b=l+r>>1,r)):D[k]);}

main(j){for(gets(L);~scanf("%d%d%ld",L+j,&p,A+j);F[p]=j++)X[j]=F[p];for(;p?:(p=F[++i],f(i,1,0,n),n/i);p=X[p])x=A[p],x=f(L[p],1,0,n);printf("%ld",x);}


Measured memory_bytes: 17152
c={}
for i in range(1,10):
  for j in range(1,10):
    l=str(i)
    r=str(j)
    c[l+r]=0


n=int(input())
for i in range(1,n+1):
  l=str(i)[0]
  r=str(i)[-1]
  try:
    c[l+r]+=1
  except:
    pass
  
      
ans=0
for i in range(1,10):
  for j in range(1,10):
    l=str(i)
    r=str(j)
    ans+=c[l+r]*c[r+l]
    
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int mex=2005;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 

int main()
{
  int a,b;
  cin>>a>>b;
  if(a<b) swap(a,b);
  fo(i,0,a)
  cout<<b;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MOD=1e9+7;
ll dp[1<<21],arr[25][25],lg[1<<21],cnt[1<<21];

bool yee(ll a,ll b)
{
	return cnt[a]<cnt[b];
}

int main()
{jizz
	ll n,L,ans=0;
	cin >> n,L=1<<n,dp[0]=1,cnt[0]=-1;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin >> arr[i][j];
	for(int i=0;i<n;++i)
		lg[1<<i]=i;
	for(int i=1;i<L;++i)
		cnt[i]=cnt[i&i-1]+1;
	for(int i=1;i<L;++i)
		for(int j=i;j;j&=j-1)
			if(arr[cnt[i]][lg[j&-j]])
				dp[i]=(dp[i]+dp[i^j&-j])%MOD;
	cout << dp[L-1] << "\n";
}

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

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t; cin>>s>>t;
    map<char,char> m,rm;
    bool ng = false;
    rep(i,s.size()){
        if (m.count(s[i]) || rm.count(t[i])){
            if (!m.count(s[i])) m[s[i]] = t[i];
            if (!rm.count(t[i])) rm[t[i]] = s[i];
            if (m[s[i]]!=t[i]){
                ng = true;
                break;
            }
            if (rm[t[i]]!=s[i]){
                ng = true;
                break;
            }
        }else{
            m[s[i]] = t[i];
            rm[t[i]] = s[i];
        }
    }
    if (ng){
        cout<<"No\n";
    }else{
        cout<<"Yes\n";
    }
    return 0;
}


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

using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<ll> T(N);
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i) >> A.at(i);
  }
  ll t=1,a=1;
  for (int i = 0; i < N; i++) {
    ll x=(t+T.at(i)-1)/T.at(i);
    ll y=(a+A.at(i)-1)/A.at(i);
    ll M=max(x,y);
    t=M*T.at(i);
    a=M*A.at(i);
  }
  cout << t+a << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(string, s, t);

    int cnt = 0;
    rep(i, 3) {
        cnt += s[i] == t[i];
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int64_t> mins(n);
	vector<int64_t> maxs(n);

	FOR_LT(i, 0, n) {
		int64_t a, b; cin >> a >> b;
		mins[i] = a;
		maxs[i] = b;
	}
	sort(mins.begin(), mins.end());
	sort(maxs.begin(), maxs.end());

	if (n & 1) {
		int64_t minv = mins[n / 2];
		int64_t maxv = maxs[n / 2];
		cout << (maxv - minv) + 1 << endl;
	}
	else {
		int64_t v1 = maxs[n / 2 - 1] - mins[n / 2 - 1];
		int64_t v2 = maxs[n / 2] - mins[n / 2];
		cout << (v1 + v2 + 1) << endl;
	}

	return 0;
}

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

int main() {
  int a, b, ans = 0;
  cin >> a >> b;
  
  if(a >= b){
    ans += a;
    a--;
  }
  else{
    ans += b;
    b--;
  }
  
  if(a >= b){
    ans += a;
    a--;
  }
  else{
    ans += b;
    b--;
  }

  cout << ans << endl;
}


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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    cout << (a < c and c < b ? "Yes" : "No") << ln;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,m;
int p[111111];
int x[111111],y[111111];
int par[111111];
int Rank[111111];
void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		Rank[i]=0;
	}
}
int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);y=find(y);
	if(x==y)return;
	if(Rank[x]<Rank[y])par[x]=y;
	else{
		par[y]=x;
		if(Rank[x]==Rank[y])Rank[x]++;
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}
signed main(){
	cin>>n>>m;
	rep(i,n)cin>>p[i];
	init(n);
	rep(i,m){
		cin>>x[i]>>y[i];
		unite(x[i]-1,y[i]-1);
	}
	int ans=0;
	rep(i,n){
		if(same(p[i]-1,i))ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

const int MAX_N = 1 << 17; //100000ぐらい
class SegmentTree {
public:
    int N; //要素数
    vector<ll> dat;

    SegmentTree(int n_) {
        N = 1;
        while (N < n_) N *= 2;
        dat.assign(2 * N - 1, (1LL << 31) - 1);
    }

    void update(int k, int a) { //k番目(0-indexed)をaに変更
        k += N - 1; //一番下
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2; //1つ上がる
            //更新
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    //[a, b)の値（最小値/和/etc.）を求める
    //kは節点の番号、l, rはその節点が[l,r)に対応づいていることを表す
    //外からはquery(a, b, 0, 0, N)と呼ぶ

    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return (1LL << 31) - 1;
        //[a, b)が[l,r)を完全に含む
        if (a <= l && r <= b) return dat[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    SegmentTree sg(n + 1);

    rep(i, q) {
        ll com, x, y;
        cin >> com >> x >> y;
        if (com == 0) sg.update(x, y);
        else cout << sg.query(x, y + 1, 0, 0, sg.N) << endl;
    }

    return 0;
}


Measured memory_bytes: 4948
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cassert>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e3+1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define FAILNO {printf("NO\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}

int N;

int main() {
#ifdef OJ
	freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
#endif

	int ans = 0;
	int mx = 0;

	scanf("%d", &N);
	while(N--) {
		int h;
		scanf("%d", &h);
		if (h >= mx) ans++;
		mx = max(mx, h);
	}

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

	return 0;
}



Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = null;
        PrintWriter writer = null;
        
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            writer = new PrintWriter(System.out);
            
            int N = Integer.parseInt(br.readLine());
            int[] a = Arrays.asList(br.readLine().split(" ")).stream()
                                                .mapToInt(e -> Integer.parseInt(e))
                                                .toArray();
            
            Arrays.sort(a);
            
            int AliceSum = 0, BobSum = 0;
            Boolean flg = true;
            
            for(int i = a.length - 1; i >= 0; i--){
                if(flg){
                    AliceSum += a[i];
                    flg = false;
                }else{
                    BobSum += a[i];
                    flg = true;
                }
                
            }
            writer.println(AliceSum - BobSum);
            
        }finally{
            if(br != null){
                br.close();
            }
            if(writer != null){
                writer.close();
            }
        }

    }
}

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

int divceil(int a, int b) {
  return (a + b - 1) / b;
}

int main() {
  int k, q;
  cin >> k >> q;
  vector<int> d(k);
  rep (i, k) cin >> d[i];
  rep (qi, q) {
    int n, x, m;
    cin >> n >> x >> m;
    ll last = x, eq = 0;
    rep(i, k) {
      ll num = divceil(n - 1 - i, k);
      last += (d[i] % m) * num;
      if (d[i] % m == 0) eq += num;
    }
    ll ans = (n - 1) - (last / m - x / m) - eq;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_N = 1e5;
vector<int> es[MAX_N];
bool used[MAX_N];

//nowより下の部分木においてnowを根として同様のゲームを行ったときのgrundy数
int grundy(int now){
    used[now] = true;
    int res = 0;
    for(auto &e: es[now]){
        if(!used[e]) res ^= grundy(e)+1;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        es[a].pb(b), es[b].pb(a);
    }
    fill(used, used+N, false);
    if(grundy(0)) cout << "Alice" << endl;
    else cout << "Bob" << endl;
}

Measured memory_bytes: 8960