akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Group{
	void init(){
		child_group.clear();
		child_member.clear();
	}
	char name[16];
	vector<int> child_group;
	vector<int> child_member;
};

struct Member{
	char name[16];
};


int check[1000];
bool visited[100];
Group group[100];
Member member[1000];

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

void recursive(int group_id){
	visited[group_id] = true;

	for(int i = 0; i < group[group_id].child_member.size();i++){
		check[group[group_id].child_member[i]] = 1;
	}

	for(int i = 0; i < group[group_id].child_group.size(); i++){
		if(visited[group[group_id].child_group[i]] == false){
			recursive(group[group_id].child_group[i]);
		}
	}
}


int main(){

	int N,count,group_index,member_index,work_index,calc_index,tmp;
	char data[100][300],work[16];
	bool FLG;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < 1000; i++)check[i] = 0;
		for(int i = 0; i < 100; i++){
			visited[i] = false;
			group[i].init();
		}

		group_index = member_index = 0;

		for(int loop = 0; loop < N; loop++){
			scanf("%s",data[loop]);
			//??°???????????????????????????
			for(work_index = 0;data[loop][work_index] != ':';work_index++){
				work[work_index] = data[loop][work_index];
			}
			work[work_index] = '\0';
			strcpy(group[group_index].name,work);
			group_index++;
		}

		for(int loop = 0; loop < N; loop++){
			for(calc_index = 0; data[loop][calc_index] != ':';calc_index++);
			while(true){
				work_index = 0;
				for(++calc_index;data[loop][calc_index] != ',' && data[loop][calc_index] != '.';calc_index++){
					work[work_index++] = data[loop][calc_index];
				}
				work[work_index] = '\0';

				FLG = false;
				for(int i = 0; i < group_index; i++){
					if(strCmp(group[i].name,work)){
						FLG = true;
						tmp = i;
						break;
					}
				}

				if(FLG){
					group[loop].child_group.push_back(tmp);
				}else{ //??????

					FLG = false;
					for(int i = 0; i < member_index; i++){
						if(strCmp(member[i].name,work)){
							FLG = true;
							tmp = i;
							break;
						}
					}

					if(FLG){
						group[loop].child_member.push_back(tmp);
					}else{
						group[loop].child_member.push_back(member_index);
						strcpy(member[member_index].name,work);
						member_index++;
					}
				}

				if(data[loop][calc_index] == '.')break;
			}
		}

		recursive(0);

		count = 0;
		for(int i = 0; i < 1000; i++)count += check[i];
		printf("%d\n",count);
	}

	return 0;
}

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

void solve(long long N, std::string S){
    int ans = 0;
    for(int i=0; i<N; i++){
        int cnt=0;
        for(char c='a'; c<='z'; c++){
            bool tmp = false;
            for(int j=0; j<i; j++)
                if(S[j] == c){
                    tmp = true;
                    break;
                }
            for(int j=i; j<N; j++)
                if(S[j] == c){
                    if(tmp)cnt++;
                    break;
                }
        }
        if(cnt > ans)ans = cnt;
    }
    cout << ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
                     // I'm in Love with Experience.
void solve()
{
    string s;cin>>s;
    ll N = s.size();
    if(s[N-1]=='s')s.append("es");
    else s.append("s");
    cout<<s<<'\n';
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);solve();exit(0);
}/*Solved By:- Ritik Agarwal*/

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
using namespace std;
#define ll long long
#define inf (999999999)
#define fi first
#define se second
#define MOD 1e9+7
#define PI acos(-1.0)
//--------------------------------------------------------------------------------------------------//
int main() {
	int a, b; 
	cin>> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    int x, y;
    cin >> x >> y;

    int ans = 0;
    if (abs(x) < abs(y)) {
        ans += abs(y) - abs(x);
        if ((x >= 0 && y < 0) || (x < 0 && y > 0)) ans++;
        else if (x < 0 && y < 0) ans += 2;
    } else if (abs(x) > abs(y)) {
        ans = abs(x) - abs(y);
        if (x < 0 && y > 0 || (x > 0 && y <= 0)) ans++;
        else if (x > 0 && y > 0) ans += 2;
    } else if (x != y) ans = 1;
    cout << ans << endl;
    return 0;
}

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

