akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000
int N;
int M;
vector<int> K;
//int KK[MAX_N*MAX_N];
// int K[MAX_N];
int L;
int ans;
bool bool_ans;

char a,b;
int an,bn;

char S[4];

int main (void)
{
  cin >> S;

  a = S[0];
  rep(i,0,4) {
    if (S[i] == a) {
      an++;
    }
  }
  if (an != 2) {
    cout << "No" << endl;
    return 0;
  }

  rep(i,1,4) {
    if (S[i] != a) {
      b = S[i];
      break;
    }
  }

  rep(i,0,4) {
    if (S[i] == b) {
      bn++;
    }
  }
  if (bn != 2 ) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t,custo,tempo,min=1001;

	scanf("%d %d",&n,&t);

	while(n--){
		scanf("%d %d",&custo,&tempo);
		if(tempo<=t){
			if(min>custo){
				min = custo;
			}
		}
	} 
	if(min>1000)
		printf("TLE");
	else
		printf("%d",min);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int K, X;
  cin >> K >> X;
  if (500 * K >= X)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
bool a[1000000010];
long long n,m;
int main(){
	double n,m,v;
	cin>>n>>m>>v;
	if(v>(n*n*m)/2){
		printf("%.10f",90.0-atan((n*n*n)/(2*((n*n*m)-v)))*180.0/3.1415926535);
	}else {
		printf("%.10f\n",90.0-atan((2.0*v)/(n*m*m))*180.0/3.1415926535);
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> cnt;
    rep(i, n) cnt[a[i]]++;
    ll q;
    cin >> q;
    ll sum = accumulate(all(a), 0LL);
    rep(i, q) {
        ll b, c;
        cin >> b >> c;
        sum -= cnt[b] * b;
        sum += cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 10120
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  gs <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
  showAdjMatrix $ solve gs

solve :: [[Int]] -> [[Int]]
solve gs = innerSolve gs $ length gs
  where
    innerSolve :: [[Int]] -> Int -> [[Int]]
    innerSolve [] _ = []
    innerSolve (x:xs) n = (makeRow x n) : (innerSolve xs n)

    makeRow :: [Int] -> Int -> [Int]
    makeRow (u:k:vs) n = [if x `elem` vs then 1 else 0 | x <- [1..n]]

showAdjMatrix :: [[Int]] -> IO ()
showAdjMatrix [] = return ()
showAdjMatrix (m:ms) = do
  putStrLn $ unwords . map show $ m
  showAdjMatrix ms



Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;

int N;

int main() {
    cin >> N;
    vector<int> A(N);
    int d = 1e9;
    int j = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (d > A[i]) {
            d = A[i];
            j = i;
        }
    }
    bool flag = true;
    while (flag) {
        flag = false;
        for (int i = 0; i < N; i++) {
            if (i != j) {
                A[i] %= d;
                if (A[i] > 0) {
                    d = A[i];
                    j = i;
                    flag = true;
                    break;
                }
            }
        }
    }
    cout << d << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC094A
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = line1[0];
            int B = line1[1];
            int X = line1[2];

            if (X >= A && X <= A + B)
            {
                Console.WriteLine("YES");
            }
            else Console.WriteLine("NO");

            Console.ReadLine();
        }
    }
}


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



int main() {
  ll a,b;
  cin >> a>> b;
  if(a<b){swap(a,b);}
  if((a+b)%2==0){cout << (a+b)/2 << endl;}else{cout << "IMPOSSIBLE" << endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main()
{
    int c1x = 0, c1y = 0, c1r = 0, c2x = 0, c2y = 0, c2r = 0;
    double d = 0;
 
    cin >> c1x >> c1y >> c1r >> c2x >> c2y >> c2r;
 
    d = sqrt(pow(c1x - c2x, 2) + pow(c1y - c2y, 2));
 
    if (d > c1r + c2r)
        cout << 4 << endl;
    else if (d == c1r + c2r)
        cout << 3 << endl;
    else if (d > abs(c1r - c2r) && d < c1r + c2r)
        cout << 2 << endl;
    else if (d == abs(c1r - c2r))
        cout << 1 << endl;
    else
        cout << 0 << endl;
 
    return 0;
}


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

int main()
{
	long long n, k;
	cin >> n >> k;

	long long l(0), r(0);
	long long count = 0;
	while (count != k) {
		l += 0 + count;
		r += n - count;
		++count;
	}

	long long ret = 0;
	for (long long i = k; i <= n + 1; ++i) {
		ret = (ret + r - l + 1) % 1000000007;
		l += i;
		r += n - i;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3608
s=input()
if int(s[0]+s[1])>12 or int(s[0]+s[1])==0:
  a=0
else:
  a=1
if int(s[2]+s[3])>12 or int(s[2]+s[3])==0:
  b=0
else:
  b=1
if a==1 and b==1:
  print("AMBIGUOUS")
elif a==1:
  print("MMYY")
elif b==1:
  print("YYMM")
else:
  print("NA")

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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;
int n,a[N];

inline int calc_status() {
	int c1=0, c2=0;
	for(int i=1;i<=n;i++)
		(a[i]&1) ? ++c1 : ++c2;
	if(c2&1) return 1;
	else if(c1>=2) return 0;
	else {
		int g=0;
		for(int i=1;i<=n;i++) {
			if(a[i]&1) {
				if(a[i]==1) return 0;
				else --a[i];
			}
			g=__gcd(a[i],g);
		}
		for(int i=1;i<=n;i++) a[i]/=g;
		return calc_status() ? 0 : 1;
	}
}
int main() {
	n=rd();
	if(n==1) {puts("Second"); return 0;}
	for(int i=1;i<=n;i++) a[i]=rd();
	if(calc_status()==1) puts("First");
	else puts("Second");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repx(i,a,b,x) for(ll i=a;i<b;i+=x)
#define rev(i,a,b) for(ll i=a;i>b;i--)
#define revx(i,a,b,x) for(ll i=a;i>b;i-=x)
#define arep(it,v) for(auto it=v.begin();it!=v.end();it++)
#define wh1(n) rep(xy1,0,n)
#define wh2(n) rep(xy2,0,n)
#define wh3(n) rep(xy3,0,n)
#define sc(i) cin>>i
#define ssc(i,j) sc(i);sc(j)
#define sssc(i,j,k) ssc(i,j);sc(k)
#define pf(i) cout<<i<<" "
#define pfn(i) cout<<i<<endl
#define cvec(v,n) rep(abc,0,n){ll xyz;sc(xyz);v.pb(xyz);}
#define pvec(v,n) rep(abc,0,n){pf(v[abc].F);pf(v[abc].S);}pfn("")
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define spll set<pll>
#define vpll vector<pll>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define pq(a) priority_queue<a>
#define pqc(a,cmp) priority_queue<a,vector<a>,cmp>
#define F first
#define S second
#define B begin
#define E end
#define R return
#define mp make_pair
#define pb push_back
#define ln length()
#define to_s to_string
#define Sort(v) sort(v.begin(),v.end())
#define Scmp(v,cmp) sort(v.begin(),v.end(),cmp)
#define zero_arr(v) memset(v,0,sizeof(v))
#define update_map(m,i) if(m.find(i)!=m.end()){m[i]++;}else{m[i]=1;}
#define update_mapx(m,i,x) if(m.find(i)!=m.end()){m[i]+=x;}else{m[i]=x;}
#define M 1000000007
#define INF 2000000000
#define fast ios::sync_with_stdio(0); cin.tie(0)
int main(){
    fast;
    ll n;
    sc(n);
    vll v;
    cvec(v,n);
    Sort(v);
    pfn(v[n-1]-v[0]);
    R 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int n;
constexpr i64 mod = 1000000007;
std::vector<std::deque<int>> g;
std::vector<std::vector<i64>> dp;

void dfs(int v, int p) {
    dp[v][0] = 1;
    dp[v][1] = 1;
    for (auto ch : g[v]) {
        if (ch == p) continue;
        dfs(ch, v);
        dp[v][0] = (dp[ch][0] + dp[ch][1]) % mod * dp[v][0] % mod;
        dp[v][1] = dp[ch][0] * dp[v][1] % mod;
    }
}

int main() {
    std::cin >> n;
    g.resize(n);
    dp.resize(n);
    for (int i = 0; i < n; i++) dp[i].resize(2);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        std::cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(0, -1);
    std::cout << (dp[0][0] + dp[0][1]) % mod << std::endl;

    return 0;
}

Measured memory_bytes: 81280
INT_MAX=10**19+7
MOD=10**12+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
s=input()
t=input()
l=len(s)
if s==t[0:l]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61764
#include<cstdio>
using namespace std;
double dp[3000][3000]={},p,ans=0.0;
int main(){
    
    int n;
    scanf("%d",&n);
    dp[0][0]=1.0;
    for(int i=0;i<n;i++){
        scanf("%lf",&p);
        dp[i+1][0]=dp[i][0]*(1-p);
        for(int j=1;j<=n;j++){
            dp[i+1][j]=dp[i][j]*(1-p)+dp[i][j-1]*p;
        }
    }
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
    }
    printf("%.10f\n",ans);
}

Measured memory_bytes: 70400
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e6 + 10 ;
const ll INF = 1e18 + 10 ;
int n ;
int dp[N][2][2] ;
int dfs(int x, int a, int b){
    if ( x == n ) {
        if ( a == 1 && b == 1 ) {
            return 1 ;
        }
        return 0 ;
    }
    if ( dp[x][a][b] != -1 ) return dp[x][a][b] ;
    int ans = 0 ;
    for(int i = 0; i < 10; i++){
        if ( i == 0 ) ans += dfs(x + 1, 1, b) ;
        else if ( i == 9 ) ans += dfs(x + 1, a, 1) ;
        else ans += dfs(x + 1, a , b) ;
        ans %= MOD ;
    }
    return dp[x][a][b] = ans ;
}
signed main(){
    fastio
    memset(dp, -1, sizeof dp) ;
    cin >> n ;
    int ans = dfs(0, 0, 0) ;
    cout << ans << endl;
    return 0; 
}


Measured memory_bytes: 112916
#include <iostream>
#include <vector>
constexpr std::size_t N_MAX = 200'005UL;  //'

using std::vector;
// 辺の集合
using Graph = vector<vector<int>>;

vector<bool> visited(N_MAX);
vector<long> node(N_MAX);

void dfs(const Graph &g, const std::size_t &s = 1UL, long sum = 0L) {
    visited.at(s) = true;

    // ここで計算
    node.at(s) += sum;

    for (const int &next : g.at(s)) {
        if (visited.at(next)) continue;
        dfs(g, next, node.at(s));
    }
    return;
};

int main(void) {
    using std::cin;
    using std::cout;
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    Graph tree(n + 1UL);
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        tree.at(a).push_back(b);
        tree.at(b).push_back(a);
    }

    for (int i = 1; i <= q; ++i) {
        long p, x;
        cin >> p >> x;
        node.at(p) += x;
    }

    dfs(tree);
    for (int i = 1; i <= n; ++i) {
        cout << node.at(i) << (i == n ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 27392
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a = 0, b = 0, c = 0;
	while (1)
	{
		int e = 0;
		int f = 0;
		cin >> a >> b >> c;
		if (a == 0 && b == 0 && c == 0)
		{
			break;
		}
		int d[200];
		for (int i = 0; i < a; i++)
		{
			cin >> d[i];
		}
		sort(d, d + a);
		for (int i = b; i <= c; i++)
		{
			if (d[a - i] - d[a - i - 1] >= e)
			{
				e = d[a - i] - d[a - i - 1];
				f = i;
			}
		}
		cout << f << endl;
	}
return 0;
}

Measured memory_bytes: 3132
N=int(input())
A=list(map(int,input().split()))
cnt=[0 for _ in range(N+1)]
for i in range(N):
    cnt[A[i]]+=1
cmb=[cnt[k]*(cnt[k]-1)//2 for k in range(N+1)]
SUM=sum(cmb)
for j in range(N):
    n=A[j]
    v=cnt[A[j]]
    print(SUM-cmb[n]+(v-1)*(v-2)//2)

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

int main() {
    long long fib[50];
    int n;
    
    cin >> n;
    fib[0] = fib[1] = 1;
    for(int i=2; i<=n; i++) fib[i] = fib[i-1] + fib[i-2];
    
    cout << fib[n] << endl;
}



Measured memory_bytes: 3088
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<int, lld> pil;
typedef pair<pii, int> piii;
int n;
lld m;
int b[200009];
int a[200009];
int main()
{
	int i, j, k, l;
	int t = 1, tv = 0;
	while(t--)
	{
		scanf("%d %lld", &n, &m);
		for (i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
			b[i] = -1;
		}
		b[1] = 0;
		int si = 1;
		int cl = -1;
		m--;
		lld tm = m;
		for (k = 1; k <= tm; k++) {
			int ti = a[si];
			if (b[ti] == -1) {
				b[ti] = k;
				si = ti;
				m--;
			}
			else {
				cl = k - b[ti];
				break;
			}
		}
		if (cl == -1) {
			printf("%d\n", a[si]);
		}
		else {
			m %= cl;
			while (m > 0) {
				m--;
				si = a[si];
			}
			printf("%d\n", a[si]);
		}
	}
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

int main(void) {
  int n;
  cin >> n;
  int ans = n;
  while (ans > 0) ans -= 1000;
  ans = -ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
	ll n;
	scanf("%lld",&n);
	ll k=sqrt(n)+1;
	while(n%k!=0)k--;
	printf("%lld",k+n/k-2);
	return 0;
}


Measured memory_bytes: 3780
#include<stdio.h>

int main(void)
{
	int h, m, s;
	int x;
	
	scanf("%d", &x);
	
	h = x / 3600;
	x = x % 3600;
	m = x / 60;
	x = x % 60;
	s = x;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return (0);
}

Measured memory_bytes: 1020
x,y = [int(i) for i in input().split()]
if y%2 == 1:
    print("No")
elif y < 2*x or y > 4*x:
    print("No")
else:
    b = int((y - 2*x)/2)
    a = x - b
    if a >= 0 and b >= 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9180
n = int(input())
ans = []
sum_a = 0
for i in range(n):
    a, b = map(int, input().split())
    sum_a += a
    if a > b:
        ans.append(b)
if ans == []:
    min_ans = sum_a
else:
    min_ans = min(ans)
print(sum_a-min_ans)


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

public class Main
{
    static class Node{
        int b = 0;
        int w = 0;
        List<Integer> child;
    }
    static int subsetSum(int[] arr, int target){
        int n = arr.length;
        int m = target + 1;
        boolean[][] dp = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            if (arr[i] > target) continue;
            dp[i][arr[i]] = true;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (dp[i-1][j]){
                    dp[i][j] = true;
                    if (j + arr[i] <= target){
                        dp[i][j+arr[i]] = true;
                    }
                }
            }
        }
        for (int i = m-1; i >= 0;i--) {
            if (dp[n-1][i]){
                return i;
            }
        }
        return 0;
    }

    static Node[] nodes;
    static int[] X;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
        nodes = new Node[N];
        X = new int[N];
        for (int i = 0; i < N; i++) {
            nodes[i] = new Node();
            nodes[i].child = new ArrayList<>();
        }
        for (int i = 1; i < N; i++) {
            int par = sc.nextInt();
            nodes[par - 1].child.add(i);
        }
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        System.out.println(recur(0) ? "POSSIBLE": "IMPOSSIBLE");
    }

    public static boolean recur(int nodeIdx){
        Node cur = nodes[nodeIdx];
        if (cur.child == null || cur.child.size() == 0){
            cur.b = 0; cur.w = X[nodeIdx];
            return true;
        }
        for (int i = 0; i < cur.child.size(); i++) {
            if (!recur(cur.child.get(i))) {
                return false;
            }
        }
        int b = 0, w = 0;
        int[] swap = new int[cur.child.size()];
        for (int i = 0; i < cur.child.size(); i++) {
            int black = nodes[cur.child.get(i)].b;
            int white = nodes[cur.child.get(i)].w;
            b += Math.min(white, black);
            w += Math.max(white, black);
            swap[i] = Math.max(white, black) - Math.min(white, black);
        }
        if (b > X[nodeIdx]) {
            return false;
        }
        int sww = subsetSum(swap, X[nodeIdx] - b);
        cur.b = X[nodeIdx];
        cur.w = w - sww;
        return true;
    }

}

Measured memory_bytes: 29140
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int a;
    string b;
    int c;
    
    cin >> a >> b >> c;
    while(b!="?"){
        if (b=="+"){
            cout << a+c << endl;
        }
        else if (b=="-"){
            cout << a-c << endl;
        }
        else if (b=="*"){
            cout << a*c << endl;
        }
        else {
            cout << a/c << endl;
        }
        cin >> a >> b >> c;
    }
    
}



Measured memory_bytes: 3144
#include<iostream>
using namespace std;
int main(){
	int N, X, L[1000];
	int count = 1;
	int D = 0;
	L[1000] = {};
	cin >> N >> X;
	for (int i = 0; i < N; i++){
		cin >> L[i];
	}
	for (int i = 0; i < N; i++){
		D += L[i];
		if (D > X)break;
		count++;
	}

	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 256
def selectionSort(A,N):
    swapCount = 0
    for i in range(N):
        minj = A[i]
        indexj = i
        for j in range(i,N):
            if A[j] < minj:
                minj = A[j]
                indexj = j
        if indexj != i:
            A[indexj] = A[i]
            A[i] = minj
            swapCount += 1
    str = ""
    for k in range(N):
        str += "{} ".format(A[k])
    print(str[:len(str)-1])
    print(swapCount)

if __name__ == '__main__':
    N = int(input())
    A = [int(_) for _ in input().split()]

    selectionSort(A,N)



Measured memory_bytes: 5604
#include <cstdio>
using namespace std;
int main ()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b)
        printf("Draw\n");

    else if(a<b)
    {
        if(a==1)
        {
            printf("Alice\n");
        }
        else
            printf("Bob\n");
    }
    else if(a>b)
    {
        if(b==1)
            printf("Bob\n");
        else
            printf("Alice\n");
    }

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,m,k;cin>>n>>m>>k;
  vector<ll> a(n), b(m);
  rep(i, n)cin>>a[i];
  rep(i, m)cin>>b[i];

  rep(i, n-1)a[i+1]+=a[i];
  rep(i, m-1)b[i+1]+=b[i];

  ll result=0;

  rep(i, n){
    ll ac = i+1;
    ll lim = k-a[i];
    if(lim<0)continue;

    result = max<ll>(result, ac);

    auto it = lower_bound(b.begin(), b.end(), lim);
    if(it==b.end())continue;
    if(*it>lim){
      if(it==b.begin())continue;
      it--;
    }

    ll bc = it-b.begin();bc++;
    result = max<ll>(result, ac+bc);
  }

  rep(i, m){
    ll bc = i+1;
    ll lim = k-b[i];
    if(lim<0)continue;

    result = max<ll>(result, bc);

    auto it = lower_bound(a.begin(), a.end(), lim);
    if(it==a.end())continue;
    if(*it>lim){
      if(it==a.begin())continue;
      it--;
    }

    ll ac = it-a.begin();ac++;
    result = max<ll>(result, ac+bc);
  }

  cout<<result<<endl;

  return 0;
}

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

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

void dfs(Graph &g, int *p, int u, bool &f, int &r){
    for(int v : g.g[u]){
        if(f) break;
        if(p[v] != -1){
            p[v] = u;
            r = u;
            f = true;
            break;
        }
        p[v] = u;
        dfs(g, p, v, f, r);
    }
    if(f) return;
    p[u] = -1;
}

int main()
{
    int n, m;
    cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
    }
    int p[1003];
    for(int i = 0; i < n; i++) p[i] = -1;
    bool f = false;
    int r = -1;
    for(int i = 0; i < n; i++){
        dfs(g, p, i, f, r);
        if(r != -1) break;
    }
    if(!f){
        cout << -1 << endl;
        return 0;
    }
    int nx[1003];
    for(int i = 0; i < n; i++) nx[i] = -1;
    while(nx[p[r]] == -1){
        nx[p[r]] = r;
        r = p[r];
    }
    int c = 0;
    int u = r;
    while(c < n * 2){
        for(int v : g.g[u]){
            if(nx[v] != -1 && nx[u] != v){
                int w = nx[u];
                while(w != v){
                    int x = w;
                    w = nx[w];
                    nx[x] = -1;
                }
                nx[u] = v;
                c = 0;
            }
        }
        u = nx[u];
        c++;
    }
    int k = 0;
    int v = u;
    vector<int> ans;
    while(k == 0 || v != u){
        ans.push_back(v);
        v = nx[v];
        k++;
    }
    cout << k << endl;
    for(int v : ans) cout << v + 1 << endl;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    string s;
    cin>>s;
    int n=s.size();
    long long ans=0;
    long long cnt=0;
    for(int i=0;i<n-1;){
        if(s[i]=='A') cnt++;
        if(s[i]=='C') cnt=0;
        if(s[i]=='B' && s[i+1]!='C') cnt=0;
        if(s[i]=='B' && s[i+1]=='C'){
            ans+=cnt;
            i++;
        }
        i++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		// ??\???
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();
		// ???????????£?¨?
		int A[][] = new int[n][m];
		int B[][] = new int[m][l];
		// ?????????????´?
		for(int i=0; i<n; i++){
			for(int i2=0; i2<m; i2++){
				int x = scan.nextInt();
				A[i][i2] = x;
			}
		}
		for(int i=0; i<m; i++){
			for(int i2=0; i2<l; i2++){
				int x = scan.nextInt();
				B[i][i2] = x;
			}
		}
		
		// 	???????±????????
		for(int i=0; i<n; i++){
			int x = 0;
			long y = 0;
			for(int j=0; j<l; j++){
				long C = 0;
				for (int k=0; k<m; k++){
					y = A[i][k]*B[k][j];
					C = C + y;
					// ??????
					if(k == (m-1)){
						System.out.print(C);
						x++;
						if(x == l) x = 0;
						else System.out.print(" ");
						
					}
				}
			}
			System.out.println();
		}
			
		
	}

}

Measured memory_bytes: 54560
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
h = Hash.new(0)

def power(n, m)
    ret = 1
    m.times do
        ret = ret * n % 1000000007
    end
    return ret
end

if n % 2 == 0
    a.sort.each_with_index do |v, i|
        if v != (i / 2) * 2 + 1
            puts 0
            exit
        end
    end

else
    a.sort.each_with_index do |v, i|
        if v != ((i+1) / 2) * 2
            puts 0
            exit
        end
    end
end
puts power(2, n / 2)


Measured memory_bytes: 10248
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {
	string s; cin >> s;
	int end_s = s.length() - 3;
	int nummin = 9999;
	for(int i = 0; i <= end_s; i++) {
		int num_s = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
		nummin = min(nummin, abs(num_s-753));
	}
	cout << nummin << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int a[maxn];
int main()
{
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
        cout << "3" << endl;
    else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
        cout << "2" << endl;
    else if (s[0] == 'R' || s[1] == 'R'
             || s[2] == 'R')
        cout << "1" << endl;
    else cout << "0" << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
 
using namespace std;

const char nl = '\n';

void solve() {
	double d,t,s;
	cin >> d >> t >> s;
	if ((d/s) <= t) {
		cout << "Yes" << nl;
	} else {
		cout << "No" << nl;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}


Measured memory_bytes: 3728
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = list(input())
    numb = 0
    numw = S.count(".")
    answer = numb + numw
    for i in range(N):
        if S[i] == "#":
            numb += 1
        else:
            numw -= 1
        if answer > numb + numw:
            answer = numb + numw

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4840
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> P;

int main(){
	int N,A,B;
	cin >> N >> A >> B;
	string s;
	cin >> s;
	int all = 0;
	int non = 0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='a' && all<A+B){
			all++;
			cout << "Yes" << endl;
		}else if(s[i]=='b' && all<A+B && non<B){
			all++;
			non++;
			cout << "Yes" << endl;
		}else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
 
struct shop{
  int p;
  int index;
  char s[20];
};
 
int main(void){
  
  int n, ret; 
  ret = scanf("%d", &n);
  
  struct shop shops[n], tmp;
  
  for(int i = 0; i < n; i++){
    ret = scanf("%s %d", shops[i].s, &shops[i].p); 
    shops[i].index = i+1;
  }
  
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      if (strcmp(shops[i].s, shops[j].s) > 0) {
        tmp = shops[i];
        shops[i] = shops[j];
        shops[j] = tmp;
      }else if(strcmp(shops[i].s, shops[j].s) == 0){
      	if(shops[i].p < shops[j].p){
          tmp = shops[i];
          shops[i] = shops[j];
          shops[j] = tmp;
        }
      }
    }
  }
  
  for(int i = 0; i < n; i++){
   printf("%d\n", shops[i].index); 
  }
  
  return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};

template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}

extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}

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

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}


int main()
{
    LL x,y;cin>>x>>y;
    LL ans=0;
    while(x<=y)
    {
        x*=2;
        ans++;
    }
    print(ans);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static int N;
  public static int M;
  public static int[] k;
  public static int[][] s;
  public static int[] p;
  public static int[] status;
  public static int count;

  public static void main (String[] args) {
	
    Scanner sc = new Scanner(System.in);
    
    N = sc.nextInt();
    M = sc.nextInt();
    
    k = new int[M];
    s = new int[M][];

    p = new int[M];

    status = new int[N];

    for (int i = 0; i < M; i++) {
      
      k[i] = sc.nextInt();
      s[i] = new int[k[i]];
      
      for (int j = 0; j < k[i]; j++) {
        s[i][j] = sc.nextInt();
      }

    }

    for (int i = 0; i < M; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    count = 0;

    dfs(0, status);

    System.out.println(count);
 
  }

  public static void dfs(int i, int[] status){

    if (i == N) {

      int check = 0;

      for (int j = 0; j < M; j++) {
        int on = 0;
        
        for (int k = 0; k < s[j].length; k++) {
          int l = s[j][k] - 1;
          if (status[l] == 1) {
            on++;
          }
        }
        if (on % 2 == p[j]){
          check++;
        }
      }

      if (check == M){
        count++;
      }

      return;

    }

    status[i] = 0;
    dfs(i+1, status);

    status[i] = 1;
    dfs(i+1, status);
    
  }

}

Measured memory_bytes: 24148
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int ans=k;
	for(int i=0;i<n-1;i++) ans*=(k-1);
	if(k==1)ans=n;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char* argv[] ){
	int input;
	std::cin>> input;
	auto hour = input / 3600;
	auto min  = (input - hour*3600) /60;
	auto sec  = input - hour*3600 - min*60;
	
	std::cout << hour << ":"<<min<<":"<<sec<<std::endl;
	
	}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    cout << (n+1) / 2 << endl;
}


Measured memory_bytes: 3608
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut v: Vec<(i64, i64, i64)> = Vec::new();
    for i in 0..n {
       let mut temp = {
           let v = read_vec();
           (v[0], v[1], v[2])
       };
       v.push(temp);
    }

    let mut dp: Vec<(i64, i64, i64)> = Vec::new();
    dp.push((0, 0, 0));

    for i in 0..n {
        let (ap, bp, cp) = v[i];
        let (at, bt, ct) = dp[i];
        let a = cmp::max(ap + bt, ap + ct);
        let b = cmp::max(bp + at, bp + ct);
        let c = cmp::max(cp + at, cp + bt);
        dp.push((a, b, c));
    }
    let (a, b, c) = dp[n];
    let ans = if a > b {
                if a > c {
                    a
                } else {
                    c
                }
            } else {
                if c > b {
                    c
                } else {
                    b
                }
            };
    println!("{}", ans);

}