int main()
{
    ll N, R;
    scanf("%ld %ld", &N, &R);

    if(N<10) {
        R=R+100*(10-N);
    };

    cout << R << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
long long k,a,b,c,e;
double d,ans,pi,g;
int main() {
           cin>>a>>b>>c>>d;
           e=d*6;
           g=30*c+d/2;
           d=abs(g-e);
           if(d>180) d=360-d;
           pi=3.141592653589793238;
           d=((d*pi)/180);
           ans=sqrt(a*a+b*b-2*a*b*cos(d));
           cout<<setprecision(19)<<ans;
}

Measured memory_bytes: 4232
n = int(input())

a = list(map(int, input().split()))


odd = []
even2 = []
even4 = []

for i in a:
  if i % 4 == 0:
    even4.append(i)
  elif i % 2 == 0:
    even2.append(i)
  else:
    odd.append(i)
    
    

if len(odd) <= len(even4):
  print("Yes")
elif len(odd) == len(even4) + 1:
  if len(even2) == 0:
    print("Yes")
  else:
    print("No")
else:
  print("No")
  

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repm(i,m,n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  
  vi p(n);
  rep(i,n) cin >> p.at(i);
  
  int ans = 0;
  rep1(i,n-2) {
    if (p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)) ans++;
    else if(p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1)) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int hi = A.reduce!max + 2;
    int lo = A.reduce!min - 2;
    long seg = (1L * N * (N - 1) / 2 + N);
    seg = (seg - 1) / 2 + 1;

    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        auto st = new SegmentTree(N*3, N);
        auto B = A.map!(a => a >= mid ? 1 : -1).array;
        int offset = 0;
        long ans = 0;
        foreach (i; 0..N) {
            offset += B[i];
            st.add(B[i] - offset, 1);
            ans += st.sum(-offset, N);
        }
        (ans >= seg ? lo : hi) = mid;
    }

    lo.writeln;
}


class SegmentTree {
    long[] table;
    int size;
    int hoge;

    this(int n, int hoge) {
        assert(bsr(n) < 29);
        size = 1 << (bsr(n) + 2);
        table = new long[](size);
        this.hoge = hoge;
    }

    void add(int pos, long num) {
        pos += hoge;
        return add(pos, num, 0, 0, size/2-1);
    }

    void add(int pos, long num, int i, int left, int right) {
        table[i] += num;
        if (left == right)
            return;
        auto mid = (left + right) / 2;
        if (pos <= mid)
            add(pos, num, i*2+1, left, mid);
        else
            add(pos, num, i*2+2, mid+1, right);
    }

    long sum(int pl, int pr) {
        pl += hoge;
        pr += hoge;
        return sum(pl, pr, 0, 0, size/2-1);
    }

    long sum(int pl, int pr, int i, int left, int right) {
        if (pl > right || pr < left)
            return 0;
        else if (pl <= left && right <= pr)
            return table[i];
        else
            return
                sum(pl, pr, i*2+1, left, (left+right)/2) +
                sum(pl, pr, i*2+2, (left+right)/2+1, right);
    }
}


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

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

    int counter = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == t[i])
        {
            counter += 1;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  ll ans = 0;
  ll sum = 10;
  if(N%2==0){
    ll i=1;
    while(N>=pow(5,i)*2){
      ans += N/sum;
      sum *= 5;
      i++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3504
// In the Name of God

#include <bits/stdc++.h>

using namespace std;

#define	ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound

const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;

map<pair<string, int>, int> m;
int n;
string s;
ll ans;

int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif
	                                            	
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
    
    cin >> n;
    cin >> s;

	rep(mask, 0, (1 << n) - 1) {
		string t = "";
		rep(i, 0, n - 1)
			if (mask & (1 << i))
				t += s[i];			
		per(i, n - 1, 0)
			if (!(mask & (1 << i)))
				t += s[i];
		++m[mp(t, bpc(mask))];
	}
	rep(mask, 0, (1 << n) - 1) {
		string t = "";
		per(i, n - 1, 0)
			if (mask & (1 << i))
				t += s[i + n];
		rep(i, 0, n - 1)
			if (!(mask & (1 << i)))
				t += s[i + n];
		ans += m[mp(t, bpc(mask))];
//		cerr << t << ' ' << mask << ' ' << m[mp(t, bpc(mask))] << "\n";
	}

	cout << ans;
	#ifdef Madi
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
	return 0;
}

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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    vector<int> cnt(n,0);
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int k=min(j-i,abs(i-x)+1+abs(j-y));
            cnt[k]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<cnt[i]<<endl;
    }
    return 0;
}

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

bool rec[10];

bool check(int num)
{
    while(num)
    {
        if(rec[num%10]) return false;
        num /= 10;
    }
    return true;
}

int main()
{
    int n,k,num;
    cin >> n >> k;
    for(int i = 0; i < k; ++i)
    {
        cin >> num;
        rec[num] = true;
    }

    while(true)
    {
        if(check(n))
        {
            cout << n << endl;
            break;
        }
        ++n;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    int64_t ans = 0;
    vector<int> L(N), R(N);
    for(int i = 0; i < N; ++i){
        cin >> L[i] >> R[i];
    }

    sort(L.begin(), L.end());
    sort(R.begin(), R.end());

    int64_t now = 0;
    for(int i = 0; i * 2 < N; ++i){
        now += 2 * L[N-i-1];
        ans = max(ans, now);
        if(i * 2 + 1 >= N) break;
        now -= 2 * R[i];
        ans = max(ans, now);
    }
    now = 0;
    for(int i = 0; i < N/2; ++i){
        now -= 2 * R[i];
        ans = max(ans, now);
        if(i * 2 + 1 >= N) break;
        now += 2 * L[N-i-1];
        ans = max(ans, now);
    }
    
    cout << ans << endl;
}

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

class PaizaSample
{

    static void Main()
    {
        
        string[] abc = Console.ReadLine().Split(' ');
        int a = int.Parse(abc[0]);
        int b = int.Parse(abc[1]);
        int c = int.Parse(abc[2]);

        bool flag = true;
        int sum = 0;


        while (true)
        {
            if(flag){ //??????????????¨???
                if (sum % 60 <= c && sum % 60 + a >= c)
                {
                    sum = sum - sum % 60 + c; 
                    break;
                }
                else
                {
                    sum += a;
                }
                flag = false;

            }else{ //???????????¨???
                sum += b;
                flag = true;
            }

           // Console.WriteLine(sum);

            if (sum % 60 == 0 && sum > 0 && flag) //?????°????????¨???
            {
                sum = -1;
                break;
            }
        }

        Console.WriteLine(sum);

        //Console.ReadKey();

    }
}

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

int main() {
    int N;
    cin >> N;
    int number = 0;
    for (int i = 0; i < N; i++) {
        int start;
        int end;
        cin >> start >> end;
        number += end - start + 1;
    }
    cout << number << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

if sum(a) < x:
    print(N - 1)

elif sum(a) > x:
    ans = 0
    ans_ = 0
    for a in a:
        ans_ += a
        if ans_ > x:
            break
        ans += 1
    print(ans)

elif sum(a) == x:
    print(N)


Measured memory_bytes: 9184
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[]){

  string S;
  cin >> S;

  if(S[1] == S[2]){
    if(S[1] == S[0] || S[1] == S[3]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


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


int main(){
int N,D;
cin >> N>> D;
int ten[20][20];
for(int i =0;i<N;i++){
    for(int j =0;j<D;j++){
    cin>>ten[i][j];
    }
    }
    int ans = 0;
    for(int i = 0;i<N;i++){
        for(int j = i+1;j<N;j++){
            int norm = 0;
            for(int k = 0; k<D;k++){
int diff = abs(ten[i][k]-ten[j][k]);
norm += diff*diff;
            }
for(int k = 0;k<=norm; k++){
    if(k*k == norm)ans++;
        }
    }

}
cout<<ans<<endl;
}

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

using namespace std;
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;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

template<typename T>
T gcd(T a, T b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll g = gcd<ll>(a, b);
  ll ans = 1;
  for(ll i = 2; i * i <= g; ++i) {
    if(g == 1) break;
    if(g % i == 0) {
      ans++;
      while(g % i == 0) {
      g /= i;
      }
    }
  }
  if(g > 1) ans++;
  out(ans);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define ll long long
#define P pair<int,int>
#define MP(a,b) make_pair(a,b)
using namespace std;
bool vis[200005];
int n,m,dis[200005],head,tail,t,h[200005];
priority_queue<P> q;
set<int> in[200005];
struct E{int v,c,next;}g[400005];
void ins(int u,int v,int c){g[++t].v=v,g[t].c=c,g[t].next=h[u],h[u]=t;}
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	memset(dis,0x3f,sizeof dis);
	n=read(),m=read();
	for(int i=1;i<=m;++i){
		int u,v,c;
		u=read(),v=read(),c=read();
		ins(u,v,c); ins(v,u,c);
	}
	q.push(MP(0,1)); dis[1]=0;
	while(!q.empty()){
		int u=q.top().second,cost=-q.top().first;
		q.pop();
		vis[u]=1;
		if(cost>dis[u]) continue;
		for(int j=h[u];j;j=g[j].next){
			if(vis[g[j].v]) continue;
			int v=g[j].v,c=g[j].c,d=dis[u]+(!in[u].count(c));
			if(d>dis[v]) continue;
			if(d<dis[v]){
				q.push(MP(-d,v));
				dis[v]=d;
				in[v].clear();
			}
			in[v].insert(c);
		}
	}
	printf("%d",dis[n]==1061109567?-1:dis[n]);
}

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

using namespace std;
vector<int>v;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=max(a,b);i++){
		if(a%i==0&&b%i==0)v.push_back(i);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	cout<<v[c-1];
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

ll msb(ll v){
  v = v | (v >>  1);
  v = v | (v >>  2);
  v = v | (v >>  4);
  v = v | (v >>  8);
  v = v | (v >> 16);
  v = v | (v >> 32);
  return v ^ (v >> 1);
}

vector<ll> elimination_F2(vector<ll> &A){
    vector<ll> V;
    for(ll a: A){
        for(ll v: V){
            if(msb(v)&a) a ^= v;
        }
        if(a>0){
            for(ll& v: V){
                if(msb(a)&v) v ^= a;
            }
            V.push_back(a);
            sort(V.rbegin(), V.rend());
        }
    }
    return V;
} 

void solve(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    string S;
    cin >> S;


    vector<ll> V;
    for(int i=N-1;i>=0;i--){
        if(S[i]=='0'){
            ll a = A[i];
            for(ll v: V){
                if(msb(v)&a) a ^= v;
            }
            if(a>0){
                for(ll& v: V){
                    if(msb(a)&v) v ^= a;
                }
                V.push_back(a);
                sort(V.rbegin(), V.rend());
            }
        }else{
            ll a = A[i];
            for(ll v: V){
                if(msb(v)&a) a ^= v;
            }
            if(a!=0){
                cout << 1 << endl;
                return;
            }
        }
    }
    cout << 0 << endl;
    return;
}

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

    ll T;
    cin >> T;
    while(T--) solve();

    return 0;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  vector<int> x(5); for(int i=0;i<5;i++) { cin >> x[i]; }
  for(int i=0;i<5;i++) {
    if(x[i] == 0) {
      cout << i+1 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
class SLE{
public:
  void comp(int a,int b){
    if(a==b)cout<<"a == b"<<endl;
    else if(a<b)cout<<"a < b"<<endl;
    else cout<<"a > b"<<endl;
  }
};
int main(){
  int a,b;
  cin>>a>>b;
  SLE sle;
  sle.comp(a,b);
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n, c;
	vector<vector<int>> d(40, vector<int>(40, 0)), e(510, vector<int>(510, 0));
	cin >> n >> c;
	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++) {
			cin >> d[i][j];
		}
	}
	vector<int> amari0(31, 0), amari1(31, 0), amari2(31, 0);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> e[i][j];
			if ((i + j) % 3 == 0) amari0[e[i][j]]++;
			if ((i + j) % 3 == 1) amari1[e[i][j]]++;
			if ((i + j) % 3 == 2) amari2[e[i][j]]++;
		}
	}

	int ans = 0, MIN = INF;
	for (int x = 1; x <= c; x++) {
		for (int y = 1; y <= c; y++) {
			for (int z = 1; z <= c; z++) {
				if (x == y || y == z || z == x) continue;

				for (int i = 1; i <= c; i++) {
					ans += amari0[i] * d[i][x];
				}
				for (int i = 1; i <= c; i++) {
					ans += amari1[i] * d[i][y];
				}
				for (int i = 1; i <= c; i++) {
					ans += amari2[i] * d[i][z];
				}

				MIN = min(MIN, ans);
				ans = 0;
			}
		}
	}
	cout << MIN << endl;
}

Measured memory_bytes: 1280
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        string s = Console.ReadLine();
        Stack<Tuple<long, int>> ponds = new Stack<Tuple<long, int>>();
        Stack<int> stack = new Stack<int>();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '\\')
            {
                stack.Push(i);
            }
            if (s[i] == '/')
            {
                if (stack.Count == 0) continue;
                var start = stack.Pop();
                long size = i - start;
                while (ponds.Count != 0 && start < ponds.Peek().Item2)
                    size += ponds.Pop().Item1;
                ponds.Push(new Tuple<long, int>(size, start));
            }
        }

        Console.WriteLine(ponds.Sum(x => x.Item1));
        Console.WriteLine(string.Join(" ", new long[] { ponds.Count }.Concat(ponds.Select(x => x.Item1).Reverse())));
    }
}