Measured memory_bytes: 13432
n = int(input())
a = list(map(int, input().split()))
s = {}
for aa in a:
    if aa not in s.keys():
        s[aa] = 1
    else:
        s[aa] += 1
    
    if aa + 1 not in s.keys():
        s[aa+1] = 1
    else:
        s[aa+1] += 1
    
    if aa - 1 not in s.keys():
        s[aa-1] = 1
    else:
        s[aa-1] += 1

print(max(s.values()))

Measured memory_bytes: 19748
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define txt freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout)
#define a3 INT_MAX
#define i3 INT_MIN
#define a6 INT64_MAX
#define i6 INT64_MIN
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define div2(a) (!(a&1))
#define deb(x) cout<<(#x)<<" "<<(x)<<"\n";
#define newl cout<<"\n" 
#define all(s) s.begin(),s.end()
#define pi 3.14159265358979323846
#define mod 1000000007
#define fp(x) fixed<<setprecision(x)<<
template<class T>
int digit(T a)
{
    vector<long long> dig = {
        0,
        9,
        99,
        999,
        9999,
        99999,
        999999,
        9999999,
        99999999,
        999999999,
        9999999999,
        99999999999,
        999999999999,
        9999999999999,
        99999999999999,
        999999999999999,
        9999999999999999,
        99999999999999999,
        999999999999999999,
        INT64_MAX};
    auto it = lower_bound(dig.begin(), dig.end(), a);
    int idx = (it - dig.begin());
    return idx;
}
template<class T>
int sumAllInts(T n){
    int a = 1;
    int su = 0;
    while(n){
        su += n%10;
        n/=10;
    }
    return su;
}
template<class T>
void split(char c,T s){
    int n = s.size();
    int i = 0;
    while ((cout<<s[i],i+=1) && (i<n) && (cout<<c<<' '));
}
void solve(){
    bool n; cin>>n;
    cout<<!n;
    
}
int main(){
    quickie;
    //txt;
    int t= 1;
    while(t--){
        solve(); 
        newl; 
    } 
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<vector<int>> a(h,vector<int>(w));
	rep(i,h) rep(j,w) cin >> a.at(i).at(j);
	vector<int> x,y,x1,y1;
	rep(i,h){
		rep(j,w){
			if(j==w-1 && i==h-1) break;
			if(j==w-1){
				if(a.at(i).at(j)%2==1){
					x.pb(j+1);
					y.pb(i+1);
					x1.pb(j+1);
					y1.pb(i+2);
					a.at(i+1).at(j)++;
				}
			}
			else{
				if(a.at(i).at(j)%2==1){
					x.pb(j+1);
					y.pb(i+1);
					x1.pb(j+2);
					y1.pb(i+1);
					a.at(i).at(j+1)++;
				}
			}
		}
	}
	cout << x.size() << endl;
	rep(i,x.size()){
		cout << y.at(i) << " " << x.at(i) << " " << y1.at(i) << " " << x1.at(i) << endl;
	}
}

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