Measured memory_bytes: 20692
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll n,a,b;
    cin >> n >> a >> b;
    ll num[3] = {};
    for (ll i=0;i<n;i++){
        ll p;
        cin >> p;
        if(p <= a){
            num[0]++;
        }else if(a<p and p<=b){
            num[1]++;
        }else{
            num[2]++;
        }
    }
    cout << min(num[0], min(num[1], num[2])) << endl;


}




Measured memory_bytes: 256
#include<bits/stdc++.h>
            //#include<ext/pb_ds/assoc_container.hpp>
            //#include<ext/pb_ds/tree_policy.hpp>
          //  using namespace __gnu_pbds;
            using namespace std;
            # define ll long long
            # define int long long  //comment it out when MLE
            # define endl "\n"
           // template <typename T>
            //using ordered_set = tree<T, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

            #define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
            //# define m 163577857
            # define mo 1000000007
            # define pi acos(-1)
           # define fi first
            # define se second
            # define pb push_back
            # define pii pair<int,int>
            #define REP(i,n) for (int i = 1; i <= n; i++)
            const ll mod =  1e9+7;
            //const int K = 2;
            //typedef vector<vector<int> > matrix;
/*
          int add(int a, int b,int mod) {
                a%=mod;
                b%=mod;
                a += b;
                if (a >= mod) a -= mod;
                if(a<0)
                {
                    a += mod;
                    a %= mod;
                }
                return a;
            }

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


            ll fact[200003];
            ll inv[200003];

            void fact0()
            {
                int i,j;
                fact[0]=1;
                for(i=1;i<=200000;i++)
                {
                    fact[i]=i*fact[i-1]%mod;
                }
                inv[0]=1;
                inv[1]=1;
                ll p=mod;
                for (i=2; i<=200000; i++)
                    inv[i] = (p - (p/i) * inv[p%i] % p) % p;

                for(i=2;i<=200000;i++)
                {
                    inv[i]*=inv[i-1];
                    inv[i]%=mod;
                }
            }
            int help(int a,int b)
            {
               // cout<<a<<" "<<b<<endl;
                int an = fact[a];
                //cout<<an<<endl;
                an *= inv[b];
                an %= mod;
                an *= inv[a-b];
                an %= mod;
                return an;
            }
/*
          void random()
            {
              srand(time(0));
            for (int i = 0; i < n; i ++)
                perm[i] = i + 1;
            random_shuffle(perm, perm + n);
            }
int ncr(int a,int b)
{
    int tt = fact[a];
    tt %= mod;
    tt *= inv[a-b];
    tt %= mod;
    tt *= inv[b];
    tt %= mod;
    return tt;
}
*/

signed main() {
	gok


	int x;
	cin>>x;
	if(x>=30)
        cout<<"Yes";
    else
        cout<<"No";






























  return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}
const string YES = "Yes";
const string NO = "No";
void solve(std::string S){
    string R = S;
    int N = S.length();
    reverse(ALL(R));
    if(R==S){
        string a = S.substr(0, (N-1)/2);
        string b = R.substr(0, (N-1)/2);
        string ar = a; string br = b;
        reverse(ALL(ar));reverse(ALL(br));
        if(a == ar && b == br){
            cout<<YES<<endl;return;
        }
    }
    cout<<NO<<endl;
}
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import math
def yo(a,b,th):
    thr = math.radians(th)
    cosa = math.cos(thr)
    tmp = float(a**2) + float(b**2) - float(2*b*a*cosa)
    re = float(math.sqrt(tmp))
    return re
A,B,h,m = map(int, input().split())
longdig = m * 6
shortdig = (h*60+m) * 0.5
theta = abs(longdig - shortdig)
print(yo(A,B,theta))

Measured memory_bytes: 9524
import java.util.*;

public class Main {

      public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = scanner.nextInt();
        }

        int[] dp = new int[h.length];
        dp[0] = 0;

        for (int i = 1; i < h.length; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = k; j > 0; j--) {
                int x = i - j;
                if (x >= 0) {
                    int vi = Math.abs(h[i] - h[x]) + dp[x];
                    min = Math.min(vi, min);
                }
            }
            dp[i] = min;
        }

        System.out.println(dp[dp.length - 1]);
    }

}

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