long long n, m;

int main(){

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

	cin >> n >> m;
	
	long long ansn, ansm;
	
	ansn = n*(n-1) / 2;
	ansm = m*(m-1) / 2;
	
	cout << ansn + ansm;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	int ans = 0;
	rep(i, n){
		cin >> a[i];
		a[i]--;
	}
	rep(i, n) if(a[a[i]] == i) ans++;
	cout << ans/2 << endl;
	return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int count = 0;
  rep(i,N){
      int x;
      cin >> x;
      if(x >= K) count += 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}
		double min = Double.MAX_VALUE;
		int minPotision = 0;
		for (int i = 0; i < N; i++) {
			if (Math.abs(T - H[i] * 0.006 - A) < min) {
				min = Math.abs(T - H[i] * 0.006 - A);
				minPotision = i;
			}
		}
		System.out.print(minPotision + 1);
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h> 
#include <sstream> 
using namespace std; 
typedef long long ll;
typedef pair< ll , ll > pll;
typedef pair< ll , pll > plll;
typedef priority_queue< plll , vector< plll > , greater<plll> > min_heap;
#define ft first
#define sd second
#define maxx 3000
int main() 
{ 
		ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	  	int n , m;
	  	cin >> n >> m;
	  	map< int , int > mp1 , mp2;
	  	set< int > st;
	  	int cnt1 = 0 , cnt2 = 0; 
	  	for(int i = 0 ; i < m ; i++){
	  		int x ;
	  		string y;
	  		cin >> x >> y;
	  		if(y == "WA")
	  		{
	  			mp2[x]++;
	  		}	
	  		if(y == "AC" && mp1[x] == 0){
	  			cnt1++;
	  			cnt2 += mp2[x];
	  			mp1[x]++;
	  		}
	  		
	  	}
	  	cout << cnt1 << " " << cnt2 << endl;

	 return 0;
 }

Measured memory_bytes: 9600
n=gets.to_i
mat=Array.new(n){Array.new(n,0)}
n.times do
  id,degree,*adj=gets.split.map(&:to_i)
  degree.times do |i|
    mat[id-1][adj[i]-1]+=1
  end
end
mat.each do |matr|
  puts matr.join(" ")
end

Measured memory_bytes: 8776
//E
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
vector<ll>v,A,B,C;
int main(){
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	for(int i = 1;i <= a;i++){
		ll x;cin >> x;A.push_back(x);
	}
	for(int i = 1;i <= b;i++){
		ll x;cin >> x;B.push_back(x);
	}
	for(int i = 1;i <= c;i++){
		ll x;cin >> x;C.push_back(x);
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	reverse(A.begin(),A.end());
	reverse(B.begin(),B.end());
	reverse(C.begin(),C.end());
	for(int i = 0;i < x;i++)v.push_back(A[i]);
	for(int i = 0;i < y;i++)v.push_back(B[i]);
	for(int i = 0;i < c;i++)v.push_back(C[i]);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i = 0;i < x+y;i++)ans += v[i];
	cout << ans;
	return 0;
}


Measured memory_bytes: 8432
#include<iostream>
#include<algorithm>
#define mod 100000
using namespace std;
int main(){
 
        int w,h;
        while(cin>>w>>h,w||h){
            int dp[101][101][2][2]={{{{0}}}},sum=0;
            dp[0][0][0][1]=dp[0][0][1][1]=1;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    for(int k=0;k<2;k++)for(int l=0;l<2;l++)dp[i][j][k][l]%=mod;
 
                    dp[i+1][j][0][0]+=dp[i][j][0][1];
                    dp[i][j+1][1][0]+=dp[i][j][1][1];
 
                    dp[i+1][j][0][0]+=dp[i][j][0][0];
                    dp[i][j+1][1][0]+=dp[i][j][1][0];
 
                    dp[i+1][j][0][1]+=dp[i][j][1][0];
                    dp[i][j+1][1][1]+=dp[i][j][0][0];
                }
            }
            for(int i=0;i<2;i++)
                for(int j=0;j<2;j++)
                    sum+=dp[h-1][w-1][i][j];
 
            sum%=mod;
            cout<<sum<<endl;
        }
}