int main() {
  int N, B, E, foo, bar, A = 0; cin >> N;
  string S;
  int size;
  
  vector<vector<int>> vec(10, vector<int>(10, 0));
  
  for (int i = 0; i <= N; i++) {
    S = to_string(i);
    size = S.size();
    B = S[0] - '0';
    E = S[size - 1] - '0';
    if (B == 0 || E == 0) continue;
    vec.at(B).at(E)++;
  }
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      foo = vec.at(i).at(j);
      bar = vec.at(j).at(i);
      A += foo * bar;
    }
  }
  cout << A << endl;
}


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

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

struct Dice
{
    int top;
    int bottom;
    int left;
    int right;
    int front;
    int back;
};

Dice rotate(Dice self, char command)
{
    int pre_top = self.top;
    switch (command)
    {
    case 'N':
        self.top = self.front;
        self.front = self.bottom;
        self.bottom = self.back;
        self.back = pre_top;
        break;
    case 'E':
        self.top = self.left;
        self.left = self.bottom;
        self.bottom = self.right;
        self.right = pre_top;
        break;
    case 'W':
        self.top = self.right;
        self.right = self.bottom;
        self.bottom = self.left;
        self.left = pre_top;
        break;
    case 'S':
        self.top = self.back;
        self.back = self.bottom;
        self.bottom = self.front;
        self.front = pre_top;
        break;
    case 'R':
        int pre_front = self.front;
        self.front = self.left;
        self.left = self.back;
        self.back = self.right;
        self.right = pre_front;
        break;
    }
    return self;
}

int main()
{
    int nums[6];

    rep(i, sizeof(nums) / sizeof(int))
    {
        cin >> nums[i];
    }

    Dice dice_x;
    dice_x.top = nums[0];
    dice_x.front = nums[1];
    dice_x.right = nums[2];
    dice_x.left = nums[3];
    dice_x.back = nums[4];
    dice_x.bottom = nums[5];

    int q;
    cin >> q;
    rep(i, q)
    {
        int top, front;
        cin >> top >> front;

        rep(j, 6)
        {
            if (top == dice_x.top)
            {
                break;
            }
            dice_x = rotate(dice_x, 'S');
        }
        rep(j, 6)
        {
            if (top == dice_x.top)
            {
                break;
            }
            dice_x = rotate(dice_x, 'E');
        }
        while (front != dice_x.front)
        {
            dice_x = rotate(dice_x, 'R');
        }
        cout << dice_x.right << endl;
    }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define gcd __gcd
#define x first
#define y second
#define st first
#define nd second
#define pb push_back

using namespace std;

template<typename T> ostream& operator<<(ostream &out, const vector<T> &v){ out << "{"; for(const T &a : v) out << a << ", "; out << "}"; return out; }
template<typename S, typename T> ostream& operator<<(ostream &out, const pair<S,T> &p){ out << "(" << p.st << ", " << p.nd << ")"; return out; }

typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef vector<int> VI;

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

long long n;
long long sum, ps, vv;
long long A[100010];
long long P[100010];

bool solve(){
	FWD(i,0,n) sum += A[i];
	if(sum % (n*(n+1)/2)) return 0;
	sum /= (n*(n+1)/2);
	FWD(i,0,n){
		P[i] = sum - (A[(i+1)%n] - A[i]);
		if(P[i] % n) return 0;
		P[i] /= n;
		if(P[i] < 0) return 0;
		ps += P[i];
		vv += (n-i)*P[i];
	}
	FWD(i,0,n){
		if(vv != A[i]) return 0;
		vv += ps - n*P[i];
	}
	return 1;
}

int main(){
	scanf("%lld", &n);
	FWD(i,0,n) scanf("%lld", &A[i]);
	printf(solve()?"YES\n":"NO\n");;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
  char a;
  scanf("%c",&a);
  
  if('A' <= a && a <= 'Z')
    printf("%c\n",'A');
  else if('a' <= a && a <= 'z')
    printf("%c\n",'a');
  
  return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int A,B;
  cin >>A>>B;
  int ans=max(A+B,A-B);
  ans=max(ans,A*B);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.par=[i for i in range(n)]
        self.size=[1]*n
    def find(self,x):
        if x==self.par[x]:
            return self.par[x]
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.size[x]>self.size[y]:
            self.size[x]+=self.size[y]
            self.par[y]=x
        else:
            self.size[y]+=self.size[x]
            self.par[x]=y

import sys
input=sys.stdin.buffer.readline
n=int(input())

x_list=[]
y_list=[]

for i in range(n):
    x,y=map(int,input().split())
    x_list.append((x,i))
    y_list.append((y,i))
x_list.sort()
y_list.sort()
edges=[]

for i in range(1,n):
    edges.append((x_list[i][0]-x_list[i-1][0],x_list[i][1],x_list[i-1][1]))

    edges.append((y_list[i][0]-y_list[i-1][0],y_list[i][1],y_list[i-1][1]))

edges.sort()
uf=UnionFind(n)
ans=0
for e in edges:
    wt=e[0]
    x=e[1]
    y=e[2]
    if uf.find(x)==uf.find(y):
        continue
    ans+=wt
    uf.unite(x,y)
print(ans)



Measured memory_bytes: 55600
main(){double x,y,X,Y,A,B,t;for(;~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x,&y,&X,&Y,&A,&B);){A-=x,B-=y,t=atan2(Y-y,X-x)*2;printf("%f %f\n",A*cos(t)+B*sin(t)+x,A*sin(t)-B*cos(t)+y);}exit(0);}

Measured memory_bytes: 708
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            ans+=a[i]*a[j];
        }
    }
    cout<<ans<<'\n';

}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