Measured memory_bytes: 3244
import Control.Monad.Trans.State

main :: IO ()
main = do
  s <- getLine
  n <- readLn
  putChar $ evalState solve (s, n)

solve :: State (String, Int) Char
solve = do
  (c:cs, k) <- get
  if k == 1 || c /= '1'
    then return c
    else put (cs, k - 1) >> solve

Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
int n,l;
vector<int> v;
int main()
{
	cin>>n>>l;
	for(int i=1;i<=n;i++)
		v.push_back(i+l-1);
	int sum=0;
	for(int i=0;i<n;i++)	
		sum+=v[i];
	int mn=1e9,ans;
	for(int i=0;i<n;i++)
		if(abs(sum-(sum-v[i]))<mn)
		{
			mn=abs(sum-(sum-v[i]));
			ans=sum-v[i];
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



N,M = map(int,input().split())
uf = UnionFind(N)

for _ in range(M):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)

ans = 1
for i in range(N):
    ans = max(ans,uf.size(i))

print(ans)


Measured memory_bytes: 14408
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b; readV(a, b);
  auto c = b-a;
  writeln(c*(c+1)/2-b);
}


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

namespace AtCoder
{
    class Program
    {
        static int n;

        static void Main(string[] args)
        {
            //[summary]A - Measure
            string s = Console.ReadLine();

            if (s.Length == 3)
            {
                var chars = s.ToCharArray().Reverse().ToArray();
                s = new String(chars);
            }

            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 13268