int main() {
  ll N, M; cin >> N >> M;
  if(N * 2 == M) {
    cout << N << endl;
  } else if(N * 2 > M) {
    cout << M / 2 << endl;
  } else if(N * 2 < M) {
    ll ans = N;
    ans += (M - 2 * N) / 4;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import sys
import math
from operator import mul
from functools import reduce
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

x,y= (int(_) for _ in input().split()) 
if (x+y)%3!=0:
    print(0)
    sys.exit()
else:
    n=(x+y)/3
    n=int(n)
    if x<n or y<n:
         print(0)
         sys.exit()
    else:
        x=x-n
        y=y-n
        ans=int(cmb(x+y, x,mod))
        print(ans%1000000007)

Measured memory_bytes: 122720
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(a[a[i]] == i){
            ans++;
        }
    }
    cout << ans / 2;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

int n, d[103], x, ct = 0;

bool twei(int k){
	int lb = -1; int ub = n;
	while (ub - lb > 1){
		ct++;
		int mid = (lb + ub) / 2;
		if (d[mid] == k) return 1;
		else if (d[mid] > k) ub = mid;
		else lb = mid;
	}
	return 0;
}

int main(){
	while (true){
		cin >> n;
		if (!n) break;
		REP(i, n)
			cin >> d[i];
		cin >> x;
		twei(x);
		cout << ct << endl;
		x = ct = 0;
	}
}

Measured memory_bytes: 1160
r=lambda x:x if u[x]<0else r(u[x])
n,m,*t=map(int,open(0).read().split())
u=[-1]*-~n
for x,y in zip(t[::3],t[1::3]):
 x,y=sorted((r(x),r(y)))
 if x!=y:u[x]+=u[y];u[y]=x
print(sum(i<0for i in u)-1)

Measured memory_bytes: 32180
<?php
list($k) = ints();
$a = ints();
$maxn = $minn = 2;
for ($i = $k - 1; $i >= 0; --$i) {
    if (intdiv($maxn, $a[$i]) === intdiv($minn - 1, $a[$i])) exit('-1');
    $maxn = intdiv($maxn, $a[$i]) * $a[$i] + ($a[$i] - 1);
    $minn = (intdiv($minn, $a[$i]) + min(1, $minn % $a[$i])) * $a[$i];
}
echo $minn . ' ' . $maxn;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 27244
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) n
    allocate(x(n),y(n))
    do i=1,n
        read(*,*)x(i),y(i)
    end do
    call m2sort(y,x)
    a=0
    do i=1,n
        a=a+x(i)
        if(a>y(i))then
            write(*,*)'No'
            stop
        end if
    end do
    write(*,*)'Yes'

   
    stop
    contains
    recursive subroutine m2sort(x,y)
    implicit none
    integer(8), intent(inout) :: x(:),y(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:),tmp2(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call m2sort(x(:mid),y(:mid))
    call m2sort(x(mid+1:),y(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n),tmp2(n))
    tmp(:) = x(:)
    tmp2(:)=y(:)
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
      tmp2(k) = y(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        y(k)=tmp2(i)
        i = i + 1
      else
        x(k) = tmp(j)
        y(k)=tmp2(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp,tmp2)
    return
  end subroutine m2sort
end program sample
  



Measured memory_bytes: 8768
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    string A,B,C;
    cin>>A>>B>>C;
    if(A.substr((A.length())-1,1)==B.substr(0,1)&&B.substr((B.length())-1,1)==C.substr(0,1)){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
a = gets.chomp.split("").map(&:to_s)
ans = []
ewr = []
ans[0] = a[0]
ans[1] = a[1]
ewr[0] = a[2]
ewr[1] = a[3]
yy = ans.join.to_i
mm = ewr.join.to_i


if mm >= 1 && mm <= 12 && yy >= 1 && yy <= 12
puts "AMBIGUOUS"
elsif mm >= 1 && mm <= 12
puts "YYMM"
elsif yy >= 1 && yy <= 12
puts "MMYY"
else
puts "NA"
end

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

using namespace std;

int main() {
    long long N, K;

    cin >> N >> K;

    if(N > K) {
        N = N % K + K;
    }

    while(abs(N - K) < N) {
        N = abs(N - K);
    }

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int maxn=1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const LL LLINF=1e14;
const double pi=acos(-1.0);


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;cin>>a>>b;
    int ans=0;
    for(int i=1;i<=12;i++) {
        if(i<a||(i==a&&i<=b)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = (list(map(int, input().split())))

print(' '.join(list(map(str, a))))
for i in range(1, n):
    key = a[i]
    j = i - 1
    while j >= 0 and a[j] > key:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = key
    print(' '.join(list(map(str, a))))


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

using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	
	int cnt = 0, length = a.length();
	
	for(int i = 0; i < length; i++) {
		if(a[i] != b[i]) cnt++;
	}
	
	cout << cnt;
}


Measured memory_bytes: 3828